mirror of
https://gitlab.com/shadow_contributor/ntptun.git
synced 2026-10-03 03:46:50 +00:00
43 lines
2.1 KiB
C++
43 lines
2.1 KiB
C++
// Tiny assertion helpers for the dependency-free unit tests.
|
|
#ifndef NTPTUN_TEST_UTIL_HPP
|
|
#define NTPTUN_TEST_UTIL_HPP
|
|
|
|
#include <cstdio>
|
|
|
|
namespace test {
|
|
inline int& failures() {
|
|
static int count = 0;
|
|
return count;
|
|
}
|
|
} // namespace test
|
|
|
|
#define CHECK(cond) \
|
|
do { \
|
|
if (!(cond)) { \
|
|
std::fprintf(stderr, "CHECK failed: %s (%s:%d)\n", #cond, \
|
|
__FILE__, __LINE__); \
|
|
++::test::failures(); \
|
|
} \
|
|
} while (0)
|
|
|
|
#define CHECK_EQ(a, b) \
|
|
do { \
|
|
if (!((a) == (b))) { \
|
|
std::fprintf(stderr, "CHECK_EQ failed: %s == %s (%s:%d)\n", #a, \
|
|
#b, __FILE__, __LINE__); \
|
|
++::test::failures(); \
|
|
} \
|
|
} while (0)
|
|
|
|
#define TEST_MAIN() \
|
|
int main() { \
|
|
run_tests(); \
|
|
if (::test::failures() != 0) { \
|
|
std::fprintf(stderr, "%d failure(s)\n", ::test::failures()); \
|
|
return 1; \
|
|
} \
|
|
std::printf("OK\n"); \
|
|
return 0; \
|
|
}
|
|
|
|
#endif // NTPTUN_TEST_UTIL_HPP
|