5 use Test::More tests => 30;
6 use ExtUtils::Typemaps;
10 my $map = ExtUtils::Typemaps->new();
11 $map->add_typemap(ctype => 'unsigned int', xstype => 'T_IV');
12 is($map->as_string(), <<'HERE', "Simple typemap matches expectations");
17 my $type = $map->get_typemap(ctype => 'unsigned int');
18 isa_ok($type, 'ExtUtils::Typemaps::Type');
19 is($type->ctype, 'unsigned int');
20 is($type->xstype, 'T_IV');
21 is($type->tidy_ctype, 'unsigned int');
26 my $map = ExtUtils::Typemaps->new();
27 $map->add_typemap(ctype => 'unsigned int', xstype => 'T_UV');
28 $map->add_inputmap(xstype => 'T_UV', code => '$var = ($type)SvUV($arg);');
29 is($map->as_string(), <<'HERE', "Simple typemap (with input) matches expectations");
35 $var = ($type)SvUV($arg);
38 my $type = $map->get_typemap(ctype => 'unsigned int');
39 isa_ok($type, 'ExtUtils::Typemaps::Type');
40 is($type->ctype, 'unsigned int');
41 is($type->xstype, 'T_UV');
42 is($type->tidy_ctype, 'unsigned int');
44 my $in = $map->get_inputmap(xstype => 'T_UV');
45 isa_ok($in, 'ExtUtils::Typemaps::InputMap');
46 is($in->xstype, 'T_UV');
48 # test fetching inputmap by ctype
49 my $in2 = $map->get_inputmap(ctype => 'unsigned int');
50 is_deeply($in2, $in, "get_inputmap returns the same typemap for ctype and xstype");
56 my $map = ExtUtils::Typemaps->new();
57 $map->add_typemap(ctype => 'unsigned int', xstype => 'T_UV');
58 $map->add_outputmap(xstype => 'T_UV', code => 'sv_setuv($arg, (UV)$var);');
59 is($map->as_string(), <<'HERE', "Simple typemap (with output) matches expectations");
65 sv_setuv($arg, (UV)$var);
68 my $type = $map->get_typemap(ctype => 'unsigned int');
69 isa_ok($type, 'ExtUtils::Typemaps::Type');
70 is($type->ctype, 'unsigned int');
71 is($type->xstype, 'T_UV');
72 is($type->tidy_ctype, 'unsigned int');
74 my $in = $map->get_outputmap(xstype => 'T_UV');
75 isa_ok($in, 'ExtUtils::Typemaps::OutputMap');
76 is($in->xstype, 'T_UV');
79 # typemap & input & output
81 my $map = ExtUtils::Typemaps->new();
82 $map->add_typemap(ctype => 'unsigned int', xstype => 'T_UV');
83 $map->add_inputmap(xstype => 'T_UV', code => '$var = ($type)SvUV($arg);');
84 $map->add_outputmap(xstype => 'T_UV', code => 'sv_setuv($arg, (UV)$var);');
85 is($map->as_string(), <<'HERE', "Simple typemap (with in- & output) matches expectations");
91 $var = ($type)SvUV($arg);
95 sv_setuv($arg, (UV)$var);
99 # two typemaps & input & output
101 my $map = ExtUtils::Typemaps->new();
102 $map->add_typemap(ctype => 'unsigned int', xstype => 'T_UV');
103 $map->add_inputmap(xstype => 'T_UV', code => '$var = ($type)SvUV($arg);');
104 $map->add_outputmap(xstype => 'T_UV', code => 'sv_setuv($arg, (UV)$var);');
106 $map->add_typemap(ctype => 'int', xstype => 'T_IV');
107 $map->add_inputmap(xstype => 'T_IV', code => '$var = ($type)SvIV($arg);');
108 $map->add_outputmap(xstype => 'T_IV', code => 'sv_setiv($arg, (IV)$var);');
109 is($map->as_string(), <<'HERE', "Simple typemap (with in- & output) matches expectations");
116 $var = ($type)SvUV($arg);
118 $var = ($type)SvIV($arg);
122 sv_setuv($arg, (UV)$var);
124 sv_setiv($arg, (IV)$var);
126 my $type = $map->get_typemap(ctype => 'unsigned int');
127 isa_ok($type, 'ExtUtils::Typemaps::Type');
128 is($type->ctype, 'unsigned int');
129 is($type->xstype, 'T_UV');
130 is($type->tidy_ctype, 'unsigned int');
132 my $in = $map->get_outputmap(xstype => 'T_UV');
133 isa_ok($in, 'ExtUtils::Typemaps::OutputMap');
134 is($in->xstype, 'T_UV');
135 $in = $map->get_outputmap(xstype => 'T_IV');
136 isa_ok($in, 'ExtUtils::Typemaps::OutputMap');
137 is($in->xstype, 'T_IV');