Update with current status
[gnash.git] / testsuite / misc-haxe.all / classes.all / DejaGnu.hx
blob298722ea79f2f7c6b3a549a3a3299389ab03b27a
1 // Dejagnu.hx - HAXE class for dejagnu-like testing.
2 //
3 // Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 import flash.Lib;
21 #if flash9
22 import flash.text.TextField;
23 import flash.text.TextFieldType;
24 import flash.external.ExternalInterface;
25 import flash.display.MovieClip;
26 #else
27 import flash.TextField;
28 import flash.MovieClip;
29 #end
30 import haxe.PosInfos;
32 class DejaGnu {
33 static var passed = 0;
34 static var failed = 0;
35 static var xpassed = 0;
36 static var xfailed = 0;
37 static var untest = 0;
38 static var unresolve = 0;
39 static var position:PosInfos;
40 static var trace = untyped __global__['trace'];
42 static private function callerInfo(p:haxe.PosInfos) {
43 return p.fileName + ": " + p.lineNumber;
46 // This is a trick to force our 'init' function
47 // to be automatically called at the start of the movie.
48 static var inithack = init();
50 static var tf:TextField;
52 static function init() {
53 //if(dejagnu_module_initialized == 1) return;
55 // create a textfield to output to
56 #if flash9
57 tf = new TextField();
58 tf.wordWrap = true;
59 tf.width = 390;
60 tf.height = 300;
61 flash.Lib.current.addChild(tf);
62 #else
63 flash.Lib.current.createTextField("tfsoft", 100,0,0,390,290);
64 untyped tfsoft.multiline = true;
65 untyped tfsoft.wordWrap = true;
66 untyped tfsoft.border = true;
67 untyped tfsoft.type = "input";
68 #end
69 //dejagnu_module_initialized = 1;
71 return null;
74 static public function fail (why, ?p:haxe.PosInfos) {
75 failed++;
76 var msg = 'FAILED: ' + why + " " + callerInfo(p);
77 xtrace(msg);
80 static public function xfail(why, ?p:haxe.PosInfos) {
81 xfailed++;
82 var msg = 'XFAILED: '+why+ " " + callerInfo(p);
83 xtrace(msg);
86 static public function pass(why, ?p:haxe.PosInfos) {
87 passed++;
88 var msg = 'PASSED: '+why+ " " + callerInfo(p);
89 xtrace(msg);
92 static public function xpass(why, ?p:haxe.PosInfos) {
93 xpassed++;
94 var msg = 'XPASSED: '+why+ " " + callerInfo(p);
95 xtrace(msg);
98 static public function check_equals(obt:Dynamic, exp:Dynamic, msg, ?p:haxe.PosInfos) {
99 if(msg == null) msg = "";
100 if (obt == exp) {
101 // Pass the calling posinfos.
102 pass(obt+' == ' + exp + ' ' + msg, p);
103 } else {
104 fail('expected: "' + exp + '" , obtained: "' + obt + '" ' + msg, p);
108 static public function xcheck_equals(obt:Dynamic, exp:Dynamic, msg, ?p:haxe.PosInfos)
110 if(msg == null) msg = "";
111 if ( obt == exp )
113 xpass(obt+' == '+exp+' '+msg, p);
115 else
117 xfail('expected: '+exp+' , obtained: '+obt+" "+msg, p);
121 static public function check(a : Dynamic, msg, ?p:haxe.PosInfos)
123 if ( a )
125 if ( msg != null ) pass(msg, p);
126 else pass(a, p);
128 else
130 if ( msg != null ) fail(msg, p);
131 else fail(a, p);
135 static public function xcheck(a : Dynamic, msg, ?p:haxe.PosInfos)
137 if ( a )
139 if ( msg != null ) xpass(msg, p);
140 else xpass(a, p);
142 else
144 if ( msg != null ) xfail(msg, p);
145 else xfail(a, p);
149 static function testcount() {
150 var c = 0;
151 if ( passed > 0 ) c += passed;
152 if ( failed > 0 ) c += failed;
153 if ( xpassed > 0 ) c += xpassed;
154 if ( xfailed > 0 ) c += xfailed;
155 if ( unresolve > 0 ) c += unresolve;
156 return c;
159 static function printtotals() {
160 xtrace('#passed: '+ passed);
161 xtrace('#failed: '+ failed);
162 if ( xpassed > 0 ) {
163 xtrace('#unexpected successes: '+ xpassed);
165 if ( xfailed > 0 ) {
166 xtrace('#expected failures: '+ xfailed);
168 if ( unresolve > 0 ) {
169 xtrace('#tests unresolved: '+ unresolve);
171 xtrace('#total tests run: '+ testcount());
174 static public function totals(exp:Dynamic, msg:Dynamic, ?p:haxe.PosInfos) {
175 var obt = testcount();
176 if ( exp != null && obt != exp ) {
177 fail('Test run '+obt+' (expected '+exp+') '+msg, p);
178 } else {
179 pass('Test run '+obt+' '+msg, p);
183 static public function xtotals(exp:Dynamic, msg:Dynamic, ?p:haxe.PosInfos) {
184 var obt = testcount();
185 if ( exp != null && obt != exp ) {
186 xfail('Test run '+obt+' (expected '+exp+') ['+msg+']', p);
187 } else {
188 xpass('Test run '+obt+' ['+msg+']', p);
192 static public function note(msg, ?p:haxe.PosInfos) {
193 xtrace(msg + " " + p.lineNumber);
196 static function xtrace(msg) {
197 #if flash9
198 tf.text += msg+"\n";
199 #else
200 untyped tfsoft.text += msg+"\n";
201 #end
202 flash.Lib.trace(msg);
205 static public function untested(msg, ?p:haxe.PosInfos) {
206 #if flash9
207 tf.text += "UNTESTED: "+msg+"\n";
208 #else
209 untyped tfsoft.text += "UNTESTED: "+msg+"\n";
210 #end
211 flash.Lib.trace("UNTESTED: " + msg );
214 static public function unresolved(msg) {
215 unresolve++;
216 #if flash9
217 tf.text += "UNRESOLVED: "+msg+"\n";
218 #else
219 untyped tfsoft.text += "UNRESOLVED: "+msg+"\n";
220 #end
221 flash.Lib.trace("UNRESOLVED: "+msg);
224 static public function done() {
225 printtotals();
226 #if flash9
227 tf.text += "__END_OF_TEST__";
228 #else
229 untyped tfsoft.text += "__END_OF_TEST__";
230 #end
231 flash.Lib.trace("__END_OF_TEST__");