TestUseOption.java revision 2365:6207608205b8
150479Speter/*
2327Sjkh * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
3327Sjkh * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4327Sjkh *
5327Sjkh * This code is free software; you can redistribute it and/or modify it
6327Sjkh * under the terms of the GNU General Public License version 2 only, as
7327Sjkh * published by the Free Software Foundation.
8327Sjkh *
9327Sjkh * This code is distributed in the hope that it will be useful, but WITHOUT
10327Sjkh * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11327Sjkh * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12327Sjkh * version 2 for more details (a copy is included in the LICENSE file that
13327Sjkh * accompanied this code).
14327Sjkh *
15327Sjkh * You should have received a copy of the GNU General Public License version
16327Sjkh * 2 along with this work; if not, write to the Free Software Foundation,
17327Sjkh * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18327Sjkh *
19327Sjkh * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20327Sjkh * or visit www.oracle.com if you need additional information or have any
21327Sjkh * questions.
22327Sjkh */
23327Sjkh
24327Sjkh/*
25327Sjkh * @test
26382Sjkh * @bug 4496290 4985072 7006178 7068595 8016328
27382Sjkh * @summary A simple test to determine if -use works.
28327Sjkh * @author jamieh
29152329Skrion * @library ../lib/
30327Sjkh * @build JavadocTester
31327Sjkh * @build TestUseOption
32156497Sphk * @run main TestUseOption
33154145Sflz */
34327Sjkh
35327Sjkhpublic class TestUseOption extends JavadocTester {
36327Sjkh
37327Sjkh    private static final String BUG_ID = "4496290-4985072-7006178-7068595";
38327Sjkh
39131285Seik    //Input for string search tests.
4011780Sjkh    private static final String[] TEST2 = {
41382Sjkh        "Field in C1.",
42327Sjkh        "Field in C2.",
43327Sjkh        "Field in C4.",
4484745Ssobomax        "Field in C5.",
4584745Ssobomax        "Field in C6.",
46327Sjkh        "Field in C7.",
47327Sjkh        "Field in C8.",
48        "Method in C1.",
49        "Method in C2.",
50        "Method in C4.",
51        "Method in C5.",
52        "Method in C6.",
53        "Method in C7.",
54        "Method in C8.",
55    };
56
57    private static final String[][] TEST3 = {
58        {BUG_ID + "-3/class-use/UsedInC.html", "Uses of <a href=" +
59                 "\"../UsedInC.html\" title=\"class in &lt;Unnamed&gt;\">" +
60                 "UsedInC</a> in <a href=\"../package-summary.html\">&lt;Unnamed&gt;</a>"
61        },
62        {BUG_ID + "-3/package-use.html", "<td class=\"colOne\">" +
63                 "<a href=\"class-use/UsedInC.html#%3CUnnamed%3E\">UsedInC</a>&nbsp;</td>"
64        }
65    };
66
67    private static final String[][] TEST4 = {
68        {BUG_ID + "-4/pkg2/class-use/C3.html", "<a href=" +
69                 "\"../../index.html?pkg2/class-use/C3.html\" target=\"_top\">" +
70                 "Frames</a></li>"
71        }
72    };
73
74    private static final String[] ARGS = new String[] {
75        "-d", BUG_ID, "-sourcepath", SRC_DIR, "-use", "pkg1", "pkg2"
76    };
77
78    private static final String[] ARGS2 = new String[] {
79        "-d", BUG_ID+"-2", "-sourcepath", SRC_DIR, "-use", "pkg1", "pkg2"
80    };
81
82    private static final String[] ARGS3 = new String[] {
83        "-d", BUG_ID + "-3", "-sourcepath", SRC_DIR, "-use", SRC_DIR +
84        "/C.java", SRC_DIR + "/UsedInC.java"
85    };
86
87    private static final String[] ARGS4 = new String[] {
88        "-d", BUG_ID + "-4", "-sourcepath", SRC_DIR, "-use", "pkg1", "pkg2"
89    };
90
91    /**
92     * The entry point of the test.
93     * @param args the array of command line arguments.
94     */
95    public static void main(String[] args) throws Exception {
96        String[][] tests = new String[11][2];
97        //Eight tests for class use.
98        for (int i = 0; i < 8; i++) {
99            tests[i][0] = BUG_ID + "/pkg1/class-use/C1.html";
100            tests[i][1] = "Test " + (i + 1) + " passes";
101        }
102        //Three more tests for package use.
103        for (int i = 8, j = 1; i < tests.length; i++, j++) {
104            tests[i][0] = BUG_ID + "/pkg1/package-use.html";
105            tests[i][1] = "Test " + j + " passes";
106        }
107        TestUseOption tester = new TestUseOption();
108        run(tester, ARGS, tests, NO_TEST);
109        tester.printSummary();
110        run(tester, ARGS2, NO_TEST, NO_TEST);
111        String usePageContents = tester.readFileToString(BUG_ID +
112            "-2/pkg1/class-use/UsedClass.html");
113        int prevIndex = -1;
114        int currentIndex = -1;
115        for (int i = 0; i < TEST2.length; i++) {
116            currentIndex = usePageContents.indexOf(TEST2[i]);
117            System.err.println(TEST2[i] + " at index " + currentIndex);
118            if (currentIndex < prevIndex)
119                throw new Exception(TEST2[i] + " is in the wrong order.");
120            prevIndex = currentIndex;
121        }
122        tester.printSummary();
123        run(tester, ARGS3, TEST3, NO_TEST);
124        run(tester, ARGS4, TEST4, NO_TEST);
125        tester.printSummary();
126    }
127
128    /**
129     * {@inheritDoc}
130     */
131    public String getBugId() {
132        return BUG_ID;
133    }
134
135    /**
136     * {@inheritDoc}
137     */
138    public String getBugName() {
139        return getClass().getName();
140    }
141}
142