aboutsummaryrefslogtreecommitdiff
path: root/src/test/ECSTest.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-12-07 14:18:54 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-12-07 14:18:54 +0100
commit90c6bf03e59fdec64f850310bcbff45ae86f69e3 (patch)
treef80305e8b712e17c41a1860ec82a139842c67ba0 /src/test/ECSTest.cpp
parentf4824f5e7e6cee12bec602f3240770945a73d043 (diff)
more script utilities
Diffstat (limited to 'src/test/ECSTest.cpp')
-rw-r--r--src/test/ECSTest.cpp50
1 files changed, 48 insertions, 2 deletions
diff --git a/src/test/ECSTest.cpp b/src/test/ECSTest.cpp
index a169b3b..ed5341e 100644
--- a/src/test/ECSTest.cpp
+++ b/src/test/ECSTest.cpp
@@ -17,6 +17,10 @@ class ECSTest : public ::testing::Test {
public:
ComponentManager mgr{m};
+
+ class TestComponent : public Component {
+ using Component::Component;
+ };
};
TEST_F(ECSTest, createGameObject) {
@@ -389,7 +393,7 @@ TEST_F(ECSTest, resetPersistent) {
EXPECT_EQ(transform.size(), 0);
}
-TEST_F(ECSTest, GetByName) {
+TEST_F(ECSTest, IDByName) {
GameObject foo = mgr.new_object("foo");
GameObject bar = mgr.new_object("bar");
@@ -405,7 +409,7 @@ TEST_F(ECSTest, GetByName) {
}
}
-TEST_F(ECSTest, GetByTag) {
+TEST_F(ECSTest, IDByTag) {
GameObject foo = mgr.new_object("foo", "common tag");
GameObject bar = mgr.new_object("bar", "common tag");
@@ -421,3 +425,45 @@ TEST_F(ECSTest, GetByTag) {
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);
+ }
+}
+