SDL  2.0
testautomation_events.c File Reference
#include <stdio.h>
#include "SDL.h"
#include "SDL_test.h"
+ Include dependency graph for testautomation_events.c:

Go to the source code of this file.

Functions

int _events_sampleNullEventFilter (void *userdata, SDL_Event *event)
int events_pushPumpAndPollUserevent (void *arg)
 Test pumping and peeking events.
int events_addDelEventWatch (void *arg)
 Adds and deletes an event watch function with NULL userdata.
int events_addDelEventWatchWithUserdata (void *arg)
 Adds and deletes an event watch function with userdata.

Variables

int _userdataCheck = 0
int _userdataValue = 0
int _eventFilterCalled = 0
int _userdataValue1 = 1
int _userdataValue2 = 2
static const
SDLTest_TestCaseReference 
eventsTest1
static const
SDLTest_TestCaseReference 
eventsTest2
static const
SDLTest_TestCaseReference 
eventsTest3
static const
SDLTest_TestCaseReference
eventsTests []
SDLTest_TestSuiteReference eventsTestSuite

Function Documentation

int _events_sampleNullEventFilter ( void userdata,
SDL_Event event 
)

Definition at line 28 of file testautomation_events.c.

References _eventFilterCalled, _userdataCheck, _userdataValue, NULL, and SDLTest_AssertCheck().

Referenced by events_addDelEventWatch(), and events_addDelEventWatchWithUserdata().

{
if (_userdataCheck != 0) {
SDLTest_AssertCheck(userdata != NULL, "Check userdata pointer, expected: non-NULL, got: %s", (userdata != NULL) ? "non-NULL" : "NULL");
if (userdata != NULL) {
SDLTest_AssertCheck(*(int *)userdata == _userdataValue, "Check userdata value, expected: %i, got: %i", _userdataValue, *(int *)userdata);
}
}
return 0;
}
int events_addDelEventWatch ( void arg)

Adds and deletes an event watch function with NULL userdata.

See Also
http://wiki.libsdl.org/moin.cgi/SDL_AddEventWatch
http://wiki.libsdl.org/moin.cgi/SDL_DelEventWatch

Definition at line 84 of file testautomation_events.c.

References _eventFilterCalled, _events_sampleNullEventFilter(), _userdataCheck, _userdataValue1, _userdataValue2, NULL, SDL_AddEventWatch, SDL_DelEventWatch, SDL_PumpEvents, SDL_PushEvent, SDL_USEREVENT, SDLTest_AssertCheck(), SDLTest_AssertPass(), SDLTest_RandomSint32(), and TEST_COMPLETED.

{
/* Create user event */
event.type = SDL_USEREVENT;
event.user.code = SDLTest_RandomSint32();
event.user.data1 = (void *)&_userdataValue1;
event.user.data2 = (void *)&_userdataValue2;
/* Disable userdata check */
/* Reset event filter call tracker */
/* Add watch */
SDLTest_AssertPass("Call to SDL_AddEventWatch()");
/* Push a user event onto the queue and force queue update */
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
/* Delete watch */
SDLTest_AssertPass("Call to SDL_DelEventWatch()");
/* Push a user event onto the queue and force queue update */
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
}
int events_addDelEventWatchWithUserdata ( void arg)

Adds and deletes an event watch function with userdata.

See Also
http://wiki.libsdl.org/moin.cgi/SDL_AddEventWatch
http://wiki.libsdl.org/moin.cgi/SDL_DelEventWatch

Definition at line 134 of file testautomation_events.c.

References _eventFilterCalled, _events_sampleNullEventFilter(), _userdataCheck, _userdataValue, _userdataValue1, _userdataValue2, SDL_AddEventWatch, SDL_DelEventWatch, SDL_PumpEvents, SDL_PushEvent, SDL_USEREVENT, SDLTest_AssertCheck(), SDLTest_AssertPass(), SDLTest_RandomIntegerInRange(), SDLTest_RandomSint32(), and TEST_COMPLETED.

{
/* Create user event */
event.type = SDL_USEREVENT;
event.user.code = SDLTest_RandomSint32();
event.user.data1 = (void *)&_userdataValue1;
event.user.data2 = (void *)&_userdataValue2;
/* Enable userdata check and set a value to check */
/* Reset event filter call tracker */
/* Add watch */
SDLTest_AssertPass("Call to SDL_AddEventWatch()");
/* Push a user event onto the queue and force queue update */
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
/* Delete watch */
SDLTest_AssertPass("Call to SDL_DelEventWatch()");
/* Push a user event onto the queue and force queue update */
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
}
int events_pushPumpAndPollUserevent ( void arg)

Test pumping and peeking events.

See Also
http://wiki.libsdl.org/moin.cgi/SDL_PumpEvents
http://wiki.libsdl.org/moin.cgi/SDL_PollEvent

Definition at line 49 of file testautomation_events.c.

References _userdataValue1, _userdataValue2, SDL_UserEvent::code, SDL_UserEvent::data1, SDL_UserEvent::data2, SDL_PollEvent, SDL_PumpEvents, SDL_PushEvent, SDL_USEREVENT, SDLTest_AssertCheck(), SDLTest_AssertPass(), SDLTest_RandomSint32(), TEST_COMPLETED, SDL_Event::type, and SDL_Event::user.

{
SDL_Event event1;
SDL_Event event2;
int result;
/* Create user event */
event1.type = SDL_USEREVENT;
event1.user.data1 = (void *)&_userdataValue1;
event1.user.data2 = (void *)&_userdataValue2;
/* Push a user event onto the queue and force queue update */
SDL_PushEvent(&event1);
SDLTest_AssertPass("Call to SDL_PushEvent()");
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);
}

Variable Documentation

int _eventFilterCalled = 0
int _userdataCheck = 0
int _userdataValue = 0
const SDLTest_TestCaseReference eventsTest1
static
Initial value:
{ (SDLTest_TestCaseFp)events_pushPumpAndPollUserevent, "events_pushPumpAndPollUserevent", "Pushes, pumps and polls a user event", TEST_ENABLED }

Definition at line 181 of file testautomation_events.c.

const SDLTest_TestCaseReference eventsTest2
static
Initial value:
{ (SDLTest_TestCaseFp)events_addDelEventWatch, "events_addDelEventWatch", "Adds and deletes an event watch function with NULL userdata", TEST_ENABLED }

Definition at line 184 of file testautomation_events.c.

const SDLTest_TestCaseReference eventsTest3
static
Initial value:
{ (SDLTest_TestCaseFp)events_addDelEventWatchWithUserdata, "events_addDelEventWatchWithUserdata", "Adds and deletes an event watch function with userdata", TEST_ENABLED }

Definition at line 187 of file testautomation_events.c.

const SDLTest_TestCaseReference* eventsTests[]
static
Initial value:

Definition at line 191 of file testautomation_events.c.

SDLTest_TestSuiteReference eventsTestSuite
Initial value:
{
"Events",
}

Definition at line 196 of file testautomation_events.c.