From 47273edf6e5016e1fcdccce5c4eca862e05104c1 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 23 Feb 2026 23:01:56 -0500 Subject: [PATCH] Test construction from raw pointers --- test/tests.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/test/tests.cpp b/test/tests.cpp index 90a29f3..fe0298e 100644 --- a/test/tests.cpp +++ b/test/tests.cpp @@ -1,5 +1,6 @@ #include #include +#include static int mybase_construct; static int mybase_destruct; @@ -48,7 +49,7 @@ public: double v; }; -void test_destructors_called() +void test_class_hierarchy() { { rcp mybase = MyBase::create(4, 5); @@ -84,11 +85,46 @@ void test_create() assert(myb->x == 8); } +struct MyObj +{ + rcp_managed_root(MyObj); +public: + int v = {42}; + template + void add_to(R & receiver) + { + receiver.add(this); + } +}; +struct Receiver +{ + std::vector> objects; + void add(MyObj * o) + { + objects.push_back(rcp(o)); + } +}; + +void test_multi_construct_from_raw_pointers() +{ + Receiver r; + auto myo = MyObj::create(); + for (size_t i = 0u; i < 5u; i++) + { + myo->add_to(r); + } + for (size_t i = 0u; i < 5u; i++) + { + assert(r.objects[i]->v == 42); + } +} + int main(int argc, char * argv[]) { - test_destructors_called(); + test_class_hierarchy(); test_dereference(); test_booleans(); test_create(); + test_multi_construct_from_raw_pointers(); return 0; }