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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
|
use Test2::V0 -no_srand => 1;
use FFI::Platypus;
use FFI::Platypus::TypeParser;
use FFI::Platypus::Internal;
use FFI::Platypus::TypeParser::Version0;
my $ffi = FFI::Platypus->new;
my $type;
my $pointer_size = $ffi->sizeof('opaque');
subtest basic => sub {
is(
$type = FFI::Platypus::TypeParser::Version0->new->parse('uint64')->meta,
{
element_size => 8,
element_type => 'int',
ffi_type => 'uint64',
sign => 0,
size => 8,
type => 'scalar',
type_code => FFI_PL_TYPE_UINT64,
},
'basic basic',
) or diag explain $type;
subtest 'longdouble' => sub {
skip_all 'test requires support for long double'
unless FFI::Platypus::TypeParser->have_type('longdouble');
is(
$type = FFI::Platypus::TypeParser::Version0->new->parse('longdouble')->meta,
{
element_size => 16,
element_type => 'float',
ffi_type => 'longdouble',
size => 16,
type => 'scalar',
type_code => FFI_PL_TYPE_LONG_DOUBLE,
},
'longdouble',
) or diag explain $type;
};
subtest 'complex' => sub {
skip_all 'test requires support for complex'
unless FFI::Platypus::TypeParser->have_type('complex_float');
skip_all 'test requires support for complex'
unless FFI::Platypus::TypeParser->have_type('complex_double');
is(
$type = FFI::Platypus::TypeParser::Version0->new->parse('complex_float')->meta,
{
element_size => 8,
element_type => 'float',
ffi_type => 'complex_float',
size => 8,
type => 'scalar',
type_code => FFI_PL_TYPE_COMPLEX_FLOAT,
},
'complex float',
) or diag explain $type;
is(
$type = FFI::Platypus::TypeParser::Version0->new->parse('complex_double')->meta,
{
element_size => 16,
element_type => 'float',
ffi_type => 'complex_double',
size => 16,
type => 'scalar',
type_code => FFI_PL_TYPE_COMPLEX_DOUBLE,
},
'complex double',
) or diag explain $type;
};
};
subtest record => sub {
is(
$type = FFI::Platypus::TypeParser::Version0->new->parse('string(42)')->meta,
{
ffi_type => 'pointer',
ref => 0,
size => 42,
type => 'record',
type_code => FFI_PL_TYPE_RECORD,
},
'fixed string',
) or diag explain $type;
is(
$type = FFI::Platypus::TypeParser::Version0->new->parse('record(42)')->meta,
{
ffi_type => 'pointer',
ref => 0,
size => 42,
type => 'record',
type_code => FFI_PL_TYPE_RECORD,
},
'unclassed record',
) or diag explain $type;
{ package
Foo::Bar::Baz;
use FFI::Platypus::Record;
record_layout (qw(
sint64 foo
));
}
is(
$type =FFI::Platypus::TypeParser::Version0->new->parse('record(Foo::Bar::Baz)')->meta,
{
ffi_type => 'pointer',
ref => 1,
size => 8,
type => 'record',
type_code => FFI_PL_TYPE_RECORD,
class => 'Foo::Bar::Baz',
},
'classed record',
) or diag explain $type;
};
subtest string => sub {
is(
$type = FFI::Platypus::TypeParser::Version0->new->parse('string')->meta,
{
access => 'ro',
element_size => $pointer_size,
ffi_type => 'pointer',
size => $pointer_size,
type => 'string',
type_code => FFI_PL_TYPE_STRING,
},
'default string',
) or diag explain $type;
is(
$type = FFI::Platypus::TypeParser::Version0->new->parse('string ro')->meta,
{
access => 'ro',
element_size => $pointer_size,
ffi_type => 'pointer',
size => $pointer_size,
type => 'string',
type_code => FFI_PL_TYPE_STRING,
},
'explicit ro string',
) or diag explain $type;
is(
$type = FFI::Platypus::TypeParser::Version0->new->parse('string_ro')->meta,
{
access => 'ro',
element_size => $pointer_size,
ffi_type => 'pointer',
size => $pointer_size,
type => 'string',
type_code => FFI_PL_TYPE_STRING,
},
'explicit ro string with underscore',
) or diag explain $type;
is(
$type = FFI::Platypus::TypeParser::Version0->new->parse('string rw')->meta,
{
access => 'rw',
element_size => $pointer_size,
ffi_type => 'pointer',
size => $pointer_size,
type => 'string',
type_code => FFI_PL_TYPE_STRING,
},
'explicit rw string',
) or diag explain $type;
is(
$type = FFI::Platypus::TypeParser::Version0->new->parse('string_rw')->meta,
{
access => 'rw',
element_size => $pointer_size,
ffi_type => 'pointer',
size => $pointer_size,
type => 'string',
type_code => FFI_PL_TYPE_STRING,
},
'explicit rw string with underscore',
) or diag explain $type;
};
subtest array => sub {
is(
$type = FFI::Platypus::TypeParser::Version0->new->parse('uint64 [4]')->meta,
{
element_count => 4,
element_size => 8,
element_type => 'int',
ffi_type => 'uint64',
sign => 0,
size => 32,
type => 'array',
type_code => FFI_PL_TYPE_UINT64 | FFI_PL_SHAPE_ARRAY,
},
'fixed array',
) or diag explain $type;
is(
$type = FFI::Platypus::TypeParser::Version0->new->parse('uint64 []')->meta,
{
element_count => 0,
element_size => 8,
element_type => 'int',
ffi_type => 'uint64',
sign => 0,
size => 0,
type => 'array',
type_code => FFI_PL_TYPE_UINT64 | FFI_PL_SHAPE_ARRAY,
},
'variable array',
) or diag explain $type;
subtest 'longdouble' => sub {
skip_all 'test requires support for long double'
unless FFI::Platypus::TypeParser->have_type('longdouble');
is(
$type = FFI::Platypus::TypeParser::Version0->new->parse('longdouble []')->meta,
{
element_count => 0,
element_size => 16,
element_type => 'float',
ffi_type => 'longdouble',
size => 0,
type => 'array',
type_code => FFI_PL_TYPE_LONG_DOUBLE | FFI_PL_SHAPE_ARRAY,
},
'variable array',
) or diag explain $type;
};
subtest 'complex' => sub {
skip_all 'test requires support for complex'
unless FFI::Platypus::TypeParser->have_type('complex_float');
skip_all 'test requires support for complex'
unless FFI::Platypus::TypeParser->have_type('complex_double');
is(
$type = FFI::Platypus::TypeParser::Version0->new->parse('complex_float []')->meta,
{
element_count => 0,
element_size => 8,
element_type => 'float',
ffi_type => 'complex_float',
size => 0,
type => 'array',
type_code => FFI_PL_TYPE_COMPLEX_FLOAT | FFI_PL_SHAPE_ARRAY,
},
'variable array',
) or diag explain $type;
is(
$type = FFI::Platypus::TypeParser::Version0->new->parse('complex_double []')->meta,
{
element_count => 0,
element_size => 16,
element_type => 'float',
ffi_type => 'complex_double',
size => 0,
type => 'array',
type_code => FFI_PL_TYPE_COMPLEX_DOUBLE | FFI_PL_SHAPE_ARRAY,
},
'variable array',
) or diag explain $type;
};
};
subtest pointer => sub {
is(
$type = FFI::Platypus::TypeParser::Version0->new->parse('uint64 *')->meta,
{
element_size => 8,
element_type => 'int',
ffi_type => 'uint64',
sign => 0,
size => $pointer_size,
type => 'pointer',
type_code => FFI_PL_TYPE_UINT64 | FFI_PL_SHAPE_POINTER,
},
'pointer',
) or diag explain $type;
subtest 'longdouble' => sub {
skip_all 'test requires support for long double'
unless FFI::Platypus::TypeParser->have_type('longdouble');
is(
$type = FFI::Platypus::TypeParser::Version0->new->parse('longdouble *')->meta,
{
element_size => 16,
element_type => 'float',
ffi_type => 'longdouble',
size => $pointer_size,
type => 'pointer',
type_code => FFI_PL_TYPE_LONG_DOUBLE | FFI_PL_SHAPE_POINTER,
},
'longdouble pointer',
) or diag explain $type;
};
subtest 'complex' => sub {
skip_all 'test requires support for complex'
unless FFI::Platypus::TypeParser->have_type('complex_float');
skip_all 'test requires support for complex'
unless FFI::Platypus::TypeParser->have_type('complex_double');
is(
$type = FFI::Platypus::TypeParser::Version0->new->parse('complex_float *')->meta,
{
element_size => 8,
element_type => 'float',
ffi_type => 'complex_float',
size => $pointer_size,
type => 'pointer',
type_code => FFI_PL_TYPE_COMPLEX_FLOAT | FFI_PL_SHAPE_POINTER,
},
'complex float pointer',
) or diag explain $type;
is(
$type = FFI::Platypus::TypeParser::Version0->new->parse('complex_double *')->meta,
{
element_size => 16,
element_type => 'float',
ffi_type => 'complex_double',
size => $pointer_size,
type => 'pointer',
type_code => FFI_PL_TYPE_COMPLEX_DOUBLE | FFI_PL_SHAPE_POINTER,
},
'complex double pointer',
) or diag explain $type;
};
};
done_testing;
|