| 1 |
use Test2::V0 -no_srand => 1; |
| 2 |
use FFI::Platypus; |
| 3 |
use FFI::CheckLib; |
| 4 |
|
| 5 |
my $ffi = FFI::Platypus->new; |
| 6 |
$ffi->load_custom_type('::StringPointer' => 'string_p'); |
| 7 |
|
| 8 |
$ffi->lib(find_lib lib => 'test', symbol => 'f0', libpath => 't/ffi'); |
| 9 |
$ffi->attach( string_pointer_pointer_get => ['string_p'] => 'string'); |
| 10 |
$ffi->attach( string_pointer_pointer_set => ['string_p', 'string'] => 'void'); |
| 11 |
$ffi->attach( pointer_pointer_is_null => ['string_p'] => 'int'); |
| 12 |
$ffi->attach( pointer_is_null => ['string_p'] => 'int'); |
| 13 |
$ffi->attach( string_pointer_pointer_return => ['string'] => 'string_p'); |
| 14 |
$ffi->attach( pointer_null => [] => 'string_p'); |
| 15 |
|
| 16 |
subtest 'arg pass in' => sub { |
| 17 |
is string_pointer_pointer_get(\"hello there"), "hello there", "not null"; |
| 18 |
is pointer_pointer_is_null(\undef), 1, "\\undef is null"; |
| 19 |
is pointer_is_null(undef), 1, "undef is null"; |
| 20 |
}; |
| 21 |
|
| 22 |
subtest 'arg pass out' => sub { |
| 23 |
my $string = ''; |
| 24 |
string_pointer_pointer_set(\$string, "hi there"); |
| 25 |
is $string, "hi there", "not null string = $string"; |
| 26 |
|
| 27 |
my $string2; |
| 28 |
string_pointer_pointer_set(\$string2, "and another"); |
| 29 |
is $string2, "and another", "not null string = $string2"; |
| 30 |
|
| 31 |
}; |
| 32 |
|
| 33 |
subtest 'return value' => sub { |
| 34 |
my $string = "once more onto"; |
| 35 |
|
| 36 |
is string_pointer_pointer_return($string), \"once more onto", "not null string = $string"; |
| 37 |
is string_pointer_pointer_return(undef), \undef, "\\null"; |
| 38 |
my $value = pointer_null(); |
| 39 |
is $value, undef, "null"; |
| 40 |
|
| 41 |
}; |
| 42 |
|
| 43 |
done_testing; |