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