SDL_test_assert.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * Assertion functions of SDL test framework.
  20. *
  21. * This code is a part of the SDL test library, not the main SDL library.
  22. */
  23. /*
  24. *
  25. * Assert API for test code and test cases
  26. *
  27. */
  28. #ifndef SDL_test_assert_h_
  29. #define SDL_test_assert_h_
  30. #include <SDL3/SDL_stdinc.h>
  31. #include <SDL3/SDL_begin_code.h>
  32. /* Set up for C function definitions, even when using C++ */
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* Fails the assert. */
  37. #define ASSERT_FAIL 0
  38. /* Passes the assert. */
  39. #define ASSERT_PASS 1
  40. /*
  41. * Assert that logs and break execution flow on failures.
  42. *
  43. * \param assertCondition Evaluated condition or variable to assert; fail (==0) or pass (!=0).
  44. * \param assertDescription Message to log with the assert describing it.
  45. */
  46. void SDLCALL SDLTest_Assert(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) SDL_PRINTF_VARARG_FUNC(2);
  47. /*
  48. * Assert for test cases that logs but does not break execution flow on failures. Updates assertion counters.
  49. *
  50. * \param assertCondition Evaluated condition or variable to assert; fail (==0) or pass (!=0).
  51. * \param assertDescription Message to log with the assert describing it.
  52. *
  53. * \returns the assertCondition so it can be used to externally to break execution flow if desired.
  54. */
  55. int SDLCALL SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) SDL_PRINTF_VARARG_FUNC(2);
  56. /*
  57. * Explicitly pass without checking an assertion condition. Updates assertion counter.
  58. *
  59. * \param assertDescription Message to log with the assert describing it.
  60. */
  61. void SDLCALL SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) SDL_PRINTF_VARARG_FUNC(1);
  62. /*
  63. * Resets the assert summary counters to zero.
  64. */
  65. void SDLCALL SDLTest_ResetAssertSummary(void);
  66. /*
  67. * Logs summary of all assertions (total, pass, fail) since last reset as INFO or ERROR.
  68. */
  69. void SDLCALL SDLTest_LogAssertSummary(void);
  70. /*
  71. * Converts the current assert summary state to a test result.
  72. *
  73. * \returns TEST_RESULT_PASSED, TEST_RESULT_FAILED, or TEST_RESULT_NO_ASSERT
  74. */
  75. int SDLCALL SDLTest_AssertSummaryToTestResult(void);
  76. #ifdef __cplusplus
  77. }
  78. #endif
  79. #include <SDL3/SDL_close_code.h>
  80. #endif /* SDL_test_assert_h_ */