@@ -169,24 +169,26 @@ static void TestMove(nlTestSuite * inSuite, void * inContext)
169
169
CtorDtorCounter::ResetCounter ();
170
170
171
171
{
172
- auto testSrc = MakeNullable<MovableCtorDtorCounter>(400 );
173
- Nullable<MovableCtorDtorCounter> testDst (std::move (testSrc));
174
- NL_TEST_ASSERT (inSuite, CtorDtorCounter::created == 2 && CtorDtorCounter::destroyed == 1 );
172
+ auto testSrc = MakeNullable<MovableCtorDtorCounter>(400 ); // contstruct
173
+ Nullable<MovableCtorDtorCounter> testDst (std::move (testSrc)); // move construct
174
+ NL_TEST_ASSERT (inSuite, CtorDtorCounter::created == 2 && CtorDtorCounter::destroyed == 0 );
175
175
NL_TEST_ASSERT (inSuite, !testDst.IsNull () && testDst.Value ().m == 400 );
176
+ // destroy both testsSrc and testDst
176
177
}
177
178
NL_TEST_ASSERT (inSuite, CtorDtorCounter::created == 2 && CtorDtorCounter::destroyed == 2 );
178
179
180
+ CtorDtorCounter::ResetCounter ();
179
181
{
180
- Nullable<MovableCtorDtorCounter> testDst;
181
- NL_TEST_ASSERT (inSuite, CtorDtorCounter::created == 2 && CtorDtorCounter::destroyed == 2 );
182
+ Nullable<MovableCtorDtorCounter> testDst; // no object construction
183
+ NL_TEST_ASSERT (inSuite, CtorDtorCounter::created == 0 && CtorDtorCounter::destroyed == 0 );
182
184
NL_TEST_ASSERT (inSuite, !!testDst.IsNull ());
183
185
184
- auto testSrc = MakeNullable<MovableCtorDtorCounter>(401 );
185
- testDst = std::move (testSrc);
186
- NL_TEST_ASSERT (inSuite, CtorDtorCounter::created == 4 && CtorDtorCounter::destroyed == 3 );
186
+ auto testSrc = MakeNullable<MovableCtorDtorCounter>(401 ); // construct object
187
+ testDst = std::move (testSrc); // construct a copy
188
+ NL_TEST_ASSERT (inSuite, CtorDtorCounter::created == 2 && CtorDtorCounter::destroyed == 0 );
187
189
NL_TEST_ASSERT (inSuite, !testDst.IsNull () && testDst.Value ().m == 401 );
188
190
}
189
- NL_TEST_ASSERT (inSuite, CtorDtorCounter::created == 4 && CtorDtorCounter::destroyed == 4 );
191
+ NL_TEST_ASSERT (inSuite, CtorDtorCounter::created == 2 && CtorDtorCounter::destroyed == 2 );
190
192
}
191
193
192
194
static void TestUpdate (nlTestSuite * inSuite, void * inContext)
0 commit comments