From 4a7659cf2a345aecebc39df82872050b30403bfb Mon Sep 17 00:00:00 2001 From: Kristin Rutenkolk Date: Mon, 17 Jun 2024 10:57:15 -0700 Subject: [PATCH] add more upcall tests --- build.clj | 16 ++++++++++++++++ test/c/ffi_test.c | 8 ++++++++ test/clj/coffi/ffi_test.clj | 10 ++++++++++ 3 files changed, 34 insertions(+) diff --git a/build.clj b/build.clj index af7aee3..756cc2d 100644 --- a/build.clj +++ b/build.clj @@ -134,3 +134,19 @@ [opts] (binding [*ns* (find-ns 'build)] (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) + +) + diff --git a/test/c/ffi_test.c b/test/c/ffi_test.c index c689e87..d0d4c03 100644 --- a/test/c/ffi_test.c +++ b/test/c/ffi_test.c @@ -26,10 +26,18 @@ CString upcall_test(StringFactory fun) { return fun(); } +int upcall_test2(int (*f)(void)) { + return f(); +} + int counter = 0; 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) { return responses[counter++ % 3]; } diff --git a/test/clj/coffi/ffi_test.clj b/test/clj/coffi/ffi_test.clj index 15cc4b6..45a724a 100644 --- a/test/clj/coffi/ffi_test.clj +++ b/test/clj/coffi/ffi_test.clj @@ -32,6 +32,16 @@ (fn [] "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 (layout/with-c-layout [::mem/struct