2023-09-11 16:44:37 +00:00
|
|
|
#include "header.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
KWIL_GEN_IMPL()
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
printf("running kwil test\n");
|
2023-09-13 08:40:39 +00:00
|
|
|
|
|
|
|
struct struct_A a = {
|
2023-09-11 16:44:37 +00:00
|
|
|
.b = -10,
|
|
|
|
.u = 13,
|
|
|
|
.a = 1.0,
|
|
|
|
.dyn_str = "WHOOAAAAA"
|
|
|
|
};
|
|
|
|
|
2023-09-13 08:40:39 +00:00
|
|
|
struct struct_B b = {
|
|
|
|
.f = 123.0,
|
|
|
|
.f_NOT_KWIL = 0,
|
|
|
|
.i_NOT_KWIL = 0,
|
|
|
|
.i = 3,
|
|
|
|
.str = "SNALE!!",
|
|
|
|
.other_struct = a,
|
|
|
|
.other_struct_typedef = {
|
|
|
|
.b = -20, .u = 13, .a = -3.14, .dyn_str = "AWESOMEE"
|
2023-09-13 10:46:12 +00:00
|
|
|
},
|
|
|
|
.other_enum = VALUE_B,
|
|
|
|
.other_enum_typedef = VALUE_C
|
2023-09-13 08:40:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int required = struct_B_json_length(&b);
|
|
|
|
char* json = malloc(required);
|
|
|
|
int json_len = struct_B_to_json(&b, json);
|
|
|
|
|
|
|
|
printf("allocated %d bytes for json of struct_B\n", required);
|
|
|
|
printf("struct_B as json:\n%s\n", json);
|
2023-09-11 16:44:37 +00:00
|
|
|
|
|
|
|
int real_len = strlen(json);
|
|
|
|
|
|
|
|
free(json);
|
|
|
|
if(real_len != json_len) {
|
2023-09-13 08:40:39 +00:00
|
|
|
printf("Json Length (%d) does not match allocated space (%d)\n", required, json_len);
|
2023-09-11 16:44:37 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-09-13 08:40:39 +00:00
|
|
|
|
2023-09-11 16:44:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|