langtools/test/com/sun/javadoc/testLinkOption/TestLinkOption.java
author jjg
Tue, 22 Apr 2014 17:41:11 -0700
changeset 24071 b0845717434e
parent 24065 fc4022e50129
child 24072 e7549dcbc4af
permissions -rw-r--r--
8041253: Avoid redundant synonyms of NO_TEST Reviewed-by: ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
23971
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 21478
diff changeset
     2
 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2216
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2216
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2216
diff changeset
    21
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
 * @test
23974
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
    26
 * @bug 4720957 5020118 8026567 8038976
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
 * @summary Test to make sure that -link and -linkoffline link to
23974
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
    28
 * right files, and URLs with and without trailing slash are accepted.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
 * @author jamieh
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
 * @library ../lib/
9083
63f3c4d2d992 7010344: Some of the html files do not have element <a> in right context.
bpatel
parents: 7681
diff changeset
    31
 * @build JavadocTester TestLinkOption
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
 * @run main TestLinkOption
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
23974
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
    35
import java.io.File;
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
    36
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
public class TestLinkOption extends JavadocTester {
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
23974
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
    39
    private static final String BUG_ID = "4720957-5020118-8038976";
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
    //Generate the documentation using -linkoffline and a URL as the first parameter.
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
    private static final String[] ARGS1 = new String[] {
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
        "-d", BUG_ID + "-1", "-sourcepath", SRC_DIR,
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
        "-linkoffline", "http://java.sun.com/j2se/1.4/docs/api/",
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
        SRC_DIR, "-package", "pkg", "java.lang"
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
    };
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    private static final String[][] TEST1 = {
23971
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 21478
diff changeset
    49
        {BUG_ID + "-1/pkg/C.html",
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    50
            "<a href=\"http://java.sun.com/j2se/1.4/docs/api/java/lang/String.html?is-external=true\" " +
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    51
            "title=\"class or interface in java.lang\"><code>Link to String Class</code></a>"
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
        },
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
        //Make sure the parameters are indented properly when the -link option is used.
23971
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 21478
diff changeset
    54
        {BUG_ID + "-1/pkg/C.html",
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 21478
diff changeset
    55
            "(int&nbsp;p1,\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 21478
diff changeset
    56
            "      int&nbsp;p2,\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 21478
diff changeset
    57
            "      int&nbsp;p3)"
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
        },
23971
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 21478
diff changeset
    59
        {BUG_ID + "-1/pkg/C.html",
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 21478
diff changeset
    60
            "(int&nbsp;p1,\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 21478
diff changeset
    61
            "      int&nbsp;p2,\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 21478
diff changeset
    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\">" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 21478
diff changeset
    63
            "Object</a>&nbsp;p3)"
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
        },
23971
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 21478
diff changeset
    65
        {BUG_ID + "-1/java/lang/StringBuilderChild.html",
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 21478
diff changeset
    66
            "<pre>public abstract class <span class=\"typeNameLabel\">StringBuilderChild</span>\n" +
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    67
                "extends <a href=\"http://java.sun.com/j2se/1.4/docs/api/java/lang/Object.html?is-external=true\" " +
23971
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 21478
diff changeset
    68
            "title=\"class or interface in java.lang\">Object</a></pre>"
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
        },
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    };
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
    private static final String[][] NEGATED_TEST1 = NO_TEST;
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    //Generate the documentation using -linkoffline and a relative path as the first parameter.
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    //We will try linking to the docs generated in test 1 with a relative path.
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    private static final String[] ARGS2 = new String[] {
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        "-d", BUG_ID + "-2", "-sourcepath", SRC_DIR,
23971
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 21478
diff changeset
    78
        "-linkoffline", "../" + BUG_ID + "-1",
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 21478
diff changeset
    79
        BUG_ID + "-1", "-package", "pkg2"
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    };
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    private static final String[][] TEST2 = {
23971
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 21478
diff changeset
    83
        {BUG_ID + "-2/pkg2/C2.html",
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 21478
diff changeset
    84
            "This is a link to <a href=\"../../" + BUG_ID +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 21478
diff changeset
    85
            "-1/pkg/C.html?is-external=true\" " +
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    86
            "title=\"class or interface in pkg\"><code>Class C</code></a>."
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    };
23974
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
    89
    /*
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
    90
     * Create the documentation using the -link option, vary the behavior with
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
    91
     * both trailing and no trailing slash. We are only interested in ensuring
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
    92
     * that the command executes with no errors or related warnings.
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
    93
     */
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
    94
    static String[] createArguments(boolean withTrailingSlash) {
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
    95
        String packagePath = new File(BUG_ID + "-1").getAbsolutePath();
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
    96
        String outputDirName = BUG_ID;
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
    97
        if (withTrailingSlash) {
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
    98
            // add the trailing slash, if it is not present!
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
    99
            if (!packagePath.endsWith(FS)) {
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   100
                packagePath = packagePath + FS;
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   101
            }
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   102
            outputDirName = outputDirName + "-3";
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   103
        } else {
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   104
            // remove the trailing slash, if it is present!
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   105
            if (packagePath.endsWith(FS)) {
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   106
                packagePath = packagePath.substring(0, packagePath.length() - 1);
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   107
            }
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   108
            outputDirName = outputDirName + "-4";
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   109
        }
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   110
        String args[] = {
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   111
            "-d", outputDirName, "-sourcepath", SRC_DIR,
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   112
            "-link", "file:///" + packagePath, "-package", "pkg2"
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   113
        };
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   114
        System.out.println("packagePath: " + packagePath);
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   115
        return args;
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   116
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
     * The entry point of the test.
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
     * @param args the array of command line arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    public static void main(String[] args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        TestLinkOption tester = new TestLinkOption();
24065
fc4022e50129 8041150: Avoid silly use of static methods in JavadocTester
jjg
parents: 23974
diff changeset
   123
        tester.run(ARGS1, TEST1, NEGATED_TEST1);
24071
b0845717434e 8041253: Avoid redundant synonyms of NO_TEST
jjg
parents: 24065
diff changeset
   124
        tester.run(ARGS1, TEST1, NEGATED_TEST1);
b0845717434e 8041253: Avoid redundant synonyms of NO_TEST
jjg
parents: 24065
diff changeset
   125
        tester.run(ARGS2, TEST2, NO_TEST);
23974
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   126
        tester.runJavadoc(createArguments(true));  // with trailing slash
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   127
        tester.runJavadoc(createArguments(false)); // without trailing slash
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   128
        tester.printSummary();
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   129
        if (tester.getWarningOutput().contains("warning - Error fetching URL")) {
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   130
            throw new Error("URL rejected ?");
d53628eda3d1 8038976: javadoc requires a trailing / for links where java 7's javadoc didn't
ksrini
parents: 23971
diff changeset
   131
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        tester.printSummary();
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    public String getBugId() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
        return BUG_ID;
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    public String getBugName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        return getClass().getName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
}