Skip to content
Snippets Groups Projects
wine.pl 2.62 KiB
Newer Older
################################################################
# Tests for wine.pm module functions
#

use wine;

################################################################
# Declarations for functions we use in this script

wine::declare( "kernel32",
               SetLastError       => "void",
               GetLastError       => ["int", []],
               GlobalAddAtomA     => ["word",["str"]],
               GlobalGetAtomNameA => ["int", ["int","ptr","int"]],
               GetCurrentThread   => ["int", []],
               GetExitCodeThread  => ["int", ["int","ptr"]],
               GetModuleHandleA   => ["int", ["str"]],
               GetProcAddress     => ["int", ["long","str"]],
               lstrcatA           => ["str", ["str","str"]],
);

################################################################
# Test some simple function calls

# Test string arguments
$atom = GlobalAddAtomA("foo");
ok( $atom >= 0xc000 && $atom <= 0xffff );
ok( !defined($wine::err) );

# Test integer and string reference arguments
$buffer = "xxxxxx";
$ret = GlobalGetAtomNameA( $atom, \$buffer, length(buffer) );
ok( !defined($wine::err) );
ok( $ret == 3 );
ok( lc $buffer eq "foo\000xx" );

# Test integer reference
$code = 0;
$ret = GetExitCodeThread( GetCurrentThread(), \$code );
ok( !defined($wine::err) );
ok( $ret );
ok( $code == 0x103 );

# Test string return value
$str = lstrcatA( "foo\0foo", "bar" );
ok( !defined($wine::err) );
ok( $str eq "foobar" );

################################################################
# Test last error handling

SetLastError( 123 );
$ret = GetLastError();

################################################################
# Test various error cases

eval { SetLastError(1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7); };
ok( $@ =~ /Too many arguments at/ );
my $funcptr = GetProcAddress( GetModuleHandleA("kernel32"), "SetLastError" );
ok( $funcptr );
eval { wine::call_wine_API( $funcptr, 10, $wine::debug-1, 0); };
ok( $@ =~ /Bad return type 10 at/ );
ok( $@ =~ /Function 'foobar' not declared at/ );

################################################################
# Test assert

assert( 1, "cannot fail" );

eval { assert( 0, "this must fail" ); };
ok( $@ =~ /Assertion failed/ );
ok( $@ =~ /this must fail/ );

################################################################
# Test todo blocks

todo_wine
{
    ok( $wine::platform ne "wine", "Must fail only on Wine" );
};
todo( $wine::platform,
      sub { ok( 0, "Failure must be ignored inside todo" ); } );
todo( $wine::platform . "xxx",
      sub { ok( 1, "Success must not cause error inside todo for other platform" ); } );