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;
47 var GLOBAL
= "[object global]";
65 var PASSED
= " PASSED!"
66 var FAILED
= " FAILED! expected: ";
69 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
70 testcases
[tc
].passed
= writeTestCaseResult(
73 testcases
[tc
].description
+" = "+
74 testcases
[tc
].actual
);
76 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
82 function TestCase( d
, e
, a
) {
89 this.bugnumber
= BUGNUMBER
;
91 this.passed
= getTestCaseResult( this.expect
, this.actual
);
94 function startTest() {
95 testcases
= new Array();
98 // JavaScript 1.3 is supposed to be compliant ecma version 1.0
99 if ( VERSION
== "JS1_4" ) {
102 if ( VERSION
== "ECMA_1" ) {
105 if ( VERSION
== "JS1_3" ) {
108 if ( VERSION
== "JS1_2" ) {
111 if ( VERSION
== "JS1_1" ) {
115 writeHeaderToLog( SECTION
+ " "+ TITLE
);
117 // verify that DataTypeClass is on the CLASSPATH
119 DT
= Packages
.com
.netscape
.javascript
.qa
.liveconnect
.DataTypeClass
;
121 if ( typeof DT
!= "function" ) {
122 throw "Test Exception: "+
123 "com.netscape.javascript.qa.liveconnect.DataTypeClass "+
124 "is not on the CLASSPATH";
128 function getTestCaseResult( expect
, actual
) {
129 // because ( NaN == NaN ) always returns false, need to do
130 // a special compare to see if we got the right result.
131 if ( actual
!= actual
) {
132 if ( typeof actual
== "object" ) {
133 actual
= "NaN object";
135 actual
= "NaN number";
138 if ( expect
!= expect
) {
139 if ( typeof expect
== "object" ) {
140 expect
= "NaN object";
142 expect
= "NaN number";
146 var passed
= ( expect
== actual
) ? true : false;
148 // if both objects are numbers
149 // need to replace w/ IEEE standard for rounding
151 && typeof(actual
) == "number"
152 && typeof(expect
) == "number"
154 if ( Math
.abs(actual
-expect
) < 0.0000001 ) {
159 // verify type is the same
160 if ( typeof(expect
) != typeof(actual
) ) {
166 function writeTestCaseResult( expect
, actual
, string
) {
167 var passed
= getTestCaseResult( expect
, actual
);
168 writeFormattedResult( expect
, actual
, string
, passed
);
171 function writeFormattedResult( expect
, actual
, string
, passed
) {
172 var s
= TT
+ string
;
175 k
< (60 - string
.length
>= 0 ? 60 - string
.length
: 5) ;
181 s
+= ( passed
) ? FONT_GREEN
+ NBSP
+ PASSED
: FONT_RED
+ NBSP
+ FAILED
+ expect
+ TT_
;
183 print( s
+ FONT_
+ B_
+ TT_
);
188 function writeHeaderToLog( string
) {
189 print( H2
+ string
+ H2_
);
194 var sizeTag
= "<#TEST CASES SIZE>";
195 var doneTag
= "<#TEST CASES DONE>";
196 var beginTag
= "<#TEST CASE ";
200 print(testcases
.length
);
201 for (tc
= 0; tc
< testcases
.length
; tc
++)
203 print(beginTag
+ 'PASSED' + endTag
);
204 print(testcases
[tc
].passed
);
205 print(beginTag
+ 'NAME' + endTag
);
206 print(testcases
[tc
].name
);
207 print(beginTag
+ 'EXPECTED' + endTag
);
208 print(testcases
[tc
].expect
);
209 print(beginTag
+ 'ACTUAL' + endTag
);
210 print(testcases
[tc
].actual
);
211 print(beginTag
+ 'DESCRIPTION' + endTag
);
212 print(testcases
[tc
].description
);
213 print(beginTag
+ 'REASON' + endTag
);
214 print(( testcases
[tc
].passed
) ? "" : "wrong value ");
215 print(beginTag
+ 'BUGNUMBER' + endTag
);
223 function getFailedCases() {
224 for ( var i
= 0; i
< testcases
.length
; i
++ ) {
225 if ( ! testcases
[i
].passed
) {
226 print( testcases
[i
].description
+" = " +testcases
[i
].actual
+" expected: "+ testcases
[i
].expect
);