wrote test

main
Sara 2023-09-11 18:44:37 +02:00
parent 9fb43f8ae9
commit 2d46929f07
3 changed files with 98 additions and 0 deletions

55
test_files/header.h Normal file
View File

@ -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

View File

@ -0,0 +1,35 @@
#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 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;
}

8
test_include/kwil.h Normal file
View File

@ -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