diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-25 10:38:18 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-25 10:38:18 +0100 |
commit | 327154fd428e0798eea544d9f073f8e1293aa158 (patch) | |
tree | 0bf5ea14a33cf54ab6bbddd22bce5e72f9398cb0 /src/test/EventTest.cpp | |
parent | 987fc16a8ae124548e2074d6f46806387c03e161 (diff) |
most test working
Diffstat (limited to 'src/test/EventTest.cpp')
-rw-r--r-- | src/test/EventTest.cpp | 66 |
1 files changed, 37 insertions, 29 deletions
diff --git a/src/test/EventTest.cpp b/src/test/EventTest.cpp index b0e6c9c..4af0830 100644 --- a/src/test/EventTest.cpp +++ b/src/test/EventTest.cpp @@ -154,37 +154,45 @@ TEST_F(EventManagerTest, EventManagerTest_callback_propagation) { } TEST_F(EventManagerTest, EventManagerTest_queue_dispatch) { - EventManager & event_manager = EventManager::get_instance(); - bool triggered1 = false; - bool triggered2 = false; - int test_channel = 1; - EventHandler<MouseClickEvent> mouse_handler1 = [&](const MouseClickEvent & e) { - triggered1 = true; - EXPECT_EQ(e.mouse_x, 100); - EXPECT_EQ(e.mouse_y, 200); - EXPECT_EQ(e.button, MouseButton::LEFT_MOUSE); - return false; // Allows propagation - }; - EventHandler<MouseClickEvent> mouse_handler2 = [&](const MouseClickEvent & e) { - triggered2 = true; - EXPECT_EQ(e.mouse_x, 100); - EXPECT_EQ(e.mouse_y, 200); - EXPECT_EQ(e.button, MouseButton::LEFT_MOUSE); - return false; // Allows propagation - }; - event_manager.subscribe<MouseClickEvent>(mouse_handler1); - event_manager.subscribe<MouseClickEvent>(mouse_handler2, test_channel); - - event_manager.queue_event<MouseClickEvent>( - MouseClickEvent{.mouse_x = 100, .mouse_y = 200, .button = MouseButton::LEFT_MOUSE}); - event_manager.queue_event<MouseClickEvent>( - MouseClickEvent{.mouse_x = 100, .mouse_y = 200, .button = MouseButton::LEFT_MOUSE}, - test_channel); - event_manager.dispatch_events(); - EXPECT_TRUE(triggered1); - EXPECT_TRUE(triggered2); + EventManager & event_manager = EventManager::get_instance(); + bool triggered1 = false; + bool triggered2 = false; + int test_channel = 1; + + // Adjusted to use KeyPressEvent with repeat as the first variable + EventHandler<KeyPressEvent> key_handler1 = [&](const KeyPressEvent & e) { + triggered1 = true; + EXPECT_EQ(e.repeat, false); // Expecting repeat to be false + EXPECT_EQ(e.key, Keycode::A); // Adjust expected key code + return false; // Allows propagation + }; + + EventHandler<KeyPressEvent> key_handler2 = [&](const KeyPressEvent & e) { + triggered2 = true; + EXPECT_EQ(e.repeat, false); // Expecting repeat to be false + EXPECT_EQ(e.key, Keycode::A); // Adjust expected key code + return false; // Allows propagation + }; + + // Subscribe handlers to KeyPressEvent + event_manager.subscribe<KeyPressEvent>(key_handler1); + event_manager.subscribe<KeyPressEvent>(key_handler2, test_channel); + + // Queue a KeyPressEvent instead of KeyDownEvent + event_manager.queue_event<KeyPressEvent>( + KeyPressEvent{.repeat = false, .key = Keycode::A}); // Adjust event with repeat flag first + + event_manager.queue_event<KeyPressEvent>( + KeyPressEvent{.repeat = false, .key = Keycode::A}, // Adjust event for second subscription + test_channel); + + event_manager.dispatch_events(); + + EXPECT_TRUE(triggered1); + EXPECT_TRUE(triggered2); } + TEST_F(EventManagerTest, EventManagerTest_unsubscribe) { EventManager & event_manager = EventManager::get_instance(); |