diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-22 12:32:22 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-22 12:32:22 +0100 |
commit | 61148c757a1f742ff09e40e5347e74e638c7371c (patch) | |
tree | a2e40998981fa6f12430d2a1254250219f30d44f /src/test/EventTest.cpp | |
parent | e2162171c7ab72f450f73a0908946aa4a4dee5ee (diff) |
Diffstat (limited to 'src/test/EventTest.cpp')
-rw-r--r-- | src/test/EventTest.cpp | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/src/test/EventTest.cpp b/src/test/EventTest.cpp index f8be3fe..6105679 100644 --- a/src/test/EventTest.cpp +++ b/src/test/EventTest.cpp @@ -10,7 +10,7 @@ using namespace crepe; class EventManagerTest : public ::testing::Test { protected: Mediator mediator; - EventManager event_mgr{mediator}; + EventManager event_mgr {mediator}; void SetUp() override { // Clear any existing subscriptions or events before each test event_mgr.clear(); @@ -30,18 +30,20 @@ TEST_F(EventManagerTest, EventSubscription) { // Verify subscription (not directly verifiable; test by triggering event) event_mgr.trigger_event<KeyPressEvent>( - KeyPressEvent{ + KeyPressEvent { .repeat = true, .key = Keycode::A, }, - 1); + 1 + ); event_mgr.trigger_event<KeyPressEvent>( - KeyPressEvent{ + KeyPressEvent { .repeat = true, .key = Keycode::A, }, - EventManager::CHANNEL_ALL); + EventManager::CHANNEL_ALL + ); } TEST_F(EventManagerTest, EventManagerTest_trigger_all_channels) { bool triggered = false; @@ -55,7 +57,7 @@ TEST_F(EventManagerTest, EventManagerTest_trigger_all_channels) { }; event_mgr.subscribe<MouseClickEvent>(mouse_handler, EventManager::CHANNEL_ALL); - MouseClickEvent click_event{.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE}; + MouseClickEvent click_event {.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE}; event_mgr.trigger_event<MouseClickEvent>(click_event, EventManager::CHANNEL_ALL); EXPECT_TRUE(triggered); @@ -72,7 +74,7 @@ TEST_F(EventManagerTest, EventManagerTest_trigger_one_channel) { }; event_mgr.subscribe<MouseClickEvent>(mouse_handler, test_channel); - MouseClickEvent click_event{.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE}; + MouseClickEvent click_event {.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE}; event_mgr.trigger_event<MouseClickEvent>(click_event, EventManager::CHANNEL_ALL); EXPECT_FALSE(triggered); @@ -103,7 +105,7 @@ TEST_F(EventManagerTest, EventManagerTest_callback_propagation) { }; // Test event - MouseClickEvent click_event{.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE}; + MouseClickEvent click_event {.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE}; event_mgr.subscribe<MouseClickEvent>(mouse_handler_true, EventManager::CHANNEL_ALL); event_mgr.subscribe<MouseClickEvent>(mouse_handler_false, EventManager::CHANNEL_ALL); @@ -151,10 +153,12 @@ TEST_F(EventManagerTest, EventManagerTest_queue_dispatch) { event_mgr.subscribe<MouseClickEvent>(mouse_handler2, test_channel); event_mgr.queue_event<MouseClickEvent>( - MouseClickEvent{.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE}); + MouseClickEvent {.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE} + ); event_mgr.queue_event<MouseClickEvent>( - MouseClickEvent{.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE}, - test_channel); + MouseClickEvent {.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE}, + test_channel + ); event_mgr.dispatch_events(); EXPECT_TRUE(triggered1); EXPECT_TRUE(triggered2); @@ -188,7 +192,8 @@ TEST_F(EventManagerTest, EventManagerTest_unsubscribe) { // Queue events event_mgr.queue_event<MouseClickEvent>( - MouseClickEvent{.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE}); + MouseClickEvent {.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE} + ); // Dispatch events - both handlers should be triggered event_mgr.dispatch_events(); @@ -204,7 +209,8 @@ TEST_F(EventManagerTest, EventManagerTest_unsubscribe) { // Queue the same event again event_mgr.queue_event<MouseClickEvent>( - MouseClickEvent{.mouse_pos = {100, 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_mgr.dispatch_events(); @@ -219,7 +225,8 @@ TEST_F(EventManagerTest, EventManagerTest_unsubscribe) { // Queue the event again event_mgr.queue_event<MouseClickEvent>( - MouseClickEvent{.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE}); + MouseClickEvent {.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE} + ); // Dispatch events - no handler should be triggered event_mgr.dispatch_events(); |