5 use Test::More tests => 29;
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');
52 my $map = ExtUtils::Typemaps->new();
53 $map->add_typemap(ctype => 'unsigned int', xstype => 'T_UV');
54 $map->add_outputmap(xstype => 'T_UV', code => 'sv_setuv($arg, (UV)$var);');
55 is($map->as_string(), <<'HERE', "Simple typemap (with output) matches expectations");
61 sv_setuv($arg, (UV)$var);
64 my $type = $map->get_typemap(ctype => 'unsigned int');
65 isa_ok($type, 'ExtUtils::Typemaps::Type');
66 is($type->ctype, 'unsigned int');
67 is($type->xstype, 'T_UV');
68 is($type->tidy_ctype, 'unsigned int');
70 my $in = $map->get_outputmap(xstype => 'T_UV');
71 isa_ok($in, 'ExtUtils::Typemaps::OutputMap');
72 is($in->xstype, 'T_UV');
75 # typemap & input & output
77 my $map = ExtUtils::Typemaps->new();
78 $map->add_typemap(ctype => 'unsigned int', xstype => 'T_UV');
79 $map->add_inputmap(xstype => 'T_UV', code => '$var = ($type)SvUV($arg);');
80 $map->add_outputmap(xstype => 'T_UV', code => 'sv_setuv($arg, (UV)$var);');
81 is($map->as_string(), <<'HERE', "Simple typemap (with in- & output) matches expectations");
87 $var = ($type)SvUV($arg);
91 sv_setuv($arg, (UV)$var);
95 # two typemaps & input & output
97 my $map = ExtUtils::Typemaps->new();
98 $map->add_typemap(ctype => 'unsigned int', xstype => 'T_UV');
99 $map->add_inputmap(xstype => 'T_UV', code => '$var = ($type)SvUV($arg);');
100 $map->add_outputmap(xstype => 'T_UV', code => 'sv_setuv($arg, (UV)$var);');
102 $map->add_typemap(ctype => 'int', xstype => 'T_IV');
103 $map->add_inputmap(xstype => 'T_IV', code => '$var = ($type)SvIV($arg);');
104 $map->add_outputmap(xstype => 'T_IV', code => 'sv_setiv($arg, (IV)$var);');
105 is($map->as_string(), <<'HERE', "Simple typemap (with in- & output) matches expectations");
112 $var = ($type)SvUV($arg);
114 $var = ($type)SvIV($arg);
118 sv_setuv($arg, (UV)$var);
120 sv_setiv($arg, (IV)$var);
122 my $type = $map->get_typemap(ctype => 'unsigned int');
123 isa_ok($type, 'ExtUtils::Typemaps::Type');
124 is($type->ctype, 'unsigned int');
125 is($type->xstype, 'T_UV');
126 is($type->tidy_ctype, 'unsigned int');
128 my $in = $map->get_outputmap(xstype => 'T_UV');
129 isa_ok($in, 'ExtUtils::Typemaps::OutputMap');
130 is($in->xstype, 'T_UV');
131 $in = $map->get_outputmap(xstype => 'T_IV');
132 isa_ok($in, 'ExtUtils::Typemaps::OutputMap');
133 is($in->xstype, 'T_IV');