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