From 2d46929f0795ff7bb708d945466ada1a896fddd7 Mon Sep 17 00:00:00 2001 From: Sara Date: Mon, 11 Sep 2023 18:44:37 +0200 Subject: [PATCH] wrote test --- test_files/header.h | 55 +++++++++++++++++++++++++++++++++++++ test_files/implementation.c | 35 +++++++++++++++++++++++ test_include/kwil.h | 8 ++++++ 3 files changed, 98 insertions(+) create mode 100644 test_files/header.h create mode 100644 test_files/implementation.c create mode 100644 test_include/kwil.h diff --git a/test_files/header.h b/test_files/header.h new file mode 100644 index 0000000..ba3014b --- /dev/null +++ b/test_files/header.h @@ -0,0 +1,55 @@ +#ifndef _TEST_HEADER_H +#define _TEST_HEADER_H + +#include "kwil.h" +#include "header.kwil.h" + +KWIL_ENUM() +enum enum_A { + VALUE_A, + VALUE_B, + VALUE_C +}; + +KWIL_STRUCT() +struct struct_A { + KWIL_FIELD() + int b; + KWIL_FIELD() + float a; + KWIL_FIELD() + unsigned u; + KWIL_FIELD() + char* dyn_str; +}; + +typedef enum enum_A enum_A; +typedef struct struct_A struct_A; + +KWIL_STRUCT() +struct struct_B { + KWIL_FIELD() + float f; + + float f_NOT_KWIL; + int i_NOT_KWIL; + + KWIL_FIELD() + int i; + KWIL_FIELD() + char* str; + KWIL_FIELD() + char str_static[44]; + + KWIL_FIELD() + struct struct_A other_struct; + KWIL_FIELD() + struct_A other_struct_typedef; + + KWIL_FIELD() + enum enum_A other_enum; + KWIL_FIELD() + enum_A other_enum_typedef; +}; + +#endif // !_TEST_HEADER_H diff --git a/test_files/implementation.c b/test_files/implementation.c new file mode 100644 index 0000000..4a75219 --- /dev/null +++ b/test_files/implementation.c @@ -0,0 +1,35 @@ +#include "header.h" + +#include +#include +#include +#include + +KWIL_GEN_IMPL() + +int main(int argc, char* argv[]) { + printf("running kwil test\n"); + struct struct_A b = { + .b = -10, + .u = 13, + .a = 1.0, + .dyn_str = "WHOOAAAAA" + }; + char* json = NULL; + int json_len = struct_A_to_json(&b, &json); + + printf("allocated %d bytes for json of struct_A\n", json_len); + printf("struct_A as json:\n%s\n", json); + + int real_len = strlen(json); + + free(json); + + if(real_len != json_len) { + printf("Json Length (%d) does not match allocated space %d\n", real_len, json_len); + return 1; + } + + return 0; +} + diff --git a/test_include/kwil.h b/test_include/kwil.h new file mode 100644 index 0000000..a7aeb1a --- /dev/null +++ b/test_include/kwil.h @@ -0,0 +1,8 @@ +#ifndef _kwil_macros_h +#define _kwil_macros_h + +#define KWIL_ENUM(...) +#define KWIL_FIELD(...) +#define KWIL_STRUCT(...) + +#endif // !_kwil_macros_h