Added PollEvent()

This commit is contained in:
Vraiment 2017-07-15 17:43:14 -07:00
parent 0da7b3c962
commit 088eaa873c
3 changed files with 39 additions and 1 deletions

View File

@ -20,3 +20,12 @@
*/
#include <SDL2pp/EventPolling.hh>
namespace SDL2pp {
bool PollEvent() {
SDL_Event event;
auto result = SDL_PollEvent(&event);
return result;
}
}

View File

@ -22,8 +22,10 @@
#ifndef SDL2PP_EVENTPOLLING_HH
#define SDL2PP_EVENTPOLLING_HH
namespace SDL2pp {
#include <SDL_events.h>
namespace SDL2pp {
bool PollEvent();
}
#endif

View File

@ -1,10 +1,37 @@
#include <SDL_main.h>
#include <SDL2pp/EventPolling.hh>
#include <SDL2pp/Exception.hh>
#include "testing.h"
using namespace SDL2pp;
inline SDL_Event PushUserEvent(Sint32 userCode = 0, void *data1 = nullptr, void *data2 = nullptr) {
SDL_Event event;
event.type = SDL_USEREVENT;
event.user.code = userCode;
event.user.data1 = data1;
event.user.data2 = data2;
if (SDL_PushEvent(&event) < 0) {
throw Exception("SDL_PushEvent");
}
return event;
}
BEGIN_TEST(int, char*[])
// With no callback and no polled event
{
EXPECT_TRUE(PollEvent() == false);
}
// With no callback and a polled event
{
PushUserEvent();
EXPECT_TRUE(PollEvent() == true);
EXPECT_TRUE(PollEvent() == false);
}
END_TEST()