Skip to content

Commit

Permalink
Add cpp_api test: Singleton_get_target
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroErrors authored and SanderMertens committed Jul 18, 2023
1 parent ac5c40e commit b718c4f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
3 changes: 2 additions & 1 deletion test/cpp_api/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,8 @@
"get_set_singleton_pair_R_t",
"add_remove_singleton_pair_R_T",
"add_remove_singleton_pair_R_t",
"add_remove_singleton_pair_r_t"
"add_remove_singleton_pair_r_t",
"get_target"
]
}, {
"id": "Misc",
Expand Down
51 changes: 51 additions & 0 deletions test/cpp_api/src/Singleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,54 @@ void Singleton_add_remove_singleton_pair_r_t() {
world.remove(rel, tgt);
test_assert(!(world.has(rel, tgt)));
}

void Singleton_get_target() {
flecs::world world;

auto Rel = world.singleton<Tag>();

auto obj1 = world.entity()
.add<Position>();

auto obj2 = world.entity()
.add<Velocity>();

auto obj3 = world.entity()
.add<Mass>();

flecs::entity entities[3] = {obj1, obj2, obj3};

world.add<Tag>(obj1);
world.add<Tag>(obj2);
world.add(Rel, obj3);

auto p = world.target<Tag>();
test_assert(p != 0);
test_assert(p == obj1);

p = world.target<Tag>(Rel);
test_assert(p != 0);
test_assert(p == obj1);

p = world.target(Rel);
test_assert(p != 0);
test_assert(p == obj1);

for (int i = 0; i < 3; i++) {
p = world.target<Tag>(i);
test_assert(p != 0);
test_assert(p == entities[i]);
}

for (int i = 0; i < 3; i++) {
p = world.target<Tag>(Rel, i);
test_assert(p != 0);
test_assert(p == entities[i]);
}

for (int i = 0; i < 3; i++) {
p = world.target(Rel, i);
test_assert(p != 0);
test_assert(p == entities[i]);
}
}
7 changes: 6 additions & 1 deletion test/cpp_api/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,7 @@ void Singleton_get_set_singleton_pair_R_t(void);
void Singleton_add_remove_singleton_pair_R_T(void);
void Singleton_add_remove_singleton_pair_R_t(void);
void Singleton_add_remove_singleton_pair_r_t(void);
void Singleton_get_target(void);

// Testsuite 'Misc'
void Misc_setup(void);
Expand Down Expand Up @@ -5536,6 +5537,10 @@ bake_test_case Singleton_testcases[] = {
{
"add_remove_singleton_pair_r_t",
Singleton_add_remove_singleton_pair_r_t
},
{
"get_target",
Singleton_get_target
}
};

Expand Down Expand Up @@ -6225,7 +6230,7 @@ static bake_test_suite suites[] = {
"Singleton",
NULL,
NULL,
18,
19,
Singleton_testcases
},
{
Expand Down

0 comments on commit b718c4f

Please sign in to comment.