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 Aleksander V. Budniy 21 */ 22 23 /** 24 * Created on 12.08.2005 25 */ 26 package org.apache.harmony.jpda.tests.jdwp.MultiSession; 27 28 import org.apache.harmony.jpda.tests.framework.TestOptions; 29 import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; 30 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; 31 import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; 32 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; 33 import org.apache.harmony.jpda.tests.jdwp.share.JDWPUnitDebuggeeWrapper; 34 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 35 36 37 /** 38 * JDWP Unit test to check capacity for work of attaching connector. 39 */ 40 public class AttachConnectorTest extends JDWPSyncTestCase { 41 getDebuggeeClassName()42 protected String getDebuggeeClassName() { 43 return "org.apache.harmony.jpda.tests.jdwp.MultiSession.ConnectorKindDebuggee"; 44 } 45 46 /** 47 * This testcase checks capacity for work of attaching connector. 48 * <BR>Before debuggee start it sets up connector kind to attaching and starts 49 * ConnectorKindDebuggee. Then testcase performs VirtualMachine.Version 50 * command and checks it's correctness. 51 * It is expected that command returns not empty strings describing VM version. 52 */ testAttachConnector001()53 public void testAttachConnector001() { 54 55 logWriter.println("==> testAttachConnector001 started.."); 56 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 57 for (int i = 0; i < 3; i++) { 58 59 CommandPacket packet = new CommandPacket( 60 JDWPCommands.VirtualMachineCommandSet.CommandSetID, 61 JDWPCommands.VirtualMachineCommandSet.VersionCommand); 62 ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); 63 checkReplyPacket(reply, "VirtualMachine::Version command"); 64 65 String description = reply.getNextValueAsString(); 66 int jdwpMajor = reply.getNextValueAsInt(); 67 int jdwpMinor = reply.getNextValueAsInt(); 68 String vmVersion = reply.getNextValueAsString(); 69 String vmName = reply.getNextValueAsString(); 70 71 logWriter.println("description\t= " + description); 72 logWriter.println("jdwpMajor\t= " + jdwpMajor); 73 logWriter.println("jdwpMinor\t= " + jdwpMinor); 74 logWriter.println("vmVersion\t= " + vmVersion); 75 logWriter.println("vmName\t\t= " + vmName); 76 77 assertTrue("Invalid description.length = 0", description.length() > 0); 78 assertTrue("Invalid vmVersion.length = 0", vmVersion.length() > 0); 79 assertTrue("Invalid vmName.length = 0", vmName.length() > 0); 80 81 logWriter.println("=> CHECK PASSED"); 82 logWriter.println("System property: " 83 + System.getProperty("isDebuggeeRunning")); 84 85 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 86 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 87 logWriter.println(""); 88 logWriter.println("=> CLOSE CONNECTION.."); 89 closeConnection(); 90 logWriter.println("=> CONNECTION CLOSED"); 91 92 logWriter.println(""); 93 logWriter.println("=> OPEN NEW CONNECTION.."); 94 openConnection(); 95 logWriter.println("=> CONNECTION OPENED"); 96 logWriter.println(""); 97 98 } 99 synchronizer.sendMessage("stop"); 100 synchronizer.receiveMessage("END"); 101 logWriter.println("==> testAttachConnector001 PASSED!"); 102 } 103 beforeDebuggeeStart(JDWPUnitDebuggeeWrapper debuggeeWrapper)104 protected void beforeDebuggeeStart(JDWPUnitDebuggeeWrapper debuggeeWrapper) { 105 settings.setAttachConnectorKind(); 106 if (settings.getTransportAddress() == null) { 107 settings.setTransportAddress(TestOptions.DEFAULT_ATTACHING_ADDRESS); 108 } 109 logWriter.println("ATTACH connector kind"); 110 super.beforeDebuggeeStart(debuggeeWrapper); 111 } 112 } 113