test/com/sun/javadoc/testValueTag/TestValueTag.java

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

     1 /*
     2  * Copyright (c) 2003, 2013, 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  */
    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  * @build    JavadocTester TestValueTag
    32  * @run main TestValueTag
    33  */
    35 public class TestValueTag extends JavadocTester {
    37     //Test information.
    38     private static final String BUG_ID = "4764045";
    40     //Javadoc arguments.
    41     private static final String[] ARGS =
    42         new String[] {
    43             "-d", BUG_ID, "-sourcepath", SRC_DIR, "-tag",
    44             "todo", "pkg1", "pkg2"
    45         };
    47     private static final String[] ARGS1 =
    48         new String[] {
    49             "-Xdoclint:none",
    50             "-d", BUG_ID + "-1", "-sourcepath", SRC_DIR, "-tag",
    51             "todo", "pkg1", "pkg2"
    52         };
    54     //Input for string search tests.
    55     private static final String[][] TEST = {
    56         //Base case:  using @value on a constant.
    57         {BUG_ID + FS + "pkg1" + FS + "Class1.html",
    58             "Result:  \"Test 1 passes\""},
    59         //Retrieve value of constant in same class.
    60         {BUG_ID + FS + "pkg1" + FS + "Class1.html",
    61             "Result:  <a href=\"../pkg1/Class1.html#TEST_2_PASSES\">\"Test 2 passes\"</a>"},
    62         {BUG_ID + FS + "pkg1" + FS + "Class1.html",
    63             "Result:  <a href=\"../pkg1/Class1.html#TEST_3_PASSES\">\"Test 3 passes\"</a>"},
    64         {BUG_ID + FS + "pkg1" + FS + "Class1.html",
    65             "Result:  <a href=\"../pkg1/Class1.html#TEST_4_PASSES\">\"Test 4 passes\"</a>"},
    66         {BUG_ID + FS + "pkg1" + FS + "Class1.html",
    67             "Result:  <a href=\"../pkg1/Class1.html#TEST_5_PASSES\">\"Test 5 passes\"</a>"},
    68         {BUG_ID + FS + "pkg1" + FS + "Class1.html",
    69             "Result:  <a href=\"../pkg1/Class1.html#TEST_6_PASSES\">\"Test 6 passes\"</a>"},
    70         //Retrieve value of constant in different class.
    71         {BUG_ID + FS + "pkg1" + FS + "Class2.html",
    72             "Result:  <a href=\"../pkg1/Class1.html#TEST_7_PASSES\">\"Test 7 passes\"</a>"},
    73         {BUG_ID + FS + "pkg1" + FS + "Class2.html",
    74             "Result:  <a href=\"../pkg1/Class1.html#TEST_8_PASSES\">\"Test 8 passes\"</a>"},
    75         {BUG_ID + FS + "pkg1" + FS + "Class2.html",
    76             "Result:  <a href=\"../pkg1/Class1.html#TEST_9_PASSES\">\"Test 9 passes\"</a>"},
    77         {BUG_ID + FS + "pkg1" + FS + "Class2.html",
    78             "Result:  <a href=\"../pkg1/Class1.html#TEST_10_PASSES\">\"Test 10 passes\"</a>"},
    79         {BUG_ID + FS + "pkg1" + FS + "Class2.html",
    80             "Result:  <a href=\"../pkg1/Class1.html#TEST_11_PASSES\">\"Test 11 passes\"</a>"},
    81         //Retrieve value of constant in different package
    82         {BUG_ID + FS + "pkg1" + FS + "Class2.html",
    83             "Result:  <a href=\"../pkg2/Class3.html#TEST_12_PASSES\">\"Test 12 passes\"</a>"},
    84         {BUG_ID + FS + "pkg1" + FS + "Class2.html",
    85             "Result:  <a href=\"../pkg2/Class3.html#TEST_13_PASSES\">\"Test 13 passes\"</a>"},
    86         {BUG_ID + FS + "pkg1" + FS + "Class2.html",
    87             "Result:  <a href=\"../pkg2/Class3.html#TEST_14_PASSES\">\"Test 14 passes\"</a>"},
    88         {BUG_ID + FS + "pkg1" + FS + "Class2.html",
    89             "Result:  <a href=\"../pkg2/Class3.html#TEST_15_PASSES\">\"Test 15 passes\"</a>"},
    90         {BUG_ID + FS + "pkg1" + FS + "Class2.html",
    91             "Result:  <a href=\"../pkg2/Class3.html#TEST_16_PASSES\">\"Test 16 passes\"</a>"},
    92         //Retrieve value of constant from a package page
    93         {BUG_ID + FS + "pkg2" + FS + "package-summary.html",
    94             "Result: <a href=\"../pkg2/Class3.html#TEST_17_PASSES\">\"Test 17 passes\"</a>"},
    95         //Test @value tag used with custom tag.
    96         {BUG_ID + FS + "pkg1" + FS + "CustomTagUsage.html",
    97             "<dt><span class=\"simpleTagLabel\">Todo:</span></dt>" + NL +
    98                 "<dd>the value of this constant is 55.</dd>"},
    99         //Test @value errors printed dues to invalid use or when used with
   100         //non-constant or with bad references.
   101         {ERROR_OUTPUT,"error: value does not refer to a constant" + NL +
   102             "     * Result:  {@value TEST_12_ERROR}"
   103         },
   104         {ERROR_OUTPUT,"error: {@value} not allowed here" + NL +
   105             "     * Result:  {@value}"
   106         },
   107         {ERROR_OUTPUT,"error: value does not refer to a constant" + NL +
   108             "     * Result:  {@value NULL}"
   109         },
   110         {ERROR_OUTPUT,"error: {@value} not allowed here" + NL +
   111             "     * Invalid (null): {@value}"
   112         },
   113         {ERROR_OUTPUT,"error: {@value} not allowed here" + NL +
   114             "     * Invalid (non-constant field): {@value}"
   115         },
   116         {ERROR_OUTPUT,"error: value does not refer to a constant" + NL +
   117             "     * Here is a bad value reference: {@value UnknownClass#unknownConstant}"
   118         },
   119         {ERROR_OUTPUT,"error: reference not found" + NL +
   120             "     * Here is a bad value reference: {@value UnknownClass#unknownConstant}"
   121         },
   122         {ERROR_OUTPUT,"error: {@value} not allowed here" + NL +
   123             "     * @todo the value of this constant is {@value}"
   124         }
   125     };
   126     private static final String[][] TEST1 = {
   127         //Test @value warning printed when used with non-constant.
   128         {WARNING_OUTPUT,"warning - @value tag (which references nonConstant) " +
   129             "can only be used in constants."
   130         },
   131         {WARNING_OUTPUT,"warning - @value tag (which references NULL) " +
   132             "can only be used in constants."
   133         },
   134         {WARNING_OUTPUT,"warning - @value tag (which references TEST_12_ERROR) " +
   135             "can only be used in constants."
   136         },
   137         //Test warning printed for bad reference.
   138         {WARNING_OUTPUT,"warning - UnknownClass#unknownConstant (referenced by " +
   139             "@value tag) is an unknown reference."
   140         },
   141         //Test warning printed for invalid use of @value.
   142         {WARNING_OUTPUT,"warning - @value tag cannot be used here."
   143         }
   144     };
   145     private static final String[][] NEGATED_TEST = {
   146         //Base case:  using @value on a constant.
   147         {BUG_ID + FS + "pkg1" + FS + "Class1.html",
   148             "Result:  <a href=\"../pkg1/Class1.html#TEST_12_ERROR\">\"Test 12 " +
   149             "generates an error message\"</a>"},
   150     };
   152     /**
   153      * The entry point of the test.
   154      * @param args the array of command line arguments.
   155      */
   156     public static void main(String[] args) {
   157         TestValueTag tester = new TestValueTag();
   158         run(tester, ARGS, TEST, NEGATED_TEST);
   159         checkForException(tester);
   160         run(tester, ARGS1, TEST1, NO_TEST);
   161         checkForException(tester);
   162         tester.printSummary();
   163     }
   165     public static void checkForException(TestValueTag tester) {
   166         if (tester.getErrorOutput().contains("DocletAbortException")) {
   167             throw new AssertionError("javadoc threw DocletAbortException");
   168         }
   169     }
   171     /**
   172      * {@inheritDoc}
   173      */
   174     public String getBugId() {
   175         return BUG_ID;
   176     }
   178     /**
   179      * {@inheritDoc}
   180      */
   181     public String getBugName() {
   182         return getClass().getName();
   183     }
   184 }

mercurial