2 * The contents of this file are subject to the Netscape Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/NPL/
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is mozilla.org code.
14 * The Initial Developer of the Original Code is Netscape
15 * Communications Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
24 * JavaScript shared functions file for running the tests in either
25 * stand-alone JavaScript engine. To run a test, first load this file,
26 * then load the test script.
29 var completed = false;
37 var TZ_DIFF = getTimeZoneDiff();
41 var GLOBAL = "[object global]";
42 var PASSED = " PASSED!"
43 var FAILED = " FAILED! expected: ";
46 for ( tc=0; tc < testcases.length; tc++ ) {
47 testcases[tc].passed = writeTestCaseResult(
50 testcases[tc].description +" = "+
51 testcases[tc].actual );
53 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
59 function TestCase( n, d, e, a ) {
66 this.bugnumber = BUGNUMBER;
68 this.passed = getTestCaseResult( this.expect, this.actual );
70 writeLineToLog( "added " + this.description );
73 function startTest() {
75 // JavaScript 1.3 is supposed to be compliant ecma version 1.0
76 if ( VERSION == "ECMA_1" ) {
79 if ( VERSION == "JS_13" ) {
82 if ( VERSION == "JS_12" ) {
85 if ( VERSION == "JS_11" ) {
91 // for ecma version 2.0, we will leave the javascript version to
92 // the default ( for now ).
94 writeHeaderToLog( SECTION + " "+ TITLE);
96 writeLineToLog ("BUGNUMBER: " + BUGNUMBER );
99 testcases = new Array();
103 function getTestCaseResult( expect, actual ) {
104 // because ( NaN == NaN ) always returns false, need to do
105 // a special compare to see if we got the right result.
106 if ( actual != actual ) {
107 if ( typeof actual == "object" ) {
108 actual = "NaN object";
110 actual = "NaN number";
113 if ( expect != expect ) {
114 if ( typeof expect == "object" ) {
115 expect = "NaN object";
117 expect = "NaN number";
121 var passed = ( expect == actual ) ? true : false;
123 // if both objects are numbers
124 // need to replace w/ IEEE standard for rounding
126 && typeof(actual) == "number"
127 && typeof(expect) == "number"
129 if ( Math.abs(actual-expect) < 0.0000001 ) {
134 // verify type is the same
135 if ( typeof(expect) != typeof(actual) ) {
142 function writeTestCaseResult( expect, actual, string ) {
143 var passed = getTestCaseResult( expect, actual );
144 writeFormattedResult( expect, actual, string, passed );
148 function writeFormattedResult( expect, actual, string, passed ) {
150 s += ( passed ) ? PASSED : FAILED + expect;
155 function writeLineToLog( string ) {
158 function writeHeaderToLog( string ) {
161 function stopTest() {
163 if ( gc != undefined ) {
167 function getFailedCases() {
168 for ( var i = 0; i < testcases.length; i++ ) {
169 if ( ! testcases[i].passed ) {
170 print( testcases[i].description +" = " +testcases[i].actual +" expected: "+ testcases[i].expect );
174 function err( msg, page, line ) {
175 writeLineToLog( page + " failed with error: " + msg + " on line " + line );
176 testcases[tc].actual = "error";
177 testcases[tc].reason = msg;
178 writeTestCaseResult( testcases[tc].expect,
179 testcases[tc].actual,
180 testcases[tc].description +" = "+ testcases[tc].actual +
181 ": " + testcases[tc].reason );
186 function Enumerate ( o ) {
187 var properties = new Array();
189 properties[ properties.length ] = new Array( p, o[p] );
194 function getFailedCases() {
195 for ( var i = 0; i < testcases.length; i++ ) {
196 if ( ! testcases[i].passed ) {
197 writeLineToLog( testcases[i].description +" = " +testcases[i].actual +
198 " expected: "+ testcases[i].expect );
202 function AddTestCase( description, expect, actual ) {
203 testcases[tc++] = new TestCase( SECTION, description, expect, actual );
208 * Originally, the test suite used a hard-coded value TZ_DIFF = -8.
209 * But that was only valid for testers in the Pacific Standard Time Zone!
210 * We calculate the proper number dynamically for any tester. We just
211 * have to be careful to use a date not subject to Daylight Savings Time...
213 function getTimeZoneDiff()
215 return -((new Date(2000, 1, 1)).getTimezoneOffset())/60;