Bläddra i källkod

snapshot: code coverage

Michele Caini 2 år sedan
förälder
incheckning
77b5907a9f
2 ändrade filer med 9 tillägg och 3 borttagningar
  1. 1 3
      src/entt/entity/snapshot.hpp
  2. 8 0
      test/entt/entity/snapshot.cpp

+ 1 - 3
src/entt/entity/snapshot.hpp

@@ -172,9 +172,7 @@ public:
     basic_snapshot_loader(registry_type &source) noexcept
     basic_snapshot_loader(registry_type &source) noexcept
         : reg{&source} {
         : reg{&source} {
         // restoring a snapshot as a whole requires a clean registry
         // restoring a snapshot as a whole requires a clean registry
-        for([[maybe_unused]] auto elem: source.storage()) {
-            ENTT_ASSERT(elem.second.empty(), "Registry must be empty");
-        }
+        ENTT_ASSERT(reg->template storage<entity_type>().empty() && (reg->storage().begin() == reg->storage().end()), "Registry must be empty");
     }
     }
 
 
     /*! @brief Default move constructor. */
     /*! @brief Default move constructor. */

+ 8 - 0
test/entt/entity/snapshot.cpp

@@ -12,6 +12,7 @@
 #include <entt/entity/registry.hpp>
 #include <entt/entity/registry.hpp>
 #include <entt/entity/snapshot.hpp>
 #include <entt/entity/snapshot.hpp>
 #include <entt/signal/sigh.hpp>
 #include <entt/signal/sigh.hpp>
+#include "../common/config.h"
 
 
 struct empty {};
 struct empty {};
 
 
@@ -231,6 +232,13 @@ TEST(BasicSnapshotLoader, Constructors) {
     ASSERT_NO_FATAL_FAILURE(loader = std::move(other));
     ASSERT_NO_FATAL_FAILURE(loader = std::move(other));
 }
 }
 
 
+ENTT_DEBUG_TEST(BasicSnapshotLoaderDeathTest, Constructors) {
+    entt::registry registry;
+    registry.emplace<int>(registry.create());
+
+    ASSERT_DEATH([[maybe_unused]] entt::basic_snapshot_loader loader{registry}, "");
+}
+
 TEST(BasicSnapshotLoader, GetEntityType) {
 TEST(BasicSnapshotLoader, GetEntityType) {
     using namespace entt::literals;
     using namespace entt::literals;
     using traits_type = entt::entt_traits<entt::entity>;
     using traits_type = entt::entt_traits<entt::entity>;