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 13.07.2005 25 */ 26 27 package org.apache.harmony.jpda.tests.jdwp.ObjectReference; 28 29 import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; 30 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; 31 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants; 32 import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; 33 import org.apache.harmony.jpda.tests.framework.jdwp.Value; 34 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; 35 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 36 37 38 /** 39 * JDWP Unit test for ObjectReference.SetValues command with null values. 40 */ 41 public class SetValues004Test extends JDWPSyncTestCase { 42 43 static final int testStatusPassed = 0; 44 static final int testStatusFailed = -1; 45 static final String thisCommandName = "ObjectReference.SetValues command"; 46 static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ObjectReference/SetValues004Debuggee;"; 47 getDebuggeeClassName()48 protected String getDebuggeeClassName() { 49 return "org.apache.harmony.jpda.tests.jdwp.ObjectReference.SetValues004Debuggee"; 50 } 51 52 /** 53 * This test exercises ObjectReference.SetValues command with null values. 54 * <BR>The test starts SetValues004Debuggee 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 57 * fields of different referenceTypes with value=null for all fields. 58 * <BR>The test expects the all fields should be set by null value. 59 */ testSetValues004()60 public void testSetValues004() { 61 String thisTestName = "testSetValues004"; 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 "testedObject", 72 "intArrayField", 73 "objectArrayField", 74 "objectField", 75 "stringField", 76 "threadField", 77 "threadGroupField", 78 "classField", 79 "classLoaderField", 80 }; 81 long checkedFieldIDs[] = checkFields(refTypeID, checkedFieldNames); 82 int checkedFieldsNumber = checkedFieldNames.length; 83 84 logWriter.println 85 ("=> Send ReferenceType::GetValues command and get ObjectID to check..."); 86 87 CommandPacket getValuesCommand = new CommandPacket( 88 JDWPCommands.ReferenceTypeCommandSet.CommandSetID, 89 JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand); 90 getValuesCommand.setNextValueAsReferenceTypeID(refTypeID); 91 getValuesCommand.setNextValueAsInt(1); 92 getValuesCommand.setNextValueAsFieldID(checkedFieldIDs[0]); 93 ReplyPacket getValuesReply = 94 debuggeeWrapper.vmMirror.performCommand(getValuesCommand); 95 getValuesCommand = null; 96 checkReplyPacket(getValuesReply, "ReferenceType::GetValue command"); 97 98 int returnedValuesNumber = getValuesReply.getNextValueAsInt(); 99 logWriter.println("=> Returned values number = " + returnedValuesNumber); 100 assertEquals("Invalid number of values,", 1, returnedValuesNumber); 101 102 Value checkedObjectFieldValue = getValuesReply.getNextValueAsValue(); 103 byte checkedObjectFieldTag = checkedObjectFieldValue.getTag(); 104 logWriter.println("=> Returned field value tag for checked object= " + checkedObjectFieldTag 105 + "(" + JDWPConstants.Tag.getName(checkedObjectFieldTag) + ")"); 106 assertEquals("Invalid value tag for checked object,", JDWPConstants.Tag.OBJECT_TAG, checkedObjectFieldTag 107 , JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG) 108 , JDWPConstants.Tag.getName(checkedObjectFieldTag)); 109 110 long checkedObjectID = checkedObjectFieldValue.getLongValue(); 111 logWriter.println("=> Returned checked ObjectID = " + checkedObjectID); 112 logWriter.println 113 ("=> CHECK: send " + thisCommandName 114 + " for this ObjectID for fields of different referenceTypes with null values..."); 115 116 CommandPacket checkedCommand = new CommandPacket( 117 JDWPCommands.ObjectReferenceCommandSet.CommandSetID, 118 JDWPCommands.ObjectReferenceCommandSet.SetValuesCommand); 119 checkedCommand.setNextValueAsObjectID(checkedObjectID); 120 checkedCommand.setNextValueAsInt(checkedFieldsNumber-1); 121 int fieldIndex = 1; 122 for (; fieldIndex < checkedFieldsNumber; fieldIndex++) { 123 checkedCommand.setNextValueAsFieldID(checkedFieldIDs[fieldIndex]); 124 checkedCommand.setNextValueAsObjectID(0); 125 } 126 ReplyPacket checkedReply = 127 debuggeeWrapper.vmMirror.performCommand(checkedCommand); 128 checkedCommand = null; 129 130 checkReplyPacket(checkedReply, "ObjectType::SetValue command"); 131 132 logWriter.println("=> Wait for Debuggee's status about check for set fields..."); 133 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 134 boolean debuggeeStatus = synchronizer.receiveMessage("PASSED"); 135 if ( ! debuggeeStatus ) { 136 logWriter.println("## " + thisTestName + ": Debuggee returned status FAILED"); 137 fail("Debuggee returned status FAILED"); 138 } else { 139 logWriter.println("=> " + thisTestName + ": Debuggee returned status PASSED"); 140 } 141 142 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": OK."); 143 } 144 } 145