Added SDL_GetWindowFromEvent
This commit is contained in:
committed by
Anonymous Maarten
parent
79f4de9f7e
commit
f57c597c60
@@ -22,6 +22,8 @@ static int g_eventFilterCalled = 0;
|
||||
static int g_userdataValue1 = 1;
|
||||
static int g_userdataValue2 = 2;
|
||||
|
||||
#define MAX_ITERATIONS 100
|
||||
|
||||
/* Event filter that sets some flags and optionally checks userdata */
|
||||
static int SDLCALL events_sampleNullEventFilter(void *userdata, SDL_Event *event)
|
||||
{
|
||||
@@ -45,31 +47,57 @@ static int SDLCALL events_sampleNullEventFilter(void *userdata, SDL_Event *event
|
||||
*/
|
||||
static int events_pushPumpAndPollUserevent(void *arg)
|
||||
{
|
||||
SDL_Event event1;
|
||||
SDL_Event event2;
|
||||
SDL_Event event_in;
|
||||
SDL_Event event_out;
|
||||
int result;
|
||||
int i;
|
||||
Sint32 ref_code = SDLTest_RandomSint32();
|
||||
SDL_Window *event_window;
|
||||
|
||||
/* Flush all events */
|
||||
SDL_FlushEvents(SDL_EVENT_FIRST, SDL_EVENT_LAST);
|
||||
SDLTest_AssertCheck(!SDL_HasEvents(SDL_EVENT_USER, SDL_EVENT_USER), "Check SDL_HasEvents returns false");
|
||||
|
||||
/* Create user event */
|
||||
event1.type = SDL_EVENT_USER;
|
||||
event1.common.timestamp = 0;
|
||||
event1.user.code = SDLTest_RandomSint32();
|
||||
event1.user.data1 = (void *)&g_userdataValue1;
|
||||
event1.user.data2 = (void *)&g_userdataValue2;
|
||||
event_in.type = SDL_EVENT_USER;
|
||||
event_in.user.windowID = 0;
|
||||
event_in.common.timestamp = 0;
|
||||
event_in.user.code = ref_code;
|
||||
event_in.user.data1 = (void *)&g_userdataValue1;
|
||||
event_in.user.data2 = (void *)&g_userdataValue2;
|
||||
|
||||
/* Push a user event onto the queue and force queue update */
|
||||
SDL_PushEvent(&event1);
|
||||
SDL_PushEvent(&event_in);
|
||||
SDLTest_AssertPass("Call to SDL_PushEvent()");
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("Call to SDL_PumpEvents()");
|
||||
|
||||
/* Poll for user event */
|
||||
result = SDL_PollEvent(&event2);
|
||||
SDLTest_AssertPass("Call to SDL_PollEvent()");
|
||||
SDLTest_AssertCheck(result == 1, "Check result from SDL_PollEvent, expected: 1, got: %d", result);
|
||||
SDLTest_AssertCheck(SDL_HasEvents(SDL_EVENT_USER, SDL_EVENT_USER), "Check SDL_HasEvents returns true");
|
||||
|
||||
/* Poll until we get a user event. */
|
||||
for (i = 0; i < MAX_ITERATIONS; i++) {
|
||||
result = SDL_PollEvent(&event_out);
|
||||
SDLTest_AssertPass("Call to SDL_PollEvent()");
|
||||
SDLTest_AssertCheck(result == 1, "Check result from SDL_PollEvent, expected: 1, got: %d", result);
|
||||
if (!result) {
|
||||
break;
|
||||
}
|
||||
if (event_out.type == SDL_EVENT_USER) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
SDLTest_AssertCheck(i < MAX_ITERATIONS, "Check the user event is seen in less then %d polls, got %d poll", MAX_ITERATIONS, i + 1);
|
||||
|
||||
SDLTest_AssertCheck(SDL_EVENT_USER == event_out.type, "Check event type is SDL_EVENT_USER, expected: 0x%x, got: 0x%" SDL_PRIx32, SDL_EVENT_USER, event_out.type);
|
||||
SDLTest_AssertCheck(ref_code == event_out.user.code, "Check SDL_Event.user.code, expected: 0x%" SDL_PRIx32 ", got: 0x%" SDL_PRIx32 , ref_code, event_out.user.code);
|
||||
SDLTest_AssertCheck(0 == event_out.user.windowID, "Check SDL_Event.user.windowID, expected: NULL , got: %" SDL_PRIu32, event_out.user.windowID);
|
||||
SDLTest_AssertCheck((void *)&g_userdataValue1 == event_out.user.data1, "Check SDL_Event.user.data1, expected: %p, got: %p", (void *)&g_userdataValue1, event_out.user.data1);
|
||||
SDLTest_AssertCheck((void *)&g_userdataValue2 == event_out.user.data2, "Check SDL_Event.user.data2, expected: %p, got: %p", (void *)&g_userdataValue2, event_out.user.data2);
|
||||
event_window = SDL_GetWindowFromEvent(&event_out);
|
||||
SDLTest_AssertCheck(NULL == SDL_GetWindowFromEvent(&event_out), "Check SDL_GetWindowFromEvent returns the window id from a user event, expected: NULL, got: %p", event_window);
|
||||
|
||||
/* Need to finish getting all events and sentinel, otherwise other tests that rely on event are in bad state */
|
||||
while (SDL_PollEvent(&event2)) {
|
||||
}
|
||||
SDL_FlushEvents(SDL_EVENT_FIRST, SDL_EVENT_LAST);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
@@ -178,21 +206,24 @@ static int events_addDelEventWatchWithUserdata(void *arg)
|
||||
/* ================= Test References ================== */
|
||||
|
||||
/* Events test cases */
|
||||
static const SDLTest_TestCaseReference eventsTest1 = {
|
||||
(SDLTest_TestCaseFp)events_pushPumpAndPollUserevent, "events_pushPumpAndPollUserevent", "Pushes, pumps and polls a user event", TEST_ENABLED
|
||||
static const SDLTest_TestCaseReference eventsTest_pushPumpAndPollUserevent = {
|
||||
events_pushPumpAndPollUserevent, "events_pushPumpAndPollUserevent", "Pushes, pumps and polls a user event", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference eventsTest2 = {
|
||||
(SDLTest_TestCaseFp)events_addDelEventWatch, "events_addDelEventWatch", "Adds and deletes an event watch function with NULL userdata", TEST_ENABLED
|
||||
static const SDLTest_TestCaseReference eventsTest_addDelEventWatch = {
|
||||
events_addDelEventWatch, "events_addDelEventWatch", "Adds and deletes an event watch function with NULL userdata", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference eventsTest3 = {
|
||||
(SDLTest_TestCaseFp)events_addDelEventWatchWithUserdata, "events_addDelEventWatchWithUserdata", "Adds and deletes an event watch function with userdata", TEST_ENABLED
|
||||
static const SDLTest_TestCaseReference eventsTest_addDelEventWatchWithUserdata = {
|
||||
events_addDelEventWatchWithUserdata, "events_addDelEventWatchWithUserdata", "Adds and deletes an event watch function with userdata", TEST_ENABLED
|
||||
};
|
||||
|
||||
/* Sequence of Events test cases */
|
||||
static const SDLTest_TestCaseReference *eventsTests[] = {
|
||||
&eventsTest1, &eventsTest2, &eventsTest3, NULL
|
||||
&eventsTest_pushPumpAndPollUserevent,
|
||||
&eventsTest_addDelEventWatch,
|
||||
&eventsTest_addDelEventWatchWithUserdata,
|
||||
NULL
|
||||
};
|
||||
|
||||
/* Events test suite (global) */
|
||||
|
||||
Reference in New Issue
Block a user