diff options
author | max-001 <maxsmits21@kpnmail.nl> | 2024-12-05 17:25:50 +0100 |
---|---|---|
committer | max-001 <maxsmits21@kpnmail.nl> | 2024-12-05 17:25:50 +0100 |
commit | 0b942f4d6eb87fb623afbbae617478674c612ccc (patch) | |
tree | 9fd575e1793367e744b60b7d2bed626a72dc70f4 /src/test/EventTest.cpp | |
parent | 121387ba92a23d6f17b36331d25757abc899f7d2 (diff) | |
parent | 1f4e961d7f9d6887c807cac1a362f2d178b0860b (diff) |
Merge remote-tracking branch 'origin/master' into max/AI
Diffstat (limited to 'src/test/EventTest.cpp')
-rw-r--r-- | src/test/EventTest.cpp | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/src/test/EventTest.cpp b/src/test/EventTest.cpp index b0e6c9c..4a4872d 100644 --- a/src/test/EventTest.cpp +++ b/src/test/EventTest.cpp @@ -1,10 +1,11 @@ - -#include "api/Event.h" -#include "api/EventManager.h" -#include "api/IKeyListener.h" -#include "api/IMouseListener.h" #include <gmock/gmock.h> #include <gtest/gtest.h> + +#include <crepe/api/Event.h> +#include <crepe/api/IKeyListener.h> +#include <crepe/api/IMouseListener.h> +#include <crepe/manager/EventManager.h> + using namespace std; using namespace std::chrono_literals; using namespace crepe; @@ -36,10 +37,7 @@ public: }; TEST_F(EventManagerTest, EventSubscription) { - EventHandler<KeyPressEvent> key_handler = [](const KeyPressEvent & e) { - std::cout << "Key Event Triggered" << std::endl; - return true; - }; + EventHandler<KeyPressEvent> key_handler = [](const KeyPressEvent & e) { return true; }; // Subscribe to KeyPressEvent EventManager::get_instance().subscribe<KeyPressEvent>(key_handler, 1); @@ -158,29 +156,37 @@ TEST_F(EventManagerTest, EventManagerTest_queue_dispatch) { bool triggered1 = false; bool triggered2 = false; int test_channel = 1; - EventHandler<MouseClickEvent> mouse_handler1 = [&](const MouseClickEvent & e) { + + // Adjusted to use KeyPressEvent with repeat as the first variable + EventHandler<KeyPressEvent> key_handler1 = [&](const KeyPressEvent & e) { triggered1 = true; - EXPECT_EQ(e.mouse_x, 100); - EXPECT_EQ(e.mouse_y, 200); - EXPECT_EQ(e.button, MouseButton::LEFT_MOUSE); + 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<MouseClickEvent> mouse_handler2 = [&](const MouseClickEvent & e) { + + EventHandler<KeyPressEvent> key_handler2 = [&](const KeyPressEvent & e) { triggered2 = true; - EXPECT_EQ(e.mouse_x, 100); - EXPECT_EQ(e.mouse_y, 200); - EXPECT_EQ(e.button, MouseButton::LEFT_MOUSE); + EXPECT_EQ(e.repeat, false); // Expecting repeat to be false + EXPECT_EQ(e.key, Keycode::A); // Adjust expected key code 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}, + // 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); } |