summaryrefslogtreecommitdiffhomepage
path: root/dev/lib/tests
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-11-22 13:11:56 -0500
committerGitHub <noreply@github.com>2025-11-22 13:11:56 -0500
commit9a70f32ddaec0eef99efbf7ff5597c2adf08f45a (patch)
tree1717d2b24d610b638cb70b12d7db74f15953f1fe /dev/lib/tests
parent8470a48ef4c6ea4b16e9a764aaedc7158f9c37ed (diff)
parent58dc03a47576601006c4870d1633bf35fc78176a (diff)
Merge pull request #17 from amlel-el-mahrouss/develop
feat: library improvements
Diffstat (limited to 'dev/lib/tests')
-rw-r--r--dev/lib/tests/hpptest.hpp71
1 files changed, 70 insertions, 1 deletions
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 <lib/io/print.hpp>
+#include <cstdlib>
+
namespace ocl::hpptest
{
+ /// @brief Standard termination error handler, called when a test fails.
+ struct standard_terminate final
+ {
+ template <bool stop_execution = true>
+ static void error() noexcept
+ {
+ ocl::io::print("standard_terminate::error, terminating...\n");
+
+ if (stop_execution)
+ std::terminate();
+ }
+ };
+
+ struct posix_terminate final
+ {
+ template <bool stop_execution = true, errno_t args>
+ 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 <condition_type expr = true>
@@ -16,6 +44,47 @@ namespace ocl::hpptest
{
#ifdef OCL_HPPTEST
OCL_HPPTEST_ASSERT(expr);
-#endif
+#endif // _WIN32
+ }
+
+ template <condition_type expect, typename on_fail>
+ inline void must_pass(condition_type cond) noexcept
+ {
+ if (cond != expect)
+ {
+ on_fail::template error<true>();
+ }
+ }
+
+ template <errno_t expect = 0>
+ inline void must_pass(errno_t ern) noexcept
+ {
+ if (ern != expect)
+ {
+ posix_terminate::error<true, expect>(ern);
+ }
+ }
+
+#ifdef _WIN32
+ struct win32_terminate final
+ {
+ template <bool stop_execution = false>
+ static void error(HRESULT err) noexcept
+ {
+ ocl::io::print("win32_terminate::error: expected=S_OK, got=", err, "\n");
+
+ if (stop_execution)
+ std::terminate();
+ }
+ };
+
+ template <HRESULT expect = S_OK>
+ inline void must_pass(HRESULT hr) noexcept
+ {
+ if (hr != expect)
+ {
+ win32_terminate::error<true>(hr);
+ }
}
+#endif // _WIN32
} // namespace ocl::hpptest