Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
201 lines (159 loc) · 6.01 KB

testautomation_events.c

File metadata and controls

201 lines (159 loc) · 6.01 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* Events test suite
*/
#include <stdio.h>
#include "SDL.h"
#include "SDL_test.h"
/* ================= Test Case Implementation ================== */
/* Test case functions */
/* Flag indicating if the userdata should be checked */
int _userdataCheck = 0;
/* Userdata value to check */
int _userdataValue = 0;
/* Flag indicating that the filter was called */
int _eventFilterCalled = 0;
/* Userdata values for event */
int _userdataValue1 = 1;
int _userdataValue2 = 2;
/* Event filter that sets some flags and optionally checks userdata */
int _events_sampleNullEventFilter(void *userdata, SDL_Event *event)
{
_eventFilterCalled = 1;
May 18, 2013
May 18, 2013
31
32
33
34
35
36
37
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);
}
}
May 18, 2013
May 18, 2013
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
return 0;
}
/**
* @brief Test pumping and peeking events.
*
* @sa http://wiki.libsdl.org/moin.cgi/SDL_PumpEvents
* @sa http://wiki.libsdl.org/moin.cgi/SDL_PollEvent
*/
int
events_pushPumpAndPollUserevent(void *arg)
{
SDL_Event event1;
SDL_Event event2;
int result;
May 18, 2013
May 18, 2013
54
55
56
57
58
59
/* Create user event */
event1.type = SDL_USEREVENT;
event1.user.code = SDLTest_RandomSint32();
event1.user.data1 = (void *)&_userdataValue1;
event1.user.data2 = (void *)&_userdataValue2;
May 18, 2013
May 18, 2013
60
61
62
63
64
65
/* Push a user event onto the queue and force queue update*/
SDL_PushEvent(&event1);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
May 18, 2013
May 18, 2013
66
67
68
69
70
/* 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);
May 18, 2013
May 18, 2013
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
return TEST_COMPLETED;
}
/**
* @brief Adds and deletes an event watch function with NULL userdata
*
* @sa http://wiki.libsdl.org/moin.cgi/SDL_AddEventWatch
* @sa http://wiki.libsdl.org/moin.cgi/SDL_DelEventWatch
*
*/
int
events_addDelEventWatch(void *arg)
{
SDL_Event event;
May 18, 2013
May 18, 2013
87
88
89
90
91
92
93
94
95
96
97
98
99
/* 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 */
_userdataCheck = 0;
/* Reset event filter call tracker */
_eventFilterCalled = 0;
May 18, 2013
May 18, 2013
100
/* Add watch */
101
102
SDL_AddEventWatch(_events_sampleNullEventFilter, NULL);
SDLTest_AssertPass("Call to SDL_AddEventWatch()");
May 18, 2013
May 18, 2013
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* Push a user event onto the queue and force queue update*/
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
/* Delete watch */
SDL_DelEventWatch(_events_sampleNullEventFilter, NULL);
SDLTest_AssertPass("Call to SDL_DelEventWatch()");
/* Push a user event onto the queue and force queue update*/
_eventFilterCalled = 0;
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
return TEST_COMPLETED;
}
/**
* @brief Adds and deletes an event watch function with userdata
*
* @sa http://wiki.libsdl.org/moin.cgi/SDL_AddEventWatch
* @sa http://wiki.libsdl.org/moin.cgi/SDL_DelEventWatch
*
*/
int
events_addDelEventWatchWithUserdata(void *arg)
{
SDL_Event event;
May 18, 2013
May 18, 2013
137
138
139
140
141
142
/* Create user event */
event.type = SDL_USEREVENT;
event.user.code = SDLTest_RandomSint32();;
event.user.data1 = (void *)&_userdataValue1;
event.user.data2 = (void *)&_userdataValue2;
May 18, 2013
May 18, 2013
143
144
145
146
147
148
149
150
/* Enable userdata check and set a value to check */
_userdataCheck = 1;
_userdataValue = SDLTest_RandomIntegerInRange(-1024, 1024);
/* Reset event filter call tracker */
_eventFilterCalled = 0;
May 18, 2013
May 18, 2013
151
/* Add watch */
152
153
154
155
156
157
158
159
160
161
162
163
164
SDL_AddEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
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()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
/* Delete watch */
SDL_DelEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
SDLTest_AssertPass("Call to SDL_DelEventWatch()");
May 18, 2013
May 18, 2013
165
166
167
168
169
170
171
172
/* Push a user event onto the queue and force queue update*/
_eventFilterCalled = 0;
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
SDLTest_AssertPass("Call to SDL_PumpEvents()");
SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
May 18, 2013
May 18, 2013
173
174
175
176
177
178
179
180
181
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Events test cases */
static const SDLTest_TestCaseReference eventsTest1 =
May 18, 2013
May 18, 2013
182
{ (SDLTest_TestCaseFp)events_pushPumpAndPollUserevent, "events_pushPumpAndPollUserevent", "Pushes, pumps and polls a user event", TEST_ENABLED };
183
184
static const SDLTest_TestCaseReference eventsTest2 =
May 18, 2013
May 18, 2013
185
{ (SDLTest_TestCaseFp)events_addDelEventWatch, "events_addDelEventWatch", "Adds and deletes an event watch function with NULL userdata", TEST_ENABLED };
186
187
static const SDLTest_TestCaseReference eventsTest3 =
May 18, 2013
May 18, 2013
188
{ (SDLTest_TestCaseFp)events_addDelEventWatchWithUserdata, "events_addDelEventWatchWithUserdata", "Adds and deletes an event watch function with userdata", TEST_ENABLED };
189
190
191
/* Sequence of Events test cases */
static const SDLTest_TestCaseReference *eventsTests[] = {
May 18, 2013
May 18, 2013
192
&eventsTest1, &eventsTest2, &eventsTest3, NULL
193
194
195
196
};
/* Events test suite (global) */
SDLTest_TestSuiteReference eventsTestSuite = {
May 18, 2013
May 18, 2013
197
198
199
200
"Events",
NULL,
eventsTests,
NULL