File tree Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 11* Support var args (` va_list ` )
22* Test with actual threads.
3- * Test that longer-lived (i.e. called more than once) callbacks work.
43* Build or recommend a library for dealing with C structs/enums/unions.
Original file line number Diff line number Diff line change 1010 void test_add_async_##t(t a, t b, void (*cb)(t)) {\
1111 cb(a + b);\
1212 }\
13+ void test_add_async_twice_##t(t a, t b, void (*cb)(t)) {\
14+ cb(a + b);\
15+ cb(a + b);\
16+ }\
1317
1418mk_adder (uint8_t )
1519mk_adder (uint16_t )
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ const test = pitesti();
1010let add ;
1111let addPtr ;
1212let addAsync ;
13+ let addTwiceAsync ;
1314
1415const libAdder = path . join ( __dirname , 'adder' , 'libadder.so' ) ;
1516
@@ -34,6 +35,13 @@ test`get functions`(() => {
3435 'void' ,
3536 [ 'uint32_t' , 'uint32_t' , [ 'void' , [ 'uint32_t' ] ] ]
3637 ) ;
38+
39+ addTwiceAsync = getNativeFunction (
40+ libAdder ,
41+ 'test_add_async_twice_uint32_t' ,
42+ 'void' ,
43+ [ 'uint32_t' , 'uint32_t' , [ 'void' , [ 'uint32_t' ] ] ]
44+ ) ;
3745} ) ;
3846
3947test `basic adding` ( ( ) => {
@@ -71,4 +79,14 @@ test`promisified adding`(async () => {
7179 assert . strictEqual ( await addPromise ( 5 , 3 ) , 8 ) ;
7280} ) ;
7381
82+ test `calling callback more than once` ( ( done ) => {
83+ let counter = 0 ;
84+ addTwiceAsync ( 4 , 5 , ( result ) => {
85+ assert . strictEqual ( result , 9 ) ;
86+ if ( ++ counter === 2 ) {
87+ done ( ) ;
88+ }
89+ } ) ;
90+ } ) ;
91+
7492test ( ) ;
You can’t perform that action at this time.
0 commit comments