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.5 $
22: */
23:
24: /**
25: * Created on 10.02.2005
26: */package org.apache.harmony.jpda.tests.jdwp.VirtualMachine;
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 VirtualMachine.CreateString command.
36: */
37: public class CreateStringTest extends JDWPSyncTestCase {
38:
39: static final String CHECKED_STRING = "Hello World!";
40:
41: protected String getDebuggeeClassName() {
42: return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld";
43: }
44:
45: /**
46: * This testcase exercises VirtualMachine.CreateString command.
47: * <BR>At first the test starts HelloWorld debuggee.
48: * <BR> Then the test performs VirtualMachine.CreateString command
49: * for some string and checks that StringReference.Value command
50: * returns the same string.
51: */
52: public void testCreateString001() {
53: synchronizer
54: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
55:
56: CommandPacket packet = new CommandPacket(
57: JDWPCommands.VirtualMachineCommandSet.CommandSetID,
58: JDWPCommands.VirtualMachineCommandSet.CreateStringCommand);
59: packet.setNextValueAsString(CHECKED_STRING);
60: logWriter.println("\tcreate string: " + CHECKED_STRING);
61:
62: ReplyPacket reply = debuggeeWrapper.vmMirror
63: .performCommand(packet);
64: checkReplyPacket(reply, "VirtualMachine::CreateString command");
65:
66: long stringID = reply.getNextValueAsStringID();
67:
68: packet = new CommandPacket(
69: JDWPCommands.StringReferenceCommandSet.CommandSetID,
70: JDWPCommands.StringReferenceCommandSet.ValueCommand);
71: packet.setNextValueAsObjectID(stringID);
72: logWriter.println("\trequest string value");
73:
74: reply = debuggeeWrapper.vmMirror.performCommand(packet);
75: checkReplyPacket(reply, "StringReference::Value command");
76:
77: String value = reply.getNextValueAsString();
78: logWriter.println("\tgot string value: " + value);
79:
80: assertString(
81: "StringReference::Value command returned invalid string value,",
82: CHECKED_STRING, value);
83:
84: synchronizer
85: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
86: }
87:
88: public static void main(String[] args) {
89: junit.textui.TestRunner.run(CreateStringTest.class);
90: }
91: }
|