From d54c2033eaaad5b6f9340b7cbaf8b3b037fb3cbe Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 17 Dec 2025 14:53:59 +0100 Subject: chore: updated file structure. Signed-off-by: Amlal El Mahrouss --- example/hash_crc32_example/CMakeLists.txt | 15 ++++++++ example/hash_crc32_example/example.cc | 15 ++++++++ example/option_example/CMakeLists.txt | 15 ++++++++ example/option_example/example.cc | 14 ++++++++ example/simple_allocator_op/CMakeLists.txt | 15 ++++++++ example/simple_allocator_op/example.cc | 14 ++++++++ example/simple_unique_socket/CMakeLists.txt | 15 ++++++++ example/simple_unique_socket/example.cc | 22 ++++++++++++ example/smart_ptr_example/CMakeLists.txt | 15 ++++++++ example/smart_ptr_example/example.cc | 10 ++++++ examples/hash_crc32_example/CMakeLists.txt | 15 -------- examples/hash_crc32_example/example.cc | 15 -------- examples/option_example/CMakeLists.txt | 15 -------- examples/option_example/example.cc | 14 -------- examples/simple_allocator_op/CMakeLists.txt | 15 -------- examples/simple_allocator_op/example.cc | 14 -------- examples/simple_unique_socket/CMakeLists.txt | 15 -------- examples/simple_unique_socket/example.cc | 22 ------------ examples/smart_ptr_example/CMakeLists.txt | 15 -------- examples/smart_ptr_example/example.cc | 10 ------ test/network_basic/CMakeLists.txt | 23 +++++++++++++ test/network_basic/network_basic_test.cc | 51 ++++++++++++++++++++++++++++ tests/network_basic/CMakeLists.txt | 23 ------------- tests/network_basic/network_basic_test.cc | 51 ---------------------------- 24 files changed, 224 insertions(+), 224 deletions(-) create mode 100644 example/hash_crc32_example/CMakeLists.txt create mode 100644 example/hash_crc32_example/example.cc create mode 100644 example/option_example/CMakeLists.txt create mode 100644 example/option_example/example.cc create mode 100644 example/simple_allocator_op/CMakeLists.txt create mode 100644 example/simple_allocator_op/example.cc create mode 100644 example/simple_unique_socket/CMakeLists.txt create mode 100644 example/simple_unique_socket/example.cc create mode 100644 example/smart_ptr_example/CMakeLists.txt create mode 100644 example/smart_ptr_example/example.cc delete mode 100644 examples/hash_crc32_example/CMakeLists.txt delete mode 100644 examples/hash_crc32_example/example.cc delete mode 100644 examples/option_example/CMakeLists.txt delete mode 100644 examples/option_example/example.cc delete mode 100644 examples/simple_allocator_op/CMakeLists.txt delete mode 100644 examples/simple_allocator_op/example.cc delete mode 100644 examples/simple_unique_socket/CMakeLists.txt delete mode 100644 examples/simple_unique_socket/example.cc delete mode 100644 examples/smart_ptr_example/CMakeLists.txt delete mode 100644 examples/smart_ptr_example/example.cc create mode 100644 test/network_basic/CMakeLists.txt create mode 100644 test/network_basic/network_basic_test.cc delete mode 100644 tests/network_basic/CMakeLists.txt delete mode 100644 tests/network_basic/network_basic_test.cc diff --git a/example/hash_crc32_example/CMakeLists.txt b/example/hash_crc32_example/CMakeLists.txt new file mode 100644 index 0000000..cd8d7b5 --- /dev/null +++ b/example/hash_crc32_example/CMakeLists.txt @@ -0,0 +1,15 @@ + +cmake_minimum_required(VERSION 3.15...3.31) + +project( + HashExample + VERSION 1.0 + LANGUAGES CXX) + +find_package(Boost REQUIRED COMPONENTS container) + +add_executable(HashExample example.cc) + +set_property(TARGET HashExample PROPERTY CXX_STANDARD 20) +target_include_directories(HashExample PUBLIC ../../include/) +target_link_libraries(HashExample PRIVATE Boost::container) diff --git a/example/hash_crc32_example/example.cc b/example/hash_crc32_example/example.cc new file mode 100644 index 0000000..be6780f --- /dev/null +++ b/example/hash_crc32_example/example.cc @@ -0,0 +1,15 @@ +#include +#include +#include + +int main(int argc, char** argv) +{ + if (argc != 2) return 1; + + std::hash hash{}; + + ocl::io::enable_stdio_sync(false); + ocl::io::print(hash.operator()(argv[1])); + + return 0; +} diff --git a/example/option_example/CMakeLists.txt b/example/option_example/CMakeLists.txt new file mode 100644 index 0000000..a77d4c5 --- /dev/null +++ b/example/option_example/CMakeLists.txt @@ -0,0 +1,15 @@ + +cmake_minimum_required(VERSION 3.15...3.31) + +project( + OptionExample + VERSION 1.0 + LANGUAGES CXX) + +find_package(Boost REQUIRED COMPONENTS container) + +add_executable(OptionExample example.cc) + +set_property(TARGET OptionExample PROPERTY CXX_STANDARD 20) +target_include_directories(OptionExample PUBLIC ../../include/) +target_link_libraries(OptionExample PRIVATE Boost::container) diff --git a/example/option_example/example.cc b/example/option_example/example.cc new file mode 100644 index 0000000..0da9d49 --- /dev/null +++ b/example/option_example/example.cc @@ -0,0 +1,14 @@ +#include +#include +#include + +int main(int argc, char** argv) +{ + ocl::option opt{ocl::eval_eq(nullptr, nullptr)}; + opt.expect("is incorrect"); + + ocl::option opt2{ocl::eval_eq(argv, nullptr)}; + opt2.expect("is incorrect"); + + return 0; +} diff --git a/example/simple_allocator_op/CMakeLists.txt b/example/simple_allocator_op/CMakeLists.txt new file mode 100644 index 0000000..fbda92b --- /dev/null +++ b/example/simple_allocator_op/CMakeLists.txt @@ -0,0 +1,15 @@ + +cmake_minimum_required(VERSION 3.15...3.31) + +project( + AllocatorExample + VERSION 1.0 + LANGUAGES CXX) + +find_package(Boost REQUIRED COMPONENTS container) + +add_executable(AllocatorExample example.cc) + +set_property(TARGET AllocatorExample PROPERTY CXX_STANDARD 20) +target_include_directories(AllocatorExample PUBLIC ../../include/) +target_link_libraries(AllocatorExample PRIVATE Boost::container) diff --git a/example/simple_allocator_op/example.cc b/example/simple_allocator_op/example.cc new file mode 100644 index 0000000..83be033 --- /dev/null +++ b/example/simple_allocator_op/example.cc @@ -0,0 +1,14 @@ +#include +#include + +/// @brief Basic Send test +int main() +{ + ocl::allocator int_alloc; + auto foo = int_alloc.construct_array<1>(); + + *foo = 67; + ocl::io::print(*foo); + + return EXIT_SUCCESS; +} diff --git a/example/simple_unique_socket/CMakeLists.txt b/example/simple_unique_socket/CMakeLists.txt new file mode 100644 index 0000000..06d5119 --- /dev/null +++ b/example/simple_unique_socket/CMakeLists.txt @@ -0,0 +1,15 @@ + +cmake_minimum_required(VERSION 3.15...3.31) + +project( + NetworkExample + VERSION 1.0 + LANGUAGES CXX) + +find_package(Boost REQUIRED COMPONENTS container) + +add_executable(NetworkExample example.cc) + +set_property(TARGET NetworkExample PROPERTY CXX_STANDARD 20) +target_include_directories(NetworkExample PUBLIC ../../include/) +target_link_libraries(NetworkExample PRIVATE Boost::container) diff --git a/example/simple_unique_socket/example.cc b/example/simple_unique_socket/example.cc new file mode 100644 index 0000000..86178e1 --- /dev/null +++ b/example/simple_unique_socket/example.cc @@ -0,0 +1,22 @@ +#include +#include + +/// @brief Basic Send test +int main() +{ + ocl::unique_socket sock = ocl::unique_socket::make_socket<8005>(ocl::unique_socket::any_address, true); + + char buf_dst[512] = {"HELLO, WORLD\0"}; + + ocl::unique_socket sock2 = ocl::unique_socket::make_socket<8005>(ocl::unique_socket::any_address, false); + + char buf_dst2[512] = {0}; + + auto new_sock = sock.accept(); + new_sock.write_from_buffer(buf_dst, strlen(buf_dst)); + sock2.read_client_buffer(buf_dst2, strlen(buf_dst)); + std::cout << "result:" << buf_dst2 << "\n"; + + + return EXIT_SUCCESS; +} diff --git a/example/smart_ptr_example/CMakeLists.txt b/example/smart_ptr_example/CMakeLists.txt new file mode 100644 index 0000000..6584ad2 --- /dev/null +++ b/example/smart_ptr_example/CMakeLists.txt @@ -0,0 +1,15 @@ + +cmake_minimum_required(VERSION 3.15...3.31) + +project( + SmartPtrExample + VERSION 1.0 + LANGUAGES CXX) + +find_package(Boost REQUIRED COMPONENTS container) + +add_executable(SmartPtrExample example.cc) + +set_property(TARGET SmartPtrExample PROPERTY CXX_STANDARD 20) +target_include_directories(SmartPtrExample PUBLIC ../../include/) +target_link_libraries(SmartPtrExample PRIVATE Boost::container) diff --git a/example/smart_ptr_example/example.cc b/example/smart_ptr_example/example.cc new file mode 100644 index 0000000..ef1a865 --- /dev/null +++ b/example/smart_ptr_example/example.cc @@ -0,0 +1,10 @@ +#include +#include +#include + +int main(int argc, char** argv) +{ + ocl::shared_ptr smart = ocl::delete_ptr(&std::cout); + + return 0; +} diff --git a/examples/hash_crc32_example/CMakeLists.txt b/examples/hash_crc32_example/CMakeLists.txt deleted file mode 100644 index cd8d7b5..0000000 --- a/examples/hash_crc32_example/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ - -cmake_minimum_required(VERSION 3.15...3.31) - -project( - HashExample - VERSION 1.0 - LANGUAGES CXX) - -find_package(Boost REQUIRED COMPONENTS container) - -add_executable(HashExample example.cc) - -set_property(TARGET HashExample PROPERTY CXX_STANDARD 20) -target_include_directories(HashExample PUBLIC ../../include/) -target_link_libraries(HashExample PRIVATE Boost::container) diff --git a/examples/hash_crc32_example/example.cc b/examples/hash_crc32_example/example.cc deleted file mode 100644 index be6780f..0000000 --- a/examples/hash_crc32_example/example.cc +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include - -int main(int argc, char** argv) -{ - if (argc != 2) return 1; - - std::hash hash{}; - - ocl::io::enable_stdio_sync(false); - ocl::io::print(hash.operator()(argv[1])); - - return 0; -} diff --git a/examples/option_example/CMakeLists.txt b/examples/option_example/CMakeLists.txt deleted file mode 100644 index a77d4c5..0000000 --- a/examples/option_example/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ - -cmake_minimum_required(VERSION 3.15...3.31) - -project( - OptionExample - VERSION 1.0 - LANGUAGES CXX) - -find_package(Boost REQUIRED COMPONENTS container) - -add_executable(OptionExample example.cc) - -set_property(TARGET OptionExample PROPERTY CXX_STANDARD 20) -target_include_directories(OptionExample PUBLIC ../../include/) -target_link_libraries(OptionExample PRIVATE Boost::container) diff --git a/examples/option_example/example.cc b/examples/option_example/example.cc deleted file mode 100644 index 0da9d49..0000000 --- a/examples/option_example/example.cc +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -#include - -int main(int argc, char** argv) -{ - ocl::option opt{ocl::eval_eq(nullptr, nullptr)}; - opt.expect("is incorrect"); - - ocl::option opt2{ocl::eval_eq(argv, nullptr)}; - opt2.expect("is incorrect"); - - return 0; -} diff --git a/examples/simple_allocator_op/CMakeLists.txt b/examples/simple_allocator_op/CMakeLists.txt deleted file mode 100644 index fbda92b..0000000 --- a/examples/simple_allocator_op/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ - -cmake_minimum_required(VERSION 3.15...3.31) - -project( - AllocatorExample - VERSION 1.0 - LANGUAGES CXX) - -find_package(Boost REQUIRED COMPONENTS container) - -add_executable(AllocatorExample example.cc) - -set_property(TARGET AllocatorExample PROPERTY CXX_STANDARD 20) -target_include_directories(AllocatorExample PUBLIC ../../include/) -target_link_libraries(AllocatorExample PRIVATE Boost::container) diff --git a/examples/simple_allocator_op/example.cc b/examples/simple_allocator_op/example.cc deleted file mode 100644 index 83be033..0000000 --- a/examples/simple_allocator_op/example.cc +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - -/// @brief Basic Send test -int main() -{ - ocl::allocator int_alloc; - auto foo = int_alloc.construct_array<1>(); - - *foo = 67; - ocl::io::print(*foo); - - return EXIT_SUCCESS; -} diff --git a/examples/simple_unique_socket/CMakeLists.txt b/examples/simple_unique_socket/CMakeLists.txt deleted file mode 100644 index 06d5119..0000000 --- a/examples/simple_unique_socket/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ - -cmake_minimum_required(VERSION 3.15...3.31) - -project( - NetworkExample - VERSION 1.0 - LANGUAGES CXX) - -find_package(Boost REQUIRED COMPONENTS container) - -add_executable(NetworkExample example.cc) - -set_property(TARGET NetworkExample PROPERTY CXX_STANDARD 20) -target_include_directories(NetworkExample PUBLIC ../../include/) -target_link_libraries(NetworkExample PRIVATE Boost::container) diff --git a/examples/simple_unique_socket/example.cc b/examples/simple_unique_socket/example.cc deleted file mode 100644 index 86178e1..0000000 --- a/examples/simple_unique_socket/example.cc +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -/// @brief Basic Send test -int main() -{ - ocl::unique_socket sock = ocl::unique_socket::make_socket<8005>(ocl::unique_socket::any_address, true); - - char buf_dst[512] = {"HELLO, WORLD\0"}; - - ocl::unique_socket sock2 = ocl::unique_socket::make_socket<8005>(ocl::unique_socket::any_address, false); - - char buf_dst2[512] = {0}; - - auto new_sock = sock.accept(); - new_sock.write_from_buffer(buf_dst, strlen(buf_dst)); - sock2.read_client_buffer(buf_dst2, strlen(buf_dst)); - std::cout << "result:" << buf_dst2 << "\n"; - - - return EXIT_SUCCESS; -} diff --git a/examples/smart_ptr_example/CMakeLists.txt b/examples/smart_ptr_example/CMakeLists.txt deleted file mode 100644 index 6584ad2..0000000 --- a/examples/smart_ptr_example/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ - -cmake_minimum_required(VERSION 3.15...3.31) - -project( - SmartPtrExample - VERSION 1.0 - LANGUAGES CXX) - -find_package(Boost REQUIRED COMPONENTS container) - -add_executable(SmartPtrExample example.cc) - -set_property(TARGET SmartPtrExample PROPERTY CXX_STANDARD 20) -target_include_directories(SmartPtrExample PUBLIC ../../include/) -target_link_libraries(SmartPtrExample PRIVATE Boost::container) diff --git a/examples/smart_ptr_example/example.cc b/examples/smart_ptr_example/example.cc deleted file mode 100644 index ef1a865..0000000 --- a/examples/smart_ptr_example/example.cc +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include -#include - -int main(int argc, char** argv) -{ - ocl::shared_ptr smart = ocl::delete_ptr(&std::cout); - - return 0; -} diff --git a/test/network_basic/CMakeLists.txt b/test/network_basic/CMakeLists.txt new file mode 100644 index 0000000..267b584 --- /dev/null +++ b/test/network_basic/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.27) +project(NetworkTestBasic LANGUAGES CXX) + +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 network_basic_test.cc) +target_link_libraries(NetworkTestBasic gtest_main) + +set_property(TARGET NetworkTestBasic PROPERTY CXX_STANDARD 20) +target_include_directories(NetworkTestBasic PUBLIC ../../include/) + +include(GoogleTest) +gtest_discover_tests(NetworkTestBasic) diff --git a/test/network_basic/network_basic_test.cc b/test/network_basic/network_basic_test.cc new file mode 100644 index 0000000..21a6668 --- /dev/null +++ b/test/network_basic/network_basic_test.cc @@ -0,0 +1,51 @@ +/* + * File: tests/net_test.cc + * Purpose: Network unit tests in C++ + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss, licensed under the Boost Software License. + */ + +#include +#include +#include + +/// @brief Basic Send test +TEST(NetworkTest, BasicNetworkIO) +{ + ocl::unique_socket sock = ocl::unique_socket::make_socket<8000>(ocl::unique_socket::any_address, true); + + std::vector buf_dst(512); + + buf_dst.push_back('H'); + buf_dst.push_back('e'); + buf_dst.push_back('l'); + buf_dst.push_back('l'); + buf_dst.push_back('o'); + buf_dst.push_back('\0'); + + auto buf = buf_dst.data(); + auto sz = buf_dst.size(); + + sock.write_from_buffer(buf, sz); + + ocl::unique_socket sock2 = ocl::unique_socket::make_socket<8000>(ocl::unique_socket::any_address, false); + + auto accepeted = sock.accept(); + accepeted.write_from_buffer(buf, sz); + + std::vector buf_dst2(512); + + buf = buf_dst2.data(); + sz = buf_dst2.size(); + + sock2.read_client_buffer(buf, sz); + + EXPECT_TRUE(!sock.bad()); + EXPECT_TRUE(!sock2.bad()); +} + +TEST(NetworkTest, BasicNetworkMakeSocket) +{ + auto socket = ocl::unique_socket::make_socket<8000>(ocl::unique_socket::any_address, true); + EXPECT_TRUE(!socket.bad()); +} \ No newline at end of file diff --git a/tests/network_basic/CMakeLists.txt b/tests/network_basic/CMakeLists.txt deleted file mode 100644 index 267b584..0000000 --- a/tests/network_basic/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -cmake_minimum_required(VERSION 3.27) -project(NetworkTestBasic LANGUAGES CXX) - -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 network_basic_test.cc) -target_link_libraries(NetworkTestBasic gtest_main) - -set_property(TARGET NetworkTestBasic PROPERTY CXX_STANDARD 20) -target_include_directories(NetworkTestBasic PUBLIC ../../include/) - -include(GoogleTest) -gtest_discover_tests(NetworkTestBasic) diff --git a/tests/network_basic/network_basic_test.cc b/tests/network_basic/network_basic_test.cc deleted file mode 100644 index 21a6668..0000000 --- a/tests/network_basic/network_basic_test.cc +++ /dev/null @@ -1,51 +0,0 @@ -/* - * File: tests/net_test.cc - * Purpose: Network unit tests in C++ - * Author: Amlal El Mahrouss (amlal@nekernel.org) - * Copyright 2025, Amlal El Mahrouss, licensed under the Boost Software License. - */ - -#include -#include -#include - -/// @brief Basic Send test -TEST(NetworkTest, BasicNetworkIO) -{ - ocl::unique_socket sock = ocl::unique_socket::make_socket<8000>(ocl::unique_socket::any_address, true); - - std::vector buf_dst(512); - - buf_dst.push_back('H'); - buf_dst.push_back('e'); - buf_dst.push_back('l'); - buf_dst.push_back('l'); - buf_dst.push_back('o'); - buf_dst.push_back('\0'); - - auto buf = buf_dst.data(); - auto sz = buf_dst.size(); - - sock.write_from_buffer(buf, sz); - - ocl::unique_socket sock2 = ocl::unique_socket::make_socket<8000>(ocl::unique_socket::any_address, false); - - auto accepeted = sock.accept(); - accepeted.write_from_buffer(buf, sz); - - std::vector buf_dst2(512); - - buf = buf_dst2.data(); - sz = buf_dst2.size(); - - sock2.read_client_buffer(buf, sz); - - EXPECT_TRUE(!sock.bad()); - EXPECT_TRUE(!sock2.bad()); -} - -TEST(NetworkTest, BasicNetworkMakeSocket) -{ - auto socket = ocl::unique_socket::make_socket<8000>(ocl::unique_socket::any_address, true); - EXPECT_TRUE(!socket.bad()); -} \ No newline at end of file -- cgit v1.2.3