kwil-header-tool/test_files/implementation.c

51 lines
1.0 KiB
C

#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");
struct struct_A a = {
.b = -10,
.u = 13,
.a = 1.0,
.dyn_str = "WHOOAAAAA"
};
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"
}
};
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);
int real_len = strlen(json);
free(json);
if(real_len != json_len) {
printf("Json Length (%d) does not match allocated space (%d)\n", required, json_len);
return 1;
}
return 0;
}