File: ffi_platypus_record_meta.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 (45 lines) | stat: -rw-r--r-- 1,159 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
use Test2::V0 -no_srand => 1;
use FFI::Platypus;
use FFI::Platypus::Record::Meta;
use Data::Dumper qw( Dumper );

my $ffi = FFI::Platypus->new;
$ffi->lib(undef);

subtest 'basic' => sub {

  my $meta = FFI::Platypus::Record::Meta->new(
    [ 'uint8', 'uint8', 'pointer', 'float', 'double' ],
  );
  isa_ok $meta, 'FFI::Platypus::Record::Meta';
  like $meta->ffi_type, qr/^-?[0-9]+$/, "meta->ffi_type = @{[ $meta->ffi_type ]}";
  is $meta->size, 0, 'meta->size';
  is $meta->alignment, 0, 'meta->alignment';

  my $got = $meta->element_pointers;
  my $exp = [map { FFI::Platypus::Record::Meta::_find_symbol($_) } qw( uint8 uint8 pointer float double )];

  is
    $got,
    $exp,
    'meta->element_pointers'
  or diag Dumper([[map { sprintf "0x%x", $_ } @$got],[ map { sprintf "0x%x", $_ } @$exp]]);
};

subtest 'bogus types' => sub {

  {
    local $@ = '';
    eval { FFI::Platypus::Record::Meta->new(qw( completely bogsu )) };
    like "$@", qr/passed something other than a array ref/;
  }

  {
    local $@ = '';
    eval { FFI::Platypus::Record::Meta->new([qw( completely bogsu )]) };
    like "$@", qr/unknown type: completely/;
  }

};

done_testing;