1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19package org.apache.harmony.jpda.tests.jdwp.ObjectReference; 20 21import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; 22import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; 23import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; 24import org.apache.harmony.jpda.tests.framework.jdwp.TaggedObject; 25import org.apache.harmony.jpda.tests.framework.jdwp.Value; 26import org.apache.harmony.jpda.tests.jdwp.share.JDWPInvokeMethodSuspendedTwiceTestCase; 27import org.apache.harmony.jpda.tests.jdwp.share.debuggee.InvokeMethodSuspendedTwiceDebuggee; 28 29/** 30 * JDWP unit test for ObjectReference.InvokeCommand command with thread suspended more than once 31 * before the invoke. 32 */ 33public class InvokeMethodAfterMultipleThreadSuspensionTest 34 extends JDWPInvokeMethodSuspendedTwiceTestCase { 35 public void testInvokeWithMultipleEvents001() { 36 runInvokeMethodTest(InvokeMethodSuspendedTwiceDebuggee.INSTANCE_METHOD_NAME); 37 } 38 39 @Override 40 protected CommandPacket buildInvokeCommand(long threadId, long classID, 41 long methodId, int invoke_options) { 42 // At first, we must find the 'this' object of the top frame. 43 ReplyPacket replyPacket = debuggeeWrapper.vmMirror.getThreadFrames(threadId, 0, 1); 44 int framesCount = replyPacket.getNextValueAsInt(); 45 assertEquals("Invalid frame count:", 1, framesCount); 46 long topFrameId = replyPacket.getNextValueAsFrameID(); 47 replyPacket.getNextValueAsLocation(); // consume 'location' 48 assertAllDataRead(replyPacket); 49 50 long receiverId = debuggeeWrapper.vmMirror.getThisObject(threadId, topFrameId); 51 52 CommandPacket command = new CommandPacket( 53 JDWPCommands.ObjectReferenceCommandSet.CommandSetID, 54 JDWPCommands.ObjectReferenceCommandSet.InvokeMethodCommand); 55 command.setNextValueAsThreadID(receiverId); 56 command.setNextValueAsThreadID(threadId); 57 command.setNextValueAsClassID(classID); 58 command.setNextValueAsMethodID(methodId); 59 command.setNextValueAsInt(0); 60 command.setNextValueAsInt(invoke_options); 61 return command; 62 } 63 64 @Override 65 protected String getInvokeCommandName() { 66 return "ObjectReference.InvokeCommand"; 67 } 68 69 @Override 70 protected void checkInvokeReply(ReplyPacket reply) { 71 // Check result is 'void' 72 Value invokeResult = reply.getNextValueAsValue(); 73 assertNull("Expect null result value for 'void'", invokeResult); 74 75 // Check exception is null. 76 TaggedObject invokeException = reply.getNextValueAsTaggedObject(); 77 assertEquals("Invalid exception object id", 0, invokeException.objectID); 78 assertAllDataRead(reply); 79 } 80 81} 82