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 20.05.2005 25 */ 26package org.apache.harmony.jpda.tests.jdwp.ReferenceType; 27 28import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; 29import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; 30import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants; 31import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; 32import org.apache.harmony.jpda.tests.framework.jdwp.Value; 33import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; 34import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 35 36 37/** 38 * JDWP Unit test for ReferenceType.GetValues command for field from another class. 39 */ 40public class GetValues004Test extends JDWPSyncTestCase { 41 42 static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/GetValues004Debuggee;"; 43 static final String anotherClassSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/RFGetValues004AnotherClass;"; 44 45 @Override 46 protected String getDebuggeeClassName() { 47 return "org.apache.harmony.jpda.tests.jdwp.ReferenceType.GetValues004Debuggee"; 48 } 49 50 /** 51 * This testcase exercises ReferenceType.GetValues command for field from another class. 52 * <BR>The test starts GetValues004Debuggee and checks that 53 * ReferenceType.GetValues command runs correctly for field declaring 54 * in some another class than passed to GetValues command ReferenceTypeID which is 55 * not assignable from that another class. 56 * <BR>Test expects that INVALID_FIELDID error is returned. 57 */ 58 public void testGetValues004() { 59 String thisTestName = "testGetValues004"; 60 logWriter.println("==> " + thisTestName + " for ReferenceType.GetValues command: START..."); 61 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 62 63 logWriter.println 64 ("\n=> Get anotherClassRefTypeID for checkedClass class = RFGetValues003AnotherClass..."); 65 long anotherClassRefTypeID = 0; 66 try { 67 anotherClassRefTypeID = debuggeeWrapper.vmMirror.getClassID(anotherClassSignature); 68 } catch ( Throwable thrown) { 69 logWriter.println("## FAILURE: Can not get anotherClassRefTypeID:"); 70 logWriter.println("## Exception: " + thrown); 71 fail("Can not get anotherClassRefTypeID, Exception: " + thrown); 72 } 73 if ( anotherClassRefTypeID == -1 ) { 74 logWriter.println("## FAILURE: Can not get debuggeeRefTypeID for given signature!"); 75 logWriter.println("## Signature = |" + anotherClassSignature + "|"); 76 fail("Can not get debuggeeRefTypeID for given signature:<" + anotherClassSignature + ">"); 77 } 78 logWriter.println("=> anotherClassRefTypeID = " + anotherClassRefTypeID); 79 80 logWriter.println 81 ("\n=> Get anotherClassCheckedFieldID for field of anotherClass..."); 82 String anotherClassCheckedFieldName = "anotherClassStaticIntVar"; 83 long anotherClassCheckedFieldID = 0; 84 try { 85 anotherClassCheckedFieldID 86 = debuggeeWrapper.vmMirror.getFieldID(anotherClassRefTypeID, anotherClassCheckedFieldName); 87 } catch ( Throwable thrown) { 88 logWriter.println("## FAILURE: Can not get anotherClassCheckedFieldID:"); 89 logWriter.println("## Exception: " + thrown); 90 fail("Can not get anotherClassCheckedFieldID, Exception: " + thrown); 91 } 92 logWriter.println("=> superClassCheckedFieldID = " + anotherClassCheckedFieldID); 93 94 logWriter.println 95 ("\n=> Get debuggeeRefTypeID for debuggee class = " + getDebuggeeClassName() + "..."); 96 long debuggeeRefTypeID = 0; 97 try { 98 debuggeeRefTypeID = debuggeeWrapper.vmMirror.getClassID(debuggeeSignature); 99 } catch ( Throwable thrown) { 100 logWriter.println("## FAILURE: Can not get debuggeeRefTypeID:"); 101 logWriter.println("## Exception: " + thrown); 102 fail("Can not get debuggeeRefTypeID, Exception: " + thrown); 103 } 104 if ( debuggeeRefTypeID == -1 ) { 105 logWriter.println("## FAILURE: Can not get debuggeeRefTypeID for given signature!"); 106 logWriter.println("## Signature = |" + debuggeeSignature + "|"); 107 fail("Can not get debuggeeRefTypeID for given signature:<" + debuggeeSignature + ">"); 108 } 109 logWriter.println("=> debuggeeRefTypeID = " + debuggeeRefTypeID); 110 111 logWriter.println 112 ("\n=> CHECK ReferenceType::GetValues command for debuggeeRefTypeID, anotherClassCheckedFieldID..."); 113 logWriter.println 114 ("=> 'INVALID_FIELDID' error is expected as anotherClassCheckedField is not field of debuggee class!"); 115 CommandPacket getValuesCommand = new CommandPacket( 116 JDWPCommands.ReferenceTypeCommandSet.CommandSetID, 117 JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand); 118 getValuesCommand.setNextValueAsReferenceTypeID(debuggeeRefTypeID); 119 getValuesCommand.setNextValueAsInt(1); 120 getValuesCommand.setNextValueAsFieldID(anotherClassCheckedFieldID); 121 ReplyPacket getValuesReply = debuggeeWrapper.vmMirror.performCommand(getValuesCommand); 122 short errorCode = getValuesReply.getErrorCode(); 123 if ( errorCode != JDWPConstants.Error.NONE ) { 124 checkReplyPacket(getValuesReply, "ReferenceType::GetValues command", JDWPConstants.Error.INVALID_FIELDID); 125 logWriter.println("=> CHECK PASSED: Expected error (INVALID_FIELDID) is returned"); 126 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 127 return; 128 } 129 logWriter.println 130 ("## FAILURE: ReferenceType::GetValues command does NOT return expected error - INVALID_FIELDID"); 131 132 // next is only for extra info 133 //int returnedValuesNumber = 134 getValuesReply.getNextValueAsInt(); 135 Value fieldValue = getValuesReply.getNextValueAsValue(); 136 byte fieldTag = fieldValue.getTag(); 137 logWriter.println("## Returned value tag = " + fieldTag 138 + "(" + JDWPConstants.Tag.getName(fieldTag) + ")"); 139 if ( fieldTag == JDWPConstants.Tag.INT_TAG ) { 140 int intValue = fieldValue.getIntValue(); 141 logWriter.println("## Returned value = " + intValue); 142 } 143 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 144 fail("ReferenceType::GetValues command does NOT return expected error - INVALID_FIELDID"); 145 } 146} 147