Properly link flecs library
This commit is contained in:
621
engine/libs/flecs/test/meta/src/ArrayTypes.c
Normal file
621
engine/libs/flecs/test/meta/src/ArrayTypes.c
Normal file
@@ -0,0 +1,621 @@
|
||||
#include <meta.h>
|
||||
|
||||
void ArrayTypes_array_bool_1(void) {
|
||||
typedef struct {
|
||||
ecs_bool_t x[1];
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_bool_t), 1}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_bool_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void ArrayTypes_array_bool_2(void) {
|
||||
typedef struct {
|
||||
ecs_bool_t x[2];
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_bool_t), 2}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_bool_t), 2);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void ArrayTypes_array_bool_3(void) {
|
||||
typedef struct {
|
||||
ecs_bool_t x[3];
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_bool_t), 3}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_bool_t), 3);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void ArrayTypes_array_bool_1_before_i32_member(void) {
|
||||
typedef struct {
|
||||
ecs_bool_t x[1];
|
||||
ecs_i32_t y;
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_bool_t), 1},
|
||||
{"y", ecs_id(ecs_i32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_bool_t), 1);
|
||||
meta_test_member(world, t, T, y, ecs_id(ecs_i32_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void ArrayTypes_array_bool_2_before_i32_member(void) {
|
||||
typedef struct {
|
||||
ecs_bool_t x[2];
|
||||
ecs_i32_t y;
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_bool_t), 2},
|
||||
{"y", ecs_id(ecs_i32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_bool_t), 2);
|
||||
meta_test_member(world, t, T, y, ecs_id(ecs_i32_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void ArrayTypes_array_bool_3_before_i32_member(void) {
|
||||
typedef struct {
|
||||
ecs_bool_t x[3];
|
||||
ecs_i32_t y;
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_bool_t), 3},
|
||||
{"y", ecs_id(ecs_i32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_bool_t), 3);
|
||||
meta_test_member(world, t, T, y, ecs_id(ecs_i32_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void ArrayTypes_array_i32_3(void) {
|
||||
typedef struct {
|
||||
ecs_i32_t x[3];
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t), 3},
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_i32_t), 3);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void ArrayTypes_array_i32_3_before_i32_member(void) {
|
||||
typedef struct {
|
||||
ecs_i32_t x[3];
|
||||
ecs_i32_t y;
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t), 3},
|
||||
{"y", ecs_id(ecs_i32_t)},
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_i32_t), 3);
|
||||
meta_test_member(world, t, T, y, ecs_id(ecs_i32_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void ArrayTypes_array_struct_bool_3(void) {
|
||||
typedef struct {
|
||||
ecs_bool_t x;
|
||||
} N1;
|
||||
|
||||
typedef struct {
|
||||
N1 n_1[3];
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t n = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "N1"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_bool_t)},
|
||||
}
|
||||
});
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"n_1", n, 3},
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, n_1, n, 3);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void ArrayTypes_array_struct_bool_3_before_i32_member(void) {
|
||||
typedef struct {
|
||||
ecs_bool_t x;
|
||||
} N1;
|
||||
|
||||
typedef struct {
|
||||
N1 n_1[3];
|
||||
int32_t x;
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t n = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "N1"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_bool_t)},
|
||||
}
|
||||
});
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"n_1", n, 3},
|
||||
{"x", ecs_id(ecs_i32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, n_1, n, 3);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_i32_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void ArrayTypes_array_struct_array_bool_3(void) {
|
||||
typedef struct {
|
||||
ecs_bool_t x[2];
|
||||
} N1;
|
||||
|
||||
typedef struct {
|
||||
N1 n_1[3];
|
||||
int32_t x;
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t n = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "N1"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_bool_t), 2},
|
||||
}
|
||||
});
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"n_1", n, 3},
|
||||
{"x", ecs_id(ecs_i32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, n_1, n, 3);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_i32_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void ArrayTypes_2_arrays_1_bool_1_i32(void) {
|
||||
typedef struct {
|
||||
ecs_bool_t x[3];
|
||||
ecs_i32_t y[2];
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_bool_t), 3},
|
||||
{"y", ecs_id(ecs_i32_t), 2}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_bool_t), 3);
|
||||
meta_test_member(world, t, T, y, ecs_id(ecs_i32_t), 2);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void ArrayTypes_2_arrays_1_i32_1_bool(void) {
|
||||
typedef struct {
|
||||
ecs_i32_t x[3];
|
||||
ecs_bool_t y[2];
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t), 3},
|
||||
{"y", ecs_id(ecs_bool_t), 2}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_i32_t), 3);
|
||||
meta_test_member(world, t, T, y, ecs_id(ecs_bool_t), 2);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void ArrayTypes_8_arrays_bool_w_padded_member(void) {
|
||||
typedef struct {
|
||||
ecs_bool_t a[1];
|
||||
ecs_i16_t p1;
|
||||
ecs_bool_t b[2];
|
||||
ecs_bool_t c[3];
|
||||
ecs_i32_t p2;
|
||||
ecs_bool_t d[4];
|
||||
ecs_bool_t e[5];
|
||||
ecs_bool_t f[6];
|
||||
ecs_bool_t g[7];
|
||||
ecs_i64_t p3;
|
||||
ecs_bool_t h[8];
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"a", ecs_id(ecs_bool_t), 1},
|
||||
{"p1", ecs_id(ecs_i16_t), 1},
|
||||
{"b", ecs_id(ecs_bool_t), 2},
|
||||
{"c", ecs_id(ecs_bool_t), 3},
|
||||
{"p2", ecs_id(ecs_i32_t), 1},
|
||||
{"d", ecs_id(ecs_bool_t), 4},
|
||||
{"e", ecs_id(ecs_bool_t), 5},
|
||||
{"f", ecs_id(ecs_bool_t), 6},
|
||||
{"g", ecs_id(ecs_bool_t), 7},
|
||||
{"p3", ecs_id(ecs_i64_t), 1},
|
||||
{"h", ecs_id(ecs_bool_t), 8},
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, a, ecs_id(ecs_bool_t), 1);
|
||||
meta_test_member(world, t, T, p1, ecs_id(ecs_i16_t), 1);
|
||||
meta_test_member(world, t, T, b, ecs_id(ecs_bool_t), 2);
|
||||
meta_test_member(world, t, T, c, ecs_id(ecs_bool_t), 3);
|
||||
meta_test_member(world, t, T, p2, ecs_id(ecs_i32_t), 1);
|
||||
meta_test_member(world, t, T, d, ecs_id(ecs_bool_t), 4);
|
||||
meta_test_member(world, t, T, e, ecs_id(ecs_bool_t), 5);
|
||||
meta_test_member(world, t, T, f, ecs_id(ecs_bool_t), 6);
|
||||
meta_test_member(world, t, T, g, ecs_id(ecs_bool_t), 7);
|
||||
meta_test_member(world, t, T, p3, ecs_id(ecs_i64_t), 1);
|
||||
meta_test_member(world, t, T, h, ecs_id(ecs_bool_t), 8);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void ArrayTypes_standaline_array_bool_1(void) {
|
||||
typedef struct {
|
||||
ecs_bool_t x[1];
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t a = ecs_array_init(world, &(ecs_array_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "A"}),
|
||||
.type = ecs_id(ecs_bool_t),
|
||||
.count = 1
|
||||
});
|
||||
|
||||
test_assert(a != 0);
|
||||
test_str(ecs_get_name(world, a), "A");
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", a}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, a, 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void ArrayTypes_standaline_array_bool_2(void) {
|
||||
typedef struct {
|
||||
ecs_bool_t x[2];
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t a = ecs_array_init(world, &(ecs_array_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "A"}),
|
||||
.type = ecs_id(ecs_bool_t),
|
||||
.count = 2
|
||||
});
|
||||
|
||||
test_assert(a != 0);
|
||||
test_str(ecs_get_name(world, a), "A");
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", a}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, a, 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void ArrayTypes_standaline_array_bool_3(void) {
|
||||
typedef struct {
|
||||
ecs_bool_t x[3];
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t a = ecs_array_init(world, &(ecs_array_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "A"}),
|
||||
.type = ecs_id(ecs_bool_t),
|
||||
.count = 3
|
||||
});
|
||||
|
||||
test_assert(a != 0);
|
||||
test_str(ecs_get_name(world, a), "A");
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", a}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, a, 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void ArrayTypes_array_of_standaline_array_bool_1(void) {
|
||||
typedef ecs_bool_t bool_1[1];
|
||||
typedef struct {
|
||||
bool_1 x[3];
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t a = ecs_array_init(world, &(ecs_array_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "A"}),
|
||||
.type = ecs_id(ecs_bool_t),
|
||||
.count = 1
|
||||
});
|
||||
|
||||
test_assert(a != 0);
|
||||
test_str(ecs_get_name(world, a), "A");
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", a, 3}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, a, 3);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void ArrayTypes_array_of_standaline_array_bool_2(void) {
|
||||
typedef ecs_bool_t bool_2[2];
|
||||
typedef struct {
|
||||
bool_2 x[3];
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t a = ecs_array_init(world, &(ecs_array_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "A"}),
|
||||
.type = ecs_id(ecs_bool_t),
|
||||
.count = 2
|
||||
});
|
||||
|
||||
test_assert(a != 0);
|
||||
test_str(ecs_get_name(world, a), "A");
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", a, 3}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, a, 3);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void ArrayTypes_array_of_standaline_array_bool_3(void) {
|
||||
typedef ecs_bool_t bool_2[3];
|
||||
typedef struct {
|
||||
bool_2 x[4];
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t a = ecs_array_init(world, &(ecs_array_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "A"}),
|
||||
.type = ecs_id(ecs_bool_t),
|
||||
.count = 3
|
||||
});
|
||||
|
||||
test_assert(a != 0);
|
||||
test_str(ecs_get_name(world, a), "A");
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", a, 4}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, a, 4);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void ArrayTypes_array_w_short_notation(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t a = ecs_array(world, {
|
||||
.entity = ecs_entity(world, {.name = "A"}),
|
||||
.type = ecs_id(ecs_bool_t),
|
||||
.count = 3
|
||||
});
|
||||
|
||||
test_assert(a != 0);
|
||||
test_str(ecs_get_name(world, a), "A");
|
||||
test_assert(ecs_has(world, a, EcsArray));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
198
engine/libs/flecs/test/meta/src/BitmaskTypes.c
Normal file
198
engine/libs/flecs/test/meta/src/BitmaskTypes.c
Normal file
@@ -0,0 +1,198 @@
|
||||
#include <meta.h>
|
||||
|
||||
static
|
||||
void meta_test_bitmask(
|
||||
ecs_world_t *world,
|
||||
ecs_entity_t t,
|
||||
int32_t count)
|
||||
{
|
||||
const EcsComponent *ct = ecs_get(world, t, EcsComponent);
|
||||
test_assert(ct != NULL);
|
||||
test_int(ct->size, ECS_SIZEOF(ecs_i32_t));
|
||||
test_int(ct->alignment, ECS_ALIGNOF(ecs_i32_t));
|
||||
|
||||
const EcsMetaType *mt = ecs_get(world, t, EcsMetaType);
|
||||
test_assert(mt != NULL);
|
||||
test_assert(mt->kind == EcsBitmaskType);
|
||||
|
||||
const EcsBitmask *bt = ecs_get(world, t, EcsBitmask);
|
||||
test_assert(bt != NULL);
|
||||
test_int(ecs_map_count(&bt->constants), count);
|
||||
}
|
||||
|
||||
static
|
||||
void meta_test_constant(
|
||||
ecs_world_t *world,
|
||||
ecs_entity_t t,
|
||||
const char *name,
|
||||
int32_t value)
|
||||
{
|
||||
ecs_entity_t m = ecs_lookup_child(world, t, name);
|
||||
test_assert(m != 0);
|
||||
test_assert(ecs_has_id(world, m, EcsConstant) ||
|
||||
ecs_has_pair(world, m, EcsConstant, EcsWildcard));
|
||||
|
||||
const EcsBitmask *bt = ecs_get(world, t, EcsBitmask);
|
||||
test_assert(bt != NULL);
|
||||
|
||||
ecs_map_iter_t it = ecs_map_iter(&bt->constants);
|
||||
bool constant_found = false;
|
||||
while (ecs_map_next(&it)) {
|
||||
ecs_bitmask_constant_t *c = ecs_map_ptr(&it);
|
||||
ecs_map_key_t key = ecs_map_key(&it);
|
||||
|
||||
test_int(c->value, key);
|
||||
test_assert(c->constant != 0);
|
||||
test_str(c->name, ecs_get_name(world, c->constant));
|
||||
|
||||
if (!ecs_os_strcmp(c->name, name)) {
|
||||
test_int(c->value, value);
|
||||
|
||||
const ecs_u32_t *vptr = ecs_get_pair_object(world, c->constant,
|
||||
EcsConstant, ecs_u32_t);
|
||||
if (vptr) {
|
||||
test_int(*vptr, value);
|
||||
}
|
||||
|
||||
constant_found = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_assert(constant_found == true);
|
||||
}
|
||||
|
||||
void BitmaskTypes_bitmask_1_constant(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t b = ecs_bitmask_init(world, &(ecs_bitmask_desc_t){
|
||||
.constants = {
|
||||
{"Lettuce"}
|
||||
}
|
||||
});
|
||||
|
||||
meta_test_bitmask(world, b, 1);
|
||||
meta_test_constant(world, b, "Lettuce", 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void BitmaskTypes_bitmask_2_constants(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t b = ecs_bitmask_init(world, &(ecs_bitmask_desc_t){
|
||||
.constants = {
|
||||
{"Lettuce"}, {"Bacon"}
|
||||
}
|
||||
});
|
||||
|
||||
meta_test_bitmask(world, b, 2);
|
||||
meta_test_constant(world, b, "Lettuce", 1);
|
||||
meta_test_constant(world, b, "Bacon", 2);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void BitmaskTypes_bitmask_3_constants(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t b = ecs_bitmask_init(world, &(ecs_bitmask_desc_t){
|
||||
.constants = {
|
||||
{"Lettuce"}, {"Bacon"}, {"Tomato"}
|
||||
}
|
||||
});
|
||||
|
||||
meta_test_bitmask(world, b, 3);
|
||||
meta_test_constant(world, b, "Lettuce", 1);
|
||||
meta_test_constant(world, b, "Bacon", 2);
|
||||
meta_test_constant(world, b, "Tomato", 4);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void BitmaskTypes_bitmask_4_constants(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t b = ecs_bitmask_init(world, &(ecs_bitmask_desc_t){
|
||||
.constants = {
|
||||
{"Lettuce"}, {"Bacon"}, {"Tomato"}, {"Cheese"}
|
||||
}
|
||||
});
|
||||
|
||||
meta_test_bitmask(world, b, 4);
|
||||
meta_test_constant(world, b, "Lettuce", 1);
|
||||
meta_test_constant(world, b, "Bacon", 2);
|
||||
meta_test_constant(world, b, "Tomato", 4);
|
||||
meta_test_constant(world, b, "Cheese", 8);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void BitmaskTypes_bitmask_4_constants_manual_values(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t b = ecs_bitmask_init(world, &(ecs_bitmask_desc_t){
|
||||
.constants = {
|
||||
{"Lettuce", 8}, {"Bacon", 4}, {"Tomato", 2}, {"BLT", 16}
|
||||
}
|
||||
});
|
||||
|
||||
meta_test_bitmask(world, b, 4);
|
||||
meta_test_constant(world, b, "Lettuce", 8);
|
||||
meta_test_constant(world, b, "Bacon", 4);
|
||||
meta_test_constant(world, b, "Tomato", 2);
|
||||
meta_test_constant(world, b, "BLT", 16);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void BitmaskTypes_struct_w_bitmask(void) {
|
||||
typedef struct {
|
||||
ecs_bool_t before;
|
||||
ecs_u32_t v;
|
||||
ecs_bool_t after;
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t b = ecs_bitmask_init(world, &(ecs_bitmask_desc_t){
|
||||
.constants = {
|
||||
{"Lettuce"}, {"Bacon"}, {"Tomato"}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(b != 0);
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"before", ecs_id(ecs_bool_t)},
|
||||
{"v", b},
|
||||
{"after", ecs_id(ecs_bool_t)}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, before, ecs_id(ecs_bool_t), 1);
|
||||
meta_test_member(world, t, T, v, b, 1);
|
||||
meta_test_member(world, t, T, after, ecs_id(ecs_bool_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void BitmaskTypes_bitmask_w_short_notation(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t b = ecs_bitmask(world, {
|
||||
.constants = {
|
||||
{"Lettuce"}, {"Bacon"}, {"Tomato"}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(b != 0);
|
||||
test_assert(ecs_has(world, b, EcsBitmask));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
4426
engine/libs/flecs/test/meta/src/Cursor.c
Normal file
4426
engine/libs/flecs/test/meta/src/Cursor.c
Normal file
File diff suppressed because it is too large
Load Diff
2744
engine/libs/flecs/test/meta/src/DeserExprOperators.c
Normal file
2744
engine/libs/flecs/test/meta/src/DeserExprOperators.c
Normal file
File diff suppressed because it is too large
Load Diff
1437
engine/libs/flecs/test/meta/src/DeserializeFromExpr.c
Normal file
1437
engine/libs/flecs/test/meta/src/DeserializeFromExpr.c
Normal file
File diff suppressed because it is too large
Load Diff
4175
engine/libs/flecs/test/meta/src/DeserializeFromJson.c
Normal file
4175
engine/libs/flecs/test/meta/src/DeserializeFromJson.c
Normal file
File diff suppressed because it is too large
Load Diff
265
engine/libs/flecs/test/meta/src/EnumTypes.c
Normal file
265
engine/libs/flecs/test/meta/src/EnumTypes.c
Normal file
@@ -0,0 +1,265 @@
|
||||
#include <meta.h>
|
||||
|
||||
static
|
||||
void meta_test_enum(
|
||||
ecs_world_t *world,
|
||||
ecs_entity_t t,
|
||||
int32_t count)
|
||||
{
|
||||
const EcsComponent *ct = ecs_get(world, t, EcsComponent);
|
||||
test_assert(ct != NULL);
|
||||
test_int(ct->size, ECS_SIZEOF(ecs_i32_t));
|
||||
test_int(ct->alignment, ECS_ALIGNOF(ecs_i32_t));
|
||||
|
||||
const EcsMetaType *mt = ecs_get(world, t, EcsMetaType);
|
||||
test_assert(mt != NULL);
|
||||
test_assert(mt->kind == EcsEnumType);
|
||||
|
||||
const EcsEnum *et = ecs_get(world, t, EcsEnum);
|
||||
test_assert(et != NULL);
|
||||
test_int(ecs_map_count(&et->constants), count);
|
||||
}
|
||||
|
||||
static
|
||||
void meta_test_constant(
|
||||
ecs_world_t *world,
|
||||
ecs_entity_t t,
|
||||
const char *name,
|
||||
int32_t value)
|
||||
{
|
||||
ecs_entity_t m = ecs_lookup_child(world, t, name);
|
||||
test_assert(m != 0);
|
||||
test_assert(ecs_has_id(world, m, EcsConstant) ||
|
||||
ecs_has_pair(world, m, EcsConstant, EcsWildcard));
|
||||
|
||||
const EcsEnum *et = ecs_get(world, t, EcsEnum);
|
||||
test_assert(et != NULL);
|
||||
|
||||
ecs_map_iter_t it = ecs_map_iter(&et->constants);
|
||||
bool constant_found = false;
|
||||
while (ecs_map_next(&it)) {
|
||||
ecs_bitmask_constant_t *c = ecs_map_ptr(&it);
|
||||
ecs_map_key_t key = ecs_map_key(&it);
|
||||
|
||||
test_int(c->value, key);
|
||||
test_assert(c->constant != 0);
|
||||
test_str(c->name, ecs_get_name(world, c->constant));
|
||||
|
||||
if (!ecs_os_strcmp(c->name, name)) {
|
||||
test_int(c->value, value);
|
||||
|
||||
const ecs_i32_t *vptr = ecs_get_pair_object(world, c->constant,
|
||||
EcsConstant, ecs_i32_t);
|
||||
if (vptr) {
|
||||
test_int(*vptr, value);
|
||||
}
|
||||
|
||||
constant_found = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_assert(constant_found == true);
|
||||
}
|
||||
|
||||
void EnumTypes_enum_1_constant(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t e = ecs_enum_init(world, &(ecs_enum_desc_t){
|
||||
.constants = {
|
||||
{"Red"}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(e != 0);
|
||||
|
||||
meta_test_enum(world, e, 1);
|
||||
meta_test_constant(world, e, "Red", 0);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void EnumTypes_enum_2_constants(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t e = ecs_enum_init(world, &(ecs_enum_desc_t){
|
||||
.constants = {
|
||||
{"Red"}, {"Blue"}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(e != 0);
|
||||
|
||||
meta_test_enum(world, e, 2);
|
||||
meta_test_constant(world, e, "Red", 0);
|
||||
meta_test_constant(world, e, "Blue", 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void EnumTypes_enum_3_constants(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t e = ecs_enum_init(world, &(ecs_enum_desc_t){
|
||||
.constants = {
|
||||
{"Red"}, {"Blue"}, {"Green"}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(e != 0);
|
||||
|
||||
meta_test_enum(world, e, 3);
|
||||
meta_test_constant(world, e, "Red", 0);
|
||||
meta_test_constant(world, e, "Blue", 1);
|
||||
meta_test_constant(world, e, "Green", 2);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void EnumTypes_enum_3_constants_manual_values(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t e = ecs_enum_init(world, &(ecs_enum_desc_t){
|
||||
.constants = {
|
||||
{"Red", 3}, {"Blue", 2}, {"Green", 1}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(e != 0);
|
||||
|
||||
meta_test_enum(world, e, 3);
|
||||
meta_test_constant(world, e, "Red", 3);
|
||||
meta_test_constant(world, e, "Blue", 2);
|
||||
meta_test_constant(world, e, "Green", 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void EnumTypes_struct_w_enum(void) {
|
||||
typedef struct {
|
||||
ecs_bool_t before;
|
||||
ecs_i32_t v;
|
||||
ecs_bool_t after;
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t e = ecs_enum_init(world, &(ecs_enum_desc_t){
|
||||
.constants = {
|
||||
{"Red"}, {"Blue"}, {"Green"}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(e != 0);
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"before", ecs_id(ecs_bool_t)},
|
||||
{"v", e},
|
||||
{"after", ecs_id(ecs_bool_t)}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, before, ecs_id(ecs_bool_t), 1);
|
||||
meta_test_member(world, t, T, v, e, 1);
|
||||
meta_test_member(world, t, T, after, ecs_id(ecs_bool_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void EnumTypes_zero_initialized(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t e = ecs_enum_init(world, &(ecs_enum_desc_t){
|
||||
.constants = {
|
||||
{"Red"}, {"Blue"}, {"Green"}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(e != 0);
|
||||
test_assert(ecs_has(world, e, EcsComponent));
|
||||
|
||||
ecs_entity_t ent = ecs_new_id(world);
|
||||
ecs_add_id(world, ent, e);
|
||||
|
||||
const int32_t *ptr = ecs_get_id(world, ent, e);
|
||||
test_assert(ptr != NULL);
|
||||
test_int(*ptr, 0);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void EnumTypes_enum_relation(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
enum Color {
|
||||
Red, Blue, Green
|
||||
};
|
||||
|
||||
ecs_entity_t e = ecs_enum_init(world, &(ecs_enum_desc_t){
|
||||
.constants = {
|
||||
{"Red"}, {"Blue"}, {"Green"}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(e != 0);
|
||||
test_assert(ecs_has(world, e, EcsComponent));
|
||||
test_assert(ecs_has_id(world, e, EcsExclusive));
|
||||
test_assert(ecs_has_id(world, e, EcsTag));
|
||||
|
||||
ecs_entity_t red = ecs_lookup_child(world, e, "Red");
|
||||
ecs_entity_t green = ecs_lookup_child(world, e, "Green");
|
||||
ecs_entity_t blue = ecs_lookup_child(world, e, "Blue");
|
||||
|
||||
test_assert(red != 0);
|
||||
test_assert(green != 0);
|
||||
test_assert(blue != 0);
|
||||
|
||||
test_assert(ecs_get_typeid(world, ecs_pair(e, red)) == 0);
|
||||
|
||||
ecs_entity_t ent = ecs_new_id(world);
|
||||
ecs_add_pair(world, ent, e, red);
|
||||
test_assert( ecs_has_pair(world, ent, e, red));
|
||||
|
||||
ecs_add_pair(world, ent, e, green);
|
||||
test_assert( ecs_has_pair(world, ent, e, green));
|
||||
test_assert( !ecs_has_pair(world, ent, e, red));
|
||||
|
||||
ecs_add_pair(world, ent, e, blue);
|
||||
test_assert( ecs_has_pair(world, ent, e, blue));
|
||||
test_assert( !ecs_has_pair(world, ent, e, green));
|
||||
test_assert( !ecs_has_pair(world, ent, e, red));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void EnumTypes_enum_w_short_notation(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t e = ecs_enum(world, {
|
||||
.constants = {
|
||||
{"Red"}, {"Blue"}, {"Green"}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(e != 0);
|
||||
test_assert(ecs_has(world, e, EcsEnum));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void EnumTypes_constant_w_name_prefix(void) {
|
||||
// Implement testcase
|
||||
}
|
||||
|
||||
void EnumTypes_constant_w_type_prefix(void) {
|
||||
// Implement testcase
|
||||
}
|
||||
|
||||
void EnumTypes_constant_w_name_type_prefix(void) {
|
||||
// Implement testcase
|
||||
}
|
||||
544
engine/libs/flecs/test/meta/src/MetaUtils.c
Normal file
544
engine/libs/flecs/test/meta/src/MetaUtils.c
Normal file
@@ -0,0 +1,544 @@
|
||||
#include <meta.h>
|
||||
|
||||
ECS_STRUCT(Struct_2_i32, {
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
});
|
||||
|
||||
ECS_STRUCT(Struct_2_bool, {
|
||||
bool x;
|
||||
bool y;
|
||||
});
|
||||
|
||||
ECS_STRUCT(Struct_2_char, {
|
||||
char x;
|
||||
char y;
|
||||
});
|
||||
|
||||
ECS_STRUCT(Struct_2_string, {
|
||||
char *x;
|
||||
char *y;
|
||||
});
|
||||
|
||||
ECS_STRUCT(Struct_2_f32, {
|
||||
float x;
|
||||
float y;
|
||||
});
|
||||
|
||||
ECS_STRUCT(Struct_2_f64, {
|
||||
double x;
|
||||
double y;
|
||||
});
|
||||
|
||||
ECS_STRUCT(_Struct_w_underscore, {
|
||||
double value;
|
||||
});
|
||||
|
||||
ECS_STRUCT(Struct_w_underscore_member_name, {
|
||||
double _value;
|
||||
});
|
||||
|
||||
ECS_STRUCT(Struct_w_underscore_member_type, {
|
||||
_Struct_w_underscore value;
|
||||
});
|
||||
|
||||
ECS_STRUCT(Struct_w_ptrs, {
|
||||
void *ptr_a;
|
||||
void* ptr_b;
|
||||
});
|
||||
|
||||
ECS_STRUCT(Struct_w_private, {
|
||||
double x;
|
||||
double y;
|
||||
ECS_PRIVATE
|
||||
double z;
|
||||
});
|
||||
|
||||
ECS_ENUM(Enum_Default, {
|
||||
Red, Green, Blue
|
||||
});
|
||||
|
||||
ECS_ENUM(Enum_Default_Multiline, {
|
||||
Red_1,
|
||||
Green_1,
|
||||
Blue_1
|
||||
});
|
||||
|
||||
ECS_ENUM(Enum_Assign, {
|
||||
Red_2 = 1, Green_2 = 3, Blue_2 = 6
|
||||
});
|
||||
|
||||
ECS_BITMASK(Bitmask, {
|
||||
Bacon = 1, Lettuce = 2, Tomato = 4, Blt = 7
|
||||
});
|
||||
|
||||
ECS_ENUM(Enum_Nospace, {EnumNospace_A,EnumNospace_B,EnumNospace_C});
|
||||
ECS_STRUCT(Struct_Nospace, {float x;float y;});
|
||||
|
||||
ECS_ENUM(TestNamePrefix, {
|
||||
TestA,
|
||||
TestB,
|
||||
TestC
|
||||
});
|
||||
|
||||
ECS_ENUM(TestTypePrefix, {
|
||||
TestTypePrefixA,
|
||||
TestTypePrefixB,
|
||||
TestTypePrefixC
|
||||
});
|
||||
|
||||
ECS_ENUM(TestNameTypePrefix, {
|
||||
TestNameTypePrefixA,
|
||||
TestNameTypePrefixB,
|
||||
TestNameTypePrefixC
|
||||
});
|
||||
|
||||
ECS_STRUCT(Struct_3_enum, {
|
||||
Enum_Default one;
|
||||
Enum_Default two;
|
||||
Enum_Default three;
|
||||
});
|
||||
|
||||
ECS_STRUCT(Struct_3_enum_multiline, {
|
||||
Enum_Default_Multiline one;
|
||||
Enum_Default_Multiline two;
|
||||
Enum_Default_Multiline three;
|
||||
});
|
||||
|
||||
ECS_STRUCT(Struct_3_enum_assign, {
|
||||
Enum_Assign one;
|
||||
Enum_Assign two;
|
||||
Enum_Assign three;
|
||||
});
|
||||
|
||||
ECS_STRUCT(Struct_3_bitmask, {
|
||||
Bitmask one;
|
||||
Bitmask two;
|
||||
Bitmask three;
|
||||
Bitmask four;
|
||||
});
|
||||
|
||||
ECS_STRUCT(Struct_3_entities, {
|
||||
ecs_entity_t one;
|
||||
ecs_entity_t two;
|
||||
ecs_entity_t three;
|
||||
});
|
||||
|
||||
ECS_STRUCT(Struct_2_array_3_i32, {
|
||||
int32_t one[3];
|
||||
int32_t two[3];
|
||||
});
|
||||
|
||||
ECS_STRUCT(Struct_nested, {
|
||||
Struct_2_i32 one;
|
||||
});
|
||||
|
||||
ECS_STRUCT(Struct_2_nested, {
|
||||
Struct_2_i32 one;
|
||||
Struct_2_i32 two;
|
||||
});
|
||||
|
||||
void MetaUtils_struct_w_2_i32(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_META_COMPONENT(world, Struct_2_i32);
|
||||
|
||||
Struct_2_i32 v = {10, 20};
|
||||
char *expr = ecs_ptr_to_expr(world, ecs_id(Struct_2_i32), &v);
|
||||
test_assert(expr != NULL);
|
||||
test_str(expr, "{x: 10, y: 20}");
|
||||
ecs_os_free(expr);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void MetaUtils_struct_w_2_bool(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_META_COMPONENT(world, Struct_2_bool);
|
||||
|
||||
Struct_2_bool v = {true, false};
|
||||
char *expr = ecs_ptr_to_expr(world, ecs_id(Struct_2_bool), &v);
|
||||
test_assert(expr != NULL);
|
||||
test_str(expr, "{x: true, y: false}");
|
||||
ecs_os_free(expr);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void MetaUtils_struct_w_2_char(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_META_COMPONENT(world, Struct_2_char);
|
||||
|
||||
Struct_2_char v = {'a', 'b'};
|
||||
char *expr = ecs_ptr_to_expr(world, ecs_id(Struct_2_char), &v);
|
||||
test_assert(expr != NULL);
|
||||
test_str(expr, "{x: \"a\", y: \"b\"}");
|
||||
ecs_os_free(expr);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void MetaUtils_struct_w_2_string(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_META_COMPONENT(world, Struct_2_string);
|
||||
|
||||
Struct_2_string v = {"Hello", "World"};
|
||||
char *expr = ecs_ptr_to_expr(world, ecs_id(Struct_2_string), &v);
|
||||
test_assert(expr != NULL);
|
||||
test_str(expr, "{x: \"Hello\", y: \"World\"}");
|
||||
ecs_os_free(expr);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void MetaUtils_struct_w_2_f32(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_META_COMPONENT(world, Struct_2_f32);
|
||||
|
||||
Struct_2_f32 v = {10.5, 20.5};
|
||||
char *expr = ecs_ptr_to_expr(world, ecs_id(Struct_2_f32), &v);
|
||||
test_assert(expr != NULL);
|
||||
test_str(expr, "{x: 10.5, y: 20.5}");
|
||||
ecs_os_free(expr);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void MetaUtils_struct_w_2_f64(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_META_COMPONENT(world, Struct_2_f64);
|
||||
|
||||
Struct_2_f64 v = {10.5, 20.5};
|
||||
char *expr = ecs_ptr_to_expr(world, ecs_id(Struct_2_f64), &v);
|
||||
test_assert(expr != NULL);
|
||||
test_str(expr, "{x: 10.5, y: 20.5}");
|
||||
ecs_os_free(expr);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void MetaUtils_struct_w_3_enum(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_META_COMPONENT(world, Enum_Default);
|
||||
ECS_META_COMPONENT(world, Struct_3_enum);
|
||||
|
||||
Struct_3_enum v = {Red, Green, Blue};
|
||||
char *expr = ecs_ptr_to_expr(world, ecs_id(Struct_3_enum), &v);
|
||||
test_assert(expr != NULL);
|
||||
test_str(expr, "{one: Red, two: Green, three: Blue}");
|
||||
ecs_os_free(expr);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void MetaUtils_struct_w_3_enum_multiline(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_META_COMPONENT(world, Enum_Default_Multiline);
|
||||
ECS_META_COMPONENT(world, Struct_3_enum_multiline);
|
||||
|
||||
Struct_3_enum_multiline v = {Red_1, Green_1, Blue_1};
|
||||
char *expr = ecs_ptr_to_expr(world, ecs_id(Struct_3_enum_multiline), &v);
|
||||
test_assert(expr != NULL);
|
||||
test_str(expr, "{one: Red_1, two: Green_1, three: Blue_1}");
|
||||
ecs_os_free(expr);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void MetaUtils_struct_w_3_enum_w_assignment(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_META_COMPONENT(world, Enum_Assign);
|
||||
ECS_META_COMPONENT(world, Struct_3_enum_assign);
|
||||
|
||||
Struct_3_enum_assign v = {Red_2, Green_2, Blue_2};
|
||||
char *expr = ecs_ptr_to_expr(world, ecs_id(Struct_3_enum_assign), &v);
|
||||
test_assert(expr != NULL);
|
||||
test_str(expr, "{one: Red_2, two: Green_2, three: Blue_2}");
|
||||
ecs_os_free(expr);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void MetaUtils_struct_w_4_bitmask(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_META_COMPONENT(world, Bitmask);
|
||||
ECS_META_COMPONENT(world, Struct_3_bitmask);
|
||||
|
||||
Struct_3_bitmask v = {0, Tomato, Bacon | Tomato, Blt};
|
||||
char *expr = ecs_ptr_to_expr(world, ecs_id(Struct_3_bitmask), &v);
|
||||
test_assert(expr != NULL);
|
||||
test_str(expr, "{one: 0, two: Tomato, three: Tomato|Bacon, four: Lettuce|Tomato|Bacon}");
|
||||
ecs_os_free(expr);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void MetaUtils_struct_w_3_entities(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_META_COMPONENT(world, Struct_3_entities);
|
||||
|
||||
Struct_3_entities v = {0, EcsFlecs, EcsFlecsCore};
|
||||
char *expr = ecs_ptr_to_expr(world, ecs_id(Struct_3_entities), &v);
|
||||
test_assert(expr != NULL);
|
||||
test_str(expr, "{one: 0, two: flecs, three: flecs.core}");
|
||||
ecs_os_free(expr);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void MetaUtils_struct_w_2_array_3_i32(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_META_COMPONENT(world, Struct_2_array_3_i32);
|
||||
|
||||
Struct_2_array_3_i32 v = {{1, 2, 3}, {6, 5, 4}};
|
||||
char *expr = ecs_ptr_to_expr(world, ecs_id(Struct_2_array_3_i32), &v);
|
||||
test_assert(expr != NULL);
|
||||
test_str(expr, "{one: [1, 2, 3], two: [6, 5, 4]}");
|
||||
ecs_os_free(expr);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void MetaUtils_struct_w_nested(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_META_COMPONENT(world, Struct_2_i32);
|
||||
ECS_META_COMPONENT(world, Struct_nested);
|
||||
|
||||
Struct_nested v = {{1, 2}};
|
||||
char *expr = ecs_ptr_to_expr(world, ecs_id(Struct_nested), &v);
|
||||
test_assert(expr != NULL);
|
||||
test_str(expr, "{one: {x: 1, y: 2}}");
|
||||
ecs_os_free(expr);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void MetaUtils_struct_w_2_nested(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_META_COMPONENT(world, Struct_2_i32);
|
||||
ECS_META_COMPONENT(world, Struct_2_nested);
|
||||
|
||||
Struct_2_nested v = {{1, 2}, {4, 3}};
|
||||
char *expr = ecs_ptr_to_expr(world, ecs_id(Struct_2_nested), &v);
|
||||
test_assert(expr != NULL);
|
||||
test_str(expr, "{one: {x: 1, y: 2}, two: {x: 4, y: 3}}");
|
||||
ecs_os_free(expr);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void MetaUtils_enum_nospace(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_META_COMPONENT(world, Enum_Nospace);
|
||||
|
||||
ecs_entity_t e = ecs_id(Enum_Nospace);
|
||||
test_assert(e != 0);
|
||||
test_str(ecs_get_name(world, e), "Enum_Nospace");
|
||||
test_assert(ecs_has(world, e, EcsEnum));
|
||||
|
||||
ecs_entity_t c_a = ecs_lookup_child(world, e, "EnumNospace_A");
|
||||
test_assert(c_a != 0);
|
||||
|
||||
ecs_entity_t c_b = ecs_lookup_child(world, e, "EnumNospace_B");
|
||||
test_assert(c_b != 0);
|
||||
|
||||
ecs_entity_t c_c = ecs_lookup_child(world, e, "EnumNospace_C");
|
||||
test_assert(c_c != 0);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void MetaUtils_struct_nospace(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_META_COMPONENT(world, Struct_Nospace);
|
||||
|
||||
ecs_entity_t e = ecs_id(Struct_Nospace);
|
||||
test_assert(e != 0);
|
||||
test_str(ecs_get_name(world, e), "Struct_Nospace");
|
||||
test_assert(ecs_has(world, e, EcsStruct));
|
||||
|
||||
ecs_entity_t c_a = ecs_lookup_child(world, e, "x");
|
||||
test_assert(c_a != 0);
|
||||
|
||||
ecs_entity_t c_b = ecs_lookup_child(world, e, "y");
|
||||
test_assert(c_b != 0);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void MetaUtils_identifier_w_underscore(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_META_COMPONENT(world, _Struct_w_underscore);
|
||||
ECS_META_COMPONENT(world, Struct_w_underscore_member_name);
|
||||
ECS_META_COMPONENT(world, Struct_w_underscore_member_type);
|
||||
|
||||
test_assert(ecs_id(_Struct_w_underscore) != 0);
|
||||
test_assert(ecs_id(Struct_w_underscore_member_name) != 0);
|
||||
test_assert(ecs_id(Struct_w_underscore_member_type) != 0);
|
||||
|
||||
{
|
||||
ecs_entity_t s = ecs_id(_Struct_w_underscore);
|
||||
ecs_entity_t m = ecs_lookup_child(world, s, "value");
|
||||
test_assert(m != 0);
|
||||
}
|
||||
|
||||
{
|
||||
ecs_entity_t s = ecs_id(Struct_w_underscore_member_name);
|
||||
ecs_entity_t m = ecs_lookup_child(world, s, "_value");
|
||||
test_assert(m != 0);
|
||||
}
|
||||
|
||||
{
|
||||
ecs_entity_t s = ecs_id(Struct_w_underscore_member_type);
|
||||
ecs_entity_t m = ecs_lookup_child(world, s, "value");
|
||||
test_assert(m != 0);
|
||||
}
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void MetaUtils_struct_w_ptr(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_META_COMPONENT(world, Struct_w_ptrs);
|
||||
|
||||
test_assert(ecs_id(Struct_w_ptrs) != 0);
|
||||
ecs_entity_t s = ecs_id(Struct_w_ptrs);
|
||||
|
||||
{
|
||||
ecs_entity_t m = ecs_lookup_child(world, s, "ptr_a");
|
||||
test_assert(m != 0);
|
||||
}
|
||||
{
|
||||
ecs_entity_t m = ecs_lookup_child(world, s, "ptr_b");
|
||||
test_assert(m != 0);
|
||||
}
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void MetaUtils_private_members(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_META_COMPONENT(world, Struct_w_private);
|
||||
|
||||
test_assert(ecs_id(Struct_w_private) != 0);
|
||||
ecs_entity_t s = ecs_id(Struct_w_private);
|
||||
|
||||
{
|
||||
ecs_entity_t m = ecs_lookup_child(world, s, "x");
|
||||
test_assert(m != 0);
|
||||
}
|
||||
{
|
||||
ecs_entity_t m = ecs_lookup_child(world, s, "y");
|
||||
test_assert(m != 0);
|
||||
}
|
||||
{
|
||||
ecs_entity_t m = ecs_lookup_child(world, s, "z");
|
||||
test_assert(m == 0);
|
||||
}
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void MetaUtils_enum_constant_w_name_prefix(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_set_name_prefix(world, "Test");
|
||||
|
||||
ECS_META_COMPONENT(world, TestNamePrefix);
|
||||
|
||||
test_assert(ecs_id(TestNamePrefix) != 0);
|
||||
ecs_entity_t e = ecs_id(TestNamePrefix);
|
||||
|
||||
test_str(ecs_get_name(world, e), "NamePrefix");
|
||||
|
||||
{
|
||||
ecs_entity_t c_a = ecs_lookup_child(world, e, "A");
|
||||
test_assert(c_a != 0);
|
||||
}
|
||||
|
||||
{
|
||||
ecs_entity_t c_b = ecs_lookup_child(world, e, "B");
|
||||
test_assert(c_b != 0);
|
||||
}
|
||||
|
||||
{
|
||||
ecs_entity_t c_c = ecs_lookup_child(world, e, "C");
|
||||
test_assert(c_c != 0);
|
||||
}
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void MetaUtils_enum_constant_w_type_prefix(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_META_COMPONENT(world, TestTypePrefix);
|
||||
|
||||
test_assert(ecs_id(TestTypePrefix) != 0);
|
||||
ecs_entity_t e = ecs_id(TestTypePrefix);
|
||||
|
||||
{
|
||||
ecs_entity_t c_a = ecs_lookup_child(world, e, "A");
|
||||
test_assert(c_a != 0);
|
||||
}
|
||||
|
||||
{
|
||||
ecs_entity_t c_b = ecs_lookup_child(world, e, "B");
|
||||
test_assert(c_b != 0);
|
||||
}
|
||||
|
||||
{
|
||||
ecs_entity_t c_c = ecs_lookup_child(world, e, "C");
|
||||
test_assert(c_c != 0);
|
||||
}
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void MetaUtils_enum_constant_w_name_type_prefix(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_set_name_prefix(world, "Test");
|
||||
|
||||
ECS_META_COMPONENT(world, TestNameTypePrefix);
|
||||
|
||||
test_assert(ecs_id(TestNameTypePrefix) != 0);
|
||||
ecs_entity_t e = ecs_id(TestNameTypePrefix);
|
||||
|
||||
test_str(ecs_get_name(world, e), "NameTypePrefix");
|
||||
|
||||
{
|
||||
ecs_entity_t c_a = ecs_lookup_child(world, e, "A");
|
||||
test_assert(c_a != 0);
|
||||
}
|
||||
|
||||
{
|
||||
ecs_entity_t c_b = ecs_lookup_child(world, e, "B");
|
||||
test_assert(c_b != 0);
|
||||
}
|
||||
|
||||
{
|
||||
ecs_entity_t c_c = ecs_lookup_child(world, e, "C");
|
||||
test_assert(c_c != 0);
|
||||
}
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
686
engine/libs/flecs/test/meta/src/Misc.c
Normal file
686
engine/libs/flecs/test/meta/src/Misc.c
Normal file
@@ -0,0 +1,686 @@
|
||||
#include <meta.h>
|
||||
|
||||
void Misc_primitive_from_stage(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_world_t *stage = ecs_get_stage(world, 0);
|
||||
test_assert(stage != NULL);
|
||||
|
||||
ecs_entity_t t = ecs_primitive(stage, { .kind = EcsI32 });
|
||||
test_assert(t != 0);
|
||||
test_assert(ecs_has(world, t, EcsPrimitive));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_enum_from_stage(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_world_t *stage = ecs_get_stage(world, 0);
|
||||
test_assert(stage != NULL);
|
||||
|
||||
ecs_entity_t t = ecs_enum(stage, {
|
||||
.constants = {
|
||||
{"Lettuce"}, {"Bacon"}, {"Tomato"}, {"Cheese"}
|
||||
}
|
||||
});
|
||||
test_assert(t != 0);
|
||||
test_assert(ecs_has(world, t, EcsEnum));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_bitmask_from_stage(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_world_t *stage = ecs_get_stage(world, 0);
|
||||
test_assert(stage != NULL);
|
||||
|
||||
ecs_entity_t t = ecs_bitmask(stage, {
|
||||
.constants = {
|
||||
{"Lettuce"}, {"Bacon"}, {"Tomato"}, {"Cheese"}
|
||||
}
|
||||
});
|
||||
test_assert(t != 0);
|
||||
test_assert(ecs_has(world, t, EcsBitmask));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_struct_from_stage(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_world_t *stage = ecs_get_stage(world, 0);
|
||||
test_assert(stage != NULL);
|
||||
|
||||
ecs_entity_t t = ecs_struct(stage, { .members = {
|
||||
{"x", ecs_id(ecs_i32_t)},
|
||||
{"y", ecs_id(ecs_i32_t)},
|
||||
} });
|
||||
test_assert(t != 0);
|
||||
test_assert(ecs_has(world, t, EcsStruct));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_opaque_from_stage(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Position);
|
||||
|
||||
ecs_world_t *stage = ecs_get_stage(world, 0);
|
||||
test_assert(stage != NULL);
|
||||
|
||||
ecs_entity_t t = ecs_opaque(stage, {
|
||||
.entity = ecs_id(Position),
|
||||
.type.as_type = ecs_id(ecs_i32_t)
|
||||
});
|
||||
test_assert(t != 0);
|
||||
test_assert(ecs_has(world, t, EcsOpaque));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_array_from_stage(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_world_t *stage = ecs_get_stage(world, 0);
|
||||
test_assert(stage != NULL);
|
||||
|
||||
ecs_entity_t t = ecs_array(stage, {
|
||||
.type = ecs_id(ecs_i32_t),
|
||||
.count = 3
|
||||
});
|
||||
test_assert(t != 0);
|
||||
test_assert(ecs_has(world, t, EcsArray));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_vector_from_stage(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_world_t *stage = ecs_get_stage(world, 0);
|
||||
test_assert(stage != NULL);
|
||||
|
||||
ecs_entity_t t = ecs_vector(stage, {
|
||||
.type = ecs_id(ecs_i32_t)
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_assert(ecs_has(world, t, EcsVector));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_unit_from_stage(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_world_t *stage = ecs_get_stage(world, 0);
|
||||
test_assert(stage != NULL);
|
||||
|
||||
ecs_entity_t t = ecs_unit(stage, {
|
||||
.symbol = "f"
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_assert(ecs_has(world, t, EcsUnit));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_unit_prefix_from_stage(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_world_t *stage = ecs_get_stage(world, 0);
|
||||
test_assert(stage != NULL);
|
||||
|
||||
ecs_entity_t t = ecs_unit_prefix(stage, {
|
||||
.symbol = "f"
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_assert(ecs_has(world, t, EcsUnitPrefix));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_quantity_from_stage(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_world_t *stage = ecs_get_stage(world, 0);
|
||||
test_assert(stage != NULL);
|
||||
|
||||
ecs_entity_t t = ecs_quantity(stage, {
|
||||
.name = "q"
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_assert(ecs_has_id(world, t, EcsQuantity));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_primitive_from_defer(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_defer_begin(world);
|
||||
|
||||
ecs_entity_t t = ecs_primitive(world, { .kind = EcsI32 });
|
||||
test_assert(t != 0);
|
||||
|
||||
ecs_defer_end(world);
|
||||
test_assert(ecs_has(world, t, EcsPrimitive));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_enum_from_defer(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_defer_begin(world);
|
||||
|
||||
ecs_entity_t t = ecs_enum(world, {
|
||||
.constants = {
|
||||
{"Lettuce"}, {"Bacon"}, {"Tomato"}, {"Cheese"}
|
||||
}
|
||||
});
|
||||
test_assert(t != 0);
|
||||
|
||||
ecs_defer_end(world);
|
||||
test_assert(ecs_has(world, t, EcsEnum));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_bitmask_from_defer(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_defer_begin(world);
|
||||
|
||||
ecs_entity_t t = ecs_bitmask(world, {
|
||||
.constants = {
|
||||
{"Lettuce"}, {"Bacon"}, {"Tomato"}, {"Cheese"}
|
||||
}
|
||||
});
|
||||
test_assert(t != 0);
|
||||
|
||||
ecs_defer_end(world);
|
||||
test_assert(ecs_has(world, t, EcsBitmask));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_array_from_defer(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_defer_begin(world);
|
||||
|
||||
ecs_entity_t t = ecs_array(world, {
|
||||
.type = ecs_id(ecs_i32_t),
|
||||
.count = 3
|
||||
});
|
||||
test_assert(t != 0);
|
||||
|
||||
ecs_defer_end(world);
|
||||
test_assert(ecs_has(world, t, EcsArray));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_vector_from_defer(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_defer_begin(world);
|
||||
|
||||
ecs_entity_t t = ecs_vector(world, {
|
||||
.type = ecs_id(ecs_i32_t)
|
||||
});
|
||||
test_assert(t != 0);
|
||||
|
||||
ecs_defer_end(world);
|
||||
test_assert(ecs_has(world, t, EcsVector));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_struct_from_defer(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_defer_begin(world);
|
||||
|
||||
ecs_entity_t t = ecs_struct(world, { .members = {
|
||||
{"x", ecs_id(ecs_i32_t)},
|
||||
{"y", ecs_id(ecs_i32_t)},
|
||||
} });
|
||||
test_assert(t != 0);
|
||||
|
||||
ecs_defer_end(world);
|
||||
test_assert(ecs_has(world, t, EcsStruct));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_opaque_from_defer(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Position);
|
||||
|
||||
ecs_defer_begin(world);
|
||||
|
||||
ecs_entity_t t = ecs_opaque(world, {
|
||||
.entity = ecs_id(Position),
|
||||
.type.as_type = ecs_id(ecs_i32_t)
|
||||
});
|
||||
test_assert(t != 0);
|
||||
test_assert(ecs_has(world, t, EcsOpaque));
|
||||
|
||||
ecs_defer_end(world);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_unit_from_defer(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_defer_begin(world);
|
||||
|
||||
ecs_entity_t t = ecs_unit(world, {
|
||||
.symbol = "f"
|
||||
});
|
||||
|
||||
ecs_defer_end(world);
|
||||
test_assert(t != 0);
|
||||
test_assert(ecs_has(world, t, EcsUnit));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_unit_prefix_from_defer(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_defer_begin(world);
|
||||
|
||||
ecs_entity_t t = ecs_unit_prefix(world, {
|
||||
.symbol = "f"
|
||||
});
|
||||
|
||||
ecs_defer_end(world);
|
||||
test_assert(t != 0);
|
||||
test_assert(ecs_has(world, t, EcsUnitPrefix));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_quantity_from_defer(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_defer_begin(world);
|
||||
|
||||
ecs_entity_t t = ecs_quantity(world, {
|
||||
.name = "q"
|
||||
});
|
||||
|
||||
ecs_defer_end(world);
|
||||
test_assert(t != 0);
|
||||
test_assert(ecs_has_id(world, t, EcsQuantity));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_primitive_from_readonly(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_readonly_begin(world);
|
||||
|
||||
ecs_entity_t t = ecs_primitive(world, { .kind = EcsI32 });
|
||||
test_assert(t != 0);
|
||||
|
||||
ecs_readonly_end(world);
|
||||
test_assert(ecs_has(world, t, EcsPrimitive));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_enum_from_readonly(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_readonly_begin(world);
|
||||
|
||||
ecs_entity_t t = ecs_enum(world, {
|
||||
.constants = {
|
||||
{"Lettuce"}, {"Bacon"}, {"Tomato"}, {"Cheese"}
|
||||
}
|
||||
});
|
||||
test_assert(t != 0);
|
||||
|
||||
ecs_readonly_end(world);
|
||||
test_assert(ecs_has(world, t, EcsEnum));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_bitmask_from_readonly(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_readonly_begin(world);
|
||||
|
||||
ecs_entity_t t = ecs_bitmask(world, {
|
||||
.constants = {
|
||||
{"Lettuce"}, {"Bacon"}, {"Tomato"}, {"Cheese"}
|
||||
}
|
||||
});
|
||||
test_assert(t != 0);
|
||||
|
||||
ecs_readonly_end(world);
|
||||
test_assert(ecs_has(world, t, EcsBitmask));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_array_from_readonly(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_readonly_begin(world);
|
||||
|
||||
ecs_entity_t t = ecs_array(world, {
|
||||
.type = ecs_id(ecs_i32_t),
|
||||
.count = 3
|
||||
});
|
||||
test_assert(t != 0);
|
||||
|
||||
ecs_readonly_end(world);
|
||||
test_assert(ecs_has(world, t, EcsArray));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_vector_from_readonly(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_readonly_begin(world);
|
||||
|
||||
ecs_entity_t t = ecs_vector(world, {
|
||||
.type = ecs_id(ecs_i32_t)
|
||||
});
|
||||
test_assert(t != 0);
|
||||
|
||||
ecs_readonly_end(world);
|
||||
test_assert(ecs_has(world, t, EcsVector));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_struct_from_readonly(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_readonly_begin(world);
|
||||
|
||||
ecs_entity_t t = ecs_struct(world, { .members = {
|
||||
{"x", ecs_id(ecs_i32_t)},
|
||||
{"y", ecs_id(ecs_i32_t)},
|
||||
} });
|
||||
test_assert(t != 0);
|
||||
|
||||
ecs_readonly_end(world);
|
||||
test_assert(ecs_has(world, t, EcsStruct));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_opaque_from_readonly(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Position);
|
||||
|
||||
ecs_readonly_begin(world);
|
||||
|
||||
ecs_entity_t t = ecs_opaque(world, {
|
||||
.entity = ecs_id(Position),
|
||||
.type.as_type = ecs_id(ecs_i32_t)
|
||||
});
|
||||
test_assert(t != 0);
|
||||
test_assert(ecs_has(world, t, EcsOpaque));
|
||||
|
||||
ecs_readonly_end(world);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_unit_from_readonly(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_readonly_begin(world);
|
||||
|
||||
ecs_entity_t t = ecs_unit(world, {
|
||||
.symbol = "f"
|
||||
});
|
||||
|
||||
ecs_readonly_end(world);
|
||||
test_assert(t != 0);
|
||||
test_assert(ecs_has(world, t, EcsUnit));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_unit_prefix_from_readonly(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_readonly_begin(world);
|
||||
|
||||
ecs_entity_t t = ecs_unit_prefix(world, {
|
||||
.symbol = "f"
|
||||
});
|
||||
|
||||
ecs_readonly_end(world);
|
||||
test_assert(t != 0);
|
||||
test_assert(ecs_has(world, t, EcsUnitPrefix));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_quantity_from_readonly(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_readonly_begin(world);
|
||||
|
||||
ecs_entity_t t = ecs_quantity(world, {
|
||||
.name = "q"
|
||||
});
|
||||
|
||||
ecs_readonly_end(world);
|
||||
test_assert(t != 0);
|
||||
test_assert(ecs_has_id(world, t, EcsQuantity));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_primitive_from_suspend_defer(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_defer_begin(world);
|
||||
ecs_defer_suspend(world);
|
||||
|
||||
ecs_entity_t t = ecs_primitive(world, { .kind = EcsI32 });
|
||||
test_assert(t != 0);
|
||||
|
||||
ecs_defer_resume(world);
|
||||
ecs_defer_end(world);
|
||||
test_assert(ecs_has(world, t, EcsPrimitive));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_enum_from_suspend_defer(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_defer_begin(world);
|
||||
ecs_defer_suspend(world);
|
||||
|
||||
ecs_entity_t t = ecs_enum(world, {
|
||||
.constants = {
|
||||
{"Lettuce"}, {"Bacon"}, {"Tomato"}, {"Cheese"}
|
||||
}
|
||||
});
|
||||
test_assert(t != 0);
|
||||
|
||||
ecs_defer_resume(world);
|
||||
ecs_defer_end(world);
|
||||
test_assert(ecs_has(world, t, EcsEnum));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_bitmask_from_suspend_defer(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_defer_begin(world);
|
||||
ecs_defer_suspend(world);
|
||||
|
||||
ecs_entity_t t = ecs_bitmask(world, {
|
||||
.constants = {
|
||||
{"Lettuce"}, {"Bacon"}, {"Tomato"}, {"Cheese"}
|
||||
}
|
||||
});
|
||||
test_assert(t != 0);
|
||||
|
||||
ecs_defer_resume(world);
|
||||
ecs_defer_end(world);
|
||||
test_assert(ecs_has(world, t, EcsBitmask));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_array_from_suspend_defer(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_defer_begin(world);
|
||||
ecs_defer_suspend(world);
|
||||
|
||||
ecs_entity_t t = ecs_array(world, {
|
||||
.type = ecs_id(ecs_i32_t),
|
||||
.count = 3
|
||||
});
|
||||
test_assert(t != 0);
|
||||
|
||||
ecs_defer_resume(world);
|
||||
ecs_defer_end(world);
|
||||
test_assert(ecs_has(world, t, EcsArray));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_vector_from_suspend_defer(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_defer_begin(world);
|
||||
ecs_defer_suspend(world);
|
||||
|
||||
ecs_entity_t t = ecs_vector(world, {
|
||||
.type = ecs_id(ecs_i32_t)
|
||||
});
|
||||
test_assert(t != 0);
|
||||
|
||||
ecs_defer_resume(world);
|
||||
ecs_defer_end(world);
|
||||
test_assert(ecs_has(world, t, EcsVector));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_struct_from_suspend_defer(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_defer_begin(world);
|
||||
ecs_defer_suspend(world);
|
||||
|
||||
ecs_entity_t t = ecs_struct(world, { .members = {
|
||||
{"x", ecs_id(ecs_i32_t)},
|
||||
{"y", ecs_id(ecs_i32_t)},
|
||||
} });
|
||||
test_assert(t != 0);
|
||||
|
||||
ecs_defer_resume(world);
|
||||
ecs_defer_end(world);
|
||||
test_assert(ecs_has(world, t, EcsStruct));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_opaque_from_suspend_defer(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Position);
|
||||
|
||||
ecs_defer_begin(world);
|
||||
ecs_defer_suspend(world);
|
||||
|
||||
ecs_entity_t t = ecs_opaque(world, {
|
||||
.entity = ecs_id(Position),
|
||||
.type.as_type = ecs_id(ecs_i32_t)
|
||||
});
|
||||
test_assert(t != 0);
|
||||
test_assert(ecs_has(world, t, EcsOpaque));
|
||||
|
||||
ecs_defer_resume(world);
|
||||
ecs_defer_end(world);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_unit_from_suspend_defer(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_defer_begin(world);
|
||||
ecs_defer_suspend(world);
|
||||
|
||||
ecs_entity_t t = ecs_unit(world, {
|
||||
.symbol = "f"
|
||||
});
|
||||
|
||||
ecs_defer_resume(world);
|
||||
ecs_defer_end(world);
|
||||
|
||||
test_assert(t != 0);
|
||||
test_assert(ecs_has(world, t, EcsUnit));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_unit_prefix_from_suspend_defer(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_defer_begin(world);
|
||||
ecs_defer_suspend(world);
|
||||
|
||||
ecs_entity_t t = ecs_unit_prefix(world, {
|
||||
.symbol = "f"
|
||||
});
|
||||
|
||||
ecs_defer_resume(world);
|
||||
ecs_defer_end(world);
|
||||
|
||||
test_assert(t != 0);
|
||||
test_assert(ecs_has(world, t, EcsUnitPrefix));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Misc_quantity_from_suspend_defer(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_defer_begin(world);
|
||||
ecs_defer_suspend(world);
|
||||
|
||||
ecs_entity_t t = ecs_quantity(world, {
|
||||
.name = "q"
|
||||
});
|
||||
|
||||
ecs_defer_resume(world);
|
||||
ecs_defer_end(world);
|
||||
|
||||
test_assert(t != 0);
|
||||
test_assert(ecs_has_id(world, t, EcsQuantity));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
1005
engine/libs/flecs/test/meta/src/NestedStructTypes.c
Normal file
1005
engine/libs/flecs/test/meta/src/NestedStructTypes.c
Normal file
File diff suppressed because it is too large
Load Diff
639
engine/libs/flecs/test/meta/src/OpaqueTypes.c
Normal file
639
engine/libs/flecs/test/meta/src/OpaqueTypes.c
Normal file
@@ -0,0 +1,639 @@
|
||||
#include <meta.h>
|
||||
|
||||
static int serialize_invoked = 0;
|
||||
|
||||
typedef int32_t Int32;
|
||||
typedef char* String;
|
||||
|
||||
typedef struct IntVec {
|
||||
int32_t count;
|
||||
Int32 *elems;
|
||||
} IntVec;
|
||||
|
||||
typedef struct StringVec {
|
||||
int32_t count;
|
||||
String *elems;
|
||||
} StringVec;
|
||||
|
||||
// Custom serializer functions
|
||||
static
|
||||
int Int32_serialize(const ecs_serializer_t *ser, const void *ptr) {
|
||||
test_assert(ser != NULL);
|
||||
test_assert(ptr != NULL);
|
||||
int result = ser->value(ser, ecs_id(ecs_i32_t), ptr);
|
||||
test_assert(result == 0);
|
||||
serialize_invoked ++;
|
||||
return result;
|
||||
}
|
||||
|
||||
static
|
||||
int String_serialize(const ecs_serializer_t *ser, const void *ptr) {
|
||||
test_assert(ser != NULL);
|
||||
test_assert(ptr != NULL);
|
||||
int result = ser->value(ser, ecs_id(ecs_string_t), ptr);
|
||||
test_assert(result == 0);
|
||||
serialize_invoked ++;
|
||||
return result;
|
||||
}
|
||||
|
||||
int IntVec_serialize(const ecs_serializer_t *ser, const void *ptr) {
|
||||
test_assert(ser != NULL);
|
||||
test_assert(ptr != NULL);
|
||||
|
||||
const IntVec *data = ptr;
|
||||
for (int i = 0; i < data->count; i ++) {
|
||||
int result = ser->value(ser, ecs_id(ecs_i32_t), &data->elems[i]);
|
||||
test_assert(result == 0);
|
||||
}
|
||||
|
||||
serialize_invoked ++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int StringVec_serialize(const ecs_serializer_t *ser, const void *ptr) {
|
||||
test_assert(ser != NULL);
|
||||
test_assert(ptr != NULL);
|
||||
|
||||
const StringVec *data = ptr;
|
||||
for (int i = 0; i < data->count; i ++) {
|
||||
int result = ser->value(ser, ecs_id(ecs_string_t), &data->elems[i]);
|
||||
test_assert(result == 0);
|
||||
}
|
||||
|
||||
serialize_invoked ++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void OpaqueTypes_ser_i32_type_to_json(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Int32);
|
||||
|
||||
ecs_opaque(world, {
|
||||
.entity = ecs_id(Int32),
|
||||
.type.as_type = ecs_primitive(world, { .kind = EcsI32 }),
|
||||
.type.serialize = Int32_serialize
|
||||
});
|
||||
|
||||
Int32 v = 10;
|
||||
|
||||
char *json = ecs_ptr_to_json(world, ecs_id(Int32), &v);
|
||||
test_assert(json != NULL);
|
||||
test_str(json, "10");
|
||||
ecs_os_free(json);
|
||||
|
||||
test_int(serialize_invoked, 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void OpaqueTypes_ser_string_type_to_json(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, String);
|
||||
|
||||
ecs_opaque(world, {
|
||||
.entity = ecs_id(String),
|
||||
.type.as_type = ecs_primitive(world, { .kind = EcsString }),
|
||||
.type.serialize = String_serialize
|
||||
});
|
||||
|
||||
String v = "Hello World";
|
||||
|
||||
char *json = ecs_ptr_to_json(world, ecs_id(String), &v);
|
||||
test_assert(json != NULL);
|
||||
test_str(json, "\"Hello World\"");
|
||||
ecs_os_free(json);
|
||||
|
||||
test_int(serialize_invoked, 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void OpaqueTypes_ser_vec_i32_type_to_json(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, IntVec);
|
||||
|
||||
ecs_opaque(world, {
|
||||
.entity = ecs_id(IntVec),
|
||||
.type.as_type = ecs_vector(world, { .type = ecs_id(ecs_i32_t) }),
|
||||
.type.serialize = IntVec_serialize
|
||||
});
|
||||
|
||||
IntVec v = {3, (int[]){1, 2, 3}};
|
||||
|
||||
char *json = ecs_ptr_to_json(world, ecs_id(IntVec), &v);
|
||||
test_assert(json != NULL);
|
||||
test_str(json, "[1, 2, 3]");
|
||||
ecs_os_free(json);
|
||||
|
||||
test_int(serialize_invoked, 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void OpaqueTypes_ser_vec_string_type_to_json(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, StringVec);
|
||||
|
||||
ecs_opaque(world, {
|
||||
.entity = ecs_id(StringVec),
|
||||
.type.as_type = ecs_vector(world, { .type = ecs_id(ecs_string_t) }),
|
||||
.type.serialize = StringVec_serialize
|
||||
});
|
||||
|
||||
StringVec v = {2, (String[]){"Hello", "World"}};
|
||||
|
||||
char *json = ecs_ptr_to_json(world, ecs_id(StringVec), &v);
|
||||
test_assert(json != NULL);
|
||||
test_str(json, "[\"Hello\", \"World\"]");
|
||||
ecs_os_free(json);
|
||||
|
||||
test_int(serialize_invoked, 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
typedef struct Struct_1_member {
|
||||
int32_t x;
|
||||
} Struct_1_member;
|
||||
|
||||
typedef struct Struct_2_member {
|
||||
int32_t x, y;
|
||||
} Struct_2_member;
|
||||
|
||||
typedef struct Struct_3_member {
|
||||
int32_t x, y, z;
|
||||
} Struct_3_member;
|
||||
|
||||
int Struct_1_member_serialize(const ecs_serializer_t *ser, const void *ptr) {
|
||||
test_assert(ser != NULL);
|
||||
test_assert(ptr != NULL);
|
||||
|
||||
const Struct_1_member *data = ptr;
|
||||
int result;
|
||||
|
||||
result = ser->member(ser, "x");
|
||||
test_assert(result == 0);
|
||||
result = ser->value(ser, ecs_id(ecs_i32_t), &data->x);
|
||||
test_assert(result == 0);
|
||||
|
||||
serialize_invoked ++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Struct_2_member_serialize(const ecs_serializer_t *ser, const void *ptr) {
|
||||
test_assert(ser != NULL);
|
||||
test_assert(ptr != NULL);
|
||||
|
||||
const Struct_2_member *data = ptr;
|
||||
int result;
|
||||
|
||||
result = ser->member(ser, "x");
|
||||
test_assert(result == 0);
|
||||
result = ser->value(ser, ecs_id(ecs_i32_t), &data->x);
|
||||
test_assert(result == 0);
|
||||
|
||||
result = ser->member(ser, "y");
|
||||
test_assert(result == 0);
|
||||
result = ser->value(ser, ecs_id(ecs_i32_t), &data->y);
|
||||
test_assert(result == 0);
|
||||
|
||||
serialize_invoked ++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Struct_3_member_serialize(const ecs_serializer_t *ser, const void *ptr) {
|
||||
test_assert(ser != NULL);
|
||||
test_assert(ptr != NULL);
|
||||
|
||||
const Struct_3_member *data = ptr;
|
||||
int result;
|
||||
|
||||
result = ser->member(ser, "x");
|
||||
test_assert(result == 0);
|
||||
result = ser->value(ser, ecs_id(ecs_i32_t), &data->x);
|
||||
test_assert(result == 0);
|
||||
|
||||
result = ser->member(ser, "y");
|
||||
test_assert(result == 0);
|
||||
result = ser->value(ser, ecs_id(ecs_i32_t), &data->y);
|
||||
test_assert(result == 0);
|
||||
|
||||
result = ser->member(ser, "z");
|
||||
test_assert(result == 0);
|
||||
result = ser->value(ser, ecs_id(ecs_i32_t), &data->z);
|
||||
test_assert(result == 0);
|
||||
|
||||
serialize_invoked ++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void OpaqueTypes_ser_struct_1_member(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Struct_1_member);
|
||||
|
||||
ecs_entity_t s = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
ecs_opaque(world, {
|
||||
.entity = ecs_id(Struct_1_member),
|
||||
.type.as_type = s,
|
||||
.type.serialize = Struct_1_member_serialize
|
||||
});
|
||||
|
||||
Struct_1_member v = { 1 };
|
||||
|
||||
char *json = ecs_ptr_to_json(world, ecs_id(Struct_1_member), &v);
|
||||
test_assert(json != NULL);
|
||||
test_str(json, "{\"x\":1}");
|
||||
ecs_os_free(json);
|
||||
|
||||
test_int(serialize_invoked, 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void OpaqueTypes_ser_struct_2_members(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Struct_2_member);
|
||||
|
||||
ecs_entity_t s = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t)},
|
||||
{"y", ecs_id(ecs_i32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
ecs_opaque(world, {
|
||||
.entity = ecs_id(Struct_2_member),
|
||||
.type.as_type = s,
|
||||
.type.serialize = Struct_2_member_serialize
|
||||
});
|
||||
|
||||
Struct_2_member v = { 1, 2 };
|
||||
|
||||
char *json = ecs_ptr_to_json(world, ecs_id(Struct_2_member), &v);
|
||||
test_assert(json != NULL);
|
||||
test_str(json, "{\"x\":1, \"y\":2}");
|
||||
ecs_os_free(json);
|
||||
|
||||
test_int(serialize_invoked, 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void OpaqueTypes_ser_struct_3_members(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Struct_3_member);
|
||||
|
||||
ecs_entity_t s = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t)},
|
||||
{"y", ecs_id(ecs_i32_t)},
|
||||
{"z", ecs_id(ecs_i32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
ecs_opaque(world, {
|
||||
.entity = ecs_id(Struct_3_member),
|
||||
.type.as_type = s,
|
||||
.type.serialize = Struct_3_member_serialize
|
||||
});
|
||||
|
||||
Struct_3_member v = { 1, 2, 3 };
|
||||
|
||||
char *json = ecs_ptr_to_json(world, ecs_id(Struct_3_member), &v);
|
||||
test_assert(json != NULL);
|
||||
test_str(json, "{\"x\":1, \"y\":2, \"z\":3}");
|
||||
ecs_os_free(json);
|
||||
|
||||
test_int(serialize_invoked, 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
#define OpaqueType(t)\
|
||||
typedef struct { \
|
||||
t value; \
|
||||
} Opaque_##t; \
|
||||
\
|
||||
static void t##_set(void *ptr, t value) { \
|
||||
((Opaque_##t*)ptr)->value = value; \
|
||||
}
|
||||
|
||||
OpaqueType(bool)
|
||||
OpaqueType(char)
|
||||
OpaqueType(int64_t)
|
||||
OpaqueType(uint64_t)
|
||||
OpaqueType(double)
|
||||
|
||||
typedef struct {
|
||||
ecs_entity_t value;
|
||||
} Opaque_entity;
|
||||
|
||||
static void Opaque_entity_set(void *ptr, ecs_world_t *world, ecs_entity_t value) {
|
||||
((Opaque_entity*)ptr)->value = value;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
char *value;
|
||||
} Opaque_string;
|
||||
|
||||
static void Opaque_string_set(void *ptr, const char *value) {
|
||||
((Opaque_string*)ptr)->value = ecs_os_strdup(value);
|
||||
}
|
||||
|
||||
void OpaqueTypes_deser_bool_from_json(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Opaque_bool);
|
||||
|
||||
ecs_opaque(world, {
|
||||
.entity = ecs_id(Opaque_bool),
|
||||
.type.as_type = ecs_id(ecs_bool_t),
|
||||
.type.assign_bool = bool_set
|
||||
});
|
||||
|
||||
Opaque_bool v = { false };
|
||||
{
|
||||
const char *r = ecs_ptr_from_json(world, ecs_id(Opaque_bool), &v, "true", NULL);
|
||||
test_str(r, "");
|
||||
test_bool(v.value, true);
|
||||
}
|
||||
{
|
||||
const char *r = ecs_ptr_from_json(world, ecs_id(Opaque_bool), &v, "false", NULL);
|
||||
test_str(r, "");
|
||||
test_bool(v.value, false);
|
||||
}
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void OpaqueTypes_deser_char_from_json(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Opaque_char);
|
||||
|
||||
ecs_opaque(world, {
|
||||
.entity = ecs_id(Opaque_char),
|
||||
.type.as_type = ecs_id(ecs_char_t),
|
||||
.type.assign_char = char_set
|
||||
});
|
||||
|
||||
Opaque_char v = { 0 };
|
||||
{
|
||||
const char *r = ecs_ptr_from_json(world, ecs_id(Opaque_char), &v, "\"a\"", NULL);
|
||||
test_str(r, "");
|
||||
test_int(v.value, 'a');
|
||||
}
|
||||
{
|
||||
const char *r = ecs_ptr_from_json(world, ecs_id(Opaque_char), &v, "\"b\"", NULL);
|
||||
test_str(r, "");
|
||||
test_int(v.value, 'b');
|
||||
}
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void OpaqueTypes_deser_int_from_json(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Opaque_int64_t);
|
||||
|
||||
ecs_opaque(world, {
|
||||
.entity = ecs_id(Opaque_int64_t),
|
||||
.type.as_type = ecs_id(ecs_i64_t),
|
||||
.type.assign_int = int64_t_set
|
||||
});
|
||||
|
||||
Opaque_int64_t v = { 0 };
|
||||
{
|
||||
const char *r = ecs_ptr_from_json(world, ecs_id(Opaque_int64_t), &v, "10", NULL);
|
||||
test_str(r, "");
|
||||
test_int(v.value, 10);
|
||||
}
|
||||
{
|
||||
const char *r = ecs_ptr_from_json(world, ecs_id(Opaque_int64_t), &v, "20", NULL);
|
||||
test_str(r, "");
|
||||
test_int(v.value, 20);
|
||||
}
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void OpaqueTypes_deser_uint_from_json(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Opaque_uint64_t);
|
||||
|
||||
ecs_opaque(world, {
|
||||
.entity = ecs_id(Opaque_uint64_t),
|
||||
.type.as_type = ecs_id(ecs_u64_t),
|
||||
.type.assign_uint = uint64_t_set
|
||||
});
|
||||
|
||||
Opaque_uint64_t v = { 0 };
|
||||
{
|
||||
const char *r = ecs_ptr_from_json(world, ecs_id(Opaque_uint64_t), &v, "10", NULL);
|
||||
test_str(r, "");
|
||||
test_int(v.value, 10);
|
||||
}
|
||||
{
|
||||
const char *r = ecs_ptr_from_json(world, ecs_id(Opaque_uint64_t), &v, "20", NULL);
|
||||
test_str(r, "");
|
||||
test_int(v.value, 20);
|
||||
}
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void OpaqueTypes_deser_float_from_json(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Opaque_double);
|
||||
|
||||
ecs_opaque(world, {
|
||||
.entity = ecs_id(Opaque_double),
|
||||
.type.as_type = ecs_id(ecs_f64_t),
|
||||
.type.assign_float = double_set
|
||||
});
|
||||
|
||||
Opaque_double v = { 0 };
|
||||
{
|
||||
const char *r = ecs_ptr_from_json(world, ecs_id(Opaque_double), &v, "10.5", NULL);
|
||||
test_str(r, "");
|
||||
test_int(v.value, 10); // avoid floating point comparison
|
||||
}
|
||||
{
|
||||
const char *r = ecs_ptr_from_json(world, ecs_id(Opaque_double), &v, "20.5", NULL);
|
||||
test_str(r, "");
|
||||
test_int(v.value, 20); // avoid floating point comparison
|
||||
}
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void OpaqueTypes_deser_string_from_json(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Opaque_string);
|
||||
|
||||
ecs_opaque(world, {
|
||||
.entity = ecs_id(Opaque_string),
|
||||
.type.as_type = ecs_id(ecs_string_t),
|
||||
.type.assign_string = Opaque_string_set
|
||||
});
|
||||
|
||||
Opaque_string v = { 0 };
|
||||
{
|
||||
const char *r = ecs_ptr_from_json(
|
||||
world, ecs_id(Opaque_string), &v, "\"Hello World\"", NULL);
|
||||
test_str(r, "");
|
||||
test_str(v.value, "Hello World");
|
||||
ecs_os_free(v.value);
|
||||
}
|
||||
{
|
||||
const char *r = ecs_ptr_from_json(
|
||||
world, ecs_id(Opaque_string), &v, "\"Foo Bar\"", NULL);
|
||||
test_str(r, "");
|
||||
test_str(v.value, "Foo Bar");
|
||||
ecs_os_free(v.value);
|
||||
}
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void OpaqueTypes_deser_entity_from_json(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Opaque_entity);
|
||||
|
||||
ecs_opaque(world, {
|
||||
.entity = ecs_id(Opaque_entity),
|
||||
.type.as_type = ecs_id(ecs_string_t),
|
||||
.type.assign_entity = Opaque_entity_set
|
||||
});
|
||||
|
||||
ecs_entity_t e1 = ecs_new_entity(world, "e1");
|
||||
ecs_entity_t e2 = ecs_new_entity(world, "e2");
|
||||
|
||||
Opaque_entity v = { 0 };
|
||||
{
|
||||
const char *r = ecs_ptr_from_json(
|
||||
world, ecs_id(Opaque_entity), &v, "\"e1\"", NULL);
|
||||
test_str(r, "");
|
||||
test_uint(v.value, e1);
|
||||
}
|
||||
{
|
||||
const char *r = ecs_ptr_from_json(
|
||||
world, ecs_id(Opaque_entity), &v, "\"e2\"", NULL);
|
||||
test_str(r, "");
|
||||
test_uint(v.value, e2);
|
||||
}
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void OpaqueTypes_ser_deser_world_w_ser_opaque(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Int32);
|
||||
|
||||
ecs_opaque(world, {
|
||||
.entity = ecs_id(Int32),
|
||||
.type.as_type = ecs_id(ecs_i32_t),
|
||||
.type.serialize = Int32_serialize
|
||||
});
|
||||
|
||||
char *json = ecs_world_to_json(world, NULL);
|
||||
test_assert(json != NULL);
|
||||
const char *r = ecs_world_from_json(world, json, NULL);
|
||||
test_str(r, "");
|
||||
ecs_os_free(json);
|
||||
|
||||
{
|
||||
Int32 v = { 10 };
|
||||
char *json = ecs_ptr_to_json(world, ecs_id(Int32), &v);
|
||||
test_assert(json != NULL);
|
||||
test_str(json, "10");
|
||||
ecs_os_free(json);
|
||||
}
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
ecs_entity_t entity;
|
||||
} Entity;
|
||||
|
||||
int Entity_serialize(const ecs_serializer_t *ser, const void *ptr) {
|
||||
const Entity *data = ptr;
|
||||
return ser->value(ser, ecs_id(ecs_entity_t), &data->entity);
|
||||
}
|
||||
|
||||
void Entity_assign(void *ptr, ecs_world_t *world, ecs_entity_t value) {
|
||||
Entity *data = ptr;
|
||||
data->entity = value;
|
||||
}
|
||||
|
||||
void OpaqueTypes_ser_deser_entity(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Entity);
|
||||
|
||||
ecs_opaque(world, {
|
||||
.entity = ecs_id(Entity),
|
||||
.type.as_type = ecs_id(ecs_entity_t),
|
||||
.type.serialize = Entity_serialize,
|
||||
.type.assign_entity = Entity_assign
|
||||
});
|
||||
|
||||
ecs_entity_t e1 = ecs_new_entity(world, "ent1");
|
||||
ecs_entity_t e2 = ecs_new_entity(world, "ent2");
|
||||
|
||||
Entity v = { e1 };
|
||||
char *json = ecs_ptr_to_json(world, ecs_id(Entity), &v);
|
||||
test_assert(json != NULL);
|
||||
test_str(json, "\"ent1\"");
|
||||
|
||||
const char *r = ecs_ptr_from_json(world, ecs_id(Entity), &v, "\"ent2\"", NULL);
|
||||
test_str(r, "");
|
||||
test_assert(v.entity == e2);
|
||||
ecs_os_free(json);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void OpaqueTypes_ser_deser_0_entity(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Entity);
|
||||
|
||||
ecs_opaque(world, {
|
||||
.entity = ecs_id(Entity),
|
||||
.type.as_type = ecs_id(ecs_entity_t),
|
||||
.type.serialize = Entity_serialize,
|
||||
.type.assign_entity = Entity_assign
|
||||
});
|
||||
|
||||
Entity v = { 0 };
|
||||
char *json = ecs_ptr_to_json(world, ecs_id(Entity), &v);
|
||||
test_assert(json != NULL);
|
||||
test_str(json, "0");
|
||||
|
||||
const char *r = ecs_ptr_from_json(world, ecs_id(Entity), &v, json, NULL);
|
||||
test_str(r, "");
|
||||
test_assert(v.entity == 0);
|
||||
ecs_os_free(json);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
511
engine/libs/flecs/test/meta/src/PrimitiveTypes.c
Normal file
511
engine/libs/flecs/test/meta/src/PrimitiveTypes.c
Normal file
@@ -0,0 +1,511 @@
|
||||
#include <meta.h>
|
||||
|
||||
static void meta_test_primitive(
|
||||
ecs_world_t *world,
|
||||
ecs_entity_t t,
|
||||
ecs_primitive_kind_t kind,
|
||||
ecs_size_t size,
|
||||
ecs_size_t alignment)
|
||||
{
|
||||
const EcsComponent *ct = ecs_get(world, t, EcsComponent);
|
||||
test_assert(ct != NULL);
|
||||
test_assert(ct->size == size);
|
||||
test_assert(ct->alignment == alignment);
|
||||
|
||||
const EcsMetaType *mt = ecs_get(world, t, EcsMetaType);
|
||||
test_assert(mt != NULL);
|
||||
test_assert(mt->kind == EcsPrimitiveType);
|
||||
|
||||
const EcsPrimitive *pt = ecs_get(world, t, EcsPrimitive);
|
||||
test_assert(pt != NULL);
|
||||
test_assert(pt->kind == kind);
|
||||
}
|
||||
|
||||
#define meta_test_type(kind, type)\
|
||||
static void meta_test_##type(ecs_world_t *world, ecs_entity_t t) {\
|
||||
meta_test_primitive(world, t, kind, ECS_SIZEOF(ecs_##type##_t), ECS_ALIGNOF(ecs_##type##_t));\
|
||||
}
|
||||
|
||||
#define meta_test_builtin(world, type)\
|
||||
meta_test_##type(world, ecs_id(ecs_##type##_t))
|
||||
|
||||
meta_test_type(EcsBool, bool)
|
||||
meta_test_type(EcsByte, byte)
|
||||
meta_test_type(EcsChar, char)
|
||||
meta_test_type(EcsI8, i8)
|
||||
meta_test_type(EcsI16, i16)
|
||||
meta_test_type(EcsI32, i32)
|
||||
meta_test_type(EcsI64, i64)
|
||||
meta_test_type(EcsIPtr, iptr)
|
||||
meta_test_type(EcsU8, u8)
|
||||
meta_test_type(EcsU16, u16)
|
||||
meta_test_type(EcsU32, u32)
|
||||
meta_test_type(EcsU64, u64)
|
||||
meta_test_type(EcsUPtr, uptr)
|
||||
meta_test_type(EcsF32, f32)
|
||||
meta_test_type(EcsF64, f64)
|
||||
meta_test_type(EcsString, string)
|
||||
meta_test_type(EcsEntity, entity)
|
||||
|
||||
void PrimitiveTypes_bool(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_set(world, 0, EcsPrimitive, {.kind = EcsBool});
|
||||
test_assert(t != 0);
|
||||
|
||||
meta_test_bool(world, t);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_byte(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_set(world, 0, EcsPrimitive, {.kind = EcsByte});
|
||||
test_assert(t != 0);
|
||||
|
||||
meta_test_byte(world, t);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_char(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_set(world, 0, EcsPrimitive, {.kind = EcsChar});
|
||||
test_assert(t != 0);
|
||||
|
||||
meta_test_char(world, t);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_i8(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_set(world, 0, EcsPrimitive, {.kind = EcsI8});
|
||||
test_assert(t != 0);
|
||||
|
||||
meta_test_i8(world, t);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_i16(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_set(world, 0, EcsPrimitive, {.kind = EcsI16});
|
||||
test_assert(t != 0);
|
||||
|
||||
meta_test_i16(world, t);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_i32(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_set(world, 0, EcsPrimitive, {.kind = EcsI32});
|
||||
test_assert(t != 0);
|
||||
|
||||
meta_test_i32(world, t);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_i64(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_set(world, 0, EcsPrimitive, {.kind = EcsI64});
|
||||
test_assert(t != 0);
|
||||
|
||||
meta_test_i64(world, t);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_iptr(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_set(world, 0, EcsPrimitive, {.kind = EcsIPtr});
|
||||
test_assert(t != 0);
|
||||
|
||||
meta_test_iptr(world, t);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_u8(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_set(world, 0, EcsPrimitive, {.kind = EcsU8});
|
||||
test_assert(t != 0);
|
||||
|
||||
meta_test_u8(world, t);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_u16(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_set(world, 0, EcsPrimitive, {.kind = EcsU16});
|
||||
test_assert(t != 0);
|
||||
|
||||
meta_test_u16(world, t);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_u32(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_set(world, 0, EcsPrimitive, {.kind = EcsU32});
|
||||
test_assert(t != 0);
|
||||
|
||||
meta_test_u32(world, t);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_u64(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_set(world, 0, EcsPrimitive, {.kind = EcsU64});
|
||||
test_assert(t != 0);
|
||||
|
||||
meta_test_u64(world, t);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_uptr(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_set(world, 0, EcsPrimitive, {.kind = EcsUPtr});
|
||||
test_assert(t != 0);
|
||||
|
||||
meta_test_uptr(world, t);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_float(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_set(world, 0, EcsPrimitive, {.kind = EcsF32});
|
||||
test_assert(t != 0);
|
||||
|
||||
meta_test_f32(world, t);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_double(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_set(world, 0, EcsPrimitive, {.kind = EcsF64});
|
||||
test_assert(t != 0);
|
||||
|
||||
meta_test_f64(world, t);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_string(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_set(world, 0, EcsPrimitive, {.kind = EcsString});
|
||||
test_assert(t != 0);
|
||||
|
||||
meta_test_string(world, t);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_entity(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_set(world, 0, EcsPrimitive, {.kind = EcsEntity});
|
||||
test_assert(t != 0);
|
||||
|
||||
meta_test_entity(world, t);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_builtin_bool(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
meta_test_builtin(world, bool);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_builtin_byte(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
meta_test_builtin(world, byte);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_builtin_char(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
meta_test_builtin(world, char);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_builtin_i8(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
meta_test_builtin(world, i8);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_builtin_i16(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
meta_test_builtin(world, i16);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_builtin_i32(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
meta_test_builtin(world, i32);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_builtin_i64(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
meta_test_builtin(world, i64);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_builtin_iptr(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
meta_test_builtin(world, iptr);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_builtin_u8(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
meta_test_builtin(world, u8);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_builtin_u16(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
meta_test_builtin(world, i16);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_builtin_u32(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
meta_test_builtin(world, u32);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_builtin_u64(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
meta_test_builtin(world, u64);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_builtin_uptr(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
meta_test_builtin(world, uptr);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_builtin_float(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
meta_test_builtin(world, f32);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_builtin_double(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
meta_test_builtin(world, f64);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_builtin_string(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
meta_test_builtin(world, string);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_builtin_entity(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
meta_test_builtin(world, entity);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
#define STRUCT_W_PRIMITIVE_TEST(PrimitiveType)\
|
||||
typedef struct {\
|
||||
ecs_bool_t before;\
|
||||
PrimitiveType v;\
|
||||
ecs_bool_t after;\
|
||||
} T;\
|
||||
\
|
||||
ecs_world_t *world = ecs_init();\
|
||||
\
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){\
|
||||
.entity = ecs_entity(world, {.name = "T"}),\
|
||||
.members = {\
|
||||
{"before", ecs_id(ecs_bool_t)},\
|
||||
{"v", ecs_id(PrimitiveType)},\
|
||||
{"after", ecs_id(ecs_bool_t)}\
|
||||
}\
|
||||
});\
|
||||
\
|
||||
test_assert(t != 0);\
|
||||
test_str(ecs_get_name(world, t), "T");\
|
||||
\
|
||||
meta_test_struct(world, t, T);\
|
||||
meta_test_member(world, t, T, before, ecs_id(ecs_bool_t), 1);\
|
||||
meta_test_member(world, t, T, v, ecs_id(PrimitiveType), 1);\
|
||||
meta_test_member(world, t, T, after, ecs_id(ecs_bool_t), 1);\
|
||||
\
|
||||
ecs_fini(world);
|
||||
|
||||
void PrimitiveTypes_struct_w_bool(void) {
|
||||
STRUCT_W_PRIMITIVE_TEST(ecs_bool_t)
|
||||
}
|
||||
|
||||
void PrimitiveTypes_struct_w_byte(void) {
|
||||
STRUCT_W_PRIMITIVE_TEST(ecs_byte_t)
|
||||
}
|
||||
|
||||
void PrimitiveTypes_struct_w_char(void) {
|
||||
STRUCT_W_PRIMITIVE_TEST(ecs_char_t)
|
||||
}
|
||||
|
||||
void PrimitiveTypes_struct_w_i8(void) {
|
||||
STRUCT_W_PRIMITIVE_TEST(ecs_i8_t)
|
||||
}
|
||||
|
||||
void PrimitiveTypes_struct_w_i16(void) {
|
||||
STRUCT_W_PRIMITIVE_TEST(ecs_i16_t)
|
||||
}
|
||||
|
||||
void PrimitiveTypes_struct_w_i32(void) {
|
||||
STRUCT_W_PRIMITIVE_TEST(ecs_i32_t)
|
||||
}
|
||||
|
||||
void PrimitiveTypes_struct_w_i64(void) {
|
||||
STRUCT_W_PRIMITIVE_TEST(ecs_i64_t)
|
||||
}
|
||||
|
||||
void PrimitiveTypes_struct_w_iptr(void) {
|
||||
STRUCT_W_PRIMITIVE_TEST(ecs_iptr_t)
|
||||
}
|
||||
|
||||
void PrimitiveTypes_struct_w_u8(void) {
|
||||
STRUCT_W_PRIMITIVE_TEST(ecs_u8_t)
|
||||
}
|
||||
|
||||
void PrimitiveTypes_struct_w_u16(void) {
|
||||
STRUCT_W_PRIMITIVE_TEST(ecs_u16_t)
|
||||
}
|
||||
|
||||
void PrimitiveTypes_struct_w_u32(void) {
|
||||
STRUCT_W_PRIMITIVE_TEST(ecs_u32_t)
|
||||
}
|
||||
|
||||
void PrimitiveTypes_struct_w_u64(void) {
|
||||
STRUCT_W_PRIMITIVE_TEST(ecs_u64_t)
|
||||
}
|
||||
|
||||
void PrimitiveTypes_struct_w_uptr(void) {
|
||||
STRUCT_W_PRIMITIVE_TEST(ecs_uptr_t)
|
||||
}
|
||||
|
||||
void PrimitiveTypes_struct_w_float(void) {
|
||||
STRUCT_W_PRIMITIVE_TEST(ecs_f32_t)
|
||||
}
|
||||
|
||||
void PrimitiveTypes_struct_w_double(void) {
|
||||
STRUCT_W_PRIMITIVE_TEST(ecs_f64_t)
|
||||
}
|
||||
|
||||
void PrimitiveTypes_struct_w_string(void) {
|
||||
STRUCT_W_PRIMITIVE_TEST(ecs_string_t)
|
||||
}
|
||||
|
||||
void PrimitiveTypes_struct_w_entity(void) {
|
||||
STRUCT_W_PRIMITIVE_TEST(ecs_entity_t)
|
||||
}
|
||||
|
||||
void PrimitiveTypes_primitive_init(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_primitive_init(world, &(ecs_primitive_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.kind = EcsU16
|
||||
});
|
||||
test_assert(t != 0);
|
||||
|
||||
test_str(ecs_get_name(world, t),"T");
|
||||
|
||||
const EcsPrimitive *prim_ptr = ecs_get(world, t, EcsPrimitive);
|
||||
test_assert(prim_ptr != NULL);
|
||||
test_int(prim_ptr->kind, EcsU16);
|
||||
|
||||
const EcsMetaType *type_ptr = ecs_get(world, t, EcsMetaType);
|
||||
test_assert(type_ptr != NULL);
|
||||
test_int(type_ptr->kind, EcsPrimitiveType);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void PrimitiveTypes_primitive_w_short_notation(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_primitive(world, {
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.kind = EcsU16
|
||||
});
|
||||
test_assert(t != 0);
|
||||
|
||||
test_str(ecs_get_name(world, t),"T");
|
||||
|
||||
const EcsPrimitive *prim_ptr = ecs_get(world, t, EcsPrimitive);
|
||||
test_assert(prim_ptr != NULL);
|
||||
test_int(prim_ptr->kind, EcsU16);
|
||||
|
||||
const EcsMetaType *type_ptr = ecs_get(world, t, EcsMetaType);
|
||||
test_assert(type_ptr != NULL);
|
||||
test_int(type_ptr->kind, EcsPrimitiveType);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
1637
engine/libs/flecs/test/meta/src/SerializeEntityToJson.c
Normal file
1637
engine/libs/flecs/test/meta/src/SerializeEntityToJson.c
Normal file
File diff suppressed because it is too large
Load Diff
2814
engine/libs/flecs/test/meta/src/SerializeIterToJson.c
Normal file
2814
engine/libs/flecs/test/meta/src/SerializeIterToJson.c
Normal file
File diff suppressed because it is too large
Load Diff
1522
engine/libs/flecs/test/meta/src/SerializeToExpr.c
Normal file
1522
engine/libs/flecs/test/meta/src/SerializeToExpr.c
Normal file
File diff suppressed because it is too large
Load Diff
1232
engine/libs/flecs/test/meta/src/SerializeToJson.c
Normal file
1232
engine/libs/flecs/test/meta/src/SerializeToJson.c
Normal file
File diff suppressed because it is too large
Load Diff
668
engine/libs/flecs/test/meta/src/SerializeTypeInfoToJson.c
Normal file
668
engine/libs/flecs/test/meta/src/SerializeTypeInfoToJson.c
Normal file
@@ -0,0 +1,668 @@
|
||||
#include <meta.h>
|
||||
|
||||
void SerializeTypeInfoToJson_bool(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
char *str = ecs_type_info_to_json(world, ecs_id(ecs_bool_t));
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"bool\"]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_byte(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
char *str = ecs_type_info_to_json(world, ecs_id(ecs_byte_t));
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"byte\"]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_char(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
char *str = ecs_type_info_to_json(world, ecs_id(ecs_char_t));
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"text\"]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_i8(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
char *str = ecs_type_info_to_json(world, ecs_id(ecs_i8_t));
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"int\"]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_i16(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
char *str = ecs_type_info_to_json(world, ecs_id(ecs_i16_t));
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"int\"]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_i32(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
char *str = ecs_type_info_to_json(world, ecs_id(ecs_i32_t));
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"int\"]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_i64(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
char *str = ecs_type_info_to_json(world, ecs_id(ecs_i64_t));
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"int\"]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_iptr(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
char *str = ecs_type_info_to_json(world, ecs_id(ecs_iptr_t));
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"int\"]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_u8(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
char *str = ecs_type_info_to_json(world, ecs_id(ecs_u8_t));
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"int\"]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_u16(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
char *str = ecs_type_info_to_json(world, ecs_id(ecs_u16_t));
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"int\"]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_u32(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
char *str = ecs_type_info_to_json(world, ecs_id(ecs_u32_t));
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"int\"]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_u64(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
char *str = ecs_type_info_to_json(world, ecs_id(ecs_u64_t));
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"int\"]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_uptr(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
char *str = ecs_type_info_to_json(world, ecs_id(ecs_uptr_t));
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"int\"]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_float(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
char *str = ecs_type_info_to_json(world, ecs_id(ecs_f32_t));
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"float\"]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_double(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
char *str = ecs_type_info_to_json(world, ecs_id(ecs_f64_t));
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"float\"]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_string(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
char *str = ecs_type_info_to_json(world, ecs_id(ecs_string_t));
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"text\"]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_entity(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
char *str = ecs_type_info_to_json(world, ecs_id(ecs_entity_t));
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"entity\"]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_enum(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t e = ecs_enum_init(world, &(ecs_enum_desc_t){
|
||||
.constants = {
|
||||
{"Red"}, {"Blue"}, {"Green"}
|
||||
}
|
||||
});
|
||||
|
||||
char *str = ecs_type_info_to_json(world, e);
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"enum\", \"Red\", \"Blue\", \"Green\"]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_bitmask(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t b = ecs_bitmask_init(world, &(ecs_bitmask_desc_t){
|
||||
.constants = {
|
||||
{"Red"}, {"Blue"}, {"Green"}
|
||||
}
|
||||
});
|
||||
|
||||
char *str = ecs_type_info_to_json(world, b);
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"bitmask\", \"Red\", \"Blue\", \"Green\"]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_struct(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_f32_t)},
|
||||
{"y", ecs_id(ecs_f32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
char *str = ecs_type_info_to_json(world, t);
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "{\"x\":[\"float\"], \"y\":[\"float\"]}");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_nested_struct(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_f32_t)},
|
||||
{"y", ecs_id(ecs_f32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
ecs_entity_t l = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.members = {
|
||||
{"start", t},
|
||||
{"stop", t}
|
||||
}
|
||||
});
|
||||
|
||||
char *str = ecs_type_info_to_json(world, l);
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "{\"start\":{\"x\":[\"float\"], \"y\":[\"float\"]}, \"stop\":{\"x\":[\"float\"], \"y\":[\"float\"]}}");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_array_type(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t at = ecs_array(world, {
|
||||
.type = ecs_id(ecs_i32_t),
|
||||
.count = 3
|
||||
});
|
||||
|
||||
char *str = ecs_type_info_to_json(world, at);
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"array\", [\"int\"], 3]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_vector_type(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t at = ecs_vector(world, {
|
||||
.type = ecs_id(ecs_i32_t)
|
||||
});
|
||||
|
||||
char *str = ecs_type_info_to_json(world, at);
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"vector\", [\"int\"]]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_struct_array_i32_2(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"a", ecs_id(ecs_i32_t), 2}
|
||||
}
|
||||
});
|
||||
|
||||
char *str = ecs_type_info_to_json(world, t);
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "{\"a\":[\"array\", [\"int\"], 2]}");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_struct_array_struct_2(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t u = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "U"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"a", u, 2}
|
||||
}
|
||||
});
|
||||
|
||||
char *str = ecs_type_info_to_json(world, t);
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "{\"a\":[\"array\", {\"x\":[\"int\"]}, 2]}");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_struct_array_type(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t a = ecs_array_init(world, &(ecs_array_desc_t){
|
||||
.type = ecs_id(ecs_i32_t),
|
||||
.count = 3
|
||||
});
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"a", a}
|
||||
}
|
||||
});
|
||||
|
||||
char *str = ecs_type_info_to_json(world, t);
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "{\"a\":[\"array\", [\"int\"], 3]}");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_struct_vector_type(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t a = ecs_vector_init(world, &(ecs_vector_desc_t){
|
||||
.type = ecs_id(ecs_i32_t)
|
||||
});
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"a", a}
|
||||
}
|
||||
});
|
||||
|
||||
char *str = ecs_type_info_to_json(world, t);
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "{\"a\":[\"vector\", [\"int\"]]}");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
static
|
||||
int DummySerialize(const ecs_serializer_t *s, const void *ptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_custom_primitive_type(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t ct = ecs_opaque(world, {
|
||||
.entity = ecs_component(world, {
|
||||
.type.size = 4,
|
||||
.type.alignment = 4
|
||||
}),
|
||||
.type.as_type = ecs_id(ecs_i32_t),
|
||||
.type.serialize = DummySerialize
|
||||
});
|
||||
|
||||
char *str = ecs_type_info_to_json(world, ct);
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"int\"]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_custom_array_type(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t at = ecs_array(world, {
|
||||
.type = ecs_id(ecs_i32_t),
|
||||
.count = 3
|
||||
});
|
||||
|
||||
char *str = ecs_type_info_to_json(world, at);
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"array\", [\"int\"], 3]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_custom_vector_type(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t ct = ecs_opaque(world, {
|
||||
.entity = ecs_component(world, {
|
||||
.type.size = 4,
|
||||
.type.alignment = 4
|
||||
}),
|
||||
.type.as_type = ecs_vector(world, {
|
||||
.type = ecs_id(ecs_i32_t)
|
||||
}),
|
||||
.type.serialize = DummySerialize
|
||||
});
|
||||
|
||||
char *str = ecs_type_info_to_json(world, ct);
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "[\"vector\", [\"int\"]]");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_custom_struct_type(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t s = ecs_struct(world, {
|
||||
.members = {
|
||||
{ "x", ecs_id(ecs_i32_t) },
|
||||
{ "y", ecs_id(ecs_i32_t) }
|
||||
}
|
||||
});
|
||||
|
||||
ecs_entity_t ct = ecs_opaque(world, {
|
||||
.entity = ecs_component(world, {
|
||||
.type.size = 4,
|
||||
.type.alignment = 4
|
||||
}),
|
||||
.type.as_type = s,
|
||||
.type.serialize = DummySerialize
|
||||
});
|
||||
|
||||
char *str = ecs_type_info_to_json(world, ct);
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "{\"x\":[\"int\"], \"y\":[\"int\"]}");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_struct_w_value_range(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t s = ecs_struct(world, {
|
||||
.members = {
|
||||
{ "value", ecs_id(ecs_i32_t), .range = {-1, 1} }
|
||||
}
|
||||
});
|
||||
|
||||
char *str = ecs_type_info_to_json(world, s);
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "{\"value\":[\"int\", {\"range\":[-1, 1]}]}");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_struct_w_error_range(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t s = ecs_struct(world, {
|
||||
.members = {
|
||||
{ "value", ecs_id(ecs_i32_t), .error_range = {-1, 1} }
|
||||
}
|
||||
});
|
||||
|
||||
char *str = ecs_type_info_to_json(world, s);
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "{\"value\":[\"int\", {\"error_range\":[-1, 1]}]}");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_struct_w_warning_range(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t s = ecs_struct(world, {
|
||||
.members = {
|
||||
{ "value", ecs_id(ecs_i32_t), .warning_range = {-1, 1} }
|
||||
}
|
||||
});
|
||||
|
||||
char *str = ecs_type_info_to_json(world, s);
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "{\"value\":[\"int\", {\"warning_range\":[-1, 1]}]}");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_struct_w_error_and_warning_range(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t s = ecs_struct(world, {
|
||||
.members = {
|
||||
{ "value", ecs_id(ecs_i32_t),
|
||||
.warning_range = {-1, 1},
|
||||
.error_range = {-2, 2}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
char *str = ecs_type_info_to_json(world, s);
|
||||
test_assert(str != NULL);
|
||||
test_str(str, "{\"value\":[\"int\", {\"error_range\":[-2, 2],"
|
||||
" \"warning_range\":[-1, 1]}]}");
|
||||
ecs_os_free(str);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_struct_nested(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t s = ecs_struct(world, {
|
||||
.members = {
|
||||
{ "x", ecs_id(ecs_i32_t) },
|
||||
{ "y", ecs_id(ecs_i32_t) }
|
||||
}
|
||||
});
|
||||
|
||||
ecs_entity_t n = ecs_struct(world, {
|
||||
.members = {
|
||||
{ "one", s }
|
||||
}
|
||||
});
|
||||
|
||||
char *ti = ecs_type_info_to_json(world, n);
|
||||
test_assert(ti != NULL);
|
||||
test_str(ti,
|
||||
"{\"one\":{\"x\":[\"int\"], \"y\":[\"int\"]}}"
|
||||
);
|
||||
ecs_os_free(ti);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_struct_nested_2_lvls(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t s = ecs_struct(world, {
|
||||
.members = {
|
||||
{ "a", ecs_id(ecs_i32_t) },
|
||||
{ "b", ecs_id(ecs_i32_t) },
|
||||
{ "c", ecs_id(ecs_i32_t) }
|
||||
}
|
||||
});
|
||||
|
||||
ecs_entity_t n_1 = ecs_struct(world, {
|
||||
.members = {
|
||||
{ "x", s },
|
||||
{ "y", s }
|
||||
}
|
||||
});
|
||||
|
||||
ecs_entity_t n_2 = ecs_struct(world, {
|
||||
.members = {
|
||||
{ "one", n_1 }
|
||||
}
|
||||
});
|
||||
|
||||
char *ti = ecs_type_info_to_json(world, n_2);
|
||||
test_assert(ti != NULL);
|
||||
test_str(ti,
|
||||
"{\"one\":{"
|
||||
"\"x\":{\"a\":[\"int\"], \"b\":[\"int\"], \"c\":[\"int\"]}, "
|
||||
"\"y\":{\"a\":[\"int\"], \"b\":[\"int\"], \"c\":[\"int\"]}"
|
||||
"}}"
|
||||
);
|
||||
ecs_os_free(ti);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_struct_nested_2_members(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t s = ecs_struct(world, {
|
||||
.members = {
|
||||
{ "x", ecs_id(ecs_i32_t) },
|
||||
{ "y", ecs_id(ecs_i32_t) }
|
||||
}
|
||||
});
|
||||
|
||||
ecs_entity_t n = ecs_struct(world, {
|
||||
.members = {
|
||||
{ "one", s },
|
||||
{ "two", s },
|
||||
}
|
||||
});
|
||||
|
||||
char *ti = ecs_type_info_to_json(world, n);
|
||||
test_assert(ti != NULL);
|
||||
test_str(ti,
|
||||
"{\"one\":{\"x\":[\"int\"], \"y\":[\"int\"]}, \"two\":{\"x\":[\"int\"], \"y\":[\"int\"]}}"
|
||||
);
|
||||
ecs_os_free(ti);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void SerializeTypeInfoToJson_struct_nested_3_members(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t s = ecs_struct(world, {
|
||||
.members = {
|
||||
{ "x", ecs_id(ecs_i32_t) },
|
||||
{ "y", ecs_id(ecs_i32_t) }
|
||||
}
|
||||
});
|
||||
|
||||
ecs_entity_t n = ecs_struct(world, {
|
||||
.members = {
|
||||
{ "one", s },
|
||||
{ "two", ecs_id(ecs_i32_t) },
|
||||
{ "three", s },
|
||||
}
|
||||
});
|
||||
|
||||
char *ti = ecs_type_info_to_json(world, n);
|
||||
test_assert(ti != NULL);
|
||||
test_str(ti,
|
||||
"{"
|
||||
"\"one\":{\"x\":[\"int\"], \"y\":[\"int\"]}, "
|
||||
"\"two\":[\"int\"], "
|
||||
"\"three\":{\"x\":[\"int\"], \"y\":[\"int\"]}"
|
||||
"}"
|
||||
);
|
||||
ecs_os_free(ti);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
2129
engine/libs/flecs/test/meta/src/Serialized.c
Normal file
2129
engine/libs/flecs/test/meta/src/Serialized.c
Normal file
File diff suppressed because it is too large
Load Diff
822
engine/libs/flecs/test/meta/src/StructTypes.c
Normal file
822
engine/libs/flecs/test/meta/src/StructTypes.c
Normal file
@@ -0,0 +1,822 @@
|
||||
#include <meta.h>
|
||||
|
||||
void _meta_test_struct(
|
||||
ecs_world_t *world,
|
||||
ecs_entity_t t,
|
||||
ecs_size_t size,
|
||||
ecs_size_t alignment)
|
||||
{
|
||||
const EcsComponent *ct = ecs_get(world, t, EcsComponent);
|
||||
test_assert(ct != NULL);
|
||||
test_int(ct->size, size);
|
||||
test_int(ct->alignment, alignment);
|
||||
|
||||
const EcsMetaType *mt = ecs_get(world, t, EcsMetaType);
|
||||
test_assert(mt != NULL);
|
||||
test_assert(mt->kind == EcsStructType);
|
||||
}
|
||||
|
||||
void _meta_test_member(
|
||||
ecs_world_t *world,
|
||||
ecs_entity_t t,
|
||||
const char *name,
|
||||
ecs_entity_t type,
|
||||
int32_t elem_count,
|
||||
ecs_size_t offset)
|
||||
{
|
||||
ecs_entity_t m = ecs_lookup_child(world, t, name);
|
||||
test_assert(m != 0);
|
||||
test_assert(ecs_has(world, m, EcsMember));
|
||||
|
||||
const EcsMember *mptr = ecs_get(world, m, EcsMember);
|
||||
test_assert(mptr != NULL);
|
||||
test_assert(mptr->type == type);
|
||||
|
||||
const EcsStruct *sptr = ecs_get(world, t, EcsStruct);
|
||||
test_assert(sptr != NULL);
|
||||
|
||||
ecs_member_t *members = ecs_vec_first_t(&sptr->members, ecs_member_t);
|
||||
int i, count = ecs_vec_count(&sptr->members);
|
||||
|
||||
for (i = 0; i < count; i ++) {
|
||||
if (members[i].member == m) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Make sure member was found */
|
||||
test_assert(i != count);
|
||||
|
||||
test_str(members[i].name, name);
|
||||
test_assert(members[i].type == type);
|
||||
test_int(members[i].offset, offset);
|
||||
test_int(members[i].count, elem_count);
|
||||
}
|
||||
|
||||
void StructTypes_i32(void) {
|
||||
typedef struct {
|
||||
ecs_i32_t x;
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_i32_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_i32_i32(void) {
|
||||
typedef struct {
|
||||
ecs_i32_t x;
|
||||
ecs_i32_t y;
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t)},
|
||||
{"y", ecs_id(ecs_i32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_i32_t), 1);
|
||||
meta_test_member(world, t, T, y, ecs_id(ecs_i32_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_i32_i32_i32(void) {
|
||||
typedef struct {
|
||||
ecs_i32_t x;
|
||||
ecs_i32_t y;
|
||||
ecs_i32_t z;
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t)},
|
||||
{"y", ecs_id(ecs_i32_t)},
|
||||
{"z", ecs_id(ecs_i32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_i32_t), 1);
|
||||
meta_test_member(world, t, T, y, ecs_id(ecs_i32_t), 1);
|
||||
meta_test_member(world, t, T, z, ecs_id(ecs_i32_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_bool_i32(void) {
|
||||
typedef struct {
|
||||
ecs_bool_t x;
|
||||
ecs_i32_t y;
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_bool_t)},
|
||||
{"y", ecs_id(ecs_i32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_bool_t), 1);
|
||||
meta_test_member(world, t, T, y, ecs_id(ecs_i32_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_bool_bool_i32(void) {
|
||||
typedef struct {
|
||||
ecs_bool_t x;
|
||||
ecs_bool_t y;
|
||||
ecs_i32_t z;
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_bool_t)},
|
||||
{"y", ecs_id(ecs_bool_t)},
|
||||
{"z", ecs_id(ecs_i32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_bool_t), 1);
|
||||
meta_test_member(world, t, T, y, ecs_id(ecs_bool_t), 1);
|
||||
meta_test_member(world, t, T, z, ecs_id(ecs_i32_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_bool_i32_bool_i32(void) {
|
||||
typedef struct {
|
||||
ecs_bool_t x;
|
||||
ecs_i32_t y;
|
||||
ecs_bool_t z;
|
||||
ecs_i32_t w;
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_bool_t)},
|
||||
{"y", ecs_id(ecs_i32_t)},
|
||||
{"z", ecs_id(ecs_bool_t)},
|
||||
{"w", ecs_id(ecs_i32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_bool_t), 1);
|
||||
meta_test_member(world, t, T, y, ecs_id(ecs_i32_t), 1);
|
||||
meta_test_member(world, t, T, z, ecs_id(ecs_bool_t), 1);
|
||||
meta_test_member(world, t, T, w, ecs_id(ecs_i32_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_i32_bool(void) {
|
||||
typedef struct {
|
||||
ecs_i32_t x;
|
||||
ecs_bool_t y;
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t)},
|
||||
{"y", ecs_id(ecs_bool_t)}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_i32_t), 1);
|
||||
meta_test_member(world, t, T, y, ecs_id(ecs_bool_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_i32_bool_bool(void) {
|
||||
typedef struct {
|
||||
ecs_i32_t x;
|
||||
ecs_bool_t y;
|
||||
ecs_bool_t z;
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t)},
|
||||
{"y", ecs_id(ecs_bool_t)},
|
||||
{"z", ecs_id(ecs_bool_t)}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_i32_t), 1);
|
||||
meta_test_member(world, t, T, y, ecs_id(ecs_bool_t), 1);
|
||||
meta_test_member(world, t, T, z, ecs_id(ecs_bool_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_i32_bool_bool_bool(void) {
|
||||
typedef struct {
|
||||
ecs_i32_t x;
|
||||
ecs_bool_t y;
|
||||
ecs_bool_t z;
|
||||
ecs_bool_t w;
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t)},
|
||||
{"y", ecs_id(ecs_bool_t)},
|
||||
{"z", ecs_id(ecs_bool_t)},
|
||||
{"w", ecs_id(ecs_bool_t)}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_i32_t), 1);
|
||||
meta_test_member(world, t, T, y, ecs_id(ecs_bool_t), 1);
|
||||
meta_test_member(world, t, T, z, ecs_id(ecs_bool_t), 1);
|
||||
meta_test_member(world, t, T, w, ecs_id(ecs_bool_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_i32_i64(void) {
|
||||
typedef struct {
|
||||
ecs_i32_t x;
|
||||
ecs_i64_t y;
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t)},
|
||||
{"y", ecs_id(ecs_i64_t)}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_i32_t), 1);
|
||||
meta_test_member(world, t, T, y, ecs_id(ecs_i64_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_i32_i64_i32(void) {
|
||||
typedef struct {
|
||||
ecs_i32_t x;
|
||||
ecs_i64_t y;
|
||||
ecs_i32_t z;
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t)},
|
||||
{"y", ecs_id(ecs_i64_t)},
|
||||
{"z", ecs_id(ecs_i32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_i32_t), 1);
|
||||
meta_test_member(world, t, T, y, ecs_id(ecs_i64_t), 1);
|
||||
meta_test_member(world, t, T, z, ecs_id(ecs_i32_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_incomplete_member(void) {
|
||||
typedef struct {
|
||||
ecs_i32_t x;
|
||||
ecs_i32_t y;
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_new_id(world);
|
||||
|
||||
ecs_entity_t m_x = ecs_new_w_pair(world, EcsChildOf, t);
|
||||
ecs_set_name(world, m_x, "x");
|
||||
ecs_set(world, m_x, EcsMember, {.type = ecs_id(ecs_i32_t)});
|
||||
|
||||
ecs_entity_t m_y = ecs_new_w_pair(world, EcsChildOf, t);
|
||||
ecs_set_name(world, m_y, "y");
|
||||
ecs_set(world, m_y, EcsMember, {.type = ecs_id(ecs_i32_t)});
|
||||
|
||||
ecs_entity_t m_z = ecs_new_w_pair(world, EcsChildOf, t);
|
||||
ecs_set_name(world, m_z, "z");
|
||||
|
||||
ecs_log_set_level(-4);
|
||||
ecs_set(world, m_z, EcsMember, {.type = 0});
|
||||
|
||||
const EcsStruct *ptr = ecs_get(world, t, EcsStruct);
|
||||
test_assert(ptr != NULL);
|
||||
test_int(ecs_vec_count(&ptr->members), 2);
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_i32_t), 1);
|
||||
meta_test_member(world, t, T, y, ecs_id(ecs_i32_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_partial_type(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Position);
|
||||
|
||||
ecs_entity_t s = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_id(Position),
|
||||
.members = {{ .name = "x", .type = ecs_id(ecs_i32_t) }}
|
||||
});
|
||||
|
||||
test_assert(s == ecs_id(Position));
|
||||
|
||||
const EcsComponent *cptr = ecs_get(world, s, EcsComponent);
|
||||
test_assert(cptr != NULL);
|
||||
test_int(cptr->size, sizeof(Position));
|
||||
test_int(cptr->alignment, ECS_ALIGNOF(Position));
|
||||
|
||||
const EcsMetaType *mptr = ecs_get(world, s, EcsMetaType);
|
||||
test_assert(mptr != NULL);
|
||||
test_bool(mptr->partial, true);
|
||||
test_bool(mptr->existing, true);
|
||||
|
||||
meta_test_struct(world, s, Position);
|
||||
meta_test_member(world, s, Position, x, ecs_id(ecs_i32_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_partial_type_custom_offset(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Vec3);
|
||||
|
||||
ecs_entity_t s = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_id(Vec3),
|
||||
.members = {{
|
||||
.name = "y",
|
||||
.type = ecs_id(ecs_i32_t),
|
||||
.offset = offsetof(Vec3, y)
|
||||
}}
|
||||
});
|
||||
|
||||
test_assert(s == ecs_id(Vec3));
|
||||
|
||||
const EcsComponent *cptr = ecs_get(world, s, EcsComponent);
|
||||
test_assert(cptr != NULL);
|
||||
test_int(cptr->size, sizeof(Vec3));
|
||||
test_int(cptr->alignment, ECS_ALIGNOF(Vec3));
|
||||
|
||||
const EcsMetaType *mptr = ecs_get(world, s, EcsMetaType);
|
||||
test_assert(mptr != NULL);
|
||||
test_bool(mptr->partial, true);
|
||||
test_bool(mptr->existing, true);
|
||||
|
||||
meta_test_struct(world, s, Vec3);
|
||||
meta_test_member(world, s, Vec3, y, ecs_id(ecs_i32_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_struct_w_short_notation(void) {
|
||||
typedef struct {
|
||||
ecs_i32_t x;
|
||||
ecs_i32_t y;
|
||||
ecs_i32_t z;
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct(world, {
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t)},
|
||||
{"y", ecs_id(ecs_i32_t)},
|
||||
{"z", ecs_id(ecs_i32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_i32_t), 1);
|
||||
meta_test_member(world, t, T, y, ecs_id(ecs_i32_t), 1);
|
||||
meta_test_member(world, t, T, z, ecs_id(ecs_i32_t), 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_value_range(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Position);
|
||||
|
||||
ecs_entity_t s = ecs_struct(world, {
|
||||
.entity = ecs_id(Position),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_f32_t), .range = {-1, 1}},
|
||||
{"y", ecs_id(ecs_f32_t), .range = {-2, 2}}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(s == ecs_id(Position));
|
||||
|
||||
ecs_entity_t x = ecs_lookup_fullpath(world, "Position.x");
|
||||
test_assert(x != 0);
|
||||
ecs_entity_t y = ecs_lookup_fullpath(world, "Position.y");
|
||||
test_assert(y != 0);
|
||||
|
||||
const EcsMemberRanges *xr = ecs_get(world, x, EcsMemberRanges);
|
||||
test_assert(xr != NULL);
|
||||
test_int(xr->value.min, -1);
|
||||
test_int(xr->value.max, 1);
|
||||
test_int(xr->warning.min, 0);
|
||||
test_int(xr->warning.max, 0);
|
||||
test_int(xr->error.min, 0);
|
||||
test_int(xr->error.max, 0);
|
||||
|
||||
const EcsMemberRanges *yr = ecs_get(world, y, EcsMemberRanges);
|
||||
test_assert(yr != NULL);
|
||||
test_int(yr->value.min, -2);
|
||||
test_int(yr->value.max, 2);
|
||||
test_int(xr->warning.min, 0);
|
||||
test_int(xr->warning.max, 0);
|
||||
test_int(xr->error.min, 0);
|
||||
test_int(xr->error.max, 0);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_error_range(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Position);
|
||||
|
||||
ecs_entity_t s = ecs_struct(world, {
|
||||
.entity = ecs_id(Position),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_f32_t), .error_range = {-1, 1}},
|
||||
{"y", ecs_id(ecs_f32_t), .error_range = {-2, 2}}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(s == ecs_id(Position));
|
||||
|
||||
ecs_entity_t x = ecs_lookup_fullpath(world, "Position.x");
|
||||
test_assert(x != 0);
|
||||
ecs_entity_t y = ecs_lookup_fullpath(world, "Position.y");
|
||||
test_assert(y != 0);
|
||||
|
||||
const EcsMemberRanges *xr = ecs_get(world, x, EcsMemberRanges);
|
||||
test_assert(xr != NULL);
|
||||
test_int(xr->error.min, -1);
|
||||
test_int(xr->error.max, 1);
|
||||
test_int(xr->warning.min, 0);
|
||||
test_int(xr->warning.max, 0);
|
||||
|
||||
const EcsMemberRanges *yr = ecs_get(world, y, EcsMemberRanges);
|
||||
test_assert(yr != NULL);
|
||||
test_int(yr->error.min, -2);
|
||||
test_int(yr->error.max, 2);
|
||||
test_int(yr->warning.min, 0);
|
||||
test_int(yr->warning.max, 0);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_warning_range(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Position);
|
||||
|
||||
ecs_entity_t s = ecs_struct(world, {
|
||||
.entity = ecs_id(Position),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_f32_t), .warning_range = {-1, 1}},
|
||||
{"y", ecs_id(ecs_f32_t), .warning_range = {-2, 2}}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(s == ecs_id(Position));
|
||||
|
||||
ecs_entity_t x = ecs_lookup_fullpath(world, "Position.x");
|
||||
test_assert(x != 0);
|
||||
ecs_entity_t y = ecs_lookup_fullpath(world, "Position.y");
|
||||
test_assert(y != 0);
|
||||
|
||||
const EcsMemberRanges *xr = ecs_get(world, x, EcsMemberRanges);
|
||||
test_assert(xr != NULL);
|
||||
test_int(xr->warning.min, -1);
|
||||
test_int(xr->warning.max, 1);
|
||||
test_int(xr->error.min, 0);
|
||||
test_int(xr->error.max, 0);
|
||||
|
||||
const EcsMemberRanges *yr = ecs_get(world, y, EcsMemberRanges);
|
||||
test_assert(yr != NULL);
|
||||
test_int(yr->warning.min, -2);
|
||||
test_int(yr->warning.max, 2);
|
||||
test_int(yr->error.min, 0);
|
||||
test_int(yr->error.max, 0);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_error_and_warning_range(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Position);
|
||||
|
||||
ecs_entity_t s = ecs_struct(world, {
|
||||
.entity = ecs_id(Position),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_f32_t), .error_range = {-2, 2}, .warning_range = {-1, 1}},
|
||||
{"y", ecs_id(ecs_f32_t), .error_range = {-4, 4}, .warning_range = {-2, 2}}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(s == ecs_id(Position));
|
||||
|
||||
ecs_entity_t x = ecs_lookup_fullpath(world, "Position.x");
|
||||
test_assert(x != 0);
|
||||
ecs_entity_t y = ecs_lookup_fullpath(world, "Position.y");
|
||||
test_assert(y != 0);
|
||||
|
||||
const EcsMemberRanges *xr = ecs_get(world, x, EcsMemberRanges);
|
||||
test_assert(xr != NULL);
|
||||
test_int(xr->error.min, -2);
|
||||
test_int(xr->error.max, 2);
|
||||
test_int(xr->warning.min, -1);
|
||||
test_int(xr->warning.max, 1);
|
||||
|
||||
const EcsMemberRanges *yr = ecs_get(world, y, EcsMemberRanges);
|
||||
test_assert(yr != NULL);
|
||||
test_int(yr->error.min, -4);
|
||||
test_int(yr->error.max, 4);
|
||||
test_int(yr->warning.min, -2);
|
||||
test_int(yr->warning.max, 2);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_error_range_invalid_type(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Position);
|
||||
|
||||
ecs_log_set_level(-4);
|
||||
ecs_entity_t s = ecs_struct(world, {
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_string_t), .error_range = {-1, 1}},
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(s == 0);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_warning_range_invalid_type(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Position);
|
||||
|
||||
ecs_log_set_level(-4);
|
||||
ecs_entity_t s = ecs_struct(world, {
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_string_t), .warning_range = {-1, 1}},
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(s == 0);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_invalid_value_range(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Position);
|
||||
|
||||
ecs_log_set_level(-4);
|
||||
ecs_entity_t s = ecs_struct(world, {
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t), .range = {1, -1}},
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(s == 0);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_invalid_error_range(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Position);
|
||||
|
||||
ecs_log_set_level(-4);
|
||||
ecs_entity_t s = ecs_struct(world, {
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t), .error_range = {1, -1}},
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(s == 0);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_invalid_warning_range(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Position);
|
||||
|
||||
ecs_log_set_level(-4);
|
||||
ecs_entity_t s = ecs_struct(world, {
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t), .warning_range = {1, -1}},
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(s == 0);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_overlapping_error_warning_range(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Position);
|
||||
|
||||
ecs_log_set_level(-4);
|
||||
ecs_entity_t s = ecs_struct(world, {
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t), .error_range = {-1, 1}, .warning_range = {-2, 2}},
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(s == 0);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_overlapping_value_error_range(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Position);
|
||||
|
||||
ecs_log_set_level(-4);
|
||||
ecs_entity_t s = ecs_struct(world, {
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t), .range = {-1, 1}, .error_range = {-2, 2}},
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(s == 0);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_overlapping_value_warning_range(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, Position);
|
||||
|
||||
ecs_log_set_level(-4);
|
||||
ecs_entity_t s = ecs_struct(world, {
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t), .range = {-1, 1}, .warning_range = {-2, 2}},
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(s == 0);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void StructTypes_struct_w_16_alignment(void) {
|
||||
#ifndef _MSC_VER
|
||||
typedef __attribute((aligned(16)))
|
||||
#else
|
||||
typedef __declspec(align(16))
|
||||
#endif
|
||||
struct T {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float w;
|
||||
} T;
|
||||
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_COMPONENT(world, T);
|
||||
|
||||
ecs_entity_t t = ecs_struct(world, {
|
||||
.entity = ecs_id(T),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_f32_t)},
|
||||
{"y", ecs_id(ecs_f32_t)},
|
||||
{"z", ecs_id(ecs_f32_t)},
|
||||
{"w", ecs_id(ecs_f32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
test_str(ecs_get_name(world, t), "T");
|
||||
|
||||
meta_test_struct(world, t, T);
|
||||
meta_test_member(world, t, T, x, ecs_id(ecs_f32_t), 1);
|
||||
meta_test_member(world, t, T, y, ecs_id(ecs_f32_t), 1);
|
||||
meta_test_member(world, t, T, z, ecs_id(ecs_f32_t), 1);
|
||||
meta_test_member(world, t, T, w, ecs_id(ecs_f32_t), 1);
|
||||
|
||||
const EcsComponent *cptr = ecs_get(world, t, EcsComponent);
|
||||
test_assert(cptr != NULL);
|
||||
test_int(cptr->size, sizeof(T));
|
||||
test_int(cptr->alignment, 16);
|
||||
|
||||
const EcsMetaType *mptr = ecs_get(world, t, EcsMetaType);
|
||||
test_assert(mptr != NULL);
|
||||
test_bool(mptr->partial, false);
|
||||
test_bool(mptr->existing, true);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
914
engine/libs/flecs/test/meta/src/Units.c
Normal file
914
engine/libs/flecs/test/meta/src/Units.c
Normal file
@@ -0,0 +1,914 @@
|
||||
#include <meta.h>
|
||||
|
||||
void Units_member_w_unit(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t u = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "percentage"}),
|
||||
.symbol = "%"
|
||||
});
|
||||
test_assert(u != 0);
|
||||
test_str("percentage", ecs_get_name(world, u));
|
||||
test_assert(ecs_has(world, u, EcsUnit));
|
||||
|
||||
const EcsUnit *uptr = ecs_get(world, u, EcsUnit);
|
||||
test_assert(uptr != NULL);
|
||||
test_str(uptr->symbol, "%");
|
||||
|
||||
ecs_entity_t s = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.members = {
|
||||
{ .name = "value", .type = ecs_id(ecs_f32_t), .unit = u }
|
||||
}
|
||||
});
|
||||
test_assert(s != 0);
|
||||
|
||||
const EcsStruct *sptr = ecs_get(world, s, EcsStruct);
|
||||
test_assert(sptr != NULL);
|
||||
test_int(1, ecs_vec_count(&sptr->members));
|
||||
ecs_member_t *members = ecs_vec_first_t(&sptr->members, ecs_member_t);
|
||||
test_str(members[0].name, "value");
|
||||
test_uint(members[0].type, ecs_id(ecs_f32_t));
|
||||
test_uint(members[0].unit, u);
|
||||
test_int(members[0].count, 1);
|
||||
|
||||
ecs_entity_t m = ecs_lookup_child(world, s, "value");
|
||||
test_assert(m != 0);
|
||||
|
||||
const EcsMember *mptr = ecs_get(world, m, EcsMember);
|
||||
test_assert(mptr != NULL);
|
||||
test_assert(mptr->type == ecs_id(ecs_f32_t));
|
||||
test_assert(mptr->unit == u);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_member_w_unit_type(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t u = ecs_primitive_init(world, &(ecs_primitive_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "percentage"}),
|
||||
.kind = EcsF32
|
||||
});
|
||||
test_assert(u != 0);
|
||||
test_str("percentage", ecs_get_name(world, u));
|
||||
test_assert(ecs_has(world, u, EcsMetaType));
|
||||
|
||||
ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = u,
|
||||
.symbol = "%"
|
||||
});
|
||||
test_assert(u != 0);
|
||||
test_assert(ecs_has(world, u, EcsUnit));
|
||||
|
||||
const EcsUnit *uptr = ecs_get(world, u, EcsUnit);
|
||||
test_assert(uptr != NULL);
|
||||
test_str(uptr->symbol, "%");
|
||||
|
||||
ecs_entity_t s = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.members = {
|
||||
{ .name = "value", .type = u }
|
||||
}
|
||||
});
|
||||
test_assert(s != 0);
|
||||
|
||||
const EcsStruct *sptr = ecs_get(world, s, EcsStruct);
|
||||
test_assert(sptr != NULL);
|
||||
test_int(1, ecs_vec_count(&sptr->members));
|
||||
ecs_member_t *members = ecs_vec_first_t(&sptr->members, ecs_member_t);
|
||||
test_str(members[0].name, "value");
|
||||
test_uint(members[0].type, u);
|
||||
test_uint(members[0].unit, u);
|
||||
test_int(members[0].count, 1);
|
||||
|
||||
ecs_entity_t m = ecs_lookup_child(world, s, "value");
|
||||
test_assert(m != 0);
|
||||
|
||||
const EcsMember *mptr = ecs_get(world, m, EcsMember);
|
||||
test_assert(mptr != NULL);
|
||||
test_assert(mptr->type == u);
|
||||
test_assert(mptr->unit == u);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_cursor_get_unit(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t u = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "percentage"}),
|
||||
.symbol = "%"
|
||||
});
|
||||
|
||||
ecs_entity_t s = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "s"}),
|
||||
.members = {
|
||||
{ .name = "value", .type = ecs_id(ecs_f32_t), .unit = u }
|
||||
}
|
||||
});
|
||||
|
||||
ecs_entity_t e = ecs_new_id(world);
|
||||
void *ptr = ecs_get_mut_id(world, e, s);
|
||||
test_assert(ptr != NULL);
|
||||
|
||||
ecs_meta_cursor_t cur = ecs_meta_cursor(world, s, ptr);
|
||||
test_int(0, ecs_meta_push(&cur));
|
||||
test_str("value", ecs_meta_get_member(&cur));
|
||||
test_uint(ecs_id(ecs_f32_t), ecs_meta_get_type(&cur));
|
||||
test_uint(u, ecs_meta_get_unit(&cur));
|
||||
test_int(0, ecs_meta_pop(&cur));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_cursor_get_unit_type(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t u = ecs_primitive_init(world, &(ecs_primitive_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "percentage"}),
|
||||
.kind = EcsF32
|
||||
});
|
||||
|
||||
ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = u,
|
||||
.symbol = "%"
|
||||
});
|
||||
|
||||
ecs_entity_t s = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.members = {
|
||||
{ .name = "value", .type = u }
|
||||
}
|
||||
});
|
||||
|
||||
ecs_entity_t e = ecs_new_id(world);
|
||||
void *ptr = ecs_get_mut_id(world, e, s);
|
||||
test_assert(ptr != NULL);
|
||||
|
||||
ecs_meta_cursor_t cur = ecs_meta_cursor(world, s, ptr);
|
||||
test_int(0, ecs_meta_push(&cur));
|
||||
test_str("value", ecs_meta_get_member(&cur));
|
||||
test_uint(u, ecs_meta_get_type(&cur));
|
||||
test_uint(u, ecs_meta_get_unit(&cur));
|
||||
test_int(0, ecs_meta_pop(&cur));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_unit_w_quantity(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t q = ecs_quantity_init(world, &(ecs_entity_desc_t){
|
||||
.name = "duration"
|
||||
});
|
||||
test_assert(q != 0);
|
||||
test_str("duration", ecs_get_name(world, q));
|
||||
test_assert(ecs_has_id(world, q, EcsQuantity));
|
||||
|
||||
ecs_entity_t u = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "seconds"}),
|
||||
.symbol = "s",
|
||||
.quantity = q
|
||||
});
|
||||
test_assert(u != 0);
|
||||
test_assert(ecs_has(world, u, EcsUnit));
|
||||
|
||||
const EcsUnit *uptr = ecs_get(world, u, EcsUnit);
|
||||
test_assert(uptr != NULL);
|
||||
test_str(uptr->symbol, "s");
|
||||
test_assert(ecs_has_pair(world, u, EcsQuantity, q));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_unit_w_self_quantity(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t q = ecs_quantity_init(world, &(ecs_entity_desc_t){
|
||||
.name = "percentage"
|
||||
});
|
||||
test_assert(q != 0);
|
||||
test_str("percentage", ecs_get_name(world, q));
|
||||
test_assert(ecs_has_id(world, q, EcsQuantity));
|
||||
|
||||
ecs_entity_t u = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = q,
|
||||
.symbol = "%"
|
||||
});
|
||||
test_assert(u != 0);
|
||||
test_assert(u == q);
|
||||
test_assert(ecs_has(world, u, EcsUnit));
|
||||
|
||||
const EcsUnit *uptr = ecs_get(world, u, EcsUnit);
|
||||
test_assert(uptr != NULL);
|
||||
test_str(uptr->symbol, "%");
|
||||
test_assert(ecs_has_pair(world, u, EcsQuantity, u));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_unit_w_self_quantity_after_init(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t u = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "percentage"}),
|
||||
.symbol = "%"
|
||||
});
|
||||
test_assert(u != 0);
|
||||
test_str("percentage", ecs_get_name(world, u));
|
||||
test_assert(ecs_has(world, u, EcsUnit));
|
||||
|
||||
const EcsUnit *uptr = ecs_get(world, u, EcsUnit);
|
||||
test_assert(uptr != NULL);
|
||||
test_str(uptr->symbol, "%");
|
||||
|
||||
ecs_entity_t q = ecs_quantity_init(world, &(ecs_entity_desc_t){
|
||||
.id = u
|
||||
});
|
||||
test_assert(q != 0);
|
||||
test_assert(q == u);
|
||||
test_assert(ecs_has_id(world, q, EcsQuantity));
|
||||
|
||||
test_assert(ecs_has_pair(world, u, EcsQuantity, u));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_unit_w_derived(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t u_1 = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "seconds"}),
|
||||
.symbol = "s"
|
||||
});
|
||||
test_assert(u_1 != 0);
|
||||
test_assert(ecs_has(world, u_1, EcsUnit));
|
||||
|
||||
ecs_entity_t u_2 = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "minutes"}),
|
||||
.symbol = "m",
|
||||
.base = u_1
|
||||
});
|
||||
test_assert(u_2 != 0);
|
||||
test_assert(ecs_has(world, u_2, EcsUnit));
|
||||
|
||||
const EcsUnit *uptr = ecs_get(world, u_1, EcsUnit);
|
||||
test_assert(uptr != NULL);
|
||||
test_str(uptr->symbol, "s");
|
||||
|
||||
uptr = ecs_get(world, u_2, EcsUnit);
|
||||
test_assert(uptr != NULL);
|
||||
test_str(uptr->symbol, "m");
|
||||
test_uint(uptr->base, u_1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_unit_w_prefix(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t u_1 = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "meters"}),
|
||||
.symbol = "m"
|
||||
});
|
||||
test_assert(u_1 != 0);
|
||||
test_assert(ecs_has(world, u_1, EcsUnit));
|
||||
|
||||
ecs_entity_t kilo = ecs_unit_prefix_init(world, &(ecs_unit_prefix_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "kilo"}),
|
||||
.symbol = "k",
|
||||
.translation = {
|
||||
.factor = 1000,
|
||||
.power = 1
|
||||
}
|
||||
});
|
||||
test_assert(kilo != 0);
|
||||
test_assert(ecs_has(world, kilo, EcsUnitPrefix));
|
||||
|
||||
ecs_entity_t u_2 = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "kilometers"}),
|
||||
.base = u_1,
|
||||
.prefix = kilo
|
||||
});
|
||||
test_assert(u_2 != 0);
|
||||
test_assert(ecs_has(world, u_2, EcsUnit));
|
||||
|
||||
const EcsUnit *uptr = ecs_get(world, u_1, EcsUnit);
|
||||
test_assert(uptr != NULL);
|
||||
test_str(uptr->symbol, "m");
|
||||
|
||||
uptr = ecs_get(world, u_2, EcsUnit);
|
||||
test_assert(uptr != NULL);
|
||||
test_str(uptr->symbol, "km");
|
||||
test_uint(uptr->base, u_1);
|
||||
test_uint(uptr->prefix, kilo);
|
||||
test_int(uptr->translation.factor, 1000);
|
||||
test_int(uptr->translation.power, 1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_unit_w_over(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t u_1 = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "seconds"}),
|
||||
.symbol = "s"
|
||||
});
|
||||
test_assert(u_1 != 0);
|
||||
test_assert(ecs_has(world, u_1, EcsUnit));
|
||||
|
||||
ecs_entity_t u_2 = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "meters"}),
|
||||
.symbol = "m"
|
||||
});
|
||||
test_assert(u_2 != 0);
|
||||
test_assert(ecs_has(world, u_2, EcsUnit));
|
||||
|
||||
ecs_entity_t u_3 = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "meters_per_second"}),
|
||||
.base = u_2,
|
||||
.over = u_1
|
||||
});
|
||||
test_assert(u_3 != 0);
|
||||
test_assert(ecs_has(world, u_3, EcsUnit));
|
||||
|
||||
const EcsUnit *uptr = ecs_get(world, u_1, EcsUnit);
|
||||
test_assert(uptr != NULL);
|
||||
test_str(uptr->symbol, "s");
|
||||
|
||||
uptr = ecs_get(world, u_2, EcsUnit);
|
||||
test_assert(uptr != NULL);
|
||||
test_str(uptr->symbol, "m");
|
||||
|
||||
uptr = ecs_get(world, u_3, EcsUnit);
|
||||
test_assert(uptr != NULL);
|
||||
test_str(uptr->symbol, "m/s");
|
||||
test_uint(uptr->base, u_2);
|
||||
test_uint(uptr->over, u_1);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_member_w_invalid_unit(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t u = ecs_new_id(world); /* not a unit */
|
||||
test_assert(u != 0);
|
||||
|
||||
ecs_log_set_level(-4);
|
||||
|
||||
ecs_entity_t s = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.members = {
|
||||
{ .name = "value", .type = ecs_id(ecs_f32_t), .unit = u }
|
||||
}
|
||||
});
|
||||
test_assert(s == 0);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_unit_w_invalid_quantity(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t q = ecs_new_id(world); /* not a quantity */
|
||||
test_assert(q != 0);
|
||||
|
||||
ecs_log_set_level(-4);
|
||||
|
||||
ecs_entity_t u = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "seconds"}),
|
||||
.symbol = "s",
|
||||
.quantity = q
|
||||
});
|
||||
test_assert(u == 0);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_unit_w_invalid_derived(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t u_1 = ecs_new_id(world); /* not a unit */
|
||||
test_assert(u_1 != 0);
|
||||
|
||||
ecs_log_set_level(-4);
|
||||
|
||||
ecs_entity_t u_2 = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "meters"}),
|
||||
.symbol = "m",
|
||||
.base = u_1
|
||||
});
|
||||
test_assert(u_2 == 0);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_unit_w_invalid_over(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t u_1 = ecs_new_id(world); /* not a unit */
|
||||
test_assert(u_1 != 0);
|
||||
|
||||
ecs_entity_t u_2 = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "meters"}),
|
||||
.symbol = "m"
|
||||
});
|
||||
test_assert(u_2 != 0);
|
||||
|
||||
ecs_log_set_level(-4);
|
||||
|
||||
ecs_entity_t u_3 = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "meters_per_second"}),
|
||||
.symbol = "mps",
|
||||
.base = u_2,
|
||||
.over = u_1
|
||||
});
|
||||
test_assert(u_3 == 0);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_unit_w_invalid_symbol_w_over(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t u_1 = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "seconds"}),
|
||||
.symbol = "s"
|
||||
});
|
||||
test_assert(u_1 != 0);
|
||||
|
||||
ecs_entity_t u_2 = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "meters"}),
|
||||
.symbol = "m"
|
||||
});
|
||||
test_assert(u_2 != 0);
|
||||
|
||||
ecs_log_set_level(-4);
|
||||
|
||||
ecs_entity_t u_3 = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "meters_per_second"}),
|
||||
.symbol = "mps",
|
||||
.base = u_2,
|
||||
.over = u_1
|
||||
});
|
||||
test_assert(u_3 == 0);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_unit_w_invalid_symbol_w_prefix(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t u_1 = ecs_unit_prefix_init(world, &(ecs_unit_prefix_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "kilo"}),
|
||||
.symbol = "k"
|
||||
});
|
||||
test_assert(u_1 != 0);
|
||||
|
||||
ecs_entity_t u_2 = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "meters"}),
|
||||
.symbol = "m"
|
||||
});
|
||||
test_assert(u_2 != 0);
|
||||
|
||||
ecs_log_set_level(-4);
|
||||
|
||||
ecs_entity_t u_3 = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "kilometers"}),
|
||||
.symbol = "Km",
|
||||
.base = u_2,
|
||||
.prefix = u_1
|
||||
});
|
||||
test_assert(u_3 == 0);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_unit_w_over_no_derived(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t u_2 = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "meters"}),
|
||||
.symbol = "m"
|
||||
});
|
||||
test_assert(u_2 != 0);
|
||||
|
||||
ecs_log_set_level(-4);
|
||||
|
||||
ecs_entity_t u_3 = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "meters_per_second"}),
|
||||
.symbol = "mps",
|
||||
.over = u_2
|
||||
});
|
||||
test_assert(u_3 == 0);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_define_twice(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t u = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "seconds"}),
|
||||
.symbol = "s"
|
||||
});
|
||||
test_assert(u != 0);
|
||||
|
||||
test_assert(u != 0);
|
||||
test_str("seconds", ecs_get_name(world, u));
|
||||
test_assert(ecs_has(world, u, EcsUnit));
|
||||
|
||||
const EcsUnit *uptr = ecs_get(world, u, EcsUnit);
|
||||
test_assert(uptr != NULL);
|
||||
test_str(uptr->symbol, "s");
|
||||
|
||||
test_assert(u == ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = u,
|
||||
.symbol = "s"
|
||||
}));
|
||||
|
||||
test_assert(u != 0);
|
||||
test_str("seconds", ecs_get_name(world, u));
|
||||
test_assert(ecs_has(world, u, EcsUnit));
|
||||
|
||||
uptr = ecs_get(world, u, EcsUnit);
|
||||
test_assert(uptr != NULL);
|
||||
test_str(uptr->symbol, "s");
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_define_twice_different_quantity(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t q_1 = ecs_quantity_init(world, &(ecs_entity_desc_t){
|
||||
.name = "percentage"
|
||||
});
|
||||
test_assert(q_1 != 0);
|
||||
|
||||
ecs_entity_t q_2 = ecs_quantity_init(world, &(ecs_entity_desc_t){
|
||||
.name = "duration"
|
||||
});
|
||||
test_assert(q_2 != 0);
|
||||
|
||||
ecs_entity_t u = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "seconds"}),
|
||||
.symbol = "s",
|
||||
.quantity = q_1
|
||||
});
|
||||
test_assert(u != 0);
|
||||
|
||||
test_assert(u != 0);
|
||||
test_str("seconds", ecs_get_name(world, u));
|
||||
test_assert(ecs_has(world, u, EcsUnit));
|
||||
test_assert(ecs_has_pair(world, u, EcsQuantity, q_1));
|
||||
|
||||
const EcsUnit *uptr = ecs_get(world, u, EcsUnit);
|
||||
test_assert(uptr != NULL);
|
||||
test_str(uptr->symbol, "s");
|
||||
|
||||
test_assert(u == ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = u,
|
||||
.symbol = "s",
|
||||
.quantity = q_2
|
||||
}));
|
||||
|
||||
test_assert(u != 0);
|
||||
test_str("seconds", ecs_get_name(world, u));
|
||||
test_assert(ecs_has(world, u, EcsUnit));
|
||||
test_assert(!ecs_has_pair(world, u, EcsQuantity, q_1));
|
||||
test_assert(ecs_has_pair(world, u, EcsQuantity, q_2));
|
||||
|
||||
uptr = ecs_get(world, u, EcsUnit);
|
||||
test_assert(uptr != NULL);
|
||||
test_str(uptr->symbol, "s");
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_define_twice_remove_quantity(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t q_1 = ecs_quantity_init(world, &(ecs_entity_desc_t){
|
||||
.name = "percentage"
|
||||
});
|
||||
test_assert(q_1 != 0);
|
||||
|
||||
ecs_entity_t u = ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "seconds"}),
|
||||
.symbol = "s",
|
||||
.quantity = q_1
|
||||
});
|
||||
test_assert(u != 0);
|
||||
|
||||
test_assert(u != 0);
|
||||
test_str("seconds", ecs_get_name(world, u));
|
||||
test_assert(ecs_has(world, u, EcsUnit));
|
||||
test_assert(ecs_has_pair(world, u, EcsQuantity, q_1));
|
||||
|
||||
const EcsUnit *uptr = ecs_get(world, u, EcsUnit);
|
||||
test_assert(uptr != NULL);
|
||||
test_str(uptr->symbol, "s");
|
||||
|
||||
test_assert(u == ecs_unit_init(world, &(ecs_unit_desc_t){
|
||||
.entity = u,
|
||||
.symbol = "s"
|
||||
}));
|
||||
|
||||
test_assert(u != 0);
|
||||
test_str("seconds", ecs_get_name(world, u));
|
||||
test_assert(ecs_has(world, u, EcsUnit));
|
||||
test_assert(!ecs_has_pair(world, u, EcsQuantity, q_1));
|
||||
test_assert(!ecs_has_pair(world, u, EcsQuantity, EcsWildcard));
|
||||
|
||||
uptr = ecs_get(world, u, EcsUnit);
|
||||
test_assert(uptr != NULL);
|
||||
test_str(uptr->symbol, "s");
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_set_unit(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t q = ecs_entity_init(world, &(ecs_entity_desc_t){
|
||||
.add = { EcsQuantity }
|
||||
});
|
||||
test_assert(q != 0);
|
||||
|
||||
ecs_entity_t u = ecs_new_id(world);
|
||||
test_assert(u != 0);
|
||||
|
||||
ecs_set(world, u, EcsUnit, {
|
||||
.symbol = "u"
|
||||
});
|
||||
|
||||
const EcsUnit *uptr = ecs_get(world, u, EcsUnit);
|
||||
test_assert(uptr != NULL);
|
||||
test_str(uptr->symbol, "u");
|
||||
|
||||
ecs_add_pair(world, u, EcsQuantity, q);
|
||||
|
||||
ecs_entity_t s = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.members = {
|
||||
{ .name = "value", .type = ecs_id(ecs_f32_t), .unit = u }
|
||||
}
|
||||
});
|
||||
test_assert(s != 0);
|
||||
|
||||
const EcsStruct *sptr = ecs_get(world, s, EcsStruct);
|
||||
test_assert(sptr != NULL);
|
||||
test_int(1, ecs_vec_count(&sptr->members));
|
||||
ecs_member_t *members = ecs_vec_first_t(&sptr->members, ecs_member_t);
|
||||
test_str(members[0].name, "value");
|
||||
test_uint(members[0].type, ecs_id(ecs_f32_t));
|
||||
test_uint(members[0].unit, u);
|
||||
test_int(members[0].count, 1);
|
||||
|
||||
ecs_entity_t m = ecs_lookup_child(world, s, "value");
|
||||
test_assert(m != 0);
|
||||
|
||||
const EcsMember *mptr = ecs_get(world, m, EcsMember);
|
||||
test_assert(mptr != NULL);
|
||||
test_assert(mptr->type == ecs_id(ecs_f32_t));
|
||||
test_assert(mptr->unit == u);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_set_unit_w_derived(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t q = ecs_entity_init(world, &(ecs_entity_desc_t){
|
||||
.add = { EcsQuantity }
|
||||
});
|
||||
test_assert(q != 0);
|
||||
|
||||
ecs_entity_t d = ecs_new_id(world);
|
||||
test_assert(d != 0);
|
||||
|
||||
ecs_set(world, d, EcsUnit, {
|
||||
.symbol = "d"
|
||||
});
|
||||
|
||||
ecs_entity_t u = ecs_new_id(world);
|
||||
test_assert(u != 0);
|
||||
|
||||
ecs_set(world, u, EcsUnit, {
|
||||
.symbol = "u",
|
||||
.base = d
|
||||
});
|
||||
|
||||
const EcsUnit *uptr = ecs_get(world, u, EcsUnit);
|
||||
test_assert(uptr != NULL);
|
||||
test_str(uptr->symbol, "u");
|
||||
test_assert(uptr->base == d);
|
||||
|
||||
ecs_add_pair(world, u, EcsQuantity, q);
|
||||
|
||||
ecs_entity_t s = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.members = {
|
||||
{ .name = "value", .type = ecs_id(ecs_f32_t), .unit = u }
|
||||
}
|
||||
});
|
||||
test_assert(s != 0);
|
||||
|
||||
const EcsStruct *sptr = ecs_get(world, s, EcsStruct);
|
||||
test_assert(sptr != NULL);
|
||||
test_int(1, ecs_vec_count(&sptr->members));
|
||||
ecs_member_t *members = ecs_vec_first_t(&sptr->members, ecs_member_t);
|
||||
test_str(members[0].name, "value");
|
||||
test_uint(members[0].type, ecs_id(ecs_f32_t));
|
||||
test_uint(members[0].unit, u);
|
||||
test_int(members[0].count, 1);
|
||||
|
||||
ecs_entity_t m = ecs_lookup_child(world, s, "value");
|
||||
test_assert(m != 0);
|
||||
|
||||
const EcsMember *mptr = ecs_get(world, m, EcsMember);
|
||||
test_assert(mptr != NULL);
|
||||
test_assert(mptr->type == ecs_id(ecs_f32_t));
|
||||
test_assert(mptr->unit == u);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_set_unit_w_over(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t q = ecs_entity_init(world, &(ecs_entity_desc_t){
|
||||
.add = { EcsQuantity }
|
||||
});
|
||||
test_assert(q != 0);
|
||||
|
||||
ecs_entity_t d = ecs_new_id(world);
|
||||
test_assert(d != 0);
|
||||
|
||||
ecs_set(world, d, EcsUnit, {
|
||||
.symbol = "d"
|
||||
});
|
||||
|
||||
ecs_entity_t o = ecs_new_id(world);
|
||||
test_assert(o != 0);
|
||||
|
||||
ecs_set(world, o, EcsUnit, {
|
||||
.symbol = "o"
|
||||
});
|
||||
|
||||
ecs_entity_t u = ecs_new_id(world);
|
||||
test_assert(u != 0);
|
||||
|
||||
ecs_set(world, u, EcsUnit, {
|
||||
.base = d,
|
||||
.over = o
|
||||
});
|
||||
|
||||
const EcsUnit *uptr = ecs_get(world, u, EcsUnit);
|
||||
test_assert(uptr != NULL);
|
||||
test_str(uptr->symbol, "d/o");
|
||||
test_assert(uptr->base == d);
|
||||
test_assert(uptr->over == o);
|
||||
|
||||
ecs_add_pair(world, u, EcsQuantity, q);
|
||||
|
||||
ecs_entity_t s = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.members = {
|
||||
{ .name = "value", .type = ecs_id(ecs_f32_t), .unit = u }
|
||||
}
|
||||
});
|
||||
test_assert(s != 0);
|
||||
|
||||
const EcsStruct *sptr = ecs_get(world, s, EcsStruct);
|
||||
test_assert(sptr != NULL);
|
||||
test_int(1, ecs_vec_count(&sptr->members));
|
||||
ecs_member_t *members = ecs_vec_first_t(&sptr->members, ecs_member_t);
|
||||
test_str(members[0].name, "value");
|
||||
test_uint(members[0].type, ecs_id(ecs_f32_t));
|
||||
test_uint(members[0].unit, u);
|
||||
test_int(members[0].count, 1);
|
||||
|
||||
ecs_entity_t m = ecs_lookup_child(world, s, "value");
|
||||
test_assert(m != 0);
|
||||
|
||||
const EcsMember *mptr = ecs_get(world, m, EcsMember);
|
||||
test_assert(mptr != NULL);
|
||||
test_assert(mptr->type == ecs_id(ecs_f32_t));
|
||||
test_assert(mptr->unit == u);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_set_unit_w_prefix(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t q = ecs_entity_init(world, &(ecs_entity_desc_t){
|
||||
.add = { EcsQuantity }
|
||||
});
|
||||
test_assert(q != 0);
|
||||
|
||||
ecs_entity_t d = ecs_new_id(world);
|
||||
test_assert(d != 0);
|
||||
|
||||
ecs_set(world, d, EcsUnit, {
|
||||
.symbol = "d"
|
||||
});
|
||||
|
||||
ecs_entity_t p = ecs_new_id(world);
|
||||
test_assert(p != 0);
|
||||
|
||||
ecs_set(world, p, EcsUnitPrefix, {
|
||||
.symbol = "P",
|
||||
.translation.factor = 10,
|
||||
.translation.power = 2
|
||||
});
|
||||
|
||||
ecs_entity_t u = ecs_new_id(world);
|
||||
test_assert(u != 0);
|
||||
|
||||
ecs_set(world, u, EcsUnit, {
|
||||
.prefix = p,
|
||||
.base = d
|
||||
});
|
||||
|
||||
const EcsUnit *uptr = ecs_get(world, u, EcsUnit);
|
||||
test_assert(uptr != NULL);
|
||||
test_str(uptr->symbol, "Pd");
|
||||
test_assert(uptr->prefix == p);
|
||||
test_assert(uptr->base == d);
|
||||
test_int(uptr->translation.factor, 10);
|
||||
test_int(uptr->translation.power, 2);
|
||||
|
||||
ecs_add_pair(world, u, EcsQuantity, q);
|
||||
|
||||
ecs_entity_t s = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.members = {
|
||||
{ .name = "value", .type = ecs_id(ecs_f32_t), .unit = u }
|
||||
}
|
||||
});
|
||||
test_assert(s != 0);
|
||||
|
||||
const EcsStruct *sptr = ecs_get(world, s, EcsStruct);
|
||||
test_assert(sptr != NULL);
|
||||
test_int(1, ecs_vec_count(&sptr->members));
|
||||
ecs_member_t *members = ecs_vec_first_t(&sptr->members, ecs_member_t);
|
||||
test_str(members[0].name, "value");
|
||||
test_uint(members[0].type, ecs_id(ecs_f32_t));
|
||||
test_uint(members[0].unit, u);
|
||||
test_int(members[0].count, 1);
|
||||
|
||||
ecs_entity_t m = ecs_lookup_child(world, s, "value");
|
||||
test_assert(m != 0);
|
||||
|
||||
const EcsMember *mptr = ecs_get(world, m, EcsMember);
|
||||
test_assert(mptr != NULL);
|
||||
test_assert(mptr->type == ecs_id(ecs_f32_t));
|
||||
test_assert(mptr->unit == u);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_builtin_units(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ECS_IMPORT(world, FlecsUnits);
|
||||
|
||||
test_assert(true); // Ensure builtin units can be successfully imported
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_unit_w_short_notation(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t u = ecs_unit(world, {
|
||||
.symbol = "fl"
|
||||
});
|
||||
test_assert(u != 0);
|
||||
test_assert(ecs_has(world, u, EcsUnit));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_unit_prefix_w_short_notation(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t u = ecs_unit_prefix(world, {
|
||||
.symbol = "fl"
|
||||
});
|
||||
test_assert(u != 0);
|
||||
test_assert(ecs_has(world, u, EcsUnitPrefix));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Units_quantity_w_short_notation(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t u = ecs_quantity(world, {
|
||||
.name = "q"
|
||||
});
|
||||
test_assert(u != 0);
|
||||
test_str("q", ecs_get_name(world, u));
|
||||
test_assert(ecs_has_id(world, u, EcsQuantity));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
406
engine/libs/flecs/test/meta/src/Vars.c
Normal file
406
engine/libs/flecs/test/meta/src/Vars.c
Normal file
@@ -0,0 +1,406 @@
|
||||
#include <meta.h>
|
||||
|
||||
void Vars_declare_1_var(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_vars_t vars = {0};
|
||||
ecs_vars_init(world, &vars);
|
||||
|
||||
ecs_expr_var_t *v = ecs_vars_declare(
|
||||
&vars, "foo", ecs_id(ecs_i32_t));
|
||||
test_assert(v != NULL);
|
||||
test_assert(v->value.ptr != NULL);
|
||||
test_assert(v->value.type != 0);
|
||||
test_uint(v->value.type, ecs_id(ecs_i32_t));
|
||||
test_int(*(int32_t*)v->value.ptr, 0);
|
||||
|
||||
const ecs_expr_var_t *v2 = ecs_vars_lookup(&vars, "foo");
|
||||
test_assert(v2 != NULL);
|
||||
test_assert(v == v2);
|
||||
|
||||
ecs_vars_fini(&vars);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Vars_declare_2_vars(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_vars_t vars = {0};
|
||||
ecs_vars_init(world, &vars);
|
||||
|
||||
ecs_expr_var_t *foo = ecs_vars_declare(
|
||||
&vars, "foo", ecs_id(ecs_i32_t));
|
||||
test_assert(foo != NULL);
|
||||
test_assert(foo->value.ptr != NULL);
|
||||
test_assert(foo->value.type != 0);
|
||||
test_uint(foo->value.type, ecs_id(ecs_i32_t));
|
||||
test_int(*(int32_t*)foo->value.ptr, 0);
|
||||
|
||||
ecs_expr_var_t *bar = ecs_vars_declare(
|
||||
&vars, "bar", ecs_id(ecs_u32_t));
|
||||
test_assert(bar != NULL);
|
||||
test_assert(bar->value.ptr != NULL);
|
||||
test_assert(bar->value.type != 0);
|
||||
test_uint(bar->value.type, ecs_id(ecs_u32_t));
|
||||
test_uint(*(ecs_u32_t*)bar->value.ptr, 0);
|
||||
|
||||
test_assert(foo == ecs_vars_lookup(&vars, "foo"));
|
||||
test_assert(bar == ecs_vars_lookup(&vars, "bar"));
|
||||
test_assert(foo != bar);
|
||||
|
||||
ecs_vars_fini(&vars);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Vars_declare_vars_nested_scope(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_vars_t vars = {0};
|
||||
ecs_vars_init(world, &vars);
|
||||
|
||||
ecs_vars_push(&vars);
|
||||
|
||||
ecs_expr_var_t *foo = ecs_vars_declare(
|
||||
&vars, "foo", ecs_id(ecs_i32_t));
|
||||
test_assert(foo != NULL);
|
||||
test_assert(foo->value.ptr != NULL);
|
||||
test_assert(foo->value.type != 0);
|
||||
test_uint(foo->value.type, ecs_id(ecs_i32_t));
|
||||
test_int(*(int32_t*)foo->value.ptr, 0);
|
||||
test_assert(foo == ecs_vars_lookup(&vars, "foo"));
|
||||
|
||||
test_int(0, ecs_vars_pop(&vars));
|
||||
|
||||
test_assert(NULL == ecs_vars_lookup(&vars, "foo"));
|
||||
|
||||
ecs_vars_fini(&vars);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Vars_declare_vars_2_scopes(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_vars_t vars = {0};
|
||||
ecs_vars_init(world, &vars);
|
||||
|
||||
ecs_expr_var_t *foo = ecs_vars_declare(
|
||||
&vars, "foo", ecs_id(ecs_i32_t));
|
||||
test_assert(foo != NULL);
|
||||
test_assert(foo->value.ptr != NULL);
|
||||
test_assert(foo->value.type != 0);
|
||||
test_uint(foo->value.type, ecs_id(ecs_i32_t));
|
||||
test_int(*(int32_t*)foo->value.ptr, 0);
|
||||
test_assert(foo == ecs_vars_lookup(&vars, "foo"));
|
||||
|
||||
ecs_vars_push(&vars);
|
||||
|
||||
ecs_expr_var_t *bar = ecs_vars_declare(
|
||||
&vars, "bar", ecs_id(ecs_u32_t));
|
||||
test_assert(bar != NULL);
|
||||
test_assert(bar->value.ptr != NULL);
|
||||
test_assert(bar->value.type != 0);
|
||||
test_uint(bar->value.type, ecs_id(ecs_u32_t));
|
||||
test_uint(*(ecs_u32_t*)bar->value.ptr, 0);
|
||||
|
||||
test_assert(foo == ecs_vars_lookup(&vars, "foo"));
|
||||
test_assert(bar == ecs_vars_lookup(&vars, "bar"));
|
||||
test_assert(foo != bar);
|
||||
|
||||
ecs_vars_pop(&vars);
|
||||
|
||||
test_assert(foo == ecs_vars_lookup(&vars, "foo"));
|
||||
test_assert(NULL == ecs_vars_lookup(&vars, "bar"));
|
||||
|
||||
ecs_vars_fini(&vars);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Vars_redeclare_var(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_vars_t vars = {0};
|
||||
ecs_vars_init(world, &vars);
|
||||
|
||||
ecs_expr_var_t *foo = ecs_vars_declare(
|
||||
&vars, "foo", ecs_id(ecs_i32_t));
|
||||
test_assert(foo != NULL);
|
||||
test_assert(foo->value.ptr != NULL);
|
||||
test_assert(foo->value.type != 0);
|
||||
test_uint(foo->value.type, ecs_id(ecs_i32_t));
|
||||
test_int(*(int32_t*)foo->value.ptr, 0);
|
||||
test_assert(foo == ecs_vars_lookup(&vars, "foo"));
|
||||
|
||||
ecs_log_set_level(-4);
|
||||
ecs_expr_var_t *foo_2 = ecs_vars_declare(
|
||||
&vars, "foo", ecs_id(ecs_i32_t));
|
||||
test_assert(foo_2 == NULL);
|
||||
|
||||
ecs_vars_fini(&vars);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Vars_i32_expr_w_i32_var(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_vars_t vars = {0};
|
||||
ecs_vars_init(world, &vars);
|
||||
|
||||
ecs_expr_var_t *foo = ecs_vars_declare(
|
||||
&vars, "foo", ecs_id(ecs_i32_t));
|
||||
*(int32_t*)foo->value.ptr = 10;
|
||||
|
||||
int32_t v = 0;
|
||||
ecs_parse_expr_desc_t desc = { .vars = &vars };
|
||||
const char *ptr = ecs_parse_expr(
|
||||
world, "$foo", &ecs_value(ecs_i32_t, &v), &desc);
|
||||
test_assert(ptr != NULL);
|
||||
test_assert(ptr[0] == 0);
|
||||
test_int(v, 10);
|
||||
|
||||
ecs_vars_fini(&vars);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Vars_i32_expr_w_f32_var(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_vars_t vars = {0};
|
||||
ecs_vars_init(world, &vars);
|
||||
|
||||
ecs_expr_var_t *foo = ecs_vars_declare(
|
||||
&vars, "foo", ecs_id(ecs_f32_t));
|
||||
*(float*)foo->value.ptr = 10.5;
|
||||
|
||||
int32_t v = 0;
|
||||
ecs_parse_expr_desc_t desc = { .vars = &vars };
|
||||
const char *ptr = ecs_parse_expr(
|
||||
world, "$foo", &ecs_value(ecs_i32_t, &v), &desc);
|
||||
test_assert(ptr != NULL);
|
||||
test_assert(ptr[0] == 0);
|
||||
test_int(v, 10);
|
||||
|
||||
ecs_vars_fini(&vars);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Vars_i32_expr_w_string_var(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_vars_t vars = {0};
|
||||
ecs_vars_init(world, &vars);
|
||||
|
||||
ecs_expr_var_t *foo = ecs_vars_declare(&vars, "foo", ecs_id(ecs_string_t));
|
||||
*(char**)foo->value.ptr = "10";
|
||||
|
||||
int32_t v = 0;
|
||||
ecs_parse_expr_desc_t desc = { .vars = &vars };
|
||||
const char *ptr = ecs_parse_expr(
|
||||
world, "$foo", &ecs_value(ecs_i32_t, &v), &desc);
|
||||
test_assert(ptr != NULL);
|
||||
test_assert(ptr[0] == 0);
|
||||
test_int(v, 10);
|
||||
|
||||
*(char**)foo->value.ptr = NULL;
|
||||
ecs_vars_fini(&vars);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Vars_string_expr_w_string_var(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_vars_t vars = {0};
|
||||
ecs_vars_init(world, &vars);
|
||||
|
||||
ecs_expr_var_t *foo = ecs_vars_declare(&vars, "foo", ecs_id(ecs_string_t));
|
||||
*(char**)foo->value.ptr = "Hello World";
|
||||
|
||||
char* v = NULL;
|
||||
ecs_parse_expr_desc_t desc = { .vars = &vars };
|
||||
const char *ptr = ecs_parse_expr(
|
||||
world, "$foo", &ecs_value(ecs_string_t, &v), &desc);
|
||||
test_assert(ptr != NULL);
|
||||
test_assert(ptr[0] == 0);
|
||||
test_str(v, "Hello World");
|
||||
|
||||
ecs_os_free(v);
|
||||
|
||||
*(char**)foo->value.ptr = NULL;
|
||||
ecs_vars_fini(&vars);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Vars_struct_expr_w_i32_vars(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t point = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t)},
|
||||
{"y", ecs_id(ecs_i32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
ecs_vars_t vars = {0};
|
||||
ecs_vars_init(world, &vars);
|
||||
|
||||
ecs_expr_var_t *foo = ecs_vars_declare(&vars, "foo", ecs_id(ecs_i32_t));
|
||||
*(int32_t*)foo->value.ptr = 10;
|
||||
ecs_expr_var_t *bar = ecs_vars_declare(&vars, "bar", ecs_id(ecs_i32_t));
|
||||
*(int32_t*)bar->value.ptr = 20;
|
||||
|
||||
Position v = {0};
|
||||
ecs_parse_expr_desc_t desc = { .vars = &vars };
|
||||
const char *ptr = ecs_parse_expr(world, "{$foo, $bar}", &(ecs_value_t){point, &v}, &desc);
|
||||
test_assert(ptr != NULL);
|
||||
test_assert(ptr[0] == 0);
|
||||
|
||||
test_int(v.x, 10);
|
||||
test_int(v.y, 20);
|
||||
|
||||
ecs_vars_fini(&vars);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Vars_struct_expr_w_struct_var(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t point = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t)},
|
||||
{"y", ecs_id(ecs_i32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
ecs_vars_t vars = {0};
|
||||
ecs_vars_init(world, &vars);
|
||||
|
||||
ecs_expr_var_t *foo = ecs_vars_declare(&vars, "foo", point);
|
||||
*(Position*)foo->value.ptr = (Position){10, 20};
|
||||
|
||||
Position v = {0};
|
||||
ecs_parse_expr_desc_t desc = { .vars = &vars };
|
||||
const char *ptr = ecs_parse_expr(world, "$foo", &(ecs_value_t){point, &v}, &desc);
|
||||
test_assert(ptr != NULL);
|
||||
test_assert(ptr[0] == 0);
|
||||
|
||||
test_int(v.x, 10);
|
||||
test_int(v.y, 20);
|
||||
|
||||
ecs_vars_fini(&vars);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Vars_nested_struct_expr_w_struct_var(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t point = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t)},
|
||||
{"y", ecs_id(ecs_i32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
ecs_entity_t line = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.members = {
|
||||
{"start", point},
|
||||
{"stop", point}
|
||||
}
|
||||
});
|
||||
|
||||
ecs_vars_t vars = {0};
|
||||
ecs_vars_init(world, &vars);
|
||||
|
||||
ecs_expr_var_t *foo = ecs_vars_declare(&vars, "foo", point);
|
||||
*(Position*)foo->value.ptr = (Position){10, 20};
|
||||
ecs_expr_var_t *bar = ecs_vars_declare(&vars, "bar", point);
|
||||
*(Position*)bar->value.ptr = (Position){30, 40};
|
||||
|
||||
Line v = {0};
|
||||
ecs_parse_expr_desc_t desc = { .vars = &vars };
|
||||
const char *ptr = ecs_parse_expr(world,
|
||||
"{start: $foo, stop: $bar}", &(ecs_value_t){line, &v}, &desc);
|
||||
test_assert(ptr != NULL);
|
||||
test_assert(ptr[0] == 0);
|
||||
|
||||
test_int(v.start.x, 10);
|
||||
test_int(v.start.y, 20);
|
||||
test_int(v.stop.x, 30);
|
||||
test_int(v.stop.y, 40);
|
||||
|
||||
ecs_vars_fini(&vars);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Vars_declare_w_value(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_vars_t vars = {0};
|
||||
ecs_vars_init(world, &vars);
|
||||
|
||||
ecs_value_t src;
|
||||
src.type = ecs_id(ecs_i32_t);
|
||||
src.ptr = ecs_value_new_t(world, ecs_i32_t);
|
||||
*(int32_t*)src.ptr = 10;
|
||||
void *src_ptr = src.ptr;
|
||||
|
||||
ecs_expr_var_t *v = ecs_vars_declare_w_value(
|
||||
&vars, "foo", &src);
|
||||
test_assert(v != NULL);
|
||||
test_assert(v->value.ptr != NULL);
|
||||
test_assert(v->value.type != 0);
|
||||
test_uint(v->value.type, ecs_id(ecs_i32_t));
|
||||
test_int(*(int32_t*)v->value.ptr, 10);
|
||||
test_assert(v->value.ptr == src_ptr);
|
||||
test_assert(src.ptr == NULL);
|
||||
|
||||
const ecs_expr_var_t *v2 = ecs_vars_lookup(&vars, "foo");
|
||||
test_assert(v2 != NULL);
|
||||
test_assert(v == v2);
|
||||
|
||||
ecs_vars_fini(&vars);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Vars_redeclare_in_scope(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_vars_t vars = {0};
|
||||
ecs_vars_init(world, &vars);
|
||||
|
||||
ecs_expr_var_t *v1 = ecs_vars_declare(&vars, "foo", ecs_id(ecs_i32_t));
|
||||
test_assert(v1 != NULL);
|
||||
ecs_vars_push(&vars);
|
||||
ecs_expr_var_t *v2 = ecs_vars_declare(&vars, "foo", ecs_id(ecs_i32_t));
|
||||
test_assert(v2 != NULL);
|
||||
test_assert(v1 != v2);
|
||||
test_assert(ecs_vars_lookup(&vars, "foo") == v2);
|
||||
ecs_vars_pop(&vars);
|
||||
test_assert(ecs_vars_lookup(&vars, "foo") == v1);
|
||||
ecs_vars_fini(&vars);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void Vars_init_fini_vars(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_vars_t vars = {0};
|
||||
ecs_vars_init(world, &vars);
|
||||
|
||||
ecs_vars_fini(&vars);
|
||||
ecs_fini(world);
|
||||
|
||||
test_assert(true);
|
||||
}
|
||||
92
engine/libs/flecs/test/meta/src/VectorTypes.c
Normal file
92
engine/libs/flecs/test/meta/src/VectorTypes.c
Normal file
@@ -0,0 +1,92 @@
|
||||
#include <meta.h>
|
||||
|
||||
void meta_test_vector(
|
||||
ecs_world_t *world,
|
||||
ecs_entity_t t,
|
||||
ecs_entity_t elem_type)
|
||||
{
|
||||
const EcsComponent *ct = ecs_get(world, t, EcsComponent);
|
||||
test_assert(ct != NULL);
|
||||
test_int(ct->size, ECS_SIZEOF(ecs_vec_t));
|
||||
test_int(ct->alignment, ECS_ALIGNOF(ecs_vec_t));
|
||||
|
||||
const EcsMetaType *mt = ecs_get(world, t, EcsMetaType);
|
||||
test_assert(mt != NULL);
|
||||
test_assert(mt->kind == EcsVectorType);
|
||||
|
||||
const EcsVector *v = ecs_get(world, t, EcsVector);
|
||||
test_assert(v != NULL);
|
||||
test_assert(v->type == elem_type);
|
||||
}
|
||||
|
||||
void VectorTypes_vector_bool(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t v = ecs_vector_init(world, &(ecs_vector_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "V"}),
|
||||
.type = ecs_id(ecs_bool_t)
|
||||
});
|
||||
|
||||
test_assert(v != 0);
|
||||
test_str(ecs_get_name(world, v), "V");
|
||||
|
||||
meta_test_vector(world, v, ecs_id(ecs_bool_t));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void VectorTypes_vector_i32(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t v = ecs_vector_init(world, &(ecs_vector_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "V"}),
|
||||
.type = ecs_id(ecs_i32_t)
|
||||
});
|
||||
|
||||
test_assert(v != 0);
|
||||
test_str(ecs_get_name(world, v), "V");
|
||||
|
||||
meta_test_vector(world, v, ecs_id(ecs_i32_t));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void VectorTypes_vector_struct(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t t = ecs_struct_init(world, &(ecs_struct_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "T"}),
|
||||
.members = {
|
||||
{"x", ecs_id(ecs_i32_t)}
|
||||
}
|
||||
});
|
||||
|
||||
test_assert(t != 0);
|
||||
|
||||
ecs_entity_t v = ecs_vector_init(world, &(ecs_vector_desc_t){
|
||||
.entity = ecs_entity(world, {.name = "V"}),
|
||||
.type = t
|
||||
});
|
||||
|
||||
test_assert(v != 0);
|
||||
test_str(ecs_get_name(world, v), "V");
|
||||
|
||||
meta_test_vector(world, v, t);
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
|
||||
void VectorTypes_vector_w_short_notation(void) {
|
||||
ecs_world_t *world = ecs_init();
|
||||
|
||||
ecs_entity_t a = ecs_vector(world, {
|
||||
.entity = ecs_entity(world, {.name = "V"}),
|
||||
.type = ecs_id(ecs_bool_t)
|
||||
});
|
||||
|
||||
test_assert(a != 0);
|
||||
test_str(ecs_get_name(world, a), "V");
|
||||
test_assert(ecs_has(world, a, EcsVector));
|
||||
|
||||
ecs_fini(world);
|
||||
}
|
||||
5175
engine/libs/flecs/test/meta/src/main.c
Normal file
5175
engine/libs/flecs/test/meta/src/main.c
Normal file
File diff suppressed because it is too large
Load Diff
9
engine/libs/flecs/test/meta/src/utils.c
Normal file
9
engine/libs/flecs/test/meta/src/utils.c
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <meta.h>
|
||||
|
||||
void install_test_abort(void) {
|
||||
ecs_os_set_api_defaults();
|
||||
ecs_os_api_t os_api = ecs_os_get_api();
|
||||
os_api.abort_ = test_abort;
|
||||
ecs_os_set_api(&os_api);
|
||||
ecs_log_set_level(-5);
|
||||
}
|
||||
Reference in New Issue
Block a user