22 var PASSED = " PASSED!"
23 var FAILED = " FAILED! expected: ";
28 for ( tc=0; tc < testcases.length; tc++ ) {
29 testcases[tc].passed = writeTestCaseResult(
32 testcases[tc].description +" = "+
33 testcases[tc].actual );
35 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
41 function TestCase( n, d, e, a ) {
48 this.bugnumber = BUGNUMBER;
50 this.passed = getTestCaseResult( this.expect, this.actual );
52 function startTest() {
54 // JavaScript 1.3 is supposed to be compliant ecma version 1.0
55 if ( VERSION == "ECMA_1" ) {
58 if ( VERSION == "JS_1.3" ) {
61 if ( VERSION == "JS_1.2" ) {
64 if ( VERSION == "JS_1.1" ) {
67 // for ecma version 2.0, we will leave the javascript version to
68 // the default ( for now ).
71 function getTestCaseResult( expect, actual ) {
72 // because ( NaN == NaN ) always returns false, need to do
73 // a special compare to see if we got the right result.
74 if ( actual != actual ) {
75 if ( typeof actual == "object" ) {
76 actual = "NaN object";
78 actual = "NaN number";
81 if ( expect != expect ) {
82 if ( typeof expect == "object" ) {
83 expect = "NaN object";
85 expect = "NaN number";
89 var passed = ( expect == actual ) ? true : false;
91 // if both objects are numbers, give a little leeway for rounding.
93 && typeof(actual) == "number"
94 && typeof(expect) == "number"
96 if ( Math.abs(actual-expect) < 0.0000001 ) {
101 // verify type is the same
102 if ( typeof(expect) != typeof(actual) ) {
108 function writeTestCaseResult( expect, actual, string ) {
109 var passed = getTestCaseResult( expect, actual );
110 writeFormattedResult( expect, actual, string, passed );
113 function writeFormattedResult( expect, actual, string, passed ) {
114 var s = TT + string ;
117 k < (60 - string.length >= 0 ? 60 - string.length : 5) ;
123 s += ( passed ) ? FONT_GREEN + NBSP + PASSED : FONT_RED + NBSP + FAILED + expect + TT_ ;
125 print( s + FONT_ + B_ + TT_ );
130 function writeHeaderToLog( string ) {
131 print( H2 + string + H2_ );
133 function stopTest() {
134 var sizeTag = "<#TEST CASES SIZE>";
135 var doneTag = "<#TEST CASES DONE>";
136 var beginTag = "<#TEST CASE ";
140 print(testcases.length);
141 for (tc = 0; tc < testcases.length; tc++)
143 print(beginTag + 'PASSED' + endTag);
144 print(testcases[tc].passed);
145 print(beginTag + 'NAME' + endTag);
146 print(testcases[tc].name);
147 print(beginTag + 'EXPECTED' + endTag);
148 print(testcases[tc].expect);
149 print(beginTag + 'ACTUAL' + endTag);
150 print(testcases[tc].actual);
151 print(beginTag + 'DESCRIPTION' + endTag);
152 print(testcases[tc].description);
153 print(beginTag + 'REASON' + endTag);
154 print(( testcases[tc].passed ) ? "" : "wrong value ");
155 print(beginTag + 'BUGNUMBER' + endTag);
161 function getFailedCases() {
162 for ( var i = 0; i < testcases.length; i++ ) {
163 if ( ! testcases[i].passed ) {
164 print( testcases[i].description +" = " +testcases[i].actual +" expected: "+ testcases[i].expect );