diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-22 18:32:34 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-22 18:42:24 +0100 |
| commit | f575de631ae39366d334167436a3fd540e45c068 (patch) | |
| tree | 89bf2b2e3f00dc2f8982305a54a92afa3030c72c | |
| parent | 10b3e4fbd0779833d3f2c7cff3c1d802664fa358 (diff) | |
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 <amlal@nekernel.org>
| -rw-r--r-- | dev/lib/net/modem.hpp | 11 | ||||
| -rw-r--r-- | dev/lib/net/url.hpp | 12 | ||||
| -rw-r--r-- | dev/lib/simd/basic_simd.hpp | 10 | ||||
| -rw-r--r-- | dev/lib/simd/simd.hpp | 14 | ||||
| -rw-r--r-- | dev/lib/tests/hpptest.hpp | 71 | ||||
| -rw-r--r-- | dev/tests/fix_basic/fix_test.cc | 5 | ||||
| -rw-r--r-- | dev/tests/tracked_ptr_basic/tracked_ptr_test.cc | 2 | ||||
| -rw-r--r-- | dev/tests/tracked_ptr_leak/tracked_ptr_test.cc | 2 |
8 files changed, 105 insertions, 22 deletions
diff --git a/dev/lib/net/modem.hpp b/dev/lib/net/modem.hpp index a498f2e..fd64f72 100644 --- a/dev/lib/net/modem.hpp +++ b/dev/lib/net/modem.hpp @@ -5,8 +5,7 @@ * Copyright 2025, Amlal El Mahrouss, licensed under the Boost Software License. */ -#ifndef _OCL_NET_NETWORK_HPP -#define _OCL_NET_NETWORK_HPP +#pragma once #include <lib/tests/hpptest.hpp> @@ -22,13 +21,14 @@ namespace ocl::net { class modem; - using socket_type = int64_t; - /// ============================================================================= /// @brief Modem container concept, a container to read and write on a network stream. /// ============================================================================= class modem final { + public: + using socket_type = int64_t; + private: socket_type fd_{}; bool server_fd_{false}; @@ -145,7 +145,7 @@ namespace ocl::net int ret = ::bind(fd_, (struct sockaddr*)&addr_, sizeof(addr_)); bad_ = ret == -1; - + ::listen(fd_, modem::backlog_count); return bad_ == false; @@ -166,4 +166,3 @@ namespace ocl::net }; } // namespace ocl::net -#endif // ifndef _OCL_NET_NETWORK_HPP diff --git a/dev/lib/net/url.hpp b/dev/lib/net/url.hpp index 4bbc271..60440ad 100644 --- a/dev/lib/net/url.hpp +++ b/dev/lib/net/url.hpp @@ -24,6 +24,8 @@ namespace ocl::net http, https, mailto, + ftp, + tel, bad = 0xff, }; @@ -53,6 +55,16 @@ namespace ocl::net m_protocol_ = url_protocol::mailto; this->operator/=(protocol.substr(std::size("mailto:"))); } + else if (protocol.starts_with("tel:")) + { + m_protocol_ = url_protocol::tel; + this->operator/=(protocol.substr(std::size("tel:"))); + } + else if (protocol.starts_with("ftp:")) + { + m_protocol_ = url_protocol::ftp; + this->operator/=(protocol.substr(std::size("ftp:"))); + } } ~basic_url() = default; diff --git a/dev/lib/simd/basic_simd.hpp b/dev/lib/simd/basic_simd.hpp index f14d977..975ab2b 100644 --- a/dev/lib/simd/basic_simd.hpp +++ b/dev/lib/simd/basic_simd.hpp @@ -19,9 +19,9 @@ using simd_type = __m256; using simd_type = float32x4_t; #endif -namespace ocl::snu::simd +namespace ocl::simd { - struct basic_simd_backend final + struct basic_simd final { struct simd_traits final { @@ -29,7 +29,7 @@ namespace ocl::snu::simd private: static bool bad; - friend class basic_simd_backend; + friend class basic_simd; }; using register_type = simd_traits; @@ -41,7 +41,7 @@ namespace ocl::snu::simd std::basic_string<char> isa() { - return "basic_simd_backend"; + return "basic_simd"; } }; -} // namespace ocl::snu::simd +} // namespace ocl::simd diff --git a/dev/lib/simd/simd.hpp b/dev/lib/simd/simd.hpp index 7a40adc..239e512 100644 --- a/dev/lib/simd/simd.hpp +++ b/dev/lib/simd/simd.hpp @@ -12,10 +12,10 @@ /// @author Amlal El Mahrouss /// @brief Basic SIMD processor. -namespace ocl::snu::simd +namespace ocl::simd { template <typename backend_type> - class basic_simd_processor + class real_type { private: backend_type backend_; @@ -30,11 +30,11 @@ namespace ocl::snu::simd }; public: - basic_simd_processor() = default; - virtual ~basic_simd_processor() = default; + real_type() = default; + virtual ~real_type() = default; - basic_simd_processor& operator=(const basic_simd_processor&) = delete; - basic_simd_processor(const basic_simd_processor&) = delete; + real_type& operator=(const real_type&) = delete; + real_type(const real_type&) = delete; typename backend_type::register_type& call(const opcode& op, typename backend_type::register_type& lhs, typename backend_type::register_type& rhs) { @@ -58,4 +58,4 @@ namespace ocl::snu::simd return backend_.isa(); } }; -} // namespace ocl::snu::simd +} // namespace ocl::simd 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 diff --git a/dev/tests/fix_basic/fix_test.cc b/dev/tests/fix_basic/fix_test.cc index 058831b..9055803 100644 --- a/dev/tests/fix_basic/fix_test.cc +++ b/dev/tests/fix_basic/fix_test.cc @@ -6,13 +6,16 @@ */ #include <lib/fix/fix.hpp> -#include <gtest/gtest.h> +#include <lib/tests/hpptest.hpp> +#include <lib/tests/gtest.hpp> TEST(FIXTest, BasicFIXUsage) { ocl::fix::basic_visitor<char> basic_visitor; ocl::fix::basic_range_data<char> fix = basic_visitor.visit("8=FIX.4.2|9=65|35=A|49=SERVER|56=CLIENT|34=177|52=20090107-18:15:16|98=0|108=30|10=062|"); + ocl::hpptest::must_pass<ENOENT>(EPERM); + EXPECT_EQ(fix.magic_, ocl::fix::detail::begin_fix()); EXPECT_TRUE(fix.is_valid()); } diff --git a/dev/tests/tracked_ptr_basic/tracked_ptr_test.cc b/dev/tests/tracked_ptr_basic/tracked_ptr_test.cc index aa862fd..ec3c51f 100644 --- a/dev/tests/tracked_ptr_basic/tracked_ptr_test.cc +++ b/dev/tests/tracked_ptr_basic/tracked_ptr_test.cc @@ -6,7 +6,7 @@ */ #include <lib/memory/tracked_ptr.hpp> -#include <gtest/gtest.h> +#include <lib/tests/gtest.hpp> TEST(TrackedPtrTest, BasicTrackedPtrUsage) { diff --git a/dev/tests/tracked_ptr_leak/tracked_ptr_test.cc b/dev/tests/tracked_ptr_leak/tracked_ptr_test.cc index 08c17a1..8ca6615 100644 --- a/dev/tests/tracked_ptr_leak/tracked_ptr_test.cc +++ b/dev/tests/tracked_ptr_leak/tracked_ptr_test.cc @@ -6,7 +6,7 @@ */ #include <lib/memory/tracked_ptr.hpp> -#include <gtest/gtest.h> +#include <lib/tests/gtest.hpp> TEST(TrackedPtrTest, LeakTrackedPtrUsage) { |
