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 28.02.2005 25 */ 26package org.apache.harmony.jpda.tests.jdwp.ObjectReference; 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 ObjectReference.SetValues command. 39 */ 40public class SetValuesTest 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/SetValuesDebuggee;"; 46 47 @Override 48 protected String getDebuggeeClassName() { 49 return "org.apache.harmony.jpda.tests.jdwp.ObjectReference.SetValuesDebuggee"; 50 } 51 52 /** 53 * This test exercises ObjectReference.SetValues command. 54 * <BR>The test starts SetValuesDebuggee class, gets objectID 55 * as value of static field of this class which (field) represents checked object. 56 * Then for this objectID test executes ObjectReference.SetValues command for special 57 * set of fieldIDs and checks that command returns reply without any errors. 58 * <BR>Then test waits for Debuggee to check if set fields have expected values. 59 * If so test passes, otherwise - fails. 60 */ 61 public void testSetValues001() { 62 String thisTestName = "testSetValues001"; 63 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START..."); 64 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 65 66 long refTypeID = getClassIDBySignature(debuggeeSignature); 67 68 logWriter.println("=> Debuggee class = " + getDebuggeeClassName()); 69 logWriter.println("=> referenceTypeID for Debuggee class = " + refTypeID); 70 71 String checkedFieldNames[] = { 72 "setValuesDebuggeeObject", 73 "intField", 74 "longField", 75 "objectField", 76 "staticIntField", 77 "privateIntField", 78 "finalIntField", 79 }; 80 long checkedFieldIDs[] = checkFields(refTypeID, checkedFieldNames); 81 int checkedFieldsNumber = checkedFieldNames.length; 82 83 logWriter.println 84 ("=> Send ReferenceType::GetValues command and and get ObjectID to check..."); 85 86 CommandPacket getValuesCommand = new CommandPacket( 87 JDWPCommands.ReferenceTypeCommandSet.CommandSetID, 88 JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand); 89 getValuesCommand.setNextValueAsReferenceTypeID(refTypeID); 90 getValuesCommand.setNextValueAsInt(1); 91 getValuesCommand.setNextValueAsFieldID(checkedFieldIDs[0]); 92 ReplyPacket getValuesReply = 93 debuggeeWrapper.vmMirror.performCommand(getValuesCommand); 94 getValuesCommand = null; 95 checkReplyPacket(getValuesReply, "ReferenceType::GetValues command"); 96 97 int returnedValuesNumber = getValuesReply.getNextValueAsInt(); 98 logWriter.println("=> Returned values number = " + returnedValuesNumber); 99 assertEquals("Invalid number of values,", 1, returnedValuesNumber); 100 101 Value checkedObjectFieldValue = getValuesReply.getNextValueAsValue(); 102 byte checkedObjectFieldTag = checkedObjectFieldValue.getTag(); 103 logWriter.println("=> Returned field value tag for checked object= " + checkedObjectFieldTag 104 + "(" + JDWPConstants.Tag.getName(checkedObjectFieldTag) + ")"); 105 assertEquals("Invalid value tag for checked object,", JDWPConstants.Tag.OBJECT_TAG, checkedObjectFieldTag 106 , JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG) 107 , JDWPConstants.Tag.getName(checkedObjectFieldTag)); 108 109 long checkedObjectID = checkedObjectFieldValue.getLongValue(); 110 logWriter.println("=> Returned checked ObjectID = " + checkedObjectID); 111 logWriter.println("=> CHECK: send " + thisCommandName + " for this ObjectID and check reply..."); 112 113 CommandPacket checkedCommand = new CommandPacket( 114 JDWPCommands.ObjectReferenceCommandSet.CommandSetID, 115 JDWPCommands.ObjectReferenceCommandSet.SetValuesCommand); 116 checkedCommand.setNextValueAsObjectID(checkedObjectID); 117 checkedCommand.setNextValueAsInt(checkedFieldsNumber-1); 118 int fieldIndex = 1; // !!! 119 for (; fieldIndex < checkedFieldsNumber; fieldIndex++) { 120 checkedCommand.setNextValueAsFieldID(checkedFieldIDs[fieldIndex]); 121 switch ( fieldIndex ) { 122 case 1: // intField 123 checkedCommand.setNextValueAsInt(1111); 124 break; 125 case 2: // longField 126 checkedCommand.setNextValueAsLong(22222222); 127 break; 128 case 3: // objectField 129 checkedCommand.setNextValueAsObjectID(checkedObjectID); 130 break; 131 case 4: // staticIntField 132 checkedCommand.setNextValueAsInt(5555); 133 break; 134 case 5: // privateIntField 135 checkedCommand.setNextValueAsInt(7777); 136 break; 137 case 6: // finalIntField 138 checkedCommand.setNextValueAsInt(6666); 139 break; 140 } 141 } 142 ReplyPacket checkedReply = 143 debuggeeWrapper.vmMirror.performCommand(checkedCommand); 144 checkedCommand = null; 145 checkReplyPacket(checkedReply, thisCommandName); 146 147 logWriter.println("=> Reply was received without any Errors"); 148 logWriter.println("=> Wait for Debuggee's status about check for set fields..."); 149 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 150 boolean debuggeeStatus = synchronizer.receiveMessage("PASSED"); 151 if ( ! debuggeeStatus ) { 152 logWriter.println("## " + thisTestName + ": Debuggee returned status FAILED"); 153 fail("Debuggee returned status FAILED"); 154 } else { 155 logWriter.println("=> " + thisTestName + ": Debuggee returned status PASSED"); 156 } 157 158 assertAllDataRead(checkedReply); 159 160 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": FINISH"); 161 } 162} 163