aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-05 00:03:10 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-05 00:03:10 +0100
commit8aa43f634c1a89f05681ffc5f3cd0a3477e50e71 (patch)
treea1321d75328da0952ba7bf294a8036f50debb60f /src/test
parentd9e46281c1e24a5f23d779d314e5df87fa3317a3 (diff)
parentcfb67ffddb9f4bb0357c2b9df4239bfee7364c5a (diff)
added loopTimer to mediator and fixed update loop
Diffstat (limited to 'src/test')
-rw-r--r--src/test/CMakeLists.txt4
-rw-r--r--src/test/DBTest.cpp3
-rw-r--r--src/test/ECSTest.cpp6
-rw-r--r--src/test/EventTest.cpp16
-rw-r--r--src/test/LoopManagerTest.cpp44
-rw-r--r--src/test/LoopTimerTest.cpp (renamed from src/test/loopTimerTest.cpp)22
-rw-r--r--src/test/ParticleTest.cpp10
-rw-r--r--src/test/PhysicsTest.cpp8
-rw-r--r--src/test/RenderSystemTest.cpp11
-rw-r--r--src/test/SceneManagerTest.cpp24
-rw-r--r--src/test/ScriptEventTest.cpp50
-rw-r--r--src/test/ScriptSceneTest.cpp30
-rw-r--r--src/test/ScriptTest.cpp150
-rw-r--r--src/test/ScriptTest.h31
-rw-r--r--src/test/loopManagerTest.cpp50
15 files changed, 274 insertions, 185 deletions
diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt
index b126add..232c763 100644
--- a/src/test/CMakeLists.txt
+++ b/src/test/CMakeLists.txt
@@ -12,5 +12,7 @@ target_sources(test_main PUBLIC
ValueBrokerTest.cpp
DBTest.cpp
Vector2Test.cpp
- loopTimerTest.cpp
+ LoopManagerTest.cpp
+ LoopTimerTest.cpp
+
)
diff --git a/src/test/DBTest.cpp b/src/test/DBTest.cpp
index e80814c..99dedff 100644
--- a/src/test/DBTest.cpp
+++ b/src/test/DBTest.cpp
@@ -1,6 +1,7 @@
-#include <crepe/facade/DB.h>
#include <gtest/gtest.h>
+#include <crepe/facade/DB.h>
+
using namespace std;
using namespace crepe;
using namespace testing;
diff --git a/src/test/ECSTest.cpp b/src/test/ECSTest.cpp
index af9d6f2..3e6c61c 100644
--- a/src/test/ECSTest.cpp
+++ b/src/test/ECSTest.cpp
@@ -2,18 +2,20 @@
#define protected public
-#include <crepe/ComponentManager.h>
#include <crepe/api/GameObject.h>
#include <crepe/api/Metadata.h>
#include <crepe/api/Transform.h>
#include <crepe/api/Vector2.h>
+#include <crepe/manager/ComponentManager.h>
using namespace std;
using namespace crepe;
class ECSTest : public ::testing::Test {
+ Mediator m;
+
public:
- ComponentManager mgr{};
+ ComponentManager mgr{m};
};
TEST_F(ECSTest, createGameObject) {
diff --git a/src/test/EventTest.cpp b/src/test/EventTest.cpp
index b0e6c9c..dccd554 100644
--- a/src/test/EventTest.cpp
+++ b/src/test/EventTest.cpp
@@ -1,10 +1,11 @@
-
-#include "api/Event.h"
-#include "api/EventManager.h"
-#include "api/IKeyListener.h"
-#include "api/IMouseListener.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
+
+#include <crepe/api/Event.h>
+#include <crepe/api/IKeyListener.h>
+#include <crepe/api/IMouseListener.h>
+#include <crepe/manager/EventManager.h>
+
using namespace std;
using namespace std::chrono_literals;
using namespace crepe;
@@ -36,10 +37,7 @@ public:
};
TEST_F(EventManagerTest, EventSubscription) {
- EventHandler<KeyPressEvent> key_handler = [](const KeyPressEvent & e) {
- std::cout << "Key Event Triggered" << std::endl;
- return true;
- };
+ EventHandler<KeyPressEvent> key_handler = [](const KeyPressEvent & e) { return true; };
// Subscribe to KeyPressEvent
EventManager::get_instance().subscribe<KeyPressEvent>(key_handler, 1);
diff --git a/src/test/LoopManagerTest.cpp b/src/test/LoopManagerTest.cpp
new file mode 100644
index 0000000..af6cb1c
--- /dev/null
+++ b/src/test/LoopManagerTest.cpp
@@ -0,0 +1,44 @@
+#include <gtest/gtest.h>
+#include <chrono>
+#include <thread>
+#define private public
+#define protected public
+#include "api/LoopTimer.h"
+#include "api/LoopManager.h"
+
+using namespace std::chrono;
+using namespace crepe;
+
+class LoopManagerTest : public ::testing::Test {
+protected:
+ LoopManager loop_manager;
+
+ void SetUp() override {
+ // Setting up loop manager and start the loop
+ loop_manager.loop_timer->set_target_fps(60);
+ }
+};
+
+//Test to check if exactly 5 fixed updates are done every second (50Hz)
+TEST_F(LoopManagerTest, FixedUpdate) {
+ loop_manager.loop_timer->fixed_delta_time = std::chrono::milliseconds(20);
+ loop_manager.loop_timer->set_target_fps(50);
+ int fixed_update_count = 0;
+ loop_manager.loop_timer->start();
+ // We want to simulate the game loop for about 1 second
+ auto start_time = steady_clock::now();
+
+ // Simulate the game loop for 1 second
+ while (duration_cast<milliseconds>(steady_clock::now() - start_time) < std::chrono::milliseconds(1000)) {
+ loop_manager.loop_timer->update();
+ // Simulate processing fixed updates while there's lag to advance
+ while (loop_manager.loop_timer->get_lag() >= loop_manager.loop_timer->get_fixed_delta_time()) {
+ fixed_update_count++;
+ loop_manager.loop_timer->advance_fixed_update();
+ }
+
+ loop_manager.loop_timer->enforce_frame_rate();
+ }
+ // gameloop is 99 because it first takes 20 millisecond to build the lag to execute the fixed loop
+ ASSERT_EQ(fixed_update_count, 50);
+}
diff --git a/src/test/loopTimerTest.cpp b/src/test/LoopTimerTest.cpp
index 9bbbff3..6e3f118 100644
--- a/src/test/loopTimerTest.cpp
+++ b/src/test/LoopTimerTest.cpp
@@ -57,3 +57,25 @@ TEST_F(LoopTimerTest, DeltaTimeCalculation) {
ASSERT_LE(delta_time, (elapsed_time + 2) / 1000.0);
}
+TEST_F(LoopTimerTest, getCurrentTime) {
+ // Set the target FPS to 60 (16.67 ms per frame)
+ loop_timer.set_target_fps(60);
+
+ auto start_time = steady_clock::now();
+
+ // Sleep for 500 milliseconds
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+
+ loop_timer.update();
+
+ auto end_time = steady_clock::now();
+
+ // Get the elapsed time in seconds as a double
+ auto elapsed_time = duration_cast<std::chrono::duration<double>>(end_time - start_time).count();
+
+ ASSERT_NEAR(loop_timer.get_current_time(), elapsed_time, 0.001);
+
+
+}
+
+
diff --git a/src/test/ParticleTest.cpp b/src/test/ParticleTest.cpp
index 976f9a1..a659fe5 100644
--- a/src/test/ParticleTest.cpp
+++ b/src/test/ParticleTest.cpp
@@ -1,12 +1,12 @@
-#include "api/Texture.h"
-#include <crepe/ComponentManager.h>
#include <crepe/Particle.h>
#include <crepe/api/Config.h>
#include <crepe/api/GameObject.h>
#include <crepe/api/ParticleEmitter.h>
#include <crepe/api/Rigidbody.h>
#include <crepe/api/Sprite.h>
+#include <crepe/api/Texture.h>
#include <crepe/api/Transform.h>
+#include <crepe/manager/ComponentManager.h>
#include <crepe/system/ParticleSystem.h>
#include <gtest/gtest.h>
#include <math.h>
@@ -16,9 +16,11 @@ using namespace std::chrono_literals;
using namespace crepe;
class ParticlesTest : public ::testing::Test {
+ Mediator m;
+
public:
- ComponentManager component_manager;
- ParticleSystem particle_system{component_manager};
+ ComponentManager component_manager{m};
+ ParticleSystem particle_system{m};
void SetUp() override {
ComponentManager & mgr = this->component_manager;
diff --git a/src/test/PhysicsTest.cpp b/src/test/PhysicsTest.cpp
index 33b6020..43af8e4 100644
--- a/src/test/PhysicsTest.cpp
+++ b/src/test/PhysicsTest.cpp
@@ -1,8 +1,8 @@
-#include <crepe/ComponentManager.h>
#include <crepe/api/Config.h>
#include <crepe/api/GameObject.h>
#include <crepe/api/Rigidbody.h>
#include <crepe/api/Transform.h>
+#include <crepe/manager/ComponentManager.h>
#include <crepe/system/PhysicsSystem.h>
#include <gtest/gtest.h>
@@ -11,9 +11,11 @@ using namespace std::chrono_literals;
using namespace crepe;
class PhysicsTest : public ::testing::Test {
+ Mediator m;
+
public:
- ComponentManager component_manager;
- PhysicsSystem system{component_manager};
+ ComponentManager component_manager{m};
+ PhysicsSystem system{m};
void SetUp() override {
ComponentManager & mgr = this->component_manager;
diff --git a/src/test/RenderSystemTest.cpp b/src/test/RenderSystemTest.cpp
index bb5b81a..c105dcb 100644
--- a/src/test/RenderSystemTest.cpp
+++ b/src/test/RenderSystemTest.cpp
@@ -1,4 +1,3 @@
-#include "types.h"
#include <functional>
#include <gtest/gtest.h>
#include <memory>
@@ -7,12 +6,12 @@
#define private public
#define protected public
-#include "crepe/api/Camera.h"
-#include <crepe/ComponentManager.h>
+#include <crepe/api/Camera.h>
#include <crepe/api/Color.h>
#include <crepe/api/GameObject.h>
#include <crepe/api/Sprite.h>
#include <crepe/api/Texture.h>
+#include <crepe/manager/ComponentManager.h>
#include <crepe/system/RenderSystem.h>
@@ -21,9 +20,11 @@ using namespace crepe;
using namespace testing;
class RenderSystemTest : public Test {
+ Mediator m;
+
public:
- ComponentManager mgr{};
- RenderSystem sys{mgr};
+ ComponentManager mgr{m};
+ RenderSystem sys{m};
GameObject entity1 = this->mgr.new_object("name");
GameObject entity2 = this->mgr.new_object("name");
GameObject entity3 = this->mgr.new_object("name");
diff --git a/src/test/SceneManagerTest.cpp b/src/test/SceneManagerTest.cpp
index 62b7d33..9bb260c 100644
--- a/src/test/SceneManagerTest.cpp
+++ b/src/test/SceneManagerTest.cpp
@@ -1,12 +1,13 @@
-#include "types.h"
-#include <crepe/ComponentManager.h>
+#include <gtest/gtest.h>
+
#include <crepe/api/GameObject.h>
#include <crepe/api/Metadata.h>
#include <crepe/api/Scene.h>
-#include <crepe/api/SceneManager.h>
#include <crepe/api/Transform.h>
#include <crepe/api/Vector2.h>
-#include <gtest/gtest.h>
+#include <crepe/manager/ComponentManager.h>
+#include <crepe/manager/SceneManager.h>
+#include <crepe/types.h>
using namespace std;
using namespace crepe;
@@ -14,7 +15,8 @@ using namespace crepe;
class ConcreteScene1 : public Scene {
public:
void load_scene() {
- ComponentManager & mgr = this->component_manager;
+ Mediator & mediator = this->mediator;
+ ComponentManager & mgr = mediator.component_manager;
GameObject object1 = mgr.new_object("scene_1", "tag_scene_1", vec2{0, 0}, 0, 1);
GameObject object2 = mgr.new_object("scene_1", "tag_scene_1", vec2{1, 0}, 0, 1);
GameObject object3 = mgr.new_object("scene_1", "tag_scene_1", vec2{2, 0}, 0, 1);
@@ -26,7 +28,8 @@ public:
class ConcreteScene2 : public Scene {
public:
void load_scene() {
- ComponentManager & mgr = this->component_manager;
+ Mediator & mediator = this->mediator;
+ ComponentManager & mgr = mediator.component_manager;
GameObject object1 = mgr.new_object("scene_2", "tag_scene_2", vec2{0, 0}, 0, 1);
GameObject object2 = mgr.new_object("scene_2", "tag_scene_2", vec2{0, 1}, 0, 1);
GameObject object3 = mgr.new_object("scene_2", "tag_scene_2", vec2{0, 2}, 0, 1);
@@ -41,7 +44,8 @@ public:
ConcreteScene3(const string & name) : name(name) {}
void load_scene() {
- ComponentManager & mgr = this->component_manager;
+ Mediator & mediator = this->mediator;
+ ComponentManager & mgr = mediator.component_manager;
GameObject object1 = mgr.new_object("scene_3", "tag_scene_3", vec2{0, 0}, 0, 1);
}
@@ -52,9 +56,11 @@ private:
};
class SceneManagerTest : public ::testing::Test {
+ Mediator m;
+
public:
- ComponentManager component_mgr{};
- SceneManager scene_mgr{component_mgr};
+ ComponentManager component_mgr{m};
+ SceneManager scene_mgr{m};
};
TEST_F(SceneManagerTest, loadScene) {
diff --git a/src/test/ScriptEventTest.cpp b/src/test/ScriptEventTest.cpp
new file mode 100644
index 0000000..5da31e7
--- /dev/null
+++ b/src/test/ScriptEventTest.cpp
@@ -0,0 +1,50 @@
+#include <gtest/gtest.h>
+
+// stupid hack to allow access to private/protected members under test
+#define private public
+#define protected public
+
+#include <crepe/api/BehaviorScript.h>
+#include <crepe/api/Event.h>
+#include <crepe/api/GameObject.h>
+#include <crepe/api/Script.h>
+#include <crepe/api/Vector2.h>
+#include <crepe/manager/ComponentManager.h>
+#include <crepe/manager/EventManager.h>
+#include <crepe/system/ScriptSystem.h>
+
+#include "ScriptTest.h"
+
+using namespace std;
+using namespace crepe;
+using namespace testing;
+
+class ScriptEventTest : public ScriptTest {
+public:
+ EventManager & event_manager = mediator.event_manager;
+
+ class MyEvent : public Event {};
+};
+
+TEST_F(ScriptEventTest, Inactive) {
+ BehaviorScript & behaviorscript = this->behaviorscript;
+ MyScript & script = this->script;
+ EventManager & evmgr = this->event_manager;
+
+ unsigned event_count = 0;
+ script.subscribe<MyEvent>([&](const MyEvent &) {
+ event_count++;
+ return true;
+ });
+
+ system.update();
+ behaviorscript.active = false;
+ EXPECT_EQ(0, event_count);
+
+ evmgr.trigger_event<MyEvent>();
+ EXPECT_EQ(0, event_count);
+
+ behaviorscript.active = true;
+ evmgr.trigger_event<MyEvent>();
+ EXPECT_EQ(1, event_count);
+}
diff --git a/src/test/ScriptSceneTest.cpp b/src/test/ScriptSceneTest.cpp
new file mode 100644
index 0000000..9ee1e52
--- /dev/null
+++ b/src/test/ScriptSceneTest.cpp
@@ -0,0 +1,30 @@
+#include <gtest/gtest.h>
+
+// stupid hack to allow access to private/protected members under test
+#define private public
+#define protected public
+
+#include "ScriptTest.h"
+#include <crepe/manager/SceneManager.h>
+
+using namespace std;
+using namespace crepe;
+using namespace testing;
+
+class ScriptSceneTest : public ScriptTest {
+public:
+ SceneManager scene_manager{mediator};
+
+ class MyScene : public Scene {};
+};
+
+TEST_F(ScriptSceneTest, Inactive) {
+ BehaviorScript & behaviorscript = this->behaviorscript;
+ MyScript & script = this->script;
+
+ const char * non_default_value = "foo";
+ ASSERT_NE(non_default_value, scene_manager.next_scene);
+
+ script.set_next_scene(non_default_value);
+ EXPECT_EQ(non_default_value, scene_manager.next_scene);
+}
diff --git a/src/test/ScriptTest.cpp b/src/test/ScriptTest.cpp
index 78d5061..1d2d6dd 100644
--- a/src/test/ScriptTest.cpp
+++ b/src/test/ScriptTest.cpp
@@ -1,129 +1,77 @@
+#include <gmock/gmock.h>
#include <gtest/gtest.h>
// stupid hack to allow access to private/protected members under test
#define private public
#define protected public
-#include <crepe/ComponentManager.h>
-#include <crepe/api/BehaviorScript.h>
-#include <crepe/api/Event.h>
-#include <crepe/api/EventManager.h>
+#include "ScriptTest.h"
#include <crepe/api/GameObject.h>
-#include <crepe/api/Script.h>
-#include <crepe/api/Vector2.h>
-#include <crepe/system/ScriptSystem.h>
using namespace std;
using namespace crepe;
using namespace testing;
-class MyEvent : public Event {};
-
-class ScriptTest : public Test {
-public:
- ComponentManager component_manager{};
- ScriptSystem system{component_manager};
- EventManager & event_manager = EventManager::get_instance();
-
- class MyScript : public Script {
- // NOTE: default (private) visibility of init and update shouldn't cause
- // issues!
- void init() {
- this->init_count++;
-
- subscribe<MyEvent>([this](const MyEvent &) {
- this->event_count++;
- return true;
- });
-
- // init should never be called more than once
- EXPECT_LE(this->init_count, 1);
- }
- void update() { this->update_count++; }
-
- public:
- unsigned init_count = 0;
- unsigned update_count = 0;
- unsigned event_count = 0;
- };
-
- OptionalRef<BehaviorScript> behaviorscript;
- OptionalRef<MyScript> script;
-
- void SetUp() override {
- auto & mgr = this->component_manager;
- GameObject entity = mgr.new_object("name");
- BehaviorScript & component = entity.add_component<BehaviorScript>();
-
- this->behaviorscript = component;
- ASSERT_TRUE(this->behaviorscript);
- EXPECT_EQ(component.script.get(), nullptr);
- component.set_script<MyScript>();
- ASSERT_NE(component.script.get(), nullptr);
-
- this->script = *(MyScript *) component.script.get();
- ASSERT_TRUE(this->script);
-
- // sanity
- MyScript & script = this->script;
- ASSERT_EQ(script.init_count, 0);
- ASSERT_EQ(script.update_count, 0);
- ASSERT_EQ(script.event_count, 0);
- }
-};
+void ScriptTest::SetUp() {
+ auto & mgr = this->component_manager;
+ GameObject entity = mgr.new_object("name");
+ BehaviorScript & component = entity.add_component<BehaviorScript>();
+
+ this->behaviorscript = component;
+ ASSERT_TRUE(this->behaviorscript);
+ EXPECT_EQ(component.script.get(), nullptr);
+ component.set_script<NiceMock<MyScript>>();
+ ASSERT_NE(component.script.get(), nullptr);
+
+ this->script = *(MyScript *) component.script.get();
+ ASSERT_TRUE(this->script);
+}
TEST_F(ScriptTest, Default) {
MyScript & script = this->script;
- EXPECT_EQ(0, script.init_count);
- EXPECT_EQ(0, script.update_count);
- EXPECT_EQ(0, script.event_count);
+ EXPECT_CALL(script, init()).Times(0);
+ EXPECT_CALL(script, update()).Times(0);
}
TEST_F(ScriptTest, UpdateOnce) {
MyScript & script = this->script;
- system.update();
- EXPECT_EQ(1, script.init_count);
- EXPECT_EQ(1, script.update_count);
- EXPECT_EQ(0, script.event_count);
+ {
+ InSequence seq;
+
+ EXPECT_CALL(script, init()).Times(1);
+ EXPECT_CALL(script, update()).Times(1);
+ system.update();
+ }
+
+ {
+ InSequence seq;
+
+ EXPECT_CALL(script, init()).Times(0);
+ EXPECT_CALL(script, update()).Times(1);
+ system.update();
+ }
}
TEST_F(ScriptTest, UpdateInactive) {
BehaviorScript & behaviorscript = this->behaviorscript;
MyScript & script = this->script;
- behaviorscript.active = false;
- system.update();
- EXPECT_EQ(0, script.init_count);
- EXPECT_EQ(0, script.update_count);
- EXPECT_EQ(0, script.event_count);
-
- behaviorscript.active = true;
- system.update();
- EXPECT_EQ(1, script.init_count);
- EXPECT_EQ(1, script.update_count);
- EXPECT_EQ(0, script.event_count);
-}
+ {
+ InSequence seq;
-TEST_F(ScriptTest, EventInactive) {
- BehaviorScript & behaviorscript = this->behaviorscript;
- MyScript & script = this->script;
- EventManager & evmgr = this->event_manager;
-
- system.update();
- behaviorscript.active = false;
- EXPECT_EQ(1, script.init_count);
- EXPECT_EQ(1, script.update_count);
- EXPECT_EQ(0, script.event_count);
-
- evmgr.trigger_event<MyEvent>();
- EXPECT_EQ(1, script.init_count);
- EXPECT_EQ(1, script.update_count);
- EXPECT_EQ(0, script.event_count);
-
- behaviorscript.active = true;
- evmgr.trigger_event<MyEvent>();
- EXPECT_EQ(1, script.init_count);
- EXPECT_EQ(1, script.update_count);
- EXPECT_EQ(1, script.event_count);
+ EXPECT_CALL(script, init()).Times(0);
+ EXPECT_CALL(script, update()).Times(0);
+ behaviorscript.active = false;
+ system.update();
+ }
+
+ {
+ InSequence seq;
+
+ EXPECT_CALL(script, init()).Times(1);
+ EXPECT_CALL(script, update()).Times(1);
+ behaviorscript.active = true;
+ system.update();
+ }
}
diff --git a/src/test/ScriptTest.h b/src/test/ScriptTest.h
new file mode 100644
index 0000000..1bbfdd3
--- /dev/null
+++ b/src/test/ScriptTest.h
@@ -0,0 +1,31 @@
+#pragma once
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include <crepe/api/BehaviorScript.h>
+#include <crepe/api/Script.h>
+#include <crepe/manager/ComponentManager.h>
+#include <crepe/system/ScriptSystem.h>
+
+class ScriptTest : public testing::Test {
+protected:
+ crepe::Mediator mediator;
+
+public:
+ crepe::ComponentManager component_manager{mediator};
+ crepe::ScriptSystem system{mediator};
+
+ class MyScript : public crepe::Script {
+ // NOTE: explicitly stating `public:` is not required on actual scripts
+
+ public:
+ MOCK_METHOD(void, init, (), (override));
+ MOCK_METHOD(void, update, (), (override));
+ };
+
+ crepe::OptionalRef<crepe::BehaviorScript> behaviorscript;
+ crepe::OptionalRef<MyScript> script;
+
+ virtual void SetUp();
+};
diff --git a/src/test/loopManagerTest.cpp b/src/test/loopManagerTest.cpp
deleted file mode 100644
index 6e66ce7..0000000
--- a/src/test/loopManagerTest.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-#include <gtest/gtest.h>
-#include <chrono>
-#include <thread>
-#define private public
-#define protected public
-#include "api/LoopTimer.h"
-#include "api/LoopManager.h"
-
-using namespace std::chrono;
-using namespace crepe;
-
-class LoopTimerTest : public ::testing::Test {
-protected:
- LoopManager loop_manager;
-
- void SetUp() override {
- // Setting up loop manager and start the loop
- loop_manager.setup();
- loop_manager.loop_timer->set_target_fps(60);
- }
-};
-
-// Test to check if exactly 5 fixed updates are done every second (50Hz)
-TEST_F(LoopTimerTest, FixedUpdateCalledAt50Hz) {
- // Set target fixed delta time to 20ms (50Hz fixed updates)
- loop_manager.loop_timer->set_fixed_delta_time(milliseconds(20));
-
- int fixed_update_count = 0;
-
- // We want to simulate the game loop for about 1 second
- auto start_time = steady_clock::now();
-
- // Simulate the game loop for 1 second
- while (duration_cast<seconds>(steady_clock::now() - start_time).count() < 1) {
- loop_manager.loop_timer->update();
-
- // Simulate processing fixed updates while there's lag to advance
- while (loop_manager.loop_timer->get_lag() >= loop_manager.loop_timer->get_fixed_delta_time()) {
- loop_manager.fixed_update(); // Process fixed update
- fixed_update_count++; // Count the number of fixed updates
- loop_manager.loop_timer->advance_fixed_update();
- }
-
- // We do not need to call render or update for this test
- loop_manager.loop_timer->enforce_frame_rate(); // Enforce the frame rate (this would normally go to the display)
- }
-
- // We expect 5 fixed updates to occur in 1 second at 50Hz
- ASSERT_EQ(fixed_update_count, 5);
-}