Debian Codegraph @

t/ffi_platypus_dl.t

raw
1 use Test2::V0 -no_srand => 1;
2 use FFI::Platypus::DL;
3 use FFI::CheckLib qw( find_lib );
4
5 my $libtest = find_lib lib => 'test', symbol => 'f0', libpath => 't/ffi';
6
7 subtest 'flags' => sub {
8
9 ok(FFI::Platypus::DL->can('RTLD_PLATYPUS_DEFAULT'), "RTLD_PLATYPUS_DEFAULT is defined");
10
11 note sprintf "%-25s %04x %s", $_, FFI::Platypus::DL->can($_)->(), FFI::Platypus::DL->can($_)->() for sort { FFI::Platypus::DL->can($a)->() <=> FFI::Platypus::DL->can($b)->() } grep /^RTLD_/, keys %main::;
12
13 };
14
15 subtest 'dlopen' => sub {
16
17 subtest 'bad library' => sub {
18 is dlopen("t/ffi/libbogus.so", RTLD_PLATYPUS_DEFAULT), undef, 'Returns undef on fail';
19 note "dlerror = @{[ dlerror ]}";
20 };
21
22 subtest 'good library' => sub {
23 my $h = dlopen $libtest, RTLD_PLATYPUS_DEFAULT;
24 ok($h, "Returns handle on good");
25 note "h = $h";
26 dlclose $h;
27 };
28
29 };
30
31 subtest 'dlsym' => sub {
32
33 my $h = dlopen $libtest, RTLD_PLATYPUS_DEFAULT;
34
35 subtest 'good symbol' => sub {
36 my $address = dlsym $h, 'f0';
37 ok $address, 'returns an address';
38 note "address = $address";
39 };
40
41 subtest 'bad symbol' => sub {
42 my $address = dlsym $h, 'bogus';
43 is $address, undef, 'bad symbol returns undef';
44 note "dlerror = @{[ dlerror ]}";
45 };
46
47 dlclose $h;
48
49 };
50
51 done_testing;
52