| 1 |
use Test2::V0 -no_srand => 1; |
| 2 |
use FFI::Platypus; |
| 3 |
use FFI::Platypus::Record::Meta; |
| 4 |
use Data::Dumper qw( Dumper ); |
| 5 |
|
| 6 |
my $ffi = FFI::Platypus->new; |
| 7 |
$ffi->lib(undef); |
| 8 |
|
| 9 |
subtest 'basic' => sub { |
| 10 |
|
| 11 |
my $meta = FFI::Platypus::Record::Meta->new( |
| 12 |
[ 'uint8', 'uint8', 'pointer', 'float', 'double' ], |
| 13 |
); |
| 14 |
isa_ok $meta, 'FFI::Platypus::Record::Meta'; |
| 15 |
like $meta->ffi_type, qr/^-?[0-9]+$/, "meta->ffi_type = @{[ $meta->ffi_type ]}"; |
| 16 |
is $meta->size, 0, 'meta->size'; |
| 17 |
is $meta->alignment, 0, 'meta->alignment'; |
| 18 |
|
| 19 |
my $got = $meta->element_pointers; |
| 20 |
my $exp = [map { FFI::Platypus::Record::Meta::_find_symbol($_) } qw( uint8 uint8 pointer float double )]; |
| 21 |
|
| 22 |
is |
| 23 |
$got, |
| 24 |
$exp, |
| 25 |
'meta->element_pointers' |
| 26 |
or diag Dumper([[map { sprintf "0x%x", $_ } @$got],[ map { sprintf "0x%x", $_ } @$exp]]); |
| 27 |
}; |
| 28 |
|
| 29 |
subtest 'bogus types' => sub { |
| 30 |
|
| 31 |
{ |
| 32 |
local $@ = ''; |
| 33 |
eval { FFI::Platypus::Record::Meta->new(qw( completely bogsu )) }; |
| 34 |
like "$@", qr/passed something other than a array ref/; |
| 35 |
} |
| 36 |
|
| 37 |
{ |
| 38 |
local $@ = ''; |
| 39 |
eval { FFI::Platypus::Record::Meta->new([qw( completely bogsu )]) }; |
| 40 |
like "$@", qr/unknown type: completely/; |
| 41 |
} |
| 42 |
|
| 43 |
}; |
| 44 |
|
| 45 |
done_testing; |