xo-object2: + StringOps.clone + utest
This commit is contained in:
parent
b628dbd187
commit
ede658219c
2 changed files with 32 additions and 0 deletions
|
|
@ -19,13 +19,21 @@ namespace xo {
|
||||||
using AAllocator = xo::mm::AAllocator;
|
using AAllocator = xo::mm::AAllocator;
|
||||||
using size_type = DString::size_type;
|
using size_type = DString::size_type;
|
||||||
|
|
||||||
|
/** wrapper for DString.empty() **/
|
||||||
template <typename AFacet = AGCObject>
|
template <typename AFacet = AGCObject>
|
||||||
static obj<AFacet,DString> empty(obj<AAllocator> mm,
|
static obj<AFacet,DString> empty(obj<AAllocator> mm,
|
||||||
size_type cap);
|
size_type cap);
|
||||||
|
|
||||||
|
/** wrapper for DString.from_cstr() **/
|
||||||
template <typename AFacet = AGCObject>
|
template <typename AFacet = AGCObject>
|
||||||
static obj<AFacet,DString> from_cstr(obj<AAllocator> mm,
|
static obj<AFacet,DString> from_cstr(obj<AAllocator> mm,
|
||||||
const char * cstr);
|
const char * cstr);
|
||||||
|
|
||||||
|
/** wrapper for DString.clone() **/
|
||||||
|
template <typename AFacet = AGCObject,
|
||||||
|
typename ASrcFacet = AGCObject>
|
||||||
|
static obj<AFacet,DString> clone(obj<AAllocator> mm,
|
||||||
|
obj<ASrcFacet,DString> src);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename AFacet>
|
template <typename AFacet>
|
||||||
|
|
@ -41,6 +49,13 @@ namespace xo {
|
||||||
{
|
{
|
||||||
return obj<AFacet,DString>(DString::from_cstr(mm, cstr));
|
return obj<AFacet,DString>(DString::from_cstr(mm, cstr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename AFacet, typename ASrcFacet>
|
||||||
|
obj<AFacet,DString>
|
||||||
|
StringOps::clone(obj<AAllocator> mm, obj<ASrcFacet,DString> src)
|
||||||
|
{
|
||||||
|
return obj<AFacet,DString>(DString::clone(mm, src.data()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,23 @@ namespace xo {
|
||||||
REQUIRE(s.data()->size() == 11);
|
REQUIRE(s.data()->size() == 11);
|
||||||
REQUIRE(std::strcmp(s.data()->chars(), cstr) == 0);
|
REQUIRE(std::strcmp(s.data()->chars(), cstr) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("StringOps-clone", "[object2][StringOps]")
|
||||||
|
{
|
||||||
|
ArenaConfig cfg { .name_ = "testarena",
|
||||||
|
.size_ = 4*1024 };
|
||||||
|
DArena arena = DArena::map(cfg);
|
||||||
|
auto alloc = with_facet<AAllocator>::mkobj(&arena);
|
||||||
|
|
||||||
|
auto src = StringOps::from_cstr(alloc, "hello world");
|
||||||
|
auto copy = StringOps::clone(alloc, src);
|
||||||
|
|
||||||
|
REQUIRE(copy.data() != nullptr);
|
||||||
|
REQUIRE(copy.data() != src.data());
|
||||||
|
REQUIRE(copy.data()->size() == src.data()->size());
|
||||||
|
REQUIRE(copy.data()->capacity() == src.data()->capacity());
|
||||||
|
REQUIRE(std::strcmp(copy.data()->chars(), src.data()->chars()) == 0);
|
||||||
|
}
|
||||||
} /*namespace ut*/
|
} /*namespace ut*/
|
||||||
} /*namespace xo*/
|
} /*namespace xo*/
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue