Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8912fd0d1c077d4952cf5b2366e0a5cc4d252dda (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*******************************************************************************
 * Copyright (c) 2000, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.jdi.tests;

import com.sun.jdi.ClassType;
import com.sun.jdi.ThreadReference;
import com.sun.jdi.event.StepEvent;
import com.sun.jdi.request.EventRequest;
import com.sun.jdi.request.StepRequest;

/**
 * Tests for JDI com.sun.jdi.event.StepEvent.
 */
public class StepEventTest extends AbstractJDITest {

	private StepEvent fStepEvent;
	/**
	 * Creates a new test.
	 */
	public StepEventTest() {
		super();
	}
	/**
	 * Init the fields that are used by this test only.
	 */
	@Override
	public void localSetUp() {
		// Trigger a step event
		fStepEvent = triggerStepAndWait();
	}
	/**
	 * Make sure the test leaves the VM in the same state it found it.
	 */
	@Override
	public void localTearDown() {
		// The test has resumed the test thread, so suspend it
		waitUntilReady();
	}
	/**
	 * Run all tests and output to standard output.
	 * @param args
	 */
	public static void main(java.lang.String[] args) {
		new StepEventTest().runSuite(args);
	}
	/**
	 * Gets the name of the test case.
	 * @see junit.framework.TestCase#getName()
	 */
	@Override
	public String getName() {
		return "com.sun.jdi.event.StepEvent";
	}
	/**
	 * Test JDI thread().
	 */
	public void testJDIThread() {
		assertEquals("1", "Test Thread", fStepEvent.thread().name());
	}
	/**
	 * Test all possible steps.
	 */
	public void testJDIVariousSteps() {
		ThreadReference thread = getThread();
		triggerStepAndWait(thread, StepRequest.STEP_MIN, StepRequest.STEP_INTO);
		waitUntilReady();
		triggerStepAndWait(thread, StepRequest.STEP_MIN, StepRequest.STEP_OVER);
		waitUntilReady();
		triggerStepAndWait(thread, StepRequest.STEP_LINE, StepRequest.STEP_INTO);
		waitUntilReady();
		triggerStepAndWait(thread, StepRequest.STEP_LINE, StepRequest.STEP_OVER);
		waitUntilReady();
		triggerStepAndWait(thread, StepRequest.STEP_LINE, StepRequest.STEP_OUT);
		waitUntilReady();
	}

	/**
	 * Tests a step request with a specified class filter
	 */
	public void testJDIClassFilter1() {
		// Request for step events
		StepRequest request = getRequest();
		request.addClassFilter("java.lang.NegativeArraySizeException");
		request.enable();
		StepEvent event = null;
		try {
			event = triggerStepAndWait(getThread(), request, 1000);
		} catch (Error e) {
		}
		if (event != null) {
			assertTrue("1", false);
		}
		waitUntilReady();
		fVM.eventRequestManager().deleteEventRequest(request);

		request = getRequest();
		request.addClassFilter("java.lang.*");
		request.enable();
		event = null;
		try {
			event = triggerStepAndWait(getThread(), request, 1000);
		} catch (Error e) {
		}
		if (event != null) {
			assertTrue("1", false);
		}
		waitUntilReady();
		fVM.eventRequestManager().deleteEventRequest(request);
	}

	/**
	 * Retests a step request with a specified class filter
	 */
	public void testJDIClassFilter2() {
		// Request for step events
		StepRequest request = getRequest();
		ClassType clazz = getClass("java.lang.NegativeArraySizeException");
		request.addClassFilter(clazz);
		request.enable();
		StepEvent event = null;
		try {
			event = triggerStepAndWait(getThread(), request, 1000);
		} catch (Error e) {
		}
		if (event != null) {
			assertTrue("1", false);
		}
		waitUntilReady();
		fVM.eventRequestManager().deleteEventRequest(request);
	}

	/**
	 * Tests a step request with a specific exclusion filter
	 */
	public void testJDIClassExclusionFilter1() {
		// Request for step events
		StepRequest request = getRequest();
		request.addClassExclusionFilter(
			"org.eclipse.debug.jdi.tests.program.MainClass");
		request.enable();
		StepEvent event = null;
		try {
			event = triggerStepAndWait(getThread(), request, 1000);
		} catch (Error e) {
		}
		if (event != null) {
			assertTrue("1", false);
		}
		waitUntilReady();
		fVM.eventRequestManager().deleteEventRequest(request);
	}

	/**
	 * Retests a step request with a specific exclusion filter
	 */
	public void testJDIClassExclusionFilter2() {
		StepRequest request = getRequest();
		request.addClassExclusionFilter("org.eclipse.*");
		request.addClassExclusionFilter("java.lang.*");
		request.enable();
		StepEvent event = null;
		try {
			event = triggerStepAndWait(getThread(), request, 1000);
		} catch (Error e) {
		}
		if (event != null) {
			System.out.println(event.location().declaringType());
			assertTrue("1", false);
		}
		waitUntilReady();
		fVM.eventRequestManager().deleteEventRequest(request);
	}

	/**
	 * Creates a returns a new <code>StepRequest</code>
	 * @return a new <code>StepRequest</code>
	 */
	public StepRequest getRequest() {
		StepRequest eventRequest =
			fVM.eventRequestManager().createStepRequest(
				getThread(),
				StepRequest.STEP_LINE,
				StepRequest.STEP_OVER);
		eventRequest.addCountFilter(1);
		eventRequest.setSuspendPolicy(EventRequest.SUSPEND_NONE);
		return eventRequest;
	}

}

Back to the top