1
0

TestToolsTracker.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * TestToolsTracker.h
  3. * ------------------
  4. * Purpose: Unit test framework for OpenMPT.
  5. * Notes : Really basic functionality that relies on a debugger that catches
  6. * exceptions and breaks right at the spot where it gets thrown.
  7. * Authors: OpenMPT Devs
  8. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  9. */
  10. #pragma once
  11. #include "openmpt/all/BuildSettings.hpp"
  12. #ifdef ENABLE_TESTS
  13. #ifdef MODPLUG_TRACKER
  14. #include "mpt/test/test.hpp"
  15. OPENMPT_NAMESPACE_BEGIN
  16. namespace Test {
  17. #if MPT_COMPILER_MSVC
  18. // With MSVC, break directly using __debugbreak intrinsic instead of calling DebugBreak which breaks one stackframe deeper than we want
  19. #define MyDebugBreak() __debugbreak()
  20. #else
  21. #define MyDebugBreak() DebugBreak()
  22. #endif
  23. class mpt_test_reporter
  24. : public mpt::test::silent_reporter
  25. {
  26. public:
  27. mpt_test_reporter() = default;
  28. ~mpt_test_reporter() override = default;
  29. public:
  30. inline void immediate_breakpoint() override {
  31. MyDebugBreak();
  32. }
  33. };
  34. // Verify that given parameters are 'equal'. Break directly into the debugger if not.
  35. // The exact meaning of equality is based on operator== of the compared types.
  36. #define VERIFY_EQUAL(x,y) \
  37. do { \
  38. if(!((x) == (y))) { \
  39. MyDebugBreak(); \
  40. } \
  41. } while(0) \
  42. /**/
  43. // Like VERIFY_EQUAL, only differs for libopenmpt
  44. #define VERIFY_EQUAL_NONCONT VERIFY_EQUAL
  45. // Like VERIFY_EQUAL, only differs for libopenmpt
  46. #define VERIFY_EQUAL_QUIET_NONCONT VERIFY_EQUAL
  47. #define VERIFY_EQUAL_EPS(x,y,eps) \
  48. do { \
  49. if(std::abs((x) - (y)) > (eps)) { \
  50. MyDebugBreak(); \
  51. } \
  52. } while(0) \
  53. /**/
  54. #define DO_TEST(func) \
  55. do { \
  56. if(IsDebuggerPresent()) { \
  57. func(); \
  58. } \
  59. } while(0) \
  60. /**/
  61. } // namespace Test
  62. OPENMPT_NAMESPACE_END
  63. #endif // MODPLUG_TRACKER
  64. #endif // ENABLE_TESTS