| 1 |
// Type conversion error should report its type. |
| 2 |
|
| 3 |
load(libdir + 'asserts.js'); |
| 4 |
|
| 5 |
function test() { |
| 6 |
// constructor |
| 7 |
assertTypeErrorMessage(() => { ctypes.int32_t("foo"); }, |
| 8 |
"can't convert the string \"foo\" to the type int32_t"); |
| 9 |
assertTypeErrorMessage(() => { ctypes.int32_t(null); }, |
| 10 |
"can't convert null to the type int32_t"); |
| 11 |
assertTypeErrorMessage(() => { ctypes.int32_t(undefined); }, |
| 12 |
"can't convert undefined to the type int32_t"); |
| 13 |
assertTypeErrorMessage(() => { ctypes.int32_t({}); }, |
| 14 |
"can't convert the object ({}) to the type int32_t"); |
| 15 |
assertTypeErrorMessage(() => { ctypes.int32_t([]); }, |
| 16 |
"can't convert the array [] to the type int32_t"); |
| 17 |
assertTypeErrorMessage(() => { ctypes.int32_t(new Int8Array([])); }, |
| 18 |
"can't convert the typed array ({}) to the type int32_t"); |
| 19 |
assertTypeErrorMessage(() => { ctypes.int32_t(ctypes.int32_t); }, |
| 20 |
"can't convert ctypes.int32_t to the type int32_t"); |
| 21 |
assertRangeErrorMessage(() => { ctypes.int32_t("0xfffffffffffffffffffffff"); }, |
| 22 |
"the string \"0xfffffffffffffffffffffff\" does not fit in the type int32_t"); |
| 23 |
if (typeof Symbol === "function") { |
| 24 |
assertTypeErrorMessage(() => { ctypes.int32_t(Symbol.iterator); }, |
| 25 |
"can't convert Symbol.iterator to the type int32_t"); |
| 26 |
assertTypeErrorMessage(() => { ctypes.int32_t(Symbol("foo")); }, |
| 27 |
"can't convert Symbol(\"foo\") to the type int32_t"); |
| 28 |
} |
| 29 |
|
| 30 |
// value setter |
| 31 |
let test_struct = ctypes.StructType("test_struct", [{ "x": ctypes.int32_t }]); |
| 32 |
let struct_val = test_struct(); |
| 33 |
assertTypeErrorMessage(() => { ctypes.bool().value = struct_val; }, |
| 34 |
"can't convert test_struct(0) to the type boolean"); |
| 35 |
assertTypeErrorMessage(() => { ctypes.char16_t().value = struct_val; }, |
| 36 |
"can't convert test_struct(0) to the type char16_t"); |
| 37 |
assertTypeErrorMessage(() => { ctypes.int8_t().value = struct_val; }, |
| 38 |
"can't convert test_struct(0) to the type int8_t"); |
| 39 |
assertTypeErrorMessage(() => { ctypes.double().value = struct_val; }, |
| 40 |
"can't convert test_struct(0) to the type double"); |
| 41 |
} |
| 42 |
|
| 43 |
if (typeof ctypes === "object") |
| 44 |
test(); |