Skip to content

Commit 53f1845

Browse files
committed
Add tests for querying hierarchies with different ChildOf/Parent permutations
1 parent 2900fb1 commit 53f1845

File tree

4 files changed

+3629
-2
lines changed

4 files changed

+3629
-2
lines changed

test/query/project.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,6 +2532,57 @@
25322532
"this_written_up_childof_2_tables_3_parents",
25332533
"this_written_self_up_childof_1_table_3_parents",
25342534
"this_written_self_up_childof_2_tables_3_parents",
2535+
2536+
"this_up_w_3_levels_ccc",
2537+
"this_up_w_3_levels_ccp",
2538+
"this_up_w_3_levels_cpc",
2539+
"this_up_w_3_levels_cpp",
2540+
"this_up_w_3_levels_pcc",
2541+
"this_up_w_3_levels_pcp",
2542+
"this_up_w_3_levels_ppc",
2543+
"this_up_w_3_levels_ppp",
2544+
"this_tag_w_up_w_3_levels_ccc",
2545+
"this_tag_w_up_w_3_levels_ccp",
2546+
"this_tag_w_up_w_3_levels_cpc",
2547+
"this_tag_w_up_w_3_levels_cpp",
2548+
"this_tag_w_up_w_3_levels_pcc",
2549+
"this_tag_w_up_w_3_levels_pcp",
2550+
"this_tag_w_up_w_3_levels_ppc",
2551+
"this_tag_w_up_w_3_levels_ppp",
2552+
"this_up_w_tag_w_3_levels_ccc",
2553+
"this_up_w_tag_w_3_levels_ccp",
2554+
"this_up_w_tag_w_3_levels_cpc",
2555+
"this_up_w_tag_w_3_levels_cpp",
2556+
"this_up_w_tag_w_3_levels_pcc",
2557+
"this_up_w_tag_w_3_levels_pcp",
2558+
"this_up_w_tag_w_3_levels_ppc",
2559+
"this_up_w_tag_w_3_levels_ppp",
2560+
2561+
"this_self_up_w_3_levels_ccc",
2562+
"this_self_up_w_3_levels_ccp",
2563+
"this_self_up_w_3_levels_cpc",
2564+
"this_self_up_w_3_levels_cpp",
2565+
"this_self_up_w_3_levels_pcc",
2566+
"this_self_up_w_3_levels_pcp",
2567+
"this_self_up_w_3_levels_ppc",
2568+
"this_self_up_w_3_levels_ppp",
2569+
"this_tag_w_self_up_w_3_levels_ccc",
2570+
"this_tag_w_self_up_w_3_levels_ccp",
2571+
"this_tag_w_self_up_w_3_levels_cpc",
2572+
"this_tag_w_self_up_w_3_levels_cpp",
2573+
"this_tag_w_self_up_w_3_levels_pcc",
2574+
"this_tag_w_self_up_w_3_levels_pcp",
2575+
"this_tag_w_self_up_w_3_levels_ppc",
2576+
"this_tag_w_self_up_w_3_levels_ppp",
2577+
"this_self_up_w_tag_w_3_levels_ccc",
2578+
"this_self_up_w_tag_w_3_levels_ccp",
2579+
"this_self_up_w_tag_w_3_levels_cpc",
2580+
"this_self_up_w_tag_w_3_levels_cpp",
2581+
"this_self_up_w_tag_w_3_levels_pcc",
2582+
"this_self_up_w_tag_w_3_levels_pcp",
2583+
"this_self_up_w_tag_w_3_levels_ppc",
2584+
"this_self_up_w_tag_w_3_levels_ppp",
2585+
25352586
"this_set_childof",
25362587
"this_set_childof_wildcard",
25372588
"this_set_childof_any",

test/query/src/Cached.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5990,7 +5990,46 @@ void Cached_self_up_w_parent_component_create_before_query(void) {
59905990
}
59915991

59925992
void Cached_self_up_w_parent_component_create_after_query(void) {
5993-
// Implement testcase
5993+
ecs_world_t *world = ecs_mini();
5994+
5995+
ECS_COMPONENT(world, Position);
5996+
5997+
ecs_query_t *q = ecs_query(world, {
5998+
.terms = {{ ecs_id(Position), .src.id = EcsSelf|EcsUp }},
5999+
.cache_kind = EcsQueryCacheAuto
6000+
});
6001+
6002+
ecs_entity_t root_a = ecs_insert(world, ecs_value(Position, {10, 20}));
6003+
ecs_entity_t parent = ecs_insert(world, ecs_value(EcsParent, {root_a}));
6004+
ecs_entity_t child = ecs_new_w_pair(world, EcsChildOf, parent);
6005+
6006+
test_assert(q != NULL);
6007+
6008+
{
6009+
ecs_iter_t it = ecs_query_iter(world, q);
6010+
test_bool(true, ecs_query_next(&it));
6011+
test_int(1, it.count);
6012+
test_uint(root_a, it.entities[0]);
6013+
test_uint(ecs_id(Position), ecs_field_id(&it, 0));
6014+
test_uint(0, ecs_field_src(&it, 0));
6015+
6016+
test_bool(true, ecs_query_next(&it));
6017+
test_int(1, it.count);
6018+
test_uint(parent, it.entities[0]);
6019+
test_uint(ecs_id(Position), ecs_field_id(&it, 0));
6020+
test_uint(root_a, ecs_field_src(&it, 0));
6021+
6022+
test_bool(true, ecs_query_next(&it));
6023+
test_int(1, it.count);
6024+
test_uint(child, it.entities[0]);
6025+
test_uint(ecs_id(Position), ecs_field_id(&it, 0));
6026+
test_uint(root_a, ecs_field_src(&it, 0));
6027+
test_bool(false, ecs_query_next(&it));
6028+
}
6029+
6030+
ecs_query_fini(q);
6031+
6032+
ecs_fini(world);
59946033
}
59956034

59966035
void Cached_rematch_after_reparent_parent(void) {

0 commit comments

Comments
 (0)