diff options
author | sanine <sanine.not@pm.me> | 2022-10-01 20:59:36 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-10-01 20:59:36 -0500 |
commit | c5fc66ee58f2c60f2d226868bb1cf5b91badaf53 (patch) | |
tree | 277dd280daf10bf77013236b8edfa5f88708c7e0 /libs/ode-0.16.1/tests/UnitTest++/src/TestMacros.h | |
parent | 1cf9cc3408af7008451f9133fb95af66a9697d15 (diff) |
add ode
Diffstat (limited to 'libs/ode-0.16.1/tests/UnitTest++/src/TestMacros.h')
-rw-r--r-- | libs/ode-0.16.1/tests/UnitTest++/src/TestMacros.h | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/libs/ode-0.16.1/tests/UnitTest++/src/TestMacros.h b/libs/ode-0.16.1/tests/UnitTest++/src/TestMacros.h new file mode 100644 index 0000000..09ecc6b --- /dev/null +++ b/libs/ode-0.16.1/tests/UnitTest++/src/TestMacros.h @@ -0,0 +1,99 @@ +#ifndef UNITTEST_TESTMACROS_H +#define UNITTEST_TESTMACROS_H + +#include "Config.h" + +#ifndef UNITTEST_POSIX + #define UNITTEST_THROW_SIGNALS +#else + #include "Posix/SignalTranslator.h" +#endif + +#ifdef TEST + #error UnitTest++ redefines TEST +#endif + +#define SUITE(Name) \ + namespace Name { \ + namespace UnitTestSuite { \ + inline char const* GetSuiteName () { \ + return #Name ; \ + } \ + } \ + } \ + namespace Name + +#define TEST_EX(Name, List) \ + class Test##Name : public UnitTest::Test \ + { \ + public: \ + Test##Name() : Test(#Name, UnitTestSuite::GetSuiteName(), __FILE__, __LINE__) {} \ + private: \ + virtual void RunImpl(UnitTest::TestResults& testResults_) const; \ + } test##Name##Instance; \ + \ + UnitTest::ListAdder adder##Name (List, &test##Name##Instance); \ + \ + void Test##Name::RunImpl(UnitTest::TestResults& testResults_) const + + +#define TEST(Name) TEST_EX(Name, UnitTest::Test::GetTestList()) + + +#define TEST_FIXTURE_EX(Fixture, Name, List) \ + class Fixture##Name##Helper : public Fixture \ + { \ + public: \ + Fixture##Name##Helper(UnitTest::TestDetails const& details) : m_details(details) {} \ + void RunTest(UnitTest::TestResults& testResults_); \ + UnitTest::TestDetails const& m_details; \ + private: \ + Fixture##Name##Helper(Fixture##Name##Helper const&); \ + Fixture##Name##Helper& operator =(Fixture##Name##Helper const&); \ + }; \ + \ + class Test##Fixture##Name : public UnitTest::Test \ + { \ + public: \ + Test##Fixture##Name() : Test(#Name, UnitTestSuite::GetSuiteName(), __FILE__, __LINE__) {} \ + private: \ + virtual void RunImpl(UnitTest::TestResults& testResults_) const; \ + } test##Fixture##Name##Instance; \ + \ + UnitTest::ListAdder adder##Fixture##Name (List, &test##Fixture##Name##Instance); \ + \ + void Test##Fixture##Name::RunImpl(UnitTest::TestResults& testResults_) const \ + { \ + bool ctorOk = false; \ + try { \ + Fixture##Name##Helper fixtureHelper(m_details); \ + ctorOk = true; \ + try { \ + UNITTEST_THROW_SIGNALS; \ + fixtureHelper.RunTest(testResults_); \ + } catch (UnitTest::AssertException const& e) { \ + testResults_.OnTestFailure(UnitTest::TestDetails(m_details.testName, m_details.suiteName, e.Filename(), e.LineNumber()), e.what()); \ + } catch (std::exception const& e) { \ + UnitTest::MemoryOutStream stream; \ + stream << "Unhandled exception: " << e.what(); \ + testResults_.OnTestFailure(m_details, stream.GetText()); \ + } catch (...) { testResults_.OnTestFailure(m_details, "Unhandled exception: Crash!"); } \ + } \ + catch (...) { \ + if (ctorOk) \ + { \ + testResults_.OnTestFailure(UnitTest::TestDetails(m_details, __LINE__), \ + "Unhandled exception while destroying fixture " #Fixture); \ + } \ + else \ + { \ + testResults_.OnTestFailure(UnitTest::TestDetails(m_details, __LINE__), \ + "Unhandled exception while constructing fixture " #Fixture); \ + } \ + } \ + } \ + void Fixture##Name##Helper::RunTest(UnitTest::TestResults& testResults_) + +#define TEST_FIXTURE(Fixture,Name) TEST_FIXTURE_EX(Fixture, Name, UnitTest::Test::GetTestList()) + +#endif |