Added PollAllEvents()

This commit is contained in:
Vraiment 2017-07-15 18:55:11 -07:00
parent 78cc589fc9
commit c10ffbb867
3 changed files with 27 additions and 0 deletions

View File

@ -28,4 +28,12 @@ namespace SDL2pp {
return result; return result;
} }
int PollAllEvents() {
int result;
for (result = 0; PollEvent(); result++);
return result;
}
} }

View File

@ -38,6 +38,8 @@ namespace SDL2pp {
return true; return true;
} }
int PollAllEvents();
} }
#endif #endif

View File

@ -111,4 +111,21 @@ BEGIN_TEST(int, char*[])
EXPECT_TRUE(PollEvent(eventHandler) == false); EXPECT_TRUE(PollEvent(eventHandler) == false);
EXPECT_TRUE(eventHandler.events.size() == 1); 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() END_TEST()