001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Aleksander V. Budniy
021: * @version $Revision: 1.6 $
022: */
023:
024: /**
025: * Created on 12.08.2005
026: */package org.apache.harmony.jpda.tests.jdwp.MultiSession;
027:
028: import org.apache.harmony.jpda.tests.framework.TestOptions;
029: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
030: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
031: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
032: import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
033: import org.apache.harmony.jpda.tests.jdwp.share.JDWPUnitDebuggeeWrapper;
034: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
035:
036: /**
037: * JDWP Unit test to check capacity for work of attaching connector.
038: */
039: public class AttachConnectorTest extends JDWPSyncTestCase {
040:
041: protected String getDebuggeeClassName() {
042: return "org.apache.harmony.jpda.tests.jdwp.MultiSession.ConnectorKindDebuggee";
043: }
044:
045: /**
046: * This testcase checks capacity for work of attaching connector.
047: * <BR>Before debuggee start it sets up connector kind to attaching and starts
048: * ConnectorKindDebuggee. Then testcase performs VirtualMachine.Version
049: * command and checks it's correctness.
050: * It is expected that command returns not empty strings describing VM version.
051: */
052: public void testAttachConnector001() {
053:
054: logWriter.println("==> testAttachConnector001 started..");
055: synchronizer
056: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
057: for (int i = 0; i < 3; i++) {
058:
059: CommandPacket packet = new CommandPacket(
060: JDWPCommands.VirtualMachineCommandSet.CommandSetID,
061: JDWPCommands.VirtualMachineCommandSet.VersionCommand);
062: ReplyPacket reply = debuggeeWrapper.vmMirror
063: .performCommand(packet);
064: checkReplyPacket(reply, "VirtualMachine::Version command");
065:
066: String description = reply.getNextValueAsString();
067: int jdwpMajor = reply.getNextValueAsInt();
068: int jdwpMinor = reply.getNextValueAsInt();
069: String vmVersion = reply.getNextValueAsString();
070: String vmName = reply.getNextValueAsString();
071:
072: logWriter.println("description\t= " + description);
073: logWriter.println("jdwpMajor\t= " + jdwpMajor);
074: logWriter.println("jdwpMinor\t= " + jdwpMinor);
075: logWriter.println("vmVersion\t= " + vmVersion);
076: logWriter.println("vmName\t\t= " + vmName);
077:
078: assertTrue("Invalid description.length = 0", description
079: .length() > 0);
080: assertTrue("Invalid vmVersion.length = 0", vmVersion
081: .length() > 0);
082: assertTrue("Invalid vmName.length = 0", vmName.length() > 0);
083:
084: logWriter.println("=> CHECK PASSED");
085: logWriter.println("System property: "
086: + System.getProperty("isDebuggeeRunning"));
087:
088: synchronizer
089: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
090: synchronizer
091: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
092: logWriter.println("");
093: logWriter.println("=> CLOSE CONNECTION..");
094: closeConnection();
095: logWriter.println("=> CONNECTION CLOSED");
096:
097: logWriter.println("");
098: logWriter.println("=> OPEN NEW CONNECTION..");
099: openConnection();
100: logWriter.println("=> CONNECTION OPENED");
101: logWriter.println("");
102:
103: }
104: synchronizer.sendMessage("stop");
105: synchronizer.receiveMessage("END");
106: logWriter.println("==> testAttachConnector001 PASSED!");
107: }
108:
109: protected void beforeDebuggeeStart(
110: JDWPUnitDebuggeeWrapper debuggeeWrapper) {
111: settings.setAttachConnectorKind();
112: if (settings.getTransportAddress() == null) {
113: settings
114: .setTransportAddress(TestOptions.DEFAULT_ATTACHING_ADDRESS);
115: }
116: logWriter.println("ATTACH connector kind");
117: super .beforeDebuggeeStart(debuggeeWrapper);
118: }
119:
120: public static void main(String[] args) {
121: junit.textui.TestRunner.run(AttachConnectorTest.class);
122: }
123: }
|