|
8 | 8 | using namespace test_utils; |
9 | 9 | using namespace rtl; |
10 | 10 |
|
| 11 | +namespace { |
| 12 | + |
| 13 | + // Cloning is only available for types explicitly registered by the user. |
| 14 | + // This is because cloning requires a lambda to be stored in a static table. |
| 15 | + // Types reflected via rtl::reflect or obtained as the return value of a reflective call |
| 16 | + // cannot be cloned unless they are explicitly registered. |
| 17 | + |
| 18 | + static rtl::CxxMirror cxx_mirror() |
| 19 | + { |
| 20 | + static rtl::CxxMirror m = rtl::CxxMirror({ |
| 21 | + rtl::type().record<int>("int").build(), |
| 22 | + rtl::type().record<Node>("Node").build() |
| 23 | + }); |
| 24 | + return m; |
| 25 | + } |
| 26 | +} |
| 27 | + |
11 | 28 | namespace rtl::unit_test |
12 | 29 | { |
13 | 30 | TEST(RObject_reflecting_shared_ptr, sharing_semantics__pod) |
@@ -101,6 +118,10 @@ namespace rtl::unit_test |
101 | 118 | { |
102 | 119 | constexpr const int NUM = -20438; |
103 | 120 | RObject robj = reflect(std::make_shared<int>(NUM)); |
| 121 | + |
| 122 | + error reterr = cxx_mirror().enableCloning(robj); |
| 123 | + ASSERT_TRUE(reterr == error::None); |
| 124 | + |
104 | 125 | ASSERT_FALSE(robj.isEmpty()); |
105 | 126 |
|
106 | 127 | // --- Step 1: Clone by default (entity::Auto semantics) --- |
@@ -193,6 +214,9 @@ namespace rtl::unit_test |
193 | 214 | RObject robj = reflect(std::make_shared<int>(NUM)); |
194 | 215 | ASSERT_FALSE(robj.isEmpty()); |
195 | 216 |
|
| 217 | + error reterr = cxx_mirror().enableCloning(robj); |
| 218 | + ASSERT_TRUE(reterr == error::None); |
| 219 | + |
196 | 220 | // --- Step 1: Clone by default (entity::Auto semantics) --- |
197 | 221 | { |
198 | 222 | // Default cloning shallow-copies the wrapper. |
@@ -247,6 +271,9 @@ namespace rtl::unit_test |
247 | 271 | ASSERT_FALSE(robj.isEmpty()); |
248 | 272 | ASSERT_TRUE(Node::instanceCount() == 1); |
249 | 273 |
|
| 274 | + error reterr = cxx_mirror().enableCloning(robj); |
| 275 | + ASSERT_TRUE(reterr == error::None); |
| 276 | + |
250 | 277 | // --- Step 2: Clone by default (entity::Auto semantics) --- |
251 | 278 | { |
252 | 279 | // Default cloning shallow-copies the wrapper. |
@@ -326,6 +353,10 @@ namespace rtl::unit_test |
326 | 353 | { |
327 | 354 | constexpr const int NUM = 241054; |
328 | 355 | RObject robj = reflect(std::make_shared<Node>(NUM)); |
| 356 | + |
| 357 | + error reterr = cxx_mirror().enableCloning(robj); |
| 358 | + ASSERT_TRUE(reterr == error::None); |
| 359 | + |
329 | 360 | ASSERT_FALSE(robj.isEmpty()); |
330 | 361 | ASSERT_TRUE(Node::instanceCount() == 1); |
331 | 362 |
|
@@ -568,6 +599,9 @@ namespace rtl::unit_test |
568 | 599 | constexpr const int NUM = 10742; |
569 | 600 | RObject robj = reflect(std::make_shared<Node>(NUM)); |
570 | 601 |
|
| 602 | + error reterr = cxx_mirror().enableCloning(robj); |
| 603 | + ASSERT_TRUE(reterr == error::None); |
| 604 | + |
571 | 605 | ASSERT_FALSE(robj.isEmpty()); |
572 | 606 | EXPECT_TRUE(robj.canViewAs<std::shared_ptr<Node>>()); |
573 | 607 |
|
|
0 commit comments