File: StepIntoSelectionTests.java

package info (click to toggle)
eclipse-jdt-debug 4.30-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,876 kB
  • sloc: java: 234,390; xml: 6,367; makefile: 5
file content (221 lines) | stat: -rw-r--r-- 8,001 bytes parent folder | download | duplicates (3)
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*******************************************************************************
 * Copyright (c) 2000, 2011 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Ivan Popov - [Bug 193488] org.eclipse.jdt.debug.test.stepping.StepIntoSelectionTests
 *     					depend on VM behavior
 *******************************************************************************/
package org.eclipse.jdt.debug.test.stepping;

import org.eclipse.debug.core.DebugEvent;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.debug.core.IJavaStackFrame;
import org.eclipse.jdt.debug.core.IJavaThread;
import org.eclipse.jdt.debug.testplugin.DebugElementEventWaiter;
import org.eclipse.jdt.debug.tests.AbstractDebugTest;
import org.eclipse.jdt.internal.debug.ui.actions.StepIntoSelectionHandler;

/**
 * Tests 'step into selection'
 */
public class StepIntoSelectionTests extends AbstractDebugTest {

	/**
	 * Constructor
	 */
	public StepIntoSelectionTests(String name) {
		super(name);
	}

	/**
	 * Step into 'new StepIntoSelectionClass()'
	 *
	 * @throws Exception
	 */
	public void testStepIntoSourceConstructor() throws Exception {
		String typeName = "org.eclipse.debug.tests.targets.StepIntoSelectionClass";
		createLineBreakpoint(24, typeName);

		IJavaThread thread= null;
		try {
			thread= launchToBreakpoint(typeName);
			assertNotNull("Breakpoint not hit within timeout period", thread);

			ICompilationUnit cu = getCompilationUnit(get14Project(), "src", "org.eclipse.debug.tests.targets", "StepIntoSelectionClass.java");
			IType type = cu.getType("StepIntoSelectionClass");
			IMethod method = type.getMethod("StepIntoSelectionClass", new String[0]);
			assertTrue("Could not find constructor", method.exists());

			StepIntoSelectionHandler handler = new StepIntoSelectionHandler(thread, (IJavaStackFrame)thread.getTopStackFrame(), method);
			DebugElementEventWaiter waiter = new DebugElementEventWaiter(DebugEvent.SUSPEND, thread);
			handler.step();
			Object source = waiter.waitForEvent();
			assertEquals("Step did not complete", thread, source);
			thread = (IJavaThread)source;

			IJavaStackFrame frame = (IJavaStackFrame)thread.getTopStackFrame();
			assertEquals("Should be in constructor", "<init>", frame.getMethodName());


		} finally {
			terminateAndRemove(thread);
			removeAllBreakpoints();
		}
	}

	/**
	 * Step into 'step()'
	 *
	 * @throws Exception
	 */
	public void testStepIntoSourceMethod() throws Exception {
		String typeName = "org.eclipse.debug.tests.targets.StepIntoSelectionClass";
		createLineBreakpoint(26, typeName);

		IJavaThread thread= null;
		try {
			thread= launchToBreakpoint(typeName);
			assertNotNull("Breakpoint not hit within timeout period", thread);

			ICompilationUnit cu = getCompilationUnit(get14Project(), "src", "org.eclipse.debug.tests.targets", "StepIntoSelectionClass.java");
			IType type = cu.getType("StepIntoSelectionClass");
			IMethod method = type.getMethod("step", new String[0]);
			assertTrue("Could not find method 'step'", method.exists());

			StepIntoSelectionHandler handler = new StepIntoSelectionHandler(thread, (IJavaStackFrame)thread.getTopStackFrame(), method);
			DebugElementEventWaiter waiter = new DebugElementEventWaiter(DebugEvent.SUSPEND, thread);
			handler.step();
			Object source = waiter.waitForEvent();
			assertEquals("Step did not complete", thread, source);
			thread = (IJavaThread)source;

			IJavaStackFrame frame = (IJavaStackFrame)thread.getTopStackFrame();
			assertEquals("Should be in method 'step'", "step", frame.getMethodName());


		} finally {
			terminateAndRemove(thread);
			removeAllBreakpoints();
		}
	}

	/**
	 * Step into 'method1(int[], String[])'
	 *
	 * @throws Exception
	 */
	public void testStepIntoSourceMethodWithParameters() throws Exception {
		String typeName = "org.eclipse.debug.tests.targets.StepIntoSelectionClass";
		createLineBreakpoint(39, typeName);

		IJavaThread thread= null;
		try {
			thread= launchToBreakpoint(typeName);
			assertNotNull("Breakpoint not hit within timeout period", thread);

			ICompilationUnit cu = getCompilationUnit(get14Project(), "src", "org.eclipse.debug.tests.targets", "StepIntoSelectionClass.java");
			IType type = cu.getType("StepIntoSelectionClass");
			IMethod method = type.getMethod("method1", new String[] {"[I", "[QString;"});
			assertTrue("Could not find method 'method1'", method.exists());

			StepIntoSelectionHandler handler = new StepIntoSelectionHandler(thread, (IJavaStackFrame)thread.getTopStackFrame(), method);
			DebugElementEventWaiter waiter = new DebugElementEventWaiter(DebugEvent.SUSPEND, thread);
			handler.step();
			Object source = waiter.waitForEvent();
			assertEquals("Step did not complete", thread, source);
			thread = (IJavaThread)source;

			IJavaStackFrame frame = (IJavaStackFrame)thread.getTopStackFrame();
			assertEquals("Should be in method 'step'", "method1", frame.getMethodName());


		} finally {
			terminateAndRemove(thread);
			removeAllBreakpoints();
		}
	}

	/**
	 * Step into 'Vector.addElement(Object)'
	 *
	 * @throws Exception
	 */
	public void testStepIntoBinaryMethod() throws Exception {
		String typeName = "org.eclipse.debug.tests.targets.StepIntoSelectionClass";
		createLineBreakpoint(37, typeName);

		IJavaThread thread= null;
		try {
			thread= launchToBreakpoint(typeName);
			assertNotNull("Breakpoint not hit within timeout period", thread);

			IType type = get14Project().findType("java.util.Vector");
			IMethod method = type.getMethod("addElement", new String[]{"Ljava.lang.Object;"});
			//for 1.5 compliance, addElement has a type 'E' not an object as the param type
			if(!method.exists()) {
				method = type.getMethod("addElement", new String[] {"TE;"});
			}
			assertTrue("Could not find method 'addElement'", method.exists());

			StepIntoSelectionHandler handler = new StepIntoSelectionHandler(thread, (IJavaStackFrame)thread.getTopStackFrame(), method);
			DebugElementEventWaiter waiter = new DebugElementEventWaiter(DebugEvent.SUSPEND, thread);
			handler.step();
			Object source = waiter.waitForEvent();
			assertEquals("Step did not complete", thread, source);
			thread = (IJavaThread)source;

			IJavaStackFrame frame = (IJavaStackFrame)thread.getTopStackFrame();
			assertEquals("Should be in method 'addElement'", "addElement", frame.getMethodName());


		} finally {
			terminateAndRemove(thread);
			removeAllBreakpoints();
		}
	}

	/**
	 * Step into 'Integer.valueOf(i)'
	 *
	 * @throws Exception
	 */
	public void testStepIntoBinaryConstructor() throws Exception {
		String typeName = "org.eclipse.debug.tests.targets.StepIntoSelectionClass";
		createLineBreakpoint(37, typeName);

		IJavaThread thread= null;
		try {
			thread= launchToBreakpoint(typeName);
			assertNotNull("Breakpoint not hit within timeout period", thread);

			IType type = get14Project().findType("java.lang.Integer");
			IMethod method = type.getMethod("Integer", new String[]{"I"});
			assertTrue("Could not find method constructor", method.exists());

			StepIntoSelectionHandler handler = new StepIntoSelectionHandler(thread, (IJavaStackFrame)thread.getTopStackFrame(), method);
			DebugElementEventWaiter waiter = new DebugElementEventWaiter(DebugEvent.SUSPEND, thread);
			handler.step();
			Object source = waiter.waitForEvent();
			assertEquals("Step did not complete", thread, source);
			thread = (IJavaThread)source;

			IJavaStackFrame frame = (IJavaStackFrame)thread.getTopStackFrame();
			assertEquals("Should be in constructor", "<init>", frame.getMethodName());


		} finally {
			terminateAndRemove(thread);
			removeAllBreakpoints();
		}
	}
}