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_TestCaseReference * | timerTests []
SDLTest_TestSuiteReference | timerTestSuite

## Function Documentation

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().

{
/* Start SDL timer subsystem */
int ret = SDL_InitSubSystem( SDL_INIT_TIMER );
SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_TIMER)");
SDLTest_AssertCheck(ret==0, "Check result from SDL_InitSubSystem(SDL_INIT_TIMER)");
if (ret != 0) {
SDLTest_LogError("%s", SDL_GetError());
}
}
SDL_GetError
#define SDL_GetError
Definition: SDL_dynapi_overrides.h:119
SDLTest_AssertPass
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.
Definition: SDL_test_assert.c:94
SDL_InitSubSystem
#define SDL_InitSubSystem
Definition: SDL_dynapi_overrides.h:61
SDLTest_LogError
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:89
SDLTest_AssertCheck
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...
Definition: SDL_test_assert.c:65
SDL_INIT_TIMER
#define SDL_INIT_TIMER
Definition: SDL.h:75

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().

{
_timerCallbackCalled = 1;
if (_paramCheck != 0) {
SDLTest_AssertCheck(param != NULL, "Check param pointer, expected: non-NULL, got: %s", (param != NULL) ? "non-NULL" : "NULL");
if (param != NULL) {
SDLTest_AssertCheck(*(int *)param == _paramValue, "Check param value, expected: %i, got: %i", _paramValue, *(int *)param);
}
}
return 0;
}
param
GLfloat param
Definition: SDL_opengl_glext.h:370
SDLTest_AssertCheck
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...
Definition: SDL_test_assert.c:65
NULL
#define NULL
Definition: begin_code.h:143
_timerCallbackCalled
int _timerCallbackCalled
Definition: testautomation_timer.c:17
_paramValue
int _paramValue
Definition: testautomation_timer.c:14
_paramCheck
int _paramCheck
Definition: testautomation_timer.c:11

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.

{
SDL_TimerID id;
SDL_bool result;
int param;
/* Reset state */
_paramCheck = 0;
_timerCallbackCalled = 0;
/* Set timer with a long delay */
id = SDL_AddTimer(10000, _timerTestCallback, NULL);
SDLTest_AssertPass("Call to SDL_AddTimer(10000,...)");
SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %d", id);
/* Remove timer again and check that callback was not called */
result = SDL_RemoveTimer(id);
SDLTest_AssertPass("Call to SDL_RemoveTimer()");
SDLTest_AssertCheck(result == SDL_TRUE, "Check result value, expected: %i, got: %i", SDL_TRUE, result);
SDLTest_AssertCheck(_timerCallbackCalled == 0, "Check callback WAS NOT called, expected: 0, got: %i", _timerCallbackCalled);
/* Try to remove timer again (should be a NOOP) */
result = SDL_RemoveTimer(id);
SDLTest_AssertPass("Call to SDL_RemoveTimer()");
SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected: %i, got: %i", SDL_FALSE, result);
/* Reset state */
param = SDLTest_RandomIntegerInRange(-1024, 1024);
_paramCheck = 1;
_paramValue = param;
_timerCallbackCalled = 0;
/* Set timer with a short delay */
id = SDL_AddTimer(10, _timerTestCallback, (void *)&param);
SDLTest_AssertPass("Call to SDL_AddTimer(10, param)");
SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %d", id);
/* Wait to let timer trigger callback */
SDL_Delay(100);
SDLTest_AssertPass("Call to SDL_Delay(100)");
/* Remove timer again and check that callback was called */
result = SDL_RemoveTimer(id);
SDLTest_AssertPass("Call to SDL_RemoveTimer()");
SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected: %i, got: %i", SDL_FALSE, result);
SDLTest_AssertCheck(_timerCallbackCalled == 1, "Check callback WAS called, expected: 1, got: %i", _timerCallbackCalled);
return TEST_COMPLETED;
}
id
GLuint id
Definition: SDL_opengl_glext.h:528
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
SDLTest_RandomIntegerInRange
Sint32 SDLTest_RandomIntegerInRange(Sint32 min, Sint32 max)
Definition: SDL_test_fuzzer.c:156
SDLTest_AssertPass
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.
Definition: SDL_test_assert.c:94
_timerTestCallback
Uint32 _timerTestCallback(Uint32 interval, void *param)
Definition: testautomation_timer.c:107
param
GLfloat param
Definition: SDL_opengl_glext.h:370
SDL_AddTimer
#define SDL_AddTimer
Definition: SDL_dynapi_overrides.h:491
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:126
SDLTest_AssertCheck
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...
Definition: SDL_test_assert.c:65
SDL_TRUE
Definition: SDL_stdinc.h:129
TEST_COMPLETED
#define TEST_COMPLETED
Definition: SDL_test_harness.h:53
SDL_Delay
#define SDL_Delay
Definition: SDL_dynapi_overrides.h:490
NULL
#define NULL
Definition: begin_code.h:143
_timerCallbackCalled
int _timerCallbackCalled
Definition: testautomation_timer.c:17
_paramValue
int _paramValue
Definition: testautomation_timer.c:14
SDL_FALSE
Definition: SDL_stdinc.h:128
_paramCheck
int _paramCheck
Definition: testautomation_timer.c:11
SDL_RemoveTimer
#define SDL_RemoveTimer
Definition: SDL_dynapi_overrides.h:492
SDL_TimerID
int SDL_TimerID
Definition: SDL_timer.h:86

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.

{
const Uint32 testDelay = 100;
const Uint32 marginOfError = 25;
Uint32 result;
Uint32 result2;
Uint32 difference;
/* Zero delay */
SDL_Delay(0);
SDLTest_AssertPass("Call to SDL_Delay(0)");
/* Non-zero delay */
SDL_Delay(1);
SDLTest_AssertPass("Call to SDL_Delay(1)");
SDL_Delay(SDLTest_RandomIntegerInRange(5, 15));
SDLTest_AssertPass("Call to SDL_Delay()");
/* Get ticks count - should be non-zero by now */
result = SDL_GetTicks();
SDLTest_AssertPass("Call to SDL_GetTicks()");
SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %d", result);
/* Delay a bit longer and measure ticks and verify difference */
SDL_Delay(testDelay);
SDLTest_AssertPass("Call to SDL_Delay(%d)", testDelay);
result2 = SDL_GetTicks();
SDLTest_AssertPass("Call to SDL_GetTicks()");
SDLTest_AssertCheck(result2 > 0, "Check result value, expected: >0, got: %d", result2);
difference = result2 - result;
SDLTest_AssertCheck(difference > (testDelay - marginOfError), "Check difference, expected: >%d, got: %d", testDelay - marginOfError, difference);
SDLTest_AssertCheck(difference < (testDelay + marginOfError), "Check difference, expected: <%d, got: %d", testDelay + marginOfError, difference);
return TEST_COMPLETED;
}
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
Uint32
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:157
SDLTest_RandomIntegerInRange
Sint32 SDLTest_RandomIntegerInRange(Sint32 min, Sint32 max)
Definition: SDL_test_fuzzer.c:156
SDLTest_AssertPass
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.
Definition: SDL_test_assert.c:94
SDL_GetTicks
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
SDLTest_AssertCheck
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...
Definition: SDL_test_assert.c:65
TEST_COMPLETED
#define TEST_COMPLETED
Definition: SDL_test_harness.h:53
SDL_Delay
#define SDL_Delay
Definition: SDL_dynapi_overrides.h:490

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.

{
Uint64 result;
result = SDL_GetPerformanceCounter();
SDLTest_AssertPass("Call to SDL_GetPerformanceCounter()");
SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %"SDL_PRIu64, result);
return TEST_COMPLETED;
}
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
SDLTest_AssertPass
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.
Definition: SDL_test_assert.c:94
Uint64
uint64_t Uint64
An unsigned 64-bit integer type.
Definition: SDL_stdinc.h:166
SDLTest_AssertCheck
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...
Definition: SDL_test_assert.c:65
TEST_COMPLETED
#define TEST_COMPLETED
Definition: SDL_test_harness.h:53
SDL_GetPerformanceCounter
#define SDL_GetPerformanceCounter
Definition: SDL_dynapi_overrides.h:488
SDL_PRIu64
#define SDL_PRIu64
Definition: SDL_stdinc.h:188

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.

{
Uint64 result;
result = SDL_GetPerformanceFrequency();
SDLTest_AssertPass("Call to SDL_GetPerformanceFrequency()");
SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %"SDL_PRIu64, result);
return TEST_COMPLETED;
}
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
SDLTest_AssertPass
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.
Definition: SDL_test_assert.c:94
SDL_GetPerformanceFrequency
Uint64 SDL_GetPerformanceFrequency(void)
Get the count per second of the high resolution counter.
Uint64
uint64_t Uint64
An unsigned 64-bit integer type.
Definition: SDL_stdinc.h:166
SDLTest_AssertCheck
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...
Definition: SDL_test_assert.c:65
TEST_COMPLETED
#define TEST_COMPLETED
Definition: SDL_test_harness.h:53
SDL_PRIu64
#define SDL_PRIu64
Definition: SDL_stdinc.h:188

## Variable Documentation

int _paramCheck = 0

Timer test suite

Definition at line 11 of file testautomation_timer.c.

Referenced by _timerTestCallback(), and timer_addRemoveTimer().

int _paramValue = 0

Definition at line 14 of file testautomation_timer.c.

Referenced by _timerTestCallback(), and timer_addRemoveTimer().

int _timerCallbackCalled = 0

Definition at line 17 of file testautomation_timer.c.

Referenced by _timerTestCallback(), and timer_addRemoveTimer().

const SDLTest_TestCaseReference timerTest1

static

Initial value:
=
{ (SDLTest_TestCaseFp)timer_getPerformanceCounter, "timer_getPerformanceCounter", "Call to SDL_GetPerformanceCounter", TEST_ENABLED }
timer_getPerformanceCounter
int timer_getPerformanceCounter(void *arg)
Call to SDL_GetPerformanceCounter.
Definition: testautomation_timer.c:39
SDLTest_TestCaseFp
int(* SDLTest_TestCaseFp)(void *arg)
Definition: SDL_test_harness.h:67
TEST_ENABLED
#define TEST_ENABLED
Definition: SDL_test_harness.h:47

Definition at line 178 of file testautomation_timer.c.

const SDLTest_TestCaseReference timerTest2

static

Initial value:
=
{ (SDLTest_TestCaseFp)timer_getPerformanceFrequency, "timer_getPerformanceFrequency", "Call to SDL_GetPerformanceFrequency", TEST_ENABLED }
timer_getPerformanceFrequency
int timer_getPerformanceFrequency(void *arg)
Call to SDL_GetPerformanceFrequency.
Definition: testautomation_timer.c:54
SDLTest_TestCaseFp
int(* SDLTest_TestCaseFp)(void *arg)
Definition: SDL_test_harness.h:67
TEST_ENABLED
#define TEST_ENABLED
Definition: SDL_test_harness.h:47

Definition at line 181 of file testautomation_timer.c.

const SDLTest_TestCaseReference timerTest3

static

Initial value:
=
{ (SDLTest_TestCaseFp)timer_delayAndGetTicks, "timer_delayAndGetTicks", "Call to SDL_Delay and SDL_GetTicks", TEST_ENABLED }
timer_delayAndGetTicks
int timer_delayAndGetTicks(void *arg)
Call to SDL_Delay and SDL_GetTicks.
Definition: testautomation_timer.c:69
SDLTest_TestCaseFp
int(* SDLTest_TestCaseFp)(void *arg)
Definition: SDL_test_harness.h:67
TEST_ENABLED
#define TEST_ENABLED
Definition: SDL_test_harness.h:47

Definition at line 184 of file testautomation_timer.c.

const SDLTest_TestCaseReference timerTest4

static

Initial value:
=
{ (SDLTest_TestCaseFp)timer_addRemoveTimer, "timer_addRemoveTimer", "Call to SDL_AddTimer and SDL_RemoveTimer", TEST_ENABLED }
timer_addRemoveTimer
int timer_addRemoveTimer(void *arg)
Call to SDL_AddTimer and SDL_RemoveTimer.
Definition: testautomation_timer.c:125
SDLTest_TestCaseFp
int(* SDLTest_TestCaseFp)(void *arg)
Definition: SDL_test_harness.h:67
TEST_ENABLED
#define TEST_ENABLED
Definition: SDL_test_harness.h:47

Definition at line 187 of file testautomation_timer.c.

const SDLTest_TestCaseReference* timerTests[]

static

Initial value:
= {
&timerTest1, &timerTest2, &timerTest3, &timerTest4, NULL
}
timerTest3
static const SDLTest_TestCaseReference timerTest3
Definition: testautomation_timer.c:184
timerTest1
static const SDLTest_TestCaseReference timerTest1
Definition: testautomation_timer.c:178
timerTest2
static const SDLTest_TestCaseReference timerTest2
Definition: testautomation_timer.c:181
timerTest4
static const SDLTest_TestCaseReference timerTest4
Definition: testautomation_timer.c:187
NULL
#define NULL
Definition: begin_code.h:143

Definition at line 191 of file testautomation_timer.c.

SDLTest_TestSuiteReference timerTestSuite

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

Definition at line 196 of file testautomation_timer.c.