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.7 $
022: */
023:
024: /**
025: * Created on 03.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.AllClasses command.
037: */
038: public class AllClassesTest 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.AllClasses command.
046: * <BR>At first the test starts HelloWorld debuggee.
047: * <BR> Then the test performs VirtualMachine.AllClasses command and checks that:
048: * <BR> - number of reference types returned by command has
049: * non-zero value;
050: * <BR> - there are no classes with the 'ARRAY' or
051: * 'PRIMITIVE' bits in the status flag;
052: */
053: public void testAllClasses002() {
054: logWriter.println("==> testAllClasses002: START...");
055:
056: synchronizer
057: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
058:
059: logWriter
060: .println("==> Send VirtualMachine::AllClasses command...");
061: CommandPacket packet = new CommandPacket(
062: JDWPCommands.VirtualMachineCommandSet.CommandSetID,
063: JDWPCommands.VirtualMachineCommandSet.AllClassesCommand);
064: ReplyPacket reply = debuggeeWrapper.vmMirror
065: .performCommand(packet);
066: checkReplyPacket(reply, "VirtualMachine::AllClasses command");
067:
068: long typeID;
069: String signature;
070: int status;
071:
072: int classes = reply.getNextValueAsInt();
073: assertTrue(classes > 0);
074:
075: int count = 0;
076: for (int i = 0; i < classes; i++) {
077:
078: reply.getNextValueAsByte();
079: typeID = reply.getNextValueAsReferenceTypeID();
080: signature = reply.getNextValueAsString();
081: status = reply.getNextValueAsInt();
082:
083: if ((status & JDWPConstants.ClassStatus.ARRAY) != 0) {
084: logWriter
085: .println("## FAILURE: Unexpected status is returned:");
086: logWriter.println("## ReferenceTypeId = "
087: + typeID);
088: logWriter.println("## Class signature: "
089: + signature);
090: logWriter.println("## Class status = 0x"
091: + Integer.toHexString(status) + "("
092: + JDWPConstants.ClassStatus.getName(status)
093: + ")");
094: logWriter
095: .println("## Status \"0x"
096: + Integer
097: .toHexString(JDWPConstants.ClassStatus.ARRAY)
098: + "("
099: + JDWPConstants.ClassStatus
100: .getName(JDWPConstants.ClassStatus.ARRAY)
101: + ")\" must NOT be returned!");
102: count++;
103: }
104: if ((status & JDWPConstants.ClassStatus.PRIMITIVE) != 0) {
105: logWriter
106: .println("## FAILURE: Unexpected status is returned:");
107: logWriter.println("## ReferenceTypeId = "
108: + typeID);
109: logWriter.println("## Class signature: "
110: + signature);
111: logWriter.println("## Class status = 0x"
112: + Integer.toHexString(status) + "("
113: + JDWPConstants.ClassStatus.getName(status)
114: + ")");
115: logWriter
116: .println("## Status \"0x"
117: + Integer
118: .toHexString(JDWPConstants.ClassStatus.PRIMITIVE)
119: + "("
120: + JDWPConstants.ClassStatus
121: .getName(JDWPConstants.ClassStatus.PRIMITIVE)
122: + ")\" must NOT be returned!");
123: count++;
124: }
125: }
126: assertEquals("count must be 0", 0, count);
127: synchronizer
128: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
129: logWriter.println("==> testAllClasses002: OK.");
130: }
131:
132: /**
133: * This testcase exercises VirtualMachine.AllClasses command.
134: * <BR>At first the test starts HelloWorld debuggee.
135: * <BR> Then the test performs VirtualMachine.AllClasses command and checks that:
136: * <BR> - number of reference types returned by command has
137: * non-zero value;
138: * <BR> - refTypeTag takes one of the TypeTag constants:
139: * 'CLASS', 'INTERFACE', 'ARRAY';
140: * <BR> - length of the signature string is not zero and starts with 'L' or
141: * '[' symbols;
142: * <BR> - signature of at least one class contains the "HelloWorld" string;
143: * <BR> - All data were read from reply packet;
144: */
145: public void testAllClasses001() {
146: logWriter.println("==> testAllClasses001: START...");
147:
148: synchronizer
149: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
150:
151: logWriter
152: .println("==> Send VirtualMachine::AllClasses command...");
153: CommandPacket packet = new CommandPacket(
154: JDWPCommands.VirtualMachineCommandSet.CommandSetID,
155: JDWPCommands.VirtualMachineCommandSet.AllClassesCommand);
156: ReplyPacket reply = debuggeeWrapper.vmMirror
157: .performCommand(packet);
158: checkReplyPacket(reply, "VirtualMachine::AllClasses command");
159:
160: byte refTypeTag;
161: String refTypeTagName;
162: long typeID;
163: String signature;
164: int status;
165: String msgLine;
166: boolean flagForHelloWorld = false;
167:
168: int classes = reply.getNextValueAsInt();
169: logWriter.println("==> Number of reference types = " + classes);
170: assertTrue(classes > 0);
171:
172: int printBound_1 = classes;
173: int printBound_2 = 0;
174: if (classes > 50) {
175: printBound_1 = 5;
176: printBound_2 = classes - 5;
177: }
178: for (int i = 0; i < classes; i++) {
179:
180: boolean infoIsPrinted = false;
181: refTypeTag = reply.getNextValueAsByte();
182: try {
183: refTypeTagName = JDWPConstants.TypeTag
184: .getName(refTypeTag);
185: } catch (Throwable thrown) {
186: refTypeTagName = "UnknownTagName";
187: }
188: msgLine = "\n" + i + ". " + refTypeTagName;
189: typeID = reply.getNextValueAsReferenceTypeID();
190: signature = reply.getNextValueAsString();
191: msgLine = msgLine + ": " + signature;
192: status = reply.getNextValueAsInt();
193: msgLine = msgLine + " "
194: + JDWPConstants.ClassStatus.getName(status);
195: if ((i < printBound_1) || (i >= printBound_2)) {
196: logWriter.println(msgLine);
197: logWriter.println("\treferenceTypeID = " + typeID);
198: logWriter.println("\trefTypeTag = " + refTypeTagName
199: + "(" + refTypeTag + ")");
200: logWriter.println("\tsignature = " + signature);
201: if (i == (printBound_1 - 1)) {
202: logWriter.println("...\n...\n...");
203: }
204: infoIsPrinted = true;
205: }
206:
207: try {
208: assertTrue(refTypeTag == JDWPConstants.TypeTag.ARRAY
209: || refTypeTag == JDWPConstants.TypeTag.CLASS
210: || refTypeTag == JDWPConstants.TypeTag.INTERFACE);
211:
212: assertTrue(signature.length() > 0);
213: assertTrue(signature.toCharArray()[0] == 'L'
214: || signature.toCharArray()[0] == '[');
215: } catch (Throwable thrown) {
216: // some assert is cought
217: if (!infoIsPrinted) {
218: logWriter.println(msgLine);
219: logWriter.println("\treferenceTypeID = " + typeID);
220: logWriter.println("\trefTypeTag = "
221: + refTypeTagName + "(" + refTypeTag + ")");
222: logWriter.println("\tsignature = " + signature);
223: }
224: logWriter
225: .println("## FAILURE is found out for this referenceType!\n");
226: assertTrue(refTypeTag == JDWPConstants.TypeTag.ARRAY
227: || refTypeTag == JDWPConstants.TypeTag.CLASS
228: || refTypeTag == JDWPConstants.TypeTag.INTERFACE);
229:
230: assertTrue(signature.length() > 0);
231: assertTrue(signature.toCharArray()[0] == 'L'
232: || signature.toCharArray()[0] == '[');
233: }
234:
235: if (signature.indexOf("HelloWorld") != -1)
236: flagForHelloWorld = true;
237: }
238: assertAllDataRead(reply);
239: assertTrue(
240: "HelloWorld has not been found in signatures of returned reference types",
241: flagForHelloWorld);
242:
243: synchronizer
244: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
245: logWriter.println("==> testAllClasses001: OK.");
246: }
247:
248: public static void main(String[] args) {
249: junit.textui.TestRunner.run(AllClassesTest.class);
250: }
251: }
|