aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/LoopManagerTest.cpp12
-rw-r--r--src/test/LoopTimerTest.cpp20
2 files changed, 13 insertions, 19 deletions
diff --git a/src/test/LoopManagerTest.cpp b/src/test/LoopManagerTest.cpp
index c44ebda..4e0ecdc 100644
--- a/src/test/LoopManagerTest.cpp
+++ b/src/test/LoopManagerTest.cpp
@@ -16,7 +16,6 @@ protected:
public:
MOCK_METHOD(void, fixed_update, (), (override));
MOCK_METHOD(void, frame_update, (), (override));
- MOCK_METHOD(void, render, (), (override));
};
TestGameLoop test_loop;
@@ -25,10 +24,9 @@ protected:
TEST_F(LoopManagerTest, FixedUpdate) {
// Arrange
- test_loop.loop_timer.set_target_fps(60);
+ test_loop.loop_timer.set_target_framerate(60);
// Set expectations for the mock calls
- EXPECT_CALL(test_loop, render).Times(::testing::Exactly(60));
EXPECT_CALL(test_loop, frame_update).Times(::testing::Exactly(60));
EXPECT_CALL(test_loop, fixed_update).Times(::testing::Exactly(50));
@@ -47,10 +45,9 @@ TEST_F(LoopManagerTest, FixedUpdate) {
}
TEST_F(LoopManagerTest, ScaledFixedUpdate) {
// Arrange
- test_loop.loop_timer.set_target_fps(60);
+ test_loop.loop_timer.set_target_framerate(60);
// Set expectations for the mock calls
- EXPECT_CALL(test_loop, render).Times(::testing::Exactly(60));
EXPECT_CALL(test_loop, frame_update).Times(::testing::Exactly(60));
EXPECT_CALL(test_loop, fixed_update).Times(::testing::Exactly(50));
@@ -69,9 +66,8 @@ TEST_F(LoopManagerTest, ScaledFixedUpdate) {
}
TEST_F(LoopManagerTest, ShutDown) {
// Arrange
- test_loop.loop_timer.set_target_fps(60);
+ test_loop.loop_timer.set_target_framerate(60);
- EXPECT_CALL(test_loop, render).Times(::testing::AtLeast(1));
EXPECT_CALL(test_loop, frame_update).Times(::testing::AtLeast(1));
EXPECT_CALL(test_loop, fixed_update).Times(::testing::AtLeast(1));
// Start the loop in a separate thread
@@ -80,6 +76,4 @@ TEST_F(LoopManagerTest, ShutDown) {
test_loop.event_manager.trigger_event<ShutDownEvent>(ShutDownEvent{});
// Wait for the loop thread to finish
loop_thread.join();
-
- // Test finished
}
diff --git a/src/test/LoopTimerTest.cpp b/src/test/LoopTimerTest.cpp
index c6655d9..1216e5e 100644
--- a/src/test/LoopTimerTest.cpp
+++ b/src/test/LoopTimerTest.cpp
@@ -17,7 +17,7 @@ protected:
};
TEST_F(LoopTimerTest, EnforcesTargetFrameRate) {
// Set the target FPS to 60 (which gives a target time per frame of ~16.67 ms)
- loop_timer.set_target_fps(60);
+ loop_timer.set_target_framerate(60);
auto start_time = steady_clock::now();
loop_timer.enforce_frame_rate();
@@ -30,33 +30,33 @@ TEST_F(LoopTimerTest, EnforcesTargetFrameRate) {
}
TEST_F(LoopTimerTest, SetTargetFps) {
// Set the target FPS to 120
- loop_timer.set_target_fps(120);
+ loop_timer.set_target_framerate(120);
// Calculate the expected frame time (~8.33ms per frame)
- auto expected_frame_time = std::chrono::duration<double>(1.0 / 120.0);
+ Duration_t expected_frame_time = std::chrono::duration<float>(1.0 / 120.0);
ASSERT_NEAR(loop_timer.frame_target_time.count(), expected_frame_time.count(), 0.001);
}
TEST_F(LoopTimerTest, DeltaTimeCalculation) {
// Set the target FPS to 60 (16.67 ms per frame)
- loop_timer.set_target_fps(60);
+ loop_timer.set_target_framerate(60);
auto start_time = steady_clock::now();
loop_timer.update();
auto end_time = steady_clock::now();
// Check the delta time
- double delta_time = loop_timer.get_delta_time();
+ Duration_t delta_time = loop_timer.get_delta_time();
auto elapsed_time = duration_cast<seconds>(end_time - start_time).count();
// Assert that delta_time is close to the elapsed time
- ASSERT_NEAR(delta_time, elapsed_time, 1);
+ ASSERT_NEAR(delta_time.count(), elapsed_time, 1);
}
TEST_F(LoopTimerTest, getCurrentTime) {
// Set the target FPS to 60 (16.67 ms per frame)
- loop_timer.set_target_fps(60);
+ loop_timer.set_target_framerate(60);
auto start_time = steady_clock::now();
@@ -68,8 +68,8 @@ TEST_F(LoopTimerTest, getCurrentTime) {
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();
+ auto elapsed_time = std::chrono::duration_cast<ElapsedTime_t>(end_time - start_time).count();
- ASSERT_NEAR(loop_timer.get_current_time(), elapsed_time, 0.001);
+
+ ASSERT_NEAR(loop_timer.get_elapsed_time().count(), elapsed_time, 5);
}