Debian Codegraph @

t/ffi_platypus_lang_win32.t

raw
1 use Test2::V0 -no_srand => 1;
2 use FFI::Platypus::Lang::Win32;
3
4 {
5 require FFI::Platypus::Type::WideString;
6 my($encoding,$width) = eval { FFI::Platypus::Type::WideString->_compute_wide_string_encoding() };
7 if(my $error = $@)
8 {
9 $error =~ s/ at .*$//;
10 skip_all "Unable to detect wide string details: $error\n";
11 }
12
13 note "encoding = $encoding";
14 note "width = $width";
15 }
16
17 subtest 'native type map diagnostic' => sub {
18
19 my $map = FFI::Platypus::Lang::Win32->native_type_map;
20
21 foreach my $alias (sort keys %$map)
22 {
23 my $type = $map->{$alias};
24 note sprintf("%-30s %s", $alias, $type);
25 }
26
27 pass 'good';
28 };
29
30 my $ffi = FFI::Platypus->new( api => 1, lib => [undef] );
31
32 subtest 'load' => sub {
33 local $@ = "";
34 eval { $ffi->lang('Win32') };
35 is "$@", "";
36 };
37
38 my @strings = (
39 [ "trivial" => "" ],
40 [ "simple" => "abcde" ],
41 [ "fancy" => "abcd\x{E9}" ],
42 [ "complex" => "I \x{2764} Platypus" ],
43 );
44
45 subtest 'LPCWSTR' => sub {
46 skip_all 'Test only works on Windows' unless $^O eq 'MSWin32';
47
48 my $lstrlenW = $ffi->function( lstrlenW => [ 'LPCWSTR' ] => 'int' );
49
50 foreach my $test (@strings)
51 {
52 my($name, $string) = @$test;
53 is($lstrlenW->call($string), length($string), $name);
54 }
55 };
56
57 subtest 'LPWSTR' => sub {
58 skip_all 'Test only works on Windows' unless $^O eq 'MSWin32';
59
60 my $GetCurrentDirectoryW = $ffi->function( GetCurrentDirectoryW => ['DWORD','LPWSTR'] => 'DWORD' );
61
62 my $size = $GetCurrentDirectoryW->call(0, undef);
63 cmp_ok $size, '>', 0;
64
65 my $buf = "\0" x ($size*2);
66 $GetCurrentDirectoryW->call($size, \$buf);
67
68 note "buf = $buf";
69
70 ok( -d $buf, "returned directory exists");
71 };
72
73 done_testing;