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.MethodsWithGeneric command. 37 */ 38 public class MethodsWithGenericTest extends JDWPSyncTestCase { 39 40 static final int testStatusPassed = 0; 41 static final int testStatusFailed = -1; 42 static final String thisCommandName = "ReferenceType.MethodsWithGeneric command"; 43 static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/MethodsWithGenericDebuggee;"; 44 getDebuggeeClassName()45 protected String getDebuggeeClassName() { 46 return "org.apache.harmony.jpda.tests.jdwp.ReferenceType.MethodsWithGenericDebuggee"; 47 } 48 49 /** 50 * This testcase exercises ReferenceType.ClassObject command. 51 * <BR>The test starts MethodsWithGenericDebuggee class, requests referenceTypeId 52 * for this class by VirtualMachine.ClassesBySignature command, then 53 * performs ReferenceType.MethodsWithGeneric command and checks that returned 54 * list of methods corresponds to expected list of methods with expected attributes. 55 */ testMethodsWithGeneric001()56 public void testMethodsWithGeneric001() { 57 String thisTestName = "testMethodsWithGeneric001"; 58 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START..."); 59 int testStatus = testStatusPassed; 60 String failMessage = ""; 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 methodsWithGenericCommand = new CommandPacket( 70 JDWPCommands.ReferenceTypeCommandSet.CommandSetID, 71 JDWPCommands.ReferenceTypeCommandSet.MethodsWithGenericCommand); 72 methodsWithGenericCommand.setNextValueAsReferenceTypeID(refTypeID); 73 74 ReplyPacket methodsWithGenericReply = debuggeeWrapper.vmMirror.performCommand(methodsWithGenericCommand); 75 methodsWithGenericCommand = null; 76 checkReplyPacket(methodsWithGenericReply, thisCommandName); 77 78 int returnedMethodsNumber = methodsWithGenericReply.getNextValueAsInt(); 79 logWriter.println("=> Returned methods number = " + returnedMethodsNumber); 80 81 String methodNames[] = { 82 "staticTestMethod", 83 "objectTestMethod", 84 "run", 85 "main", 86 "<init>" 87 }; 88 89 String methodSignatures[] = { 90 "(D)Z", 91 "(Ljava/util/Collection;)Ljava/lang/Object;", 92 "()V", 93 "([Ljava/lang/String;)V", 94 "()V" 95 }; 96 97 String methodGenericSignatures[] = { 98 "", 99 "", 100 "", 101 "", 102 "" 103 }; 104 105 int methodModifiers[] = { 106 0x8, // ACC_STATIC flag 107 0x0, 108 0x1, // ACC_PUBLIC flag 109 0x9, // ACC_STATIC | ACC_PUBLIC flags 110 0x1 // ACC_PUBLIC flag 111 }; 112 113 boolean methodFound[] = { 114 false, 115 false, 116 false, 117 false, 118 false 119 }; 120 int expectedMetodsNumber = methodNames.length; 121 int methodSyntheticFlag = 0xf0000000; 122 123 logWriter.println("=> CHECK for all expected methods..."); 124 for (int i = 0; i < returnedMethodsNumber; i++) { 125 long returnedMethodID = methodsWithGenericReply.getNextValueAsMethodID(); 126 String returnedMethodName = methodsWithGenericReply.getNextValueAsString(); 127 String returnedMethodSignature = methodsWithGenericReply.getNextValueAsString(); 128 String returnedGenericSignature = methodsWithGenericReply.getNextValueAsString(); 129 int returnedMethodModifiers = methodsWithGenericReply.getNextValueAsInt(); 130 logWriter.println("\n=> Method ID = " + returnedMethodID); 131 logWriter.println("=> Method name = " + returnedMethodName); 132 logWriter.println("=> Method signature = \"" + returnedMethodSignature + "\""); 133 logWriter.println("=> Method generic signature = \"" + returnedGenericSignature + "\""); 134 logWriter.println("=> Method modifiers = 0x" + Integer.toHexString(returnedMethodModifiers)); 135 if ( (returnedMethodModifiers & methodSyntheticFlag) == methodSyntheticFlag ) { 136 continue; // do not check synthetic methods 137 } 138 int k = 0; 139 for (; k < expectedMetodsNumber; k++) { 140 if ( ! methodNames[k].equals(returnedMethodName)) { 141 continue; 142 } 143 if ( methodFound[k] ) { 144 logWriter.println("\n## FAILURE: The method is found out repeatedly in the list"); 145 logWriter.println("## Method name = " + returnedMethodName); 146 testStatus = testStatusFailed; 147 failMessage = failMessage + 148 "The method is found repeatedly in the list: " + 149 returnedMethodName + ";\n"; 150 break; 151 } 152 methodFound[k] = true; 153 if ( ! methodSignatures[k].equals(returnedMethodSignature) ) { 154 logWriter.println("\n## FAILURE: Unexpected method signature is returned:"); 155 logWriter.println("## Method name = " + returnedMethodName); 156 logWriter.println("## Expected signature = " + methodSignatures[k]); 157 logWriter.println("## Returned signature = " + returnedMethodSignature); 158 testStatus = testStatusFailed; 159 failMessage = failMessage + 160 "Unexpected method signature is returned:" + 161 ", Method = " + returnedMethodName + 162 ", Expected = " + methodSignatures[k] + 163 ", Returned = " + returnedMethodSignature + ";\n"; 164 } 165 if ( ! methodGenericSignatures[k].equals(returnedGenericSignature) ) { 166 logWriter.println("\n## FAILURE: Unexpected method generic signature is returned:"); 167 logWriter.println("## Method name = " + returnedMethodName); 168 logWriter.println 169 ("## Expected generic signature = " + methodGenericSignatures[k]); 170 logWriter.println 171 ("## Returned generic signature = " + returnedGenericSignature); 172 testStatus = testStatusFailed; 173 failMessage = failMessage + 174 "Unexpected method generic signature is returned:" + 175 ", Method = " + returnedMethodName + 176 ", Expected = " + methodGenericSignatures[k] + 177 ", Returned = " + returnedGenericSignature + ";\n"; 178 } 179 if ( methodModifiers[k] != returnedMethodModifiers ) { 180 logWriter.println("\n## FAILURE: Unexpected method modifiers are returned:"); 181 logWriter.println("## Method name = " + returnedMethodName); 182 logWriter.println 183 ("## Expected modifiers = 0x" + Integer.toHexString(methodModifiers[k])); 184 logWriter.println 185 ("## Returned modifiers = 0x" + Integer.toHexString(returnedMethodModifiers)); 186 testStatus = testStatusFailed; 187 failMessage = failMessage + 188 "Unexpected method modifiers are returned:" + 189 ", Method name = " + returnedMethodName + 190 ", Expected modifiers = 0x" + Integer.toHexString(methodModifiers[k]) + 191 ", Returned modifiers = 0x" + Integer.toHexString(returnedMethodModifiers) + ";\n"; 192 } 193 break; 194 } 195 if ( k == expectedMetodsNumber ) { 196 // returned method is not found out in the list of expected methos 197 logWriter.println("\n## FAILURE: It is found out unexpected returned method:"); 198 logWriter.println("## Method name = " + returnedMethodName); 199 logWriter.println("## Method signature = " + returnedMethodSignature); 200 logWriter.println("## Method generic signature = " + returnedGenericSignature); 201 logWriter.println 202 ("## Method modifiers = 0x" + Integer.toHexString(returnedMethodModifiers)); 203 testStatus = testStatusFailed; 204 failMessage = failMessage + 205 "Unexpected method has been found: " + 206 ", name = " + returnedMethodName + 207 ", signature = " + returnedMethodSignature + 208 ", generic signature = " + returnedGenericSignature + 209 ", modifiers = 0x" + Integer.toHexString(returnedMethodModifiers) + ";\n"; 210 } 211 } 212 213 for (int k=0; k < expectedMetodsNumber; k++) { 214 if ( ! methodFound[k] ) { 215 logWriter.println 216 ("\n## FAILURE: Expected method is NOT found out in the list of retuned methods:"); 217 logWriter.println("## Method name = " + methodNames[k]); 218 testStatus = testStatusFailed; 219 failMessage = failMessage + 220 "Expected method is NOT found in the list of retuned methods: " + 221 " name = " + methodNames[k]; 222 } 223 } 224 225 if (testStatus == testStatusPassed) { 226 logWriter.println 227 ("=> CHECK PASSED: All expected methods are found out and have expected attributes"); 228 } 229 230 assertAllDataRead(methodsWithGenericReply); 231 232 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 233 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": FINISH"); 234 235 if (testStatus == testStatusFailed) { 236 fail(failMessage); 237 } 238 } 239 } 240