From 54e32a8a3535d99d104775687af0731b0be3b129 Mon Sep 17 00:00:00 2001 From: Amlal Date: Tue, 12 Aug 2025 11:53:13 +0200 Subject: wip: work in progress network tests using GTest. Reworked print module too. Signed-off-by: Amlal --- dev/tests/network_basic/CMakeLists.txt | 23 ++++++++++++++++++++++ dev/tests/network_basic/net_test.cc | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 dev/tests/network_basic/CMakeLists.txt create mode 100644 dev/tests/network_basic/net_test.cc (limited to 'dev/tests/network_basic') diff --git a/dev/tests/network_basic/CMakeLists.txt b/dev/tests/network_basic/CMakeLists.txt new file mode 100644 index 0000000..9e0fc6b --- /dev/null +++ b/dev/tests/network_basic/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.10) +project(SOCLTests) + +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip +) + +# For Windows: Prevent overriding the parent project's compiler/linker settings +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googletest) + +enable_testing() + +add_executable(NetworkTestBasic net_test.cc) +target_link_libraries(NetworkTestBasic gtest_main) + +set_property(TARGET NetworkTestBasic PROPERTY CXX_STANDARD 20) +target_include_directories(NetworkTestBasic PUBLIC ../../) + +include(GoogleTest) +gtest_discover_tests(NetworkTestBasic) diff --git a/dev/tests/network_basic/net_test.cc b/dev/tests/network_basic/net_test.cc new file mode 100644 index 0000000..72bcda0 --- /dev/null +++ b/dev/tests/network_basic/net_test.cc @@ -0,0 +1,36 @@ +/* + * File: tests/tracked_ptr_test.cc + * Purpose: Custom smart pointer unit tests in C++ + * Author: Amlal El Mahrouss (founder@snu.systems) + * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp. + */ + +#include +#include +#include +#include + +TEST(NetworkTest, BasicNetworkUsage) +{ + + snu::net::basic_modem modem; + modem.construct(snu::net::basic_modem::local_address_ip4, true); + + snu::net::basic_modem modem_cl; + modem.construct(snu::net::basic_modem::local_address_ip4, false); + + EXPECT_TRUE(modem_cl.is_valid()); + EXPECT_TRUE(modem.is_valid()); + + std::basic_string buf_dst = "HELLO, NET!"; + char* buf = new char[buf_dst.size()]; + + modem_cl.transmit(buf_dst); + modem.receive(buf, buf_dst.size()); + + snu::io::println<>(buf); + snu::io::println<>(buf_dst); + + delete[] buf; + buf = nullptr; +} \ No newline at end of file -- cgit v1.2.3 From 4522b12ee7929f6ba195de9c0b3111802e8e0100 Mon Sep 17 00:00:00 2001 From: Amlal Date: Wed, 13 Aug 2025 18:43:41 +0200 Subject: feat! improve network test. Signed-off-by: Amlal --- dev/tests/network_basic/net_test.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'dev/tests/network_basic') diff --git a/dev/tests/network_basic/net_test.cc b/dev/tests/network_basic/net_test.cc index 72bcda0..9423fe7 100644 --- a/dev/tests/network_basic/net_test.cc +++ b/dev/tests/network_basic/net_test.cc @@ -1,6 +1,6 @@ /* - * File: tests/tracked_ptr_test.cc - * Purpose: Custom smart pointer unit tests in C++ + * File: tests/net_test.cc + * Purpose: Network unit tests in C++ * Author: Amlal El Mahrouss (founder@snu.systems) * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp. */ @@ -12,12 +12,11 @@ TEST(NetworkTest, BasicNetworkUsage) { - snu::net::basic_modem modem; modem.construct(snu::net::basic_modem::local_address_ip4, true); snu::net::basic_modem modem_cl; - modem.construct(snu::net::basic_modem::local_address_ip4, false); + modem_cl.construct(snu::net::basic_modem::local_address_ip4, false); EXPECT_TRUE(modem_cl.is_valid()); EXPECT_TRUE(modem.is_valid()); @@ -33,4 +32,4 @@ TEST(NetworkTest, BasicNetworkUsage) delete[] buf; buf = nullptr; -} \ No newline at end of file +} -- cgit v1.2.3 From 70945244a35e0e6d2a2e0f84ae83f31b9898a0ca Mon Sep 17 00:00:00 2001 From: Amlal Date: Fri, 15 Aug 2025 12:09:28 +0200 Subject: feat: new hpptest and gtest module. Other module improvements. Signed-off-by: Amlal --- README.md | 12 +++++++++--- dev/examples/fix/fix.cc | 2 +- dev/lib/core/includes.hpp | 15 +++++++++++++++ dev/lib/except/hpptest.hpp | 9 --------- dev/lib/fix/parser.hpp | 2 +- dev/lib/io/print.hpp | 19 +++++++++---------- dev/lib/net/url.hpp | 16 ++++++++-------- dev/lib/tests/gtest.hpp | 8 ++++++++ dev/lib/tests/hpptest.hpp | 22 ++++++++++++++++++++++ dev/tests/network_basic/CMakeLists.txt | 4 ++-- dev/tests/network_basic/net_test.cc | 7 ++++--- 11 files changed, 79 insertions(+), 37 deletions(-) create mode 100644 dev/lib/core/includes.hpp delete mode 100644 dev/lib/except/hpptest.hpp create mode 100644 dev/lib/tests/gtest.hpp create mode 100644 dev/lib/tests/hpptest.hpp (limited to 'dev/tests/network_basic') diff --git a/README.md b/README.md index bdee118..c7bf8c4 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,15 @@ A C++ library with additional modules for your C++ SDLC. -## Getting Started: +## Requirements: -Here is an example of how snu::opt works. +- Boost C++ libraries (https://www.boost.org/) +- Clang (https://clang.llvm.org/) +- Git (https://git-scm.com/) + +## Examples: + +### Logic Module (Option container) ```cpp #include @@ -23,4 +29,4 @@ int main(int argc, char** argv) } ``` -##### (c) 2025 SNU Systems, Corp. \ No newline at end of file +##### (c) 2025 SNU Systems, Corp. diff --git a/dev/examples/fix/fix.cc b/dev/examples/fix/fix.cc index 3656c0c..ce48186 100644 --- a/dev/examples/fix/fix.cc +++ b/dev/examples/fix/fix.cc @@ -4,7 +4,7 @@ licensed under the MIT license */ -#include +#include #include #include #include diff --git a/dev/lib/core/includes.hpp b/dev/lib/core/includes.hpp new file mode 100644 index 0000000..b516e5f --- /dev/null +++ b/dev/lib/core/includes.hpp @@ -0,0 +1,15 @@ +/* + * File: core/includes.hpp + * Purpose: Core includes for the SOCL library. + * Author: Amlal El Mahrouss (founder@snu.systems) + * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include diff --git a/dev/lib/except/hpptest.hpp b/dev/lib/except/hpptest.hpp deleted file mode 100644 index 5277780..0000000 --- a/dev/lib/except/hpptest.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -/// @note Place your static asserts here, for hpptest.py! -#ifdef SOCL_HPPTEST -SOCL_HPPTEST_ASSERT(true); -SOCL_HPPTEST_ASSERT(1 + 1 == 2); -#endif - -/// @brief This header file is meant to be a tutorial on how to use mk.test and its macro framework. diff --git a/dev/lib/fix/parser.hpp b/dev/lib/fix/parser.hpp index 0f2287e..8181359 100644 --- a/dev/lib/fix/parser.hpp +++ b/dev/lib/fix/parser.hpp @@ -159,7 +159,7 @@ namespace snu::fix if (in.empty()) return ret; - thread_local std::basic_string in_tmp{}; + static thread_local std::basic_string in_tmp{}; in_tmp.reserve(in.size()); diff --git a/dev/lib/io/print.hpp b/dev/lib/io/print.hpp index 36192c4..eb425c1 100644 --- a/dev/lib/io/print.hpp +++ b/dev/lib/io/print.hpp @@ -13,31 +13,30 @@ #include namespace snu::io -{ - template - inline void printv(T fmt) noexcept +{ + template + inline void print(T fmt, Args... other) noexcept { std::cout << fmt; + print(other...); } template - inline void printv(std::initializer_list fmt) noexcept + inline void print(T fmt) noexcept { std::cout << fmt; } - template - inline void print(T... fmt) noexcept + inline void print() noexcept { - (printv(fmt), ...); + std::cout << std::endl; } template inline void println(T... fmt) noexcept { - print(static_cast(fmt)...); - std::cout << std::endl; + print(fmt...); } } // namespace snu::io -#endif // ifndef _SNU_PRINT_HPP \ No newline at end of file +#endif // ifndef _SNU_PRINT_HPP diff --git a/dev/lib/net/url.hpp b/dev/lib/net/url.hpp index 496889c..f6dba95 100644 --- a/dev/lib/net/url.hpp +++ b/dev/lib/net/url.hpp @@ -51,14 +51,14 @@ namespace snu::net return *this; } - explicit operator bool() - { - return this->is_valid(); - } + explicit operator bool() + { + return this->is_valid(); + } - bool is_valid() - { - return ss_.size() > 0; - } + bool is_valid() + { + return ss_.size() > 0; + } }; } // namespace snu::net diff --git a/dev/lib/tests/gtest.hpp b/dev/lib/tests/gtest.hpp new file mode 100644 index 0000000..14474c0 --- /dev/null +++ b/dev/lib/tests/gtest.hpp @@ -0,0 +1,8 @@ +/* + * File: tests/gtest.hpp + * Purpose: Google Test wrapper for the SOCL library. + * Author: Amlal El Mahrouss (founder@snu.systems) + * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp. + */ + +#include diff --git a/dev/lib/tests/hpptest.hpp b/dev/lib/tests/hpptest.hpp new file mode 100644 index 0000000..4c99ce6 --- /dev/null +++ b/dev/lib/tests/hpptest.hpp @@ -0,0 +1,22 @@ +/* + * File: tests/hpptest.hpp + * Purpose: HPP Test wrapper for the SOCL library. + * Author: Amlal El Mahrouss (founder@snu.systems) + * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp. + */ + +#pragma once + + +#ifdef SOCL_HPPTEST +namespace snu::hpptest +{ + typedef bool condition_type; + + template + consteval inline void must_pass() + { + SOCL_HPPTEST_ASSERT(expr); + } +} // namespace snu::hpptest +#endif diff --git a/dev/tests/network_basic/CMakeLists.txt b/dev/tests/network_basic/CMakeLists.txt index 9e0fc6b..a5704fc 100644 --- a/dev/tests/network_basic/CMakeLists.txt +++ b/dev/tests/network_basic/CMakeLists.txt @@ -1,5 +1,5 @@ -cmake_minimum_required(VERSION 3.10) -project(SOCLTests) +cmake_minimum_required(VERSION 3.28) +project(SOCLTests LANGUAGES CXX) include(FetchContent) FetchContent_Declare( diff --git a/dev/tests/network_basic/net_test.cc b/dev/tests/network_basic/net_test.cc index 9423fe7..634048e 100644 --- a/dev/tests/network_basic/net_test.cc +++ b/dev/tests/network_basic/net_test.cc @@ -7,8 +7,8 @@ #include #include +#include #include -#include TEST(NetworkTest, BasicNetworkUsage) { @@ -27,8 +27,9 @@ TEST(NetworkTest, BasicNetworkUsage) modem_cl.transmit(buf_dst); modem.receive(buf, buf_dst.size()); - snu::io::println<>(buf); - snu::io::println<>(buf_dst); + snu::io::print(buf_dst); + snu::io::print(buf); + snu::io::print(); delete[] buf; buf = nullptr; -- cgit v1.2.3