22 var PASSED
= " PASSED!"
23 var FAILED
= " FAILED! expected: ";
27 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
28 testcases
[tc
].passed
= writeTestCaseResult(
31 testcases
[tc
].description
+" = "+
32 testcases
[tc
].actual
);
34 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
39 function TestCase( n
, d
, e
, a
) {
46 this.bugnumber
= BUGNUMBER
;
48 this.passed
= getTestCaseResult( this.expect
, this.actual
);
50 function startTest() {
52 // JavaScript 1.3 is supposed to be compliant ecma version 1.0
53 if ( VERSION == "ECMA_1" ) {
56 if ( VERSION == "JS_1.3" ) {
59 if ( VERSION == "JS_1.2" ) {
62 if ( VERSION == "JS_1.1" ) {
65 // for ecma version 2.0, we will leave the javascript version to
66 // the default ( for now ).
69 function getTestCaseResult( expect
, actual
) {
70 // because ( NaN == NaN ) always returns false, need to do
71 // a special compare to see if we got the right result.
72 if ( actual
!= actual
) {
73 if ( typeof actual
== "object" ) {
74 actual
= "NaN object";
76 actual
= "NaN number";
79 if ( expect
!= expect
) {
80 if ( typeof expect
== "object" ) {
81 expect
= "NaN object";
83 expect
= "NaN number";
87 var passed
= ( expect
== actual
) ? true : false;
89 // if both objects are numbers, give a little leeway for rounding.
91 && typeof(actual
) == "number"
92 && typeof(expect
) == "number"
94 if ( Math
.abs(actual
-expect
) < 0.0000001 ) {
99 // verify type is the same
100 if ( typeof(expect
) != typeof(actual
) ) {
106 function writeTestCaseResult( expect
, actual
, string
) {
107 var passed
= getTestCaseResult( expect
, actual
);
108 writeFormattedResult( expect
, actual
, string
, passed
);
111 function writeFormattedResult( expect
, actual
, string
, passed
) {
112 var s
= TT
+ string
;
115 k
< (60 - string
.length
>= 0 ? 60 - string
.length
: 5) ;
121 s
+= ( passed
) ? FONT_GREEN
+ NBSP
+ PASSED
: FONT_RED
+ NBSP
+ FAILED
+ expect
+ TT_
;
123 print( s
+ FONT_
+ B_
+ TT_
);
128 function writeHeaderToLog( string
) {
129 print( H2
+ string
+ H2_
);
131 function stopTest() {
132 var sizeTag
= "<#TEST CASES SIZE>";
133 var doneTag
= "<#TEST CASES DONE>";
134 var beginTag
= "<#TEST CASE ";
138 print(testcases
.length
);
139 for (tc
= 0; tc
< testcases
.length
; tc
++)
141 print(beginTag
+ 'PASSED' + endTag
);
142 print(testcases
[tc
].passed
);
143 print(beginTag
+ 'NAME' + endTag
);
144 print(testcases
[tc
].name
);
145 print(beginTag
+ 'EXPECTED' + endTag
);
146 print(testcases
[tc
].expect
);
147 print(beginTag
+ 'ACTUAL' + endTag
);
148 print(testcases
[tc
].actual
);
149 print(beginTag
+ 'DESCRIPTION' + endTag
);
150 print(testcases
[tc
].description
);
151 print(beginTag
+ 'REASON' + endTag
);
152 print(( testcases
[tc
].passed
) ? "" : "wrong value ");
153 print(beginTag
+ 'BUGNUMBER' + endTag
);
160 function getFailedCases() {
161 for ( var i
= 0; i
< testcases
.length
; i
++ ) {
162 if ( ! testcases
[i
].passed
) {
163 print( testcases
[i
].description
+" = " +testcases
[i
].actual
+" expected: "+ testcases
[i
].expect
);