Added regedit unit test, a couple minor changes to regedit.
[wine] / programs / winetest / tests / wine.pl
1 ################################################################
2 # Tests for wine.pm module functions
3 #
4 # Copyright 2001 Alexandre Julliard
5 #
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.
10 #
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.
15 #
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 #
20
21 use wine;
22
23 use kernel32;
24
25 ################################################################
26 # Test some simple function calls
27
28 # Test string arguments
29 $atom = GlobalAddAtomA("foo");
30 ok( $atom >= 0xc000 && $atom <= 0xffff );
31 ok( !defined($wine::err) );
32
33 # Test integer and string reference arguments
34 $buffer = "xxxxxx";
35 $ret = GlobalGetAtomNameA( $atom, \$buffer, length(buffer) );
36 ok( !defined($wine::err) );
37 ok( $ret == 3 );
38 ok( lc $buffer eq "foo\000xx" );
39
40 # Test integer reference
41 $code = 0;
42 $ret = GetExitCodeThread( GetCurrentThread(), \$code );
43 ok( !defined($wine::err) );
44 ok( $ret );
45 ok( $code == 0x103 );
46
47 # Test string return value
48 $str = lstrcatA( "foo\0foo", "bar" );
49 ok( !defined($wine::err) );
50 ok( $str eq "foobar" );
51
52 ################################################################
53 # Test last error handling
54
55 SetLastError( 123 );
56 $ret = GetLastError();
57 ok( $ret == 123 );
58
59 ################################################################
60 # Test various error cases
61
62 eval { SetLastError(1,2); };
63 ok( $@ =~ /Wrong number of arguments, expected 1, got 2/ );
64
65 wine::declare("kernel32", "SetLastError" => "int" );  # disable prototype
66 eval { SetLastError(1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7); };
67 ok( $@ =~ /Too many arguments/ );
68
69 wine::declare("kernel32", "non_existent_func" => ["int",["int"]]);
70 eval { non_existent_func(1); };
71 ok( $@ =~ /Could not get address for kernel32\.non_existent_func/ );
72
73 my $funcptr = GetProcAddress( GetModuleHandleA("kernel32"), "SetLastError" );
74 ok( $funcptr );
75 eval { wine::call_wine_API( $funcptr, 10, $wine::debug-1, 0); };
76 ok( $@ =~ /Bad return type 10 at/ );
77
78 eval { foobar(1,2,3); };
79 ok( $@ =~ /Function 'foobar' not declared at/ );
80
81 ################################################################
82 # Test assert
83
84 assert( 1, "cannot fail" );
85
86 eval { assert( 0, "this must fail" ); };
87 ok( $@ =~ /Assertion failed/ );
88 ok( $@ =~ /this must fail/ );
89
90 ################################################################
91 # Test todo blocks
92
93 todo_wine
94 {
95     ok( $wine::platform ne "wine", "Must fail only on Wine" );
96 };
97
98 todo( $wine::platform,
99       sub { ok( 0, "Failure must be ignored inside todo" ); } );
100 todo( $wine::platform . "xxx",
101       sub { ok( 1, "Success must not cause error inside todo for other platform" ); } );