Browse Source

storage: test the proper use of component traits by the storage iterator

Michele Caini 3 years ago
parent
commit
9a97a57423
1 changed files with 16 additions and 1 deletions
  1. 16 1
      test/entt/entity/storage.cpp

+ 16 - 1
test/entt/entity/storage.cpp

@@ -83,7 +83,7 @@ struct create_from_constructor {
 template<>
 struct entt::component_traits<std::unordered_set<char>> {
     static constexpr auto in_place_delete = true;
-    static constexpr auto page_size = 128u;
+    static constexpr auto page_size = 4u;
 };
 
 inline bool operator==(const boxed_int &lhs, const boxed_int &rhs) {
@@ -1199,6 +1199,21 @@ TEST(Storage, IteratorConversion) {
     ASSERT_NE(++cit, it);
 }
 
+TEST(Storage, IteratorPageSizeAwareness) {
+    entt::storage<std::unordered_set<char>> pool;
+    constexpr auto page_size = entt::component_traits<std::unordered_set<char>>::page_size;
+    const std::unordered_set<char> check{'c'};
+
+    for(unsigned int next{}; next < page_size; ++next) {
+        pool.emplace(entt::entity{next});
+    }
+
+    pool.emplace(entt::entity{page_size}, check);
+
+    // test the proper use of component traits by the storage iterator
+    ASSERT_EQ(*pool.begin(), check);
+}
+
 TEST(Storage, Iterable) {
     using iterator = typename entt::storage<boxed_int>::iterable::iterator;