test/com/sun/javadoc/testLinkOption/TestLinkOption.java

Wed, 08 Oct 2014 14:16:40 -0700

author
asaha
date
Wed, 08 Oct 2014 14:16:40 -0700
changeset 2586
f5e5ca7505e2
parent 2366
5b8151ede720
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Merge

     1 /*
     2  * Copyright (c) 2002, 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 4720957 5020118 8026567 8038976
    27  * @summary Test to make sure that -link and -linkoffline link to
    28  * right files, and URLs with and without trailing slash are accepted.
    29  * @author jamieh
    30  * @library ../lib/
    31  * @build JavadocTester TestLinkOption
    32  * @run main TestLinkOption
    33  */
    35 import java.io.File;
    37 public class TestLinkOption extends JavadocTester {
    39     private static final String BUG_ID = "4720957-5020118-8038976";
    41     //Generate the documentation using -linkoffline and a URL as the first parameter.
    42     private static final String[] ARGS1 = new String[] {
    43         "-d", BUG_ID + "-1", "-sourcepath", SRC_DIR,
    44         "-linkoffline", "http://java.sun.com/j2se/1.4/docs/api/",
    45         SRC_DIR, "-package", "pkg", "java.lang"
    46     };
    48     private static final String[][] TEST1 = {
    49         {BUG_ID + "-1" + FS + "pkg" + FS + "C.html",
    50             "<a href=\"http://java.sun.com/j2se/1.4/docs/api/java/lang/String.html?is-external=true\" " +
    51             "title=\"class or interface in java.lang\"><code>Link to String Class</code></a>"
    52         },
    53         //Make sure the parameters are indented properly when the -link option is used.
    54         {BUG_ID + "-1" + FS + "pkg" + FS + "C.html",
    55                                 "(int&nbsp;p1," + NL +
    56                                 "      int&nbsp;p2," + NL +
    57                                 "      int&nbsp;p3)"
    58         },
    59         {BUG_ID + "-1" + FS + "pkg" + FS + "C.html",
    60                                 "(int&nbsp;p1," + NL +
    61                                 "      int&nbsp;p2," + NL +
    62                                 "      <a href=\"http://java.sun.com/j2se/1.4/docs/api/java/lang/Object.html?is-external=true\" title=\"class or interface in java.lang\">" +
    63                                 "Object</a>&nbsp;p3)"
    64         },
    65         {BUG_ID + "-1" + FS + "java" + FS + "lang" + FS + "StringBuilderChild.html",
    66                 "<pre>public abstract class <span class=\"typeNameLabel\">StringBuilderChild</span>" + NL +
    67                 "extends <a href=\"http://java.sun.com/j2se/1.4/docs/api/java/lang/Object.html?is-external=true\" " +
    68                 "title=\"class or interface in java.lang\">Object</a></pre>"
    69         },
    71     };
    72     private static final String[][] NEGATED_TEST1 = NO_TEST;
    74     //Generate the documentation using -linkoffline and a relative path as the first parameter.
    75     //We will try linking to the docs generated in test 1 with a relative path.
    76     private static final String[] ARGS2 = new String[] {
    77         "-d", BUG_ID + "-2", "-sourcepath", SRC_DIR,
    78         "-linkoffline", "../" + BUG_ID + "-1", BUG_ID + "-1", "-package", "pkg2"
    79     };
    81     private static final String[][] TEST2 = {
    82         {BUG_ID + "-2" + FS + "pkg2" + FS + "C2.html",
    83             "This is a link to <a href=\"../../" + BUG_ID + "-1/pkg/C.html?is-external=true\" " +
    84             "title=\"class or interface in pkg\"><code>Class C</code></a>."
    85         }
    86     };
    87     private static final String[][] NEGATED_TEST2 = NO_TEST;
    88     /*
    89      * Create the documentation using the -link option, vary the behavior with
    90      * both trailing and no trailing slash. We are only interested in ensuring
    91      * that the command executes with no errors or related warnings.
    92      */
    93     static String[] createArguments(boolean withTrailingSlash) {
    94         String packagePath = new File(BUG_ID + "-1").getAbsolutePath();
    95         String outputDirName = BUG_ID;
    96         if (withTrailingSlash) {
    97             // add the trailing slash, if it is not present!
    98             if (!packagePath.endsWith(FS)) {
    99                 packagePath = packagePath + FS;
   100             }
   101             outputDirName = outputDirName + "-3";
   102         } else {
   103             // remove the trailing slash, if it is present!
   104             if (packagePath.endsWith(FS)) {
   105                 packagePath = packagePath.substring(0, packagePath.length() - 1);
   106             }
   107             outputDirName = outputDirName + "-4";
   108         }
   109         String args[] = {
   110             "-d", outputDirName, "-sourcepath", SRC_DIR,
   111             "-link", "file:///" + packagePath, "-package", "pkg2"
   112         };
   113         System.out.println("packagePath: " + packagePath);
   114         return args;
   115     }
   116     /**
   117      * The entry point of the test.
   118      * @param args the array of command line arguments.
   119      */
   120     public static void main(String[] args) {
   121         TestLinkOption tester = new TestLinkOption();
   122         run(tester, ARGS1, TEST1, NEGATED_TEST1);
   123         run(tester, ARGS2, TEST2, NEGATED_TEST2);
   124         tester.runJavadoc(createArguments(true));  // with trailing slash
   125         tester.runJavadoc(createArguments(false)); // without trailing slash
   126         tester.printSummary();
   127         if (tester.getWarningOutput().contains("warning - Error fetching URL")) {
   128             throw new Error("URL rejected ?");
   129         }
   130         tester.printSummary();
   131     }
   133     /**
   134      * {@inheritDoc}
   135      */
   136     public String getBugId() {
   137         return BUG_ID;
   138     }
   140     /**
   141      * {@inheritDoc}
   142      */
   143     public String getBugName() {
   144         return getClass().getName();
   145     }
   146 }

mercurial