Update with current status
[gnash.git] / testsuite / misc-haxe.all / classes.all / Boolean_as.hx
blob69d973b06cab9f9845dcd80f03e7c82966531efd
1 // Boolean_as.hx: ActionScript 3 "Boolean" class, for Gnash.
2 //
3 // Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software
4 // Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 // Test case for Boolean ActionScript class
22 // Migrated to haXe by Jonathan Crider
24 #if flash9
25 import flash.display.MovieClip;
26 #else
27 import flash.MovieClip;
28 #end
30 import flash.Lib;
31 import Type;
32 import Reflect;
33 import Std;
35 // importing our testing api
36 import DejaGnu;
38 class Boolean_as {
39 static function main() {
41 //NOTE: These tests do not compile in swf version 9. This is due to the way
42 // in which haxe implements a Bool. Compilation in swf9 gives the error
43 // 'Unbound variable Boolean' at each place the Boolean name is used.
44 // So far I have been unable to find a workaround for this. For now we
45 // will be unable to compile these test for flash9.
46 #if flash9
47 DejaGnu.note("These tests do not currently compile in flash version 9: see comments in Boolean_as.hx");
49 #else
51 //check_equals(typeof(Boolean), 'function');
52 if ( untyped __typeof__(Boolean) == 'function') {
53 DejaGnu.pass("Boolean class exists");
54 } else {
55 DejaGnu.fail("Boolean class does not exist");
57 //check_equals(typeof(Boolean()), 'undefined');
58 if ( untyped __typeof__(Boolean()) == 'undefined') {
59 DejaGnu.pass("Call to Boolean() returns null");
60 } else {
61 DejaGnu.fail("Call to Boolean() does not return null");
63 //check_equals(typeof(Boolean(true)), 'boolean');
64 if ( untyped __typeof__(Boolean(true)) == 'boolean') {
65 DejaGnu.pass("Boolean(true) correctly returns a boolean value");
66 } else {
67 DejaGnu.fail("Boolean(true) does not return a boolean value");
69 //check_equals(typeof(new Boolean()), 'object');
70 if (Reflect.isObject(untyped __new__(Boolean))) {
71 DejaGnu.pass("new Boolean(); correctly constructs an object");
72 } else {
73 DejaGnu.fail("new Boolean(); does not correctly construct an object");
76 //var boolObj = new Boolean;
77 var boolObj = untyped __new__(Boolean);
79 // test the Boolean constuctor
80 //check (boolObj);
81 if (boolObj ) {
82 DejaGnu.pass("Boolean object successfully constructed and assigned");
83 } else {
84 DejaGnu.fail("Boolean object not successfully constructed or assigned");
87 //check (boolObj.toString);
88 if (untyped boolObj.toString) {
89 DejaGnu.pass("boolObj.toString() inherited correctly");
90 } else {
91 DejaGnu.fail("boolObj.toString() was not inherited correctly");
93 //check (boolObj.valueOf);
94 if (untyped boolObj.valueOf) {
95 DejaGnu.pass("boolObj.valueOf() inherited correctly");
96 } else {
97 DejaGnu.fail("boolObj.valueOf() not inherited correctly");
101 #if flash6
102 // flash6 is not case sensitive
103 //check (boolObj.tostring)
104 if (untyped boolObj.tostring) {
105 DejaGnu.pass("boolObj.tostring property exists (Not Case Sensitive)");
106 } else {
107 DejaGnu.fail("boolObj.tostring property does not exist");
109 //check (boolObj.valueof)
110 if (untyped boolObj.valueof) {
111 DejaGnu.pass("boolObj.valueof property exists (Not Case Sensitive)");
112 } else {
113 DejaGnu.fail("boolObj.valueof property does not exist");
115 #else
116 // SWF7 and up is case-sensitive
117 //check_equals (boolObj.tostring, undefined);
118 if (Type.typeof(untyped boolObj.tostring) == ValueType.TNull) {
119 DejaGnu.pass("tostring property does not exist (Case Sensitive)");
120 } else {
121 DejaGnu.fail("tostring property exists when it should not");
123 //check_equals (boolObj.valueof, undefined);
124 if (Type.typeof(untyped boolObj.valueof) == ValueType.TNull) {
125 DejaGnu.pass("valueof property does not exist (Case Sensitive)");
126 } else {
127 DejaGnu.fail("valueof property exists when it should not");
129 #end
131 //var defaultBool = new Boolean();
132 var defaultBool = untyped __new__(Boolean);
133 //check_equals(defaultBool.toString(), "false");
134 if (untyped defaultBool.toString() == "false") {
135 DejaGnu.pass("Default constructor correctly sets value to false");
136 } else {
137 DejaGnu.fail("Default constructor does not set value to false");
139 //check_equals(defaultBool.valueOf(), false);
140 if (untyped defaultBool.valueOf() == false) {
141 DejaGnu.pass("Default valueOf() correctly returns false");
142 } else {
143 DejaGnu.fail("Default valueOf() does not return false");
146 //var trueBool = new Boolean(true);
147 var trueBool = untyped __new__(Boolean, true);
148 //check_equals(trueBool.toString(), "true");
149 if (untyped trueBool.toString() == "true") {
150 DejaGnu.pass("Correctly constructed Boolean with value 'true'");
151 } else {
152 DejaGnu.fail("Did not correctly construct Boolean with value 'true'");
154 //check_equals(trueBool.valueOf(), true);
155 if (untyped trueBool.valueOf() == true) {
156 DejaGnu.pass("trueBool.valueOf() correctly returned true");
157 } else {
158 DejaGnu.fail("trueBool.valueOf() did not correctly return true");
161 //var falseBool = new Boolean(false);
162 var falseBool = untyped __new__(Boolean, false);
163 //check_equals(falseBool.toString(), "false");
164 if (untyped falseBool.toString() == "false") {
165 DejaGnu.pass("Boolean correctly constructed with argument 'false'");
166 } else {
167 DejaGnu.fail("Boolean not correctly constructed with argument 'false'");
169 //check_equals(falseBool.valueOf(), false);
170 if (untyped falseBool.valueOf() == false) {
171 DejaGnu.pass("falseBool.valueOf() correctly returned false");
172 } else {
173 DejaGnu.fail("falseBool.valueOf() did not correctly return false");
177 //---------------------------------------------------
178 // Test convertion to boolean
179 //---------------------------------------------------
180 DejaGnu.note("*** Begin testing convertion to Boolean");
182 // boolean
183 //check( true );
184 if (true) {
185 DejaGnu.pass("keyword 'true' correctly evaluates to true");
186 } else {
187 DejaGnu.fail("keyword 'true' does not correctly evaluate to true");
189 //check( ! false );
190 if ( ! false ) {
191 DejaGnu.pass("expression '! false' correctly evaluates to true");
192 } else {
193 DejaGnu.fail("expression '! false' did not evaluate to true");
196 // number
197 //check( 1 );
198 if (untyped 1) {
199 DejaGnu.pass("expression '1' correctly evaluates to true");
200 } else {
201 DejaGnu.fail("expression '1' did not correctly evaluate to true");
204 if (untyped 0) {
205 DejaGnu.fail("expression '0' evaluated to true");
206 } else {
207 DejaGnu.pass("expression '0' evaluated to false");
209 //check( !0 );
210 if ( untyped !0 ) {
211 DejaGnu.pass("expression '!0' correctly evaluates to true");
212 } else {
213 DejaGnu.fail("expression '!0' did not evaluate to true");
216 // movieclip
217 //check( _root );
218 if (untyped flash.Lib.current) {
219 DejaGnu.pass("_root; (flash.lib.current in haxe) evaluated true");
220 } else {
221 DejaGnu.fail("_root; (flash.lib.current in haxe) evaluated false");
224 // string
225 //check( "1" );
226 if (untyped "1") {
227 DejaGnu.pass("String expression '1' evaluated true");
228 } else {
229 DejaGnu.fail("String expression '1' did not evaluate true");
231 //#if OUTPUT_VERSION < 7
232 #if flash6
233 //check( ! "0" );
234 if ( untyped !"0" ) {
235 DejaGnu.pass("string expression !'0' evaluated true");
236 } else {
237 DejaGnu.fail("string expression !'0' did not evaluate true");
239 //check( ! "true" );
240 if ( untyped !"true") {
241 DejaGnu.pass("string expression !'true' evaluated true");
242 } else {
243 DejaGnu.fail("string expression !'true' did not evaluate true");
245 //check( ! "false" );
246 if ( untyped !"false") {
247 DejaGnu.pass("string expression !'false' evaluated true");
248 } else {
249 DejaGnu.fail("string expression !'false' did not evaluate true");
251 #else
252 //check( "0" );
253 if ( untyped "0" ) {
254 DejaGnu.pass("string expression '0' evaluated true");
255 } else {
256 DejaGnu.fail("string expression '0' did not evaluate true");
258 //check( "true" );
259 if ( untyped "true" ) {
260 DejaGnu.pass("string expression 'true' evaluated true");
261 } else {
262 DejaGnu.fail("string expression 'true' did not evaluate true");
264 //check( "false" );
265 if ( untyped "false" ) {
266 DejaGnu.pass("string expression 'false' evaluated true");
267 } else {
268 DejaGnu.fail("string expression 'false' did not evaluate true");
270 //#endif
271 #end
273 // Null
274 //check_equals(typeOf(null), "null" );
275 if (untyped __typeof__(null) == "null") {
276 DejaGnu.pass("typeof null is null");
277 } else {
278 DejaGnu.fail("typeof null is not null");
280 //check( ! null );
281 if ( ! null ) {
282 DejaGnu.pass("expression '!null' evaluates to true");
283 } else {
284 DejaGnu.fail("expression '!null' did not evaluate to true");
287 // Undefined
288 //check( ! undefined );
289 if ( !(untyped undefined) ) {
290 DejaGnu.pass("expression '! undefined' evaluates to true");
291 } else {
292 DejaGnu.fail("expression '! undefined' did not evaluate to true");
295 // Function
296 //var playfunc = untyped __global__["play"];
297 //check( play );
298 if ( untyped play ) {
299 DejaGnu.pass("Global function play evaluates to true");
300 } else {
301 DejaGnu.fail("Global function play does not evaluate to true");
304 // Object - conversion might depend on object type
305 //emptyArray = new Array();
306 var emptyArray = untyped __new__(Array);
307 //check( emptyArray );
308 if ( emptyArray ) {
309 DejaGnu.pass("emptyArray object evaluates to true");
310 } else {
311 DejaGnu.fail("emptyArray object does not evaluate to true");
314 #end //end if !flash9
317 //NOTE: may need to retain Ming tests at the end of the file somehow
319 DejaGnu.done();
323 //NOTE: Haxe does not give acces to the Boolean class directly.
324 // In haXe Bool is an Enum value and does all the processing in the
325 // background.