1/*
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/*
25 * @test
26 * @bug      8183582
27 * @summary  Rationalize doclet -docencoding and -charset options.
28 * @library  ../lib
29 * @modules jdk.javadoc/jdk.javadoc.internal.tool
30 * @build    JavadocTester
31 * @run main TestCharsetDocencodingOptions
32 */
33
34public class TestCharsetDocencodingOptions extends JavadocTester {
35
36    public static void main(String... args) throws Exception {
37        TestCharsetDocencodingOptions tester = new TestCharsetDocencodingOptions();
38        tester.runTests();
39    }
40
41    @Test
42    void testWithNoOptions() {
43        javadoc("-d", "out",
44                "-sourcepath", testSrc,
45                "pkg");
46        checkExit(Exit.OK);
47
48        checkOutputFileEncoding("utf-8");
49    }
50
51    @Test
52    void testWithDocencoding() {
53        javadoc("-d", "out-1",
54                "-docencoding", "ISO-8859-1",
55                "-sourcepath", testSrc,
56                "pkg");
57        checkExit(Exit.OK);
58
59        checkOutputFileEncoding("ISO-8859-1");
60    }
61
62    @Test
63    void testWithCharset() {
64        javadoc("-d", "out-2",
65                "-charset", "ISO-8859-1",
66                "-sourcepath", testSrc,
67                "pkg");
68        checkExit(Exit.OK);
69
70        checkOutputFileEncoding("ISO-8859-1");
71    }
72
73    @Test
74    void testDocencodingWithCharsetSimilar() {
75        javadoc("-d", "out-3",
76                "-docencoding", "ISO-8859-1",
77                "-charset", "ISO-8859-1",
78                "-sourcepath", testSrc,
79                "pkg");
80        checkExit(Exit.OK);
81
82        checkOutputFileEncoding("ISO-8859-1");
83    }
84
85    @Test
86    void testDocencodingWithCharsetDifferent() {
87        javadoc("-d", "out-4",
88                "-charset", "UTF-8",
89                "-docencoding", "ISO-8859-1",
90                "-sourcepath", testSrc,
91                "pkg");
92        checkExit(Exit.ERROR);
93
94        checkOutput(Output.OUT, true,
95                "javadoc: error - Option -charset conflicts with -docencoding");
96    }
97
98    @Test
99    void testWithEncoding() {
100        javadoc("-d", "out-5",
101                "-sourcepath", testSrc,
102                "-encoding", "ISO-8859-1",
103                "pkg");
104        checkExit(Exit.OK);
105
106        checkOutputFileEncoding("ISO-8859-1");
107    }
108
109
110    void checkOutputFileEncoding(String charset) {
111        checkOutput("index.html", true,
112                "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" + charset + "\">");
113        checkOutput("pkg/Foo.html", true,
114                "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" + charset + "\">");
115    }
116}
117