test/testautomation_events.c
changeset 7191 75360622e65f
parent 6800 26c6795ec1a4
child 7677 871d43c6968a
equal deleted inserted replaced
7190:11612d544fcd 7191:75360622e65f
    26 
    26 
    27 /* Event filter that sets some flags and optionally checks userdata */
    27 /* Event filter that sets some flags and optionally checks userdata */
    28 int _events_sampleNullEventFilter(void *userdata, SDL_Event *event)
    28 int _events_sampleNullEventFilter(void *userdata, SDL_Event *event)
    29 {
    29 {
    30    _eventFilterCalled = 1;
    30    _eventFilterCalled = 1;
    31    
    31 
    32    if (_userdataCheck != 0) {
    32    if (_userdataCheck != 0) {
    33        SDLTest_AssertCheck(userdata != NULL, "Check userdata pointer, expected: non-NULL, got: %s", (userdata != NULL) ? "non-NULL" : "NULL");
    33        SDLTest_AssertCheck(userdata != NULL, "Check userdata pointer, expected: non-NULL, got: %s", (userdata != NULL) ? "non-NULL" : "NULL");
    34        if (userdata != NULL) {
    34        if (userdata != NULL) {
    35           SDLTest_AssertCheck(*(int *)userdata == _userdataValue, "Check userdata value, expected: %i, got: %i", _userdataValue, *(int *)userdata);
    35           SDLTest_AssertCheck(*(int *)userdata == _userdataValue, "Check userdata value, expected: %i, got: %i", _userdataValue, *(int *)userdata);
    36        }
    36        }
    37    }
    37    }
    38    
    38 
    39    return 0;
    39    return 0;
    40 }
    40 }
    41 
    41 
    42 /**
    42 /**
    43  * @brief Test pumping and peeking events.
    43  * @brief Test pumping and peeking events.
    49 events_pushPumpAndPollUserevent(void *arg)
    49 events_pushPumpAndPollUserevent(void *arg)
    50 {
    50 {
    51    SDL_Event event1;
    51    SDL_Event event1;
    52    SDL_Event event2;
    52    SDL_Event event2;
    53    int result;
    53    int result;
    54    
    54 
    55    /* Create user event */
    55    /* Create user event */
    56    event1.type = SDL_USEREVENT;
    56    event1.type = SDL_USEREVENT;
    57    event1.user.code = SDLTest_RandomSint32();
    57    event1.user.code = SDLTest_RandomSint32();
    58    event1.user.data1 = (void *)&_userdataValue1;
    58    event1.user.data1 = (void *)&_userdataValue1;
    59    event1.user.data2 = (void *)&_userdataValue2;
    59    event1.user.data2 = (void *)&_userdataValue2;
    60    
    60 
    61    /* Push a user event onto the queue and force queue update*/
    61    /* Push a user event onto the queue and force queue update*/
    62    SDL_PushEvent(&event1);
    62    SDL_PushEvent(&event1);
    63    SDLTest_AssertPass("Call to SDL_PushEvent()");
    63    SDLTest_AssertPass("Call to SDL_PushEvent()");
    64    SDL_PumpEvents();
    64    SDL_PumpEvents();
    65    SDLTest_AssertPass("Call to SDL_PumpEvents()");
    65    SDLTest_AssertPass("Call to SDL_PumpEvents()");
    66    
    66 
    67    /* Poll for user event */
    67    /* Poll for user event */
    68    result = SDL_PollEvent(&event2);
    68    result = SDL_PollEvent(&event2);
    69    SDLTest_AssertPass("Call to SDL_PollEvent()");
    69    SDLTest_AssertPass("Call to SDL_PollEvent()");
    70    SDLTest_AssertCheck(result == 1, "Check result from SDL_PollEvent, expected: 1, got: %d", result);
    70    SDLTest_AssertCheck(result == 1, "Check result from SDL_PollEvent, expected: 1, got: %d", result);
    71    
    71 
    72    return TEST_COMPLETED;
    72    return TEST_COMPLETED;
    73 }
    73 }
    74 
    74 
    75 
    75 
    76 /**
    76 /**
    82  */
    82  */
    83 int
    83 int
    84 events_addDelEventWatch(void *arg)
    84 events_addDelEventWatch(void *arg)
    85 {
    85 {
    86    SDL_Event event;
    86    SDL_Event event;
    87    
    87 
    88    /* Create user event */
    88    /* Create user event */
    89    event.type = SDL_USEREVENT;
    89    event.type = SDL_USEREVENT;
    90    event.user.code = SDLTest_RandomSint32();;
    90    event.user.code = SDLTest_RandomSint32();;
    91    event.user.data1 = (void *)&_userdataValue1;
    91    event.user.data1 = (void *)&_userdataValue1;
    92    event.user.data2 = (void *)&_userdataValue2;
    92    event.user.data2 = (void *)&_userdataValue2;
    95    _userdataCheck = 0;
    95    _userdataCheck = 0;
    96 
    96 
    97    /* Reset event filter call tracker */
    97    /* Reset event filter call tracker */
    98    _eventFilterCalled = 0;
    98    _eventFilterCalled = 0;
    99 
    99 
   100    /* Add watch */      
   100    /* Add watch */
   101    SDL_AddEventWatch(_events_sampleNullEventFilter, NULL);
   101    SDL_AddEventWatch(_events_sampleNullEventFilter, NULL);
   102    SDLTest_AssertPass("Call to SDL_AddEventWatch()");
   102    SDLTest_AssertPass("Call to SDL_AddEventWatch()");
   103    
   103 
   104    /* Push a user event onto the queue and force queue update*/
   104    /* Push a user event onto the queue and force queue update*/
   105    SDL_PushEvent(&event);
   105    SDL_PushEvent(&event);
   106    SDLTest_AssertPass("Call to SDL_PushEvent()");
   106    SDLTest_AssertPass("Call to SDL_PushEvent()");
   107    SDL_PumpEvents();
   107    SDL_PumpEvents();
   108    SDLTest_AssertPass("Call to SDL_PumpEvents()");
   108    SDLTest_AssertPass("Call to SDL_PumpEvents()");
   132  */
   132  */
   133 int
   133 int
   134 events_addDelEventWatchWithUserdata(void *arg)
   134 events_addDelEventWatchWithUserdata(void *arg)
   135 {
   135 {
   136    SDL_Event event;
   136    SDL_Event event;
   137    
   137 
   138    /* Create user event */
   138    /* Create user event */
   139    event.type = SDL_USEREVENT;
   139    event.type = SDL_USEREVENT;
   140    event.user.code = SDLTest_RandomSint32();;
   140    event.user.code = SDLTest_RandomSint32();;
   141    event.user.data1 = (void *)&_userdataValue1;
   141    event.user.data1 = (void *)&_userdataValue1;
   142    event.user.data2 = (void *)&_userdataValue2;
   142    event.user.data2 = (void *)&_userdataValue2;
   143    
   143 
   144    /* Enable userdata check and set a value to check */
   144    /* Enable userdata check and set a value to check */
   145    _userdataCheck = 1;
   145    _userdataCheck = 1;
   146    _userdataValue = SDLTest_RandomIntegerInRange(-1024, 1024);
   146    _userdataValue = SDLTest_RandomIntegerInRange(-1024, 1024);
   147 
   147 
   148    /* Reset event filter call tracker */
   148    /* Reset event filter call tracker */
   149    _eventFilterCalled = 0;
   149    _eventFilterCalled = 0;
   150 
   150 
   151    /* Add watch */    
   151    /* Add watch */
   152    SDL_AddEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
   152    SDL_AddEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
   153    SDLTest_AssertPass("Call to SDL_AddEventWatch()");
   153    SDLTest_AssertPass("Call to SDL_AddEventWatch()");
   154 
   154 
   155    /* Push a user event onto the queue and force queue update*/
   155    /* Push a user event onto the queue and force queue update*/
   156    SDL_PushEvent(&event);
   156    SDL_PushEvent(&event);
   160    SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
   160    SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
   161 
   161 
   162    /* Delete watch */
   162    /* Delete watch */
   163    SDL_DelEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
   163    SDL_DelEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
   164    SDLTest_AssertPass("Call to SDL_DelEventWatch()");
   164    SDLTest_AssertPass("Call to SDL_DelEventWatch()");
   165      
   165 
   166    /* Push a user event onto the queue and force queue update*/
   166    /* Push a user event onto the queue and force queue update*/
   167    _eventFilterCalled = 0;
   167    _eventFilterCalled = 0;
   168    SDL_PushEvent(&event);
   168    SDL_PushEvent(&event);
   169    SDLTest_AssertPass("Call to SDL_PushEvent()");
   169    SDLTest_AssertPass("Call to SDL_PushEvent()");
   170    SDL_PumpEvents();
   170    SDL_PumpEvents();
   171    SDLTest_AssertPass("Call to SDL_PumpEvents()");
   171    SDLTest_AssertPass("Call to SDL_PumpEvents()");
   172    SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
   172    SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
   173    
   173 
   174    return TEST_COMPLETED;
   174    return TEST_COMPLETED;
   175 }
   175 }
   176 
   176 
   177 
   177 
   178 /* ================= Test References ================== */
   178 /* ================= Test References ================== */
   179 
   179 
   180 /* Events test cases */
   180 /* Events test cases */
   181 static const SDLTest_TestCaseReference eventsTest1 =
   181 static const SDLTest_TestCaseReference eventsTest1 =
   182 		{ (SDLTest_TestCaseFp)events_pushPumpAndPollUserevent, "events_pushPumpAndPollUserevent", "Pushes, pumps and polls a user event", TEST_ENABLED };
   182         { (SDLTest_TestCaseFp)events_pushPumpAndPollUserevent, "events_pushPumpAndPollUserevent", "Pushes, pumps and polls a user event", TEST_ENABLED };
   183 
   183 
   184 static const SDLTest_TestCaseReference eventsTest2 =
   184 static const SDLTest_TestCaseReference eventsTest2 =
   185 		{ (SDLTest_TestCaseFp)events_addDelEventWatch, "events_addDelEventWatch", "Adds and deletes an event watch function with NULL userdata", TEST_ENABLED };
   185         { (SDLTest_TestCaseFp)events_addDelEventWatch, "events_addDelEventWatch", "Adds and deletes an event watch function with NULL userdata", TEST_ENABLED };
   186 
   186 
   187 static const SDLTest_TestCaseReference eventsTest3 =
   187 static const SDLTest_TestCaseReference eventsTest3 =
   188 		{ (SDLTest_TestCaseFp)events_addDelEventWatchWithUserdata, "events_addDelEventWatchWithUserdata", "Adds and deletes an event watch function with userdata", TEST_ENABLED };
   188         { (SDLTest_TestCaseFp)events_addDelEventWatchWithUserdata, "events_addDelEventWatchWithUserdata", "Adds and deletes an event watch function with userdata", TEST_ENABLED };
   189 
   189 
   190 /* Sequence of Events test cases */
   190 /* Sequence of Events test cases */
   191 static const SDLTest_TestCaseReference *eventsTests[] =  {
   191 static const SDLTest_TestCaseReference *eventsTests[] =  {
   192 	&eventsTest1, &eventsTest2, &eventsTest3, NULL
   192     &eventsTest1, &eventsTest2, &eventsTest3, NULL
   193 };
   193 };
   194 
   194 
   195 /* Events test suite (global) */
   195 /* Events test suite (global) */
   196 SDLTest_TestSuiteReference eventsTestSuite = {
   196 SDLTest_TestSuiteReference eventsTestSuite = {
   197 	"Events",
   197     "Events",
   198 	NULL,
   198     NULL,
   199 	eventsTests,
   199     eventsTests,
   200 	NULL
   200     NULL
   201 };
   201 };