Skip to content

Commit

Permalink
added 3 more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jpeletier committed Sep 5, 2024
1 parent ee6f05b commit d1cb2cc
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
5 changes: 4 additions & 1 deletion test/meta/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@
"array_dtor",
"array_move",
"array_copy",
"mixed"
"vector_lifecycle",
"vector_lifecycle_trivial_type",
"mixed",
"opaque"
]
}, {
"id": "StructTypes",
Expand Down
33 changes: 33 additions & 0 deletions test/meta/src/RuntimeTypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1065,4 +1065,37 @@ void RuntimeTypes_mixed(void) {
test_assert(resource_id_available(i + 1));
}
free_resource_ids();
}

// Tests that RTT ignores opaque types
void RuntimeTypes_opaque(void) {
ecs_world_t *world = ecs_init();

ECS_COMPONENT(world, ResourceHandle);

ecs_type_hooks_t hooks = *ecs_get_hooks(world, ResourceHandle);
hooks.ctor = ResourceHandle_ctor;
hooks.dtor = ResourceHandle_dtor;
hooks.move = ResourceHandle_move;
hooks.copy = ResourceHandle_copy;
ecs_set_hooks_id(world, ecs_id(ResourceHandle), &hooks);

// Create struct type that describes the structure of ResourceHandle
ecs_entity_t resource_handle_descriptor = ecs_struct(world, {.members = {
{.name = "value", .type = ecs_id(ecs_u32_t)},
}});
// Register ResourceHandle as opaque type.
ecs_opaque(world, {// Link reflection with component
.entity = ecs_id(ResourceHandle),
// Let reflection framework know the type represents a struct
.type = {.as_type = resource_handle_descriptor}});

// Now test that hooks defined for the opaque type are intact:
hooks = *ecs_get_hooks(world, ResourceHandle);
test_assert(hooks.ctor == ResourceHandle_ctor);
test_assert(hooks.dtor == ResourceHandle_dtor);
test_assert(hooks.move == ResourceHandle_move);
test_assert(hooks.copy == ResourceHandle_copy);

ecs_fini(world);
}
17 changes: 16 additions & 1 deletion test/meta/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ void RuntimeTypes_array_ctor(void);
void RuntimeTypes_array_dtor(void);
void RuntimeTypes_array_move(void);
void RuntimeTypes_array_copy(void);
void RuntimeTypes_vector_lifecycle(void);
void RuntimeTypes_vector_lifecycle_trivial_type(void);
void RuntimeTypes_mixed(void);
void RuntimeTypes_opaque(void);

// Testsuite 'StructTypes'
void StructTypes_i32(void);
Expand Down Expand Up @@ -1294,9 +1297,21 @@ bake_test_case RuntimeTypes_testcases[] = {
"array_copy",
RuntimeTypes_array_copy
},
{
"vector_lifecycle",
RuntimeTypes_vector_lifecycle
},
{
"vector_lifecycle_trivial_type",
RuntimeTypes_vector_lifecycle_trivial_type
},
{
"mixed",
RuntimeTypes_mixed
},
{
"opaque",
RuntimeTypes_opaque
}
};

Expand Down Expand Up @@ -4670,7 +4685,7 @@ static bake_test_suite suites[] = {
"RuntimeTypes",
NULL,
NULL,
12,
15,
RuntimeTypes_testcases
},
{
Expand Down

0 comments on commit d1cb2cc

Please sign in to comment.