From 2ffd38a35510c968fcbc8afb9d89b549485321b5 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Thu, 26 Sep 2024 10:57:42 +0200 Subject: [PATCH] test: registry and custom registry support for reactive mixin --- test/entt/entity/reactive_mixin.cpp | 54 +++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/test/entt/entity/reactive_mixin.cpp b/test/entt/entity/reactive_mixin.cpp index 25fff7931..6813d123d 100644 --- a/test/entt/entity/reactive_mixin.cpp +++ b/test/entt/entity/reactive_mixin.cpp @@ -11,7 +11,9 @@ #include #include "../../common/config.h" #include "../../common/empty.h" +#include "../../common/entity.h" #include "../../common/linter.hpp" +#include "../../common/registry.h" #include "../../common/throwing_allocator.hpp" template @@ -26,6 +28,11 @@ void remove(Type &storage, const typename Type::registry_type &, const typename storage.remove(entity); } +template +struct entt::storage_type, std::enable_if_t>> { + using type = entt::basic_sigh_mixin, test::basic_custom_registry>; +}; + template struct ReactiveMixin: testing::Test { using type = Type; @@ -378,6 +385,53 @@ ENTT_DEBUG_TYPED_TEST(ReactiveMixinDeathTest, OnDestroy) { ASSERT_DEATH(pool.template on_destroy(), ""); } +TYPED_TEST(ReactiveMixin, Registry) { + using value_type = typename TestFixture::type; + + entt::registry registry; + entt::reactive_mixin> pool; + + ASSERT_FALSE(pool); + + pool.bind(registry); + + ASSERT_TRUE(pool); + ASSERT_EQ(&pool.registry(), ®istry); + ASSERT_EQ(&std::as_const(pool).registry(), ®istry); +} + +ENTT_DEBUG_TYPED_TEST(ReactiveMixinDeathTest, Registry) { + using value_type = typename TestFixture::type; + entt::reactive_mixin> pool; + ASSERT_DEATH([[maybe_unused]] auto ®istry = pool.registry(), ""); + ASSERT_DEATH([[maybe_unused]] const auto ®istry = std::as_const(pool).registry(), ""); +} + +TYPED_TEST(ReactiveMixin, CustomRegistry) { + using value_type = typename TestFixture::type; + using registry_type = test::basic_custom_registry; + + registry_type registry; + entt::basic_reactive_mixin, registry_type> pool; + const std::array entity{registry.create(), registry.create()}; + + pool.bind(static_cast &>(registry)); + pool.template on_construct(); + registry.insert(entity.begin(), entity.end()); + + ASSERT_EQ(pool.size(), 2u); + ASSERT_TRUE(pool.contains(entity[0u])); + ASSERT_TRUE(pool.contains(entity[1u])); +} + +ENTT_DEBUG_TYPED_TEST(ReactiveMixinDeathTest, CustomRegistry) { + using value_type = typename TestFixture::type; + using registry_type = test::basic_custom_registry; + entt::basic_reactive_mixin, registry_type> pool; + ASSERT_DEATH([[maybe_unused]] auto ®istry = pool.registry(), ""); + ASSERT_DEATH([[maybe_unused]] const auto ®istry = std::as_const(pool).registry(), ""); +} + TYPED_TEST(ReactiveMixin, ThrowingAllocator) { using value_type = typename TestFixture::type; using storage_type = entt::reactive_mixin>>;