From db7c41065d50b2ddb7a1522ad0e38c36e6db17e8 Mon Sep 17 00:00:00 2001 From: AYA Date: Wed, 29 May 2024 11:20:20 +0200 Subject: [PATCH] adding more tests --- src/app/tests/BUILD.gn | 14 +- src/app/tests/TestDefaultICDClientStorage.cpp | 162 ++++++------------ src/app/tests/TestPendingNotificationMap.cpp | 90 +++++----- .../tests/TestPendingResponseTrackerImpl.cpp | 84 ++++----- 4 files changed, 134 insertions(+), 216 deletions(-) diff --git a/src/app/tests/BUILD.gn b/src/app/tests/BUILD.gn index c1973be185cbac..44cdf8594e6c76 100644 --- a/src/app/tests/BUILD.gn +++ b/src/app/tests/BUILD.gn @@ -143,6 +143,8 @@ chip_test_suite("tests") { "TestBuilderParser.cpp", "TestMessageDef.cpp", "TestNullable.cpp", + "TestPendingNotificationMap.cpp", + "TestPendingResponseTrackerImpl.cpp", "TestStatusIB.cpp", "TestStatusResponseMessage.cpp", ] @@ -168,6 +170,11 @@ chip_test_suite("tests") { "${chip_root}/src/lib/support:test_utils", "${chip_root}/src/lib/support:testing", ] + + # DefaultICDClientStorage assumes that raw AES key is used by the application + if (chip_crypto != "psa") { + test_sources += [ "TestDefaultICDClientStorage.cpp" ] + } } chip_test_suite_using_nltest("tests_nltest") { @@ -195,8 +202,6 @@ chip_test_suite_using_nltest("tests_nltest") { "TestInteractionModelEngine.cpp", "TestNumericAttributeTraits.cpp", "TestOperationalStateClusterObjects.cpp", - "TestPendingNotificationMap.cpp", - "TestPendingResponseTrackerImpl.cpp", "TestPowerSourceCluster.cpp", "TestReadInteraction.cpp", "TestReportingEngine.cpp", @@ -206,11 +211,6 @@ chip_test_suite_using_nltest("tests_nltest") { "TestWriteInteraction.cpp", ] - # DefaultICDClientStorage assumes that raw AES key is used by the application - if (chip_crypto != "psa") { - test_sources += [ "TestDefaultICDClientStorage.cpp" ] - } - # # On NRF platforms, the allocation of a large number of pbufs in this test # to exercise chunking causes it to run out of memory. For now, disable it there. diff --git a/src/app/tests/TestDefaultICDClientStorage.cpp b/src/app/tests/TestDefaultICDClientStorage.cpp index 62787a2c9e4144..e9761656bd192b 100644 --- a/src/app/tests/TestDefaultICDClientStorage.cpp +++ b/src/app/tests/TestDefaultICDClientStorage.cpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include @@ -55,7 +55,14 @@ struct TestClientInfo : public ICDClientInfo } }; -void TestClientInfoCount(nlTestSuite * apSuite, void * apContext) +class TestDefaultICDClientStorage : public ::testing::Test +{ +public: + static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); } + static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); } +}; + +TEST_F(TestDefaultICDClientStorage, TestClientInfoCount) { CHIP_ERROR err = CHIP_NO_ERROR; FabricIndex fabricId = 1; @@ -67,9 +74,9 @@ void TestClientInfoCount(nlTestSuite * apSuite, void * apContext) { DefaultICDClientStorage manager; err = manager.Init(&clientInfoStorage, &keystore); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = manager.UpdateFabricList(fabricId); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); // Write some ClientInfos and see the counts are correct ICDClientInfo clientInfo1; clientInfo1.peer_node = ScopedNodeId(nodeId1, fabricId); @@ -78,38 +85,38 @@ void TestClientInfoCount(nlTestSuite * apSuite, void * apContext) ICDClientInfo clientInfo3; clientInfo3.peer_node = ScopedNodeId(nodeId1, fabricId); err = manager.SetKey(clientInfo1, ByteSpan(kKeyBuffer1)); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = manager.StoreEntry(clientInfo1); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = manager.SetKey(clientInfo2, ByteSpan(kKeyBuffer2)); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = manager.StoreEntry(clientInfo2); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = manager.SetKey(clientInfo3, ByteSpan(kKeyBuffer3)); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = manager.StoreEntry(clientInfo3); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); ICDClientInfo clientInfo; // Make sure iterator counts correctly auto * iterator = manager.IterateICDClientInfo(); // same nodeId for clientInfo2 and clientInfo3, so the new one replace old one - NL_TEST_ASSERT(apSuite, iterator->Count() == 2); + EXPECT_EQ(iterator->Count(), 2u); - NL_TEST_ASSERT(apSuite, iterator->Next(clientInfo)); - NL_TEST_ASSERT(apSuite, clientInfo.peer_node.GetNodeId() == nodeId2); - NL_TEST_ASSERT(apSuite, iterator->Next(clientInfo)); - NL_TEST_ASSERT(apSuite, clientInfo.peer_node.GetNodeId() == nodeId1); + EXPECT_TRUE(iterator->Next(clientInfo)); + EXPECT_EQ(clientInfo.peer_node.GetNodeId(), nodeId2); + EXPECT_TRUE(iterator->Next(clientInfo)); + EXPECT_EQ(clientInfo.peer_node.GetNodeId(), nodeId1); iterator->Release(); // Delete all and verify iterator counts 0 err = manager.DeleteAllEntries(fabricId); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); iterator = manager.IterateICDClientInfo(); - NL_TEST_ASSERT(apSuite, iterator->Count() == 0); + EXPECT_EQ(iterator->Count(), 0u); // Verify ClientInfos manually count correctly size_t count = 0; @@ -118,19 +125,19 @@ void TestClientInfoCount(nlTestSuite * apSuite, void * apContext) count++; } iterator->Release(); - NL_TEST_ASSERT(apSuite, count == 0); + EXPECT_EQ(count, 0u); } { DefaultICDClientStorage manager; err = manager.Init(&clientInfoStorage, &keystore); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = manager.UpdateFabricList(fabricId); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); } } -void TestClientInfoCountMultipleFabric(nlTestSuite * apSuite, void * apContext) +TEST_F(TestDefaultICDClientStorage, TestClientInfoCountMultipleFabric) { CHIP_ERROR err = CHIP_NO_ERROR; FabricIndex fabricId1 = 1; @@ -142,11 +149,11 @@ void TestClientInfoCountMultipleFabric(nlTestSuite * apSuite, void * apContext) TestPersistentStorageDelegate clientInfoStorage; TestSessionKeystoreImpl keystore; err = manager.Init(&clientInfoStorage, &keystore); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = manager.UpdateFabricList(fabricId1); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = manager.UpdateFabricList(fabricId2); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); // Write some ClientInfos and see the counts are correct ICDClientInfo clientInfo1; @@ -157,39 +164,39 @@ void TestClientInfoCountMultipleFabric(nlTestSuite * apSuite, void * apContext) clientInfo3.peer_node = ScopedNodeId(nodeId3, fabricId2); err = manager.SetKey(clientInfo1, ByteSpan(kKeyBuffer1)); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = manager.StoreEntry(clientInfo1); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = manager.SetKey(clientInfo2, ByteSpan(kKeyBuffer2)); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = manager.StoreEntry(clientInfo2); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = manager.SetKey(clientInfo3, ByteSpan(kKeyBuffer3)); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = manager.StoreEntry(clientInfo3); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); // Make sure iterator counts correctly auto * iterator = manager.IterateICDClientInfo(); - NL_TEST_ASSERT(apSuite, iterator->Count() == 3); + EXPECT_EQ(iterator->Count(), 3u); iterator->Release(); // Delete all and verify iterator counts 0 err = manager.DeleteEntry(ScopedNodeId(nodeId1, fabricId1)); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); iterator = manager.IterateICDClientInfo(); - NL_TEST_ASSERT(apSuite, iterator != nullptr); + ASSERT_NE(iterator, nullptr); DefaultICDClientStorage::ICDClientInfoIteratorWrapper clientInfoIteratorWrapper(iterator); - NL_TEST_ASSERT(apSuite, iterator->Count() == 2); + EXPECT_EQ(iterator->Count(), 2u); err = manager.DeleteEntry(ScopedNodeId(nodeId2, fabricId1)); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - NL_TEST_ASSERT(apSuite, iterator->Count() == 1); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(iterator->Count(), 1u); err = manager.DeleteEntry(ScopedNodeId(nodeId3, fabricId2)); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - NL_TEST_ASSERT(apSuite, iterator->Count() == 0); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(iterator->Count(), 0u); // Verify ClientInfos manually count correctly size_t count = 0; @@ -199,10 +206,10 @@ void TestClientInfoCountMultipleFabric(nlTestSuite * apSuite, void * apContext) count++; } - NL_TEST_ASSERT(apSuite, count == 0); + EXPECT_FALSE(count); } -void TestProcessCheckInPayload(nlTestSuite * apSuite, void * apContext) +TEST_F(TestDefaultICDClientStorage, TestProcessCheckInPayload) { CHIP_ERROR err = CHIP_NO_ERROR; FabricIndex fabricId = 1; @@ -212,98 +219,41 @@ void TestProcessCheckInPayload(nlTestSuite * apSuite, void * apContext) DefaultICDClientStorage manager; err = manager.Init(&clientInfoStorage, &keystore); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = manager.UpdateFabricList(fabricId); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); // Populate clientInfo ICDClientInfo clientInfo; clientInfo.peer_node = ScopedNodeId(nodeId, fabricId); err = manager.SetKey(clientInfo, ByteSpan(kKeyBuffer1)); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = manager.StoreEntry(clientInfo); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); uint32_t counter = 1; System::PacketBufferHandle buffer = MessagePacketBuffer::New(chip::Protocols::SecureChannel::CheckinMessage::kMinPayloadSize); MutableByteSpan output{ buffer->Start(), buffer->MaxDataLength() }; err = chip::Protocols::SecureChannel::CheckinMessage::GenerateCheckinMessagePayload( clientInfo.aes_key_handle, clientInfo.hmac_key_handle, counter, ByteSpan(), output); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); buffer->SetDataLength(static_cast(output.size())); ICDClientInfo decodeClientInfo; uint32_t checkInCounter = 0; ByteSpan payload{ buffer->Start(), buffer->DataLength() }; err = manager.ProcessCheckInPayload(payload, decodeClientInfo, checkInCounter); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); // 2. Use a key not available in the storage for encoding err = manager.SetKey(clientInfo, ByteSpan(kKeyBuffer2)); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = chip::Protocols::SecureChannel::CheckinMessage::GenerateCheckinMessagePayload( clientInfo.aes_key_handle, clientInfo.hmac_key_handle, counter, ByteSpan(), output); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); buffer->SetDataLength(static_cast(output.size())); ByteSpan payload1{ buffer->Start(), buffer->DataLength() }; err = manager.ProcessCheckInPayload(payload1, decodeClientInfo, checkInCounter); - NL_TEST_ASSERT(apSuite, err == CHIP_ERROR_NOT_FOUND); -} - -/** - * Set up the test suite. - */ -int TestClientInfo_Setup(void * apContext) -{ - VerifyOrReturnError(CHIP_NO_ERROR == Platform::MemoryInit(), FAILURE); - - return SUCCESS; + EXPECT_EQ(err, CHIP_ERROR_NOT_FOUND); } - -/** - * Tear down the test suite. - */ -int TestClientInfo_Teardown(void * apContext) -{ - Platform::MemoryShutdown(); - return SUCCESS; -} - -// Test Suite - -/** - * Test Suite that lists all the test functions. - */ -// clang-format off -static const nlTest sTests[] = -{ - NL_TEST_DEF("TestClientInfoCount", TestClientInfoCount), - NL_TEST_DEF("TestClientInfoCountMultipleFabric", TestClientInfoCountMultipleFabric), - NL_TEST_DEF("TestProcessCheckInPayload", TestProcessCheckInPayload), - - NL_TEST_SENTINEL() -}; -// clang-format on - -// clang-format off -static nlTestSuite sSuite = -{ - "TestDefaultICDClientStorage", - &sTests[0], - &TestClientInfo_Setup, &TestClientInfo_Teardown -}; -// clang-format on - -/** - * Main - */ -int TestDefaultICDClientStorage() -{ - // Run test suit against one context - nlTestRunner(&sSuite, nullptr); - - return (nlTestRunnerStats(&sSuite)); -} - -CHIP_REGISTER_TEST_SUITE(TestDefaultICDClientStorage) diff --git a/src/app/tests/TestPendingNotificationMap.cpp b/src/app/tests/TestPendingNotificationMap.cpp index 98e27cb5f7b45a..5a98abc3dfdbbe 100644 --- a/src/app/tests/TestPendingNotificationMap.cpp +++ b/src/app/tests/TestPendingNotificationMap.cpp @@ -15,12 +15,12 @@ * limitations under the License. */ +#include + #include #include #include #include -#include -#include using chip::BindingTable; using chip::ClusterId; @@ -33,6 +33,16 @@ using chip::PendingNotificationMap; namespace { +class TestPendingNotificationMap : public ::testing::Test +{ +public: + static void SetUpTestSuite() + { + static chip::TestPersistentStorageDelegate storage; + BindingTable::GetInstance().SetPersistentStorage(&storage); + } +}; + void ClearBindingTable(BindingTable & table) { auto iter = table.begin(); @@ -50,103 +60,83 @@ void CreateDefaultFullBindingTable(BindingTable & table) } } -void TestEmptyMap(nlTestSuite * aSuite, void * aContext) +TEST_F(TestPendingNotificationMap, TestEmptyMap) { PendingNotificationMap pendingMap; - NL_TEST_ASSERT(aSuite, pendingMap.begin() == pendingMap.end()); + EXPECT_EQ(pendingMap.begin(), pendingMap.end()); chip::ScopedNodeId peer; - NL_TEST_ASSERT(aSuite, pendingMap.FindLRUConnectPeer(peer) == CHIP_ERROR_NOT_FOUND); + EXPECT_EQ(pendingMap.FindLRUConnectPeer(peer), CHIP_ERROR_NOT_FOUND); } -void TestAddRemove(nlTestSuite * aSuite, void * aContext) +TEST_F(TestPendingNotificationMap, TestAddRemove) { PendingNotificationMap pendingMap; ClearBindingTable(BindingTable::GetInstance()); CreateDefaultFullBindingTable(BindingTable::GetInstance()); for (uint8_t i = 0; i < MATTER_BINDING_TABLE_SIZE; i++) { - NL_TEST_ASSERT(aSuite, pendingMap.AddPendingNotification(i, nullptr) == CHIP_NO_ERROR); + EXPECT_EQ(pendingMap.AddPendingNotification(i, nullptr), CHIP_NO_ERROR); } // Confirm adding in one more element fails - NL_TEST_ASSERT(aSuite, pendingMap.AddPendingNotification(MATTER_BINDING_TABLE_SIZE, nullptr) == CHIP_ERROR_NO_MEMORY); + EXPECT_EQ(pendingMap.AddPendingNotification(MATTER_BINDING_TABLE_SIZE, nullptr), CHIP_ERROR_NO_MEMORY); auto iter = pendingMap.begin(); for (uint8_t i = 0; i < MATTER_BINDING_TABLE_SIZE; i++) { PendingNotificationEntry entry = *iter; - NL_TEST_ASSERT(aSuite, entry.mBindingEntryId == i); + EXPECT_EQ(entry.mBindingEntryId, i); ++iter; } - NL_TEST_ASSERT(aSuite, iter == pendingMap.end()); + EXPECT_EQ(iter, pendingMap.end()); pendingMap.RemoveAllEntriesForNode(chip::ScopedNodeId()); uint8_t expectedEntryIndecies[] = { 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; iter = pendingMap.begin(); for (uint8_t ch : expectedEntryIndecies) { PendingNotificationEntry entry = *iter; - NL_TEST_ASSERT(aSuite, entry.mBindingEntryId == ch); + EXPECT_EQ(entry.mBindingEntryId, ch); ++iter; } - NL_TEST_ASSERT(aSuite, iter == pendingMap.end()); + EXPECT_EQ(iter, pendingMap.end()); pendingMap.RemoveAllEntriesForFabric(0); iter = pendingMap.begin(); for (uint8_t i = 0; i < 10; i++) { PendingNotificationEntry entry = *iter; - NL_TEST_ASSERT(aSuite, entry.mBindingEntryId == 10 + i); + EXPECT_EQ(entry.mBindingEntryId, 10u + i); ++iter; } - NL_TEST_ASSERT(aSuite, iter == pendingMap.end()); + EXPECT_EQ(iter, pendingMap.end()); pendingMap.RemoveAllEntriesForFabric(1); - NL_TEST_ASSERT(aSuite, pendingMap.begin() == pendingMap.end()); + EXPECT_EQ(pendingMap.begin(), pendingMap.end()); } -void TestLRUEntry(nlTestSuite * aSuite, void * aContext) +TEST_F(TestPendingNotificationMap, TestLRUEntry) { PendingNotificationMap pendingMap; ClearBindingTable(BindingTable::GetInstance()); CreateDefaultFullBindingTable(BindingTable::GetInstance()); - NL_TEST_ASSERT(aSuite, pendingMap.AddPendingNotification(0, nullptr) == CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, pendingMap.AddPendingNotification(1, nullptr) == CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, pendingMap.AddPendingNotification(5, nullptr) == CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, pendingMap.AddPendingNotification(7, nullptr) == CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, pendingMap.AddPendingNotification(11, nullptr) == CHIP_NO_ERROR); + EXPECT_EQ(pendingMap.AddPendingNotification(0, nullptr), CHIP_NO_ERROR); + EXPECT_EQ(pendingMap.AddPendingNotification(1, nullptr), CHIP_NO_ERROR); + EXPECT_EQ(pendingMap.AddPendingNotification(5, nullptr), CHIP_NO_ERROR); + EXPECT_EQ(pendingMap.AddPendingNotification(7, nullptr), CHIP_NO_ERROR); + EXPECT_EQ(pendingMap.AddPendingNotification(11, nullptr), CHIP_NO_ERROR); chip::ScopedNodeId node; - NL_TEST_ASSERT(aSuite, pendingMap.FindLRUConnectPeer(node) == CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, node.GetFabricIndex() == 0 && node.GetNodeId() == 1); + EXPECT_EQ(pendingMap.FindLRUConnectPeer(node), CHIP_NO_ERROR); + EXPECT_EQ(node.GetFabricIndex(), 0u); + EXPECT_EQ(node.GetNodeId(), 1u); pendingMap.RemoveEntry(1); - NL_TEST_ASSERT(aSuite, pendingMap.FindLRUConnectPeer(node) == CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, node.GetFabricIndex() == 0 && node.GetNodeId() == 0); + EXPECT_EQ(pendingMap.FindLRUConnectPeer(node), CHIP_NO_ERROR); + EXPECT_EQ(node.GetFabricIndex(), 0u); + EXPECT_EQ(node.GetNodeId(), 0u); pendingMap.RemoveAllEntriesForFabric(0); - NL_TEST_ASSERT(aSuite, pendingMap.FindLRUConnectPeer(node) == CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, node.GetFabricIndex() == 1 && node.GetNodeId() == 1); + EXPECT_EQ(pendingMap.FindLRUConnectPeer(node), CHIP_NO_ERROR); + EXPECT_EQ(node.GetFabricIndex(), 1u); + EXPECT_EQ(node.GetNodeId(), 1u); } } // namespace - -int TestPeindingNotificationMap() -{ - static nlTest sTests[] = { - NL_TEST_DEF("TestEmptyMap", TestEmptyMap), - NL_TEST_DEF("TestAddRemove", TestAddRemove), - NL_TEST_DEF("TestLRUEntry", TestLRUEntry), - NL_TEST_SENTINEL(), - }; - - nlTestSuite theSuite = { - "PendingNotificationMap", - &sTests[0], - nullptr, - nullptr, - }; - chip::TestPersistentStorageDelegate storage; - BindingTable::GetInstance().SetPersistentStorage(&storage); - nlTestRunner(&theSuite, nullptr); - return (nlTestRunnerStats(&theSuite)); -} - -CHIP_REGISTER_TEST_SUITE(TestPeindingNotificationMap) diff --git a/src/app/tests/TestPendingResponseTrackerImpl.cpp b/src/app/tests/TestPendingResponseTrackerImpl.cpp index da6239434cd3b1..2ccd5380642786 100644 --- a/src/app/tests/TestPendingResponseTrackerImpl.cpp +++ b/src/app/tests/TestPendingResponseTrackerImpl.cpp @@ -15,75 +15,75 @@ * limitations under the License. */ -#include -#include - #include #include #include +#include +#include + namespace { using namespace chip; -void TestPendingResponseTracker_FillEntireTracker(nlTestSuite * inSuite, void * inContext) +TEST(TestPendingResponseTrackerImpl, TestPendingResponseTracker_FillEntireTracker) { chip::app::PendingResponseTrackerImpl pendingResponseTracker; for (uint16_t commandRef = 0; commandRef < std::numeric_limits::max(); commandRef++) { - NL_TEST_ASSERT(inSuite, false == pendingResponseTracker.IsTracked(commandRef)); - NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == pendingResponseTracker.Add(commandRef)); - NL_TEST_ASSERT(inSuite, true == pendingResponseTracker.IsTracked(commandRef)); + EXPECT_FALSE(pendingResponseTracker.IsTracked(commandRef)); + EXPECT_EQ(CHIP_NO_ERROR, pendingResponseTracker.Add(commandRef)); + EXPECT_TRUE(pendingResponseTracker.IsTracked(commandRef)); } - NL_TEST_ASSERT(inSuite, std::numeric_limits::max() == pendingResponseTracker.Count()); + EXPECT_EQ(std::numeric_limits::max(), pendingResponseTracker.Count()); for (uint16_t commandRef = 0; commandRef < std::numeric_limits::max(); commandRef++) { - NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == pendingResponseTracker.Remove(commandRef)); - NL_TEST_ASSERT(inSuite, false == pendingResponseTracker.IsTracked(commandRef)); + EXPECT_EQ(CHIP_NO_ERROR, pendingResponseTracker.Remove(commandRef)); + EXPECT_EQ(false, pendingResponseTracker.IsTracked(commandRef)); } - NL_TEST_ASSERT(inSuite, 0 == pendingResponseTracker.Count()); + EXPECT_EQ(0u, pendingResponseTracker.Count()); } -void TestPendingResponseTracker_FillSingleEntryInTracker(nlTestSuite * inSuite, void * inContext) +TEST(TestPendingResponseTrackerImpl, TestPendingResponseTracker_FillSingleEntryInTracker) { chip::app::PendingResponseTrackerImpl pendingResponseTracker; // The value 40 is arbitrary; any value would work for this purpose. uint16_t commandRefToSet = 40; - NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == pendingResponseTracker.Add(commandRefToSet)); + EXPECT_EQ(CHIP_NO_ERROR, pendingResponseTracker.Add(commandRefToSet)); for (uint16_t commandRef = 0; commandRef < std::numeric_limits::max(); commandRef++) { bool expectedIsSetResult = (commandRef == commandRefToSet); - NL_TEST_ASSERT(inSuite, expectedIsSetResult == pendingResponseTracker.IsTracked(commandRef)); + EXPECT_EQ(expectedIsSetResult, pendingResponseTracker.IsTracked(commandRef)); } } -void TestPendingResponseTracker_RemoveNonExistentEntryInTrackerFails(nlTestSuite * inSuite, void * inContext) +TEST(TestPendingResponseTrackerImpl, TestPendingResponseTracker_RemoveNonExistentEntryInTrackerFails) { chip::app::PendingResponseTrackerImpl pendingResponseTracker; // The value 40 is arbitrary; any value would work for this purpose. uint16_t commandRef = 40; - NL_TEST_ASSERT(inSuite, false == pendingResponseTracker.IsTracked(commandRef)); - NL_TEST_ASSERT(inSuite, CHIP_ERROR_KEY_NOT_FOUND == pendingResponseTracker.Remove(commandRef)); + EXPECT_FALSE(pendingResponseTracker.IsTracked(commandRef)); + EXPECT_EQ(CHIP_ERROR_KEY_NOT_FOUND, pendingResponseTracker.Remove(commandRef)); } -void TestPendingResponseTracker_AddingSecondEntryFails(nlTestSuite * inSuite, void * inContext) +TEST(TestPendingResponseTrackerImpl, TestPendingResponseTracker_AddingSecondEntryFails) { chip::app::PendingResponseTrackerImpl pendingResponseTracker; // The value 40 is arbitrary; any value would work for this purpose. uint16_t commandRef = 40; - NL_TEST_ASSERT(inSuite, false == pendingResponseTracker.IsTracked(commandRef)); - NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == pendingResponseTracker.Add(commandRef)); - NL_TEST_ASSERT(inSuite, true == pendingResponseTracker.IsTracked(commandRef)); - NL_TEST_ASSERT(inSuite, CHIP_ERROR_INVALID_ARGUMENT == pendingResponseTracker.Add(commandRef)); + EXPECT_FALSE(pendingResponseTracker.IsTracked(commandRef)); + EXPECT_EQ(CHIP_NO_ERROR, pendingResponseTracker.Add(commandRef)); + EXPECT_TRUE(pendingResponseTracker.IsTracked(commandRef)); + EXPECT_EQ(CHIP_ERROR_INVALID_ARGUMENT, pendingResponseTracker.Add(commandRef)); } -void TestPendingResponseTracker_PopFindsAllPendingRequests(nlTestSuite * inSuite, void * inContext) +TEST(TestPendingResponseTrackerImpl, TestPendingResponseTracker_PopFindsAllPendingRequests) { chip::app::PendingResponseTrackerImpl pendingResponseTracker; @@ -91,45 +91,23 @@ void TestPendingResponseTracker_PopFindsAllPendingRequests(nlTestSuite * inSuite std::vector requestsToAdd = { 0, 50, 2, 2000 }; for (const uint16_t & commandRef : requestsToAdd) { - NL_TEST_ASSERT(inSuite, false == pendingResponseTracker.IsTracked(commandRef)); - NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == pendingResponseTracker.Add(commandRef)); - NL_TEST_ASSERT(inSuite, true == pendingResponseTracker.IsTracked(commandRef)); + EXPECT_FALSE(pendingResponseTracker.IsTracked(commandRef)); + EXPECT_EQ(CHIP_NO_ERROR, pendingResponseTracker.Add(commandRef)); + EXPECT_TRUE(pendingResponseTracker.IsTracked(commandRef)); } - NL_TEST_ASSERT(inSuite, requestsToAdd.size() == pendingResponseTracker.Count()); + EXPECT_EQ(requestsToAdd.size(), pendingResponseTracker.Count()); for (size_t i = 0; i < requestsToAdd.size(); i++) { auto commandRef = pendingResponseTracker.PopPendingResponse(); - NL_TEST_ASSERT(inSuite, true == commandRef.HasValue()); + EXPECT_TRUE(commandRef.HasValue()); bool expectedCommandRef = std::find(requestsToAdd.begin(), requestsToAdd.end(), commandRef.Value()) != requestsToAdd.end(); - NL_TEST_ASSERT(inSuite, true == expectedCommandRef); + EXPECT_TRUE(expectedCommandRef); } - NL_TEST_ASSERT(inSuite, 0 == pendingResponseTracker.Count()); + EXPECT_EQ(0u, pendingResponseTracker.Count()); auto commandRef = pendingResponseTracker.PopPendingResponse(); - NL_TEST_ASSERT(inSuite, false == commandRef.HasValue()); + EXPECT_FALSE(commandRef.HasValue()); } } // namespace - -#define NL_TEST_DEF_FN(fn) NL_TEST_DEF("Test " #fn, fn) -/** - * Test Suite. It lists all the test functions. - */ -static const nlTest sTests[] = { NL_TEST_DEF_FN(TestPendingResponseTracker_FillEntireTracker), - NL_TEST_DEF_FN(TestPendingResponseTracker_FillSingleEntryInTracker), - NL_TEST_DEF_FN(TestPendingResponseTracker_RemoveNonExistentEntryInTrackerFails), - NL_TEST_DEF_FN(TestPendingResponseTracker_AddingSecondEntryFails), - NL_TEST_DEF_FN(TestPendingResponseTracker_PopFindsAllPendingRequests), - NL_TEST_SENTINEL() }; - -int TestPendingResponseTracker() -{ - nlTestSuite theSuite = { "CHIP PendingResponseTrackerImpl tests", &sTests[0], nullptr, nullptr }; - - // Run test suite against one context. - nlTestRunner(&theSuite, nullptr); - return nlTestRunnerStats(&theSuite); -} - -CHIP_REGISTER_TEST_SUITE(TestPendingResponseTracker)