aboutsummaryrefslogtreecommitdiff
path: root/src/test/EventTest.cpp
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-07 20:39:19 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-07 20:39:19 +0100
commit666292e33d6997a61d9eaff31e8180a602656474 (patch)
treedfe0f1cca9b3f8cecf0467fc598598caa32027af /src/test/EventTest.cpp
parentfdb4c99e139a264d4e15e6913a3756fc6cccb2f2 (diff)
save
Diffstat (limited to 'src/test/EventTest.cpp')
-rw-r--r--src/test/EventTest.cpp39
1 files changed, 18 insertions, 21 deletions
diff --git a/src/test/EventTest.cpp b/src/test/EventTest.cpp
index 4a4872d..53c2469 100644
--- a/src/test/EventTest.cpp
+++ b/src/test/EventTest.cpp
@@ -63,16 +63,15 @@ TEST_F(EventManagerTest, EventManagerTest_trigger_all_channels) {
EventHandler<MouseClickEvent> mouse_handler = [&](const MouseClickEvent & e) {
triggered = true;
- EXPECT_EQ(e.mouse_x, 100);
- EXPECT_EQ(e.mouse_y, 200);
+ EXPECT_EQ(e.mouse_pos.x, 100);
+ EXPECT_EQ(e.mouse_pos.y, 200);
EXPECT_EQ(e.button, MouseButton::LEFT_MOUSE);
return false;
};
EventManager::get_instance().subscribe<MouseClickEvent>(mouse_handler,
EventManager::CHANNEL_ALL);
- MouseClickEvent click_event{
- .mouse_x = 100, .mouse_y = 200, .button = MouseButton::LEFT_MOUSE};
+ MouseClickEvent click_event{.mouse_pos = {100,200}, .button = MouseButton::LEFT_MOUSE};
EventManager::get_instance().trigger_event<MouseClickEvent>(click_event,
EventManager::CHANNEL_ALL);
@@ -83,15 +82,14 @@ TEST_F(EventManagerTest, EventManagerTest_trigger_one_channel) {
int test_channel = 1;
EventHandler<MouseClickEvent> mouse_handler = [&](const MouseClickEvent & e) {
triggered = true;
- EXPECT_EQ(e.mouse_x, 100);
- EXPECT_EQ(e.mouse_y, 200);
+ EXPECT_EQ(e.mouse_pos.x, 100);
+ EXPECT_EQ(e.mouse_pos.y, 200);
EXPECT_EQ(e.button, MouseButton::LEFT_MOUSE);
return false;
};
EventManager::get_instance().subscribe<MouseClickEvent>(mouse_handler, test_channel);
- MouseClickEvent click_event{
- .mouse_x = 100, .mouse_y = 200, .button = MouseButton::LEFT_MOUSE};
+ MouseClickEvent click_event{.mouse_pos = {100,200}, .button = MouseButton::LEFT_MOUSE};
EventManager::get_instance().trigger_event<MouseClickEvent>(click_event,
EventManager::CHANNEL_ALL);
@@ -109,23 +107,22 @@ TEST_F(EventManagerTest, EventManagerTest_callback_propagation) {
// Handlers
EventHandler<MouseClickEvent> mouse_handler_true = [&](const MouseClickEvent & e) {
triggered_true = true;
- EXPECT_EQ(e.mouse_x, 100);
- EXPECT_EQ(e.mouse_y, 200);
+ EXPECT_EQ(e.mouse_pos.x, 100);
+ EXPECT_EQ(e.mouse_pos.y, 200);
EXPECT_EQ(e.button, MouseButton::LEFT_MOUSE);
return true; // Stops propagation
};
EventHandler<MouseClickEvent> mouse_handler_false = [&](const MouseClickEvent & e) {
triggered_false = true;
- EXPECT_EQ(e.mouse_x, 100);
- EXPECT_EQ(e.mouse_y, 200);
+ EXPECT_EQ(e.mouse_pos.x, 100);
+ EXPECT_EQ(e.mouse_pos.y, 200);
EXPECT_EQ(e.button, MouseButton::LEFT_MOUSE);
return false; // Allows propagation
};
// Test event
- MouseClickEvent click_event{
- .mouse_x = 100, .mouse_y = 200, .button = MouseButton::LEFT_MOUSE};
+ MouseClickEvent click_event{.mouse_pos = {100,200}, .button = MouseButton::LEFT_MOUSE};
event_manager.subscribe<MouseClickEvent>(mouse_handler_true, EventManager::CHANNEL_ALL);
event_manager.subscribe<MouseClickEvent>(mouse_handler_false, EventManager::CHANNEL_ALL);
@@ -201,16 +198,16 @@ TEST_F(EventManagerTest, EventManagerTest_unsubscribe) {
// Define EventHandlers
EventHandler<MouseClickEvent> mouse_handler1 = [&](const MouseClickEvent & e) {
triggered1 = true;
- EXPECT_EQ(e.mouse_x, 100);
- EXPECT_EQ(e.mouse_y, 200);
+ EXPECT_EQ(e.mouse_pos.x, 100);
+ EXPECT_EQ(e.mouse_pos.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.mouse_pos.x, 100);
+ EXPECT_EQ(e.mouse_pos.y, 200);
EXPECT_EQ(e.button, MouseButton::LEFT_MOUSE);
return false; // Allows propagation
};
@@ -220,7 +217,7 @@ TEST_F(EventManagerTest, EventManagerTest_unsubscribe) {
// Queue events
event_manager.queue_event<MouseClickEvent>(
- MouseClickEvent{.mouse_x = 100, .mouse_y = 200, .button = MouseButton::LEFT_MOUSE});
+ MouseClickEvent{.mouse_pos = {100,200}, .button = MouseButton::LEFT_MOUSE});
// Dispatch events - both handlers should be triggered
event_manager.dispatch_events();
@@ -236,7 +233,7 @@ TEST_F(EventManagerTest, EventManagerTest_unsubscribe) {
// Queue the same event again
event_manager.queue_event<MouseClickEvent>(
- MouseClickEvent{.mouse_x = 100, .mouse_y = 200, .button = MouseButton::LEFT_MOUSE});
+ MouseClickEvent{.mouse_pos = {100,200}, .button = MouseButton::LEFT_MOUSE});
// Dispatch events - only handler 2 should be triggered, handler 1 should NOT
event_manager.dispatch_events();
@@ -251,7 +248,7 @@ TEST_F(EventManagerTest, EventManagerTest_unsubscribe) {
// Queue the event again
event_manager.queue_event<MouseClickEvent>(
- MouseClickEvent{.mouse_x = 100, .mouse_y = 200, .button = MouseButton::LEFT_MOUSE});
+ MouseClickEvent{.mouse_pos = {100,200}, .button = MouseButton::LEFT_MOUSE});
// Dispatch events - no handler should be triggered
event_manager.dispatch_events();