test/testautomation_events.c
author David Ludwig <dludwig@pobox.com>
Wed, 25 Dec 2013 21:39:48 -0500
changeset 8563 c0e68f3b6bbb
parent 7677 871d43c6968a
child 10517 563edd87e287
permissions -rw-r--r--
WinRT: compiled the d3d11 renderer's shaders into SDL itself

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