summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <bbn@mjolner.dk>2020-11-20 08:39:04 +0100
committerBent Bisballe Nyeng <bbn@mjolner.dk>2020-11-20 08:39:04 +0100
commitfd83de802d05a227cc00489f66ea70fccb4dda05 (patch)
tree28e094257401403482ab263d2a7999f84af7573b
parentc5de72efd46a2f779fda176268b0ccef9e532341 (diff)
Make unit-test assertion function public static on the uUnit class, so they can be called from outside the scope of the test-classes.
-rw-r--r--uunit.h42
1 files changed, 21 insertions, 21 deletions
diff --git a/uunit.h b/uunit.h
index f11fa1c..4532ef8 100644
--- a/uunit.h
+++ b/uunit.h
@@ -168,18 +168,8 @@ public:
static std::function<void(const char*, const char*, bool)> status_cb;
-protected:
- template<typename O, typename F>
- void registerTest(O* obj, const F& fn, const char* name, const char* file)
- {
- tests.push_back({std::bind(fn, obj), name, file});
- }
- #define uUNIT_TEST(func) \
- registerTest(this, &func, #func, __FILE__)
- #define uTEST(...) uUNIT_TEST(__VA_ARGS__)
-
- void u_assert(bool value, const char* expr,
- const char* file, std::size_t line)
+ static void u_assert(bool value, const char* expr,
+ const char* file, std::size_t line)
{
if(!value)
{
@@ -191,11 +181,11 @@ protected:
}
//! Convenience macro to pass along filename and linenumber
#define uUNIT_ASSERT(value) \
- u_assert(value, #value, __FILE__, __LINE__)
+ uUnit::u_assert(value, #value, __FILE__, __LINE__)
#define uASSERT(...) uUNIT_ASSERT(__VA_ARGS__)
- void assert_equal(double expected, double value,
- const char* file, std::size_t line)
+ static void assert_equal(double expected, double value,
+ const char* file, std::size_t line)
{
if(std::fabs(expected - value) > 0.0000001)
{
@@ -208,8 +198,8 @@ protected:
}
template<typename T, typename U>
- void assert_equal(const T& expected, const U& value,
- const char* file, std::size_t line)
+ static void assert_equal(const T& expected, const U& value,
+ const char* file, std::size_t line)
{
if(expected != value)
{
@@ -222,12 +212,12 @@ protected:
}
//! Convenience macro to pass along filename and linenumber
#define uUNIT_ASSERT_EQUAL(expected, value) \
- assert_equal(expected, value, __FILE__, __LINE__)
+ uUnit::assert_equal(expected, value, __FILE__, __LINE__)
#define uASSERT_EQUAL(...) uUNIT_ASSERT_EQUAL(__VA_ARGS__)
template<typename T>
- void assert_throws(const char* expected, std::function<void()> expr,
- const char* file, std::size_t line)
+ static void assert_throws(const char* expected, std::function<void()> expr,
+ const char* file, std::size_t line)
{
try
{
@@ -252,9 +242,19 @@ protected:
}
}
#define uUNIT_ASSERT_THROWS(expected, expr) \
- assert_throws<expected>(#expected, [&](){ expr; }, __FILE__, __LINE__)
+ uUnit::assert_throws<expected>(#expected, [&](){expr;}, __FILE__, __LINE__)
#define uASSERT_THROWS(...) uUNIT_ASSERT_THROWS(__VA_ARGS__)
+protected:
+ template<typename O, typename F>
+ void registerTest(O* obj, const F& fn, const char* name, const char* file)
+ {
+ tests.push_back({std::bind(fn, obj), name, file});
+ }
+ #define uUNIT_TEST(func) \
+ registerTest(this, &func, #func, __FILE__)
+ #define uTEST(...) uUNIT_TEST(__VA_ARGS__)
+
private:
static std::string sanitize(const std::string& input)
{