|
|
@@ -1,4 +1,5 @@
|
|
|
#include <gtest/gtest.h>
|
|
|
+#include <entt/entity/component.hpp>
|
|
|
#include <entt/entity/entity.hpp>
|
|
|
#include <entt/entity/helper.hpp>
|
|
|
#include <entt/entity/registry.hpp>
|
|
|
@@ -11,16 +12,29 @@ struct clazz {
|
|
|
entt::entity entt{entt::null};
|
|
|
};
|
|
|
|
|
|
-struct stable_type {
|
|
|
- static constexpr auto in_place_delete = true;
|
|
|
- int value;
|
|
|
-};
|
|
|
-
|
|
|
void sigh_callback(int &value) {
|
|
|
++value;
|
|
|
}
|
|
|
|
|
|
-TEST(Helper, AsView) {
|
|
|
+struct pointer_stable {
|
|
|
+ static constexpr auto in_place_delete = true;
|
|
|
+ int value{};
|
|
|
+};
|
|
|
+
|
|
|
+template<typename Type>
|
|
|
+struct ToEntity: testing::Test {
|
|
|
+ using type = Type;
|
|
|
+};
|
|
|
+
|
|
|
+template<typename Type>
|
|
|
+using ToEntityDeprecated = ToEntity<Type>;
|
|
|
+
|
|
|
+using ToEntityTypes = ::testing::Types<int, pointer_stable>;
|
|
|
+
|
|
|
+TYPED_TEST_SUITE(ToEntity, ToEntityTypes, );
|
|
|
+TYPED_TEST_SUITE(ToEntityDeprecated, ToEntityTypes, );
|
|
|
+
|
|
|
+TEST(AsView, Functionalities) {
|
|
|
entt::registry registry;
|
|
|
const entt::registry cregistry;
|
|
|
|
|
|
@@ -30,7 +44,7 @@ TEST(Helper, AsView) {
|
|
|
([](entt::view<entt::get_t<const char, const double>, entt::exclude_t<const int>>) {})(entt::as_view{cregistry});
|
|
|
}
|
|
|
|
|
|
-TEST(Helper, AsGroup) {
|
|
|
+TEST(AsGroup, Functionalities) {
|
|
|
entt::registry registry;
|
|
|
const entt::registry cregistry;
|
|
|
|
|
|
@@ -39,7 +53,7 @@ TEST(Helper, AsGroup) {
|
|
|
([](entt::group<entt::owned_t<const double>, entt::get_t<const char>, entt::exclude_t<const int>>) {})(entt::as_group{cregistry});
|
|
|
}
|
|
|
|
|
|
-TEST(Helper, Invoke) {
|
|
|
+TEST(Invoke, Functionalities) {
|
|
|
entt::registry registry;
|
|
|
const auto entity = registry.create();
|
|
|
|
|
|
@@ -49,87 +63,93 @@ TEST(Helper, Invoke) {
|
|
|
ASSERT_EQ(entity, registry.get<clazz>(entity).entt);
|
|
|
}
|
|
|
|
|
|
-TEST(Helper, ToEntity) {
|
|
|
+TYPED_TEST(ToEntity, Functionalities) {
|
|
|
+ using value_type = typename TestFixture::type;
|
|
|
+ using traits_type = entt::component_traits<value_type>;
|
|
|
+
|
|
|
entt::registry registry;
|
|
|
const entt::entity null = entt::null;
|
|
|
- constexpr auto page_size = entt::storage_type_t<int>::traits_type::page_size;
|
|
|
- const int value = 42;
|
|
|
+ auto &storage = registry.storage<value_type>();
|
|
|
+ constexpr auto page_size = entt::storage_type_t<value_type>::traits_type::page_size;
|
|
|
+ const value_type value{42};
|
|
|
|
|
|
- ASSERT_EQ(entt::to_entity(registry, 42), null);
|
|
|
- ASSERT_EQ(entt::to_entity(registry, value), null);
|
|
|
+ ASSERT_EQ(entt::to_entity(storage, value_type{42}), null);
|
|
|
+ ASSERT_EQ(entt::to_entity(storage, value), null);
|
|
|
|
|
|
const auto entity = registry.create();
|
|
|
- auto &&storage = registry.storage<int>();
|
|
|
storage.emplace(entity);
|
|
|
|
|
|
- while(storage.size() < (page_size - 1u)) {
|
|
|
+ while(storage.size() < (page_size - (1u + traits_type::in_place_delete))) {
|
|
|
storage.emplace(registry.create(), value);
|
|
|
}
|
|
|
|
|
|
const auto other = registry.create();
|
|
|
const auto next = registry.create();
|
|
|
|
|
|
- registry.emplace<int>(other);
|
|
|
- registry.emplace<int>(next);
|
|
|
+ registry.emplace<value_type>(other);
|
|
|
+ registry.emplace<value_type>(next);
|
|
|
|
|
|
- ASSERT_EQ(entt::to_entity(registry, registry.get<int>(entity)), entity);
|
|
|
- ASSERT_EQ(entt::to_entity(registry, registry.get<int>(other)), other);
|
|
|
- ASSERT_EQ(entt::to_entity(registry, registry.get<int>(next)), next);
|
|
|
+ ASSERT_EQ(entt::to_entity(storage, registry.get<value_type>(entity)), entity);
|
|
|
+ ASSERT_EQ(entt::to_entity(storage, registry.get<value_type>(other)), other);
|
|
|
+ ASSERT_EQ(entt::to_entity(storage, registry.get<value_type>(next)), next);
|
|
|
|
|
|
- ASSERT_EQ(®istry.get<int>(entity) + page_size - 1u, ®istry.get<int>(other));
|
|
|
+ ASSERT_EQ(®istry.get<value_type>(entity) + page_size - (1u + traits_type::in_place_delete), ®istry.get<value_type>(other));
|
|
|
|
|
|
registry.destroy(other);
|
|
|
|
|
|
- ASSERT_EQ(entt::to_entity(registry, registry.get<int>(entity)), entity);
|
|
|
- ASSERT_EQ(entt::to_entity(registry, registry.get<int>(next)), next);
|
|
|
+ ASSERT_EQ(entt::to_entity(storage, registry.get<value_type>(entity)), entity);
|
|
|
+ ASSERT_EQ(entt::to_entity(storage, registry.get<value_type>(next)), next);
|
|
|
|
|
|
- ASSERT_EQ(®istry.get<int>(entity) + page_size - 1u, ®istry.get<int>(next));
|
|
|
+ ASSERT_EQ(®istry.get<value_type>(entity) + page_size - 1u, ®istry.get<value_type>(next));
|
|
|
|
|
|
- ASSERT_EQ(entt::to_entity(registry, 42), null);
|
|
|
- ASSERT_EQ(entt::to_entity(registry, value), null);
|
|
|
+ ASSERT_EQ(entt::to_entity(storage, value_type{42}), null);
|
|
|
+ ASSERT_EQ(entt::to_entity(storage, value), null);
|
|
|
}
|
|
|
|
|
|
-TEST(Helper, ToEntityStableType) {
|
|
|
+TYPED_TEST(ToEntityDeprecated, Functionalities) {
|
|
|
+ using value_type = typename TestFixture::type;
|
|
|
+ using traits_type = entt::component_traits<value_type>;
|
|
|
+
|
|
|
entt::registry registry;
|
|
|
const entt::entity null = entt::null;
|
|
|
- constexpr auto page_size = entt::storage_type_t<stable_type>::traits_type::page_size;
|
|
|
- const stable_type value{42};
|
|
|
+ constexpr auto page_size = entt::storage_type_t<value_type>::traits_type::page_size;
|
|
|
+ const value_type value{42};
|
|
|
|
|
|
- ASSERT_EQ(entt::to_entity(registry, stable_type{42}), null);
|
|
|
+ ASSERT_EQ(entt::to_entity(registry, value_type{42}), null);
|
|
|
ASSERT_EQ(entt::to_entity(registry, value), null);
|
|
|
|
|
|
const auto entity = registry.create();
|
|
|
- auto &&storage = registry.storage<stable_type>();
|
|
|
- registry.emplace<stable_type>(entity);
|
|
|
+ auto &&storage = registry.storage<value_type>();
|
|
|
+ storage.emplace(entity);
|
|
|
|
|
|
- while(storage.size() < (page_size - 2u)) {
|
|
|
+ while(storage.size() < (page_size - (1u + traits_type::in_place_delete))) {
|
|
|
storage.emplace(registry.create(), value);
|
|
|
}
|
|
|
|
|
|
const auto other = registry.create();
|
|
|
const auto next = registry.create();
|
|
|
|
|
|
- registry.emplace<stable_type>(other);
|
|
|
- registry.emplace<stable_type>(next);
|
|
|
+ registry.emplace<value_type>(other);
|
|
|
+ registry.emplace<value_type>(next);
|
|
|
|
|
|
- ASSERT_EQ(entt::to_entity(registry, registry.get<stable_type>(entity)), entity);
|
|
|
- ASSERT_EQ(entt::to_entity(registry, registry.get<stable_type>(other)), other);
|
|
|
- ASSERT_EQ(entt::to_entity(registry, registry.get<stable_type>(next)), next);
|
|
|
+ ASSERT_EQ(entt::to_entity(registry, registry.get<value_type>(entity)), entity);
|
|
|
+ ASSERT_EQ(entt::to_entity(registry, registry.get<value_type>(other)), other);
|
|
|
+ ASSERT_EQ(entt::to_entity(registry, registry.get<value_type>(next)), next);
|
|
|
|
|
|
- ASSERT_EQ(®istry.get<stable_type>(entity) + page_size - 2u, ®istry.get<stable_type>(other));
|
|
|
+ ASSERT_EQ(®istry.get<value_type>(entity) + page_size - (1u + traits_type::in_place_delete), ®istry.get<value_type>(other));
|
|
|
|
|
|
registry.destroy(other);
|
|
|
|
|
|
- ASSERT_EQ(entt::to_entity(registry, registry.get<stable_type>(entity)), entity);
|
|
|
- ASSERT_EQ(entt::to_entity(registry, registry.get<stable_type>(next)), next);
|
|
|
+ ASSERT_EQ(entt::to_entity(registry, registry.get<value_type>(entity)), entity);
|
|
|
+ ASSERT_EQ(entt::to_entity(registry, registry.get<value_type>(next)), next);
|
|
|
|
|
|
- ASSERT_EQ(®istry.get<stable_type>(entity) + page_size - 1u, ®istry.get<stable_type>(next));
|
|
|
+ ASSERT_EQ(®istry.get<value_type>(entity) + page_size - 1u, ®istry.get<value_type>(next));
|
|
|
|
|
|
- ASSERT_EQ(entt::to_entity(registry, stable_type{42}), null);
|
|
|
+ ASSERT_EQ(entt::to_entity(registry, value_type{42}), null);
|
|
|
ASSERT_EQ(entt::to_entity(registry, value), null);
|
|
|
}
|
|
|
|
|
|
-TEST(Helper, SighHelper) {
|
|
|
+TEST(SighHelper, Functionalities) {
|
|
|
using namespace entt::literals;
|
|
|
|
|
|
entt::registry registry{};
|