File: ffi_platypus_dl.t

package info (click to toggle)
libffi-platypus-perl 2.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,860 kB
  • sloc: perl: 7,388; ansic: 6,862; cpp: 53; sh: 19; makefile: 14
file content (52 lines) | stat: -rw-r--r-- 1,274 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use Test2::V0 -no_srand => 1;
use FFI::Platypus::DL;
use FFI::CheckLib qw( find_lib );

my $libtest = find_lib lib => 'test', symbol => 'f0', libpath => 't/ffi';

subtest 'flags' => sub {

  ok(FFI::Platypus::DL->can('RTLD_PLATYPUS_DEFAULT'), "RTLD_PLATYPUS_DEFAULT is defined");

  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::;

};

subtest 'dlopen' => sub {

  subtest 'bad library' => sub {
    is dlopen("t/ffi/libbogus.so", RTLD_PLATYPUS_DEFAULT), undef, 'Returns undef on fail';
    note "dlerror = @{[ dlerror ]}";
  };

  subtest 'good library' => sub {
    my $h = dlopen $libtest, RTLD_PLATYPUS_DEFAULT;
    ok($h, "Returns handle on good");
    note "h = $h";
    dlclose $h;
  };

};

subtest 'dlsym' => sub {

  my $h = dlopen $libtest, RTLD_PLATYPUS_DEFAULT;

  subtest 'good symbol' => sub {
    my $address = dlsym $h, 'f0';
    ok $address, 'returns an address';
    note "address = $address";
  };

  subtest 'bad symbol' => sub {
    my $address = dlsym $h, 'bogus';
    is $address, undef, 'bad symbol returns undef';
    note "dlerror = @{[ dlerror ]}";
  };

  dlclose $h;

};

done_testing;