Skip to content

Commit

Permalink
test: non-regression test for storage iterator page size deduction
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Jul 3, 2024
1 parent 060590b commit 7d8461b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions test/entt/entity/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ struct entt::component_traits<std::unordered_set<char>> {
static constexpr auto page_size = 4u;
};

template<>
struct entt::component_traits<int> {
static constexpr auto in_place_delete = false;
static constexpr auto page_size = 128u;
};

template<typename Type>
struct Storage: testing::Test {
static_assert(entt::component_traits<Type>::page_size != 0u, "Empty type not allowed");
Expand Down Expand Up @@ -533,16 +539,17 @@ TYPED_TEST(Storage, IteratorPageSizeAwareness) {
using traits_type = entt::component_traits<value_type>;
entt::storage<value_type> pool;

const value_type check{2};
static_assert(!std::is_same_v<value_type, int> || (traits_type::page_size != entt::component_traits<value_type *>::page_size), "Different page size required");

for(unsigned int next{}; next < traits_type::page_size; ++next) {
pool.emplace(entt::entity{next});
}

pool.emplace(entt::entity{traits_type::page_size}, check);
pool.emplace(entt::entity{traits_type::page_size});

// test the proper use of component traits by the storage iterator
ASSERT_EQ(*pool.begin(), check);
ASSERT_EQ(&pool.begin()[0], pool.raw()[1u]);
ASSERT_EQ(&pool.begin()[traits_type::page_size], pool.raw()[0u]);
}

TYPED_TEST(Storage, Getters) {
Expand Down

0 comments on commit 7d8461b

Please sign in to comment.