]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/mozilla/js1_2/shell.js
JavaScriptCore-461.tar.gz
[apple/javascriptcore.git] / tests / mozilla / js1_2 / shell.js
CommitLineData
b37bf2e1
A
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/
5 *
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.
10 *
11 * The Original Code is Mozilla Communicator client code, released March
12 * 31, 1998.
13 *
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
17 * Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 */
22var completed = false;
23var testcases;
24
25var SECTION = "";
26var VERSION = "";
27var BUGNUMBER = "";
28
29var GLOBAL = "[object global]";
30var PASSED = " PASSED!"
31var FAILED = " FAILED! expected: ";
32
33startTest();
34
35 version(120);
36
37function test() {
38 for ( tc=0; tc < testcases.length; tc++ ) {
39 testcases[tc].passed = writeTestCaseResult(
40 testcases[tc].expect,
41 testcases[tc].actual,
42 testcases[tc].description +" = "+
43 testcases[tc].actual );
44
45 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
46 }
47 stopTest();
48 return ( testcases );
49}
50/* wrapper for test cas constructor that doesn't require the SECTION
51 * argument.
52 */
53
54function AddTestCase( description, expect, actual ) {
55 testcases[tc++] = new TestCase( SECTION, description, expect, actual );
56}
57
58
59function TestCase( n, d, e, a ) {
60 this.name = n;
61 this.description = d;
62 this.expect = e;
63 this.actual = a;
64 this.passed = true;
65 this.reason = "";
66
67 this.passed = getTestCaseResult( this.expect, this.actual );
68}
69function startTest() {
70 version(120);
71
72 if ( BUGNUMBER ) {
73 writeLineToLog ("BUGNUMBER: " + BUGNUMBER );
74 }
75
76 testcases = new Array();
77 tc = 0;
78}
79function 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";
85 } else {
86 actual = "NaN number";
87 }
88 }
89 if ( expect != expect ) {
90 if ( typeof expect == "object" ) {
91 expect = "NaN object";
92 } else {
93 expect = "NaN number";
94 }
95 }
96
97 var passed = ( expect == actual ) ? true : false;
98
99 // if both objects are numbers, give a little leeway for rounding.
100 if ( !passed
101 && typeof(actual) == "number"
102 && typeof(expect) == "number"
103 ) {
104 if ( Math.abs(actual-expect) < 0.0000001 ) {
105 passed = true;
106 }
107 }
108
109 // verify type is the same
110 if ( typeof(expect) != typeof(actual) ) {
111 passed = false;
112 }
113
114 return passed;
115}
116/*
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
120 * document.write.
121 */
122
123function writeTestCaseResult( expect, actual, string ) {
124 var passed = getTestCaseResult( expect, actual );
125 writeFormattedResult( expect, actual, string, passed );
126 return passed;
127}
128function writeFormattedResult( expect, actual, string, passed ) {
129 var s = string ;
130 s += ( passed ) ? PASSED : FAILED + expect;
131 writeLineToLog( s);
132 return passed;
133}
134function writeLineToLog( string ) {
135 print( string );
136}
137function writeHeaderToLog( string ) {
138 print( string );
139}
140/* end of print functions */
141
142function stopTest() {
143 var gc;
144 if ( gc != undefined ) {
145 gc();
146 }
147}