KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > model > repl > JavaDebugInterpreterTest


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.repl;
35
36 import edu.rice.cs.drjava.model.debug.*;
37 import edu.rice.cs.drjava.model.*;
38 import edu.rice.cs.util.text.EditDocumentException;
39 import edu.rice.cs.util.swing.Utilities;
40
41 import java.util.LinkedList JavaDoc;
42 import java.io.*;
43 import javax.swing.text.*;
44
45 import koala.dynamicjava.util.*;
46 import koala.dynamicjava.tree.*;
47 import koala.dynamicjava.interpreter.context.*;
48
49 /** Class to test JavaDebugInterpreters by ensuring that appropriate events are generated on each assignment.
50  *
51  * NOTE: The tests at the bottom are disabled for now, since nothing needs to be done on an assignment. (We
52  * just copy back when the thread is resumed.)
53  *
54  * @version $Id: JavaDebugInterpreterTest.java 4031 2006-11-15 22:09:06Z rcartwright $
55  */

56 public final class JavaDebugInterpreterTest extends DebugTestCase {
57   private static final String JavaDoc _newLine = System.getProperty("line.separator");
58   private JavaDebugInterpreter _debugInterpreter;
59
60 // private String _assignedInterpreterName;
61

62   protected static final String JavaDoc MONKEY_STUFF =
63     /*1*/ "class MonkeyStuff {\n" +
64     /*2*/ " int foo = 6;\n" +
65     /*3*/ " class MonkeyInner {\n" +
66     /*4*/ " int innerFoo = 8;\n" +
67     /*5*/ " public class MonkeyTwoDeep {\n" +
68     /*6*/ " int twoDeepFoo = 13;\n" +
69     /*7*/ " class MonkeyThreeDeep {\n" +
70     /*8*/ " public int threeDeepFoo = 18;\n" +
71     /*9*/ " public void threeDeepMethod() {\n" +
72     /*10*/" int blah;\n" +
73     /*11*/" System.out.println(MonkeyStuff.MonkeyInner.MonkeyTwoDeep.MonkeyThreeDeep.this.threeDeepFoo);\n" +
74     /*12*/" }\n" +
75     /*13*/" }\n" +
76     /*14*/" int getNegativeTwo() { return -2; }\n" +
77     /*15*/" }\n" +
78     /*16*/" }\n" +
79     /*17*/"\n" +
80     /*18*/" public static void main(String[] args) {\n" +
81     /*19*/" new MonkeyStuff().new MonkeyInner().new MonkeyTwoDeep().new MonkeyThreeDeep().threeDeepMethod();\n" +
82     /*20*/" }\n" +
83     /*21*/"}";
84
85   protected static final String JavaDoc MONKEY_STATIC_STUFF =
86     /*1*/ "package monkey;\n" +
87     /*2*/ "public class MonkeyStaticStuff {\n" +
88     /*3*/ " static int foo = 6;\n" +
89     /*4*/ " static class MonkeyInner {\n" +
90     /*5*/ " static int innerFoo = 8;\n" +
91     /*6*/ " static public class MonkeyTwoDeep {\n" +
92     /*7*/ " static int twoDeepFoo = 13;\n" +
93     /*8*/ " public static class MonkeyThreeDeep {\n" +
94     /*9*/ " public static int threeDeepFoo = 18;\n" +
95     /*10*/ " public static void threeDeepMethod() {\n" +
96     /*11*/" System.out.println(MonkeyStaticStuff.MonkeyInner.MonkeyTwoDeep.MonkeyThreeDeep.threeDeepFoo);\n" +
97     /*12*/" System.out.println(MonkeyTwoDeep.twoDeepFoo);\n" +
98     /*13*/" System.out.println(twoDeepFoo);\n" +
99     /*14*/" }\n" +
100     /*15*/" }\n" +
101     /*16*/" static int getNegativeTwo() { return -2; }\n" +
102     /*17*/" }\n" +
103     /*18*/" }\n" +
104     /*19*/"}";
105
106   protected static final String JavaDoc MONKEY_WITH_INNER_CLASS =
107     /* 1 */ "class Monkey {\n" +
108     /* 2 */ " static int foo = 6; \n" +
109     /* 3 */ " class MonkeyInner { \n" +
110     /* 4 */ " int innerFoo = 8;\n" +
111     /* 5 */ " class MonkeyInnerInner { \n" +
112     /* 6 */ " int innerInnerFoo = 10;\n" +
113     /* 7 */ " public void innerMethod() { \n" +
114     /* 8 */ " int innerMethodFoo;\n" +
115     /* 9 */ " String nullString = null;\n" +
116     /* 10 */ " innerMethodFoo = 12;\n" +
117     /* 11 */ " foo++;\n" +
118     /* 12 */ " innerFoo++;\n" +
119     /* 13 */ " innerInnerFoo++;\n" +
120     /* 14 */ " innerMethodFoo++;\n" +
121     /* 15 */ " staticMethod();\n" +
122     /* 16 */ " System.out.println(\"innerMethodFoo: \" + innerMethodFoo);\n" +
123     /* 17 */ " }\n" +
124     /* 18 */ " }\n" +
125     /* 19 */ " }\n" +
126     /* 20 */ " public void bar() {\n" +
127     /* 21 */ " final MonkeyInner.MonkeyInnerInner mi = \n" +
128     /* 22 */ " new MonkeyInner().new MonkeyInnerInner();\n" +
129     /* 23 */ " mi.innerMethod();\n" +
130     /* 24 */ " final int localVar = 99;\n" +
131     /* 25 */ " new Thread() {\n" +
132     /* 26 */ " public void run() {\n" +
133     /* 27 */ " final int localVar = mi.innerInnerFoo;\n" +
134     /* 28 */ " new Thread() {\n" +
135     /* 29 */ " public void run() {\n" +
136     /* 30 */ " new Thread() {\n" +
137     /* 31 */ " public void run() {\n" +
138     /* 32 */ " System.out.println(\"localVar = \" + localVar);\n" +
139     /* 33 */ " }\n" +
140     /* 34 */ " }.run();\n" +
141     /* 35 */ " }\n" +
142     /* 36 */ " }.run();\n" +
143     /* 37 */ " }\n" +
144     /* 38 */ " }.run();\n" +
145     /* 39 */ " }\n" +
146     /* 40 */ " public static void staticMethod() {\n" +
147     /* 41 */ " int z = 3;\n" +
148     /* 42 */ " }\n" +
149     /* 43 */ "}\n";
150
151
152   public void setUp() throws Exception JavaDoc {
153     super.setUp();
154     // Creating a JavaDebugInterpreter with a custom notifyInterpreterAssignment() method
155
_debugInterpreter = new JavaDebugInterpreter("test", "") {
156       public EvaluationVisitorExtension makeEvaluationVisitor(Context context) {
157         return new DebugEvaluationVisitor(context, _name);
158 // return new DebugEvaluationVisitor(context, _name) {
159
// protected void _notifyAssigned(Expression e) {
160
// notifyInterpreterAssignment(_name);
161
// }
162
// };
163
}
164     };
165 // _assignedInterpreterName = "";
166
}
167
168   public void notifyInterpreterAssignment(String JavaDoc name) {
169 // _assignedInterpreterName = name;
170
}
171
172   public void testVerifyClassName() {
173     _debugInterpreter.setClassName("bar.baz.Foo$FooInner$FooInnerInner");
174     assertEquals("verify failed", 0, _debugInterpreter.verifyClassName("bar.baz.Foo.FooInner.FooInnerInner"));
175     assertEquals("verify failed", 1, _debugInterpreter.verifyClassName("bar.baz.Foo.FooInner"));
176     assertEquals("verify failed", 2, _debugInterpreter.verifyClassName("bar.baz.Foo"));
177     assertEquals("verify failed", -1, _debugInterpreter.verifyClassName("bar.baz"));
178     assertEquals("verify failed", 0, _debugInterpreter.verifyClassName("Foo.FooInner.FooInnerInner"));
179     assertEquals("verify failed", 2, _debugInterpreter.verifyClassName("Foo"));
180     assertEquals("verify failed", 1, _debugInterpreter.verifyClassName("FooInner"));
181     assertEquals("verify failed", 0, _debugInterpreter.verifyClassName("FooInnerInner"));
182     assertEquals("verify failed", 1, _debugInterpreter.verifyClassName("Foo.FooInner"));
183     assertEquals("verify failed", 0, _debugInterpreter.verifyClassName("FooInner.FooInnerInner"));
184     assertEquals("verify failed", -1, _debugInterpreter.verifyClassName("FooInner.FooInnerInner.Foo"));
185     assertEquals("verify failed", -1, _debugInterpreter.verifyClassName("FooInner.FooInnerInner.foo"));
186     assertEquals("verify failed", -1, _debugInterpreter.verifyClassName("o.FooInner"));
187     _debugInterpreter.setClassName("Foo$FooInner$FooInnerInner");
188     assertEquals("verify failed", 0, _debugInterpreter.verifyClassName("Foo.FooInner.FooInnerInner"));
189     assertEquals("verify failed", 2, _debugInterpreter.verifyClassName("Foo"));
190     assertEquals("verify failed", 1, _debugInterpreter.verifyClassName("FooInner"));
191     assertEquals("verify failed", 0, _debugInterpreter.verifyClassName("FooInnerInner"));
192     assertEquals("verify failed", 1, _debugInterpreter.verifyClassName("Foo.FooInner"));
193     assertEquals("verify failed", 0, _debugInterpreter.verifyClassName("FooInner.FooInnerInner"));
194     assertEquals("verify failed", -1, _debugInterpreter.verifyClassName("FooInner.FooInnerInner.Foo"));
195     assertEquals("verify failed", -1, _debugInterpreter.verifyClassName("FooInner.FooInnerInner.foo"));
196     assertEquals("verify failed", -1, _debugInterpreter.verifyClassName("o.FooInner"));
197   }
198
199   private void assertEqualsNodes(String JavaDoc message, Node expected, Node actual) {
200     ByteArrayOutputStream baos = new ByteArrayOutputStream();
201     DisplayVisitor dve = new DisplayVisitor(baos);
202     expected.acceptVisitor(dve);
203     String JavaDoc s1 = baos.toString();
204     baos.reset();
205     actual.acceptVisitor(dve);
206     String JavaDoc s2 = baos.toString();
207     //System.out.println("s1 = " + s1 + "\ns2 = " + s2);
208
assertEquals(message, s1, s2);
209   }
210
211   /** Tests that a this expression with no classname will be correctly converted to a QualifiedName. */
212   public void testConvertToName() {
213     ThisExpression thisExp = _debugInterpreter.buildUnqualifiedThis();
214     Node n = _debugInterpreter.visitThis(thisExp);
215     LinkedList JavaDoc<IdentifierToken> thisList = new LinkedList JavaDoc<IdentifierToken>(); // Add parameterization <Identifier>.
216
thisList.add(new Identifier("this"));
217     QualifiedName expected = new QualifiedName(thisList);
218     assertEqualsNodes("convertThisToName did not return the correct QualifiedName", expected, n);
219   }
220
221   /** Tests that a this expression with a classname will be correctly converted to an ObjectFieldAccess. */
222   public void testConvertToObjectFieldAccess() {
223     _debugInterpreter.setClassName("bar.baz.Foo$FooInner$FooInnerInner");
224     LinkedList JavaDoc<IdentifierToken> ids = new LinkedList JavaDoc<IdentifierToken>(); // Add parameterization <Identifier>.
225
ids.add(new Identifier("Foo"));
226     ThisExpression thisExp = new ThisExpression(ids, "", 0, 0, 0, 0);
227     Node n = _debugInterpreter.visitThis(thisExp);
228     Node expected =
229       new ObjectFieldAccess(
230         new ObjectFieldAccess(_debugInterpreter._convertThisToName(_debugInterpreter.buildUnqualifiedThis()), "this$1"),
231           "this$0");
232
233     assertEqualsNodes("convertThisToObjectFieldAccess did not return the correct ObjectFieldAccess",
234                       expected,
235                       n);
236   }
237
238   /**
239    * Tests that the user can access fields of outer classes
240    * in the debug interpreter.
241    */

242   public void testAccessFieldsAndMethodsOfOuterClasses()
243     throws DebugException, BadLocationException, EditDocumentException, IOException, InterruptedException JavaDoc {
244     File file = new File(_tempDir, "MonkeyStuff.java");
245     OpenDefinitionsDocument doc = doCompile(MONKEY_STUFF, file);
246     BreakpointTestListener debugListener = new BreakpointTestListener();
247     _debugger.addListener(debugListener);
248     // Start debugger
249
synchronized(_notifierLock) {
250       _debugger.startUp();
251       _setPendingNotifies(1); // startUp
252
while (_pendingNotifies > 0) _notifierLock.wait();
253     }
254
255     // Set one breakpoint
256
int index = MONKEY_STUFF.indexOf("System.out.println");
257     _debugger.toggleBreakpoint(doc, index, 11, true);
258
259     // Run the main() method, hitting the breakpoint
260
synchronized(_notifierLock) {
261       interpretIgnoreResult("java MonkeyStuff");
262        _setPendingNotifies(3); // suspended, updated, breakpointReached
263
while (_pendingNotifies > 0) _notifierLock.wait();
264      }
265
266     // Calling interpret instead of interpretIgnoreResult because we want to wait until the interaction has ended.
267

268     // Test that IdentityVisitor really does visit all nodes and their subnodes
269
// by giving it a statement consisting of lots of different syntax components.
270
interpret("try {\n" +
271               " for (int i = MonkeyStuff.this.foo; i < 7; i++) {\n"+
272               " do{System.out.println(MonkeyInner.this.innerFoo);}\n" +
273               " while(MonkeyStuff.MonkeyInner.this.innerFoo == MonkeyThreeDeep.this.threeDeepFoo);\n" +
274               " switch(MonkeyStuff.MonkeyInner.MonkeyTwoDeep.this.twoDeepFoo) {\n" +
275               " case 13: if (this.threeDeepFoo == 5) {\n" +
276               " System.out.println(MonkeyThreeDeep.this.threeDeepFoo);\n" +
277               " }\n" +
278               " else {\n" +
279               " MonkeyThreeDeep.this.threeDeepFoo = MonkeyThreeDeep.this.threeDeepFoo + MonkeyStuff.this.foo;\n" +
280               " }\n" +
281               " }\n" +
282               " }\n" +
283               "}\n" +
284               "catch(Exception e) { System.out.println(MonkeyThreeDeep.this.threeDeepFoo);}\n" +
285               "finally {System.out.println(MonkeyInner.MonkeyTwoDeep.this.twoDeepFoo);}");
286     assertInteractionsDoesNotMatch(".*^18$.*");
287     assertInteractionsDoesNotMatch(".*^6$.*");
288     assertInteractionsMatches(".*^8" + _newLine + "13$.*");
289     
290     // Tests that the debugger has the correct notion of
291
interpret("foo");
292     
293 // System.err.println(getInteractionsText());
294

295     assertInteractionsMatches(".*^6$.*");
296     
297     interpret("foo = 123");
298     assertEquals("foo should have been modified" , "123", interpret("MonkeyStuff.this.foo"));
299     interpret("int foo = 999;");
300     assertEquals("foo should refer to defined foo", "999", interpret("foo"));
301     assertEquals("declaring foo should not change MonkeyStuff.this.foo", "123", interpret("MonkeyStuff.this.foo"));
302
303     assertEquals("call method of outer class #1", "-2", interpret("getNegativeTwo()"));
304     assertEquals("call method of outer class #2", "-2", interpret("MonkeyTwoDeep.this.getNegativeTwo()"));
305     assertEquals("call method of outer class #3", "-2",
306                  interpret("MonkeyInner.MonkeyTwoDeep.this.getNegativeTwo()"));
307     assertEquals("call method of outer class #4", "-2",
308                  interpret("MonkeyStuff.MonkeyInner.MonkeyTwoDeep.this.getNegativeTwo()"));
309
310     // Close doc and make sure breakpoints are removed
311
_model.closeFile(doc);
312     
313     Utilities.clearEventQueue();
314     debugListener.assertRegionRemovedCount(1); //fires once
315

316     // Shutdown the debugger
317
_log.log("Shutting down...");
318     synchronized(_notifierLock) {
319       _debugger.shutdown();
320       _setPendingNotifies(1); // shutdown
321
while (_pendingNotifies > 0) _notifierLock.wait();
322     }
323
324     debugListener.assertDebuggerShutdownCount(1); //fires
325
_log.log("Shut down.");
326     _debugger.removeListener(debugListener);
327   }
328
329   /** Tests that the user can access static fields of outer classes in the debug interpreter. */
330   public void testAccessStaticFieldsAndMethodsOfOuterClasses()
331     throws DebugException, BadLocationException, EditDocumentException, IOException, InterruptedException JavaDoc {
332     File dir = new File(_tempDir, "monkey");
333     dir.mkdir();
334     File file = new File(dir, "MonkeyStaticStuff.java");
335     OpenDefinitionsDocument doc = doCompile(MONKEY_STATIC_STUFF, file);
336     BreakpointTestListener debugListener = new BreakpointTestListener();
337     _debugger.addListener(debugListener);
338     // Start debugger
339
synchronized(_notifierLock) {
340       _debugger.startUp();
341       _setPendingNotifies(1); // startUp
342
while (_pendingNotifies > 0) _notifierLock.wait();
343     }
344
345     // Set one breakpoint
346
int index = MONKEY_STATIC_STUFF.indexOf("System.out.println");
347     _debugger.toggleBreakpoint(doc,index,11,true);
348
349     // Run the main() method, hitting both breakpoints in different threads
350
synchronized(_notifierLock) {
351       //interpret("package monkey;");
352
interpretIgnoreResult("monkey.MonkeyStaticStuff.MonkeyInner.MonkeyTwoDeep.MonkeyThreeDeep.threeDeepMethod();");
353       _setPendingNotifies(3); // suspended, updated, breakpointReached
354
while (_pendingNotifies > 0) _notifierLock.wait();
355     }
356
357     assertEquals("should find field of static outer class",
358                  "13",
359                  interpret("twoDeepFoo"));
360     assertEquals("should find field of static outer class",
361                  "13",
362                  interpret("MonkeyInner.MonkeyTwoDeep.twoDeepFoo"));
363
364     interpret("twoDeepFoo = 100;");
365     assertEquals("should have assigned field of static outer class",
366                  "100",
367                  interpret("twoDeepFoo"));
368     assertEquals("should have assigned the field of static outer class",
369                  "100",
370                  interpret("MonkeyStaticStuff.MonkeyInner.MonkeyTwoDeep.twoDeepFoo"));
371     assertEquals("should have assigned the field of static outer class",
372                  "100",
373                  interpret("monkey.MonkeyStaticStuff.MonkeyInner.MonkeyTwoDeep.twoDeepFoo"));
374
375     interpret("int twoDeepFoo = -10;");
376     assertEquals("Should have successfully shadowed field of static outer class", "-10", interpret("twoDeepFoo"));
377     
378     assertEquals("should have assigned the field of static outer class", "100",
379                  interpret("MonkeyTwoDeep.twoDeepFoo"));
380     
381     assertEquals("should have assigned the field of static outer class", "100",
382                  interpret("MonkeyStaticStuff.MonkeyInner.MonkeyTwoDeep.twoDeepFoo"));
383
384     assertEquals("Should be able to access a static field of a non-static outer class", "6", interpret("foo"));
385     assertEquals("Should be able to access a static field of a non-static outer class", "6",
386                  interpret("MonkeyStaticStuff.foo"));
387
388     interpret("foo = 987;");
389     assertEquals("Should have changed the value of a static field of a non-static outer class", "987",
390                  interpret("foo"));
391     
392     assertEquals("Should have changed the value of a static field of a non-static outer class", "987",
393                  interpret("MonkeyStaticStuff.foo"));
394
395     interpret("int foo = 56;");
396     assertEquals("Should have defined a new variable", "56", interpret("foo"));
397     assertEquals("Should have shadowed the value of a static field of a non-static outer class", "987",
398                  interpret("MonkeyStaticStuff.foo"));
399
400     assertEquals("should be able to call method of outer class", "-2", interpret("getNegativeTwo()"));
401     assertEquals("should be able to call method of outer class", "-2", interpret("MonkeyTwoDeep.getNegativeTwo()"));
402     assertEquals("should be able to call method of outer class", "-2",
403                  interpret("MonkeyInner.MonkeyTwoDeep.getNegativeTwo()"));
404     assertEquals("should be able to call method of outer class", "-2",
405                  interpret("MonkeyStaticStuff.MonkeyInner.MonkeyTwoDeep.getNegativeTwo()"));
406
407     // Shutdown the debugger
408
_log.log("Shutting down...");
409
410     synchronized(_notifierLock) {
411       _debugger.shutdown();
412       _setPendingNotifies(1); // shutdown
413
while (_pendingNotifies > 0) _notifierLock.wait();
414     }
415
416     debugListener.assertDebuggerShutdownCount(1); //fires
417
_log.log("Shut down.");
418
419     _debugger.removeListener(debugListener);
420   }
421
422   public void testAccessNullFieldsAndFinalLocalVariables()
423     throws DebugException, BadLocationException, EditDocumentException, IOException, InterruptedException JavaDoc {
424     File file = new File(_tempDir, "Monkey.java");
425     OpenDefinitionsDocument doc = doCompile(MONKEY_WITH_INNER_CLASS, file);
426     BreakpointTestListener debugListener = new BreakpointTestListener();
427     _debugger.addListener(debugListener);
428     // Start debugger
429
synchronized(_notifierLock) {
430       _debugger.startUp();
431       _setPendingNotifies(1); // startUp
432
while (_pendingNotifies > 0) _notifierLock.wait();
433     }
434
435     // Set one breakpoint
436
int index = MONKEY_WITH_INNER_CLASS.indexOf("innerMethodFoo = 12;");
437     _debugger.toggleBreakpoint(doc,index,10,true);
438     index = MONKEY_WITH_INNER_CLASS.indexOf("System.out.println(\"localVar = \" + localVar);");
439     _debugger.toggleBreakpoint(doc,index,32,true);
440
441     // Run the main() method, hitting both breakpoints in different threads
442
synchronized(_notifierLock) {
443       interpretIgnoreResult("new Monkey().bar()");
444        _setPendingNotifies(3); // suspended, updated, breakpointReached
445
while (_pendingNotifies > 0) _notifierLock.wait();
446      }
447
448     // Test accessing a field initialized to null
449
assertEquals("nullString should be null", "null", interpret("nullString"));
450     interpret("nullString = new Integer(3)");
451     assertInteractionsContains("Error: Bad types in assignment");
452     assertEquals("nullString should still be null", "null", interpret("nullString"));
453     assertEquals("Should be able to assign a string to nullString", "\"asdf\"", interpret("nullString = \"asdf\""));
454     assertEquals("Should equal \"asdf\"", "true", interpret("nullString.equals(\"asdf\")"));
455
456     // Resumes this thread, switching to the next break point
457
synchronized(_notifierLock) {
458       _asyncResume();
459       _setPendingNotifies(3); // breakpointReached, suspended, updated
460
while (_pendingNotifies > 0) _notifierLock.wait();
461     }
462     // Test accessing final local variables
463
assertEquals("Should be able to access localVar", "11", interpret("localVar"));
464     interpret("localVar = 5");
465     /* The Following test is commented out TEMPORARILY to work around bug in JDK 1.5 Beta2 JVM */
466     /* Update (10/12/2005): The test still fails under a current JDK 1.5 JVM. I'm not sure it's the JDK's fault */
467     // assertEquals("The value of localVar should not have changed", "11", interpret("localVar"));
468

469     // Shutdown the debugger
470
_log.log(this + " is Shutting Down...");
471     synchronized(_notifierLock) {
472       _debugger.shutdown();
473       _setPendingNotifies(1); // shutdown
474
while (_pendingNotifies > 0) _notifierLock.wait();
475     }
476
477     debugListener.assertDebuggerShutdownCount(1); //fires
478
_log.log(this + " is Shutting Down.");
479     _debugger.removeListener(debugListener);
480   }
481
482   /**
483    * Disabled...
484    *
485   public void testNoAssignment() throws ExceptionReturnedException {
486
487     // 1
488     _debugInterpreter.interpret("1 + 1");
489     assertEquals("Should not have made an assignment.", "", _assignedInterpreterName);
490
491     // 2
492     _debugInterpreter.interpret("public void foo() {}; foo()");
493     assertEquals("Should not have made an assignment.", "", _assignedInterpreterName);
494
495     // 3
496     _debugInterpreter.interpret("int x");
497     assertEquals("Should not have made an assignment.", "", _assignedInterpreterName);
498
499   }*/

500
501   /**
502    * Disabled...
503    *
504   public void testWithAssignment() throws ExceptionReturnedException {
505     // 1
506     _debugInterpreter.interpret("x = 0");
507     assertEquals("Should have made an assignment.", "test", _assignedInterpreterName);
508     _assignedInterpreterName = "";
509
510     // 2
511     _debugInterpreter.interpret("y = null");
512     assertEquals("Should have made an assignment.", "test", _assignedInterpreterName);
513     _assignedInterpreterName = "";
514
515     // 3
516     _debugInterpreter.interpret("int z; z = 2");
517     assertEquals("Should have made an assignment.", "test", _assignedInterpreterName);
518     _assignedInterpreterName = "";
519   } */

520 }
521
Popular Tags