-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpointers.test.js
More file actions
33 lines (28 loc) · 1.12 KB
/
pointers.test.js
File metadata and controls
33 lines (28 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const expect = require("chai").expect;
const bind = require("./build/Release/napi_bind_test.node");
/**
* set_function(env, value, "create_struct_ptr", create_struct_ptr);
set_function(env, value, "create_void_ptr", create_void_ptr);
set_function(env, value, "create_null_ptr", create_null_ptr);
set_function(env, value, "delete_struct_ptr", delete_struct_ptr);
set_function(env, value, "identity_void_ptr", identity<void *>);
set_function(env, value, "identity_test_ptr", identity<test_struct *>);
*/
describe("pointers", () => {
const addr = bind.pointers.get_ptr_address;
it("nullptr", () => {
const nullptr = bind.pointers.create_null_ptr();
expect(nullptr).to.be.null;
expect(addr(nullptr)).to.eq(0n);
});
it("void *", () => {
const ptr = bind.pointers.create_void_ptr();
expect(addr(bind.pointers.identity_void_ptr(ptr))).to.eq(addr(ptr));
bind.pointers.delete_void_ptr(ptr);
});
it("struct *", () => {
const ptr = bind.pointers.create_struct_ptr();
expect(addr(bind.pointers.identity_struct_ptr(ptr))).to.eq(addr(ptr));
bind.pointers.delete_struct_ptr(ptr);
});
});