Follow-on fix for bug 457825. Use sheet principal for agent and user sheets. r=dbaron...
[wine-gecko.git] / js / tests / lc3 / jsref.js
blob5a135a25737b5bf13c6537d25a43f35d0f8adce1
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is Mozilla Communicator client code, released
15 * March 31, 1998.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
37 var completed = false;
38 var testcases;
40 SECTION = "";
41 VERSION = "";
42 TITLE = "";
44 BUGNUMBER="";
45 var EXCLUDE = "";
47 var GLOBAL = "[object global]";
48 var TT = "";
49 var TT_ = "";
50 var BR = "";
51 var NBSP = " ";
52 var CR = "\n";
53 var FONT = "";
54 var FONT_ = "";
55 var FONT_RED = "";
56 var FONT_GREEN = "";
57 var B = "";
58 var B_ = ""
59 var H2 = "";
60 var H2_ = "";
61 var HR = "";
63 // version("130");
65 var PASSED = " PASSED!"
66 var FAILED = " FAILED! expected: ";
68 function test() {
69 for ( tc=0; tc < testcases.length; tc++ ) {
70 testcases[tc].passed = writeTestCaseResult(
71 testcases[tc].expect,
72 testcases[tc].actual,
73 testcases[tc].description +" = "+
74 testcases[tc].actual );
76 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
78 stopTest();
79 return ( testcases );
82 function TestCase( d, e, a ) {
83 this.name = SECTION;
84 this.description = d;
85 this.expect = e;
86 this.actual = a;
87 this.passed = true;
88 this.reason = "";
89 this.bugnumber = BUGNUMBER;
91 this.passed = getTestCaseResult( this.expect, this.actual );
94 function startTest() {
95 testcases = new Array();
96 tc = 0;
98 // JavaScript 1.3 is supposed to be compliant ecma version 1.0
99 if ( VERSION == "JS1_4" ) {
100 version( 140 );
102 if ( VERSION == "ECMA_1" ) {
103 version ( "130" );
105 if ( VERSION == "JS1_3" ) {
106 version ( "130" );
108 if ( VERSION == "JS1_2" ) {
109 version ( "120" );
111 if ( VERSION == "JS1_1" ) {
112 version ( "110" );
115 writeHeaderToLog( SECTION + " "+ TITLE);
117 // verify that DataTypeClass is on the CLASSPATH
119 DT = Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass;
121 if ( typeof DT != "function" ) {
122 throw "Test Exception: "+
123 "com.netscape.javascript.qa.liveconnect.DataTypeClass "+
124 "is not on the CLASSPATH";
128 function getTestCaseResult( expect, actual ) {
129 // because ( NaN == NaN ) always returns false, need to do
130 // a special compare to see if we got the right result.
131 if ( actual != actual ) {
132 if ( typeof actual == "object" ) {
133 actual = "NaN object";
134 } else {
135 actual = "NaN number";
138 if ( expect != expect ) {
139 if ( typeof expect == "object" ) {
140 expect = "NaN object";
141 } else {
142 expect = "NaN number";
146 var passed = ( expect == actual ) ? true : false;
148 // if both objects are numbers
149 // need to replace w/ IEEE standard for rounding
150 if ( !passed
151 && typeof(actual) == "number"
152 && typeof(expect) == "number"
154 if ( Math.abs(actual-expect) < 0.0000001 ) {
155 passed = true;
159 // verify type is the same
160 if ( typeof(expect) != typeof(actual) ) {
161 passed = false;
164 return passed;
166 function writeTestCaseResult( expect, actual, string ) {
167 var passed = getTestCaseResult( expect, actual );
168 writeFormattedResult( expect, actual, string, passed );
169 return passed;
171 function writeFormattedResult( expect, actual, string, passed ) {
172 var s = TT + string ;
174 for ( k = 0;
175 k < (60 - string.length >= 0 ? 60 - string.length : 5) ;
176 k++ ) {
177 // s += NBSP;
180 s += B ;
181 s += ( passed ) ? FONT_GREEN + NBSP + PASSED : FONT_RED + NBSP + FAILED + expect + TT_ ;
183 print( s + FONT_ + B_ + TT_ );
185 return passed;
188 function writeHeaderToLog( string ) {
189 print( H2 + string + H2_ );
191 function stopTest()
194 var sizeTag = "<#TEST CASES SIZE>";
195 var doneTag = "<#TEST CASES DONE>";
196 var beginTag = "<#TEST CASE ";
197 var endTag = ">";
199 print(sizeTag);
200 print(testcases.length);
201 for (tc = 0; tc < testcases.length; tc++)
203 print(beginTag + 'PASSED' + endTag);
204 print(testcases[tc].passed);
205 print(beginTag + 'NAME' + endTag);
206 print(testcases[tc].name);
207 print(beginTag + 'EXPECTED' + endTag);
208 print(testcases[tc].expect);
209 print(beginTag + 'ACTUAL' + endTag);
210 print(testcases[tc].actual);
211 print(beginTag + 'DESCRIPTION' + endTag);
212 print(testcases[tc].description);
213 print(beginTag + 'REASON' + endTag);
214 print(( testcases[tc].passed ) ? "" : "wrong value ");
215 print(beginTag + 'BUGNUMBER' + endTag);
216 print( BUGNUMBER );
218 print(doneTag);
220 print( HR );
221 gc();
223 function getFailedCases() {
224 for ( var i = 0; i < testcases.length; i++ ) {
225 if ( ! testcases[i].passed ) {
226 print( testcases[i].description +" = " +testcases[i].actual +" expected: "+ testcases[i].expect );