From 3349cea2898c9c6f2ab13b5c18b2fcfcb2351120 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Thu, 15 Jan 2026 10:46:38 -0500 Subject: [PATCH] xo-object2: + StringOps + utest --- xo-object2/include/xo/object2/StringOps.hpp | 36 ++++++++++++++ xo-object2/utest/CMakeLists.txt | 1 + xo-object2/utest/DString.test.cpp | 2 +- xo-object2/utest/StringOps.test.cpp | 54 +++++++++++++++++++++ 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 xo-object2/include/xo/object2/StringOps.hpp create mode 100644 xo-object2/utest/StringOps.test.cpp diff --git a/xo-object2/include/xo/object2/StringOps.hpp b/xo-object2/include/xo/object2/StringOps.hpp new file mode 100644 index 00000000..3cc71988 --- /dev/null +++ b/xo-object2/include/xo/object2/StringOps.hpp @@ -0,0 +1,36 @@ +/** @file StringOps.hpp +* + * @author Roland Conybeare, Jan 2026 + **/ + +#pragma once + +#include "string/IGCObject_DString.hpp" +#include "DString.hpp" + +namespace xo { + namespace scm { + /** @brief string functions + * + * note: separate from DString + **/ + struct StringOps { + using AGCObject = xo::mm::AGCObject; + using AAllocator = xo::mm::AAllocator; + using size_type = DString::size_type; + + template + static obj empty(obj mm, + size_type cap); + }; + + template + obj + StringOps::empty(obj mm, size_type cap) + { + return obj(DString::empty(mm, cap)); + } + } +} + +/* end StringOps.hpp */ diff --git a/xo-object2/utest/CMakeLists.txt b/xo-object2/utest/CMakeLists.txt index a681e52c..7207b7db 100644 --- a/xo-object2/utest/CMakeLists.txt +++ b/xo-object2/utest/CMakeLists.txt @@ -4,6 +4,7 @@ set(UTEST_EXE utest.object2) set(UTEST_SRCS object2_utest_main.cpp DString.test.cpp + StringOps.test.cpp X1Collector.test.cpp Printable.test.cpp ) diff --git a/xo-object2/utest/DString.test.cpp b/xo-object2/utest/DString.test.cpp index 213f5023..226d63c8 100644 --- a/xo-object2/utest/DString.test.cpp +++ b/xo-object2/utest/DString.test.cpp @@ -3,7 +3,7 @@ * @author Roland Conybeare, Jan 2026 **/ -#include +#include #include #include #include diff --git a/xo-object2/utest/StringOps.test.cpp b/xo-object2/utest/StringOps.test.cpp new file mode 100644 index 00000000..60069b53 --- /dev/null +++ b/xo-object2/utest/StringOps.test.cpp @@ -0,0 +1,54 @@ +/** @file StringOps.test.cpp + * + * @author Roland Conybeare, Jan 2026 + **/ + +#include +#include +#include +#include + +namespace xo { + using xo::scm::StringOps; + using xo::scm::DString; + using xo::mm::AAllocator; + using xo::mm::AGCObject; + using xo::mm::DArena; + using xo::mm::ArenaConfig; + using xo::facet::with_facet; + using xo::facet::obj; + + namespace ut { + TEST_CASE("StringOps-empty", "[object2][StringOps]") + { + ArenaConfig cfg { .name_ = "testarena", + .size_ = 4*1024 }; + DArena arena = DArena::map(cfg); + auto alloc = with_facet::mkobj(&arena); + + obj s = StringOps::empty(alloc, 16); + + REQUIRE(s.data() != nullptr); + REQUIRE(s.data()->capacity() == 16); + REQUIRE(s.data()->size() == 0); + REQUIRE(s.data()->chars()[0] == '\0'); + } + + TEST_CASE("StringOps-empty-with-content", "[object2][StringOps]") + { + ArenaConfig cfg { .name_ = "testarena", + .size_ = 4*1024 }; + DArena arena = DArena::map(cfg); + auto alloc = with_facet::mkobj(&arena); + + obj s = StringOps::empty(alloc, 32); + + s.data()->sprintf("hello %s %d", "world", 42); + + REQUIRE(s.data()->size() == 14); + REQUIRE(std::strcmp(s.data()->chars(), "hello world 42") == 0); + } + } /*namespace ut*/ +} /*namespace xo*/ + +/* end StringOps.test.cpp */