diff --git a/SDL2pp/EventPolling.cc b/SDL2pp/EventPolling.cc index de81211..ece01e8 100644 --- a/SDL2pp/EventPolling.cc +++ b/SDL2pp/EventPolling.cc @@ -28,4 +28,12 @@ namespace SDL2pp { return result; } + + int PollAllEvents() { + int result; + + for (result = 0; PollEvent(); result++); + + return result; + } } diff --git a/SDL2pp/EventPolling.hh b/SDL2pp/EventPolling.hh index 4bb77bf..1b13ede 100644 --- a/SDL2pp/EventPolling.hh +++ b/SDL2pp/EventPolling.hh @@ -38,6 +38,8 @@ namespace SDL2pp { return true; } + + int PollAllEvents(); } #endif diff --git a/tests/test_eventpolling.cc b/tests/test_eventpolling.cc index 3e9a692..efd0945 100644 --- a/tests/test_eventpolling.cc +++ b/tests/test_eventpolling.cc @@ -111,4 +111,21 @@ BEGIN_TEST(int, char*[]) EXPECT_TRUE(PollEvent(eventHandler) == false); EXPECT_TRUE(eventHandler.events.size() == 1); } + + // With no callback and no polled events + { + EXPECT_TRUE(PollAllEvents() == 0); + } + + // With no callback and several polled events + { + constexpr int totalEvents = 5; + for (int n = 0; n < totalEvents; ++n) { + PushUserEvent(); + } + + EXPECT_TRUE(PollAllEvents() == totalEvents); + // Verify no further events + EXPECT_TRUE(PollEvent() == false); + } END_TEST()