diff options
Diffstat (limited to 'test/test.hh')
| -rw-r--r-- | test/test.hh | 49 |
1 files changed, 49 insertions, 0 deletions
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 <cstring> +#include <iostream> + +#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 |
