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 19 /** 20 * @author Vitaly A. Provodin 21 */ 22 23 /** 24 * Created on 25.02.2005 25 */ 26 package org.apache.harmony.jpda.tests.jdwp.ThreadGroupReference; 27 28 import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; 29 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; 30 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants; 31 import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; 32 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; 33 import org.apache.harmony.jpda.tests.jdwp.share.JDWPTestConstants; 34 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 35 36 37 /** 38 * JDWP Unit test for ThreadGroupReference.Parent command. 39 */ 40 public class ParentTest extends JDWPSyncTestCase { 41 getDebuggeeClassName()42 protected String getDebuggeeClassName() { 43 return "org.apache.harmony.jpda.tests.jdwp.ThreadGroupReference.NameDebuggee"; 44 } 45 46 /** 47 * This testcase exercises ThreadGroupReference.Parent command. 48 * <BR>At first the test starts NameDebuggee. 49 * <BR> Then the test with help of the ThreadGroupReference.Parent command checks 50 * that the parent group of the group of the tested thread is group 51 * with name 'PARENT_GROUP'. 52 * 53 */ testParent001()54 public void testParent001() { 55 logWriter.println("wait for SGNL_READY"); 56 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 57 58 // getting ID of the tested thread 59 CommandPacket packet; 60 long threadID = debuggeeWrapper.vmMirror.getThreadID(NameDebuggee.TESTED_THREAD); 61 62 long groupID; 63 String groupName; 64 65 // getting the thread group ID 66 packet = new CommandPacket( 67 JDWPCommands.ThreadReferenceCommandSet.CommandSetID, 68 JDWPCommands.ThreadReferenceCommandSet.ThreadGroupCommand); 69 packet.setNextValueAsThreadID(threadID); 70 71 ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); 72 checkReplyPacket(reply, "ThreadReference::ThreadGroup command"); 73 74 groupID = reply.getNextValueAsThreadGroupID(); 75 76 packet = new CommandPacket( 77 JDWPCommands.ThreadGroupReferenceCommandSet.CommandSetID, 78 JDWPCommands.ThreadGroupReferenceCommandSet.ParentCommand); 79 packet.setNextValueAsThreadID(groupID); 80 81 reply = debuggeeWrapper.vmMirror.performCommand(packet); 82 checkReplyPacket(reply, "ThreadGroupReference::Parent command"); 83 84 groupID = reply.getNextValueAsThreadGroupID(); 85 86 groupName = debuggeeWrapper.vmMirror.getThreadGroupName(groupID); 87 88 logWriter.println("\tgroupID=" + groupID 89 + "; groupName=" + groupName); 90 91 assertString("ThreadGroupReference::Parent command returned invalid group name,", 92 NameDebuggee.PARENT_GROUP, groupName); 93 94 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 95 } 96 97 /** 98 * This testcase exercises ThreadGroupReference.Parent command. 99 * <BR>At first the test starts NameDebuggee. 100 * <BR> Then the test with help of the ThreadGroupReference.Parent command 101 * checks that INVALID_OBJECT error is returned for the null object id. 102 * 103 */ testParent_NullObject()104 public void testParent_NullObject() { 105 logWriter.println("wait for SGNL_READY"); 106 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 107 108 checkCommandError(JDWPTestConstants.NULL_OBJECT_ID, 109 JDWPConstants.Error.INVALID_OBJECT); 110 111 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 112 } 113 114 /** 115 * This testcase exercises ThreadGroupReference.Parentcommand. 116 * <BR>At first the test starts NameDebuggee. 117 * <BR> Then the test with help of the ThreadGroupReference.Parent command 118 * checks that INVALID_OBJECT error is returned for an invalid object id. 119 * 120 */ testParent_InvalidObject()121 public void testParent_InvalidObject() { 122 logWriter.println("wait for SGNL_READY"); 123 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 124 125 checkCommandError(JDWPTestConstants.INVALID_OBJECT_ID, 126 JDWPConstants.Error.INVALID_OBJECT); 127 128 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 129 } 130 131 /** 132 * This testcase exercises ThreadGroupReference.Parent command. 133 * <BR>At first the test starts NameDebuggee. 134 * <BR> Then the test with help of the ThreadGroupReference.Parent command 135 * checks that INVALID_THREAD_GROUP error is returned for an object that is 136 * not a java.lang.ThreadGroup. 137 * 138 */ testParent_InvalidThreadGroup()139 public void testParent_InvalidThreadGroup() { 140 logWriter.println("wait for SGNL_READY"); 141 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 142 143 long threadID = debuggeeWrapper.vmMirror.getThreadID(NameDebuggee.TESTED_THREAD); 144 145 checkCommandError(threadID, JDWPConstants.Error.INVALID_THREAD_GROUP); 146 147 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 148 } 149 checkCommandError(long groupID, int expectedError)150 private void checkCommandError(long groupID, int expectedError) { 151 logWriter.println("Send ThreadGroupReference.Name command with id " + groupID); 152 153 CommandPacket packet = new CommandPacket( 154 JDWPCommands.ThreadGroupReferenceCommandSet.CommandSetID, 155 JDWPCommands.ThreadGroupReferenceCommandSet.NameCommand); 156 packet.setNextValueAsThreadGroupID(groupID); 157 ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); 158 159 checkReplyPacket(reply, "ThreadGroupReference::Name command", expectedError); 160 } 161 } 162