| 1 |
use Test2::V0 -no_srand => 1; |
| 2 |
use FFI::Platypus; |
| 3 |
use Math::Complex; |
| 4 |
use Test::LeakTrace qw( no_leaks_ok ); |
| 5 |
|
| 6 |
my @types = map { "${_}[2]" } ( 'float', 'double', 'longdouble', |
| 7 |
map { ( "sint$_" , "uint$_" ) } |
| 8 |
qw( 8 16 32 64 )); |
| 9 |
|
| 10 |
foreach my $type (@types) |
| 11 |
{ |
| 12 |
subtest $type => sub { |
| 13 |
my $ffi = FFI::Platypus->new; |
| 14 |
my $f = $ffi->function(0 => [ $type ] => 'void' ); |
| 15 |
no_leaks_ok { |
| 16 |
my @a = (1,2); |
| 17 |
$f->call(\@a) |
| 18 |
}; |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
subtest 'opaque' => sub { |
| 23 |
my $ffi = FFI::Platypus->new( lib => [undef] ); |
| 24 |
my $malloc = $ffi->function( malloc => [ 'size_t' ] => 'opaque' ); |
| 25 |
my $free = $ffi->function( free => [ 'opaque' ] => 'void' ); |
| 26 |
my $ptr = $malloc->call(200); |
| 27 |
my $f = $ffi->function(0 => [ 'opaque[2]' ] => 'void' ); |
| 28 |
|
| 29 |
my @a = ($ptr, undef); |
| 30 |
no_leaks_ok { $f->call(\@a) }; |
| 31 |
$free->call($ptr); |
| 32 |
}; |
| 33 |
|
| 34 |
subtest 'string' => sub { |
| 35 |
my $ffi = FFI::Platypus->new; |
| 36 |
my $f = $ffi->function(0 => [ 'string[2]' ] => 'void' ); |
| 37 |
|
| 38 |
my @a = ("hello world", undef); |
| 39 |
no_leaks_ok { $f->call(\@a) }; |
| 40 |
}; |
| 41 |
|
| 42 |
subtest 'complex' => sub { |
| 43 |
|
| 44 |
foreach my $type (qw( complex_float[2] complex_double[2] )) |
| 45 |
{ |
| 46 |
subtest $type => sub { |
| 47 |
my $ffi = FFI::Platypus->new; |
| 48 |
my $f = $ffi->function(0 => [ $type ] => 'void' ); |
| 49 |
|
| 50 |
{ |
| 51 |
my @c = ([1.0,2.0],[3.0,4.0]); |
| 52 |
no_leaks_ok { $f->call(\@c) }; |
| 53 |
} |
| 54 |
|
| 55 |
{ |
| 56 |
my @c = (Math::Complex->make(1.0,2.0),Math::Complex->make(3.0,4.0)); |
| 57 |
no_leaks_ok { $f->call(\@c) }; |
| 58 |
} |
| 59 |
}; |
| 60 |
} |
| 61 |
|
| 62 |
}; |
| 63 |
|
| 64 |
done_testing; |