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.ReferenceType; 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 ReferenceType.GetValues command for fields with null value. 40 */ 41 public class GetValues005Test extends JDWPSyncTestCase { 42 43 static final String thisCommandName = "ReferenceType.GetValues command"; 44 static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/GetValues005Debuggee;"; 45 getDebuggeeClassName()46 protected String getDebuggeeClassName() { 47 return "org.apache.harmony.jpda.tests.jdwp.ReferenceType.GetValues005Debuggee"; 48 } 49 50 /** 51 * This testcase exercises ReferenceType.GetValues command for fields with null value. 52 * <BR>The test starts GetValues005Debuggee class and performs 53 * ReferenceType.GetValues command for fields of different 54 * referenceTypes with value=null for all fields. 55 * <BR>The test expects the all returned values should be represented by expected 56 * JDWP tag with null value. 57 */ testGetValues005()58 public void testGetValues005() { 59 String thisTestName = "testGetValues005"; 60 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START..."); 61 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 62 63 long debuggeeRefTypeID = getClassIDBySignature(debuggeeSignature); 64 65 logWriter.println("=> Debuggee class = " + getDebuggeeClassName()); 66 logWriter.println("=> referenceTypeID for Debuggee class = " + debuggeeRefTypeID); 67 68 String checkedFieldNames[] = { 69 "intArrayField", 70 "objectArrayField", 71 "objectField", 72 "stringField", 73 "threadField", 74 "threadGroupField", 75 "classField", 76 "classLoaderField", 77 }; 78 79 long checkedFieldIDs[] = checkFields(debuggeeRefTypeID, checkedFieldNames); 80 int checkedFieldsNumber = checkedFieldNames.length; 81 82 logWriter.println 83 ("=> CHECK: send " + thisCommandName 84 + " for Debuggee class for fields of different referenceTypes with with null values..."); 85 86 CommandPacket checkedCommand = new CommandPacket( 87 JDWPCommands.ReferenceTypeCommandSet.CommandSetID, 88 JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand); 89 checkedCommand.setNextValueAsObjectID(debuggeeRefTypeID); 90 checkedCommand.setNextValueAsInt(checkedFieldsNumber); 91 for (int i = 0; i < checkedFieldsNumber; i++) { 92 checkedCommand.setNextValueAsFieldID(checkedFieldIDs[i]); 93 } 94 ReplyPacket checkedReply = 95 debuggeeWrapper.vmMirror.performCommand(checkedCommand); 96 checkedCommand = null; 97 98 checkReplyPacket(checkedReply, thisCommandName); 99 100 int returnedValuesNumber = checkedReply.getNextValueAsInt(); 101 logWriter.println("=> Returned values number = " + returnedValuesNumber); 102 if ( checkedFieldsNumber != returnedValuesNumber ) { 103 logWriter.println 104 ("\n## FAILURE: ReferenceType::GetValues command returned unexpected number of values:"); 105 logWriter.println("## Expected number = " + checkedFieldsNumber); 106 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": FINISH"); 107 assertTrue(false); 108 } 109 byte expectedFieldTags[] = { 110 JDWPConstants.Tag.ARRAY_TAG, 111 JDWPConstants.Tag.ARRAY_TAG, 112 JDWPConstants.Tag.OBJECT_TAG, 113 JDWPConstants.Tag.STRING_TAG, 114 JDWPConstants.Tag.THREAD_TAG, 115 JDWPConstants.Tag.THREAD_GROUP_TAG, 116 JDWPConstants.Tag.CLASS_OBJECT_TAG, 117 JDWPConstants.Tag.CLASS_LOADER_TAG, 118 }; 119 logWriter.println("=> CHECK for returned values..."); 120 for (int i=0; i < returnedValuesNumber; i++) { 121 Value fieldValue = checkedReply.getNextValueAsValue(); 122 byte fieldTag = fieldValue.getTag(); 123 logWriter.println 124 ("\n=> Check for returned value for field: " + checkedFieldNames[i] + " ..."); 125 logWriter.println("=> Returned value tag = " + fieldTag 126 + "(" + JDWPConstants.Tag.getName(fieldTag) + ")"); 127 if ( (fieldTag != expectedFieldTags[i]) && (fieldTag != JDWPConstants.Tag.OBJECT_TAG) ) { 128 logWriter.println("\n## FAILURE: Unexpected value tag is returned"); 129 logWriter.println("## Expected value tag = " + expectedFieldTags[i] 130 + "(" + JDWPConstants.Tag.getName(expectedFieldTags[i]) + ")" 131 + " or = " + JDWPConstants.Tag.OBJECT_TAG 132 + "(" + JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG) + ")"); 133 //testStatus = testStatusFailed; 134 fail("Unexpected value tag is returned"); 135 } 136 long objectIDValue = fieldValue.getLongValue(); 137 logWriter.println("=> ObjectId value = " + objectIDValue); 138 assertEquals("Invalid objectID value is returned,", 0, objectIDValue); 139 } 140 141 assertAllDataRead(checkedReply); 142 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 143 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": OK."); 144 } 145 } 146