Add automated tests on function-type FSCommand parameter passing.
[gnash.git] / testsuite / misc-haxe.all / Dejagnu.hx
blob75ece1c974784f70eadcc51c1edccb6d9bc19c8e
1 // Dejagnu.as - HAXE class for dejagnu-like testing.
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 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
22 import flash.Lib;
23 import flash.text.TextField;
25 class Dejagnu {
26 static var passed = 0;
27 static var failed = 0;
28 static var xpassed = 0;
29 static var xfailed = 0;
30 static var untest = 0;
31 static var unresolve = 0;
33 // This is a trick to force our 'init' function
34 // to be automatically called at the start of the movie.
35 static var inithack = init();
37 static var tf:flash.text.TextField;
39 static function init() {
40 //if(dejagnu_module_initialized == 1) return;
42 // create a textfield to output to
43 tf = new flash.text.TextField();
44 tf.autoSize = flash.text.TextFieldAutoSize.LEFT;
45 //flash.Lib.current.createTextField("textout", 99, 10, 10, 500, 500);
46 flash.Lib.current.addChild(tf);
48 //dejagnu_module_initialized = 1;
50 return null;
53 static function fail (why) {
54 failed++;
55 var msg = 'FAILED: '+why;
56 xtrace(msg);
59 static function xfail(why) {
60 xfailed++;
61 var msg = 'XFAILED: '+why;
62 xtrace(msg);
65 static function pass(why) {
66 passed++;
67 var msg = 'PASSED: '+why;
68 flash.Lib.trace(msg);
71 static function xpass(why) {
72 xpassed++;
73 var msg = 'XPASSED: '+why;
74 flash.Lib.trace(msg);
77 static function testcount() {
78 var c = 0;
79 if ( passed > 0 ) c += passed;
80 if ( failed > 0 ) c += failed;
81 if ( xpassed > 0 ) c += xpassed;
82 if ( xfailed > 0 ) c += xfailed;
83 if ( unresolve > 0 ) c += unresolve;
84 return c;
87 static function printtotals() {
88 xtrace('#passed: '+ passed);
89 xtrace('#failed: '+ failed);
90 if ( xpassed > 0 ) {
91 xtrace('#unexpected successes: '+ xpassed);
93 if ( xfailed > 0 ) {
94 xtrace('#expected failures: '+ xfailed);
96 if ( unresolve > 0) {
97 xtrace('#tests unresolved'+ unresolve);
99 xtrace('#total tests run: '+ testcount());
102 static public function totals(exp:Dynamic, msg:Dynamic) {
103 var obt = testcount();
104 if ( exp != null && obt != exp ) {
105 fail('Test run '+obt+' (expected '+exp+') '+msg);
106 } else {
107 pass('Test run '+obt+' '+msg);
111 static function xtotals(exp:Dynamic, msg:Dynamic) {
112 var obt = testcount();
113 if ( exp != null && obt != exp ) {
114 xfail('Test run '+obt+' (expected '+exp+') ['+msg+']');
115 } else {
116 xpass('Test run '+obt+' ['+msg+']');
120 static public function check_equals(obt:Dynamic, exp:Dynamic, msg) {
121 if(msg == null) msg = "";
122 if ( obt == exp )
123 pass(obt+' == '+exp+' '+msg);
124 else
125 fail('expected: "'+exp+'" , obtained: "'+obt+'" '+msg);
128 static public function xcheck_equals(obt:Dynamic, exp:Dynamic, msg)
130 if(msg == null) msg = "";
131 if ( obt == exp )
133 xpass(obt+' == '+exp+' '+msg);
135 else
137 xfail('expected: '+exp+' , obtained: '+obt+" "+msg);
141 static public function check(a : Dynamic, msg)
143 if ( a )
145 if ( msg != null ) pass(msg);
146 else pass(a);
148 else
150 if ( msg != null ) fail(msg);
151 else fail(a);
155 static public function xcheck(a : Dynamic, msg)
157 if ( a )
159 if ( msg != null ) xpass(msg);
160 else xpass(a);
162 else
164 if ( msg != null ) xfail(msg);
165 else xfail(a);
169 static public function note(msg) {
170 xtrace(msg);
173 static function xtrace(msg) {
174 tf.text += msg + "\n";
175 flash.Lib.trace(msg);
178 static function untested(msg) {
179 flash.Lib.trace("UNTESTED: "+msg);
182 static function unresolved(msg) {
183 unresolve++;
184 flash.Lib.trace("UNRESOLVED: "+msg);
187 static public function done() {
188 printtotals();
189 flash.Lib.trace("__END_OF_TEST__");
190 //loadMovie('fscommand:quit', _root);