Path: blob/master/test/langtools/jdk/javadoc/doclet/testCharsetDocencodingOptions/TestCharsetDocencodingOptions.java
40971 views
/*1* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 818358226* @summary Rationalize doclet -docencoding and -charset options.27* @library ../../lib28* @modules jdk.javadoc/jdk.javadoc.internal.tool29* @build javadoc.tester.*30* @run main TestCharsetDocencodingOptions31*/3233import javadoc.tester.JavadocTester;3435public class TestCharsetDocencodingOptions extends JavadocTester {3637public static void main(String... args) throws Exception {38TestCharsetDocencodingOptions tester = new TestCharsetDocencodingOptions();39tester.runTests();40}4142@Test43public void testWithNoOptions() {44javadoc("-d", "out",45"-sourcepath", testSrc,46"pkg");47checkExit(Exit.OK);4849checkOutputFileEncoding("utf-8");50}5152@Test53public void testWithDocencoding() {54javadoc("-d", "out-1",55"-docencoding", "ISO-8859-1",56"-sourcepath", testSrc,57"pkg");58checkExit(Exit.OK);5960checkOutputFileEncoding("ISO-8859-1");61}6263@Test64public void testWithCharset() {65javadoc("-d", "out-2",66"-charset", "ISO-8859-1",67"-sourcepath", testSrc,68"pkg");69checkExit(Exit.OK);7071checkOutputFileEncoding("ISO-8859-1");72}7374@Test75public void testDocencodingWithCharsetSimilar() {76javadoc("-d", "out-3",77"-docencoding", "ISO-8859-1",78"-charset", "ISO-8859-1",79"-sourcepath", testSrc,80"pkg");81checkExit(Exit.OK);8283checkOutputFileEncoding("ISO-8859-1");84}8586@Test87public void testDocencodingWithCharsetDifferent() {88javadoc("-d", "out-4",89"-charset", "UTF-8",90"-docencoding", "ISO-8859-1",91"-sourcepath", testSrc,92"pkg");93checkExit(Exit.ERROR);9495checkOutput(Output.OUT, true,96"error: Option -charset conflicts with -docencoding");97}9899@Test100public void testWithEncoding() {101javadoc("-d", "out-5",102"-sourcepath", testSrc,103"-encoding", "ISO-8859-1",104"pkg");105checkExit(Exit.OK);106107checkOutputFileEncoding("ISO-8859-1");108}109110111void checkOutputFileEncoding(String charset) {112checkOutput("index.html", true,113"""114<meta http-equiv="Content-Type" content="text/html; charset=""" + charset + "\">");115checkOutput("pkg/Foo.html", true,116"""117<meta http-equiv="Content-Type" content="text/html; charset=""" + charset + "\">");118}119}120121122