test/jdk/javadoc/doclet/testLinkOption/TestLinkOption.java

Print this page




  56         String url = "http://java.sun.com/j2se/1.4/docs/api/";
  57         javadoc("-d", out1,
  58                 "-sourcepath", testSrc,
  59                 "-linkoffline", url, testSrc,
  60                 "-package",
  61                 "pkg", "java.lang");
  62         checkExit(Exit.OK);
  63 
  64         checkOutput("pkg/C.html", true,
  65                 "<a href=\"" + url + "java/lang/String.html?is-external=true\" "
  66                 + "title=\"class or interface in java.lang\"><code>Link to String Class</code></a>",
  67                 //Make sure the parameters are indented properly when the -link option is used.
  68                 "(int&nbsp;p1,\n"
  69                 + "      int&nbsp;p2,\n"
  70                 + "      int&nbsp;p3)",
  71                 "(int&nbsp;p1,\n"
  72                 + "      int&nbsp;p2,\n"
  73                 + "      <a href=\"" + url + "java/lang/Object.html?is-external=true\" title=\"class or interface in java.lang\">"
  74                 + "Object</a>&nbsp;p3)");
  75 























  76         checkOutput("java/lang/StringBuilderChild.html", true,
  77                 "<pre>public abstract class <span class=\"typeNameLabel\">StringBuilderChild</span>\n"
  78                 + "extends <a href=\"" + url + "java/lang/Object.html?is-external=true\" "
  79                 + "title=\"class or interface in java.lang\">Object</a></pre>"
  80         );
  81 
  82         // Generate the documentation using -linkoffline and a relative path as the first parameter.
  83         // We will try linking to the docs generated in test 1 with a relative path.
  84         String out2 = "out2";
  85         javadoc("-d", out2,
  86                 "-sourcepath", testSrc,
  87                 "-linkoffline", "../" + out1, out1,
  88                 "-package",
  89                 "pkg2");
  90         checkExit(Exit.OK);
  91         checkOutput("pkg2/C2.html", true,
  92             "This is a link to <a href=\"../../" + out1 + "/pkg/C.html?is-external=true\" " +
  93             "title=\"class or interface in pkg\"><code>Class C</code></a>."
  94         );
  95 
  96         String out3 = "out3";
  97         javadoc(createArguments(out3, out1, true));  // with trailing slash
  98         checkExit(Exit.OK);
  99 
 100         String out4 = "out4";
 101         javadoc(createArguments(out4, out1, false)); // without trailing slash
 102         checkExit(Exit.OK);
 103         // Note: the following test is very weak, and will fail if ever the test
 104         // of the message is changed. We should have a separate test to verify
 105         // this is the text that is given when there is a problem with a URL
 106         checkOutput(Output.WARNING, false,
 107                 "warning - Error fetching URL");
 108     }
 109 
 110     /*
 111      * Create the documentation using the -link option, vary the behavior with
 112      * both trailing and no trailing slash. We are only interested in ensuring
 113      * that the command executes with no errors or related warnings.
 114      */
 115     static String[] createArguments(String outDir, String packageDir, boolean withTrailingSlash) {
 116         String packagePath = new File(packageDir).getAbsolutePath();
 117         if (withTrailingSlash) {
 118             // add the trailing slash, if it is not present!
 119             if (!packagePath.endsWith(FS)) {
 120                 packagePath = packagePath + FS;
 121             }
 122         } else {
 123             // remove the trailing slash, if it is present!
 124             if (packagePath.endsWith(FS)) {
 125                 packagePath = packagePath.substring(0, packagePath.length() - 1);
 126             }


  56         String url = "http://java.sun.com/j2se/1.4/docs/api/";
  57         javadoc("-d", out1,
  58                 "-sourcepath", testSrc,
  59                 "-linkoffline", url, testSrc,
  60                 "-package",
  61                 "pkg", "java.lang");
  62         checkExit(Exit.OK);
  63 
  64         checkOutput("pkg/C.html", true,
  65                 "<a href=\"" + url + "java/lang/String.html?is-external=true\" "
  66                 + "title=\"class or interface in java.lang\"><code>Link to String Class</code></a>",
  67                 //Make sure the parameters are indented properly when the -link option is used.
  68                 "(int&nbsp;p1,\n"
  69                 + "      int&nbsp;p2,\n"
  70                 + "      int&nbsp;p3)",
  71                 "(int&nbsp;p1,\n"
  72                 + "      int&nbsp;p2,\n"
  73                 + "      <a href=\"" + url + "java/lang/Object.html?is-external=true\" title=\"class or interface in java.lang\">"
  74                 + "Object</a>&nbsp;p3)");
  75 
  76         checkOutput("pkg/B.html", true,
  77                 "<div class=\"block\">A method with html tag the method "
  78                 + "<a href=\"http://java.sun.com/j2se/1.4/docs/api/java/lang/ClassLoader.html?is-external=true#getSystemClassLoader--\""
  79                 + " title=\"class or interface in java.lang\"><code><tt>getSystemClassLoader()</tt>"
  80                 + "</code></a> as the parent class loader.</div>",
  81                 "<div class=\"block\">is equivalent to invoking <code>"
  82                 + "<a href=\"../pkg/B.html#createTempFile-java.lang.String-java.lang.String-java.io.File-\">"
  83                 + "<code>createTempFile(prefix,&nbsp;suffix,&nbsp;null)</code></a></code>.</div>",
  84                 "<a href=\"" + url + "java/lang/String.html?is-external=true\" "
  85                 + "title=\"class or interface in java.lang\">Link-Plain to String Class</a>",
  86                 "<code><tt>getSystemClassLoader()</tt></code>",
  87                 "<code>createTempFile(prefix,&nbsp;suffix,&nbsp;null)</code>",
  88                 "<dd><a href=\"http://www.ietf.org/rfc/rfc2279.txt\"><i>RFC&nbsp;2279: UTF-8, a\n" +
  89                 " transformation format of ISO 10646</i></a>, <br><a " +
  90                 "href=\"http://www.ietf.org/rfc/rfc2373.txt\"><i>RFC&nbsp;2373: IPv6 Addressing\n" +
  91                 " Architecture</i></a>, <br><a href=\"http://www.ietf.org/rfc/rfc2396.txt\">" +
  92                 "<i>RFC&nbsp;2396: Uniform\n" +
  93                 " Resource Identifiers (URI): Generic Syntax</i></a>, " +
  94                 "<br><a href=\"http://www.ietf.org/rfc/rfc2732.txt\"><i>RFC&nbsp;2732: Format for\n" +
  95                 " Literal IPv6 Addresses in URLs</i></a>, <br><a href=\"URISyntaxException.html\">" +
  96                 "URISyntaxException</a></dd>\n" +
  97                 "</dl>");
  98 
  99         checkOutput("java/lang/StringBuilderChild.html", true,
 100                 "<pre>public abstract class <span class=\"typeNameLabel\">StringBuilderChild</span>\n"
 101                 + "extends <a href=\"" + url + "java/lang/Object.html?is-external=true\" "
 102                 + "title=\"class or interface in java.lang\">Object</a></pre>"
 103         );
 104 
 105         // Generate the documentation using -linkoffline and a relative path as the first parameter.
 106         // We will try linking to the docs generated in test 1 with a relative path.
 107         String out2 = "out2";
 108         javadoc("-d", out2,
 109                 "-sourcepath", testSrc,
 110                 "-linkoffline", "../" + out1, out1,
 111                 "-package",
 112                 "pkg2");
 113         checkExit(Exit.OK);
 114         checkOutput("pkg2/C2.html", true,
 115             "This is a link to <a href=\"../../" + out1 + "/pkg/C.html?is-external=true\" " +
 116             "title=\"class or interface in pkg\"><code>Class C</code></a>."
 117         );
 118 
 119         String out3 = "out3";
 120         javadoc(createArguments(out3, out1, true));  // with trailing slash
 121         checkExit(Exit.OK);
 122 
 123         String out4 = "out4";
 124         javadoc(createArguments(out4, out1, false)); // without trailing slash
 125         checkExit(Exit.OK);
 126         // Note: the following test is very weak, and will fail if ever the test
 127         // of the message is changed. We should have a separate test to verify
 128         // this is the text that is given when there is a problem with a URL
 129         checkOutput(Output.OUT, false,
 130                 "warning - Error fetching URL");
 131     }
 132 
 133     /*
 134      * Create the documentation using the -link option, vary the behavior with
 135      * both trailing and no trailing slash. We are only interested in ensuring
 136      * that the command executes with no errors or related warnings.
 137      */
 138     static String[] createArguments(String outDir, String packageDir, boolean withTrailingSlash) {
 139         String packagePath = new File(packageDir).getAbsolutePath();
 140         if (withTrailingSlash) {
 141             // add the trailing slash, if it is not present!
 142             if (!packagePath.endsWith(FS)) {
 143                 packagePath = packagePath + FS;
 144             }
 145         } else {
 146             // remove the trailing slash, if it is present!
 147             if (packagePath.endsWith(FS)) {
 148                 packagePath = packagePath.substring(0, packagePath.length() - 1);
 149             }