38 #define POTHOS_TEST_BLOCK(path, name) \
39 struct name : Pothos::TestingBase \
41 void runTestsImpl(void); \
42 void runTestsImpl_(void); \
44 pothos_static_block(name) \
46 std::shared_ptr<Pothos::TestingBase> testObj(new name()); \
47 Pothos::PluginRegistry::add(Pothos::Plugin( \
48 Pothos::PluginPath(path).join(#name), Pothos::Object(testObj))); \
50 void name::runTestsImpl(void) \
52 POTHOS_TEST_CHECKPOINT(); \
53 this->runTestsImpl_(); \
55 void name::runTestsImpl_(void)
58 #define POTHOS_TEST_CHECKPOINT() \
59 Pothos::TestingBase::current().report("checkpoint", "", "", __LINE__, __FILE__)
62 #define __POTHOS_TEST_STATEMENT(message, statement) \
64 Pothos::TestingBase::current().report(message, #statement, "", __LINE__, __FILE__); \
66 catch(const std::string &ex){Pothos::TestingBase::current().report(message, #statement, ex, __LINE__, __FILE__);} \
67 catch(const Pothos::Exception &ex){Pothos::TestingBase::current().report(message, #statement, ex.displayText(), __LINE__, __FILE__);} \
68 catch(const std::exception &ex){Pothos::TestingBase::current().report(message, #statement, ex.what(), __LINE__, __FILE__);} \
69 catch(...){Pothos::TestingBase::current().report(message, #statement, "unknown", __LINE__, __FILE__);} \
73 #define __POTHOS_TEST_ASSERT(message, statement) \
75 __POTHOS_TEST_STATEMENT(message, if (statement) {} else throw std::string("statement \"" #statement "\" evaluated false");); \
79 #define POTHOS_TEST_TRUE(statement) \
81 __POTHOS_TEST_ASSERT(#statement, statement) \
85 #define POTHOS_TEST_EQUAL(lhs, rhs) \
87 __POTHOS_TEST_ASSERT(Pothos::TestingBase::current().toString(lhs) + \
88 " == " + Pothos::TestingBase::current().toString(rhs), (lhs) == (rhs)); \
92 #define POTHOS_TEST_EQUALV(lhs, rhs) \
94 POTHOS_TEST_EQUAL((lhs).size(), (rhs).size()); \
95 for (size_t i = 0; i < (lhs).size(); i++) \
97 __POTHOS_TEST_ASSERT( \
98 "index " + Pothos::TestingBase::current().toString(i) + \
99 " asserts " + Pothos::TestingBase::current().toString((lhs)[i]) + \
100 " == " + Pothos::TestingBase::current().toString((rhs)[i]), (lhs)[i] == (rhs)[i]); \
105 #define POTHOS_TEST_EQUALA(lhs, rhs, size) \
107 for (size_t i = 0; i < (size); i++) \
109 __POTHOS_TEST_ASSERT( \
110 "index " + Pothos::TestingBase::current().toString(i) + \
111 " asserts " + Pothos::TestingBase::current().toString((lhs)[i]) + \
112 " == " + Pothos::TestingBase::current().toString((rhs)[i]), (lhs)[i] == (rhs)[i]); \
117 #define POTHOS_TEST_THROWS(statement, expectedException) \
119 Pothos::TestingBase::current().report(#statement, #statement, "", __LINE__, __FILE__); \
120 __POTHOS_TEST_STATEMENT(#statement " must throw " #expectedException, \
121 try{statement;throw std::string("statement \"" #statement "\" did not throw");} \
122 catch(const expectedException &){}); \
131 static TestingBase ¤t(
void);
133 virtual void runTestsImpl() = 0;
135 const std::string &message,
136 const std::string &statement,
137 const std::string &error,
139 const std::string &file);
140 template <
typename T>
#define POTHOS_API
Definition: Config.hpp:41
std::string toString(void) const
Definition: Object.hpp:55
Definition: Testing.hpp:127
std::string toString(const T &v)
Definition: Testing.hpp:141