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 Anatoly F. Bondarenko 21 */ 22 23 /** 24 * Created on 24.02.2005 25 */ 26 package org.apache.harmony.jpda.tests.jdwp.ReferenceType; 27 28 import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; 29 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; 30 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants; 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.share.JPDADebuggeeSynchronizer; 34 35 36 /** 37 * JDWP Unit test for ReferenceType.SourceDebugExtension command. 38 */ 39 public class SourceDebugExtensionTest extends JDWPSyncTestCase { 40 41 static final int testStatusPassed = 0; 42 static final int testStatusFailed = -1; 43 static final String thisCommandName = "ReferenceType.SourceDebugExtension command"; 44 static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/SourceDebugExtensionDebuggee;"; 45 getDebuggeeClassName()46 protected String getDebuggeeClassName() { 47 return "org.apache.harmony.jpda.tests.jdwp.ReferenceType.SourceDebugExtensionDebuggee"; 48 } 49 50 /** 51 * This testcase exercises ReferenceType.SourceDebugExtension command. 52 * <BR>The test starts SourceDebugExtensionDebuggee class, requests referenceTypeId 53 * for this class by VirtualMachine.ClassesBySignature command, then 54 * performs ReferenceType.SourceDebugExtension command and checks that 55 * no any unexpected ERROR is returned. 56 */ testSourceDebugExtension001()57 public void testSourceDebugExtension001() { 58 String thisTestName = "testSourceDebugExtension001"; 59 60 //check capability, relevant for this test 61 logWriter.println("=> Check capability: canGetSourceDebugExtension"); 62 debuggeeWrapper.vmMirror.capabilities(); 63 boolean isCapability = debuggeeWrapper.vmMirror.targetVMCapabilities.canGetSourceDebugExtension; 64 if (!isCapability) { 65 logWriter.println("##WARNING: this VM doesn't possess capability: canGetSourceDebugExtension"); 66 return; 67 } 68 69 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START..."); 70 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 71 72 long refTypeID = getClassIDBySignature(debuggeeSignature); 73 74 logWriter.println("=> Debuggee class = " + getDebuggeeClassName()); 75 logWriter.println("=> referenceTypeID for Debuggee class = " + refTypeID); 76 logWriter.println("=> CHECK: send " + thisCommandName + " and check reply..."); 77 78 CommandPacket checkedCommand = new CommandPacket( 79 JDWPCommands.ReferenceTypeCommandSet.CommandSetID, 80 JDWPCommands.ReferenceTypeCommandSet.SourceDebugExtensionCommand); 81 checkedCommand.setNextValueAsReferenceTypeID(refTypeID); 82 83 ReplyPacket checkedReply = debuggeeWrapper.vmMirror.performCommand(checkedCommand); 84 checkedCommand = null; 85 86 short errorCode = checkedReply.getErrorCode(); 87 88 switch ( errorCode ) { 89 case JDWPConstants.Error.NONE: 90 logWriter.println("=> No any ERROR is returned"); 91 String SourceDebugExtension = checkedReply.getNextValueAsString(); 92 logWriter.println("=> Returned SourceDebugExtension = " + SourceDebugExtension); 93 break; 94 case JDWPConstants.Error.NOT_IMPLEMENTED: 95 logWriter.println("=> ERROR is returned: "+ errorCode 96 + "(" + JDWPConstants.Error.getName(errorCode) + ")"); 97 logWriter.println("=> It is possible ERROR"); 98 break; 99 case JDWPConstants.Error.ABSENT_INFORMATION: 100 logWriter.println("=> ERROR is returned: "+ errorCode 101 + "(" + JDWPConstants.Error.getName(errorCode) + ")"); 102 logWriter.println("=> It is possible ERROR"); 103 break; 104 default: 105 logWriter.println("\n## FAILURE: " + thisCommandName + " returns unexpected ERROR = " 106 + errorCode + "(" + JDWPConstants.Error.getName(errorCode) + ")"); 107 fail(thisCommandName + " returns unexpected ERROR = " 108 + errorCode + "(" + JDWPConstants.Error.getName(errorCode) + ")"); 109 } 110 111 assertAllDataRead(checkedReply); 112 113 logWriter.println("=> CHECK PASSED: No any unexpected ERROR is returned"); 114 115 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 116 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": FINISH"); 117 } 118 } 119