1var completed = false;
2var	testcases;
3var tc = 0;
4
5SECTION	= "";
6VERSION	= "";
7BUGNUMBER =	"";
8
9var	GLOBAL = "[object global]";
10var PASSED = " PASSED!"
11var FAILED = " FAILED! expected: ";
12
13function test() {
14    for ( tc=0; tc < testcases.length; tc++ ) {
15        testcases[tc].passed = writeTestCaseResult(
16                            testcases[tc].expect,
17                            testcases[tc].actual,
18                            testcases[tc].description +" = "+
19                            testcases[tc].actual );
20
21        testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
22    }
23    stopTest();
24    return ( testcases );
25}
26/* wrapper for test cas constructor that doesn't require the SECTION
27 * argument.
28 */
29
30function AddTestCase( description, expect, actual ) {
31    testcases[tc++] = new TestCase( SECTION, description, expect, actual );
32}
33
34function TestCase( n, d, e, a ) {
35    this.name        = n;
36    this.description = d;
37    this.expect      = e;
38    this.actual      = a;
39    this.passed      = true;
40    this.reason      = "";
41
42    this.passed = getTestCaseResult( this.expect, this.actual );
43}
44function startTest() {
45/*
46    //  JavaScript 1.3 is supposed to be compliant ecma version 1.0
47    if ( VERSION == "ECMA_1" ) {
48        version ( 130 );
49    }
50    if ( VERSION == "JS_1.3" ) {
51        version ( 130 );
52    }
53    if ( VERSION == "JS_1.2" ) {
54        version ( 120 );
55    }
56    if ( VERSION  == "JS_1.1" ) {
57        version ( 110 );
58    }
59    // for ecma version 2.0, we will leave the javascript version to
60    // the default ( for now ).
61*/
62
63    if ( BUGNUMBER ) {
64            writeLineToLog ("BUGNUMBER: " + BUGNUMBER );
65    }
66
67    testcases = new Array();
68    tc = 0;
69}
70function getTestCaseResult( expect, actual ) {
71    //  because ( NaN == NaN ) always returns false, need to do
72    //  a special compare to see if we got the right result.
73        if ( actual != actual ) {
74            if ( typeof actual == "object" ) {
75                actual = "NaN object";
76            } else {
77                actual = "NaN number";
78            }
79        }
80        if ( expect != expect ) {
81            if ( typeof expect == "object" ) {
82                expect = "NaN object";
83            } else {
84                expect = "NaN number";
85            }
86        }
87
88        var passed = ( expect == actual ) ? true : false;
89
90    //  if both objects are numbers, give a little leeway for rounding.
91        if (    !passed
92                && typeof(actual) == "number"
93                && typeof(expect) == "number"
94            ) {
95                if ( Math.abs(actual-expect) < 0.0000001 ) {
96                    passed = true;
97                }
98        }
99
100    //  verify type is the same
101        if ( typeof(expect) != typeof(actual) ) {
102            passed = false;
103        }
104
105        return passed;
106}
107/*
108 * Begin printing functions.  These functions use the shell's
109 * print function.  When running tests in the browser, these
110 * functions, override these functions with functions that use
111 * document.write.
112 */
113
114function writeTestCaseResult( expect, actual, string ) {
115		var	passed = getTestCaseResult(	expect,	actual );
116		writeFormattedResult( expect, actual, string, passed );
117		return passed;
118}
119function writeFormattedResult( expect, actual, string, passed ) {
120        var s = string ;
121        s += ( passed ) ? PASSED : FAILED + expect;
122        writeLineToLog( s);
123        return passed;
124}
125function writeLineToLog( string	) {
126	print( string );
127}
128function writeHeaderToLog( string )	{
129	print( string );
130}
131/* end of print functions */
132
133function stopTest() {
134   var gc;
135   if ( gc != undefined ) {
136        gc();
137   }
138}
139