aboutsummaryrefslogtreecommitdiff
path: root/src/test/LoopManagerTest.cpp
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-07 14:19:16 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-07 14:19:16 +0100
commita73ff31b67faa7e6a922cfb5598f56f80bc01d62 (patch)
tree04840dfbdbe6207100fbbc2aba04f48a46de1022 /src/test/LoopManagerTest.cpp
parenta0070890fcdb422db85660fc44bcc709832870b8 (diff)
added loopTimer and eventManager to mediator and removed the singletons
Diffstat (limited to 'src/test/LoopManagerTest.cpp')
-rw-r--r--src/test/LoopManagerTest.cpp29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/test/LoopManagerTest.cpp b/src/test/LoopManagerTest.cpp
index 503eb1f..57f7a2e 100644
--- a/src/test/LoopManagerTest.cpp
+++ b/src/test/LoopManagerTest.cpp
@@ -2,13 +2,11 @@
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <thread>
-#include <iostream>
#define private public
#define protected public
-#include "api/LoopManager.h"
-#include "api/LoopTimer.h"
-#include "manager/EventManager.h"
-#include "api/Event.h"
+#include <crepe/api/LoopManager.h>
+#include <crepe/manager/LoopTimerManager.h>
+#include <crepe/manager/EventManager.h>
using namespace std::chrono;
using namespace crepe;
@@ -24,19 +22,18 @@ protected:
TestGameLoop test_loop;
// LoopManager test_loop;
void SetUp() override {
- test_loop.loop_timer->set_target_fps(10);
}
};
TEST_F(LoopManagerTest, FixedUpdate) {
// Arrange
- test_loop.loop_timer->set_target_fps(60);
+ test_loop.loop_timer.set_target_fps(60);
// Set expectations for the mock calls
EXPECT_CALL(test_loop, render).Times(::testing::Exactly(60));
EXPECT_CALL(test_loop, update).Times(::testing::Exactly(60));
- EXPECT_CALL(test_loop, fixed_update).Times(::testing::AtLeast(50));
+ EXPECT_CALL(test_loop, fixed_update).Times(::testing::Exactly(50));
// Start the loop in a separate thread
std::thread loop_thread([&]() { test_loop.start(); });
@@ -46,12 +43,26 @@ TEST_F(LoopManagerTest, FixedUpdate) {
// Stop the game loop
test_loop.game_running = false;
-
// Wait for the loop thread to finish
loop_thread.join();
// Test finished
}
+TEST_F(LoopManagerTest, ShutDown) {
+ // Arrange
+ test_loop.loop_timer.set_target_fps(60);
+ EXPECT_CALL(test_loop, render).Times(::testing::AtLeast(1));
+ EXPECT_CALL(test_loop, update).Times(::testing::AtLeast(1));
+ EXPECT_CALL(test_loop, fixed_update).Times(::testing::AtLeast(1));
+ // Start the loop in a separate thread
+ std::thread loop_thread([&]() { test_loop.start(); });
+ std::this_thread::sleep_for(std::chrono::milliseconds(1));
+ test_loop.event_manager.trigger_event<ShutDownEvent>(ShutDownEvent{});
+ // Wait for the loop thread to finish
+ loop_thread.join();
+
+ // Test finished
+}