File: 10_bare.t

package info (click to toggle)
libextutils-typemap-perl 1.00-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 120 kB
  • sloc: perl: 276; makefile: 2
file content (149 lines) | stat: -rw-r--r-- 4,272 bytes parent folder | download | duplicates (3)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/perl
use strict;
use warnings;

use Test::More tests => 29;
use ExtUtils::Typemap;

sub _isa_any_ok {
  my $obj = shift;
  my @classes = @_;
  my $ok = 0;
  foreach (@classes) {
    $ok = 1 if $obj->isa($_);
  }
  ok($ok, "Object isa_any '".join("', '", @classes)."'");
  if (not $ok) {
    diag("Object isa '" . ref($obj) . "', not any of '".join("', '", @classes)."'");
  }
  return $ok;
}

# typemap only
SCOPE: {
  my $map = ExtUtils::Typemap->new();
  $map->add_typemap(ctype => 'unsigned int', xstype => 'T_IV');
  is($map->as_string(), <<'HERE', "Simple typemap matches expectations");
TYPEMAP
unsigned int	T_IV
HERE

  my $type = $map->get_typemap(ctype => 'unsigned int');
  _isa_any_ok($type, 'ExtUtils::Typemap::Type', 'ExtUtils::Typemaps::Type');
  is($type->ctype, 'unsigned int');
  is($type->xstype, 'T_IV');
  is($type->tidy_ctype, 'unsigned int');
}

# typemap & input
SCOPE: {
  my $map = ExtUtils::Typemap->new();
  $map->add_typemap(ctype => 'unsigned int', xstype => 'T_UV');
  $map->add_inputmap(xstype => 'T_UV', code => '$var = ($type)SvUV($arg);');
  is($map->as_string(), <<'HERE', "Simple typemap (with input) matches expectations");
TYPEMAP
unsigned int	T_UV

INPUT
T_UV
	$var = ($type)SvUV($arg);
HERE

  my $type = $map->get_typemap(ctype => 'unsigned int');
  _isa_any_ok($type, 'ExtUtils::Typemap::Type', 'ExtUtils::Typemaps::Type');
  is($type->ctype, 'unsigned int');
  is($type->xstype, 'T_UV');
  is($type->tidy_ctype, 'unsigned int');

  my $in = $map->get_inputmap(xstype => 'T_UV');
  _isa_any_ok($in, 'ExtUtils::Typemap::InputMap', 'ExtUtils::Typemaps::InputMap');
  is($in->xstype, 'T_UV');
}


# typemap & output
SCOPE: {
  my $map = ExtUtils::Typemap->new();
  $map->add_typemap(ctype => 'unsigned int', xstype => 'T_UV');
  $map->add_outputmap(xstype => 'T_UV', code => 'sv_setuv($arg, (UV)$var);');
  is($map->as_string(), <<'HERE', "Simple typemap (with output) matches expectations");
TYPEMAP
unsigned int	T_UV

OUTPUT
T_UV
	sv_setuv($arg, (UV)$var);
HERE

  my $type = $map->get_typemap(ctype => 'unsigned int');
  _isa_any_ok($type, 'ExtUtils::Typemap::Type', 'ExtUtils::Typemaps::Type');
  is($type->ctype, 'unsigned int');
  is($type->xstype, 'T_UV');
  is($type->tidy_ctype, 'unsigned int');

  my $in = $map->get_outputmap(xstype => 'T_UV');
  _isa_any_ok($in, 'ExtUtils::Typemap::OutputMap', 'ExtUtils::Typemaps::OutputMap');
  is($in->xstype, 'T_UV');
}

# typemap & input & output
SCOPE: {
  my $map = ExtUtils::Typemap->new();
  $map->add_typemap(ctype => 'unsigned int', xstype => 'T_UV');
  $map->add_inputmap(xstype => 'T_UV', code => '$var = ($type)SvUV($arg);');
  $map->add_outputmap(xstype => 'T_UV', code => 'sv_setuv($arg, (UV)$var);');
  is($map->as_string(), <<'HERE', "Simple typemap (with in- & output) matches expectations");
TYPEMAP
unsigned int	T_UV

INPUT
T_UV
	$var = ($type)SvUV($arg);

OUTPUT
T_UV
	sv_setuv($arg, (UV)$var);
HERE
}

# two typemaps & input & output
SCOPE: {
  my $map = ExtUtils::Typemap->new();
  $map->add_typemap(ctype => 'unsigned int', xstype => 'T_UV');
  $map->add_inputmap(xstype => 'T_UV', code => '$var = ($type)SvUV($arg);');
  $map->add_outputmap(xstype => 'T_UV', code => 'sv_setuv($arg, (UV)$var);');

  $map->add_typemap(ctype => 'int', xstype => 'T_IV');
  $map->add_inputmap(xstype => 'T_IV', code => '$var = ($type)SvIV($arg);');
  $map->add_outputmap(xstype => 'T_IV', code => 'sv_setiv($arg, (IV)$var);');
  is($map->as_string(), <<'HERE', "Simple typemap (with in- & output) matches expectations");
TYPEMAP
unsigned int	T_UV
int	T_IV

INPUT
T_UV
	$var = ($type)SvUV($arg);
T_IV
	$var = ($type)SvIV($arg);

OUTPUT
T_UV
	sv_setuv($arg, (UV)$var);
T_IV
	sv_setiv($arg, (IV)$var);
HERE
  my $type = $map->get_typemap(ctype => 'unsigned int');
  _isa_any_ok($type, 'ExtUtils::Typemap::Type', 'ExtUtils::Typemaps::Type');
  is($type->ctype, 'unsigned int');
  is($type->xstype, 'T_UV');
  is($type->tidy_ctype, 'unsigned int');

  my $in = $map->get_outputmap(xstype => 'T_UV');
  _isa_any_ok($in, 'ExtUtils::Typemap::OutputMap', 'ExtUtils::Typemaps::OutputMap');
  is($in->xstype, 'T_UV');
  $in = $map->get_outputmap(xstype => 'T_IV');
  _isa_any_ok($in, 'ExtUtils::Typemap::OutputMap', 'ExtUtils::Typemaps::OutputMap');
  is($in->xstype, 'T_IV');
}