1313 *******************************************************************************/
1414package org .eclipse .jdt .debug .test .stepping ;
1515
16+ import org .eclipse .core .runtime .ISafeRunnable ;
17+ import org .eclipse .debug .core .DebugEvent ;
1618import org .eclipse .debug .core .model .ILineBreakpoint ;
1719import org .eclipse .jdt .debug .core .IJavaStackFrame ;
1820import org .eclipse .jdt .debug .core .IJavaThread ;
21+ import org .eclipse .jdt .debug .testplugin .DebugElementKindEventWaiter ;
22+ import org .eclipse .jdt .debug .testplugin .DebugEventWaiter ;
1923import org .eclipse .jdt .debug .tests .AbstractDebugTest ;
2024import org .eclipse .jdt .internal .debug .ui .IJDIPreferencesConstants ;
2125import org .eclipse .jdt .internal .debug .ui .JDIDebugUIPlugin ;
2226import org .eclipse .jface .preference .IPreferenceStore ;
2327
2428public class StatementSteppingTests extends AbstractDebugTest {
2529
26- private boolean fOriginalState ;
30+ private boolean originalPreferenceValue ;
2731
2832 public StatementSteppingTests (String name ) {
2933 super (name );
@@ -32,42 +36,52 @@ public StatementSteppingTests(String name) {
3236 @ Override
3337 protected void setUp () throws Exception {
3438 super .setUp ();
35- fOriginalState = getPrefStore ().getBoolean (IJDIPreferencesConstants .PREF_STATEMENT_LEVEL_STEPPING );
36- if (!fOriginalState ) {
39+ originalPreferenceValue = getPrefStore ().getBoolean (IJDIPreferencesConstants .PREF_STATEMENT_LEVEL_STEPPING );
40+ if (!originalPreferenceValue ) {
3741 getPrefStore ().setValue (IJDIPreferencesConstants .PREF_STATEMENT_LEVEL_STEPPING , true );
3842 }
3943 }
4044
45+ @ Override
46+ protected void tearDown () throws Exception {
47+ if (originalPreferenceValue != getPrefStore ().getBoolean (IJDIPreferencesConstants .PREF_STATEMENT_LEVEL_STEPPING )) {
48+ getPrefStore ().setValue (IJDIPreferencesConstants .PREF_STATEMENT_LEVEL_STEPPING , originalPreferenceValue );
49+ }
50+ super .tearDown ();
51+ }
52+
4153 /**
4254 * Tests a step over with lots of arguments
4355 */
4456 public void testLotsOfMultilineArguments () throws Exception {
4557
4658 String typeName = "StatementStep" ;
4759 ILineBreakpoint bp = createLineBreakpoint (21 , typeName );
48- IJavaThread thread = null ;
60+ IJavaThread t = null ;
4961 try {
50- thread = launchToLineBreakpoint (typeName , bp , true );
62+ IJavaThread thread = launchToLineBreakpoint (typeName , bp , true );
63+ t = thread ;
5164 IJavaStackFrame stackFrame = (IJavaStackFrame ) thread .getTopStackFrame ();
52- thread . stepOver ();
53- Thread . sleep ( 1000 );
65+
66+ runAndWaitForSuspendEvent (() -> thread . stepOver () );
5467 assertEquals ("Should be at line 26" , 26 , stackFrame .getLineNumber ());
5568
56- thread .stepInto ();
57- Thread . sleep ( 1000 );
69+ runAndWaitForSuspendEvent (() -> thread .stepInto () );
70+
5871 stackFrame = (IJavaStackFrame ) thread .getTopStackFrame ();
5972 assertEquals ("Should be at line 36" , 36 , stackFrame .getLineNumber ());
6073
61- thread .stepReturn ();
62- Thread . sleep ( 1000 );
74+ runAndWaitForSuspendEvent (() -> thread .stepReturn () );
75+
6376 stackFrame = (IJavaStackFrame ) thread .getTopStackFrame ();
6477 assertEquals ("Should be at line 22" , 22 , stackFrame .getLineNumber ());
6578
6679 thread .stepOver ();
67- Thread .sleep (1000 );
80+ runAndWaitForSuspendEvent (() -> thread .stepOver ());
81+
6882 assertEquals ("Should be at line 28" , 28 , stackFrame .getLineNumber ());
6983 } finally {
70- terminateAndRemove (thread );
84+ terminateAndRemove (t );
7185 removeAllBreakpoints ();
7286 }
7387 }
@@ -76,20 +90,19 @@ public void testStepOverWithSingleMultilineArgument() throws Exception {
7690
7791 String typeName = "StatementStepArgument" ;
7892 ILineBreakpoint bp = createLineBreakpoint (28 , typeName );
79- IJavaThread thread = null ;
93+ IJavaThread t = null ;
8094 try {
81- thread = launchToLineBreakpoint (typeName , bp , true );
95+ IJavaThread thread = launchToLineBreakpoint (typeName , bp , true );
96+ t = thread ;
8297 IJavaStackFrame stackFrame = (IJavaStackFrame ) thread .getTopStackFrame ();
83- thread .stepOver ();
84- Thread .sleep (1000 );
98+ runAndWaitForSuspendEvent (() -> thread .stepOver ());
8599 assertEquals ("Should be at line 30" , 30 , stackFrame .getLineNumber ());
86100
87- thread .stepOver ();
88- Thread .sleep (1000 );
101+ runAndWaitForSuspendEvent (() -> thread .stepOver ());
89102 assertEquals ("Should be at line 34" , 34 , stackFrame .getLineNumber ());
90103
91104 } finally {
92- terminateAndRemove (thread );
105+ terminateAndRemove (t );
93106 removeAllBreakpoints ();
94107 }
95108 }
@@ -98,38 +111,33 @@ public void testStepOverWithNestedMultiLineArgs() throws Exception {
98111
99112 String typeName = "StatementStepNested" ;
100113 ILineBreakpoint bp = createLineBreakpoint (20 , typeName );
101- IJavaThread thread = null ;
114+ IJavaThread t = null ;
102115 try {
103- thread = launchToLineBreakpoint (typeName , bp , true );
116+ IJavaThread thread = launchToLineBreakpoint (typeName , bp , true );
117+ t = thread ;
104118 IJavaStackFrame stackFrame = (IJavaStackFrame ) thread .getTopStackFrame ();
105- thread .stepOver ();
106- Thread .sleep (1000 );
119+ runAndWaitForSuspendEvent (() -> thread .stepOver ());
107120 assertEquals ("Should be at line 27" , 27 , stackFrame .getLineNumber ());
108121
109- thread .stepInto ();
110- Thread .sleep (1000 );
122+ runAndWaitForSuspendEvent (() -> thread .stepInto ());
111123 stackFrame = (IJavaStackFrame ) thread .getTopStackFrame ();
112124 assertEquals ("Should be at line 38" , 38 , stackFrame .getLineNumber ());
113125
114- thread .stepReturn ();
115- Thread .sleep (1000 );
126+ runAndWaitForSuspendEvent (() -> thread .stepReturn ());
116127 stackFrame = (IJavaStackFrame ) thread .getTopStackFrame ();
117128 assertEquals ("Should be at line 26" , 26 , stackFrame .getLineNumber ());
118129
119- thread .stepOver ();
120- Thread .sleep (1000 );
130+ runAndWaitForSuspendEvent (() -> thread .stepOver ());
121131 assertEquals ("Should be at line 24" , 24 , stackFrame .getLineNumber ());
122132
123- thread .stepOver ();
124- Thread .sleep (1000 );
133+ runAndWaitForSuspendEvent (() -> thread .stepOver ());
125134 assertEquals ("Should be at line 22" , 22 , stackFrame .getLineNumber ());
126135
127- thread .stepOver ();
128- Thread .sleep (1000 );
136+ runAndWaitForSuspendEvent (() -> thread .stepOver ());
129137 assertEquals ("Should be at line 34" , 34 , stackFrame .getLineNumber ());
130138
131139 } finally {
132- terminateAndRemove (thread );
140+ terminateAndRemove (t );
133141 removeAllBreakpoints ();
134142 }
135143 }
@@ -141,11 +149,14 @@ protected IPreferenceStore getPrefStore() {
141149 return JDIDebugUIPlugin .getDefault ().getPreferenceStore ();
142150 }
143151
152+ private void runAndWaitForSuspendEvent (ISafeRunnable runnable ) throws Exception {
153+ DebugEventWaiter waiter = new DebugElementKindEventWaiter (DebugEvent .SUSPEND , IJavaThread .class );
154+ runnable .run ();
155+ waiter .waitForEvent ();
156+ }
157+
144158 @ Override
145- protected void tearDown () throws Exception {
146- super .tearDown ();
147- if (fOriginalState != getPrefStore ().getBoolean (IJDIPreferencesConstants .PREF_STATEMENT_LEVEL_STEPPING )) {
148- getPrefStore ().setValue (IJDIPreferencesConstants .PREF_STATEMENT_LEVEL_STEPPING , fOriginalState );
149- }
159+ protected boolean enableUIEventLoopProcessingInWaiter () {
160+ return true ;
150161 }
151162}
0 commit comments