Просмотр исходного кода

test: stress assert on entity limit

Michele Caini 2 лет назад
Родитель
Сommit
916203a240
2 измененных файлов с 24 добавлено и 1 удалено
  1. 0 1
      TODO
  2. 24 0
      test/entt/entity/registry.cpp

+ 0 - 1
TODO

@@ -25,5 +25,4 @@ WIP:
 * exploit the tombstone mechanism to allow enabling/disabling entities (see bump, compact and clear for further details)
 * basic_storage::bind for cross-registry setups (see and remove todo from entity_copy.cpp)
 * process scheduler: reviews, use free lists internally
-* add test for maximum number of entities reached
 * deprecate non-owning groups in favor of owning views and view packs, introduce lazy owning views

+ 24 - 0
test/entt/entity/registry.cpp

@@ -85,6 +85,22 @@ private:
     bool *ctx_check{};
 };
 
+enum class small_entity : std::uint32_t {};
+
+struct small_entity_traits {
+    using value_type = small_entity;
+    using entity_type = uint32_t;
+    using version_type = uint16_t;
+    static constexpr entity_type entity_mask = 0xFF;
+    static constexpr entity_type version_mask = 0x00;
+};
+
+template<>
+struct entt::entt_traits<small_entity>: entt::basic_entt_traits<small_entity_traits> {
+    using base_type = entt::basic_entt_traits<small_entity_traits>;
+    static constexpr auto page_size = ENTT_SPARSE_PAGE;
+};
+
 TEST(Registry, Context) {
     entt::registry registry;
     auto &ctx = registry.ctx();
@@ -640,6 +656,14 @@ TEST(Registry, CreateDestroyReleaseCornerCase) {
     ASSERT_EQ(registry.current(e1), 1u);
 }
 
+ENTT_DEBUG_TEST(RegistryDeathTest, CreateTooManyEntities) {
+    entt::basic_registry<small_entity> registry;
+    std::vector<small_entity> entities(entt::entt_traits<small_entity>::to_entity(entt::null));
+    registry.create(entities.begin(), entities.end());
+
+    ASSERT_DEATH([[maybe_unused]] const auto entity = registry.create(), "");
+}
+
 TEST(Registry, DestroyVersion) {
     entt::registry registry;