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.

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

Referenced by events_addDelEventWatch(), and events_addDelEventWatchWithUserdata().

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 _eventFilterCalled
int _userdataCheck
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:164
int _userdataValue

◆ 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.

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.

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 */
95  _userdataCheck = 0;
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 */
105  SDL_PushEvent(&event);
106  SDLTest_AssertPass("Call to SDL_PushEvent()");
107  SDL_PumpEvents();
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 */
116  _eventFilterCalled = 0;
117  SDL_PushEvent(&event);
118  SDLTest_AssertPass("Call to SDL_PushEvent()");
119  SDL_PumpEvents();
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_DelEventWatch
Sint32 SDLTest_RandomSint32(void)
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.
int _eventFilterCalled
#define SDL_PumpEvents
int _userdataCheck
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...
struct _cl_event * event
int _events_sampleNullEventFilter(void *userdata, SDL_Event *event)
#define SDL_PushEvent
int _userdataValue1
#define TEST_COMPLETED
#define NULL
Definition: begin_code.h:164
#define SDL_AddEventWatch
General event structure.
Definition: SDL_events.h:525
int _userdataValue2

◆ 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.

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.

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 */
149  _eventFilterCalled = 0;
150 
151  /* Add watch */
153  SDLTest_AssertPass("Call to SDL_AddEventWatch()");
154 
155  /* Push a user event onto the queue and force queue update */
156  SDL_PushEvent(&event);
157  SDLTest_AssertPass("Call to SDL_PushEvent()");
158  SDL_PumpEvents();
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 */
167  _eventFilterCalled = 0;
168  SDL_PushEvent(&event);
169  SDLTest_AssertPass("Call to SDL_PushEvent()");
170  SDL_PumpEvents();
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 }
#define SDL_DelEventWatch
Sint32 SDLTest_RandomIntegerInRange(Sint32 min, Sint32 max)
Sint32 SDLTest_RandomSint32(void)
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.
int _eventFilterCalled
#define SDL_PumpEvents
int _userdataCheck
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...
struct _cl_event * event
int _events_sampleNullEventFilter(void *userdata, SDL_Event *event)
#define SDL_PushEvent
int _userdataValue1
#define TEST_COMPLETED
#define SDL_AddEventWatch
int _userdataValue
General event structure.
Definition: SDL_events.h:525
int _userdataValue2

◆ 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.

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.

50 {
51  SDL_Event event1;
52  SDL_Event event2;
53  int result;
54 
55  /* Create user event */
56  event1.type = SDL_USEREVENT;
57  event1.user.code = SDLTest_RandomSint32();
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 }
void * data1
Definition: SDL_events.h:501
#define SDL_PollEvent
GLuint64EXT * result
void * data2
Definition: SDL_events.h:502
Sint32 SDLTest_RandomSint32(void)
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.
#define SDL_PumpEvents
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 SDL_PushEvent
int _userdataValue1
#define TEST_COMPLETED
General event structure.
Definition: SDL_events.h:525
SDL_UserEvent user
Definition: SDL_events.h:546
Uint32 type
Definition: SDL_events.h:527
int _userdataValue2

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 }
int(* SDLTest_TestCaseFp)(void *arg)
#define TEST_ENABLED
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.
int(* SDLTest_TestCaseFp)(void *arg)
#define TEST_ENABLED

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(* SDLTest_TestCaseFp)(void *arg)
int events_addDelEventWatchWithUserdata(void *arg)
Adds and deletes an event watch function with userdata.
#define TEST_ENABLED

Definition at line 187 of file testautomation_events.c.

◆ eventsTests

const SDLTest_TestCaseReference* eventsTests[]
static
Initial value:
= {
}
static const SDLTest_TestCaseReference eventsTest3
static const SDLTest_TestCaseReference eventsTest2
#define NULL
Definition: begin_code.h:164
static const SDLTest_TestCaseReference eventsTest1

Definition at line 191 of file testautomation_events.c.

◆ eventsTestSuite

SDLTest_TestSuiteReference eventsTestSuite
Initial value:
= {
"Events",
}
static const SDLTest_TestCaseReference * eventsTests[]
#define NULL
Definition: begin_code.h:164

Definition at line 196 of file testautomation_events.c.