aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authormax-001 <maxsmits21@kpnmail.nl>2024-12-20 12:01:36 +0100
committermax-001 <maxsmits21@kpnmail.nl>2024-12-20 12:01:36 +0100
commit79d3a9f4311e6684b6df83a15ca7844f58c1959c (patch)
treeb2883e83f61cee9edf290a6a7228c7f0b1fbae8a /src/test
parent9140b73e4af7aa925b53e4fb4e6aa7f4ea2e3385 (diff)
parent03aea832aa0bc2edba2cc5ab4d9f8eba42d355be (diff)
Merge remote-tracking branch 'origin/master' into max/game
Diffstat (limited to 'src/test')
-rw-r--r--src/test/AudioTest.cpp28
-rw-r--r--src/test/CMakeLists.txt3
-rw-r--r--src/test/CollisionTest.cpp116
-rw-r--r--src/test/DBTest.cpp8
-rw-r--r--src/test/ECSTest.cpp14
-rw-r--r--src/test/InputTest.cpp136
-rw-r--r--src/test/LoopManagerTest.cpp4
-rw-r--r--src/test/ParticleTest.cpp18
-rw-r--r--src/test/PhysicsTest.cpp18
-rw-r--r--src/test/Profiling.cpp24
-rw-r--r--src/test/RenderSystemTest.cpp6
-rw-r--r--src/test/ReplayManagerTest.cpp38
-rw-r--r--src/test/SaveManagerTest.cpp17
-rw-r--r--src/test/ScriptEventTest.cpp2
-rw-r--r--src/test/ScriptTest.cpp38
-rw-r--r--src/test/ScriptTest.h8
-rw-r--r--src/test/main.cpp3
17 files changed, 302 insertions, 179 deletions
diff --git a/src/test/AudioTest.cpp b/src/test/AudioTest.cpp
index 48bba1b..415a12e 100644
--- a/src/test/AudioTest.cpp
+++ b/src/test/AudioTest.cpp
@@ -50,11 +50,11 @@ TEST_F(AudioTest, Default) {
EXPECT_CALL(context, stop(_)).Times(0);
EXPECT_CALL(context, set_volume(_, _)).Times(0);
EXPECT_CALL(context, set_loop(_, _)).Times(0);
- system.update();
+ system.fixed_update();
}
TEST_F(AudioTest, Play) {
- system.update();
+ system.fixed_update();
{
InSequence seq;
@@ -67,12 +67,12 @@ TEST_F(AudioTest, Play) {
InSequence seq;
EXPECT_CALL(context, play(_)).Times(1);
- system.update();
+ system.fixed_update();
}
}
TEST_F(AudioTest, Stop) {
- system.update();
+ system.fixed_update();
{
InSequence seq;
@@ -85,12 +85,12 @@ TEST_F(AudioTest, Stop) {
InSequence seq;
EXPECT_CALL(context, stop(_)).Times(1);
- system.update();
+ system.fixed_update();
}
}
TEST_F(AudioTest, Volume) {
- system.update();
+ system.fixed_update();
{
InSequence seq;
@@ -103,12 +103,12 @@ TEST_F(AudioTest, Volume) {
InSequence seq;
EXPECT_CALL(context, set_volume(_, component.volume)).Times(1);
- system.update();
+ system.fixed_update();
}
}
TEST_F(AudioTest, Looping) {
- system.update();
+ system.fixed_update();
{
InSequence seq;
@@ -121,33 +121,33 @@ TEST_F(AudioTest, Looping) {
InSequence seq;
EXPECT_CALL(context, set_loop(_, component.loop)).Times(1);
- system.update();
+ system.fixed_update();
}
}
TEST_F(AudioTest, StopOnDeactivate) {
- system.update();
+ system.fixed_update();
{
InSequence seq;
EXPECT_CALL(context, stop(_)).Times(1);
component.active = false;
- system.update();
+ system.fixed_update();
}
}
TEST_F(AudioTest, PlayOnActive) {
component.active = false;
component.play_on_awake = true;
- system.update();
+ system.fixed_update();
{
InSequence seq;
EXPECT_CALL(context, play(_)).Times(1);
component.active = true;
- system.update();
+ system.fixed_update();
}
}
@@ -157,5 +157,5 @@ TEST_F(AudioTest, PlayImmediately) {
EXPECT_CALL(context, play(_)).Times(1);
- system.update();
+ system.fixed_update();
}
diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt
index 11b4ca9..ea92d96 100644
--- a/src/test/CMakeLists.txt
+++ b/src/test/CMakeLists.txt
@@ -15,7 +15,7 @@ target_sources(test_main PUBLIC
ValueBrokerTest.cpp
DBTest.cpp
Vector2Test.cpp
- LoopManagerTest.cpp
+ # LoopManagerTest.cpp
LoopTimerTest.cpp
InputTest.cpp
ScriptEventTest.cpp
@@ -24,4 +24,5 @@ target_sources(test_main PUBLIC
SaveManagerTest.cpp
ScriptSaveManagerTest.cpp
ScriptECSTest.cpp
+ ReplayManagerTest.cpp
)
diff --git a/src/test/CollisionTest.cpp b/src/test/CollisionTest.cpp
index ff9e7cc..c8d804c 100644
--- a/src/test/CollisionTest.cpp
+++ b/src/test/CollisionTest.cpp
@@ -54,6 +54,7 @@ public:
ComponentManager mgr{m};
CollisionSystem collision_sys{m};
ScriptSystem script_sys{m};
+ LoopTimerManager loop_timer{m};
GameObject world = mgr.new_object("world", "", {50, 50});
GameObject game_object1 = mgr.new_object("object1", "", {50, 50});
@@ -66,7 +67,6 @@ public:
world.add_component<Rigidbody>(Rigidbody::Data{
// TODO: remove unrelated properties:
.body_type = Rigidbody::BodyType::STATIC,
- .offset = {0, 0},
});
// Create a box with an inner size of 10x10 units
world.add_component<BoxCollider>(vec2{100, 100}, vec2{0, -100}); // Top
@@ -80,8 +80,7 @@ public:
.body_type = Rigidbody::BodyType::DYNAMIC,
.linear_velocity = {0, 0},
.constraints = {0, 0, 0},
- .elastisity_coefficient = 1,
- .offset = {0, 0},
+ .elasticity_coefficient = 1,
.collision_layers = {0},
});
game_object1.add_component<BoxCollider>(vec2{10, 10}, vec2{0, 0});
@@ -96,8 +95,7 @@ public:
.body_type = Rigidbody::BodyType::DYNAMIC,
.linear_velocity = {0, 0},
.constraints = {0, 0, 0},
- .elastisity_coefficient = 1,
- .offset = {0, 0},
+ .elasticity_coefficient = 1,
.collision_layers = {0},
});
game_object2.add_component<BoxCollider>(vec2{10, 10}, vec2{0, 0});
@@ -107,7 +105,7 @@ public:
ASSERT_NE(script_object2_ref, nullptr);
// Ensure Script::init() is called on all BehaviorScript instances
- script_sys.update();
+ script_sys.fixed_update();
}
};
@@ -115,14 +113,14 @@ TEST_F(CollisionTest, collision_example) {
bool collision_happend = false;
script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.this_collider.game_object_id, 1);
+ EXPECT_EQ(ev.info.self.transform.game_object_id, 1);
};
script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.this_collider.game_object_id, 2);
+ EXPECT_EQ(ev.info.self.transform.game_object_id, 2);
};
EXPECT_FALSE(collision_happend);
- collision_sys.update();
+ collision_sys.fixed_update();
EXPECT_FALSE(collision_happend);
}
@@ -130,22 +128,22 @@ TEST_F(CollisionTest, collision_box_box_dynamic_both_no_velocity) {
bool collision_happend = false;
script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.this_collider.game_object_id, 1);
+ EXPECT_EQ(ev.info.self.transform.game_object_id, 1);
EXPECT_EQ(ev.info.resolution.x, 10);
EXPECT_EQ(ev.info.resolution.y, 10);
EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::BOTH);
};
script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.this_collider.game_object_id, 2);
- EXPECT_EQ(ev.info.resolution.x, 10);
- EXPECT_EQ(ev.info.resolution.y, 10);
+ EXPECT_EQ(ev.info.self.transform.game_object_id, 2);
+ EXPECT_EQ(ev.info.resolution.x, -10);
+ EXPECT_EQ(ev.info.resolution.y, -10);
EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::BOTH);
};
EXPECT_FALSE(collision_happend);
Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get();
tf.position = {50, 30};
- collision_sys.update();
+ collision_sys.fixed_update();
EXPECT_TRUE(collision_happend);
}
@@ -153,7 +151,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_x_direction_no_velocity) {
bool collision_happend = false;
script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.this_collider.game_object_id, 1);
+ EXPECT_EQ(ev.info.self.transform.game_object_id, 1);
EXPECT_EQ(ev.info.resolution.x, -5);
EXPECT_EQ(ev.info.resolution.y, 0);
EXPECT_EQ(ev.info.resolution_direction,
@@ -161,7 +159,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_x_direction_no_velocity) {
};
script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.this_collider.game_object_id, 2);
+ EXPECT_EQ(ev.info.self.transform.game_object_id, 2);
EXPECT_EQ(ev.info.resolution.x, 5);
EXPECT_EQ(ev.info.resolution.y, 0);
EXPECT_EQ(ev.info.resolution_direction,
@@ -170,7 +168,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_x_direction_no_velocity) {
EXPECT_FALSE(collision_happend);
Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get();
tf.position = {45, 30};
- collision_sys.update();
+ collision_sys.fixed_update();
EXPECT_TRUE(collision_happend);
}
@@ -178,7 +176,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_y_direction_no_velocity) {
bool collision_happend = false;
script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.this_collider.game_object_id, 1);
+ EXPECT_EQ(ev.info.self.transform.game_object_id, 1);
EXPECT_EQ(ev.info.resolution.x, 0);
EXPECT_EQ(ev.info.resolution.y, -5);
EXPECT_EQ(ev.info.resolution_direction,
@@ -186,7 +184,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_y_direction_no_velocity) {
};
script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.this_collider.game_object_id, 2);
+ EXPECT_EQ(ev.info.self.transform.game_object_id, 2);
EXPECT_EQ(ev.info.resolution.x, 0);
EXPECT_EQ(ev.info.resolution.y, 5);
EXPECT_EQ(ev.info.resolution_direction,
@@ -195,7 +193,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_y_direction_no_velocity) {
EXPECT_FALSE(collision_happend);
Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get();
tf.position = {50, 25};
- collision_sys.update();
+ collision_sys.fixed_update();
EXPECT_TRUE(collision_happend);
}
@@ -203,16 +201,16 @@ TEST_F(CollisionTest, collision_box_box_dynamic_both) {
bool collision_happend = false;
script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.this_collider.game_object_id, 1);
+ EXPECT_EQ(ev.info.self.transform.game_object_id, 1);
EXPECT_EQ(ev.info.resolution.x, 10);
EXPECT_EQ(ev.info.resolution.y, 10);
EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::BOTH);
};
script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.this_collider.game_object_id, 2);
- EXPECT_EQ(ev.info.resolution.x, 10);
- EXPECT_EQ(ev.info.resolution.y, 10);
+ EXPECT_EQ(ev.info.self.transform.game_object_id, 2);
+ EXPECT_EQ(ev.info.resolution.x, -10);
+ EXPECT_EQ(ev.info.resolution.y, -10);
EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::BOTH);
};
EXPECT_FALSE(collision_happend);
@@ -222,7 +220,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_both) {
rg1.data.linear_velocity = {10, 10};
Rigidbody & rg2 = this->mgr.get_components_by_id<Rigidbody>(2).front().get();
rg2.data.linear_velocity = {10, 10};
- collision_sys.update();
+ collision_sys.fixed_update();
EXPECT_TRUE(collision_happend);
}
@@ -230,7 +228,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_x_direction) {
bool collision_happend = false;
script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.this_collider.game_object_id, 1);
+ EXPECT_EQ(ev.info.self.transform.game_object_id, 1);
EXPECT_EQ(ev.info.resolution.x, -5);
EXPECT_EQ(ev.info.resolution.y, 5);
EXPECT_EQ(ev.info.resolution_direction,
@@ -238,7 +236,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_x_direction) {
};
script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.this_collider.game_object_id, 2);
+ EXPECT_EQ(ev.info.self.transform.game_object_id, 2);
EXPECT_EQ(ev.info.resolution.x, 5);
EXPECT_EQ(ev.info.resolution.y, -5);
EXPECT_EQ(ev.info.resolution_direction,
@@ -251,7 +249,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_x_direction) {
rg1.data.linear_velocity = {10, 10};
Rigidbody & rg2 = this->mgr.get_components_by_id<Rigidbody>(2).front().get();
rg2.data.linear_velocity = {10, 10};
- collision_sys.update();
+ collision_sys.fixed_update();
EXPECT_TRUE(collision_happend);
}
@@ -259,7 +257,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_y_direction) {
bool collision_happend = false;
script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.this_collider.game_object_id, 1);
+ EXPECT_EQ(ev.info.self.transform.game_object_id, 1);
EXPECT_EQ(ev.info.resolution.x, 5);
EXPECT_EQ(ev.info.resolution.y, -5);
EXPECT_EQ(ev.info.resolution_direction,
@@ -267,7 +265,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_y_direction) {
};
script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.this_collider.game_object_id, 2);
+ EXPECT_EQ(ev.info.self.transform.game_object_id, 2);
EXPECT_EQ(ev.info.resolution.x, -5);
EXPECT_EQ(ev.info.resolution.y, 5);
EXPECT_EQ(ev.info.resolution_direction,
@@ -280,7 +278,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_y_direction) {
rg1.data.linear_velocity = {10, 10};
Rigidbody & rg2 = this->mgr.get_components_by_id<Rigidbody>(2).front().get();
rg2.data.linear_velocity = {10, 10};
- collision_sys.update();
+ collision_sys.fixed_update();
EXPECT_TRUE(collision_happend);
}
@@ -288,21 +286,19 @@ TEST_F(CollisionTest, collision_box_box_static_both) {
bool collision_happend = false;
script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.this_collider.game_object_id, 1);
+ EXPECT_EQ(ev.info.self.transform.game_object_id, 1);
EXPECT_EQ(ev.info.resolution.x, 10);
EXPECT_EQ(ev.info.resolution.y, 10);
EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::BOTH);
};
- script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
- // is static should not be called
- FAIL();
- };
+ script_object2_ref->test_fn
+ = [&collision_happend](const CollisionEvent & ev) { collision_happend = true; };
EXPECT_FALSE(collision_happend);
Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get();
tf.position = {50, 30};
Rigidbody & rg2 = this->mgr.get_components_by_id<Rigidbody>(2).front().get();
rg2.data.body_type = crepe::Rigidbody::BodyType::STATIC;
- collision_sys.update();
+ collision_sys.fixed_update();
EXPECT_TRUE(collision_happend);
}
@@ -310,7 +306,7 @@ TEST_F(CollisionTest, collision_box_box_static_x_direction) {
bool collision_happend = false;
script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.this_collider.game_object_id, 1);
+ EXPECT_EQ(ev.info.self.transform.game_object_id, 1);
EXPECT_EQ(ev.info.resolution.x, -5);
EXPECT_EQ(ev.info.resolution.y, 5);
EXPECT_EQ(ev.info.resolution_direction,
@@ -318,7 +314,7 @@ TEST_F(CollisionTest, collision_box_box_static_x_direction) {
};
script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
// is static should not be called
- FAIL();
+ //FAIL();
};
EXPECT_FALSE(collision_happend);
Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get();
@@ -327,7 +323,7 @@ TEST_F(CollisionTest, collision_box_box_static_x_direction) {
rg1.data.linear_velocity = {10, 10};
Rigidbody & rg2 = this->mgr.get_components_by_id<Rigidbody>(2).front().get();
rg2.data.body_type = crepe::Rigidbody::BodyType::STATIC;
- collision_sys.update();
+ collision_sys.fixed_update();
EXPECT_TRUE(collision_happend);
}
@@ -335,7 +331,7 @@ TEST_F(CollisionTest, collision_box_box_static_y_direction) {
bool collision_happend = false;
script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.this_collider.game_object_id, 1);
+ EXPECT_EQ(ev.info.self.transform.game_object_id, 1);
EXPECT_EQ(ev.info.resolution.x, 5);
EXPECT_EQ(ev.info.resolution.y, -5);
EXPECT_EQ(ev.info.resolution_direction,
@@ -343,7 +339,7 @@ TEST_F(CollisionTest, collision_box_box_static_y_direction) {
};
script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
// is static should not be called
- FAIL();
+ //FAIL();
};
EXPECT_FALSE(collision_happend);
Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get();
@@ -352,40 +348,6 @@ TEST_F(CollisionTest, collision_box_box_static_y_direction) {
rg1.data.linear_velocity = {10, 10};
Rigidbody & rg2 = this->mgr.get_components_by_id<Rigidbody>(2).front().get();
rg2.data.body_type = crepe::Rigidbody::BodyType::STATIC;
- collision_sys.update();
- EXPECT_TRUE(collision_happend);
-}
-
-TEST_F(CollisionTest, collision_box_box_static_multiple) { //todo check visually
- bool collision_happend = false;
- float offset_value = 0;
- float resolution = 0;
- script_object1_ref->test_fn = [&](const CollisionEvent & ev) {
- collision_happend = true;
- EXPECT_EQ(ev.info.this_collider.game_object_id, 1);
- EXPECT_EQ(ev.info.this_collider.offset.x, offset_value);
- EXPECT_EQ(ev.info.resolution.x, resolution);
- };
- script_object2_ref->test_fn = [&](const CollisionEvent & ev) {
- // is static should not be called
- FAIL();
- };
- EXPECT_FALSE(collision_happend);
- Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get();
- tf.position = {45, 30};
- Rigidbody & rg1 = this->mgr.get_components_by_id<Rigidbody>(1).front().get();
- rg1.data.linear_velocity = {10, 10};
- Rigidbody & rg2 = this->mgr.get_components_by_id<Rigidbody>(2).front().get();
- rg2.data.body_type = crepe::Rigidbody::BodyType::STATIC;
- BoxCollider & bxc = this->mgr.get_components_by_id<BoxCollider>(1).front().get();
- bxc.offset = {5, 0};
- this->game_object1.add_component<BoxCollider>(vec2{-5, 0}, vec2{10, 10});
- offset_value = 5;
- resolution = 10;
- collision_sys.update();
- offset_value = -5;
- resolution = 10;
- tf.position = {55, 30};
- collision_sys.update();
+ collision_sys.fixed_update();
EXPECT_TRUE(collision_happend);
}
diff --git a/src/test/DBTest.cpp b/src/test/DBTest.cpp
index 99dedff..7f2c339 100644
--- a/src/test/DBTest.cpp
+++ b/src/test/DBTest.cpp
@@ -27,3 +27,11 @@ TEST_F(DBTest, Has) {
db.set("foo", "bar");
EXPECT_EQ(db.has("foo"), true);
}
+
+TEST_F(DBTest, MultipleKeys) {
+ db.set("foo", "foo");
+ db.set("bar", "bar");
+
+ EXPECT_EQ(db.get("foo"), "foo");
+ EXPECT_EQ(db.get("bar"), "bar");
+}
diff --git a/src/test/ECSTest.cpp b/src/test/ECSTest.cpp
index af2b7b0..8f86a91 100644
--- a/src/test/ECSTest.cpp
+++ b/src/test/ECSTest.cpp
@@ -466,3 +466,17 @@ TEST_F(ECSTest, ComponentsByTag) {
EXPECT_EQ(objects.size(), 3);
}
}
+
+TEST_F(ECSTest, Snapshot) {
+ GameObject foo = mgr.new_object("foo");
+
+ foo.transform.position = {1, 1};
+
+ ComponentManager::Snapshot snapshot = mgr.save();
+
+ foo.transform.position = {0, 0};
+
+ mgr.restore(snapshot);
+
+ EXPECT_EQ(foo.transform.position, (vec2{1, 1}));
+}
diff --git a/src/test/InputTest.cpp b/src/test/InputTest.cpp
index d893276..0243bd8 100644
--- a/src/test/InputTest.cpp
+++ b/src/test/InputTest.cpp
@@ -1,7 +1,10 @@
-#include "system/RenderSystem.h"
#include <gtest/gtest.h>
+
+#include <crepe/manager/ResourceManager.h>
+#include <crepe/system/RenderSystem.h>
#define protected public
#define private public
+
#include "api/KeyCodes.h"
#include "manager/ComponentManager.h"
#include "manager/EventManager.h"
@@ -29,17 +32,19 @@ public:
SDLContext sdl_context{mediator};
InputSystem input_system{mediator};
+ ResourceManager resman{mediator};
RenderSystem render{mediator};
EventManager event_manager{mediator};
//GameObject camera;
+ vec2 offset = {100, 200};
protected:
void SetUp() override {
- GameObject obj = mgr.new_object("camera", "camera", vec2{0, 0}, 0, 1);
+ GameObject obj = mgr.new_object("camera", "camera", offset, 0, 1);
auto & camera
= obj.add_component<Camera>(ivec2{500, 500}, vec2{500, 500},
Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f});
- render.update();
+ render.frame_update();
//mediator.event_manager = event_manager;
//mediator.component_manager = mgr;
//event_manager.clear();
@@ -71,8 +76,7 @@ TEST_F(InputTest, MouseDown) {
EventHandler<MousePressEvent> on_mouse_down = [&](const MousePressEvent & event) {
mouse_triggered = true;
//middle of the screen = 0,0
- EXPECT_EQ(event.mouse_pos.x, 0);
- EXPECT_EQ(event.mouse_pos.y, 0);
+ EXPECT_EQ(event.mouse_pos, offset);
EXPECT_EQ(event.button, MouseButton::LEFT_MOUSE);
return false;
};
@@ -87,7 +91,7 @@ TEST_F(InputTest, MouseDown) {
event.button.button = SDL_BUTTON_LEFT;
SDL_PushEvent(&event);
- input_system.update();
+ input_system.fixed_update();
event_manager.dispatch_events();
EXPECT_TRUE(mouse_triggered);
}
@@ -96,8 +100,7 @@ TEST_F(InputTest, MouseUp) {
bool function_triggered = false;
EventHandler<MouseReleaseEvent> on_mouse_release = [&](const MouseReleaseEvent & e) {
function_triggered = true;
- EXPECT_EQ(e.mouse_pos.x, 0);
- EXPECT_EQ(e.mouse_pos.y, 0);
+ EXPECT_EQ(e.mouse_pos, offset);
EXPECT_EQ(e.button, MouseButton::LEFT_MOUSE);
return false;
};
@@ -111,7 +114,7 @@ TEST_F(InputTest, MouseUp) {
event.button.button = SDL_BUTTON_LEFT;
SDL_PushEvent(&event);
- input_system.update();
+ input_system.fixed_update();
event_manager.dispatch_events();
EXPECT_TRUE(function_triggered);
}
@@ -120,8 +123,7 @@ TEST_F(InputTest, MouseMove) {
bool function_triggered = false;
EventHandler<MouseMoveEvent> on_mouse_move = [&](const MouseMoveEvent & e) {
function_triggered = true;
- EXPECT_EQ(e.mouse_pos.x, 0);
- EXPECT_EQ(e.mouse_pos.y, 0);
+ EXPECT_EQ(e.mouse_pos, offset);
EXPECT_EQ(e.mouse_delta.x, 10);
EXPECT_EQ(e.mouse_delta.y, 10);
return false;
@@ -137,7 +139,7 @@ TEST_F(InputTest, MouseMove) {
event.motion.yrel = 10;
SDL_PushEvent(&event);
- input_system.update();
+ input_system.fixed_update();
event_manager.dispatch_events();
EXPECT_TRUE(function_triggered);
}
@@ -163,7 +165,7 @@ TEST_F(InputTest, KeyDown) {
test_event.key.repeat = 1; // Set repeat flag
SDL_PushEvent(&test_event);
- input_system.update(); // Process the event
+ input_system.fixed_update(); // Process the event
event_manager.dispatch_events(); // Dispatch events to handlers
EXPECT_TRUE(function_triggered); // Check if the handler was triggered
@@ -184,7 +186,7 @@ TEST_F(InputTest, KeyUp) {
event.key.keysym.scancode = SDL_SCANCODE_B;
SDL_PushEvent(&event);
- input_system.update();
+ input_system.fixed_update();
event_manager.dispatch_events();
EXPECT_TRUE(function_triggered);
}
@@ -194,14 +196,13 @@ TEST_F(InputTest, MouseClick) {
EventHandler<MouseClickEvent> on_mouse_click = [&](const MouseClickEvent & event) {
on_click_triggered = true;
EXPECT_EQ(event.button, MouseButton::LEFT_MOUSE);
- EXPECT_EQ(event.mouse_pos.x, 0);
- EXPECT_EQ(event.mouse_pos.y, 0);
+ EXPECT_EQ(event.mouse_pos, offset);
return false;
};
event_manager.subscribe<MouseClickEvent>(on_mouse_click);
this->simulate_mouse_click(250, 250, SDL_BUTTON_LEFT);
- input_system.update();
+ input_system.fixed_update();
event_manager.dispatch_events();
EXPECT_TRUE(on_click_triggered);
}
@@ -209,43 +210,85 @@ TEST_F(InputTest, MouseClick) {
TEST_F(InputTest, testButtonClick) {
GameObject button_obj = mgr.new_object("body", "person", vec2{0, 0}, 0, 1);
bool button_clicked = false;
- std::function<void()> on_click = [&]() { button_clicked = true; };
- auto & button = button_obj.add_component<Button>(vec2{100, 100}, vec2{0, 0}, on_click);
+ event_manager.subscribe<ButtonPressEvent>([&](const ButtonPressEvent & event) {
+ button_clicked = true;
+ EXPECT_EQ(event.metadata.game_object_id, button_obj.id);
+ return false;
+ });
+ auto & button = button_obj.add_component<Button>(vec2{100, 100}, vec2{0, 0});
bool hover = false;
button.active = true;
this->simulate_mouse_click(999, 999, SDL_BUTTON_LEFT);
- input_system.update();
+ input_system.fixed_update();
event_manager.dispatch_events();
EXPECT_FALSE(button_clicked);
this->simulate_mouse_click(250, 250, SDL_BUTTON_LEFT);
- input_system.update();
+ input_system.fixed_update();
event_manager.dispatch_events();
EXPECT_TRUE(button_clicked);
}
-
-TEST_F(InputTest, testButtonHover) {
- GameObject button_obj = mgr.new_object("body", "person", vec2{0, 0}, 0, 1);
+TEST_F(InputTest, buttonPositionCamera) {
+ GameObject button_obj = mgr.new_object("body", "person", vec2{50, 50}, 0, 1);
bool button_clicked = false;
- std::function<void()> on_click = [&]() { button_clicked = true; };
- auto & button = button_obj.add_component<Button>(vec2{100, 100}, vec2{0, 0}, on_click);
- button.active = true;
+ event_manager.subscribe<ButtonPressEvent>([&](const ButtonPressEvent & event) {
+ button_clicked = true;
+ EXPECT_EQ(event.metadata.game_object_id, button_obj.id);
+ return false;
+ });
+ auto & button = button_obj.add_component<Button>(vec2{10, 10}, vec2{0, 0});
- // Mouse not on button
- SDL_Event event;
- SDL_zero(event);
- event.type = SDL_MOUSEMOTION;
- event.motion.x = 700;
- event.motion.y = 700;
- event.motion.xrel = 10;
- event.motion.yrel = 10;
- SDL_PushEvent(&event);
+ button.world_space = false;
+ bool hover = false;
+ button.active = true;
+ this->simulate_mouse_click(999, 999, SDL_BUTTON_LEFT);
+ input_system.fixed_update();
+ event_manager.dispatch_events();
+ EXPECT_FALSE(button_clicked);
- input_system.update();
+ this->simulate_mouse_click(300, 300, SDL_BUTTON_LEFT);
+ input_system.fixed_update();
event_manager.dispatch_events();
- EXPECT_FALSE(button.hover);
+ EXPECT_TRUE(button_clicked);
+}
+TEST_F(InputTest, buttonPositionWorld) {
+ GameObject button_obj = mgr.new_object("body", "person", vec2{50, 50}, 0, 1);
+ bool button_clicked = false;
+ event_manager.subscribe<ButtonPressEvent>([&](const ButtonPressEvent & event) {
+ button_clicked = true;
+ EXPECT_EQ(event.metadata.game_object_id, button_obj.id);
+ return false;
+ });
+ auto & button = button_obj.add_component<Button>(vec2{10, 10}, vec2{0, 0});
+ button.world_space = true;
+ bool hover = false;
+ button.active = true;
+ this->simulate_mouse_click(999, 999, SDL_BUTTON_LEFT);
+ input_system.fixed_update();
+ event_manager.dispatch_events();
+ EXPECT_FALSE(button_clicked);
+ this->simulate_mouse_click(300, 300, SDL_BUTTON_LEFT);
+ input_system.fixed_update();
+ event_manager.dispatch_events();
+ EXPECT_FALSE(button_clicked);
+}
+TEST_F(InputTest, testButtonHover) {
+ GameObject button_obj = mgr.new_object("body", "person", vec2{0, 0}, 0, 1);
+ bool button_hover = false;
+ event_manager.subscribe<ButtonEnterEvent>([&](const ButtonEnterEvent & event) {
+ button_hover = true;
+ EXPECT_EQ(event.metadata.game_object_id, button_obj.id);
+ return false;
+ });
+ event_manager.subscribe<ButtonExitEvent>([&](const ButtonExitEvent & event) {
+ button_hover = false;
+ EXPECT_EQ(event.metadata.game_object_id, button_obj.id);
+ return false;
+ });
+ auto & button = button_obj.add_component<Button>(vec2{100, 100}, vec2{0, 0});
+ button.active = true;
// Mouse on button
SDL_Event hover_event;
SDL_zero(hover_event);
@@ -256,7 +299,22 @@ TEST_F(InputTest, testButtonHover) {
hover_event.motion.yrel = 10;
SDL_PushEvent(&hover_event);
- input_system.update();
+ input_system.fixed_update();
event_manager.dispatch_events();
EXPECT_TRUE(button.hover);
+ EXPECT_TRUE(button_hover);
+ // Mouse not on button
+ SDL_Event event;
+ SDL_zero(event);
+ event.type = SDL_MOUSEMOTION;
+ event.motion.x = 500;
+ event.motion.y = 500;
+ event.motion.xrel = 10;
+ event.motion.yrel = 10;
+ SDL_PushEvent(&event);
+
+ input_system.fixed_update();
+ event_manager.dispatch_events();
+ EXPECT_FALSE(button.hover);
+ EXPECT_FALSE(button_hover);
}
diff --git a/src/test/LoopManagerTest.cpp b/src/test/LoopManagerTest.cpp
index df132ae..f6653fa 100644
--- a/src/test/LoopManagerTest.cpp
+++ b/src/test/LoopManagerTest.cpp
@@ -4,7 +4,7 @@
#include <thread>
#define private public
#define protected public
-#include <crepe/api/LoopManager.h>
+#include <crepe/api/Engine.h>
#include <crepe/manager/EventManager.h>
#include <crepe/manager/LoopTimerManager.h>
using namespace std::chrono;
@@ -12,7 +12,7 @@ using namespace crepe;
class DISABLED_LoopManagerTest : public ::testing::Test {
protected:
- class TestGameLoop : public crepe::LoopManager {
+ class TestGameLoop : public crepe::Engine {
public:
MOCK_METHOD(void, fixed_update, (), (override));
MOCK_METHOD(void, frame_update, (), (override));
diff --git a/src/test/ParticleTest.cpp b/src/test/ParticleTest.cpp
index 9263e00..7a731a3 100644
--- a/src/test/ParticleTest.cpp
+++ b/src/test/ParticleTest.cpp
@@ -97,18 +97,18 @@ TEST_F(ParticlesTest, spawnParticle) {
emitter.data.max_angle = 0.1;
emitter.data.max_speed = 10;
emitter.data.max_angle = 10;
- particle_system.update();
+ particle_system.fixed_update();
//check if nothing happend
EXPECT_EQ(emitter.particles[0].active, false);
emitter.data.emission_rate = 50;
//check particle spawnes
- particle_system.update();
+ particle_system.fixed_update();
EXPECT_EQ(emitter.particles[0].active, true);
- particle_system.update();
+ particle_system.fixed_update();
EXPECT_EQ(emitter.particles[1].active, true);
- particle_system.update();
+ particle_system.fixed_update();
EXPECT_EQ(emitter.particles[2].active, true);
- particle_system.update();
+ particle_system.fixed_update();
EXPECT_EQ(emitter.particles[3].active, true);
for (auto & particle : emitter.particles) {
@@ -142,7 +142,7 @@ TEST_F(ParticlesTest, moveParticleHorizontal) {
emitter.data.max_angle = 0;
emitter.data.emission_rate = 50;
for (int a = 1; a < emitter.data.boundary.width / 2; a++) {
- particle_system.update();
+ particle_system.fixed_update();
EXPECT_EQ(emitter.particles[0].position.x, a);
}
}
@@ -160,7 +160,7 @@ TEST_F(ParticlesTest, moveParticleVertical) {
emitter.data.max_angle = 90;
emitter.data.emission_rate = 50;
for (int a = 1; a < emitter.data.boundary.width / 2; a++) {
- particle_system.update();
+ particle_system.fixed_update();
EXPECT_EQ(emitter.particles[0].position.y, a);
}
}
@@ -179,7 +179,7 @@ TEST_F(ParticlesTest, boundaryParticleReset) {
emitter.data.max_angle = 90;
emitter.data.emission_rate = 1;
for (int a = 0; a < emitter.data.boundary.width / 2 + 1; a++) {
- particle_system.update();
+ particle_system.fixed_update();
}
EXPECT_EQ(emitter.particles[0].active, false);
}
@@ -198,7 +198,7 @@ TEST_F(ParticlesTest, boundaryParticleStop) {
emitter.data.max_angle = 90;
emitter.data.emission_rate = 1;
for (int a = 0; a < emitter.data.boundary.width / 2 + 1; a++) {
- particle_system.update();
+ particle_system.fixed_update();
}
const double TOLERANCE = 0.01;
EXPECT_NEAR(emitter.particles[0].velocity.x, 0, TOLERANCE);
diff --git a/src/test/PhysicsTest.cpp b/src/test/PhysicsTest.cpp
index 3afb3c7..79ed0b8 100644
--- a/src/test/PhysicsTest.cpp
+++ b/src/test/PhysicsTest.cpp
@@ -57,10 +57,10 @@ TEST_F(PhysicsTest, gravity) {
ASSERT_FALSE(transforms.empty());
EXPECT_EQ(transform.position.y, 0);
- system.update();
+ system.fixed_update();
EXPECT_NEAR(transform.position.y, 0.0004, 0.0001);
- system.update();
+ system.fixed_update();
EXPECT_NEAR(transform.position.y, 0.002, 0.001);
}
@@ -74,14 +74,14 @@ TEST_F(PhysicsTest, max_velocity) {
rigidbody.add_force_linear({100, 100});
rigidbody.add_force_angular(100);
- system.update();
+ system.fixed_update();
EXPECT_NEAR(rigidbody.data.linear_velocity.y, 7.07, 0.01);
EXPECT_NEAR(rigidbody.data.linear_velocity.x, 7.07, 0.01);
EXPECT_EQ(rigidbody.data.angular_velocity, 10);
rigidbody.add_force_linear({-100, -100});
rigidbody.add_force_angular(-100);
- system.update();
+ system.fixed_update();
EXPECT_NEAR(rigidbody.data.linear_velocity.y, -7.07, 0.01);
EXPECT_NEAR(rigidbody.data.linear_velocity.x, -7.07, 0.01);
EXPECT_EQ(rigidbody.data.angular_velocity, -10);
@@ -99,7 +99,7 @@ TEST_F(PhysicsTest, movement) {
rigidbody.add_force_linear({1, 1});
rigidbody.add_force_angular(1);
- system.update();
+ system.fixed_update();
EXPECT_NEAR(transform.position.x, 0.02, 0.001);
EXPECT_NEAR(transform.position.y, 0.02, 0.001);
EXPECT_NEAR(transform.rotation, 0.02, 0.001);
@@ -112,7 +112,7 @@ TEST_F(PhysicsTest, movement) {
rigidbody.data.linear_velocity_coefficient.x = 0.5;
rigidbody.data.linear_velocity_coefficient.y = 0.5;
rigidbody.data.angular_velocity_coefficient = 0.5;
- system.update();
+ system.fixed_update();
EXPECT_NEAR(rigidbody.data.linear_velocity.x, 0.98, 0.01);
EXPECT_NEAR(rigidbody.data.linear_velocity.y, 0.98, 0.01);
EXPECT_NEAR(rigidbody.data.angular_velocity, 0.98, 0.01);
@@ -121,12 +121,12 @@ TEST_F(PhysicsTest, movement) {
rigidbody.data.angular_velocity_coefficient = 0;
rigidbody.data.max_angular_velocity = 1000;
rigidbody.data.angular_velocity = 360;
- system.update();
+ system.fixed_update();
EXPECT_NEAR(transform.rotation, 7.24, 0.01);
rigidbody.data.angular_velocity = -360;
- system.update();
+ system.fixed_update();
EXPECT_NEAR(transform.rotation, 0.04, 0.001);
- system.update();
+ system.fixed_update();
EXPECT_NEAR(transform.rotation, 352.84, 0.01);
}
diff --git a/src/test/Profiling.cpp b/src/test/Profiling.cpp
index 16736b8..d1da5a0 100644
--- a/src/test/Profiling.cpp
+++ b/src/test/Profiling.cpp
@@ -32,14 +32,14 @@ using namespace testing;
class TestScript : public Script {
bool oncollision(const CollisionEvent & test) {
- Log::logf("Box {} script on_collision()", test.info.this_collider.game_object_id);
+ Log::logf("Box {} script on_collision()", test.info.self.transform.game_object_id);
return true;
}
void init() {
subscribe<CollisionEvent>(
[this](const CollisionEvent & ev) -> bool { return this->oncollision(ev); });
}
- void update() {
+ void fixed_update() {
// Retrieve component from the same GameObject this script is on
}
};
@@ -50,7 +50,7 @@ public:
// Minimum amount to let test pass
const int min_gameobject_count = 100;
// Maximum amount to stop test
- const int max_gameobject_count = 150;
+ const int max_gameobject_count = 3000;
// Amount of times a test runs to calculate average
const int average = 5;
// Maximum duration to stop test
@@ -61,6 +61,8 @@ public:
ResourceManager resman{m};
ComponentManager mgr{m};
// Add system used for profling tests
+ EventManager evmgr{m};
+ LoopTimerManager loopmgr{m};
CollisionSystem collision_sys{m};
PhysicsSystem physics_sys{m};
ParticleSystem particle_sys{m};
@@ -82,9 +84,9 @@ public:
});
// initialize systems here:
//calls init
- script_sys.update();
+ script_sys.fixed_update();
//creates window
- render_sys.update();
+ render_sys.frame_update();
}
// Helper function to time an update call and store its duration
@@ -102,12 +104,14 @@ public:
// Run and profile all systems, return the total time in milliseconds
std::chrono::microseconds run_all_systems() {
std::chrono::microseconds total_microseconds = 0us;
- total_microseconds += time_function("PhysicsSystem", [&]() { physics_sys.update(); });
total_microseconds
- += time_function("CollisionSystem", [&]() { collision_sys.update(); });
+ += time_function("PhysicsSystem", [&]() { physics_sys.fixed_update(); });
total_microseconds
- += time_function("ParticleSystem", [&]() { particle_sys.update(); });
- total_microseconds += time_function("RenderSystem", [&]() { render_sys.update(); });
+ += time_function("CollisionSystem", [&]() { collision_sys.fixed_update(); });
+ total_microseconds
+ += time_function("ParticleSystem", [&]() { particle_sys.fixed_update(); });
+ total_microseconds
+ += time_function("RenderSystem", [&]() { render_sys.frame_update(); });
return total_microseconds;
}
@@ -233,7 +237,7 @@ TEST_F(DISABLED_ProfilingTest, Profiling_3) {
});
}
- render_sys.update();
+ render_sys.frame_update();
this->game_object_count++;
this->total_time = 0us;
diff --git a/src/test/RenderSystemTest.cpp b/src/test/RenderSystemTest.cpp
index b4519cb..689a6d4 100644
--- a/src/test/RenderSystemTest.cpp
+++ b/src/test/RenderSystemTest.cpp
@@ -85,7 +85,7 @@ public:
TEST_F(RenderSystemTest, NoCamera) {
// No camera
- EXPECT_ANY_THROW({ this->sys.update(); });
+ EXPECT_ANY_THROW({ this->sys.frame_update(); });
}
TEST_F(RenderSystemTest, make_sprites) {}
@@ -139,7 +139,7 @@ TEST_F(RenderSystemTest, Update) {
EXPECT_EQ(sprites[2].get().game_object_id, 2);
EXPECT_EQ(sprites[3].get().game_object_id, 3);
}
- this->sys.update();
+ this->sys.frame_update();
{
vector<reference_wrapper<Sprite>> sprites = this->mgr.get_components_by_type<Sprite>();
ASSERT_EQ(sprites.size(), 4);
@@ -178,7 +178,7 @@ TEST_F(RenderSystemTest, Color) {
EXPECT_EQ(sprite.data.color.g, Color::GREEN.g);
EXPECT_EQ(sprite.data.color.b, Color::GREEN.b);
EXPECT_EQ(sprite.data.color.a, Color::GREEN.a);
- this->sys.update();
+ this->sys.frame_update();
EXPECT_EQ(sprite.data.color.r, Color::GREEN.r);
EXPECT_EQ(sprite.data.color.g, Color::GREEN.g);
EXPECT_EQ(sprite.data.color.b, Color::GREEN.b);
diff --git a/src/test/ReplayManagerTest.cpp b/src/test/ReplayManagerTest.cpp
new file mode 100644
index 0000000..5ee4b40
--- /dev/null
+++ b/src/test/ReplayManagerTest.cpp
@@ -0,0 +1,38 @@
+#include <gtest/gtest.h>
+
+#include <crepe/api/BehaviorScript.h>
+#include <crepe/api/Scene.h>
+#include <crepe/api/Script.h>
+#include <crepe/manager/ReplayManager.h>
+#include <crepe/system/ReplaySystem.h>
+
+using namespace std;
+using namespace crepe;
+using namespace testing;
+
+class ReplayManagerTest : public Test {
+ Mediator mediator;
+
+public:
+ ComponentManager component_manager{mediator};
+ ReplayManager replay_manager{mediator};
+ ReplaySystem replay_system{mediator};
+
+ GameObject entity = component_manager.new_object("foo");
+ Transform & entity_transform
+ = component_manager.get_components_by_id<Transform>(entity.id).back();
+ Metadata & entity_metadata
+ = component_manager.get_components_by_id<Metadata>(entity.id).back();
+};
+
+TEST_F(ReplayManagerTest, Default) {
+ // replay_manager.record_start();
+
+ // replay_system.fixed_update();
+ // entity_transform.position += {1, 1};
+ // replay_system.fixed_update();
+ // entity_transform.position += {1, 1};
+ // replay_system.fixed_update();
+
+ // recording_t recording = replay_manager.record_end();
+}
diff --git a/src/test/SaveManagerTest.cpp b/src/test/SaveManagerTest.cpp
index e9b0c29..7609e69 100644
--- a/src/test/SaveManagerTest.cpp
+++ b/src/test/SaveManagerTest.cpp
@@ -27,8 +27,8 @@ TEST_F(SaveManagerTest, ReadWrite) {
mgr.set<string>("foo", "bar");
ASSERT_TRUE(mgr.has("foo"));
- ValueBroker value = mgr.get<string>("foo");
- EXPECT_EQ(value.get(), "bar");
+ string value = mgr.get<string>("foo");
+ EXPECT_EQ(value, "bar");
}
TEST_F(SaveManagerTest, DefaultValue) {
@@ -36,5 +36,16 @@ TEST_F(SaveManagerTest, DefaultValue) {
ASSERT_EQ(value.get(), 3);
value.set(5);
- ASSERT_EQ(value.get(), 5);
+ EXPECT_EQ(value.get(), 5);
+}
+
+TEST_F(SaveManagerTest, MultipleKeys) {
+ ValueBroker foo = mgr.get<int>("foo", 1);
+ ValueBroker bar = mgr.get<int>("bar", 2);
+
+ EXPECT_EQ(foo.get(), 1);
+ EXPECT_EQ(bar.get(), 2);
+
+ EXPECT_EQ(mgr.get<int>("foo"), 1);
+ EXPECT_EQ(mgr.get<int>("bar"), 2);
}
diff --git a/src/test/ScriptEventTest.cpp b/src/test/ScriptEventTest.cpp
index c1b4028..479e3f5 100644
--- a/src/test/ScriptEventTest.cpp
+++ b/src/test/ScriptEventTest.cpp
@@ -37,7 +37,7 @@ TEST_F(ScriptEventTest, Default) {
return true;
});
- system.update();
+ system.fixed_update();
behaviorscript.active = false;
EXPECT_EQ(0, event_count);
diff --git a/src/test/ScriptTest.cpp b/src/test/ScriptTest.cpp
index acdae70..40aa25c 100644
--- a/src/test/ScriptTest.cpp
+++ b/src/test/ScriptTest.cpp
@@ -28,7 +28,8 @@ void ScriptTest::SetUp() {
TEST_F(ScriptTest, Default) {
MyScript & script = this->script;
EXPECT_CALL(script, init()).Times(0);
- EXPECT_CALL(script, update()).Times(0);
+ EXPECT_CALL(script, fixed_update(_)).Times(0);
+ EXPECT_CALL(script, frame_update(_)).Times(0);
}
TEST_F(ScriptTest, UpdateOnce) {
@@ -38,16 +39,23 @@ TEST_F(ScriptTest, UpdateOnce) {
InSequence seq;
EXPECT_CALL(script, init()).Times(1);
- EXPECT_CALL(script, update()).Times(1);
- system.update();
+ EXPECT_CALL(script, fixed_update(_)).Times(1);
+ system.fixed_update();
}
{
InSequence seq;
EXPECT_CALL(script, init()).Times(0);
- EXPECT_CALL(script, update()).Times(1);
- system.update();
+ EXPECT_CALL(script, fixed_update(_)).Times(1);
+ system.fixed_update();
+ }
+
+ {
+ InSequence seq;
+
+ EXPECT_CALL(script, frame_update(_)).Times(1);
+ system.frame_update();
}
}
@@ -59,17 +67,29 @@ TEST_F(ScriptTest, UpdateInactive) {
InSequence seq;
EXPECT_CALL(script, init()).Times(0);
- EXPECT_CALL(script, update()).Times(0);
+ EXPECT_CALL(script, fixed_update(_)).Times(0);
behaviorscript.active = false;
- system.update();
+ system.fixed_update();
}
{
InSequence seq;
EXPECT_CALL(script, init()).Times(1);
- EXPECT_CALL(script, update()).Times(1);
+ EXPECT_CALL(script, fixed_update(_)).Times(1);
behaviorscript.active = true;
- system.update();
+ system.fixed_update();
}
}
+
+TEST_F(ScriptTest, SaveManager) {
+ MyScript & script = this->script;
+
+ EXPECT_EQ(&script.get_save_manager(), &this->save_manager);
+}
+
+TEST_F(ScriptTest, LoopTimerManager) {
+ MyScript & script = this->script;
+
+ EXPECT_EQ(&script.get_loop_timer(), &this->loop_timer);
+}
diff --git a/src/test/ScriptTest.h b/src/test/ScriptTest.h
index 31fa7c9..8637df0 100644
--- a/src/test/ScriptTest.h
+++ b/src/test/ScriptTest.h
@@ -7,7 +7,10 @@
#include <crepe/api/Script.h>
#include <crepe/manager/ComponentManager.h>
#include <crepe/manager/EventManager.h>
+#include <crepe/manager/LoopTimerManager.h>
+#include <crepe/manager/SaveManager.h>
#include <crepe/system/ScriptSystem.h>
+
class ScriptTest : public testing::Test {
protected:
crepe::Mediator mediator;
@@ -17,6 +20,8 @@ public:
crepe::ComponentManager component_manager{mediator};
crepe::ScriptSystem system{mediator};
crepe::EventManager event_mgr{mediator};
+ crepe::LoopTimerManager loop_timer{mediator};
+ crepe::SaveManager save_manager{mediator};
crepe::GameObject entity = component_manager.new_object(OBJ_NAME);
class MyScript : public crepe::Script {
@@ -24,7 +29,8 @@ public:
public:
MOCK_METHOD(void, init, (), (override));
- MOCK_METHOD(void, update, (), (override));
+ MOCK_METHOD(void, fixed_update, (crepe::duration_t), (override));
+ MOCK_METHOD(void, frame_update, (crepe::duration_t), (override));
};
crepe::OptionalRef<crepe::BehaviorScript> behaviorscript;
diff --git a/src/test/main.cpp b/src/test/main.cpp
index ed2aed5..0e1bc75 100644
--- a/src/test/main.cpp
+++ b/src/test/main.cpp
@@ -1,6 +1,7 @@
-#include <crepe/api/Config.h>
#include <gtest/gtest.h>
+#include <crepe/api/Config.h>
+
using namespace crepe;
using namespace testing;