1 # --------------------------------------------------------------------
2 # Main routines for the Wine test environment
4 # Copyright 2001 John F Sturtz for Codeweavers
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # This library 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 GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # --------------------------------------------------------------------
24 use vars
qw(@ISA @EXPORT @EXPORT_OK $todo_level
25 $successes $failures $todo_successes $todo_failures $winetest_report_success);
31 # Items to export into callers namespace by default. Note: do not export
32 # names by default without a very good reason. Use EXPORT_OK instead.
33 # Do not simply export all your public functions/methods/constants.
46 $wine::debug
= defined($ENV{WINETEST_DEBUG
}) ?
$ENV{WINETEST_DEBUG
} : 1;
47 $wine::platform
= defined($ENV{WINETEST_PLATFORM
}) ?
$ENV{WINETEST_PLATFORM
} : "windows";
54 $winetest_report_success = defined($ENV{WINETEST_REPORT_SUCCESS
}) ?
$ENV{WINETEST_REPORT_SUCCESS
} : 0;
56 # ----------------------------------------------------------------------
59 # | Purpose: Display a hex dump of a string |
62 # | Usage: hd STR, LENGTH |
65 # ----------------------------------------------------------------------
71 my ($str1, $str2, $str, $t);
76 # --------------------------------------------------------------
77 # | Get args; if no BUF specified, blow |
78 # --------------------------------------------------------------
80 $length = (shift or length ($buf));
82 if ((not defined ($buf)) || ($length <= 0));
84 # --------------------------------------------------------------
86 # --------------------------------------------------------------
91 # --------------------------------------------------------------
92 # | For each character |
93 # --------------------------------------------------------------
94 for (0 .. ($length - 1))
96 $c = substr ($buf, $_, 1);
97 $x = sprintf ("%02x", ord ($c));
99 $str2 .= (((ord ($c) >= 33) && (ord ($c) <= 126)) ?
$c : ".");
101 # --------------------------------------------------------------
102 # | Every group of 4, add an extra space |
103 # --------------------------------------------------------------
106 ((($_ + 1) % 16) == 4) ||
107 ((($_ + 1) % 16) == 12)
114 # --------------------------------------------------------------
115 # | Every group of 8, add a '-' |
116 # --------------------------------------------------------------
119 ((($_ + 1) % 16) == 8)
126 # --------------------------------------------------------------
127 # | Every group of 16, dump |
128 # --------------------------------------------------------------
131 ((($_ + 1) % 16) == 0) ||
132 ($_ == ($length - 1))
135 $str = sprintf ("%-64s%s", $str1, $str2);
138 $t = ("-" x
length ($str));
140 print " | $length bytes\n";
145 $str1 = sprintf ("%05d:", ($_ + 1));
147 if ($_ == ($length - 1))
156 # --------------------------------------------------------------
158 # --------------------------------------------------------------
165 # ----------------------------------------------------------------------
168 # | Purpose: Generate unicode string |
170 # | Usage: wc ASCII_STRING |
172 # | Returns: string generated |
173 # ----------------------------------------------------------------------
176 return pack("S*",unpack("C*",shift));
181 # ----------------------------------------------------------------------
182 # | Subroutine: wclen |
184 # | Purpose: Return length of unicode string |
186 # | Usage: wclen UNICODE_STRING |
188 # | Returns: string generated |
189 # ----------------------------------------------------------------------
199 while (length ($str) > 0)
201 $c1 = substr ($str, 0, 1, "");
202 $c2 = substr ($str, 0, 1, "");
203 (($c1 eq "\x00") && ($c2 eq "\x00")) ?
last : $n++;
212 # ----------------------------------------------------------------------
215 # Purpose: Print warning if something fails
217 # Usage: ok CONDITION [DESCRIPTION]
220 # ----------------------------------------------------------------------
223 my $assertion = shift;
224 my $description = shift;
225 my ($filename, $line) = (caller (0))[1,2];
230 print STDERR
("$filename:$line: Test succeeded inside todo block" .
231 ($description ?
": $description" : "") . "\n");
234 else { $todo_successes++; }
240 print STDERR
("$filename:$line: Test failed" .
241 ($description ?
": $description" : "") . "\n");
246 print STDERR
("$filename:$line: Test succeeded\n") if ($winetest_report_success);
253 # ----------------------------------------------------------------------
256 # Purpose: Print error and die if something fails
258 # Usage: assert CONDITION [DESCRIPTION]
261 # ----------------------------------------------------------------------
264 my $assertion = shift;
265 my $description = shift;
266 my ($filename, $line) = (caller (0))[1,2];
269 die ("$filename:$line: Assertion failed" . ($description ?
": $description" : "") . "\n");
274 # ----------------------------------------------------------------------
277 # Purpose: Print debugging traces
279 # Usage: trace format [arguments]
280 # ----------------------------------------------------------------------
283 return unless ($wine::debug
> 0);
285 my $filename = (caller(0))[1];
286 $filename =~ s!.*/!!;
287 printf "trace:$filename $format", @_;
290 # ----------------------------------------------------------------------
293 # Purpose: Specify a block of code as todo for a given platform
295 # Usage: todo name coderef
296 # ----------------------------------------------------------------------
299 my ($platform,$code) = @_;
300 if ($wine::platform
eq $platform)
313 # ----------------------------------------------------------------------
314 # Subroutine: todo_wine
316 # Purpose: Specify a block of test as todo for the Wine platform
318 # Usage: todo_wine { code }
319 # ----------------------------------------------------------------------
323 todo
( "wine", $code );
327 # ----------------------------------------------------------------------
330 # Purpose: Called at the end of execution, print results summary
331 # ----------------------------------------------------------------------
334 return if $?
; # got some other error already
335 if ($wine::debug
> 0)
337 my $filename = (caller(0))[1];
338 printf STDERR
("%s: %d tests executed, %d marked as todo, %d %s.\n",
339 $filename, $successes + $failures + $todo_successes + $todo_failures,
340 $todo_successes, $failures + $todo_failures,
341 ($failures + $todo_failures != 1) ?
"failures" : "failure" );
343 $?
= ($failures + $todo_failures < 255) ?
$failures + $todo_failures : 255;