1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is Mozilla Communicator client code, released
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
37 var completed
= false;
49 var GLOBAL
= "[object global]";
50 var PASSED
= " PASSED!"
51 var FAILED
= " FAILED! expected: ";
57 * change this for date tests if you're not in PST
61 /* wrapper for test cas constructor that doesn't require the SECTION
65 function AddTestCase( description
, expect
, actual
) {
66 testcases
[tc
++] = new TestCase( SECTION
, description
, expect
, actual
);
68 function TestCase( n
, d
, e
, a
) {
75 this.bugnumber
= BUGNUMBER
;
77 this.passed
= getTestCaseResult( this.expect
, this.actual
);
79 function startTest() {
82 // for ecma version 2.0, we will leave the javascript version to
83 // the default ( for now ).
84 // print out bugnumber
87 print ("BUGNUMBER: " + BUGNUMBER
);
90 testcases
= new Array();
95 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
96 testcases
[tc
].passed
= writeTestCaseResult(
99 testcases
[tc
].description
+" = "+
100 testcases
[tc
].actual
);
102 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
105 return ( testcases
);
107 function getTestCaseResult( expect
, actual
) {
108 // because ( NaN == NaN ) always returns false, need to do
109 // a special compare to see if we got the right result.
110 if ( actual
!= actual
) {
111 if ( typeof actual
== "object" ) {
112 actual
= "NaN object";
114 actual
= "NaN number";
117 if ( expect
!= expect
) {
118 if ( typeof expect
== "object" ) {
119 expect
= "NaN object";
121 expect
= "NaN number";
125 var passed
= ( expect
== actual
) ? true : false;
127 // if both objects are numbers, give a little leeway for rounding.
129 && typeof(actual
) == "number"
130 && typeof(expect
) == "number"
132 if ( Math
.abs(actual
-expect
) < 0.0000001 ) {
137 // verify type is the same
138 if ( typeof(expect
) != typeof(actual
) ) {
145 * Begin printing functions. These functions use the shell's
146 * print function. When running tests in the browser, these
147 * functions, override these functions with functions that use
151 function writeTestCaseResult( expect
, actual
, string
) {
152 var passed
= getTestCaseResult( expect
, actual
);
153 writeFormattedResult( expect
, actual
, string
, passed
);
156 function writeFormattedResult( expect
, actual
, string
, passed
) {
158 s
+= ( passed
) ? PASSED
: FAILED
+ expect
;
163 function writeHeaderToLog( string
) {
166 /* end of print functions */
169 function stopTest() {
170 var sizeTag
= "<#TEST CASES SIZE>";
171 var doneTag
= "<#TEST CASES DONE>";
172 var beginTag
= "<#TEST CASE ";
176 print(testcases
.length
);
177 for (tc
= 0; tc
< testcases
.length
; tc
++)
179 print(beginTag
+ 'PASSED' + endTag
);
180 print(testcases
[tc
].passed
);
181 print(beginTag
+ 'NAME' + endTag
);
182 print(testcases
[tc
].name
);
183 print(beginTag
+ 'EXPECTED' + endTag
);
184 print(testcases
[tc
].expect
);
185 print(beginTag
+ 'ACTUAL' + endTag
);
186 print(testcases
[tc
].actual
);
187 print(beginTag
+ 'DESCRIPTION' + endTag
);
188 print(testcases
[tc
].description
);
189 print(beginTag
+ 'REASON' + endTag
);
190 print(( testcases
[tc
].passed
) ? "" : "wrong value ");
191 print(beginTag
+ 'BUGNUMBER' + endTag
);
198 function getFailedCases() {
199 for ( var i
= 0; i
< testcases
.length
; i
++ ) {
200 if ( ! testcases
[i
].passed
) {
201 print( testcases
[i
].description
+" = " +testcases
[i
].actual
+" expected: "+ testcases
[i
].expect
);
205 function err( msg
, page
, line
) {
206 testcases
[tc
].actual
= "error";
207 testcases
[tc
].reason
= msg
;
208 writeTestCaseResult( testcases
[tc
].expect
,
209 testcases
[tc
].actual
,
210 testcases
[tc
].description
+" = "+ testcases
[tc
].actual
+
211 ": " + testcases
[tc
].reason
);
215 function Enumerate ( o
) {
218 print( p
+": " + o
[p
] );
221 function GetContext() {
222 return Packages
.com
.netscape
.javascript
.Context
.getCurrentContext();
224 function OptLevel( i
) {
226 var cx
= GetContext();
227 cx
.setOptimizationLevel(i
);