SDL_test_assert.h File Reference
`#include "begin_code.h"`
`#include "close_code.h"`
Include dependency graph for SDL_test_assert.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Macros

#define | ASSERT_FAIL 0
| Fails the assert. More...
#define | ASSERT_PASS 1
| Passes the assert. More...

## Functions

void | SDLTest_Assert (int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(2)
| Assert that logs and break execution flow on failures. More...
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 counters. More...
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. More...
void | SDLTest_ResetAssertSummary ()
| Resets the assert summary counters to zero. More...
void | SDLTest_LogAssertSummary ()
| Logs summary of all assertions (total, pass, fail) since last reset as INFO or ERROR. More...
int | SDLTest_AssertSummaryToTestResult ()
| Converts the current assert summary state to a test result. More...

## Detailed Description

Include file for SDL test framework.

This code is a part of the SDL2_test library, not the main SDL library.

Definition in file SDL_test_assert.h.

## Macro Definition Documentation

#define ASSERT_FAIL 0

Fails the assert.

Definition at line 48 of file SDL_test_assert.h.

Referenced by SDLTest_AssertCheck().

#define ASSERT_PASS 1

Passes the assert.

Definition at line 53 of file SDL_test_assert.h.

## Function Documentation

void SDLTest_Assert | ( | int | assertCondition,
|  | SDL_PRINTF_FORMAT_STRING const char * | assertDescription,
|  |  | ...
| ) |  |

Assert that logs and break execution flow on failures.

Parameters

  assertCondition | Evaluated condition or variable to assert; fail (==0) or pass (!=0).
  assertDescription | Message to log with the assert describing it.

Definition at line 47 of file SDL_test_assert.c.

References SDL_assert, SDL_memset, SDL_vsnprintf, SDLTest_AssertCheck(), and SDLTEST_MAX_LOGMESSAGE_LENGTH.

Referenced by keyboard_getScancodeFromNameNegative().

{
va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
/* Print assert description into a buffer */
SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
va_start(list, assertDescription);
SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
va_end(list);
/* Log, then assert and break on failure */
SDL_assert((SDLTest_AssertCheck(assertCondition, "%s", logMessage)));
}
SDLTEST_MAX_LOGMESSAGE_LENGTH
#define SDLTEST_MAX_LOGMESSAGE_LENGTH
Definition: SDL_test.h:58
SDL_vsnprintf
#define SDL_vsnprintf
Definition: SDL_dynapi_overrides.h:427
SDL_assert
#define SDL_assert(condition)
Definition: SDL_assert.h:167
SDL_memset
#define SDL_memset
Definition: SDL_dynapi_overrides.h:392
SDLTest_AssertCheck
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...)
Assert for test cases that logs but does not break execution flow on failures. Updates assertion coun...
Definition: SDL_test_assert.c:65

int SDLTest_AssertCheck | ( | int | assertCondition,
|  | SDL_PRINTF_FORMAT_STRING const char * | assertDescription,
|  |  | ...
| ) |  |

Assert for test cases that logs but does not break execution flow on failures. Updates assertion counters.

Parameters

  assertCondition | Evaluated condition or variable to assert; fail (==0) or pass (!=0).
  assertDescription | Message to log with the assert describing it.

Returns
  Returns the assertCondition so it can be used to externally to break execution flow if desired.

Definition at line 65 of file SDL_test_assert.c.

References ASSERT_FAIL, SDL_memset, SDL_vsnprintf, SDLTest_AssertCheckFormat, SDLTest_AssertsFailed, SDLTest_AssertsPassed, SDLTest_Log(), SDLTest_LogError(), and SDLTEST_MAX_LOGMESSAGE_LENGTH.

Referenced by _AssertFileExist(), _audioSetUp(), _changeCursorVisibility(), _checkInvalidNameError(), _checkInvalidParameterError(), _checkInvalidScancodeError(), _checkInvalidWindowError(), _clearScreen(), _clearTestSurface(), _compare(), _createMouseSuiteTestWindow(), _createVideoSuiteTestWindow(), _events_sampleNullEventFilter(), _setAndCheckWindowGrabState(), _surfaceSetUp(), _testBlitBlendMode(), _testGenericRWopsValidations(), _testSetTextInputRect(), _timerSetUp(), _timerTestCallback(), _validateHasIntersectionResults(), _validateIntersectRectAndLineResults(), _validateIntersectRectResults(), _validateRectEmptyResults(), _validateRectEqualsResults(), _validateUnionRectResults(), audio_buildAudioCVT(), audio_buildAudioCVTNegative(), audio_convertAudio(), audio_enumerateAndNameAudioDevices(), audio_enumerateAndNameAudioDevicesNegativeTests(), audio_getAudioStatus(), audio_initOpenCloseQuitAudio(), audio_initQuitAudio(), audio_lockUnlockOpenAudioDevice(), audio_openCloseAndGetAudioStatus(), audio_openCloseAudioDeviceConnected(), audio_pauseUnpauseAudio(), audio_printAudioDrivers(), audio_printCurrentAudioDriver(), clipboard_testClipboardTextFunctions(), clipboard_testSetClipboardText(), events_addDelEventWatch(), events_addDelEventWatchWithUserdata(), events_pushPumpAndPollUserevent(), hints_getHint(), hints_setHint(), InitCreateRenderer(), keyboard_getKeyboardState(), keyboard_getKeyFromName(), keyboard_getKeyFromScancode(), keyboard_getKeyName(), keyboard_getKeyNameNegative(), keyboard_getScancodeFromKey(), keyboard_getScancodeFromName(), keyboard_getScancodeFromNameNegative(), keyboard_getScancodeNameNegative(), keyboard_getSetModState(), keyboard_setTextInputRectNegative(), main_testImpliedJoystickInit(), main_testImpliedJoystickQuit(), main_testInitQuitJoystickHaptic(), main_testInitQuitSubSystem(), mouse_createFreeColorCursor(), mouse_createFreeCursor(), mouse_getCursor(), mouse_getMouseFocus(), mouse_getMouseState(), mouse_getRelativeMouseState(), mouse_getSetRelativeMouseMode(), mouse_setCursor(), mouse_showCursor(), pixels_allocFreeFormat(), pixels_allocFreePalette(), pixels_calcGammaRamp(), pixels_getPixelFormatName(), platform_testDefaultInit(), platform_testEndianessAndSwap(), platform_testGetFunctions(), platform_testGetPowerInfo(), platform_testGetSetClearError(), platform_testGetVersion(), platform_testSDLVersion(), platform_testSetErrorEmptyInput(), platform_testSetErrorInvalidInput(), platform_testTypes(), rect_testEnclosePoints(), rect_testEnclosePointsParam(), rect_testEnclosePointsRepeatedInput(), rect_testEnclosePointsWithClipping(), rect_testHasIntersectionParam(), rect_testIntersectRectAndLineParam(), rect_testIntersectRectEmpty(), rect_testIntersectRectParam(), rect_testRectEmptyParam(), rect_testRectEqualsParam(), render_testBlit(), render_testBlitAlpha(), render_testBlitBlend(), render_testBlitColor(), render_testGetNumRenderDrivers(), render_testPrimitives(), render_testPrimitivesBlend(), rwops_testAllocFree(), rwops_testCompareRWFromMemWithRWFromFile(), rwops_testConstMem(), rwops_testFileRead(), rwops_testFileWrite(), rwops_testFileWriteReadEndian(), rwops_testFPRead(), rwops_testFPWrite(), rwops_testMem(), rwops_testParamNegative(), RWopsSetUp(), RWopsTearDown(), SDLTest_Assert(), sdltest_generateRunSeed(), sdltest_getFuzzerInvocationCount(), sdltest_randomAsciiString(), sdltest_randomAsciiStringOfSize(), sdltest_randomAsciiStringWithMaximumLength(), sdltest_randomBoundaryNumberSint16(), sdltest_randomBoundaryNumberSint32(), sdltest_randomBoundaryNumberSint64(), sdltest_randomBoundaryNumberSint8(), sdltest_randomBoundaryNumberUint16(), sdltest_randomBoundaryNumberUint32(), sdltest_randomBoundaryNumberUint64(), sdltest_randomBoundaryNumberUint8(), sdltest_randomIntegerInRange(), sdltest_randomNumber(), stdlib_getsetenv(), stdlib_snprintf(), stdlib_strlcpy(), surface_testBlit(), surface_testBlitAlphaMod(), surface_testBlitBlendAdd(), surface_testBlitBlendBlend(), surface_testBlitBlendLoop(), surface_testBlitBlendMod(), surface_testBlitBlendNone(), surface_testBlitColorMod(), surface_testCompleteSurfaceConversion(), surface_testLoadFailure(), surface_testSaveLoadBitmap(), surface_testSurfaceConversion(), syswm_getWindowWMInfo(), timer_addRemoveTimer(), timer_delayAndGetTicks(), timer_getPerformanceCounter(), timer_getPerformanceFrequency(), video_createWindowVariousFlags(), video_createWindowVariousPositions(), video_createWindowVariousSizes(), video_enableDisableScreensaver(), video_getClosestDisplayModeCurrentResolution(), video_getNumDisplayModes(), video_getNumDisplayModesNegative(), video_getSetWindowData(), video_getSetWindowGrab(), video_getSetWindowMaximumSize(), video_getSetWindowMinimumSize(), video_getSetWindowPosition(), video_getSetWindowSize(), video_getWindowBrightness(), video_getWindowBrightnessNegative(), video_getWindowDisplayMode(), video_getWindowDisplayModeNegative(), video_getWindowFlags(), video_getWindowGammaRamp(), video_getWindowGammaRampNegative(), video_getWindowId(), and video_getWindowPixelFormat().

{
va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
/* Print assert description into a buffer */
SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
va_start(list, assertDescription);
SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
va_end(list);
/* Log pass or fail message */
if (assertCondition == ASSERT_FAIL)
{
SDLTest_AssertsFailed++;
SDLTest_LogError(SDLTest_AssertCheckFormat, logMessage, "Failed");
}
else
{
SDLTest_AssertsPassed++;
SDLTest_Log(SDLTest_AssertCheckFormat, logMessage, "Passed");
}
return assertCondition;
}
SDLTEST_MAX_LOGMESSAGE_LENGTH
#define SDLTEST_MAX_LOGMESSAGE_LENGTH
Definition: SDL_test.h:58
SDLTest_AssertsPassed
static Uint32 SDLTest_AssertsPassed
Definition: SDL_test_assert.c:42
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_AssertsFailed
static Uint32 SDLTest_AssertsFailed
Definition: SDL_test_assert.c:39
SDL_vsnprintf
#define SDL_vsnprintf
Definition: SDL_dynapi_overrides.h:427
ASSERT_FAIL
#define ASSERT_FAIL
Fails the assert.
Definition: SDL_test_assert.h:48
SDLTest_AssertCheckFormat
const char * SDLTest_AssertCheckFormat
Definition: SDL_test_assert.c:33
SDLTest_Log
void SDLTest_Log(SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(1)
Prints given message with a timestamp in the TEST category and INFO priority.
Definition: SDL_test_log.c:71
SDL_memset
#define SDL_memset
Definition: SDL_dynapi_overrides.h:392

void SDLTest_AssertPass | ( | SDL_PRINTF_FORMAT_STRING const char * | assertDescription,
|  |  | ...
| ) |  |

Explicitly pass without checking an assertion condition. Updates assertion counter.

Parameters

  assertDescription | Message to log with the assert describing it.

Definition at line 94 of file SDL_test_assert.c.

References SDL_memset, SDL_vsnprintf, SDLTest_AssertCheckFormat, SDLTest_AssertsPassed, SDLTest_Log(), and SDLTEST_MAX_LOGMESSAGE_LENGTH.

Referenced by _audioSetUp(), _audioTearDown(), _changeCursorVisibility(), _checkInvalidNameError(), _checkInvalidParameterError(), _checkInvalidScancodeError(), _checkInvalidWindowError(), _clearTestSurface(), _createMouseSuiteTestWindow(), _createVideoSuiteTestWindow(), _destroyMouseSuiteTestWindow(), _destroyVideoSuiteTestWindow(), _setAndCheckWindowGrabState(), _testBlitBlendMode(), _testGenericRWopsValidations(), _testSetTextInputRect(), _timerSetUp(), audio_buildAudioCVT(), audio_buildAudioCVTNegative(), audio_convertAudio(), audio_enumerateAndNameAudioDevices(), audio_enumerateAndNameAudioDevicesNegativeTests(), audio_getAudioStatus(), audio_initOpenCloseQuitAudio(), audio_initQuitAudio(), audio_lockUnlockOpenAudioDevice(), audio_openCloseAndGetAudioStatus(), audio_openCloseAudioDeviceConnected(), audio_pauseUnpauseAudio(), audio_printAudioDrivers(), audio_printCurrentAudioDriver(), audio_quitInitAudioSubSystem(), CleanupDestroyRenderer(), clipboard_testClipboardTextFunctions(), clipboard_testGetClipboardText(), clipboard_testHasClipboardText(), clipboard_testSetClipboardText(), events_addDelEventWatch(), events_addDelEventWatchWithUserdata(), events_pushPumpAndPollUserevent(), hints_getHint(), hints_setHint(), InitCreateRenderer(), keyboard_getKeyboardFocus(), keyboard_getKeyboardState(), keyboard_getKeyFromName(), keyboard_getKeyFromScancode(), keyboard_getKeyName(), keyboard_getKeyNameNegative(), keyboard_getScancodeFromKey(), keyboard_getScancodeFromName(), keyboard_getScancodeFromNameNegative(), keyboard_getScancodeNameNegative(), keyboard_getSetModState(), keyboard_setTextInputRect(), keyboard_setTextInputRectNegative(), keyboard_startStopTextInput(), mouse_createFreeColorCursor(), mouse_createFreeCursor(), mouse_getCursor(), mouse_getMouseFocus(), mouse_getMouseState(), mouse_getRelativeMouseState(), mouse_getSetRelativeMouseMode(), mouse_setCursor(), mouse_showCursor(), mouse_warpMouseInWindow(), pixels_allocFreeFormat(), pixels_allocFreePalette(), pixels_calcGammaRamp(), pixels_getPixelFormatName(), platform_testGetFunctions(), platform_testGetPowerInfo(), platform_testGetSetClearError(), platform_testHasFunctions(), platform_testSetErrorEmptyInput(), platform_testSetErrorInvalidInput(), rect_testUnionRectParam(), rwops_testAllocFree(), rwops_testCompareRWFromMemWithRWFromFile(), rwops_testConstMem(), rwops_testFileRead(), rwops_testFileWrite(), rwops_testFileWriteReadEndian(), rwops_testFPRead(), rwops_testFPWrite(), rwops_testMem(), rwops_testParamNegative(), RWopsSetUp(), RWopsTearDown(), sdltest_generateRunSeed(), sdltest_getFuzzerInvocationCount(), sdltest_randomAsciiString(), sdltest_randomAsciiStringOfSize(), sdltest_randomAsciiStringWithMaximumLength(), sdltest_randomBoundaryNumberSint16(), sdltest_randomBoundaryNumberSint32(), sdltest_randomBoundaryNumberSint64(), sdltest_randomBoundaryNumberSint8(), sdltest_randomBoundaryNumberUint16(), sdltest_randomBoundaryNumberUint32(), sdltest_randomBoundaryNumberUint64(), sdltest_randomBoundaryNumberUint8(), sdltest_randomIntegerInRange(), sdltest_randomNumber(), stdlib_getsetenv(), stdlib_snprintf(), stdlib_strlcpy(), surface_testCompleteSurfaceConversion(), surface_testSaveLoadBitmap(), surface_testSurfaceConversion(), syswm_getWindowWMInfo(), timer_addRemoveTimer(), timer_delayAndGetTicks(), timer_getPerformanceCounter(), timer_getPerformanceFrequency(), video_createWindowVariousFlags(), video_createWindowVariousPositions(), video_createWindowVariousSizes(), video_enableDisableScreensaver(), video_getClosestDisplayModeCurrentResolution(), video_getClosestDisplayModeRandomResolution(), video_getNumDisplayModes(), video_getNumDisplayModesNegative(), video_getSetWindowData(), video_getSetWindowGrab(), video_getSetWindowMaximumSize(), video_getSetWindowMinimumSize(), video_getSetWindowPosition(), video_getSetWindowSize(), video_getWindowBrightness(), video_getWindowBrightnessNegative(), video_getWindowDisplayMode(), video_getWindowDisplayModeNegative(), video_getWindowFlags(), video_getWindowGammaRamp(), video_getWindowGammaRampNegative(), video_getWindowId(), and video_getWindowPixelFormat().

{
va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
/* Print assert description into a buffer */
SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
va_start(list, assertDescription);
SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
va_end(list);
/* Log pass message */
SDLTest_AssertsPassed++;
SDLTest_Log(SDLTest_AssertCheckFormat, logMessage, "Pass");
}
SDLTEST_MAX_LOGMESSAGE_LENGTH
#define SDLTEST_MAX_LOGMESSAGE_LENGTH
Definition: SDL_test.h:58
SDLTest_AssertsPassed
static Uint32 SDLTest_AssertsPassed
Definition: SDL_test_assert.c:42
SDL_vsnprintf
#define SDL_vsnprintf
Definition: SDL_dynapi_overrides.h:427
SDLTest_AssertCheckFormat
const char * SDLTest_AssertCheckFormat
Definition: SDL_test_assert.c:33
SDLTest_Log
void SDLTest_Log(SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(1)
Prints given message with a timestamp in the TEST category and INFO priority.
Definition: SDL_test_log.c:71
SDL_memset
#define SDL_memset
Definition: SDL_dynapi_overrides.h:392

int SDLTest_AssertSummaryToTestResult | ( |  | ) |

Converts the current assert summary state to a test result.

Returns
  TEST_RESULT_PASSED, TEST_RESULT_FAILED, or TEST_RESULT_NO_ASSERT

Definition at line 139 of file SDL_test_assert.c.

References SDLTest_AssertsFailed, SDLTest_AssertsPassed, TEST_RESULT_FAILED, TEST_RESULT_NO_ASSERT, and TEST_RESULT_PASSED.

Referenced by SDLTest_RunTest().

{
if (SDLTest_AssertsFailed > 0) {
return TEST_RESULT_FAILED;
} else {
if (SDLTest_AssertsPassed > 0) {
return TEST_RESULT_PASSED;
} else {
return TEST_RESULT_NO_ASSERT;
}
}
}
SDLTest_AssertsPassed
static Uint32 SDLTest_AssertsPassed
Definition: SDL_test_assert.c:42
TEST_RESULT_FAILED
#define TEST_RESULT_FAILED
Definition: SDL_test_harness.h:58
SDLTest_AssertsFailed
static Uint32 SDLTest_AssertsFailed
Definition: SDL_test_assert.c:39
TEST_RESULT_NO_ASSERT
#define TEST_RESULT_NO_ASSERT
Definition: SDL_test_harness.h:59
TEST_RESULT_PASSED
#define TEST_RESULT_PASSED
Definition: SDL_test_harness.h:57

void SDLTest_LogAssertSummary | ( |  | ) |

Logs summary of all assertions (total, pass, fail) since last reset as INFO or ERROR.

Definition at line 123 of file SDL_test_assert.c.

References SDLTest_AssertsFailed, SDLTest_AssertsPassed, SDLTest_AssertSummaryFormat, SDLTest_Log(), and SDLTest_LogError().

Referenced by SDLTest_RunTest().

{
Uint32 totalAsserts = SDLTest_AssertsPassed + SDLTest_AssertsFailed;
if (SDLTest_AssertsFailed == 0)
{
SDLTest_Log(SDLTest_AssertSummaryFormat, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
}
else
{
SDLTest_LogError(SDLTest_AssertSummaryFormat, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
}
}
Uint32
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:155
SDLTest_AssertsPassed
static Uint32 SDLTest_AssertsPassed
Definition: SDL_test_assert.c:42
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_AssertsFailed
static Uint32 SDLTest_AssertsFailed
Definition: SDL_test_assert.c:39
SDLTest_AssertSummaryFormat
const char * SDLTest_AssertSummaryFormat
Definition: SDL_test_assert.c:36
SDLTest_Log
void SDLTest_Log(SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(1)
Prints given message with a timestamp in the TEST category and INFO priority.
Definition: SDL_test_log.c:71

void SDLTest_ResetAssertSummary | ( |  | ) |

Resets the assert summary counters to zero.

Definition at line 113 of file SDL_test_assert.c.

References SDLTest_AssertsFailed, and SDLTest_AssertsPassed.

Referenced by SDLTest_RunTest().

{
SDLTest_AssertsPassed = 0;
SDLTest_AssertsFailed = 0;
}
SDLTest_AssertsPassed
static Uint32 SDLTest_AssertsPassed
Definition: SDL_test_assert.c:42
SDLTest_AssertsFailed
static Uint32 SDLTest_AssertsFailed
Definition: SDL_test_assert.c:39