xo-object2: + StringOps + utest
This commit is contained in:
parent
f02e550f8c
commit
3349cea289
4 changed files with 92 additions and 1 deletions
54
xo-object2/utest/StringOps.test.cpp
Normal file
54
xo-object2/utest/StringOps.test.cpp
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/** @file StringOps.test.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#include <xo/object2/StringOps.hpp>
|
||||
#include <xo/alloc2/arena/IAllocator_DArena.hpp>
|
||||
#include <catch2/catch.hpp>
|
||||
#include <cstring>
|
||||
|
||||
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<AAllocator>::mkobj(&arena);
|
||||
|
||||
obj<AGCObject, DString> 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<AAllocator>::mkobj(&arena);
|
||||
|
||||
obj<AGCObject, DString> 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 */
|
||||
Loading…
Add table
Add a link
Reference in a new issue