Exemple #1
0
 /** Close the context. */
 public void close() {
   try {
     ((Context) cx).exit();
   } catch (Exception e) {
     suite.passed = false;
     file.passed = false;
     file.exception = "file failed with exception:  " + e;
   }
 }
Exemple #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;
    }
  }
Exemple #3
0
  /**
   * Evaluates the RhinoFile result. If the result is an instance of javax.javascript.Scriptable,
   * assume it is a JavaScript Array of TestCase objects, as described in RhinoDrv.java. For each
   * test case in the array, add an element to the RhinoFile's test case vector. If all test cases
   * passed, set the RhinoFile's passed value to true; else set its passed value to false.
   *
   * <p>If the result is not a Scriptable object, the test failed. Set the the RhinoFile's exception
   * property to the string value of the result. However, negative tests, which should have a
   * "-n.js" extension, are expected to fail.
   */
  public boolean parseResult() {
    FlattenedObject fo = null;

    if (result instanceof Scriptable) {
      fo = new FlattenedObject((Scriptable) result);

      try {
        file.totalCases = ((Number) fo.getProperty("length")).intValue();
        for (int i = 0; i < file.totalCases; i++) {
          Scriptable tc = (Scriptable) ((Scriptable) result).get(i, (Scriptable) result);

          TestCase rt =
              new TestCase(
                  getString(tc.get("passed", tc)),
                  getString(tc.get("name", tc)),
                  getString(tc.get("description", tc)),
                  getString(tc.get("expect", tc)),
                  getString(tc.get("actual", tc)),
                  getString(tc.get("reason", tc)));

          file.bugnumber =
              (getString(tc.get("bugnumber", tc))).startsWith("com.netscape.javascript")
                  ? file.bugnumber
                  : getString(tc.get("bugnumber", tc));

          file.caseVector.addElement(rt);
          if (rt.passed.equals("false")) {
            this.file.passed = false;
            this.suite.passed = false;
          }
        }

        if (file.totalCases == 0) {
          if (file.name.endsWith("-n.js")) {
            this.file.passed = true;
          } else {
            this.file.reason = "File contains no testcases. " + this.file.reason;
            this.file.passed = false;
            this.suite.passed = false;
          }
        }

      } catch (Exception e) {
        this.file.exception =
            "Got a Scriptable result, but failed "
                + "parsing its arguments.  Exception: "
                + e.toString()
                + " Flattened Object is: "
                + fo.toString();

        this.file.passed = false;
        this.suite.passed = false;

        return false;
      }
    } else {
      // if it's not a scriptable object, test failed.  set the file's
      // exception to the string value of whatever result we did get.
      this.file.exception = result.toString();

      // if the file's name ends in "-n", the test expected an error.

      if (file.name.endsWith("-n.js")) {
        this.file.passed = true;
      } else {
        this.file.passed = false;
        this.suite.passed = false;
        return false;
      }
    }

    return true;
  }