From c61e60681bf865510f0886031de841d5b1b63cf9 Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 23 Sep 2021 12:29:48 -0500 Subject: [PATCH] Add tests for some types --- test/clj/coffi/ffi_test.clj | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/clj/coffi/ffi_test.clj b/test/clj/coffi/ffi_test.clj index 07c58a2..3f08607 100644 --- a/test/clj/coffi/ffi_test.clj +++ b/test/clj/coffi/ffi_test.clj @@ -6,4 +6,20 @@ (sut/load-library "target/ffi_test.so") (t/deftest can-load-symbols - (t/is (not (nil? (sut/find-symbol "add_points"))))) + (t/is (not (nil? (sut/find-symbol "add_numbers"))))) + +(t/deftest can-call-primitive-fns + (t/is (= 5 ((sut/cfn "add_numbers" [::sut/int ::sut/int] ::sut/int) 2 3)))) + +(sut/defstruct ::point + :x ::sut/float + :y ::sut/float) + +(t/deftest can-call-with-structs + (t/is (= {:x 2.0 :y 2.0} + ((sut/cfn "add_points" [::point ::point] ::point) {:x 1 :y 2} {:x 1 :y 0})))) + +(t/deftest can-call-deserialized-fn-pointers + (t/is (= "Alternate string" + (((sut/cfn "get_downcall" [::sut/int] [::sut/fn [] ::sut/c-string :wrap-serde? true]) + 1)))))