TestValueTag.java revision 3294:9adfb22ff08f
1104478Ssam/*
2104630Ssam * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
3104478Ssam * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4139749Simp *
5104478Ssam * This code is free software; you can redistribute it and/or modify it
6104478Ssam * under the terms of the GNU General Public License version 2 only, as
7104478Ssam * published by the Free Software Foundation.
8104478Ssam *
9104478Ssam * This code is distributed in the hope that it will be useful, but WITHOUT
10104478Ssam * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11104478Ssam * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12104478Ssam * version 2 for more details (a copy is included in the LICENSE file that
13104478Ssam * accompanied this code).
14104478Ssam *
15104478Ssam * You should have received a copy of the GNU General Public License version
16104478Ssam * 2 along with this work; if not, write to the Free Software Foundation,
17104478Ssam * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18104478Ssam *
19104478Ssam * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20104478Ssam * or visit www.oracle.com if you need additional information or have any
21104478Ssam * questions.
22104478Ssam */
23104478Ssam
24104478Ssam/*
25104478Ssam * @test
26104478Ssam * @bug      4764045 8004825 8026567
27104478Ssam * @summary  This test ensures that the value tag works in all
28104478Ssam * use cases. The explainations for each test case are written below.
29104478Ssam * @author   jamieh
30104478Ssam * @library ../lib
31104478Ssam * @modules jdk.javadoc/jdk.javadoc.internal.tool
32104478Ssam * @build    JavadocTester
33104478Ssam * @run main TestValueTag
34104478Ssam */
35104478Ssam
36104478Ssampublic class TestValueTag extends JavadocTester {
37104478Ssam
38104478Ssam    public static void main(String... args) throws Exception {
39104478Ssam        TestValueTag tester = new TestValueTag();
40104478Ssam        tester.runTests();
41104478Ssam    }
42104478Ssam
43104478Ssam    @Test
44104478Ssam    void test1() {
45104478Ssam        javadoc("-d", "out1",
46104478Ssam                "-sourcepath", testSrc,
47104478Ssam                "-tag", "todo",
48104478Ssam                "pkg1", "pkg2");
49104478Ssam        checkExit(Exit.FAILED);
50104478Ssam
51104478Ssam        checkOutput("pkg1/Class1.html", true,
52104478Ssam                // Base case:  using @value on a constant.
53104478Ssam                "Result:  \"Test 1 passes\"",
54104478Ssam                // Retrieve value of constant in same class.
55104478Ssam                "Result:  <a href=\"../pkg1/Class1.html#TEST_2_PASSES\">\"Test 2 passes\"</a>",
56110519Ssam                "Result:  <a href=\"../pkg1/Class1.html#TEST_3_PASSES\">\"Test 3 passes\"</a>",
57110519Ssam                "Result:  <a href=\"../pkg1/Class1.html#TEST_4_PASSES\">\"Test 4 passes\"</a>",
58104478Ssam                "Result:  <a href=\"../pkg1/Class1.html#TEST_5_PASSES\">\"Test 5 passes\"</a>",
59104478Ssam                "Result:  <a href=\"../pkg1/Class1.html#TEST_6_PASSES\">\"Test 6 passes\"</a>");
60104478Ssam
61108823Ssam        checkOutput("pkg1/Class2.html", true,
62104478Ssam                // Retrieve value of constant in different class.
63104478Ssam                "Result:  <a href=\"../pkg1/Class1.html#TEST_7_PASSES\">\"Test 7 passes\"</a>",
64104478Ssam                "Result:  <a href=\"../pkg1/Class1.html#TEST_8_PASSES\">\"Test 8 passes\"</a>",
65104478Ssam                "Result:  <a href=\"../pkg1/Class1.html#TEST_9_PASSES\">\"Test 9 passes\"</a>",
66104478Ssam                "Result:  <a href=\"../pkg1/Class1.html#TEST_10_PASSES\">\"Test 10 passes\"</a>",
67104478Ssam                "Result:  <a href=\"../pkg1/Class1.html#TEST_11_PASSES\">\"Test 11 passes\"</a>",
68104478Ssam                // Retrieve value of constant in different package
69104478Ssam                "Result:  <a href=\"../pkg2/Class3.html#TEST_12_PASSES\">\"Test 12 passes\"</a>",
70104478Ssam                "Result:  <a href=\"../pkg2/Class3.html#TEST_13_PASSES\">\"Test 13 passes\"</a>",
71104478Ssam                "Result:  <a href=\"../pkg2/Class3.html#TEST_14_PASSES\">\"Test 14 passes\"</a>",
72104478Ssam                "Result:  <a href=\"../pkg2/Class3.html#TEST_15_PASSES\">\"Test 15 passes\"</a>",
73104478Ssam                "Result:  <a href=\"../pkg2/Class3.html#TEST_16_PASSES\">\"Test 16 passes\"</a>");
74104478Ssam
75104478Ssam        checkOutput("pkg2/package-summary.html", true,
76104478Ssam                // Retrieve value of constant from a package page
77104478Ssam                "Result: <a href=\"../pkg2/Class3.html#TEST_17_PASSES\">\"Test 17 passes\"</a>");
78104478Ssam
79104478Ssam        checkOutput("pkg1/CustomTagUsage.html", true,
80104478Ssam                // Test @value tag used with custom tag.
81104478Ssam                "<dt><span class=\"simpleTagLabel\">Todo:</span></dt>\n" +
82104478Ssam                "<dd>the value of this constant is 55.</dd>");
83104478Ssam
84104478Ssam        checkOutput(Output.OUT, true,
85104478Ssam                // Test @value errors printed due to invalid use or when used with
86104478Ssam                // non-constant or with bad references.
87104478Ssam                "error: value does not refer to a constant\n"
88104478Ssam                + "     * Result:  {@value TEST_12_ERROR}",
89104478Ssam                "error: {@value} not allowed here\n"
90104478Ssam                + "     * Result:  {@value}",
91104478Ssam                "error: value does not refer to a constant\n"
92104478Ssam                + "     * Result:  {@value NULL}",
93104478Ssam                "error: {@value} not allowed here\n"
94104478Ssam                + "     * Invalid (null): {@value}",
95104630Ssam                "error: {@value} not allowed here\n"
96104478Ssam                + "     * Invalid (non-constant field): {@value}",
97104478Ssam                "error: value does not refer to a constant\n"
98104478Ssam                + "     * Here is a bad value reference: {@value UnknownClass#unknownConstant}",
99104478Ssam                "error: reference not found\n"
100104478Ssam                + "     * Here is a bad value reference: {@value UnknownClass#unknownConstant}",
101104478Ssam                "error: {@value} not allowed here\n"
102104478Ssam                + "     * @todo the value of this constant is {@value}"
103104478Ssam        );
104104478Ssam
105104478Ssam        checkOutput("pkg1/Class1.html", false,
106104478Ssam                //Base case:  using @value on a constant.
107104478Ssam                "Result:  <a href=\"../pkg1/Class1.html#TEST_12_ERROR\">\"Test 12 "
108104478Ssam                + "generates an error message\"</a>");
109104478Ssam
110104478Ssam        checkForException();
111104478Ssam    }
112104478Ssam
113104478Ssam    @Test()
114104478Ssam    void test2() {
115104478Ssam        javadoc("-Xdoclint:none",
116104478Ssam                "-d", "out2",
117104478Ssam                "-sourcepath", testSrc,
118104478Ssam                "-tag", "todo",
119104478Ssam                "pkg1", "pkg2");
120104478Ssam        checkExit(Exit.OK);
121104478Ssam        checkOutput(Output.OUT, true,
122104478Ssam                //Test @value warning printed when used with non-constant.
123104478Ssam                "warning - @value tag (which references nonConstant) "
124104478Ssam                + "can only be used in constants.",
125104478Ssam                "warning - @value tag (which references NULL) "
126104478Ssam                + "can only be used in constants.",
127104478Ssam                "warning - @value tag (which references TEST_12_ERROR) "
128104478Ssam                + "can only be used in constants."
129104478Ssam// TODO: re-examine these.
130104478Ssam//                //Test warning printed for bad reference.
131104478Ssam//                "warning - UnknownClass#unknownConstant (referenced by "
132104478Ssam//                + "@value tag) is an unknown reference.",
133104478Ssam//                //Test warning printed for invalid use of @value.
134104478Ssam//                "warning - @value tag cannot be used here."
135104478Ssam        );
136104478Ssam        checkForException();
137104478Ssam    }
138104478Ssam
139104478Ssam    void checkForException() {
140104478Ssam        checkOutput(Output.STDERR, false, "DocletAbortException");
141104478Ssam    }
142104478Ssam}
143104478Ssam