|
1 /* |
|
2 * Copyright (c) 2001, 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 package nsk.jdi.ObjectReference.uniqueID; |
|
25 |
|
26 import nsk.share.*; |
|
27 import nsk.share.jpda.*; |
|
28 import nsk.share.jdi.*; |
|
29 |
|
30 import com.sun.jdi.*; |
|
31 import java.util.*; |
|
32 import java.io.*; |
|
33 |
|
34 /** |
|
35 * The test for the implementation of an object of the type <BR> |
|
36 * ObjectReference. <BR> |
|
37 * <BR> |
|
38 * The test checks up that results of the method <BR> |
|
39 * <code>com.sun.jdi.ObjectReference.uniqueID()</code> <BR> |
|
40 * complies with its specification. <BR> |
|
41 * <BR> |
|
42 * The test checks up that the method returns a long value. <BR> |
|
43 */ |
|
44 |
|
45 public class uniqueid001 { |
|
46 |
|
47 //----------------------------------------------------- templete section |
|
48 static final int PASSED = 0; |
|
49 static final int FAILED = 2; |
|
50 static final int PASS_BASE = 95; |
|
51 |
|
52 //----------------------------------------------------- templete parameters |
|
53 static final String |
|
54 sHeader1 = "\n==> nsk/jdi/ObjectReference/uniqueID/uniqueid001 ", |
|
55 sHeader2 = "--> debugger: ", |
|
56 sHeader3 = "##> debugger: "; |
|
57 |
|
58 //----------------------------------------------------- main method |
|
59 |
|
60 public static void main (String argv[]) { |
|
61 int result = run(argv, System.out); |
|
62 System.exit(result + PASS_BASE); |
|
63 } |
|
64 |
|
65 public static int run (String argv[], PrintStream out) { |
|
66 return new uniqueid001().runThis(argv, out); |
|
67 } |
|
68 |
|
69 //-------------------------------------------------- log procedures |
|
70 |
|
71 private static Log logHandler; |
|
72 |
|
73 private static void log1(String message) { |
|
74 logHandler.display(sHeader1 + message); |
|
75 } |
|
76 private static void log2(String message) { |
|
77 logHandler.display(sHeader2 + message); |
|
78 } |
|
79 private static void log3(String message) { |
|
80 logHandler.complain(sHeader3 + message); |
|
81 } |
|
82 |
|
83 // ************************************************ test parameters |
|
84 |
|
85 private String debuggeeName = |
|
86 "nsk.jdi.ObjectReference.uniqueID.uniqueid001a"; |
|
87 |
|
88 private String testedClassName = |
|
89 "nsk.jdi.ObjectReference.uniqueID.TestClass"; |
|
90 |
|
91 //String mName = "nsk.jdi.ObjectReference.uniqueID"; |
|
92 |
|
93 //====================================================== test program |
|
94 //------------------------------------------------------ common section |
|
95 |
|
96 static ArgumentHandler argsHandler; |
|
97 |
|
98 static int waitTime; |
|
99 |
|
100 static VirtualMachine vm = null; |
|
101 |
|
102 ReferenceType testedClass = null; |
|
103 |
|
104 static int testExitCode = PASSED; |
|
105 |
|
106 static final int returnCode0 = 0; |
|
107 static final int returnCode1 = 1; |
|
108 static final int returnCode2 = 2; |
|
109 static final int returnCode3 = 3; |
|
110 static final int returnCode4 = 4; |
|
111 |
|
112 //------------------------------------------------------ methods |
|
113 |
|
114 private int runThis (String argv[], PrintStream out) { |
|
115 |
|
116 Debugee debuggee; |
|
117 |
|
118 argsHandler = new ArgumentHandler(argv); |
|
119 logHandler = new Log(out, argsHandler); |
|
120 Binder binder = new Binder(argsHandler, logHandler); |
|
121 |
|
122 if (argsHandler.verbose()) { |
|
123 debuggee = binder.bindToDebugee(debuggeeName + " -vbs"); |
|
124 } else { |
|
125 debuggee = binder.bindToDebugee(debuggeeName); |
|
126 } |
|
127 |
|
128 waitTime = argsHandler.getWaitTime(); |
|
129 |
|
130 |
|
131 IOPipe pipe = new IOPipe(debuggee); |
|
132 |
|
133 debuggee.redirectStderr(out); |
|
134 log2("issuspended002a debuggee launched"); |
|
135 debuggee.resume(); |
|
136 |
|
137 String line = pipe.readln(); |
|
138 if ((line == null) || !line.equals("ready")) { |
|
139 log3("signal received is not 'ready' but: " + line); |
|
140 return FAILED; |
|
141 } else { |
|
142 log2("'ready' recieved"); |
|
143 } |
|
144 |
|
145 vm = debuggee.VM(); |
|
146 |
|
147 //------------------------------------------------------ testing section |
|
148 log1(" TESTING BEGINS"); |
|
149 |
|
150 for (int i = 0; ; i++) { |
|
151 |
|
152 pipe.println("newcheck"); |
|
153 line = pipe.readln(); |
|
154 |
|
155 if (line.equals("checkend")) { |
|
156 log2(" : returned string is 'checkend'"); |
|
157 break ; |
|
158 } else if (!line.equals("checkready")) { |
|
159 log3("ERROR: returned string is not 'checkready'"); |
|
160 testExitCode = FAILED; |
|
161 break ; |
|
162 } |
|
163 |
|
164 log1("new checkready: #" + i); |
|
165 |
|
166 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part |
|
167 |
|
168 String objName = "testObj"; |
|
169 |
|
170 log2(".......getting ObjectReference objRef object"); |
|
171 try { |
|
172 |
|
173 testedClass = (ReferenceType) |
|
174 vm.classesByName(debuggeeName).get(0); |
|
175 |
|
176 ObjectReference objRef = (ObjectReference) |
|
177 testedClass.getValue(testedClass.fieldByName(objName)); |
|
178 |
|
179 log2(".......checking up on throwing Exception by objRef.uniqueID()"); |
|
180 |
|
181 try { |
|
182 long id = objRef.uniqueID(); |
|
183 log2(" uniqueID value == " + id); |
|
184 } catch ( Exception e2 ) { |
|
185 testExitCode = FAILED; |
|
186 log3("ERROR: UNEXPECTED Exception is thrown : " + e2); |
|
187 } |
|
188 |
|
189 } catch ( Exception e) { |
|
190 log3("ERROR: Exception at very beginning !? : " + e); |
|
191 testExitCode = FAILED; |
|
192 } |
|
193 |
|
194 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
195 } |
|
196 log1(" TESTING ENDS"); |
|
197 |
|
198 //-------------------------------------------------- test summary section |
|
199 //------------------------------------------------- standard end section |
|
200 |
|
201 pipe.println("quit"); |
|
202 log2("waiting for the debuggee to finish ..."); |
|
203 debuggee.waitFor(); |
|
204 |
|
205 int status = debuggee.getStatus(); |
|
206 if (status != PASSED + PASS_BASE) { |
|
207 log3("debuggee returned UNEXPECTED exit status: " + |
|
208 status + " != PASS_BASE"); |
|
209 testExitCode = FAILED; |
|
210 } else { |
|
211 log2("debuggee returned expected exit status: " + |
|
212 status + " == PASS_BASE"); |
|
213 } |
|
214 |
|
215 if (testExitCode != PASSED) { |
|
216 logHandler.complain("TEST FAILED"); |
|
217 } |
|
218 return testExitCode; |
|
219 } |
|
220 } |