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