SDL  2.0
testautomation_timer.c File Reference
#include <stdio.h>
#include "SDL.h"
#include "SDL_test.h"
+ Include dependency graph for testautomation_timer.c:

Go to the source code of this file.

Functions

void _timerSetUp (void *arg)
 
int timer_getPerformanceCounter (void *arg)
 Call to SDL_GetPerformanceCounter. More...
 
int timer_getPerformanceFrequency (void *arg)
 Call to SDL_GetPerformanceFrequency. More...
 
int timer_delayAndGetTicks (void *arg)
 Call to SDL_Delay and SDL_GetTicks. More...
 
Uint32 _timerTestCallback (Uint32 interval, void *param)
 
int timer_addRemoveTimer (void *arg)
 Call to SDL_AddTimer and SDL_RemoveTimer. More...
 

Variables

int _paramCheck = 0
 
int _paramValue = 0
 
int _timerCallbackCalled = 0
 
static const SDLTest_TestCaseReference timerTest1
 
static const SDLTest_TestCaseReference timerTest2
 
static const SDLTest_TestCaseReference timerTest3
 
static const SDLTest_TestCaseReference timerTest4
 
static const SDLTest_TestCaseReferencetimerTests []
 
SDLTest_TestSuiteReference timerTestSuite
 

Function Documentation

◆ _timerSetUp()

void _timerSetUp ( void arg)

Definition at line 22 of file testautomation_timer.c.

References SDL_GetError, SDL_INIT_TIMER, SDL_InitSubSystem, SDLTest_AssertCheck(), SDLTest_AssertPass(), and SDLTest_LogError().

23 {
24  /* Start SDL timer subsystem */
25  int ret = SDL_InitSubSystem( SDL_INIT_TIMER );
26  SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_TIMER)");
27  SDLTest_AssertCheck(ret==0, "Check result from SDL_InitSubSystem(SDL_INIT_TIMER)");
28  if (ret != 0) {
30  }
31 }
#define SDL_GetError
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(1)
Explicitly pass without checking an assertion condition. Updates assertion counter.
#define SDL_InitSubSystem
void SDLTest_LogError(SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(1)
Prints given message with a timestamp in the TEST category and the ERROR priority.
Definition: SDL_test_log.c:103
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(2)
Assert for test cases that logs but does not break execution flow on failures. Updates assertion coun...
#define SDL_INIT_TIMER
Definition: SDL.h:76

◆ _timerTestCallback()

Uint32 _timerTestCallback ( Uint32  interval,
void param 
)

Definition at line 107 of file testautomation_timer.c.

References _paramCheck, _paramValue, _timerCallbackCalled, NULL, and SDLTest_AssertCheck().

Referenced by timer_addRemoveTimer().

108 {
110 
111  if (_paramCheck != 0) {
112  SDLTest_AssertCheck(param != NULL, "Check param pointer, expected: non-NULL, got: %s", (param != NULL) ? "non-NULL" : "NULL");
113  if (param != NULL) {
114  SDLTest_AssertCheck(*(int *)param == _paramValue, "Check param value, expected: %i, got: %i", _paramValue, *(int *)param);
115  }
116  }
117 
118  return 0;
119 }
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(2)
Assert for test cases that logs but does not break execution flow on failures. Updates assertion coun...
#define NULL
Definition: begin_code.h:164
int _timerCallbackCalled
int _paramValue
int _paramCheck
GLfloat param

◆ timer_addRemoveTimer()

int timer_addRemoveTimer ( void arg)

Call to SDL_AddTimer and SDL_RemoveTimer.

Definition at line 125 of file testautomation_timer.c.

References _paramCheck, _paramValue, _timerCallbackCalled, _timerTestCallback(), NULL, SDL_AddTimer, SDL_Delay, SDL_FALSE, SDL_RemoveTimer, SDL_TRUE, SDLTest_AssertCheck(), SDLTest_AssertPass(), SDLTest_RandomIntegerInRange(), and TEST_COMPLETED.

126 {
127  SDL_TimerID id;
129  int param;
130 
131  /* Reset state */
132  _paramCheck = 0;
134 
135  /* Set timer with a long delay */
136  id = SDL_AddTimer(10000, _timerTestCallback, NULL);
137  SDLTest_AssertPass("Call to SDL_AddTimer(10000,...)");
138  SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %d", id);
139 
140  /* Remove timer again and check that callback was not called */
141  result = SDL_RemoveTimer(id);
142  SDLTest_AssertPass("Call to SDL_RemoveTimer()");
143  SDLTest_AssertCheck(result == SDL_TRUE, "Check result value, expected: %i, got: %i", SDL_TRUE, result);
144  SDLTest_AssertCheck(_timerCallbackCalled == 0, "Check callback WAS NOT called, expected: 0, got: %i", _timerCallbackCalled);
145 
146  /* Try to remove timer again (should be a NOOP) */
147  result = SDL_RemoveTimer(id);
148  SDLTest_AssertPass("Call to SDL_RemoveTimer()");
149  SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected: %i, got: %i", SDL_FALSE, result);
150 
151  /* Reset state */
152  param = SDLTest_RandomIntegerInRange(-1024, 1024);
153  _paramCheck = 1;
154  _paramValue = param;
156 
157  /* Set timer with a short delay */
158  id = SDL_AddTimer(10, _timerTestCallback, (void *)&param);
159  SDLTest_AssertPass("Call to SDL_AddTimer(10, param)");
160  SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %d", id);
161 
162  /* Wait to let timer trigger callback */
163  SDL_Delay(100);
164  SDLTest_AssertPass("Call to SDL_Delay(100)");
165 
166  /* Remove timer again and check that callback was called */
167  result = SDL_RemoveTimer(id);
168  SDLTest_AssertPass("Call to SDL_RemoveTimer()");
169  SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected: %i, got: %i", SDL_FALSE, result);
170  SDLTest_AssertCheck(_timerCallbackCalled == 1, "Check callback WAS called, expected: 1, got: %i", _timerCallbackCalled);
171 
172  return TEST_COMPLETED;
173 }
GLuint id
GLuint64EXT * result
Sint32 SDLTest_RandomIntegerInRange(Sint32 min, Sint32 max)
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(1)
Explicitly pass without checking an assertion condition. Updates assertion counter.
Uint32 _timerTestCallback(Uint32 interval, void *param)
#define SDL_AddTimer
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(2)
Assert for test cases that logs but does not break execution flow on failures. Updates assertion coun...
#define TEST_COMPLETED
#define SDL_Delay
#define NULL
Definition: begin_code.h:164
SDL_bool
Definition: SDL_stdinc.h:139
int _timerCallbackCalled
int _paramValue
int _paramCheck
GLfloat param
#define SDL_RemoveTimer
int SDL_TimerID
Definition: SDL_timer.h:86

◆ timer_delayAndGetTicks()

int timer_delayAndGetTicks ( void arg)

Call to SDL_Delay and SDL_GetTicks.

Definition at line 69 of file testautomation_timer.c.

References SDL_Delay, SDL_GetTicks(), SDLTest_AssertCheck(), SDLTest_AssertPass(), SDLTest_RandomIntegerInRange(), and TEST_COMPLETED.

70 {
71  const Uint32 testDelay = 100;
72  const Uint32 marginOfError = 25;
73  Uint32 result;
74  Uint32 result2;
75  Uint32 difference;
76 
77  /* Zero delay */
78  SDL_Delay(0);
79  SDLTest_AssertPass("Call to SDL_Delay(0)");
80 
81  /* Non-zero delay */
82  SDL_Delay(1);
83  SDLTest_AssertPass("Call to SDL_Delay(1)");
84 
86  SDLTest_AssertPass("Call to SDL_Delay()");
87 
88  /* Get ticks count - should be non-zero by now */
89  result = SDL_GetTicks();
90  SDLTest_AssertPass("Call to SDL_GetTicks()");
91  SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %d", result);
92 
93  /* Delay a bit longer and measure ticks and verify difference */
94  SDL_Delay(testDelay);
95  SDLTest_AssertPass("Call to SDL_Delay(%d)", testDelay);
96  result2 = SDL_GetTicks();
97  SDLTest_AssertPass("Call to SDL_GetTicks()");
98  SDLTest_AssertCheck(result2 > 0, "Check result value, expected: >0, got: %d", result2);
99  difference = result2 - result;
100  SDLTest_AssertCheck(difference > (testDelay - marginOfError), "Check difference, expected: >%d, got: %d", testDelay - marginOfError, difference);
101  SDLTest_AssertCheck(difference < (testDelay + marginOfError), "Check difference, expected: <%d, got: %d", testDelay + marginOfError, difference);
102 
103  return TEST_COMPLETED;
104 }
GLuint64EXT * result
Sint32 SDLTest_RandomIntegerInRange(Sint32 min, Sint32 max)
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(1)
Explicitly pass without checking an assertion condition. Updates assertion counter.
uint32_t Uint32
Definition: SDL_stdinc.h:181
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(2)
Assert for test cases that logs but does not break execution flow on failures. Updates assertion coun...
#define TEST_COMPLETED
#define SDL_Delay

◆ timer_getPerformanceCounter()

int timer_getPerformanceCounter ( void arg)

Call to SDL_GetPerformanceCounter.

Definition at line 39 of file testautomation_timer.c.

References SDL_GetPerformanceCounter, SDL_PRIu64, SDLTest_AssertCheck(), SDLTest_AssertPass(), and TEST_COMPLETED.

40 {
41  Uint64 result;
42 
43  result = SDL_GetPerformanceCounter();
44  SDLTest_AssertPass("Call to SDL_GetPerformanceCounter()");
45  SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %"SDL_PRIu64, result);
46 
47  return TEST_COMPLETED;
48 }
GLuint64EXT * result
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(1)
Explicitly pass without checking an assertion condition. Updates assertion counter.
uint64_t Uint64
Definition: SDL_stdinc.h:194
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(2)
Assert for test cases that logs but does not break execution flow on failures. Updates assertion coun...
#define TEST_COMPLETED
#define SDL_GetPerformanceCounter
#define SDL_PRIu64
Definition: SDL_stdinc.h:216

◆ timer_getPerformanceFrequency()

int timer_getPerformanceFrequency ( void arg)

Call to SDL_GetPerformanceFrequency.

Definition at line 54 of file testautomation_timer.c.

References SDL_GetPerformanceFrequency(), SDL_PRIu64, SDLTest_AssertCheck(), SDLTest_AssertPass(), and TEST_COMPLETED.

55 {
56  Uint64 result;
57 
58  result = SDL_GetPerformanceFrequency();
59  SDLTest_AssertPass("Call to SDL_GetPerformanceFrequency()");
60  SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %"SDL_PRIu64, result);
61 
62  return TEST_COMPLETED;
63 }
GLuint64EXT * result
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(1)
Explicitly pass without checking an assertion condition. Updates assertion counter.
Uint64 SDL_GetPerformanceFrequency(void)
Get the count per second of the high resolution counter.
uint64_t Uint64
Definition: SDL_stdinc.h:194
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(2)
Assert for test cases that logs but does not break execution flow on failures. Updates assertion coun...
#define TEST_COMPLETED
#define SDL_PRIu64
Definition: SDL_stdinc.h:216

Variable Documentation

◆ _paramCheck

int _paramCheck = 0

Timer test suite

Definition at line 11 of file testautomation_timer.c.

Referenced by _timerTestCallback(), and timer_addRemoveTimer().

◆ _paramValue

int _paramValue = 0

Definition at line 14 of file testautomation_timer.c.

Referenced by _timerTestCallback(), and timer_addRemoveTimer().

◆ _timerCallbackCalled

int _timerCallbackCalled = 0

Definition at line 17 of file testautomation_timer.c.

Referenced by _timerTestCallback(), and timer_addRemoveTimer().

◆ timerTest1

const SDLTest_TestCaseReference timerTest1
static
Initial value:
=
{ (SDLTest_TestCaseFp)timer_getPerformanceCounter, "timer_getPerformanceCounter", "Call to SDL_GetPerformanceCounter", TEST_ENABLED }
int timer_getPerformanceCounter(void *arg)
Call to SDL_GetPerformanceCounter.
int(* SDLTest_TestCaseFp)(void *arg)
#define TEST_ENABLED

Definition at line 178 of file testautomation_timer.c.

◆ timerTest2

const SDLTest_TestCaseReference timerTest2
static
Initial value:
=
{ (SDLTest_TestCaseFp)timer_getPerformanceFrequency, "timer_getPerformanceFrequency", "Call to SDL_GetPerformanceFrequency", TEST_ENABLED }
int timer_getPerformanceFrequency(void *arg)
Call to SDL_GetPerformanceFrequency.
int(* SDLTest_TestCaseFp)(void *arg)
#define TEST_ENABLED

Definition at line 181 of file testautomation_timer.c.

◆ timerTest3

const SDLTest_TestCaseReference timerTest3
static
Initial value:
=
{ (SDLTest_TestCaseFp)timer_delayAndGetTicks, "timer_delayAndGetTicks", "Call to SDL_Delay and SDL_GetTicks", TEST_ENABLED }
int timer_delayAndGetTicks(void *arg)
Call to SDL_Delay and SDL_GetTicks.
int(* SDLTest_TestCaseFp)(void *arg)
#define TEST_ENABLED

Definition at line 184 of file testautomation_timer.c.

◆ timerTest4

const SDLTest_TestCaseReference timerTest4
static
Initial value:
=
{ (SDLTest_TestCaseFp)timer_addRemoveTimer, "timer_addRemoveTimer", "Call to SDL_AddTimer and SDL_RemoveTimer", TEST_ENABLED }
int timer_addRemoveTimer(void *arg)
Call to SDL_AddTimer and SDL_RemoveTimer.
int(* SDLTest_TestCaseFp)(void *arg)
#define TEST_ENABLED

Definition at line 187 of file testautomation_timer.c.

◆ timerTests

const SDLTest_TestCaseReference* timerTests[]
static
Initial value:
= {
}
static const SDLTest_TestCaseReference timerTest3
static const SDLTest_TestCaseReference timerTest1
static const SDLTest_TestCaseReference timerTest2
static const SDLTest_TestCaseReference timerTest4
#define NULL
Definition: begin_code.h:164

Definition at line 191 of file testautomation_timer.c.

◆ timerTestSuite

Initial value:
= {
"Timer",
}
static const SDLTest_TestCaseReference * timerTests[]
#define NULL
Definition: begin_code.h:164
void _timerSetUp(void *arg)

Definition at line 196 of file testautomation_timer.c.