KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > model > debug > DebugContextTest


1 /*BEGIN_COPYRIGHT_BLOCK
2  *
3  * This file is part of DrJava. Download the current version of this project from http://www.drjava.org/
4  * or http://sourceforge.net/projects/drjava/
5  *
6  * DrJava Open Source License
7  *
8  * Copyright (C) 2001-2005 JavaPLT group at Rice University (javaplt@rice.edu). All rights reserved.
9  *
10  * Developed by: Java Programming Languages Team, Rice University, http://www.cs.rice.edu/~javaplt/
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13  * documentation files (the "Software"), to deal with the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15  * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16  *
17  * - Redistributions of source code must retain the above copyright notice, this list of conditions and the
18  * following disclaimers.
19  * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
20  * following disclaimers in the documentation and/or other materials provided with the distribution.
21  * - Neither the names of DrJava, the JavaPLT, Rice University, nor the names of its contributors may be used to
22  * endorse or promote products derived from this Software without specific prior written permission.
23  * - Products derived from this software may not be called "DrJava" nor use the term "DrJava" as part of their
24  * names without prior written permission from the JavaPLT group. For permission, write to javaplt@rice.edu.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
27  * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * WITH THE SOFTWARE.
31  *
32  *END_COPYRIGHT_BLOCK*/

33
34 package edu.rice.cs.drjava.model.debug;
35
36 import java.io.*;
37 import java.util.Vector JavaDoc;
38
39 import edu.rice.cs.drjava.DrJava;
40 import edu.rice.cs.drjava.config.*;
41 import edu.rice.cs.drjava.model.*;
42 import edu.rice.cs.util.swing.Utilities;
43
44 /** More tests over the JPDA debugger.
45  * @version $Id: DebugContextTest.java 4043 2006-11-22 23:04:59Z rcartwright $
46  */

47 public final class DebugContextTest extends DebugTestCase {
48   
49   
50 // inherits _log from GlobalModelTestCase
51
// public static Log _log = new Log("Debug.txt", true);
52

53   /** Tests that the sourcepath config option properly adds files to the search directories. */
54   public void testDebugSourcepath() throws Exception JavaDoc {
55     _log.log("----testDebugSourcePath----");
56     final StepTestListener debugListener = new StepTestListener();
57     _debugger.addListener(debugListener);
58
59     // Start up
60
final OpenDefinitionsDocument doc = _startupDebugger("DrJavaDebugClass.java", DEBUG_CLASS);
61     final Vector JavaDoc<File> path = new Vector JavaDoc<File>();
62     path.addElement(_tempDir); // directory where doc's file is saved
63

64     // Add a breakpoint
65
_debugger.toggleBreakpoint(doc,DEBUG_CLASS.indexOf("bar();"),4,true);
66
67     // Run the foo() method, hitting breakpoint
68
synchronized(_notifierLock) {
69       _setPendingNotifies(3); // suspended, updated, breakpointReached
70
interpretIgnoreResult("new DrJavaDebugClass().foo()");
71       while (_pendingNotifies > 0) _notifierLock.wait();
72     }
73     // Source is highlighted because document is stored in breakpoint
74
debugListener.assertThreadLocationUpdatedCount(1); // fires
75

76     // Step into bar() method
77
synchronized(_notifierLock) {
78       _setPendingNotifies(2); // suspended, updated
79
_asyncStep(Debugger.STEP_INTO);
80       while (_pendingNotifies > 0) _notifierLock.wait();
81     }
82     // Source is highlighted because file is in source root set
83
debugListener.assertStepRequestedCount(1); // fires (don't wait)
84
debugListener.assertThreadLocationUpdatedCount(2); // fires
85

86     // Close file so it won't be in source root set
87
_model.closeFile(doc);
88     Utilities.clearEventQueue();
89     debugListener.assertRegionRemovedCount(1);
90
91     // Step to next line
92
synchronized(_notifierLock) {
93       _setPendingNotifies(1); // suspended
94
_asyncStep(Debugger.STEP_OVER);
95       while (_pendingNotifies > 0) _notifierLock.wait();
96     }
97     // Source is not highlighted
98
debugListener.assertStepRequestedCount(2); // fires (don't wait)
99
debugListener.assertThreadLocationUpdatedCount(2); // doesn't fire
100

101     synchronized(_debugger) {
102       // Add _tempDir to our sourcepath
103
Utilities.invokeAndWait(new Runnable JavaDoc() {
104         public void run() {
105           DrJava.getConfig().setSetting(OptionConstants.DEBUG_SOURCEPATH, path);
106         }
107       });
108     }
109
110     // Step to next line
111
synchronized(_notifierLock) {
112       _asyncStep(Debugger.STEP_OVER);
113       _setPendingNotifies(2); // suspended, updated
114
while (_pendingNotifies > 0) _notifierLock.wait();
115     }
116     // Source is highlighted because file is now on sourcepath
117
debugListener.assertStepRequestedCount(3); // fires (don't wait)
118
debugListener.assertThreadLocationUpdatedCount(3); // fires
119

120     _log.log("Shutting down testDebugSourcePath");
121
122     // Shut down
123
_shutdownAndWaitForInteractionEnded();
124     _debugger.removeListener(debugListener);
125   }
126
127   /** Tests that breakpoints behave correctly in non-public classes. */
128   public synchronized void testBreakpointsAndStepsInNonPublicClasses() throws Exception JavaDoc {
129     _log.log("----testBreakpointsAndStepsInNonPublicClasses----");
130     final StepTestListener debugListener = new StepTestListener();
131     _debugger.addListener(debugListener);
132
133     // Start up
134
OpenDefinitionsDocument doc = _startupDebugger("DrJavaDebugClass.java", DEBUG_CLASS);
135
136     // Add a breakpoint
137
_debugger.toggleBreakpoint(doc,DEBUG_CLASS.indexOf("Baz Line 1"), 14,true);
138     
139     Utilities.clearEventQueue();
140     debugListener.assertRegionAddedCount(1);
141
142     // Run the baz() method, hitting breakpoint
143
synchronized(_notifierLock) {
144       _setPendingNotifies(3); // suspended, updated, breakpointReached
145
interpretIgnoreResult("new DrJavaDebugClass2().baz()");
146       while (_pendingNotifies > 0) _notifierLock.wait();
147     }
148
149 // _log.log("----After breakpoint:\n" + getInteractionsText());
150

151     // Ensure breakpoint is hit
152
debugListener.assertBreakpointReachedCount(1); //fires
153
debugListener.assertThreadLocationUpdatedCount(1); //fires
154
debugListener.assertCurrThreadSuspendedCount(1); //fires
155
debugListener.assertCurrThreadResumedCount(0);
156     debugListener.assertCurrThreadDiedCount(0);
157     assertInteractionsDoesNotContain("Baz Line 1");
158
159 // _log.log("adding another breakpoint");
160

161     // Set another breakpoint (after is class loaded)
162
_debugger.toggleBreakpoint(doc, DEBUG_CLASS.indexOf("System.out.println(\"Bar Line 2\")"), 9,true);
163     
164     Utilities.clearEventQueue();
165     debugListener.assertRegionAddedCount(2);
166
167     // Step to next line
168
synchronized(_notifierLock) {
169       _setPendingNotifies(2); // suspended, updated
170
_asyncStep(Debugger.STEP_OVER);
171       while (_pendingNotifies > 0) _notifierLock.wait();
172     }
173
174 // _log.log("****"+getInteractionsText());
175
debugListener.assertStepRequestedCount(1); // fires (don't wait)
176
debugListener.assertCurrThreadResumedCount(1); // fires (don't wait)
177
debugListener.assertThreadLocationUpdatedCount(2); // fires
178
debugListener.assertCurrThreadDiedCount(0);
179     debugListener.assertCurrThreadSuspendedCount(2); //fires
180
debugListener.assertBreakpointReachedCount(1);
181     assertInteractionsContains("Baz Line 1");
182     assertInteractionsDoesNotContain("Bar Line 1");
183
184     // Resume until next breakpoint
185
synchronized(_notifierLock) {
186 // _log.log("resuming");
187
_setPendingNotifies(3); // suspended, updated, breakpointReached
188
_asyncResume();
189       while (_pendingNotifies > 0) _notifierLock.wait();
190     }
191 // _log.log("----After one resume:\n" + getInteractionsText());
192
debugListener.assertCurrThreadResumedCount(2); //fires (no waiting)
193
debugListener.assertBreakpointReachedCount(2); //fires
194
debugListener.assertThreadLocationUpdatedCount(3); //fires
195
debugListener.assertCurrThreadSuspendedCount(3); //fires
196
debugListener.assertCurrThreadDiedCount(0);
197     assertInteractionsContains("Bar Line 1");
198     assertInteractionsDoesNotContain("Bar Line 2");
199
200 // _log.log("-------- Adding interpret listener --------");
201
// Resume until finished, waiting for call to interpret to end
202
InterpretListener interpretListener = new InterpretListener();
203     _model.addListener(interpretListener);
204     synchronized(_notifierLock) {
205 // _log.log("-------- resuming --------");
206
_setPendingNotifies(3); // interactionEnded, interpreterChanged, currThreadDied (since it's the last thread)
207
_asyncResume();
208       while (_pendingNotifies > 0) _notifierLock.wait();
209     }
210     interpretListener.assertInteractionEndCount(1);
211     _model.removeListener(interpretListener);
212
213     _log.log("----After second resume:\n" + getInteractionsText());
214     debugListener.assertCurrThreadResumedCount(3); //fires (no waiting)
215
debugListener.assertBreakpointReachedCount(2);
216     debugListener.assertThreadLocationUpdatedCount(3);
217     debugListener.assertCurrThreadSuspendedCount(3);
218     assertInteractionsContains("Bar Line 2");
219
220     // Shut down
221
_shutdownWithoutSuspendedInteraction();
222     _debugger.removeListener(debugListener);
223   }
224
225   /** Tests that stepping into a breakpoint works. */
226   public synchronized void testStepIntoOverBreakpoint() throws Exception JavaDoc {
227     _log.log("----testStepIntoOverBreakpoint----");
228     StepTestListener debugListener = new StepTestListener();
229     _debugger.addListener(debugListener);
230
231     // Start up
232
OpenDefinitionsDocument doc = _startupDebugger("DrJavaDebugClass.java", DEBUG_CLASS);
233
234     // Add a breakpoint
235
_debugger.toggleBreakpoint(doc,DEBUG_CLASS.indexOf("Foo Line 1"), 3,true);
236     _debugger.toggleBreakpoint(doc,DEBUG_CLASS.indexOf("bar();\n"), 4,true);
237     
238     Utilities.clearEventQueue();
239     debugListener.assertRegionAddedCount(2);
240
241     // Run the foo() method, hitting breakpoint
242
synchronized(_notifierLock) {
243       _setPendingNotifies(3); // suspended, updated, breakpointReached
244
interpretIgnoreResult("new DrJavaDebugClass().foo()");
245       while (_pendingNotifies > 0) _notifierLock.wait();
246     }
247
248 // _log.log("----After breakpoint:\n" + getInteractionsText());
249

250     // Ensure breakpoint is hit
251
debugListener.assertBreakpointReachedCount(1); //fires
252
debugListener.assertThreadLocationUpdatedCount(1); //fires
253
debugListener.assertCurrThreadSuspendedCount(1); //fires
254
debugListener.assertCurrThreadResumedCount(0);
255     debugListener.assertCurrThreadDiedCount(0);
256     assertInteractionsDoesNotContain("Foo Line 1");
257
258     // Step over once
259
synchronized(_notifierLock) {
260       _setPendingNotifies(2); // suspended, updated
261
_asyncStep(Debugger.STEP_OVER);
262       while (_pendingNotifies > 0) _notifierLock.wait();
263     }
264     debugListener.assertStepRequestedCount(1); // fires (don't wait)
265
debugListener.assertCurrThreadResumedCount(1); // fires (don't wait)
266
debugListener.assertThreadLocationUpdatedCount(2); // fires
267
debugListener.assertCurrThreadSuspendedCount(2); // fires
268
debugListener.assertBreakpointReachedCount(1);
269     debugListener.assertCurrThreadDiedCount(0);
270     assertInteractionsContains("Foo Line 1");
271
272     // Step over again
273
synchronized(_notifierLock) {
274       _setPendingNotifies(2); // suspended, updated
275
_asyncStep(Debugger.STEP_OVER);
276       while (_pendingNotifies > 0) _notifierLock.wait();
277     }
278
279 // _log.log("****"+getInteractionsText());
280
debugListener.assertStepRequestedCount(2); // fires (don't wait)
281
debugListener.assertCurrThreadResumedCount(2); // fires (don't wait)
282
debugListener.assertThreadLocationUpdatedCount(3); // fires
283
debugListener.assertCurrThreadDiedCount(0);
284     debugListener.assertCurrThreadSuspendedCount(3); // fires
285
debugListener.assertBreakpointReachedCount(1);
286
287     // Resume until finished, waiting for interpret call to finish
288
InterpretListener interpretListener = new InterpretListener();
289     _model.addListener(interpretListener);
290     synchronized(_notifierLock) {
291       _setPendingNotifies(3); // interactionEnded, interpreterChanged, currThreadDied (since it's the last thread)
292
_asyncResume();
293       while (_pendingNotifies > 0) _notifierLock.wait();
294     }
295     interpretListener.assertInteractionEndCount(1);
296     _model.removeListener(interpretListener);
297
298 // _log.log("----After resume:\n" + getInteractionsText());
299
debugListener.assertCurrThreadResumedCount(3); //fires (no waiting)
300
debugListener.assertBreakpointReachedCount(1);
301     debugListener.assertThreadLocationUpdatedCount(3);
302     debugListener.assertCurrThreadSuspendedCount(3);
303
304     // Close doc and make sure breakpoints are removed
305
_model.closeFile(doc);
306     Utilities.clearEventQueue();
307     debugListener.assertRegionRemovedCount(2); //fires (no waiting)
308

309     // Shutdown the debugger
310
// _log.log("Shutting down ...");
311

312     synchronized(_notifierLock) {
313       _setPendingNotifies(1); // shutdown
314
_debugger.shutdown();
315       while (_pendingNotifies > 0) _notifierLock.wait();
316     }
317
318     debugListener.assertDebuggerShutdownCount(1); //fires
319
_log.log("Completed testStepIntoOverBreakpoint");
320     _debugger.removeListener(debugListener);
321   }
322
323   /** Tests that static fields are consistent across different interpreter contexts. */
324   public void testStaticFieldsConsistent() throws Exception JavaDoc {
325     _log.log("----testStaticFieldsConsistent----");
326     StepTestListener debugListener = new StepTestListener();
327     _debugger.addListener(debugListener);
328
329     // Start up
330
OpenDefinitionsDocument doc = _startupDebugger("DrJavaDebugStaticField.java", CLASS_WITH_STATIC_FIELD);
331
332     // Set a breakpoint
333
_debugger.toggleBreakpoint(doc,CLASS_WITH_STATIC_FIELD.indexOf("System.out.println"), 4,true);
334     
335     Utilities.clearEventQueue();
336     debugListener.assertRegionAddedCount(1);
337
338     // Run the main method, hitting breakpoint
339
synchronized(_notifierLock) {
340       _setPendingNotifies(6); // (suspended, updated, breakpointReached) *2
341
interpretIgnoreResult("java DrJavaDebugStaticField");
342       while (_pendingNotifies > 0) _notifierLock.wait();
343     }
344
345     // TODO: Why is this call being made?
346
DebugThreadData threadA = new DebugThreadData(_debugger.getCurrentThread());
347     DebugThreadData threadB = new DebugThreadData(_debugger.getThreadAt(1));
348 // _log.log("----After breakpoint:\n" + getInteractionsText());
349

350     // Ensure breakpoint is hit
351
debugListener.assertBreakpointReachedCount(2); //fires
352
debugListener.assertThreadLocationUpdatedCount(2); //fires
353
debugListener.assertCurrThreadSuspendedCount(2); //fires
354
debugListener.assertCurrThreadResumedCount(0);
355     debugListener.assertCurrThreadDiedCount(0);
356     assertEquals("x has correct value at start", "0", interpret("DrJavaDebugStaticField.x"));
357     assertEquals("assigning x succeeds", "5", interpret("DrJavaDebugStaticField.x = 5"));
358     assertEquals("assignment reflected in this", "5", interpret("this.x"));
359
360     // Step over once
361
synchronized(_notifierLock) {
362       _setPendingNotifies(2); // suspended, updated
363
_asyncStep(Debugger.STEP_OVER);
364       while (_pendingNotifies > 0) _notifierLock.wait();
365     }
366     debugListener.assertStepRequestedCount(1); // fires (don't wait)
367
debugListener.assertCurrThreadResumedCount(1); // fires (don't wait)
368
debugListener.assertThreadLocationUpdatedCount(3); // fires
369
debugListener.assertCurrThreadSuspendedCount(3); // fires
370
debugListener.assertBreakpointReachedCount(2);
371     debugListener.assertCurrThreadDiedCount(0);
372     assertInteractionsContains("x == 5");
373     assertEquals("x retains correct value after step", "5", interpret("DrJavaDebugStaticField.x"));
374     assertEquals("this has correct value for x after step", "5", interpret("this.x"));
375
376     // Step over again
377
synchronized(_notifierLock) {
378       _setPendingNotifies(2); // suspended, updated
379
_asyncStep(Debugger.STEP_OVER);
380       while (_pendingNotifies > 0) _notifierLock.wait();
381     }
382 // _log.log("****"+getInteractionsText());
383
debugListener.assertStepRequestedCount(2); // fires (don't wait)
384
debugListener.assertCurrThreadResumedCount(2); // fires (don't wait)
385
debugListener.assertThreadLocationUpdatedCount(4); // fires
386
debugListener.assertCurrThreadSuspendedCount(4); // fires
387
debugListener.assertBreakpointReachedCount(2);
388     debugListener.assertCurrThreadDiedCount(0);
389     assertEquals("x has correct value after increment", "6", interpret("DrJavaDebugStaticField.x"));
390     assertEquals("this has correct value for x after increment", "6", interpret("this.x"));
391
392     synchronized(_notifierLock) {
393       _setPendingNotifies(2); // suspended, updated
394
_asyncDoSetCurrentThread(threadB);
395       while (_pendingNotifies > 0) _notifierLock.wait();
396     }
397     interpret("");
398     assertInteractionsContains("The current thread has changed.");
399     assertEquals("x has correct value in other thread", "6", interpret("DrJavaDebugStaticField.x"));
400     assertEquals("this has correct value for x in other thread", "6", interpret("this.x"));
401
402     // Shut down
403
_shutdownAndWaitForInteractionEnded();
404     _debugger.removeListener(debugListener);
405   }
406
407   /** Tests that watches can correctly see the values of local variables, fields and fields of outer classes. Also tests
408     * that we can watch objects initialized to null (bug #771040) and that we can watch final local variables of outer
409     * classes (bug #769174).
410     */

411   public void testNonStaticWatches() throws Exception JavaDoc {
412     _log.log("----testNonStaticWatches----");
413     StepTestListener debugListener = new StepTestListener();
414     _debugger.addListener(debugListener);
415     
416     final String JavaDoc monkey = MONKEY_WITH_INNER_CLASS;
417
418     // Start up
419
OpenDefinitionsDocument doc = _startupDebugger("Monkey.java", monkey);
420
421     // Set a breakpoint
422
_debugger.toggleBreakpoint(doc, monkey.indexOf("innerMethodFoo = 12;"), 10, true);
423     _debugger.toggleBreakpoint(doc, monkey.indexOf("System.out.println(\"localVar = \" + localVar);"), 32, true);
424     
425     Utilities.clearEventQueue();
426     debugListener.assertRegionAddedCount(2);
427
428     // Run an inner method, hitting breakpoint
429
synchronized(_notifierLock) {
430       _setPendingNotifies(3); // suspended, updated, breakpointReached
431
interpretIgnoreResult("new Monkey().bar()");//new MonkeyInner().new MonkeyInnerInner().innerMethod()");
432
while (_pendingNotifies > 0) _notifierLock.wait();
433     }
434
435     _debugger.addWatch("foo");
436     _debugger.addWatch("innerFoo");
437     _debugger.addWatch("innerInnerFoo");
438     _debugger.addWatch("innerMethodFoo");
439     _debugger.addWatch("asdf");
440     _debugger.addWatch("nullString");
441     _debugger.addWatch("localVar");
442     Utilities.clearEventQueue();
443     debugListener.assertWatchSetCount(7);
444
445 // _log.log("first step");
446

447     // Step to line 11
448
synchronized(_notifierLock) {
449       _setPendingNotifies(2); // suspended, updated
450
_asyncStep(Debugger.STEP_OVER);
451       while (_pendingNotifies > 0) _notifierLock.wait();
452     }
453     debugListener.assertStepRequestedCount(1); // fires (don't wait)
454
debugListener.assertCurrThreadResumedCount(1); // fires (don't wait)
455
debugListener.assertThreadLocationUpdatedCount(2); // fires
456
debugListener.assertCurrThreadSuspendedCount(2); // fires
457
debugListener.assertBreakpointReachedCount(1);
458     debugListener.assertCurrThreadDiedCount(0);
459
460     Vector JavaDoc<DebugWatchData> watches = _debugger.getWatches();
461     assertEquals("watch name incorrect", "foo", watches.get(0).getName());
462     assertEquals("watch name incorrect", "innerFoo", watches.get(1).getName());
463     assertEquals("watch name incorrect", "innerInnerFoo", watches.get(2).getName());
464     assertEquals("watch name incorrect", "innerMethodFoo", watches.get(3).getName());
465     assertEquals("watch name incorrect", "asdf", watches.get(4).getName());
466     assertEquals("watch name incorrect", "nullString", watches.get(5).getName());
467     assertEquals("watch value incorrect", "6", watches.get(0).getValue());
468     assertEquals("watch value incorrect", "8", watches.get(1).getValue());
469     assertEquals("watch value incorrect", "10", watches.get(2).getValue());
470     assertEquals("watch value incorrect", "12", watches.get(3).getValue());
471     assertEquals("watch value incorrect", DebugWatchData.NO_VALUE, watches.get(4).getValue());
472     assertEquals("watch value incorrect", "null", watches.get(5).getValue());
473     assertEquals("watch type incorrect", "java.lang.String", watches.get(5).getType());
474
475     interpret("innerFoo = 0");
476     watches = _debugger.getWatches();
477     assertEquals("watch name incorrect", "innerFoo", watches.get(1).getName());
478     assertEquals("watch value incorrect", "0", watches.get(1).getValue());
479
480     interpret("innerFoo = 8");
481     assertEquals("watch name incorrect", "innerFoo", watches.get(1).getName());
482     assertEquals("watch value incorrect", "8", watches.get(1).getValue());
483
484 // _log.log("second step in " + this);
485

486     // Step to line 12
487
synchronized(_notifierLock) {
488       _setPendingNotifies(2); // suspended, updated
489
_asyncStep(Debugger.STEP_OVER);
490       while (_pendingNotifies > 0) _notifierLock.wait();
491     }
492     debugListener.assertStepRequestedCount(2); // fires (don't wait)
493
debugListener.assertCurrThreadResumedCount(2); // fires (don't wait)
494
debugListener.assertThreadLocationUpdatedCount(3); // fires
495
debugListener.assertCurrThreadSuspendedCount(3); // fires
496
debugListener.assertBreakpointReachedCount(1);
497     debugListener.assertCurrThreadDiedCount(0);
498
499 // _log.log("third step in " + this);
500

501     // Step to line 13
502
synchronized(_notifierLock) {
503       _setPendingNotifies(2); // suspended, updated
504
_asyncStep(Debugger.STEP_OVER);
505       while (_pendingNotifies > 0) _notifierLock.wait();
506     }
507     debugListener.assertStepRequestedCount(3); // fires (don't wait)
508
debugListener.assertCurrThreadResumedCount(3); // fires (don't wait)
509
debugListener.assertThreadLocationUpdatedCount(4); // fires
510
debugListener.assertCurrThreadSuspendedCount(4); // fires
511
debugListener.assertBreakpointReachedCount(1);
512     debugListener.assertCurrThreadDiedCount(0);
513
514 // _log.log("fourth step in " + this);
515

516     // Step to line 14
517
synchronized(_notifierLock) {
518       _setPendingNotifies(2); // suspended, updated
519
_asyncStep(Debugger.STEP_OVER);
520       while (_pendingNotifies > 0) _notifierLock.wait();
521     }
522     debugListener.assertStepRequestedCount(4); // fires (don't wait)
523
debugListener.assertCurrThreadResumedCount(4); // fires (don't wait)
524
debugListener.assertThreadLocationUpdatedCount(5); // fires
525
debugListener.assertCurrThreadSuspendedCount(5); // fires
526
debugListener.assertBreakpointReachedCount(1);
527     debugListener.assertCurrThreadDiedCount(0);
528
529 // _log.log("fifth step in " + this);
530

531     // Step to line 15
532
synchronized(_notifierLock) {
533       _setPendingNotifies(2); // suspended, updated
534
_asyncStep(Debugger.STEP_OVER);
535       while (_pendingNotifies > 0) _notifierLock.wait();
536     }
537     debugListener.assertStepRequestedCount(5); // fires (don't wait)
538
debugListener.assertCurrThreadResumedCount(5); // fires (don't wait)
539
debugListener.assertThreadLocationUpdatedCount(6); // fires
540
debugListener.assertCurrThreadSuspendedCount(6); // fires
541
debugListener.assertBreakpointReachedCount(1);
542     debugListener.assertCurrThreadDiedCount(0);
543
544     watches = _debugger.getWatches();
545     assertEquals("watch name incorrect", "foo", watches.get(0).getName());
546     assertEquals("watch name incorrect", "innerFoo", watches.get(1).getName());
547     assertEquals("watch name incorrect", "innerInnerFoo", watches.get(2).getName());
548     assertEquals("watch name incorrect", "innerMethodFoo", watches.get(3).getName());
549     assertEquals("watch name incorrect", "asdf", watches.get(4).getName());
550     assertEquals("watch name incorrect", "nullString", watches.get(5).getName());
551     assertEquals("watch value incorrect", "7", watches.get(0).getValue());
552     assertEquals("watch value incorrect", "9", watches.get(1).getValue());
553     assertEquals("watch value incorrect", "11", watches.get(2).getValue());
554     assertEquals("watch value incorrect", "13", watches.get(3).getValue());
555     assertEquals("watch value incorrect", DebugWatchData.NO_VALUE, watches.get(4).getValue());
556     assertEquals("watch value incorrect", "null", watches.get(5).getValue());
557     assertEquals("watch type incorrect", "java.lang.String", watches.get(5).getType());
558
559 // _log.log("sixth step in " + this);
560

561     // Step into static method
562
synchronized(_notifierLock) {
563       _setPendingNotifies(2); // suspended, updated
564
_asyncStep(Debugger.STEP_INTO);
565       while (_pendingNotifies > 0) _notifierLock.wait();
566     }
567     debugListener.assertStepRequestedCount(6); // fires (don't wait)
568
debugListener.assertCurrThreadResumedCount(6); // fires (don't wait)
569
debugListener.assertThreadLocationUpdatedCount(7); // fires
570
debugListener.assertCurrThreadSuspendedCount(7); // fires
571
debugListener.assertBreakpointReachedCount(1);
572     debugListener.assertCurrThreadDiedCount(0);
573
574     // Test watches in a static context.
575
watches = _debugger.getWatches();
576     assertEquals("watch name incorrect", "foo", watches.get(0).getName());
577     assertEquals("watch name incorrect", "innerFoo", watches.get(1).getName());
578     assertEquals("watch name incorrect", "innerInnerFoo", watches.get(2).getName());
579     assertEquals("watch name incorrect", "innerMethodFoo", watches.get(3).getName());
580     assertEquals("watch name incorrect", "asdf", watches.get(4).getName());
581     assertEquals("watch name incorrect", "nullString", watches.get(5).getName());
582     assertEquals("watch value incorrect", "7", watches.get(0).getValue());
583     assertEquals("watch value incorrect", DebugWatchData.NO_VALUE, watches.get(1).getValue());
584     assertEquals("watch value incorrect", DebugWatchData.NO_VALUE, watches.get(2).getValue());
585     assertEquals("watch value incorrect", DebugWatchData.NO_VALUE, watches.get(3).getValue());
586     assertEquals("watch value incorrect", DebugWatchData.NO_VALUE, watches.get(4).getValue());
587     assertEquals("watch value incorrect", DebugWatchData.NO_VALUE, watches.get(5).getValue());
588     assertEquals("watch type incorrect", DebugWatchData.NO_TYPE, watches.get(5).getType());
589
590     // Resumes one thread, finishing it and switching to the next break point
591
synchronized(_notifierLock) {
592       _setPendingNotifies(3); // breakpointReached, suspended, updated
593
_asyncResume();
594       while (_pendingNotifies > 0) _notifierLock.wait();
595     }
596     debugListener.assertStepRequestedCount(6); // fires (don't wait)
597
debugListener.assertCurrThreadResumedCount(7); // fires (don't wait)
598
debugListener.assertThreadLocationUpdatedCount(8); // fires
599
debugListener.assertCurrThreadSuspendedCount(8); // fires
600
debugListener.assertBreakpointReachedCount(2);
601     debugListener.assertCurrThreadDiedCount(0);
602
603     // Test watching a final local variable of an outer class
604
watches = _debugger.getWatches();
605     assertEquals("watch name incorrect", "localVar", watches.get(6).getName());
606     assertEquals("watch value incorrect", "11", watches.get(6).getValue());
607
608     // Close doc and make sure breakpoints are removed
609
_model.closeFile(doc);
610     Utilities.clearEventQueue();
611     debugListener.assertRegionRemovedCount(2); //fires (no waiting)
612

613     // Shut down
614
_shutdownAndWaitForInteractionEnded();
615     _debugger.removeListener(debugListener);
616   }
617
618   /**
619    * Tests that watches can correctly see the values of local
620    * variables, fields and fields of outer classes.
621    */

622   public void testStaticWatches() throws Exception JavaDoc {
623     _log.log("----testStaticWatches----");
624     StepTestListener debugListener = new StepTestListener();
625     _debugger.addListener(debugListener);
626
627     // Start up
628
OpenDefinitionsDocument doc = _startupDebugger("MonkeyStaticStuff.java", MONKEY_STATIC_STUFF);
629
630     // Set a breakpoint
631
int index = MONKEY_STATIC_STUFF.indexOf("System.out.println(MonkeyInner.MonkeyTwoDeep.twoDeepFoo);");
632     _debugger.toggleBreakpoint(doc, index, 14, true);
633     
634     Utilities.clearEventQueue();
635     debugListener.assertRegionAddedCount(1);
636
637     // Run an inner method, hitting breakpoint
638
synchronized(_notifierLock) {
639       _setPendingNotifies(3); // suspended, updated, breakpointReached
640
interpretIgnoreResult("MonkeyStaticStuff.MonkeyInner.MonkeyTwoDeep.MonkeyThreeDeep.threeDeepMethod();");
641       while (_pendingNotifies > 0) _notifierLock.wait();
642     }
643
644     _debugger.addWatch("foo");
645     _debugger.addWatch("innerFoo");
646     _debugger.addWatch("twoDeepFoo");
647     _debugger.addWatch("threeDeepFoo");
648     _debugger.addWatch("asdf");
649     Utilities.clearEventQueue();
650     debugListener.assertWatchSetCount(5);
651     
652     Vector JavaDoc<DebugWatchData> watches = _debugger.getWatches();
653     assertEquals("watch name incorrect", "foo", watches.get(0).getName());
654     assertEquals("watch name incorrect", "innerFoo", watches.get(1).getName());
655     assertEquals("watch name incorrect", "twoDeepFoo", watches.get(2).getName());
656     assertEquals("watch name incorrect", "threeDeepFoo", watches.get(3).getName());
657     assertEquals("watch name incorrect", "asdf", watches.get(4).getName());
658     assertEquals("watch value incorrect", "6", watches.get(0).getValue());
659     assertEquals("watch value incorrect", "8", watches.get(1).getValue());
660     assertEquals("watch value incorrect", "13", watches.get(2).getValue());
661     assertEquals("watch value incorrect", "18", watches.get(3).getValue());
662     assertEquals("watch value incorrect", DebugWatchData.NO_VALUE, watches.get(4).getValue());
663
664     interpret("innerFoo = 0");
665     watches = _debugger.getWatches();
666     assertEquals("watch name incorrect", "innerFoo", watches.get(1).getName());
667     assertEquals("watch value incorrect", "0", watches.get(1).getValue());
668
669     interpret("innerFoo = 8");
670     assertEquals("watch name incorrect", "innerFoo", watches.get(1).getName());
671     assertEquals("watch value incorrect", "8", watches.get(1).getValue());
672
673     // Shut down
674
_shutdownAndWaitForInteractionEnded();
675     _debugger.removeListener(debugListener);
676   }
677
678   /** Tests that watches can correctly see the values of final local variables and method parameters from enclosing
679     * classes. Note: Some final local variables are inlined by the compiler (even in debug mode), so they are
680     * unavailable to the debugger.
681     */

682   public void testWatchLocalVarsFromInnerClass() throws Exception JavaDoc {
683     _log.log("----testWatchLocalVarsFromInnerClass----");
684     StepTestListener debugListener = new StepTestListener();
685     _debugger.addListener(debugListener);
686
687     // Start up
688
OpenDefinitionsDocument doc = _startupDebugger("InnerClassWithLocalVariables.java", INNER_CLASS_WITH_LOCAL_VARS);
689
690     // Set a breakpoint
691
int index = INNER_CLASS_WITH_LOCAL_VARS.indexOf("numArgs:");
692     _debugger.toggleBreakpoint(doc, index, 7, true);
693     
694     Utilities.clearEventQueue();
695     debugListener.assertRegionAddedCount(1);
696
697     // Run the main method, hitting breakpoint
698
synchronized(_notifierLock) {
699       _setPendingNotifies(3); // suspended, updated, breakpointReached
700
interpretIgnoreResult("java InnerClassWithLocalVariables arg");
701       while (_pendingNotifies > 0) _notifierLock.wait();
702     }
703     _debugger.addWatch("numArgs");
704     _debugger.addWatch("args");
705     _debugger.addWatch("inlined");
706     Utilities.clearEventQueue();
707     debugListener.assertWatchSetCount(3);
708
709     // Check watch values
710
Vector JavaDoc<DebugWatchData> watches = _debugger.getWatches();
711     assertEquals("numArgs watch value incorrect", "1", watches.get(0).getValue());
712     String JavaDoc argsWatch = watches.get(1).getValue();
713     assertTrue("args watch value incorrect", argsWatch.indexOf("java.lang.String") != -1);
714
715     // unfortunately, inlined variable can't be seen
716
assertEquals("watch value incorrect", DebugWatchData.NO_VALUE, watches.get(2).getValue());
717
718     // Shut down
719
_shutdownAndWaitForInteractionEnded();
720     _debugger.removeListener(debugListener);
721   }
722
723   /** Tests that watches can correctly see the values of final local variables and method parameters from enclosing
724     * classes. Note: Some final local variables are inlined by the compiler (even in debug mode), so they are
725     * unavailable to the debugger.
726     */

727   public void testThreadShouldDie() throws Exception JavaDoc {
728     _log.log("----testThreadShouldDie----");
729     StepTestListener debugListener = new StepTestListener();
730     _debugger.addListener(debugListener);
731
732     // Start up
733
OpenDefinitionsDocument doc = _startupDebugger("DrJavaThreadDeathTest.java", THREAD_DEATH_CLASS);
734
735     // Before bugs 697825 and 779111 were fixed, this line would just
736
// hang, since dead threads remained suspended indefinitely.
737
interpret("Jones.threadShouldDie()");
738
739     // Shut down
740
_shutdownWithoutSuspendedInteraction();
741     _debugger.removeListener(debugListener);
742   }
743 }
744
Popular Tags