aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-07 15:32:47 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-07 15:32:47 +0100
commit24c9a9ab277897a7191d4e99213c2ab9f5d4ecd8 (patch)
tree0e5f9dc8be0592431b52149db51337ccf3bc2e7f /src/test
parent0f2451f4d48c78426c2663501e6cdd6871f1e94a (diff)
make format
Diffstat (limited to 'src/test')
-rw-r--r--src/test/EventTest.cpp13
-rw-r--r--src/test/LoopManagerTest.cpp70
-rw-r--r--src/test/LoopTimerTest.cpp4
-rw-r--r--src/test/ScriptTest.h2
4 files changed, 41 insertions, 48 deletions
diff --git a/src/test/EventTest.cpp b/src/test/EventTest.cpp
index 8479998..82272b5 100644
--- a/src/test/EventTest.cpp
+++ b/src/test/EventTest.cpp
@@ -1,8 +1,8 @@
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
#include <crepe/api/Event.h>
#include <crepe/manager/EventManager.h>
#include <crepe/manager/Mediator.h>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
using namespace std;
using namespace std::chrono_literals;
using namespace crepe;
@@ -53,13 +53,11 @@ TEST_F(EventManagerTest, EventManagerTest_trigger_all_channels) {
EXPECT_EQ(e.button, MouseButton::LEFT_MOUSE);
return false;
};
- event_mgr.subscribe<MouseClickEvent>(mouse_handler,
- EventManager::CHANNEL_ALL);
+ event_mgr.subscribe<MouseClickEvent>(mouse_handler, EventManager::CHANNEL_ALL);
MouseClickEvent click_event{
.mouse_x = 100, .mouse_y = 200, .button = MouseButton::LEFT_MOUSE};
- event_mgr.trigger_event<MouseClickEvent>(click_event,
- EventManager::CHANNEL_ALL);
+ event_mgr.trigger_event<MouseClickEvent>(click_event, EventManager::CHANNEL_ALL);
EXPECT_TRUE(triggered);
}
@@ -77,8 +75,7 @@ TEST_F(EventManagerTest, EventManagerTest_trigger_one_channel) {
MouseClickEvent click_event{
.mouse_x = 100, .mouse_y = 200, .button = MouseButton::LEFT_MOUSE};
- event_mgr.trigger_event<MouseClickEvent>(click_event,
- EventManager::CHANNEL_ALL);
+ event_mgr.trigger_event<MouseClickEvent>(click_event, EventManager::CHANNEL_ALL);
EXPECT_FALSE(triggered);
event_mgr.trigger_event<MouseClickEvent>(click_event, test_channel);
diff --git a/src/test/LoopManagerTest.cpp b/src/test/LoopManagerTest.cpp
index 13a0ada..f73605e 100644
--- a/src/test/LoopManagerTest.cpp
+++ b/src/test/LoopManagerTest.cpp
@@ -1,67 +1,63 @@
#include <chrono>
-#include <gtest/gtest.h>
#include <gmock/gmock.h>
+#include <gtest/gtest.h>
#include <thread>
#define private public
#define protected public
#include <crepe/api/LoopManager.h>
-#include <crepe/manager/LoopTimerManager.h>
#include <crepe/manager/EventManager.h>
+#include <crepe/manager/LoopTimerManager.h>
using namespace std::chrono;
using namespace crepe;
class LoopManagerTest : public ::testing::Test {
protected:
- class TestGameLoop : public crepe::LoopManager {
- public:
- MOCK_METHOD(void, fixed_update, (), (override));
- MOCK_METHOD(void, update, (), (override));
+ class TestGameLoop : public crepe::LoopManager {
+ public:
+ MOCK_METHOD(void, fixed_update, (), (override));
+ MOCK_METHOD(void, update, (), (override));
MOCK_METHOD(void, render, (), (override));
- };
+ };
- TestGameLoop test_loop;
- void SetUp() override {
-
- }
+ TestGameLoop test_loop;
+ void SetUp() override {}
};
TEST_F(LoopManagerTest, FixedUpdate) {
- // Arrange
- test_loop.loop_timer.set_target_fps(60);
+ // Arrange
+ test_loop.loop_timer.set_target_fps(60);
- // Set expectations for the mock calls
- EXPECT_CALL(test_loop, render).Times(::testing::Exactly(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::Exactly(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(); });
+ // Start the loop in a separate thread
+ std::thread loop_thread([&]() { test_loop.start(); });
- // Let the loop run for exactly 1 second
- std::this_thread::sleep_for(std::chrono::seconds(1));
+ // Let the loop run for exactly 1 second
+ std::this_thread::sleep_for(std::chrono::seconds(1));
- // Stop the game loop
- test_loop.game_running = false;
- // Wait for the loop thread to finish
- loop_thread.join();
+ // Stop the game loop
+ test_loop.game_running = false;
+ // Wait for the loop thread to finish
+ loop_thread.join();
- // Test finished
+ // Test finished
}
TEST_F(LoopManagerTest, ShutDown) {
- // Arrange
- test_loop.loop_timer.set_target_fps(60);
+ // Arrange
+ test_loop.loop_timer.set_target_fps(60);
- EXPECT_CALL(test_loop, render).Times(::testing::AtLeast(1));
+ 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));
+ 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();
+ // Wait for the loop thread to finish
+ loop_thread.join();
- // Test finished
+ // Test finished
}
-
-
diff --git a/src/test/LoopTimerTest.cpp b/src/test/LoopTimerTest.cpp
index 09b4e00..c6655d9 100644
--- a/src/test/LoopTimerTest.cpp
+++ b/src/test/LoopTimerTest.cpp
@@ -1,6 +1,6 @@
#include <chrono>
-#include <thread>
#include <gtest/gtest.h>
+#include <thread>
#define private public
#define protected public
#include <crepe/manager/LoopTimerManager.h>
@@ -26,7 +26,7 @@ TEST_F(LoopTimerTest, EnforcesTargetFrameRate) {
auto elapsed_ms = duration_cast<milliseconds>(elapsed_time).count();
// For 60 FPS, the target frame time is around 16.67ms
- ASSERT_NEAR(elapsed_ms,16.7,1);
+ ASSERT_NEAR(elapsed_ms, 16.7, 1);
}
TEST_F(LoopTimerTest, SetTargetFps) {
// Set the target FPS to 120
diff --git a/src/test/ScriptTest.h b/src/test/ScriptTest.h
index ee68c23..e0205ff 100644
--- a/src/test/ScriptTest.h
+++ b/src/test/ScriptTest.h
@@ -6,8 +6,8 @@
#include <crepe/api/BehaviorScript.h>
#include <crepe/api/Script.h>
#include <crepe/manager/ComponentManager.h>
-#include <crepe/system/ScriptSystem.h>
#include <crepe/manager/EventManager.h>
+#include <crepe/system/ScriptSystem.h>
class ScriptTest : public testing::Test {
protected:
crepe::Mediator mediator;