summaryrefslogtreecommitdiffhomepage
path: root/tests/chunk_string
diff options
context:
space:
mode:
Diffstat (limited to 'tests/chunk_string')
-rw-r--r--tests/chunk_string/CMakeLists.txt25
-rw-r--r--tests/chunk_string/chunk_test.cc31
2 files changed, 56 insertions, 0 deletions
diff --git a/tests/chunk_string/CMakeLists.txt b/tests/chunk_string/CMakeLists.txt
new file mode 100644
index 0000000..53a9add
--- /dev/null
+++ b/tests/chunk_string/CMakeLists.txt
@@ -0,0 +1,25 @@
+cmake_minimum_required(VERSION 3.27)
+project(BasicChunkUsage LANGUAGES CXX)
+
+# find_package(Boost REQUIRED COMPONENTS container)
+
+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(BasicChunkUsage chunk_test.cc)
+target_link_libraries(BasicChunkUsage PRIVATE gtest_main)
+
+set_property(TARGET BasicChunkUsage PROPERTY CXX_STANDARD 20)
+target_include_directories(BasicChunkUsage PUBLIC ../../include/ocl)
+
+include(GoogleTest)
+gtest_discover_tests(BasicChunkUsage)
diff --git a/tests/chunk_string/chunk_test.cc b/tests/chunk_string/chunk_test.cc
new file mode 100644
index 0000000..6b2d290
--- /dev/null
+++ b/tests/chunk_string/chunk_test.cc
@@ -0,0 +1,31 @@
+/*
+ * File: tests/chunk_test.cc
+ * Purpose: Chunk unit tests in C++
+ * Author: Amlal El Mahrouss (amlal@nekernel.org)
+ * Copyright 2025, Amlal El Mahrouss, licensed under the Boost Software License.
+ */
+
+#include <io/print.hpp>
+#include <tests/gtest.hpp>
+#include <core/chunk_string.hpp>
+
+TEST(ChunkTest, BasicChunkUsage)
+{
+ const char* test_string = "HELLO, WORLD!\r\n";
+ const auto iterations = 1024000;
+ const auto limit = 30;
+
+ auto start = std::chrono::high_resolution_clock::now();
+
+ ocl::basic_chunk_string<char, iterations> optimized;
+
+ for (unsigned i = 0; i < iterations; ++i)
+ {
+ optimized += test_string;
+ }
+
+ auto end = std::chrono::high_resolution_clock::now();
+ auto optimized_time = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
+
+ EXPECT_TRUE(optimized_time.count() < 100U);
+}