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