Source Code Cross Referenced for InvokeMethodTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » jpda » tests » jdwp » ClassType » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.jpda.tests.jdwp.ClassType 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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 Viacheslav G. Rybalov
021:         * @version $Revision: 1.4 $
022:         */
023:
024:        /**
025:         * Created on 10.03.2005
026:         */package org.apache.harmony.jpda.tests.jdwp.ClassType;
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.JDWPConstants;
031:        import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
032:        import org.apache.harmony.jpda.tests.framework.jdwp.TaggedObject;
033:        import org.apache.harmony.jpda.tests.framework.jdwp.Value;
034:        import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
035:        import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
036:
037:        /**
038:         * JDWP unit test for ClassType.InvokeMethod command.
039:         */
040:        public class InvokeMethodTest extends JDWPSyncTestCase {
041:
042:            static final int testStatusPassed = 0;
043:            static final int testStatusFailed = -1;
044:
045:            protected String getDebuggeeClassName() {
046:                return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.InvokeMethodDebuggee";
047:            }
048:
049:            /**
050:             * This testcase exercises ClassType.InvokeMethod command.
051:             * <BR>At first the test starts debuggee. 
052:             * <BR>Then does the following checks: 
053:             * <BR>&nbsp;&nbsp; - send ClassType.InvokeMethod command for method,
054:             * which should not throw any Exception, and checks,
055:             * that returned value is expected int value and returned
056:             * exception object is null;
057:             * <BR>&nbsp;&nbsp; - send ClassType.InvokeMethod command for method,
058:             * which should throw some Exception, and checks, that
059:             * returned exception object is not null and has expected attributes;
060:             */
061:            public void testInvokeMethod001() {
062:                synchronizer
063:                        .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
064:
065:                // Get referenceTypeID
066:                CommandPacket packet = new CommandPacket(
067:                        JDWPCommands.VirtualMachineCommandSet.CommandSetID,
068:                        JDWPCommands.VirtualMachineCommandSet.ClassesBySignatureCommand);
069:                String classSig = "Lorg/apache/harmony/jpda/tests/jdwp/share/debuggee/InvokeMethodDebuggee;";
070:                packet.setNextValueAsString(classSig);
071:                ReplyPacket reply = debuggeeWrapper.vmMirror
072:                        .performCommand(packet);
073:                checkReplyPacket(reply,
074:                        "VirtualMachine::ClassesBySignature command");
075:
076:                int classes = reply.getNextValueAsInt();
077:                assertEquals(
078:                        "VirtualMachine::ClassesBySignature returned invalid number of classes,",
079:                        1, classes); //this class may be loaded only once
080:                byte refTypeTag = reply.getNextValueAsByte();
081:                long typeID = reply.getNextValueAsReferenceTypeID();
082:                int status = reply.getNextValueAsInt();
083:                assertAllDataRead(reply);
084:                assertEquals(
085:                        "VirtualMachine::ClassesBySignature returned Invalid type tag,",
086:                        JDWPConstants.TypeTag.CLASS, refTypeTag,
087:                        JDWPConstants.TypeTag
088:                                .getName(JDWPConstants.TypeTag.CLASS),
089:                        JDWPConstants.TypeTag.getName(refTypeTag));
090:
091:                logWriter
092:                        .println(" VirtualMachine.ClassesBySignature: classes="
093:                                + classes + " refTypeTag=" + refTypeTag
094:                                + " typeID= " + typeID + " status=" + status);
095:
096:                // Get methodID
097:                packet = new CommandPacket(
098:                        JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
099:                        JDWPCommands.ReferenceTypeCommandSet.MethodsCommand);
100:                packet.setNextValueAsClassID(typeID);
101:                reply = debuggeeWrapper.vmMirror.performCommand(packet);
102:                checkReplyPacket(reply, "ReferenceType::Methods command");
103:
104:                int declared = reply.getNextValueAsInt();
105:                logWriter.println(" ReferenceType.Methods: declared="
106:                        + declared);
107:                long targetMethodID = 0;
108:                for (int i = 0; i < declared; i++) {
109:                    long methodID = reply.getNextValueAsMethodID();
110:                    String name = reply.getNextValueAsString();
111:                    String signature = reply.getNextValueAsString();
112:                    int modBits = reply.getNextValueAsInt();
113:                    logWriter.println("  methodID=" + methodID + " name="
114:                            + name + " signature=" + signature + " modBits="
115:                            + modBits);
116:                    if (name.equals("testMethod2")) {
117:                        targetMethodID = methodID;
118:                    }
119:                }
120:                assertAllDataRead(reply);
121:
122:                // Set EventRequest
123:                packet = new CommandPacket(
124:                        JDWPCommands.EventRequestCommandSet.CommandSetID,
125:                        JDWPCommands.EventRequestCommandSet.SetCommand);
126:                packet.setNextValueAsByte(JDWPConstants.EventKind.METHOD_ENTRY);
127:                packet.setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL);
128:                packet.setNextValueAsInt(1);
129:                packet.setNextValueAsByte((byte) 5);
130:                packet.setNextValueAsString("*.InvokeMethodDebuggee");
131:                reply = debuggeeWrapper.vmMirror.performCommand(packet);
132:                checkReplyPacket(reply, "EventRequest::Set command");
133:
134:                int requestID = reply.getNextValueAsInt();
135:                logWriter.println(" EventRequest.Set: requestID=" + requestID);
136:                assertAllDataRead(reply);
137:                synchronizer
138:                        .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
139:
140:                long targetThreadID = 0;
141:                // Wait event
142:                CommandPacket event = debuggeeWrapper.vmMirror.receiveEvent();
143:                byte suspendPolicy = event.getNextValueAsByte();
144:                int events = event.getNextValueAsInt();
145:                logWriter.println(" EVENT_THREAD event: suspendPolicy="
146:                        + suspendPolicy + " events=" + events);
147:                for (int i = 0; i < events; i++) {
148:                    byte eventKind = event.getNextValueAsByte();
149:                    int newRequestID = event.getNextValueAsInt();
150:                    long threadID = event.getNextValueAsThreadID();
151:                    //Location location =
152:                    event.getNextValueAsLocation();
153:                    logWriter.println("  EVENT_THREAD event " + i
154:                            + ": eventKind=" + eventKind + " requestID="
155:                            + newRequestID + " threadID=" + threadID);
156:                    if (newRequestID == requestID) {
157:                        targetThreadID = threadID;
158:                    }
159:                }
160:                assertAllDataRead(event);
161:                assertTrue("Invalid targetThreadID, must be != 0",
162:                        targetThreadID != 0);
163:
164:                //  Let's clear event request
165:                packet = new CommandPacket(
166:                        JDWPCommands.EventRequestCommandSet.CommandSetID,
167:                        JDWPCommands.EventRequestCommandSet.ClearCommand);
168:                packet.setNextValueAsByte(JDWPConstants.EventKind.METHOD_ENTRY);
169:                packet.setNextValueAsInt(requestID);
170:                reply = debuggeeWrapper.vmMirror.performCommand(packet);
171:                checkReplyPacket(reply, "EventRequest::Clear command");
172:                assertAllDataRead(reply);
173:
174:                // Make InvokeMethod without Exception
175:                packet = new CommandPacket(
176:                        JDWPCommands.ClassTypeCommandSet.CommandSetID,
177:                        JDWPCommands.ClassTypeCommandSet.InvokeMethodCommand);
178:                packet.setNextValueAsClassID(typeID);
179:                packet.setNextValueAsThreadID(targetThreadID);
180:                packet.setNextValueAsMethodID(targetMethodID);
181:                packet.setNextValueAsInt(1);
182:                packet.setNextValueAsValue(new Value(false));
183:                packet.setNextValueAsInt(0);
184:                logWriter
185:                        .println(" Send ClassType.InvokeMethod without Exception");
186:                reply = debuggeeWrapper.vmMirror.performCommand(packet);
187:                checkReplyPacket(reply, "ClassType::InvokeMethod command");
188:
189:                Value returnValue = reply.getNextValueAsValue();
190:                assertNotNull("Returned value is null", returnValue);
191:                assertEquals("Invalid returned value,", 234, returnValue
192:                        .getIntValue());
193:                logWriter
194:                        .println(" ClassType.InvokeMethod: returnValue.getIntValue()="
195:                                + returnValue.getIntValue());
196:
197:                TaggedObject exception = reply.getNextValueAsTaggedObject();
198:                assertNotNull("Returned exception is null", exception);
199:                assertTrue("Invalid exception object ID:<" + exception.objectID
200:                        + ">", exception.objectID == 0);
201:                assertEquals(
202:                        "Invalid exception tag,",
203:                        JDWPConstants.Tag.OBJECT_TAG,
204:                        exception.tag,
205:                        JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG),
206:                        JDWPConstants.Tag.getName(exception.tag));
207:                logWriter.println(" ClassType.InvokeMethod: exception.tag="
208:                        + exception.tag + " exception.objectID="
209:                        + exception.objectID);
210:                assertAllDataRead(reply);
211:
212:                // Make InvokeMethod with Exception
213:                packet = new CommandPacket(
214:                        JDWPCommands.ClassTypeCommandSet.CommandSetID,
215:                        JDWPCommands.ClassTypeCommandSet.InvokeMethodCommand);
216:                packet.setNextValueAsClassID(typeID);
217:                packet.setNextValueAsThreadID(targetThreadID);
218:                packet.setNextValueAsMethodID(targetMethodID);
219:                packet.setNextValueAsInt(1);
220:                packet.setNextValueAsValue(new Value(true));
221:                packet.setNextValueAsInt(0);
222:                logWriter
223:                        .println(" Send ClassType.InvokeMethod with Exception");
224:                reply = debuggeeWrapper.vmMirror.performCommand(packet);
225:                checkReplyPacket(reply, "ClassType::InvokeMethod command");
226:
227:                returnValue = reply.getNextValueAsValue();
228:                logWriter
229:                        .println(" ClassType.InvokeMethod: returnValue.getIntValue()="
230:                                + returnValue.getIntValue());
231:
232:                exception = reply.getNextValueAsTaggedObject();
233:                assertNotNull("Returned exception is null", exception);
234:                assertTrue("Invalid exception object ID:<" + exception.objectID
235:                        + ">", exception.objectID != 0);
236:                assertEquals(
237:                        "Invalid exception tag,",
238:                        JDWPConstants.Tag.OBJECT_TAG,
239:                        exception.tag,
240:                        JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG),
241:                        JDWPConstants.Tag.getName(exception.tag));
242:                logWriter.println(" ClassType.InvokeMethod: exception.tag="
243:                        + exception.tag + " exception.objectID="
244:                        + exception.objectID);
245:                assertAllDataRead(reply);
246:
247:                //  Let's resume application
248:                packet = new CommandPacket(
249:                        JDWPCommands.VirtualMachineCommandSet.CommandSetID,
250:                        JDWPCommands.VirtualMachineCommandSet.ResumeCommand);
251:                reply = debuggeeWrapper.vmMirror.performCommand(packet);
252:                checkReplyPacket(reply, "VirtualMachine::Resume command");
253:                assertAllDataRead(reply);
254:
255:                synchronizer
256:                        .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
257:            }
258:
259:            /**
260:             * This testcase exercises ClassType.InvokeMethod command.
261:             * <BR>At first the test starts debuggee. 
262:             * <BR>Then does the following checks: 
263:             * <BR>&nbsp;&nbsp; - send ClassType.InvokeMethod command for method,
264:             * which actually does not belong to passed class (taking into account 
265:             * inheritance). 
266:             * <BR>Test expects that INVALID_METHODID error is returned by command.
267:             */
268:            public void testInvokeMethod002() {
269:                logWriter.println("==> testInvokeMethod002: START...");
270:                synchronizer
271:                        .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
272:
273:                logWriter.println("\n==> Getting debuggeeRefTypeID... ");
274:                String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/share/debuggee/InvokeMethodDebuggee;";
275:                logWriter.println("==> debuggeeSignature = |"
276:                        + debuggeeSignature + "|+");
277:                long debuggeeRefTypeID = debuggeeWrapper.vmMirror
278:                        .getClassID(debuggeeSignature);
279:                if (debuggeeRefTypeID == -1) {
280:                    logWriter
281:                            .println("## FAILURE: Can not get debuggeeRefTypeID!");
282:                    fail("Can not get debuggeeRefTypeID!");
283:                }
284:                logWriter.println("==> debuggeeRefTypeID = "
285:                        + debuggeeRefTypeID);
286:
287:                logWriter
288:                        .println("\n==> Getting testMethodID for debuggee method 'testMethod2'... ");
289:                String testMethodName = "testMethod2";
290:                long testMethodID = debuggeeWrapper.vmMirror.getMethodID(
291:                        debuggeeRefTypeID, testMethodName);
292:                if (testMethodID == -1) {
293:                    logWriter.println("## FAILURE: Can not get methodID!");
294:                    fail("Can not get methodID!");
295:                }
296:                logWriter.println("==> testMethodID = " + testMethodID);
297:
298:                logWriter.println("\n==> Setting EventRequest... ");
299:                CommandPacket packet = new CommandPacket(
300:                        JDWPCommands.EventRequestCommandSet.CommandSetID,
301:                        JDWPCommands.EventRequestCommandSet.SetCommand);
302:                packet.setNextValueAsByte(JDWPConstants.EventKind.METHOD_ENTRY);
303:                packet.setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL);
304:                packet.setNextValueAsInt(1);
305:                packet.setNextValueAsByte((byte) 5);
306:                packet.setNextValueAsString("*.InvokeMethodDebuggee");
307:
308:                ReplyPacket reply = debuggeeWrapper.vmMirror
309:                        .performCommand(packet);
310:                checkReplyPacket(reply, "EventRequest::Set command");
311:
312:                int requestID = reply.getNextValueAsInt();
313:                logWriter.println(" EventRequest.Set: requestID=" + requestID);
314:
315:                synchronizer
316:                        .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
317:
318:                logWriter.println("\n==> Getting targetThreadID... ");
319:                long targetThreadID = 0;
320:                // Wait event
321:                CommandPacket event = debuggeeWrapper.vmMirror.receiveEvent();
322:                byte suspendPolicy = event.getNextValueAsByte();
323:                int events = event.getNextValueAsInt();
324:                logWriter.println(" EVENT_THREAD event: suspendPolicy="
325:                        + suspendPolicy + " events=" + events);
326:                for (int i = 0; i < events; i++) {
327:                    byte eventKind = event.getNextValueAsByte();
328:                    int newRequestID = event.getNextValueAsInt();
329:                    long threadID = event.getNextValueAsThreadID();
330:                    //Location location =
331:                    event.getNextValueAsLocation();
332:                    logWriter.println("  EVENT_THREAD event " + i
333:                            + ": eventKind=" + eventKind + " requestID="
334:                            + newRequestID + " threadID=" + threadID);
335:                    if (newRequestID == requestID) {
336:                        targetThreadID = threadID;
337:                    }
338:                }
339:                logWriter.println("==> targetThreadID = " + targetThreadID);
340:                assertTrue("Invalid targetThreadID, must be != 0",
341:                        targetThreadID != 0);
342:
343:                logWriter.println("\n==> Clear EventRequest... ");
344:                packet = new CommandPacket(
345:                        JDWPCommands.EventRequestCommandSet.CommandSetID,
346:                        JDWPCommands.EventRequestCommandSet.ClearCommand);
347:                packet.setNextValueAsByte(JDWPConstants.EventKind.METHOD_ENTRY);
348:                packet.setNextValueAsInt(requestID);
349:                reply = debuggeeWrapper.vmMirror.performCommand(packet);
350:                checkReplyPacket(reply, "EventRequest::Clear command");
351:
352:                logWriter.println("\n==> Getting invalidClassRefTypeID... ");
353:                String invalidClassSignature = "Lorg/apache/harmony/jpda/tests/jdwp/share/debuggee/testClass2;";
354:                logWriter.println("==> invalidClassSignature = |"
355:                        + invalidClassSignature + "|+");
356:                long invalidClassRefTypeID = debuggeeWrapper.vmMirror
357:                        .getClassID(invalidClassSignature);
358:                if (invalidClassRefTypeID == -1) {
359:                    logWriter
360:                            .println("## FAILURE: Can not get invalidClassRefTypeID!");
361:                    fail("Can not get invalidClassRefTypeID!");
362:                }
363:                logWriter.println("==> invalidClassRefTypeID = "
364:                        + invalidClassRefTypeID);
365:
366:                logWriter
367:                        .println("\n==> Send ClassType::InvokeMethod for invalidClassRefTypeID, testMethodID...");
368:                packet = new CommandPacket(
369:                        JDWPCommands.ClassTypeCommandSet.CommandSetID,
370:                        JDWPCommands.ClassTypeCommandSet.InvokeMethodCommand);
371:                packet.setNextValueAsClassID(invalidClassRefTypeID);
372:                packet.setNextValueAsThreadID(targetThreadID);
373:                packet.setNextValueAsMethodID(testMethodID);
374:                packet.setNextValueAsInt(1);
375:                packet.setNextValueAsValue(new Value(false));
376:                packet.setNextValueAsInt(0);
377:                reply = debuggeeWrapper.vmMirror.performCommand(packet);
378:                short errorCode = reply.getErrorCode();
379:                if (errorCode == JDWPConstants.Error.NONE) {
380:                    logWriter
381:                            .println("## FAILURE: ClassType::InvokeMethod command does NOT return expected error - INVALID_METHODID");
382:
383:                    // next is only for extra info
384:                    logWriter.println("\n==> Result if invoke method:");
385:                    Value returnValue = reply.getNextValueAsValue();
386:                    if (returnValue != null) {
387:                        logWriter
388:                                .println(" ClassType.InvokeMethod: returnValue.getIntValue()="
389:                                        + returnValue.getIntValue());
390:                    }
391:
392:                    TaggedObject exception = reply.getNextValueAsTaggedObject();
393:                    if (exception != null) {
394:                        logWriter
395:                                .println(" ClassType.InvokeMethod: exception.tag="
396:                                        + exception.tag
397:                                        + " exception.objectID="
398:                                        + exception.objectID);
399:                        if (exception.objectID != 0) {
400:                            String exceptionSignature = getObjectSignature(exception.objectID);
401:                            logWriter.println(" exceptionSignature = "
402:                                    + exceptionSignature);
403:                        }
404:                    }
405:                }
406:                checkReplyPacket(reply, "ClassType::InvokeMethod command",
407:                        JDWPConstants.Error.INVALID_METHODID);
408:
409:                logWriter
410:                        .println("==> PASSED: Expected error (INVALID_METHODID) is returned");
411:                logWriter.println("\n==> resumeDebuggee...");
412:                resumeDebuggee();
413:
414:                synchronizer
415:                        .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
416:            }
417:
418:            /**
419:             * This testcase exercises ClassType.InvokeMethod command.
420:             * <BR>At first the test starts debuggee. 
421:             * <BR>Then does the following checks: 
422:             * <BR>&nbsp;&nbsp; - send ClassType.InvokeMethod command for method,
423:             * which actually is not static method. 
424:             * <BR>Test expects that INVALID_METHODID error is returned by command.
425:             */
426:            public void testInvokeMethod003() {
427:                logWriter.println("==> testInvokeMethod003: START...");
428:                synchronizer
429:                        .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
430:
431:                logWriter.println("\n==> Getting debuggeeRefTypeID... ");
432:                String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/share/debuggee/InvokeMethodDebuggee;";
433:                logWriter.println("==> debuggeeSignature = |"
434:                        + debuggeeSignature + "|+");
435:                long debuggeeRefTypeID = debuggeeWrapper.vmMirror
436:                        .getClassID(debuggeeSignature);
437:                if (debuggeeRefTypeID == -1) {
438:                    logWriter
439:                            .println("## FAILURE: Can not get debuggeeRefTypeID!");
440:                    fail("Can not get debuggeeRefTypeID!");
441:                }
442:                logWriter.println("==> debuggeeRefTypeID = "
443:                        + debuggeeRefTypeID);
444:
445:                logWriter
446:                        .println("\n==> Getting nonStaticMethodID for debuggee method 'testMethod1'... ");
447:                String nonStaticMethodName = "testMethod1";
448:                long nonStaticMethodID = debuggeeWrapper.vmMirror.getMethodID(
449:                        debuggeeRefTypeID, nonStaticMethodName);
450:                if (nonStaticMethodID == -1) {
451:                    logWriter.println("## FAILURE: Can not get methodID!");
452:                    fail("Can not get methodID!");
453:                }
454:                logWriter.println("==> nonStaticMethodID = "
455:                        + nonStaticMethodID);
456:
457:                logWriter.println("\n==> Setting EventRequest... ");
458:                CommandPacket packet = new CommandPacket(
459:                        JDWPCommands.EventRequestCommandSet.CommandSetID,
460:                        JDWPCommands.EventRequestCommandSet.SetCommand);
461:                packet.setNextValueAsByte(JDWPConstants.EventKind.METHOD_ENTRY);
462:                packet.setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL);
463:                packet.setNextValueAsInt(1);
464:                packet.setNextValueAsByte((byte) 5);
465:                packet.setNextValueAsString("*.InvokeMethodDebuggee");
466:
467:                ReplyPacket reply = debuggeeWrapper.vmMirror
468:                        .performCommand(packet);
469:                checkReplyPacket(reply, "EventRequest::Set command");
470:
471:                int requestID = reply.getNextValueAsInt();
472:                logWriter.println(" EventRequest.Set: requestID=" + requestID);
473:
474:                synchronizer
475:                        .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
476:
477:                logWriter.println("\n==> Getting targetThreadID... ");
478:                long targetThreadID = 0;
479:                // Wait event
480:                CommandPacket event = debuggeeWrapper.vmMirror.receiveEvent();
481:                byte suspendPolicy = event.getNextValueAsByte();
482:                int events = event.getNextValueAsInt();
483:                logWriter.println(" EVENT_THREAD event: suspendPolicy="
484:                        + suspendPolicy + " events=" + events);
485:                for (int i = 0; i < events; i++) {
486:                    byte eventKind = event.getNextValueAsByte();
487:                    int newRequestID = event.getNextValueAsInt();
488:                    long threadID = event.getNextValueAsThreadID();
489:                    //Location location =
490:                    event.getNextValueAsLocation();
491:                    logWriter.println("  EVENT_THREAD event " + i
492:                            + ": eventKind=" + eventKind + " requestID="
493:                            + newRequestID + " threadID=" + threadID);
494:                    if (newRequestID == requestID) {
495:                        targetThreadID = threadID;
496:                    }
497:                }
498:                logWriter.println("==> targetThreadID = " + targetThreadID);
499:                assertTrue("Invalid targetThreadID, must be != 0",
500:                        targetThreadID != 0);
501:
502:                logWriter.println("\n==> Clear EventRequest... ");
503:                packet = new CommandPacket(
504:                        JDWPCommands.EventRequestCommandSet.CommandSetID,
505:                        JDWPCommands.EventRequestCommandSet.ClearCommand);
506:                packet.setNextValueAsByte(JDWPConstants.EventKind.METHOD_ENTRY);
507:                packet.setNextValueAsInt(requestID);
508:                reply = debuggeeWrapper.vmMirror.performCommand(packet);
509:                checkReplyPacket(reply, "EventRequest::Clear command");
510:
511:                logWriter
512:                        .println("\n==> Send ClassType::InvokeMethod for debuggeeRefTypeID, nonStaticMethodID...");
513:                packet = new CommandPacket(
514:                        JDWPCommands.ClassTypeCommandSet.CommandSetID,
515:                        JDWPCommands.ClassTypeCommandSet.InvokeMethodCommand);
516:                packet.setNextValueAsClassID(debuggeeRefTypeID);
517:                packet.setNextValueAsThreadID(targetThreadID);
518:                packet.setNextValueAsMethodID(nonStaticMethodID);
519:                packet.setNextValueAsInt(1);
520:                packet.setNextValueAsValue(new Value(false));
521:                packet.setNextValueAsInt(0);
522:                reply = debuggeeWrapper.vmMirror.performCommand(packet);
523:                short errorCode = reply.getErrorCode();
524:                if (errorCode == JDWPConstants.Error.NONE) {
525:                    logWriter
526:                            .println("## FAILURE: ClassType::InvokeMethod command does NOT return expected error - INVALID_METHODID");
527:
528:                    // next is only for extra info
529:                    logWriter.println("\n==> Result if invoke method:");
530:                    Value returnValue = reply.getNextValueAsValue();
531:                    if (returnValue != null) {
532:                        logWriter
533:                                .println(" ClassType.InvokeMethod: returnValue.getIntValue()="
534:                                        + returnValue.getIntValue());
535:                    }
536:
537:                    TaggedObject exception = reply.getNextValueAsTaggedObject();
538:                    if (exception != null) {
539:                        logWriter
540:                                .println(" ClassType.InvokeMethod: exception.tag="
541:                                        + exception.tag
542:                                        + " exception.objectID="
543:                                        + exception.objectID);
544:                        if (exception.objectID != 0) {
545:                            String exceptionSignature = getObjectSignature(exception.objectID);
546:                            logWriter.println(" exceptionSignature = "
547:                                    + exceptionSignature);
548:                        }
549:                    }
550:                }
551:                checkReplyPacket(reply, "ClassType::InvokeMethod command",
552:                        JDWPConstants.Error.INVALID_METHODID);
553:
554:                logWriter
555:                        .println("==> PASSED: Expected error (INVALID_METHODID) is returned");
556:                logWriter.println("\n==> resumeDebuggee...");
557:                resumeDebuggee();
558:
559:                synchronizer
560:                        .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
561:            }
562:
563:            public static void main(String[] args) {
564:                junit.textui.TestRunner.run(InvokeMethodTest.class);
565:            }
566:        }
ww___w__.___ja__v_a2s__.___c_om___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.