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 Vitaly A. Provodin
021: * @version $Revision: 1.5 $
022: */
023:
024: /**
025: * Created on 09.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.VirtualMachine;
027:
028: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
029: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
030: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
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.share.JPDADebuggeeSynchronizer;
034:
035: /**
036: * JDWP Unit test for VirtualMachine.ClassesBySignature command.
037: */
038: public class ClassesBySignatureTest extends JDWPSyncTestCase {
039:
040: static final String SIGNATURE001 = "Lorg/apache/harmony/jpda/tests/jdwp/share/debuggee/HelloWorld;";
041:
042: protected String getDebuggeeClassName() {
043: return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld";
044: }
045:
046: /**
047: * This testcase exercises VirtualMachine.ClassesBySignature command.
048: * <BR>At first the test starts HelloWorld debuggee.
049: * <BR> Then the test performs VirtualMachine.ClassesBySignature command
050: * for signature of HelloWorld class and checks that:
051: * <BR> - number of returned reference types is equal to 1;
052: * <BR> - the JDWP command ReferenceType.Signature for
053: * returned referenceTypeID returns the expected string signature;
054: * <BR> - there are no extra data in the reply packet;
055: */
056: public void testClassesBySignature001() {
057: synchronizer
058: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
059:
060: CommandPacket packet = new CommandPacket(
061: JDWPCommands.VirtualMachineCommandSet.CommandSetID,
062: JDWPCommands.VirtualMachineCommandSet.ClassesBySignatureCommand);
063: packet.setNextValueAsString(SIGNATURE001);
064:
065: ReplyPacket reply = debuggeeWrapper.vmMirror
066: .performCommand(packet);
067: checkReplyPacket(reply,
068: "VirtualMachine::ClassesBySignature command");
069:
070: byte refTypeTag;
071: long typeID;
072: String signature;
073: int status;
074: ReplyPacket replySignature;
075:
076: int classes = reply.getNextValueAsInt();
077: logWriter.println("Number of reference types = " + classes);
078: if (classes != 1) {
079: logWriter.printError("Wrong Number of reference types");
080: //assertEquals(1, classes);
081: fail("Wrong Number of reference types");
082: }
083:
084: for (int i = 0; i < classes; i++) {
085:
086: refTypeTag = reply.getNextValueAsByte();
087: typeID = reply.getNextValueAsReferenceTypeID();
088: status = reply.getNextValueAsInt();
089:
090: logWriter.println("\trefTypeTag = "
091: + JDWPConstants.TypeTag.getName(refTypeTag) + "("
092: + refTypeTag + ")");
093: if (JDWPConstants.TypeTag.CLASS != refTypeTag) {
094: printErrorAndFail("refTypeTag must be "
095: + JDWPConstants.TypeTag
096: .getName(JDWPConstants.TypeTag.CLASS)
097: + "(" + JDWPConstants.TypeTag.CLASS + ")");
098: }
099:
100: packet = new CommandPacket(
101: JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
102: JDWPCommands.ReferenceTypeCommandSet.SignatureCommand);
103: packet.setNextValueAsReferenceTypeID(typeID);
104:
105: replySignature = debuggeeWrapper.vmMirror
106: .performCommand(packet);
107: signature = replySignature.getNextValueAsString();
108:
109: logWriter.println("\ttypeID = " + typeID + "(" + signature
110: + ")");
111: if (!SIGNATURE001.equals(signature)) {
112: printErrorAndFail("Signature must be " + SIGNATURE001);
113: }
114:
115: logWriter.println("\tstatus = "
116: + JDWPConstants.ClassStatus.getName(status) + "("
117: + status + ")");
118: }
119: assertAllDataRead(reply);
120: synchronizer
121: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
122: }
123:
124: public static void main(String[] args) {
125: junit.textui.TestRunner.run(ClassesBySignatureTest.class);
126: }
127: }
|