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.JDWPInvokeMethodWithSuspensionTestCase;
27
28/**
29 * JDWP unit test for ClassType.NewInstance command with a thread suspension.
30 */
31public class NewInstanceWithSuspensionTest extends JDWPInvokeMethodWithSuspensionTestCase {
32    public void testInvokeWithMultipleEvents001() {
33        runInvokeMethodTest("<init>");
34    }
35
36    @Override
37    protected CommandPacket buildInvokeCommand(long threadId, long classID,
38            long methodId, int invoke_options) {
39        CommandPacket command = new CommandPacket(
40                JDWPCommands.ClassTypeCommandSet.CommandSetID,
41                JDWPCommands.ClassTypeCommandSet.NewInstanceCommand);
42        command.setNextValueAsClassID(classID);
43        command.setNextValueAsThreadID(threadId);
44        command.setNextValueAsMethodID(methodId);
45        command.setNextValueAsInt(0);
46        command.setNextValueAsInt(invoke_options);
47        return command;
48    }
49
50    @Override
51    protected String getInvokeCommandName() {
52        return "ClassType.NewInstance";
53    }
54
55    @Override
56    protected void checkInvokeReply(ReplyPacket reply) {
57        // Check result is 'void'
58        TaggedObject invokeNewObject = reply.getNextValueAsTaggedObject();
59        assertEquals(JDWPConstants.Tag.OBJECT_TAG, invokeNewObject.tag);
60        assertFalse("Invalid exception object id", invokeNewObject.objectID == 0);
61
62        // Check exception is null.
63        TaggedObject invokeException = reply.getNextValueAsTaggedObject();
64        assertEquals(JDWPConstants.Tag.OBJECT_TAG, invokeException.tag);
65        assertEquals("Invalid exception object id", 0, invokeException.objectID);
66
67        assertAllDataRead(reply);
68
69    }
70
71}
72