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 10.02.2005 25 */ 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 /** 36 * JDWP Unit test for VirtualMachine.CreateString command. 37 */ 38 public class CreateStringTest extends JDWPSyncTestCase { 39 40 static final String CHECKED_STRING = "Hello World!"; 41 getDebuggeeClassName()42 protected String getDebuggeeClassName() { 43 return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld"; 44 } 45 46 /** 47 * This testcase exercises VirtualMachine.CreateString command. 48 * <BR>At first the test starts HelloWorld debuggee. 49 * <BR> Then the test performs VirtualMachine.CreateString command 50 * for some string and checks that StringReference.Value command 51 * returns the same string. 52 */ testCreateString001()53 public void testCreateString001() { 54 synchronizer.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.performCommand(packet); 63 checkReplyPacket(reply, "VirtualMachine::CreateString command"); 64 65 long stringID = reply.getNextValueAsStringID(); 66 67 packet = new CommandPacket( 68 JDWPCommands.StringReferenceCommandSet.CommandSetID, 69 JDWPCommands.StringReferenceCommandSet.ValueCommand); 70 packet.setNextValueAsObjectID(stringID); 71 logWriter.println("\trequest string value"); 72 73 reply = debuggeeWrapper.vmMirror.performCommand(packet); 74 checkReplyPacket(reply, "StringReference::Value command"); 75 76 String value = reply.getNextValueAsString(); 77 logWriter.println("\tgot string value: " + value); 78 79 assertString("StringReference::Value command returned invalid string value,", CHECKED_STRING, value); 80 81 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 82 } 83 } 84