michael@0: var completed = false; michael@0: var testcases; michael@0: michael@0: var BUGNUMBER=""; michael@0: var EXCLUDE = ""; michael@0: michael@0: var TT = ""; michael@0: var TT_ = ""; michael@0: var BR = ""; michael@0: var NBSP = " "; michael@0: var CR = "\n"; michael@0: var FONT = ""; michael@0: var FONT_ = ""; michael@0: var FONT_RED = ""; michael@0: var FONT_GREEN = ""; michael@0: var B = ""; michael@0: var B_ = "" michael@0: var H2 = ""; michael@0: var H2_ = ""; michael@0: var HR = ""; michael@0: michael@0: var PASSED = " PASSED!" michael@0: var FAILED = " FAILED! expected: "; michael@0: michael@0: version( 140 ); michael@0: function test() { michael@0: for ( tc=0; tc < testcases.length; tc++ ) { michael@0: testcases[tc].passed = writeTestCaseResult( michael@0: testcases[tc].expect, michael@0: testcases[tc].actual, michael@0: testcases[tc].description +" = "+ michael@0: testcases[tc].actual ); michael@0: michael@0: testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; michael@0: } michael@0: stopTest(); michael@0: return ( testcases ); michael@0: } michael@0: function TestCase( n, d, e, a ) { michael@0: this.name = n; michael@0: this.description = d; michael@0: this.expect = e; michael@0: this.actual = a; michael@0: this.passed = true; michael@0: this.reason = ""; michael@0: this.bugnumber = BUGNUMBER; michael@0: michael@0: this.passed = getTestCaseResult( this.expect, this.actual ); michael@0: } michael@0: function startTest() { michael@0: /* michael@0: // JavaScript 1.3 is supposed to be compliant ecma version 1.0 michael@0: if ( VERSION == "ECMA_1" ) { michael@0: version ( "130" ); michael@0: } michael@0: if ( VERSION == "JS_1.3" ) { michael@0: version ( "130" ); michael@0: } michael@0: if ( VERSION == "JS_1.2" ) { michael@0: version ( "120" ); michael@0: } michael@0: if ( VERSION == "JS_1.1" ) { michael@0: version ( "110" ); michael@0: } michael@0: // for ecma version 2.0, we will leave the javascript version to michael@0: // the default ( for now ). michael@0: */ michael@0: } michael@0: function getTestCaseResult( expect, actual ) { michael@0: // because ( NaN == NaN ) always returns false, need to do michael@0: // a special compare to see if we got the right result. michael@0: if ( actual != actual ) { michael@0: if ( typeof actual == "object" ) { michael@0: actual = "NaN object"; michael@0: } else { michael@0: actual = "NaN number"; michael@0: } michael@0: } michael@0: if ( expect != expect ) { michael@0: if ( typeof expect == "object" ) { michael@0: expect = "NaN object"; michael@0: } else { michael@0: expect = "NaN number"; michael@0: } michael@0: } michael@0: michael@0: var passed = ( expect == actual ) ? true : false; michael@0: michael@0: // if both objects are numbers, give a little leeway for rounding. michael@0: if ( !passed michael@0: && typeof(actual) == "number" michael@0: && typeof(expect) == "number" michael@0: ) { michael@0: if ( Math.abs(actual-expect) < 0.0000001 ) { michael@0: passed = true; michael@0: } michael@0: } michael@0: michael@0: // verify type is the same michael@0: if ( typeof(expect) != typeof(actual) ) { michael@0: passed = false; michael@0: } michael@0: michael@0: return passed; michael@0: } michael@0: function writeTestCaseResult( expect, actual, string ) { michael@0: var passed = getTestCaseResult( expect, actual ); michael@0: writeFormattedResult( expect, actual, string, passed ); michael@0: return passed; michael@0: } michael@0: function writeFormattedResult( expect, actual, string, passed ) { michael@0: var s = TT + string ; michael@0: michael@0: for ( k = 0; michael@0: k < (60 - string.length >= 0 ? 60 - string.length : 5) ; michael@0: k++ ) { michael@0: // s += NBSP; michael@0: } michael@0: michael@0: s += B ; michael@0: s += ( passed ) ? FONT_GREEN + NBSP + PASSED : FONT_RED + NBSP + FAILED + expect + TT_ ; michael@0: michael@0: print( s + FONT_ + B_ + TT_ ); michael@0: michael@0: return passed; michael@0: } michael@0: michael@0: function writeHeaderToLog( string ) { michael@0: print( H2 + string + H2_ ); michael@0: } michael@0: function stopTest() { michael@0: var sizeTag = "<#TEST CASES SIZE>"; michael@0: var doneTag = "<#TEST CASES DONE>"; michael@0: var beginTag = "<#TEST CASE "; michael@0: var endTag = ">"; michael@0: michael@0: print(sizeTag); michael@0: print(testcases.length); michael@0: for (tc = 0; tc < testcases.length; tc++) michael@0: { michael@0: print(beginTag + 'PASSED' + endTag); michael@0: print(testcases[tc].passed); michael@0: print(beginTag + 'NAME' + endTag); michael@0: print(testcases[tc].name); michael@0: print(beginTag + 'EXPECTED' + endTag); michael@0: print(testcases[tc].expect); michael@0: print(beginTag + 'ACTUAL' + endTag); michael@0: print(testcases[tc].actual); michael@0: print(beginTag + 'DESCRIPTION' + endTag); michael@0: print(testcases[tc].description); michael@0: print(beginTag + 'REASON' + endTag); michael@0: print(( testcases[tc].passed ) ? "" : "wrong value "); michael@0: print(beginTag + 'BUGNUMBER' + endTag); michael@0: print( BUGNUMBER ); michael@0: michael@0: } michael@0: print(doneTag); michael@0: gc(); michael@0: } michael@0: function getFailedCases() { michael@0: for ( var i = 0; i < testcases.length; i++ ) { michael@0: if ( ! testcases[i].passed ) { michael@0: print( testcases[i].description +" = " +testcases[i].actual +" expected: "+ testcases[i].expect ); michael@0: } michael@0: } michael@0: }