aboutsummaryrefslogtreecommitdiff
path: root/src/test/ECSTest.cpp
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-11 14:33:12 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-11 14:33:12 +0100
commit68bf20b491b4b7673c2ece7a6497b9faffd44eb1 (patch)
treeec0aa56081bc744b595f1665f048c4d26242884f /src/test/ECSTest.cpp
parentf64b793ad8e796458c8e175f298e8d13eb3b3459 (diff)
parent78c4a8772526f40c531b5402b56932b0a41e22e8 (diff)
feedback but error after conflict
Diffstat (limited to 'src/test/ECSTest.cpp')
-rw-r--r--src/test/ECSTest.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/test/ECSTest.cpp b/src/test/ECSTest.cpp
index 3e6c61c..af2b7b0 100644
--- a/src/test/ECSTest.cpp
+++ b/src/test/ECSTest.cpp
@@ -1,6 +1,7 @@
#include <gtest/gtest.h>
#define protected public
+#define private public
#include <crepe/api/GameObject.h>
#include <crepe/api/Metadata.h>
@@ -16,6 +17,10 @@ class ECSTest : public ::testing::Test {
public:
ComponentManager mgr{m};
+
+ class TestComponent : public Component {
+ using Component::Component;
+ };
};
TEST_F(ECSTest, createGameObject) {
@@ -387,3 +392,77 @@ TEST_F(ECSTest, resetPersistent) {
EXPECT_EQ(metadata.size(), 0);
EXPECT_EQ(transform.size(), 0);
}
+
+TEST_F(ECSTest, IDByName) {
+ GameObject foo = mgr.new_object("foo");
+ GameObject bar = mgr.new_object("bar");
+
+ {
+ auto objects = mgr.get_objects_by_name("");
+ EXPECT_EQ(objects.size(), 0);
+ }
+
+ {
+ auto objects = mgr.get_objects_by_name("foo");
+ EXPECT_EQ(objects.size(), 1);
+ EXPECT_TRUE(objects.contains(foo.id));
+ }
+}
+
+TEST_F(ECSTest, IDByTag) {
+ GameObject foo = mgr.new_object("foo", "common tag");
+ GameObject bar = mgr.new_object("bar", "common tag");
+
+ {
+ auto objects = mgr.get_objects_by_tag("");
+ EXPECT_EQ(objects.size(), 0);
+ }
+
+ {
+ auto objects = mgr.get_objects_by_tag("common tag");
+ EXPECT_EQ(objects.size(), 2);
+ EXPECT_TRUE(objects.contains(foo.id));
+ EXPECT_TRUE(objects.contains(bar.id));
+ }
+}
+
+TEST_F(ECSTest, ComponentsByName) {
+ GameObject foo = mgr.new_object("foo");
+ foo.add_component<TestComponent>();
+ GameObject bar = mgr.new_object("bar");
+ bar.add_component<TestComponent>();
+ bar.add_component<TestComponent>();
+
+ {
+ auto objects = mgr.get_components_by_name<TestComponent>("");
+ EXPECT_EQ(objects.size(), 0);
+ }
+
+ {
+ auto objects = mgr.get_components_by_name<TestComponent>("foo");
+ EXPECT_EQ(objects.size(), 1);
+ }
+
+ {
+ auto objects = mgr.get_components_by_name<TestComponent>("bar");
+ EXPECT_EQ(objects.size(), 2);
+ }
+}
+
+TEST_F(ECSTest, ComponentsByTag) {
+ GameObject foo = mgr.new_object("foo", "common tag");
+ foo.add_component<TestComponent>();
+ GameObject bar = mgr.new_object("bar", "common tag");
+ bar.add_component<TestComponent>();
+ bar.add_component<TestComponent>();
+
+ {
+ auto objects = mgr.get_components_by_tag<TestComponent>("");
+ EXPECT_EQ(objects.size(), 0);
+ }
+
+ {
+ auto objects = mgr.get_components_by_tag<TestComponent>("common tag");
+ EXPECT_EQ(objects.size(), 3);
+ }
+}