From 66e2b07ce574b5c4c4cb12b8d16286c6f8e41443 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 6 Aug 2025 09:32:09 -0500 Subject: [PATCH] xo-alloc xo-object; + utests --- xo-alloc/utest/IAlloc.test.cpp | 29 ++++++++++++++++++++ xo-object/utest/Boolean.test.cpp | 46 ++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 xo-alloc/utest/IAlloc.test.cpp create mode 100644 xo-object/utest/Boolean.test.cpp diff --git a/xo-alloc/utest/IAlloc.test.cpp b/xo-alloc/utest/IAlloc.test.cpp new file mode 100644 index 00000000..b0214749 --- /dev/null +++ b/xo-alloc/utest/IAlloc.test.cpp @@ -0,0 +1,29 @@ +/* @file IAlloc.test.cpp + * + * author: Roland Conybeare, Aug 2025 + */ + +#include "xo/alloc/IAlloc.hpp" +#include + +namespace xo { + using xo::gc::IAlloc; + + namespace ut { + TEST_CASE("ialloc", "[alloc]") + { + REQUIRE(IAlloc::alloc_padding(0) == 0); + REQUIRE(IAlloc::alloc_padding(1) == 7); + REQUIRE(IAlloc::alloc_padding(2) == 6); + REQUIRE(IAlloc::alloc_padding(3) == 5); + REQUIRE(IAlloc::alloc_padding(4) == 4); + REQUIRE(IAlloc::alloc_padding(5) == 3); + REQUIRE(IAlloc::alloc_padding(6) == 2); + REQUIRE(IAlloc::alloc_padding(7) == 1); + REQUIRE(IAlloc::alloc_padding(8) == 0); + REQUIRE(IAlloc::alloc_padding(9) == 7); + } + } /*namespace ut*/ +} /*namespace xo*/ + +/* end IAlloc.test.cpp */ diff --git a/xo-object/utest/Boolean.test.cpp b/xo-object/utest/Boolean.test.cpp new file mode 100644 index 00000000..601de00e --- /dev/null +++ b/xo-object/utest/Boolean.test.cpp @@ -0,0 +1,46 @@ +/* @file Boolean.test.cpp + * + * author: Roland Conybeare, Aug 2025 + */ + +#include "xo/object/Boolean.hpp" +#include "xo/alloc/GC.hpp" +#include + +namespace xo { + using xo::obj::Boolean; + using xo::gc::GC; + using xo::gc::generation_result; + + namespace ut { + TEST_CASE("Boolean", "[Boolean]") + { + up gc = GC::make( + { .initial_nursery_z_ = 1024, + .initial_tenured_z_ = 1024 + }); + + REQUIRE(gc.get()); + + /* use gc for "all" Object allocs. + * Not using, but want it to be available, verify conscious choice + */ + Object::mm = gc.get(); + + gp btrue = Boolean::true_obj(); + gp bfalse = Boolean::false_obj(); + + REQUIRE(btrue.ptr()); + REQUIRE(btrue->value() == true); + + REQUIRE(bfalse.ptr()); + REQUIRE(bfalse->value() == false); + + REQUIRE(btrue->_shallow_size() == sizeof(Boolean)); + + // booleans are global constants + REQUIRE(gc->tospace_generation_of(btrue.ptr()) == generation_result::not_found); + REQUIRE(gc->tospace_generation_of(bfalse.ptr()) == generation_result::not_found); + } + } /*namespace ut*/ +} /*namespace xo*/