1 /* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
11 * The Original Code is Mozilla Communicator client code, released March
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
22 var completed = false;
29 var GLOBAL = "[object global]";
30 var PASSED = " PASSED!"
31 var FAILED = " FAILED! expected: ";
38 for ( tc=0; tc < testcases.length; tc++ ) {
39 testcases[tc].passed = writeTestCaseResult(
42 testcases[tc].description +" = "+
43 testcases[tc].actual );
45 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
50 /* wrapper for test cas constructor that doesn't require the SECTION
54 function AddTestCase( description, expect, actual ) {
55 testcases[tc++] = new TestCase( SECTION, description, expect, actual );
59 function TestCase( n, d, e, a ) {
67 this.passed = getTestCaseResult( this.expect, this.actual );
69 function startTest() {
73 writeLineToLog ("BUGNUMBER: " + BUGNUMBER );
76 testcases = new Array();
79 function getTestCaseResult( expect, actual ) {
80 // because ( NaN == NaN ) always returns false, need to do
81 // a special compare to see if we got the right result.
82 if ( actual != actual ) {
83 if ( typeof actual == "object" ) {
84 actual = "NaN object";
86 actual = "NaN number";
89 if ( expect != expect ) {
90 if ( typeof expect == "object" ) {
91 expect = "NaN object";
93 expect = "NaN number";
97 var passed = ( expect == actual ) ? true : false;
99 // if both objects are numbers, give a little leeway for rounding.
101 && typeof(actual) == "number"
102 && typeof(expect) == "number"
104 if ( Math.abs(actual-expect) < 0.0000001 ) {
109 // verify type is the same
110 if ( typeof(expect) != typeof(actual) ) {
117 * Begin printing functions. These functions use the shell's
118 * print function. When running tests in the browser, these
119 * functions, override these functions with functions that use
123 function writeTestCaseResult( expect, actual, string ) {
124 var passed = getTestCaseResult( expect, actual );
125 writeFormattedResult( expect, actual, string, passed );
128 function writeFormattedResult( expect, actual, string, passed ) {
130 s += ( passed ) ? PASSED : FAILED + expect;
134 function writeLineToLog( string ) {
137 function writeHeaderToLog( string ) {
140 /* end of print functions */
142 function stopTest() {
144 if ( gc != undefined ) {