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 }

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 */
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 */
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;
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 }

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 */
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 */
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;
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 }

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;
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 }

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 }

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 }

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 }

Definition at line 187 of file testautomation_events.c.

◆ eventsTests

const SDLTest_TestCaseReference* eventsTests[]
static
Initial value:

Definition at line 191 of file testautomation_events.c.

◆ eventsTestSuite

SDLTest_TestSuiteReference eventsTestSuite
Initial value:
= {
"Events",
}

Definition at line 196 of file testautomation_events.c.

SDL_Event::type
Uint32 type
Definition: SDL_events.h:559
SDL_PollEvent
#define SDL_PollEvent
Definition: SDL_dynapi_overrides.h:122
NULL
#define NULL
Definition: begin_code.h:167
eventsTest2
static const SDLTest_TestCaseReference eventsTest2
Definition: testautomation_events.c:184
_events_sampleNullEventFilter
int _events_sampleNullEventFilter(void *userdata, SDL_Event *event)
Definition: testautomation_events.c:28
TEST_ENABLED
#define TEST_ENABLED
Definition: SDL_test_harness.h:47
eventsTests
static const SDLTest_TestCaseReference * eventsTests[]
Definition: testautomation_events.c:191
SDL_UserEvent::code
Sint32 code
Definition: SDL_events.h:532
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
SDL_PumpEvents
#define SDL_PumpEvents
Definition: SDL_dynapi_overrides.h:116
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
_userdataValue1
int _userdataValue1
Definition: testautomation_events.c:24
SDLTest_TestCaseFp
int(* SDLTest_TestCaseFp)(void *arg)
Definition: SDL_test_harness.h:67
SDLTest_AssertPass
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.
Definition: SDL_test_assert.c:94
SDL_PushEvent
#define SDL_PushEvent
Definition: SDL_dynapi_overrides.h:125
events_pushPumpAndPollUserevent
int events_pushPumpAndPollUserevent(void *arg)
Test pumping and peeking events.
Definition: testautomation_events.c:49
eventsTest3
static const SDLTest_TestCaseReference eventsTest3
Definition: testautomation_events.c:187
SDLTest_AssertCheck
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...
Definition: SDL_test_assert.c:65
_userdataValue
int _userdataValue
Definition: testautomation_events.c:18
TEST_COMPLETED
#define TEST_COMPLETED
Definition: SDL_test_harness.h:53
_userdataCheck
int _userdataCheck
Definition: testautomation_events.c:15
SDL_Event::user
SDL_UserEvent user
Definition: SDL_events.h:580
_userdataValue2
int _userdataValue2
Definition: testautomation_events.c:25
SDLTest_RandomSint32
Sint32 SDLTest_RandomSint32(void)
Definition: SDL_test_fuzzer.c:111
SDL_AddEventWatch
#define SDL_AddEventWatch
Definition: SDL_dynapi_overrides.h:128
SDL_UserEvent::data2
void * data2
Definition: SDL_events.h:534
SDL_UserEvent::data1
void * data1
Definition: SDL_events.h:533
SDL_Event
General event structure.
Definition: SDL_events.h:557
_eventFilterCalled
int _eventFilterCalled
Definition: testautomation_events.c:21
events_addDelEventWatchWithUserdata
int events_addDelEventWatchWithUserdata(void *arg)
Adds and deletes an event watch function with userdata.
Definition: testautomation_events.c:134
eventsTest1
static const SDLTest_TestCaseReference eventsTest1
Definition: testautomation_events.c:181
events_addDelEventWatch
int events_addDelEventWatch(void *arg)
Adds and deletes an event watch function with NULL userdata.
Definition: testautomation_events.c:84
SDL_DelEventWatch
#define SDL_DelEventWatch
Definition: SDL_dynapi_overrides.h:129
SDL_USEREVENT
@ SDL_USEREVENT
Definition: SDL_events.h:160
SDLTest_RandomIntegerInRange
Sint32 SDLTest_RandomIntegerInRange(Sint32 min, Sint32 max)
Definition: SDL_test_fuzzer.c:163