TestSearch.java revision 3233:b5d08bc0d224
1/*
2 * Copyright (c) 2015, 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 8141492
27 * @summary Test the search feature of javadoc.
28 * @author bpatel
29 * @library ../lib
30 * @modules jdk.javadoc
31 * @build JavadocTester
32 * @run main TestSearch
33 */
34
35public class TestSearch extends JavadocTester {
36
37    public static void main(String... args) throws Exception {
38        TestSearch tester = new TestSearch();
39        tester.runTests();
40    }
41
42    @Test
43    void test1() {
44        javadoc("-d", "out-1", "-sourcepath", "-use", testSrc("UnnamedPkgClass.java"));
45        checkExit(Exit.OK);
46        checkSearchOutput("UnnamedPkgClass.html", true);
47        checkJqueryAndImageFiles(true);
48        checkFiles(false,
49                "package-search-index.zip",
50                "tag-search-index.zip");
51        checkFiles(true,
52                "member-search-index.zip",
53                "type-search-index.zip");
54    }
55
56    @Test
57    void test2() {
58        javadoc("-d", "out-2", "-Xdoclint:none", "-sourcepath", testSrc,
59                "-use", "pkg", "pkg1", "pkg2", "pkg3");
60        checkExit(Exit.OK);
61        checkInvalidUsageIndexTag();
62        checkSearchOutput(true);
63        checkSingleIndex(true);
64        checkJqueryAndImageFiles(true);
65        checkFiles(true,
66                "member-search-index.zip",
67                "package-search-index.zip",
68                "tag-search-index.zip",
69                "type-search-index.zip");
70    }
71
72    @Test
73    void test2a() {
74        javadoc("-d", "out-2a", "-Xdoclint:all", "-sourcepath", testSrc,
75                "-use", "pkg", "pkg1", "pkg2", "pkg3");
76        checkExit(Exit.FAILED);
77        checkDocLintErrors();
78        checkSearchOutput(true);
79        checkSingleIndex(true);
80        checkJqueryAndImageFiles(true);
81        checkFiles(true,
82                "member-search-index.zip",
83                "package-search-index.zip",
84                "tag-search-index.zip",
85                "type-search-index.zip");
86    }
87
88    @Test
89    void test3() {
90        javadoc("-d", "out-3", "-noindex", "-Xdoclint:none",
91                "-sourcepath", testSrc,
92                "-use", "pkg", "pkg1", "pkg2", "pkg3");
93        checkExit(Exit.OK);
94        checkSearchOutput(false);
95        checkJqueryAndImageFiles(false);
96        checkFiles(false,
97                "member-search-index.zip",
98                "package-search-index.zip",
99                "tag-search-index.zip",
100                "type-search-index.zip",
101                "index-all.html");
102    }
103
104    @Test
105    void test4() {
106        javadoc("-d", "out-4", "-html5", "-Xdoclint:none",
107                "-sourcepath", testSrc,
108                "-use", "pkg", "pkg1", "pkg2", "pkg3");
109        checkExit(Exit.OK);
110        checkSearchOutput(true);
111        checkSingleIndex(true);
112        checkJqueryAndImageFiles(true);
113        checkFiles(true,
114                "member-search-index.zip",
115                "package-search-index.zip",
116                "tag-search-index.zip",
117                "type-search-index.zip");
118    }
119
120    @Test
121    void test5() {
122        javadoc("-d", "out-5", "-noindex", "-html5", "-Xdoclint:none",
123                "-sourcepath", testSrc,
124                "-use", "pkg", "pkg1", "pkg2", "pkg3");
125        checkExit(Exit.OK);
126        checkSearchOutput(false);
127        checkJqueryAndImageFiles(false);
128        checkFiles(false,
129                "member-search-index.zip",
130                "package-search-index.zip",
131                "tag-search-index.zip",
132                "type-search-index.zip",
133                "index-all.html");
134    }
135
136    @Test
137    void test6() {
138        javadoc("-d", "out-6", "-nocomment", "-Xdoclint:none",
139                "-sourcepath", testSrc,
140                "-use", "pkg", "pkg1", "pkg2", "pkg3");
141        checkExit(Exit.OK);
142        checkSearchOutput(true);
143        checkIndexNoComment();
144        checkJqueryAndImageFiles(true);
145        checkFiles(true,
146                "member-search-index.zip",
147                "package-search-index.zip",
148                "tag-search-index.zip",
149                "type-search-index.zip");
150    }
151
152    @Test
153    void test7() {
154        javadoc("-d", "out-7", "-nodeprecated", "-Xdoclint:none",
155                "-sourcepath", testSrc,
156                "-use", "pkg", "pkg1", "pkg2", "pkg3");
157        checkExit(Exit.OK);
158        checkSearchOutput(true);
159        checkIndexNoDeprecated();
160        checkJqueryAndImageFiles(true);
161        checkFiles(true,
162                "member-search-index.zip",
163                "package-search-index.zip",
164                "tag-search-index.zip",
165                "type-search-index.zip");
166    }
167
168    @Test
169    void test8() {
170        javadoc("-d", "out-8", "-splitindex", "-Xdoclint:none", "-sourcepath", testSrc,
171                "-use", "pkg", "pkg1", "pkg2", "pkg3");
172        checkExit(Exit.OK);
173        checkInvalidUsageIndexTag();
174        checkSearchOutput(true);
175        checkSplitIndex();
176        checkJqueryAndImageFiles(true);
177        checkFiles(true,
178                "member-search-index.zip",
179                "package-search-index.zip",
180                "tag-search-index.zip",
181                "type-search-index.zip");
182    }
183
184    @Test
185    void test9() {
186        javadoc("-d", "out-9", "-sourcepath", testSrc, "-javafx", "-package",
187                "-use", "pkgfx", "pkg3");
188        checkExit(Exit.OK);
189        checkSearchOutput(true);
190        checkJavaFXOutput();
191        checkJqueryAndImageFiles(true);
192        checkFiles(false,
193                "tag-search-index.zip");
194        checkFiles(true,
195                "member-search-index.zip",
196                "package-search-index.zip",
197                "type-search-index.zip");
198    }
199
200    void checkDocLintErrors() {
201        checkOutput(Output.OUT, true,
202                "A sample method. Testing search tag for {@index \"unclosed quote}.",
203                "Another test class. Testing empty {@index }.",
204                "Constant field. Testing no text in index tag {@index}.",
205                "A test field. Testing only white-spaces in index tag text {@index       }.");
206    }
207
208    void checkSearchOutput(boolean expectedOutput) {
209        checkSearchOutput("overview-summary.html", expectedOutput);
210    }
211
212    void checkSearchOutput(String fileName, boolean expectedOutput) {
213        // Test for search related markup
214        checkOutput(fileName, expectedOutput,
215                "<link rel=\"stylesheet\" type=\"text/css\" href=\"jquery/jquery-ui.css\" title=\"Style\">\n",
216                "<script type=\"text/javascript\" src=\"jquery/jszip/dist/jszip.min.js\"></script>\n",
217                "<script type=\"text/javascript\" src=\"jquery/jszip-utils/dist/jszip-utils.min.js\"></script>\n",
218                "<!--[if IE]>\n",
219                "<script type=\"text/javascript\" src=\"jquery/jszip-utils/dist/jszip-utils-ie.min.js\"></script>\n",
220                "<![endif]-->\n",
221                "<script type=\"text/javascript\" src=\"jquery/jquery-1.10.2.js\"></script>\n",
222                "<script type=\"text/javascript\" src=\"jquery/jquery-ui.js\"></script>",
223                "var pathtoroot = \"./\";loadScripts(document, 'script');",
224                "<ul class=\"navListSearch\">\n",
225                "<li><span>SEARCH:&nbsp;</span>\n",
226                "<input type=\"text\" id=\"search\" value=\" \" disabled=\"disabled\">\n",
227                "<input type=\"reset\" id=\"reset\" value=\" \" disabled=\"disabled\">\n");
228        checkOutput(fileName, true,
229                "<div class=\"fixedNav\">");
230    }
231
232    void checkSingleIndex(boolean expectedOutput) {
233        // Test for search tags markup in index file.
234        checkOutput("index-all.html", expectedOutput,
235                "<dt><span class=\"searchTagLink\"><a href=\"pkg/package-summary.html#phrasewithspaces\">"
236                        + "phrase with spaces</a></span> - Search tag in pkg</dt>",
237                "<dt><span class=\"searchTagLink\"><a href=\"pkg1/RegClass.html#searchphrase\">"
238                        + "search phrase</a></span> - Search tag in pkg1.RegClass</dt>",
239                "<dt><span class=\"searchTagLink\"><a href=\"pkg1/RegClass.html#SearchWordWithDescription\">"
240                        + "SearchWordWithDescription</a></span> - Search tag in pkg1.RegClass.CONSTANT_FIELD_1</dt>",
241                "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestAnnotationType.html#searchphrasewithdescdeprecated\">"
242                        + "search phrase with desc deprecated</a></span> - Search tag in pkg2.TestAnnotationType</dt>",
243                "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestClass.html#SearchTagDeprecatedClass\">"
244                        + "SearchTagDeprecatedClass</a></span> - Search tag in pkg2.TestClass</dt>",
245                "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestEnum.html#searchphrasedeprecated\">"
246                        + "search phrase deprecated</a></span> - Search tag in pkg2.TestEnum.ONE</dt>",
247                "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestEnum.html#searchphrasedeprecated\">"
248                        + "search phrase deprecated</a></span> - Search tag in pkg2.TestEnum.ONE</dt>",
249                "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestError.html#SearchTagDeprecatedMethod\">"
250                        + "SearchTagDeprecatedMethod</a></span> - Search tag in pkg2.TestError</dt>",
251                "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestError.html#SearchTagDeprecatedMethod\">"
252                        + "SearchTagDeprecatedMethod</a></span> - Search tag in pkg2.TestError</dt>",
253                "<dt><span class=\"searchTagLink\"><a href=\"pkg/package-summary.html#SingleWord\">"
254                        + "SingleWord</a></span> - Search tag in pkg</dt>",
255                "<dt><span class=\"searchTagLink\"><a href=\"pkg/AnotherClass.ModalExclusionType.html"
256                        + "#nested%7B@indexnested_tag_test%7D\">nested {@index nested_tag_test}</a></span> - "
257                        + "Search tag in pkg.AnotherClass.ModalExclusionType.NO_EXCLUDE</dt>",
258                "<dt><span class=\"searchTagLink\"><a href=\"pkg/AnotherClass.ModalExclusionType.html"
259                        + "#html-span-see-/span-\">html &lt;span&gt; see &lt;/span&gt;</a></span> - Search "
260                        + "tag in pkg.AnotherClass.ModalExclusionType.APPLICATION_EXCLUDE</dt>",
261                "<dt><span class=\"searchTagLink\"><a href=\"pkg/AnotherClass.html#quoted\">quoted</a>"
262                        + "</span> - Search tag in pkg.AnotherClass.CONSTANT1</dt>");
263        checkOutput("index-all.html", true,
264                "<div class=\"block\"><span class=\"deprecationComment\">class_test1 passes. Search tag"
265                        + " <a id=\"SearchTagDeprecatedClass\">SearchTagDeprecatedClass</a></span></div>",
266                "<div class=\"block\"><span class=\"deprecationComment\">error_test3 passes. Search tag for\n"
267                        + " method <a id=\"SearchTagDeprecatedMethod\">SearchTagDeprecatedMethod</a></span></div>");
268    }
269
270    void checkSplitIndex() {
271        // Test for search tags markup in split index file.
272        checkOutput("index-files/index-12.html", true,
273                "<dt><span class=\"searchTagLink\"><a href=\"../pkg1/RegClass.html#searchphrase\">"
274                        + "search phrase</a></span> - Search tag in pkg1.RegClass</dt>",
275                "<dt><span class=\"searchTagLink\"><a href=\"../pkg1/RegClass.html#SearchWordWithDescription\">"
276                        + "SearchWordWithDescription</a></span> - Search tag in pkg1.RegClass.CONSTANT_FIELD_1</dt>",
277                "<dt><span class=\"searchTagLink\"><a href=\"../pkg2/TestAnnotationType.html#searchphrasewithdescdeprecated\">"
278                        + "search phrase with desc deprecated</a></span> - Search tag in pkg2.TestAnnotationType</dt>",
279                "<dt><span class=\"searchTagLink\"><a href=\"../pkg2/TestClass.html#SearchTagDeprecatedClass\">"
280                        + "SearchTagDeprecatedClass</a></span> - Search tag in pkg2.TestClass</dt>",
281                "<dt><span class=\"searchTagLink\"><a href=\"../pkg2/TestEnum.html#searchphrasedeprecated\">"
282                        + "search phrase deprecated</a></span> - Search tag in pkg2.TestEnum.ONE</dt>",
283                "<dt><span class=\"searchTagLink\"><a href=\"../pkg2/TestEnum.html#searchphrasedeprecated\">"
284                        + "search phrase deprecated</a></span> - Search tag in pkg2.TestEnum.ONE</dt>",
285                "<dt><span class=\"searchTagLink\"><a href=\"../pkg2/TestError.html#SearchTagDeprecatedMethod\">"
286                        + "SearchTagDeprecatedMethod</a></span> - Search tag in pkg2.TestError</dt>",
287                "<dt><span class=\"searchTagLink\"><a href=\"../pkg2/TestError.html#SearchTagDeprecatedMethod\">"
288                        + "SearchTagDeprecatedMethod</a></span> - Search tag in pkg2.TestError</dt>",
289                "<dt><span class=\"searchTagLink\"><a href=\"../pkg/package-summary.html#SingleWord\">"
290                        + "SingleWord</a></span> - Search tag in pkg</dt>");
291        checkOutput("index-files/index-9.html", true,
292                "<dt><span class=\"searchTagLink\"><a href=\"../pkg/package-summary.html#phrasewithspaces\">"
293                        + "phrase with spaces</a></span> - Search tag in pkg</dt>");
294        checkOutput("index-files/index-8.html", true,
295                "<dt><span class=\"searchTagLink\"><a href=\"../pkg/AnotherClass.ModalExclusionType.html"
296                        + "#nested%7B@indexnested_tag_test%7D\">nested {@index nested_tag_test}</a></span> - "
297                        + "Search tag in pkg.AnotherClass.ModalExclusionType.NO_EXCLUDE</dt>");
298        checkOutput("index-files/index-5.html", true,
299                "<dt><span class=\"searchTagLink\"><a href=\"../pkg/AnotherClass.ModalExclusionType.html"
300                        + "#html-span-see-/span-\">html &lt;span&gt; see &lt;/span&gt;</a></span> - Search "
301                        + "tag in pkg.AnotherClass.ModalExclusionType.APPLICATION_EXCLUDE</dt>");
302        checkOutput("index-files/index-10.html", true,
303                "<dt><span class=\"searchTagLink\"><a href=\"../pkg/AnotherClass.html#quoted\">quoted</a>"
304                        + "</span> - Search tag in pkg.AnotherClass.CONSTANT1</dt>");
305    }
306
307    void checkIndexNoComment() {
308        // Test for search tags markup in index file when javadoc is executed with -nocomment.
309        checkOutput("index-all.html", false,
310                "<dt><span class=\"searchTagLink\"><a href=\"pkg/package-summary.html#phrasewithspaces\">"
311                        + "phrase with spaces</a></span> - Search tag in pkg</dt>",
312                "<dt><span class=\"searchTagLink\"><a href=\"pkg1/RegClass.html#searchphrase\">"
313                        + "search phrase</a></span> - Search tag in pkg1.RegClass</dt>",
314                "<dt><span class=\"searchTagLink\"><a href=\"pkg1/RegClass.html#SearchWordWithDescription\">"
315                        + "SearchWordWithDescription</a></span> - Search tag in pkg1.RegClass.CONSTANT_FIELD_1</dt>",
316                "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestAnnotationType.html#searchphrasewithdescdeprecated\">"
317                        + "search phrase with desc deprecated</a></span> - Search tag in pkg2.TestAnnotationType</dt>",
318                "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestClass.html#SearchTagDeprecatedClass\">"
319                        + "SearchTagDeprecatedClass</a></span> - Search tag in pkg2.TestClass</dt>",
320                "<dt><span class=\"searchTagLink\"><a href=\"pkg/package-summary.html#SingleWord\">"
321                        + "SingleWord</a></span> - Search tag in pkg</dt>",
322                "<div class=\"block\"><span class=\"deprecationComment\">class_test1 passes. Search tag"
323                        + " <a id=\"SearchTagDeprecatedClass\">SearchTagDeprecatedClass</a></span></div>",
324                "<div class=\"block\"><span class=\"deprecationComment\">error_test3 passes. Search tag for\n"
325                        + " method <a id=\"SearchTagDeprecatedMethod\">SearchTagDeprecatedMethod</a></span></div>");
326        checkOutput("index-all.html", true,
327                "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestEnum.html#searchphrasedeprecated\">"
328                        + "search phrase deprecated</a></span> - Search tag in pkg2.TestEnum.ONE</dt>",
329                "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestError.html#SearchTagDeprecatedMethod\">"
330                        + "SearchTagDeprecatedMethod</a></span> - Search tag in pkg2.TestError</dt>");
331    }
332
333    void checkIndexNoDeprecated() {
334        // Test for search tags markup in index file when javadoc is executed using -nodeprecated.
335        checkOutput("index-all.html", true,
336                "<dt><span class=\"searchTagLink\"><a href=\"pkg/package-summary.html#phrasewithspaces\">"
337                        + "phrase with spaces</a></span> - Search tag in pkg</dt>",
338                "<dt><span class=\"searchTagLink\"><a href=\"pkg1/RegClass.html#searchphrase\">"
339                        + "search phrase</a></span> - Search tag in pkg1.RegClass</dt>",
340                "<dt><span class=\"searchTagLink\"><a href=\"pkg1/RegClass.html#SearchWordWithDescription\">"
341                        + "SearchWordWithDescription</a></span> - Search tag in pkg1.RegClass.CONSTANT_FIELD_1</dt>",
342                "<dt><span class=\"searchTagLink\"><a href=\"pkg/package-summary.html#SingleWord\">"
343                        + "SingleWord</a></span> - Search tag in pkg</dt>");
344        checkOutput("index-all.html", false,
345                "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestAnnotationType.html#searchphrasewithdescdeprecated\">"
346                        + "search phrase with desc deprecated</a></span> - Search tag in pkg2.TestAnnotationType</dt>",
347                "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestClass.html#SearchTagDeprecatedClass\">"
348                        + "SearchTagDeprecatedClass</a></span> - Search tag in pkg2.TestClass</dt>",
349                "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestEnum.html#searchphrasedeprecated\">"
350                        + "search phrase deprecated</a></span> - Search tag in pkg2.TestEnum.ONE</dt>",
351                "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestError.html#SearchTagDeprecatedMethod\">"
352                        + "SearchTagDeprecatedMethod</a></span> - Search tag in pkg2.TestError</dt>",
353                "<div class=\"block\"><span class=\"deprecationComment\">class_test1 passes. Search tag"
354                        + " <a id=\"SearchTagDeprecatedClass\">SearchTagDeprecatedClass</a></span></div>",
355                "<div class=\"block\"><span class=\"deprecationComment\">error_test3 passes. Search tag for\n"
356                        + " method <a id=\"SearchTagDeprecatedMethod\">SearchTagDeprecatedMethod</a></span></div>");
357    }
358
359    void checkJavaFXOutput() {
360        checkOutput("index-all.html", false, "test treat as private");
361    }
362
363    void checkInvalidUsageIndexTag() {
364        checkOutput(Output.OUT, true,
365                "AnotherClass.java:29: warning - invalid usage of tag {@index",
366                "AnotherClass.java:41: warning - invalid usage of tag {@index",
367                "AnotherClass.java:36: warning - invalid usage of tag {@index",
368                "AnotherClass.java:70: warning - invalid usage of tag {@index");
369    }
370
371    void checkJqueryAndImageFiles(boolean expectedOutput) {
372        checkFiles(expectedOutput,
373                "search.js",
374                "jquery/jquery-1.10.2.js",
375                "jquery/jquery-ui.js",
376                "jquery/jquery-ui.css",
377                "jquery/jquery-ui.min.js",
378                "jquery/jquery-ui.min.css",
379                "jquery/jquery-ui.structure.min.css",
380                "jquery/jquery-ui.structure.css",
381                "jquery/external/jquery/jquery.js",
382                "jquery/jszip/dist/jszip.js",
383                "jquery/jszip/dist/jszip.min.js",
384                "jquery/jszip-utils/dist/jszip-utils.js",
385                "jquery/jszip-utils/dist/jszip-utils.min.js",
386                "jquery/jszip-utils/dist/jszip-utils-ie.js",
387                "jquery/jszip-utils/dist/jszip-utils-ie.min.js",
388                "jquery/images/ui-bg_flat_0_aaaaaa_40x100.png",
389                "jquery/images/ui-icons_454545_256x240.png",
390                "jquery/images/ui-bg_glass_95_fef1ec_1x400.png",
391                "jquery/images/ui-bg_glass_75_dadada_1x400.png",
392                "jquery/images/ui-bg_highlight-soft_75_cccccc_1x100.png",
393                "jquery/images/ui-icons_888888_256x240.png",
394                "jquery/images/ui-icons_2e83ff_256x240.png",
395                "jquery/images/ui-bg_glass_65_ffffff_1x400.png",
396                "jquery/images/ui-icons_cd0a0a_256x240.png",
397                "jquery/images/ui-bg_glass_55_fbf9ee_1x400.png",
398                "jquery/images/ui-icons_222222_256x240.png",
399                "jquery/images/ui-bg_glass_75_e6e6e6_1x400.png",
400                "jquery/images/ui-bg_flat_75_ffffff_40x100.png",
401                "resources/x.png",
402                "resources/glass.png");
403    }
404}
405