Ejemplo n.º 1
0
  /**
   * A Test to guarantee that the Dancing UI bug will not rear its ugly head again. Basically, add a
   * component listener to the leftComponent of _docSplitPane and make certain its size does not
   * change while closing an OpenDefinitionsDocument outside the event thread.
   */
  public void testDancingUIFileClosed() throws IOException {
    /**
     * Maybe this sequence of calls should be incorporated into one function createTestDir(), which
     * would get the username and create the temporary directory. Only sticky part is deciding where
     * to put it, in FileOps maybe?
     */
    String user = System.getProperty("user.name");
    _tempDir = IOUtil.createAndMarkTempDirectory("DrJava-test-" + user, "");
    File forceOpenClass1_file = new File(_tempDir, "ForceOpenClass1.java");
    String forceOpenClass1_string =
        "public class ForceOpenClass1 {\n"
            + "  ForceOpenClass2 class2;\n"
            + "  ForceOpenClass3 class3;\n\n"
            + "  public ForceOpenClass1() {\n"
            + "    class2 = new ForceOpenClass2();\n"
            + "    class3 = new ForceOpenClass3();\n"
            + "  }\n"
            + "}";

    IOUtil.writeStringToFile(forceOpenClass1_file, forceOpenClass1_string);
    forceOpenClass1_file.deleteOnExit();

    final ComponentAdapter listener =
        new ComponentAdapter() {
          public void componentResized(ComponentEvent event) {
            _testFailed = true;
            fail("testDancingUI: Open Documents List danced!");
          }
        };
    final SingleDisplayModelFileClosedListener closeListener =
        new SingleDisplayModelFileClosedListener();

    _closeDone = false;
    Utilities.invokeAndWait(
        new Runnable() {
          public void run() {
            //       _frame.setVisible(true);
            _frame.pack();
            _frame.addComponentListenerToOpenDocumentsList(listener);
            _frame.open(
                new FileOpenSelector() {
                  public File[] getFiles() {
                    File[] return_me = new File[1];
                    return_me[0] = new File(_tempDir, "ForceOpenClass1.java");
                    return return_me;
                  }
                });
            _frame.getModel().addListener(closeListener);
          }
        });
    Utilities.clearEventQueue();

    /* Asynchronously close the file */
    Utilities.invokeLater(
        new Runnable() {
          public void run() {
            _frame.getCloseButton().doClick();
          }
        });

    _log.log("Waiting for file closing");

    synchronized (_closeLock) {
      try {
        while (!_closeDone) _closeLock.wait();
      } catch (InterruptedException e) {
        fail(e.toString());
      }
    }

    if (!IOUtil.deleteRecursively(_tempDir)) {
      System.err.println(
          "Couldn't fully delete directory " + _tempDir.getAbsolutePath() + "\nDo it by hand.\n");
    }
    _log.log("testDancingUIFileClosed completed");
  }
Ejemplo n.º 2
0
  /**
   * A Test to guarantee that the Dancing UI bug will not rear its ugly head again. Basically, add a
   * component listener to the leftComponent of _docSplitPane and make certain its size does not
   * change while compiling a class which depends on another class.
   */
  public void testDancingUIFileOpened() throws IOException {
    // System.out.println("DEBUG: Entering messed up test");
    /**
     * Maybe this sequence of calls should be incorporated into one function createTestDir(), which
     * would get the username and create the temporary directory. Only sticky part is deciding where
     * to put it, in FileOps maybe?
     */
    _log.log("Starting testingDancingUIFileOpened");

    final GlobalModel _model = _frame.getModel();

    String user = System.getProperty("user.name");
    _tempDir = IOUtil.createAndMarkTempDirectory("DrJava-test-" + user, "");

    File forceOpenClass1_file = new File(_tempDir, "ForceOpenClass1.java");
    String forceOpenClass1_string =
        "public class ForceOpenClass1 {\n"
            + "  ForceOpenClass2 class2;\n"
            + "  ForceOpenClass3 class3;\n\n"
            + "  public ForceOpenClass1() {\n"
            + "    class2 = new ForceOpenClass2();\n"
            + "    class3 = new ForceOpenClass3();\n"
            + "  }\n"
            + "}";

    File forceOpenClass2_file = new File(_tempDir, "ForceOpenClass2.java");
    String forceOpenClass2_string = "public class ForceOpenClass2 {\n" + "  inx x = 4;\n" + "}";

    File forceOpenClass3_file = new File(_tempDir, "ForceOpenClass3.java");
    String forceOpenClass3_string =
        "public class ForceOpenClass3 {\n" + "  String s = \"asf\";\n" + "}";

    IOUtil.writeStringToFile(forceOpenClass1_file, forceOpenClass1_string);
    IOUtil.writeStringToFile(forceOpenClass2_file, forceOpenClass2_string);
    IOUtil.writeStringToFile(forceOpenClass3_file, forceOpenClass3_string);
    forceOpenClass1_file.deleteOnExit();
    forceOpenClass2_file.deleteOnExit();
    forceOpenClass3_file.deleteOnExit();

    _log.log("DancingUIFileOpened Set Up");

    // _frame.setVisible(true);

    // set up listeners and signal flags

    final ComponentAdapter listener =
        new ComponentAdapter() {
          public void componentResized(ComponentEvent event) {
            _testFailed = true;
            fail("testDancingUI: Open Documents List danced!");
          }
        };
    final SingleDisplayModelFileOpenedListener openListener =
        new SingleDisplayModelFileOpenedListener();
    final SingleDisplayModelCompileListener compileListener =
        new SingleDisplayModelCompileListener();

    _openDone = false;

    Utilities.invokeAndWait(
        new Runnable() {
          public void run() {
            //       _frame.setVisible(true);
            _frame.pack();
            _frame.addComponentListenerToOpenDocumentsList(listener);
          }
        });
    Utilities.clearEventQueue();

    _model.addListener(openListener);

    _log.log("opening file");

    Utilities.invokeLater(
        new Runnable() {
          public void run() {
            _frame.open(
                new FileOpenSelector() {
                  public File[] getFiles() {
                    File[] return_me = new File[1];
                    return_me[0] = new File(_tempDir, "ForceOpenClass1.java");
                    return return_me;
                  }
                });
          }
        });
    Utilities.clearEventQueue();

    /* wait until file has been open and active document changed. */
    synchronized (_openLock) {
      try {
        while (!_openDone) _openLock.wait();
      } catch (InterruptedException e) {
        fail(e.toString());
      }
    }

    _model.removeListener(openListener);

    _log.log("File opened");

    _compileDone = false;
    _model.addListener(compileListener);

    // save and compile the new file asynchronously

    Utilities.invokeLater(
        new Runnable() {
          public void run() {
            _log.log("saving all files");
            _frame._saveAll();
            _log.log("invoking compileAll action");
            _frame.getCompileAllButton().doClick();
          }
        });
    Utilities.clearEventQueue();

    synchronized (_compileLock) {
      try {
        while (!_compileDone) _compileLock.wait();
      } catch (InterruptedException e) {
        fail(e.toString());
      }
    }
    _log.log("File saved and compiled");

    if (!IOUtil.deleteRecursively(_tempDir))
      System.err.println(
          "Couldn't fully delete directory " + _tempDir.getAbsolutePath() + "\nDo it by hand.\n");

    _log.log("testDancingUIFileOpened completed");
  }