Michele Caini 3 vuotta sitten
vanhempi
commit
c6707bec97
1 muutettua tiedostoa jossa 52 lisäystä ja 0 poistoa
  1. 52 0
      test/entt/entity/handle.cpp

+ 52 - 0
test/entt/entity/handle.cpp

@@ -2,6 +2,7 @@
 #include <type_traits>
 #include <utility>
 #include <gtest/gtest.h>
+#include <entt/core/type_info.hpp>
 #include <entt/entity/entity.hpp>
 #include <entt/entity/handle.hpp>
 #include <entt/entity/registry.hpp>
@@ -241,3 +242,54 @@ TEST(BasicHandle, ImplicitConversions) {
     ASSERT_EQ(vhandle.get<int>(), cvhandle.get<int>());
     ASSERT_EQ(cvhandle.get<int>(), 42);
 }
+
+TEST(BasicHandle, Storage) {
+    entt::registry registry;
+    const auto entity = registry.create();
+
+    entt::handle handle{registry, entity};
+    entt::const_handle chandle{std::as_const(registry), entity};
+
+    static_assert(std::is_same_v<decltype(*handle.storage().begin()), std::pair<entt::id_type, entt::sparse_set &>>);
+    static_assert(std::is_same_v<decltype(*chandle.storage().begin()), std::pair<entt::id_type, const entt::sparse_set &>>);
+
+    ASSERT_EQ(handle.storage().begin(), handle.storage().end());
+    ASSERT_EQ(chandle.storage().begin(), chandle.storage().end());
+
+    registry.storage<double>();
+    registry.emplace<int>(entity);
+
+    ASSERT_NE(handle.storage().begin(), handle.storage().end());
+    ASSERT_NE(chandle.storage().begin(), chandle.storage().end());
+
+    ASSERT_EQ(++handle.storage().begin(), handle.storage().end());
+    ASSERT_EQ(++chandle.storage().begin(), chandle.storage().end());
+
+    ASSERT_EQ(handle.storage().begin()->second.type(), entt::type_id<int>());
+    ASSERT_EQ(chandle.storage().begin()->second.type(), entt::type_id<int>());
+}
+
+TEST(BasicHandle, HandleStorageIterator) {
+    entt::registry registry;
+    const auto entity = registry.create();
+
+    registry.emplace<int>(entity);
+    registry.emplace<double>(entity);
+
+    auto test = [entity](auto iterable) {
+        auto end{iterable.begin()};
+        decltype(end) begin{};
+        begin = iterable.end();
+        std::swap(begin, end);
+
+        ASSERT_EQ(begin, iterable.cbegin());
+        ASSERT_EQ(end, iterable.cend());
+        ASSERT_NE(begin, end);
+
+        ASSERT_EQ(begin++, iterable.begin());
+        ASSERT_EQ(++begin, iterable.end());
+    };
+
+    test(entt::handle{registry, entity}.storage());
+    test(entt::const_handle{std::as_const(registry), entity}.storage());
+}