#pragma once // Minimal test harness: CHECK accumulates failures, TEST_MAIN reports and sets the exit // code. Deliberately tiny — the daemon does not pull in a test framework for this. #include #include #include namespace veloxd_test { inline std::vector& failures() { static std::vector f; return f; } inline int& checks() { static int n = 0; return n; } } // namespace veloxd_test #define CHECK(cond) \ do { \ ++::veloxd_test::checks(); \ if (!(cond)) { \ ::veloxd_test::failures().push_back(std::string(__FILE__) + ":" + \ std::to_string(__LINE__) + ": " + #cond); \ } \ } while (0) #define CHECK_EQ(a, b) \ do { \ ++::veloxd_test::checks(); \ auto _va = (a); \ auto _vb = (b); \ if (!(_va == _vb)) { \ ::veloxd_test::failures().push_back(std::string(__FILE__) + ":" + \ std::to_string(__LINE__) + ": " + #a + \ " == " + #b); \ } \ } while (0) #define TEST_MAIN() \ int main() { \ run(); \ for (const auto& f : ::veloxd_test::failures()) std::printf("FAIL %s\n", f.c_str()); \ std::printf("%d/%d checks passed\n", \ ::veloxd_test::checks() - \ static_cast(::veloxd_test::failures().size()), \ ::veloxd_test::checks()); \ return ::veloxd_test::failures().empty() ? 0 : 1; \ }