1 #include <gtest/gtest.h>
2 #include <entt/core/hashed_string.hpp>
3 #include <entt/entity/helper.hpp>
4 #include <entt/entity/entity.hpp>
5 #include <entt/entity/registry.hpp>
6 #include <entt/core/type_traits.hpp>
7
8 struct clazz {
funcclazz9 void func(entt::registry &, entt::entity curr) { entt = curr; }
10 entt::entity entt{entt::null};
11 };
12
TEST(Helper,AsView)13 TEST(Helper, AsView) {
14 entt::registry registry;
15 const entt::registry cregistry;
16
17 ([](entt::view<entt::exclude_t<>, int>) {})(entt::as_view{registry});
18 ([](entt::view<entt::exclude_t<int>, char, double>) {})(entt::as_view{registry});
19 ([](entt::view<entt::exclude_t<int>, const char, double>) {})(entt::as_view{registry});
20 ([](entt::view<entt::exclude_t<int>, const char, const double>) {})(entt::as_view{cregistry});
21 }
22
TEST(Helper,AsGroup)23 TEST(Helper, AsGroup) {
24 entt::registry registry;
25 const entt::registry cregistry;
26
27 ([](entt::group<entt::exclude_t<int>, entt::get_t<char>, double>) {})(entt::as_group{registry});
28 ([](entt::group<entt::exclude_t<int>, entt::get_t<const char>, double>) {})(entt::as_group{registry});
29 ([](entt::group<entt::exclude_t<int>, entt::get_t<const char>, const double>) {})(entt::as_group{cregistry});
30 }
31
TEST(Helper,Invoke)32 TEST(Helper, Invoke) {
33 entt::registry registry;
34 const auto entity = registry.create();
35
36 registry.on_construct<clazz>().connect<entt::invoke<&clazz::func>>();
37 registry.emplace<clazz>(entity);
38
39 ASSERT_EQ(entity, registry.get<clazz>(entity).entt);
40 }
41
TEST(Helper,ToEntity)42 TEST(Helper, ToEntity) {
43 entt::registry registry;
44 const entt::entity null = entt::null;
45 const int value = 42;
46
47 ASSERT_EQ(entt::to_entity(registry, 42), null);
48 ASSERT_EQ(entt::to_entity(registry, value), null);
49
50 const auto entity = registry.create();
51 registry.emplace<int>(entity);
52
53 while(registry.size<int>() < (ENTT_PACKED_PAGE - 1u)) {
54 registry.emplace<int>(registry.create(), value);
55 }
56
57 const auto other = registry.create();
58 const auto next = registry.create();
59
60 registry.emplace<int>(other);
61 registry.emplace<int>(next);
62
63 ASSERT_EQ(entt::to_entity(registry, registry.get<int>(entity)), entity);
64 ASSERT_EQ(entt::to_entity(registry, registry.get<int>(other)), other);
65 ASSERT_EQ(entt::to_entity(registry, registry.get<int>(next)), next);
66
67 ASSERT_EQ(®istry.get<int>(entity) + ENTT_PACKED_PAGE - 1u, ®istry.get<int>(other));
68
69 registry.destroy(other);
70
71 ASSERT_EQ(entt::to_entity(registry, registry.get<int>(entity)), entity);
72 ASSERT_EQ(entt::to_entity(registry, registry.get<int>(next)), next);
73
74 ASSERT_EQ(®istry.get<int>(entity) + ENTT_PACKED_PAGE - 1u, ®istry.get<int>(next));
75
76 ASSERT_EQ(entt::to_entity(registry, 42), null);
77 ASSERT_EQ(entt::to_entity(registry, value), null);
78 }
79