| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
if (typeof version != 'undefined') |
| 11 |
{ |
| 12 |
version(150); |
| 13 |
} |
| 14 |
|
| 15 |
var STATUS = "STATUS: "; |
| 16 |
var VERBOSE = false; |
| 17 |
var SECT_PREFIX = 'Section '; |
| 18 |
var SECT_SUFFIX = ' of test - '; |
| 19 |
var callStack = new Array(); |
| 20 |
|
| 21 |
var gTestfile; |
| 22 |
var gTestPath; |
| 23 |
var gTestsuite; |
| 24 |
var gTestsubsuite; |
| 25 |
var gDelayTestDriverEnd = false; |
| 26 |
|
| 27 |
var gTestcases = new Array(); |
| 28 |
var gTc = gTestcases.length; |
| 29 |
var BUGNUMBER = ''; |
| 30 |
var summary = ''; |
| 31 |
var description = ''; |
| 32 |
var expected = ''; |
| 33 |
var actual = ''; |
| 34 |
var msg = ''; |
| 35 |
|
| 36 |
var SECTION = ""; |
| 37 |
var VERSION = ""; |
| 38 |
var BUGNUMBER = ""; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
var GLOBAL = this + ''; |
| 44 |
var PASSED = " PASSED! "; |
| 45 |
var FAILED = " FAILED! "; |
| 46 |
|
| 47 |
var DEBUG = false; |
| 48 |
|
| 49 |
var DESCRIPTION; |
| 50 |
var EXPECTED; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
function AddTestCase( description, expect, actual ) { |
| 58 |
new TestCase( SECTION, description, expect, actual ); |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
function startTest() { |
| 66 |
|
| 67 |
|
| 68 |
if ( BUGNUMBER ) { |
| 69 |
print ("BUGNUMBER: " + BUGNUMBER ); |
| 70 |
} |
| 71 |
if ( typeof version != 'function') { |
| 72 |
return; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
if ( VERSION == "ECMA_1" ) { |
| 77 |
version ( "130" ); |
| 78 |
} |
| 79 |
else if ( VERSION == "JS_1.8" || gTestsuite == 'js1_8') { |
| 80 |
version ( "180" ); |
| 81 |
} |
| 82 |
else if ( VERSION == "JS_1.7" || gTestsuite == 'js1_7') { |
| 83 |
version ( "170" ); |
| 84 |
} |
| 85 |
else if ( VERSION == "JS_1.6" || gTestsuite == 'js1_6') { |
| 86 |
version ( "160" ); |
| 87 |
} |
| 88 |
else if ( VERSION == "JS_1.5" || gTestsuite == 'js1_5') { |
| 89 |
version ( "150" ); |
| 90 |
} |
| 91 |
else if ( VERSION == "JS_1.4" || gTestsuite == 'js1_4') { |
| 92 |
version ( "140" ); |
| 93 |
} |
| 94 |
else if ( VERSION == "JS_1.3" || gTestsuite == 'js1_3') { |
| 95 |
version ( "130" ); |
| 96 |
} |
| 97 |
else if ( VERSION == "JS_1.2" || gTestsuite == 'js1_2') { |
| 98 |
version ( "120" ); |
| 99 |
} |
| 100 |
else if ( VERSION == "JS_1.1" || gTestsuite == 'js1_1') { |
| 101 |
version ( "110" ); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
function TestCase(n, d, e, a) |
| 106 |
{ |
| 107 |
this.path = (typeof gTestPath == 'undefined') ? |
| 108 |
(gTestsuite + '/' + gTestsubsuite + '/' + gTestfile) : |
| 109 |
gTestPath; |
| 110 |
this.file = gTestfile; |
| 111 |
this.name = n; |
| 112 |
this.description = d; |
| 113 |
this.expect = e; |
| 114 |
this.actual = a; |
| 115 |
this.passed = getTestCaseResult(e, a); |
| 116 |
this.reason = ''; |
| 117 |
this.bugnumber = typeof(BUGNUMER) != 'undefined' ? BUGNUMBER : ''; |
| 118 |
this.type = (typeof window == 'undefined' ? 'shell' : 'browser'); |
| 119 |
gTestcases[gTc++] = this; |
| 120 |
} |
| 121 |
|
| 122 |
TestCase.prototype.dump = function () { |
| 123 |
dump('\njstest: ' + this.path + ' ' + |
| 124 |
'bug: ' + this.bugnumber + ' ' + |
| 125 |
'result: ' + (this.passed ? 'PASSED':'FAILED') + ' ' + |
| 126 |
'type: ' + this.type + ' ' + |
| 127 |
'description: ' + toPrinted(this.description) + ' ' + |
| 128 |
|
| 129 |
|
| 130 |
'reason: ' + toPrinted(this.reason) + '\n'); |
| 131 |
}; |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
function expectExitCode(n) |
| 138 |
{ |
| 139 |
print('--- NOTE: IN THIS TESTCASE, WE EXPECT EXIT CODE ' + n + ' ---'); |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
function inSection(x) |
| 146 |
{ |
| 147 |
return SECT_PREFIX + x + SECT_SUFFIX; |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
function reportFailure (msg) |
| 154 |
{ |
| 155 |
var lines = msg.split ("\n"); |
| 156 |
var l; |
| 157 |
var funcName = currentFunc(); |
| 158 |
var prefix = (funcName) ? "[reported from " + funcName + "] ": ""; |
| 159 |
|
| 160 |
for (var i=0; i<lines.length; i++) |
| 161 |
print (FAILED + prefix + lines[i]); |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
function printStatus (msg) |
| 168 |
{ |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
msg = msg.toString(); |
| 174 |
var lines = msg.split ("\n"); |
| 175 |
var l; |
| 176 |
|
| 177 |
for (var i=0; i<lines.length; i++) |
| 178 |
print (STATUS + lines[i]); |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
function printBugNumber (num) |
| 185 |
{ |
| 186 |
BUGNUMBER = num; |
| 187 |
print ('BUGNUMBER: ' + num); |
| 188 |
} |
| 189 |
|
| 190 |
function toPrinted(value) |
| 191 |
{ |
| 192 |
if (typeof value == "xml") |
| 193 |
{ |
| 194 |
value = value.toXMLString(); |
| 195 |
} |
| 196 |
else |
| 197 |
{ |
| 198 |
value = String(value); |
| 199 |
} |
| 200 |
value = value.replace(/\\n/g, 'NL') |
| 201 |
.replace(/\n/g, 'NL') |
| 202 |
.replace(/\\r/g, 'CR') |
| 203 |
.replace(/[^\x20-\x7E]+/g, escapeString); |
| 204 |
return value; |
| 205 |
} |
| 206 |
|
| 207 |
function escapeString (str) |
| 208 |
{ |
| 209 |
var a, b, c, d; |
| 210 |
var len = str.length; |
| 211 |
var result = ""; |
| 212 |
var digits = ["0", "1", "2", "3", "4", "5", "6", "7", |
| 213 |
"8", "9", "A", "B", "C", "D", "E", "F"]; |
| 214 |
|
| 215 |
for (var i=0; i<len; i++) |
| 216 |
{ |
| 217 |
var ch = str.charCodeAt(i); |
| 218 |
|
| 219 |
a = digits[ch & 0xf]; |
| 220 |
ch >>= 4; |
| 221 |
b = digits[ch & 0xf]; |
| 222 |
ch >>= 4; |
| 223 |
|
| 224 |
if (ch) |
| 225 |
{ |
| 226 |
c = digits[ch & 0xf]; |
| 227 |
ch >>= 4; |
| 228 |
d = digits[ch & 0xf]; |
| 229 |
|
| 230 |
result += "\\u" + d + c + b + a; |
| 231 |
} |
| 232 |
else |
| 233 |
{ |
| 234 |
result += "\\x" + b + a; |
| 235 |
} |
| 236 |
} |
| 237 |
|
| 238 |
return result; |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
if (typeof assertEq == 'undefined') |
| 247 |
{ |
| 248 |
var assertEq = |
| 249 |
function (actual, expected) |
| 250 |
{ |
| 251 |
if (actual !== expected) |
| 252 |
{ |
| 253 |
throw new TypeError('Assertion failed: got "' + actual + '", expected "' + expected); |
| 254 |
} |
| 255 |
}; |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
function reportCompare (expected, actual, description) { |
| 264 |
var expected_t = typeof expected; |
| 265 |
var actual_t = typeof actual; |
| 266 |
var output = ""; |
| 267 |
|
| 268 |
if (typeof description == "undefined") |
| 269 |
{ |
| 270 |
description = ''; |
| 271 |
} |
| 272 |
else if (VERBOSE) |
| 273 |
{ |
| 274 |
printStatus ("Comparing '" + description + "'"); |
| 275 |
} |
| 276 |
|
| 277 |
if (expected_t != actual_t) |
| 278 |
{ |
| 279 |
output += "Type mismatch, expected type " + expected_t + |
| 280 |
", actual type " + actual_t + " "; |
| 281 |
} |
| 282 |
else if (VERBOSE) |
| 283 |
{ |
| 284 |
printStatus ("Expected type '" + expected_t + "' matched actual " + |
| 285 |
"type '" + actual_t + "'"); |
| 286 |
} |
| 287 |
|
| 288 |
if (expected != actual) |
| 289 |
{ |
| 290 |
output += "Expected value '" + toPrinted(expected) + |
| 291 |
"', Actual value '" + toPrinted(actual) + "' "; |
| 292 |
} |
| 293 |
else if (VERBOSE) |
| 294 |
{ |
| 295 |
printStatus ("Expected value '" + toPrinted(expected) + |
| 296 |
"' matched actual value '" + toPrinted(actual) + "'"); |
| 297 |
} |
| 298 |
|
| 299 |
var testcase = new TestCase(gTestfile, description, expected, actual); |
| 300 |
testcase.reason = output; |
| 301 |
|
| 302 |
if (testcase.passed) |
| 303 |
{ |
| 304 |
print(PASSED + description); |
| 305 |
} |
| 306 |
else |
| 307 |
{ |
| 308 |
reportFailure (description + " : " + output); |
| 309 |
} |
| 310 |
|
| 311 |
return testcase.passed; |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
function reportMatch (expectedRegExp, actual, description) { |
| 321 |
var expected_t = "string"; |
| 322 |
var actual_t = typeof actual; |
| 323 |
var output = ""; |
| 324 |
|
| 325 |
if (typeof description == "undefined") |
| 326 |
{ |
| 327 |
description = ''; |
| 328 |
} |
| 329 |
else if (VERBOSE) |
| 330 |
{ |
| 331 |
printStatus ("Comparing '" + description + "'"); |
| 332 |
} |
| 333 |
|
| 334 |
if (expected_t != actual_t) |
| 335 |
{ |
| 336 |
output += "Type mismatch, expected type " + expected_t + |
| 337 |
", actual type " + actual_t + " "; |
| 338 |
} |
| 339 |
else if (VERBOSE) |
| 340 |
{ |
| 341 |
printStatus ("Expected type '" + expected_t + "' matched actual " + |
| 342 |
"type '" + actual_t + "'"); |
| 343 |
} |
| 344 |
|
| 345 |
var matches = expectedRegExp.test(actual); |
| 346 |
if (!matches) |
| 347 |
{ |
| 348 |
output += "Expected match to '" + toPrinted(expectedRegExp) + |
| 349 |
"', Actual value '" + toPrinted(actual) + "' "; |
| 350 |
} |
| 351 |
else if (VERBOSE) |
| 352 |
{ |
| 353 |
printStatus ("Expected match to '" + toPrinted(expectedRegExp) + |
| 354 |
"' matched actual value '" + toPrinted(actual) + "'"); |
| 355 |
} |
| 356 |
|
| 357 |
var testcase = new TestCase(gTestfile, description, true, matches); |
| 358 |
testcase.reason = output; |
| 359 |
|
| 360 |
if (testcase.passed) |
| 361 |
{ |
| 362 |
print(PASSED + description); |
| 363 |
} |
| 364 |
else |
| 365 |
{ |
| 366 |
reportFailure (description + " : " + output); |
| 367 |
} |
| 368 |
|
| 369 |
return testcase.passed; |
| 370 |
} |
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
function enterFunc (funcName) |
| 377 |
{ |
| 378 |
if (!funcName.match(/\(\)$/)) |
| 379 |
funcName += "()"; |
| 380 |
|
| 381 |
callStack.push(funcName); |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
function exitFunc (funcName) |
| 389 |
{ |
| 390 |
var lastFunc = callStack.pop(); |
| 391 |
|
| 392 |
if (funcName) |
| 393 |
{ |
| 394 |
if (!funcName.match(/\(\)$/)) |
| 395 |
funcName += "()"; |
| 396 |
|
| 397 |
if (lastFunc != funcName) |
| 398 |
reportCompare(funcName, lastFunc, "Test driver failure wrong exit function "); |
| 399 |
} |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
function currentFunc() |
| 406 |
{ |
| 407 |
return callStack[callStack.length - 1]; |
| 408 |
} |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
function BigO(data) |
| 416 |
{ |
| 417 |
var order = 0; |
| 418 |
var origLength = data.X.length; |
| 419 |
|
| 420 |
while (data.X.length > 2) |
| 421 |
{ |
| 422 |
var lr = new LinearRegression(data); |
| 423 |
if (lr.b > 1e-6) |
| 424 |
{ |
| 425 |
|
| 426 |
|
| 427 |
order++; |
| 428 |
} |
| 429 |
|
| 430 |
if (lr.r > 0.98 || lr.Syx < 1 || lr.b < 1e-6) |
| 431 |
{ |
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
break; |
| 436 |
} |
| 437 |
data = dataDeriv(data); |
| 438 |
} |
| 439 |
|
| 440 |
if (2 == origLength - order) |
| 441 |
{ |
| 442 |
order = Number.POSITIVE_INFINITY; |
| 443 |
} |
| 444 |
return order; |
| 445 |
|
| 446 |
function LinearRegression(data) |
| 447 |
{ |
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
var i; |
| 456 |
|
| 457 |
if (data.X.length != data.Y.length) |
| 458 |
{ |
| 459 |
throw 'LinearRegression: data point length mismatch'; |
| 460 |
} |
| 461 |
if (data.X.length < 3) |
| 462 |
{ |
| 463 |
throw 'LinearRegression: data point length < 2'; |
| 464 |
} |
| 465 |
var n = data.X.length; |
| 466 |
var X = data.X; |
| 467 |
var Y = data.Y; |
| 468 |
|
| 469 |
this.Xavg = 0; |
| 470 |
this.Yavg = 0; |
| 471 |
|
| 472 |
var SUM_X = 0; |
| 473 |
var SUM_XY = 0; |
| 474 |
var SUM_XX = 0; |
| 475 |
var SUM_Y = 0; |
| 476 |
var SUM_YY = 0; |
| 477 |
|
| 478 |
for (i = 0; i < n; i++) |
| 479 |
{ |
| 480 |
SUM_X += X[i]; |
| 481 |
SUM_XY += X[i]*Y[i]; |
| 482 |
SUM_XX += X[i]*X[i]; |
| 483 |
SUM_Y += Y[i]; |
| 484 |
SUM_YY += Y[i]*Y[i]; |
| 485 |
} |
| 486 |
|
| 487 |
this.b = (n * SUM_XY - SUM_X * SUM_Y)/(n * SUM_XX - SUM_X * SUM_X); |
| 488 |
this.a = (SUM_Y - this.b * SUM_X)/n; |
| 489 |
|
| 490 |
this.Xavg = SUM_X/n; |
| 491 |
this.Yavg = SUM_Y/n; |
| 492 |
|
| 493 |
var SUM_Ydiff2 = 0; |
| 494 |
var SUM_Xdiff2 = 0; |
| 495 |
var SUM_XdiffYdiff = 0; |
| 496 |
|
| 497 |
for (i = 0; i < n; i++) |
| 498 |
{ |
| 499 |
var Ydiff = Y[i] - this.Yavg; |
| 500 |
var Xdiff = X[i] - this.Xavg; |
| 501 |
|
| 502 |
SUM_Ydiff2 += Ydiff * Ydiff; |
| 503 |
SUM_Xdiff2 += Xdiff * Xdiff; |
| 504 |
SUM_XdiffYdiff += Xdiff * Ydiff; |
| 505 |
} |
| 506 |
|
| 507 |
var Syx2 = (SUM_Ydiff2 - Math.pow(SUM_XdiffYdiff/SUM_Xdiff2, 2))/(n - 2); |
| 508 |
var r2 = Math.pow((n*SUM_XY - SUM_X * SUM_Y), 2) / |
| 509 |
((n*SUM_XX - SUM_X*SUM_X)*(n*SUM_YY-SUM_Y*SUM_Y)); |
| 510 |
|
| 511 |
this.Syx = Math.sqrt(Syx2); |
| 512 |
this.r = Math.sqrt(r2); |
| 513 |
|
| 514 |
} |
| 515 |
|
| 516 |
function dataDeriv(data) |
| 517 |
{ |
| 518 |
if (data.X.length != data.Y.length) |
| 519 |
{ |
| 520 |
throw 'length mismatch'; |
| 521 |
} |
| 522 |
var length = data.X.length; |
| 523 |
|
| 524 |
if (length < 2) |
| 525 |
{ |
| 526 |
throw 'length ' + length + ' must be >= 2'; |
| 527 |
} |
| 528 |
var X = data.X; |
| 529 |
var Y = data.Y; |
| 530 |
|
| 531 |
var deriv = {X: [], Y: [] }; |
| 532 |
|
| 533 |
for (var i = 0; i < length - 1; i++) |
| 534 |
{ |
| 535 |
deriv.X[i] = (X[i] + X[i+1])/2; |
| 536 |
deriv.Y[i] = (Y[i+1] - Y[i])/(X[i+1] - X[i]); |
| 537 |
} |
| 538 |
return deriv; |
| 539 |
} |
| 540 |
|
| 541 |
return 0; |
| 542 |
} |
| 543 |
|
| 544 |
function compareSource(expect, actual, summary) |
| 545 |
{ |
| 546 |
|
| 547 |
var expectP = expect. |
| 548 |
replace(/([(){},.:\[\]])/mg, ' $1 '). |
| 549 |
replace(/(\w+)/mg, ' $1 '). |
| 550 |
replace(/<(\/)? (\w+) (\/)?>/mg, '<$1$2$3>'). |
| 551 |
replace(/\s+/mg, ' '). |
| 552 |
replace(/new (\w+)\s*\(\s*\)/mg, 'new $1'); |
| 553 |
|
| 554 |
var actualP = actual. |
| 555 |
replace(/([(){},.:\[\]])/mg, ' $1 '). |
| 556 |
replace(/(\w+)/mg, ' $1 '). |
| 557 |
replace(/<(\/)? (\w+) (\/)?>/mg, '<$1$2$3>'). |
| 558 |
replace(/\s+/mg, ' '). |
| 559 |
replace(/new (\w+)\s*\(\s*\)/mg, 'new $1'); |
| 560 |
|
| 561 |
print('expect:\n' + expectP); |
| 562 |
print('actual:\n' + actualP); |
| 563 |
|
| 564 |
reportCompare(expectP, actualP, summary); |
| 565 |
|
| 566 |
|
| 567 |
try |
| 568 |
{ |
| 569 |
var expectCompile = 'No Error'; |
| 570 |
var actualCompile; |
| 571 |
|
| 572 |
eval(expect); |
| 573 |
try |
| 574 |
{ |
| 575 |
eval(actual); |
| 576 |
actualCompile = 'No Error'; |
| 577 |
} |
| 578 |
catch(ex1) |
| 579 |
{ |
| 580 |
actualCompile = ex1 + ''; |
| 581 |
} |
| 582 |
reportCompare(expectCompile, actualCompile, |
| 583 |
summary + ': compile actual'); |
| 584 |
} |
| 585 |
catch(ex) |
| 586 |
{ |
| 587 |
} |
| 588 |
} |
| 589 |
|
| 590 |
function optionsInit() { |
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
options.initvalues = {}; |
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
options.stackvalues = []; |
| 599 |
|
| 600 |
var optionNames = options().split(','); |
| 601 |
|
| 602 |
for (var i = 0; i < optionNames.length; i++) |
| 603 |
{ |
| 604 |
var optionName = optionNames[i]; |
| 605 |
if (optionName) |
| 606 |
{ |
| 607 |
options.initvalues[optionName] = ''; |
| 608 |
} |
| 609 |
} |
| 610 |
} |
| 611 |
|
| 612 |
function optionsClear() { |
| 613 |
|
| 614 |
|
| 615 |
var optionNames = options().split(','); |
| 616 |
for (var i = 0; i < optionNames.length; i++) |
| 617 |
{ |
| 618 |
var optionName = optionNames[i]; |
| 619 |
if (optionName) |
| 620 |
{ |
| 621 |
options(optionName); |
| 622 |
} |
| 623 |
} |
| 624 |
} |
| 625 |
|
| 626 |
function optionsPush() |
| 627 |
{ |
| 628 |
var optionsframe = {}; |
| 629 |
|
| 630 |
options.stackvalues.push(optionsframe); |
| 631 |
|
| 632 |
var optionNames = options().split(','); |
| 633 |
|
| 634 |
for (var i = 0; i < optionNames.length; i++) |
| 635 |
{ |
| 636 |
var optionName = optionNames[i]; |
| 637 |
if (optionName) |
| 638 |
{ |
| 639 |
optionsframe[optionName] = ''; |
| 640 |
} |
| 641 |
} |
| 642 |
|
| 643 |
optionsClear(); |
| 644 |
} |
| 645 |
|
| 646 |
function optionsPop() |
| 647 |
{ |
| 648 |
var optionsframe = options.stackvalues.pop(); |
| 649 |
|
| 650 |
optionsClear(); |
| 651 |
|
| 652 |
for (optionName in optionsframe) |
| 653 |
{ |
| 654 |
options(optionName); |
| 655 |
} |
| 656 |
|
| 657 |
} |
| 658 |
|
| 659 |
function optionsReset() { |
| 660 |
|
| 661 |
try |
| 662 |
{ |
| 663 |
optionsClear(); |
| 664 |
|
| 665 |
|
| 666 |
for (optionName in options.initvalues) |
| 667 |
{ |
| 668 |
options(optionName); |
| 669 |
} |
| 670 |
} |
| 671 |
catch(ex) |
| 672 |
{ |
| 673 |
print('optionsReset: caught ' + ex); |
| 674 |
} |
| 675 |
|
| 676 |
} |
| 677 |
|
| 678 |
if (typeof options == 'function') |
| 679 |
{ |
| 680 |
optionsInit(); |
| 681 |
optionsClear(); |
| 682 |
} |
| 683 |
|
| 684 |
function getTestCaseResult(expected, actual) |
| 685 |
{ |
| 686 |
if (typeof expected != typeof actual) |
| 687 |
return false; |
| 688 |
if (typeof expected != 'number') |
| 689 |
|
| 690 |
return actual == expected; |
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
if (actual != actual) |
| 695 |
return expected != expected; |
| 696 |
if (expected != expected) |
| 697 |
return false; |
| 698 |
|
| 699 |
|
| 700 |
if (actual != expected) |
| 701 |
return Math.abs(actual - expected) <= 1E-10; |
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
return true; |
| 710 |
} |
| 711 |
|
| 712 |
if (typeof dump == 'undefined') |
| 713 |
{ |
| 714 |
if (typeof window == 'undefined' && |
| 715 |
typeof print == 'function') |
| 716 |
{ |
| 717 |
dump = print; |
| 718 |
} |
| 719 |
else |
| 720 |
{ |
| 721 |
dump = (function () {}); |
| 722 |
} |
| 723 |
} |
| 724 |
|
| 725 |
function test() { |
| 726 |
for ( gTc=0; gTc < gTestcases.length; gTc++ ) { |
| 727 |
|
| 728 |
try |
| 729 |
{ |
| 730 |
gTestcases[gTc].passed = writeTestCaseResult( |
| 731 |
gTestcases[gTc].expect, |
| 732 |
gTestcases[gTc].actual, |
| 733 |
gTestcases[gTc].description +" = "+ gTestcases[gTc].actual ); |
| 734 |
gTestcases[gTc].reason += ( gTestcases[gTc].passed ) ? "" : "wrong value "; |
| 735 |
} |
| 736 |
catch(e) |
| 737 |
{ |
| 738 |
print('test(): empty testcase for gTc = ' + gTc + ' ' + e); |
| 739 |
} |
| 740 |
} |
| 741 |
stopTest(); |
| 742 |
return ( gTestcases ); |
| 743 |
} |
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
function writeTestCaseResult( expect, actual, string ) { |
| 753 |
var passed = getTestCaseResult( expect, actual ); |
| 754 |
writeFormattedResult( expect, actual, string, passed ); |
| 755 |
return passed; |
| 756 |
} |
| 757 |
function writeFormattedResult( expect, actual, string, passed ) { |
| 758 |
var s = ( passed ? PASSED : FAILED ) + string + ' expected: ' + expect; |
| 759 |
print(s); |
| 760 |
return passed; |
| 761 |
} |
| 762 |
|
| 763 |
function writeHeaderToLog( string ) { |
| 764 |
print( string ); |
| 765 |
} |
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
function stopTest() { |
| 775 |
var gc; |
| 776 |
if ( gc != undefined ) { |
| 777 |
gc(); |
| 778 |
} |
| 779 |
} |
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
function getFailedCases() { |
| 787 |
for ( var i = 0; i < gTestcases.length; i++ ) { |
| 788 |
if ( ! gTestcases[i].passed ) { |
| 789 |
print( gTestcases[i].description + " = " +gTestcases[i].actual + |
| 790 |
" expected: " + gTestcases[i].expect ); |
| 791 |
} |
| 792 |
} |
| 793 |
} |
| 794 |
|
| 795 |
function jsTestDriverEnd() |
| 796 |
{ |
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
if (gDelayTestDriverEnd) |
| 806 |
{ |
| 807 |
return; |
| 808 |
} |
| 809 |
|
| 810 |
try |
| 811 |
{ |
| 812 |
optionsReset(); |
| 813 |
} |
| 814 |
catch(ex) |
| 815 |
{ |
| 816 |
dump('jsTestDriverEnd ' + ex); |
| 817 |
} |
| 818 |
|
| 819 |
for (var i = 0; i < gTestcases.length; i++) |
| 820 |
{ |
| 821 |
gTestcases[i].dump(); |
| 822 |
} |
| 823 |
|
| 824 |
} |
| 825 |
|
| 826 |
function jit(on) |
| 827 |
{ |
| 828 |
if (on && !options().match(/jit/)) |
| 829 |
{ |
| 830 |
options('jit'); |
| 831 |
} |
| 832 |
else if (!on && options().match(/jit/)) |
| 833 |
{ |
| 834 |
options('jit'); |
| 835 |
} |
| 836 |
} |
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
function inRhino() |
| 842 |
{ |
| 843 |
return (typeof defineClass == "function"); |
| 844 |
} |
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
function GetContext() { |
| 849 |
return Packages.com.netscape.javascript.Context.getCurrentContext(); |
| 850 |
} |
| 851 |
function OptLevel( i ) { |
| 852 |
i = Number(i); |
| 853 |
var cx = GetContext(); |
| 854 |
cx.setOptimizationLevel(i); |
| 855 |
} |
| 856 |
|
| 857 |
|
| 858 |
|