]> git.localhorst.tv Git - blank.git/blob - tst/io/EventTest.cpp
7f5df10ba42153692b81e835515ef7c32b739778
[blank.git] / tst / io / EventTest.cpp
1 #include "EventTest.hpp"
2
3 #include "io/event.hpp"
4
5 #include <sstream>
6 #include <string>
7 #include <SDL_syswm.h>
8
9
10 CPPUNIT_TEST_SUITE_REGISTRATION(blank::test::EventTest);
11
12 using namespace std;
13
14 namespace blank {
15 namespace test {
16
17 void EventTest::setUp() {
18
19 }
20
21 void EventTest::tearDown() {
22
23 }
24
25
26 namespace {
27
28 template<class T>
29 string string_cast(const T &val) {
30         stringstream str;
31         str << val;
32         return str.str();
33 }
34
35 }
36
37 #if SDL_VERSION_ATLEAST(2, 0, 4)
38
39 void EventTest::testAudioDevice() {
40         SDL_Event event;
41         event.type = SDL_AUDIODEVICEADDED;
42         event.adevice.which = 1;
43         event.adevice.iscapture = false;
44         CPPUNIT_ASSERT_EQUAL_MESSAGE(
45                 "output format of SDL audio device event",
46                 string("audio device added: device ID: 1, capture: no"), string_cast(event));
47         event.adevice.which = 2;
48         event.adevice.iscapture = true;
49         CPPUNIT_ASSERT_EQUAL_MESSAGE(
50                 "output format of SDL audio device event",
51                 string("audio device added: device ID: 2, capture: yes"), string_cast(event));
52                 event.type = SDL_AUDIODEVICEREMOVED;
53         event.adevice.which = 3;
54         event.adevice.iscapture = false;
55         CPPUNIT_ASSERT_EQUAL_MESSAGE(
56                 "output format of SDL audio device event",
57                 string("audio device removed: device ID: 3, capture: no"), string_cast(event));
58         event.adevice.which = 4;
59         event.adevice.iscapture = true;
60         CPPUNIT_ASSERT_EQUAL_MESSAGE(
61                 "output format of SDL audio device event",
62                 string("audio device removed: device ID: 4, capture: yes"), string_cast(event));
63 }
64
65 #endif
66
67 void EventTest::testController() {
68         SDL_Event event;
69         event.type = SDL_CONTROLLERAXISMOTION;
70         event.caxis.which = 0;
71         event.caxis.axis = 1;
72         event.caxis.value = 16384;
73         CPPUNIT_ASSERT_EQUAL_MESSAGE(
74                 "output format of SDL controller axis event",
75                 string("controller axis motion: controller ID: 0, axis ID: 1, value: 0.5"), string_cast(event));
76
77         event.type = SDL_CONTROLLERBUTTONDOWN;
78         event.cbutton.which = 2;
79         event.cbutton.button = 3;
80         event.cbutton.state = SDL_PRESSED;
81         CPPUNIT_ASSERT_EQUAL_MESSAGE(
82                 "output format of SDL controller button event",
83                 string("controller button down: controller ID: 2, button ID: 3, state: pressed"), string_cast(event));
84         event.type = SDL_CONTROLLERBUTTONUP;
85         event.cbutton.which = 4;
86         event.cbutton.button = 5;
87         event.cbutton.state = SDL_RELEASED;
88         CPPUNIT_ASSERT_EQUAL_MESSAGE(
89                 "output format of SDL controller button event",
90                 string("controller button up: controller ID: 4, button ID: 5, state: released"), string_cast(event));
91
92         event.type = SDL_CONTROLLERDEVICEADDED;
93         event.cdevice.which = 6;
94         CPPUNIT_ASSERT_EQUAL_MESSAGE(
95                 "output format of SDL controller device event",
96                 string("controller device added: controller ID: 6"), string_cast(event));
97         event.type = SDL_CONTROLLERDEVICEREMOVED;
98         event.cdevice.which = 7;
99         CPPUNIT_ASSERT_EQUAL_MESSAGE(
100                 "output format of SDL controller device event",
101                 string("controller device removed: controller ID: 7"), string_cast(event));
102         event.type = SDL_CONTROLLERDEVICEREMAPPED;
103         event.cdevice.which = 8;
104         CPPUNIT_ASSERT_EQUAL_MESSAGE(
105                 "output format of SDL controller device event",
106                 string("controller device remapped: controller ID: 8"), string_cast(event));
107 }
108
109 void EventTest::testDollar() {
110         SDL_Event event;
111         event.type = SDL_DOLLARGESTURE;
112         event.dgesture.touchId = 0;
113         event.dgesture.gestureId = 1;
114         event.dgesture.numFingers = 2;
115         event.dgesture.error = 3;
116         event.dgesture.x = 4;
117         event.dgesture.y = 5;
118         CPPUNIT_ASSERT_EQUAL_MESSAGE(
119                 "output format of SDL dollar gesture event",
120                 string("dollar gesture: device ID: 0, gesture ID: 1, fingers: 2, error: 3, position: 4 5"), string_cast(event));
121
122         event.type = SDL_DOLLARRECORD;
123         event.dgesture.touchId = 6;
124         event.dgesture.gestureId = 7;
125         event.dgesture.numFingers = 8;
126         event.dgesture.error = 9;
127         event.dgesture.x = 10;
128         event.dgesture.y = 11;
129         CPPUNIT_ASSERT_EQUAL_MESSAGE(
130                 "output format of SDL dollar record event",
131                 string("dollar record: device ID: 6, gesture ID: 7, fingers: 8, error: 9, position: 10 11"), string_cast(event));
132 }
133
134 void EventTest::testDrop() {
135         char filename[] = "/dev/random";
136         SDL_Event event;
137         event.type = SDL_DROPFILE;
138         event.drop.file = filename;
139         CPPUNIT_ASSERT_EQUAL_MESSAGE(
140                 "output format of SDL drop file event",
141                 string("drop file: file: ") + filename, string_cast(event));
142 }
143
144 void EventTest::testFinger() {
145         SDL_Event event;
146         event.type = SDL_FINGERMOTION;
147         event.tfinger.touchId = 0;
148         event.tfinger.fingerId = 1;
149         event.tfinger.x = 2;
150         event.tfinger.y = 3;
151         event.tfinger.dx = 4;
152         event.tfinger.dy = 5;
153         event.tfinger.pressure = 6;
154         CPPUNIT_ASSERT_EQUAL_MESSAGE(
155                 "output format of SDL finger motion event",
156                 string("finger motion: device ID: 0, finger ID: 1, position: 2 3, delta: 4 5, pressure: 6"), string_cast(event));
157
158         event.type = SDL_FINGERDOWN;
159         event.tfinger.touchId = 7;
160         event.tfinger.fingerId = 8;
161         event.tfinger.x = 9;
162         event.tfinger.y = 10;
163         event.tfinger.dx = 11;
164         event.tfinger.dy = 12;
165         event.tfinger.pressure = 13;
166         CPPUNIT_ASSERT_EQUAL_MESSAGE(
167                 "output format of SDL finger down event",
168                 string("finger down: device ID: 7, finger ID: 8, position: 9 10, delta: 11 12, pressure: 13"), string_cast(event));
169
170         event.type = SDL_FINGERUP;
171         event.tfinger.touchId = 14;
172         event.tfinger.fingerId = 15;
173         event.tfinger.x = 16;
174         event.tfinger.y = 17;
175         event.tfinger.dx = 18;
176         event.tfinger.dy = 19;
177         event.tfinger.pressure = 20;
178         CPPUNIT_ASSERT_EQUAL_MESSAGE(
179                 "output format of SDL finger up event",
180                 string("finger up: device ID: 14, finger ID: 15, position: 16 17, delta: 18 19, pressure: 20"), string_cast(event));
181 }
182
183 void EventTest::testKey() {
184         SDL_Event event;
185         event.type = SDL_KEYDOWN;
186         event.key.windowID = 0;
187         event.key.state = SDL_PRESSED;
188         event.key.repeat = 0;
189         event.key.keysym.scancode = SDL_SCANCODE_0;
190         event.key.keysym.sym = SDLK_0;
191         event.key.keysym.mod = KMOD_NONE;
192         CPPUNIT_ASSERT_EQUAL_MESSAGE(
193                 "output format of SDL key down event",
194                 string("key down: window ID: 0, state: pressed, repeat: no, keysym: "
195                         "scancode: ") + to_string(int(SDL_SCANCODE_0)) + ", sym: "
196                         + to_string(int(SDLK_0)) +" (\"0\")", string_cast(event));
197         event.key.windowID = 2;
198         event.key.repeat = 1;
199         event.key.keysym.scancode = SDL_SCANCODE_BACKSPACE;
200         event.key.keysym.sym = SDLK_BACKSPACE;
201         event.key.keysym.mod = KMOD_LCTRL | KMOD_LALT;
202         CPPUNIT_ASSERT_EQUAL_MESSAGE(
203                 "output format of SDL key down event",
204                 string("key down: window ID: 2, state: pressed, repeat: yes, keysym: "
205                         "scancode: ") + to_string(int(SDL_SCANCODE_BACKSPACE)) + ", sym: "
206                         + to_string(int(SDLK_BACKSPACE)) +" (\"Backspace\"), mod: LCTRL LALT", string_cast(event));
207
208         event.type = SDL_KEYUP;
209         event.key.windowID = 1;
210         event.key.state = SDL_RELEASED;
211         event.key.repeat = 0;
212         event.key.keysym.scancode = SDL_SCANCODE_SYSREQ;
213         event.key.keysym.sym = SDLK_SYSREQ;
214         event.key.keysym.mod = KMOD_LSHIFT | KMOD_RALT;
215         CPPUNIT_ASSERT_EQUAL_MESSAGE(
216                 "output format of SDL key up event",
217                 string("key up: window ID: 1, state: released, repeat: no, keysym: "
218                         "scancode: ") + to_string(int(SDL_SCANCODE_SYSREQ)) + ", sym: "
219                         + to_string(int(SDLK_SYSREQ)) +" (\"SysReq\"), mod: LSHIFT RALT", string_cast(event));
220         event.key.windowID = 3;
221         event.key.repeat = 1;
222         event.key.keysym.scancode = SDL_SCANCODE_L;
223         event.key.keysym.sym = SDLK_l;
224         event.key.keysym.mod = KMOD_RSHIFT | KMOD_LGUI;
225         CPPUNIT_ASSERT_EQUAL_MESSAGE(
226                 "output format of SDL key up event",
227                 string("key up: window ID: 3, state: released, repeat: yes, keysym: "
228                         "scancode: ") + to_string(int(SDL_SCANCODE_L)) + ", sym: "
229                         + to_string(int(SDLK_l)) +" (\"L\"), mod: RSHIFT LSUPER", string_cast(event));
230         event.key.windowID = 4;
231         event.key.repeat = 2;
232         event.key.keysym.scancode = SDL_SCANCODE_VOLUMEUP;
233         event.key.keysym.sym = SDLK_VOLUMEUP;
234         event.key.keysym.mod = KMOD_RGUI | KMOD_NUM | KMOD_CAPS | KMOD_MODE;
235         CPPUNIT_ASSERT_EQUAL_MESSAGE(
236                 "output format of SDL key up event",
237                 string("key up: window ID: 4, state: released, repeat: yes, keysym: "
238                         "scancode: ") + to_string(int(SDL_SCANCODE_VOLUMEUP)) + ", sym: "
239                         + to_string(int(SDLK_VOLUMEUP)) +" (\"VolumeUp\"), mod: RSUPER NUM CAPS ALTGR", string_cast(event));
240 }
241
242 void EventTest::testJoystick() {
243         SDL_Event event;
244         event.type = SDL_JOYAXISMOTION;
245         event.jaxis.which = 0;
246         event.jaxis.axis = 1;
247         event.jaxis.value = 16384;
248         CPPUNIT_ASSERT_EQUAL_MESSAGE(
249                 "output format of SDL joystick axis motion event",
250                 string("joystick axis motion: joystick ID: 0, axis ID: 1, value: 0.5"), string_cast(event));
251
252         event.type = SDL_JOYBALLMOTION;
253         event.jball.which = 2;
254         event.jball.ball = 3;
255         event.jball.xrel = 4;
256         event.jball.yrel = 5;
257         CPPUNIT_ASSERT_EQUAL_MESSAGE(
258                 "output format of SDL joystick ball motion event",
259                 string("joystick ball motion: joystick ID: 2, ball ID: 3, delta: 4 5"), string_cast(event));
260
261         event.type = SDL_JOYHATMOTION;
262         event.jhat.which = 6;
263         event.jhat.hat = 7;
264         event.jhat.value = SDL_HAT_LEFTUP;
265         CPPUNIT_ASSERT_EQUAL_MESSAGE(
266                 "output format of SDL joystick hat motion event",
267                 string("joystick hat motion: joystick ID: 6, hat ID: 7, value: left up"), string_cast(event));
268         event.jhat.value = SDL_HAT_UP;
269         CPPUNIT_ASSERT_EQUAL_MESSAGE(
270                 "output format of SDL joystick hat motion event",
271                 string("joystick hat motion: joystick ID: 6, hat ID: 7, value: up"), string_cast(event));
272         event.jhat.value = SDL_HAT_RIGHTUP;
273         CPPUNIT_ASSERT_EQUAL_MESSAGE(
274                 "output format of SDL joystick hat motion event",
275                 string("joystick hat motion: joystick ID: 6, hat ID: 7, value: right up"), string_cast(event));
276         event.jhat.value = SDL_HAT_LEFT;
277         CPPUNIT_ASSERT_EQUAL_MESSAGE(
278                 "output format of SDL joystick hat motion event",
279                 string("joystick hat motion: joystick ID: 6, hat ID: 7, value: left"), string_cast(event));
280         event.jhat.value = SDL_HAT_CENTERED;
281         CPPUNIT_ASSERT_EQUAL_MESSAGE(
282                 "output format of SDL joystick hat motion event",
283                 string("joystick hat motion: joystick ID: 6, hat ID: 7, value: center"), string_cast(event));
284         event.jhat.value = SDL_HAT_RIGHT;
285         CPPUNIT_ASSERT_EQUAL_MESSAGE(
286                 "output format of SDL joystick hat motion event",
287                 string("joystick hat motion: joystick ID: 6, hat ID: 7, value: right"), string_cast(event));
288         event.jhat.value = SDL_HAT_LEFTDOWN;
289         CPPUNIT_ASSERT_EQUAL_MESSAGE(
290                 "output format of SDL joystick hat motion event",
291                 string("joystick hat motion: joystick ID: 6, hat ID: 7, value: left down"), string_cast(event));
292         event.jhat.value = SDL_HAT_DOWN;
293         CPPUNIT_ASSERT_EQUAL_MESSAGE(
294                 "output format of SDL joystick hat motion event",
295                 string("joystick hat motion: joystick ID: 6, hat ID: 7, value: down"), string_cast(event));
296         event.jhat.value = SDL_HAT_RIGHTDOWN;
297         CPPUNIT_ASSERT_EQUAL_MESSAGE(
298                 "output format of SDL joystick hat motion event",
299                 string("joystick hat motion: joystick ID: 6, hat ID: 7, value: right down"), string_cast(event));
300         event.jhat.value = -1;
301         CPPUNIT_ASSERT_EQUAL_MESSAGE(
302                 "output format of SDL joystick hat motion event",
303                 string("joystick hat motion: joystick ID: 6, hat ID: 7, value: unknown"), string_cast(event));
304
305         event.type = SDL_JOYBUTTONDOWN;
306         event.jbutton.which = 8;
307         event.jbutton.button = 9;
308         event.jbutton.state = SDL_PRESSED;
309         CPPUNIT_ASSERT_EQUAL_MESSAGE(
310                 "output format of SDL joystick button down event",
311                 string("joystick button down: joystick ID: 8, button ID: 9, state: pressed"), string_cast(event));
312         event.type = SDL_JOYBUTTONUP;
313         event.jbutton.which = 10;
314         event.jbutton.button = 11;
315         event.jbutton.state = SDL_RELEASED;
316         CPPUNIT_ASSERT_EQUAL_MESSAGE(
317                 "output format of SDL joystick button up event",
318                 string("joystick button up: joystick ID: 10, button ID: 11, state: released"), string_cast(event));
319
320         event.type = SDL_JOYDEVICEADDED;
321         event.jdevice.which = 12;
322         CPPUNIT_ASSERT_EQUAL_MESSAGE(
323                 "output format of SDL joystick device added event",
324                 string("joystick device added: joystick ID: 12"), string_cast(event));
325         event.type = SDL_JOYDEVICEREMOVED;
326         event.jdevice.which = 13;
327         CPPUNIT_ASSERT_EQUAL_MESSAGE(
328                 "output format of SDL joystick device removed event",
329                 string("joystick device removed: joystick ID: 13"), string_cast(event));
330 }
331
332 void EventTest::testMouse() {
333         SDL_Event event;
334         event.type = SDL_MOUSEMOTION;
335         event.motion.windowID = 0;
336         event.motion.which = 1;
337         event.motion.x = 2;
338         event.motion.y = 3;
339         event.motion.xrel = 4;
340         event.motion.yrel = 5;
341         event.motion.state = 0;
342         CPPUNIT_ASSERT_EQUAL_MESSAGE(
343                 "output format of SDL mouse motion event",
344                 string("mouse motion: window ID: 0, mouse ID: 1, position: 2 3, delta: 4 5"), string_cast(event));
345         event.motion.windowID = 6;
346         event.motion.which = 7;
347         event.motion.x = 8;
348         event.motion.y = 9;
349         event.motion.xrel = 10;
350         event.motion.yrel = 11;
351         event.motion.state = SDL_BUTTON_LMASK | SDL_BUTTON_MMASK | SDL_BUTTON_RMASK;
352         CPPUNIT_ASSERT_EQUAL_MESSAGE(
353                 "output format of SDL mouse motion event",
354                 string("mouse motion: window ID: 6, mouse ID: 7, position: 8 9, delta: 10 11, buttons: left middle right"), string_cast(event));
355         event.motion.state = SDL_BUTTON_X1MASK | SDL_BUTTON_X2MASK;
356         CPPUNIT_ASSERT_EQUAL_MESSAGE(
357                 "output format of SDL mouse motion event",
358                 string("mouse motion: window ID: 6, mouse ID: 7, position: 8 9, delta: 10 11, buttons: X1 X2"), string_cast(event));
359
360         event.type = SDL_MOUSEBUTTONDOWN;
361         event.button.windowID = 0;
362         event.button.which = 1;
363         event.button.button = SDL_BUTTON_LEFT;
364         event.button.state = SDL_PRESSED;
365         event.button.clicks = 2;
366         event.button.x = 3;
367         event.button.y = 4;
368         CPPUNIT_ASSERT_EQUAL_MESSAGE(
369                 "output format of SDL mouse button down event",
370                 string("mouse button down: window ID: 0, mouse ID: 1, button: left, state: pressed, clicks: 2, position: 3 4"), string_cast(event));
371         event.type = SDL_MOUSEBUTTONUP;
372         event.button.windowID = 5;
373         event.button.which = 6;
374         event.button.button = SDL_BUTTON_MIDDLE;
375         event.button.clicks = 7;
376         event.button.x = 8;
377         event.button.y = 9;
378         CPPUNIT_ASSERT_EQUAL_MESSAGE(
379                 "output format of SDL mouse button up event",
380                 string("mouse button up: window ID: 5, mouse ID: 6, button: middle, state: pressed, clicks: 7, position: 8 9"), string_cast(event));
381         event.button.button = SDL_BUTTON_RIGHT;
382         CPPUNIT_ASSERT_EQUAL_MESSAGE(
383                 "output format of SDL mouse button up event",
384                 string("mouse button up: window ID: 5, mouse ID: 6, button: right, state: pressed, clicks: 7, position: 8 9"), string_cast(event));
385         event.button.button = SDL_BUTTON_X1;
386         CPPUNIT_ASSERT_EQUAL_MESSAGE(
387                 "output format of SDL mouse button up event",
388                 string("mouse button up: window ID: 5, mouse ID: 6, button: X1, state: pressed, clicks: 7, position: 8 9"), string_cast(event));
389         event.button.button = SDL_BUTTON_X2;
390         CPPUNIT_ASSERT_EQUAL_MESSAGE(
391                 "output format of SDL mouse button up event",
392                 string("mouse button up: window ID: 5, mouse ID: 6, button: X2, state: pressed, clicks: 7, position: 8 9"), string_cast(event));
393
394         event.type = SDL_MOUSEWHEEL;
395         event.wheel.windowID = 0;
396         event.wheel.which = 1;
397         event.wheel.x = 2;
398         event.wheel.y = 3;
399 #if SDL_VERSION_ATLEAST(2, 0, 4)
400         event.wheel.direction = SDL_MOUSEWHEEL_NORMAL;
401         CPPUNIT_ASSERT_EQUAL_MESSAGE(
402                 "output format of SDL mouse wheel event",
403                 string("mouse wheel: window ID: 0, mouse ID: 1, delta: 2 3, direction: normal"), string_cast(event));
404         event.wheel.windowID = 4;
405         event.wheel.which = 5;
406         event.wheel.x = 6;
407         event.wheel.y = 7;
408         event.wheel.direction = SDL_MOUSEWHEEL_FLIPPED;
409         CPPUNIT_ASSERT_EQUAL_MESSAGE(
410                 "output format of SDL mouse wheel event",
411                 string("mouse wheel: window ID: 4, mouse ID: 5, delta: 6 7, direction: flipped"), string_cast(event));
412 #else
413         CPPUNIT_ASSERT_EQUAL_MESSAGE(
414                 "output format of SDL mouse wheel event",
415                 string("mouse wheel: window ID: 0, mouse ID: 1, delta: 2 3"), string_cast(event));
416 #endif
417 }
418
419 void EventTest::testMultiGesture() {
420         SDL_Event event;
421         event.type = SDL_MULTIGESTURE;
422         event.mgesture.touchId = 0;
423         event.mgesture.dTheta = 1;
424         event.mgesture.dDist = 2;
425         event.mgesture.x = 3;
426         event.mgesture.y = 4;
427         event.mgesture.numFingers = 5;
428         CPPUNIT_ASSERT_EQUAL_MESSAGE(
429                 "output format of SDL multi gesture event",
430                 string("multi gesture: device ID: 0, theta: 1, distance: 2, position: 3 4, fingers: 5"), string_cast(event));
431 }
432
433 void EventTest::testQuit() {
434         SDL_Event event;
435         event.type = SDL_QUIT;
436         CPPUNIT_ASSERT_EQUAL_MESSAGE(
437                 "output format of SDL quit event",
438                 string("quit: quit"), string_cast(event));
439 }
440
441 void EventTest::testSysWM() {
442         SDL_Event event;
443         event.type = SDL_SYSWMEVENT;
444         event.syswm.msg = nullptr;
445         CPPUNIT_ASSERT_EQUAL_MESSAGE(
446                 "output format of SDL sys wm event",
447                 string("sys wm: without message"), string_cast(event));
448         SDL_SysWMmsg msg;
449         event.syswm.msg = &msg;
450         CPPUNIT_ASSERT_EQUAL_MESSAGE(
451                 "output format of SDL sys wm event",
452                 string("sys wm: with message"), string_cast(event));
453 }
454
455 void EventTest::testText() {
456         SDL_Event event;
457         event.type = SDL_TEXTEDITING;
458         event.edit.windowID = 0;
459         event.edit.text[0] = '\303';
460         event.edit.text[1] = '\244';
461         event.edit.text[2] = '\0';
462         event.edit.start = 1;
463         event.edit.length = 2;
464         CPPUNIT_ASSERT_EQUAL_MESSAGE(
465                 "output format of SDL text editing event",
466                 string("text editing: window ID: 0, text: \"รค\", start: 1, length: 2"), string_cast(event));
467
468         event.type = SDL_TEXTINPUT;
469         event.text.windowID = 3;
470         event.text.text[0] = '\0';
471         CPPUNIT_ASSERT_EQUAL_MESSAGE(
472                 "output format of SDL text input event",
473                 string("text input: window ID: 3, text: \"\""), string_cast(event));
474 }
475
476 void EventTest::testUser() {
477         SDL_Event event;
478         event.type = SDL_USEREVENT;
479         event.user.windowID = 0;
480         event.user.code = 1;
481         event.user.data1 = nullptr;
482         event.user.data2 = reinterpret_cast<void *>(1);
483         CPPUNIT_ASSERT_EQUAL_MESSAGE(
484                 "output format of SDL user event",
485                 string("user: window ID: 0, code: 1, data 1: 0, data 2: 0x1"), string_cast(event));
486 }
487
488 void EventTest::testWindow() {
489         SDL_Event event;
490         event.type = SDL_WINDOWEVENT;
491         event.window.event = SDL_WINDOWEVENT_SHOWN;
492         event.window.windowID = 0;
493         CPPUNIT_ASSERT_EQUAL_MESSAGE(
494                 "output format of SDL window event",
495                 string("window: shown, window ID: 0"), string_cast(event));
496
497         event.window.event = SDL_WINDOWEVENT_HIDDEN;
498         event.window.windowID = 1;
499         CPPUNIT_ASSERT_EQUAL_MESSAGE(
500                 "output format of SDL window event",
501                 string("window: hidden, window ID: 1"), string_cast(event));
502
503         event.window.event = SDL_WINDOWEVENT_EXPOSED;
504         event.window.windowID = 2;
505         CPPUNIT_ASSERT_EQUAL_MESSAGE(
506                 "output format of SDL window event",
507                 string("window: exposed, window ID: 2"), string_cast(event));
508
509         event.window.event = SDL_WINDOWEVENT_MOVED;
510         event.window.windowID = 3;
511         event.window.data1 = 4;
512         event.window.data2 = 5;
513         CPPUNIT_ASSERT_EQUAL_MESSAGE(
514                 "output format of SDL window event",
515                 string("window: moved, window ID: 3, position: 4 5"), string_cast(event));
516
517         event.window.event = SDL_WINDOWEVENT_RESIZED;
518         event.window.windowID = 6;
519         event.window.data1 = 7;
520         event.window.data2 = 8;
521         CPPUNIT_ASSERT_EQUAL_MESSAGE(
522                 "output format of SDL window event",
523                 string("window: resized, window ID: 6, size: 7x8"), string_cast(event));
524
525         event.window.event = SDL_WINDOWEVENT_SIZE_CHANGED;
526         event.window.windowID = 9;
527         event.window.data1 = 10;
528         event.window.data2 = 11;
529         CPPUNIT_ASSERT_EQUAL_MESSAGE(
530                 "output format of SDL window event",
531                 string("window: size changed, window ID: 9, size: 10x11"), string_cast(event));
532
533         event.window.event = SDL_WINDOWEVENT_MINIMIZED;
534         event.window.windowID = 12;
535         CPPUNIT_ASSERT_EQUAL_MESSAGE(
536                 "output format of SDL window event",
537                 string("window: minimized, window ID: 12"), string_cast(event));
538
539         event.window.event = SDL_WINDOWEVENT_MAXIMIZED;
540         event.window.windowID = 13;
541         CPPUNIT_ASSERT_EQUAL_MESSAGE(
542                 "output format of SDL window event",
543                 string("window: maximized, window ID: 13"), string_cast(event));
544
545         event.window.event = SDL_WINDOWEVENT_RESTORED;
546         event.window.windowID = 14;
547         CPPUNIT_ASSERT_EQUAL_MESSAGE(
548                 "output format of SDL window event",
549                 string("window: restored, window ID: 14"), string_cast(event));
550
551         event.window.event = SDL_WINDOWEVENT_ENTER;
552         event.window.windowID = 15;
553         CPPUNIT_ASSERT_EQUAL_MESSAGE(
554                 "output format of SDL window event",
555                 string("window: mouse entered, window ID: 15"), string_cast(event));
556
557         event.window.event = SDL_WINDOWEVENT_LEAVE;
558         event.window.windowID = 16;
559         CPPUNIT_ASSERT_EQUAL_MESSAGE(
560                 "output format of SDL window event",
561                 string("window: mouse left, window ID: 16"), string_cast(event));
562
563         event.window.event = SDL_WINDOWEVENT_FOCUS_GAINED;
564         event.window.windowID = 17;
565         CPPUNIT_ASSERT_EQUAL_MESSAGE(
566                 "output format of SDL window event",
567                 string("window: focus gained, window ID: 17"), string_cast(event));
568
569         event.window.event = SDL_WINDOWEVENT_FOCUS_LOST;
570         event.window.windowID = 18;
571         CPPUNIT_ASSERT_EQUAL_MESSAGE(
572                 "output format of SDL window event",
573                 string("window: focus lost, window ID: 18"), string_cast(event));
574
575         event.window.event = SDL_WINDOWEVENT_CLOSE;
576         event.window.windowID = 19;
577         CPPUNIT_ASSERT_EQUAL_MESSAGE(
578                 "output format of SDL window event",
579                 string("window: closed, window ID: 19"), string_cast(event));
580
581         event.window.event = SDL_WINDOWEVENT_NONE;
582         CPPUNIT_ASSERT_EQUAL_MESSAGE(
583                 "output format of SDL window event",
584                 string("window: unknown"), string_cast(event));
585 }
586
587 void EventTest::testUnknown() {
588         SDL_Event event;
589         // SDL_LASTEVENT holds the number of entries in the enum and therefore
590         // shouldn't be recognized as any valid event type
591         event.type = SDL_LASTEVENT;
592         CPPUNIT_ASSERT_EQUAL_MESSAGE(
593                 "output format of SDL user event",
594                 string("unknown"), string_cast(event));
595 }
596
597 }
598 }