Debian Codegraph @

t/ffi_platypus_constant.t

raw
1 use Test2::V0 -no_srand => 1;
2 use FFI::Platypus::Constant;
3 use File::Path qw( mkpath );
4 use File::Basename qw( dirname );
5 use FFI::Temp;
6
7 subtest 'very very basic...' => sub {
8
9 my $api = FFI::Platypus::Constant->new;
10 isa_ok $api, 'FFI::Platypus::Constant';
11 undef $api;
12 ok 'did not appear to crash :tada:';
13
14 };
15
16 subtest 'create constants' => sub {
17
18 my $root = FFI::Temp->newdir;
19 spew("$root/lib/Foo/Bar1.pm", <<'EOF');
20 package Foo::Bar1;
21 use strict;
22 use warnings;
23 use FFI::Platypus;
24 my $ffi = FFI::Platypus->new( api => 1, lang => 'ASM' );
25 $ffi->bundle;
26 1;
27 EOF
28
29 spew("$root/ffi/bar1.c", <<'EOF');
30 #include <ffi_platypus_bundle.h>
31 void ffi_pl_bundle_constant(const char *package, ffi_platypus_constant_t *b)
32 {
33 b->set_str("FOO1", "VAL1");
34 b->set_str("Foo::Bar1::Baz::FOO2", "VAL2");
35 b->set_sint("FOO3", -42);
36 b->set_uint("FOO4", 512);
37 b->set_double("FOO5", 2.5);
38 b->set_str("FOO6", package);
39 }
40 EOF
41
42 local @INC = @INC;
43 unshift @INC, "$root/lib";
44 local $@ = '';
45 eval " require Foo::Bar1; ";
46 is "$@", '';
47
48 is( Foo::Bar1::FOO1(), "VAL1" );
49 is( Foo::Bar1::Baz::FOO2(), "VAL2" );
50 is( Foo::Bar1::FOO3(), -42 );
51 is( Foo::Bar1::FOO4(), 512 );
52 is( Foo::Bar1::FOO5(), 2.5 );
53 is( Foo::Bar1::FOO6(), "Foo::Bar1" );
54
55 };
56
57 done_testing;
58
59 sub spew
60 {
61 my($fn, $content) = @_;
62
63 note "spew(start)[$fn]\n";
64 note $content;
65 note "spew(end)\n";
66
67 my $dir = dirname $fn;
68 mkpath $dir, 0, oct(755) unless -d $dir;
69 open my $fh, '>', $fn;
70 print $fh $content;
71 close $fh;
72 }