30 var PASSED
= " PASSED!"
31 var FAILED
= " FAILED! expected: ";
34 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
35 testcases
[tc
].passed
= writeTestCaseResult(
38 testcases
[tc
].description
+" = "+
39 testcases
[tc
].actual
);
41 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
47 function TestCase( n
, d
, e
, a
) {
55 this.bugnumber
= BUGNUMBER
;
57 this.passed
= getTestCaseResult( this.expect
, this.actual
);
59 print( "added " + this.description
);
62 function startTest() {
63 // JavaScript 1.3 is supposed to be compliant ecma version 1.0
64 if ( VERSION
== "ECMA_1" ) {
67 if ( VERSION
== "JS_1.3" ) {
70 if ( VERSION
== "JS_1.2" ) {
73 if ( VERSION
== "JS_1.1" ) {
76 // for ecma version 2.0, we will leave the javascript version to
77 // the default ( for now ).
79 function 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";
86 actual
= "NaN number";
89 if ( expect
!= expect
) {
90 if ( typeof expect
== "object" ) {
91 expect
= "NaN object";
93 expect
= "NaN number";
97 var passed
= ( expect
== actual
) ? true : false;
99 // if both objects are numbers
100 // need to replace w/ IEEE standard for rounding
102 && typeof(actual
) == "number"
103 && typeof(expect
) == "number"
105 if ( Math
.abs(actual
-expect
) < 0.0000001 ) {
110 // verify type is the same
111 if ( typeof(expect
) != typeof(actual
) ) {
117 function writeTestCaseResult( expect
, actual
, string
) {
118 var passed
= getTestCaseResult( expect
, actual
);
119 writeFormattedResult( expect
, actual
, string
, passed
);
122 function writeFormattedResult( expect
, actual
, string
, passed
) {
123 var s
= TT
+ string
;
126 k
< (60 - string
.length
>= 0 ? 60 - string
.length
: 5) ;
131 s
+= ( passed
) ? FONT_GREEN
+ NBSP
+ PASSED
: FONT_RED
+ NBSP
+ FAILED
+ expect
+ TT_
;
133 print( s
+ FONT_
+ B_
+ TT_
);
138 function writeHeaderToLog( string
) {
139 print( H2
+ string
+ H2_
);
143 var sizeTag
= "<#TEST CASES SIZE>";
144 var doneTag
= "<#TEST CASES DONE>";
145 var beginTag
= "<#TEST CASE ";
149 print(testcases
.length
);
150 for (tc
= 0; tc
< testcases
.length
; tc
++)
152 print(beginTag
+ 'PASSED' + endTag
);
153 print(testcases
[tc
].passed
);
154 print(beginTag
+ 'NAME' + endTag
);
155 print(testcases
[tc
].name
);
156 print(beginTag
+ 'EXPECTED' + endTag
);
157 print(testcases
[tc
].expect
);
158 print(beginTag
+ 'ACTUAL' + endTag
);
159 print(testcases
[tc
].actual
);
160 print(beginTag
+ 'DESCRIPTION' + endTag
);
161 print(testcases
[tc
].description
);
162 print(beginTag
+ 'REASON' + endTag
);
163 print(( testcases
[tc
].passed
) ? "" : "wrong value ");
164 print(beginTag
+ 'BUGNUMBER' + endTag
);
172 function getFailedCases() {
173 for ( var i
= 0; i
< testcases
.length
; i
++ ) {
174 if ( ! testcases
[i
].passed
) {
175 print( testcases
[i
].description
+" = " +testcases
[i
].actual
+" expected: "+ testcases
[i
].expect
);
179 function err( msg
, page
, line
) {
180 testcases
[tc
].actual
= "error";
181 testcases
[tc
].reason
= msg
;
182 writeTestCaseResult( testcases
[tc
].expect
,
183 testcases
[tc
].actual
,
184 testcases
[tc
].description
+" = "+ testcases
[tc
].actual
+
185 ": " + testcases
[tc
].reason
);
190 function Enumerate ( o
) {
193 print( p
+": " + o
[p
] );