001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Vitaly A. Provodin
021: * @version $Revision: 1.8 $
022: */
023:
024: /**
025: * Created on 10.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.VirtualMachine;
027:
028: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
029: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
030: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
031: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
032: import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
033: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
034:
035: /**
036: * JDWP Unit test for VirtualMachine.AllClassesWithGeneric command.
037: */
038: public class AllClassesWithGenericTest extends JDWPSyncTestCase {
039:
040: protected String getDebuggeeClassName() {
041: return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld";
042: }
043:
044: /**
045: * This testcase exercises VirtualMachine.AllClassesWithGeneric command.
046: * <BR>At first the test starts HelloWorld debuggee.
047: * <BR> Then the test performs VirtualMachine.AllClassesWithGeneric
048: * command and checks that:
049: * <BR> - number of reference types returned by command has
050: * non-zero value;
051: * <BR> - there are no classes with the 'ARRAY' or
052: * 'PRIMITIVE' bits in the status flag;
053: */
054: public void testAllClassesWithGeneric002() {
055: logWriter.println("==> testAllClassesWithGeneric002: START...");
056:
057: synchronizer
058: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
059:
060: logWriter
061: .println("==> Send VirtualMachine::AllClassesWithGeneric command...");
062: CommandPacket packet = new CommandPacket(
063: JDWPCommands.VirtualMachineCommandSet.CommandSetID,
064: JDWPCommands.VirtualMachineCommandSet.AllClassesWithGenericCommand);
065: ReplyPacket reply = debuggeeWrapper.vmMirror
066: .performCommand(packet);
067: checkReplyPacket(reply,
068: "VirtualMachine::AllClassesWithGeneric command");
069:
070: long typeID;
071: String signature, genericSignature;
072: int status;
073:
074: int classes = reply.getNextValueAsInt();
075: assertTrue(classes > 0);
076:
077: int count = 0;
078: for (int i = 0; i < classes; i++) {
079:
080: reply.getNextValueAsByte();
081: typeID = reply.getNextValueAsReferenceTypeID();
082: signature = reply.getNextValueAsString();
083: genericSignature = reply.getNextValueAsString();
084: status = reply.getNextValueAsInt();
085:
086: if ((status & JDWPConstants.ClassStatus.ARRAY) != 0) {
087: logWriter
088: .println("## FAILURE: Unexpected status is returned:");
089: logWriter.println("## ReferenceTypeId = "
090: + typeID);
091: logWriter.println("## Class signature: "
092: + signature);
093: logWriter
094: .println("## Class generic signature: "
095: + genericSignature);
096: logWriter.println("## Class status = 0x"
097: + Integer.toHexString(status) + "("
098: + JDWPConstants.ClassStatus.getName(status)
099: + ")");
100: logWriter
101: .println("## Status \"0x"
102: + Integer
103: .toHexString(JDWPConstants.ClassStatus.ARRAY)
104: + "("
105: + JDWPConstants.ClassStatus
106: .getName(JDWPConstants.ClassStatus.ARRAY)
107: + ")\" must NOT be returned!");
108: count++;
109: }
110: if ((status & JDWPConstants.ClassStatus.PRIMITIVE) != 0) {
111: logWriter
112: .println("## FAILURE: Unexpected status is returned:");
113: logWriter.println("## ReferenceTypeId = "
114: + typeID);
115: logWriter.println("## Class signature: "
116: + signature);
117: logWriter
118: .println("## Class generic signature: "
119: + genericSignature);
120: logWriter.println("## Class status = 0x"
121: + Integer.toHexString(status) + "("
122: + JDWPConstants.ClassStatus.getName(status)
123: + ")");
124: logWriter
125: .println("## Status \"0x"
126: + Integer
127: .toHexString(JDWPConstants.ClassStatus.PRIMITIVE)
128: + "("
129: + JDWPConstants.ClassStatus
130: .getName(JDWPConstants.ClassStatus.PRIMITIVE)
131: + ")\" must NOT be returned!");
132: count++;
133: }
134: }
135: assertEquals("count must be 0", 0, count);
136: synchronizer
137: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
138: logWriter.println("==> testAllClassesWithGeneric002: OK.");
139: }
140:
141: /**
142: * This testcase exercises VirtualMachine.AllClassesWithGeneric command.
143: * <BR>At first the test starts HelloWorld debuggee.
144: * <BR> Then the test performs VirtualMachine.AllClassesWithGeneric
145: * command and checks that:
146: * <BR> - number of reference types returned by command has
147: * non-zero value;
148: * <BR> - refTypeTag takes one of the TypeTag constants:
149: * 'CLASS', 'INTERFACE', 'ARRAY';
150: * <BR> - length of the signature string is not zero and starts with 'L' or
151: * '[' symbols;
152: * <BR> - signature of at least one class contains the "HelloWorld" string;
153: * <BR> - All data were read from reply packet;
154: */
155: public void testAllClassesWithGeneric001() {
156:
157: logWriter.println("==> testAllClassesWithGeneric001: START...");
158: synchronizer
159: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
160:
161: logWriter
162: .println("==> Send VirtualMachine::AllClassesWithGeneric command...");
163: CommandPacket packet = new CommandPacket(
164: JDWPCommands.VirtualMachineCommandSet.CommandSetID,
165: JDWPCommands.VirtualMachineCommandSet.AllClassesWithGenericCommand);
166: ReplyPacket reply = debuggeeWrapper.vmMirror
167: .performCommand(packet);
168: checkReplyPacket(reply,
169: "VirtualMachine::AllClassesWithGeneric command");
170:
171: byte refTypeTag;
172: String refTypeTagName;
173: long typeID;
174: String signature, genericSignature;
175: int status;
176: String msgLine;
177: boolean flagForHelloWorld = false;
178:
179: int classes = reply.getNextValueAsInt();
180: logWriter.println("==> Number of reference types = " + classes);
181: assertTrue(
182: "VirtualMachine::AllClassesWithGeneric command returned invalid number of classes: "
183: + classes, classes > 0);
184:
185: int printBound_1 = classes;
186: int printBound_2 = 0;
187: if (classes > 50) {
188: printBound_1 = 5;
189: printBound_2 = classes - 5;
190: }
191: for (int i = 0; i < classes; i++) {
192:
193: boolean infoIsPrinted = false;
194: refTypeTag = reply.getNextValueAsByte();
195: try {
196: refTypeTagName = JDWPConstants.TypeTag
197: .getName(refTypeTag);
198: } catch (Throwable thrown) {
199: refTypeTagName = "UnknownTagName";
200: }
201: msgLine = "\n" + i + ". " + refTypeTagName;
202: typeID = reply.getNextValueAsReferenceTypeID();
203: signature = reply.getNextValueAsString();
204: msgLine = msgLine + ": " + signature;
205: genericSignature = reply.getNextValueAsString();
206: status = reply.getNextValueAsInt();
207: msgLine = msgLine + " "
208: + JDWPConstants.ClassStatus.getName(status);
209: if ((i < printBound_1) || (i >= printBound_2)) {
210: logWriter.println(msgLine);
211: logWriter.println("\treferenceTypeID = " + typeID);
212: logWriter.println("\trefTypeTag = " + refTypeTagName
213: + "(" + refTypeTag + ")");
214: logWriter.println("\tsignature = " + signature);
215: logWriter.println("\tgenericSignature = "
216: + genericSignature);
217: if (i == (printBound_1 - 1)) {
218: logWriter.println("...\n...\n...");
219: }
220: infoIsPrinted = true;
221: }
222:
223: try {
224: assertTrue(refTypeTag == JDWPConstants.TypeTag.ARRAY
225: || refTypeTag == JDWPConstants.TypeTag.CLASS
226: || refTypeTag == JDWPConstants.TypeTag.INTERFACE);
227:
228: assertTrue(signature.length() > 0);
229: assertTrue(signature.toCharArray()[0] == 'L'
230: || signature.toCharArray()[0] == '[');
231: } catch (Throwable thrown) {
232: // some assert is cought
233: if (!infoIsPrinted) {
234: logWriter.println(msgLine);
235: logWriter.println("\treferenceTypeID = " + typeID);
236: logWriter.println("\trefTypeTag = "
237: + refTypeTagName + "(" + refTypeTag + ")");
238: logWriter.println("\tsignature = " + signature);
239: logWriter.println("\tgenericSignature = "
240: + genericSignature);
241: }
242: logWriter
243: .println("## FAILURE is found out for this referenceType!\n");
244: assertTrue(
245: "Unexpected refTypeTag",
246: refTypeTag == JDWPConstants.TypeTag.ARRAY
247: || refTypeTag == JDWPConstants.TypeTag.CLASS
248: || refTypeTag == JDWPConstants.TypeTag.INTERFACE);
249:
250: assertTrue("Invalid signature", signature.length() > 0);
251: assertTrue("Invalid signature",
252: signature.toCharArray()[0] == 'L'
253: || signature.toCharArray()[0] == '[');
254: }
255: if (signature.indexOf("HelloWorld") != -1)
256: flagForHelloWorld = true;
257: }
258:
259: assertAllDataRead(reply);
260: assertTrue(
261: "HelloWorld has not been found in signatures of returned reference types",
262: flagForHelloWorld);
263:
264: synchronizer
265: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
266: logWriter.println("==> testAllClassesWithGeneric001: OK.");
267: }
268:
269: public static void main(String[] args) {
270: junit.textui.TestRunner.run(AllClassesWithGenericTest.class);
271: }
272: }
|