Skip to content

Commit 93e5331

Browse files
committed
Fix test: previous code was enforcing chip::optional behavior on in-place construction
1 parent 39c351f commit 93e5331

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/app/tests/TestNullable.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -169,24 +169,26 @@ static void TestMove(nlTestSuite * inSuite, void * inContext)
169169
CtorDtorCounter::ResetCounter();
170170

171171
{
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);
175175
NL_TEST_ASSERT(inSuite, !testDst.IsNull() && testDst.Value().m == 400);
176+
// destroy both testsSrc and testDst
176177
}
177178
NL_TEST_ASSERT(inSuite, CtorDtorCounter::created == 2 && CtorDtorCounter::destroyed == 2);
178179

180+
CtorDtorCounter::ResetCounter();
179181
{
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);
182184
NL_TEST_ASSERT(inSuite, !!testDst.IsNull());
183185

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);
187189
NL_TEST_ASSERT(inSuite, !testDst.IsNull() && testDst.Value().m == 401);
188190
}
189-
NL_TEST_ASSERT(inSuite, CtorDtorCounter::created == 4 && CtorDtorCounter::destroyed == 4);
191+
NL_TEST_ASSERT(inSuite, CtorDtorCounter::created == 2 && CtorDtorCounter::destroyed == 2);
190192
}
191193

192194
static void TestUpdate(nlTestSuite * inSuite, void * inContext)

0 commit comments

Comments
 (0)