1 /*
   2  * Copyright (c) 2003, 2015, 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      4764045 8004825 8026567
  27  * @summary  This test ensures that the value tag works in all
  28  * use cases. The explainations for each test case are written below.
  29  * @author   jamieh
  30  * @library ../lib
  31  * @modules jdk.javadoc
  32  * @build    JavadocTester
  33  * @run main TestValueTag
  34  */
  35 
  36 public class TestValueTag extends JavadocTester {
  37 
  38     public static void main(String... args) throws Exception {
  39         TestValueTag tester = new TestValueTag();
  40         tester.runTests();
  41     }
  42 
  43     @Test
  44     void test1() {
  45         javadoc("-d", "out1",
  46                 "-sourcepath", testSrc,
  47                 "-tag", "todo",
  48                 "pkg1", "pkg2");
  49         checkExit(Exit.FAILED);
  50 
  51         checkOutput("pkg1/Class1.html", true,
  52                 // Base case:  using @value on a constant.
  53                 "Result:  \"Test 1 passes\"",
  54                 // Retrieve value of constant in same class.
  55                 "Result:  <a href=\"../pkg1/Class1.html#TEST_2_PASSES\">\"Test 2 passes\"</a>",
  56                 "Result:  <a href=\"../pkg1/Class1.html#TEST_3_PASSES\">\"Test 3 passes\"</a>",
  57                 "Result:  <a href=\"../pkg1/Class1.html#TEST_4_PASSES\">\"Test 4 passes\"</a>",
  58                 "Result:  <a href=\"../pkg1/Class1.html#TEST_5_PASSES\">\"Test 5 passes\"</a>",
  59                 "Result:  <a href=\"../pkg1/Class1.html#TEST_6_PASSES\">\"Test 6 passes\"</a>");
  60 
  61         checkOutput("pkg1/Class2.html", true,
  62                 // Retrieve value of constant in different class.
  63                 "Result:  <a href=\"../pkg1/Class1.html#TEST_7_PASSES\">\"Test 7 passes\"</a>",
  64                 "Result:  <a href=\"../pkg1/Class1.html#TEST_8_PASSES\">\"Test 8 passes\"</a>",
  65                 "Result:  <a href=\"../pkg1/Class1.html#TEST_9_PASSES\">\"Test 9 passes\"</a>",
  66                 "Result:  <a href=\"../pkg1/Class1.html#TEST_10_PASSES\">\"Test 10 passes\"</a>",
  67                 "Result:  <a href=\"../pkg1/Class1.html#TEST_11_PASSES\">\"Test 11 passes\"</a>",
  68                 // Retrieve value of constant in different package
  69                 "Result:  <a href=\"../pkg2/Class3.html#TEST_12_PASSES\">\"Test 12 passes\"</a>",
  70                 "Result:  <a href=\"../pkg2/Class3.html#TEST_13_PASSES\">\"Test 13 passes\"</a>",
  71                 "Result:  <a href=\"../pkg2/Class3.html#TEST_14_PASSES\">\"Test 14 passes\"</a>",
  72                 "Result:  <a href=\"../pkg2/Class3.html#TEST_15_PASSES\">\"Test 15 passes\"</a>",
  73                 "Result:  <a href=\"../pkg2/Class3.html#TEST_16_PASSES\">\"Test 16 passes\"</a>");
  74 
  75         checkOutput("pkg2/package-summary.html", true,
  76                 // Retrieve value of constant from a package page
  77                 "Result: <a href=\"../pkg2/Class3.html#TEST_17_PASSES\">\"Test 17 passes\"</a>");
  78 
  79         checkOutput("pkg1/CustomTagUsage.html", true,
  80                 // Test @value tag used with custom tag.
  81                 "<dt><span class=\"simpleTagLabel\">Todo:</span></dt>\n" +
  82                 "<dd>the value of this constant is 55.</dd>");
  83 
  84         checkOutput(Output.ERROR, true,
  85                 // Test @value errors printed due to invalid use or when used with
  86                 // non-constant or with bad references.
  87                 "error: value does not refer to a constant\n"
  88                 + "     * Result:  {@value TEST_12_ERROR}",
  89                 "error: {@value} not allowed here\n"
  90                 + "     * Result:  {@value}",
  91                 "error: value does not refer to a constant\n"
  92                 + "     * Result:  {@value NULL}",
  93                 "error: {@value} not allowed here\n"
  94                 + "     * Invalid (null): {@value}",
  95                 "error: {@value} not allowed here\n"
  96                 + "     * Invalid (non-constant field): {@value}",
  97                 "error: value does not refer to a constant\n"
  98                 + "     * Here is a bad value reference: {@value UnknownClass#unknownConstant}",
  99                 "error: reference not found\n"
 100                 + "     * Here is a bad value reference: {@value UnknownClass#unknownConstant}",
 101                 "error: {@value} not allowed here\n"
 102                 + "     * @todo the value of this constant is {@value}"
 103         );
 104 
 105         checkOutput("pkg1/Class1.html", false,
 106                 //Base case:  using @value on a constant.
 107                 "Result:  <a href=\"../pkg1/Class1.html#TEST_12_ERROR\">\"Test 12 "
 108                 + "generates an error message\"</a>");
 109 
 110         checkForException();
 111     }
 112 
 113     @Test()
 114     void test2() {
 115         javadoc("-Xdoclint:none",
 116                 "-d", "out2",
 117                 "-sourcepath", testSrc,
 118                 "-tag", "todo",
 119                 "pkg1", "pkg2");
 120         checkExit(Exit.OK);
 121         checkOutput(Output.WARNING, true,
 122                 //Test @value warning printed when used with non-constant.
 123                 "warning - @value tag (which references nonConstant) "
 124                 + "can only be used in constants.",
 125                 "warning - @value tag (which references NULL) "
 126                 + "can only be used in constants.",
 127                 "warning - @value tag (which references TEST_12_ERROR) "
 128                 + "can only be used in constants.",
 129                 //Test warning printed for bad reference.
 130                 "warning - UnknownClass#unknownConstant (referenced by "
 131                 + "@value tag) is an unknown reference.",
 132                 //Test warning printed for invalid use of @value.
 133                 "warning - @value tag cannot be used here."
 134         );
 135         checkForException();
 136     }
 137 
 138     void checkForException() {
 139         checkOutput(Output.STDERR, false, "DocletAbortException");
 140     }
 141 }