From 65747afc0dadd7f0d9d93f1d0984f442c11eec82 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Mon, 9 Dec 2024 14:14:11 +0100 Subject: resize/move tests working --- src/test/InputTest.cpp | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'src/test') diff --git a/src/test/InputTest.cpp b/src/test/InputTest.cpp index 7d4a017..0c81cfa 100644 --- a/src/test/InputTest.cpp +++ b/src/test/InputTest.cpp @@ -1,7 +1,4 @@ #include - -#include - #define protected public #define private public #include "api/KeyCodes.h" @@ -294,12 +291,15 @@ TEST_F(InputTest, testButtonHover) { } TEST_F(InputTest, WindowResizeTest) { + GameObject obj = mgr.new_object("camera", "camera", vec2{0, 0}, 0, 1); + auto & camera = obj.add_component( + ivec2{0, 0}, vec2{500, 500}, Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f}); + camera.active = true; bool callback_triggered = false; EventHandler on_window_resize = [&](const WindowResizeEvent & event) { - std::cout << "test callback" << std::endl; callback_triggered = true; - EXPECT_EQ(event.dimensions.x, 0); - EXPECT_EQ(event.dimensions.y, 0); + EXPECT_EQ(event.dimensions.x, 800); + EXPECT_EQ(event.dimensions.y, 600); return false; }; event_manager.subscribe(on_window_resize); @@ -314,3 +314,27 @@ TEST_F(InputTest, WindowResizeTest) { event_manager.dispatch_events(); EXPECT_TRUE(callback_triggered); } +TEST_F(InputTest, WindowMoveTest) { + GameObject obj = mgr.new_object("camera", "camera", vec2{0, 0}, 0, 1); + auto & camera = obj.add_component( + ivec2{0, 0}, vec2{500, 500}, Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f}); + camera.active = true; + bool callback_triggered = false; + EventHandler on_window_move = [&](const WindowMoveEvent & event) { + callback_triggered = true; + EXPECT_EQ(event.delta_move.x, 800); + EXPECT_EQ(event.delta_move.y, 600); + return false; + }; + event_manager.subscribe(on_window_move); + SDL_Event resize_event; + SDL_zero(resize_event); + resize_event.type = SDL_WINDOWEVENT; + resize_event.window.event = SDL_WINDOWEVENT_MOVED; + resize_event.window.data1 = 800; // new width + resize_event.window.data2 = 600; // new height + SDL_PushEvent(&resize_event); + input_system.update(); + event_manager.dispatch_events(); + EXPECT_TRUE(callback_triggered); +} -- cgit v1.2.3