SDL 2.0
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 (void)
 Resets the assert summary counters to zero. More...
 
void SDLTest_LogAssertSummary (void)
 Logs summary of all assertions (total, pass, fail) since last reset as INFO or ERROR. More...
 
int SDLTest_AssertSummaryToTestResult (void)
 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

◆ ASSERT_FAIL

#define ASSERT_FAIL   0

Fails the assert.

Definition at line 48 of file SDL_test_assert.h.

◆ ASSERT_PASS

#define ASSERT_PASS   1

Passes the assert.

Definition at line 53 of file SDL_test_assert.h.

Function Documentation

◆ SDLTest_Assert()

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

Assert that logs and break execution flow on failures.

Parameters
assertConditionEvaluated condition or variable to assert; fail (==0) or pass (!=0).
assertDescriptionMessage to log with the assert describing it.

Definition at line 47 of file SDL_test_assert.c.

48{
49 va_list list;
50 char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
51
52 /* Print assert description into a buffer */
54 va_start(list, assertDescription);
55 SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
56 va_end(list);
57
58 /* Log, then assert and break on failure */
59 SDL_assert((SDLTest_AssertCheck(assertCondition, "%s", logMessage)));
60}
#define SDL_assert(condition)
Definition: SDL_assert.h:169
#define SDL_memset
#define SDL_vsnprintf
#define SDLTEST_MAX_LOGMESSAGE_LENGTH
Definition: SDL_test.h:59
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...

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

Referenced by keyboard_getScancodeFromNameNegative().

◆ 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 counters.

Parameters
assertConditionEvaluated condition or variable to assert; fail (==0) or pass (!=0).
assertDescriptionMessage 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.

66{
67 va_list list;
68 char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
69
70 /* Print assert description into a buffer */
72 va_start(list, assertDescription);
73 SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
74 va_end(list);
75
76 /* Log pass or fail message */
77 if (assertCondition == ASSERT_FAIL)
78 {
80 SDLTest_LogError(SDLTEST_ASSERT_CHECK_FORMAT, logMessage, "Failed");
81 }
82 else
83 {
85 SDLTest_Log(SDLTEST_ASSERT_CHECK_FORMAT, logMessage, "Passed");
86 }
87
88 return assertCondition;
89}
#define SDLTEST_ASSERT_CHECK_FORMAT
static Uint32 SDLTest_AssertsPassed
static Uint32 SDLTest_AssertsFailed
#define ASSERT_FAIL
Fails the assert.
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
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:85

References ASSERT_FAIL, SDL_memset, SDL_vsnprintf, SDLTEST_ASSERT_CHECK_FORMAT, 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_sscanf(), 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().

◆ SDLTest_AssertPass()

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

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

Parameters
assertDescriptionMessage to log with the assert describing it.

Definition at line 94 of file SDL_test_assert.c.

95{
96 va_list list;
97 char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
98
99 /* Print assert description into a buffer */
101 va_start(list, assertDescription);
102 SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
103 va_end(list);
104
105 /* Log pass message */
107 SDLTest_Log(SDLTEST_ASSERT_CHECK_FORMAT, logMessage, "Pass");
108}

References SDL_memset, SDL_vsnprintf, SDLTEST_ASSERT_CHECK_FORMAT, 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_sscanf(), 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().

◆ SDLTest_AssertSummaryToTestResult()

int SDLTest_AssertSummaryToTestResult ( void  )

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.

140{
141 if (SDLTest_AssertsFailed > 0) {
142 return TEST_RESULT_FAILED;
143 } else {
144 if (SDLTest_AssertsPassed > 0) {
145 return TEST_RESULT_PASSED;
146 } else {
148 }
149 }
150}
#define TEST_RESULT_FAILED
#define TEST_RESULT_NO_ASSERT
#define TEST_RESULT_PASSED

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

Referenced by SDLTest_RunTest().

◆ SDLTest_LogAssertSummary()

void SDLTest_LogAssertSummary ( void  )

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.

124{
126 if (SDLTest_AssertsFailed == 0)
127 {
129 }
130 else
131 {
133 }
134}
uint32_t Uint32
Definition: SDL_stdinc.h:203
#define SDLTEST_ASSERT_SUMMARY_FORMAT

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

Referenced by SDLTest_RunTest().

◆ SDLTest_ResetAssertSummary()

void SDLTest_ResetAssertSummary ( void  )

Resets the assert summary counters to zero.

Definition at line 113 of file SDL_test_assert.c.

114{
117}

References SDLTest_AssertsFailed, and SDLTest_AssertsPassed.

Referenced by SDLTest_RunTest().