From 7070f22d86057eafca3b82321d4146958c14a33e Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Wed, 27 Nov 2024 14:25:32 +0100 Subject: pr feedback --- src/test/inputTest.cpp | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'src/test') diff --git a/src/test/inputTest.cpp b/src/test/inputTest.cpp index 3a9d341..0e3e097 100644 --- a/src/test/inputTest.cpp +++ b/src/test/inputTest.cpp @@ -20,12 +20,14 @@ using namespace crepe; class InputTest : public ::testing::Test { public: ComponentManager mgr{}; - InputSystem input_system{mgr}; + InputSystem input_system{mgr}; // Initializes the InputSystem with the ComponentManager - EventManager & event_manager = EventManager::get_instance(); + EventManager& event_manager = EventManager::get_instance(); protected: - void SetUp() override { event_manager.clear(); } + void SetUp() override { + event_manager.clear(); + } void simulate_mouse_click(int mouse_x, int mouse_y, Uint8 mouse_button) { SDL_Event event; @@ -37,6 +39,8 @@ protected: event.button.y = mouse_y; event.button.button = mouse_button; SDL_PushEvent(&event); + + // Simulate Mouse Button Up event SDL_zero(event); event.type = SDL_MOUSEBUTTONUP; event.button.x = mouse_x; @@ -48,7 +52,7 @@ protected: TEST_F(InputTest, MouseDown) { bool mouse_triggered = false; - EventHandler on_mouse_down = [&](const MousePressEvent & event) { + EventHandler on_mouse_down = [&](const MousePressEvent& event) { mouse_triggered = true; EXPECT_EQ(event.mouse_x, 10); EXPECT_EQ(event.mouse_y, 10); @@ -64,6 +68,7 @@ TEST_F(InputTest, MouseDown) { event.button.y = 10; event.button.button = SDL_BUTTON_LEFT; SDL_PushEvent(&event); + input_system.update(); event_manager.dispatch_events(); EXPECT_TRUE(mouse_triggered); @@ -71,8 +76,7 @@ TEST_F(InputTest, MouseDown) { TEST_F(InputTest, MouseUp) { bool function_triggered = false; - EventHandler on_mouse_release = [&](const MouseReleaseEvent & e) { - // Handle the mouse click event here + EventHandler on_mouse_release = [&](const MouseReleaseEvent& e) { function_triggered = true; EXPECT_EQ(e.mouse_x, 10); EXPECT_EQ(e.mouse_y, 10); @@ -88,6 +92,7 @@ TEST_F(InputTest, MouseUp) { event.button.y = 10; event.button.button = SDL_BUTTON_LEFT; SDL_PushEvent(&event); + input_system.update(); event_manager.dispatch_events(); EXPECT_TRUE(function_triggered); @@ -95,8 +100,7 @@ TEST_F(InputTest, MouseUp) { TEST_F(InputTest, MouseMove) { bool function_triggered = false; - EventHandler on_mouse_move = [&](const MouseMoveEvent & e) { - // Handle the mouse click event here + EventHandler on_mouse_move = [&](const MouseMoveEvent& e) { function_triggered = true; EXPECT_EQ(e.mouse_x, 10); EXPECT_EQ(e.mouse_y, 10); @@ -114,6 +118,7 @@ TEST_F(InputTest, MouseMove) { event.motion.xrel = 10; event.motion.yrel = 10; SDL_PushEvent(&event); + input_system.update(); event_manager.dispatch_events(); EXPECT_TRUE(function_triggered); @@ -123,7 +128,7 @@ TEST_F(InputTest, KeyDown) { bool function_triggered = false; // Define event handler for KeyPressEvent - EventHandler on_key_press = [&](const KeyPressEvent & event) { + EventHandler on_key_press = [&](const KeyPressEvent& event) { function_triggered = true; EXPECT_EQ(event.key, Keycode::B); // Validate the key is 'B' EXPECT_EQ(event.repeat, true); // Validate repeat flag @@ -148,7 +153,7 @@ TEST_F(InputTest, KeyDown) { TEST_F(InputTest, KeyUp) { bool function_triggered = false; - EventHandler on_key_release = [&](const KeyReleaseEvent & event) { + EventHandler on_key_release = [&](const KeyReleaseEvent& event) { function_triggered = true; EXPECT_EQ(event.key, Keycode::B); return false; @@ -160,6 +165,7 @@ TEST_F(InputTest, KeyUp) { event.type = SDL_KEYUP; event.key.keysym.scancode = SDL_SCANCODE_B; SDL_PushEvent(&event); + input_system.update(); event_manager.dispatch_events(); EXPECT_TRUE(function_triggered); @@ -167,7 +173,7 @@ TEST_F(InputTest, KeyUp) { TEST_F(InputTest, MouseClick) { bool on_click_triggered = false; - EventHandler on_mouse_click = [&](const MouseClickEvent & event) { + EventHandler on_mouse_click = [&](const MouseClickEvent& event) { on_click_triggered = true; EXPECT_EQ(event.button, MouseButton::LEFT_MOUSE); EXPECT_EQ(event.mouse_x, 10); @@ -184,13 +190,11 @@ TEST_F(InputTest, MouseClick) { TEST_F(InputTest, testButtonClick) { GameObject obj = mgr.new_object("body", "person", vec2{0, 0}, 0, 1); - auto & button = obj.add_component