1 /*
   2  * Copyright (c) 2018, 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 8213957 8213958
  27  * @summary Test use of at-index in package-iinfo and doc-files
  28  * @library /tools/lib ../../lib
  29  * @modules jdk.javadoc/jdk.javadoc.internal.tool
  30  * @build toolbox.ToolBox javadoc.tester.*
  31  * @run main TestIndexInPackageFiles
  32  */
  33 
  34 import java.io.IOException;
  35 import java.nio.file.Path;
  36 
  37 import javadoc.tester.JavadocTester;
  38 import toolbox.ToolBox;
  39 
  40 public class TestIndexInPackageFiles extends JavadocTester {
  41 
  42     public static void main(String... args) throws Exception {
  43         TestIndexInPackageFiles  tester = new TestIndexInPackageFiles ();
  44         tester.runTests();
  45     }
  46 
  47     ToolBox tb = new ToolBox();
  48 
  49     @Test
  50     public void test() throws IOException {
  51         Path src = Path.of("src");
  52         tb.writeJavaFiles(src,
  53               "/**\n"
  54             + " * Summary.\n"
  55             + " * {@index test.name.1 additional info}\n"
  56             + " * {@systemProperty test.property.1}\n"
  57             + " */\n"
  58             + "package p.q;",
  59               "package p.q;\n"
  60             + "/** This is a class in p.q. */\n"
  61             + "public class C { }\n");
  62 
  63         tb.writeFile(src.resolve("p/q/doc-files/extra.html"),
  64             "<html><head><title>Extra</title></head><body>\n"
  65             + "<h1>Extra</h1>\n"
  66             + "{@index test.name.2 additional info}\n"
  67             + "{@systemProperty test.property.2}\n"
  68             + "</body></html>\n");
  69 
  70         tb.writeFile("overview.html",
  71             "<html><head><title>Overview</title></head><body>\n"
  72             + "<h1>Overview</h1>\n"
  73             + "{@index test.name.3 additional info}\n"
  74             + "</body></html>\n");
  75 
  76 
  77         javadoc("-d", "out",
  78                 "-sourcepath", src.toString(),
  79                 "-overview", "overview.html",
  80                 "p.q");
  81 
  82         checkExit(Exit.OK);
  83 
  84         // Note there is an implicit call to checkLinks, but that only
  85         // checks the links are valid if they are actually present.
  86         // Here, we specifically check for both ends of each link.
  87         // However, we assume the search index files are generated appropriately,
  88         // to match the A-Z index files checked here.
  89 
  90         checkOutput("p/q/package-summary.html", true,
  91             "<span id=\"test.name.1\" class=\"searchTagResult\">test.name.1</span>",
  92             "<span id=\"test.property.1\" class=\"searchTagResult\">test.property.1</span>");
  93 
  94         checkOutput("p/q/doc-files/extra.html", true,
  95             "<span id=\"test.name.2\" class=\"searchTagResult\">test.name.2</span>",
  96             "<span id=\"test.property.2\" class=\"searchTagResult\">test.property.2</span>");
  97 
  98         checkOutput("index.html", true,
  99             "<span id=\"test.name.3\" class=\"searchTagResult\">test.name.3</span>");
 100 
 101         checkOutput("index-all.html", true,
 102             "<span class=\"searchTagLink\"><a href=\"p/q/package-summary.html#test.name.1\">test.name.1</a></span>",
 103             "<span class=\"searchTagLink\"><a href=\"p/q/doc-files/extra.html#test.name.2\">test.name.2</a></span>",
 104             "<span class=\"searchTagLink\"><a href=\"index.html#test.name.3\">test.name.3</a></span> - Search tag in Overview</dt>",
 105             "<span class=\"searchTagLink\"><a href=\"p/q/package-summary.html#test.property.1\">test.property.1</a></span>",
 106             "<span class=\"searchTagLink\"><a href=\"p/q/doc-files/extra.html#test.property.2\">test.property.2</a></span>");
 107     }
 108 }
 109