KickJava   Java API By Example, From Geeks To Geeks.

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


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 edu.rice.cs.drjava.model.*;
37 import edu.rice.cs.plt.io.IOUtil;
38 import edu.rice.cs.util.Log;
39
40 import java.io.*;
41
42 /** This class contains the basic fields and methods that are necessary for any test file that needs to use the
43  * JPDADebugger.
44  * @version $Id: DebugTestCase.java 4069 2007-01-18 17:11:59Z dlsmith $
45  */

46 public abstract class DebugTestCase extends GlobalModelTestCase {
47
48 // protected final boolean printEvents = true;
49
// protected final boolean printMessages = true;
50
// protected PrintStream printStream = System.err;
51

52   // _log inherited from GlabalModelTestCase
53

54   protected volatile int _pendingNotifies = 0;
55   protected final Object JavaDoc _notifierLock = new Object JavaDoc();
56
57   protected volatile JPDADebugger _debugger;
58
59   protected static final String JavaDoc DEBUG_CLASS =
60     /* 1 */ "class DrJavaDebugClass {\n" +
61     /* 2 */ " public void foo() {\n" +
62     /* 3 */ " System.out.println(\"Foo Line 1\");\n" +
63     /* 4 */ " bar();\n" +
64     /* 5 */ " System.out.println(\"Foo Line 3\");\n" +
65     /* 6 */ " }\n" +
66     /* 7 */ " public void bar() {\n" +
67     /* 8 */ " System.out.println(\"Bar Line 1\");\n" +
68     /* 9 */ " System.out.println(\"Bar Line 2\");\n" +
69     /* 10 */ " }\n" +
70     /* 11 */ "}\n" +
71     /* 12 */ "class DrJavaDebugClass2 {\n" +
72     /* 13 */ " public void baz() {\n" +
73     /* 14 */ " System.out.println(\"Baz Line 1\");\n" +
74     /* 15 */ " new DrJavaDebugClass().bar();\n" +
75     /* 16 */ " }\n" +
76     /* 17 */ "}";
77
78   protected static final String JavaDoc DEBUG_CLASS_WITH_PACKAGE =
79     /* 1 */ "package a;\n" +
80     /* 2 */ "public class DrJavaDebugClassWithPackage {\n" +
81     /* 3 */ " public void foo() {\n" +
82     /* 4 */ " System.out.println(\"foo line 1\");\n" +
83     /* 5 */ " System.out.println(\"foo line 2\");\n" +
84     /* 6 */ " }\n" +
85     /* 7 */ "}";
86
87   protected static final String JavaDoc SUSPEND_CLASS =
88     "class Suspender {\n" +
89     " public static void main(String[] args) {\n" +
90     " Thread t1 = new Thread(){\n" +
91     " public void run(){\n" +
92     " int a = 1;\n" +
93     " while(true);\n" +
94     " }\n" +
95     " };\n" +
96     " t1.start();\n" +
97     " }\n" +
98     "}";
99
100   protected static final String JavaDoc MONKEY_CLASS =
101     /* 1 */ "class Monkey {\n" +
102     /* 2 */ " public static void main(String[] args) {\n" +
103     /* 3 */ "\n" +
104     /* 4 */ " Thread t = new Thread(){\n" +
105     /* 5 */ " public void run(){\n" +
106     /* 6 */ " try{\n" +
107     /* 7 */ " Thread.sleep(1000);\n" +
108     /* 8 */ " }\n" +
109     /* 9 */ " catch(InterruptedException e){\n" +
110     /* 10 */ " }\n" +
111     /* 11 */ " System.out.println(\"I\'m a thread! Yeah!\");\n" +
112     /* 12 */ " }\n" +
113     /* 13 */ " };\n" +
114     /* 14 */ " try{\n" +
115     /* 15 */ " t.start();\n" +
116     /* 16 */ " System.out.println(\"I just woke up. I\'m a big boy now.\");\n" +
117     /* 17 */ " System.out.println(\"James likes bananas!\");\n" +
118     /* 18 */ " System.out.println(\"Yes they do.\");\n" +
119     /* 19 */ " }catch(Exception e){\n" +
120     /* 20 */ " e.printStackTrace();\n" +
121     /* 21 */ " }\n" +
122     /* 22 */ " }\n" +
123     /* 23 */ "}\n";
124
125   protected static final String JavaDoc MONKEY_WITH_INNER_CLASS =
126     /* 1 */ "class Monkey {\n" +
127     /* 2 */ " static int foo = 6; \n" +
128     /* 3 */ " class MonkeyInner { \n" +
129     /* 4 */ " int innerFoo = 8;\n" +
130     /* 5 */ " class MonkeyInnerInner { \n" +
131     /* 6 */ " int innerInnerFoo = 10;\n" +
132     /* 7 */ " public void innerMethod() { \n" +
133     /* 8 */ " int innerMethodFoo;\n" +
134     /* 9 */ " String nullString = null;\n" +
135     /* 10 */ " innerMethodFoo = 12;\n" +
136     /* 11 */ " foo++;\n" +
137     /* 12 */ " innerFoo++;\n" +
138     /* 13 */ " innerInnerFoo++;\n" +
139     /* 14 */ " innerMethodFoo++;\n" +
140     /* 15 */ " staticMethod();\n" +
141     /* 16 */ " System.out.println(\"innerMethodFoo: \" + innerMethodFoo);\n" +
142     /* 17 */ " }\n" +
143     /* 18 */ " }\n" +
144     /* 19 */ " }\n" +
145     /* 20 */ " public void bar() {\n" +
146     /* 21 */ " final MonkeyInner.MonkeyInnerInner mi = \n" +
147     /* 22 */ " new MonkeyInner().new MonkeyInnerInner();\n" +
148     /* 23 */ " mi.innerMethod();\n" +
149     /* 24 */ " final int localVar = 99;\n" +
150     /* 25 */ " new Thread() {\n" +
151     /* 26 */ " public void run() {\n" +
152     /* 27 */ " final int localVar = mi.innerInnerFoo;\n" +
153     /* 28 */ " new Thread() {\n" +
154     /* 29 */ " public void run() {\n" +
155     /* 30 */ " new Thread() {\n" +
156     /* 31 */ " public void run() {\n" +
157     /* 32 */ " System.out.println(\"localVar = \" + localVar);\n" +
158     /* 33 */ " }\n" +
159     /* 34 */ " }.run();\n" +
160     /* 35 */ " }\n" +
161     /* 36 */ " }.run();\n" +
162     /* 37 */ " }\n" +
163     /* 38 */ " }.run();\n" +
164     /* 39 */ " }\n" +
165     /* 40 */ " public static void staticMethod() {\n" +
166     /* 41 */ " int z = 3;\n" +
167     /* 42 */ " }\n" +
168     /* 43 */ "}\n";
169
170   protected static final String JavaDoc INNER_CLASS_WITH_LOCAL_VARS =
171     /* 1 */ "class InnerClassWithLocalVariables {\n" +
172     /* 2 */ " public static void main(final String[] args) {\n" +
173     /* 3 */ " final int numArgs = args.length;\n" +
174     /* 4 */ " final int inlined = 0;\n" +
175     /* 5 */ " new Runnable() {\n" +
176     /* 6 */ " public void run() {\n" +
177     /* 7 */ " System.out.println(\"numArgs: \" + numArgs);\n" +
178     /* 8 */ " System.out.println(\"inlined: \" + inlined);\n" +
179     /* 9 */ " System.out.println(\"args.length: \" + args.length);\n" +
180     /* 10 */ " }\n" +
181     /* 11 */ " }.run();\n" +
182     /* 12 */ " }\n" +
183     /* 13 */ "}\n";
184
185   protected static final String JavaDoc CLASS_WITH_STATIC_FIELD =
186     /* 1 */ "public class DrJavaDebugStaticField {\n" +
187     /* 2 */ " public static int x = 0;\n" +
188     /* 3 */ " public void bar() {\n" +
189     /* 4 */ " System.out.println(\"x == \" + x);\n" +
190     /* 5 */ " x++;\n" +
191     /* 6 */ " }\n" +
192     /* 7 */ " public static void main(String[] nu) {\n" +
193     /* 8 */ " new Thread(\"stuff\") {\n" +
194     /* 9 */ " public void run() {\n" +
195     /* 10 */ " new DrJavaDebugStaticField().bar();\n" +
196     /* 11 */ " }\n" +
197     /* 12 */ " }.start();\n" +
198     /* 13 */ " new DrJavaDebugStaticField().bar();\n" +
199     /* 14 */ " }\n" +
200     /* 15 */ "}";
201
202   protected static final String JavaDoc MONKEY_STATIC_STUFF =
203     /*1*/ "class MonkeyStaticStuff {\n" +
204     /*2*/ " static int foo = 6;\n" +
205     /*3*/ " static class MonkeyInner {\n" +
206     /*4*/ " static int innerFoo = 8;\n" +
207     /*5*/ " static public class MonkeyTwoDeep {\n" +
208     /*6*/ " static int twoDeepFoo = 13;\n" +
209     /*7*/ " static class MonkeyThreeDeep {\n" +
210     /*8*/ " public static int threeDeepFoo = 18;\n" +
211     /*9*/ " public static void threeDeepMethod() {\n" +
212     /*10*/" System.out.println(MonkeyStaticStuff.MonkeyInner.MonkeyTwoDeep.MonkeyThreeDeep.threeDeepFoo);\n" +
213     /*11*/" System.out.println(MonkeyTwoDeep.twoDeepFoo);\n" +
214     /*12*/" System.out.println(MonkeyStaticStuff.foo);\n" +
215     /*13*/" System.out.println(MonkeyStaticStuff.MonkeyInner.innerFoo);\n" +
216     /*14*/" System.out.println(MonkeyInner.MonkeyTwoDeep.twoDeepFoo);\n" +
217     /*15*/" System.out.println(innerFoo);\n" +
218     /*16*/" }\n" +
219     /*17*/" }\n" +
220     /*18*/" static int getNegativeTwo() { return -2; }\n" +
221     /*19*/" }\n" +
222     /*20*/" }\n" +
223     /*21*/"}";
224
225   protected static final String JavaDoc THREAD_DEATH_CLASS =
226     /* 1 */ "class Jones {\n" +
227     /* 2 */ " public static void threadShouldDie() {\n" +
228     /* 3 */ " Thread cooper = new Thread() {\n" +
229     /* 4 */ " public void run() {\n" +
230     /* 5 */ " System.out.println(\"This thread should die.\");\n" +
231     /* 6 */ " }\n" +
232     /* 7 */ " };\n" +
233     /* 8 */ " cooper.start();\n" +
234     /* 9 */ " while(cooper.isAlive()) {}\n" +
235     /* 10 */ " System.out.println(\"Thread died.\");\n" +
236     /* 11 */ " }\n" +
237     /* 12 */ "}";
238
239   /** Sets up the debugger for each test. */
240   public void setUp() throws Exception JavaDoc {
241     _log.log("Setting up (DebugTestCase)" + this);
242     super.setUp();
243     _debugger = (JPDADebugger) _model.getDebugger();
244     assertNotNull("Debug Manager should not be null", _debugger);
245   }
246
247   /** Cleans up the debugger after each test. */
248   public void tearDown() throws Exception JavaDoc {
249     _log.log("Tearing down (DebugTestCase)" + this);
250     _debugger = null;
251     super.tearDown();
252   }
253
254   /** Ensures that the given object will wait for n notifications. Callers must call o.wait() AFTER this is
255    * called. Use _notifyLock instead of o.notify() when using this method. Only one object (o) can use this
256    * synchronization protocol at a time, since it uses a field to store the number of pending notifications.
257    * @param n The number of times to be "notified" through _notifyLock
258    */

259   protected void _setPendingNotifies(int n) throws InterruptedException JavaDoc {
260     synchronized(_notifierLock) {
261       _log.log("Waiting for " + n + " notifications ...");
262       _pendingNotifies = n;
263     }
264   }
265
266   /** Notifies _notifierLock if the after the notify count has expired. See _setPendingNotifies. */
267   protected void _notifyLock() {
268     synchronized(_notifierLock) {
269       _pendingNotifies--;
270       _log.log("notified; count = " + _pendingNotifies);
271       if (_pendingNotifies == 0) {
272         _log.log("Notify count reached 0 -- notifying!");
273         _notifierLock.notifyAll(); // can accommodate multiple threads waiting on this event (NOT USED?)
274
}
275       if (_pendingNotifies < 0) fail("Notified too many times");
276     }
277   }
278
279   /** Cleanly starts the debugger with a newly compiled file saved in a temporary directory. Assumes that the
280    * file will compile successfully.
281    * @param fileName Name of the file to save in a temp directory
282    * @param classText String containing the code for the class to compile
283    * @return OpenDefinitionsDocument containing the compiled source file
284    */

285   protected OpenDefinitionsDocument _startupDebugger(String JavaDoc fileName, String JavaDoc classText) throws Exception JavaDoc {
286     // Create a file in the temporary directory
287
File file = IOUtil.attemptCanonicalFile(new File(_tempDir, fileName));
288     return _startupDebugger(file, classText);
289   }
290
291   /** Cleanly starts the debugger with a newly compiled file saved in a temporary directory. Assumes that the
292    * file will compile successfully.
293    * @param file File to save the class in
294    * @param classText String containing the code for the class to compile
295    * @return OpenDefinitionsDocument containing the compiled source file
296    */

297   protected OpenDefinitionsDocument _startupDebugger(File file, String JavaDoc classText) throws Exception JavaDoc {
298     // Compile the file
299
_log.log("Compiling " + file);
300     OpenDefinitionsDocument doc = doCompile(classText, file);
301     _log.log("Staring debugger in " + this);
302     // Start debugger
303
synchronized(_notifierLock) {
304       _setPendingNotifies(1); // startUp
305
_debugger.startUp();
306       while (_pendingNotifies > 0) _notifierLock.wait();
307     }
308     _log.log("Finished starting debugger in " + this);
309     return doc;
310   }
311
312   /** Cleanly shuts down the debugger, without having to wait for a suspended interaction to complete. */
313   protected void _shutdownWithoutSuspendedInteraction() throws Exception JavaDoc {
314     _log.log("Shutting down debugger in " + this + " without waiting");
315     _model.getBreakpointManager().clearRegions();
316
317     // Shutdown the debugger
318
_log.log("Shutting down...");
319     synchronized(_notifierLock) {
320       _setPendingNotifies(1); // shutdown
321
_debugger.shutdown();
322       while (_pendingNotifies > 0) _notifierLock.wait();
323     }
324     _log.log("Shut down.");
325     _log.log("Completed debugger shutdown for " + this);
326   }
327
328   /** Cleanly shuts down the debugger, waiting for a suspended interaction to complete. */
329   protected void _shutdownAndWaitForInteractionEnded() throws Exception JavaDoc {
330         _log.log("Shutting down debugger in " + this + " with waiting");
331     _model.getBreakpointManager().clearRegions();
332
333     // Shutdown the debugger
334
_log.log("Shutting down...");
335     InterpretListener interpretListener = new InterpretListener() {
336        public void interpreterChanged(boolean inProgress) {
337          // Don't notify: happens in the same thread
338
interpreterChangedCount++;
339        }
340      };
341     _model.addListener(interpretListener);
342     synchronized(_notifierLock) {
343       _setPendingNotifies(2); // interactionEnded, shutdown
344
_debugger.shutdown();
345       while (_pendingNotifies > 0) _notifierLock.wait();
346     }
347     interpretListener.assertInteractionEndCount(1);
348     interpretListener.assertInterpreterChangedCount(1); // fires (don't wait)
349
_model.removeListener(interpretListener);
350
351     _log.log("Shut down.");
352     _log.log("Completed debugger shutdown for " + this);
353   }
354
355   /** Sets the current debugger thread to the specified thread t.*/
356   protected void _doSetCurrentThread(final DebugThreadData t) throws DebugException {
357     _debugger.setCurrentThread(t);
358   }
359
360   /** Resumes the debugger asynchronously so as to avoid getting notified before we start waiting for notifies. */
361   protected void _asyncStep(final int whatKind) {
362     new Thread JavaDoc("asyncStep Thread") {
363       public void run() {
364         try { _debugger.step(whatKind); }
365         catch(DebugException dbe) {
366           dbe.printStackTrace();
367           listenerFail("Debugger couldn't be resumed!\n" + dbe);
368         }
369       }
370     }.start();
371   }
372
373   /**
374    * Resumes the debugger asynchronously so as to aovid
375    * getting notified before we start waiting for notifies
376    */

377   protected void _asyncResume() {
378     new Thread JavaDoc("asyncResume Thread") {
379       public void run() {
380         try { _debugger.resume(); }
381         catch(DebugException dbe) {
382           dbe.printStackTrace();
383           listenerFail("Debugger couldn't be resumed!\n" + dbe);
384         }
385       }
386     }.start();
387   }
388
389   /** Sets the current thread in a new thread to avoid being notified of events before we start waiting for them. */
390   protected void _asyncDoSetCurrentThread(final DebugThreadData th) {
391     new Thread JavaDoc("asyncDoSetCurrentThread Thread") {
392       public void run() {
393         try { _doSetCurrentThread(th); }
394         catch (DebugException dbe) {
395           dbe.printStackTrace();
396           listenerFail("Couldn't set current thread in _asyncDoSetCurrentThread\n" + dbe);
397         }
398       }
399     }.start();
400   }
401
402   /** Listens to events from the debugger to ensure that they happen at the correct times. */
403   protected class DebugTestListener implements DebugListener {
404     protected volatile int debuggerStartedCount = 0;
405     protected volatile int debuggerShutdownCount = 0;
406     protected volatile int threadLocationUpdatedCount = 0;
407     protected volatile int breakpointReachedCount = 0;
408     protected volatile int regionAddedCount = 0;
409     protected volatile int regionChangedCount = 0;
410     protected volatile int regionRemovedCount = 0;
411     protected volatile int watchSetCount = 0;
412     protected volatile int watchRemovedCount = 0;
413     protected volatile int stepRequestedCount = 0;
414     protected volatile int currThreadSuspendedCount = 0;
415     protected volatile int currThreadResumedCount = 0;
416     protected volatile int threadStartedCount = 0;
417     protected volatile int currThreadDiedCount = 0;
418     protected volatile int currThreadSetCount = 0;
419     protected volatile int nonCurrThreadDiedCount = 0;
420
421     public void assertDebuggerStartedCount(int i) {
422       assertEquals("number of times debuggerStarted fired", i, debuggerStartedCount);
423     }
424
425     public void assertDebuggerShutdownCount(int i) {
426       assertEquals("number of times debuggerShutdown fired", i, debuggerShutdownCount);
427     }
428
429     public void assertThreadLocationUpdatedCount(int i) {
430       assertEquals("number of times threadLocationUpdated fired", i, threadLocationUpdatedCount);
431     }
432
433     public void assertBreakpointReachedCount(int i) {
434       assertEquals("number of times breakpointReached fired", i, breakpointReachedCount);
435     }
436
437     public void assertRegionAddedCount(int i) {
438       assertEquals("number of times regionAdded fired", i, regionAddedCount);
439     }
440
441     public void assertRegionChangedCount(int i) {
442       assertEquals("number of times regionChanged fired", i, regionChangedCount);
443     }
444
445     public void assertRegionRemovedCount(int i) {
446       assertEquals("number of times regionRemoved fired", i, regionRemovedCount);
447     }
448
449     public void assertWatchSetCount(int i) {
450       assertEquals("number of times watchSet fired", i, watchSetCount);
451     }
452
453     public void assertWatchRemovedCount(int i) {
454       assertEquals("number of times watchRemoved fired", i, watchRemovedCount);
455     }
456
457     public void assertStepRequestedCount(int i) {
458       assertEquals("number of times stepRequested fired", i, stepRequestedCount);
459     }
460
461     public void assertStepFinishedCount(int i) {
462       assertEquals("number of times stepRequested fired", i, stepRequestedCount);
463     }
464
465     public void assertCurrThreadSuspendedCount(int i) {
466       assertEquals("number of times currThreadSuspended fired", i, currThreadSuspendedCount);
467     }
468
469     public void assertCurrThreadResumedCount(int i) {
470       assertEquals("number of times currThreadResumed fired", i, currThreadResumedCount);
471     }
472
473     public void assertCurrThreadSetCount(int i) {
474       assertEquals("number of times currThreadSet fired", i, currThreadSetCount);
475     }
476
477     public void assertThreadStartedCount(int i) {
478       assertEquals("number of times threadStarted fired", i,threadStartedCount);
479     }
480
481     public void assertCurrThreadDiedCount(int i) {
482       assertEquals("number of times currThreadDied fired", i, currThreadDiedCount);
483     }
484
485     public void assertNonCurrThreadDiedCount(int i) {
486       assertEquals("number of times nonCurrThreadDied fired", i, nonCurrThreadDiedCount);
487     }
488
489
490     public void debuggerStarted() { fail("debuggerStarted fired unexpectedly"); }
491
492     public void debuggerShutdown() { fail("debuggerShutdown fired unexpectedly"); }
493
494     public void threadLocationUpdated(OpenDefinitionsDocument doc, int lineNumber, boolean shouldHighlight) {
495       fail("threadLocationUpdated fired unexpectedly");
496     }
497
498     public void breakpointReached(Breakpoint bp) { fail("breakpointReached fired unexpectedly"); }
499
500     public void regionAdded(Breakpoint bp, int index) { fail("regionAdded fired unexpectedly"); }
501
502     public void regionChanged(Breakpoint bp, int index) { fail("regionChanged fired unexpectedly"); }
503
504     public void regionRemoved(Breakpoint bp) { fail("regionRemoved fired unexpectedly"); }
505
506     public void watchSet(DebugWatchData w) { fail("watchSet fired unexpectedly"); }
507
508     public void watchRemoved(DebugWatchData w) { fail("watchRemoved fired unexpectedly"); }
509
510     public void stepRequested() { fail("stepRequested fired unexpectedly"); }
511
512     public void currThreadSuspended() { fail("currThreadSuspended fired unexpectedly"); }
513
514     public void currThreadResumed() { fail("currThreadResumed fired unexpectedly"); }
515
516     public void currThreadSet(DebugThreadData dtd) { fail("currThreadSet fired unexpectedly"); }
517
518     /** This won't fail because threads could be starting at any time. We have to expect this to be fired. */
519     public void threadStarted() { threadStartedCount++; }
520
521     public void currThreadDied() { fail("currThreadDied fired unexpectedly"); }
522
523     /** This won't fail because threads could be dying at any time. We have to expect this to be fired. */
524     public void nonCurrThreadDied() { nonCurrThreadDiedCount++; }
525   }
526
527   /** DebugTestListener for all tests starting the debugger. */
528   protected class DebugStartAndStopListener extends DebugTestListener {
529     public void debuggerStarted() {
530       // EventHandler's thread: test should wait
531
synchronized(_notifierLock) {
532         debuggerStartedCount++;
533         _log.log("debuggerStarted " + debuggerStartedCount);
534         _notifyLock();
535       }
536     }
537     public void debuggerShutdown() {
538       // EventHandler's thread: test should wait
539
synchronized(_notifierLock) {
540         debuggerShutdownCount++;
541         _log.log("debuggerShutdown " + debuggerShutdownCount);
542         _notifyLock();
543       }
544     }
545   }
546
547   /** DebugTestListener for all tests setting breakpoints. */
548   protected class BreakpointTestListener extends DebugStartAndStopListener {
549     public BreakpointTestListener() { }
550     public void breakpointReached(Breakpoint bp) {
551       // EventHandler's thread: test should wait
552
synchronized(_notifierLock) {
553         breakpointReachedCount++;
554         _log.log("breakpointReached " + breakpointReachedCount);
555         _notifyLock();
556       }
557     }
558     public void regionAdded(Breakpoint bp, int index) {
559       // Manager's thread: test shouldn't wait
560
regionAddedCount++;
561     }
562     public void regionRemoved(Breakpoint bp) {
563       // Manager's thread: test shouldn't wait
564
regionRemovedCount++;
565       _log.log("regionRemoved " + regionRemovedCount);
566     }
567
568     public void currThreadSuspended() {
569       // EventHandler's thread: test should wait
570
synchronized(_notifierLock) {
571         currThreadSuspendedCount++;
572         _log.log("threadSuspended " + currThreadSuspendedCount);
573         _notifyLock();
574       }
575     }
576     public void currThreadResumed() {
577       // Manager's thread: test shouldn't wait
578
currThreadResumedCount++;
579       _log.log("threadResumed " + currThreadResumedCount);
580     }
581     public void currThreadSet(DebugThreadData dtd) {
582       // Manager's thread: test shouldn't wait
583
currThreadSetCount++;
584       _log.log("threadSet " + currThreadSetCount);
585     }
586     public void currThreadDied() {
587       // EventHandler's thread: test should wait
588
synchronized(_notifierLock) {
589         currThreadDiedCount++;
590         _log.log("currThreadDied " + currThreadDiedCount);
591         _notifyLock();
592       }
593     }
594     public void threadLocationUpdated(OpenDefinitionsDocument doc, int lineNumber, boolean shouldHighlight) {
595       // EventHandler's thread: test should wait
596
synchronized(_notifierLock) {
597         threadLocationUpdatedCount++;
598         _log.log("threadUpdated " + threadLocationUpdatedCount);
599         _notifyLock();
600       }
601     }
602     public void watchSet(DebugWatchData w) {
603       // Manager's thread: test shouldn't wait
604
watchSetCount++;
605       _log.log("watchSet " + watchSetCount);
606     }
607     public void watchRemoved(DebugWatchData w) {
608       // Manager's thread: test shouldn't wait
609
watchRemovedCount++;
610       _log.log("watchRemoved " + watchRemovedCount);
611     }
612   }
613
614   /** DebugTestListener for all tests using the stepper. */
615   protected class StepTestListener extends BreakpointTestListener {
616     public void stepRequested() {
617       // Manager's thread: test shouldn't wait
618
stepRequestedCount++;
619       _log.log("stepRequested " + stepRequestedCount);
620     }
621   }
622
623   /** TestListener that listens for an interpretation to end, and then notifies anyone waiting on it.
624    * (Necessary to prevent tests from overlapping.) */

625   protected class InterpretListener extends TestListener {
626     public void interactionStarted() {
627       synchronized(_notifierLock) {
628         interactionStartCount++;
629         _log.log("interactionStarted " + interactionStartCount);
630         _notifyLock();
631       }
632     }
633     public void interactionEnded() {
634       synchronized(_notifierLock) {
635         interactionEndCount++;
636         _log.log("interactionEnded " + interactionEndCount);
637         _notifyLock();
638       }
639     }
640
641     public void interpreterChanged(boolean inProgress) {
642       synchronized(_notifierLock) {
643         interpreterChangedCount++;
644         _log.log("interpreterChanged " + interpreterChangedCount);
645         _notifyLock();
646       }
647     }
648   }
649 }
Popular Tags