blob: 96df25d792d44ff0e24c41c38a4ea3ad60f25d13 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2001-2003 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/**
25 * @test
26 * @bug 4406439 4925740
27 * @summary ClassesByName2 verifies that all the classes in the loaded class list can be found with classesByName..
28 *
29 * @author Tim Bell (based on ClassesByName by Robert Field)
30 *
31 * @run build TestScaffold VMConnection TargetListener TargetAdapter
32 * @run compile -g ClassesByName2Test.java
33 * @run main ClassesByName2Test
34 */
35import com.sun.jdi.*;
36import com.sun.jdi.event.*;
37import com.sun.jdi.request.*;
38
39import java.util.*;
40
41 /********** target program **********/
42
43class ClassesByName2Targ {
44 public static void ready() {
45 System.out.println("Ready!");
46 }
47
48 public static void main(String[] args){
49 System.out.println("Howdy!");
50 try {
51
52 Thread zero = new Thread ("ZERO") {
53 public void run () {
54 System.setProperty("java.awt.headless", "true");
55 java.awt.Toolkit tk = java.awt.Toolkit.getDefaultToolkit();
56
57 }
58 };
59
60 Thread one = new Thread ("ONE") {
61 public void run () {
62 try {
63 java.security.KeyPairGenerator keyGen =
64 java.security.KeyPairGenerator.getInstance("DSA", "SUN");
65 } catch (Exception e) {
66 e.printStackTrace();
67 }
68 }
69 };
70
71 Thread two = new Thread ("TWO") {
72 public void run () {
73 javax.rmi.CORBA.Util.getCodebase(this.getClass());
74 }
75 };
76
77 ready();
78
79 two.start();
80 one.start();
81 zero.start();
82
83 try {
84 zero.join();
85 one.join();
86 two.join();
87 } catch (InterruptedException iex) {
88 iex.printStackTrace();
89 }
90 } catch (Exception e) {
91 e.printStackTrace();
92 }
93 System.out.println("Goodbye from ClassesByName2Targ!");
94 }
95}
96
97 /********** test program **********/
98
99public class ClassesByName2Test extends TestScaffold {
100
101 ClassesByName2Test (String args[]) {
102 super(args);
103 }
104
105 public static void main(String[] args) throws Exception {
106 new ClassesByName2Test(args).startTests();
107 }
108
109 protected void runTests() throws Exception {
110 /*
111 * Get to the top of ready()
112 */
113 startTo("ClassesByName2Targ", "ready", "()V");
114
115 vm().resume();
116
117 int i = 0;
118 while (i < 8 && !vmDisconnected) {
119 i++;
120 List all = vm().allClasses();
121 System.out.println("");
122 System.out.println("++++ Lookup number: " + i + ". allClasses() returned " +
123 all.size() + " classes.");
124 for (Iterator it = all.iterator(); it.hasNext(); ) {
125 ReferenceType cls = (ReferenceType)it.next();
126 String name = cls.name();
127 List found = vm().classesByName(name);
128 if (found.contains(cls)) {
129 //System.out.println("Found class: " + name);
130 } else {
131 System.out.println("CLASS NOT FOUND: " + name);
132 throw new Exception("CLASS NOT FOUND (by classesByName): " +
133 name);
134 }
135 }
136 }
137 /*
138 * resume the target listening for events
139 */
140 listenUntilVMDisconnect();
141
142 /*
143 * deal with results of test
144 * if anything has called failure("foo") testFailed will be true
145 */
146 if (!testFailed) {
147 println("ClassesByName2Test: passed");
148 } else {
149 throw new Exception("ClassesByName2Test: failed");
150 }
151 }
152}