#include "header.h" #include #include #include #include KWIL_GEN_IMPL() int main(int argc, char* argv[]) { printf("running kwil test\n"); struct struct_A a = { .b = -10, .u = 13, .a = 1.0, .dyn_str = "WHOOAAAAA" }; struct struct_B b = { .f = 123.0, .i = 3, .str_static = "", .other_struct = a, .other_struct_typedef = { .b = -20, .u = 13, .a = -3.14, .dyn_str = "AWESOMEE" }, .other_enum = VALUE_B, .other_enum_typedef = VALUE_C }; int allocate_bytes = struct_B_json_length(&b)+1; char* json = malloc(allocate_bytes); int json_len = struct_B_to_json(&b, json); printf("allocated %d bytes for json of struct_B\n", allocate_bytes); printf("returned length of json string: %d\n", json_len); printf("actual length of json string: %zu\n\n", strlen(json)); printf("struct_B as json:\n%s\n\n", json); int real_len = strlen(json); if (real_len != allocate_bytes) { printf("Json Length (%d) does not match allocated space (%d)\n", json_len, allocate_bytes); free(json); return 1; } struct struct_B deserialized = struct_B_from_json(json); allocate_bytes = struct_B_json_length(&b); char* reserialized_json = malloc(allocate_bytes); struct_B_to_json(&deserialized, reserialized_json); printf("deserialzed (serialized):\n%s\n\n", json); if(strcmp(json, reserialized_json) != 0) { printf("Deserialized struct does not match original\n"); free(json); return 2; } free(json); return 0; }