| 1 |
// Type conversion error should report its type. |
| 2 |
|
| 3 |
load(libdir + 'asserts.js'); |
| 4 |
|
| 5 |
function test() { |
| 6 |
// Note: js shell cannot handle the exception in return value. |
| 7 |
|
| 8 |
// primitive |
| 9 |
let func_type = ctypes.FunctionType(ctypes.default_abi, ctypes.voidptr_t, |
| 10 |
[ctypes.int32_t]).ptr; |
| 11 |
let f1 = func_type(function() {}); |
| 12 |
assertTypeErrorMessage(() => { f1("foo"); }, |
| 13 |
/can't pass the string "foo" to argument 1 of ctypes\.FunctionType\(ctypes\.default_abi, ctypes\.voidptr_t, \[ctypes\.int32_t\]\)\.ptr\(ctypes\.UInt64\("[x0-9A-Fa-f]+"\)\)/); |
| 14 |
|
| 15 |
// struct |
| 16 |
let test_struct = ctypes.StructType("test_struct", [{ "x": ctypes.int32_t }]); |
| 17 |
let func_type2 = ctypes.FunctionType(ctypes.default_abi, ctypes.int32_t, |
| 18 |
[test_struct]).ptr; |
| 19 |
let f2 = func_type2(function() {}); |
| 20 |
assertTypeErrorMessage(() => { f2({ "x": "foo" }); }, |
| 21 |
/can't convert the string \"foo\" to the 'x' field \(int32_t\) of test_struct at argument 1 of ctypes\.FunctionType\(ctypes\.default_abi, ctypes.int32_t, \[test_struct\]\)\.ptr\(ctypes\.UInt64\(\"[x0-9A-Fa-f]+\"\)\)/); |
| 22 |
assertTypeErrorMessage(() => { f2({ "x": "foo", "y": "bar" }); }, |
| 23 |
/property count of the object \(\{x:\"foo\", y:\"bar\"\}\) does not match to field count of the type test_struct \(expected 1, got 2\) at argument 1 of ctypes\.FunctionType\(ctypes\.default_abi, ctypes\.int32_t, \[test_struct\]\)\.ptr\(ctypes\.UInt64\(\"[x0-9A-Fa-f]+\"\)\)/); |
| 24 |
assertTypeErrorMessage(() => { f2({ 0: "foo" }); }, |
| 25 |
/property name the number 0 of the object \(\{0:\"foo\"\}\) is not a string at argument 1 of ctypes\.FunctionType\(ctypes\.default_abi, ctypes\.int32_t, \[test_struct\]\)\.ptr\(ctypes\.UInt64\(\"[x0-9A-Fa-f]+\"\)\)/); |
| 26 |
|
| 27 |
// error sentinel |
| 28 |
assertTypeErrorMessage(() => { func_type(function() {}, null, "foo"); }, |
| 29 |
"can't convert the string \"foo\" to the return type of ctypes.FunctionType(ctypes.default_abi, ctypes.voidptr_t, [ctypes.int32_t])"); |
| 30 |
} |
| 31 |
|
| 32 |
if (typeof ctypes === "object") |
| 33 |
test(); |