diff options
Diffstat (limited to 'test_ffi/tests')
-rw-r--r-- | test_ffi/tests/bench.js | 33 | ||||
-rw-r--r-- | test_ffi/tests/ffi_types.ts | 24 | ||||
-rw-r--r-- | test_ffi/tests/integration_tests.rs | 2 | ||||
-rw-r--r-- | test_ffi/tests/test.js | 3 |
4 files changed, 62 insertions, 0 deletions
diff --git a/test_ffi/tests/bench.js b/test_ffi/tests/bench.js index c1a3d630f..b59097082 100644 --- a/test_ffi/tests/bench.js +++ b/test_ffi/tests/bench.js @@ -15,6 +15,7 @@ const dylib = Deno.dlopen(libPath, { "add_u64": { parameters: ["u64", "u64"], result: "u64" }, "ffi_string": { parameters: [], result: "pointer" }, "hash": { parameters: ["buffer", "u32"], result: "u32" }, + "nop_bool": { parameters: ["bool"], result: "void" }, "nop_u8": { parameters: ["u8"], result: "void" }, "nop_i8": { parameters: ["i8"], result: "void" }, "nop_u16": { parameters: ["u16"], result: "void" }, @@ -28,6 +29,7 @@ const dylib = Deno.dlopen(libPath, { "nop_f32": { parameters: ["f32"], result: "void" }, "nop_f64": { parameters: ["f64"], result: "void" }, "nop_buffer": { parameters: ["buffer"], result: "void" }, + "return_bool": { parameters: [], result: "bool" }, "return_u8": { parameters: [], result: "u8" }, "return_i8": { parameters: [], result: "i8" }, "return_u16": { parameters: [], result: "u16" }, @@ -43,6 +45,11 @@ const dylib = Deno.dlopen(libPath, { "return_buffer": { parameters: [], result: "buffer" }, // Nonblocking calls "nop_nonblocking": { name: "nop", parameters: [], result: "void" }, + "nop_bool_nonblocking": { + name: "nop_bool", + parameters: ["bool"], + result: "void", + }, "nop_u8_nonblocking": { name: "nop_u8", parameters: ["u8"], result: "void" }, "nop_i8_nonblocking": { name: "nop_i8", parameters: ["i8"], result: "void" }, "nop_u16_nonblocking": { @@ -100,6 +107,11 @@ const dylib = Deno.dlopen(libPath, { parameters: ["buffer"], result: "void", }, + "return_bool_nonblocking": { + name: "return_bool", + parameters: [], + result: "bool", + }, "return_u8_nonblocking": { name: "return_u8", parameters: [], result: "u8" }, "return_i8_nonblocking": { name: "return_i8", parameters: [], result: "i8" }, "return_u16_nonblocking": { @@ -267,6 +279,11 @@ Deno.bench("return_i64()", () => { return_i64(); }); +const { nop_bool } = dylib.symbols; +Deno.bench("nop_bool()", () => { + nop_bool(true); +}); + const { nop_u8 } = dylib.symbols; Deno.bench("nop_u8()", () => { nop_u8(100); @@ -343,6 +360,11 @@ Deno.bench("nop_buffer()", () => { nop_buffer(buffer); }); +const { return_bool } = dylib.symbols; +Deno.bench("return_bool()", () => { + return_bool(); +}); + const { return_u8 } = dylib.symbols; Deno.bench("return_u8()", () => { return_u8(); @@ -400,6 +422,11 @@ Deno.bench("nop_nonblocking()", async () => { await nop_nonblocking(); }); +const { nop_bool_nonblocking } = dylib.symbols; +Deno.bench("nop_bool_nonblocking()", async () => { + await nop_bool_nonblocking(true); +}); + const { nop_u8_nonblocking } = dylib.symbols; Deno.bench("nop_u8_nonblocking()", async () => { await nop_u8_nonblocking(100); @@ -465,6 +492,12 @@ const { nop_buffer_nonblocking } = dylib.symbols; Deno.bench("nop_buffer_nonblocking()", async () => { await nop_buffer_nonblocking(buffer); }); + +const { return_bool_nonblocking } = dylib.symbols; +Deno.bench("return_bool_nonblocking()", async () => { + await return_bool_nonblocking(); +}); + const { return_u8_nonblocking } = dylib.symbols; Deno.bench("return_u8_nonblocking()", async () => { await return_u8_nonblocking(); diff --git a/test_ffi/tests/ffi_types.ts b/test_ffi/tests/ffi_types.ts index be8a3f770..76c013a8f 100644 --- a/test_ffi/tests/ffi_types.ts +++ b/test_ffi/tests/ffi_types.ts @@ -42,6 +42,10 @@ const remote = Deno.dlopen( parameters: ["buffer"], result: "void", }, + method24: { + parameters: ["bool"], + result: "bool", + }, static1: { type: "usize" }, static2: { type: "pointer" }, static3: { type: "usize" }, @@ -56,6 +60,7 @@ const remote = Deno.dlopen( static12: { type: "i64" }, static13: { type: "f32" }, static14: { type: "f64" }, + static15: { type: "bool" }, } as const, ); @@ -258,6 +263,22 @@ remote.symbols.method23(0); remote.symbols.method23(0n); remote.symbols.method23(null); +// @ts-expect-error: Cannot pass number as bool. +remote.symbols.method24(0); +// @ts-expect-error: Cannot pass number as bool. +remote.symbols.method24(1); +// @ts-expect-error: Cannot pass null as bool. +remote.symbols.method24(null); +remote.symbols.method24(true); +remote.symbols.method24(false); +// @ts-expect-error: Cannot assert return type as a number. +<number> remote.symbols.method24(true); +// @ts-expect-error: Cannot assert return type truthiness. +let r24_0: true = remote.symbols.method24(true); +// @ts-expect-error: Cannot assert return type as a number. +let r42_1: number = remote.symbols.method24(true); +<boolean> remote.symbols.method24(Math.random() > 0.5); + // @ts-expect-error: Invalid member type const static1_wrong: null = remote.symbols.static1; const static1_right: Deno.PointerValue = remote.symbols.static1; @@ -300,6 +321,9 @@ const static13_right: number = remote.symbols.static13; // @ts-expect-error: Invalid member type const static14_wrong: null = remote.symbols.static14; const static14_right: number = remote.symbols.static14; +// @ts-expect-error: Invalid member type +const static15_wrong: number = remote.symbols.static15; +const static15_right: boolean = remote.symbols.static15; // Adapted from https://stackoverflow.com/a/53808212/10873797 type Equal<T, U> = (<G>() => G extends T ? 1 : 2) extends diff --git a/test_ffi/tests/integration_tests.rs b/test_ffi/tests/integration_tests.rs index 079293550..88da8a0b9 100644 --- a/test_ffi/tests/integration_tests.rs +++ b/test_ffi/tests/integration_tests.rs @@ -78,6 +78,8 @@ fn basic() { -9007199254740992n\n\ 579.9119873046875\n\ 579.912\n\ + true\n\ + false\n\ 579\n\ 8589934590\n\ -8589934590\n\ diff --git a/test_ffi/tests/test.js b/test_ffi/tests/test.js index 7e8c41cfe..f71f23adc 100644 --- a/test_ffi/tests/test.js +++ b/test_ffi/tests/test.js @@ -59,6 +59,7 @@ const dylib = Deno.dlopen(libPath, { "add_isize": { parameters: ["isize", "isize"], result: "isize" }, "add_f32": { parameters: ["f32", "f32"], result: "f32" }, "add_f64": { parameters: ["f64", "f64"], result: "f64" }, + "and": { parameters: ["bool", "bool"], result: "bool" }, "add_u32_nonblocking": { name: "add_u32", parameters: ["u32", "u32"], @@ -290,6 +291,8 @@ console.log(dylib.symbols.add_isize(Number.MAX_SAFE_INTEGER, 1)); console.log(dylib.symbols.add_isize(Number.MIN_SAFE_INTEGER, -1)); console.log(dylib.symbols.add_f32(123.123, 456.789)); console.log(dylib.symbols.add_f64(123.123, 456.789)); +console.log(dylib.symbols.and(true, true)); +console.log(dylib.symbols.and(true, false)); // Test adders as nonblocking calls console.log(await dylib.symbols.add_i32_nonblocking(123, 456)); |