Skip to content

Commit

Permalink
test: reactive mixin and custom allocators
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Sep 26, 2024
1 parent 2ffd38a commit 1de4b20
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions test/entt/entity/reactive_mixin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,58 @@ ENTT_DEBUG_TYPED_TEST(ReactiveMixinDeathTest, CustomRegistry) {
ASSERT_DEATH([[maybe_unused]] const auto &registry = std::as_const(pool).registry(), "");
}

TYPED_TEST(ReactiveMixin, CustomAllocator) {
using value_type = typename TestFixture::type;
using storage_type = entt::reactive_mixin<entt::basic_storage<value_type, entt::entity, test::throwing_allocator<value_type>>>;
using registry_type = typename storage_type::registry_type;

const test::throwing_allocator<entt::entity> allocator{};
storage_type pool{allocator};
registry_type registry;
const std::array entity{registry.create(), registry.create()};

pool.bind(registry);
pool.template on_construct<test::empty>();

pool.reserve(1u);

ASSERT_NE(pool.capacity(), 0u);

registry.template emplace<test::empty>(entity[0u]);
registry.template emplace<test::empty>(entity[1u]);

decltype(pool) other{std::move(pool), allocator};

test::is_initialized(pool);

ASSERT_TRUE(pool.empty());
ASSERT_FALSE(other.empty());
ASSERT_NE(other.capacity(), 0u);
ASSERT_EQ(other.size(), 2u);

pool = std::move(other);
test::is_initialized(other);

ASSERT_FALSE(pool.empty());
ASSERT_TRUE(other.empty());
ASSERT_NE(pool.capacity(), 0u);
ASSERT_EQ(pool.size(), 2u);

pool.swap(other);
pool = std::move(other);
test::is_initialized(other);

ASSERT_FALSE(pool.empty());
ASSERT_TRUE(other.empty());
ASSERT_NE(pool.capacity(), 0u);
ASSERT_EQ(pool.size(), 2u);

pool.clear();

ASSERT_NE(pool.capacity(), 0u);
ASSERT_EQ(pool.size(), 0u);
}

TYPED_TEST(ReactiveMixin, ThrowingAllocator) {
using value_type = typename TestFixture::type;
using storage_type = entt::reactive_mixin<entt::basic_storage<value_type, entt::entity, test::throwing_allocator<value_type>>>;
Expand Down

0 comments on commit 1de4b20

Please sign in to comment.