Compare commits

..

No commits in common. "c18765e44a110f2fe4616726305bafadbce4f5e9" and "c016fcdbd987e962b3514aece75a3ef9db01073f" have entirely different histories.

2 changed files with 29 additions and 30 deletions

View file

@ -1,7 +1,7 @@
#include "test_helpers.h" #include "test_helpers.h"
std::atomic_int64_t checks_checked = std::atomic_int64_t(0); int checks_checked = 0;
std::atomic_int64_t checks_passed = std::atomic_int64_t(0); int checks_passed = 0;
int main() { int main() {
TEST_EC_Bitset(); TEST_EC_Bitset();
@ -37,8 +37,8 @@ int main() {
TEST_ECThreadPool_QueryCount(); TEST_ECThreadPool_QueryCount();
TEST_ECThreadPool_easyStartAndWait(); TEST_ECThreadPool_easyStartAndWait();
std::cout << "checks_checked: " << checks_checked.load() << '\n' std::cout << "checks_checked: " << checks_checked << '\n'
<< "checks_passed: " << checks_passed.load() << std::endl; << "checks_passed: " << checks_passed << std::endl;
return checks_checked.load() == checks_passed.load() ? 0 : 1; return checks_checked == checks_passed ? 0 : 1;
} }

View file

@ -3,61 +3,60 @@
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include <atomic>
extern std::atomic_int64_t checks_checked; extern int checks_checked;
extern std::atomic_int64_t checks_passed; extern int checks_passed;
// Macros for unit testing. // Macros for unit testing.
#define CHECK_TRUE(x) \ #define CHECK_TRUE(x) \
do { \ do { \
checks_checked.fetch_add(1); \ ++checks_checked; \
if (!(x)) { \ if (!(x)) { \
std::cout << "CHECK_TRUE at line " << __LINE__ << " failed: " << #x \ std::cout << "CHECK_TRUE at line " << __LINE__ << " failed: " << #x \
<< '\n'; \ << '\n'; \
} else { \ } else { \
checks_passed.fetch_add(1); \ ++checks_passed; \
} \ } \
} while (false); } while (false);
#define ASSERT_TRUE(x) \ #define ASSERT_TRUE(x) \
do { \ do { \
checks_checked.fetch_add(1); \ ++checks_checked; \
if (!(x)) { \ if (!(x)) { \
std::cout << "CHECK_TRUE at line " << __LINE__ << " failed: " << #x \ std::cout << "CHECK_TRUE at line " << __LINE__ << " failed: " << #x \
<< '\n'; \ << '\n'; \
return; \ return; \
} else { \ } else { \
checks_passed.fetch_add(1); \ ++checks_passed; \
} \ } \
} while (false); } while (false);
#define CHECK_FALSE(x) \ #define CHECK_FALSE(x) \
do { \ do { \
checks_checked.fetch_add(1); \ ++checks_checked; \
if (x) { \ if (x) { \
std::cout << "CHECK_FALSE at line " << __LINE__ << " failed: " << #x \ std::cout << "CHECK_FALSE at line " << __LINE__ << " failed: " << #x \
<< '\n'; \ << '\n'; \
} else { \ } else { \
checks_passed.fetch_add(1); \ ++checks_passed; \
} \ } \
} while (false); } while (false);
#define ASSERT_FALSE(x) \ #define ASSERT_FALSE(x) \
do { \ do { \
checks_checked.fetch_add(1); \ ++checks_checked; \
if (x) { \ if (x) { \
std::cout << "CHECK_FALSE at line " << __LINE__ << " failed: " << #x \ std::cout << "CHECK_FALSE at line " << __LINE__ << " failed: " << #x \
<< '\n'; \ << '\n'; \
return; \ return; \
} else { \ } else { \
checks_passed.fetch_add(1); \ ++checks_passed; \
} \ } \
} while (false); } while (false);
#define CHECK_FLOAT(var, value) \ #define CHECK_FLOAT(var, value) \
do { \ do { \
checks_checked.fetch_add(1); \ ++checks_checked; \
if ((var) > (value) - 0.0001F && (var) < (value) + 0.0001F) { \ if ((var) > (value) - 0.0001F && (var) < (value) + 0.0001F) { \
checks_passed.fetch_add(1); \ ++checks_passed; \
} else { \ } else { \
std::cout << "CHECK_FLOAT at line " << __LINE__ << " failed: " << #var \ std::cout << "CHECK_FLOAT at line " << __LINE__ << " failed: " << #var \
<< " != " << #value << '\n'; \ << " != " << #value << '\n'; \
@ -66,9 +65,9 @@ extern std::atomic_int64_t checks_passed;
#define CHECK_EQ(var, value) \ #define CHECK_EQ(var, value) \
do { \ do { \
checks_checked.fetch_add(1); \ ++checks_checked; \
if ((var) == (value)) { \ if ((var) == (value)) { \
checks_passed.fetch_add(1); \ ++checks_passed; \
} else { \ } else { \
std::cout << "CHECK_EQ at line " << __LINE__ << " failed: " << #var \ std::cout << "CHECK_EQ at line " << __LINE__ << " failed: " << #var \
<< " != " << #value << '\n'; \ << " != " << #value << '\n'; \
@ -76,9 +75,9 @@ extern std::atomic_int64_t checks_passed;
} while (false); } while (false);
#define ASSERT_EQ(var, value) \ #define ASSERT_EQ(var, value) \
do { \ do { \
checks_checked.fetch_add(1); \ ++checks_checked; \
if ((var) == (value)) { \ if ((var) == (value)) { \
checks_passed.fetch_add(1); \ ++checks_passed; \
} else { \ } else { \
std::cout << "ASSERT_EQ at line " << __LINE__ << " failed: " << #var \ std::cout << "ASSERT_EQ at line " << __LINE__ << " failed: " << #var \
<< " != " << #value << '\n'; \ << " != " << #value << '\n'; \
@ -87,9 +86,9 @@ extern std::atomic_int64_t checks_passed;
} while (false); } while (false);
#define CHECK_NE(var, value) \ #define CHECK_NE(var, value) \
do { \ do { \
checks_checked.fetch_add(1); \ ++checks_checked; \
if ((var) != (value)) { \ if ((var) != (value)) { \
checks_passed.fetch_add(1); \ ++checks_passed; \
} else { \ } else { \
std::cout << "CHECK_NE at line " << __LINE__ << " failed: " << #var \ std::cout << "CHECK_NE at line " << __LINE__ << " failed: " << #var \
<< " == " << #value << '\n'; \ << " == " << #value << '\n'; \
@ -97,9 +96,9 @@ extern std::atomic_int64_t checks_passed;
} while (false); } while (false);
#define CHECK_GE(var, value) \ #define CHECK_GE(var, value) \
do { \ do { \
checks_checked.fetch_add(1); \ ++checks_checked; \
if ((var) >= (value)) { \ if ((var) >= (value)) { \
checks_passed.fetch_add(1); \ ++checks_passed; \
} else { \ } else { \
std::cout << "CHECK_GE at line " << __LINE__ << " failed: " << #var \ std::cout << "CHECK_GE at line " << __LINE__ << " failed: " << #var \
<< " < " << #value << '\n'; \ << " < " << #value << '\n'; \
@ -107,9 +106,9 @@ extern std::atomic_int64_t checks_passed;
} while (false); } while (false);
#define CHECK_LE(var, value) \ #define CHECK_LE(var, value) \
do { \ do { \
checks_checked.fetch_add(1); \ ++checks_checked; \
if ((var) <= (value)) { \ if ((var) <= (value)) { \
checks_passed.fetch_add(1); \ ++checks_passed; \
} else { \ } else { \
std::cout << "CHECK_LE at line " << __LINE__ << " failed: " << #var \ std::cout << "CHECK_LE at line " << __LINE__ << " failed: " << #var \
<< " > " << #value << '\n'; \ << " > " << #value << '\n'; \
@ -118,9 +117,9 @@ extern std::atomic_int64_t checks_passed;
#define CHECK_STREQ(str_a, str_b) \ #define CHECK_STREQ(str_a, str_b) \
do { \ do { \
checks_checked.fetch_add(1); \ ++checks_checked; \
if (std::strcmp((str_a), (str_b)) == 0) { \ if (std::strcmp((str_a), (str_b)) == 0) { \
checks_passed.fetch_add(1); \ ++checks_passed; \
} else { \ } else { \
std::cout << "CHECK_STREQ at line " << __LINE__ << "failed: " << #str_a \ std::cout << "CHECK_STREQ at line " << __LINE__ << "failed: " << #str_a \
<< " != " << #str_b << '\n'; \ << " != " << #str_b << '\n'; \