test/testautomation_timer.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Wed, 17 Aug 2016 21:04:50 +0200
changeset 10275 ba7dc3ebb81e
parent 9260 039714172dc3
permissions -rw-r--r--
Emscripten: Fixed opening previously closed joystick.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     1
/**
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     2
 * Timer test suite
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     3
 */
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     4
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     5
#include <stdio.h>
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     6
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     7
#include "SDL.h"
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     8
#include "SDL_test.h"
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     9
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    10
/* Flag indicating if the param should be checked */
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    11
int _paramCheck = 0;
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    12
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    13
/* Userdata value to check */
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    14
int _paramValue = 0;
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    15
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    16
/* Flag indicating that the callback was called */
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    17
int _timerCallbackCalled = 0;
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    18
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    19
/* Fixture */
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    20
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    21
void
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    22
_timerSetUp(void *arg)
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    23
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
    24
    /* Start SDL timer subsystem */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
    25
    int ret = SDL_InitSubSystem( SDL_INIT_TIMER );
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    26
        SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_TIMER)");
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
    27
    SDLTest_AssertCheck(ret==0, "Check result from SDL_InitSubSystem(SDL_INIT_TIMER)");
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
    28
    if (ret != 0) {
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    29
           SDLTest_LogError("%s", SDL_GetError());
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    30
        }
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    31
}
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    32
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    33
/* Test case functions */
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    34
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    35
/**
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    36
 * @brief Call to SDL_GetPerformanceCounter
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    37
 */
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    38
int
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    39
timer_getPerformanceCounter(void *arg)
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    40
{
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    41
  Uint64 result;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
    42
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    43
  result = SDL_GetPerformanceCounter();
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    44
  SDLTest_AssertPass("Call to SDL_GetPerformanceCounter()");
9260
039714172dc3 switch to use SDL_PRI* macros for long long formatting everywhere.
Edward Rudd <urkle@outoforder.cc>
parents: 9254
diff changeset
    45
  SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %"SDL_PRIu64, result);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
    46
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    47
  return TEST_COMPLETED;
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    48
}
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    49
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    50
/**
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    51
 * @brief Call to SDL_GetPerformanceFrequency
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    52
 */
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    53
int
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    54
timer_getPerformanceFrequency(void *arg)
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    55
{
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    56
  Uint64 result;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
    57
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    58
  result = SDL_GetPerformanceFrequency();
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    59
  SDLTest_AssertPass("Call to SDL_GetPerformanceFrequency()");
9260
039714172dc3 switch to use SDL_PRI* macros for long long formatting everywhere.
Edward Rudd <urkle@outoforder.cc>
parents: 9254
diff changeset
    60
  SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %"SDL_PRIu64, result);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
    61
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    62
  return TEST_COMPLETED;
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    63
}
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    64
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    65
/**
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    66
 * @brief Call to SDL_Delay and SDL_GetTicks
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    67
 */
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    68
int
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    69
timer_delayAndGetTicks(void *arg)
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    70
{
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    71
  const Uint32 testDelay = 100;
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    72
  const Uint32 marginOfError = 25;
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    73
  Uint32 result;
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    74
  Uint32 result2;
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    75
  Uint32 difference;
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    76
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
    77
  /* Zero delay */
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    78
  SDL_Delay(0);
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    79
  SDLTest_AssertPass("Call to SDL_Delay(0)");
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
    80
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    81
  /* Non-zero delay */
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    82
  SDL_Delay(1);
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    83
  SDLTest_AssertPass("Call to SDL_Delay(1)");
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    84
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    85
  SDL_Delay(SDLTest_RandomIntegerInRange(5, 15));
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    86
  SDLTest_AssertPass("Call to SDL_Delay()");
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
    87
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
    88
  /* Get ticks count - should be non-zero by now */
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    89
  result = SDL_GetTicks();
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    90
  SDLTest_AssertPass("Call to SDL_GetTicks()");
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    91
  SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %d", result);
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    92
7144
c700de9c8ed4 Corrected spelling in C source files of test suites.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 6815
diff changeset
    93
  /* Delay a bit longer and measure ticks and verify difference */
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    94
  SDL_Delay(testDelay);
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    95
  SDLTest_AssertPass("Call to SDL_Delay(%d)", testDelay);
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    96
  result2 = SDL_GetTicks();
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    97
  SDLTest_AssertPass("Call to SDL_GetTicks()");
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    98
  SDLTest_AssertCheck(result2 > 0, "Check result value, expected: >0, got: %d", result2);
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    99
  difference = result2 - result;
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   100
  SDLTest_AssertCheck(difference > (testDelay - marginOfError), "Check difference, expected: >%d, got: %d", testDelay - marginOfError, difference);
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   101
  SDLTest_AssertCheck(difference < (testDelay + marginOfError), "Check difference, expected: <%d, got: %d", testDelay + marginOfError, difference);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
   102
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   103
  return TEST_COMPLETED;
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   104
}
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   105
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   106
/* Test callback */
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   107
Uint32 _timerTestCallback(Uint32 interval, void *param)
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   108
{
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   109
   _timerCallbackCalled = 1;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
   110
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   111
   if (_paramCheck != 0) {
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   112
       SDLTest_AssertCheck(param != NULL, "Check param pointer, expected: non-NULL, got: %s", (param != NULL) ? "non-NULL" : "NULL");
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   113
       if (param != NULL) {
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   114
          SDLTest_AssertCheck(*(int *)param == _paramValue, "Check param value, expected: %i, got: %i", _paramValue, *(int *)param);
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   115
       }
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   116
   }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
   117
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   118
   return 0;
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   119
}
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   120
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   121
/**
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   122
 * @brief Call to SDL_AddTimer and SDL_RemoveTimer
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   123
 */
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   124
int
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   125
timer_addRemoveTimer(void *arg)
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   126
{
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   127
  SDL_TimerID id;
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   128
  SDL_bool result;
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   129
  int param;
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   130
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   131
  /* Reset state */
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   132
  _paramCheck = 0;
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   133
  _timerCallbackCalled = 0;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
   134
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
   135
  /* Set timer with a long delay */
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   136
  id = SDL_AddTimer(10000, _timerTestCallback, NULL);
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   137
  SDLTest_AssertPass("Call to SDL_AddTimer(10000,...)");
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   138
  SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %d", id);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
   139
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   140
  /* Remove timer again and check that callback was not called */
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   141
  result = SDL_RemoveTimer(id);
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   142
  SDLTest_AssertPass("Call to SDL_RemoveTimer()");
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   143
  SDLTest_AssertCheck(result == SDL_TRUE, "Check result value, expected: %i, got: %i", SDL_TRUE, result);
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   144
  SDLTest_AssertCheck(_timerCallbackCalled == 0, "Check callback WAS NOT called, expected: 0, got: %i", _timerCallbackCalled);
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   145
7144
c700de9c8ed4 Corrected spelling in C source files of test suites.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 6815
diff changeset
   146
  /* Try to remove timer again (should be a NOOP) */
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   147
  result = SDL_RemoveTimer(id);
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   148
  SDLTest_AssertPass("Call to SDL_RemoveTimer()");
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   149
  SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected: %i, got: %i", SDL_FALSE, result);
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   150
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   151
  /* Reset state */
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   152
  param = SDLTest_RandomIntegerInRange(-1024, 1024);
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   153
  _paramCheck = 1;
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   154
  _paramValue = param;
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   155
  _timerCallbackCalled = 0;
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   156
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
   157
  /* Set timer with a short delay */
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   158
  id = SDL_AddTimer(10, _timerTestCallback, (void *)&param);
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   159
  SDLTest_AssertPass("Call to SDL_AddTimer(10, param)");
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   160
  SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %d", id);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
   161
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   162
  /* Wait to let timer trigger callback */
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   163
  SDL_Delay(100);
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   164
  SDLTest_AssertPass("Call to SDL_Delay(100)");
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
   165
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   166
  /* Remove timer again and check that callback was called */
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   167
  result = SDL_RemoveTimer(id);
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   168
  SDLTest_AssertPass("Call to SDL_RemoveTimer()");
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   169
  SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected: %i, got: %i", SDL_FALSE, result);
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   170
  SDLTest_AssertCheck(_timerCallbackCalled == 1, "Check callback WAS called, expected: 1, got: %i", _timerCallbackCalled);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
   171
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   172
  return TEST_COMPLETED;
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   173
}
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   174
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   175
/* ================= Test References ================== */
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   176
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   177
/* Timer test cases */
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   178
static const SDLTest_TestCaseReference timerTest1 =
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
   179
        { (SDLTest_TestCaseFp)timer_getPerformanceCounter, "timer_getPerformanceCounter", "Call to SDL_GetPerformanceCounter", TEST_ENABLED };
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   180
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   181
static const SDLTest_TestCaseReference timerTest2 =
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
   182
        { (SDLTest_TestCaseFp)timer_getPerformanceFrequency, "timer_getPerformanceFrequency", "Call to SDL_GetPerformanceFrequency", TEST_ENABLED };
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   183
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   184
static const SDLTest_TestCaseReference timerTest3 =
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
   185
        { (SDLTest_TestCaseFp)timer_delayAndGetTicks, "timer_delayAndGetTicks", "Call to SDL_Delay and SDL_GetTicks", TEST_ENABLED };
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   186
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   187
static const SDLTest_TestCaseReference timerTest4 =
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
   188
        { (SDLTest_TestCaseFp)timer_addRemoveTimer, "timer_addRemoveTimer", "Call to SDL_AddTimer and SDL_RemoveTimer", TEST_ENABLED };
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   189
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   190
/* Sequence of Timer test cases */
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   191
static const SDLTest_TestCaseReference *timerTests[] =  {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
   192
    &timerTest1, &timerTest2, &timerTest3, &timerTest4, NULL
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   193
};
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   194
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   195
/* Timer test suite (global) */
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   196
SDLTest_TestSuiteReference timerTestSuite = {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
   197
    "Timer",
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
   198
    _timerSetUp,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
   199
    timerTests,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7156
diff changeset
   200
    NULL
6815
5fefa916e039 Added timer test suite
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   201
};