Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 61009 invoked from network); 28 Nov 2006 17:51:44 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 28 Nov 2006 17:51:44 -0000 Received: (qmail 56065 invoked by uid 500); 28 Nov 2006 17:51:50 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 56016 invoked by uid 500); 28 Nov 2006 17:51:50 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 55959 invoked by uid 99); 28 Nov 2006 17:51:49 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Nov 2006 09:51:49 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Nov 2006 09:51:29 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 9BA581A984E; Tue, 28 Nov 2006 09:50:00 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r480141 [22/38] - in /harmony/enhanced/jdktools/trunk/modules/jpda: ./ doc/ doc/images/ make/ src/ src/common/ src/common/other/ src/common/other/jpda/ src/common/other/jpda/jdwp/ src/common/other/jpda/jdwp/agent/ src/common/other/jpda/jdwp... Date: Tue, 28 Nov 2006 17:49:31 -0000 To: commits@harmony.apache.org From: geirm@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061128175000.9BA581A984E@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/InvokeMethod002Test.java URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/InvokeMethod002Test.java?view=auto&rev=480141 ============================================================================== --- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/InvokeMethod002Test.java (added) +++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/InvokeMethod002Test.java Tue Nov 28 09:49:08 2006 @@ -0,0 +1,279 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Pavel N. Vyssotski + * @version $Revision: 1.4 $ + */ + +// $Id: InvokeMethod002Test.java,v 1.4 2006/06/20 11:15:16 rscherba Exp $ + +package org.apache.harmony.jpda.tests.jdwp.ClassType; + +import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; +import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; +import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants; +import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; +import org.apache.harmony.jpda.tests.framework.jdwp.TaggedObject; +import org.apache.harmony.jpda.tests.framework.jdwp.Value; +import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; +import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; + + +/** + * JDWP unit test for ClassType.InvokeMethod command. + */ +public class InvokeMethod002Test extends JDWPSyncTestCase { + + public static void main(String[] args) { + junit.textui.TestRunner.run(InvokeMethod002Test.class); + } + + protected String getDebuggeeClassName() { + return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.InvokeMethodDebuggee"; + } + + /** + * This testcase checks ClassType.InvokeMethod command. + *
Checked method is + *
public static String testMethod3( + * int, int[], int[][], String, String[], String[][]) + *
of org.apache.harmony.jpda.tests.jdwp.share.debuggee.InvokeMethodDebuggee class. + *
The testcase expects that returned value is not null object and returned + * exception object is null; + */ + public void testInvokeMethod004() { + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + // Get referenceTypeID + CommandPacket packet = new CommandPacket( + JDWPCommands.VirtualMachineCommandSet.CommandSetID, + JDWPCommands.VirtualMachineCommandSet.ClassesBySignatureCommand); + String classSig = "Lorg/apache/harmony/jpda/tests/jdwp/share/debuggee/InvokeMethodDebuggee;"; + packet.setNextValueAsString(classSig); + + ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "VirtualMachine::ClassesBySignature command"); + + int classes = reply.getNextValueAsInt(); + assertEquals("VirtualMachine::ClassesBySignature returned invalid number of classes,", + 1, classes); //this class may be loaded only once + byte refTypeTag = reply.getNextValueAsByte(); + long classID = reply.getNextValueAsReferenceTypeID(); + int status = reply.getNextValueAsInt(); + assertAllDataRead(reply); + assertEquals("VirtualMachine::ClassesBySignature returned invalid TypeTag,", + JDWPConstants.TypeTag.CLASS, refTypeTag, + JDWPConstants.TypeTag.getName(JDWPConstants.TypeTag.CLASS), + JDWPConstants.TypeTag.getName(refTypeTag)); + + logWriter.println(" VirtualMachine.ClassesBySignature: classes=" + + classes + " refTypeTag=" + refTypeTag + " classID= " + classID + + " status=" + status); + + // Get methodID + packet = new CommandPacket( + JDWPCommands.ReferenceTypeCommandSet.CommandSetID, + JDWPCommands.ReferenceTypeCommandSet.MethodsCommand); + packet.setNextValueAsClassID(classID); + + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "ReferenceType::Methods command"); + + int declared = reply.getNextValueAsInt(); + logWriter.println(" ReferenceType.Methods: declared=" + declared); + long targetMethodID = 0; + for (int i = 0; i < declared; i++) { + long methodID = reply.getNextValueAsMethodID(); + String name = reply.getNextValueAsString(); + String signature = reply.getNextValueAsString(); + int modBits = reply.getNextValueAsInt(); + logWriter.println(" methodID=" + methodID + " name=" + name + + " signature=" + signature + " modBits=" + modBits); + if (name.equals("testMethod3")) { + targetMethodID = methodID; + } + } + assertAllDataRead(reply); + + // Set EventRequest + packet = new CommandPacket( + JDWPCommands.EventRequestCommandSet.CommandSetID, + JDWPCommands.EventRequestCommandSet.SetCommand); + packet.setNextValueAsByte(JDWPConstants.EventKind.METHOD_ENTRY); + packet.setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL); + packet.setNextValueAsInt(1); + packet.setNextValueAsByte((byte) 5); + packet.setNextValueAsString("*.InvokeMethodDebuggee"); + + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "EventRequest::Set command"); + + int requestID = reply.getNextValueAsInt(); + logWriter.println(" EventRequest.Set: requestID=" + requestID); + assertAllDataRead(reply); + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + + long targetThreadID = 0; + // Wait event + CommandPacket event = debuggeeWrapper.vmMirror.receiveEvent(); + byte suspendPolicy = event.getNextValueAsByte(); + int events = event.getNextValueAsInt(); + logWriter.println(" EVENT_THREAD event: suspendPolicy=" + suspendPolicy + + " events=" + events); + for (int i = 0; i < events; i++) { + byte eventKind = event.getNextValueAsByte(); + int newRequestID = event.getNextValueAsInt(); + long threadID = event.getNextValueAsThreadID(); + //Location location = + event.getNextValueAsLocation(); + logWriter.println(" EVENT_THREAD event " + i + ": eventKind=" + + eventKind + " requestID=" + newRequestID + " threadID=" + + threadID); + if (newRequestID == requestID) { + targetThreadID = threadID; + } + } + assertAllDataRead(event); + assertTrue("Invalid targetThreadID, must be != 0", targetThreadID != 0); + + // Let's clear event request + packet = new CommandPacket( + JDWPCommands.EventRequestCommandSet.CommandSetID, + JDWPCommands.EventRequestCommandSet.ClearCommand); + packet.setNextValueAsByte(JDWPConstants.EventKind.METHOD_ENTRY); + packet.setNextValueAsInt(requestID); + + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "EventRequest::Clear command"); + assertAllDataRead(reply); + + logWriter.println("Read values of fields to pass them as arguments:"); + String fieldNames[] = { + "checkInt", + "checkIntArray", + "checkIntArray2", + "checkString", + "checkStringArray", + "checkStringArray2", + "checkClass", + "checkClassArray", + "checkClassArray2" + }; + long[] fieldIDs = {0,0,0,0,0,0,0,0,0}; + Value[] fieldValues = {null,null,null,null,null,null,null,null,null}; + + packet = new CommandPacket( + JDWPCommands.ReferenceTypeCommandSet.CommandSetID, + JDWPCommands.ReferenceTypeCommandSet.FieldsCommand); + packet.setNextValueAsReferenceTypeID(classID); + + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "ReferenceType::Fields command"); + + int fieldsCount = reply.getNextValueAsInt(); + assertTrue("Invalid fieldsCount=" + fieldsCount + ", must be > " + fieldValues.length + , fieldsCount > fieldValues.length); + + for (int i = 0; i < fieldsCount; i++) { + long id = reply.getNextValueAsFieldID(); + String name = reply.getNextValueAsString(); + //String signature = + reply.getNextValueAsString(); + //int modifiers = + reply.getNextValueAsInt(); + for (int k = 0; k < fieldNames.length; k++) { + if (fieldNames[k].equals(name)) { + fieldIDs[k] = id; + logWriter.println(" name=" + name + ", ID=" + id); + break; + } + } + } + assertAllDataRead(reply); + + for (int i = 0; i < fieldIDs.length; i++) { + if (fieldIDs[i] == 0) { + logWriter.println( + "ERROR: \"" + fieldNames[i] + "\" field not found"); + fail("\"" + fieldNames[i] + "\" field not found"); + } + } + + packet = new CommandPacket( + JDWPCommands.ReferenceTypeCommandSet.CommandSetID, + JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand); + packet.setNextValueAsReferenceTypeID(classID); + packet.setNextValueAsInt(fieldIDs.length); + for (int i = 0; i < fieldIDs.length; i++) { + packet.setNextValueAsFieldID(fieldIDs[i]); + } + + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "ReferenceType::GetValues command"); + + int valuesCount = reply.getNextValueAsInt(); + for (int i = 0; i < valuesCount; i++) { + fieldValues[i] = reply.getNextValueAsValue(); + } + assertAllDataRead(reply); + + // Make InvokeMethod + packet = new CommandPacket( + JDWPCommands.ClassTypeCommandSet.CommandSetID, + JDWPCommands.ClassTypeCommandSet.InvokeMethodCommand); + packet.setNextValueAsClassID(classID); + packet.setNextValueAsThreadID(targetThreadID); + packet.setNextValueAsMethodID(targetMethodID); + packet.setNextValueAsInt(fieldValues.length); + for (int i = 0; i < fieldValues.length; i++) { + packet.setNextValueAsValue(fieldValues[i]); + } + packet.setNextValueAsInt(0); + logWriter.println(" Send ClassType.InvokeMethod"); + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "ClassType::InvokeMethod command"); + + Value returnValue = reply.getNextValueAsValue(); + assertNotNull("Returned value is null", returnValue); + logWriter.println(" ClassType.InvokeMethod: returnValue=" + returnValue); + + TaggedObject exception = reply.getNextValueAsTaggedObject(); + assertNotNull("ClassType::InvokeMethod returned null exception", + exception); + assertEquals("ClassType::InvokeMethod returned invalid exception objectID,", + 0, exception.objectID); + assertEquals("ClassType::InvokeMethod returned invalid exception.tag", + JDWPConstants.Tag.OBJECT_TAG, exception.tag, + JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG), + JDWPConstants.Tag.getName(exception.tag)); + logWriter.println(" ClassType.InvokeMethod: exception.tag=" + + exception.tag + " exception.objectID=" + exception.objectID); + assertAllDataRead(reply); + + // Let's resume application + packet = new CommandPacket( + JDWPCommands.VirtualMachineCommandSet.CommandSetID, + JDWPCommands.VirtualMachineCommandSet.ResumeCommand); + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "VirtualMachine::Resume command"); + assertAllDataRead(reply); + + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + } + +} Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/InvokeMethod002Test.java ------------------------------------------------------------------------------ svn:eol-style = native Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/InvokeMethodTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/InvokeMethodTest.java?view=auto&rev=480141 ============================================================================== --- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/InvokeMethodTest.java (added) +++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/InvokeMethodTest.java Tue Nov 28 09:49:08 2006 @@ -0,0 +1,502 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Viacheslav G. Rybalov + * @version $Revision: 1.4 $ + */ + +/** + * Created on 10.03.2005 + */ +package org.apache.harmony.jpda.tests.jdwp.ClassType; + +import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; +import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; +import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants; +import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; +import org.apache.harmony.jpda.tests.framework.jdwp.TaggedObject; +import org.apache.harmony.jpda.tests.framework.jdwp.Value; +import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; +import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; + + +/** + * JDWP unit test for ClassType.InvokeMethod command. + */ +public class InvokeMethodTest extends JDWPSyncTestCase { + + static final int testStatusPassed = 0; + static final int testStatusFailed = -1; + + protected String getDebuggeeClassName() { + return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.InvokeMethodDebuggee"; + } + + /** + * This testcase exercises ClassType.InvokeMethod command. + *
At first the test starts debuggee. + *
Then does the following checks: + *
   - send ClassType.InvokeMethod command for method, + * which should not throw any Exception, and checks, + * that returned value is expected int value and returned + * exception object is null; + *
   - send ClassType.InvokeMethod command for method, + * which should throw some Exception, and checks, that + * returned exception object is not null and has expected attributes; + */ + public void testInvokeMethod001() { + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + // Get referenceTypeID + CommandPacket packet = new CommandPacket( + JDWPCommands.VirtualMachineCommandSet.CommandSetID, + JDWPCommands.VirtualMachineCommandSet.ClassesBySignatureCommand); + String classSig = "Lorg/apache/harmony/jpda/tests/jdwp/share/debuggee/InvokeMethodDebuggee;"; + packet.setNextValueAsString(classSig); + ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "VirtualMachine::ClassesBySignature command"); + + int classes = reply.getNextValueAsInt(); + assertEquals("VirtualMachine::ClassesBySignature returned invalid number of classes,", + 1, classes); //this class may be loaded only once + byte refTypeTag = reply.getNextValueAsByte(); + long typeID = reply.getNextValueAsReferenceTypeID(); + int status = reply.getNextValueAsInt(); + assertAllDataRead(reply); + assertEquals("VirtualMachine::ClassesBySignature returned Invalid type tag,", + JDWPConstants.TypeTag.CLASS, refTypeTag, + JDWPConstants.TypeTag.getName(JDWPConstants.TypeTag.CLASS), + JDWPConstants.TypeTag.getName(refTypeTag)); + + logWriter.println(" VirtualMachine.ClassesBySignature: classes=" + + classes + " refTypeTag=" + refTypeTag + " typeID= " + typeID + + " status=" + status); + + // Get methodID + packet = new CommandPacket( + JDWPCommands.ReferenceTypeCommandSet.CommandSetID, + JDWPCommands.ReferenceTypeCommandSet.MethodsCommand); + packet.setNextValueAsClassID(typeID); + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "ReferenceType::Methods command"); + + int declared = reply.getNextValueAsInt(); + logWriter.println(" ReferenceType.Methods: declared=" + declared); + long targetMethodID = 0; + for (int i = 0; i < declared; i++) { + long methodID = reply.getNextValueAsMethodID(); + String name = reply.getNextValueAsString(); + String signature = reply.getNextValueAsString(); + int modBits = reply.getNextValueAsInt(); + logWriter.println(" methodID=" + methodID + " name=" + name + + " signature=" + signature + " modBits=" + modBits); + if (name.equals("testMethod2")) { + targetMethodID = methodID; + } + } + assertAllDataRead(reply); + + // Set EventRequest + packet = new CommandPacket( + JDWPCommands.EventRequestCommandSet.CommandSetID, + JDWPCommands.EventRequestCommandSet.SetCommand); + packet.setNextValueAsByte(JDWPConstants.EventKind.METHOD_ENTRY); + packet.setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL); + packet.setNextValueAsInt(1); + packet.setNextValueAsByte((byte) 5); + packet.setNextValueAsString("*.InvokeMethodDebuggee"); + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "EventRequest::Set command"); + + int requestID = reply.getNextValueAsInt(); + logWriter.println(" EventRequest.Set: requestID=" + requestID); + assertAllDataRead(reply); + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + + long targetThreadID = 0; + // Wait event + CommandPacket event = debuggeeWrapper.vmMirror.receiveEvent(); + byte suspendPolicy = event.getNextValueAsByte(); + int events = event.getNextValueAsInt(); + logWriter.println(" EVENT_THREAD event: suspendPolicy=" + suspendPolicy + " events=" + events); + for (int i = 0; i < events; i++) { + byte eventKind = event.getNextValueAsByte(); + int newRequestID = event.getNextValueAsInt(); + long threadID = event.getNextValueAsThreadID(); + //Location location = + event.getNextValueAsLocation(); + logWriter.println(" EVENT_THREAD event " + i + ": eventKind=" + + eventKind + " requestID=" + newRequestID + " threadID=" + + threadID); + if (newRequestID == requestID) { + targetThreadID = threadID; + } + } + assertAllDataRead(event); + assertTrue("Invalid targetThreadID, must be != 0", targetThreadID != 0); + + // Let's clear event request + packet = new CommandPacket( + JDWPCommands.EventRequestCommandSet.CommandSetID, + JDWPCommands.EventRequestCommandSet.ClearCommand); + packet.setNextValueAsByte(JDWPConstants.EventKind.METHOD_ENTRY); + packet.setNextValueAsInt(requestID); + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "EventRequest::Clear command"); + assertAllDataRead(reply); + + // Make InvokeMethod without Exception + packet = new CommandPacket( + JDWPCommands.ClassTypeCommandSet.CommandSetID, + JDWPCommands.ClassTypeCommandSet.InvokeMethodCommand); + packet.setNextValueAsClassID(typeID); + packet.setNextValueAsThreadID(targetThreadID); + packet.setNextValueAsMethodID(targetMethodID); + packet.setNextValueAsInt(1); + packet.setNextValueAsValue(new Value(false)); + packet.setNextValueAsInt(0); + logWriter.println(" Send ClassType.InvokeMethod without Exception"); + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "ClassType::InvokeMethod command"); + + Value returnValue = reply.getNextValueAsValue(); + assertNotNull("Returned value is null", returnValue); + assertEquals("Invalid returned value,", 234, returnValue.getIntValue()); + logWriter.println(" ClassType.InvokeMethod: returnValue.getIntValue()=" + + returnValue.getIntValue()); + + TaggedObject exception = reply.getNextValueAsTaggedObject(); + assertNotNull("Returned exception is null", exception); + assertTrue("Invalid exception object ID:<" + exception.objectID + ">", exception.objectID == 0); + assertEquals("Invalid exception tag,", JDWPConstants.Tag.OBJECT_TAG, exception.tag + , JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG) + , JDWPConstants.Tag.getName(exception.tag)); + logWriter.println(" ClassType.InvokeMethod: exception.tag=" + + exception.tag + " exception.objectID=" + exception.objectID); + assertAllDataRead(reply); + + // Make InvokeMethod with Exception + packet = new CommandPacket( + JDWPCommands.ClassTypeCommandSet.CommandSetID, + JDWPCommands.ClassTypeCommandSet.InvokeMethodCommand); + packet.setNextValueAsClassID(typeID); + packet.setNextValueAsThreadID(targetThreadID); + packet.setNextValueAsMethodID(targetMethodID); + packet.setNextValueAsInt(1); + packet.setNextValueAsValue(new Value(true)); + packet.setNextValueAsInt(0); + logWriter.println(" Send ClassType.InvokeMethod with Exception"); + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "ClassType::InvokeMethod command"); + + returnValue = reply.getNextValueAsValue(); + logWriter.println(" ClassType.InvokeMethod: returnValue.getIntValue()=" + + returnValue.getIntValue()); + + exception = reply.getNextValueAsTaggedObject(); + assertNotNull("Returned exception is null", exception); + assertTrue("Invalid exception object ID:<" + exception.objectID + ">", exception.objectID != 0); + assertEquals("Invalid exception tag,", JDWPConstants.Tag.OBJECT_TAG, exception.tag + , JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG) + , JDWPConstants.Tag.getName(exception.tag)); + logWriter.println(" ClassType.InvokeMethod: exception.tag=" + + exception.tag + " exception.objectID=" + exception.objectID); + assertAllDataRead(reply); + + // Let's resume application + packet = new CommandPacket( + JDWPCommands.VirtualMachineCommandSet.CommandSetID, + JDWPCommands.VirtualMachineCommandSet.ResumeCommand); + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "VirtualMachine::Resume command"); + assertAllDataRead(reply); + + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + } + + /** + * This testcase exercises ClassType.InvokeMethod command. + *
At first the test starts debuggee. + *
Then does the following checks: + *
   - send ClassType.InvokeMethod command for method, + * which actually does not belong to passed class (taking into account + * inheritance). + *
Test expects that INVALID_METHODID error is returned by command. + */ + public void testInvokeMethod002() { + logWriter.println("==> testInvokeMethod002: START..."); + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + logWriter.println("\n==> Getting debuggeeRefTypeID... "); + String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/share/debuggee/InvokeMethodDebuggee;"; + logWriter.println("==> debuggeeSignature = |" + debuggeeSignature + "|+"); + long debuggeeRefTypeID = debuggeeWrapper.vmMirror.getClassID(debuggeeSignature); + if ( debuggeeRefTypeID == -1 ) { + logWriter.println("## FAILURE: Can not get debuggeeRefTypeID!"); + fail("Can not get debuggeeRefTypeID!"); + } + logWriter.println("==> debuggeeRefTypeID = " + debuggeeRefTypeID); + + logWriter.println("\n==> Getting testMethodID for debuggee method 'testMethod2'... "); + String testMethodName = "testMethod2"; + long testMethodID = + debuggeeWrapper.vmMirror.getMethodID(debuggeeRefTypeID, testMethodName); + if ( testMethodID == -1 ) { + logWriter.println("## FAILURE: Can not get methodID!"); + fail("Can not get methodID!"); + } + logWriter.println("==> testMethodID = " + testMethodID); + + logWriter.println("\n==> Setting EventRequest... "); + CommandPacket packet = new CommandPacket( + JDWPCommands.EventRequestCommandSet.CommandSetID, + JDWPCommands.EventRequestCommandSet.SetCommand); + packet.setNextValueAsByte(JDWPConstants.EventKind.METHOD_ENTRY); + packet.setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL); + packet.setNextValueAsInt(1); + packet.setNextValueAsByte((byte) 5); + packet.setNextValueAsString("*.InvokeMethodDebuggee"); + + ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "EventRequest::Set command"); + + int requestID = reply.getNextValueAsInt(); + logWriter.println(" EventRequest.Set: requestID=" + requestID); + + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + + logWriter.println("\n==> Getting targetThreadID... "); + long targetThreadID = 0; + // Wait event + CommandPacket event = debuggeeWrapper.vmMirror + .receiveEvent(); + byte suspendPolicy = event.getNextValueAsByte(); + int events = event.getNextValueAsInt(); + logWriter.println(" EVENT_THREAD event: suspendPolicy=" + suspendPolicy + + " events=" + events); + for (int i = 0; i < events; i++) { + byte eventKind = event.getNextValueAsByte(); + int newRequestID = event.getNextValueAsInt(); + long threadID = event.getNextValueAsThreadID(); + //Location location = + event.getNextValueAsLocation(); + logWriter.println(" EVENT_THREAD event " + i + ": eventKind=" + + eventKind + " requestID=" + newRequestID + " threadID=" + + threadID); + if (newRequestID == requestID) { + targetThreadID = threadID; + } + } + logWriter.println("==> targetThreadID = " + targetThreadID); + assertTrue("Invalid targetThreadID, must be != 0", targetThreadID != 0); + + logWriter.println("\n==> Clear EventRequest... "); + packet = new CommandPacket( + JDWPCommands.EventRequestCommandSet.CommandSetID, + JDWPCommands.EventRequestCommandSet.ClearCommand); + packet.setNextValueAsByte(JDWPConstants.EventKind.METHOD_ENTRY); + packet.setNextValueAsInt(requestID); + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "EventRequest::Clear command"); + + logWriter.println("\n==> Getting invalidClassRefTypeID... "); + String invalidClassSignature = "Lorg/apache/harmony/jpda/tests/jdwp/share/debuggee/testClass2;"; + logWriter.println("==> invalidClassSignature = |" + invalidClassSignature + "|+"); + long invalidClassRefTypeID = debuggeeWrapper.vmMirror.getClassID(invalidClassSignature); + if ( invalidClassRefTypeID == -1 ) { + logWriter.println("## FAILURE: Can not get invalidClassRefTypeID!"); + fail("Can not get invalidClassRefTypeID!"); + } + logWriter.println("==> invalidClassRefTypeID = " + invalidClassRefTypeID); + + logWriter.println + ("\n==> Send ClassType::InvokeMethod for invalidClassRefTypeID, testMethodID..."); + packet = new CommandPacket( + JDWPCommands.ClassTypeCommandSet.CommandSetID, + JDWPCommands.ClassTypeCommandSet.InvokeMethodCommand); + packet.setNextValueAsClassID(invalidClassRefTypeID); + packet.setNextValueAsThreadID(targetThreadID); + packet.setNextValueAsMethodID(testMethodID); + packet.setNextValueAsInt(1); + packet.setNextValueAsValue(new Value(false)); + packet.setNextValueAsInt(0); + reply = debuggeeWrapper.vmMirror.performCommand(packet); + short errorCode = reply.getErrorCode(); + if (errorCode == JDWPConstants.Error.NONE) { + logWriter.println + ("## FAILURE: ClassType::InvokeMethod command does NOT return expected error - INVALID_METHODID"); + + // next is only for extra info + logWriter.println("\n==> Result if invoke method:"); + Value returnValue = reply.getNextValueAsValue(); + if (returnValue != null) { + logWriter.println(" ClassType.InvokeMethod: returnValue.getIntValue()=" + + returnValue.getIntValue()); + } + + TaggedObject exception = reply.getNextValueAsTaggedObject(); + if (exception != null) { + logWriter.println(" ClassType.InvokeMethod: exception.tag=" + + exception.tag + " exception.objectID=" + exception.objectID); + if ( exception.objectID != 0 ) { + String exceptionSignature = getObjectSignature(exception.objectID); + logWriter.println(" exceptionSignature = " + exceptionSignature); + } + } + } + checkReplyPacket(reply, "ClassType::InvokeMethod command", JDWPConstants.Error.INVALID_METHODID); + + logWriter.println("==> PASSED: Expected error (INVALID_METHODID) is returned"); + logWriter.println("\n==> resumeDebuggee..."); + resumeDebuggee(); + + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + } + + /** + * This testcase exercises ClassType.InvokeMethod command. + *
At first the test starts debuggee. + *
Then does the following checks: + *
   - send ClassType.InvokeMethod command for method, + * which actually is not static method. + *
Test expects that INVALID_METHODID error is returned by command. + */ + public void testInvokeMethod003() { + logWriter.println("==> testInvokeMethod003: START..."); + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + logWriter.println("\n==> Getting debuggeeRefTypeID... "); + String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/share/debuggee/InvokeMethodDebuggee;"; + logWriter.println("==> debuggeeSignature = |" + debuggeeSignature + "|+"); + long debuggeeRefTypeID = debuggeeWrapper.vmMirror.getClassID(debuggeeSignature); + if ( debuggeeRefTypeID == -1 ) { + logWriter.println("## FAILURE: Can not get debuggeeRefTypeID!"); + fail("Can not get debuggeeRefTypeID!"); + } + logWriter.println("==> debuggeeRefTypeID = " + debuggeeRefTypeID); + + logWriter.println("\n==> Getting nonStaticMethodID for debuggee method 'testMethod1'... "); + String nonStaticMethodName = "testMethod1"; + long nonStaticMethodID = + debuggeeWrapper.vmMirror.getMethodID(debuggeeRefTypeID, nonStaticMethodName); + if ( nonStaticMethodID == -1 ) { + logWriter.println("## FAILURE: Can not get methodID!"); + fail("Can not get methodID!"); + } + logWriter.println("==> nonStaticMethodID = " + nonStaticMethodID); + + logWriter.println("\n==> Setting EventRequest... "); + CommandPacket packet = new CommandPacket( + JDWPCommands.EventRequestCommandSet.CommandSetID, + JDWPCommands.EventRequestCommandSet.SetCommand); + packet.setNextValueAsByte(JDWPConstants.EventKind.METHOD_ENTRY); + packet.setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL); + packet.setNextValueAsInt(1); + packet.setNextValueAsByte((byte) 5); + packet.setNextValueAsString("*.InvokeMethodDebuggee"); + + ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "EventRequest::Set command"); + + int requestID = reply.getNextValueAsInt(); + logWriter.println(" EventRequest.Set: requestID=" + requestID); + + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + + logWriter.println("\n==> Getting targetThreadID... "); + long targetThreadID = 0; + // Wait event + CommandPacket event = debuggeeWrapper.vmMirror + .receiveEvent(); + byte suspendPolicy = event.getNextValueAsByte(); + int events = event.getNextValueAsInt(); + logWriter.println(" EVENT_THREAD event: suspendPolicy=" + suspendPolicy + + " events=" + events); + for (int i = 0; i < events; i++) { + byte eventKind = event.getNextValueAsByte(); + int newRequestID = event.getNextValueAsInt(); + long threadID = event.getNextValueAsThreadID(); + //Location location = + event.getNextValueAsLocation(); + logWriter.println(" EVENT_THREAD event " + i + ": eventKind=" + + eventKind + " requestID=" + newRequestID + " threadID=" + + threadID); + if (newRequestID == requestID) { + targetThreadID = threadID; + } + } + logWriter.println("==> targetThreadID = " + targetThreadID); + assertTrue("Invalid targetThreadID, must be != 0", targetThreadID != 0); + + logWriter.println("\n==> Clear EventRequest... "); + packet = new CommandPacket( + JDWPCommands.EventRequestCommandSet.CommandSetID, + JDWPCommands.EventRequestCommandSet.ClearCommand); + packet.setNextValueAsByte(JDWPConstants.EventKind.METHOD_ENTRY); + packet.setNextValueAsInt(requestID); + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "EventRequest::Clear command"); + + logWriter.println + ("\n==> Send ClassType::InvokeMethod for debuggeeRefTypeID, nonStaticMethodID..."); + packet = new CommandPacket( + JDWPCommands.ClassTypeCommandSet.CommandSetID, + JDWPCommands.ClassTypeCommandSet.InvokeMethodCommand); + packet.setNextValueAsClassID(debuggeeRefTypeID); + packet.setNextValueAsThreadID(targetThreadID); + packet.setNextValueAsMethodID(nonStaticMethodID); + packet.setNextValueAsInt(1); + packet.setNextValueAsValue(new Value(false)); + packet.setNextValueAsInt(0); + reply = debuggeeWrapper.vmMirror.performCommand(packet); + short errorCode = reply.getErrorCode(); + if (errorCode == JDWPConstants.Error.NONE) { + logWriter.println + ("## FAILURE: ClassType::InvokeMethod command does NOT return expected error - INVALID_METHODID"); + + // next is only for extra info + logWriter.println("\n==> Result if invoke method:"); + Value returnValue = reply.getNextValueAsValue(); + if (returnValue != null) { + logWriter.println(" ClassType.InvokeMethod: returnValue.getIntValue()=" + + returnValue.getIntValue()); + } + + TaggedObject exception = reply.getNextValueAsTaggedObject(); + if (exception != null) { + logWriter.println(" ClassType.InvokeMethod: exception.tag=" + + exception.tag + " exception.objectID=" + exception.objectID); + if ( exception.objectID != 0 ) { + String exceptionSignature = getObjectSignature(exception.objectID); + logWriter.println(" exceptionSignature = " + exceptionSignature); + } + } + } + checkReplyPacket(reply, "ClassType::InvokeMethod command", JDWPConstants.Error.INVALID_METHODID); + + logWriter.println("==> PASSED: Expected error (INVALID_METHODID) is returned"); + logWriter.println("\n==> resumeDebuggee..."); + resumeDebuggee(); + + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(InvokeMethodTest.class); + } +} Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/InvokeMethodTest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/JDWPClassTypeTestCase.java URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/JDWPClassTypeTestCase.java?view=auto&rev=480141 ============================================================================== --- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/JDWPClassTypeTestCase.java (added) +++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/JDWPClassTypeTestCase.java Tue Nov 28 09:49:08 2006 @@ -0,0 +1,136 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Anton V. Karnachuk + * @version $Revision: 1.4 $ + */ + +/** + * Created on 11.02.2005 + */ +package org.apache.harmony.jpda.tests.jdwp.ClassType; + +import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; +import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; +import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants; +import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; +import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; + + +/** + * Super class of some JDWP unit tests for JDWP ClassType command set. + */ +public class JDWPClassTypeTestCase extends JDWPSyncTestCase { + + /** + * Returns full name of debuggee class which is used by + * testcases in this test. + * @return full name of debuggee class. + */ + protected String getDebuggeeClassName() { + return "org.apache.harmony.jpda.tests.jdwp.ClassType.ClassTypeDebuggee"; + } + + /** + * Returns signature of debuggee class which is used by + * testcases in this test. + * @return signature of debuggee class. + */ + protected String getDebuggeeSignature() { + return "Lorg/apache/harmony/jpda/tests/jdwp/ClassType/ClassTypeDebuggee;"; + } + + class FieldInfo { + private long fieldID; + private String name; + private String signature; + private int modBits; + + /** + * @return Returns the fieldID. + */ + public long getFieldID() { + return fieldID; + } + + /** + * @return Returns the modBits. + */ + public int getModBits() { + return modBits; + } + + /** + * @return Returns the name. + */ + public String getName() { + return name; + } + + /** + * @return Returns the signature. + */ + public String getSignature() { + return signature; + } + + public FieldInfo(long fieldID, String name, String signature, + int modBits) { + super(); + this.fieldID = fieldID; + this.name = name; + this.signature = signature; + this.modBits = modBits; + } + + public String toString() { + return "fieldID=" + fieldID + "; name='" + name + "'; signature='" + signature + + "'; modbits=" + modBits; + } + + } + + /** + * Returns for specified class array with information about fields of this class. + *
Each element of array contains: + *
Field ID, Field name, Field signature, Field modifier bit flags; + * @param refType - ReferenceTypeID, defining class. + * @return array with information about fields. + */ + protected FieldInfo[] jdwpGetFields(long refType) { + CommandPacket packet = new CommandPacket( + JDWPCommands.ReferenceTypeCommandSet.CommandSetID, + JDWPCommands.ReferenceTypeCommandSet.FieldsCommand); + packet.setNextValueAsReferenceTypeID(refType); + + ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); + assertTrue(reply.getErrorCode() == JDWPConstants.Error.NONE); + + int declared = reply.getNextValueAsInt(); + FieldInfo[] fields = new FieldInfo[declared]; + for (int i = 0; i < declared; i++) { + fields[i] = + new FieldInfo(reply.getNextValueAsFieldID(), + reply.getNextValueAsString(), + reply.getNextValueAsString(), + reply.getNextValueAsInt()); + } + return fields; + } + +} \ No newline at end of file Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/JDWPClassTypeTestCase.java ------------------------------------------------------------------------------ svn:eol-style = native Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/NewInstanceTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/NewInstanceTest.java?view=auto&rev=480141 ============================================================================== --- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/NewInstanceTest.java (added) +++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/NewInstanceTest.java Tue Nov 28 09:49:08 2006 @@ -0,0 +1,410 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Viacheslav G. Rybalov + * @version $Revision: 1.4 $ + */ + +/** + * Created on 11.03.2005 + */ +package org.apache.harmony.jpda.tests.jdwp.ClassType; + +import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; +import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; +import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants; +import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; +import org.apache.harmony.jpda.tests.framework.jdwp.TaggedObject; +import org.apache.harmony.jpda.tests.framework.jdwp.Value; +import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; +import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; + + +/** + * JDWP unit test for ClassType.NewInstance command. + */ +public class NewInstanceTest extends JDWPSyncTestCase { + + protected String getDebuggeeClassName() { + return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.InvokeMethodDebuggee"; + } + + /** + * This testcase exercises ClassType.NewInstance command. + *
At first the test starts debuggee. + *
Then does the following checks: + *
   - send ClassType.NewInstance command for class, + * constructor of which should not throw any Exception, and checks, + * that returned new object has expected attributes and returned + * exception object is null; + *
   - send ClassType.NewInstance command for class, + * constructor of which should throw some Exception, and checks, + * that returned new object is null and returned exception object + * is not null and has expected attributes; + */ + public void testNewInstance001() { + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + // Get referenceTypeID + CommandPacket packet = new CommandPacket( + JDWPCommands.VirtualMachineCommandSet.CommandSetID, + JDWPCommands.VirtualMachineCommandSet.ClassesBySignatureCommand); + String classSig = "Lorg/apache/harmony/jpda/tests/jdwp/share/debuggee/testClass2;"; + packet.setNextValueAsString(classSig); + ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "VirtualMachine::ClassesBySignature command"); + + int classes = reply.getNextValueAsInt(); + assertTrue(classes == 1); //this class may be loaded only once + byte refTypeTag = reply.getNextValueAsByte(); + long typeID = reply.getNextValueAsReferenceTypeID(); + int status = reply.getNextValueAsInt(); + logWriter.println(" VirtualMachine.ClassesBySignature: classes=" + + classes + "; refTypeTag=" + refTypeTag + "; typeID= " + typeID + + "; status=" + status); + + assertAllDataRead(reply); + assertEquals("VirtualMachine::ClassesBySignature returned invalid TypeTag,", JDWPConstants.TypeTag.CLASS, refTypeTag + , JDWPConstants.TypeTag.getName(JDWPConstants.TypeTag.CLASS) + , JDWPConstants.TypeTag.getName(refTypeTag)); + + // Get methodID + packet = new CommandPacket( + JDWPCommands.ReferenceTypeCommandSet.CommandSetID, + JDWPCommands.ReferenceTypeCommandSet.MethodsCommand); + packet.setNextValueAsClassID(typeID); + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "ReferenceType::Methods command"); + + int declared = reply.getNextValueAsInt(); + logWriter.println(" ReferenceType.Methods: declared=" + declared); + long targetMethodID = 0; + for (int i = 0; i < declared; i++) { + long methodID = reply.getNextValueAsMethodID(); + String name = reply.getNextValueAsString(); + String signature = reply.getNextValueAsString(); + int modBits = reply.getNextValueAsInt(); + logWriter.println(" methodID=" + methodID + "; name=" + name + + "; signature=" + signature + "; modBits=" + modBits); + if (name.equals("")) { + targetMethodID = methodID; + } + } + assertAllDataRead(reply); + + // Set EventRequest + packet = new CommandPacket( + JDWPCommands.EventRequestCommandSet.CommandSetID, + JDWPCommands.EventRequestCommandSet.SetCommand); + packet.setNextValueAsByte(JDWPConstants.EventKind.METHOD_ENTRY); + packet.setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL); + packet.setNextValueAsInt(1); + packet.setNextValueAsByte((byte) 5); + packet.setNextValueAsString("*.InvokeMethodDebuggee"); + + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "EventRequest::Set command"); + + int requestID = reply.getNextValueAsInt(); + logWriter.println(" EventRequest.Set: requestID=" + requestID); + assertAllDataRead(reply); + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + + long targetThreadID = 0; + // Wait event + CommandPacket event = debuggeeWrapper.vmMirror + .receiveCertainEvent(JDWPConstants.EventKind.METHOD_ENTRY); + byte suspendPolicy = event.getNextValueAsByte(); + int events = event.getNextValueAsInt(); + logWriter.println(" EVENT_THREAD event: suspendPolicy=" + suspendPolicy + + " events=" + events); + for (int i = 0; i < events; i++) { + byte eventKind = event.getNextValueAsByte(); + int newRequestID = event.getNextValueAsInt(); + long threadID = event.getNextValueAsThreadID(); + //Location location = + event.getNextValueAsLocation(); + logWriter.println(" EVENT_THREAD event " + i + ": eventKind=" + + eventKind + "; requestID=" + newRequestID + "; threadID=" + + threadID); + if (newRequestID == requestID) { + targetThreadID = threadID; + } + } + assertAllDataRead(event); + assertTrue("Invalid targetThreadID, must be != 0", targetThreadID != 0); + + // Let's clear event request + packet = new CommandPacket( + JDWPCommands.EventRequestCommandSet.CommandSetID, + JDWPCommands.EventRequestCommandSet.ClearCommand); + packet.setNextValueAsByte(JDWPConstants.EventKind.METHOD_ENTRY); + packet.setNextValueAsInt(requestID); + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "EventRequest::Clear command"); + assertAllDataRead(reply); + + // Make NewInstance without Exception + packet = new CommandPacket( + JDWPCommands.ClassTypeCommandSet.CommandSetID, + JDWPCommands.ClassTypeCommandSet.NewInstanceCommand); + packet.setNextValueAsClassID(typeID); + packet.setNextValueAsThreadID(targetThreadID); + packet.setNextValueAsMethodID(targetMethodID); + packet.setNextValueAsInt(1); + packet.setNextValueAsValue(new Value(false)); + packet.setNextValueAsInt(0); + logWriter.println(" Send ClassType.NewInstance (without Exception)"); + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "ClassType::NewInstance command"); + + TaggedObject newObject = reply.getNextValueAsTaggedObject(); + logWriter.println(" ClassType.NewInstance: newObject.tag=" + + newObject.tag + "; newObject.objectID=" + newObject.objectID); + TaggedObject exception = reply.getNextValueAsTaggedObject(); + logWriter.println(" ClassType.NewInstance: exception.tag=" + + exception.tag + "; exception.objectID=" + exception.objectID); + + assertNotNull("newObject is null", newObject); + assertTrue("newObject.objectID is 0", newObject.objectID != 0); + assertEquals("ClassType::NewInstance returned invalid newObject.tag,", JDWPConstants.Tag.OBJECT_TAG, newObject.tag + , JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG) + , JDWPConstants.Tag.getName(newObject.tag)); + + assertNotNull("exception is null", newObject); + assertEquals("ClassType::NewInstance returned invalid exception.objectID,", 0, exception.objectID); + assertTrue(exception.tag == JDWPConstants.Tag.OBJECT_TAG); + assertAllDataRead(reply); + + // Let's check object reference + packet = new CommandPacket( + JDWPCommands.ObjectReferenceCommandSet.CommandSetID, + JDWPCommands.ObjectReferenceCommandSet.ReferenceTypeCommand); + packet.setNextValueAsObjectID(newObject.objectID); + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "ObjectReference::ReferenceType command"); + + byte newRefTypeTag = reply.getNextValueAsByte(); + long newTypeID = reply.getNextValueAsReferenceTypeID(); + logWriter.println(" ObjectReference.ReferenceType: refTypeTag=" + + newRefTypeTag + "; typeID= " + newTypeID); + assertEquals("ObjectReference::ReferenceType returned invalid newRefTypeTag,", + JDWPConstants.TypeTag.CLASS, newRefTypeTag, + JDWPConstants.TypeTag.getName(JDWPConstants.TypeTag.CLASS), + JDWPConstants.TypeTag.getName(newRefTypeTag)); + assertEquals("Invalid type ID,", typeID, newTypeID); + assertAllDataRead(reply); + + // Make NewInstance with Exception + packet = new CommandPacket( + JDWPCommands.ClassTypeCommandSet.CommandSetID, + JDWPCommands.ClassTypeCommandSet.NewInstanceCommand); + packet.setNextValueAsClassID(typeID); + packet.setNextValueAsThreadID(targetThreadID); + packet.setNextValueAsMethodID(targetMethodID); + packet.setNextValueAsInt(1); + packet.setNextValueAsValue(new Value(true)); + packet.setNextValueAsInt(0); + logWriter.println(" Send ClassType.NewInstance (with Exception)"); + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "ClassType::NewInstance command"); + + newObject = reply.getNextValueAsTaggedObject(); + logWriter.println(" ClassType.NewInstance: newObject.tag=" + + newObject.tag + "; newObject.objectID=" + newObject.objectID); + exception = reply.getNextValueAsTaggedObject(); + logWriter.println(" ClassType.NewInstance: exception.tag=" + + exception.tag + "; exception.objectID=" + exception.objectID); + assertNotNull("newObject is null", newObject); + assertEquals("ClassType::NewInstance returned invalid newObject.objectID,", + 0, newObject.objectID); + assertEquals("ClassType::NewInstance returned invalid invalid newObject.tag,", + JDWPConstants.Tag.OBJECT_TAG, newObject.tag, + JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG), + JDWPConstants.Tag.getName(newObject.tag)); + + assertNotNull("ClassType::NewInstance returned invalid exception = null", newObject); + assertTrue("ClassType::NewInstance returned invalid exception.objectID = 0", + exception.objectID != 0); + assertEquals("ClassType::NewInstance returned invalid invalid exception.tag,", + JDWPConstants.Tag.OBJECT_TAG, exception.tag, + JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG), + JDWPConstants.Tag.getName(exception.tag)); + assertAllDataRead(reply); + + // Let's resume application + packet = new CommandPacket( + JDWPCommands.VirtualMachineCommandSet.CommandSetID, + JDWPCommands.VirtualMachineCommandSet.ResumeCommand); + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "VirtualMachine::Resume command"); + assertAllDataRead(reply); + + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + } + + /** + * This testcase exercises ClassType.NewInstance command. + *
At first the test starts debuggee. + *
Then does the following check: + *
   - send ClassType.NewInstance command for class + * and passes invalid arguments' list for constructor. + *
The testcase expects that ILLEGAL_ARGUMENT error is returned. + */ + public void testNewInstance002() { + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + // Get referenceTypeID + CommandPacket packet = new CommandPacket( + JDWPCommands.VirtualMachineCommandSet.CommandSetID, + JDWPCommands.VirtualMachineCommandSet.ClassesBySignatureCommand); + String classSig = "Lorg/apache/harmony/jpda/tests/jdwp/share/debuggee/InvokeMethodDebuggee$testClass1;"; + packet.setNextValueAsString(classSig); + ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "VirtualMachine::ClassesBySignature command"); + + int classes = reply.getNextValueAsInt(); + assertEquals("VirtualMachine::ClassesBySignature returned invalid cluss number,", + 1, classes); //this class may be loaded only once + byte refTypeTag = reply.getNextValueAsByte(); + long typeID = reply.getNextValueAsReferenceTypeID(); + int status = reply.getNextValueAsInt(); + logWriter.println(" VirtualMachine.ClassesBySignature: classes=" + + classes + "; refTypeTag=" + refTypeTag + "; typeID= " + typeID + + "; status=" + status); + + assertAllDataRead(reply); + assertEquals("VirtualMachine::ClassesBySignature returned invalid TypeTag,", + JDWPConstants.TypeTag.CLASS, refTypeTag, + JDWPConstants.TypeTag.getName(JDWPConstants.TypeTag.CLASS), + JDWPConstants.TypeTag.getName(refTypeTag)); + + // Get methodID + packet = new CommandPacket( + JDWPCommands.ReferenceTypeCommandSet.CommandSetID, + JDWPCommands.ReferenceTypeCommandSet.MethodsCommand); + packet.setNextValueAsClassID(typeID); + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "ReferenceType::Methods command"); + + int declared = reply.getNextValueAsInt(); + logWriter.println(" ReferenceType.Methods: declared=" + declared); + long targetMethodID = 0; + for (int i = 0; i < declared; i++) { + long methodID = reply.getNextValueAsMethodID(); + String name = reply.getNextValueAsString(); + String signature = reply.getNextValueAsString(); + int modBits = reply.getNextValueAsInt(); + logWriter.println(" methodID=" + methodID + "; name=" + name + + "; signature=" + signature + "; modBits=" + modBits); + if (name.equals("")) { + targetMethodID = methodID; + } + } + assertAllDataRead(reply); + + // Set EventRequest + packet = new CommandPacket( + JDWPCommands.EventRequestCommandSet.CommandSetID, + JDWPCommands.EventRequestCommandSet.SetCommand); + packet.setNextValueAsByte(JDWPConstants.EventKind.METHOD_ENTRY); + packet.setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL); + packet.setNextValueAsInt(1); + packet.setNextValueAsByte((byte) 5); + packet.setNextValueAsString("*.InvokeMethodDebuggee"); + + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "EventRequest::Set command"); + + int requestID = reply.getNextValueAsInt(); + logWriter.println(" EventRequest.Set: requestID=" + requestID); + assertAllDataRead(reply); + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + + long targetThreadID = 0; + // Wait event + CommandPacket event = debuggeeWrapper.vmMirror + .receiveCertainEvent(JDWPConstants.EventKind.METHOD_ENTRY); + byte suspendPolicy = event.getNextValueAsByte(); + int events = event.getNextValueAsInt(); + logWriter.println(" EVENT_THREAD event: suspendPolicy=" + suspendPolicy + + " events=" + events); + for (int i = 0; i < events; i++) { + byte eventKind = event.getNextValueAsByte(); + int newRequestID = event.getNextValueAsInt(); + long threadID = event.getNextValueAsThreadID(); + //Location location = + event.getNextValueAsLocation(); + logWriter.println(" EVENT_THREAD event " + i + ": eventKind=" + + eventKind + "; requestID=" + newRequestID + "; threadID=" + + threadID); + if (newRequestID == requestID) { + targetThreadID = threadID; + } + } + assertAllDataRead(event); + assertTrue("Invalid targetThreadID, must be != 0", targetThreadID != 0); + + // Let's clear event request + packet = new CommandPacket( + JDWPCommands.EventRequestCommandSet.CommandSetID, + JDWPCommands.EventRequestCommandSet.ClearCommand); + packet.setNextValueAsByte(JDWPConstants.EventKind.METHOD_ENTRY); + packet.setNextValueAsInt(requestID); + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "EventRequest::Clear command"); + assertAllDataRead(reply); + + // Make NewInstance without Exception + packet = new CommandPacket( + JDWPCommands.ClassTypeCommandSet.CommandSetID, + JDWPCommands.ClassTypeCommandSet.NewInstanceCommand); + packet.setNextValueAsClassID(typeID); + packet.setNextValueAsThreadID(targetThreadID); + packet.setNextValueAsMethodID(targetMethodID); + packet.setNextValueAsInt(0); // Providing of 'this' arg missed! + packet.setNextValueAsInt(0); // This int value will be interpreted as + // reference!? + logWriter.println(" Send ClassType.NewInstance"); + reply = debuggeeWrapper.vmMirror.performCommand(packet); + + short error = reply.getErrorCode(); + logWriter.println(" ClassType.NewInstance: ErrorCode=" + error + + "(" + JDWPConstants.Error.getName(error) + ")"); + assertEquals("ClassType.NewInstance returned invalid error code,", + JDWPConstants.Error.ILLEGAL_ARGUMENT, error, + JDWPConstants.Error.getName(JDWPConstants.Error.ILLEGAL_ARGUMENT), + JDWPConstants.Error.getName(error)); + logWriter.println(" It is EXPECTED ERROR!"); + assertAllDataRead(reply); + + // Let's resume application + packet = new CommandPacket( + JDWPCommands.VirtualMachineCommandSet.CommandSetID, + JDWPCommands.VirtualMachineCommandSet.ResumeCommand); + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "VirtualMachine::Resume command"); + assertAllDataRead(reply); + + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(NewInstanceTest.class); + } +} \ No newline at end of file Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/NewInstanceTest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/SetValues002Debuggee.java URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/SetValues002Debuggee.java?view=auto&rev=480141 ============================================================================== --- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/SetValues002Debuggee.java (added) +++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/SetValues002Debuggee.java Tue Nov 28 09:49:08 2006 @@ -0,0 +1,85 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Anatoly F. Bondarenko + * @version $Revision: 1.2 $ + */ + +/** + * Created on 05.07.2005 + */ +package org.apache.harmony.jpda.tests.jdwp.ClassType; + +import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; +import org.apache.harmony.jpda.tests.share.SyncDebuggee; + +public class SetValues002Debuggee extends SyncDebuggee { + + static String passedStatus = "PASSED"; + static String failedStatus = "FAILED"; + static String status = passedStatus; + + static SetValues002Debuggee SetValues002DebuggeeObject; + + static SetValues002Debuggee_ExtraClass objectField; + static SetValues002Debuggee_ExtraClass objectFieldCopy; + + public void run() { + logWriter.println("--> Debuggee: SetValues002Debuggee: START"); + SetValues002DebuggeeObject = new SetValues002Debuggee(); + objectField = new SetValues002Debuggee_ExtraClass(); + objectFieldCopy = objectField; + + logWriter.println("\n--> Debuggee: Before ClassType::SetValues command:"); + logWriter.println("--> objectField value = " + objectField); + logWriter.println("--> value to set = " + SetValues002DebuggeeObject); + + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + + logWriter.println("\n--> Debuggee: After ClassType::SetValues command:"); + logWriter.println("--> objectField value = " + objectField); + if ( ! objectFieldCopy.equals(objectField) ) { + logWriter.println("##> Debuggee: FAILURE: Unexpected value"); + logWriter.println("##> Expected value = " + objectFieldCopy); + status = failedStatus; + } else { + logWriter.println("--> Debuggee: PASSED: Expected value"); + } + + if ( status.equals(failedStatus) ) { + logWriter.println("\n##> Debuggee: Check status = FAILED"); + } else { + logWriter.println("\n--> Debuggee: Check status = PASSED"); + } + + logWriter.println("--> Debuggee: Send check status for SetValues002Test...\n"); + synchronizer.sendMessage(status); + + logWriter.println("--> Debuggee: SetValues002Debuggee: FINISH"); + } + + public static void main(String [] args) { + runDebuggee(SetValues002Debuggee.class); + } +} + +class SetValues002Debuggee_ExtraClass { + +} + Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/SetValues002Debuggee.java ------------------------------------------------------------------------------ svn:eol-style = native Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/SetValues002Test.java URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/SetValues002Test.java?view=auto&rev=480141 ============================================================================== --- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/SetValues002Test.java (added) +++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/SetValues002Test.java Tue Nov 28 09:49:08 2006 @@ -0,0 +1,169 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Anatoly F. Bondarenko + * @version $Revision: 1.6 $ + */ + +/** + * Created on 05.07.2005 + */ +package org.apache.harmony.jpda.tests.jdwp.ClassType; + +import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; +import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; +import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants; +import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; +import org.apache.harmony.jpda.tests.framework.jdwp.Value; +import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; +import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; + + +/** + * JDWP unit test for ClassType.SetValues command with incorrect types of values. + */ +public class SetValues002Test extends JDWPSyncTestCase { + + static final int testStatusPassed = 0; + static final int testStatusFailed = -1; + static final String thisCommandName = "ClassType::SetValues command"; + static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ClassType/SetValues002Debuggee;"; + + protected String getDebuggeeClassName() { + return "org.apache.harmony.jpda.tests.jdwp.ClassType.SetValues002Debuggee"; + } + + /** + * The test checks ClassType.SetValues command for + * field of Debuggee class with value which has other + * referenceType than field to set. + * The test expects the field should not be set. + */ + public void testSetValues002() { + String thisTestName = "testSetValues002"; + logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START..."); + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + CommandPacket classesBySignatureCommand = new CommandPacket( + JDWPCommands.VirtualMachineCommandSet.CommandSetID, + JDWPCommands.VirtualMachineCommandSet.ClassesBySignatureCommand); + classesBySignatureCommand.setNextValueAsString(debuggeeSignature); + ReplyPacket classesBySignatureReply = + debuggeeWrapper.vmMirror.performCommand(classesBySignatureCommand); + classesBySignatureCommand = null; + checkReplyPacket(classesBySignatureReply, "VirtualMachine::ClassesBySignature command"); + + classesBySignatureReply.getNextValueAsInt(); + // Number of returned reference types - is NOt used here + + classesBySignatureReply.getNextValueAsByte(); + // refTypeTag of class - is NOt used here + + long refTypeID = classesBySignatureReply.getNextValueAsReferenceTypeID(); + classesBySignatureReply = null; + + logWriter.println("=> Debuggee class = " + getDebuggeeClassName()); + logWriter.println("=> referenceTypeID for Debuggee class = " + refTypeID); + + String checkedFieldNames[] = { + "SetValues002DebuggeeObject", + "objectField", + }; + long checkedFieldIDs[] = checkFields(refTypeID, checkedFieldNames); + int checkedFieldsNumber = checkedFieldNames.length; + + logWriter.println + ("=> Send ReferenceType::GetValues command and get ObjectID for value to set..."); + + CommandPacket getValuesCommand = new CommandPacket( + JDWPCommands.ReferenceTypeCommandSet.CommandSetID, + JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand); + getValuesCommand.setNextValueAsReferenceTypeID(refTypeID); + getValuesCommand.setNextValueAsInt(1); + getValuesCommand.setNextValueAsFieldID(checkedFieldIDs[0]); + ReplyPacket getValuesReply = + debuggeeWrapper.vmMirror.performCommand(getValuesCommand); + getValuesCommand = null; + checkReplyPacket(getValuesReply, "ReferenceType::GetValues command"); + + int returnedValuesNumber = getValuesReply.getNextValueAsInt(); + logWriter.println("=> Returned values number = " + returnedValuesNumber); + assertEquals("ReferenceType::GetValues returned invalid values number,", + 1, returnedValuesNumber); + + Value objectFieldValueToSet = getValuesReply.getNextValueAsValue(); + byte objectFieldValueToSetTag = objectFieldValueToSet.getTag(); + logWriter.println + ("=> Returned field value tag for checked object= " + objectFieldValueToSetTag + + "(" + JDWPConstants.Tag.getName(objectFieldValueToSetTag) + ")"); + assertEquals("ReferenceType::GetValues returned invalid value tag,", + JDWPConstants.Tag.OBJECT_TAG, objectFieldValueToSetTag, + JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG), + JDWPConstants.Tag.getName(objectFieldValueToSetTag)); + + long objectFieldID = objectFieldValueToSet.getLongValue(); + logWriter.println("=> Returned ObjectID = " + objectFieldID); + logWriter.println + ("=> CHECK: send " + thisCommandName + + " for Debuggee class with value which has other referenceType than field to set..."); + + CommandPacket checkedCommand = new CommandPacket( + JDWPCommands.ClassTypeCommandSet.CommandSetID, + JDWPCommands.ClassTypeCommandSet.SetValuesCommand); + checkedCommand.setNextValueAsClassID(refTypeID); + checkedCommand.setNextValueAsInt(checkedFieldsNumber-1); + int fieldIndex = 1; + for (; fieldIndex < checkedFieldsNumber; fieldIndex++) { + checkedCommand.setNextValueAsFieldID(checkedFieldIDs[fieldIndex]); + switch ( fieldIndex ) { + case 1: // objectField + checkedCommand.setNextValueAsObjectID(objectFieldID); + break; + } + } + ReplyPacket checkedReply = + debuggeeWrapper.vmMirror.performCommand(checkedCommand); + checkedCommand = null; + + short errorCode = checkedReply.getErrorCode(); + if ( errorCode == JDWPConstants.Error.NONE ) { + logWriter.println("=> " + thisCommandName + + " run without any ERROR!"); + } else { + logWriter.println("=> " + thisCommandName + + " returns ERROR = " + errorCode + + "(" + JDWPConstants.Error.getName(errorCode) + ")"); + } + + logWriter.println("=> Wait for Debuggee's status about check for set field..."); + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + boolean debuggeeStatus = synchronizer.receiveMessage("PASSED"); + if ( ! debuggeeStatus ) { + logWriter.println("## " + thisTestName + ": Debuggee returned status FAILED"); + fail("Debuggee returned status FAILED"); + } else { + logWriter.println("=> " + thisTestName + ": Debuggee returned status PASSED"); + } + + logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": OK"); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(SetValues002Test.class); + } +} Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/SetValues002Test.java ------------------------------------------------------------------------------ svn:eol-style = native Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/SetValuesTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/SetValuesTest.java?view=auto&rev=480141 ============================================================================== --- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/SetValuesTest.java (added) +++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/SetValuesTest.java Tue Nov 28 09:49:08 2006 @@ -0,0 +1,185 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Anton V. Karnachuk + * @version $Revision: 1.3 $ + */ + +/** + * Created on 10.02.2005 + */ +package org.apache.harmony.jpda.tests.jdwp.ClassType; + +import java.io.UnsupportedEncodingException; + +import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; +import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; +import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; +import org.apache.harmony.jpda.tests.framework.jdwp.Value; +import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; + + + +/** + * JDWP unit test for ClassType.SetValues command. + */ + +public class SetValuesTest extends JDWPClassTypeTestCase { + + /** + * Starts this test by junit.textui.TestRunner.run() method. + */ + public static void main(String[] args) { + junit.textui.TestRunner.run(SetValuesTest.class); + } + + /** + * This testcase exercises ClassType.SetValues command. + *
Starts ClassTypeDebuggee. + *
Receives all fields from debuggee with ReferenceType.fields command. + * Then sets values for these fields with ClassType.SetValues command + * and checks set values using ReferenceType.GetValues command. + */ + public void testSetValues001() throws UnsupportedEncodingException { + logWriter.println("testSetValues001 started"); + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + long classID = getClassIDBySignature(getDebuggeeSignature()); + + FieldInfo[] fields = jdwpGetFieldIDs(classID); + + for (int i = 0; i < fields.length; i++) { + FieldInfo field = fields[i]; + //logWriter.println(field.toString()); + testField(classID, field); + } + } + + private void testField(long classID, FieldInfo fieldInfo) throws UnsupportedEncodingException { + + //System.err.println("testField: "+fieldInfo.toString()); + // if field has primitive type + if (fieldInfo.getSignature().length()>=1) { + switch (fieldInfo.getSignature().charAt(0)) { + case 'B': // byte + testField(classID, fieldInfo, new Value(Byte.MIN_VALUE)); + testField(classID, fieldInfo, new Value(Byte.MAX_VALUE)); + testField(classID, fieldInfo, new Value((byte)0)); + break; + case 'C': // char + testField(classID, fieldInfo, new Value((char)Character.MAX_VALUE)); + testField(classID, fieldInfo, new Value((char)Character.MIN_VALUE)); + break; + case 'F': // float + testField(classID, fieldInfo, new Value((float)Float.MIN_VALUE)); + testField(classID, fieldInfo, new Value((float)Float.MAX_VALUE)); + testField(classID, fieldInfo, new Value((float)Float.NaN)); + testField(classID, fieldInfo, new Value((float)Float.NEGATIVE_INFINITY)); + testField(classID, fieldInfo, new Value((float)Float.POSITIVE_INFINITY)); + testField(classID, fieldInfo, new Value((float)0)); + break; + case 'D': // double + testField(classID, fieldInfo, new Value((double)Double.MIN_VALUE)); + testField(classID, fieldInfo, new Value((double)Double.MAX_VALUE)); + testField(classID, fieldInfo, new Value((double)Double.NaN)); + testField(classID, fieldInfo, new Value((double)Double.NEGATIVE_INFINITY)); + testField(classID, fieldInfo, new Value((double)Double.POSITIVE_INFINITY)); + testField(classID, fieldInfo, new Value((double)0)); + break; + case 'I': // int + testField(classID, fieldInfo, new Value((int)Integer.MIN_VALUE)); + testField(classID, fieldInfo, new Value((int)Integer.MAX_VALUE)); + testField(classID, fieldInfo, new Value((int)0)); + break; + case 'J': // long + testField(classID, fieldInfo, new Value((long)Long.MIN_VALUE)); + testField(classID, fieldInfo, new Value((long)Long.MAX_VALUE)); + testField(classID, fieldInfo, new Value((long)0)); + break; + case 'S': // short + testField(classID, fieldInfo, new Value((short)Short.MIN_VALUE)); + testField(classID, fieldInfo, new Value((short)Short.MAX_VALUE)); + testField(classID, fieldInfo, new Value((short)0)); + break; + case 'Z': // boolean + testField(classID, fieldInfo, new Value((boolean)Boolean.FALSE.booleanValue())); + testField(classID, fieldInfo, new Value((boolean)Boolean.TRUE.booleanValue())); + break; + } + } + } + + private void testField(long classID, FieldInfo fieldInfo, Value value) throws UnsupportedEncodingException { + + logWriter.println("\n==> testField: "); + logWriter.println(" classID = " + classID); + logWriter.println(" fieldInfo = " + fieldInfo); + logWriter.println(" value to set = " + value); + CommandPacket packet = new CommandPacket( + JDWPCommands.ClassTypeCommandSet.CommandSetID, + JDWPCommands.ClassTypeCommandSet.SetValuesCommand); + packet.setNextValueAsClassID(classID); + packet.setNextValueAsInt(1); + packet.setNextValueAsFieldID(fieldInfo.getFieldID()); + + packet.setNextValueAsUntaggedValue(value); + + ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "ClassType::SetValues command"); + + packet = new CommandPacket( + JDWPCommands.ReferenceTypeCommandSet.CommandSetID, + JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand); + packet.setNextValueAsReferenceTypeID(classID); + packet.setNextValueAsInt(1); + packet.setNextValueAsFieldID(fieldInfo.getFieldID()); + + reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "ClassType::GetValues command"); + + int fields = reply.getNextValueAsInt(); + assertEquals("ClassType::SetValues returne invalid fields number,", 1, fields); + Value returnedValue = reply.getNextValueAsValue(); + assertEquals("ClassType::SetValues returne invalid returned value,", value, returnedValue); + logWriter.println("==> testField: OK"); + } + + private FieldInfo[] jdwpGetFieldIDs(long classID) { + CommandPacket packet = new CommandPacket( + JDWPCommands.ReferenceTypeCommandSet.CommandSetID, + JDWPCommands.ReferenceTypeCommandSet.FieldsCommand); + packet.setNextValueAsReferenceTypeID(classID); + + ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "ReferenceType::Fields command"); + + int declared = reply.getNextValueAsInt(); + FieldInfo[] fields = new FieldInfo[declared]; + for (int i = 0; i < declared; i++) { + fields[i] = new FieldInfo( + reply.getNextValueAsFieldID(), + reply.getNextValueAsString(), + reply.getNextValueAsString(), + reply.getNextValueAsInt() + ); + } + + return fields; + } + +} \ No newline at end of file Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ClassType/SetValuesTest.java ------------------------------------------------------------------------------ svn:eol-style = native