From f575de631ae39366d334167436a3fd540e45c068 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 22 Nov 2025 18:32:34 +0100 Subject: feat: hpptest: new 'standard_terminate' structure from hpptest.hpp feat: hpptest: new overload of must_pass for Generic, POSIX, and Win32. Signed-off-by: Amlal El Mahrouss --- dev/lib/tests/hpptest.hpp | 71 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) (limited to 'dev/lib/tests') diff --git a/dev/lib/tests/hpptest.hpp b/dev/lib/tests/hpptest.hpp index 05f985a..a3136b7 100644 --- a/dev/lib/tests/hpptest.hpp +++ b/dev/lib/tests/hpptest.hpp @@ -7,8 +7,36 @@ #pragma once +#include +#include + namespace ocl::hpptest { + /// @brief Standard termination error handler, called when a test fails. + struct standard_terminate final + { + template + static void error() noexcept + { + ocl::io::print("standard_terminate::error, terminating...\n"); + + if (stop_execution) + std::terminate(); + } + }; + + struct posix_terminate final + { + template + static void error(errno_t err) noexcept + { + ocl::io::print("posix_terminate::error: expected=", strerror(args), ", got=", strerror(err), "\n"); + + if (stop_execution) + std::terminate(); + } + }; + typedef bool condition_type; template @@ -16,6 +44,47 @@ namespace ocl::hpptest { #ifdef OCL_HPPTEST OCL_HPPTEST_ASSERT(expr); -#endif +#endif // _WIN32 + } + + template + inline void must_pass(condition_type cond) noexcept + { + if (cond != expect) + { + on_fail::template error(); + } + } + + template + inline void must_pass(errno_t ern) noexcept + { + if (ern != expect) + { + posix_terminate::error(ern); + } + } + +#ifdef _WIN32 + struct win32_terminate final + { + template + static void error(HRESULT err) noexcept + { + ocl::io::print("win32_terminate::error: expected=S_OK, got=", err, "\n"); + + if (stop_execution) + std::terminate(); + } + }; + + template + inline void must_pass(HRESULT hr) noexcept + { + if (hr != expect) + { + win32_terminate::error(hr); + } } +#endif // _WIN32 } // namespace ocl::hpptest -- cgit v1.2.3