xo-procedure2: + DSimpleRcx utest

This commit is contained in:
Roland Conybeare 2026-01-26 16:56:35 -05:00
commit df86cef2b1
3 changed files with 63 additions and 0 deletions

View file

@ -3,6 +3,8 @@
* @author Roland Conybeare, Jan 2026
**/
#pragma once
#include <xo/alloc2/Allocator.hpp>
namespace xo {

View file

@ -4,6 +4,7 @@ set(UTEST_EXE utest.procedure2)
set(UTEST_SRCS
procedure2_utest_main.cpp
DPrimitive.test.cpp
DSimpleRcx.test.cpp
)
xo_add_utest_executable(${UTEST_EXE} ${UTEST_SRCS})

60
utest/DSimpleRcx.test.cpp Normal file
View file

@ -0,0 +1,60 @@
/** @file DSimpleRcx.test.cpp
*
* @author Roland Conybeare, Jan 2026
**/
#include <xo/procedure2/init_procedure2.hpp>
#include <xo/procedure2/DSimpleRcx.hpp>
#include <xo/procedure2/detail/IRuntimeContext_DSimpleRcx.hpp>
#include <xo/alloc2/arena/IAllocator_DArena.hpp>
#include <catch2/catch.hpp>
namespace xo {
using xo::scm::DSimpleRcx;
using xo::scm::ARuntimeContext;
using xo::mm::AAllocator;
using xo::mm::DArena;
using xo::mm::ArenaConfig;
using xo::facet::with_facet;
using xo::facet::obj;
namespace ut {
static InitEvidence s_init = InitSubsys<S_procedure2_tag>::require();
TEST_CASE("DSimpleRcx-init", "[procedure2][DSimpleRcx]")
{
REQUIRE(s_init.evidence());
}
TEST_CASE("DSimpleRcx-construct", "[procedure2][DSimpleRcx]")
{
ArenaConfig cfg { .name_ = "testarena",
.size_ = 4*1024 };
DArena arena = DArena::map(cfg);
auto alloc = with_facet<AAllocator>::mkobj(&arena);
DSimpleRcx rcx(alloc);
REQUIRE((void*)rcx.allocator().data() == (void*)alloc.data());
}
TEST_CASE("DSimpleRcx-as-ARuntimeContext", "[procedure2][DSimpleRcx]")
{
ArenaConfig cfg { .name_ = "testarena",
.size_ = 4*1024 };
DArena arena = DArena::map(cfg);
auto alloc = with_facet<AAllocator>::mkobj(&arena);
DSimpleRcx rcx(alloc);
obj<ARuntimeContext> rcx_obj = with_facet<ARuntimeContext>::mkobj(&rcx);
// verify we can recover allocator from obj<ARuntimeContext>
obj<AAllocator> recovered_alloc = rcx_obj.allocator();
REQUIRE((void*)recovered_alloc.data() == (void*)alloc.data());
}
} /*namespace ut*/
} /*namespace xo*/
/* end DSimpleRcx.test.cpp */