/** * 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; }