001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Vitaly A. Provodin
021: * @version $Revision: 1.4 $
022: */
023:
024: /**
025: * Created on 25.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.ThreadGroupReference;
027:
028: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
029: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
030: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
031: import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
032: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
033:
034: /**
035: * JDWP Unit test for ThreadGroupReference.Children command.
036: */
037: public class ChildrenTest extends JDWPSyncTestCase {
038:
039: protected String getDebuggeeClassName() {
040: return "org.apache.harmony.jpda.tests.jdwp.ThreadGroupReference.ChildrenDebuggee";
041: }
042:
043: /**
044: * This testcase exercises ThreadGroupReference.Children command.
045: * <BR>At first the test starts ChildrenDebuggee.
046: * <BR> Then the test with help of the ThreadGroupReference.Children command checks
047: * that the group 'PARENT_GROUP' has one child thread - 'TESTED_THREAD'
048: * and one child group - 'CHILD_GROUP'.
049: *
050: */
051: public void testChildren001() {
052: logWriter.println("==> ChildrenTest.testChildren001 START...");
053: logWriter.println("==> Wait for SGNL_READY...");
054: synchronizer
055: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
056:
057: // getting ID of the tested thread
058: logWriter.println("==> Get testedThreadID...");
059: CommandPacket packet;
060: long threadID = debuggeeWrapper.vmMirror
061: .getThreadID(NameDebuggee.TESTED_THREAD);
062: logWriter.println("==> testedThreadID = " + threadID);
063:
064: long groupID;
065: String groupName;
066:
067: // getting the thread group ID
068: logWriter
069: .println("==> Send ThreadReference.ThreadGroup command for testedThreadID...");
070: packet = new CommandPacket(
071: JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
072: JDWPCommands.ThreadReferenceCommandSet.ThreadGroupCommand);
073: packet.setNextValueAsThreadID(threadID);
074: ReplyPacket reply = debuggeeWrapper.vmMirror
075: .performCommand(packet);
076: checkReplyPacket(reply, "ThreadReference.ThreadGroup command");
077:
078: groupID = reply.getNextValueAsThreadGroupID();
079: logWriter.println("==> groupID = " + groupID);
080:
081: logWriter
082: .println("==> Send ThreadGroupReference.Children command...");
083: packet = new CommandPacket(
084: JDWPCommands.ThreadGroupReferenceCommandSet.CommandSetID,
085: JDWPCommands.ThreadGroupReferenceCommandSet.ChildrenCommand);
086: packet.setNextValueAsThreadID(groupID);
087: reply = debuggeeWrapper.vmMirror.performCommand(packet);
088: checkReplyPacket(reply, "ThreadGroupReference.Children command");
089:
090: logWriter.println("\n==> Children of the group: \""
091: + debuggeeWrapper.vmMirror.getThreadGroupName(groupID)
092: + "\": ");
093:
094: int childThreads = reply.getNextValueAsInt();
095: if (childThreads != 1) {
096: logWriter
097: .println("## FAILURE: Unexpected number of child threads = "
098: + childThreads);
099: logWriter
100: .println("## Expected number of child threads = 1");
101: assertEquals("Invalid number of child threads,", 1,
102: childThreads);
103: }
104: long childThreadID = reply.getNextValueAsThreadID();
105: String threadName = debuggeeWrapper.vmMirror
106: .getThreadName(childThreadID);
107: logWriter.println("==> thread: threadID = " + childThreadID
108: + "; threadName = " + threadName);
109:
110: if (threadID != childThreadID) {
111: logWriter
112: .println("## FAILURE: Unexpected ID of child thread = "
113: + childThreadID);
114: logWriter.println("## Expected ID of child thread = "
115: + threadID);
116: assertEquals("Invalid ID of child thread,", threadID,
117: childThreadID);
118: }
119: if (!threadName.equals(NameDebuggee.TESTED_THREAD)) {
120: logWriter
121: .println("## FAILURE: unexpected thread name, it is expected: "
122: + NameDebuggee.TESTED_THREAD);
123: assertString("Invalid thread name,",
124: NameDebuggee.TESTED_THREAD, threadName);
125: }
126:
127: int childGroups = reply.getNextValueAsInt();
128: if (childGroups != 1) {
129: logWriter
130: .println("## FAILURE: Unexpected number of child groups "
131: + childGroups);
132: logWriter.println("## Expected number = 1");
133: assertEquals("Invalid number of child groups,", 1,
134: childGroups);
135: }
136:
137: groupID = reply.getNextValueAsThreadGroupID();
138: groupName = debuggeeWrapper.vmMirror
139: .getThreadGroupName(groupID);
140:
141: logWriter.println("\n==> group: groupID = " + groupID
142: + "; groupName = " + groupName);
143:
144: assertString("Invalid group name,", NameDebuggee.CHILD_GROUP,
145: groupName);
146:
147: synchronizer
148: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
149: }
150:
151: public static void main(String[] args) {
152: junit.textui.TestRunner.run(ChildrenTest.class);
153: }
154: }
|