From c029d90d1975e124d237605f1edb2be16bd05b5d Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Tue, 28 Feb 2017 21:50:44 +0100 Subject: Initial commit --- test/test.hh | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/test.hh (limited to 'test/test.hh') diff --git a/test/test.hh b/test/test.hh new file mode 100644 index 0000000..8d1f661 --- /dev/null +++ b/test/test.hh @@ -0,0 +1,49 @@ +// -*- mode: c++; c-basic-offset: 2; -*- + +#ifndef TEST_HH +#define TEST_HH + +#include +#include + +#define BEFORE \ + unsigned int tot = 0, ok = 0 + +#define AFTER \ + do { \ + std::cout << "PASS: " << ok << '\n' \ + << "FAIL: " << (tot - ok) << std::endl; \ + return ok == tot ? EXIT_SUCCESS : EXIT_FAILURE; \ + } while (false) + +#define RUN(test) \ + do { \ + ++tot; \ + if ((test)) ++ok; \ + } while (false) + +#define ASSERT_EQ(expected, actual) \ + do { \ + auto e_ = (expected); \ + auto a_ = (actual); \ + if (e_ != a_) { \ + std::cerr << __FILE__ << ':' << __LINE__ << ": " \ + << __FUNCTION__ << ": Expected " << e_ \ + << " got " << a_ << std::endl; \ + return false; \ + } \ + } while (false) + +#define ASSERT_STREQ(expected, actual) \ + do { \ + auto e_ = (expected); \ + auto a_ = (actual); \ + if (!(a_ == e_ || (a_ && e_ && strcmp(a_, e_) == 0))) { \ + std::cerr << __FILE__ << ':' << __LINE__ << ": " \ + << __FUNCTION__ << ": Expected " << (e_ ? e_ : "null") \ + << " got " << (a_ ? a_ : "null") << std::endl; \ + return false; \ + } \ + } while (false) + +#endif // TEST_HH -- cgit v1.2.3-70-g09d2