001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Anatoly F. Bondarenko
021: * @version $Revision: 1.4 $
022: */
023:
024: /**
025: * Created on 18.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.ReferenceType;
027:
028: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
029: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
030: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
031: import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
032: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
033:
034: /**
035: * JDWP Unit test for ReferenceType.Methods command.
036: */
037: public class MethodsTest extends JDWPSyncTestCase {
038:
039: static final int testStatusPassed = 0;
040: static final int testStatusFailed = -1;
041: static final String this CommandName = "ReferenceType.Methods command";
042: static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/MethodsDebuggee;";
043:
044: protected String getDebuggeeClassName() {
045: return "org.apache.harmony.jpda.tests.jdwp.ReferenceType.MethodsDebuggee";
046: }
047:
048: /**
049: * This testcase exercises ReferenceType.Methods command.
050: * <BR>The test starts MethodsDebuggee class, requests referenceTypeId
051: * for this class by VirtualMachine.ClassesBySignature command, then
052: * performs ReferenceType.Methods command and checks that returned
053: * list of methods corresponds to expected list of methods with expected attributes.
054: */
055: public void testMethods001() {
056: String this TestName = "testMethods001";
057: logWriter.println("==> " + this TestName + " for "
058: + this CommandName + ": START...");
059: int testStatus = testStatusPassed;
060: synchronizer
061: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
062:
063: long refTypeID = getClassIDBySignature(debuggeeSignature);
064:
065: logWriter.println("=> Debuggee class = "
066: + getDebuggeeClassName());
067: logWriter.println("=> referenceTypeID for Debuggee class = "
068: + refTypeID);
069: logWriter.println("=> CHECK: send " + this CommandName
070: + " and check reply...");
071:
072: CommandPacket methodsCommand = new CommandPacket(
073: JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
074: JDWPCommands.ReferenceTypeCommandSet.MethodsCommand);
075: methodsCommand.setNextValueAsReferenceTypeID(refTypeID);
076:
077: ReplyPacket methodsReply = debuggeeWrapper.vmMirror
078: .performCommand(methodsCommand);
079: methodsCommand = null;
080: checkReplyPacket(methodsReply, this CommandName);
081:
082: int returnedMethodsNumber = methodsReply.getNextValueAsInt();
083: logWriter.println("=> Returned methods number = "
084: + returnedMethodsNumber);
085:
086: String methodNames[] = { "staticTestMethod",
087: "objectTestMethod", "run", "main", "<init>" };
088:
089: String methodSignatures[] = { "(J)I",
090: "(Ljava/lang/Object;)Ljava/lang/Object;", "()V",
091: "([Ljava/lang/String;)V", "()V" };
092:
093: int methodModifiers[] = { 0x8, 0x0, 0x1, 0x9, 0x1 };
094:
095: boolean methodFound[] = { false, false, false, false, false };
096: int expectedMetodsNumber = methodNames.length;
097: int methodSyntheticFlag = 0xf0000000;
098: String failMessage = "";
099:
100: logWriter.println("=> CHECK for all expected methods...");
101: for (int i = 0; i < returnedMethodsNumber; i++) {
102: long returnedMethodID = methodsReply
103: .getNextValueAsMethodID();
104: String returnedMethodName = methodsReply
105: .getNextValueAsString();
106: String returnedMethodSignature = methodsReply
107: .getNextValueAsString();
108: int returnedMethodModifiers = methodsReply
109: .getNextValueAsInt();
110: logWriter.println("\n=> Method ID = " + returnedMethodID);
111: logWriter.println("=> Method name = " + returnedMethodName);
112: logWriter.println("=> Method signature = "
113: + returnedMethodSignature);
114: logWriter.println("=> Method modifiers = 0x"
115: + Integer.toHexString(returnedMethodModifiers));
116: if ((returnedMethodModifiers & methodSyntheticFlag) == methodSyntheticFlag) {
117: continue; // do not check synthetic methods
118: }
119: int k = 0;
120: for (; k < expectedMetodsNumber; k++) {
121: if (!methodNames[k].equals(returnedMethodName)) {
122: continue;
123: }
124: if (methodFound[k]) {
125: logWriter
126: .println("\n## FAILURE: The method is found out repeatedly in the list");
127: logWriter.println("## Method name = "
128: + returnedMethodName);
129: testStatus = testStatusFailed;
130: failMessage = failMessage + "The method '"
131: + returnedMethodName
132: + "' is found repeatedly in the list;\n";
133: break;
134: }
135: methodFound[k] = true;
136: if (!methodSignatures[k]
137: .equals(returnedMethodSignature)) {
138: logWriter
139: .println("\n## FAILURE: Unexpected method signature is returned:");
140: logWriter.println("## Method name = "
141: + returnedMethodName);
142: logWriter.println("## Expected signature = "
143: + methodSignatures[k]);
144: logWriter.println("## Returned signature = "
145: + returnedMethodSignature);
146: testStatus = testStatusFailed;
147: failMessage = failMessage
148: + "Unexpected signature is returned for method: "
149: + returnedMethodName + ", Expected: "
150: + methodSignatures[k] + ", Returned: "
151: + returnedMethodSignature + ";\n";
152: }
153: if (methodModifiers[k] != returnedMethodModifiers) {
154: logWriter
155: .println("\n## FAILURE: Unexpected method modifiers are returned:");
156: logWriter.println("## Method name = "
157: + returnedMethodName);
158: logWriter.println("## Expected modifiers = 0x"
159: + Integer.toHexString(methodModifiers[k]));
160: logWriter
161: .println("## Returned modifiers = 0x"
162: + Integer
163: .toHexString(returnedMethodModifiers));
164: testStatus = testStatusFailed;
165: failMessage = failMessage
166: + "Unexpected modifiers are returned for method: "
167: + returnedMethodName
168: + ", Expected: 0x"
169: + Integer.toHexString(methodModifiers[k])
170: + ", Returned: 0x"
171: + Integer
172: .toHexString(returnedMethodModifiers)
173: + ";\n";
174: }
175: break;
176: }
177: if (k == expectedMetodsNumber) {
178: // returned method is not found out in the list of expected methods
179: logWriter
180: .println("\n## FAILURE: It is found out unexpected returned method:");
181: logWriter.println("## Method name = "
182: + returnedMethodName);
183: logWriter.println("## Method signature = "
184: + returnedMethodSignature);
185: logWriter.println("## Method modifiers = 0x"
186: + Integer.toHexString(returnedMethodModifiers));
187: testStatus = testStatusFailed;
188: failMessage = failMessage
189: + "Unexpected returned method is found:"
190: + ", name = " + returnedMethodName
191: + ", signature = " + returnedMethodSignature
192: + ", modifiers = 0x"
193: + Integer.toHexString(returnedMethodModifiers)
194: + ";\n";
195: }
196: }
197: for (int k = 0; k < expectedMetodsNumber; k++) {
198: if (!methodFound[k]) {
199: logWriter
200: .println("\n## FAILURE: Expected method is NOT found out in the list of retuned methods:");
201: logWriter.println("## Method name = " + methodNames[k]);
202: testStatus = testStatusFailed;
203: failMessage = failMessage
204: + "Expected method is NOT found in the list of retuned methods:"
205: + " name = " + methodNames[k];
206: }
207: }
208: if (testStatus == testStatusPassed) {
209: logWriter
210: .println("=> CHECK PASSED: All expected methods are found out and have expected attributes");
211: }
212:
213: synchronizer
214: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
215: logWriter.println("==> " + this TestName + " for "
216: + this CommandName + ": FINISH");
217: if (testStatus == testStatusFailed) {
218: fail(failMessage);
219: }
220: assertAllDataRead(methodsReply);
221: }
222:
223: public static void main(String[] args) {
224: junit.textui.TestRunner.run(MethodsTest.class);
225: }
226: }
|