001: /*BEGIN_COPYRIGHT_BLOCK
002: *
003: * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are met:
008: * * Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: * * Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
014: * names of its contributors may be used to endorse or promote products
015: * derived from this software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
021: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
023: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: *
029: * This software is Open Source Initiative approved Open Source Software.
030: * Open Source Initative Approved is a trademark of the Open Source Initiative.
031: *
032: * This file is part of DrJava. Download the current version of this project
033: * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
034: *
035: * END_COPYRIGHT_BLOCK*/
036:
037: package edu.rice.cs.drjava.model;
038:
039: import java.io.*;
040: import javax.swing.text.BadLocationException;
041: import javax.swing.event.*;
042: import java.util.Vector;
043: import java.util.Iterator;
044:
045: import edu.rice.cs.drjava.DrJava;
046: import edu.rice.cs.drjava.config.*;
047: import edu.rice.cs.drjava.model.repl.*;
048: import edu.rice.cs.util.Log;
049: import edu.rice.cs.util.UnexpectedException;
050: import edu.rice.cs.util.text.EditDocumentException;
051: import edu.rice.cs.util.swing.Utilities;
052: import edu.rice.cs.plt.iter.IterUtil;
053:
054: /** A test on the GlobalModel that does deals with everything outside of simple file operations, e.g., compile, quit.
055: * @version $Id: GlobalModelOtherTest.java 4255 2007-08-28 19:17:37Z mgricken $
056: */
057: public final class GlobalModelOtherTest extends GlobalModelTestCase
058: implements OptionConstants {
059:
060: // _log can be inherited from GlobalModelTestCase
061: Log _log = new Log("GlobalModelOtherTest.txt", false);
062:
063: private static final String FOO_CLASS = "package bar;\n"
064: + "public class Foo {\n"
065: + " public static void main(String[] args) {\n"
066: + " System.out.println(\"Foo\");\n" + " }\n" + "}\n";
067:
068: /** Get the canonical name of a file. If the operation fails, the test will fail. */
069: private File makeCanonical(File f) {
070: try {
071: return f.getCanonicalFile();
072: } catch (IOException e) {
073: fail("Can't get a canonical path for file " + f);
074: return null;
075: }
076: }
077:
078: /** Tests that the undoableEditHappened event is fired if the undo manager is in use. */
079: public void testUndoEventsOccur() throws BadLocationException {
080: final OpenDefinitionsDocument doc = _model.newFile();
081:
082: // Have to add an undoable edit listener for Undo to work
083: doc.addUndoableEditListener(new UndoableEditListener() {
084: public void undoableEditHappened(UndoableEditEvent e) {
085: doc.getUndoManager().addEdit(e.getEdit());
086: }
087: });
088:
089: TestListener listener = new TestListener() {
090: public void undoableEditHappened() {
091: undoableEditCount++;
092: }
093: };
094:
095: _model.addListener(listener);
096: changeDocumentText("test", doc);
097:
098: Utilities.clearEventQueue();
099: _model.removeListener(listener);
100: listener.assertUndoableEditCount(1);
101: // Utilities.showDebug("testUndoEvents finished");
102:
103: // _log.log("testUndoEventsOccur() completed");
104: }
105:
106: /** Checks that System.exit is handled appropriately from interactions pane. */
107: public void testExitInteractions() throws EditDocumentException,
108: InterruptedException {
109: InteractionListener listener = new InteractionListener() {
110:
111: // public void consoleReset() { consoleResetCount++; }
112: };
113:
114: _model.addListener(listener);
115:
116: listener.logInteractionStart();
117: interpretIgnoreResult("System.exit(23);");
118: listener.waitInteractionDone();
119: listener.waitResetDone();
120: Utilities.clearEventQueue();
121:
122: _model.removeListener(listener);
123:
124: // listener.assertConsoleResetCount(0);
125: listener.assertInteractionStartCount(1);
126: listener.assertInterpreterResettingCount(1);
127: listener.assertInterpreterReadyCount(1);
128: listener.assertInterpreterExitedCount(1);
129: assertEquals("exit status", 23, listener.getLastExitStatus());
130:
131: _log.log("testExitInteractions() completed");
132: }
133:
134: /** Checks that the interpreter can be aborted and then work correctly later. Part of what we check here is that
135: * the interactions classpath is correctly reset after aborting interactions. That is, we ensure that the compiled
136: * class is still visible after aborting. This was broken in drjava-20020108-0958 -- or so I thought. I can't
137: * consistently reproduce the problem in the UI (seems to show up using IBM's JDK only), and I can never reproduce
138: * it in the test case. Grr. <p> OK, now I found the explanation: We were in some cases running two new JVMs
139: * on an abort. I fixed the problem in MainJVM#restartInterpreterJVM
140: *
141: * The above method no longer exists... Does anyone remember what this meant? -nrh
142: */
143: public void testInteractionAbort() throws BadLocationException,
144: EditDocumentException, InterruptedException, IOException {
145:
146: doCompile(setupDocument(FOO_TEXT), tempFile());
147:
148: Utilities.clearEventQueue();
149:
150: final String beforeAbort = interpret("DrJavaTestFoo.class.getName()"); /* interpret("17"); */
151:
152: _log.log("Completed initial interpret call");
153:
154: assertEquals("\"DrJavaTestFoo\"", beforeAbort);
155:
156: Utilities.clearEventQueue();
157:
158: InteractionListener listener = new InteractionListener();
159:
160: _model.addListener(listener);
161: listener.logInteractionStart();
162: _log.log("Starting infinite loop");
163: interpretIgnoreResult("while (true) {}");
164: Utilities.clearEventQueue();
165:
166: listener.assertInteractionStartCount(1);
167:
168: _log.log("Resetting interactions");
169: _model.resetInteractions(FileOption.NULL_FILE);
170: listener.waitResetDone();
171:
172: Utilities.clearEventQueue();
173:
174: listener.assertInterpreterResettingCount(1);
175: listener.assertInterpreterReadyCount(1);
176: listener.assertInterpreterExitedCount(0);
177: listener.assertConsoleResetCount(0);
178:
179: // now make sure it still works!
180: assertEquals("5", interpret("5"));
181: _model.removeListener(listener);
182:
183: // make sure we can still see class foo
184: final String afterAbort = interpret("DrJavaTestFoo.class.getName()");
185: Utilities.clearEventQueue();
186: assertEquals("\"DrJavaTestFoo\"", afterAbort);
187: _log.log("testInteractionAbort() completed");
188: }
189:
190: /** Checks that reset console works. */
191: public void testResetConsole() throws EditDocumentException,
192: InterruptedException {
193: //System.err.println("Entering testResetConsole");
194: InteractionListener listener = new InteractionListener();
195:
196: _model.addListener(listener);
197:
198: listener.logInteractionStart();
199:
200: _model.resetConsole();
201: Utilities.clearEventQueue();
202:
203: assertEquals("Length of console text", 0, _model
204: .getConsoleDocument().getLength());
205:
206: listener.assertConsoleResetCount(1);
207:
208: listener.logInteractionStart(); // only resets the interactionDone and resetDone flags
209: listener.resetConsoleResetCount(); // resets the resetConsoleCount in the listener
210:
211: interpretIgnoreResult("System.out.print(\"a\");");
212: listener.waitInteractionDone();
213:
214: Utilities.clearEventQueue();
215:
216: assertEquals("Length of console text", 1, _model
217: .getConsoleDocument().getLength());
218:
219: _model.resetConsole();
220:
221: Utilities.clearEventQueue();
222: assertEquals("Length of console text", 0, _model
223: .getConsoleDocument().getLength());
224:
225: listener.assertConsoleResetCount(1);
226: _log.log("testResetConsole() completed");
227: }
228:
229: /** Creates a new class, compiles it and then checks that the REPL can see it. Then checks that a compiled class
230: * file in another directory can be both accessed and extended if it is on the "extra.classpath" config option.
231: */
232: public void testInteractionsCanSeeCompiledClasses()
233: throws BadLocationException, EditDocumentException,
234: IOException, InterruptedException {
235: // Compile Foo
236: OpenDefinitionsDocument doc1 = setupDocument(FOO_TEXT);
237: File dir1 = makeCanonical(new File(_tempDir, "dir1"));
238: dir1.mkdir();
239: File file1 = makeCanonical(new File(dir1, "TestFile1.java"));
240: doCompile(doc1, file1);
241:
242: assertEquals("interactions result", "\"DrJavaTestFoo\"",
243: interpret("new DrJavaTestFoo().getClass().getName()"));
244:
245: // Add directory 1 to extra classpath and close doc1
246: Vector<File> cp = new Vector<File>();
247: cp.add(dir1);
248: DrJava.getConfig().setSetting(EXTRA_CLASSPATH, cp);
249:
250: Utilities.clearEventQueue();
251: _model.closeFile(doc1);
252:
253: // Compile Baz which extends Foo in another directory.
254: OpenDefinitionsDocument doc2 = setupDocument(BAZ_TEXT);
255: File dir2 = makeCanonical(new File(_tempDir, "dir2"));
256: dir2.mkdir();
257: File file2 = makeCanonical(new File(dir2, "TestFile1.java"));
258: doCompile(doc2, file2);
259:
260: // Ensure that Baz can use the Foo class from extra classpath
261: assertEquals("interactions result", "\"DrJavaTestBaz\"",
262: interpret("new DrJavaTestBaz().getClass().getName()"));
263:
264: // Ensure that static fields can be seen
265: assertEquals("result of static field", "3",
266: interpret("DrJavaTestBaz.x"));
267:
268: // Also ensure that Foo can be used directly
269: assertEquals("interactions result", "\"DrJavaTestFoo\"",
270: interpret("new DrJavaTestFoo().getClass().getName()"));
271:
272: _log.log("testInteractionsCanSeeCompletedClasses() completed");
273: }
274:
275: /** Compiles a new class in the default package with a mixed case name, and ensures that it can be instantiated on a
276: * variable with an identical name (but a lowercase first letter). Catches SF bug #689026 ("DynamicJava can't handle
277: * certain variable names")
278: */
279: public void testInteractionsVariableWithLowercaseClassName()
280: throws BadLocationException, EditDocumentException,
281: IOException, InterruptedException {
282: // Compile a test file
283: OpenDefinitionsDocument doc1 = setupDocument("public class DrJavaTestClass {}");
284: File file1 = makeCanonical(new File(_tempDir,
285: "DrJavaTestClass.java"));
286: doCompile(doc1, file1);
287:
288: // This shouldn't cause an error (no output should be displayed)
289: assertEquals("interactions result", "",
290: interpret("drJavaTestClass = new DrJavaTestClass();"));
291: _log
292: .log("testInteractionsVariableWithLowercaseClassName() completed");
293: }
294:
295: /** Checks that updating a class and recompiling it is visible from the REPL. */
296: public void testInteractionsCanSeeChangedClass()
297: throws BadLocationException, EditDocumentException,
298: IOException, InterruptedException {
299: final String text_before = "class DrJavaTestFoo { public int m() { return ";
300: final String text_after = "; } }";
301: final int num_iterations = 3;
302: File file;
303: OpenDefinitionsDocument doc;
304:
305: for (int i = 0; i < num_iterations; i++) {
306: doc = setupDocument(text_before + i + text_after);
307: file = tempFile(i);
308: doCompile(doc, file);
309:
310: assertEquals("interactions result, i=" + i, String
311: .valueOf(i), interpret("new DrJavaTestFoo().m()"));
312: }
313: _log.log("testInteractionsCanSeeChangedClass() completed");
314: }
315:
316: /** Checks that an anonymous inner class can be defined in the repl! */
317: public void testInteractionsDefineAnonymousInnerClass()
318: throws BadLocationException, EditDocumentException,
319: IOException, InterruptedException {
320: final String interface_text = "public interface I { int getValue(); }";
321: final File file = createFile("I.java");
322:
323: OpenDefinitionsDocument doc;
324:
325: doc = setupDocument(interface_text);
326: doCompile(doc, file);
327:
328: for (int i = 0; i < 3; i++) {
329: String s = "new I() { public int getValue() { return " + i
330: + "; } }.getValue()";
331:
332: assertEquals("interactions result, i=" + i, String
333: .valueOf(i), interpret(s));
334: }
335: _log
336: .log("testInteractionsDefineAnonymousInnerClass() completed");
337: }
338:
339: public void testGetSourceRootDefaultPackage()
340: throws BadLocationException, IOException {
341:
342: // Get source root (current directory only)
343: Iterable<File> roots = _model.getSourceRootSet();
344: assertEquals("number of source roots", 0, IterUtil
345: .sizeOf(roots));
346:
347: // Create temp directory
348: File baseTempDir = tempDirectory();
349:
350: // Now make subdirectory a/b/c
351: File subdir = makeCanonical(new File(baseTempDir, "a"));
352: subdir = makeCanonical(new File(subdir, "b"));
353: subdir = makeCanonical(new File(subdir, "c"));
354: subdir.mkdirs();
355:
356: // Save the footext to DrJavaTestFoo.java in the subdirectory
357: File fooFile = makeCanonical(new File(subdir,
358: "DrJavaTestFoo.java"));
359: OpenDefinitionsDocument doc = setupDocument(FOO_TEXT);
360: doc.saveFileAs(new FileSelector(fooFile));
361:
362: // No events should fire
363: _model.addListener(new TestListener());
364:
365: // Get source roots
366: roots = _model.getSourceRootSet();
367: assertEquals("number of source roots", 1, IterUtil
368: .sizeOf(roots));
369: // Get the source root for the new file in directory subdir
370: assertEquals("source root", subdir, IterUtil.first(roots));
371:
372: _log.log("testGetSourceRootDefaultPackage() completed");
373: }
374:
375: public void testGetSourceRootPackageThreeDeepValid()
376: throws BadLocationException, IOException {
377: // Create temp directory
378: File baseTempDir = tempDirectory();
379:
380: // Now make subdirectory a/b/c
381: File subdir = makeCanonical(new File(baseTempDir, "a"));
382: subdir = makeCanonical(new File(subdir, "b").getCanonicalFile());
383: subdir = makeCanonical(new File(subdir, "c").getCanonicalFile());
384: subdir.mkdirs();
385:
386: // Save the footext to DrJavaTestFoo.java in the subdirectory
387: File fooFile = makeCanonical(new File(subdir,
388: "DrJavaTestFoo.java"));
389: OpenDefinitionsDocument doc = setupDocument("package a.b.c;\n"
390: + FOO_TEXT);
391: doc.saveFileAs(new FileSelector(fooFile));
392: // System.err.println("Package name is: " + _model.getPackageName());
393:
394: // No events should fire
395: _model.addListener(new TestListener());
396:
397: // Since we had the package statement the source root should be base dir
398: Iterable<File> roots = _model.getSourceRootSet();
399: assertEquals("number of source roots", 1, IterUtil
400: .sizeOf(roots));
401: assertEquals("source root", baseTempDir.getCanonicalFile(),
402: IterUtil.first(roots).getCanonicalFile());
403:
404: _log.log("testGetSourceRootPackageThreeDeepValid() completed");
405: }
406:
407: /** Tests that getSourceRoot works with a relative path when a package name is present. */
408: public void testGetSourceRootPackageThreeDeepValidRelative()
409: throws BadLocationException, IOException {
410: // Create temp directory
411: File baseTempDir = tempDirectory();
412: File subdir = makeCanonical(new File(baseTempDir, "a"));
413: subdir = makeCanonical(new File(subdir, "b"));
414: subdir = makeCanonical(new File(subdir, "c"));
415: subdir.mkdirs();
416:
417: // Save the footext to DrJavaTestFoo.java in a relative directory
418: // temp/./a/b/../b/c == temp/a/b/c
419: File relDir = makeCanonical(new File(baseTempDir,
420: "./a/b/../b/c"));
421: File fooFile = makeCanonical(new File(relDir,
422: "DrJavaTestFoo.java"));
423: OpenDefinitionsDocument doc = setupDocument("package a.b.c;\n"
424: + FOO_TEXT);
425: doc.saveFileAs(new FileSelector(fooFile));
426:
427: // No events should fire
428: _model.addListener(new TestListener());
429:
430: // Since we had the package statement the source root should be base dir
431: Iterable<File> roots = _model.getSourceRootSet();
432: assertEquals("number of source roots", 1, IterUtil
433: .sizeOf(roots));
434: assertEquals("source root", baseTempDir.getCanonicalFile(),
435: IterUtil.first(roots).getCanonicalFile());
436:
437: _log
438: .log("testGetSourceRootPackageThreeDeepValidRelative() completed");
439: }
440:
441: public void testGetSourceRootPackageThreeDeepInvalid()
442: throws BadLocationException, IOException {
443: // Create temp directory
444: File baseTempDir = tempDirectory();
445:
446: // Now make subdirectory a/b/d
447: File subdir = makeCanonical(new File(baseTempDir, "a"));
448: subdir = makeCanonical(new File(subdir, "b"));
449: subdir = makeCanonical(new File(subdir, "d"));
450: subdir.mkdirs();
451:
452: // Save the footext to DrJavaTestFoo.java in the subdirectory
453: File fooFile = makeCanonical(new File(subdir,
454: "DrJavaTestFoo.java"));
455: OpenDefinitionsDocument doc = setupDocument("package a.b.c;\n"
456: + FOO_TEXT);
457: doc.saveFileAs(new FileSelector(fooFile));
458:
459: // No events should fire
460: _model.addListener(new TestListener());
461:
462: // The package name is wrong so this should return only currDir
463: Iterable<File> roots = _model.getSourceRootSet();
464: assertEquals("number of source roots", 0, IterUtil
465: .sizeOf(roots));
466:
467: _log
468: .log("testGetSourceRootPackageThreeDeepInvalid() completed");
469: }
470:
471: public void testGetSourceRootPackageOneDeepValid()
472: throws BadLocationException, IOException {
473: // Create temp directory
474: File baseTempDir = tempDirectory();
475:
476: // Now make subdirectory a
477: File subdir = makeCanonical(new File(baseTempDir, "a"));
478: subdir.mkdir();
479:
480: // Save the footext to DrJavaTestFoo.java in the subdirectory
481: File fooFile = makeCanonical(new File(subdir,
482: "DrJavaTestFoo.java"));
483: OpenDefinitionsDocument doc = setupDocument("package a;\n"
484: + FOO_TEXT);
485: doc.saveFileAs(new FileSelector(fooFile));
486:
487: // No events should fire
488: _model.addListener(new TestListener());
489:
490: // Since we had the package statement the source root should be base dir
491: Iterable<File> roots = _model.getSourceRootSet();
492: assertEquals("number of source roots", 1, IterUtil
493: .sizeOf(roots));
494: assertEquals("source root", baseTempDir.getCanonicalFile(),
495: IterUtil.first(roots).getCanonicalFile());
496:
497: _log.log("testGetSourceRootPackageOneDeepValid() completed");
498: }
499:
500: public void testGetMultipleSourceRootsDefaultPackage()
501: throws BadLocationException, IOException {
502: // Create temp directory
503: File baseTempDir = tempDirectory();
504:
505: // Now make subdirectories a, b
506: File subdir1 = makeCanonical(new File(baseTempDir, "a"));
507: subdir1.mkdir();
508: File subdir2 = makeCanonical(new File(baseTempDir, "b"));
509: subdir2.mkdir();
510:
511: // Save the footext to DrJavaTestFoo.java in subdirectory 1
512: File file1 = makeCanonical(new File(subdir1,
513: "DrJavaTestFoo.java"));
514: OpenDefinitionsDocument doc1 = setupDocument(FOO_TEXT);
515: doc1.saveFileAs(new FileSelector(file1));
516:
517: // Save the bartext to Bar.java in subdirectory 1
518: File file2 = makeCanonical(new File(subdir1, "Bar.java"));
519: OpenDefinitionsDocument doc2 = setupDocument(BAR_TEXT);
520: doc2.saveFileAs(new FileSelector(file2));
521:
522: // Save the bartext to Bar.java in subdirectory 2
523: File file3 = makeCanonical(new File(subdir2, "Bar.java"));
524: OpenDefinitionsDocument doc3 = setupDocument(BAR_TEXT);
525: doc3.saveFileAs(new FileSelector(file3));
526:
527: Utilities.clearEventQueue();
528:
529: // No events should fire
530: _model.addListener(new TestListener());
531:
532: // Get source roots (should be 2: no duplicates)
533: Iterable<File> roots = _model.getSourceRootSet();
534: assertEquals("number of source roots", 2, IterUtil
535: .sizeOf(roots));
536: Iterator<File> i = roots.iterator();
537: File root1 = i.next();
538: File root2 = i.next();
539:
540: // Make sure both source roots are in set
541: // But we don't care about the order
542: if (!((root1.equals(subdir1) && root2.equals(subdir2)) || (root1
543: .equals(subdir2) && root2.equals(subdir1)))) {
544: fail("source roots did not match");
545: }
546:
547: _log
548: .log("testGetMultipleSourceRootsDefaultPackage() completed");
549: }
550:
551: /** Creates a new class, compiles it and then checks that the REPL can see it. */
552: public void testInteractionsLiveUpdateClassPath()
553: throws BadLocationException, EditDocumentException,
554: IOException, InterruptedException {
555:
556: OpenDefinitionsDocument doc = setupDocument(FOO_TEXT);
557: Utilities.clearEventQueue();
558:
559: File f = tempFile();
560:
561: doCompile(doc, f);
562:
563: // Rename the directory so it's not on the classpath anymore
564: String tempPath = f.getParent();
565: File tempDir = makeCanonical(new File(tempPath));
566: tempDir.renameTo(makeCanonical(new File(tempPath + "a")));
567:
568: String result = interpret("new DrJavaTestFoo().getClass().getName()");
569:
570: // Should cause a NoClassDefFound, but we shouldn't check exact syntax.
571: // Instead, make sure it isn't "DrJavaTestFoo", as if the class was found.
572: assertFalse(
573: "interactions should have an error, not the correct answer",
574: "\"DrJavaTestFoo\"".equals(result));
575: // System.err.println("Result1 is: " + result);
576:
577: // Add new directory to classpath through Config
578: Vector<File> cp = new Vector<File>();
579: cp.add(makeCanonical(new File(tempPath + "a")));
580: DrJava.getConfig().setSetting(EXTRA_CLASSPATH, cp);
581:
582: Utilities.clearEventQueue();
583: _model.resetInteractionsClassPath();
584:
585: result = interpret("new DrJavaTestFoo().getClass().getName()");
586:
587: // Now it should be on the classpath
588: assertEquals("interactions result", "\"DrJavaTestFoo\"", result);
589:
590: // Rename directory back to clean up
591: tempDir = makeCanonical(new File(tempPath + "a"));
592: boolean renamed = tempDir.renameTo(makeCanonical(new File(
593: tempPath)));
594:
595: _log.log("testInteractionsLiveUpdateClasspath() completed");
596: }
597:
598: /** Tests that the appropriate event is fired when the model's interpreter changes.*/
599: public void testSwitchInterpreters() {
600: TestListener listener = new TestListener() {
601: public void interpreterChanged(boolean inProgress) {
602: assertTrue("should not be in progress", !inProgress);
603: interpreterChangedCount++;
604: }
605: };
606: _model.addListener(listener);
607:
608: DefaultInteractionsModel dim = _model.getInteractionsModel();
609:
610: // Create a new Java interpreter, and set it to be active
611: dim.addJavaInterpreter("testInterpreter");
612:
613: dim.setActiveInterpreter("testInterpreter", "myPrompt>");
614:
615: Utilities.clearEventQueue();
616: listener.assertInterpreterChangedCount(1);
617: _model.removeListener(listener);
618:
619: _log.log("testSwitchInterpreters() completed");
620: }
621:
622: public void testRunMainMethod() throws Exception {
623: File dir = makeCanonical(new File(_tempDir, "bar"));
624: dir.mkdir();
625: File file = makeCanonical(new File(dir, "Foo.java"));
626: final OpenDefinitionsDocument doc = doCompile(FOO_CLASS, file);
627: Utilities.invokeAndWait(new Runnable() {
628: public void run() {
629: try {
630: doc.runMain();
631: } catch (Exception e) {
632: throw new UnexpectedException(e);
633: }
634: }
635: });
636:
637: // Utilities.clearEventQueue();
638: assertInteractionsContains(InteractionsModel.BANNER_PREFIX);
639: doc.insertString(doc.getLength(), " ", null);
640:
641: Utilities.invokeAndWait(new Runnable() {
642: public void run() {
643: try {
644: doc.runMain();
645: } catch (Exception e) {
646: throw new UnexpectedException(e);
647: }
648: }
649: });
650:
651: // Utilities.clearEventQueue();
652: assertInteractionsContains(DefaultGlobalModel.DOCUMENT_OUT_OF_SYNC_MSG);
653: Utilities.clearEventQueue();
654: // Killing time here; Slave JVM may not have released Foo.class so that the file can be deleted on Windows.
655:
656: _log.log("testRunMainMethod() completed");
657: }
658: }
|