diff --git a/test/entt/entity/reactive_mixin.cpp b/test/entt/entity/reactive_mixin.cpp index e427af31f..8609818f4 100644 --- a/test/entt/entity/reactive_mixin.cpp +++ b/test/entt/entity/reactive_mixin.cpp @@ -221,6 +221,82 @@ ENTT_DEBUG_TYPED_TEST(ReactiveMixinDeathTest, OnConstruct) { ASSERT_DEATH(pool.template on_construct(), ""); } +TYPED_TEST(ReactiveMixin, OnUpdate) { + using value_type = typename TestFixture::type; + + entt::registry registry; + entt::reactive_mixin> pool; + const entt::entity entity{registry.create()}; + + pool.bind(registry); + registry.emplace(entity); + registry.patch(entity); + + ASSERT_FALSE(pool.contains(entity)); + + pool.template on_update(); + registry.patch(entity); + + ASSERT_FALSE(pool.contains(entity)); + + registry.on_update().disconnect(&pool); + pool.template on_update(); + registry.patch(entity); + + ASSERT_TRUE(pool.contains(entity)); + + registry.clear(); + + ASSERT_TRUE(pool.contains(entity)); + + registry.emplace(entity); + registry.emplace_or_replace(entity); + + ASSERT_TRUE(pool.contains(entity)); + + registry.destroy(entity); + + ASSERT_TRUE(pool.contains(entity)); +} + +TYPED_TEST(ReactiveMixin, OnUpdateCallback) { + using value_type = typename TestFixture::type; + + entt::registry registry; + entt::reactive_mixin> pool; + const std::array entity{registry.create(), registry.create(entt::entity{3})}; + + pool.bind(registry); + pool.template on_update>, 3u>>(); + registry.insert(entity.begin(), entity.end()); + registry.patch(entity[0u]); + + ASSERT_TRUE(pool.empty()); + + registry.patch(entity[1u]); + + ASSERT_EQ(pool.size(), 1u); + ASSERT_TRUE(pool.contains(entity[1u])); + + pool.clear(); + registry.clear(); + + ASSERT_TRUE(pool.empty()); + + registry.insert(entity.begin(), entity.end()); + registry.patch(entity[0u]); + registry.patch(entity[1u]); + + ASSERT_EQ(pool.size(), 1u); + ASSERT_TRUE(pool.contains(entity[1u])); +} + +ENTT_DEBUG_TYPED_TEST(ReactiveMixinDeathTest, OnUpdate) { + using value_type = typename TestFixture::type; + entt::reactive_mixin> pool; + ASSERT_DEATH(pool.template on_update(), ""); +} + TYPED_TEST(ReactiveMixin, ThrowingAllocator) { using value_type = typename TestFixture::type; using storage_type = entt::reactive_mixin>>;