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 Pavel N. Vyssotski
021: * @version $Revision: 1.4 $
022: */package org.apache.harmony.jpda.tests.jdwp.ClassType;
023:
024: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
025: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
026: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
027: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
028: import org.apache.harmony.jpda.tests.framework.jdwp.TaggedObject;
029: import org.apache.harmony.jpda.tests.framework.jdwp.Value;
030: import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
031: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
032:
033: /**
034: * JDWP unit test for ClassType.InvokeMethod command.
035: */
036: public class InvokeMethod002Test extends JDWPSyncTestCase {
037:
038: public static void main(String[] args) {
039: junit.textui.TestRunner.run(InvokeMethod002Test.class);
040: }
041:
042: protected String getDebuggeeClassName() {
043: return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.InvokeMethodDebuggee";
044: }
045:
046: /**
047: * This testcase checks ClassType.InvokeMethod command.
048: * <BR>Checked method is
049: * <BR>public static String testMethod3(
050: * int, int[], int[][], String, String[], String[][])
051: * <BR>of org.apache.harmony.jpda.tests.jdwp.share.debuggee.InvokeMethodDebuggee class.
052: * <BR> The testcase expects that returned value is not null object and returned
053: * exception object is null;
054: */
055: public void testInvokeMethod004() {
056: synchronizer
057: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
058:
059: // Get referenceTypeID
060: CommandPacket packet = new CommandPacket(
061: JDWPCommands.VirtualMachineCommandSet.CommandSetID,
062: JDWPCommands.VirtualMachineCommandSet.ClassesBySignatureCommand);
063: String classSig = "Lorg/apache/harmony/jpda/tests/jdwp/share/debuggee/InvokeMethodDebuggee;";
064: packet.setNextValueAsString(classSig);
065:
066: ReplyPacket reply = debuggeeWrapper.vmMirror
067: .performCommand(packet);
068: checkReplyPacket(reply,
069: "VirtualMachine::ClassesBySignature command");
070:
071: int classes = reply.getNextValueAsInt();
072: assertEquals(
073: "VirtualMachine::ClassesBySignature returned invalid number of classes,",
074: 1, classes); //this class may be loaded only once
075: byte refTypeTag = reply.getNextValueAsByte();
076: long classID = reply.getNextValueAsReferenceTypeID();
077: int status = reply.getNextValueAsInt();
078: assertAllDataRead(reply);
079: assertEquals(
080: "VirtualMachine::ClassesBySignature returned invalid TypeTag,",
081: JDWPConstants.TypeTag.CLASS, refTypeTag,
082: JDWPConstants.TypeTag
083: .getName(JDWPConstants.TypeTag.CLASS),
084: JDWPConstants.TypeTag.getName(refTypeTag));
085:
086: logWriter
087: .println(" VirtualMachine.ClassesBySignature: classes="
088: + classes + " refTypeTag=" + refTypeTag
089: + " classID= " + classID + " status=" + status);
090:
091: // Get methodID
092: packet = new CommandPacket(
093: JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
094: JDWPCommands.ReferenceTypeCommandSet.MethodsCommand);
095: packet.setNextValueAsClassID(classID);
096:
097: reply = debuggeeWrapper.vmMirror.performCommand(packet);
098: checkReplyPacket(reply, "ReferenceType::Methods command");
099:
100: int declared = reply.getNextValueAsInt();
101: logWriter.println(" ReferenceType.Methods: declared="
102: + declared);
103: long targetMethodID = 0;
104: for (int i = 0; i < declared; i++) {
105: long methodID = reply.getNextValueAsMethodID();
106: String name = reply.getNextValueAsString();
107: String signature = reply.getNextValueAsString();
108: int modBits = reply.getNextValueAsInt();
109: logWriter.println(" methodID=" + methodID + " name="
110: + name + " signature=" + signature + " modBits="
111: + modBits);
112: if (name.equals("testMethod3")) {
113: targetMethodID = methodID;
114: }
115: }
116: assertAllDataRead(reply);
117:
118: // Set EventRequest
119: packet = new CommandPacket(
120: JDWPCommands.EventRequestCommandSet.CommandSetID,
121: JDWPCommands.EventRequestCommandSet.SetCommand);
122: packet.setNextValueAsByte(JDWPConstants.EventKind.METHOD_ENTRY);
123: packet.setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL);
124: packet.setNextValueAsInt(1);
125: packet.setNextValueAsByte((byte) 5);
126: packet.setNextValueAsString("*.InvokeMethodDebuggee");
127:
128: reply = debuggeeWrapper.vmMirror.performCommand(packet);
129: checkReplyPacket(reply, "EventRequest::Set command");
130:
131: int requestID = reply.getNextValueAsInt();
132: logWriter.println(" EventRequest.Set: requestID=" + requestID);
133: assertAllDataRead(reply);
134: synchronizer
135: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
136:
137: long targetThreadID = 0;
138: // Wait event
139: CommandPacket event = debuggeeWrapper.vmMirror.receiveEvent();
140: byte suspendPolicy = event.getNextValueAsByte();
141: int events = event.getNextValueAsInt();
142: logWriter.println(" EVENT_THREAD event: suspendPolicy="
143: + suspendPolicy + " events=" + events);
144: for (int i = 0; i < events; i++) {
145: byte eventKind = event.getNextValueAsByte();
146: int newRequestID = event.getNextValueAsInt();
147: long threadID = event.getNextValueAsThreadID();
148: //Location location =
149: event.getNextValueAsLocation();
150: logWriter.println(" EVENT_THREAD event " + i
151: + ": eventKind=" + eventKind + " requestID="
152: + newRequestID + " threadID=" + threadID);
153: if (newRequestID == requestID) {
154: targetThreadID = threadID;
155: }
156: }
157: assertAllDataRead(event);
158: assertTrue("Invalid targetThreadID, must be != 0",
159: targetThreadID != 0);
160:
161: // Let's clear event request
162: packet = new CommandPacket(
163: JDWPCommands.EventRequestCommandSet.CommandSetID,
164: JDWPCommands.EventRequestCommandSet.ClearCommand);
165: packet.setNextValueAsByte(JDWPConstants.EventKind.METHOD_ENTRY);
166: packet.setNextValueAsInt(requestID);
167:
168: reply = debuggeeWrapper.vmMirror.performCommand(packet);
169: checkReplyPacket(reply, "EventRequest::Clear command");
170: assertAllDataRead(reply);
171:
172: logWriter
173: .println("Read values of fields to pass them as arguments:");
174: String fieldNames[] = { "checkInt", "checkIntArray",
175: "checkIntArray2", "checkString", "checkStringArray",
176: "checkStringArray2", "checkClass", "checkClassArray",
177: "checkClassArray2" };
178: long[] fieldIDs = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
179: Value[] fieldValues = { null, null, null, null, null, null,
180: null, null, null };
181:
182: packet = new CommandPacket(
183: JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
184: JDWPCommands.ReferenceTypeCommandSet.FieldsCommand);
185: packet.setNextValueAsReferenceTypeID(classID);
186:
187: reply = debuggeeWrapper.vmMirror.performCommand(packet);
188: checkReplyPacket(reply, "ReferenceType::Fields command");
189:
190: int fieldsCount = reply.getNextValueAsInt();
191: assertTrue("Invalid fieldsCount=" + fieldsCount
192: + ", must be >= " + fieldValues.length,
193: fieldsCount >= fieldValues.length);
194:
195: for (int i = 0; i < fieldsCount; i++) {
196: long id = reply.getNextValueAsFieldID();
197: String name = reply.getNextValueAsString();
198: //String signature =
199: reply.getNextValueAsString();
200: //int modifiers =
201: reply.getNextValueAsInt();
202: for (int k = 0; k < fieldNames.length; k++) {
203: if (fieldNames[k].equals(name)) {
204: fieldIDs[k] = id;
205: logWriter.println(" name=" + name + ", ID=" + id);
206: break;
207: }
208: }
209: }
210: assertAllDataRead(reply);
211:
212: for (int i = 0; i < fieldIDs.length; i++) {
213: if (fieldIDs[i] == 0) {
214: logWriter.println("ERROR: \"" + fieldNames[i]
215: + "\" field not found");
216: fail("\"" + fieldNames[i] + "\" field not found");
217: }
218: }
219:
220: packet = new CommandPacket(
221: JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
222: JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand);
223: packet.setNextValueAsReferenceTypeID(classID);
224: packet.setNextValueAsInt(fieldIDs.length);
225: for (int i = 0; i < fieldIDs.length; i++) {
226: packet.setNextValueAsFieldID(fieldIDs[i]);
227: }
228:
229: reply = debuggeeWrapper.vmMirror.performCommand(packet);
230: checkReplyPacket(reply, "ReferenceType::GetValues command");
231:
232: int valuesCount = reply.getNextValueAsInt();
233: for (int i = 0; i < valuesCount; i++) {
234: fieldValues[i] = reply.getNextValueAsValue();
235: }
236: assertAllDataRead(reply);
237:
238: // Make InvokeMethod
239: packet = new CommandPacket(
240: JDWPCommands.ClassTypeCommandSet.CommandSetID,
241: JDWPCommands.ClassTypeCommandSet.InvokeMethodCommand);
242: packet.setNextValueAsClassID(classID);
243: packet.setNextValueAsThreadID(targetThreadID);
244: packet.setNextValueAsMethodID(targetMethodID);
245: packet.setNextValueAsInt(fieldValues.length);
246: for (int i = 0; i < fieldValues.length; i++) {
247: packet.setNextValueAsValue(fieldValues[i]);
248: }
249: packet.setNextValueAsInt(0);
250: logWriter.println(" Send ClassType.InvokeMethod");
251: reply = debuggeeWrapper.vmMirror.performCommand(packet);
252: checkReplyPacket(reply, "ClassType::InvokeMethod command");
253:
254: Value returnValue = reply.getNextValueAsValue();
255: assertNotNull("Returned value is null", returnValue);
256: logWriter.println(" ClassType.InvokeMethod: returnValue="
257: + returnValue);
258:
259: TaggedObject exception = reply.getNextValueAsTaggedObject();
260: assertNotNull(
261: "ClassType::InvokeMethod returned null exception",
262: exception);
263: assertEquals(
264: "ClassType::InvokeMethod returned invalid exception objectID,",
265: 0, exception.objectID);
266: assertEquals(
267: "ClassType::InvokeMethod returned invalid exception.tag",
268: JDWPConstants.Tag.OBJECT_TAG,
269: exception.tag,
270: JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG),
271: JDWPConstants.Tag.getName(exception.tag));
272: logWriter.println(" ClassType.InvokeMethod: exception.tag="
273: + exception.tag + " exception.objectID="
274: + exception.objectID);
275: assertAllDataRead(reply);
276:
277: // Let's resume application
278: packet = new CommandPacket(
279: JDWPCommands.VirtualMachineCommandSet.CommandSetID,
280: JDWPCommands.VirtualMachineCommandSet.ResumeCommand);
281: reply = debuggeeWrapper.vmMirror.performCommand(packet);
282: checkReplyPacket(reply, "VirtualMachine::Resume command");
283: assertAllDataRead(reply);
284:
285: synchronizer
286: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
287: }
288:
289: }
|