Skip to content

Commit

Permalink
Updated tests to be more precise and added them to project.json + rer…
Browse files Browse the repository at this point in the history
…an bake
  • Loading branch information
Gaspard-- authored and SanderMertens committed Sep 1, 2024
1 parent 13fbc14 commit 7922011
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 24 deletions.
4 changes: 3 additions & 1 deletion test/cpp/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,9 @@
"run_w_iter_fini_empty",
"run_w_iter_fini_no_query",
"add_to_match_from_staged_query",
"add_to_match_from_staged_query_readonly_threaded"
"add_to_match_from_staged_query_readonly_threaded",
"pair_with_variable_src",
"pair_with_variable_src_no_row_fields"
]
}, {
"id": "QueryBuilder",
Expand Down
52 changes: 30 additions & 22 deletions test/cpp/src/Query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3057,8 +3057,7 @@ void Query_empty_tables_each_w_iter(void) {
void Query_pair_with_variable_src(void) {
flecs::world world;

struct EmptyRel {};
struct Rel { int x; };
struct Rel {};
struct ThisComp { int x; };
struct OtherComp { int x; };

Expand All @@ -3069,30 +3068,15 @@ void Query_pair_with_variable_src(void) {
auto other = flecs::entity(world)
.set(OtherComp{0});

// Guaranty we don't lukily hit zero if we read the the wrong component
flecs::entity(world)
.set(OtherComp{1});

for (int i = 0; i < 3; ++i)
flecs::entity(world)
.set(ThisComp{i})
.add<Rel>(other)
.add<EmptyRel>(other);
.add<Rel>(other);

{
auto q = world.query_builder<Rel, ThisComp, OtherComp>()
.term_at(0).second("$other")
.term_at(2).src("$other")
.build();

size_t isPresentBitField = 0;
q.each([&isPresentBitField](Rel &rel, ThisComp &thisComp, OtherComp &otherComp) {
isPresentBitField |= (1 << thisComp.x);
rel.x = thisComp.x;
test_int(otherComp.x, 0);
});

test_int(isPresentBitField, 7);
}
{
auto q = world.query_builder<Rel const, ThisComp const, OtherComp const>()
.term_at(0).second("$other")
Expand All @@ -3102,20 +3086,44 @@ void Query_pair_with_variable_src(void) {
size_t isPresentBitField = 0;
q.each([&isPresentBitField](Rel const &rel, ThisComp const &thisComp, OtherComp const &otherComp) {
isPresentBitField |= (1 << thisComp.x);
test_int(rel.x, thisComp.x);
test_int(otherComp.x, 0);
});

test_int(isPresentBitField, 7);
}
}

void Query_pair_with_variable_src_no_row_fields(void) {
flecs::world world;

struct Rel { int dummy; }; // make sure this isn't a tag, so that the query contains no row field
struct ThisComp { int x; };
struct OtherComp { int x; };

world.component<Rel>();
world.component<ThisComp>();
world.component<OtherComp>();

auto other = flecs::entity(world)
.set(OtherComp{0});

// Guaranty we don't lukily hit zero if we read the the wrong component
flecs::entity(world)
.set(OtherComp{1});

for (int i = 0; i < 3; ++i)
flecs::entity(world)
.set(ThisComp{i})
.add<Rel>(other);

{
auto q = world.query_builder<EmptyRel const, ThisComp const, OtherComp const>()
auto q = world.query_builder<Rel const, ThisComp const, OtherComp const>()
.term_at(0).second("$other")
.term_at(2).src("$other")
.build();

size_t isPresentBitField = 0;
q.each([&isPresentBitField](EmptyRel const &, ThisComp const &thisComp, OtherComp const &otherComp) {
q.each([&isPresentBitField](Rel const &rel, ThisComp const &thisComp, OtherComp const &otherComp) {
isPresentBitField |= (1 << thisComp.x);
test_int(otherComp.x, 0);
});
Expand Down
12 changes: 11 additions & 1 deletion test/cpp/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,8 @@ void Query_run_w_iter_fini_empty(void);
void Query_run_w_iter_fini_no_query(void);
void Query_add_to_match_from_staged_query(void);
void Query_add_to_match_from_staged_query_readonly_threaded(void);
void Query_pair_with_variable_src(void);
void Query_pair_with_variable_src_no_row_fields(void);

// Testsuite 'QueryBuilder'
void QueryBuilder_setup(void);
Expand Down Expand Up @@ -3818,6 +3820,14 @@ bake_test_case Query_testcases[] = {
{
"add_to_match_from_staged_query_readonly_threaded",
Query_add_to_match_from_staged_query_readonly_threaded
},
{
"pair_with_variable_src",
Query_pair_with_variable_src
},
{
"pair_with_variable_src_no_row_fields",
Query_pair_with_variable_src_no_row_fields
}
};

Expand Down Expand Up @@ -6588,7 +6598,7 @@ static bake_test_suite suites[] = {
"Query",
NULL,
NULL,
109,
111,
Query_testcases
},
{
Expand Down

0 comments on commit 7922011

Please sign in to comment.