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.ArrayReference; 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 ArrayReference.SetValues command with specific values. 40 */ 41 public class SetValues002Test extends JDWPSyncTestCase { 42 43 static final int testStatusPassed = 0; 44 static final int testStatusFailed = -1; 45 static final String thisCommandName = "ArrayReference::SetValues command"; 46 static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ArrayReference/SetValues002Debuggee;"; 47 48 /** 49 * Returns full name of debuggee class which is used by this test. 50 * @return full name of debuggee class. 51 */ 52 @Override 53 protected String getDebuggeeClassName() { 54 return "org.apache.harmony.jpda.tests.jdwp.ArrayReference.SetValues002Debuggee"; 55 } 56 57 /** 58 * This testcase exercises ArrayReference.SetValues command for 59 * array of elements of referenceType with value=null. 60 * <BR>The test expects array element should be set by null value. 61 */ 62 public void testSetValues002() { 63 String thisTestName = "testSetValues002"; 64 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START..."); 65 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 66 67 CommandPacket classesBySignatureCommand = new CommandPacket( 68 JDWPCommands.VirtualMachineCommandSet.CommandSetID, 69 JDWPCommands.VirtualMachineCommandSet.ClassesBySignatureCommand); 70 classesBySignatureCommand.setNextValueAsString(debuggeeSignature); 71 ReplyPacket classesBySignatureReply = 72 debuggeeWrapper.vmMirror.performCommand(classesBySignatureCommand); 73 classesBySignatureCommand = null; 74 checkReplyPacket(classesBySignatureReply, "VirtualMachine::ClassesBySignature command"); 75 76 classesBySignatureReply.getNextValueAsInt(); 77 // Number of returned reference types - is NOT used here 78 79 classesBySignatureReply.getNextValueAsByte(); 80 // refTypeTag of class - is NOT used here 81 82 long refTypeID = classesBySignatureReply.getNextValueAsReferenceTypeID(); 83 classesBySignatureReply = null; 84 85 logWriter.println("=> Debuggee class = " + getDebuggeeClassName()); 86 logWriter.println("=> referenceTypeID for Debuggee class = " + refTypeID); 87 88 String checkedFieldNames[] = { 89 "objectArrayField", 90 }; 91 long checkedFieldIDs[] = checkFields(refTypeID, checkedFieldNames); 92 93 logWriter.println("=> Send ReferenceType::GetValues command and get ArrayID to check..."); 94 95 CommandPacket getValuesCommand = new CommandPacket( 96 JDWPCommands.ReferenceTypeCommandSet.CommandSetID, 97 JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand); 98 getValuesCommand.setNextValueAsReferenceTypeID(refTypeID); 99 getValuesCommand.setNextValueAsInt(1); 100 getValuesCommand.setNextValueAsFieldID(checkedFieldIDs[0]); 101 ReplyPacket getValuesReply = 102 debuggeeWrapper.vmMirror.performCommand(getValuesCommand); 103 getValuesCommand = null; 104 checkReplyPacket(getValuesReply, "ReferenceType::GetValues command"); 105 106 int returnedValuesNumber = getValuesReply.getNextValueAsInt(); 107 assertEquals("ReferenceType::GetValues returned invalid number of values,", 108 1, returnedValuesNumber); 109 logWriter.println("=> Returned values number = " + returnedValuesNumber); 110 111 Value checkedObjectFieldValue = getValuesReply.getNextValueAsValue(); 112 byte checkedObjectFieldTag = checkedObjectFieldValue.getTag(); 113 logWriter.println("=> Returned field value tag for checked object= " + checkedObjectFieldTag 114 + "(" + JDWPConstants.Tag.getName(checkedObjectFieldTag) + ")"); 115 116 assertEquals("ReferenceType::GetValues returned invalid object field tag,", 117 JDWPConstants.Tag.ARRAY_TAG, checkedObjectFieldTag, 118 JDWPConstants.Tag.getName(JDWPConstants.Tag.ARRAY_TAG), 119 JDWPConstants.Tag.getName(checkedObjectFieldTag)); 120 121 long checkedObjectID = checkedObjectFieldValue.getLongValue(); 122 logWriter.println("=> Returned checked ArrayID = " + checkedObjectID); 123 logWriter.println("=> CHECK: send " + thisCommandName 124 + " for this ArrayID for element of referenceType with null values..."); 125 126 CommandPacket checkedCommand = new CommandPacket( 127 JDWPCommands.ArrayReferenceCommandSet.CommandSetID, 128 JDWPCommands.ArrayReferenceCommandSet.SetValuesCommand); 129 checkedCommand.setNextValueAsObjectID(checkedObjectID); 130 checkedCommand.setNextValueAsInt(0); // first index 131 checkedCommand.setNextValueAsInt(1); // elements' number 132 checkedCommand.setNextValueAsObjectID(0); // null value 133 ReplyPacket checkedReply = debuggeeWrapper.vmMirror.performCommand(checkedCommand); 134 checkedCommand = null; 135 checkReplyPacket(checkedReply, "ArrayReference::SetValues command"); 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 //logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": FAILED"); 143 fail("Debuggee returned status FAILED"); 144 } else { 145 logWriter.println("=> " + thisTestName + ": Debuggee returned status PASSED"); 146 } 147 148 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": OK."); 149 } 150 } 151