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 17.03.2005 25 */ 26 package org.apache.harmony.jpda.tests.jdwp.ObjectReference; 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.framework.jdwp.Value; 33 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; 34 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 35 36 37 /** 38 * JDWP Unit test for ObjectReference.SetValues command with value with incorrect Type. 39 */ 40 public class SetValues003Test extends JDWPSyncTestCase { 41 42 static final int testStatusPassed = 0; 43 static final int testStatusFailed = -1; 44 static final String thisCommandName = "ObjectReference.SetValues command"; 45 static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ObjectReference/SetValues003Debuggee;"; 46 getDebuggeeClassName()47 protected String getDebuggeeClassName() { 48 return "org.apache.harmony.jpda.tests.jdwp.ObjectReference.SetValues003Debuggee"; 49 } 50 51 /** 52 * This test exercises ObjectReference.SetValues command with value with incorrect Type. 53 * <BR>The test starts SetValues003Debuggee class, gets objectID 54 * as value of static field of this class which (field) represents checked object. 55 * Then for this objectID test executes ObjectReference.SetValues command for 56 * fieldID of referenceType but with value of other referenceType. 57 * <BR>The test expects the field should not be set. 58 */ testSetValues003()59 public void testSetValues003() { 60 61 String thisTestName = "testSetValues003"; 62 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START..."); 63 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 64 65 long refTypeID = getClassIDBySignature(debuggeeSignature); 66 67 logWriter.println("=> Debuggee class = " + getDebuggeeClassName()); 68 logWriter.println("=> referenceTypeID for Debuggee class = " + refTypeID); 69 70 String checkedFieldNames[] = { 71 "setValues003DebuggeeObject", 72 "objectField", 73 }; 74 long checkedFieldIDs[] = checkFields(refTypeID, checkedFieldNames); 75 int checkedFieldsNumber = checkedFieldNames.length; 76 77 logWriter.println 78 ("=> Send ReferenceType::GetValues command and get ObjectID to check..."); 79 80 CommandPacket getValuesCommand = new CommandPacket( 81 JDWPCommands.ReferenceTypeCommandSet.CommandSetID, 82 JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand); 83 getValuesCommand.setNextValueAsReferenceTypeID(refTypeID); 84 getValuesCommand.setNextValueAsInt(1); 85 getValuesCommand.setNextValueAsFieldID(checkedFieldIDs[0]); 86 ReplyPacket getValuesReply = 87 debuggeeWrapper.vmMirror.performCommand(getValuesCommand); 88 getValuesCommand = null; 89 checkReplyPacket(getValuesReply, "ReferenceType::GetValues command"); 90 91 int returnedValuesNumber = getValuesReply.getNextValueAsInt(); 92 logWriter.println("=> Returned values number = " + returnedValuesNumber); 93 assertEquals("Invalid number of values,", 1, returnedValuesNumber); 94 95 Value checkedObjectFieldValue = getValuesReply.getNextValueAsValue(); 96 byte checkedObjectFieldTag = checkedObjectFieldValue.getTag(); 97 logWriter.println("=> Returned field value tag for checked object= " + checkedObjectFieldTag 98 + "(" + JDWPConstants.Tag.getName(checkedObjectFieldTag) + ")"); 99 assertEquals("Invalid value tag for checked object,", JDWPConstants.Tag.OBJECT_TAG, checkedObjectFieldTag 100 , JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG) 101 , JDWPConstants.Tag.getName(checkedObjectFieldTag)); 102 103 long checkedObjectID = checkedObjectFieldValue.getLongValue(); 104 logWriter.println("=> Returned checked ObjectID = " + checkedObjectID); 105 logWriter.println 106 ("=> CHECK: send " + thisCommandName 107 + " for this ObjectID with value which has other referenceType than field to set..."); 108 109 CommandPacket checkedCommand = new CommandPacket( 110 JDWPCommands.ObjectReferenceCommandSet.CommandSetID, 111 JDWPCommands.ObjectReferenceCommandSet.SetValuesCommand); 112 checkedCommand.setNextValueAsObjectID(checkedObjectID); 113 checkedCommand.setNextValueAsInt(checkedFieldsNumber-1); 114 int fieldIndex = 1; 115 for (; fieldIndex < checkedFieldsNumber; fieldIndex++) { 116 checkedCommand.setNextValueAsFieldID(checkedFieldIDs[fieldIndex]); 117 switch ( fieldIndex ) { 118 case 1: // objectField 119 checkedCommand.setNextValueAsObjectID(checkedObjectID); 120 break; 121 } 122 } 123 ReplyPacket checkedReply = 124 debuggeeWrapper.vmMirror.performCommand(checkedCommand); 125 checkedCommand = null; 126 127 short errorCode = checkedReply.getErrorCode(); 128 if ( errorCode == JDWPConstants.Error.NONE ) { 129 logWriter.println("=> " + thisCommandName 130 + " run without any ERROR!"); 131 } else { 132 logWriter.println("=> " + thisCommandName 133 + " returns ERROR = " + errorCode 134 + "(" + JDWPConstants.Error.getName(errorCode) + ")"); 135 } 136 137 logWriter.println("=> Wait for Debuggee's status about check for set field..."); 138 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 139 boolean debuggeeStatus = synchronizer.receiveMessage("PASSED"); 140 if ( ! debuggeeStatus ) { 141 logWriter.println("## " + thisTestName + ": Debuggee returned status FAILED"); 142 fail("Debuggee returned status FAILED"); 143 } else { 144 logWriter.println("=> " + thisTestName + ": Debuggee returned status PASSED"); 145 } 146 147 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": OK."); 148 } 149 } 150