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.ThreadReference;
014: import com.sun.jdi.event.StepEvent;
015: import com.sun.jdi.request.EventRequest;
016: import com.sun.jdi.request.StepRequest;
017:
018: /**
019: * Tests for JDI com.sun.jdi.event.StepEvent.
020: */
021: public class StepEventTest extends AbstractJDITest {
022:
023: private StepEvent fStepEvent;
024:
025: /**
026: * Creates a new test.
027: */
028: public StepEventTest() {
029: super ();
030: }
031:
032: /**
033: * Init the fields that are used by this test only.
034: */
035: public void localSetUp() {
036: // Trigger a step event
037: fStepEvent = triggerStepAndWait();
038: }
039:
040: /**
041: * Make sure the test leaves the VM in the same state it found it.
042: */
043: public void localTearDown() {
044: // The test has resumed the test thread, so suspend it
045: waitUntilReady();
046: }
047:
048: /**
049: * Run all tests and output to standard output.
050: * @param args
051: */
052: public static void main(java.lang.String[] args) {
053: new StepEventTest().runSuite(args);
054: }
055:
056: /**
057: * Gets the name of the test case.
058: * @see junit.framework.TestCase#getName()
059: */
060: public String getName() {
061: return "com.sun.jdi.event.StepEvent";
062: }
063:
064: /**
065: * Test JDI thread().
066: */
067: public void testJDIThread() {
068: assertEquals("1", "Test Thread", fStepEvent.thread().name());
069: }
070:
071: /**
072: * Test all possible steps.
073: */
074: public void testJDIVariousSteps() {
075: ThreadReference thread = getThread();
076: triggerStepAndWait(thread, StepRequest.STEP_MIN,
077: StepRequest.STEP_INTO);
078: waitUntilReady();
079: triggerStepAndWait(thread, StepRequest.STEP_MIN,
080: StepRequest.STEP_OVER);
081: waitUntilReady();
082: triggerStepAndWait(thread, StepRequest.STEP_LINE,
083: StepRequest.STEP_INTO);
084: waitUntilReady();
085: triggerStepAndWait(thread, StepRequest.STEP_LINE,
086: StepRequest.STEP_OVER);
087: waitUntilReady();
088: triggerStepAndWait(thread, StepRequest.STEP_LINE,
089: StepRequest.STEP_OUT);
090: waitUntilReady();
091: }
092:
093: /**
094: * Tests a step request with a specified class filter
095: */
096: public void testJDIClassFilter1() {
097: // Request for step events
098: StepRequest request = getRequest();
099: request.addClassFilter("java.lang.NegativeArraySizeException");
100: request.enable();
101: StepEvent event = null;
102: try {
103: event = triggerStepAndWait(getThread(), request, 1000);
104: } catch (Error e) {
105: }
106: if (event != null) {
107: assertTrue("1", false);
108: }
109: waitUntilReady();
110: fVM.eventRequestManager().deleteEventRequest(request);
111:
112: request = getRequest();
113: request.addClassFilter("java.lang.*");
114: request.enable();
115: event = null;
116: try {
117: event = triggerStepAndWait(getThread(), request, 1000);
118: } catch (Error e) {
119: }
120: if (event != null) {
121: assertTrue("1", false);
122: }
123: waitUntilReady();
124: fVM.eventRequestManager().deleteEventRequest(request);
125: }
126:
127: /**
128: * Retests a step request with a specified class filter
129: */
130: public void testJDIClassFilter2() {
131: // Request for step events
132: StepRequest request = getRequest();
133: ClassType clazz = getClass("java.lang.NegativeArraySizeException");
134: request.addClassFilter(clazz);
135: request.enable();
136: StepEvent event = null;
137: try {
138: event = triggerStepAndWait(getThread(), request, 1000);
139: } catch (Error e) {
140: }
141: if (event != null) {
142: assertTrue("1", false);
143: }
144: waitUntilReady();
145: fVM.eventRequestManager().deleteEventRequest(request);
146: }
147:
148: /**
149: * Tests a step request with a specific exclusion filter
150: */
151: public void testJDIClassExclusionFilter1() {
152: // Request for step events
153: StepRequest request = getRequest();
154: request
155: .addClassExclusionFilter("org.eclipse.debug.jdi.tests.program.MainClass");
156: request.enable();
157: StepEvent event = null;
158: try {
159: event = triggerStepAndWait(getThread(), request, 1000);
160: } catch (Error e) {
161: }
162: if (event != null) {
163: assertTrue("1", false);
164: }
165: waitUntilReady();
166: fVM.eventRequestManager().deleteEventRequest(request);
167: }
168:
169: /**
170: * Retests a step request with a specific exclusion filter
171: */
172: public void testJDIClassExclusionFilter2() {
173: StepRequest request = getRequest();
174: request.addClassExclusionFilter("org.eclipse.*");
175: request.addClassExclusionFilter("java.lang.*");
176: request.enable();
177: StepEvent event = null;
178: try {
179: event = triggerStepAndWait(getThread(), request, 1000);
180: } catch (Error e) {
181: }
182: if (event != null) {
183: System.out.println(event.location().declaringType());
184: assertTrue("1", false);
185: }
186: waitUntilReady();
187: fVM.eventRequestManager().deleteEventRequest(request);
188: }
189:
190: /**
191: * Creates a returns a new <code>StepRequest</code>
192: * @return a new <code>StepRequest</code>
193: */
194: public StepRequest getRequest() {
195: StepRequest eventRequest = fVM.eventRequestManager()
196: .createStepRequest(getThread(), StepRequest.STEP_LINE,
197: StepRequest.STEP_OVER);
198: eventRequest.addCountFilter(1);
199: eventRequest.setSuspendPolicy(EventRequest.SUSPEND_NONE);
200: return eventRequest;
201: }
202:
203: }
|