Skip to content

Commit 6920fd0

Browse files
authored
Merge pull request #76 from ReflectCxx/develop
updated move-constructor tests.
2 parents 0e87b55 + 620b312 commit 6920fd0

File tree

6 files changed

+48
-2
lines changed

6 files changed

+48
-2
lines changed

CxxRTLTestApplication/src/FunctionalityTests/MoveConstructorTests.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ namespace rtl_tests
3333
// 'Event' has a unique_ptr<Date> and two 'Event' instances exists, So-
3434
EXPECT_TRUE(date::get_instance_count() == 2);
3535

36+
// Sets Calender's move operation counter to zero
37+
calender::reset_move_ops_counter();
38+
3639
// Moving a RObject created via alloc::Stack, invokes Calender's move constructor.
3740
RObject calender1 = std::move(calender0);
41+
42+
// Calender's move-constructor called once.
43+
EXPECT_TRUE(calender::get_move_ops_count() == 1);
3844

3945
ASSERT_FALSE(calender1.isEmpty());
4046
EXPECT_TRUE(calender1.isConstCastSafe());
@@ -91,10 +97,16 @@ namespace rtl_tests
9197
// 'Event' has a unique_ptr<Date> and two 'Event' instances exists, So-
9298
EXPECT_TRUE(date::get_instance_count() == 2);
9399

100+
// Sets Calender's move operation counter to zero
101+
calender::reset_move_ops_counter();
102+
94103
// RObject created via alloc::HEAP, contains pointer to reflected type internally, So just the
95104
// address wrapped in std::any inside Robject is moved. Calender's move constructor is not called.
96105
RObject calender1 = std::move(calender0);
97106

107+
// Calender's move constructor isn't called.
108+
EXPECT_TRUE(calender::get_move_ops_count() == 0);
109+
98110
ASSERT_FALSE(calender1.isEmpty());
99111
EXPECT_TRUE(calender1.isConstCastSafe());
100112
EXPECT_TRUE(calender1.isOnHeap());
@@ -228,9 +240,15 @@ namespace rtl_tests
228240
// 'Event' has a unique_ptr<Date> and two 'Event' instances exists, So-
229241
EXPECT_TRUE(date::get_instance_count() == 2);
230242

243+
// Sets Calender's move operation counter to zero
244+
calender::reset_move_ops_counter();
245+
231246
// Moving a RObject created via alloc::Stack, invokes Calender's move constructor.
232247
RObject calender1 = std::move(calender0);
233248

249+
// Calender's move-constructor called once.
250+
EXPECT_TRUE(calender::get_move_ops_count() == 1);
251+
234252
ASSERT_FALSE(calender1.isEmpty());
235253
EXPECT_TRUE(calender1.isConstCastSafe());
236254
EXPECT_FALSE(calender1.isOnHeap());

CxxRTLTypeRegistration/src/TestMirrorProvider.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ namespace test_mirror
242242
static const auto _ = [&]()
243243
{
244244
const std::string pathStr = std::filesystem::current_path().string() + "/MyReflection.json";
245-
std::cout << "\n[ OUTPUT] test_mirror::cxx::mirror()==> dumping metadata as JSON."
246-
<< "\n file path: " << pathStr << std::endl;
245+
std::cout << "\n[ OUTPUT] test_mirror::cxx::mirror() ==> dumping 'CxxMirror' as JSON."
246+
<< "\n file path: " << pathStr << "\n" << std::endl;
247247
rtl::CxxMirrorToJson::dump(cxx_mirror, pathStr);
248248
return 0;
249249
}();

CxxTestProps/inc/Date.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ namespace nsdate
5454
const Event& getTheEvent();
5555
const Event& getSavedEvent();
5656

57+
static void resetMoveOpsCounter();
5758
static std::size_t instanceCount();
59+
static std::size_t getMoveOpsCount();
5860

5961
static Calender create();
6062

@@ -65,6 +67,8 @@ namespace nsdate
6567
std::unique_ptr<Event> m_savedEvent;
6668

6769
static std::size_t m_instanceCount;
70+
71+
static std::size_t m_moveOpsCount;
6872
};
6973

7074

CxxTestProps/src/Date.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace nsdate
1010
std::size_t Date::m_instanceCount = 0;
1111
std::size_t Event::m_instanceCount = 0;
1212
std::size_t Calender::m_instanceCount = 0;
13+
std::size_t Calender::m_moveOpsCount = 0;
1314

1415
Calender::~Calender()
1516
{
@@ -34,6 +35,7 @@ namespace nsdate
3435
: m_theEvent(std::move(pOther.m_theEvent))
3536
, m_savedEvent(std::move(pOther.m_savedEvent))
3637
{
38+
m_moveOpsCount++;
3739
m_instanceCount++;
3840
}
3941

@@ -66,6 +68,16 @@ namespace nsdate
6668
{
6769
return m_instanceCount;
6870
}
71+
72+
std::size_t Calender::getMoveOpsCount()
73+
{
74+
return m_moveOpsCount;
75+
}
76+
77+
void Calender::resetMoveOpsCounter()
78+
{
79+
m_moveOpsCount = 0;
80+
}
6981
}
7082

7183
namespace nsdate

CxxTestUtils/inc/TestUtilsDate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ namespace test_utils
3434
static constexpr const char* str_getTheEvent = "getTheEvent";
3535
static constexpr const char* str_getSavedEvent = "getSavedEvent";
3636

37+
static void reset_move_ops_counter();
3738
static const bool assert_zero_instance_count();
3839
static const std::size_t get_instance_count();
40+
static const std::size_t get_move_ops_count();
3941
};
4042

4143
struct date

CxxTestUtils/src/TestUtilsDate.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ namespace test_utils
2020
return Calender::instanceCount();
2121
}
2222

23+
void calender::reset_move_ops_counter()
24+
{
25+
Calender::resetMoveOpsCounter();
26+
}
27+
28+
const std::size_t calender::get_move_ops_count()
29+
{
30+
return Calender::getMoveOpsCount();
31+
}
32+
2333
const bool event::assert_zero_instance_count()
2434
{
2535
return (Event::instanceCount() == 0);

0 commit comments

Comments
 (0)