예제 #1
0
  /**
   * Given a filename, evaluate the file's contents as a JavaScript program. Return the value of the
   * program. If the test throws a Java exception or JavaScript runtime or compilation error, return
   * the string value of the error message.
   *
   * @param s full path to the file that will be exectued.
   * @return test result object. If the test is positive, result should be an instance of
   *     Scriptable. if the test is negative, the result should be a String, whose value is the
   *     message in the JavaScript error or Java exception.
   */
  public Object executeTestFile(String s) {
    // this bit is stolen from Main.java
    FileReader in = null;
    try {
      in = new FileReader(s);
    } catch (FileNotFoundException ex) {
      driver.p("couldn't open file " + s);
    }

    Object result = null;

    try {
      // Here we evalute the entire contents of the file as
      // as script. Text is printed only if the print() function
      // is called.
      //  cx.evaluateReader((Scriptable) global, in, args[i], 1, null);

      result =
          ((Scriptable)
              (((Context) cx).evaluateReader((Scriptable) global, (Reader) in, s, 1, null)));

    } catch (WrappedException we) {
      driver.p("Wrapped Exception:  " + we.getWrappedException().toString());
      result = we.getWrappedException().toString();
    } catch (Exception jse) {
      driver.p("JavaScriptException: " + jse.getMessage());
      result = jse.getMessage();
    }

    return (result);
  }
예제 #2
0
  /**
   * Creates the JavaScript Context, which evaluates the contents of a RhinoFile and returns a
   * result. The RhinoEnv parses the test result, and sets values of the RhinoFile test result
   * properties.
   *
   * @see com.netscape.javascript.Context#setOptimizationLevel
   * @see com.netscape.javascript.Context#setDebugLevel
   */
  public synchronized void runTest() {
    this.driver.p(file.name);
    try {
      cx = createContext();
      ((Context) cx).setOptimizationLevel(driver.OPT_LEVEL);
      ((Context) cx).setDebugLevel(driver.DEBUG_LEVEL);
      Object loadFn = executeTestFile(driver.HELPER_FUNCTIONS.getAbsolutePath());

      file.startTime = driver.getCurrentTime();
      result = executeTestFile(file.filePath);
      file.endTime = driver.getCurrentTime();
      parseResult();

    } catch (Exception e) {
      suite.passed = false;
      file.passed = false;
      file.exception += "file failed with exception:  " + e;
    }
  }