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 11.02.2005
25 */
26package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
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.ReplyPacket;
31import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
32import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
33
34
35/**
36 * JDWP Unit test for ThreadReference.Name command.
37 */
38public class NameTest extends JDWPSyncTestCase {
39
40    protected String getDebuggeeClassName() {
41        return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld";
42    }
43
44    /**
45     * This testcase exercises ThreadReference.Name command.
46     * <BR>At first the test starts HelloWorld debuggee.
47     * <BR> Then the tests performs the ThreadReference.Name command
48     * for every thread in debuggee.
49     * <BR>It is expected that the returned names are not empty.
50     */
51    public void testName001() {
52        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
53
54        ReplyPacket thrdReply, reply = debuggeeWrapper.vmMirror.getAllThreadID();
55
56        CommandPacket packet;
57        long threadID;
58        String threadName;
59        int threads = reply.getNextValueAsInt();
60        for (int i = 0 ;i < threads; i++) {
61            threadID = reply.getNextValueAsThreadID();
62            packet = new CommandPacket(
63                    JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
64                    JDWPCommands.ThreadReferenceCommandSet.NameCommand);
65            packet.setNextValueAsThreadID(threadID);
66
67            thrdReply = debuggeeWrapper.vmMirror.performCommand(packet);
68            checkReplyPacket(thrdReply, "ThreadReference::Name command");
69
70            threadName = thrdReply.getNextValueAsString();
71            logWriter.println("\tthreadID = " + threadID + " threadName = "
72                    + threadName);
73            if (threadName.length() == 0) {
74                printErrorAndFail("Empty name for thread with ID=" + threadID);
75            }
76        }
77
78        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
79    }
80}
81