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 18.02.2005 25 */ 26 package org.apache.harmony.jpda.tests.jdwp.ReferenceType; 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.ReplyPacket; 31 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; 32 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 33 34 35 /** 36 * JDWP Unit test for ReferenceType.FieldsWithGeneric command. 37 */ 38 public class FieldsWithGenericTest extends JDWPSyncTestCase { 39 40 static final int testStatusPassed = 0; 41 static final int testStatusFailed = -1; 42 static final String thisCommandName = "ReferenceType.FieldsWithGeneric command"; 43 static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/FieldsWithGenericDebuggee;"; 44 getDebuggeeClassName()45 protected String getDebuggeeClassName() { 46 return "org.apache.harmony.jpda.tests.jdwp.ReferenceType.FieldsWithGenericDebuggee"; 47 } 48 49 /** 50 * This testcase exercises ReferenceType.FieldsWithGeneric command. 51 * <BR>The test starts FieldsWithGenericDebuggee class, 52 * requests referenceTypeId for this class by VirtualMachine.ClassesBySignature 53 * command, then performs ReferenceType.FieldsWithGeneric command 54 * and checks that returned list of fields corresponds to expected list 55 * with expected attributes. 56 */ testFieldsWithGeneric001()57 public void testFieldsWithGeneric001() { 58 String thisTestName = "testFieldsWithGeneric001"; 59 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START..."); 60 int testStatus = testStatusPassed; 61 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 62 63 long refTypeID = getClassIDBySignature(debuggeeSignature); 64 65 logWriter.println("=> Debuggee class = " + getDebuggeeClassName()); 66 logWriter.println("=> referenceTypeID for Debuggee class = " + refTypeID); 67 logWriter.println("=> CHECK: send " + thisCommandName + " and check reply..."); 68 69 CommandPacket fieldsWithGenericCommand = new CommandPacket( 70 JDWPCommands.ReferenceTypeCommandSet.CommandSetID, 71 JDWPCommands.ReferenceTypeCommandSet.FieldsWithGenericCommand); 72 fieldsWithGenericCommand.setNextValueAsReferenceTypeID(refTypeID); 73 74 ReplyPacket fieldsWithGenericReply = debuggeeWrapper.vmMirror.performCommand(fieldsWithGenericCommand); 75 fieldsWithGenericCommand = null; 76 checkReplyPacket(fieldsWithGenericReply, thisCommandName); 77 78 int returnedFieldsNumber = fieldsWithGenericReply.getNextValueAsInt(); 79 logWriter.println("=> Returned fields number = " + returnedFieldsNumber); 80 81 String fieldNames[] = { 82 "staticLongField", 83 "stringArrayField", 84 "objectArrayField", 85 "classObjectField" 86 }; 87 88 String fieldSignatures[] = { 89 "J", 90 "[Ljava/lang/String;", 91 "[Ljava/lang/Object;", 92 "Ljava/lang/Class;" 93 }; 94 95 String fieldGenericSignatures[] = { 96 "", 97 "", 98 "", 99 "" 100 }; 101 102 int fieldModifiers[] = { 103 0x8, // ACC_STATIC flag 104 0x0, 105 0x0, 106 0x0 107 }; 108 109 boolean fieldFound[] = { 110 false, 111 false, 112 false, 113 false 114 }; 115 int expectedFieldsNumber = fieldNames.length; 116 int fieldSyntheticFlag = 0xf0000000; 117 String message = null; 118 119 logWriter.println("=> CHECK for all expected fields..."); 120 for (int i = 0; i < returnedFieldsNumber; i++) { 121 long returnedFieldID = fieldsWithGenericReply.getNextValueAsFieldID(); 122 String returnedFieldName = fieldsWithGenericReply.getNextValueAsString(); 123 String returnedFieldSignature = fieldsWithGenericReply.getNextValueAsString(); 124 String returnedGenericSignature = fieldsWithGenericReply.getNextValueAsString(); 125 int returnedFieldModifiers = fieldsWithGenericReply.getNextValueAsInt(); 126 logWriter.println("\n=> Field ID = " + returnedFieldID); 127 logWriter.println("=> Field name = " + returnedFieldName); 128 logWriter.println("=> Field signature = \"" + returnedFieldSignature + "\""); 129 logWriter.println("=> Field generic signature = \"" + returnedGenericSignature + "\""); 130 logWriter.println("=> Field modifiers = 0x" + Integer.toHexString(returnedFieldModifiers)); 131 if ( (returnedFieldModifiers & fieldSyntheticFlag) == fieldSyntheticFlag ) { 132 continue; // do not check synthetic fields 133 } 134 int k = 0; 135 for (; k < expectedFieldsNumber; k++) { 136 if ( ! fieldNames[k].equals(returnedFieldName)) { 137 continue; 138 } 139 if ( fieldFound[k] ) { 140 logWriter.println("\n## FAILURE: The field is found out repeatedly in the list"); 141 logWriter.println("## Field name = " + returnedFieldName); 142 testStatus = testStatusFailed; 143 message = "The field is found repeatedly in the list: " + 144 returnedFieldName; 145 break; 146 } 147 fieldFound[k] = true; 148 if ( ! fieldSignatures[k].equals(returnedFieldSignature) ) { 149 logWriter.println("\n## FAILURE: Unexpected field signature is returned:"); 150 logWriter.println("## Field name = " + returnedFieldName); 151 logWriter.println("## Expected signature = " + fieldSignatures[k]); 152 logWriter.println("## Returned signature = " + returnedFieldSignature); 153 testStatus = testStatusFailed; 154 message = "Unexpected signature is returned for field: " + returnedFieldName + 155 ", expected: " + fieldSignatures[k] + 156 ", returned: " + returnedFieldSignature; 157 } 158 if ( ! fieldGenericSignatures[k].equals(returnedGenericSignature) ) { 159 logWriter.println("\n## FAILURE: Unexpected field generic signature is returned:"); 160 logWriter.println("## Field name = " + returnedFieldName); 161 logWriter.println 162 ("## Expected generic signature = \"" + fieldGenericSignatures[k] + "\""); 163 logWriter.println 164 ("## Returned generic signature = \"" + returnedGenericSignature + "\""); 165 testStatus = testStatusFailed; 166 message = "Unexpected generic signature is returned for filed: " + 167 returnedFieldName + 168 ", expected: \"" + fieldGenericSignatures[k] + "\"" + 169 ", returned: \"" + returnedGenericSignature + "\""; 170 } 171 if ( fieldModifiers[k] != returnedFieldModifiers ) { 172 logWriter.println("\n## FAILURE: Unexpected field modifiers are returned:"); 173 logWriter.println("## Field name = " + returnedFieldName); 174 logWriter.println 175 ("## Expected modifiers = 0x" + Integer.toHexString(fieldModifiers[k])); 176 logWriter.println 177 ("## Returned modifiers = 0x" + Integer.toHexString(returnedFieldModifiers)); 178 testStatus = testStatusFailed; 179 message = "Unexpected modifiers are returned for field: " + returnedFieldName + 180 ", expected: 0x" + Integer.toHexString(fieldModifiers[k]) + 181 ", returned: 0x" + Integer.toHexString(returnedFieldModifiers); 182 } 183 break; 184 } 185 if ( k == expectedFieldsNumber ) { 186 // returned field is not found out in the list of expected fields 187 logWriter.println("\n## FAILURE: It is found out unexpected returned field:"); 188 logWriter.println("## Field name = " + returnedFieldName); 189 logWriter.println("## Field signature = " + returnedFieldSignature); 190 logWriter.println("## Field generic signature = \"" + returnedGenericSignature + "\""); 191 logWriter.println 192 ("## Field modifiers = 0x" + Integer.toHexString(returnedFieldModifiers)); 193 testStatus = testStatusFailed; 194 message = 195 "Unexpected returned field: " + 196 returnedFieldName + 197 ", signature = " + returnedFieldSignature + 198 ", generic signature = \"" + returnedGenericSignature + "\"" + 199 ", modifiers = 0x" + Integer.toHexString(returnedFieldModifiers); 200 } 201 } 202 203 for (int k = 0; k < expectedFieldsNumber; k++) { 204 if (!fieldFound[k]) { 205 logWriter.println 206 ("\n## FAILURE: Expected field is NOT found out in the list of retuned fields:"); 207 logWriter.println("## Field name = " + fieldNames[k]); 208 testStatus = testStatusFailed; 209 message = 210 "Expected field is NOT found in the list of retuned fields: " + 211 fieldNames[k]; 212 } 213 } 214 215 if (testStatus == testStatusPassed) { 216 logWriter.println 217 ("=> CHECK PASSED: All expected fields are found out and have expected attributes"); 218 } 219 220 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 221 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": FINISH"); 222 if (testStatus == testStatusFailed) { 223 fail(message); 224 } 225 226 assertAllDataRead(fieldsWithGenericReply); 227 } 228 } 229