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. More...
 
int events_addDelEventWatch (void *arg)
 Adds and deletes an event watch function with NULL userdata. More...
 
int events_addDelEventWatchWithUserdata (void *arg)
 Adds and deletes an event watch function with userdata. More...
 

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_TestCaseReferenceeventsTests []
 
SDLTest_TestSuiteReference eventsTestSuite
 

Function Documentation

◆ _events_sampleNullEventFilter()

int _events_sampleNullEventFilter ( void userdata,
SDL_Event event 
)

Definition at line 28 of file testautomation_events.c.

29{
31
32 if (_userdataCheck != 0) {
33 SDLTest_AssertCheck(userdata != NULL, "Check userdata pointer, expected: non-NULL, got: %s", (userdata != NULL) ? "non-NULL" : "NULL");
34 if (userdata != NULL) {
35 SDLTest_AssertCheck(*(int *)userdata == _userdataValue, "Check userdata value, expected: %i, got: %i", _userdataValue, *(int *)userdata);
36 }
37 }
38
39 return 0;
40}
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(2)
Assert for test cases that logs but does not break execution flow on failures. Updates assertion coun...
#define NULL
Definition: begin_code.h:167
int _userdataCheck
int _eventFilterCalled
int _userdataValue

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

Referenced by events_addDelEventWatch(), and events_addDelEventWatchWithUserdata().

◆ events_addDelEventWatch()

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.

85{
87
88 /* Create user event */
89 event.type = SDL_USEREVENT;
90 event.user.code = SDLTest_RandomSint32();
91 event.user.data1 = (void *)&_userdataValue1;
92 event.user.data2 = (void *)&_userdataValue2;
93
94 /* Disable userdata check */
96
97 /* Reset event filter call tracker */
99
100 /* Add watch */
102 SDLTest_AssertPass("Call to SDL_AddEventWatch()");
103
104 /* Push a user event onto the queue and force queue update */
106 SDLTest_AssertPass("Call to SDL_PushEvent()");
108 SDLTest_AssertPass("Call to SDL_PumpEvents()");
109 SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
110
111 /* Delete watch */
113 SDLTest_AssertPass("Call to SDL_DelEventWatch()");
114
115 /* Push a user event onto the queue and force queue update */
118 SDLTest_AssertPass("Call to SDL_PushEvent()");
120 SDLTest_AssertPass("Call to SDL_PumpEvents()");
121 SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
122
123 return TEST_COMPLETED;
124}
#define SDL_PumpEvents
#define SDL_PushEvent
#define SDL_DelEventWatch
#define SDL_AddEventWatch
@ SDL_USEREVENT
Definition: SDL_events.h:160
struct _cl_event * event
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(1)
Explicitly pass without checking an assertion condition. Updates assertion counter.
Sint32 SDLTest_RandomSint32(void)
#define TEST_COMPLETED
int _events_sampleNullEventFilter(void *userdata, SDL_Event *event)
int _userdataValue1
int _userdataValue2
General event structure.
Definition: SDL_events.h:558

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.

◆ events_addDelEventWatchWithUserdata()

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.

135{
137
138 /* Create user event */
139 event.type = SDL_USEREVENT;
140 event.user.code = SDLTest_RandomSint32();
141 event.user.data1 = (void *)&_userdataValue1;
142 event.user.data2 = (void *)&_userdataValue2;
143
144 /* Enable userdata check and set a value to check */
145 _userdataCheck = 1;
147
148 /* Reset event filter call tracker */
150
151 /* Add watch */
153 SDLTest_AssertPass("Call to SDL_AddEventWatch()");
154
155 /* Push a user event onto the queue and force queue update */
157 SDLTest_AssertPass("Call to SDL_PushEvent()");
159 SDLTest_AssertPass("Call to SDL_PumpEvents()");
160 SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
161
162 /* Delete watch */
164 SDLTest_AssertPass("Call to SDL_DelEventWatch()");
165
166 /* Push a user event onto the queue and force queue update */
169 SDLTest_AssertPass("Call to SDL_PushEvent()");
171 SDLTest_AssertPass("Call to SDL_PumpEvents()");
172 SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
173
174 return TEST_COMPLETED;
175}
Sint32 SDLTest_RandomIntegerInRange(Sint32 min, Sint32 max)

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.

◆ events_pushPumpAndPollUserevent()

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.

50{
51 SDL_Event event1;
52 SDL_Event event2;
53 int result;
54
55 /* Create user event */
56 event1.type = SDL_USEREVENT;
58 event1.user.data1 = (void *)&_userdataValue1;
59 event1.user.data2 = (void *)&_userdataValue2;
60
61 /* Push a user event onto the queue and force queue update */
62 SDL_PushEvent(&event1);
63 SDLTest_AssertPass("Call to SDL_PushEvent()");
65 SDLTest_AssertPass("Call to SDL_PumpEvents()");
66
67 /* Poll for user event */
68 result = SDL_PollEvent(&event2);
69 SDLTest_AssertPass("Call to SDL_PollEvent()");
70 SDLTest_AssertCheck(result == 1, "Check result from SDL_PollEvent, expected: 1, got: %d", result);
71
72 return TEST_COMPLETED;
73}
#define SDL_PollEvent
GLuint64EXT * result
void * data2
Definition: SDL_events.h:534
void * data1
Definition: SDL_events.h:533
Uint32 type
Definition: SDL_events.h:559
SDL_UserEvent user
Definition: SDL_events.h:580

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.

Variable Documentation

◆ _eventFilterCalled

int _eventFilterCalled = 0

◆ _userdataCheck

int _userdataCheck = 0

◆ _userdataValue

int _userdataValue = 0

◆ _userdataValue1

◆ _userdataValue2

◆ eventsTest1

const SDLTest_TestCaseReference eventsTest1
static
Initial value:
=
{ (SDLTest_TestCaseFp)events_pushPumpAndPollUserevent, "events_pushPumpAndPollUserevent", "Pushes, pumps and polls a user event", TEST_ENABLED }
#define TEST_ENABLED
int(* SDLTest_TestCaseFp)(void *arg)
int events_pushPumpAndPollUserevent(void *arg)
Test pumping and peeking events.

Definition at line 181 of file testautomation_events.c.

◆ eventsTest2

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 }
int events_addDelEventWatch(void *arg)
Adds and deletes an event watch function with NULL userdata.

Definition at line 184 of file testautomation_events.c.

◆ eventsTest3

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

Definition at line 187 of file testautomation_events.c.

◆ eventsTests

const SDLTest_TestCaseReference* eventsTests[]
static
Initial value:
= {
}
static const SDLTest_TestCaseReference eventsTest2
static const SDLTest_TestCaseReference eventsTest1
static const SDLTest_TestCaseReference eventsTest3

Definition at line 191 of file testautomation_events.c.

◆ eventsTestSuite

SDLTest_TestSuiteReference eventsTestSuite
Initial value:
= {
"Events",
}
static const SDLTest_TestCaseReference * eventsTests[]

Definition at line 196 of file testautomation_events.c.