01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: * @version $Revision: 1.4 $
22: */
23:
24: /**
25: * Created on 11.02.2005
26: */package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
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.ReplyPacket;
31: import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
32: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
33:
34: /**
35: * JDWP Unit test for ThreadReference.Name command.
36: */
37: public class NameTest extends JDWPSyncTestCase {
38:
39: protected String getDebuggeeClassName() {
40: return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld";
41: }
42:
43: /**
44: * This testcase exercises ThreadReference.Name command.
45: * <BR>At first the test starts HelloWorld debuggee.
46: * <BR> Then the tests performs the ThreadReference.Name command
47: * for every thread in debuggee.
48: * <BR>It is expected that the returned names are not empty.
49: */
50: public void testName001() {
51: synchronizer
52: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
53:
54: ReplyPacket thrdReply, reply = debuggeeWrapper.vmMirror
55: .getAllThreadID();
56:
57: CommandPacket packet;
58: long threadID;
59: String threadName;
60: int threads = reply.getNextValueAsInt();
61: for (int i = 0; i < threads; i++) {
62: threadID = reply.getNextValueAsThreadID();
63: packet = new CommandPacket(
64: JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
65: JDWPCommands.ThreadReferenceCommandSet.NameCommand);
66: packet.setNextValueAsThreadID(threadID);
67:
68: thrdReply = debuggeeWrapper.vmMirror.performCommand(packet);
69: checkReplyPacket(thrdReply, "ThreadReference::Name command");
70:
71: threadName = thrdReply.getNextValueAsString();
72: logWriter.println("\tthreadID = " + threadID
73: + " threadName = " + threadName);
74: if (threadName.length() == 0) {
75: printErrorAndFail("Empty name for thread with ID="
76: + threadID);
77: }
78: }
79:
80: synchronizer
81: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
82: }
83:
84: public static void main(String[] args) {
85: junit.textui.TestRunner.run(NameTest.class);
86: }
87: }
|