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 Anatoly F. Bondarenko
021: * @version $Revision: 1.3 $
022: */
023:
024: /**
025: * Created on 16.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.ReferenceType;
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.ReplyPacket;
031: import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
032: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
033:
034: /**
035: * JDWP Unit test for ReferenceType.Signature command.
036: */
037: public class SignatureTest extends JDWPSyncTestCase {
038:
039: static final int testStatusPassed = 0;
040: static final int testStatusFailed = -1;
041: static final String this CommandName = "ReferenceType.Signature command";
042: static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/share/debuggee/HelloWorld;";
043:
044: protected String getDebuggeeClassName() {
045: return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld";
046: }
047:
048: /**
049: * This testcase exercises ReferenceType.Signature command.
050: * <BR>The test starts HelloWorld debuggee, requests referenceTypeId
051: * for it by VirtualMachine.ClassesBySignature command, then
052: * performs ReferenceType.Signature command and checks that returned
053: * signature is equal to expected signature:
054: * <BR>'Lorg/apache/harmony/jpda/tests/jdwp/share/debuggee/HelloWorld;'
055: */
056: public void testSignature001() {
057: String this TestName = "testSignature001";
058: logWriter.println("==> " + this TestName + " for "
059: + this CommandName + ": START...");
060: synchronizer
061: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
062:
063: long refTypeID = getClassIDBySignature(debuggeeSignature);
064:
065: logWriter.println("=> Debuggee class = "
066: + getDebuggeeClassName());
067: logWriter.println("=> referenceTypeID for Debuggee class = "
068: + refTypeID);
069: logWriter.println("=> CHECK1: send " + this CommandName
070: + " and check reply...");
071:
072: CommandPacket signatureCommand = new CommandPacket(
073: JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
074: JDWPCommands.ReferenceTypeCommandSet.SignatureCommand);
075: signatureCommand.setNextValueAsReferenceTypeID(refTypeID);
076:
077: ReplyPacket signatureReply = debuggeeWrapper.vmMirror
078: .performCommand(signatureCommand);
079: signatureCommand = null;
080: checkReplyPacket(signatureReply, this CommandName);
081:
082: String returnedSignature = signatureReply
083: .getNextValueAsString();
084:
085: if (!debuggeeSignature.equals(returnedSignature)) {
086: printErrorAndFail(this CommandName
087: + " returned invalid signature" + ", Expected = "
088: + debuggeeSignature + ", Returned = "
089: + returnedSignature);
090: } else {
091: logWriter
092: .println("=> CHECK1: PASSED: expected signature is returned = "
093: + returnedSignature);
094: }
095: assertAllDataRead(signatureReply);
096: synchronizer
097: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
098: logWriter.println("==> " + this TestName + " for "
099: + this CommandName + ": FINISH");
100: }
101:
102: public static void main(String[] args) {
103: junit.textui.TestRunner.run(SignatureTest.class);
104: }
105: }
|