xo-object2: + StringOps::from_cstr + utest

This commit is contained in:
Roland Conybeare 2026-01-15 11:17:55 -05:00
commit cb56e1ed26
2 changed files with 29 additions and 2 deletions

View file

@ -26,7 +26,7 @@ namespace xo {
DArena arena = DArena::map(cfg);
auto alloc = with_facet<AAllocator>::mkobj(&arena);
obj<AGCObject, DString> s = StringOps::empty(alloc, 16);
auto s = StringOps::empty(alloc, 16);
REQUIRE(s.data() != nullptr);
REQUIRE(s.data()->capacity() == 16);
@ -41,13 +41,29 @@ namespace xo {
DArena arena = DArena::map(cfg);
auto alloc = with_facet<AAllocator>::mkobj(&arena);
obj<AGCObject, DString> s = StringOps::empty(alloc, 32);
auto 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);
}
TEST_CASE("StringOps-from_cstr", "[object2][StringOps]")
{
ArenaConfig cfg { .name_ = "testarena",
.size_ = 4*1024 };
DArena arena = DArena::map(cfg);
auto alloc = with_facet<AAllocator>::mkobj(&arena);
const char * cstr = "hello world";
auto s = StringOps::from_cstr(alloc, cstr);
REQUIRE(s.data() != nullptr);
REQUIRE(s.data()->capacity() == 12);
REQUIRE(s.data()->size() == 11);
REQUIRE(std::strcmp(s.data()->chars(), cstr) == 0);
}
} /*namespace ut*/
} /*namespace xo*/