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.7 $
022: */
023:
024: /**
025: * Created on 24.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.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 ReferenceType.SourceDebugExtension command.
037: */
038: public class SourceDebugExtensionTest extends JDWPSyncTestCase {
039:
040: static final int testStatusPassed = 0;
041: static final int testStatusFailed = -1;
042: static final String this CommandName = "ReferenceType.SourceDebugExtension command";
043: static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/SourceDebugExtensionDebuggee;";
044:
045: protected String getDebuggeeClassName() {
046: return "org.apache.harmony.jpda.tests.jdwp.ReferenceType.SourceDebugExtensionDebuggee";
047: }
048:
049: /**
050: * This testcase exercises ReferenceType.SourceDebugExtension command.
051: * <BR>The test starts SourceDebugExtensionDebuggee class, requests referenceTypeId
052: * for this class by VirtualMachine.ClassesBySignature command, then
053: * performs ReferenceType.SourceDebugExtension command and checks that
054: * no any unexpected ERROR is returned.
055: */
056: public void testSourceDebugExtension001() {
057: String this TestName = "testSourceDebugExtension001";
058:
059: //check capability, relevant for this test
060: logWriter
061: .println("=> Check capability: canGetSourceDebugExtension");
062: debuggeeWrapper.vmMirror.capabilities();
063: boolean isCapability = debuggeeWrapper.vmMirror.targetVMCapabilities.canGetSourceDebugExtension;
064: if (!isCapability) {
065: logWriter
066: .println("##WARNING: this VM doesn't possess capability: canGetSourceDebugExtension");
067: return;
068: }
069:
070: logWriter.println("==> " + this TestName + " for "
071: + this CommandName + ": START...");
072: synchronizer
073: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
074:
075: long refTypeID = getClassIDBySignature(debuggeeSignature);
076:
077: logWriter.println("=> Debuggee class = "
078: + getDebuggeeClassName());
079: logWriter.println("=> referenceTypeID for Debuggee class = "
080: + refTypeID);
081: logWriter.println("=> CHECK: send " + this CommandName
082: + " and check reply...");
083:
084: CommandPacket checkedCommand = new CommandPacket(
085: JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
086: JDWPCommands.ReferenceTypeCommandSet.SourceDebugExtensionCommand);
087: checkedCommand.setNextValueAsReferenceTypeID(refTypeID);
088:
089: ReplyPacket checkedReply = debuggeeWrapper.vmMirror
090: .performCommand(checkedCommand);
091: checkedCommand = null;
092:
093: short errorCode = checkedReply.getErrorCode();
094:
095: switch (errorCode) {
096: case JDWPConstants.Error.NONE:
097: logWriter.println("=> No any ERROR is returned");
098: String SourceDebugExtension = checkedReply
099: .getNextValueAsString();
100: logWriter.println("=> Returned SourceDebugExtension = "
101: + SourceDebugExtension);
102: break;
103: case JDWPConstants.Error.NOT_IMPLEMENTED:
104: logWriter.println("=> ERROR is returned: " + errorCode
105: + "(" + JDWPConstants.Error.getName(errorCode)
106: + ")");
107: logWriter.println("=> It is possible ERROR");
108: break;
109: case JDWPConstants.Error.ABSENT_INFORMATION:
110: logWriter.println("=> ERROR is returned: " + errorCode
111: + "(" + JDWPConstants.Error.getName(errorCode)
112: + ")");
113: logWriter.println("=> It is possible ERROR");
114: break;
115: default:
116: logWriter.println("\n## FAILURE: " + this CommandName
117: + " returns unexpected ERROR = " + errorCode + "("
118: + JDWPConstants.Error.getName(errorCode) + ")");
119: fail(this CommandName + " returns unexpected ERROR = "
120: + errorCode + "("
121: + JDWPConstants.Error.getName(errorCode) + ")");
122: }
123:
124: assertAllDataRead(checkedReply);
125:
126: logWriter
127: .println("=> CHECK PASSED: No any unexpected ERROR is returned");
128:
129: synchronizer
130: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
131: logWriter.println("==> " + this TestName + " for "
132: + this CommandName + ": FINISH");
133: }
134:
135: public static void main(String[] args) {
136: junit.textui.TestRunner.run(SourceDebugExtensionTest.class);
137: }
138: }
|