test/testautomation_events.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 12 Aug 2016 19:59:00 -0400
changeset 10266 c09f06c4e8c8
parent 7677 871d43c6968a
permissions -rw-r--r--
emscripten: send fake mouse events for touches, like other targets do. (This really should be handled at the higher level and not in the individual targets, but this fixes the immediate bug.)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6800
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     1
/**
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     2
 * Events test suite
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     3
 */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     4
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     5
#include <stdio.h>
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     6
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     7
#include "SDL.h"
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     8
#include "SDL_test.h"
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     9
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    10
/* ================= Test Case Implementation ================== */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    11
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    12
/* Test case functions */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    13
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    14
/* Flag indicating if the userdata should be checked */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    15
int _userdataCheck = 0;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    16
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    17
/* Userdata value to check */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    18
int _userdataValue = 0;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    19
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    20
/* Flag indicating that the filter was called */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    21
int _eventFilterCalled = 0;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    22
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    23
/* Userdata values for event */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    24
int _userdataValue1 = 1;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    25
int _userdataValue2 = 2;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    26
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    27
/* Event filter that sets some flags and optionally checks userdata */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    28
int _events_sampleNullEventFilter(void *userdata, SDL_Event *event)
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    29
{
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    30
   _eventFilterCalled = 1;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6800
diff changeset
    31
6800
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    32
   if (_userdataCheck != 0) {
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    33
       SDLTest_AssertCheck(userdata != NULL, "Check userdata pointer, expected: non-NULL, got: %s", (userdata != NULL) ? "non-NULL" : "NULL");
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    34
       if (userdata != NULL) {
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    35
          SDLTest_AssertCheck(*(int *)userdata == _userdataValue, "Check userdata value, expected: %i, got: %i", _userdataValue, *(int *)userdata);
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    36
       }
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    37
   }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6800
diff changeset
    38
6800
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    39
   return 0;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    40
}
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    41
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    42
/**
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    43
 * @brief Test pumping and peeking events.
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    44
 *
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    45
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_PumpEvents
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    46
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_PollEvent
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    47
 */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    48
int
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    49
events_pushPumpAndPollUserevent(void *arg)
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    50
{
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    51
   SDL_Event event1;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    52
   SDL_Event event2;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    53
   int result;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6800
diff changeset
    54
6800
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    55
   /* Create user event */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    56
   event1.type = SDL_USEREVENT;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    57
   event1.user.code = SDLTest_RandomSint32();
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    58
   event1.user.data1 = (void *)&_userdataValue1;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    59
   event1.user.data2 = (void *)&_userdataValue2;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6800
diff changeset
    60
7677
871d43c6968a OCD fixes: Adds a space before */
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7191
diff changeset
    61
   /* Push a user event onto the queue and force queue update */
6800
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    62
   SDL_PushEvent(&event1);
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    63
   SDLTest_AssertPass("Call to SDL_PushEvent()");
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    64
   SDL_PumpEvents();
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    65
   SDLTest_AssertPass("Call to SDL_PumpEvents()");
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6800
diff changeset
    66
6800
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    67
   /* Poll for user event */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    68
   result = SDL_PollEvent(&event2);
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    69
   SDLTest_AssertPass("Call to SDL_PollEvent()");
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    70
   SDLTest_AssertCheck(result == 1, "Check result from SDL_PollEvent, expected: 1, got: %d", result);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6800
diff changeset
    71
6800
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    72
   return TEST_COMPLETED;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    73
}
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    74
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    75
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    76
/**
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    77
 * @brief Adds and deletes an event watch function with NULL userdata
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    78
 *
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    79
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_AddEventWatch
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    80
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_DelEventWatch
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    81
 *
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    82
 */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    83
int
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    84
events_addDelEventWatch(void *arg)
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    85
{
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    86
   SDL_Event event;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6800
diff changeset
    87
6800
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    88
   /* Create user event */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    89
   event.type = SDL_USEREVENT;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    90
   event.user.code = SDLTest_RandomSint32();;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    91
   event.user.data1 = (void *)&_userdataValue1;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    92
   event.user.data2 = (void *)&_userdataValue2;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    93
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    94
   /* Disable userdata check */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    95
   _userdataCheck = 0;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    96
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    97
   /* Reset event filter call tracker */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    98
   _eventFilterCalled = 0;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    99
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6800
diff changeset
   100
   /* Add watch */
6800
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   101
   SDL_AddEventWatch(_events_sampleNullEventFilter, NULL);
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   102
   SDLTest_AssertPass("Call to SDL_AddEventWatch()");
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6800
diff changeset
   103
7677
871d43c6968a OCD fixes: Adds a space before */
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7191
diff changeset
   104
   /* Push a user event onto the queue and force queue update */
6800
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   105
   SDL_PushEvent(&event);
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   106
   SDLTest_AssertPass("Call to SDL_PushEvent()");
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   107
   SDL_PumpEvents();
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   108
   SDLTest_AssertPass("Call to SDL_PumpEvents()");
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   109
   SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   110
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   111
   /* Delete watch */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   112
   SDL_DelEventWatch(_events_sampleNullEventFilter, NULL);
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   113
   SDLTest_AssertPass("Call to SDL_DelEventWatch()");
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   114
7677
871d43c6968a OCD fixes: Adds a space before */
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7191
diff changeset
   115
   /* Push a user event onto the queue and force queue update */
6800
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   116
   _eventFilterCalled = 0;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   117
   SDL_PushEvent(&event);
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   118
   SDLTest_AssertPass("Call to SDL_PushEvent()");
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   119
   SDL_PumpEvents();
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   120
   SDLTest_AssertPass("Call to SDL_PumpEvents()");
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   121
   SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   122
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   123
   return TEST_COMPLETED;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   124
}
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   125
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   126
/**
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   127
 * @brief Adds and deletes an event watch function with userdata
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   128
 *
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   129
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_AddEventWatch
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   130
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_DelEventWatch
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   131
 *
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   132
 */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   133
int
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   134
events_addDelEventWatchWithUserdata(void *arg)
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   135
{
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   136
   SDL_Event event;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6800
diff changeset
   137
6800
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   138
   /* Create user event */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   139
   event.type = SDL_USEREVENT;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   140
   event.user.code = SDLTest_RandomSint32();;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   141
   event.user.data1 = (void *)&_userdataValue1;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   142
   event.user.data2 = (void *)&_userdataValue2;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6800
diff changeset
   143
6800
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   144
   /* Enable userdata check and set a value to check */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   145
   _userdataCheck = 1;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   146
   _userdataValue = SDLTest_RandomIntegerInRange(-1024, 1024);
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   147
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   148
   /* Reset event filter call tracker */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   149
   _eventFilterCalled = 0;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   150
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6800
diff changeset
   151
   /* Add watch */
6800
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   152
   SDL_AddEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   153
   SDLTest_AssertPass("Call to SDL_AddEventWatch()");
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   154
7677
871d43c6968a OCD fixes: Adds a space before */
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7191
diff changeset
   155
   /* Push a user event onto the queue and force queue update */
6800
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   156
   SDL_PushEvent(&event);
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   157
   SDLTest_AssertPass("Call to SDL_PushEvent()");
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   158
   SDL_PumpEvents();
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   159
   SDLTest_AssertPass("Call to SDL_PumpEvents()");
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   160
   SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   161
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   162
   /* Delete watch */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   163
   SDL_DelEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   164
   SDLTest_AssertPass("Call to SDL_DelEventWatch()");
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6800
diff changeset
   165
7677
871d43c6968a OCD fixes: Adds a space before */
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7191
diff changeset
   166
   /* Push a user event onto the queue and force queue update */
6800
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   167
   _eventFilterCalled = 0;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   168
   SDL_PushEvent(&event);
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   169
   SDLTest_AssertPass("Call to SDL_PushEvent()");
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   170
   SDL_PumpEvents();
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   171
   SDLTest_AssertPass("Call to SDL_PumpEvents()");
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   172
   SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6800
diff changeset
   173
6800
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   174
   return TEST_COMPLETED;
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   175
}
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   176
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   177
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   178
/* ================= Test References ================== */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   179
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   180
/* Events test cases */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   181
static const SDLTest_TestCaseReference eventsTest1 =
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6800
diff changeset
   182
        { (SDLTest_TestCaseFp)events_pushPumpAndPollUserevent, "events_pushPumpAndPollUserevent", "Pushes, pumps and polls a user event", TEST_ENABLED };
6800
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   183
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   184
static const SDLTest_TestCaseReference eventsTest2 =
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6800
diff changeset
   185
        { (SDLTest_TestCaseFp)events_addDelEventWatch, "events_addDelEventWatch", "Adds and deletes an event watch function with NULL userdata", TEST_ENABLED };
6800
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   186
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   187
static const SDLTest_TestCaseReference eventsTest3 =
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6800
diff changeset
   188
        { (SDLTest_TestCaseFp)events_addDelEventWatchWithUserdata, "events_addDelEventWatchWithUserdata", "Adds and deletes an event watch function with userdata", TEST_ENABLED };
6800
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   189
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   190
/* Sequence of Events test cases */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   191
static const SDLTest_TestCaseReference *eventsTests[] =  {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6800
diff changeset
   192
    &eventsTest1, &eventsTest2, &eventsTest3, NULL
6800
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   193
};
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   194
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   195
/* Events test suite (global) */
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   196
SDLTest_TestSuiteReference eventsTestSuite = {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6800
diff changeset
   197
    "Events",
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6800
diff changeset
   198
    NULL,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6800
diff changeset
   199
    eventsTests,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6800
diff changeset
   200
    NULL
6800
26c6795ec1a4 Add new test suites (events, keyboard, syswm, video) with a few new tests each
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   201
};