Sfoglia il codice sorgente

test: code coverage for groups and registry

Michele Caini 3 anni fa
parent
commit
5e346748ea
2 ha cambiato i file con 61 aggiunte e 0 eliminazioni
  1. 54 0
      test/entt/entity/group.cpp
  2. 7 0
      test/entt/entity/registry.cpp

+ 54 - 0
test/entt/entity/group.cpp

@@ -8,6 +8,7 @@
 #include <gtest/gtest.h>
 #include <entt/entity/group.hpp>
 #include <entt/entity/registry.hpp>
+#include "../common/config.h"
 
 struct empty_type {};
 
@@ -720,6 +721,32 @@ TEST(NonOwningGroup, Storage) {
     ASSERT_FALSE((registry.any_of<int, double, float>(entity)));
 }
 
+TEST(NonOwningGroup, Overlapping) {
+    entt::registry registry;
+
+    auto group = registry.group(entt::get<char>, entt::exclude<double>);
+    auto other = registry.group<int>(entt::get<char>, entt::exclude<double>);
+
+    ASSERT_TRUE(group.empty());
+    ASSERT_TRUE(other.empty());
+
+    const auto entity = registry.create();
+    registry.emplace<char>(entity, '1');
+
+    ASSERT_FALSE(group.empty());
+    ASSERT_TRUE(other.empty());
+
+    registry.emplace<int>(entity, 42);
+
+    ASSERT_FALSE(group.empty());
+    ASSERT_FALSE(other.empty());
+
+    registry.emplace<double>(entity, 3.);
+
+    ASSERT_TRUE(group.empty());
+    ASSERT_TRUE(other.empty());
+}
+
 TEST(OwningGroup, Functionalities) {
     entt::registry registry;
     auto group = registry.group<int>(entt::get<char>);
@@ -1552,3 +1579,30 @@ TEST(OwningGroup, Storage) {
     ASSERT_TRUE((registry.all_of<char>(entity)));
     ASSERT_FALSE((registry.any_of<int, double, float>(entity)));
 }
+
+TEST(OwningGroup, Overlapping) {
+    entt::registry registry;
+
+    auto group = registry.group<char>(entt::get<int>, entt::exclude<double>);
+    auto other = registry.group<char>(entt::get<int, float>, entt::exclude<double>);
+
+    ASSERT_TRUE(group.empty());
+    ASSERT_TRUE(other.empty());
+
+    const auto entity = registry.create();
+    registry.emplace<char>(entity, '1');
+    registry.emplace<int>(entity, 42);
+
+    ASSERT_FALSE(group.empty());
+    ASSERT_TRUE(other.empty());
+
+    registry.emplace<float>(entity, 7.f);
+
+    ASSERT_FALSE(group.empty());
+    ASSERT_FALSE(other.empty());
+
+    registry.emplace<double>(entity, 3.);
+
+    ASSERT_TRUE(group.empty());
+    ASSERT_TRUE(other.empty());
+}

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

@@ -1353,6 +1353,13 @@ TEST(Registry, NestedGroups) {
     ASSERT_EQ(g3.size(), 0u);
 }
 
+ENTT_DEBUG_TEST(Registry, ConflictingGroups) {
+    entt::registry registry;
+
+    [[maybe_unused]] auto group = registry.group<char>(entt::get<int>, entt::exclude<double>);
+    ASSERT_DEATH(auto other = registry.group<char>(entt::get<float>, entt::exclude<double>), "");
+}
+
 TEST(Registry, SortSingle) {
     entt::registry registry;