1 // Dejagnu.as - MTASC class for dejagnu-like testing.
3 // Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software
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 // Original author: David Rorex - drorex@gmail.com
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 function init
() {
38 if(_level0
.dejagnu_module_initialized
== 1) return;
40 // create a textfield to output to
41 _level0
.createTextField
("textout", 99, 10, 10, 500, 500);
42 _level0
.dejagnu_module_initialized
= 1;
45 static function fail
(why
) {
47 var msg
= 'FAILED: '+why
;
51 static function xfail
(why
) {
53 var msg
= 'XFAILED: '+why
;
57 static function pass
(why
) {
59 var msg
= 'PASSED: '+why
;
63 static function xpass
(why
) {
65 var msg
= 'XPASSED: '+why
;
69 static function testcount
() {
71 if ( passed
) c
+= passed
;
72 if ( failed
) c
+= failed
;
73 if ( xpassed
) c
+= xpassed
;
74 if ( xfailed
) c
+= xfailed
;
78 static function printtotals
() {
79 xtrace
('#passed: '+ passed
);
80 xtrace
('#failed: '+ failed
);
82 xtrace
('#unexpected successes: '+ xpassed
);
85 xtrace
('#expected failures: '+ xfailed
);
87 xtrace
('#total tests run: '+ testcount
());
90 static function totals
(exp
, msg
) {
91 var obt
= testcount
();
92 if ( exp
!= undefined && obt
!= exp
) {
93 fail
('Test run '+obt
+' (expected '+exp
+') ['+msg
+']');
95 pass
('Test run '+obt
+' ['+msg
+']');
99 static function xtotals
(exp
, msg
) {
100 var obt
= testcount
();
101 if ( exp
!= undefined && obt
!= exp
) {
102 xfail
('Test run '+obt
+' (expected '+exp
+') ['+msg
+']');
104 xpass
('Test run '+obt
+' ['+msg
+']');
108 static function check_equals
(obt
, exp
, msg
) {
109 if(msg
== null) msg
= "";
111 pass
(obt
+' == '+exp
+' '+msg
);
113 fail
('expected: "'+exp
+'" , obtained: "'+obt
+'" '+msg
);
116 static function xcheck_equals
(obt
, exp
, msg
) {
117 if(msg
== null) msg
= "";
119 xpass
(obt
+' == '+exp
+' '+msg
);
121 xfail
('expected: '+exp
+' , obtained: '+obt
+" "+msg
);
124 static function check
(a
, msg
) {
126 pass
(msg
!= undefined ? msg
: a
);
128 fail
(msg
!= undefined ? msg
: a
);
131 static function xcheck
(a
, msg
) {
133 xpass
(msg
!= undefined ? msg
: a
);
135 xfail
(msg
!= undefined ? msg
: a
);
138 static function note
(msg
) {
142 static function xtrace
(msg
) {
143 _level0
.textout
.text
+= msg
+ "\n";
147 static function untested
(msg
) {
148 trace
("UNTESTED: "+msg
);
151 static function unresolved
(msg
) {
152 trace
("UNRESOLVED: "+msg
);
155 static function done
() {
157 trace
("__END_OF_TEST__");
158 loadMovie
('fscommand:quit', _root
);