NewInstanceAfterMultipleThreadSuspensionTest.java revision ec561efd83dc4bb97a5677a28f09a7fc41deea79
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.ClassType;
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.JDWPConstants;
24import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
25import org.apache.harmony.jpda.tests.framework.jdwp.TaggedObject;
26import org.apache.harmony.jpda.tests.jdwp.share.JDWPInvokeMethodSuspendedTwiceTestCase;
27
28/**
29 * JDWP unit test for ClassType.NewInstance command with thread suspended more than once before the
30 * invoke.
31 */
32public class NewInstanceAfterMultipleThreadSuspensionTest
33        extends JDWPInvokeMethodSuspendedTwiceTestCase {
34    public void testInvokeWithMultipleEvents001() {
35        runInvokeMethodTest("<init>");
36    }
37
38    @Override
39    protected CommandPacket buildInvokeCommand(long threadId, long classID,
40            long methodId, int invoke_options) {
41        CommandPacket command = new CommandPacket(
42                JDWPCommands.ClassTypeCommandSet.CommandSetID,
43                JDWPCommands.ClassTypeCommandSet.NewInstanceCommand);
44        command.setNextValueAsClassID(classID);
45        command.setNextValueAsThreadID(threadId);
46        command.setNextValueAsMethodID(methodId);
47        command.setNextValueAsInt(0);
48        command.setNextValueAsInt(invoke_options);
49        return command;
50    }
51
52    @Override
53    protected String getInvokeCommandName() {
54        return "ClassType.NewInstance";
55    }
56
57    @Override
58    protected void checkInvokeReply(ReplyPacket reply) {
59        // Check result is an object.
60        TaggedObject invokeNewObject = reply.getNextValueAsTaggedObject();
61        assertEquals(JDWPConstants.Tag.OBJECT_TAG, invokeNewObject.tag);
62        assertTrue("Invalid exception object id", invokeNewObject.objectID != 0);
63
64        // Check exception is null.
65        TaggedObject invokeException = reply.getNextValueAsTaggedObject();
66        assertEquals(JDWPConstants.Tag.OBJECT_TAG, invokeException.tag);
67        assertEquals("Invalid exception object id", 0, invokeException.objectID);
68
69        assertAllDataRead(reply);
70    }
71
72}
73