xo-alloc xo-object; + utests

This commit is contained in:
Roland Conybeare 2025-08-06 09:32:09 -05:00
commit 66e2b07ce5
2 changed files with 75 additions and 0 deletions

View file

@ -0,0 +1,29 @@
/* @file IAlloc.test.cpp
*
* author: Roland Conybeare, Aug 2025
*/
#include "xo/alloc/IAlloc.hpp"
#include <catch2/catch.hpp>
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 */

View file

@ -0,0 +1,46 @@
/* @file Boolean.test.cpp
*
* author: Roland Conybeare, Aug 2025
*/
#include "xo/object/Boolean.hpp"
#include "xo/alloc/GC.hpp"
#include <catch2/catch.hpp>
namespace xo {
using xo::obj::Boolean;
using xo::gc::GC;
using xo::gc::generation_result;
namespace ut {
TEST_CASE("Boolean", "[Boolean]")
{
up<GC> 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<Boolean> btrue = Boolean::true_obj();
gp<Boolean> 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*/