| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
var completed = false; |
| 6 |
var testcases; |
| 7 |
|
| 8 |
SECTION = ""; |
| 9 |
VERSION = ""; |
| 10 |
|
| 11 |
BUGNUMBER=""; |
| 12 |
EXCLUDE = ""; |
| 13 |
|
| 14 |
var TT = ""; |
| 15 |
var TT_ = ""; |
| 16 |
var BR = ""; |
| 17 |
var NBSP = " "; |
| 18 |
var CR = "\n"; |
| 19 |
var FONT = ""; |
| 20 |
var FONT_ = ""; |
| 21 |
var FONT_RED = ""; |
| 22 |
var FONT_GREEN = ""; |
| 23 |
var B = ""; |
| 24 |
var B_ = "" |
| 25 |
var H2 = ""; |
| 26 |
var H2_ = ""; |
| 27 |
var HR = ""; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
var PASSED = " PASSED!" |
| 32 |
var FAILED = " FAILED! expected: "; |
| 33 |
|
| 34 |
function TestCase( n, d, e, a ) { |
| 35 |
this.name = n; |
| 36 |
this.description = d; |
| 37 |
this.expect = e; |
| 38 |
this.actual = a; |
| 39 |
this.passed = true; |
| 40 |
this.reason = ""; |
| 41 |
this.bugnumber = BUGNUMBER; |
| 42 |
|
| 43 |
this.passed = getTestCaseResult( this.expect, this.actual ); |
| 44 |
} |
| 45 |
function startTest() { |
| 46 |
|
| 47 |
if ( VERSION == "ECMA_1" ) { |
| 48 |
version ( "130" ); |
| 49 |
} |
| 50 |
if ( VERSION == "JS_1.3" ) { |
| 51 |
version ( "130" ); |
| 52 |
} |
| 53 |
if ( VERSION == "JS_1.2" ) { |
| 54 |
version ( "120" ); |
| 55 |
} |
| 56 |
if ( VERSION == "JS_1.1" ) { |
| 57 |
version ( "110" ); |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
} |
| 62 |
function getTestCaseResult( expect, actual ) { |
| 63 |
|
| 64 |
|
| 65 |
if ( actual != actual ) { |
| 66 |
if ( typeof actual == "object" ) { |
| 67 |
actual = "NaN object"; |
| 68 |
} else { |
| 69 |
actual = "NaN number"; |
| 70 |
} |
| 71 |
} |
| 72 |
if ( expect != expect ) { |
| 73 |
if ( typeof expect == "object" ) { |
| 74 |
expect = "NaN object"; |
| 75 |
} else { |
| 76 |
expect = "NaN number"; |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
var passed = ( expect == actual ) ? true : false; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
if ( !passed |
| 85 |
&& typeof(actual) == "number" |
| 86 |
&& typeof(expect) == "number" |
| 87 |
) { |
| 88 |
if ( Math.abs(actual-expect) < 0.0000001 ) { |
| 89 |
passed = true; |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
if ( typeof(expect) != typeof(actual) ) { |
| 95 |
passed = false; |
| 96 |
} |
| 97 |
|
| 98 |
return passed; |
| 99 |
} |
| 100 |
function writeTestCaseResult( expect, actual, string ) { |
| 101 |
var passed = getTestCaseResult( expect, actual ); |
| 102 |
writeFormattedResult( expect, actual, string, passed ); |
| 103 |
return passed; |
| 104 |
} |
| 105 |
function writeFormattedResult( expect, actual, string, passed ) { |
| 106 |
var s = TT + string ; |
| 107 |
|
| 108 |
for ( k = 0; |
| 109 |
k < (60 - string.length >= 0 ? 60 - string.length : 5) ; |
| 110 |
k++ ) { |
| 111 |
|
| 112 |
} |
| 113 |
|
| 114 |
s += B ; |
| 115 |
s += ( passed ) ? FONT_GREEN + NBSP + PASSED : FONT_RED + NBSP + FAILED + expect + TT_ ; |
| 116 |
|
| 117 |
print( s + FONT_ + B_ + TT_ ); |
| 118 |
|
| 119 |
return passed; |
| 120 |
} |
| 121 |
|
| 122 |
function writeHeaderToLog( string ) { |
| 123 |
print( H2 + string + H2_ ); |
| 124 |
} |
| 125 |
function stopTest() |
| 126 |
{ |
| 127 |
var sizeTag = "<#TEST CASES SIZE>"; |
| 128 |
var doneTag = "<#TEST CASES DONE>"; |
| 129 |
var beginTag = "<#TEST CASE "; |
| 130 |
var endTag = ">"; |
| 131 |
|
| 132 |
print(sizeTag); |
| 133 |
print(testcases.length); |
| 134 |
for (tc = 0; tc < testcases.length; tc++) |
| 135 |
{ |
| 136 |
print(beginTag + 'PASSED' + endTag); |
| 137 |
print(testcases[tc].passed); |
| 138 |
print(beginTag + 'NAME' + endTag); |
| 139 |
print(testcases[tc].name); |
| 140 |
print(beginTag + 'EXPECTED' + endTag); |
| 141 |
print(testcases[tc].expect); |
| 142 |
print(beginTag + 'ACTUAL' + endTag); |
| 143 |
print(testcases[tc].actual); |
| 144 |
print(beginTag + 'DESCRIPTION' + endTag); |
| 145 |
print(testcases[tc].description); |
| 146 |
print(beginTag + 'REASON' + endTag); |
| 147 |
print(( testcases[tc].passed ) ? "" : "wrong value "); |
| 148 |
print(beginTag + 'BUGNUMBER' + endTag); |
| 149 |
print( BUGNUMBER ); |
| 150 |
} |
| 151 |
print(doneTag); |
| 152 |
|
| 153 |
print( HR ); |
| 154 |
gc(); |
| 155 |
} |
| 156 |
function getFailedCases() { |
| 157 |
for ( var i = 0; i < testcases.length; i++ ) { |
| 158 |
if ( ! testcases[i].passed ) { |
| 159 |
print( testcases[i].description +" = " +testcases[i].actual +" expected: "+ testcases[i].expect ); |
| 160 |
} |
| 161 |
} |
| 162 |
} |
| 163 |
function err( msg, page, line ) { |
| 164 |
testcases[tc].actual = "error"; |
| 165 |
testcases[tc].reason = msg; |
| 166 |
writeTestCaseResult( testcases[tc].expect, |
| 167 |
testcases[tc].actual, |
| 168 |
testcases[tc].description +" = "+ testcases[tc].actual + |
| 169 |
": " + testcases[tc].reason ); |
| 170 |
stopTest(); |
| 171 |
return true; |
| 172 |
} |