SDL 2.0
testautomation_events.c
Go to the documentation of this file.
1/**
2 * Events test suite
3 */
4
5#include <stdio.h>
6
7#include "SDL.h"
8#include "SDL_test.h"
9
10/* ================= Test Case Implementation ================== */
11
12/* Test case functions */
13
14/* Flag indicating if the userdata should be checked */
16
17/* Userdata value to check */
19
20/* Flag indicating that the filter was called */
22
23/* Userdata values for event */
26
27/* Event filter that sets some flags and optionally checks userdata */
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}
41
42/**
43 * @brief Test pumping and peeking events.
44 *
45 * @sa http://wiki.libsdl.org/moin.cgi/SDL_PumpEvents
46 * @sa http://wiki.libsdl.org/moin.cgi/SDL_PollEvent
47 */
48int
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}
74
75
76/**
77 * @brief Adds and deletes an event watch function with NULL userdata
78 *
79 * @sa http://wiki.libsdl.org/moin.cgi/SDL_AddEventWatch
80 * @sa http://wiki.libsdl.org/moin.cgi/SDL_DelEventWatch
81 *
82 */
83int
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}
125
126/**
127 * @brief Adds and deletes an event watch function with userdata
128 *
129 * @sa http://wiki.libsdl.org/moin.cgi/SDL_AddEventWatch
130 * @sa http://wiki.libsdl.org/moin.cgi/SDL_DelEventWatch
131 *
132 */
133int
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}
176
177
178/* ================= Test References ================== */
179
180/* Events test cases */
182 { (SDLTest_TestCaseFp)events_pushPumpAndPollUserevent, "events_pushPumpAndPollUserevent", "Pushes, pumps and polls a user event", TEST_ENABLED };
183
185 { (SDLTest_TestCaseFp)events_addDelEventWatch, "events_addDelEventWatch", "Adds and deletes an event watch function with NULL userdata", TEST_ENABLED };
186
188 { (SDLTest_TestCaseFp)events_addDelEventWatchWithUserdata, "events_addDelEventWatchWithUserdata", "Adds and deletes an event watch function with userdata", TEST_ENABLED };
189
190/* Sequence of Events test cases */
193};
194
195/* Events test suite (global) */
197 "Events",
198 NULL,
200 NULL
201};
#define SDL_PumpEvents
#define SDL_PollEvent
#define SDL_PushEvent
#define SDL_DelEventWatch
#define SDL_AddEventWatch
@ SDL_USEREVENT
Definition: SDL_events.h:160
#define SDLCALL
Definition: SDL_internal.h:49
struct _cl_event * event
GLuint64EXT * result
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 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...
Sint32 SDLTest_RandomSint32(void)
Sint32 SDLTest_RandomIntegerInRange(Sint32 min, Sint32 max)
#define TEST_ENABLED
#define TEST_COMPLETED
int(* SDLTest_TestCaseFp)(void *arg)
#define NULL
Definition: begin_code.h:167
void * data2
Definition: SDL_events.h:534
void * data1
Definition: SDL_events.h:533
int events_addDelEventWatch(void *arg)
Adds and deletes an event watch function with NULL userdata.
SDLTest_TestSuiteReference eventsTestSuite
int _events_sampleNullEventFilter(void *userdata, SDL_Event *event)
int _userdataValue1
int _userdataValue2
int events_pushPumpAndPollUserevent(void *arg)
Test pumping and peeking events.
int _userdataCheck
int events_addDelEventWatchWithUserdata(void *arg)
Adds and deletes an event watch function with userdata.
static const SDLTest_TestCaseReference eventsTest2
int _eventFilterCalled
static const SDLTest_TestCaseReference eventsTest1
int _userdataValue
static const SDLTest_TestCaseReference * eventsTests[]
static const SDLTest_TestCaseReference eventsTest3
General event structure.
Definition: SDL_events.h:558
Uint32 type
Definition: SDL_events.h:559
SDL_UserEvent user
Definition: SDL_events.h:580