Add test for c alignment

This commit is contained in:
Joshua Suskalo 2022-01-10 14:37:56 -06:00
parent da12b26e3c
commit fb927e827a
2 changed files with 31 additions and 2 deletions

View file

@ -48,3 +48,18 @@ StringFactory get_downcall(int whichString) {
return 0;
}
}
typedef struct alignment_test {
char a;
double x;
float y;
} AlignmentTest;
AlignmentTest get_struct() {
AlignmentTest ret = {};
ret.a = 'x';
ret.x = 3.14;
ret.y = 42.0;
return ret;
}

View file

@ -1,8 +1,9 @@
(ns coffi.ffi-test
(:require
[clojure.test :as t]
[coffi.mem :as mem]
[coffi.ffi :as ffi]))
[coffi.ffi :as ffi]
[coffi.layout :as layout]
[coffi.mem :as mem]))
(ffi/load-library "target/ffi_test.so")
@ -30,3 +31,16 @@
(t/is (= ((ffi/cfn "upcall_test" [[::ffi/fn [] ::mem/c-string]] ::mem/c-string)
(fn [] "hello"))
"hello")))
(mem/defalias ::alignment-test
(layout/with-c-layout
[::mem/struct
[[:a ::mem/char]
[:x ::mem/double]
[:y ::mem/float]]]))
(t/deftest padding-matches
(t/is (= (dissoc ((ffi/cfn "get_struct" [] ::alignment-test)) ::layout/padding)
{:a \x
:x 3.14
:y 42.0})))