add more upcall tests
This commit is contained in:
parent
c740745d49
commit
4a7659cf2a
3 changed files with 34 additions and 0 deletions
16
build.clj
16
build.clj
|
|
@ -134,3 +134,19 @@
|
||||||
[opts]
|
[opts]
|
||||||
(binding [*ns* (find-ns 'build)]
|
(binding [*ns* (find-ns 'build)]
|
||||||
(run! (call-optionally-with opts) (:tasks opts))))
|
(run! (call-optionally-with opts) (:tasks opts))))
|
||||||
|
|
||||||
|
|
||||||
|
(def prep-all ['compile-java 'compile-test-library])
|
||||||
|
|
||||||
|
(comment
|
||||||
|
|
||||||
|
(compile-java)
|
||||||
|
|
||||||
|
(compile-test-library)
|
||||||
|
|
||||||
|
(run-tasks prep-all)
|
||||||
|
|
||||||
|
(compile-test-library)
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,18 @@ CString upcall_test(StringFactory fun) {
|
||||||
return fun();
|
return fun();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int upcall_test2(int (*f)(void)) {
|
||||||
|
return f();
|
||||||
|
}
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
|
||||||
static char* responses[] = { "Hello, world!", "Goodbye friend.", "co'oi prenu" };
|
static char* responses[] = { "Hello, world!", "Goodbye friend.", "co'oi prenu" };
|
||||||
|
|
||||||
|
char* upcall_test_int_fn_string_ret(int (*f)(void)) {
|
||||||
|
return responses[f()];
|
||||||
|
}
|
||||||
|
|
||||||
CString get_string1(void) {
|
CString get_string1(void) {
|
||||||
return responses[counter++ % 3];
|
return responses[counter++ % 3];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,16 @@
|
||||||
(fn [] "hello"))
|
(fn [] "hello"))
|
||||||
"hello")))
|
"hello")))
|
||||||
|
|
||||||
|
(t/deftest can-make-upcall2
|
||||||
|
(t/is (= ((ffi/cfn "upcall_test2" [[::ffi/fn [] ::mem/int]] ::mem/int)
|
||||||
|
(fn [] 6))
|
||||||
|
5)))
|
||||||
|
|
||||||
|
(t/deftest can-make-upcall-int-fn-string-ret
|
||||||
|
(t/is (= ((ffi/cfn "upcall_test_int_fn_string_ret" [[::ffi/fn [] ::mem/int]] ::mem/c-string)
|
||||||
|
(fn [] 2))
|
||||||
|
"co'oi prenu")))
|
||||||
|
|
||||||
(mem/defalias ::alignment-test
|
(mem/defalias ::alignment-test
|
||||||
(layout/with-c-layout
|
(layout/with-c-layout
|
||||||
[::mem/struct
|
[::mem/struct
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue