Add tests for string variables in native
This commit is contained in:
parent
053166d0f4
commit
5d94afdbf3
2 changed files with 9 additions and 1 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
const int c = 42;
|
const int c = 42;
|
||||||
|
const char *s = "Test string";
|
||||||
|
|
||||||
int add_numbers(int a, int b) {
|
int add_numbers(int a, int b) {
|
||||||
return a + b;
|
return a + b;
|
||||||
|
|
@ -33,6 +34,7 @@ int upcall_test2(int (*f)(void)) {
|
||||||
return f();
|
return f();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *mut_str = NULL;
|
||||||
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" };
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,8 @@
|
||||||
(t/is (not (nil? (ffi/find-symbol "add_numbers")))))
|
(t/is (not (nil? (ffi/find-symbol "add_numbers")))))
|
||||||
|
|
||||||
(t/deftest can-fetch-constant
|
(t/deftest can-fetch-constant
|
||||||
(t/is (= 42 (ffi/const "c" ::mem/int))))
|
(t/is (= 42 (ffi/const "c" ::mem/int)))
|
||||||
|
(t/is (= "Test string" (ffi/const "s" ::mem/c-string))))
|
||||||
|
|
||||||
(t/deftest can-call-primitive-fns
|
(t/deftest can-call-primitive-fns
|
||||||
(t/is (= 5 ((ffi/cfn "add_numbers" [::mem/int ::mem/int] ::mem/int) 2 3))))
|
(t/is (= 5 ((ffi/cfn "add_numbers" [::mem/int ::mem/int] ::mem/int) 2 3))))
|
||||||
|
|
@ -59,6 +60,11 @@
|
||||||
:y 42.0})))
|
:y 42.0})))
|
||||||
|
|
||||||
(t/deftest static-variables-are-mutable
|
(t/deftest static-variables-are-mutable
|
||||||
|
(let [mut-str (ffi/static-variable "mut_str" ::mem/c-string)]
|
||||||
|
(ffi/freset! mut-str nil)
|
||||||
|
(t/is (nil? @mut-str))
|
||||||
|
(ffi/freset! mut-str "Hello world!")
|
||||||
|
(t/is (= "Hello world!" @mut-str)))
|
||||||
(ffi/freset! (ffi/static-variable "counter" ::mem/int) 1)
|
(ffi/freset! (ffi/static-variable "counter" ::mem/int) 1)
|
||||||
(t/is (= ((ffi/cfn "get_string1" [] ::mem/c-string))
|
(t/is (= ((ffi/cfn "get_string1" [] ::mem/c-string))
|
||||||
"Goodbye friend.")))
|
"Goodbye friend.")))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue