| 1 |
use Test2::V0 -no_srand => 1; |
| 2 |
use FFI::Platypus; |
| 3 |
use FFI::Platypus::TypeParser; |
| 4 |
use FFI::Platypus::Internal; |
| 5 |
use FFI::Platypus::TypeParser::Version0; |
| 6 |
|
| 7 |
my $ffi = FFI::Platypus->new; |
| 8 |
my $type; |
| 9 |
my $pointer_size = $ffi->sizeof('opaque'); |
| 10 |
|
| 11 |
subtest basic => sub { |
| 12 |
|
| 13 |
is( |
| 14 |
$type = FFI::Platypus::TypeParser::Version0->new->parse('uint64')->meta, |
| 15 |
{ |
| 16 |
element_size => 8, |
| 17 |
element_type => 'int', |
| 18 |
ffi_type => 'uint64', |
| 19 |
sign => 0, |
| 20 |
size => 8, |
| 21 |
type => 'scalar', |
| 22 |
type_code => FFI_PL_TYPE_UINT64, |
| 23 |
}, |
| 24 |
'basic basic', |
| 25 |
) or diag explain $type; |
| 26 |
|
| 27 |
subtest 'longdouble' => sub { |
| 28 |
|
| 29 |
skip_all 'test requires support for long double' |
| 30 |
unless FFI::Platypus::TypeParser->have_type('longdouble'); |
| 31 |
|
| 32 |
is( |
| 33 |
$type = FFI::Platypus::TypeParser::Version0->new->parse('longdouble')->meta, |
| 34 |
{ |
| 35 |
element_size => 16, |
| 36 |
element_type => 'float', |
| 37 |
ffi_type => 'longdouble', |
| 38 |
size => 16, |
| 39 |
type => 'scalar', |
| 40 |
type_code => FFI_PL_TYPE_LONG_DOUBLE, |
| 41 |
}, |
| 42 |
'longdouble', |
| 43 |
) or diag explain $type; |
| 44 |
|
| 45 |
}; |
| 46 |
|
| 47 |
subtest 'complex' => sub { |
| 48 |
|
| 49 |
skip_all 'test requires support for complex' |
| 50 |
unless FFI::Platypus::TypeParser->have_type('complex_float'); |
| 51 |
|
| 52 |
skip_all 'test requires support for complex' |
| 53 |
unless FFI::Platypus::TypeParser->have_type('complex_double'); |
| 54 |
|
| 55 |
is( |
| 56 |
$type = FFI::Platypus::TypeParser::Version0->new->parse('complex_float')->meta, |
| 57 |
{ |
| 58 |
element_size => 8, |
| 59 |
element_type => 'float', |
| 60 |
ffi_type => 'complex_float', |
| 61 |
size => 8, |
| 62 |
type => 'scalar', |
| 63 |
type_code => FFI_PL_TYPE_COMPLEX_FLOAT, |
| 64 |
}, |
| 65 |
'complex float', |
| 66 |
) or diag explain $type; |
| 67 |
|
| 68 |
is( |
| 69 |
$type = FFI::Platypus::TypeParser::Version0->new->parse('complex_double')->meta, |
| 70 |
{ |
| 71 |
element_size => 16, |
| 72 |
element_type => 'float', |
| 73 |
ffi_type => 'complex_double', |
| 74 |
size => 16, |
| 75 |
type => 'scalar', |
| 76 |
type_code => FFI_PL_TYPE_COMPLEX_DOUBLE, |
| 77 |
}, |
| 78 |
'complex double', |
| 79 |
) or diag explain $type; |
| 80 |
|
| 81 |
}; |
| 82 |
|
| 83 |
}; |
| 84 |
|
| 85 |
subtest record => sub { |
| 86 |
|
| 87 |
is( |
| 88 |
$type = FFI::Platypus::TypeParser::Version0->new->parse('string(42)')->meta, |
| 89 |
{ |
| 90 |
ffi_type => 'pointer', |
| 91 |
ref => 0, |
| 92 |
size => 42, |
| 93 |
type => 'record', |
| 94 |
type_code => FFI_PL_TYPE_RECORD, |
| 95 |
}, |
| 96 |
'fixed string', |
| 97 |
) or diag explain $type; |
| 98 |
|
| 99 |
is( |
| 100 |
$type = FFI::Platypus::TypeParser::Version0->new->parse('record(42)')->meta, |
| 101 |
{ |
| 102 |
ffi_type => 'pointer', |
| 103 |
ref => 0, |
| 104 |
size => 42, |
| 105 |
type => 'record', |
| 106 |
type_code => FFI_PL_TYPE_RECORD, |
| 107 |
}, |
| 108 |
'unclassed record', |
| 109 |
) or diag explain $type; |
| 110 |
|
| 111 |
{ package |
| 112 |
Foo::Bar::Baz; |
| 113 |
use FFI::Platypus::Record; |
| 114 |
record_layout (qw( |
| 115 |
sint64 foo |
| 116 |
)); |
| 117 |
} |
| 118 |
|
| 119 |
is( |
| 120 |
$type =FFI::Platypus::TypeParser::Version0->new->parse('record(Foo::Bar::Baz)')->meta, |
| 121 |
{ |
| 122 |
ffi_type => 'pointer', |
| 123 |
ref => 1, |
| 124 |
size => 8, |
| 125 |
type => 'record', |
| 126 |
type_code => FFI_PL_TYPE_RECORD, |
| 127 |
class => 'Foo::Bar::Baz', |
| 128 |
}, |
| 129 |
'classed record', |
| 130 |
) or diag explain $type; |
| 131 |
|
| 132 |
}; |
| 133 |
|
| 134 |
subtest string => sub { |
| 135 |
|
| 136 |
is( |
| 137 |
$type = FFI::Platypus::TypeParser::Version0->new->parse('string')->meta, |
| 138 |
{ |
| 139 |
access => 'ro', |
| 140 |
element_size => $pointer_size, |
| 141 |
ffi_type => 'pointer', |
| 142 |
size => $pointer_size, |
| 143 |
type => 'string', |
| 144 |
type_code => FFI_PL_TYPE_STRING, |
| 145 |
}, |
| 146 |
'default string', |
| 147 |
) or diag explain $type; |
| 148 |
|
| 149 |
is( |
| 150 |
$type = FFI::Platypus::TypeParser::Version0->new->parse('string ro')->meta, |
| 151 |
{ |
| 152 |
access => 'ro', |
| 153 |
element_size => $pointer_size, |
| 154 |
ffi_type => 'pointer', |
| 155 |
size => $pointer_size, |
| 156 |
type => 'string', |
| 157 |
type_code => FFI_PL_TYPE_STRING, |
| 158 |
}, |
| 159 |
'explicit ro string', |
| 160 |
) or diag explain $type; |
| 161 |
|
| 162 |
is( |
| 163 |
$type = FFI::Platypus::TypeParser::Version0->new->parse('string_ro')->meta, |
| 164 |
{ |
| 165 |
access => 'ro', |
| 166 |
element_size => $pointer_size, |
| 167 |
ffi_type => 'pointer', |
| 168 |
size => $pointer_size, |
| 169 |
type => 'string', |
| 170 |
type_code => FFI_PL_TYPE_STRING, |
| 171 |
}, |
| 172 |
'explicit ro string with underscore', |
| 173 |
) or diag explain $type; |
| 174 |
|
| 175 |
is( |
| 176 |
$type = FFI::Platypus::TypeParser::Version0->new->parse('string rw')->meta, |
| 177 |
{ |
| 178 |
access => 'rw', |
| 179 |
element_size => $pointer_size, |
| 180 |
ffi_type => 'pointer', |
| 181 |
size => $pointer_size, |
| 182 |
type => 'string', |
| 183 |
type_code => FFI_PL_TYPE_STRING, |
| 184 |
}, |
| 185 |
'explicit rw string', |
| 186 |
) or diag explain $type; |
| 187 |
|
| 188 |
is( |
| 189 |
$type = FFI::Platypus::TypeParser::Version0->new->parse('string_rw')->meta, |
| 190 |
{ |
| 191 |
access => 'rw', |
| 192 |
element_size => $pointer_size, |
| 193 |
ffi_type => 'pointer', |
| 194 |
size => $pointer_size, |
| 195 |
type => 'string', |
| 196 |
type_code => FFI_PL_TYPE_STRING, |
| 197 |
}, |
| 198 |
'explicit rw string with underscore', |
| 199 |
) or diag explain $type; |
| 200 |
|
| 201 |
}; |
| 202 |
|
| 203 |
subtest array => sub { |
| 204 |
|
| 205 |
is( |
| 206 |
$type = FFI::Platypus::TypeParser::Version0->new->parse('uint64 [4]')->meta, |
| 207 |
{ |
| 208 |
element_count => 4, |
| 209 |
element_size => 8, |
| 210 |
element_type => 'int', |
| 211 |
ffi_type => 'uint64', |
| 212 |
sign => 0, |
| 213 |
size => 32, |
| 214 |
type => 'array', |
| 215 |
type_code => FFI_PL_TYPE_UINT64 | FFI_PL_SHAPE_ARRAY, |
| 216 |
}, |
| 217 |
'fixed array', |
| 218 |
) or diag explain $type; |
| 219 |
|
| 220 |
is( |
| 221 |
$type = FFI::Platypus::TypeParser::Version0->new->parse('uint64 []')->meta, |
| 222 |
{ |
| 223 |
element_count => 0, |
| 224 |
element_size => 8, |
| 225 |
element_type => 'int', |
| 226 |
ffi_type => 'uint64', |
| 227 |
sign => 0, |
| 228 |
size => 0, |
| 229 |
type => 'array', |
| 230 |
type_code => FFI_PL_TYPE_UINT64 | FFI_PL_SHAPE_ARRAY, |
| 231 |
}, |
| 232 |
'variable array', |
| 233 |
) or diag explain $type; |
| 234 |
|
| 235 |
subtest 'longdouble' => sub { |
| 236 |
|
| 237 |
skip_all 'test requires support for long double' |
| 238 |
unless FFI::Platypus::TypeParser->have_type('longdouble'); |
| 239 |
|
| 240 |
is( |
| 241 |
$type = FFI::Platypus::TypeParser::Version0->new->parse('longdouble []')->meta, |
| 242 |
{ |
| 243 |
element_count => 0, |
| 244 |
element_size => 16, |
| 245 |
element_type => 'float', |
| 246 |
ffi_type => 'longdouble', |
| 247 |
size => 0, |
| 248 |
type => 'array', |
| 249 |
type_code => FFI_PL_TYPE_LONG_DOUBLE | FFI_PL_SHAPE_ARRAY, |
| 250 |
}, |
| 251 |
'variable array', |
| 252 |
) or diag explain $type; |
| 253 |
|
| 254 |
}; |
| 255 |
|
| 256 |
subtest 'complex' => sub { |
| 257 |
|
| 258 |
skip_all 'test requires support for complex' |
| 259 |
unless FFI::Platypus::TypeParser->have_type('complex_float'); |
| 260 |
|
| 261 |
skip_all 'test requires support for complex' |
| 262 |
unless FFI::Platypus::TypeParser->have_type('complex_double'); |
| 263 |
|
| 264 |
is( |
| 265 |
$type = FFI::Platypus::TypeParser::Version0->new->parse('complex_float []')->meta, |
| 266 |
{ |
| 267 |
element_count => 0, |
| 268 |
element_size => 8, |
| 269 |
element_type => 'float', |
| 270 |
ffi_type => 'complex_float', |
| 271 |
size => 0, |
| 272 |
type => 'array', |
| 273 |
type_code => FFI_PL_TYPE_COMPLEX_FLOAT | FFI_PL_SHAPE_ARRAY, |
| 274 |
}, |
| 275 |
'variable array', |
| 276 |
) or diag explain $type; |
| 277 |
|
| 278 |
is( |
| 279 |
$type = FFI::Platypus::TypeParser::Version0->new->parse('complex_double []')->meta, |
| 280 |
{ |
| 281 |
element_count => 0, |
| 282 |
element_size => 16, |
| 283 |
element_type => 'float', |
| 284 |
ffi_type => 'complex_double', |
| 285 |
size => 0, |
| 286 |
type => 'array', |
| 287 |
type_code => FFI_PL_TYPE_COMPLEX_DOUBLE | FFI_PL_SHAPE_ARRAY, |
| 288 |
}, |
| 289 |
'variable array', |
| 290 |
) or diag explain $type; |
| 291 |
|
| 292 |
}; |
| 293 |
|
| 294 |
}; |
| 295 |
|
| 296 |
subtest pointer => sub { |
| 297 |
|
| 298 |
is( |
| 299 |
$type = FFI::Platypus::TypeParser::Version0->new->parse('uint64 *')->meta, |
| 300 |
{ |
| 301 |
element_size => 8, |
| 302 |
element_type => 'int', |
| 303 |
ffi_type => 'uint64', |
| 304 |
sign => 0, |
| 305 |
size => $pointer_size, |
| 306 |
type => 'pointer', |
| 307 |
type_code => FFI_PL_TYPE_UINT64 | FFI_PL_SHAPE_POINTER, |
| 308 |
}, |
| 309 |
'pointer', |
| 310 |
) or diag explain $type; |
| 311 |
|
| 312 |
subtest 'longdouble' => sub { |
| 313 |
|
| 314 |
skip_all 'test requires support for long double' |
| 315 |
unless FFI::Platypus::TypeParser->have_type('longdouble'); |
| 316 |
|
| 317 |
is( |
| 318 |
$type = FFI::Platypus::TypeParser::Version0->new->parse('longdouble *')->meta, |
| 319 |
{ |
| 320 |
element_size => 16, |
| 321 |
element_type => 'float', |
| 322 |
ffi_type => 'longdouble', |
| 323 |
size => $pointer_size, |
| 324 |
type => 'pointer', |
| 325 |
type_code => FFI_PL_TYPE_LONG_DOUBLE | FFI_PL_SHAPE_POINTER, |
| 326 |
}, |
| 327 |
'longdouble pointer', |
| 328 |
) or diag explain $type; |
| 329 |
|
| 330 |
}; |
| 331 |
|
| 332 |
subtest 'complex' => sub { |
| 333 |
|
| 334 |
skip_all 'test requires support for complex' |
| 335 |
unless FFI::Platypus::TypeParser->have_type('complex_float'); |
| 336 |
|
| 337 |
skip_all 'test requires support for complex' |
| 338 |
unless FFI::Platypus::TypeParser->have_type('complex_double'); |
| 339 |
|
| 340 |
is( |
| 341 |
$type = FFI::Platypus::TypeParser::Version0->new->parse('complex_float *')->meta, |
| 342 |
{ |
| 343 |
element_size => 8, |
| 344 |
element_type => 'float', |
| 345 |
ffi_type => 'complex_float', |
| 346 |
size => $pointer_size, |
| 347 |
type => 'pointer', |
| 348 |
type_code => FFI_PL_TYPE_COMPLEX_FLOAT | FFI_PL_SHAPE_POINTER, |
| 349 |
}, |
| 350 |
'complex float pointer', |
| 351 |
) or diag explain $type; |
| 352 |
|
| 353 |
is( |
| 354 |
$type = FFI::Platypus::TypeParser::Version0->new->parse('complex_double *')->meta, |
| 355 |
{ |
| 356 |
element_size => 16, |
| 357 |
element_type => 'float', |
| 358 |
ffi_type => 'complex_double', |
| 359 |
size => $pointer_size, |
| 360 |
type => 'pointer', |
| 361 |
type_code => FFI_PL_TYPE_COMPLEX_DOUBLE | FFI_PL_SHAPE_POINTER, |
| 362 |
}, |
| 363 |
'complex double pointer', |
| 364 |
) or diag explain $type; |
| 365 |
|
| 366 |
}; |
| 367 |
|
| 368 |
}; |
| 369 |
|
| 370 |
done_testing; |