diff --git a/test/entt/entity/reactive_mixin.cpp b/test/entt/entity/reactive_mixin.cpp index 08842f040..93f0f7648 100644 --- a/test/entt/entity/reactive_mixin.cpp +++ b/test/entt/entity/reactive_mixin.cpp @@ -1,8 +1,15 @@ +#include #include +#include +#include #include +#include #include #include +#include #include +#include "../../common/empty.h" +#include "../../common/linter.hpp" template struct ReactiveMixin: testing::Test { using type = Type; @@ -33,3 +40,65 @@ TYPED_TEST(ReactiveMixin, Constructors) { ASSERT_EQ(pool.type(), entt::type_id()); } +TYPED_TEST(ReactiveMixin, Move) { + using value_type = typename TestFixture::type; + + entt::registry registry; + entt::reactive_mixin> pool; + const std::array entity{registry.create(), registry.create()}; + + pool.bind(registry); + pool.template on_construct(); + pool.template on_update(); + registry.emplace(entity[0u]); + + static_assert(std::is_move_constructible_v, "Move constructible type required"); + static_assert(std::is_move_assignable_v, "Move assignable type required"); + + ASSERT_TRUE(pool.contains(entity[0u])); + ASSERT_EQ(pool.type(), entt::type_id()); + + entt::reactive_mixin> other{std::move(pool)}; + + test::is_initialized(pool); + + ASSERT_TRUE(pool.empty()); + ASSERT_FALSE(other.empty()); + + ASSERT_EQ(other.type(), entt::type_id()); + + ASSERT_EQ(other.index(entity[0u]), 0u); + ASSERT_EQ(&other.registry(), ®istry); + + other.clear(); + registry.replace(entity[0u]); + + ASSERT_FALSE(pool.empty()); + ASSERT_TRUE(other.empty()); + + std::swap(other, pool); + pool = std::move(other); + test::is_initialized(other); + + ASSERT_FALSE(pool.empty()); + ASSERT_TRUE(other.empty()); + + ASSERT_EQ(pool.index(entity[0u]), 0u); + ASSERT_EQ(&pool.registry(), ®istry); + + other = entt::reactive_mixin>{}; + other.bind(registry); + other.template on_construct(); + registry.on_construct().disconnect(&pool); + + registry.emplace(entity[1u]); + other = std::move(pool); + test::is_initialized(pool); + + ASSERT_FALSE(pool.empty()); + ASSERT_FALSE(other.empty()); + + ASSERT_EQ(other.index(entity[0u]), 0u); + ASSERT_EQ(&other.registry(), &pool.registry()); +} +