|
1 var completed = false; |
|
2 var testcases; |
|
3 |
|
4 SECTION = ""; |
|
5 VERSION = ""; |
|
6 |
|
7 BUGNUMBER =""; |
|
8 var EXCLUDE = ""; |
|
9 |
|
10 TZ_DIFF = -8; |
|
11 |
|
12 var TT = ""; |
|
13 var TT_ = ""; |
|
14 var BR = ""; |
|
15 var NBSP = " "; |
|
16 var CR = "\n"; |
|
17 var FONT = ""; |
|
18 var FONT_ = ""; |
|
19 var FONT_RED = ""; |
|
20 var FONT_GREEN = ""; |
|
21 var B = ""; |
|
22 var B_ = "" |
|
23 var H2 = ""; |
|
24 var H2_ = ""; |
|
25 var HR = ""; |
|
26 var DEBUG = false; |
|
27 |
|
28 version(130); |
|
29 |
|
30 var PASSED = " PASSED!" |
|
31 var FAILED = " FAILED! expected: "; |
|
32 |
|
33 function test() { |
|
34 for ( tc=0; tc < testcases.length; tc++ ) { |
|
35 testcases[tc].passed = writeTestCaseResult( |
|
36 testcases[tc].expect, |
|
37 testcases[tc].actual, |
|
38 testcases[tc].description +" = "+ |
|
39 testcases[tc].actual ); |
|
40 |
|
41 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; |
|
42 } |
|
43 stopTest(); |
|
44 return ( testcases ); |
|
45 } |
|
46 |
|
47 function TestCase( n, d, e, a ) { |
|
48 this.name = n; |
|
49 this.description = d; |
|
50 this.expect = e; |
|
51 this.actual = a; |
|
52 this.passed = true; |
|
53 this.reason = ""; |
|
54 |
|
55 this.bugnumber = BUGNUMBER; |
|
56 |
|
57 this.passed = getTestCaseResult( this.expect, this.actual ); |
|
58 if ( DEBUG ) { |
|
59 print( "added " + this.description ); |
|
60 } |
|
61 } |
|
62 function startTest() { |
|
63 // JavaScript 1.3 is supposed to be compliant ecma version 1.0 |
|
64 if ( VERSION == "ECMA_1" ) { |
|
65 version ( "130" ); |
|
66 } |
|
67 if ( VERSION == "JS_1.3" ) { |
|
68 version ( "130" ); |
|
69 } |
|
70 if ( VERSION == "JS_1.2" ) { |
|
71 version ( "120" ); |
|
72 } |
|
73 if ( VERSION == "JS_1.1" ) { |
|
74 version ( "110" ); |
|
75 } |
|
76 // for ecma version 2.0, we will leave the javascript version to |
|
77 // the default ( for now ). |
|
78 } |
|
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"; |
|
85 } else { |
|
86 actual = "NaN number"; |
|
87 } |
|
88 } |
|
89 if ( expect != expect ) { |
|
90 if ( typeof expect == "object" ) { |
|
91 expect = "NaN object"; |
|
92 } else { |
|
93 expect = "NaN number"; |
|
94 } |
|
95 } |
|
96 |
|
97 var passed = ( expect == actual ) ? true : false; |
|
98 |
|
99 // if both objects are numbers |
|
100 // need to replace w/ IEEE standard for rounding |
|
101 if ( !passed |
|
102 && typeof(actual) == "number" |
|
103 && typeof(expect) == "number" |
|
104 ) { |
|
105 if ( Math.abs(actual-expect) < 0.0000001 ) { |
|
106 passed = true; |
|
107 } |
|
108 } |
|
109 |
|
110 // verify type is the same |
|
111 if ( typeof(expect) != typeof(actual) ) { |
|
112 passed = false; |
|
113 } |
|
114 |
|
115 return passed; |
|
116 } |
|
117 function writeTestCaseResult( expect, actual, string ) { |
|
118 var passed = getTestCaseResult( expect, actual ); |
|
119 writeFormattedResult( expect, actual, string, passed ); |
|
120 return passed; |
|
121 } |
|
122 function writeFormattedResult( expect, actual, string, passed ) { |
|
123 var s = TT + string ; |
|
124 |
|
125 for ( k = 0; |
|
126 k < (60 - string.length >= 0 ? 60 - string.length : 5) ; |
|
127 k++ ) { |
|
128 } |
|
129 |
|
130 s += B ; |
|
131 s += ( passed ) ? FONT_GREEN + NBSP + PASSED : FONT_RED + NBSP + FAILED + expect + TT_ ; |
|
132 |
|
133 print( s + FONT_ + B_ + TT_ ); |
|
134 |
|
135 return passed; |
|
136 } |
|
137 |
|
138 function writeHeaderToLog( string ) { |
|
139 print( H2 + string + H2_ ); |
|
140 } |
|
141 function stopTest() |
|
142 { |
|
143 var sizeTag = "<#TEST CASES SIZE>"; |
|
144 var doneTag = "<#TEST CASES DONE>"; |
|
145 var beginTag = "<#TEST CASE "; |
|
146 var endTag = ">"; |
|
147 |
|
148 print(sizeTag); |
|
149 print(testcases.length); |
|
150 for (tc = 0; tc < testcases.length; tc++) |
|
151 { |
|
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); |
|
165 print( BUGNUMBER ); |
|
166 } |
|
167 print(doneTag); |
|
168 |
|
169 print( HR ); |
|
170 gc(); |
|
171 } |
|
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 ); |
|
176 } |
|
177 } |
|
178 } |
|
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 ); |
|
186 stopTest(); |
|
187 return true; |
|
188 } |
|
189 |
|
190 function Enumerate ( o ) { |
|
191 var p; |
|
192 for ( p in o ) { |
|
193 print( p +": " + o[p] ); |
|
194 } |
|
195 } |