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