001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.debug.jdi.tests;
011:
012: import com.sun.jdi.ClassType;
013: import com.sun.jdi.Method;
014: import com.sun.jdi.ReferenceType;
015: import com.sun.jdi.ThreadReference;
016: import com.sun.jdi.event.Event;
017: import com.sun.jdi.event.MethodEntryEvent;
018: import com.sun.jdi.request.MethodEntryRequest;
019:
020: /**
021: * Tests a method entry request
022: */
023: public class MethodEntryRequestTest extends AbstractJDITest {
024:
025: /**
026: * @see org.eclipse.debug.jdi.tests.AbstractJDITest#localSetUp()
027: */
028: public void localSetUp() {
029: }
030:
031: /**
032: * @see org.eclipse.debug.jdi.tests.AbstractJDITest#localTearDown()
033: */
034: public void localTearDown() {
035: fVM.resume();
036: waitUntilReady();
037: }
038:
039: /**
040: * Run all tests and output to standard output.
041: * @param args
042: */
043: public static void main(java.lang.String[] args) {
044: new MethodEntryRequestTest().runSuite(args);
045: }
046:
047: /**
048: * Gets the name of the test case.
049: * @see junit.framework.TestCase#getName()
050: */
051: public String getName() {
052: return "com.sun.jdi.MethodEntryRequest";
053: }
054:
055: /**
056: * Creates and returns a new <code>MethodEntryRequest</code>
057: * @return a new <code>MethodEntryRequest</code>
058: */
059: protected MethodEntryRequest getMethodEntryRequest() {
060: return fVM.eventRequestManager().createMethodEntryRequest();
061: }
062:
063: /**
064: * Tests a request without any filtering
065: */
066: public void testJDIWithoutFilter() {
067: MethodEntryRequest request = getMethodEntryRequest();
068:
069: Event e = triggerAndWait(request, "BreakpointEvent", true);
070: assertEquals(request, e.request());
071:
072: MethodEntryEvent event = (MethodEntryEvent) e;
073: assertEquals(getThread(), event.thread());
074: fVM.eventRequestManager().deleteEventRequest(request);
075: }
076:
077: /**
078: * Test a request with class exclusion filtering
079: */
080: public void testJDIWithClassExclusionFilter() {
081: MethodEntryRequest request = getMethodEntryRequest();
082: request
083: .addClassExclusionFilter("org.eclipse.debug.jdi.tests.program.*");
084:
085: Event e = triggerAndWait(request, "BreakpointEvent", true);
086: assertEquals(request, e.request());
087:
088: MethodEntryEvent event = (MethodEntryEvent) e;
089: Method m = event.method();
090: ReferenceType r = m.location().declaringType();
091: assertTrue("1", !r.name().startsWith(
092: "org.eclipse.debug.jdi.tests.program."));
093: fVM.eventRequestManager().deleteEventRequest(request);
094: }
095:
096: /**
097: * Tests a method entry request with a specified class filter
098: */
099: public void testJDIWithClassFilter1() {
100: MethodEntryRequest request = getMethodEntryRequest();
101: ClassType clazz = getClass("java.io.PrintStream");
102: request.addClassFilter(clazz);
103:
104: Event e = triggerAndWait(request, "BreakpointEvent", true);
105: assertEquals(request, e.request());
106:
107: MethodEntryEvent event = (MethodEntryEvent) e;
108: Method m = event.method();
109: ReferenceType r = m.location().declaringType();
110: assertEquals(clazz, r);
111: fVM.eventRequestManager().deleteEventRequest(request);
112: }
113:
114: /**
115: * Retests a method entry request with a specified class filter
116: */
117: public void testJDIWithClassFilter2() {
118: MethodEntryRequest request = getMethodEntryRequest();
119: request.addClassFilter("java.io.PrintStream");
120:
121: Event e = triggerAndWait(request, "BreakpointEvent", true);
122: assertEquals(request, e.request());
123:
124: MethodEntryEvent event = (MethodEntryEvent) e;
125: Method m = event.method();
126: ReferenceType r = m.location().declaringType();
127: assertEquals("java.io.PrintStream", r.name());
128: fVM.eventRequestManager().deleteEventRequest(request);
129: }
130:
131: /**
132: * Tests a method entry request with a thread filter
133: */
134: public void testJDIWithThreadFilter() {
135: MethodEntryRequest request = getMethodEntryRequest();
136: ThreadReference thr = getMainThread();
137: request.addThreadFilter(thr);
138:
139: Event e = triggerAndWait(request, "BreakpointEvent", true);
140: assertEquals(request, e.request());
141:
142: MethodEntryEvent event = (MethodEntryEvent) e;
143: assertEquals(thr, event.thread());
144: fVM.eventRequestManager().deleteEventRequest(request);
145: }
146: }
|