| 1 |
load(libdir + 'asserts.js'); |
| 2 |
|
| 3 |
function test() { |
| 4 |
assertRangeErrorMessage(() => { ctypes.FunctionType(ctypes.default_abi, ctypes.int32_t, []).ptr(x=>1)(1); }, |
| 5 |
"number of arguments does not match declaration of ctypes.FunctionType(ctypes.default_abi, ctypes.int32_t) (expected 0, got 1)"); |
| 6 |
|
| 7 |
assertTypeErrorMessage(() => { ctypes.FunctionType(ctypes.default_abi, ctypes.int32_t, [1]); }, |
| 8 |
"the type of argument 1 is not a ctypes type (got the number 1)"); |
| 9 |
assertTypeErrorMessage(() => { ctypes.FunctionType(ctypes.default_abi, ctypes.int32_t, [ctypes.void_t]); }, |
| 10 |
"the type of argument 1 cannot be void or function (got ctypes.void)"); |
| 11 |
assertTypeErrorMessage(() => { ctypes.FunctionType(ctypes.default_abi, ctypes.int32_t, [ctypes.FunctionType(ctypes.default_abi, ctypes.int32_t, [])]); }, |
| 12 |
"the type of argument 1 cannot be void or function (got ctypes.FunctionType(ctypes.default_abi, ctypes.int32_t))"); |
| 13 |
assertTypeErrorMessage(() => { ctypes.FunctionType(ctypes.default_abi, ctypes.int32_t, [ctypes.StructType("a")]); }, |
| 14 |
"the type of argument 1 must have defined size (got ctypes.StructType(\"a\"))"); |
| 15 |
|
| 16 |
assertTypeErrorMessage(() => { ctypes.FunctionType(ctypes.default_abi, ctypes.int32_t, [])(); }, |
| 17 |
"cannot construct from FunctionType; use FunctionType.ptr instead"); |
| 18 |
|
| 19 |
assertTypeErrorMessage(() => { ctypes.FunctionType(ctypes.default_abi, 1, []); }, |
| 20 |
"return type is not a ctypes type (got the number 1)"); |
| 21 |
assertTypeErrorMessage(() => { ctypes.FunctionType(ctypes.default_abi, ctypes.int32_t.array(), []); }, |
| 22 |
"return type cannot be an array or function (got ctypes.int32_t.array())"); |
| 23 |
assertTypeErrorMessage(() => { ctypes.FunctionType(ctypes.default_abi, ctypes.FunctionType(ctypes.default_abi, ctypes.int32_t, []), []); }, |
| 24 |
"return type cannot be an array or function (got ctypes.FunctionType(ctypes.default_abi, ctypes.int32_t))"); |
| 25 |
assertTypeErrorMessage(() => { ctypes.FunctionType(ctypes.default_abi, ctypes.StructType("a"), []); }, |
| 26 |
"return type must have defined size (got ctypes.StructType(\"a\"))"); |
| 27 |
|
| 28 |
let lib; |
| 29 |
try { |
| 30 |
lib = ctypes.open(ctypes.libraryName("m")); |
| 31 |
} catch (e) { |
| 32 |
} |
| 33 |
if (!lib) |
| 34 |
return; |
| 35 |
|
| 36 |
let func = lib.declare("hypot", |
| 37 |
ctypes.default_abi, |
| 38 |
ctypes.double, |
| 39 |
ctypes.double, "..."); |
| 40 |
assertRangeErrorMessage(() => { func(); }, |
| 41 |
"number of arguments does not match declaration of double hypot(double, ...) (expected 1 or more, got 0)"); |
| 42 |
assertTypeErrorMessage(() => { func(1, 2); }, |
| 43 |
"variadic argument 2 must be a CData object (got the number 2)"); |
| 44 |
} |
| 45 |
|
| 46 |
if (typeof ctypes === "object") |
| 47 |
test(); |