From 5dd912f755f6374be063d41f8e0caac7247e64d2 Mon Sep 17 00:00:00 2001 From: Amine Alami <43780877+Alami-Amine@users.noreply.github.com> Date: Mon, 3 Jun 2024 23:00:07 +0200 Subject: [PATCH] pw_unit_test migration: apps-1 and stub-refactoring (#33638) * Decoupling ember functions + some tests * Fix TearDown issue of some App Tests * adding more tests * Integrating comments * Rename ember-test-compatibility to test-interaction-model-api * adding ember test-utilities source files * restyled patch * integrating comments * restyled --- src/BUILD.gn | 1 + src/app/tests/BUILD.gn | 96 +- src/app/tests/TestAclAttribute.cpp | 43 +- .../TestAttributeAccessInterfaceCache.cpp | 88 +- .../tests/TestAttributePathExpandIterator.cpp | 137 +- .../TestAttributePersistenceProvider.cpp | 246 ++-- src/app/tests/TestAttributeValueDecoder.cpp | 58 +- src/app/tests/TestAttributeValueEncoder.cpp | 242 ++-- src/app/tests/TestBindingTable.cpp | 182 +-- src/app/tests/TestBuilderParser.cpp | 79 +- src/app/tests/TestDefaultICDClientStorage.cpp | 164 +-- src/app/tests/TestFailSafeContext.cpp | 102 +- src/app/tests/TestMessageDef.cpp | 1283 ++++++++--------- src/app/tests/TestNullable.cpp | 196 ++- src/app/tests/TestNumericAttributeTraits.cpp | 508 +++---- .../TestOperationalStateClusterObjects.cpp | 378 ++--- src/app/tests/TestPendingNotificationMap.cpp | 90 +- .../tests/TestPendingResponseTrackerImpl.cpp | 85 +- src/app/tests/TestPowerSourceCluster.cpp | 190 +-- src/app/tests/TestReadInteraction.cpp | 51 +- ...estSimpleSubscriptionResumptionStorage.cpp | 220 ++- src/app/tests/TestStatusIB.cpp | 125 +- src/app/tests/TestStatusResponseMessage.cpp | 96 +- .../tests/TestTestEventTriggerDelegate.cpp | 108 +- src/app/tests/TestTimeSyncDataProvider.cpp | 171 +-- src/app/tests/TestWriteInteraction.cpp | 30 +- src/app/tests/test-ember-api.cpp | 36 + src/app/tests/test-ember-api.h | 28 + src/app/tests/test-interaction-model-api.cpp | 139 ++ src/app/tests/test-interaction-model-api.h | 69 + .../openiotsdk/unit-tests/test_components.txt | 1 + .../unit-tests/test_components_nl.txt | 2 +- 32 files changed, 2323 insertions(+), 2921 deletions(-) create mode 100644 src/app/tests/test-ember-api.cpp create mode 100644 src/app/tests/test-ember-api.h create mode 100644 src/app/tests/test-interaction-model-api.cpp create mode 100644 src/app/tests/test-interaction-model-api.h diff --git a/src/BUILD.gn b/src/BUILD.gn index cf15f40ec00629..5f7d6cc95ab6ba 100644 --- a/src/BUILD.gn +++ b/src/BUILD.gn @@ -96,6 +96,7 @@ if (chip_build_tests) { if (chip_device_platform != "efr32") { tests += [ "${chip_root}/src/app/tests", + "${chip_root}/src/app/tests:tests_nltest", "${chip_root}/src/credentials/tests", "${chip_root}/src/lib/format/tests", "${chip_root}/src/lib/support/tests", diff --git a/src/app/tests/BUILD.gn b/src/app/tests/BUILD.gn index 28408773e15edf..e8413b92026d9a 100644 --- a/src/app/tests/BUILD.gn +++ b/src/app/tests/BUILD.gn @@ -15,6 +15,7 @@ import("//build_overrides/build.gni") import("//build_overrides/chip.gni") import("//build_overrides/nlunit_test.gni") +import("//build_overrides/pigweed.gni") import("${chip_root}/build/chip/chip_test_suite.gni") import("${chip_root}/src/app/icd/icd.gni") @@ -37,9 +38,10 @@ static_library("helpers") { "${chip_root}/src/access", "${chip_root}/src/app", "${chip_root}/src/lib/support", - "${chip_root}/src/messaging/tests:helpers", "${chip_root}/src/transport/raw/tests:helpers", ] + + public_deps = [ "${chip_root}/src/messaging/tests:helpers" ] } source_set("binding-test-srcs") { @@ -119,31 +121,33 @@ source_set("operational-state-test-srcs") { ] } -chip_test_suite_using_nltest("tests") { +source_set("app-test-stubs") { + sources = [ + "test-ember-api.cpp", + "test-ember-api.h", + "test-interaction-model-api.cpp", + "test-interaction-model-api.h", + ] + public_configs = [ "${chip_root}/src/lib/support/pw_log_chip:config" ] + + public_deps = [ + "${chip_root}/src/app/util/mock:mock_ember", + "${chip_root}/src/lib/core", + "${chip_root}/src/lib/support", + ] +} + +chip_test_suite("tests") { output_name = "libAppTests" test_sources = [ - "TestAclAttribute.cpp", - "TestAclEvent.cpp", "TestAttributeAccessInterfaceCache.cpp", "TestAttributePathExpandIterator.cpp", "TestAttributePersistenceProvider.cpp", "TestAttributeValueDecoder.cpp", "TestAttributeValueEncoder.cpp", - "TestBasicCommandPathRegistry.cpp", "TestBindingTable.cpp", "TestBuilderParser.cpp", - "TestClusterInfo.cpp", - "TestCommandInteraction.cpp", - "TestCommandPathParams.cpp", - "TestConcreteAttributePath.cpp", - "TestDataModelSerialization.cpp", - "TestDefaultOTARequestorStorage.cpp", - "TestEventLoggingNoUTCTime.cpp", - "TestEventOverflow.cpp", - "TestEventPathParams.cpp", - "TestFabricScopedEventLogging.cpp", - "TestInteractionModelEngine.cpp", "TestMessageDef.cpp", "TestNullable.cpp", "TestNumericAttributeTraits.cpp", @@ -151,15 +155,10 @@ chip_test_suite_using_nltest("tests") { "TestPendingNotificationMap.cpp", "TestPendingResponseTrackerImpl.cpp", "TestPowerSourceCluster.cpp", - "TestReadInteraction.cpp", - "TestReportScheduler.cpp", - "TestReportingEngine.cpp", "TestStatusIB.cpp", "TestStatusResponseMessage.cpp", "TestTestEventTriggerDelegate.cpp", "TestTimeSyncDataProvider.cpp", - "TestTimedHandler.cpp", - "TestWriteInteraction.cpp", ] if (!chip_fake_platform) { @@ -171,6 +170,56 @@ chip_test_suite_using_nltest("tests") { test_sources += [ "TestDefaultICDClientStorage.cpp" ] } + if (chip_persist_subscriptions) { + test_sources += [ "TestSimpleSubscriptionResumptionStorage.cpp" ] + } + + cflags = [ "-Wconversion" ] + + public_deps = [ + ":app-test-stubs", + ":binding-test-srcs", + ":operational-state-test-srcs", + ":ota-requestor-test-srcs", + ":power-cluster-test-srcs", + ":time-sync-data-provider-test-srcs", + "${chip_root}/src/app", + "${chip_root}/src/app/common:cluster-objects", + "${chip_root}/src/app/icd/client:manager", + "${chip_root}/src/app/tests:helpers", + "${chip_root}/src/app/util/mock:mock_ember", + "${chip_root}/src/lib/core", + "${chip_root}/src/lib/core:string-builder-adapters", + "${chip_root}/src/lib/support:test_utils", + "${chip_root}/src/lib/support:testing", + ] +} + +chip_test_suite_using_nltest("tests_nltest") { + output_name = "libAppTestsNL" + + test_sources = [ + "TestAclAttribute.cpp", + "TestAclEvent.cpp", + "TestBasicCommandPathRegistry.cpp", + "TestClusterInfo.cpp", + "TestCommandInteraction.cpp", + "TestCommandPathParams.cpp", + "TestConcreteAttributePath.cpp", + "TestDataModelSerialization.cpp", + "TestDefaultOTARequestorStorage.cpp", + "TestEventLoggingNoUTCTime.cpp", + "TestEventOverflow.cpp", + "TestEventPathParams.cpp", + "TestFabricScopedEventLogging.cpp", + "TestInteractionModelEngine.cpp", + "TestReadInteraction.cpp", + "TestReportScheduler.cpp", + "TestReportingEngine.cpp", + "TestTimedHandler.cpp", + "TestWriteInteraction.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. @@ -192,6 +241,7 @@ chip_test_suite_using_nltest("tests") { cflags = [ "-Wconversion" ] public_deps = [ + ":app-test-stubs", ":binding-test-srcs", ":operational-state-test-srcs", ":ota-requestor-test-srcs", @@ -227,8 +277,4 @@ chip_test_suite_using_nltest("tests") { "${chip_root}/src/messaging/tests/echo:common", ] } - - if (chip_persist_subscriptions) { - test_sources += [ "TestSimpleSubscriptionResumptionStorage.cpp" ] - } } diff --git a/src/app/tests/TestAclAttribute.cpp b/src/app/tests/TestAclAttribute.cpp index 427b257f9efd7c..1c928515dc5d74 100644 --- a/src/app/tests/TestAclAttribute.cpp +++ b/src/app/tests/TestAclAttribute.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -46,18 +47,13 @@ namespace { using namespace chip; using namespace chip::Access; -chip::ClusterId kTestClusterId = 1; -chip::ClusterId kTestDeniedClusterId1 = 1000; -chip::ClusterId kTestDeniedClusterId2 = 3; -chip::EndpointId kTestEndpointId = 4; - class TestAccessControlDelegate : public AccessControl::Delegate { public: CHIP_ERROR Check(const SubjectDescriptor & subjectDescriptor, const chip::Access::RequestPath & requestPath, Privilege requestPrivilege) override { - if (requestPath.cluster == kTestDeniedClusterId2) + if (requestPath.cluster == chip::Test::kTestDeniedClusterId2) { return CHIP_ERROR_ACCESS_DENIED; } @@ -125,21 +121,6 @@ class MockInteractionModelApp : public chip::app::ReadClient::Callback namespace chip { namespace app { -bool ConcreteAttributePathExists(const ConcreteAttributePath & aPath) -{ - return aPath.mClusterId != kTestDeniedClusterId1; -} - -Protocols::InteractionModel::Status CheckEventSupportStatus(const ConcreteEventPath & aPath) -{ - if (aPath.mClusterId == kTestDeniedClusterId1) - { - return Protocols::InteractionModel::Status::UnsupportedCluster; - } - - return Protocols::InteractionModel::Status::Success; -} - class TestAclAttribute { public: @@ -166,12 +147,12 @@ void TestAclAttribute::TestACLDeniedAttribute(nlTestSuite * apSuite, void * apCo chip::app::ReadClient::InteractionType::Subscribe); chip::app::AttributePathParams attributePathParams[2]; - attributePathParams[0].mEndpointId = kTestEndpointId; - attributePathParams[0].mClusterId = kTestDeniedClusterId1; + attributePathParams[0].mEndpointId = chip::Test::kTestEndpointId; + attributePathParams[0].mClusterId = chip::Test::kTestDeniedClusterId1; attributePathParams[0].mAttributeId = 1; - attributePathParams[1].mEndpointId = kTestEndpointId; - attributePathParams[1].mClusterId = kTestDeniedClusterId1; + attributePathParams[1].mEndpointId = chip::Test::kTestEndpointId; + attributePathParams[1].mClusterId = chip::Test::kTestDeniedClusterId1; attributePathParams[1].mAttributeId = 2; ReadPrepareParams readPrepareParams(ctx.GetSessionBobToAlice()); @@ -194,10 +175,10 @@ void TestAclAttribute::TestACLDeniedAttribute(nlTestSuite * apSuite, void * apCo chip::app::AttributePathParams attributePathParams[2]; - attributePathParams[0].mClusterId = kTestDeniedClusterId2; + attributePathParams[0].mClusterId = chip::Test::kTestDeniedClusterId2; attributePathParams[0].mAttributeId = 1; - attributePathParams[1].mClusterId = kTestDeniedClusterId2; + attributePathParams[1].mClusterId = chip::Test::kTestDeniedClusterId2; attributePathParams[1].mAttributeId = 2; ReadPrepareParams readPrepareParams(ctx.GetSessionBobToAlice()); @@ -219,12 +200,12 @@ void TestAclAttribute::TestACLDeniedAttribute(nlTestSuite * apSuite, void * apCo chip::app::ReadClient::InteractionType::Subscribe); chip::app::AttributePathParams attributePathParams[2]; - attributePathParams[0].mEndpointId = kTestEndpointId; - attributePathParams[0].mClusterId = kTestDeniedClusterId1; + attributePathParams[0].mEndpointId = chip::Test::kTestEndpointId; + attributePathParams[0].mClusterId = chip::Test::kTestDeniedClusterId1; attributePathParams[0].mAttributeId = 1; - attributePathParams[1].mEndpointId = kTestEndpointId; - attributePathParams[1].mClusterId = kTestClusterId; + attributePathParams[1].mEndpointId = chip::Test::kTestEndpointId; + attributePathParams[1].mClusterId = chip::Test::kTestClusterId; attributePathParams[1].mAttributeId = 2; ReadPrepareParams readPrepareParams(ctx.GetSessionBobToAlice()); diff --git a/src/app/tests/TestAttributeAccessInterfaceCache.cpp b/src/app/tests/TestAttributeAccessInterfaceCache.cpp index 47b8e6d921de94..28aa91db42b16f 100644 --- a/src/app/tests/TestAttributeAccessInterfaceCache.cpp +++ b/src/app/tests/TestAttributeAccessInterfaceCache.cpp @@ -18,15 +18,15 @@ #include #include -#include -#include +#include +#include using namespace chip; using namespace chip::app; namespace { -void TestBasicLifecycle(nlTestSuite * inSuite, void * inContext) +TEST(TestAttributeAccessInterfaceCache, TestBasicLifecycle) { using CacheResult = AttributeAccessInterfaceCache::CacheResult; @@ -44,86 +44,58 @@ void TestBasicLifecycle(nlTestSuite * inSuite, void * inContext) // Cache can keep track of at least 1 entry, AttributeAccessInterface * entry = nullptr; - NL_TEST_ASSERT(inSuite, cache.Get(1, 1, &entry) == CacheResult::kCacheMiss); - NL_TEST_ASSERT(inSuite, entry == nullptr); + EXPECT_EQ(cache.Get(1, 1, &entry), CacheResult::kCacheMiss); + EXPECT_EQ(entry, nullptr); cache.MarkUsed(1, 1, accessor1); - NL_TEST_ASSERT(inSuite, cache.Get(1, 1, &entry) == CacheResult::kDefinitelyUsed); - NL_TEST_ASSERT(inSuite, entry == accessor1); + EXPECT_EQ(cache.Get(1, 1, &entry), CacheResult::kDefinitelyUsed); + EXPECT_EQ(entry, accessor1); entry = nullptr; - NL_TEST_ASSERT(inSuite, cache.Get(1, 2, &entry) == CacheResult::kCacheMiss); - NL_TEST_ASSERT(inSuite, entry == nullptr); - NL_TEST_ASSERT(inSuite, cache.Get(2, 1, &entry) == CacheResult::kCacheMiss); - NL_TEST_ASSERT(inSuite, entry == nullptr); + EXPECT_EQ(cache.Get(1, 2, &entry), CacheResult::kCacheMiss); + EXPECT_EQ(entry, nullptr); + EXPECT_EQ(cache.Get(2, 1, &entry), CacheResult::kCacheMiss); + EXPECT_EQ(entry, nullptr); cache.MarkUsed(1, 2, accessor1); entry = nullptr; - NL_TEST_ASSERT(inSuite, cache.Get(1, 2, &entry) == CacheResult::kDefinitelyUsed); - NL_TEST_ASSERT(inSuite, entry == accessor1); - NL_TEST_ASSERT(inSuite, cache.Get(2, 1, &entry) == CacheResult::kCacheMiss); + EXPECT_EQ(cache.Get(1, 2, &entry), CacheResult::kDefinitelyUsed); + EXPECT_EQ(entry, accessor1); + EXPECT_EQ(cache.Get(2, 1, &entry), CacheResult::kCacheMiss); cache.MarkUsed(1, 2, accessor2); entry = nullptr; - NL_TEST_ASSERT(inSuite, cache.Get(1, 2, &entry) == CacheResult::kDefinitelyUsed); - NL_TEST_ASSERT(inSuite, entry == accessor2); + EXPECT_EQ(cache.Get(1, 2, &entry), CacheResult::kDefinitelyUsed); + EXPECT_EQ(entry, accessor2); // The following should not crash (e.g. output not used if nullptr). - NL_TEST_ASSERT(inSuite, cache.Get(1, 2, nullptr) == CacheResult::kDefinitelyUsed); + EXPECT_EQ(cache.Get(1, 2, nullptr), CacheResult::kDefinitelyUsed); // Setting used to nullptr == does not mark used. cache.MarkUsed(1, 2, nullptr); entry = nullptr; - NL_TEST_ASSERT(inSuite, cache.Get(1, 2, &entry) == CacheResult::kCacheMiss); - NL_TEST_ASSERT(inSuite, entry == nullptr); + EXPECT_EQ(cache.Get(1, 2, &entry), CacheResult::kCacheMiss); + EXPECT_EQ(entry, nullptr); cache.Invalidate(); - NL_TEST_ASSERT(inSuite, cache.Get(1, 1, &entry) == CacheResult::kCacheMiss); - NL_TEST_ASSERT(inSuite, entry == nullptr); - NL_TEST_ASSERT(inSuite, cache.Get(1, 2, &entry) == CacheResult::kCacheMiss); - NL_TEST_ASSERT(inSuite, cache.Get(2, 1, &entry) == CacheResult::kCacheMiss); + EXPECT_EQ(cache.Get(1, 1, &entry), CacheResult::kCacheMiss); + EXPECT_EQ(entry, nullptr); + EXPECT_EQ(cache.Get(1, 2, &entry), CacheResult::kCacheMiss); + EXPECT_EQ(cache.Get(2, 1, &entry), CacheResult::kCacheMiss); // Marking unused works, keeps single entry, and is invalidated when invalidated fully. - NL_TEST_ASSERT(inSuite, cache.Get(2, 2, nullptr) != CacheResult::kDefinitelyUnused); - NL_TEST_ASSERT(inSuite, cache.Get(3, 3, nullptr) != CacheResult::kDefinitelyUnused); + EXPECT_NE(cache.Get(2, 2, nullptr), CacheResult::kDefinitelyUnused); + EXPECT_NE(cache.Get(3, 3, nullptr), CacheResult::kDefinitelyUnused); cache.MarkUnused(2, 2); - NL_TEST_ASSERT(inSuite, cache.Get(2, 2, nullptr) == CacheResult::kDefinitelyUnused); - NL_TEST_ASSERT(inSuite, cache.Get(3, 3, nullptr) != CacheResult::kDefinitelyUnused); + EXPECT_EQ(cache.Get(2, 2, nullptr), CacheResult::kDefinitelyUnused); + EXPECT_NE(cache.Get(3, 3, nullptr), CacheResult::kDefinitelyUnused); cache.MarkUnused(3, 3); - NL_TEST_ASSERT(inSuite, cache.Get(2, 2, nullptr) != CacheResult::kDefinitelyUnused); - NL_TEST_ASSERT(inSuite, cache.Get(3, 3, nullptr) == CacheResult::kDefinitelyUnused); + EXPECT_NE(cache.Get(2, 2, nullptr), CacheResult::kDefinitelyUnused); + EXPECT_EQ(cache.Get(3, 3, nullptr), CacheResult::kDefinitelyUnused); cache.Invalidate(); - NL_TEST_ASSERT(inSuite, cache.Get(3, 3, nullptr) != CacheResult::kDefinitelyUnused); + EXPECT_NE(cache.Get(3, 3, nullptr), CacheResult::kDefinitelyUnused); } - -// clang-format off -const nlTest sTests[] = -{ - NL_TEST_DEF("Basic AttributeAccessInterfaceCache lifecycle works", TestBasicLifecycle), - NL_TEST_SENTINEL() -}; -// clang-format on - } // namespace - -int TestAttributeAccessInterfaceCache() -{ - // clang-format off - nlTestSuite theSuite = - { - "Test for AttributeAccessInterface cache utility", - &sTests[0], - nullptr, - nullptr - }; - // clang-format on - - nlTestRunner(&theSuite, nullptr); - - return (nlTestRunnerStats(&theSuite)); -} - -CHIP_REGISTER_TEST_SUITE(TestAttributeAccessInterfaceCache) diff --git a/src/app/tests/TestAttributePathExpandIterator.cpp b/src/app/tests/TestAttributePathExpandIterator.cpp index e5505320193b81..032581bff16f8a 100644 --- a/src/app/tests/TestAttributePathExpandIterator.cpp +++ b/src/app/tests/TestAttributePathExpandIterator.cpp @@ -26,10 +26,10 @@ #include #include #include -#include #include -#include +#include +#include using namespace chip; using namespace chip::Test; @@ -39,7 +39,7 @@ namespace { using P = app::ConcreteAttributePath; -void TestAllWildcard(nlTestSuite * apSuite, void * apContext) +TEST(TestAttributePathExpandIterator, TestAllWildcard) { SingleLinkedListNode clusInfo; @@ -136,17 +136,18 @@ void TestAllWildcard(nlTestSuite * apSuite, void * apContext) { ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId, ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId)); - NL_TEST_ASSERT(apSuite, index < ArraySize(paths) && paths[index] == path); + EXPECT_LT(index, ArraySize(paths)); + EXPECT_EQ(paths[index], path); index++; } - NL_TEST_ASSERT(apSuite, index == ArraySize(paths)); + EXPECT_EQ(index, ArraySize(paths)); } -void TestWildcardEndpoint(nlTestSuite * apSuite, void * apContext) +TEST(TestAttributePathExpandIterator, TestWildcardEndpoint) { SingleLinkedListNode clusInfo; - clusInfo.mValue.mClusterId = Test::MockClusterId(3); - clusInfo.mValue.mAttributeId = Test::MockAttributeId(3); + clusInfo.mValue.mClusterId = chip::Test::MockClusterId(3); + clusInfo.mValue.mAttributeId = chip::Test::MockAttributeId(3); app::ConcreteAttributePath path; P paths[] = { @@ -159,16 +160,17 @@ void TestWildcardEndpoint(nlTestSuite * apSuite, void * apContext) { ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId, ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId)); - NL_TEST_ASSERT(apSuite, index < ArraySize(paths) && paths[index] == path); + EXPECT_LT(index, ArraySize(paths)); + EXPECT_EQ(paths[index], path); index++; } - NL_TEST_ASSERT(apSuite, index == ArraySize(paths)); + EXPECT_EQ(index, ArraySize(paths)); } -void TestWildcardCluster(nlTestSuite * apSuite, void * apContext) +TEST(TestAttributePathExpandIterator, TestWildcardCluster) { SingleLinkedListNode clusInfo; - clusInfo.mValue.mEndpointId = Test::kMockEndpoint3; + clusInfo.mValue.mEndpointId = chip::Test::kMockEndpoint3; clusInfo.mValue.mAttributeId = app::Clusters::Globals::Attributes::ClusterRevision::Id; app::ConcreteAttributePath path; @@ -185,16 +187,17 @@ void TestWildcardCluster(nlTestSuite * apSuite, void * apContext) { ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId, ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId)); - NL_TEST_ASSERT(apSuite, index < ArraySize(paths) && paths[index] == path); + EXPECT_LT(index, ArraySize(paths)); + EXPECT_EQ(paths[index], path); index++; } - NL_TEST_ASSERT(apSuite, index == ArraySize(paths)); + EXPECT_EQ(index, ArraySize(paths)); } -void TestWildcardClusterGlobalAttributeNotInMetadata(nlTestSuite * apSuite, void * apContext) +TEST(TestAttributePathExpandIterator, TestWildcardClusterGlobalAttributeNotInMetadata) { SingleLinkedListNode clusInfo; - clusInfo.mValue.mEndpointId = Test::kMockEndpoint3; + clusInfo.mValue.mEndpointId = chip::Test::kMockEndpoint3; clusInfo.mValue.mAttributeId = app::Clusters::Globals::Attributes::AttributeList::Id; app::ConcreteAttributePath path; @@ -211,17 +214,18 @@ void TestWildcardClusterGlobalAttributeNotInMetadata(nlTestSuite * apSuite, void { ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId, ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId)); - NL_TEST_ASSERT(apSuite, index < ArraySize(paths) && paths[index] == path); + EXPECT_LT(index, ArraySize(paths)); + EXPECT_EQ(paths[index], path); index++; } - NL_TEST_ASSERT(apSuite, index == ArraySize(paths)); + EXPECT_EQ(index, ArraySize(paths)); } -void TestWildcardAttribute(nlTestSuite * apSuite, void * apContext) +TEST(TestAttributePathExpandIterator, TestWildcardAttribute) { SingleLinkedListNode clusInfo; - clusInfo.mValue.mEndpointId = Test::kMockEndpoint2; - clusInfo.mValue.mClusterId = Test::MockClusterId(3); + clusInfo.mValue.mEndpointId = chip::Test::kMockEndpoint2; + clusInfo.mValue.mClusterId = chip::Test::MockClusterId(3); app::ConcreteAttributePath path; P paths[] = { @@ -244,18 +248,19 @@ void TestWildcardAttribute(nlTestSuite * apSuite, void * apContext) { ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId, ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId)); - NL_TEST_ASSERT(apSuite, index < ArraySize(paths) && paths[index] == path); + EXPECT_LT(index, ArraySize(paths)); + EXPECT_EQ(paths[index], path); index++; } - NL_TEST_ASSERT(apSuite, index == ArraySize(paths)); + EXPECT_EQ(index, ArraySize(paths)); } -void TestNoWildcard(nlTestSuite * apSuite, void * apContext) +TEST(TestAttributePathExpandIterator, TestNoWildcard) { SingleLinkedListNode clusInfo; - clusInfo.mValue.mEndpointId = Test::kMockEndpoint2; - clusInfo.mValue.mClusterId = Test::MockClusterId(3); - clusInfo.mValue.mAttributeId = Test::MockAttributeId(3); + clusInfo.mValue.mEndpointId = chip::Test::kMockEndpoint2; + clusInfo.mValue.mClusterId = chip::Test::MockClusterId(3); + clusInfo.mValue.mAttributeId = chip::Test::MockAttributeId(3); app::ConcreteAttributePath path; P paths[] = { @@ -268,33 +273,34 @@ void TestNoWildcard(nlTestSuite * apSuite, void * apContext) { ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId, ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId)); - NL_TEST_ASSERT(apSuite, index < ArraySize(paths) && paths[index] == path); + EXPECT_LT(index, ArraySize(paths)); + EXPECT_EQ(paths[index], path); index++; } - NL_TEST_ASSERT(apSuite, index == ArraySize(paths)); + EXPECT_EQ(index, ArraySize(paths)); } -void TestMultipleClusInfo(nlTestSuite * apSuite, void * apContext) +TEST(TestAttributePathExpandIterator, TestMultipleClusInfo) { SingleLinkedListNode clusInfo1; SingleLinkedListNode clusInfo2; - clusInfo2.mValue.mClusterId = Test::MockClusterId(3); - clusInfo2.mValue.mAttributeId = Test::MockAttributeId(3); + clusInfo2.mValue.mClusterId = chip::Test::MockClusterId(3); + clusInfo2.mValue.mAttributeId = chip::Test::MockAttributeId(3); SingleLinkedListNode clusInfo3; - clusInfo3.mValue.mEndpointId = Test::kMockEndpoint3; + clusInfo3.mValue.mEndpointId = chip::Test::kMockEndpoint3; clusInfo3.mValue.mAttributeId = app::Clusters::Globals::Attributes::ClusterRevision::Id; SingleLinkedListNode clusInfo4; - clusInfo4.mValue.mEndpointId = Test::kMockEndpoint2; - clusInfo4.mValue.mClusterId = Test::MockClusterId(3); + clusInfo4.mValue.mEndpointId = chip::Test::kMockEndpoint2; + clusInfo4.mValue.mClusterId = chip::Test::MockClusterId(3); SingleLinkedListNode clusInfo5; - clusInfo5.mValue.mEndpointId = Test::kMockEndpoint2; - clusInfo5.mValue.mClusterId = Test::MockClusterId(3); - clusInfo5.mValue.mAttributeId = Test::MockAttributeId(3); + clusInfo5.mValue.mEndpointId = chip::Test::kMockEndpoint2; + clusInfo5.mValue.mClusterId = chip::Test::MockClusterId(3); + clusInfo5.mValue.mAttributeId = chip::Test::MockAttributeId(3); clusInfo1.mpNext = &clusInfo2; clusInfo2.mpNext = &clusInfo3; @@ -411,60 +417,11 @@ void TestMultipleClusInfo(nlTestSuite * apSuite, void * apContext) { ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId, ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId)); - NL_TEST_ASSERT(apSuite, index < ArraySize(paths) && paths[index] == path); + EXPECT_LT(index, ArraySize(paths)); + EXPECT_EQ(paths[index], path); index++; } - NL_TEST_ASSERT(apSuite, index == ArraySize(paths)); + EXPECT_EQ(index, ArraySize(paths)); } -static int TestSetup(void * inContext) -{ - return SUCCESS; -} - -/** - * Tear down the test suite. - */ -static int TestTeardown(void * inContext) -{ - return SUCCESS; -} - -/** - * Test Suite. It lists all the test functions. - */ - -// clang-format off -const nlTest sTests[] = -{ - NL_TEST_DEF("TestAllWildcard", TestAllWildcard), - NL_TEST_DEF("TestWildcardEndpoint", TestWildcardEndpoint), - NL_TEST_DEF("TestWildcardCluster", TestWildcardCluster), - NL_TEST_DEF("TestWildcardClusterGlobalAttributeNotInMetadata", - TestWildcardClusterGlobalAttributeNotInMetadata), - NL_TEST_DEF("TestWildcardAttribute", TestWildcardAttribute), - NL_TEST_DEF("TestNoWildcard", TestNoWildcard), - NL_TEST_DEF("TestMultipleClusInfo", TestMultipleClusInfo), - NL_TEST_SENTINEL() -}; -// clang-format on - -// clang-format off -nlTestSuite sSuite = -{ - "TestAttributePathExpandIterator", - &sTests[0], - TestSetup, - TestTeardown, -}; -// clang-format on - } // namespace - -int TestAttributePathExpandIterator() -{ - nlTestRunner(&sSuite, nullptr); - return (nlTestRunnerStats(&sSuite)); -} - -CHIP_REGISTER_TEST_SUITE(TestAttributePathExpandIterator) diff --git a/src/app/tests/TestAttributePersistenceProvider.cpp b/src/app/tests/TestAttributePersistenceProvider.cpp index 9c75715d14e03d..7ae40b52402fe0 100644 --- a/src/app/tests/TestAttributePersistenceProvider.cpp +++ b/src/app/tests/TestAttributePersistenceProvider.cpp @@ -16,17 +16,11 @@ * limitations under the License. */ -/** - * @file - * This file implements unit tests for AttributePersistenceProvider - * - */ - #include #include +#include #include -#include -#include +#include using namespace chip; using namespace chip::app; @@ -36,48 +30,36 @@ const ConcreteAttributePath TestConcretePath = ConcreteAttributePath(1, 1, 1); namespace { -/** - * Set up the test suite. - */ -int Test_Setup(void * inContext) -{ - CHIP_ERROR error = chip::Platform::MemoryInit(); - VerifyOrReturnError(error == CHIP_NO_ERROR, FAILURE); - return SUCCESS; -} - -/** - * Tear down the test suite. - */ -int Test_Teardown(void * inContext) +class TestAttributePersistenceProvider : public ::testing::Test { - chip::Platform::MemoryShutdown(); - return SUCCESS; -} +public: + static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); } + static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); } +}; /** * Tests the storage and retrival of data from the KVS as ByteSpan */ -void TestStorageAndRetrivalByteSpans(nlTestSuite * inSuite, void * inContext) +TEST_F(TestAttributePersistenceProvider, TestStorageAndRetrivalByteSpans) { TestPersistentStorageDelegate storageDelegate; DefaultAttributePersistenceProvider persistenceProvider; // Init ChipError err = persistenceProvider.Init(&storageDelegate); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); // Store ByteSpan of size 1 uint8_t valueArray[1] = { 0x42 }; ByteSpan value(valueArray); err = persistenceProvider.SafeWriteValue(TestConcretePath, value); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); uint8_t getArray[1]; MutableByteSpan valueReadBack(getArray); err = persistenceProvider.SafeReadValue(TestConcretePath, valueReadBack); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, std::equal(valueReadBack.begin(), valueReadBack.end(), value.begin(), value.end())); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_TRUE(std::equal(valueReadBack.begin(), valueReadBack.end(), value.begin(), value.end())); // Finishing persistenceProvider.Shutdown(); @@ -89,17 +71,16 @@ void TestStorageAndRetrivalByteSpans(nlTestSuite * inSuite, void * inContext) * @param testValue The test value to store and retrieve */ template -void testHelperStorageAndRetrivalScalarValues(nlTestSuite * inSuite, DefaultAttributePersistenceProvider & persistenceProvider, - T testValue) +void testHelperStorageAndRetrivalScalarValues(DefaultAttributePersistenceProvider & persistenceProvider, T testValue) { CHIP_ERROR err = persistenceProvider.WriteScalarValue(TestConcretePath, testValue); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); T valueReadBack = 0; err = persistenceProvider.ReadScalarValue(TestConcretePath, valueReadBack); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, valueReadBack == testValue); + EXPECT_EQ(valueReadBack, testValue); } /** @@ -108,55 +89,55 @@ void testHelperStorageAndRetrivalScalarValues(nlTestSuite * inSuite, DefaultAttr * @param testValue The test value to store and retrieve */ template -void testHelperStorageAndRetrivalScalarValues(nlTestSuite * inSuite, DefaultAttributePersistenceProvider & persistenceProvider, +void testHelperStorageAndRetrivalScalarValues(DefaultAttributePersistenceProvider & persistenceProvider, DataModel::Nullable testValue) { CHIP_ERROR err = persistenceProvider.WriteScalarValue(TestConcretePath, testValue); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DataModel::Nullable valueReadBack(0); err = persistenceProvider.ReadScalarValue(TestConcretePath, valueReadBack); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, valueReadBack == testValue); + EXPECT_EQ(valueReadBack, testValue); } /** * Tests the storage and retrival of data from the KVS of types bool, uint8_t, uint16_t, uint32_t, uint64_t. */ -void TestStorageAndRetrivalScalarValues(nlTestSuite * inSuite, void * inContext) +TEST_F(TestAttributePersistenceProvider, TestStorageAndRetrivalScalarValues) { TestPersistentStorageDelegate storageDelegate; DefaultAttributePersistenceProvider persistenceProvider; // Init CHIP_ERROR err = persistenceProvider.Init(&storageDelegate); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); // Test bool - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, bool(true)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, bool(false)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, bool(true)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, bool(true)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, bool(false)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, bool(true)); // Test uint8_t - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, uint8_t(0)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, uint8_t(42)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, uint8_t(0xff)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, uint8_t(0)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, uint8_t(42)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, uint8_t(0xff)); // Test uint16_t - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, uint16_t(0)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, uint16_t(0x0101)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, uint16_t(0xffff)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, uint16_t(0)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, uint16_t(0x0101)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, uint16_t(0xffff)); // Test uint32_t - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, uint32_t(0)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, uint32_t(0x01ffff)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, uint32_t(0xffffffff)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, uint32_t(0)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, uint32_t(0x01ffff)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, uint32_t(0xffffffff)); // Test uint64_t - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, uint64_t(0)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, uint64_t(0x0100000001)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, uint64_t(0xffffffffffffffff)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, uint64_t(0)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, uint64_t(0x0100000001)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, uint64_t(0xffffffffffffffff)); // Finishing persistenceProvider.Shutdown(); @@ -165,34 +146,34 @@ void TestStorageAndRetrivalScalarValues(nlTestSuite * inSuite, void * inContext) /** * Tests the storage and retrival of data from the KVS of types int8_t, int16_t, int32_t, int64_t. */ -void TestStorageAndRetrivalSignedScalarValues(nlTestSuite * inSuite, void * inContext) +TEST_F(TestAttributePersistenceProvider, TestStorageAndRetrivalSignedScalarValues) { TestPersistentStorageDelegate storageDelegate; DefaultAttributePersistenceProvider persistenceProvider; // Init CHIP_ERROR err = persistenceProvider.Init(&storageDelegate); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); // Test int8_t - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, int8_t(0)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, int8_t(42)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, int8_t(-127)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, int8_t(0)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, int8_t(42)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, int8_t(-127)); // Test int16_t - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, int16_t(0)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, int16_t(0x7fff)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, int16_t(0x8000)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, int16_t(0)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, int16_t(0x7fff)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, int16_t(0x8000)); // Test int32_t - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, int32_t(0)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, int32_t(0x7fffffff)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, int32_t(0x80000000)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, int32_t(0)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, int32_t(0x7fffffff)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, int32_t(0x80000000)); // Test int64_t - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, int64_t(0)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, int64_t(0x7fffffffffffffff)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, int64_t(0x8000000000000000)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, int64_t(0)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, int64_t(0x7fffffffffffffff)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, int64_t(0x8000000000000000)); // Finishing persistenceProvider.Shutdown(); @@ -201,54 +182,54 @@ void TestStorageAndRetrivalSignedScalarValues(nlTestSuite * inSuite, void * inCo /** * Tests the storage and retrival of data from the KVS of DataModel::Nullable types bool, uint8_t, uint16_t, uint32_t, uint64_t. */ -void TestStorageAndRetrivalNullableScalarValues(nlTestSuite * inSuite, void * inContext) +TEST_F(TestAttributePersistenceProvider, TestStorageAndRetrivalNullableScalarValues) { TestPersistentStorageDelegate storageDelegate; DefaultAttributePersistenceProvider persistenceProvider; // Init CHIP_ERROR err = persistenceProvider.Init(&storageDelegate); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); // Test bool - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(true)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(false)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(true)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(true)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(false)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(true)); auto nullValBool = DataModel::Nullable(); nullValBool.SetNull(); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, nullValBool); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, nullValBool); // Test uint8_t - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(0)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(42)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(0xfe)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(0)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(42)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(0xfe)); auto nullVal8 = DataModel::Nullable(); nullVal8.SetNull(); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, nullVal8); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, nullVal8); // Test uint16_t - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(0)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(0x0101)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(0xfffe)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(0)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(0x0101)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(0xfffe)); auto nullVal16 = DataModel::Nullable(); nullVal16.SetNull(); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, nullVal16); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, nullVal16); // Test uint32_t - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(0)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(0x01ffff)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(0xfffffffe)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(0)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(0x01ffff)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(0xfffffffe)); auto nullVal32 = DataModel::Nullable(); nullVal32.SetNull(); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, nullVal32); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, nullVal32); // Test uint64_t - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(0)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(0x0100000001)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(0xfffffffffffffffe)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(0)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(0x0100000001)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(0xfffffffffffffffe)); auto nullVal64 = DataModel::Nullable(); nullVal64.SetNull(); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, nullVal64); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, nullVal64); // Finishing persistenceProvider.Shutdown(); @@ -257,46 +238,46 @@ void TestStorageAndRetrivalNullableScalarValues(nlTestSuite * inSuite, void * in /** * Tests the storage and retrival of data from the KVS of DataModel::Nullable types int8_t, int16_t, int32_t, int64_t. */ -void TestStorageAndRetrivalSignedNullableScalarValues(nlTestSuite * inSuite, void * inContext) +TEST_F(TestAttributePersistenceProvider, TestStorageAndRetrivalSignedNullableScalarValues) { TestPersistentStorageDelegate storageDelegate; DefaultAttributePersistenceProvider persistenceProvider; // Init CHIP_ERROR err = persistenceProvider.Init(&storageDelegate); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); // Test int8_t - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(0)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(42)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(-127)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(0)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(42)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(-127)); auto nullVal8 = DataModel::Nullable(); nullVal8.SetNull(); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, nullVal8); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, nullVal8); // Test int16_t - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(0)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(0x7fff)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(-0x7fff)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(0)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(0x7fff)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(-0x7fff)); auto nullVal16 = DataModel::Nullable(); nullVal16.SetNull(); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, nullVal16); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, nullVal16); // Test int32_t - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(0)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(0x7fffffff)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(-0x7fffffff)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(0)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(0x7fffffff)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(-0x7fffffff)); auto nullVal32 = DataModel::Nullable(); nullVal32.SetNull(); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, nullVal32); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, nullVal32); // Test int64_t - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(0)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(0x7fffffffffffffff)); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, DataModel::Nullable(-0x7fffffffffffffff)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(0)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(0x7fffffffffffffff)); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, DataModel::Nullable(-0x7fffffffffffffff)); auto nullVal64 = DataModel::Nullable(); nullVal64.SetNull(); - testHelperStorageAndRetrivalScalarValues(inSuite, persistenceProvider, nullVal64); + testHelperStorageAndRetrivalScalarValues(persistenceProvider, nullVal64); // Finishing persistenceProvider.Shutdown(); @@ -305,85 +286,62 @@ void TestStorageAndRetrivalSignedNullableScalarValues(nlTestSuite * inSuite, voi /** * Test that the correct error is given when trying to read a value with a buffer that's too small. */ -void TestBufferTooSmallErrors(nlTestSuite * inSuite, void * inContext) +TEST_F(TestAttributePersistenceProvider, TestBufferTooSmallErrors) { TestPersistentStorageDelegate storageDelegate; DefaultAttributePersistenceProvider persistenceProvider; // Init CHIP_ERROR err = persistenceProvider.Init(&storageDelegate); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); // Store large data uint8_t valueArray[9] = { 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42 }; ByteSpan value(valueArray); err = persistenceProvider.SafeWriteValue(TestConcretePath, value); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); // Confirm the daya is there uint8_t getArray[9]; MutableByteSpan valueReadBack(getArray); err = persistenceProvider.SafeReadValue(TestConcretePath, valueReadBack); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, std::equal(valueReadBack.begin(), valueReadBack.end(), value.begin(), value.end())); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_TRUE(std::equal(valueReadBack.begin(), valueReadBack.end(), value.begin(), value.end())); // Fail to get data as ByteSpace of size 0 uint8_t getArray0[0]; MutableByteSpan valueReadBackByteSpan0(getArray0, 0); err = persistenceProvider.SafeReadValue(TestConcretePath, valueReadBackByteSpan0); - NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUFFER_TOO_SMALL); + EXPECT_EQ(err, CHIP_ERROR_BUFFER_TOO_SMALL); // Fail to get data as ByteSpace of size > 0 but < required uint8_t getArray8[8]; MutableByteSpan valueReadBackByteSpan8(getArray8, sizeof(getArray8)); err = persistenceProvider.SafeReadValue(TestConcretePath, valueReadBackByteSpan8); - NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUFFER_TOO_SMALL); + EXPECT_EQ(err, CHIP_ERROR_BUFFER_TOO_SMALL); // Fail to get value as uint8_t uint8_t valueReadBack8; err = persistenceProvider.ReadScalarValue(TestConcretePath, valueReadBack8); - NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUFFER_TOO_SMALL); + EXPECT_EQ(err, CHIP_ERROR_BUFFER_TOO_SMALL); // Fail to get value as uint16_t uint16_t valueReadBack16; err = persistenceProvider.ReadScalarValue(TestConcretePath, valueReadBack16); - NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUFFER_TOO_SMALL); + EXPECT_EQ(err, CHIP_ERROR_BUFFER_TOO_SMALL); // Fail to get value as uint32_t uint32_t valueReadBack32; err = persistenceProvider.ReadScalarValue(TestConcretePath, valueReadBack32); - NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUFFER_TOO_SMALL); + EXPECT_EQ(err, CHIP_ERROR_BUFFER_TOO_SMALL); // Fail to get value as uint64_t uint64_t valueReadBack64; err = persistenceProvider.ReadScalarValue(TestConcretePath, valueReadBack64); - NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUFFER_TOO_SMALL); + EXPECT_EQ(err, CHIP_ERROR_BUFFER_TOO_SMALL); // Finishing persistenceProvider.Shutdown(); } } // anonymous namespace - -namespace { -const nlTest sTests[] = { - NL_TEST_DEF("Storage and retrival of ByteSpans", TestStorageAndRetrivalByteSpans), - NL_TEST_DEF("Storage and retrival of unsigned scalar values", TestStorageAndRetrivalScalarValues), - NL_TEST_DEF("Storage and retrival of signed scalar values", TestStorageAndRetrivalSignedScalarValues), - NL_TEST_DEF("Storage and retrival of unsigned nullable scalar values", TestStorageAndRetrivalNullableScalarValues), - NL_TEST_DEF("Storage and retrival of signed nullable scalar values", TestStorageAndRetrivalSignedNullableScalarValues), - NL_TEST_DEF("Small buffer errors", TestBufferTooSmallErrors), - NL_TEST_SENTINEL() -}; -} - -int TestAttributePersistenceProvider() -{ - nlTestSuite theSuite = { "AttributePersistenceProvider", &sTests[0], Test_Setup, Test_Teardown }; - - nlTestRunner(&theSuite, nullptr); - - return (nlTestRunnerStats(&theSuite)); -} - -CHIP_REGISTER_TEST_SUITE(TestAttributePersistenceProvider) diff --git a/src/app/tests/TestAttributeValueDecoder.cpp b/src/app/tests/TestAttributeValueDecoder.cpp index c25738588e6afa..b48cd230ea2537 100644 --- a/src/app/tests/TestAttributeValueDecoder.cpp +++ b/src/app/tests/TestAttributeValueDecoder.cpp @@ -16,18 +16,13 @@ * limitations under the License. */ -/** - * @file - * This file implements unit tests for CommandPathParams - * - */ +#include +#include #include #include #include #include -#include -#include using namespace chip; using namespace chip::app; @@ -62,7 +57,7 @@ struct TestSetup TLVWriter writer; }; -void TestOverwriteFabricIndexInStruct(nlTestSuite * aSuite, void * aContext) +TEST(TestAttributeValueDecoder, TestOverwriteFabricIndexInStruct) { TestSetup setup; CHIP_ERROR err; @@ -73,29 +68,29 @@ void TestOverwriteFabricIndexInStruct(nlTestSuite * aSuite, void * aContext) item.fabricIndex = 0; err = setup.Encode(item); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); TLV::TLVReader reader; TLVType ignored; reader.Init(setup.buf, setup.writer.GetLengthWritten()); err = reader.Next(); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = reader.EnterContainer(ignored); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = reader.Next(); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); AttributeValueDecoder decoder(reader, subjectDescriptor); err = decoder.Decode(decodeItem); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, decodeItem.fabricIndex == kTestFabricIndex); + EXPECT_EQ(decodeItem.fabricIndex, kTestFabricIndex); } -void TestOverwriteFabricIndexInListOfStructs(nlTestSuite * aSuite, void * aContext) +TEST(TestAttributeValueDecoder, TestOverwriteFabricIndexInListOfStructs) { TestSetup setup; CHIP_ERROR err; @@ -109,7 +104,7 @@ void TestOverwriteFabricIndexInListOfStructs(nlTestSuite * aSuite, void * aConte } err = setup.Encode(DataModel::List(items)); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); TLV::TLVReader reader; TLVType ignored; @@ -118,44 +113,27 @@ void TestOverwriteFabricIndexInListOfStructs(nlTestSuite * aSuite, void * aConte reader.Init(setup.buf, setup.writer.GetLengthWritten()); err = reader.Next(); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = reader.EnterContainer(ignored); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = reader.Next(); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); AttributeValueDecoder decoder(reader, subjectDescriptor); err = decoder.Decode(decodeItems); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = decodeItems.ComputeSize(&decodeCount); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, decodeCount == kTestListElements); + EXPECT_EQ(decodeCount, kTestListElements); for (auto iter = decodeItems.begin(); iter.Next();) { const auto & entry = iter.GetValue(); - NL_TEST_ASSERT(aSuite, entry.fabricIndex == kTestFabricIndex); + EXPECT_EQ(entry.fabricIndex, kTestFabricIndex); } } } // anonymous namespace - -namespace { -const nlTest sTests[] = { NL_TEST_DEF("TestOverwriteFabricIndexInStruct", TestOverwriteFabricIndexInStruct), - NL_TEST_DEF("TestOverwriteFabricIndexInListOfStructs", TestOverwriteFabricIndexInListOfStructs), - NL_TEST_SENTINEL() }; -} - -int TestAttributeValueDecoder() -{ - nlTestSuite theSuite = { "AttributeValueDecoder", &sTests[0], nullptr, nullptr }; - - nlTestRunner(&theSuite, nullptr); - - return (nlTestRunnerStats(&theSuite)); -} - -CHIP_REGISTER_TEST_SUITE(TestAttributeValueDecoder) diff --git a/src/app/tests/TestAttributeValueEncoder.cpp b/src/app/tests/TestAttributeValueEncoder.cpp index 085c4f870cdf64..43a015d27c4b9e 100644 --- a/src/app/tests/TestAttributeValueEncoder.cpp +++ b/src/app/tests/TestAttributeValueEncoder.cpp @@ -16,11 +16,10 @@ * limitations under the License. */ -/** - * @file - * This file implements unit tests for CommandPathParams - * - */ +#include + +#include +#include #include #include @@ -30,10 +29,6 @@ #include #include #include -#include -#include - -#include using namespace chip; using namespace chip::app; @@ -75,7 +70,7 @@ Access::SubjectDescriptor DescriptorWithFabric(FabricIndex fabricIndex) template struct LimitedTestSetup { - LimitedTestSetup(nlTestSuite * aSuite, const FabricIndex aFabricIndex = kUndefinedFabricIndex, + LimitedTestSetup(const FabricIndex aFabricIndex = kUndefinedFabricIndex, const AttributeEncodeState & aState = AttributeEncodeState()) : encoder(builder, DescriptorWithFabric(aFabricIndex), ConcreteAttributePath(kRandomEndpointId, kRandomClusterId, kRandomAttributeId), kRandomDataVersion, @@ -85,11 +80,11 @@ struct LimitedTestSetup { TLVType ignored; CHIP_ERROR err = writer.StartContainer(AnonymousTag(), kTLVType_Structure, ignored); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); } { CHIP_ERROR err = builder.Init(&writer, 1); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); } } @@ -103,11 +98,11 @@ using TestSetup = LimitedTestSetup<1024>; // Macro so we get better error reporting in terms of which test failed, because // the reporting uses __LINE__. -#define VERIFY_BUFFER_STATE(aSuite, aSetup, aExpected) \ +#define VERIFY_BUFFER_STATE(aSetup, aExpected) \ do \ { \ - NL_TEST_ASSERT(aSuite, aSetup.writer.GetLengthWritten() == sizeof(aExpected)); \ - NL_TEST_ASSERT(aSuite, memcmp(aSetup.buf, aExpected, sizeof(aExpected)) == 0); \ + EXPECT_EQ(aSetup.writer.GetLengthWritten(), sizeof(aExpected)); \ + EXPECT_EQ(memcmp(aSetup.buf, aExpected, sizeof(aExpected)), 0); \ if (aSetup.writer.GetLengthWritten() != sizeof(aExpected) || memcmp(aSetup.buf, aExpected, sizeof(aExpected)) != 0) \ { \ printf("Encoded: \n"); \ @@ -125,19 +120,19 @@ using TestSetup = LimitedTestSetup<1024>; } \ } while (0) -void TestEncodeNothing(nlTestSuite * aSuite, void * aContext) +TEST(TestAttributeValueEncoder, TestEncodeNothing) { - TestSetup test(aSuite); + TestSetup test{}; // Just have an anonymous struct marker, and the AttributeReportIBs opened. const uint8_t expected[] = { 0x15, 0x36, 0x01 }; - VERIFY_BUFFER_STATE(aSuite, test, expected); + VERIFY_BUFFER_STATE(test, expected); } -void TestEncodeBool(nlTestSuite * aSuite, void * aContext) +TEST(TestAttributeValueEncoder, TestEncodeBool) { - TestSetup test(aSuite); + TestSetup test{}; CHIP_ERROR err = test.encoder.Encode(true); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); const uint8_t expected[] = { // clang-format off 0x15, 0x36, 0x01, // Test overhead, Start Anonymous struct + Start 1 byte Tag Array + Tag (01) @@ -154,15 +149,15 @@ void TestEncodeBool(nlTestSuite * aSuite, void * aContext) 0x18, // End of container // clang-format on }; - VERIFY_BUFFER_STATE(aSuite, test, expected); + VERIFY_BUFFER_STATE(test, expected); } -void TestEncodeListOfBools1(nlTestSuite * aSuite, void * aContext) +TEST(TestAttributeValueEncoder, TestEncodeListOfBools1) { - TestSetup test(aSuite); + TestSetup test{}; bool list[] = { true, false }; CHIP_ERROR err = test.encoder.Encode(DataModel::List(list)); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); const uint8_t expected[] = { // clang-format off 0x15, 0x36, 0x01, // Test overhead, Start Anonymous struct + Start 1 byte Tag Array + Tag (01) @@ -182,12 +177,12 @@ void TestEncodeListOfBools1(nlTestSuite * aSuite, void * aContext) 0x18, // End of attribute structure // clang-format on }; - VERIFY_BUFFER_STATE(aSuite, test, expected); + VERIFY_BUFFER_STATE(test, expected); } -void TestEncodeListOfBools2(nlTestSuite * aSuite, void * aContext) +TEST(TestAttributeValueEncoder, TestEncodeListOfBools2) { - TestSetup test(aSuite); + TestSetup test{}; bool list[] = { true, false }; CHIP_ERROR err = test.encoder.EncodeList([&list](const auto & encoder) -> CHIP_ERROR { for (auto & item : list) @@ -196,7 +191,7 @@ void TestEncodeListOfBools2(nlTestSuite * aSuite, void * aContext) } return CHIP_NO_ERROR; }); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); const uint8_t expected[] = { // clang-format off 0x15, 0x36, 0x01, // Test overhead, Start Anonymous struct + Start 1 byte Tag Array + Tag (01) @@ -216,7 +211,7 @@ void TestEncodeListOfBools2(nlTestSuite * aSuite, void * aContext) 0x18, // End of attribute structure // clang-format on }; - VERIFY_BUFFER_STATE(aSuite, test, expected); + VERIFY_BUFFER_STATE(test, expected); } constexpr uint8_t emptyListExpected[] = { @@ -238,25 +233,25 @@ constexpr uint8_t emptyListExpected[] = { // clang-format on }; -void TestEncodeEmptyList1(nlTestSuite * aSuite, void * aContext) +TEST(TestAttributeValueEncoder, TestEncodeEmptyList1) { - TestSetup test(aSuite); + TestSetup test{}; CHIP_ERROR err = test.encoder.EncodeList([](const auto & encoder) -> CHIP_ERROR { return CHIP_NO_ERROR; }); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); - VERIFY_BUFFER_STATE(aSuite, test, emptyListExpected); + EXPECT_EQ(err, CHIP_NO_ERROR); + VERIFY_BUFFER_STATE(test, emptyListExpected); } -void TestEncodeEmptyList2(nlTestSuite * aSuite, void * aContext) +TEST(TestAttributeValueEncoder, TestEncodeEmptyList2) { - TestSetup test(aSuite); + TestSetup test{}; CHIP_ERROR err = test.encoder.EncodeEmptyList(); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); - VERIFY_BUFFER_STATE(aSuite, test, emptyListExpected); + EXPECT_EQ(err, CHIP_NO_ERROR); + VERIFY_BUFFER_STATE(test, emptyListExpected); } -void TestEncodeFabricScoped(nlTestSuite * aSuite, void * aContext) +TEST(TestAttributeValueEncoder, TestEncodeFabricScoped) { - TestSetup test(aSuite, kTestFabricIndex); + TestSetup test(kTestFabricIndex); Clusters::AccessControl::Structs::AccessControlExtensionStruct::Type items[3]; items[0].fabricIndex = 1; items[1].fabricIndex = 2; @@ -270,7 +265,7 @@ void TestEncodeFabricScoped(nlTestSuite * aSuite, void * aContext) } return CHIP_NO_ERROR; }); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); const uint8_t expected[] = { // clang-format off 0x15, 0x36, 0x01, // Test overhead, Start Anonymous struct + Start 1 byte Tag Array + Tag (01) @@ -292,10 +287,10 @@ void TestEncodeFabricScoped(nlTestSuite * aSuite, void * aContext) 0x18, // End of attribute structure // clang-format on }; - VERIFY_BUFFER_STATE(aSuite, test, expected); + VERIFY_BUFFER_STATE(test, expected); } -void TestEncodeListChunking(nlTestSuite * aSuite, void * aContext) +TEST(TestAttributeValueEncoder, TestEncodeListChunking) { AttributeEncodeState state; @@ -316,9 +311,9 @@ void TestEncodeListChunking(nlTestSuite * aSuite, void * aContext) // corresponding to the "test overhead" container starts. But TLVWriter automatically // reserves space when containers are opened, so we have to have enough space to have // encoded those last two close containers. - LimitedTestSetup<30> test1(aSuite, kTestFabricIndex); + LimitedTestSetup<30> test1(kTestFabricIndex); CHIP_ERROR err = test1.encoder.EncodeList(listEncoder); - NL_TEST_ASSERT(aSuite, err == CHIP_ERROR_NO_MEMORY || err == CHIP_ERROR_BUFFER_TOO_SMALL); + EXPECT_TRUE(err == CHIP_ERROR_NO_MEMORY || err == CHIP_ERROR_BUFFER_TOO_SMALL); state = test1.encoder.GetState(); const uint8_t expected[] = { @@ -340,14 +335,14 @@ void TestEncodeListChunking(nlTestSuite * aSuite, void * aContext) 0x18, // End of attribute structure // clang-format on }; - VERIFY_BUFFER_STATE(aSuite, test1, expected); + VERIFY_BUFFER_STATE(test1, expected); } { // Use 30 bytes buffer to force chunking after the second "false". The kTestFabricIndex is // not effective in this test. - LimitedTestSetup<30> test2(aSuite, 0, state); + LimitedTestSetup<30> test2(0, state); CHIP_ERROR err = test2.encoder.EncodeList(listEncoder); - NL_TEST_ASSERT(aSuite, err == CHIP_ERROR_NO_MEMORY || err == CHIP_ERROR_BUFFER_TOO_SMALL); + EXPECT_TRUE(err == CHIP_ERROR_NO_MEMORY || err == CHIP_ERROR_BUFFER_TOO_SMALL); state = test2.encoder.GetState(); const uint8_t expected[] = { @@ -367,13 +362,13 @@ void TestEncodeListChunking(nlTestSuite * aSuite, void * aContext) 0x18, // End of container // clang-format on }; - VERIFY_BUFFER_STATE(aSuite, test2, expected); + VERIFY_BUFFER_STATE(test2, expected); } { // Allow encoding everything else. The kTestFabricIndex is not effective in this test. - TestSetup test3(aSuite, 0, state); + TestSetup test3(0, state); CHIP_ERROR err = test3.encoder.EncodeList(listEncoder); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); const uint8_t expected[] = { // clang-format off @@ -416,11 +411,11 @@ void TestEncodeListChunking(nlTestSuite * aSuite, void * aContext) 0x18, // End of container // clang-format on }; - VERIFY_BUFFER_STATE(aSuite, test3, expected); + VERIFY_BUFFER_STATE(test3, expected); } } -void TestEncodeListChunking2(nlTestSuite * aSuite, void * aContext) +TEST(TestAttributeValueEncoder, TestEncodeListChunking2) { AttributeEncodeState state; @@ -441,9 +436,9 @@ void TestEncodeListChunking2(nlTestSuite * aSuite, void * aContext) // corresponding to the "test overhead" container starts. But TLVWriter automatically // reserves space when containers are opened, so we have to have enough space to have // encoded those last two close containers. - LimitedTestSetup<28> test1(aSuite, kTestFabricIndex); + LimitedTestSetup<28> test1(kTestFabricIndex); CHIP_ERROR err = test1.encoder.EncodeList(listEncoder); - NL_TEST_ASSERT(aSuite, err == CHIP_ERROR_NO_MEMORY || err == CHIP_ERROR_BUFFER_TOO_SMALL); + EXPECT_TRUE(err == CHIP_ERROR_NO_MEMORY || err == CHIP_ERROR_BUFFER_TOO_SMALL); state = test1.encoder.GetState(); const uint8_t expected[] = { @@ -463,14 +458,14 @@ void TestEncodeListChunking2(nlTestSuite * aSuite, void * aContext) 0x18, // End of attribute structure // clang-format on }; - VERIFY_BUFFER_STATE(aSuite, test1, expected); + VERIFY_BUFFER_STATE(test1, expected); } { // Use 30 bytes buffer to force chunking after the first "true". The kTestFabricIndex is not // effective in this test. - LimitedTestSetup<30> test2(aSuite, 0, state); + LimitedTestSetup<30> test2(0, state); CHIP_ERROR err = test2.encoder.EncodeList(listEncoder); - NL_TEST_ASSERT(aSuite, err == CHIP_ERROR_NO_MEMORY || err == CHIP_ERROR_BUFFER_TOO_SMALL); + EXPECT_TRUE(err == CHIP_ERROR_NO_MEMORY || err == CHIP_ERROR_BUFFER_TOO_SMALL); state = test2.encoder.GetState(); const uint8_t expected[] = { @@ -490,14 +485,14 @@ void TestEncodeListChunking2(nlTestSuite * aSuite, void * aContext) 0x18, // End of container // clang-format on }; - VERIFY_BUFFER_STATE(aSuite, test2, expected); + VERIFY_BUFFER_STATE(test2, expected); } { // Use 60 bytes buffer to force chunking after the second "false". The kTestFabricIndex is not // effective in this test. - LimitedTestSetup<60> test3(aSuite, 0, state); + LimitedTestSetup<60> test3(0, state); CHIP_ERROR err = test3.encoder.EncodeList(listEncoder); - NL_TEST_ASSERT(aSuite, err == CHIP_ERROR_NO_MEMORY || err == CHIP_ERROR_BUFFER_TOO_SMALL); + EXPECT_TRUE(err == CHIP_ERROR_NO_MEMORY || err == CHIP_ERROR_BUFFER_TOO_SMALL); state = test3.encoder.GetState(); const uint8_t expected[] = { @@ -529,13 +524,13 @@ void TestEncodeListChunking2(nlTestSuite * aSuite, void * aContext) 0x18, // End of container // clang-format on }; - VERIFY_BUFFER_STATE(aSuite, test3, expected); + VERIFY_BUFFER_STATE(test3, expected); } { // Allow encoding everything else. The kTestFabricIndex is not effective in this test. - TestSetup test4(aSuite, 0, state); + TestSetup test4(0, state); CHIP_ERROR err = test4.encoder.EncodeList(listEncoder); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); const uint8_t expected[] = { // clang-format off @@ -578,27 +573,27 @@ void TestEncodeListChunking2(nlTestSuite * aSuite, void * aContext) 0x18, // End of container // clang-format on }; - VERIFY_BUFFER_STATE(aSuite, test4, expected); + VERIFY_BUFFER_STATE(test4, expected); } } -void TestEncodePreEncoded(nlTestSuite * aSuite, void * aContext) +TEST(TestAttributeValueEncoder, TestEncodePreEncoded) { - TestSetup test(aSuite); + TestSetup test{}; uint8_t buffer[128]; TLV::TLVWriter writer; writer.Init(buffer); // Use a random tag that is not the right tag. CHIP_ERROR err = writer.PutString(TLV::ProfileTag(0x1234abcd, 0x5678fedc), "hello"); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = writer.Finalize(); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); ByteSpan value(buffer, writer.GetLengthWritten()); err = test.encoder.Encode(DataModel::PreEncodedValue(value)); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); const uint8_t expected[] = { // clang-format off @@ -616,12 +611,12 @@ void TestEncodePreEncoded(nlTestSuite * aSuite, void * aContext) 0x18, // End of container // clang-format on }; - VERIFY_BUFFER_STATE(aSuite, test, expected); + VERIFY_BUFFER_STATE(test, expected); } -void TestEncodeListOfPreEncoded(nlTestSuite * aSuite, void * aContext) +TEST(TestAttributeValueEncoder, TestEncodeListOfPreEncoded) { - TestSetup test(aSuite); + TestSetup test{}; uint8_t buffers[2][128]; std::optional values[2]; @@ -631,10 +626,10 @@ void TestEncodeListOfPreEncoded(nlTestSuite * aSuite, void * aContext) writer.Init(buffers[0]); // Use a random tag that is not the right tag. CHIP_ERROR err = writer.PutString(TLV::ProfileTag(0x1234abcd, 0x5678fedc), "hello"); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = writer.Finalize(); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); values[0].emplace(ByteSpan(buffers[0], writer.GetLengthWritten())); } @@ -644,10 +639,10 @@ void TestEncodeListOfPreEncoded(nlTestSuite * aSuite, void * aContext) writer.Init(buffers[1]); // Use a random tag that is not the right tag. CHIP_ERROR err = writer.PutString(TLV::ProfileTag(0x1234abcd, 0x00010002), "bye"); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = writer.Finalize(); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); values[1].emplace(ByteSpan(buffers[1], writer.GetLengthWritten())); } @@ -659,7 +654,7 @@ void TestEncodeListOfPreEncoded(nlTestSuite * aSuite, void * aContext) } return CHIP_NO_ERROR; }); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); const uint8_t expected[] = { // clang-format off @@ -680,12 +675,12 @@ void TestEncodeListOfPreEncoded(nlTestSuite * aSuite, void * aContext) 0x18, // End of container // clang-format on }; - VERIFY_BUFFER_STATE(aSuite, test, expected); + VERIFY_BUFFER_STATE(test, expected); } -void TestEncodeListOfFabricScopedPreEncoded(nlTestSuite * aSuite, void * aContext) +TEST(TestAttributeValueEncoder, TestEncodeListOfFabricScopedPreEncoded) { - TestSetup test(aSuite); + TestSetup test{}; uint8_t buffers[2][128]; std::optional values[2]; @@ -697,19 +692,19 @@ void TestEncodeListOfFabricScopedPreEncoded(nlTestSuite * aSuite, void * aContex TLV::TLVType outerContainerType; CHIP_ERROR err = writer.StartContainer(TLV::ProfileTag(0x1234abcd, 0x5678fedc), TLV::kTLVType_Structure, outerContainerType); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = writer.PutString(TLV::ContextTag(7), "hello"); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = writer.Put(kFabricIndexTag, kTestFabricIndex); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = writer.EndContainer(outerContainerType); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = writer.Finalize(); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); values[0].emplace(ByteSpan(buffers[0], writer.GetLengthWritten())); } @@ -721,19 +716,19 @@ void TestEncodeListOfFabricScopedPreEncoded(nlTestSuite * aSuite, void * aContex TLV::TLVType outerContainerType; CHIP_ERROR err = writer.StartContainer(TLV::ProfileTag(0x1234abcd, 0x00010002), TLV::kTLVType_Structure, outerContainerType); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = writer.PutString(TLV::ContextTag(7), "bye"); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = writer.Put(kFabricIndexTag, static_cast(kTestFabricIndex + 1)); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = writer.EndContainer(outerContainerType); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = writer.Finalize(); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); values[1].emplace(ByteSpan(buffers[1], writer.GetLengthWritten())); } @@ -745,7 +740,7 @@ void TestEncodeListOfFabricScopedPreEncoded(nlTestSuite * aSuite, void * aContex } return CHIP_NO_ERROR; }); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); const uint8_t expected[] = { // clang-format off @@ -772,12 +767,12 @@ void TestEncodeListOfFabricScopedPreEncoded(nlTestSuite * aSuite, void * aContex 0x18, // End of container // clang-format on }; - VERIFY_BUFFER_STATE(aSuite, test, expected); + VERIFY_BUFFER_STATE(test, expected); } -void TestEncodeFabricFilteredListOfPreEncoded(nlTestSuite * aSuite, void * aContext) +TEST(TestAttributeValueEncoder, TestEncodeFabricFilteredListOfPreEncoded) { - TestSetup test(aSuite, kTestFabricIndex); + TestSetup test(kTestFabricIndex); uint8_t buffers[2][128]; std::optional values[2]; @@ -789,19 +784,19 @@ void TestEncodeFabricFilteredListOfPreEncoded(nlTestSuite * aSuite, void * aCont TLV::TLVType outerContainerType; CHIP_ERROR err = writer.StartContainer(TLV::ProfileTag(0x1234abcd, 0x5678fedc), TLV::kTLVType_Structure, outerContainerType); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = writer.PutString(TLV::ContextTag(7), "hello"); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = writer.Put(kFabricIndexTag, kTestFabricIndex); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = writer.EndContainer(outerContainerType); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = writer.Finalize(); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); values[0].emplace(ByteSpan(buffers[0], writer.GetLengthWritten())); } @@ -813,19 +808,19 @@ void TestEncodeFabricFilteredListOfPreEncoded(nlTestSuite * aSuite, void * aCont TLV::TLVType outerContainerType; CHIP_ERROR err = writer.StartContainer(TLV::ProfileTag(0x1234abcd, 0x00010002), TLV::kTLVType_Structure, outerContainerType); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = writer.PutString(TLV::ContextTag(7), "bye"); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = writer.Put(kFabricIndexTag, static_cast(kTestFabricIndex + 1)); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = writer.EndContainer(outerContainerType); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = writer.Finalize(); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); values[1].emplace(ByteSpan(buffers[1], writer.GetLengthWritten())); } @@ -837,7 +832,7 @@ void TestEncodeFabricFilteredListOfPreEncoded(nlTestSuite * aSuite, void * aCont } return CHIP_NO_ERROR; }); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); const uint8_t expected[] = { // clang-format off @@ -861,42 +856,9 @@ void TestEncodeFabricFilteredListOfPreEncoded(nlTestSuite * aSuite, void * aCont 0x18, // End of container // clang-format on }; - VERIFY_BUFFER_STATE(aSuite, test, expected); + VERIFY_BUFFER_STATE(test, expected); } #undef VERIFY_BUFFER_STATE } // anonymous namespace - -namespace { -const nlTest sTests[] = { - // clang-format off - NL_TEST_DEF("TestEncodeNothing", TestEncodeNothing), - NL_TEST_DEF("TestEncodeBool", TestEncodeBool), - NL_TEST_DEF("TestEncodeEmptyList1", TestEncodeEmptyList1), - NL_TEST_DEF("TestEncodeEmptyList2", TestEncodeEmptyList2), - NL_TEST_DEF("TestEncodeListOfBools1", TestEncodeListOfBools1), - NL_TEST_DEF("TestEncodeListOfBools2", TestEncodeListOfBools2), - NL_TEST_DEF("TestEncodeListChunking", TestEncodeListChunking), - NL_TEST_DEF("TestEncodeListChunking2", TestEncodeListChunking2), - NL_TEST_DEF("TestEncodeFabricScoped", TestEncodeFabricScoped), - NL_TEST_DEF("TestEncodePreEncoded", TestEncodePreEncoded), - NL_TEST_DEF("TestEncodeListOfPreEncoded", TestEncodeListOfPreEncoded), - NL_TEST_DEF("TestEncodeListFabricScopedPreEncoded", TestEncodeListOfPreEncoded), - NL_TEST_DEF("TestEncodeListOfFabricScopedPreEncoded", TestEncodeListOfFabricScopedPreEncoded), - NL_TEST_DEF("TestEncodeFabricFilteredListOfPreEncoded", TestEncodeFabricFilteredListOfPreEncoded), - NL_TEST_SENTINEL() - // clang-format on -}; -} - -int TestAttributeValueEncoder() -{ - nlTestSuite theSuite = { "AttributeValueEncoder", &sTests[0], nullptr, nullptr }; - - nlTestRunner(&theSuite, nullptr); - - return (nlTestRunnerStats(&theSuite)); -} - -CHIP_REGISTER_TEST_SUITE(TestAttributeValueEncoder) diff --git a/src/app/tests/TestBindingTable.cpp b/src/app/tests/TestBindingTable.cpp index db95408813a0c1..a4d5d0e2fcf6a7 100644 --- a/src/app/tests/TestBindingTable.cpp +++ b/src/app/tests/TestBindingTable.cpp @@ -15,122 +15,122 @@ * limitations under the License. */ +#include +#include + #include #include #include #include #include -#include using chip::BindingTable; namespace { -void TestEmptyBindingTable(nlTestSuite * aSuite, void * aContext) +void VerifyTableSame(BindingTable & table, const std::vector & expected) +{ + ASSERT_EQ(table.Size(), expected.size()); + auto iter1 = table.begin(); + auto iter2 = expected.begin(); + while (iter2 != expected.end()) + { + EXPECT_EQ(*iter1, *iter2); + ++iter1; + ++iter2; + } + EXPECT_EQ(iter1, table.end()); +} + +void VerifyRestored(chip::TestPersistentStorageDelegate & storage, const std::vector & expected) +{ + BindingTable restoredTable; + restoredTable.SetPersistentStorage(&storage); + EXPECT_EQ(restoredTable.LoadFromStorage(), CHIP_NO_ERROR); + VerifyTableSame(restoredTable, expected); +} + +TEST(TestBindingTable, TestEmptyBindingTable) { BindingTable table; chip::TestPersistentStorageDelegate testStorage; table.SetPersistentStorage(&testStorage); - NL_TEST_ASSERT(aSuite, table.Size() == 0); - NL_TEST_ASSERT(aSuite, table.begin() == table.end()); + EXPECT_EQ(table.Size(), 0u); + EXPECT_EQ(table.begin(), table.end()); } -void TestAdd(nlTestSuite * aSuite, void * aContext) +TEST(TestBindingTable, TestAdd) { BindingTable table; chip::TestPersistentStorageDelegate testStorage; table.SetPersistentStorage(&testStorage); EmberBindingTableEntry unusedEntry; unusedEntry.type = MATTER_UNUSED_BINDING; - NL_TEST_ASSERT(aSuite, table.Add(unusedEntry) == CHIP_ERROR_INVALID_ARGUMENT); + EXPECT_EQ(table.Add(unusedEntry), CHIP_ERROR_INVALID_ARGUMENT); for (uint8_t i = 0; i < MATTER_BINDING_TABLE_SIZE; i++) { - NL_TEST_ASSERT(aSuite, table.Add(EmberBindingTableEntry::ForNode(0, i, 0, 0, std::nullopt)) == CHIP_NO_ERROR); + EXPECT_EQ(table.Add(EmberBindingTableEntry::ForNode(0, i, 0, 0, std::nullopt)), CHIP_NO_ERROR); } - NL_TEST_ASSERT(aSuite, table.Add(EmberBindingTableEntry::ForNode(0, 0, 0, 0, std::nullopt)) == CHIP_ERROR_NO_MEMORY); - NL_TEST_ASSERT(aSuite, table.Size() == MATTER_BINDING_TABLE_SIZE); + EXPECT_EQ(table.Add(EmberBindingTableEntry::ForNode(0, 0, 0, 0, std::nullopt)), CHIP_ERROR_NO_MEMORY); + EXPECT_EQ(table.Size(), MATTER_BINDING_TABLE_SIZE); auto iter = table.begin(); for (uint8_t i = 0; i < MATTER_BINDING_TABLE_SIZE; i++) { - NL_TEST_ASSERT(aSuite, iter != table.end()); - NL_TEST_ASSERT(aSuite, iter->nodeId == i); - NL_TEST_ASSERT(aSuite, iter.GetIndex() == i); + EXPECT_NE(iter, table.end()); + EXPECT_EQ(iter->nodeId, i); + EXPECT_EQ(iter.GetIndex(), i); ++iter; } - NL_TEST_ASSERT(aSuite, iter == table.end()); + EXPECT_EQ(iter, table.end()); } -void TestRemoveThenAdd(nlTestSuite * aSuite, void * aContext) +TEST(TestBindingTable, TestRemoveThenAdd) { BindingTable table; chip::TestPersistentStorageDelegate testStorage; table.SetPersistentStorage(&testStorage); - NL_TEST_ASSERT(aSuite, table.Add(EmberBindingTableEntry::ForNode(0, 0, 0, 0, std::nullopt)) == CHIP_NO_ERROR); + EXPECT_EQ(table.Add(EmberBindingTableEntry::ForNode(0, 0, 0, 0, std::nullopt)), CHIP_NO_ERROR); auto iter = table.begin(); - NL_TEST_ASSERT(aSuite, table.RemoveAt(iter) == CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, iter == table.end()); - NL_TEST_ASSERT(aSuite, table.Size() == 0); - NL_TEST_ASSERT(aSuite, table.begin() == table.end()); + EXPECT_EQ(table.RemoveAt(iter), CHIP_NO_ERROR); + EXPECT_EQ(iter, table.end()); + EXPECT_EQ(table.Size(), 0u); + EXPECT_EQ(table.begin(), table.end()); for (uint8_t i = 0; i < MATTER_BINDING_TABLE_SIZE; i++) { - NL_TEST_ASSERT(aSuite, table.Add(EmberBindingTableEntry::ForNode(0, i, 0, 0, std::nullopt)) == CHIP_NO_ERROR); + EXPECT_EQ(table.Add(EmberBindingTableEntry::ForNode(0, i, 0, 0, std::nullopt)), CHIP_NO_ERROR); } iter = table.begin(); ++iter; - NL_TEST_ASSERT(aSuite, table.RemoveAt(iter) == CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, table.Size() == MATTER_BINDING_TABLE_SIZE - 1); - NL_TEST_ASSERT(aSuite, iter->nodeId == 2); - NL_TEST_ASSERT(aSuite, iter.GetIndex() == 2); + EXPECT_EQ(table.RemoveAt(iter), CHIP_NO_ERROR); + EXPECT_EQ(table.Size(), MATTER_BINDING_TABLE_SIZE - 1); + EXPECT_EQ(iter->nodeId, 2u); + EXPECT_EQ(iter.GetIndex(), 2u); auto iterCheck = table.begin(); ++iterCheck; - NL_TEST_ASSERT(aSuite, iter == iterCheck); + EXPECT_EQ(iter, iterCheck); - NL_TEST_ASSERT(aSuite, table.Add(EmberBindingTableEntry::ForNode(0, 1, 0, 0, std::nullopt)) == CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, table.Size() == MATTER_BINDING_TABLE_SIZE); + EXPECT_EQ(table.Add(EmberBindingTableEntry::ForNode(0, 1, 0, 0, std::nullopt)), CHIP_NO_ERROR); + EXPECT_EQ(table.Size(), MATTER_BINDING_TABLE_SIZE); iter = table.begin(); for (uint8_t i = 0; i < MATTER_BINDING_TABLE_SIZE - 1; i++) { ++iter; } - NL_TEST_ASSERT(aSuite, iter->nodeId == 1); - NL_TEST_ASSERT(aSuite, iter.GetIndex() == 1); + EXPECT_EQ(iter->nodeId, 1u); + EXPECT_EQ(iter.GetIndex(), 1u); ++iter; - NL_TEST_ASSERT(aSuite, iter == table.end()); + EXPECT_EQ(iter, table.end()); iter = table.begin(); - NL_TEST_ASSERT(aSuite, table.RemoveAt(iter) == CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, table.Size() == MATTER_BINDING_TABLE_SIZE - 1); - NL_TEST_ASSERT(aSuite, iter == table.begin()); - NL_TEST_ASSERT(aSuite, iter.GetIndex() == 2); - NL_TEST_ASSERT(aSuite, iter->nodeId == 2); - NL_TEST_ASSERT(aSuite, table.GetAt(0).type == MATTER_UNUSED_BINDING); -} - -void VerifyTableSame(nlTestSuite * aSuite, BindingTable & table, const std::vector & expected) -{ - NL_TEST_ASSERT(aSuite, table.Size() == expected.size()); - auto iter1 = table.begin(); - auto iter2 = expected.begin(); - while (iter2 != expected.end()) - { - NL_TEST_ASSERT(aSuite, iter1 != table.end()); - NL_TEST_ASSERT(aSuite, *iter1 == *iter2); - ++iter1; - ++iter2; - } - NL_TEST_ASSERT(aSuite, iter1 == table.end()); + EXPECT_EQ(table.RemoveAt(iter), CHIP_NO_ERROR); + EXPECT_EQ(table.Size(), MATTER_BINDING_TABLE_SIZE - 1); + EXPECT_EQ(iter, table.begin()); + EXPECT_EQ(iter.GetIndex(), 2u); + EXPECT_EQ(iter->nodeId, 2u); + EXPECT_EQ(table.GetAt(0).type, MATTER_UNUSED_BINDING); } -void VerifyRestored(nlTestSuite * aSuite, chip::TestPersistentStorageDelegate & storage, - const std::vector & expected) -{ - BindingTable restoredTable; - restoredTable.SetPersistentStorage(&storage); - NL_TEST_ASSERT(aSuite, restoredTable.LoadFromStorage() == CHIP_NO_ERROR); - VerifyTableSame(aSuite, restoredTable, expected); -} - -void TestPersistentStorage(nlTestSuite * aSuite, void * aContext) +TEST(TestBindingTable, TestPersistentStorage) { chip::TestPersistentStorageDelegate testStorage; BindingTable table; @@ -142,68 +142,46 @@ void TestPersistentStorage(nlTestSuite * aSuite, void * aContext) EmberBindingTableEntry::ForGroup(3, 3, 0, cluster.std_optional()), }; table.SetPersistentStorage(&testStorage); - NL_TEST_ASSERT(aSuite, table.Add(expected[0]) == CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, table.Add(expected[1]) == CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, table.Add(expected[2]) == CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, table.Add(expected[3]) == CHIP_NO_ERROR); - VerifyRestored(aSuite, testStorage, expected); + EXPECT_EQ(table.Add(expected[0]), CHIP_NO_ERROR); + EXPECT_EQ(table.Add(expected[1]), CHIP_NO_ERROR); + EXPECT_EQ(table.Add(expected[2]), CHIP_NO_ERROR); + EXPECT_EQ(table.Add(expected[3]), CHIP_NO_ERROR); + VerifyRestored(testStorage, expected); // Verify storage untouched if add fails testStorage.AddPoisonKey(chip::DefaultStorageKeyAllocator::BindingTableEntry(4).KeyName()); - NL_TEST_ASSERT(aSuite, table.Add(EmberBindingTableEntry::ForNode(4, 4, 0, 0, std::nullopt)) != CHIP_NO_ERROR); - VerifyRestored(aSuite, testStorage, expected); + EXPECT_NE(table.Add(EmberBindingTableEntry::ForNode(4, 4, 0, 0, std::nullopt)), CHIP_NO_ERROR); + VerifyRestored(testStorage, expected); testStorage.ClearPoisonKeys(); // Verify storage untouched if removing head fails testStorage.AddPoisonKey(chip::DefaultStorageKeyAllocator::BindingTable().KeyName()); auto iter = table.begin(); - NL_TEST_ASSERT(aSuite, table.RemoveAt(iter) != CHIP_NO_ERROR); - VerifyTableSame(aSuite, table, expected); + EXPECT_NE(table.RemoveAt(iter), CHIP_NO_ERROR); + VerifyTableSame(table, expected); testStorage.ClearPoisonKeys(); - VerifyRestored(aSuite, testStorage, expected); + VerifyRestored(testStorage, expected); // Verify storage untouched if removing other nodes fails testStorage.AddPoisonKey(chip::DefaultStorageKeyAllocator::BindingTableEntry(0).KeyName()); iter = table.begin(); ++iter; - NL_TEST_ASSERT(aSuite, table.RemoveAt(iter) != CHIP_NO_ERROR); - VerifyTableSame(aSuite, table, expected); + EXPECT_NE(table.RemoveAt(iter), CHIP_NO_ERROR); + VerifyTableSame(table, expected); testStorage.ClearPoisonKeys(); - VerifyRestored(aSuite, testStorage, expected); + VerifyRestored(testStorage, expected); // Verify removing head iter = table.begin(); - NL_TEST_ASSERT(aSuite, table.RemoveAt(iter) == CHIP_NO_ERROR); - VerifyTableSame(aSuite, table, { expected[1], expected[2], expected[3] }); - VerifyRestored(aSuite, testStorage, { expected[1], expected[2], expected[3] }); + EXPECT_EQ(table.RemoveAt(iter), CHIP_NO_ERROR); + VerifyTableSame(table, { expected[1], expected[2], expected[3] }); + VerifyRestored(testStorage, { expected[1], expected[2], expected[3] }); // Verify removing other nodes ++iter; - NL_TEST_ASSERT(aSuite, table.RemoveAt(iter) == CHIP_NO_ERROR); - VerifyTableSame(aSuite, table, { expected[1], expected[3] }); - VerifyRestored(aSuite, testStorage, { expected[1], expected[3] }); + EXPECT_EQ(table.RemoveAt(iter), CHIP_NO_ERROR); + VerifyTableSame(table, { expected[1], expected[3] }); + VerifyRestored(testStorage, { expected[1], expected[3] }); } } // namespace - -int TestBindingTable() -{ - static nlTest sTests[] = { - NL_TEST_DEF("TestEmptyBindingTable", TestEmptyBindingTable), - NL_TEST_DEF("TestAdd", TestAdd), - NL_TEST_DEF("TestRemoveThenAdd", TestRemoveThenAdd), - NL_TEST_DEF("TestPersistentStorage", TestPersistentStorage), - NL_TEST_SENTINEL(), - }; - - nlTestSuite theSuite = { - "BindingTable", - &sTests[0], - nullptr, - nullptr, - }; - nlTestRunner(&theSuite, nullptr); - return (nlTestRunnerStats(&theSuite)); -} - -CHIP_REGISTER_TEST_SUITE(TestBindingTable) diff --git a/src/app/tests/TestBuilderParser.cpp b/src/app/tests/TestBuilderParser.cpp index 314353e8b70029..b59042c4aa6dff 100644 --- a/src/app/tests/TestBuilderParser.cpp +++ b/src/app/tests/TestBuilderParser.cpp @@ -25,23 +25,30 @@ #include #include #include -#include #include -#include +#include +#include namespace { using namespace chip::app; -void ListTest(nlTestSuite * apSuite, void * apContext) +class TestBuilderParser : public ::testing::Test +{ +public: + static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); } + static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); } +}; + +TEST_F(TestBuilderParser, TestList) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); ListBuilder listBuilder; - NL_TEST_ASSERT(apSuite, listBuilder.Init(&writer) == CHIP_NO_ERROR); + EXPECT_EQ(listBuilder.Init(&writer), CHIP_NO_ERROR); listBuilder.EndOfContainer(); chip::System::PacketBufferHandle buf; @@ -50,18 +57,18 @@ void ListTest(nlTestSuite * apSuite, void * apContext) ListParser listParser; reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - NL_TEST_ASSERT(apSuite, listParser.Init(reader) == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(listParser.Init(reader), CHIP_NO_ERROR); } -void StructTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestBuilderParser, TestStruct) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); StructBuilder structBuilder; - NL_TEST_ASSERT(apSuite, structBuilder.Init(&writer) == CHIP_NO_ERROR); + EXPECT_EQ(structBuilder.Init(&writer), CHIP_NO_ERROR); structBuilder.EndOfContainer(); chip::System::PacketBufferHandle buf; @@ -71,17 +78,17 @@ void StructTest(nlTestSuite * apSuite, void * apContext) reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, structParser.Init(reader) == CHIP_NO_ERROR); + EXPECT_EQ(structParser.Init(reader), CHIP_NO_ERROR); } -void ArrayTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestBuilderParser, TestArray) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); ArrayBuilder arrayBuilder; - NL_TEST_ASSERT(apSuite, arrayBuilder.Init(&writer) == CHIP_NO_ERROR); + EXPECT_EQ(arrayBuilder.Init(&writer), CHIP_NO_ERROR); arrayBuilder.EndOfContainer(); chip::System::PacketBufferHandle buf; @@ -91,55 +98,7 @@ void ArrayTest(nlTestSuite * apSuite, void * apContext) reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, arrayParser.Init(reader) == CHIP_NO_ERROR); + EXPECT_EQ(arrayParser.Init(reader), CHIP_NO_ERROR); } -// clang-format off -const nlTest sTests[] = - { - NL_TEST_DEF("ListTest", ListTest), - NL_TEST_DEF("StructTest", StructTest), - NL_TEST_DEF("ArrayTest", ArrayTest), - NL_TEST_SENTINEL() - }; -// clang-format on } // namespace - -/** - * Set up the test suite. - */ -static int TestSetup(void * inContext) -{ - CHIP_ERROR error = chip::Platform::MemoryInit(); - if (error != CHIP_NO_ERROR) - return FAILURE; - return SUCCESS; -} - -/** - * Tear down the test suite. - */ -static int TestTeardown(void * inContext) -{ - chip::Platform::MemoryShutdown(); - return SUCCESS; -} - -int TestBuilderParser() -{ - // clang-format off - nlTestSuite theSuite = - { - "TestBuilderParser", - &sTests[0], - TestSetup, - TestTeardown, - }; - // clang-format on - - nlTestRunner(&theSuite, nullptr); - - return (nlTestRunnerStats(&theSuite)); -} - -CHIP_REGISTER_TEST_SUITE(TestBuilderParser) diff --git a/src/app/tests/TestDefaultICDClientStorage.cpp b/src/app/tests/TestDefaultICDClientStorage.cpp index 62787a2c9e4144..8cf4c8d86fa2a1 100644 --- a/src/app/tests/TestDefaultICDClientStorage.cpp +++ b/src/app/tests/TestDefaultICDClientStorage.cpp @@ -15,9 +15,9 @@ * limitations under the License. */ +#include #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/TestFailSafeContext.cpp b/src/app/tests/TestFailSafeContext.cpp index 2d2b9fa15d2b7d..96868ff241fa28 100644 --- a/src/app/tests/TestFailSafeContext.cpp +++ b/src/app/tests/TestFailSafeContext.cpp @@ -28,11 +28,11 @@ #include #include +#include + #include #include #include -#include -#include #include using namespace chip; @@ -44,100 +44,62 @@ namespace { constexpr FabricIndex kTestAccessingFabricIndex1 = 1; constexpr FabricIndex kTestAccessingFabricIndex2 = 2; +class TestFailSafeContext : public ::testing::Test +{ +public: + static void SetUpTestSuite() + { + ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); + ASSERT_EQ(PlatformMgr().InitChipStack(), CHIP_NO_ERROR); + } + static void TearDownTestSuite() + { + PlatformMgr().Shutdown(); + chip::Platform::MemoryShutdown(); + } +}; + // ================================= // Unit tests // ================================= -static void TestPlatformMgr_Init(nlTestSuite * inSuite, void * inContext) -{ - CHIP_ERROR err = PlatformMgr().InitChipStack(); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); -} - -static void TestFailSafeContext_ArmFailSafe(nlTestSuite * inSuite, void * inContext) +TEST_F(TestFailSafeContext, TestFailSafeContext_ArmFailSafe) { CHIP_ERROR err = CHIP_NO_ERROR; chip::app::FailSafeContext failSafeContext; err = failSafeContext.ArmFailSafe(kTestAccessingFabricIndex1, System::Clock::Seconds16(1)); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, failSafeContext.IsFailSafeArmed() == true); - NL_TEST_ASSERT(inSuite, failSafeContext.GetFabricIndex() == kTestAccessingFabricIndex1); - NL_TEST_ASSERT(inSuite, failSafeContext.IsFailSafeArmed(kTestAccessingFabricIndex1) == true); - NL_TEST_ASSERT(inSuite, failSafeContext.IsFailSafeArmed(kTestAccessingFabricIndex2) == false); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_TRUE(failSafeContext.IsFailSafeArmed()); + EXPECT_EQ(failSafeContext.GetFabricIndex(), kTestAccessingFabricIndex1); + EXPECT_TRUE(failSafeContext.IsFailSafeArmed(kTestAccessingFabricIndex1)); + EXPECT_FALSE(failSafeContext.IsFailSafeArmed(kTestAccessingFabricIndex2)); failSafeContext.DisarmFailSafe(); - NL_TEST_ASSERT(inSuite, failSafeContext.IsFailSafeArmed() == false); + EXPECT_FALSE(failSafeContext.IsFailSafeArmed()); } -static void TestFailSafeContext_NocCommandInvoked(nlTestSuite * inSuite, void * inContext) +TEST_F(TestFailSafeContext, TestFailSafeContext_NocCommandInvoked) { CHIP_ERROR err = CHIP_NO_ERROR; chip::app::FailSafeContext failSafeContext; err = failSafeContext.ArmFailSafe(kTestAccessingFabricIndex1, System::Clock::Seconds16(1)); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, failSafeContext.GetFabricIndex() == kTestAccessingFabricIndex1); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(failSafeContext.GetFabricIndex(), kTestAccessingFabricIndex1); failSafeContext.SetAddNocCommandInvoked(kTestAccessingFabricIndex2); - NL_TEST_ASSERT(inSuite, failSafeContext.NocCommandHasBeenInvoked() == true); - NL_TEST_ASSERT(inSuite, failSafeContext.AddNocCommandHasBeenInvoked() == true); - NL_TEST_ASSERT(inSuite, failSafeContext.GetFabricIndex() == kTestAccessingFabricIndex2); + EXPECT_TRUE(failSafeContext.NocCommandHasBeenInvoked()); + EXPECT_TRUE(failSafeContext.AddNocCommandHasBeenInvoked()); + EXPECT_EQ(failSafeContext.GetFabricIndex(), kTestAccessingFabricIndex2); failSafeContext.SetUpdateNocCommandInvoked(); - NL_TEST_ASSERT(inSuite, failSafeContext.NocCommandHasBeenInvoked() == true); - NL_TEST_ASSERT(inSuite, failSafeContext.UpdateNocCommandHasBeenInvoked() == true); + EXPECT_TRUE(failSafeContext.NocCommandHasBeenInvoked()); + EXPECT_TRUE(failSafeContext.UpdateNocCommandHasBeenInvoked()); failSafeContext.DisarmFailSafe(); } -/** - * Test Suite. It lists all the test functions. - */ -static const nlTest sTests[] = { - - NL_TEST_DEF("Test PlatformMgr::Init", TestPlatformMgr_Init), - NL_TEST_DEF("Test FailSafeContext::ArmFailSafe", TestFailSafeContext_ArmFailSafe), - NL_TEST_DEF("Test FailSafeContext::NocCommandInvoked", TestFailSafeContext_NocCommandInvoked), - - NL_TEST_SENTINEL() -}; - -/** - * Set up the test suite. - */ -int TestFailSafeContext_Setup(void * inContext) -{ - CHIP_ERROR error = chip::Platform::MemoryInit(); - if (error != CHIP_NO_ERROR) - return FAILURE; - return SUCCESS; -} - -/** - * Tear down the test suite. - */ -int TestFailSafeContext_Teardown(void * inContext) -{ - PlatformMgr().Shutdown(); - chip::Platform::MemoryShutdown(); - return SUCCESS; -} - } // namespace - -/** - * Main - */ -int TestFailSafeContext() -{ - nlTestSuite theSuite = { "FailSafeContext tests", &sTests[0], TestFailSafeContext_Setup, TestFailSafeContext_Teardown }; - - // Run test suite against one context. - nlTestRunner(&theSuite, nullptr); - return nlTestRunnerStats(&theSuite); -} - -CHIP_REGISTER_TEST_SUITE(TestFailSafeContext) diff --git a/src/app/tests/TestMessageDef.cpp b/src/app/tests/TestMessageDef.cpp index 10417fa2025522..01f3acb263877a 100644 --- a/src/app/tests/TestMessageDef.cpp +++ b/src/app/tests/TestMessageDef.cpp @@ -16,12 +16,6 @@ * limitations under the License. */ -/** - * @file - * This file implements a test for CHIP Interaction Model Message Def - * - */ - #include #include #include @@ -38,16 +32,23 @@ #include #include #include -#include #include #include -#include +#include +#include namespace { using namespace chip::app; +class TestMessageDef : public ::testing::Test +{ +public: + static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); } + static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); } +}; + void ENFORCE_FORMAT(1, 2) TLVPrettyPrinter(const char * aFormat, ...) { va_list args; @@ -75,7 +76,7 @@ CHIP_ERROR DebugPrettyPrint(const chip::System::PacketBufferHandle & aMsgBuf) return err; } -void BuildStatusIB(nlTestSuite * apSuite, StatusIB::Builder & aStatusIBBuilder) +void BuildStatusIB(StatusIB::Builder & aStatusIBBuilder) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -83,10 +84,10 @@ void BuildStatusIB(nlTestSuite * apSuite, StatusIB::Builder & aStatusIBBuilder) statusIB.mStatus = chip::Protocols::InteractionModel::Status::InvalidSubscription; aStatusIBBuilder.EncodeStatusIB(statusIB); err = aStatusIBBuilder.GetError(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); } -void ParseStatusIB(nlTestSuite * apSuite, StatusIB::Parser & aStatusIBParser) +void ParseStatusIB(StatusIB::Parser & aStatusIBParser) { CHIP_ERROR err = CHIP_NO_ERROR; StatusIB::Parser StatusIBParser; @@ -96,20 +97,20 @@ void ParseStatusIB(nlTestSuite * apSuite, StatusIB::Parser & aStatusIBParser) aStatusIBParser.PrettyPrint(); #endif err = aStatusIBParser.DecodeStatusIB(statusIB); - NL_TEST_ASSERT(apSuite, - err == CHIP_NO_ERROR && statusIB.mStatus == chip::Protocols::InteractionModel::Status::InvalidSubscription && - !statusIB.mClusterStatus.HasValue()); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(statusIB.mStatus, chip::Protocols::InteractionModel::Status::InvalidSubscription); + EXPECT_FALSE(statusIB.mClusterStatus.HasValue()); } -void BuildClusterPathIB(nlTestSuite * apSuite, ClusterPathIB::Builder & aClusterPathBuilder) +void BuildClusterPathIB(ClusterPathIB::Builder & aClusterPathBuilder) { CHIP_ERROR err = CHIP_NO_ERROR; aClusterPathBuilder.Node(1).Endpoint(2).Cluster(3).EndOfClusterPathIB(); err = aClusterPathBuilder.GetError(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); } -void ParseClusterPathIB(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseClusterPathIB(chip::TLV::TLVReader & aReader) { ClusterPathIB::Parser clusterPathParser; CHIP_ERROR err = CHIP_NO_ERROR; @@ -118,31 +119,34 @@ void ParseClusterPathIB(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) chip::ClusterId cluster = 0; err = clusterPathParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); #if CHIP_CONFIG_IM_PRETTY_PRINT clusterPathParser.PrettyPrint(); #endif err = clusterPathParser.GetNode(&node); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && node == 1); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(node, 1u); err = clusterPathParser.GetEndpoint(&endpoint); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && endpoint == 2); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(endpoint, 2u); err = clusterPathParser.GetCluster(&cluster); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && cluster == 3); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(cluster, 3u); } -void BuildDataVersionFilterIB(nlTestSuite * apSuite, DataVersionFilterIB::Builder & aDataVersionFilterIBBuilder) +void BuildDataVersionFilterIB(DataVersionFilterIB::Builder & aDataVersionFilterIBBuilder) { ClusterPathIB::Builder & clusterPathBuilder = aDataVersionFilterIBBuilder.CreatePath(); - NL_TEST_ASSERT(apSuite, clusterPathBuilder.GetError() == CHIP_NO_ERROR); - BuildClusterPathIB(apSuite, clusterPathBuilder); + EXPECT_EQ(clusterPathBuilder.GetError(), CHIP_NO_ERROR); + BuildClusterPathIB(clusterPathBuilder); aDataVersionFilterIBBuilder.DataVersion(2).EndOfDataVersionFilterIB(); - NL_TEST_ASSERT(apSuite, aDataVersionFilterIBBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(aDataVersionFilterIBBuilder.GetError(), CHIP_NO_ERROR); } -void ParseDataVersionFilterIB(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseDataVersionFilterIB(chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; DataVersionFilterIB::Parser dataVersionFilterIBParser; @@ -150,46 +154,47 @@ void ParseDataVersionFilterIB(nlTestSuite * apSuite, chip::TLV::TLVReader & aRea chip::DataVersion dataVersion = 2; err = dataVersionFilterIBParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); #if CHIP_CONFIG_IM_PRETTY_PRINT dataVersionFilterIBParser.PrettyPrint(); #endif err = dataVersionFilterIBParser.GetPath(&clusterPath); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = dataVersionFilterIBParser.GetDataVersion(&dataVersion); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && dataVersion == 2); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(dataVersion, 2u); } -void BuildDataVersionFilterIBs(nlTestSuite * apSuite, DataVersionFilterIBs::Builder & aDataVersionFilterIBsBuilder) +void BuildDataVersionFilterIBs(DataVersionFilterIBs::Builder & aDataVersionFilterIBsBuilder) { DataVersionFilterIB::Builder & dataVersionFilterIBBuilder = aDataVersionFilterIBsBuilder.CreateDataVersionFilter(); - NL_TEST_ASSERT(apSuite, aDataVersionFilterIBsBuilder.GetError() == CHIP_NO_ERROR); - BuildDataVersionFilterIB(apSuite, dataVersionFilterIBBuilder); + EXPECT_EQ(aDataVersionFilterIBsBuilder.GetError(), CHIP_NO_ERROR); + BuildDataVersionFilterIB(dataVersionFilterIBBuilder); aDataVersionFilterIBsBuilder.EndOfDataVersionFilterIBs(); - NL_TEST_ASSERT(apSuite, aDataVersionFilterIBsBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(aDataVersionFilterIBsBuilder.GetError(), CHIP_NO_ERROR); } -void ParseDataVersionFilterIBs(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseDataVersionFilterIBs(chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; DataVersionFilterIBs::Parser dataVersionFilterIBsParser; err = dataVersionFilterIBsParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); #if CHIP_CONFIG_IM_PRETTY_PRINT dataVersionFilterIBsParser.PrettyPrint(); #endif } -void BuildEventFilterIB(nlTestSuite * apSuite, EventFilterIB::Builder & aEventFilterIBBuilder) +void BuildEventFilterIB(EventFilterIB::Builder & aEventFilterIBBuilder) { aEventFilterIBBuilder.Node(1).EventMin(2).EndOfEventFilterIB(); - NL_TEST_ASSERT(apSuite, aEventFilterIBBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(aEventFilterIBBuilder.GetError(), CHIP_NO_ERROR); } -void ParseEventFilterIB(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseEventFilterIB(chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; EventFilterIB::Parser eventFilterIBParser; @@ -197,39 +202,41 @@ void ParseEventFilterIB(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) uint64_t eventMin = 2; err = eventFilterIBParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); #if CHIP_CONFIG_IM_PRETTY_PRINT eventFilterIBParser.PrettyPrint(); #endif err = eventFilterIBParser.GetNode(&node); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && node == 1); + EXPECT_EQ(err, CHIP_NO_ERROR); + + EXPECT_EQ(node, 1u); err = eventFilterIBParser.GetEventMin(&eventMin); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && eventMin == 2); + EXPECT_EQ(eventMin, 2u); } -void BuildEventFilters(nlTestSuite * apSuite, EventFilterIBs::Builder & aEventFiltersBuilder) +void BuildEventFilters(EventFilterIBs::Builder & aEventFiltersBuilder) { EventFilterIB::Builder & eventFilterBuilder = aEventFiltersBuilder.CreateEventFilter(); - NL_TEST_ASSERT(apSuite, aEventFiltersBuilder.GetError() == CHIP_NO_ERROR); - BuildEventFilterIB(apSuite, eventFilterBuilder); + EXPECT_EQ(aEventFiltersBuilder.GetError(), CHIP_NO_ERROR); + BuildEventFilterIB(eventFilterBuilder); aEventFiltersBuilder.EndOfEventFilters(); - NL_TEST_ASSERT(apSuite, aEventFiltersBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(aEventFiltersBuilder.GetError(), CHIP_NO_ERROR); } -void ParseEventFilters(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseEventFilters(chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; EventFilterIBs::Parser eventFiltersParser; err = eventFiltersParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); #if CHIP_CONFIG_IM_PRETTY_PRINT eventFiltersParser.PrettyPrint(); #endif } -void BuildAttributePathIB(nlTestSuite * apSuite, AttributePathIB::Builder & aAttributePathBuilder) +void BuildAttributePathIB(AttributePathIB::Builder & aAttributePathBuilder) { CHIP_ERROR err = CHIP_NO_ERROR; err = aAttributePathBuilder.EnableTagCompression(false) @@ -239,10 +246,10 @@ void BuildAttributePathIB(nlTestSuite * apSuite, AttributePathIB::Builder & aAtt .Attribute(4) .ListIndex(5) .EndOfAttributePathIB(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); } -void ParseAttributePathIB(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseAttributePathIB(chip::TLV::TLVReader & aReader) { AttributePathIB::Parser attributePathParser; CHIP_ERROR err = CHIP_NO_ERROR; @@ -254,63 +261,69 @@ void ParseAttributePathIB(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) chip::ListIndex listIndex = 5; err = attributePathParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); #if CHIP_CONFIG_IM_PRETTY_PRINT attributePathParser.PrettyPrint(); #endif err = attributePathParser.GetEnableTagCompression(&enableTagCompression); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && enableTagCompression == false); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_FALSE(enableTagCompression); err = attributePathParser.GetNode(&node); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && node == 1); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(node, 1u); err = attributePathParser.GetEndpoint(&endpoint); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && endpoint == 2); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(endpoint, 2u); err = attributePathParser.GetCluster(&cluster); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && cluster == 3); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(cluster, 3u); err = attributePathParser.GetAttribute(&attribute); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && attribute == 4); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(attribute, 4u); err = attributePathParser.GetListIndex(&listIndex); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && listIndex == 5); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(listIndex, 5u); } -void BuildAttributePathList(nlTestSuite * apSuite, AttributePathIBs::Builder & aAttributePathListBuilder) +void BuildAttributePathList(AttributePathIBs::Builder & aAttributePathListBuilder) { AttributePathIB::Builder & attributePathBuilder = aAttributePathListBuilder.CreatePath(); - NL_TEST_ASSERT(apSuite, attributePathBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributePathIB(apSuite, attributePathBuilder); + EXPECT_EQ(attributePathBuilder.GetError(), CHIP_NO_ERROR); + BuildAttributePathIB(attributePathBuilder); aAttributePathListBuilder.EndOfAttributePathIBs(); - NL_TEST_ASSERT(apSuite, aAttributePathListBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(aAttributePathListBuilder.GetError(), CHIP_NO_ERROR); } -void ParseAttributePathList(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseAttributePathList(chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; AttributePathIBs::Parser attributePathListParser; AttributePathIB::Parser attributePathParser; err = attributePathListParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); #if CHIP_CONFIG_IM_PRETTY_PRINT attributePathListParser.PrettyPrint(); #endif } -void BuildEventPath(nlTestSuite * apSuite, EventPathIB::Builder & aEventPathBuilder) +void BuildEventPath(EventPathIB::Builder & aEventPathBuilder) { CHIP_ERROR err = CHIP_NO_ERROR; aEventPathBuilder.Node(1).Endpoint(2).Cluster(3).Event(4).IsUrgent(true).EndOfEventPathIB(); err = aEventPathBuilder.GetError(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); } -void ParseEventPath(nlTestSuite * apSuite, EventPathIB::Parser & aEventPathParser) +void ParseEventPath(EventPathIB::Parser & aEventPathParser) { CHIP_ERROR err = CHIP_NO_ERROR; chip::NodeId node = 1; @@ -323,50 +336,55 @@ void ParseEventPath(nlTestSuite * apSuite, EventPathIB::Parser & aEventPathParse aEventPathParser.PrettyPrint(); #endif err = aEventPathParser.GetNode(&node); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && node == 1); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(node, 1u); err = aEventPathParser.GetEndpoint(&endpoint); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && endpoint == 2); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(endpoint, 2u); err = aEventPathParser.GetCluster(&cluster); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && cluster == 3); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(cluster, 3u); err = aEventPathParser.GetEvent(&event); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && event == 4); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(event, 4u); err = aEventPathParser.GetIsUrgent(&isUrgent); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && isUrgent == true); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_TRUE(isUrgent); } -void BuildEventPaths(nlTestSuite * apSuite, EventPathIBs::Builder & aEventPathsBuilder) +void BuildEventPaths(EventPathIBs::Builder & aEventPathsBuilder) { EventPathIB::Builder & eventPathBuilder = aEventPathsBuilder.CreatePath(); - NL_TEST_ASSERT(apSuite, eventPathBuilder.GetError() == CHIP_NO_ERROR); - BuildEventPath(apSuite, eventPathBuilder); + EXPECT_EQ(eventPathBuilder.GetError(), CHIP_NO_ERROR); + BuildEventPath(eventPathBuilder); aEventPathsBuilder.EndOfEventPaths(); - NL_TEST_ASSERT(apSuite, aEventPathsBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(aEventPathsBuilder.GetError(), CHIP_NO_ERROR); } -void ParseEventPaths(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseEventPaths(chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; EventPathIBs::Parser eventPathListParser; err = eventPathListParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); #if CHIP_CONFIG_IM_PRETTY_PRINT eventPathListParser.PrettyPrint(); #endif } -void BuildCommandPath(nlTestSuite * apSuite, CommandPathIB::Builder & aCommandPathBuilder) +void BuildCommandPath(CommandPathIB::Builder & aCommandPathBuilder) { aCommandPathBuilder.EndpointId(1).ClusterId(3).CommandId(4).EndOfCommandPathIB(); - NL_TEST_ASSERT(apSuite, aCommandPathBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(aCommandPathBuilder.GetError(), CHIP_NO_ERROR); } -void ParseCommandPath(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseCommandPath(chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; CommandPathIB::Parser commandPathParser; @@ -375,52 +393,55 @@ void ParseCommandPath(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) chip::CommandId commandId = 0; err = commandPathParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); #if CHIP_CONFIG_IM_PRETTY_PRINT commandPathParser.PrettyPrint(); #endif err = commandPathParser.GetEndpointId(&endpointId); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && endpointId == 1); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(endpointId, 1u); err = commandPathParser.GetClusterId(&clusterId); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && clusterId == 3); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(clusterId, 3u); err = commandPathParser.GetCommandId(&commandId); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && commandId == 4); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(commandId, 4u); } -void BuildEventDataIB(nlTestSuite * apSuite, EventDataIB::Builder & aEventDataIBBuilder) +void BuildEventDataIB(EventDataIB::Builder & aEventDataIBBuilder) { CHIP_ERROR err = CHIP_NO_ERROR; EventPathIB::Builder & eventPathBuilder = aEventDataIBBuilder.CreatePath(); - NL_TEST_ASSERT(apSuite, eventPathBuilder.GetError() == CHIP_NO_ERROR); - BuildEventPath(apSuite, eventPathBuilder); + EXPECT_EQ(eventPathBuilder.GetError(), CHIP_NO_ERROR); + BuildEventPath(eventPathBuilder); aEventDataIBBuilder.EventNumber(2).Priority(3).EpochTimestamp(4).SystemTimestamp(5).DeltaEpochTimestamp(6).DeltaSystemTimestamp( 7); err = aEventDataIBBuilder.GetError(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); // Construct test event data { chip::TLV::TLVWriter * pWriter = aEventDataIBBuilder.GetWriter(); chip::TLV::TLVType dummyType = chip::TLV::kTLVType_NotSpecified; err = pWriter->StartContainer(chip::TLV::ContextTag(chip::to_underlying(EventDataIB::Tag::kData)), chip::TLV::kTLVType_Structure, dummyType); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = pWriter->PutBoolean(chip::TLV::ContextTag(1), true); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = pWriter->EndContainer(dummyType); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); } aEventDataIBBuilder.EndOfEventDataIB(); } -void ParseEventDataIB(nlTestSuite * apSuite, EventDataIB::Parser & aEventDataIBParser) +void ParseEventDataIB(EventDataIB::Parser & aEventDataIBParser) { CHIP_ERROR err = CHIP_NO_ERROR; uint8_t priorityLevel = 0; @@ -437,20 +458,31 @@ void ParseEventDataIB(nlTestSuite * apSuite, EventDataIB::Parser & aEventDataIBP { EventPathIB::Parser eventPath; err = aEventDataIBParser.GetPath(&eventPath); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); } err = aEventDataIBParser.GetEventNumber(&number); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && number == 2); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(number, 2u); + err = aEventDataIBParser.GetPriority(&priorityLevel); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && priorityLevel == 3); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(priorityLevel, 3u); + err = aEventDataIBParser.GetEpochTimestamp(&EpochTimestamp); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && EpochTimestamp == 4); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(EpochTimestamp, 4u); + err = aEventDataIBParser.GetSystemTimestamp(&systemTimestamp); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && systemTimestamp == 5); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(systemTimestamp, 5u); + err = aEventDataIBParser.GetDeltaEpochTimestamp(&deltaUTCTimestamp); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && deltaUTCTimestamp == 6); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(deltaUTCTimestamp, 6u); + err = aEventDataIBParser.GetDeltaSystemTimestamp(&deltaSystemTimestamp); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && deltaSystemTimestamp == 7); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(deltaSystemTimestamp, 7u); { chip::TLV::TLVReader reader; @@ -458,35 +490,36 @@ void ParseEventDataIB(nlTestSuite * apSuite, EventDataIB::Parser & aEventDataIBP chip::TLV::TLVType container; aEventDataIBParser.GetData(&reader); err = reader.EnterContainer(container); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = reader.Get(val); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && val); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_TRUE(val); err = reader.ExitContainer(container); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); } } } -void BuildEventStatusIB(nlTestSuite * apSuite, EventStatusIB::Builder & aEventStatusIBBuilder) +void BuildEventStatusIB(EventStatusIB::Builder & aEventStatusIBBuilder) { EventPathIB::Builder & eventPathBuilder = aEventStatusIBBuilder.CreatePath(); - NL_TEST_ASSERT(apSuite, aEventStatusIBBuilder.GetError() == CHIP_NO_ERROR); - BuildEventPath(apSuite, eventPathBuilder); + EXPECT_EQ(aEventStatusIBBuilder.GetError(), CHIP_NO_ERROR); + BuildEventPath(eventPathBuilder); StatusIB::Builder & statusIBBuilder = aEventStatusIBBuilder.CreateErrorStatus(); - NL_TEST_ASSERT(apSuite, statusIBBuilder.GetError() == CHIP_NO_ERROR); - BuildStatusIB(apSuite, statusIBBuilder); + EXPECT_EQ(statusIBBuilder.GetError(), CHIP_NO_ERROR); + BuildStatusIB(statusIBBuilder); aEventStatusIBBuilder.EndOfEventStatusIB(); - NL_TEST_ASSERT(apSuite, aEventStatusIBBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(aEventStatusIBBuilder.GetError(), CHIP_NO_ERROR); } -void ParseEventStatusIB(nlTestSuite * apSuite, EventStatusIB::Parser & aEventStatusIBParser) +void ParseEventStatusIB(EventStatusIB::Parser & aEventStatusIBParser) { CHIP_ERROR err = CHIP_NO_ERROR; EventPathIB::Parser eventPathParser; @@ -495,23 +528,23 @@ void ParseEventStatusIB(nlTestSuite * apSuite, EventStatusIB::Parser & aEventSta aEventStatusIBParser.PrettyPrint(); #endif err = aEventStatusIBParser.GetPath(&eventPathParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = aEventStatusIBParser.GetErrorStatus(&statusParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); } -void BuildEventReportIB(nlTestSuite * apSuite, EventReportIB::Builder & aEventReportIBBuilder) +void BuildEventReportIB(EventReportIB::Builder & aEventReportIBBuilder) { EventDataIB::Builder & eventDataIBBuilder = aEventReportIBBuilder.CreateEventData(); - NL_TEST_ASSERT(apSuite, aEventReportIBBuilder.GetError() == CHIP_NO_ERROR); - BuildEventDataIB(apSuite, eventDataIBBuilder); + EXPECT_EQ(aEventReportIBBuilder.GetError(), CHIP_NO_ERROR); + BuildEventDataIB(eventDataIBBuilder); aEventReportIBBuilder.EndOfEventReportIB(); - NL_TEST_ASSERT(apSuite, aEventReportIBBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(aEventReportIBBuilder.GetError(), CHIP_NO_ERROR); } -void ParseEventReportIB(nlTestSuite * apSuite, EventReportIB::Parser & aEventReportIBParser) +void ParseEventReportIB(EventReportIB::Parser & aEventReportIBParser) { CHIP_ERROR err = CHIP_NO_ERROR; EventStatusIB::Parser eventStatusParser; @@ -522,45 +555,45 @@ void ParseEventReportIB(nlTestSuite * apSuite, EventReportIB::Parser & aEventRep #endif err = aEventReportIBParser.GetEventData(&eventDataParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); } -void BuildEventReports(nlTestSuite * apSuite, EventReportIBs::Builder & aEventReportsBuilder) +void BuildEventReports(EventReportIBs::Builder & aEventReportsBuilder) { EventReportIB::Builder & eventReportIBBuilder = aEventReportsBuilder.CreateEventReport(); - NL_TEST_ASSERT(apSuite, aEventReportsBuilder.GetError() == CHIP_NO_ERROR); - BuildEventReportIB(apSuite, eventReportIBBuilder); + EXPECT_EQ(aEventReportsBuilder.GetError(), CHIP_NO_ERROR); + BuildEventReportIB(eventReportIBBuilder); aEventReportsBuilder.EndOfEventReports(); - NL_TEST_ASSERT(apSuite, aEventReportsBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(aEventReportsBuilder.GetError(), CHIP_NO_ERROR); } -void ParseEventReports(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseEventReports(chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; EventReportIBs::Parser eventReportsParser; err = eventReportsParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); #if CHIP_CONFIG_IM_PRETTY_PRINT eventReportsParser.PrettyPrint(); #endif } -void BuildAttributeStatusIB(nlTestSuite * apSuite, AttributeStatusIB::Builder & aAttributeStatusIBBuilder) +void BuildAttributeStatusIB(AttributeStatusIB::Builder & aAttributeStatusIBBuilder) { AttributePathIB::Builder & attributePathBuilder = aAttributeStatusIBBuilder.CreatePath(); - NL_TEST_ASSERT(apSuite, attributePathBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributePathIB(apSuite, attributePathBuilder); + EXPECT_EQ(attributePathBuilder.GetError(), CHIP_NO_ERROR); + BuildAttributePathIB(attributePathBuilder); StatusIB::Builder & statusIBBuilder = aAttributeStatusIBBuilder.CreateErrorStatus(); - NL_TEST_ASSERT(apSuite, statusIBBuilder.GetError() == CHIP_NO_ERROR); - BuildStatusIB(apSuite, statusIBBuilder); + EXPECT_EQ(statusIBBuilder.GetError(), CHIP_NO_ERROR); + BuildStatusIB(statusIBBuilder); aAttributeStatusIBBuilder.EndOfAttributeStatusIB(); - NL_TEST_ASSERT(apSuite, aAttributeStatusIBBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(aAttributeStatusIBBuilder.GetError(), CHIP_NO_ERROR); } -void ParseAttributeStatusIB(nlTestSuite * apSuite, AttributeStatusIB::Parser & aAttributeStatusIBParser) +void ParseAttributeStatusIB(AttributeStatusIB::Parser & aAttributeStatusIBParser) { CHIP_ERROR err = CHIP_NO_ERROR; AttributePathIB::Parser attributePathParser; @@ -570,43 +603,43 @@ void ParseAttributeStatusIB(nlTestSuite * apSuite, AttributeStatusIB::Parser & a aAttributeStatusIBParser.PrettyPrint(); #endif err = aAttributeStatusIBParser.GetPath(&attributePathParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = aAttributeStatusIBParser.GetErrorStatus(&StatusIBParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); } -void BuildAttributeStatuses(nlTestSuite * apSuite, AttributeStatusIBs::Builder & aAttributeStatusesBuilder) +void BuildAttributeStatuses(AttributeStatusIBs::Builder & aAttributeStatusesBuilder) { AttributeStatusIB::Builder & aAttributeStatusIBBuilder = aAttributeStatusesBuilder.CreateAttributeStatus(); - NL_TEST_ASSERT(apSuite, aAttributeStatusesBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributeStatusIB(apSuite, aAttributeStatusIBBuilder); + EXPECT_EQ(aAttributeStatusesBuilder.GetError(), CHIP_NO_ERROR); + BuildAttributeStatusIB(aAttributeStatusIBBuilder); aAttributeStatusesBuilder.EndOfAttributeStatuses(); - NL_TEST_ASSERT(apSuite, aAttributeStatusesBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(aAttributeStatusesBuilder.GetError(), CHIP_NO_ERROR); } -void ParseAttributeStatuses(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseAttributeStatuses(chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; AttributeStatusIBs::Parser attributeStatusParser; err = attributeStatusParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); #if CHIP_CONFIG_IM_PRETTY_PRINT attributeStatusParser.PrettyPrint(); #endif } -void BuildAttributeDataIB(nlTestSuite * apSuite, AttributeDataIB::Builder & aAttributeDataIBBuilder) +void BuildAttributeDataIB(AttributeDataIB::Builder & aAttributeDataIBBuilder) { CHIP_ERROR err = CHIP_NO_ERROR; aAttributeDataIBBuilder.DataVersion(2); AttributePathIB::Builder & attributePathBuilder = aAttributeDataIBBuilder.CreatePath(); - NL_TEST_ASSERT(apSuite, aAttributeDataIBBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributePathIB(apSuite, attributePathBuilder); + EXPECT_EQ(aAttributeDataIBBuilder.GetError(), CHIP_NO_ERROR); + BuildAttributePathIB(attributePathBuilder); // Construct attribute data { @@ -614,22 +647,22 @@ void BuildAttributeDataIB(nlTestSuite * apSuite, AttributeDataIB::Builder & aAtt chip::TLV::TLVType dummyType = chip::TLV::kTLVType_NotSpecified; err = pWriter->StartContainer(chip::TLV::ContextTag(chip::to_underlying(AttributeDataIB::Tag::kData)), chip::TLV::kTLVType_Structure, dummyType); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = pWriter->PutBoolean(chip::TLV::ContextTag(1), true); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = pWriter->EndContainer(dummyType); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); } err = aAttributeDataIBBuilder.GetError(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); aAttributeDataIBBuilder.EndOfAttributeDataIB(); - NL_TEST_ASSERT(apSuite, aAttributeDataIBBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(aAttributeDataIBBuilder.GetError(), CHIP_NO_ERROR); } -void ParseAttributeDataIB(nlTestSuite * apSuite, AttributeDataIB::Parser & aAttributeDataIBParser) +void ParseAttributeDataIB(AttributeDataIB::Parser & aAttributeDataIBParser) { CHIP_ERROR err = CHIP_NO_ERROR; AttributePathIB::Parser attributePathParser; @@ -638,10 +671,11 @@ void ParseAttributeDataIB(nlTestSuite * apSuite, AttributeDataIB::Parser & aAttr aAttributeDataIBParser.PrettyPrint(); #endif err = aAttributeDataIBParser.GetPath(&attributePathParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = aAttributeDataIBParser.GetDataVersion(&version); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && version == 2); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(version, 2u); { chip::TLV::TLVReader reader; @@ -649,52 +683,53 @@ void ParseAttributeDataIB(nlTestSuite * apSuite, AttributeDataIB::Parser & aAttr chip::TLV::TLVType container; aAttributeDataIBParser.GetData(&reader); err = reader.EnterContainer(container); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = reader.Get(val); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && val); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_TRUE(val); err = reader.ExitContainer(container); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); } } -void BuildAttributeDataIBs(nlTestSuite * apSuite, AttributeDataIBs::Builder & aAttributeDataIBsBuilder) +void BuildAttributeDataIBs(AttributeDataIBs::Builder & aAttributeDataIBsBuilder) { AttributeDataIB::Builder & attributeDataIBBuilder = aAttributeDataIBsBuilder.CreateAttributeDataIBBuilder(); - NL_TEST_ASSERT(apSuite, aAttributeDataIBsBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributeDataIB(apSuite, attributeDataIBBuilder); + EXPECT_EQ(aAttributeDataIBsBuilder.GetError(), CHIP_NO_ERROR); + BuildAttributeDataIB(attributeDataIBBuilder); aAttributeDataIBsBuilder.EndOfAttributeDataIBs(); - NL_TEST_ASSERT(apSuite, aAttributeDataIBsBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(aAttributeDataIBsBuilder.GetError(), CHIP_NO_ERROR); } -void ParseAttributeDataIBs(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseAttributeDataIBs(chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; AttributeDataIBs::Parser AttributeDataIBsParser; err = AttributeDataIBsParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); #if CHIP_CONFIG_IM_PRETTY_PRINT AttributeDataIBsParser.PrettyPrint(); #endif } -void BuildAttributeReportIB(nlTestSuite * apSuite, AttributeReportIB::Builder & aAttributeReportIBBuilder) +void BuildAttributeReportIB(AttributeReportIB::Builder & aAttributeReportIBBuilder) { AttributeDataIB::Builder & attributeDataIBBuilder = aAttributeReportIBBuilder.CreateAttributeData(); - NL_TEST_ASSERT(apSuite, aAttributeReportIBBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributeDataIB(apSuite, attributeDataIBBuilder); + EXPECT_EQ(aAttributeReportIBBuilder.GetError(), CHIP_NO_ERROR); + BuildAttributeDataIB(attributeDataIBBuilder); aAttributeReportIBBuilder.EndOfAttributeReportIB(); - NL_TEST_ASSERT(apSuite, aAttributeReportIBBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(aAttributeReportIBBuilder.GetError(), CHIP_NO_ERROR); } -void ParseAttributeReportIB(nlTestSuite * apSuite, AttributeReportIB::Parser & aAttributeReportIBParser) +void ParseAttributeReportIB(AttributeReportIB::Parser & aAttributeReportIBParser) { CHIP_ERROR err = CHIP_NO_ERROR; AttributeStatusIB::Parser attributeStatusParser; @@ -704,38 +739,38 @@ void ParseAttributeReportIB(nlTestSuite * apSuite, AttributeReportIB::Parser & a aAttributeReportIBParser.PrettyPrint(); #endif err = aAttributeReportIBParser.GetAttributeData(&attributeDataParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); } -void BuildAttributeReportIBs(nlTestSuite * apSuite, AttributeReportIBs::Builder & aAttributeReportIBsBuilder) +void BuildAttributeReportIBs(AttributeReportIBs::Builder & aAttributeReportIBsBuilder) { AttributeReportIB::Builder & attributeReportIBBuilder = aAttributeReportIBsBuilder.CreateAttributeReport(); - NL_TEST_ASSERT(apSuite, aAttributeReportIBsBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributeReportIB(apSuite, attributeReportIBBuilder); + EXPECT_EQ(aAttributeReportIBsBuilder.GetError(), CHIP_NO_ERROR); + BuildAttributeReportIB(attributeReportIBBuilder); aAttributeReportIBsBuilder.EndOfAttributeReportIBs(); - NL_TEST_ASSERT(apSuite, aAttributeReportIBsBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(aAttributeReportIBsBuilder.GetError(), CHIP_NO_ERROR); } -void ParseAttributeReportIBs(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseAttributeReportIBs(chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; AttributeReportIBs::Parser attributeReportIBsParser; err = attributeReportIBsParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); #if CHIP_CONFIG_IM_PRETTY_PRINT attributeReportIBsParser.PrettyPrint(); #endif } -void BuildCommandDataIB(nlTestSuite * apSuite, CommandDataIB::Builder & aCommandDataIBBuilder) +void BuildCommandDataIB(CommandDataIB::Builder & aCommandDataIBBuilder) { CHIP_ERROR err = CHIP_NO_ERROR; CommandPathIB::Builder & commandPathBuilder = aCommandDataIBBuilder.CreatePath(); - NL_TEST_ASSERT(apSuite, aCommandDataIBBuilder.GetError() == CHIP_NO_ERROR); - BuildCommandPath(apSuite, commandPathBuilder); + EXPECT_EQ(aCommandDataIBBuilder.GetError(), CHIP_NO_ERROR); + BuildCommandPath(commandPathBuilder); // Construct command data { @@ -743,20 +778,20 @@ void BuildCommandDataIB(nlTestSuite * apSuite, CommandDataIB::Builder & aCommand chip::TLV::TLVType dummyType = chip::TLV::kTLVType_NotSpecified; err = pWriter->StartContainer(chip::TLV::ContextTag(chip::to_underlying(CommandDataIB::Tag::kFields)), chip::TLV::kTLVType_Structure, dummyType); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = pWriter->PutBoolean(chip::TLV::ContextTag(1), true); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = pWriter->EndContainer(dummyType); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); } aCommandDataIBBuilder.EndOfCommandDataIB(); - NL_TEST_ASSERT(apSuite, aCommandDataIBBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(aCommandDataIBBuilder.GetError(), CHIP_NO_ERROR); } -void ParseCommandDataIB(nlTestSuite * apSuite, CommandDataIB::Parser & aCommandDataIBParser) +void ParseCommandDataIB(CommandDataIB::Parser & aCommandDataIBParser) { CHIP_ERROR err = CHIP_NO_ERROR; CommandPathIB::Parser commandPathParser; @@ -764,7 +799,7 @@ void ParseCommandDataIB(nlTestSuite * apSuite, CommandDataIB::Parser & aCommandD aCommandDataIBParser.PrettyPrint(); #endif err = aCommandDataIBParser.GetPath(&commandPathParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); { chip::TLV::TLVReader reader; @@ -772,34 +807,35 @@ void ParseCommandDataIB(nlTestSuite * apSuite, CommandDataIB::Parser & aCommandD chip::TLV::TLVType container; aCommandDataIBParser.GetFields(&reader); err = reader.EnterContainer(container); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = reader.Get(val); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && val); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_TRUE(val); err = reader.ExitContainer(container); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); } } -void BuildCommandStatusIB(nlTestSuite * apSuite, CommandStatusIB::Builder & aCommandStatusIBBuilder) +void BuildCommandStatusIB(CommandStatusIB::Builder & aCommandStatusIBBuilder) { CommandPathIB::Builder & commandPathBuilder = aCommandStatusIBBuilder.CreatePath(); - NL_TEST_ASSERT(apSuite, aCommandStatusIBBuilder.GetError() == CHIP_NO_ERROR); - BuildCommandPath(apSuite, commandPathBuilder); + EXPECT_EQ(aCommandStatusIBBuilder.GetError(), CHIP_NO_ERROR); + BuildCommandPath(commandPathBuilder); StatusIB::Builder & statusIBBuilder = aCommandStatusIBBuilder.CreateErrorStatus(); - NL_TEST_ASSERT(apSuite, statusIBBuilder.GetError() == CHIP_NO_ERROR); - BuildStatusIB(apSuite, statusIBBuilder); + EXPECT_EQ(statusIBBuilder.GetError(), CHIP_NO_ERROR); + BuildStatusIB(statusIBBuilder); aCommandStatusIBBuilder.EndOfCommandStatusIB(); - NL_TEST_ASSERT(apSuite, aCommandStatusIBBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(aCommandStatusIBBuilder.GetError(), CHIP_NO_ERROR); } -void ParseCommandStatusIB(nlTestSuite * apSuite, CommandStatusIB::Parser & aCommandStatusIBParser) +void ParseCommandStatusIB(CommandStatusIB::Parser & aCommandStatusIBParser) { CHIP_ERROR err = CHIP_NO_ERROR; CommandPathIB::Parser commandPathParser; @@ -808,37 +844,37 @@ void ParseCommandStatusIB(nlTestSuite * apSuite, CommandStatusIB::Parser & aComm aCommandStatusIBParser.PrettyPrint(); #endif err = aCommandStatusIBParser.GetPath(&commandPathParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = aCommandStatusIBParser.GetErrorStatus(&statusParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); } -void BuildWrongInvokeResponseIB(nlTestSuite * apSuite, InvokeResponseIB::Builder & aInvokeResponseIBBuilder) +void BuildWrongInvokeResponseIB(InvokeResponseIB::Builder & aInvokeResponseIBBuilder) { aInvokeResponseIBBuilder.CreateCommand(); - NL_TEST_ASSERT(apSuite, aInvokeResponseIBBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(aInvokeResponseIBBuilder.GetError(), CHIP_NO_ERROR); } -void BuildInvokeResponseIBWithCommandDataIB(nlTestSuite * apSuite, InvokeResponseIB::Builder & aInvokeResponseIBBuilder) +void BuildInvokeResponseIBWithCommandDataIB(InvokeResponseIB::Builder & aInvokeResponseIBBuilder) { CommandDataIB::Builder & commandDataBuilder = aInvokeResponseIBBuilder.CreateCommand(); - NL_TEST_ASSERT(apSuite, aInvokeResponseIBBuilder.GetError() == CHIP_NO_ERROR); - BuildCommandDataIB(apSuite, commandDataBuilder); + EXPECT_EQ(aInvokeResponseIBBuilder.GetError(), CHIP_NO_ERROR); + BuildCommandDataIB(commandDataBuilder); aInvokeResponseIBBuilder.EndOfInvokeResponseIB(); - NL_TEST_ASSERT(apSuite, aInvokeResponseIBBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(aInvokeResponseIBBuilder.GetError(), CHIP_NO_ERROR); } -void BuildInvokeResponseIBWithCommandStatusIB(nlTestSuite * apSuite, InvokeResponseIB::Builder & aInvokeResponseIBBuilder) +void BuildInvokeResponseIBWithCommandStatusIB(InvokeResponseIB::Builder & aInvokeResponseIBBuilder) { CommandStatusIB::Builder & commandStatusBuilder = aInvokeResponseIBBuilder.CreateStatus(); - NL_TEST_ASSERT(apSuite, aInvokeResponseIBBuilder.GetError() == CHIP_NO_ERROR); - BuildCommandStatusIB(apSuite, commandStatusBuilder); + EXPECT_EQ(aInvokeResponseIBBuilder.GetError(), CHIP_NO_ERROR); + BuildCommandStatusIB(commandStatusBuilder); aInvokeResponseIBBuilder.EndOfInvokeResponseIB(); - NL_TEST_ASSERT(apSuite, aInvokeResponseIBBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(aInvokeResponseIBBuilder.GetError(), CHIP_NO_ERROR); } -void ParseInvokeResponseIBWithCommandDataIB(nlTestSuite * apSuite, InvokeResponseIB::Parser & aInvokeResponseIBParser) +void ParseInvokeResponseIBWithCommandDataIB(InvokeResponseIB::Parser & aInvokeResponseIBParser) { CHIP_ERROR err = CHIP_NO_ERROR; CommandDataIB::Parser commandDataParser; @@ -847,10 +883,10 @@ void ParseInvokeResponseIBWithCommandDataIB(nlTestSuite * apSuite, InvokeRespons aInvokeResponseIBParser.PrettyPrint(); #endif err = aInvokeResponseIBParser.GetCommand(&commandDataParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); } -void ParseInvokeResponseIBWithCommandStatusIB(nlTestSuite * apSuite, InvokeResponseIB::Parser & aInvokeResponseIBParser) +void ParseInvokeResponseIBWithCommandStatusIB(InvokeResponseIB::Parser & aInvokeResponseIBParser) { CHIP_ERROR err = CHIP_NO_ERROR; CommandDataIB::Parser commandDataParser; @@ -859,90 +895,90 @@ void ParseInvokeResponseIBWithCommandStatusIB(nlTestSuite * apSuite, InvokeRespo aInvokeResponseIBParser.PrettyPrint(); #endif err = aInvokeResponseIBParser.GetStatus(&statusIBParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); } -void BuildInvokeRequests(nlTestSuite * apSuite, InvokeRequests::Builder & aInvokeRequestsBuilder) +void BuildInvokeRequests(InvokeRequests::Builder & aInvokeRequestsBuilder) { CommandDataIB::Builder & aCommandDataIBBuilder = aInvokeRequestsBuilder.CreateCommandData(); - NL_TEST_ASSERT(apSuite, aInvokeRequestsBuilder.GetError() == CHIP_NO_ERROR); - BuildCommandDataIB(apSuite, aCommandDataIBBuilder); + EXPECT_EQ(aInvokeRequestsBuilder.GetError(), CHIP_NO_ERROR); + BuildCommandDataIB(aCommandDataIBBuilder); aInvokeRequestsBuilder.EndOfInvokeRequests(); - NL_TEST_ASSERT(apSuite, aInvokeRequestsBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(aInvokeRequestsBuilder.GetError(), CHIP_NO_ERROR); } -void ParseInvokeRequests(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseInvokeRequests(chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; InvokeRequests::Parser invokeRequestsParser; err = invokeRequestsParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); #if CHIP_CONFIG_IM_PRETTY_PRINT invokeRequestsParser.PrettyPrint(); #endif } -void BuildInvokeResponses(nlTestSuite * apSuite, InvokeResponseIBs::Builder & aInvokeResponsesBuilder) +void BuildInvokeResponses(InvokeResponseIBs::Builder & aInvokeResponsesBuilder) { InvokeResponseIB::Builder & invokeResponseIBBuilder = aInvokeResponsesBuilder.CreateInvokeResponse(); - NL_TEST_ASSERT(apSuite, aInvokeResponsesBuilder.GetError() == CHIP_NO_ERROR); - BuildInvokeResponseIBWithCommandDataIB(apSuite, invokeResponseIBBuilder); + EXPECT_EQ(aInvokeResponsesBuilder.GetError(), CHIP_NO_ERROR); + BuildInvokeResponseIBWithCommandDataIB(invokeResponseIBBuilder); aInvokeResponsesBuilder.EndOfInvokeResponses(); - NL_TEST_ASSERT(apSuite, aInvokeResponsesBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(aInvokeResponsesBuilder.GetError(), CHIP_NO_ERROR); } -void ParseInvokeResponses(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseInvokeResponses(chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; InvokeResponseIBs::Parser invokeResponsesParser; err = invokeResponsesParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); #if CHIP_CONFIG_IM_PRETTY_PRINT invokeResponsesParser.PrettyPrint(); #endif } -void BuildInvokeRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) +void BuildInvokeRequestMessage(chip::TLV::TLVWriter & aWriter) { CHIP_ERROR err = CHIP_NO_ERROR; InvokeRequestMessage::Builder invokeRequestMessageBuilder; err = invokeRequestMessageBuilder.Init(&aWriter); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); invokeRequestMessageBuilder.SuppressResponse(true); invokeRequestMessageBuilder.TimedRequest(true); InvokeRequests::Builder & invokeRequestsBuilder = invokeRequestMessageBuilder.CreateInvokeRequests(); - NL_TEST_ASSERT(apSuite, invokeRequestsBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(invokeRequestsBuilder.GetError(), CHIP_NO_ERROR); - BuildInvokeRequests(apSuite, invokeRequestsBuilder); + BuildInvokeRequests(invokeRequestsBuilder); invokeRequestMessageBuilder.EndOfInvokeRequestMessage(); - NL_TEST_ASSERT(apSuite, invokeRequestMessageBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(invokeRequestMessageBuilder.GetError(), CHIP_NO_ERROR); } -void ParseInvokeRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseInvokeRequestMessage(chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; InvokeRequestMessage::Parser invokeRequestMessageParser; err = invokeRequestMessageParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); bool suppressResponse = false; bool timedRequest = false; invokeRequestMessageParser.GetSuppressResponse(&suppressResponse); invokeRequestMessageParser.GetTimedRequest(&timedRequest); - NL_TEST_ASSERT(apSuite, suppressResponse == true); - NL_TEST_ASSERT(apSuite, timedRequest == true); + EXPECT_TRUE(suppressResponse); + EXPECT_TRUE(timedRequest); #if CHIP_CONFIG_IM_PRETTY_PRINT invokeRequestMessageParser.PrettyPrint(); #endif - NL_TEST_ASSERT(apSuite, invokeRequestMessageParser.ExitContainer() == CHIP_NO_ERROR); + EXPECT_EQ(invokeRequestMessageParser.ExitContainer(), CHIP_NO_ERROR); } -void BuildInvokeResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) +void BuildInvokeResponseMessage(chip::TLV::TLVWriter & aWriter) { CHIP_ERROR err = CHIP_NO_ERROR; InvokeResponseMessage::Builder invokeResponseMessageBuilder; @@ -950,67 +986,67 @@ void BuildInvokeResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aW invokeResponseMessageBuilder.SuppressResponse(true); InvokeResponseIBs::Builder & invokeResponsesBuilder = invokeResponseMessageBuilder.CreateInvokeResponses(); - NL_TEST_ASSERT(apSuite, invokeResponseMessageBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(invokeResponseMessageBuilder.GetError(), CHIP_NO_ERROR); - BuildInvokeResponses(apSuite, invokeResponsesBuilder); + BuildInvokeResponses(invokeResponsesBuilder); invokeResponseMessageBuilder.MoreChunkedMessages(true); - NL_TEST_ASSERT(apSuite, invokeResponseMessageBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(invokeResponseMessageBuilder.GetError(), CHIP_NO_ERROR); invokeResponseMessageBuilder.EndOfInvokeResponseMessage(); - NL_TEST_ASSERT(apSuite, invokeResponseMessageBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(invokeResponseMessageBuilder.GetError(), CHIP_NO_ERROR); } -void ParseInvokeResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseInvokeResponseMessage(chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; InvokeResponseMessage::Parser invokeResponseMessageParser; err = invokeResponseMessageParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); bool suppressResponse = false; err = invokeResponseMessageParser.GetSuppressResponse(&suppressResponse); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - NL_TEST_ASSERT(apSuite, suppressResponse == true); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_TRUE(suppressResponse); bool moreChunkedMessages = true; err = invokeResponseMessageParser.GetMoreChunkedMessages(&suppressResponse); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - NL_TEST_ASSERT(apSuite, moreChunkedMessages == true); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_TRUE(moreChunkedMessages); #if CHIP_CONFIG_IM_PRETTY_PRINT invokeResponseMessageParser.PrettyPrint(); #endif - NL_TEST_ASSERT(apSuite, invokeResponseMessageParser.ExitContainer() == CHIP_NO_ERROR); + EXPECT_EQ(invokeResponseMessageParser.ExitContainer(), CHIP_NO_ERROR); } -void BuildReportDataMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) +void BuildReportDataMessage(chip::TLV::TLVWriter & aWriter) { CHIP_ERROR err = CHIP_NO_ERROR; ReportDataMessage::Builder reportDataMessageBuilder; err = reportDataMessageBuilder.Init(&aWriter); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); reportDataMessageBuilder.SubscriptionId(2); - NL_TEST_ASSERT(apSuite, reportDataMessageBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(reportDataMessageBuilder.GetError(), CHIP_NO_ERROR); AttributeReportIBs::Builder & attributeReportIBs = reportDataMessageBuilder.CreateAttributeReportIBs(); - NL_TEST_ASSERT(apSuite, reportDataMessageBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributeReportIBs(apSuite, attributeReportIBs); + EXPECT_EQ(reportDataMessageBuilder.GetError(), CHIP_NO_ERROR); + BuildAttributeReportIBs(attributeReportIBs); EventReportIBs::Builder & eventReportIBs = reportDataMessageBuilder.CreateEventReports(); - NL_TEST_ASSERT(apSuite, reportDataMessageBuilder.GetError() == CHIP_NO_ERROR); - BuildEventReports(apSuite, eventReportIBs); + EXPECT_EQ(reportDataMessageBuilder.GetError(), CHIP_NO_ERROR); + BuildEventReports(eventReportIBs); reportDataMessageBuilder.MoreChunkedMessages(true).SuppressResponse(true); - NL_TEST_ASSERT(apSuite, reportDataMessageBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(reportDataMessageBuilder.GetError(), CHIP_NO_ERROR); reportDataMessageBuilder.EndOfReportDataMessage(); - NL_TEST_ASSERT(apSuite, reportDataMessageBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(reportDataMessageBuilder.GetError(), CHIP_NO_ERROR); } -void ParseReportDataMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseReportDataMessage(chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; ReportDataMessage::Parser reportDataParser; @@ -1026,55 +1062,58 @@ void ParseReportDataMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aReade reportDataParser.PrettyPrint(); #endif err = reportDataParser.GetSuppressResponse(&suppressResponse); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && suppressResponse); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_TRUE(suppressResponse); err = reportDataParser.GetSubscriptionId(&subscriptionId); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && subscriptionId == 2); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(subscriptionId, 2u); err = reportDataParser.GetAttributeReportIBs(&attributeReportIBsParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = reportDataParser.GetEventReports(&eventReportsParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = reportDataParser.GetMoreChunkedMessages(&moreChunkedMessages); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && moreChunkedMessages); - NL_TEST_ASSERT(apSuite, reportDataParser.ExitContainer() == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_TRUE(moreChunkedMessages); + EXPECT_EQ(reportDataParser.ExitContainer(), CHIP_NO_ERROR); } -void BuildReadRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) +void BuildReadRequestMessage(chip::TLV::TLVWriter & aWriter) { CHIP_ERROR err = CHIP_NO_ERROR; ReadRequestMessage::Builder readRequestBuilder; err = readRequestBuilder.Init(&aWriter); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); AttributePathIBs::Builder & attributePathIBs = readRequestBuilder.CreateAttributeRequests(); - NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributePathList(apSuite, attributePathIBs); + EXPECT_EQ(readRequestBuilder.GetError(), CHIP_NO_ERROR); + BuildAttributePathList(attributePathIBs); EventPathIBs::Builder & eventPathList = readRequestBuilder.CreateEventRequests(); - NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); - BuildEventPaths(apSuite, eventPathList); + EXPECT_EQ(readRequestBuilder.GetError(), CHIP_NO_ERROR); + BuildEventPaths(eventPathList); EventFilterIBs::Builder & eventFilters = readRequestBuilder.CreateEventFilters(); - NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); - BuildEventFilters(apSuite, eventFilters); + EXPECT_EQ(readRequestBuilder.GetError(), CHIP_NO_ERROR); + BuildEventFilters(eventFilters); readRequestBuilder.IsFabricFiltered(true); - NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(readRequestBuilder.GetError(), CHIP_NO_ERROR); DataVersionFilterIBs::Builder & dataVersionFilters = readRequestBuilder.CreateDataVersionFilters(); - NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); - BuildDataVersionFilterIBs(apSuite, dataVersionFilters); + EXPECT_EQ(readRequestBuilder.GetError(), CHIP_NO_ERROR); + BuildDataVersionFilterIBs(dataVersionFilters); readRequestBuilder.EndOfReadRequestMessage(); - NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(readRequestBuilder.GetError(), CHIP_NO_ERROR); } -void ParseReadRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseReadRequestMessage(chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -1086,53 +1125,54 @@ void ParseReadRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aRead bool isFabricFiltered = false; err = readRequestParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); #if CHIP_CONFIG_IM_PRETTY_PRINT readRequestParser.PrettyPrint(); #endif err = readRequestParser.GetAttributeRequests(&attributePathListParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = readRequestParser.GetDataVersionFilters(&dataVersionFilterIBsParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = readRequestParser.GetEventRequests(&eventPathListParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = readRequestParser.GetEventFilters(&eventFiltersParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = readRequestParser.GetIsFabricFiltered(&isFabricFiltered); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && isFabricFiltered); - NL_TEST_ASSERT(apSuite, readRequestParser.ExitContainer() == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_TRUE(isFabricFiltered); + EXPECT_EQ(readRequestParser.ExitContainer(), CHIP_NO_ERROR); } -void BuildWriteRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) +void BuildWriteRequestMessage(chip::TLV::TLVWriter & aWriter) { CHIP_ERROR err = CHIP_NO_ERROR; WriteRequestMessage::Builder writeRequestBuilder; err = writeRequestBuilder.Init(&aWriter); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); writeRequestBuilder.SuppressResponse(true); - NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(writeRequestBuilder.GetError(), CHIP_NO_ERROR); writeRequestBuilder.TimedRequest(true); - NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(writeRequestBuilder.GetError(), CHIP_NO_ERROR); AttributeDataIBs::Builder & attributeDataIBs = writeRequestBuilder.CreateWriteRequests(); - NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributeDataIBs(apSuite, attributeDataIBs); + EXPECT_EQ(writeRequestBuilder.GetError(), CHIP_NO_ERROR); + BuildAttributeDataIBs(attributeDataIBs); writeRequestBuilder.MoreChunkedMessages(true); - NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(writeRequestBuilder.GetError(), CHIP_NO_ERROR); writeRequestBuilder.EndOfWriteRequestMessage(); - NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(writeRequestBuilder.GetError(), CHIP_NO_ERROR); } -void ParseWriteRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseWriteRequestMessage(chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -1143,97 +1183,100 @@ void ParseWriteRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aRea bool moreChunkedMessages = false; err = writeRequestParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); #if CHIP_CONFIG_IM_PRETTY_PRINT writeRequestParser.PrettyPrint(); #endif err = writeRequestParser.GetSuppressResponse(&suppressResponse); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && suppressResponse); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_TRUE(suppressResponse); err = writeRequestParser.GetTimedRequest(&timeRequest); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && timeRequest); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_TRUE(timeRequest); err = writeRequestParser.GetWriteRequests(&writeRequests); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = writeRequestParser.GetMoreChunkedMessages(&moreChunkedMessages); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && moreChunkedMessages); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_TRUE(moreChunkedMessages); } -void BuildWriteResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) +void BuildWriteResponseMessage(chip::TLV::TLVWriter & aWriter) { CHIP_ERROR err = CHIP_NO_ERROR; WriteResponseMessage::Builder writeResponseBuilder; err = writeResponseBuilder.Init(&aWriter); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); AttributeStatusIBs::Builder & attributeStatuses = writeResponseBuilder.CreateWriteResponses(); - NL_TEST_ASSERT(apSuite, writeResponseBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributeStatuses(apSuite, attributeStatuses); + EXPECT_EQ(writeResponseBuilder.GetError(), CHIP_NO_ERROR); + BuildAttributeStatuses(attributeStatuses); writeResponseBuilder.EndOfWriteResponseMessage(); - NL_TEST_ASSERT(apSuite, writeResponseBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(writeResponseBuilder.GetError(), CHIP_NO_ERROR); } -void ParseWriteResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseWriteResponseMessage(chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; WriteResponseMessage::Parser writeResponseParser; AttributeStatusIBs::Parser attributeStatusesParser; err = writeResponseParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); #if CHIP_CONFIG_IM_PRETTY_PRINT writeResponseParser.PrettyPrint(); #endif err = writeResponseParser.GetWriteResponses(&attributeStatusesParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - NL_TEST_ASSERT(apSuite, writeResponseParser.ExitContainer() == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(writeResponseParser.ExitContainer(), CHIP_NO_ERROR); } -void BuildSubscribeRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) +void BuildSubscribeRequestMessage(chip::TLV::TLVWriter & aWriter) { CHIP_ERROR err = CHIP_NO_ERROR; SubscribeRequestMessage::Builder subscribeRequestBuilder; err = subscribeRequestBuilder.Init(&aWriter); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); subscribeRequestBuilder.KeepSubscriptions(true); - NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(subscribeRequestBuilder.GetError(), CHIP_NO_ERROR); subscribeRequestBuilder.MinIntervalFloorSeconds(2); - NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(subscribeRequestBuilder.GetError(), CHIP_NO_ERROR); subscribeRequestBuilder.MaxIntervalCeilingSeconds(3); - NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(subscribeRequestBuilder.GetError(), CHIP_NO_ERROR); AttributePathIBs::Builder & attributePathIBs = subscribeRequestBuilder.CreateAttributeRequests(); - NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributePathList(apSuite, attributePathIBs); + EXPECT_EQ(subscribeRequestBuilder.GetError(), CHIP_NO_ERROR); + BuildAttributePathList(attributePathIBs); EventPathIBs::Builder & eventPathList = subscribeRequestBuilder.CreateEventRequests(); - NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); - BuildEventPaths(apSuite, eventPathList); + EXPECT_EQ(subscribeRequestBuilder.GetError(), CHIP_NO_ERROR); + BuildEventPaths(eventPathList); EventFilterIBs::Builder & eventFilters = subscribeRequestBuilder.CreateEventFilters(); - NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); - BuildEventFilters(apSuite, eventFilters); + EXPECT_EQ(subscribeRequestBuilder.GetError(), CHIP_NO_ERROR); + BuildEventFilters(eventFilters); subscribeRequestBuilder.IsFabricFiltered(true); - NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(subscribeRequestBuilder.GetError(), CHIP_NO_ERROR); DataVersionFilterIBs::Builder & dataVersionFilters = subscribeRequestBuilder.CreateDataVersionFilters(); - NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); - BuildDataVersionFilterIBs(apSuite, dataVersionFilters); + EXPECT_EQ(subscribeRequestBuilder.GetError(), CHIP_NO_ERROR); + BuildDataVersionFilterIBs(dataVersionFilters); subscribeRequestBuilder.EndOfSubscribeRequestMessage(); - NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(subscribeRequestBuilder.GetError(), CHIP_NO_ERROR); } -void ParseSubscribeRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseSubscribeRequestMessage(chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -1248,55 +1291,57 @@ void ParseSubscribeRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & bool isFabricFiltered = false; err = subscribeRequestParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); #if CHIP_CONFIG_IM_PRETTY_PRINT subscribeRequestParser.PrettyPrint(); #endif err = subscribeRequestParser.GetAttributeRequests(&attributePathListParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = subscribeRequestParser.GetDataVersionFilters(&dataVersionFilterIBsParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = subscribeRequestParser.GetEventRequests(&eventPathListParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = subscribeRequestParser.GetEventFilters(&eventFiltersParser); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = subscribeRequestParser.GetMinIntervalFloorSeconds(&minIntervalFloorSeconds); - NL_TEST_ASSERT(apSuite, minIntervalFloorSeconds == 2 && err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(minIntervalFloorSeconds, 2u); err = subscribeRequestParser.GetMaxIntervalCeilingSeconds(&maxIntervalCeilingSeconds); - NL_TEST_ASSERT(apSuite, maxIntervalCeilingSeconds == 3 && err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(maxIntervalCeilingSeconds, 3u); err = subscribeRequestParser.GetKeepSubscriptions(&keepExistingSubscription); - NL_TEST_ASSERT(apSuite, keepExistingSubscription && err == CHIP_NO_ERROR); + EXPECT_TRUE(keepExistingSubscription); err = subscribeRequestParser.GetIsFabricFiltered(&isFabricFiltered); - NL_TEST_ASSERT(apSuite, isFabricFiltered && err == CHIP_NO_ERROR); - NL_TEST_ASSERT(apSuite, subscribeRequestParser.ExitContainer() == CHIP_NO_ERROR); + EXPECT_TRUE(isFabricFiltered); + EXPECT_EQ(subscribeRequestParser.ExitContainer(), CHIP_NO_ERROR); } -void BuildSubscribeResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) +void BuildSubscribeResponseMessage(chip::TLV::TLVWriter & aWriter) { CHIP_ERROR err = CHIP_NO_ERROR; SubscribeResponseMessage::Builder subscribeResponseBuilder; err = subscribeResponseBuilder.Init(&aWriter); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); subscribeResponseBuilder.SubscriptionId(1); - NL_TEST_ASSERT(apSuite, subscribeResponseBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(subscribeResponseBuilder.GetError(), CHIP_NO_ERROR); subscribeResponseBuilder.MaxInterval(2); - NL_TEST_ASSERT(apSuite, subscribeResponseBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(subscribeResponseBuilder.GetError(), CHIP_NO_ERROR); subscribeResponseBuilder.EndOfSubscribeResponseMessage(); - NL_TEST_ASSERT(apSuite, subscribeResponseBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(subscribeResponseBuilder.GetError(), CHIP_NO_ERROR); } -void ParseSubscribeResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseSubscribeResponseMessage(chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -1304,32 +1349,34 @@ void ParseSubscribeResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & chip::SubscriptionId subscriptionId = 0; uint16_t maxInterval = 0; err = subscribeResponseParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); #if CHIP_CONFIG_IM_PRETTY_PRINT subscribeResponseParser.PrettyPrint(); #endif err = subscribeResponseParser.GetSubscriptionId(&subscriptionId); - NL_TEST_ASSERT(apSuite, subscriptionId == 1 && err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(subscriptionId, 1u); err = subscribeResponseParser.GetMaxInterval(&maxInterval); - NL_TEST_ASSERT(apSuite, maxInterval == 2 && err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(maxInterval, 2u); - NL_TEST_ASSERT(apSuite, subscribeResponseParser.ExitContainer() == CHIP_NO_ERROR); + EXPECT_EQ(subscribeResponseParser.ExitContainer(), CHIP_NO_ERROR); } -void BuildTimedRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) +void BuildTimedRequestMessage(chip::TLV::TLVWriter & aWriter) { CHIP_ERROR err = CHIP_NO_ERROR; TimedRequestMessage::Builder TimedRequestMessageBuilder; err = TimedRequestMessageBuilder.Init(&aWriter); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); TimedRequestMessageBuilder.TimeoutMs(1); - NL_TEST_ASSERT(apSuite, TimedRequestMessageBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(TimedRequestMessageBuilder.GetError(), CHIP_NO_ERROR); } -void ParseTimedRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseTimedRequestMessage(chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -1337,17 +1384,19 @@ void ParseTimedRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aRea uint16_t timeout = 0; err = timedRequestMessageParser.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); #if CHIP_CONFIG_IM_PRETTY_PRINT timedRequestMessageParser.PrettyPrint(); #endif err = timedRequestMessageParser.GetTimeoutMs(&timeout); - NL_TEST_ASSERT(apSuite, timeout == 1 && err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); + + EXPECT_EQ(timeout, 1u); - NL_TEST_ASSERT(apSuite, timedRequestMessageParser.ExitContainer() == CHIP_NO_ERROR); + EXPECT_EQ(timedRequestMessageParser.ExitContainer(), CHIP_NO_ERROR); } -void DataVersionFilterIBTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestDataVersionFilterIB) { CHIP_ERROR err = CHIP_NO_ERROR; DataVersionFilterIB::Builder dataVersionFilterIBBuilder; @@ -1355,20 +1404,20 @@ void DataVersionFilterIBTest(nlTestSuite * apSuite, void * apContext) chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); dataVersionFilterIBBuilder.Init(&writer); - BuildDataVersionFilterIB(apSuite, dataVersionFilterIBBuilder); + BuildDataVersionFilterIB(dataVersionFilterIBBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - ParseDataVersionFilterIB(apSuite, reader); + EXPECT_EQ(err, CHIP_NO_ERROR); + ParseDataVersionFilterIB(reader); } -void DataVersionFilterIBsTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestDataVersionFilterIBs) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; @@ -1377,22 +1426,22 @@ void DataVersionFilterIBsTest(nlTestSuite * apSuite, void * apContext) writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); err = dataVersionFilterIBsBuilder.Init(&writer); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); - BuildDataVersionFilterIBs(apSuite, dataVersionFilterIBsBuilder); + BuildDataVersionFilterIBs(dataVersionFilterIBsBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - ParseDataVersionFilterIBs(apSuite, reader); + EXPECT_EQ(err, CHIP_NO_ERROR); + ParseDataVersionFilterIBs(reader); } -void EventFilterTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestEventFilter) { CHIP_ERROR err = CHIP_NO_ERROR; EventFilterIB::Builder eventFilterBuilder; @@ -1400,20 +1449,20 @@ void EventFilterTest(nlTestSuite * apSuite, void * apContext) chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); eventFilterBuilder.Init(&writer); - BuildEventFilterIB(apSuite, eventFilterBuilder); + BuildEventFilterIB(eventFilterBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - ParseEventFilterIB(apSuite, reader); + EXPECT_EQ(err, CHIP_NO_ERROR); + ParseEventFilterIB(reader); } -void EventFiltersTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestEventFilters) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; @@ -1423,22 +1472,22 @@ void EventFiltersTest(nlTestSuite * apSuite, void * apContext) writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); err = eventFiltersBuilder.Init(&writer); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); - BuildEventFilters(apSuite, eventFiltersBuilder); + BuildEventFilters(eventFiltersBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - ParseEventFilters(apSuite, reader); + EXPECT_EQ(err, CHIP_NO_ERROR); + ParseEventFilters(reader); } -void ClusterPathIBTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestClusterPathIB) { CHIP_ERROR err = CHIP_NO_ERROR; ClusterPathIB::Builder clusterPathBuilder; @@ -1446,21 +1495,21 @@ void ClusterPathIBTest(nlTestSuite * apSuite, void * apContext) chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); clusterPathBuilder.Init(&writer); - BuildClusterPathIB(apSuite, clusterPathBuilder); + BuildClusterPathIB(clusterPathBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); - ParseClusterPathIB(apSuite, reader); + ParseClusterPathIB(reader); } -void AttributePathTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestAttributePath) { CHIP_ERROR err = CHIP_NO_ERROR; AttributePathIB::Builder attributePathBuilder; @@ -1468,21 +1517,21 @@ void AttributePathTest(nlTestSuite * apSuite, void * apContext) chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); attributePathBuilder.Init(&writer); - BuildAttributePathIB(apSuite, attributePathBuilder); + BuildAttributePathIB(attributePathBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); - ParseAttributePathIB(apSuite, reader); + ParseAttributePathIB(reader); } -void AttributePathListTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestAttributePathList) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; @@ -1492,22 +1541,22 @@ void AttributePathListTest(nlTestSuite * apSuite, void * apContext) writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); err = attributePathListBuilder.Init(&writer); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); - BuildAttributePathList(apSuite, attributePathListBuilder); + BuildAttributePathList(attributePathListBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - ParseAttributePathList(apSuite, reader); + EXPECT_EQ(err, CHIP_NO_ERROR); + ParseAttributePathList(reader); } -void EventPathTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestEventPath) { CHIP_ERROR err = CHIP_NO_ERROR; EventPathIB::Parser eventPathParser; @@ -1516,22 +1565,22 @@ void EventPathTest(nlTestSuite * apSuite, void * apContext) chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); eventPathBuilder.Init(&writer); - BuildEventPath(apSuite, eventPathBuilder); + BuildEventPath(eventPathBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); eventPathParser.Init(reader); - ParseEventPath(apSuite, eventPathParser); + ParseEventPath(eventPathParser); } -void EventPathsTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestEventPaths) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; @@ -1541,22 +1590,22 @@ void EventPathsTest(nlTestSuite * apSuite, void * apContext) writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); err = eventPathListBuilder.Init(&writer); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); - BuildEventPaths(apSuite, eventPathListBuilder); + BuildEventPaths(eventPathListBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - ParseEventPaths(apSuite, reader); + EXPECT_EQ(err, CHIP_NO_ERROR); + ParseEventPaths(reader); } -void CommandPathIBTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestCommandPathIB) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; @@ -1564,24 +1613,24 @@ void CommandPathIBTest(nlTestSuite * apSuite, void * apContext) CommandPathIB::Builder commandPathBuilder; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); err = commandPathBuilder.Init(&writer); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); - BuildCommandPath(apSuite, commandPathBuilder); + BuildCommandPath(commandPathBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); - ParseCommandPath(apSuite, reader); + ParseCommandPath(reader); } -void EventDataIBTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestEventDataIB) { CHIP_ERROR err = CHIP_NO_ERROR; EventDataIB::Builder eventDataIBBuilder; @@ -1590,22 +1639,22 @@ void EventDataIBTest(nlTestSuite * apSuite, void * apContext) chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); eventDataIBBuilder.Init(&writer); - BuildEventDataIB(apSuite, eventDataIBBuilder); + BuildEventDataIB(eventDataIBBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); eventDataIBParser.Init(reader); - ParseEventDataIB(apSuite, eventDataIBParser); + ParseEventDataIB(eventDataIBParser); } -void EventReportIBTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestEventReportIB) { CHIP_ERROR err = CHIP_NO_ERROR; EventReportIB::Builder eventReportIBBuilder; @@ -1614,22 +1663,22 @@ void EventReportIBTest(nlTestSuite * apSuite, void * apContext) chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); eventReportIBBuilder.Init(&writer); - BuildEventReportIB(apSuite, eventReportIBBuilder); + BuildEventReportIB(eventReportIBBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); eventReportIBParser.Init(reader); - ParseEventReportIB(apSuite, eventReportIBParser); + ParseEventReportIB(eventReportIBParser); } -void EventReportsTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestEventReports) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; @@ -1637,20 +1686,20 @@ void EventReportsTest(nlTestSuite * apSuite, void * apContext) EventReportIBs::Builder eventReportsBuilder; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); eventReportsBuilder.Init(&writer); - BuildEventReports(apSuite, eventReportsBuilder); + BuildEventReports(eventReportsBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - ParseEventReports(apSuite, reader); + EXPECT_EQ(err, CHIP_NO_ERROR); + ParseEventReports(reader); } -void EmptyEventReportsTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestEmptyEventReports) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; @@ -1659,20 +1708,20 @@ void EmptyEventReportsTest(nlTestSuite * apSuite, void * apContext) writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); eventReportsBuilder.Init(&writer); eventReportsBuilder.EndOfEventReports(); - NL_TEST_ASSERT(apSuite, eventReportsBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(eventReportsBuilder.GetError(), CHIP_NO_ERROR); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - ParseEventReports(apSuite, reader); + EXPECT_EQ(err, CHIP_NO_ERROR); + ParseEventReports(reader); } -void AttributeReportIBTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestAttributeReportIB) { CHIP_ERROR err = CHIP_NO_ERROR; AttributeReportIB::Builder attributeReportIBBuilder; @@ -1681,22 +1730,22 @@ void AttributeReportIBTest(nlTestSuite * apSuite, void * apContext) chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); attributeReportIBBuilder.Init(&writer); - BuildAttributeReportIB(apSuite, attributeReportIBBuilder); + BuildAttributeReportIB(attributeReportIBBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); attributeReportIBParser.Init(reader); - ParseAttributeReportIB(apSuite, attributeReportIBParser); + ParseAttributeReportIB(attributeReportIBParser); } -void AttributeReportIBsTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestAttributeReportIBs) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; @@ -1704,20 +1753,20 @@ void AttributeReportIBsTest(nlTestSuite * apSuite, void * apContext) AttributeReportIBs::Builder attributeReportIBsBuilder; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); attributeReportIBsBuilder.Init(&writer); - BuildAttributeReportIBs(apSuite, attributeReportIBsBuilder); + BuildAttributeReportIBs(attributeReportIBsBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - ParseAttributeReportIBs(apSuite, reader); + EXPECT_EQ(err, CHIP_NO_ERROR); + ParseAttributeReportIBs(reader); } -void EmptyAttributeReportIBsTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestEmptyAttributeReportIBs) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; @@ -1726,20 +1775,20 @@ void EmptyAttributeReportIBsTest(nlTestSuite * apSuite, void * apContext) writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); attributeReportIBsBuilder.Init(&writer); attributeReportIBsBuilder.EndOfAttributeReportIBs(); - NL_TEST_ASSERT(apSuite, attributeReportIBsBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(attributeReportIBsBuilder.GetError(), CHIP_NO_ERROR); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - ParseAttributeReportIBs(apSuite, reader); + EXPECT_EQ(err, CHIP_NO_ERROR); + ParseAttributeReportIBs(reader); } -void StatusIBTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestStatusIB) { CHIP_ERROR err = CHIP_NO_ERROR; StatusIB::Builder statusIBBuilder; @@ -1748,22 +1797,22 @@ void StatusIBTest(nlTestSuite * apSuite, void * apContext) chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); statusIBBuilder.Init(&writer); - BuildStatusIB(apSuite, statusIBBuilder); + BuildStatusIB(statusIBBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); StatusIBParser.Init(reader); - ParseStatusIB(apSuite, StatusIBParser); + ParseStatusIB(StatusIBParser); } -void EventStatusIBTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestEventStatusIB) { CHIP_ERROR err = CHIP_NO_ERROR; EventStatusIB::Builder eventStatusIBBuilder; @@ -1772,22 +1821,22 @@ void EventStatusIBTest(nlTestSuite * apSuite, void * apContext) chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); eventStatusIBBuilder.Init(&writer); - BuildEventStatusIB(apSuite, eventStatusIBBuilder); + BuildEventStatusIB(eventStatusIBBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); eventStatusIBParser.Init(reader); - ParseEventStatusIB(apSuite, eventStatusIBParser); + ParseEventStatusIB(eventStatusIBParser); } -void AttributeStatusIBTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestAttributeStatusIB) { CHIP_ERROR err = CHIP_NO_ERROR; AttributeStatusIB::Builder attributeStatusIBBuilder; @@ -1796,22 +1845,22 @@ void AttributeStatusIBTest(nlTestSuite * apSuite, void * apContext) chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); attributeStatusIBBuilder.Init(&writer); - BuildAttributeStatusIB(apSuite, attributeStatusIBBuilder); + BuildAttributeStatusIB(attributeStatusIBBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); attributeStatusIBParser.Init(reader); - ParseAttributeStatusIB(apSuite, attributeStatusIBParser); + ParseAttributeStatusIB(attributeStatusIBParser); } -void AttributeStatusesTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestAttributeStatuses) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; @@ -1819,21 +1868,21 @@ void AttributeStatusesTest(nlTestSuite * apSuite, void * apContext) writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); AttributeStatusIBs::Builder attributeStatusesBuilder; err = attributeStatusesBuilder.Init(&writer); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - BuildAttributeStatuses(apSuite, attributeStatusesBuilder); + EXPECT_EQ(err, CHIP_NO_ERROR); + BuildAttributeStatuses(attributeStatusesBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - ParseAttributeStatuses(apSuite, reader); + EXPECT_EQ(err, CHIP_NO_ERROR); + ParseAttributeStatuses(reader); } -void AttributeDataIBTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestAttributeDataIB) { CHIP_ERROR err = CHIP_NO_ERROR; AttributeDataIB::Builder AttributeDataIBBuilder; @@ -1842,22 +1891,22 @@ void AttributeDataIBTest(nlTestSuite * apSuite, void * apContext) chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); AttributeDataIBBuilder.Init(&writer); - BuildAttributeDataIB(apSuite, AttributeDataIBBuilder); + BuildAttributeDataIB(AttributeDataIBBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); AttributeDataIBParser.Init(reader); - ParseAttributeDataIB(apSuite, AttributeDataIBParser); + ParseAttributeDataIB(AttributeDataIBParser); } -void AttributeDataIBsTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestAttributeDataIBs) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; @@ -1865,20 +1914,20 @@ void AttributeDataIBsTest(nlTestSuite * apSuite, void * apContext) writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); AttributeDataIBs::Builder AttributeDataIBsBuilder; AttributeDataIBsBuilder.Init(&writer); - BuildAttributeDataIBs(apSuite, AttributeDataIBsBuilder); + BuildAttributeDataIBs(AttributeDataIBsBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - ParseAttributeDataIBs(apSuite, reader); + EXPECT_EQ(err, CHIP_NO_ERROR); + ParseAttributeDataIBs(reader); } -void CommandDataIBTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestCommandDataIB) { CHIP_ERROR err = CHIP_NO_ERROR; CommandDataIB::Builder commandDataIBBuilder; @@ -1887,22 +1936,22 @@ void CommandDataIBTest(nlTestSuite * apSuite, void * apContext) chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); commandDataIBBuilder.Init(&writer); - BuildCommandDataIB(apSuite, commandDataIBBuilder); + BuildCommandDataIB(commandDataIBBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); commandDataIBParser.Init(reader); - ParseCommandDataIB(apSuite, commandDataIBParser); + ParseCommandDataIB(commandDataIBParser); } -void CommandStatusIBTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestCommandStatusIB) { CHIP_ERROR err = CHIP_NO_ERROR; CommandStatusIB::Builder commandStatusIBBuilder; @@ -1911,22 +1960,22 @@ void CommandStatusIBTest(nlTestSuite * apSuite, void * apContext) chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); commandStatusIBBuilder.Init(&writer); - BuildCommandStatusIB(apSuite, commandStatusIBBuilder); + BuildCommandStatusIB(commandStatusIBBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); commandStatusIBParser.Init(reader); - ParseCommandStatusIB(apSuite, commandStatusIBParser); + ParseCommandStatusIB(commandStatusIBParser); } -void InvokeResponseIBWithCommandDataIBTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestInvokeResponseIBWithCommandDataIB) { CHIP_ERROR err = CHIP_NO_ERROR; InvokeResponseIB::Builder invokeResponseIBBuilder; @@ -1935,22 +1984,22 @@ void InvokeResponseIBWithCommandDataIBTest(nlTestSuite * apSuite, void * apConte chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); invokeResponseIBBuilder.Init(&writer); - BuildInvokeResponseIBWithCommandDataIB(apSuite, invokeResponseIBBuilder); + BuildInvokeResponseIBWithCommandDataIB(invokeResponseIBBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); invokeResponseIBParser.Init(reader); - ParseInvokeResponseIBWithCommandDataIB(apSuite, invokeResponseIBParser); + ParseInvokeResponseIBWithCommandDataIB(invokeResponseIBParser); } -void InvokeResponseIBWithCommandStatusIBTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestInvokeResponseIBWithCommandStatusIB) { CHIP_ERROR err = CHIP_NO_ERROR; InvokeResponseIB::Builder invokeResponseIBBuilder; @@ -1959,22 +2008,22 @@ void InvokeResponseIBWithCommandStatusIBTest(nlTestSuite * apSuite, void * apCon chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); invokeResponseIBBuilder.Init(&writer); - BuildInvokeResponseIBWithCommandStatusIB(apSuite, invokeResponseIBBuilder); + BuildInvokeResponseIBWithCommandStatusIB(invokeResponseIBBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); invokeResponseIBParser.Init(reader); - ParseInvokeResponseIBWithCommandStatusIB(apSuite, invokeResponseIBParser); + ParseInvokeResponseIBWithCommandStatusIB(invokeResponseIBParser); } -void InvokeResponseIBWithMalformDataTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestInvokeResponseIBWithMalformData) { CHIP_ERROR err = CHIP_NO_ERROR; InvokeResponseIB::Builder invokeResponseIBBuilder; @@ -1983,22 +2032,22 @@ void InvokeResponseIBWithMalformDataTest(nlTestSuite * apSuite, void * apContext chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); invokeResponseIBBuilder.Init(&writer); - BuildWrongInvokeResponseIB(apSuite, invokeResponseIBBuilder); + BuildWrongInvokeResponseIB(invokeResponseIBBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = invokeResponseIBParser.Init(reader); - NL_TEST_ASSERT(apSuite, err != CHIP_NO_ERROR); + EXPECT_NE(err, CHIP_NO_ERROR); } -void InvokeRequestsTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestInvokeRequests) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; @@ -2006,20 +2055,20 @@ void InvokeRequestsTest(nlTestSuite * apSuite, void * apContext) InvokeRequests::Builder invokeRequestsBuilder; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); invokeRequestsBuilder.Init(&writer); - BuildInvokeRequests(apSuite, invokeRequestsBuilder); + BuildInvokeRequests(invokeRequestsBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - ParseInvokeRequests(apSuite, reader); + EXPECT_EQ(err, CHIP_NO_ERROR); + ParseInvokeRequests(reader); } -void InvokeResponsesTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestInvokeResponses) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; @@ -2027,37 +2076,37 @@ void InvokeResponsesTest(nlTestSuite * apSuite, void * apContext) InvokeResponseIBs::Builder invokeResponsesBuilder; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); invokeResponsesBuilder.Init(&writer); - BuildInvokeResponses(apSuite, invokeResponsesBuilder); + BuildInvokeResponses(invokeResponsesBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - ParseInvokeResponses(apSuite, reader); + EXPECT_EQ(err, CHIP_NO_ERROR); + ParseInvokeResponses(reader); } -void InvokeInvokeRequestMessageTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestInvokeInvokeRequestMessage) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); - BuildInvokeRequestMessage(apSuite, writer); + BuildInvokeRequestMessage(writer); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); - ParseInvokeRequestMessage(apSuite, reader); + ParseInvokeRequestMessage(reader); } -void InvokeRequestMessageEndOfMessageReservationTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestInvokeRequestMessageEndOfMessageReservation) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; @@ -2065,18 +2114,18 @@ void InvokeRequestMessageEndOfMessageReservationTest(nlTestSuite * apSuite, void const uint32_t kSmallBufferSize = 100; writer.Init(chip::System::PacketBufferHandle::New(kSmallBufferSize, /* aReservedSize = */ 0), /* useChainedBuffers = */ false); err = invokeRequestMessageBuilder.InitWithEndBufferReserved(&writer); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); uint32_t remainingLengthAfterInitWithReservation = writer.GetRemainingFreeLength(); err = invokeRequestMessageBuilder.EndOfInvokeRequestMessage(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); uint32_t remainingLengthAfterEndingInvokeRequestMessage = writer.GetRemainingFreeLength(); - NL_TEST_ASSERT(apSuite, remainingLengthAfterInitWithReservation == remainingLengthAfterEndingInvokeRequestMessage); + EXPECT_EQ(remainingLengthAfterInitWithReservation, remainingLengthAfterEndingInvokeRequestMessage); } -void InvokeRequestsEndOfRequestReservationTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestInvokeRequestsEndOfRequestReservation) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; @@ -2084,41 +2133,41 @@ void InvokeRequestsEndOfRequestReservationTest(nlTestSuite * apSuite, void * apC const uint32_t kSmallBufferSize = 100; writer.Init(chip::System::PacketBufferHandle::New(kSmallBufferSize, /* aReservedSize = */ 0), /* useChainedBuffers = */ false); err = invokeRequestMessageBuilder.InitWithEndBufferReserved(&writer); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); invokeRequestMessageBuilder.CreateInvokeRequests(/* aReserveEndBuffer = */ true); InvokeRequests::Builder & invokeRequestsBuilder = invokeRequestMessageBuilder.GetInvokeRequests(); err = invokeRequestsBuilder.GetError(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); auto * invokeRequestsWriter = invokeRequestsBuilder.GetWriter(); uint32_t remainingLengthAfterInitWithReservation = invokeRequestsWriter->GetRemainingFreeLength(); err = invokeRequestsBuilder.EndOfInvokeRequests(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); uint32_t remainingLengthAfterEndingInvokeRequests = invokeRequestsWriter->GetRemainingFreeLength(); - NL_TEST_ASSERT(apSuite, remainingLengthAfterInitWithReservation == remainingLengthAfterEndingInvokeRequests); + EXPECT_EQ(remainingLengthAfterInitWithReservation, remainingLengthAfterEndingInvokeRequests); } -void InvokeInvokeResponseMessageTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestInvokeInvokeResponseMessage) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); - BuildInvokeResponseMessage(apSuite, writer); + BuildInvokeResponseMessage(writer); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); - ParseInvokeResponseMessage(apSuite, reader); + ParseInvokeResponseMessage(reader); } -void InvokeResponseMessageEndOfMessageReservationTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestInvokeResponseMessageEndOfMessageReservation) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; @@ -2126,17 +2175,17 @@ void InvokeResponseMessageEndOfMessageReservationTest(nlTestSuite * apSuite, voi const uint32_t kSmallBufferSize = 100; writer.Init(chip::System::PacketBufferHandle::New(kSmallBufferSize, /* aReservedSize = */ 0), /* useChainedBuffers = */ false); err = invokeResponseMessageBuilder.InitWithEndBufferReserved(&writer); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); uint32_t remainingLengthAfterInitWithReservation = writer.GetRemainingFreeLength(); err = invokeResponseMessageBuilder.EndOfInvokeResponseMessage(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); uint32_t remainingLengthAfterEndingInvokeResponseMessage = writer.GetRemainingFreeLength(); - NL_TEST_ASSERT(apSuite, remainingLengthAfterInitWithReservation == remainingLengthAfterEndingInvokeResponseMessage); + EXPECT_EQ(remainingLengthAfterInitWithReservation, remainingLengthAfterEndingInvokeResponseMessage); } -void InvokeResponseMessageReservationForEndandMoreChunkTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestInvokeResponseMessageReservationForEndandMoreChunk) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; @@ -2144,22 +2193,22 @@ void InvokeResponseMessageReservationForEndandMoreChunkTest(nlTestSuite * apSuit const uint32_t kSmallBufferSize = 100; writer.Init(chip::System::PacketBufferHandle::New(kSmallBufferSize, /* aReservedSize = */ 0), /* useChainedBuffers = */ false); err = invokeResponseMessageBuilder.InitWithEndBufferReserved(&writer); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = invokeResponseMessageBuilder.ReserveSpaceForMoreChunkedMessages(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); uint32_t remainingLengthAllReservations = writer.GetRemainingFreeLength(); invokeResponseMessageBuilder.MoreChunkedMessages(/* aMoreChunkedMessages = */ true); - NL_TEST_ASSERT(apSuite, invokeResponseMessageBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(invokeResponseMessageBuilder.GetError(), CHIP_NO_ERROR); err = invokeResponseMessageBuilder.EndOfInvokeResponseMessage(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); uint32_t remainingLengthAfterEndingInvokeResponseMessage = writer.GetRemainingFreeLength(); - NL_TEST_ASSERT(apSuite, remainingLengthAllReservations == remainingLengthAfterEndingInvokeResponseMessage); + EXPECT_EQ(remainingLengthAllReservations, remainingLengthAfterEndingInvokeResponseMessage); } -void InvokeResponsesEndOfResponseReservationTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestInvokeResponsesEndOfResponseReservation) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; @@ -2167,142 +2216,142 @@ void InvokeResponsesEndOfResponseReservationTest(nlTestSuite * apSuite, void * a const uint32_t kSmallBufferSize = 100; writer.Init(chip::System::PacketBufferHandle::New(kSmallBufferSize, /* aReservedSize = */ 0), /* useChainedBuffers = */ false); err = invokeResponseMessageBuilder.InitWithEndBufferReserved(&writer); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); invokeResponseMessageBuilder.CreateInvokeResponses(/* aReserveEndBuffer = */ true); InvokeResponseIBs::Builder & invokeResponsesBuilder = invokeResponseMessageBuilder.GetInvokeResponses(); err = invokeResponsesBuilder.GetError(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); auto * invokeResponsesWriter = invokeResponsesBuilder.GetWriter(); uint32_t remainingLengthAfterInitWithReservation = invokeResponsesWriter->GetRemainingFreeLength(); err = invokeResponsesBuilder.EndOfInvokeResponses(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); uint32_t remainingLengthAfterEndingInvokeResponses = invokeResponsesWriter->GetRemainingFreeLength(); - NL_TEST_ASSERT(apSuite, remainingLengthAfterInitWithReservation == remainingLengthAfterEndingInvokeResponses); + EXPECT_EQ(remainingLengthAfterInitWithReservation, remainingLengthAfterEndingInvokeResponses); } -void ReportDataMessageTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestReportDataMessage) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); - BuildReportDataMessage(apSuite, writer); + BuildReportDataMessage(writer); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); - ParseReportDataMessage(apSuite, reader); + ParseReportDataMessage(reader); } -void ReadRequestMessageTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestReadRequestMessage) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); - BuildReadRequestMessage(apSuite, writer); + BuildReadRequestMessage(writer); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); - ParseReadRequestMessage(apSuite, reader); + ParseReadRequestMessage(reader); } -void WriteRequestMessageTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestWriteRequestMessage) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); - BuildWriteRequestMessage(apSuite, writer); + BuildWriteRequestMessage(writer); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); - ParseWriteRequestMessage(apSuite, reader); + ParseWriteRequestMessage(reader); } -void WriteResponseMessageTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestWriteResponseMessage) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); - BuildWriteResponseMessage(apSuite, writer); + BuildWriteResponseMessage(writer); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); - ParseWriteResponseMessage(apSuite, reader); + ParseWriteResponseMessage(reader); } -void SubscribeRequestMessageTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestSubscribeRequestMessage) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); - BuildSubscribeRequestMessage(apSuite, writer); + BuildSubscribeRequestMessage(writer); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); - ParseSubscribeRequestMessage(apSuite, reader); + ParseSubscribeRequestMessage(reader); } -void SubscribeResponseMessageTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestSubscribeResponseMessage) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); - BuildSubscribeResponseMessage(apSuite, writer); + BuildSubscribeResponseMessage(writer); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); - ParseSubscribeResponseMessage(apSuite, reader); + ParseSubscribeResponseMessage(reader); } -void TimedRequestMessageTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestTimedRequestMessage) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); - BuildTimedRequestMessage(apSuite, writer); + BuildTimedRequestMessage(writer); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); - ParseTimedRequestMessage(apSuite, reader); + ParseTimedRequestMessage(reader); } -void CheckPointRollbackTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestMessageDef, TestCheckPointRollback) { CHIP_ERROR err = CHIP_NO_ERROR; size_t NumDataElement = 0; @@ -2316,32 +2365,32 @@ void CheckPointRollbackTest(nlTestSuite * apSuite, void * apContext) // encode one attribute element AttributeDataIB::Builder & attributeDataIBBuilder1 = attributeDataIBsBuilder.CreateAttributeDataIBBuilder(); - NL_TEST_ASSERT(apSuite, attributeDataIBsBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributeDataIB(apSuite, attributeDataIBBuilder1); + EXPECT_EQ(attributeDataIBsBuilder.GetError(), CHIP_NO_ERROR); + BuildAttributeDataIB(attributeDataIBBuilder1); // checkpoint attributeDataIBsBuilder.Checkpoint(checkpoint); // encode another attribute element AttributeDataIB::Builder & attributeDataIBBuilder2 = attributeDataIBsBuilder.CreateAttributeDataIBBuilder(); - NL_TEST_ASSERT(apSuite, attributeDataIBsBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributeDataIB(apSuite, attributeDataIBBuilder2); + EXPECT_EQ(attributeDataIBsBuilder.GetError(), CHIP_NO_ERROR); + BuildAttributeDataIB(attributeDataIBBuilder2); // rollback to previous checkpoint attributeDataIBsBuilder.Rollback(checkpoint); attributeDataIBsBuilder.EndOfAttributeDataIBs(); - NL_TEST_ASSERT(apSuite, attributeDataIBsBuilder.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(attributeDataIBsBuilder.GetError(), CHIP_NO_ERROR); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); DebugPrettyPrint(buf); reader.Init(std::move(buf)); err = reader.Next(); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = AttributeDataIBsParser.Init(reader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); #if CHIP_CONFIG_IM_PRETTY_PRINT AttributeDataIBsParser.PrettyPrint(); @@ -2351,101 +2400,7 @@ void CheckPointRollbackTest(nlTestSuite * apSuite, void * apContext) ++NumDataElement; } - NL_TEST_ASSERT(apSuite, NumDataElement == 1); + EXPECT_EQ(NumDataElement, 1u); } -/** - * Test Suite. It lists all the test functions. - */ - -// clang-format off -const nlTest sTests[] = - { - NL_TEST_DEF("ClusterPathIBTest", ClusterPathIBTest), - NL_TEST_DEF("DataVersionFilterIBTest", DataVersionFilterIBTest), - NL_TEST_DEF("DataVersionFilterIBsTest", DataVersionFilterIBsTest), - NL_TEST_DEF("EventFilterTest", EventFilterTest), - NL_TEST_DEF("EventFiltersTest", EventFiltersTest), - NL_TEST_DEF("AttributePathTest", AttributePathTest), - NL_TEST_DEF("AttributePathListTest", AttributePathListTest), - NL_TEST_DEF("AttributeStatusIBTest", AttributeStatusIBTest), - NL_TEST_DEF("AttributeStatusesTest", AttributeStatusesTest), - NL_TEST_DEF("AttributeDataIBTest", AttributeDataIBTest), - NL_TEST_DEF("AttributeDataIBsTest", AttributeDataIBsTest), - NL_TEST_DEF("AttributeReportIBTest", AttributeReportIBTest), - NL_TEST_DEF("AttributeReportIBsTest", AttributeReportIBsTest), - NL_TEST_DEF("EmptyAttributeReportIBsTest", EmptyAttributeReportIBsTest), - NL_TEST_DEF("EventPathTest", EventPathTest), - NL_TEST_DEF("EventPathsTest", EventPathsTest), - NL_TEST_DEF("EventDataIBTest", EventDataIBTest), - NL_TEST_DEF("EventReportIBTest", EventReportIBTest), - NL_TEST_DEF("EventReportsTest", EventReportsTest), - NL_TEST_DEF("EmptyEventReportsTest", EmptyEventReportsTest), - NL_TEST_DEF("StatusIBTest", StatusIBTest), - NL_TEST_DEF("EventStatusIBTest", EventStatusIBTest), - NL_TEST_DEF("CommandPathIBTest", CommandPathIBTest), - NL_TEST_DEF("CommandDataIBTest", CommandDataIBTest), - NL_TEST_DEF("CommandStatusIBTest", CommandStatusIBTest), - NL_TEST_DEF("InvokeResponseIBWithCommandDataIBTest", InvokeResponseIBWithCommandDataIBTest), - NL_TEST_DEF("InvokeResponseIBWithCommandStatusIBTest", InvokeResponseIBWithCommandStatusIBTest), - NL_TEST_DEF("InvokeResponseIBWithMalformDataTest", InvokeResponseIBWithMalformDataTest), - NL_TEST_DEF("InvokeRequestsTest", InvokeRequestsTest), - NL_TEST_DEF("InvokeResponsesTest", InvokeResponsesTest), - NL_TEST_DEF("InvokeInvokeRequestMessageTest", InvokeInvokeRequestMessageTest), - NL_TEST_DEF("InvokeRequestMessageEndOfMessageReservationTest", InvokeRequestMessageEndOfMessageReservationTest), - NL_TEST_DEF("InvokeRequestsEndOfRequestReservationTest", InvokeRequestsEndOfRequestReservationTest), - NL_TEST_DEF("InvokeInvokeResponseMessageTest", InvokeInvokeResponseMessageTest), - NL_TEST_DEF("InvokeResponseMessageEndOfMessageReservationTest", InvokeResponseMessageEndOfMessageReservationTest), - NL_TEST_DEF("InvokeResponseMessageReservationForEndandMoreChunkTest", InvokeResponseMessageReservationForEndandMoreChunkTest), - NL_TEST_DEF("InvokeResponsesEndOfResponseReservationTest", InvokeResponsesEndOfResponseReservationTest), - NL_TEST_DEF("ReportDataMessageTest", ReportDataMessageTest), - NL_TEST_DEF("ReadRequestMessageTest", ReadRequestMessageTest), - NL_TEST_DEF("WriteRequestMessageTest", WriteRequestMessageTest), - NL_TEST_DEF("WriteResponseMessageTest", WriteResponseMessageTest), - NL_TEST_DEF("SubscribeRequestMessageTest", SubscribeRequestMessageTest), - NL_TEST_DEF("SubscribeResponseMessageTest", SubscribeResponseMessageTest), - NL_TEST_DEF("TimedRequestMessageTest", TimedRequestMessageTest), - NL_TEST_DEF("CheckPointRollbackTest", CheckPointRollbackTest), - NL_TEST_SENTINEL() - }; -// clang-format on } // namespace - -/** - * Set up the test suite. - */ -static int TestSetup(void * inContext) -{ - CHIP_ERROR error = chip::Platform::MemoryInit(); - if (error != CHIP_NO_ERROR) - return FAILURE; - return SUCCESS; -} - -/** - * Tear down the test suite. - */ -static int TestTeardown(void * inContext) -{ - chip::Platform::MemoryShutdown(); - return SUCCESS; -} - -int TestMessageDef() -{ - // clang-format off - nlTestSuite theSuite = - { - "MessageDef", - &sTests[0], - TestSetup, - TestTeardown, - }; - // clang-format on - - nlTestRunner(&theSuite, nullptr); - - return (nlTestRunnerStats(&theSuite)); -} - -CHIP_REGISTER_TEST_SUITE(TestMessageDef) diff --git a/src/app/tests/TestNullable.cpp b/src/app/tests/TestNullable.cpp index 660037339d44e1..9a8104f86ce4d3 100644 --- a/src/app/tests/TestNullable.cpp +++ b/src/app/tests/TestNullable.cpp @@ -21,10 +21,11 @@ #include #include +#include +#include + #include #include -#include -#include using namespace chip; using namespace chip::app::DataModel; @@ -79,7 +80,7 @@ int CtorDtorCounter::destroyed = 0; } // namespace -static void TestBasic(nlTestSuite * inSuite, void * inContext) +TEST(TestNullable, TestBasic) { // Set up our test CtorDtorCounter objects, which will mess with counts, before we reset the // counts. @@ -89,109 +90,109 @@ static void TestBasic(nlTestSuite * inSuite, void * inContext) { auto testNullable = MakeNullable(100); - NL_TEST_ASSERT(inSuite, CtorDtorCounter::created == 1 && CtorDtorCounter::destroyed == 0); - NL_TEST_ASSERT(inSuite, !testNullable.IsNull() && testNullable.Value().m == 100); - NL_TEST_ASSERT(inSuite, testNullable == c100); - NL_TEST_ASSERT(inSuite, testNullable != c101); - NL_TEST_ASSERT(inSuite, testNullable != c102); + EXPECT_TRUE(CtorDtorCounter::created == 1 && CtorDtorCounter::destroyed == 0); + EXPECT_TRUE(!testNullable.IsNull() && testNullable.Value().m == 100); + EXPECT_EQ(testNullable, c100); + EXPECT_NE(testNullable, c101); + EXPECT_NE(testNullable, c102); testNullable.SetNull(); - NL_TEST_ASSERT(inSuite, CtorDtorCounter::created == 1 && CtorDtorCounter::destroyed == 1); - NL_TEST_ASSERT(inSuite, !!testNullable.IsNull()); - NL_TEST_ASSERT(inSuite, testNullable != c100); - NL_TEST_ASSERT(inSuite, testNullable != c101); - NL_TEST_ASSERT(inSuite, testNullable != c102); + EXPECT_TRUE(CtorDtorCounter::created == 1 && CtorDtorCounter::destroyed == 1); + EXPECT_TRUE(testNullable.IsNull()); + EXPECT_NE(testNullable, c100); + EXPECT_NE(testNullable, c101); + EXPECT_NE(testNullable, c102); testNullable.SetNonNull(CtorDtorCounter(101)); - NL_TEST_ASSERT(inSuite, CtorDtorCounter::created == 3 && CtorDtorCounter::destroyed == 2); - NL_TEST_ASSERT(inSuite, !testNullable.IsNull() && testNullable.Value().m == 101); - NL_TEST_ASSERT(inSuite, testNullable != c100); - NL_TEST_ASSERT(inSuite, testNullable == c101); - NL_TEST_ASSERT(inSuite, testNullable != c102); + EXPECT_TRUE(CtorDtorCounter::created == 3 && CtorDtorCounter::destroyed == 2); + EXPECT_TRUE(!testNullable.IsNull() && testNullable.Value().m == 101); + EXPECT_NE(testNullable, c100); + EXPECT_EQ(testNullable, c101); + EXPECT_NE(testNullable, c102); testNullable.SetNonNull(102); - NL_TEST_ASSERT(inSuite, CtorDtorCounter::created == 4 && CtorDtorCounter::destroyed == 3); - NL_TEST_ASSERT(inSuite, !testNullable.IsNull() && testNullable.Value().m == 102); - NL_TEST_ASSERT(inSuite, testNullable != c100); - NL_TEST_ASSERT(inSuite, testNullable != c101); - NL_TEST_ASSERT(inSuite, testNullable == c102); + EXPECT_TRUE(CtorDtorCounter::created == 4 && CtorDtorCounter::destroyed == 3); + EXPECT_TRUE(!testNullable.IsNull() && testNullable.Value().m == 102); + EXPECT_NE(testNullable, c100); + EXPECT_NE(testNullable, c101); + EXPECT_EQ(testNullable, c102); } // Our test CtorDtorCounter objects are still in scope here. - NL_TEST_ASSERT(inSuite, CtorDtorCounter::created == 4 && CtorDtorCounter::destroyed == 4); + EXPECT_TRUE(CtorDtorCounter::created == 4 && CtorDtorCounter::destroyed == 4); } -static void TestMake(nlTestSuite * inSuite, void * inContext) +TEST(TestNullable, TestMake) { CtorDtorCounter::ResetCounter(); { auto testNullable = MakeNullable(200); - NL_TEST_ASSERT(inSuite, CtorDtorCounter::created == 1 && CtorDtorCounter::destroyed == 0); - NL_TEST_ASSERT(inSuite, !testNullable.IsNull() && testNullable.Value().m == 200); + EXPECT_TRUE(CtorDtorCounter::created == 1 && CtorDtorCounter::destroyed == 0); + EXPECT_TRUE(!testNullable.IsNull() && testNullable.Value().m == 200); } - NL_TEST_ASSERT(inSuite, CtorDtorCounter::created == 1 && CtorDtorCounter::destroyed == 1); + EXPECT_TRUE(CtorDtorCounter::created == 1 && CtorDtorCounter::destroyed == 1); } -static void TestCopy(nlTestSuite * inSuite, void * inContext) +TEST(TestNullable, TestCopy) { CtorDtorCounter::ResetCounter(); { auto testSrc = MakeNullable(300); - NL_TEST_ASSERT(inSuite, CtorDtorCounter::created == 1 && CtorDtorCounter::destroyed == 0); - NL_TEST_ASSERT(inSuite, !testSrc.IsNull() && testSrc.Value().m == 300); + EXPECT_TRUE(CtorDtorCounter::created == 1 && CtorDtorCounter::destroyed == 0); + EXPECT_TRUE(!testSrc.IsNull() && testSrc.Value().m == 300); { Nullable testDst(testSrc); - NL_TEST_ASSERT(inSuite, CtorDtorCounter::created == 2 && CtorDtorCounter::destroyed == 0); - NL_TEST_ASSERT(inSuite, !testDst.IsNull() && testDst.Value().m == 300); + EXPECT_TRUE(CtorDtorCounter::created == 2 && CtorDtorCounter::destroyed == 0); + EXPECT_TRUE(!testDst.IsNull() && testDst.Value().m == 300); } - NL_TEST_ASSERT(inSuite, CtorDtorCounter::created == 2 && CtorDtorCounter::destroyed == 1); + EXPECT_TRUE(CtorDtorCounter::created == 2 && CtorDtorCounter::destroyed == 1); { Nullable testDst; - NL_TEST_ASSERT(inSuite, CtorDtorCounter::created == 2 && CtorDtorCounter::destroyed == 1); - NL_TEST_ASSERT(inSuite, !!testDst.IsNull()); + EXPECT_TRUE(CtorDtorCounter::created == 2 && CtorDtorCounter::destroyed == 1); + EXPECT_TRUE(testDst.IsNull()); testDst = testSrc; - NL_TEST_ASSERT(inSuite, CtorDtorCounter::created == 3 && CtorDtorCounter::destroyed == 1); - NL_TEST_ASSERT(inSuite, !testDst.IsNull() && testDst.Value().m == 300); + EXPECT_TRUE(CtorDtorCounter::created == 3 && CtorDtorCounter::destroyed == 1); + EXPECT_TRUE(!testDst.IsNull() && testDst.Value().m == 300); } - NL_TEST_ASSERT(inSuite, CtorDtorCounter::created == 3 && CtorDtorCounter::destroyed == 2); + EXPECT_TRUE(CtorDtorCounter::created == 3 && CtorDtorCounter::destroyed == 2); } - NL_TEST_ASSERT(inSuite, CtorDtorCounter::created == 3 && CtorDtorCounter::destroyed == 3); + EXPECT_TRUE(CtorDtorCounter::created == 3 && CtorDtorCounter::destroyed == 3); } -static void TestMove(nlTestSuite * inSuite, void * inContext) +TEST(TestNullable, TestMove) { CtorDtorCounter::ResetCounter(); { auto testSrc = MakeNullable(400); // construct Nullable testDst(std::move(testSrc)); // move construct - NL_TEST_ASSERT(inSuite, CtorDtorCounter::created == 2 && CtorDtorCounter::destroyed == 0); - NL_TEST_ASSERT(inSuite, !testDst.IsNull() && testDst.Value().m == 400); + EXPECT_TRUE(CtorDtorCounter::created == 2 && CtorDtorCounter::destroyed == 0); + EXPECT_TRUE(!testDst.IsNull() && testDst.Value().m == 400); // destroy both testsSrc and testDst } - NL_TEST_ASSERT(inSuite, CtorDtorCounter::created == 2 && CtorDtorCounter::destroyed == 2); + EXPECT_TRUE(CtorDtorCounter::created == 2 && CtorDtorCounter::destroyed == 2); CtorDtorCounter::ResetCounter(); { Nullable testDst; // no object construction - NL_TEST_ASSERT(inSuite, CtorDtorCounter::created == 0 && CtorDtorCounter::destroyed == 0); - NL_TEST_ASSERT(inSuite, !!testDst.IsNull()); + EXPECT_TRUE(CtorDtorCounter::created == 0 && CtorDtorCounter::destroyed == 0); + EXPECT_TRUE(testDst.IsNull()); auto testSrc = MakeNullable(401); // construct object testDst = std::move(testSrc); // construct a copy - NL_TEST_ASSERT(inSuite, CtorDtorCounter::created == 2 && CtorDtorCounter::destroyed == 0); - NL_TEST_ASSERT(inSuite, !testDst.IsNull() && testDst.Value().m == 401); + EXPECT_TRUE(CtorDtorCounter::created == 2 && CtorDtorCounter::destroyed == 0); + EXPECT_TRUE(!testDst.IsNull() && testDst.Value().m == 401); } - NL_TEST_ASSERT(inSuite, CtorDtorCounter::created == 2 && CtorDtorCounter::destroyed == 2); + EXPECT_TRUE(CtorDtorCounter::created == 2 && CtorDtorCounter::destroyed == 2); } -static void TestUpdate(nlTestSuite * inSuite, void * inContext) +TEST(TestNullable, TestUpdate) { using SmallArray = std::array; // Arrays @@ -199,19 +200,19 @@ static void TestUpdate(nlTestSuite * inSuite, void * inContext) auto nullable1 = MakeNullable({ 1, 2, 3 }); auto nullable2 = MakeNullable({ 1, 2, 3 }); - NL_TEST_ASSERT(inSuite, !nullable1.IsNull()); - NL_TEST_ASSERT(inSuite, !nullable2.IsNull()); - NL_TEST_ASSERT(inSuite, nullable1 == nullable2); + EXPECT_FALSE(nullable1.IsNull()); + EXPECT_FALSE(nullable2.IsNull()); + EXPECT_EQ(nullable1, nullable2); // No-op on change to same. - NL_TEST_ASSERT(inSuite, nullable1.Update(nullable2) == false); - NL_TEST_ASSERT(inSuite, nullable1 == nullable2); + EXPECT_FALSE(nullable1.Update(nullable2)); + EXPECT_EQ(nullable1, nullable2); nullable1.Value()[0] = 100; - NL_TEST_ASSERT(inSuite, nullable1 != nullable2); - NL_TEST_ASSERT(inSuite, nullable2.Update(nullable1) == true); - NL_TEST_ASSERT(inSuite, nullable1 == nullable2); + EXPECT_NE(nullable1, nullable2); + EXPECT_TRUE(nullable2.Update(nullable1)); + EXPECT_EQ(nullable1, nullable2); } // Structs @@ -227,83 +228,52 @@ static void TestUpdate(nlTestSuite * inSuite, void * inContext) auto nullable1 = MakeNullable({ 1, 2 }); auto nullable2 = MakeNullable({ 1, 2 }); - NL_TEST_ASSERT(inSuite, !nullable1.IsNull()); - NL_TEST_ASSERT(inSuite, !nullable2.IsNull()); - NL_TEST_ASSERT(inSuite, nullable1 == nullable2); + EXPECT_FALSE(nullable1.IsNull()); + EXPECT_FALSE(nullable2.IsNull()); + EXPECT_EQ(nullable1, nullable2); // No-op on change to same. - NL_TEST_ASSERT(inSuite, nullable1.Update(nullable2) == false); - NL_TEST_ASSERT(inSuite, nullable1 == nullable2); + EXPECT_FALSE(nullable1.Update(nullable2)); + EXPECT_EQ(nullable1, nullable2); nullable1.Value().a = 100; - NL_TEST_ASSERT(inSuite, nullable1 != nullable2); - NL_TEST_ASSERT(inSuite, nullable2.Update(nullable1) == true); - NL_TEST_ASSERT(inSuite, nullable1 == nullable2); + EXPECT_NE(nullable1, nullable2); + EXPECT_TRUE(nullable2.Update(nullable1)); + EXPECT_EQ(nullable1, nullable2); } // Scalar cases { auto nullable1 = MakeNullable(static_cast(1)); - NL_TEST_ASSERT(inSuite, !nullable1.IsNull()); + EXPECT_FALSE(nullable1.IsNull()); // Non-null to non-null same value - NL_TEST_ASSERT(inSuite, nullable1.Update(nullable1) == false); - NL_TEST_ASSERT(inSuite, !nullable1.IsNull()); + EXPECT_FALSE(nullable1.Update(nullable1)); + EXPECT_FALSE(nullable1.IsNull()); // Non-null to null - NL_TEST_ASSERT(inSuite, nullable1.Update(NullNullable) == true); - NL_TEST_ASSERT(inSuite, nullable1.IsNull()); + EXPECT_TRUE(nullable1.Update(NullNullable)); + EXPECT_TRUE(nullable1.IsNull()); // Null to null - NL_TEST_ASSERT(inSuite, nullable1.Update(NullNullable) == false); - NL_TEST_ASSERT(inSuite, nullable1.IsNull()); + EXPECT_FALSE(nullable1.Update(NullNullable)); + EXPECT_TRUE(nullable1.IsNull()); // Null to non-null - NL_TEST_ASSERT(inSuite, nullable1.Update(MakeNullable(static_cast(1))) == true); - NL_TEST_ASSERT(inSuite, !nullable1.IsNull()); - NL_TEST_ASSERT(inSuite, nullable1.Value() == 1); + EXPECT_TRUE(nullable1.Update(MakeNullable(static_cast(1)))); + EXPECT_FALSE(nullable1.IsNull()); + EXPECT_EQ(nullable1.Value(), 1); // Non-null to non-null different value - NL_TEST_ASSERT(inSuite, nullable1.Update(MakeNullable(static_cast(2))) == true); - NL_TEST_ASSERT(inSuite, !nullable1.IsNull()); - NL_TEST_ASSERT(inSuite, nullable1.Value() == 2); + EXPECT_TRUE(nullable1.Update(MakeNullable(static_cast(2)))); + EXPECT_FALSE(nullable1.IsNull()); + EXPECT_EQ(nullable1.Value(), 2); // Non-null to extent of range --> changes to "invalid" value in range. - NL_TEST_ASSERT(inSuite, nullable1.Update(MakeNullable(static_cast(255))) == true); - NL_TEST_ASSERT(inSuite, !nullable1.IsNull()); - NL_TEST_ASSERT(inSuite, nullable1.Value() == 255); + EXPECT_TRUE(nullable1.Update(MakeNullable(static_cast(255)))); + EXPECT_FALSE(nullable1.IsNull()); + EXPECT_EQ(nullable1.Value(), 255); } } - -// clang-format off -static const nlTest sTests[] = -{ - NL_TEST_DEF("NullableBasic", TestBasic), - NL_TEST_DEF("NullableMake", TestMake), - NL_TEST_DEF("NullableCopy", TestCopy), - NL_TEST_DEF("NullableMove", TestMove), - NL_TEST_DEF("Nullable Update operation", TestUpdate), - NL_TEST_SENTINEL() -}; -// clang-format on - -int TestNullable() -{ - // clang-format off - nlTestSuite theSuite = - { - "Test for Nullable abstraction", - &sTests[0], - nullptr, - nullptr - }; - // clang-format on - - nlTestRunner(&theSuite, nullptr); - - return (nlTestRunnerStats(&theSuite)); -} - -CHIP_REGISTER_TEST_SUITE(TestNullable) diff --git a/src/app/tests/TestNumericAttributeTraits.cpp b/src/app/tests/TestNumericAttributeTraits.cpp index a88f3925c2a1d0..6d6c35735066a4 100644 --- a/src/app/tests/TestNumericAttributeTraits.cpp +++ b/src/app/tests/TestNumericAttributeTraits.cpp @@ -27,8 +27,8 @@ * */ -#include -#include +#include +#include // We are testing the odd-sized-integers.h module #include @@ -38,7 +38,7 @@ using namespace chip::app; namespace { -void Test_UINT8(nlTestSuite * apSuite, void * apContext) +TEST(TestNumericAttributeTraits, Test_UINT8) { // Unsigned 8-bit Integer : 1 byte, endianness does not matter. using IntType = NumericAttributeTraits; @@ -53,8 +53,8 @@ void Test_UINT8(nlTestSuite * apSuite, void * apContext) const WorkingType workingTestUnsignedNullValue = 0xFF; // 1) Verify the size of the types - NL_TEST_ASSERT(apSuite, sizeof(sValue) == 1); - NL_TEST_ASSERT(apSuite, sizeof(wValue) >= 1); + EXPECT_EQ(sizeof(sValue), 1u); + EXPECT_GE(sizeof(wValue), 1u); // Initialize the Storage Value with the test-buffer memcpy(&sValue, &storageTestData, sizeof(sValue)); @@ -63,7 +63,7 @@ void Test_UINT8(nlTestSuite * apSuite, void * apContext) wValue = IntType::StorageToWorking(sValue); // 2) Verify that the correct storage format has been used - NL_TEST_ASSERT(apSuite, wValue == 17); + EXPECT_EQ(wValue, 17u); StorageType sNewValue; @@ -71,22 +71,22 @@ void Test_UINT8(nlTestSuite * apSuite, void * apContext) IntType::WorkingToStorage(wValue, sNewValue); // 3) Verify that the bytes are located as intended - NL_TEST_ASSERT(apSuite, memcmp(&storageTestData, &sNewValue, sizeof(sNewValue)) == 0); + EXPECT_EQ(memcmp(&storageTestData, &sNewValue, sizeof(sNewValue)), 0); // Set Storage value to Null IntType::SetNull(sNullValue); wNullValue = IntType::StorageToWorking(sNullValue); - NL_TEST_ASSERT(apSuite, wNullValue == workingTestUnsignedNullValue); - NL_TEST_ASSERT(apSuite, (IntType::IsNullValue(sNullValue) == true)); + EXPECT_EQ(wNullValue, workingTestUnsignedNullValue); + EXPECT_TRUE(IntType::IsNullValue(sNullValue)); // Verify that null values can fit into not nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, sNullValue) == true)); + EXPECT_TRUE(IntType::CanRepresentValue(false, sNullValue)); // Verify that null values can't fit into nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, sNullValue) == false)); + EXPECT_FALSE(IntType::CanRepresentValue(true, sNullValue)); } -void Test_SINT8(nlTestSuite * apSuite, void * apContext) +TEST(TestNumericAttributeTraits, Test_SINT8) { // Signed 8-bit Integer : 1 byte, endianness does not matter. using IntType = NumericAttributeTraits; @@ -101,8 +101,8 @@ void Test_SINT8(nlTestSuite * apSuite, void * apContext) const WorkingType workingTestUnsignedNullValue = -128; // 0x80 // 1) Verify the size of the types - NL_TEST_ASSERT(apSuite, sizeof(sValue) == 1); - NL_TEST_ASSERT(apSuite, sizeof(wValue) >= 1); + EXPECT_EQ(sizeof(sValue), 1u); + EXPECT_GE(sizeof(wValue), 1u); // Initialize the Storage Value with the test-buffer memcpy(&sValue, &storageTestData, sizeof(sValue)); @@ -111,7 +111,7 @@ void Test_SINT8(nlTestSuite * apSuite, void * apContext) wValue = IntType::StorageToWorking(sValue); // 2) Verify that the correct storage format has been used - NL_TEST_ASSERT(apSuite, wValue == 17); + EXPECT_EQ(wValue, 17); StorageType sNewValue; @@ -119,19 +119,19 @@ void Test_SINT8(nlTestSuite * apSuite, void * apContext) IntType::WorkingToStorage(wValue, sNewValue); // 3) Verify that the bytes are located as intended - NL_TEST_ASSERT(apSuite, memcmp(&storageTestData, &sNewValue, sizeof(sNewValue)) == 0); + EXPECT_EQ(memcmp(&storageTestData, &sNewValue, sizeof(sNewValue)), 0); // Set Storage value to Null IntType::SetNull(sNullValue); wNullValue = IntType::StorageToWorking(sNullValue); - NL_TEST_ASSERT(apSuite, wNullValue == workingTestUnsignedNullValue); - NL_TEST_ASSERT(apSuite, (IntType::IsNullValue(sNullValue) == true)); + EXPECT_EQ(wNullValue, workingTestUnsignedNullValue); + EXPECT_TRUE(IntType::IsNullValue(sNullValue)); // Verify that null values can fit into not nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, sNullValue) == true)); + EXPECT_TRUE(IntType::CanRepresentValue(false, sNullValue)); // Verify that null values can't fit into nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, sNullValue) == false)); + EXPECT_FALSE(IntType::CanRepresentValue(true, sNullValue)); } enum class SimpleEnum : uint8_t @@ -140,7 +140,7 @@ enum class SimpleEnum : uint8_t kOne = 1, }; -void Test_SimpleEnum(nlTestSuite * apSuite, void * apContext) +TEST(TestNumericAttributeTraits, Test_SimpleEnum) { // Unsigned 8-bit Integer : 1 byte, endianness does not matter. using IntType = NumericAttributeTraits; @@ -155,8 +155,8 @@ void Test_SimpleEnum(nlTestSuite * apSuite, void * apContext) const WorkingType workingTestUnsignedNullValue = static_cast(0xFF); // 1) Verify the size of the types - NL_TEST_ASSERT(apSuite, sizeof(sValue) == 1); - NL_TEST_ASSERT(apSuite, sizeof(wValue) >= 1); + EXPECT_EQ(sizeof(sValue), 1u); + EXPECT_GE(sizeof(wValue), 1u); // Initialize the Storage Value with the test-buffer memcpy(&sValue, &storageTestData, sizeof(sValue)); @@ -165,7 +165,7 @@ void Test_SimpleEnum(nlTestSuite * apSuite, void * apContext) wValue = IntType::StorageToWorking(sValue); // 2) Verify that the correct storage format has been used - NL_TEST_ASSERT(apSuite, wValue == SimpleEnum::kOne); + EXPECT_EQ(wValue, SimpleEnum::kOne); StorageType sNewValue; @@ -173,19 +173,19 @@ void Test_SimpleEnum(nlTestSuite * apSuite, void * apContext) IntType::WorkingToStorage(wValue, sNewValue); // 3) Verify that the bytes are located as intended - NL_TEST_ASSERT(apSuite, memcmp(&storageTestData, &sNewValue, sizeof(sNewValue)) == 0); + EXPECT_EQ(memcmp(&storageTestData, &sNewValue, sizeof(sNewValue)), 0); // Set Storage value to Null IntType::SetNull(sNullValue); wNullValue = IntType::StorageToWorking(sNullValue); - NL_TEST_ASSERT(apSuite, wNullValue == workingTestUnsignedNullValue); - NL_TEST_ASSERT(apSuite, (IntType::IsNullValue(sNullValue) == true)); + EXPECT_EQ(wNullValue, workingTestUnsignedNullValue); + EXPECT_TRUE(IntType::IsNullValue(sNullValue)); // Verify that null values can fit into not nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, sNullValue) == true)); + EXPECT_TRUE(IntType::CanRepresentValue(false, sNullValue)); // Verify that null values can't fit into nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, sNullValue) == false)); + EXPECT_FALSE(IntType::CanRepresentValue(true, sNullValue)); } //////////////////////////////////////////////////////////// @@ -200,7 +200,7 @@ void Test_SimpleEnum(nlTestSuite * apSuite, void * apContext) // $$$$$$$$/ $$/ $$$$$$$/ $$$$$$/ $$/ // // // //////////////////////////////////////////////////////////// -void Test_UINT24_LE(nlTestSuite * apSuite, void * apContext) +TEST(TestNumericAttributeTraits, Test_UINT24_LE) { // Unsigned 24-bit Integer : 3 bytes - little-endian using IntType = NumericAttributeTraits, false>; @@ -215,8 +215,8 @@ void Test_UINT24_LE(nlTestSuite * apSuite, void * apContext) const WorkingType workingTestUnsignedNullValue = 16777215; // 0xFFFFFF // 1) Verify the size of the types - NL_TEST_ASSERT(apSuite, sizeof(sValue) == 3); - NL_TEST_ASSERT(apSuite, sizeof(wValue) >= 3); + EXPECT_EQ(sizeof(sValue), 3u); + EXPECT_GE(sizeof(wValue), 3u); // Initialize the Storage Value with the test-buffer memcpy(&sValue, storageTestData, sizeof(sValue)); @@ -225,7 +225,7 @@ void Test_UINT24_LE(nlTestSuite * apSuite, void * apContext) wValue = IntType::StorageToWorking(sValue); // 2) Verify that the correct storage format has been used - NL_TEST_ASSERT(apSuite, wValue == 0x123456); + EXPECT_EQ(wValue, 0x123456u); StorageType sNewValue; @@ -233,22 +233,22 @@ void Test_UINT24_LE(nlTestSuite * apSuite, void * apContext) IntType::WorkingToStorage(wValue, sNewValue); // 3) Verify that the bytes are located as intended - NL_TEST_ASSERT(apSuite, memcmp(storageTestData, &sNewValue, sizeof(sNewValue)) == 0); + EXPECT_EQ(memcmp(storageTestData, &sNewValue, sizeof(sNewValue)), 0); // Set Storage value to Null IntType::SetNull(sNullValue); wNullValue = IntType::StorageToWorking(sNullValue); - NL_TEST_ASSERT(apSuite, wNullValue == workingTestUnsignedNullValue); - NL_TEST_ASSERT(apSuite, (IntType::IsNullValue(sNullValue) == true)); + EXPECT_EQ(wNullValue, workingTestUnsignedNullValue); + EXPECT_TRUE(IntType::IsNullValue(sNullValue)); // Verify that null values can fit into not nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, sNullValue) == true)); + EXPECT_TRUE(IntType::CanRepresentValue(false, sNullValue)); // Verify that null values can't fit into nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, sNullValue) == false)); + EXPECT_FALSE(IntType::CanRepresentValue(true, sNullValue)); } -void Test_UINT24_BE(nlTestSuite * apSuite, void * apContext) +TEST(TestNumericAttributeTraits, Test_UINT24_BE) { // Unsigned 24-bit Integer : 3 bytes - big-endian using IntType = NumericAttributeTraits, true>; @@ -263,8 +263,8 @@ void Test_UINT24_BE(nlTestSuite * apSuite, void * apContext) const WorkingType workingTestUnsignedNullValue = 16777215; // 0xFFFFFF // 1) Verify the size of the types - NL_TEST_ASSERT(apSuite, sizeof(sValue) == 3); - NL_TEST_ASSERT(apSuite, sizeof(wValue) >= 3); + EXPECT_EQ(sizeof(sValue), 3u); + EXPECT_GE(sizeof(wValue), 3u); // Initialize the Storage Value with the test-buffer memcpy(&sValue, storageTestData, sizeof(sValue)); @@ -273,7 +273,7 @@ void Test_UINT24_BE(nlTestSuite * apSuite, void * apContext) wValue = IntType::StorageToWorking(sValue); // 2) Verify that the correct storage format has been used - NL_TEST_ASSERT(apSuite, wValue == 0x123456); + EXPECT_EQ(wValue, 0x123456u); StorageType sNewValue; @@ -281,22 +281,22 @@ void Test_UINT24_BE(nlTestSuite * apSuite, void * apContext) IntType::WorkingToStorage(wValue, sNewValue); // 3) Verify that the bytes are located as intended - NL_TEST_ASSERT(apSuite, memcmp(storageTestData, &sNewValue, sizeof(sNewValue)) == 0); + EXPECT_EQ(memcmp(storageTestData, &sNewValue, sizeof(sNewValue)), 0); // Set Storage value to Null IntType::SetNull(sNullValue); wNullValue = IntType::StorageToWorking(sNullValue); - NL_TEST_ASSERT(apSuite, wNullValue == workingTestUnsignedNullValue); - NL_TEST_ASSERT(apSuite, (IntType::IsNullValue(sNullValue) == true)); + EXPECT_EQ(wNullValue, workingTestUnsignedNullValue); + EXPECT_TRUE(IntType::IsNullValue(sNullValue)); // Verify that null values can fit into not nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, sNullValue) == true)); + EXPECT_TRUE(IntType::CanRepresentValue(false, sNullValue)); // Verify that null values can't fit into nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, sNullValue) == false)); + EXPECT_FALSE(IntType::CanRepresentValue(true, sNullValue)); } -void Test_SINT24_LE(nlTestSuite * apSuite, void * apContext) +TEST(TestNumericAttributeTraits, Test_SINT24_LE) { // Signed 24-bit Integer : 3 bytes - little-endian using IntType = NumericAttributeTraits, false>; @@ -315,10 +315,10 @@ void Test_SINT24_LE(nlTestSuite * apSuite, void * apContext) const WorkingType workingTestSignedNullValue = -8388608; // -0x800000 // 1) Verify the size of the types - NL_TEST_ASSERT(apSuite, sizeof(sValuePos) == 3); - NL_TEST_ASSERT(apSuite, sizeof(wValuePos) >= 3); - NL_TEST_ASSERT(apSuite, sizeof(sValueNeg) == 3); - NL_TEST_ASSERT(apSuite, sizeof(wValueNeg) >= 3); + EXPECT_EQ(sizeof(sValuePos), 3u); + EXPECT_GE(sizeof(wValuePos), 3u); + EXPECT_EQ(sizeof(sValueNeg), 3u); + EXPECT_GE(sizeof(wValueNeg), 3u); // Initialize the Storage Values with the test-buffer memcpy(&sValuePos, storageTestDataPos, sizeof(sValuePos)); @@ -329,8 +329,8 @@ void Test_SINT24_LE(nlTestSuite * apSuite, void * apContext) wValueNeg = IntType::StorageToWorking(sValueNeg); // 2) Verify that the correct storage format has been used - NL_TEST_ASSERT(apSuite, wValuePos == workingDataPos); - NL_TEST_ASSERT(apSuite, wValueNeg == workingDataNeg); + EXPECT_EQ(wValuePos, workingDataPos); + EXPECT_EQ(wValueNeg, workingDataNeg); StorageType sNewValuePos; StorageType sNewValueNeg; @@ -340,8 +340,8 @@ void Test_SINT24_LE(nlTestSuite * apSuite, void * apContext) IntType::WorkingToStorage(wValueNeg, sNewValueNeg); // 3) Verify that the bytes are located as intended - NL_TEST_ASSERT(apSuite, memcmp(storageTestDataPos, &sNewValuePos, sizeof(sNewValuePos)) == 0); - NL_TEST_ASSERT(apSuite, memcmp(storageTestDataNeg, &sNewValueNeg, sizeof(sNewValueNeg)) == 0); + EXPECT_EQ(memcmp(storageTestDataPos, &sNewValuePos, sizeof(sNewValuePos)), 0); + EXPECT_EQ(memcmp(storageTestDataNeg, &sNewValueNeg, sizeof(sNewValueNeg)), 0); StorageType sNullValue; WorkingType wNullValue; @@ -349,19 +349,19 @@ void Test_SINT24_LE(nlTestSuite * apSuite, void * apContext) // Set Storage value to Null IntType::SetNull(sNullValue); wNullValue = IntType::StorageToWorking(sNullValue); - NL_TEST_ASSERT(apSuite, wNullValue == workingTestSignedNullValue); - NL_TEST_ASSERT(apSuite, (IntType::IsNullValue(sNullValue) == true)); + EXPECT_EQ(wNullValue, workingTestSignedNullValue); + EXPECT_TRUE(IntType::IsNullValue(sNullValue)); // Verify that null values can fit into not nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, sNullValue) == true)); - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, wNullValue) == true)); + EXPECT_TRUE(IntType::CanRepresentValue(false, sNullValue)); + EXPECT_TRUE(IntType::CanRepresentValue(false, wNullValue)); // Verify that null values can't fit into nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, sNullValue) == false)); - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, wNullValue) == false)); + EXPECT_FALSE(IntType::CanRepresentValue(true, sNullValue)); + EXPECT_FALSE(IntType::CanRepresentValue(true, wNullValue)); } -void Test_SINT24_BE(nlTestSuite * apSuite, void * apContext) +TEST(TestNumericAttributeTraits, Test_SINT24_BE) { // Signed 24-bit Integer : 3 bytes - big-endian using IntType = NumericAttributeTraits, true>; @@ -380,10 +380,10 @@ void Test_SINT24_BE(nlTestSuite * apSuite, void * apContext) const WorkingType workingTestSignedNullValue = -8388608; // -0x800000 // 1) Verify the size of the types - NL_TEST_ASSERT(apSuite, sizeof(sValuePos) == 3); - NL_TEST_ASSERT(apSuite, sizeof(wValuePos) >= 3); - NL_TEST_ASSERT(apSuite, sizeof(sValueNeg) == 3); - NL_TEST_ASSERT(apSuite, sizeof(wValueNeg) >= 3); + EXPECT_EQ(sizeof(sValuePos), 3u); + EXPECT_GE(sizeof(wValuePos), 3u); + EXPECT_EQ(sizeof(sValueNeg), 3u); + EXPECT_GE(sizeof(wValueNeg), 3u); // Initialize the Storage Values with the test-buffer memcpy(&sValuePos, storageTestDataPos, sizeof(sValuePos)); @@ -394,8 +394,8 @@ void Test_SINT24_BE(nlTestSuite * apSuite, void * apContext) wValueNeg = IntType::StorageToWorking(sValueNeg); // 2) Verify that the correct storage format has been used - NL_TEST_ASSERT(apSuite, wValuePos == workingDataPos); - NL_TEST_ASSERT(apSuite, wValueNeg == workingDataNeg); + EXPECT_EQ(wValuePos, workingDataPos); + EXPECT_EQ(wValueNeg, workingDataNeg); StorageType sNewValuePos; StorageType sNewValueNeg; @@ -405,8 +405,8 @@ void Test_SINT24_BE(nlTestSuite * apSuite, void * apContext) IntType::WorkingToStorage(wValueNeg, sNewValueNeg); // 3) Verify that the bytes are located as intended - NL_TEST_ASSERT(apSuite, memcmp(storageTestDataPos, &sNewValuePos, sizeof(sNewValuePos)) == 0); - NL_TEST_ASSERT(apSuite, memcmp(storageTestDataNeg, &sNewValueNeg, sizeof(sNewValueNeg)) == 0); + EXPECT_EQ(memcmp(storageTestDataPos, &sNewValuePos, sizeof(sNewValuePos)), 0); + EXPECT_EQ(memcmp(storageTestDataNeg, &sNewValueNeg, sizeof(sNewValueNeg)), 0); StorageType sNullValue; WorkingType wNullValue; @@ -414,16 +414,16 @@ void Test_SINT24_BE(nlTestSuite * apSuite, void * apContext) // Set Storage value to Null IntType::SetNull(sNullValue); wNullValue = IntType::StorageToWorking(sNullValue); - NL_TEST_ASSERT(apSuite, wNullValue == workingTestSignedNullValue); - NL_TEST_ASSERT(apSuite, (IntType::IsNullValue(sNullValue) == true)); + EXPECT_EQ(wNullValue, workingTestSignedNullValue); + EXPECT_TRUE(IntType::IsNullValue(sNullValue)); // Verify that null values can fit into not nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, sNullValue) == true)); - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, wNullValue) == true)); + EXPECT_TRUE(IntType::CanRepresentValue(false, sNullValue)); + EXPECT_TRUE(IntType::CanRepresentValue(false, wNullValue)); // Verify that null values can't fit into nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, sNullValue) == false)); - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, wNullValue) == false)); + EXPECT_FALSE(IntType::CanRepresentValue(true, sNullValue)); + EXPECT_FALSE(IntType::CanRepresentValue(true, wNullValue)); } //////////////////////////////////////////////////////////// @@ -438,7 +438,7 @@ void Test_SINT24_BE(nlTestSuite * apSuite, void * apContext) // $$/ $$$$$$/ $$$$$$$/ $$$$$$/ $$/ // // // //////////////////////////////////////////////////////////// -void Test_UINT40_LE(nlTestSuite * apSuite, void * apContext) +TEST(TestNumericAttributeTraits, Test_UINT40_LE) { // Unsigned 40-bit Integer : 5 bytes - little-endian using IntType = NumericAttributeTraits, false>; @@ -453,8 +453,8 @@ void Test_UINT40_LE(nlTestSuite * apSuite, void * apContext) const WorkingType workingTestUnsignedNullValue = 1099511627775; // 0xFFFFFFFFFF // 1) Verify the size of the types - NL_TEST_ASSERT(apSuite, sizeof(sValue) == 5); - NL_TEST_ASSERT(apSuite, sizeof(wValue) >= 5); + EXPECT_EQ(sizeof(sValue), 5u); + EXPECT_GE(sizeof(wValue), 5u); // Initialize the Storage Value with the test-buffer memcpy(&sValue, storageTestData, sizeof(sValue)); @@ -463,7 +463,7 @@ void Test_UINT40_LE(nlTestSuite * apSuite, void * apContext) wValue = IntType::StorageToWorking(sValue); // 2) Verify that the correct storage format has been used - NL_TEST_ASSERT(apSuite, wValue == 0x123456789A); + EXPECT_EQ(wValue, 0x123456789Au); StorageType sNewValue; @@ -471,22 +471,22 @@ void Test_UINT40_LE(nlTestSuite * apSuite, void * apContext) IntType::WorkingToStorage(wValue, sNewValue); // 3) Verify that the bytes are located as intended - NL_TEST_ASSERT(apSuite, memcmp(storageTestData, &sNewValue, sizeof(sNewValue)) == 0); + EXPECT_EQ(memcmp(storageTestData, &sNewValue, sizeof(sNewValue)), 0); // Set Storage value to Null IntType::SetNull(sNullValue); wNullValue = IntType::StorageToWorking(sNullValue); - NL_TEST_ASSERT(apSuite, wNullValue == workingTestUnsignedNullValue); - NL_TEST_ASSERT(apSuite, (IntType::IsNullValue(sNullValue) == true)); + EXPECT_EQ(wNullValue, workingTestUnsignedNullValue); + EXPECT_TRUE(IntType::IsNullValue(sNullValue)); // Verify that null values can fit into not nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, sNullValue) == true)); + EXPECT_TRUE(IntType::CanRepresentValue(false, sNullValue)); // Verify that null values can't fit into nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, sNullValue) == false)); + EXPECT_FALSE(IntType::CanRepresentValue(true, sNullValue)); } -void Test_UINT40_BE(nlTestSuite * apSuite, void * apContext) +TEST(TestNumericAttributeTraits, Test_UINT40_BE) { // Unsigned 40-bit Integer : 5 bytes - big-endian using IntType = NumericAttributeTraits, true>; @@ -500,8 +500,8 @@ void Test_UINT40_BE(nlTestSuite * apSuite, void * apContext) const StorageType storageTestData = { 0x12, 0x34, 0x56, 0x78, 0x9A }; const WorkingType workingTestUnsignedNullValue = 1099511627775; // 0xFFFFFFFFFF // 1) Verify the size of the types - NL_TEST_ASSERT(apSuite, sizeof(sValue) == 5); - NL_TEST_ASSERT(apSuite, sizeof(wValue) >= 5); + EXPECT_EQ(sizeof(sValue), 5u); + EXPECT_GE(sizeof(wValue), 5u); // Initialize the Storage Value with the test-buffer memcpy(&sValue, storageTestData, sizeof(sValue)); @@ -510,7 +510,7 @@ void Test_UINT40_BE(nlTestSuite * apSuite, void * apContext) wValue = IntType::StorageToWorking(sValue); // 2) Verify that the correct storage format has been used - NL_TEST_ASSERT(apSuite, wValue == 0x123456789A); + EXPECT_EQ(wValue, 0x123456789Au); StorageType sNewValue; @@ -518,22 +518,22 @@ void Test_UINT40_BE(nlTestSuite * apSuite, void * apContext) IntType::WorkingToStorage(wValue, sNewValue); // 3) Verify that the bytes are located as intended - NL_TEST_ASSERT(apSuite, memcmp(storageTestData, &sNewValue, sizeof(sNewValue)) == 0); + EXPECT_EQ(memcmp(storageTestData, &sNewValue, sizeof(sNewValue)), 0); // Set Storage value to Null IntType::SetNull(sNullValue); wNullValue = IntType::StorageToWorking(sNullValue); - NL_TEST_ASSERT(apSuite, wNullValue == workingTestUnsignedNullValue); - NL_TEST_ASSERT(apSuite, (IntType::IsNullValue(sNullValue) == true)); + EXPECT_EQ(wNullValue, workingTestUnsignedNullValue); + EXPECT_TRUE(IntType::IsNullValue(sNullValue)); // Verify that null values can fit into not nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, sNullValue) == true)); + EXPECT_TRUE(IntType::CanRepresentValue(false, sNullValue)); // Verify that null values can't fit into nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, sNullValue) == false)); + EXPECT_FALSE(IntType::CanRepresentValue(true, sNullValue)); } -void Test_SINT40_LE(nlTestSuite * apSuite, void * apContext) +TEST(TestNumericAttributeTraits, Test_SINT40_LE) { // Signed 40-bit Integer : 5 bytes - little-endian using IntType = NumericAttributeTraits, false>; @@ -552,10 +552,10 @@ void Test_SINT40_LE(nlTestSuite * apSuite, void * apContext) const WorkingType workingTestSignedNullValue = -549755813888; // -0x8000000000 // 1) Verify the size of the types - NL_TEST_ASSERT(apSuite, sizeof(sValuePos) == 5); - NL_TEST_ASSERT(apSuite, sizeof(wValuePos) >= 5); - NL_TEST_ASSERT(apSuite, sizeof(sValueNeg) == 5); - NL_TEST_ASSERT(apSuite, sizeof(wValueNeg) >= 5); + EXPECT_EQ(sizeof(sValuePos), 5u); + EXPECT_GE(sizeof(wValuePos), 5u); + EXPECT_EQ(sizeof(sValueNeg), 5u); + EXPECT_GE(sizeof(wValueNeg), 5u); // Initialize the Storage Values with the test-buffer memcpy(&sValuePos, storageTestDataPos, sizeof(sValuePos)); @@ -566,8 +566,8 @@ void Test_SINT40_LE(nlTestSuite * apSuite, void * apContext) wValueNeg = IntType::StorageToWorking(sValueNeg); // 2) Verify that the correct storage format has been used - NL_TEST_ASSERT(apSuite, wValuePos == workingDataPos); - NL_TEST_ASSERT(apSuite, wValueNeg == workingDataNeg); + EXPECT_EQ(wValuePos, workingDataPos); + EXPECT_EQ(wValueNeg, workingDataNeg); StorageType sNewValuePos; StorageType sNewValueNeg; @@ -577,8 +577,8 @@ void Test_SINT40_LE(nlTestSuite * apSuite, void * apContext) IntType::WorkingToStorage(wValueNeg, sNewValueNeg); // 3) Verify that the bytes are located as intended - NL_TEST_ASSERT(apSuite, memcmp(storageTestDataPos, &sNewValuePos, sizeof(sNewValuePos)) == 0); - NL_TEST_ASSERT(apSuite, memcmp(storageTestDataNeg, &sNewValueNeg, sizeof(sNewValueNeg)) == 0); + EXPECT_EQ(memcmp(storageTestDataPos, &sNewValuePos, sizeof(sNewValuePos)), 0); + EXPECT_EQ(memcmp(storageTestDataNeg, &sNewValueNeg, sizeof(sNewValueNeg)), 0); StorageType sNullValue; WorkingType wNullValue; @@ -586,19 +586,19 @@ void Test_SINT40_LE(nlTestSuite * apSuite, void * apContext) // Set Storage value to Null IntType::SetNull(sNullValue); wNullValue = IntType::StorageToWorking(sNullValue); - NL_TEST_ASSERT(apSuite, wNullValue == workingTestSignedNullValue); - NL_TEST_ASSERT(apSuite, (IntType::IsNullValue(sNullValue) == true)); + EXPECT_EQ(wNullValue, workingTestSignedNullValue); + EXPECT_TRUE(IntType::IsNullValue(sNullValue)); // Verify that null values can fit into not nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, sNullValue) == true)); - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, wNullValue) == true)); + EXPECT_TRUE(IntType::CanRepresentValue(false, sNullValue)); + EXPECT_TRUE(IntType::CanRepresentValue(false, wNullValue)); // Verify that null values can't fit into nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, sNullValue) == false)); - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, wNullValue) == false)); + EXPECT_FALSE(IntType::CanRepresentValue(true, sNullValue)); + EXPECT_FALSE(IntType::CanRepresentValue(true, wNullValue)); } -void Test_SINT40_BE(nlTestSuite * apSuite, void * apContext) +TEST(TestNumericAttributeTraits, Test_SINT40_BE) { // Signed 40-bit Integer : 5 bytes - big-endian using IntType = NumericAttributeTraits, true>; @@ -617,10 +617,10 @@ void Test_SINT40_BE(nlTestSuite * apSuite, void * apContext) const WorkingType workingTestSignedNullValue = -549755813888; // -0x8000000000 // 1) Verify the size of the types - NL_TEST_ASSERT(apSuite, sizeof(sValuePos) == 5); - NL_TEST_ASSERT(apSuite, sizeof(wValuePos) >= 5); - NL_TEST_ASSERT(apSuite, sizeof(sValueNeg) == 5); - NL_TEST_ASSERT(apSuite, sizeof(wValueNeg) >= 5); + EXPECT_EQ(sizeof(sValuePos), 5u); + EXPECT_GE(sizeof(wValuePos), 5u); + EXPECT_EQ(sizeof(sValueNeg), 5u); + EXPECT_GE(sizeof(wValueNeg), 5u); // Initialize the Storage Values with the test-buffer memcpy(&sValuePos, storageTestDataPos, sizeof(sValuePos)); @@ -631,8 +631,8 @@ void Test_SINT40_BE(nlTestSuite * apSuite, void * apContext) wValueNeg = IntType::StorageToWorking(sValueNeg); // 2) Verify that the correct storage format has been used - NL_TEST_ASSERT(apSuite, wValuePos == workingDataPos); - NL_TEST_ASSERT(apSuite, wValueNeg == workingDataNeg); + EXPECT_EQ(wValuePos, workingDataPos); + EXPECT_EQ(wValueNeg, workingDataNeg); StorageType sNewValuePos; StorageType sNewValueNeg; @@ -642,8 +642,8 @@ void Test_SINT40_BE(nlTestSuite * apSuite, void * apContext) IntType::WorkingToStorage(wValueNeg, sNewValueNeg); // 3) Verify that the bytes are located as intended - NL_TEST_ASSERT(apSuite, memcmp(storageTestDataPos, &sNewValuePos, sizeof(sNewValuePos)) == 0); - NL_TEST_ASSERT(apSuite, memcmp(storageTestDataNeg, &sNewValueNeg, sizeof(sNewValueNeg)) == 0); + EXPECT_EQ(memcmp(storageTestDataPos, &sNewValuePos, sizeof(sNewValuePos)), 0); + EXPECT_EQ(memcmp(storageTestDataNeg, &sNewValueNeg, sizeof(sNewValueNeg)), 0); StorageType sNullValue; WorkingType wNullValue; @@ -651,16 +651,16 @@ void Test_SINT40_BE(nlTestSuite * apSuite, void * apContext) // Set Storage value to Null IntType::SetNull(sNullValue); wNullValue = IntType::StorageToWorking(sNullValue); - NL_TEST_ASSERT(apSuite, wNullValue == workingTestSignedNullValue); - NL_TEST_ASSERT(apSuite, (IntType::IsNullValue(sNullValue) == true)); + EXPECT_EQ(wNullValue, workingTestSignedNullValue); + EXPECT_TRUE(IntType::IsNullValue(sNullValue)); // Verify that null values can fit into not nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, sNullValue) == true)); - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, wNullValue) == true)); + EXPECT_TRUE(IntType::CanRepresentValue(false, sNullValue)); + EXPECT_TRUE(IntType::CanRepresentValue(false, wNullValue)); // Verify that null values can't fit into nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, sNullValue) == false)); - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, wNullValue) == false)); + EXPECT_FALSE(IntType::CanRepresentValue(true, sNullValue)); + EXPECT_FALSE(IntType::CanRepresentValue(true, wNullValue)); } //////////////////////////////////////////////////////////// @@ -675,7 +675,7 @@ void Test_SINT40_BE(nlTestSuite * apSuite, void * apContext) // $$/ $$$$$$/ $$$$$$$/ $$$$$$/ $$/ // // // //////////////////////////////////////////////////////////// -void Test_UINT48_LE(nlTestSuite * apSuite, void * apContext) +TEST(TestNumericAttributeTraits, Test_UINT48_LE) { // Unsigned 48-bit Integer : 6 bytes - little-endian using IntType = NumericAttributeTraits, false>; @@ -690,8 +690,8 @@ void Test_UINT48_LE(nlTestSuite * apSuite, void * apContext) const WorkingType workingTestUnsignedNullValue = 281474976710655; // 0xFFFFFFFFFFFF // 1) Verify the size of the types - NL_TEST_ASSERT(apSuite, sizeof(sValue) == 6); - NL_TEST_ASSERT(apSuite, sizeof(wValue) >= 6); + EXPECT_EQ(sizeof(sValue), 6u); + EXPECT_GE(sizeof(wValue), 6u); // Initialize the Storage Value with the test-buffer memcpy(&sValue, storageTestData, sizeof(sValue)); @@ -700,7 +700,7 @@ void Test_UINT48_LE(nlTestSuite * apSuite, void * apContext) wValue = IntType::StorageToWorking(sValue); // 2) Verify that the correct storage format has been used - NL_TEST_ASSERT(apSuite, wValue == 0x123456789ABC); + EXPECT_EQ(wValue, 0x123456789ABCu); StorageType sNewValue; @@ -708,22 +708,22 @@ void Test_UINT48_LE(nlTestSuite * apSuite, void * apContext) IntType::WorkingToStorage(wValue, sNewValue); // 3) Verify that the bytes are located as intended - NL_TEST_ASSERT(apSuite, memcmp(storageTestData, &sNewValue, sizeof(sNewValue)) == 0); + EXPECT_EQ(memcmp(storageTestData, &sNewValue, sizeof(sNewValue)), 0); // Set Storage value to Null IntType::SetNull(sNullValue); wNullValue = IntType::StorageToWorking(sNullValue); - NL_TEST_ASSERT(apSuite, wNullValue == workingTestUnsignedNullValue); - NL_TEST_ASSERT(apSuite, (IntType::IsNullValue(sNullValue) == true)); + EXPECT_EQ(wNullValue, workingTestUnsignedNullValue); + EXPECT_TRUE(IntType::IsNullValue(sNullValue)); // Verify that null values can fit into not nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, sNullValue) == true)); + EXPECT_TRUE(IntType::CanRepresentValue(false, sNullValue)); // Verify that null values can't fit into nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, sNullValue) == false)); + EXPECT_FALSE(IntType::CanRepresentValue(true, sNullValue)); } -void Test_UINT48_BE(nlTestSuite * apSuite, void * apContext) +TEST(TestNumericAttributeTraits, Test_UINT48_BE) { // Unsigned 48-bit Integer : 6 bytes - big-endian using IntType = NumericAttributeTraits, true>; @@ -738,8 +738,8 @@ void Test_UINT48_BE(nlTestSuite * apSuite, void * apContext) const WorkingType workingTestUnsignedNullValue = 281474976710655; // 0xFFFFFFFFFFFF // 1) Verify the size of the types - NL_TEST_ASSERT(apSuite, sizeof(sValue) == 6); - NL_TEST_ASSERT(apSuite, sizeof(wValue) >= 6); + EXPECT_EQ(sizeof(sValue), 6u); + EXPECT_GE(sizeof(wValue), 6u); // Initialize the Storage Value with the test-buffer memcpy(&sValue, storageTestData, sizeof(sValue)); @@ -748,7 +748,7 @@ void Test_UINT48_BE(nlTestSuite * apSuite, void * apContext) wValue = IntType::StorageToWorking(sValue); // 2) Verify that the correct storage format has been used - NL_TEST_ASSERT(apSuite, wValue == 0x123456789ABC); + EXPECT_EQ(wValue, 0x123456789ABCu); StorageType sNewValue; @@ -756,22 +756,22 @@ void Test_UINT48_BE(nlTestSuite * apSuite, void * apContext) IntType::WorkingToStorage(wValue, sNewValue); // 3) Verify that the bytes are located as intended - NL_TEST_ASSERT(apSuite, memcmp(storageTestData, &sNewValue, sizeof(sNewValue)) == 0); + EXPECT_EQ(memcmp(storageTestData, &sNewValue, sizeof(sNewValue)), 0); // Set Storage value to Null IntType::SetNull(sNullValue); wNullValue = IntType::StorageToWorking(sNullValue); - NL_TEST_ASSERT(apSuite, wNullValue == workingTestUnsignedNullValue); - NL_TEST_ASSERT(apSuite, (IntType::IsNullValue(sNullValue) == true)); + EXPECT_EQ(wNullValue, workingTestUnsignedNullValue); + EXPECT_TRUE(IntType::IsNullValue(sNullValue)); // Verify that null values can fit into not nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, sNullValue) == true)); + EXPECT_TRUE(IntType::CanRepresentValue(false, sNullValue)); // Verify that null values can't fit into nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, sNullValue) == false)); + EXPECT_FALSE(IntType::CanRepresentValue(true, sNullValue)); } -void Test_SINT48_LE(nlTestSuite * apSuite, void * apContext) +TEST(TestNumericAttributeTraits, Test_SINT48_LE) { // Signed 48-bit Integer : 6 bytes - little-endian using IntType = NumericAttributeTraits, false>; @@ -790,10 +790,10 @@ void Test_SINT48_LE(nlTestSuite * apSuite, void * apContext) const WorkingType workingTestSignedNullValue = -140737488355328; // -0x800000000000 // 1) Verify the size of the types - NL_TEST_ASSERT(apSuite, sizeof(sValuePos) == 6); - NL_TEST_ASSERT(apSuite, sizeof(wValuePos) >= 6); - NL_TEST_ASSERT(apSuite, sizeof(sValueNeg) == 6); - NL_TEST_ASSERT(apSuite, sizeof(wValueNeg) >= 6); + EXPECT_EQ(sizeof(sValuePos), 6u); + EXPECT_GE(sizeof(wValuePos), 6u); + EXPECT_EQ(sizeof(sValueNeg), 6u); + EXPECT_GE(sizeof(wValueNeg), 6u); // Initialize the Storage Values with the test-buffer memcpy(&sValuePos, storageTestDataPos, sizeof(sValuePos)); @@ -804,8 +804,8 @@ void Test_SINT48_LE(nlTestSuite * apSuite, void * apContext) wValueNeg = IntType::StorageToWorking(sValueNeg); // 2) Verify that the correct storage format has been used - NL_TEST_ASSERT(apSuite, wValuePos == workingDataPos); - NL_TEST_ASSERT(apSuite, wValueNeg == workingDataNeg); + EXPECT_EQ(wValuePos, workingDataPos); + EXPECT_EQ(wValueNeg, workingDataNeg); StorageType sNewValuePos; StorageType sNewValueNeg; @@ -815,8 +815,8 @@ void Test_SINT48_LE(nlTestSuite * apSuite, void * apContext) IntType::WorkingToStorage(wValueNeg, sNewValueNeg); // 3) Verify that the bytes are located as intended - NL_TEST_ASSERT(apSuite, memcmp(storageTestDataPos, &sNewValuePos, sizeof(sNewValuePos)) == 0); - NL_TEST_ASSERT(apSuite, memcmp(storageTestDataNeg, &sNewValueNeg, sizeof(sNewValueNeg)) == 0); + EXPECT_EQ(memcmp(storageTestDataPos, &sNewValuePos, sizeof(sNewValuePos)), 0); + EXPECT_EQ(memcmp(storageTestDataNeg, &sNewValueNeg, sizeof(sNewValueNeg)), 0); StorageType sNullValue; WorkingType wNullValue; @@ -824,19 +824,19 @@ void Test_SINT48_LE(nlTestSuite * apSuite, void * apContext) // Set Storage value to Null IntType::SetNull(sNullValue); wNullValue = IntType::StorageToWorking(sNullValue); - NL_TEST_ASSERT(apSuite, wNullValue == workingTestSignedNullValue); - NL_TEST_ASSERT(apSuite, (IntType::IsNullValue(sNullValue) == true)); + EXPECT_EQ(wNullValue, workingTestSignedNullValue); + EXPECT_TRUE(IntType::IsNullValue(sNullValue)); // Verify that null values can fit into not nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, sNullValue) == true)); - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, wNullValue) == true)); + EXPECT_TRUE(IntType::CanRepresentValue(false, sNullValue)); + EXPECT_TRUE(IntType::CanRepresentValue(false, wNullValue)); // Verify that null values can't fit into nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, sNullValue) == false)); - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, wNullValue) == false)); + EXPECT_FALSE(IntType::CanRepresentValue(true, sNullValue)); + EXPECT_FALSE(IntType::CanRepresentValue(true, wNullValue)); } -void Test_SINT48_BE(nlTestSuite * apSuite, void * apContext) +TEST(TestNumericAttributeTraits, Test_SINT48_BE) { // Signed 48-bit Integer : 6 bytes - big-endian using IntType = NumericAttributeTraits, true>; @@ -855,10 +855,10 @@ void Test_SINT48_BE(nlTestSuite * apSuite, void * apContext) const WorkingType workingTestSignedNullValue = -140737488355328; // -0x800000000000 // 1) Verify the size of the types - NL_TEST_ASSERT(apSuite, sizeof(sValuePos) == 6); - NL_TEST_ASSERT(apSuite, sizeof(wValuePos) >= 6); - NL_TEST_ASSERT(apSuite, sizeof(sValueNeg) == 6); - NL_TEST_ASSERT(apSuite, sizeof(wValueNeg) >= 6); + EXPECT_EQ(sizeof(sValuePos), 6u); + EXPECT_GE(sizeof(wValuePos), 6u); + EXPECT_EQ(sizeof(sValueNeg), 6u); + EXPECT_GE(sizeof(wValueNeg), 6u); // Initialize the Storage Values with the test-buffer memcpy(&sValuePos, storageTestDataPos, sizeof(sValuePos)); @@ -869,8 +869,8 @@ void Test_SINT48_BE(nlTestSuite * apSuite, void * apContext) wValueNeg = IntType::StorageToWorking(sValueNeg); // 2) Verify that the correct storage format has been used - NL_TEST_ASSERT(apSuite, wValuePos == workingDataPos); - NL_TEST_ASSERT(apSuite, wValueNeg == workingDataNeg); + EXPECT_EQ(wValuePos, workingDataPos); + EXPECT_EQ(wValueNeg, workingDataNeg); StorageType sNewValuePos; StorageType sNewValueNeg; @@ -880,8 +880,8 @@ void Test_SINT48_BE(nlTestSuite * apSuite, void * apContext) IntType::WorkingToStorage(wValueNeg, sNewValueNeg); // 3) Verify that the bytes are located as intended - NL_TEST_ASSERT(apSuite, memcmp(storageTestDataPos, &sNewValuePos, sizeof(sNewValuePos)) == 0); - NL_TEST_ASSERT(apSuite, memcmp(storageTestDataNeg, &sNewValueNeg, sizeof(sNewValueNeg)) == 0); + EXPECT_EQ(memcmp(storageTestDataPos, &sNewValuePos, sizeof(sNewValuePos)), 0); + EXPECT_EQ(memcmp(storageTestDataNeg, &sNewValueNeg, sizeof(sNewValueNeg)), 0); StorageType sNullValue; WorkingType wNullValue; @@ -889,16 +889,16 @@ void Test_SINT48_BE(nlTestSuite * apSuite, void * apContext) // Set Storage value to Null IntType::SetNull(sNullValue); wNullValue = IntType::StorageToWorking(sNullValue); - NL_TEST_ASSERT(apSuite, wNullValue == workingTestSignedNullValue); - NL_TEST_ASSERT(apSuite, (IntType::IsNullValue(sNullValue) == true)); + EXPECT_EQ(wNullValue, workingTestSignedNullValue); + EXPECT_TRUE(IntType::IsNullValue(sNullValue)); // Verify that null values can fit into not nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, sNullValue) == true)); - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, wNullValue) == true)); + EXPECT_TRUE(IntType::CanRepresentValue(false, sNullValue)); + EXPECT_TRUE(IntType::CanRepresentValue(false, wNullValue)); // Verify that null values can't fit into nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, sNullValue) == false)); - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, wNullValue) == false)); + EXPECT_FALSE(IntType::CanRepresentValue(true, sNullValue)); + EXPECT_FALSE(IntType::CanRepresentValue(true, wNullValue)); } //////////////////////////////////////////////////////////// @@ -913,7 +913,7 @@ void Test_SINT48_BE(nlTestSuite * apSuite, void * apContext) // $$$$$$/ $$$$$$/ $$$$$$$/ $$$$$$/ $$/ // // // //////////////////////////////////////////////////////////// -void Test_UINT56_LE(nlTestSuite * apSuite, void * apContext) +TEST(TestNumericAttributeTraits, Test_UINT56_LE) { // Unsigned 56-bit Integer : 7 bytes - little-endian using IntType = NumericAttributeTraits, false>; @@ -928,8 +928,8 @@ void Test_UINT56_LE(nlTestSuite * apSuite, void * apContext) const WorkingType workingTestUnsignedNullValue = 72057594037927935; // 0xFFFFFFFFFFFFFF // 1) Verify the size of the types - NL_TEST_ASSERT(apSuite, sizeof(sValue) == 7); - NL_TEST_ASSERT(apSuite, sizeof(wValue) >= 7); + EXPECT_EQ(sizeof(sValue), 7u); + EXPECT_GE(sizeof(wValue), 7u); // Initialize the Storage Value with the test-buffer memcpy(&sValue, storageTestData, sizeof(sValue)); @@ -938,7 +938,7 @@ void Test_UINT56_LE(nlTestSuite * apSuite, void * apContext) wValue = IntType::StorageToWorking(sValue); // 2) Verify that the correct storage format has been used - NL_TEST_ASSERT(apSuite, wValue == 0x123456789ABCDE); + EXPECT_EQ(wValue, 0x123456789ABCDEu); StorageType sNewValue; @@ -946,22 +946,22 @@ void Test_UINT56_LE(nlTestSuite * apSuite, void * apContext) IntType::WorkingToStorage(wValue, sNewValue); // 3) Verify that the bytes are located as intended - NL_TEST_ASSERT(apSuite, memcmp(storageTestData, &sNewValue, sizeof(sNewValue)) == 0); + EXPECT_EQ(memcmp(storageTestData, &sNewValue, sizeof(sNewValue)), 0); // Set Storage value to Null IntType::SetNull(sNullValue); wNullValue = IntType::StorageToWorking(sNullValue); - NL_TEST_ASSERT(apSuite, wNullValue == workingTestUnsignedNullValue); - NL_TEST_ASSERT(apSuite, (IntType::IsNullValue(sNullValue) == true)); + EXPECT_EQ(wNullValue, workingTestUnsignedNullValue); + EXPECT_TRUE(IntType::IsNullValue(sNullValue)); // Verify that null values can fit into not nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, sNullValue) == true)); + EXPECT_TRUE(IntType::CanRepresentValue(false, sNullValue)); // Verify that null values can't fit into nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, sNullValue) == false)); + EXPECT_FALSE(IntType::CanRepresentValue(true, sNullValue)); } -void Test_UINT56_BE(nlTestSuite * apSuite, void * apContext) +TEST(TestNumericAttributeTraits, Test_UINT56_BE) { // Unsigned 56-bit Integer : 7 bytes - big-endian using IntType = NumericAttributeTraits, true>; @@ -976,8 +976,8 @@ void Test_UINT56_BE(nlTestSuite * apSuite, void * apContext) const WorkingType workingTestUnsignedNullValue = 72057594037927935; // 0xFFFFFFFFFFFFFF // 1) Verify the size of the types - NL_TEST_ASSERT(apSuite, sizeof(sValue) == 7); - NL_TEST_ASSERT(apSuite, sizeof(wValue) >= 7); + EXPECT_EQ(sizeof(sValue), 7u); + EXPECT_GE(sizeof(wValue), 7u); // Initialize the Storage Value with the test-buffer memcpy(&sValue, storageTestData, sizeof(sValue)); @@ -986,7 +986,7 @@ void Test_UINT56_BE(nlTestSuite * apSuite, void * apContext) wValue = IntType::StorageToWorking(sValue); // 2) Verify that the correct storage format has been used - NL_TEST_ASSERT(apSuite, wValue == 0x123456789ABCDE); + EXPECT_EQ(wValue, 0x123456789ABCDEu); StorageType sNewValue; @@ -994,22 +994,22 @@ void Test_UINT56_BE(nlTestSuite * apSuite, void * apContext) IntType::WorkingToStorage(wValue, sNewValue); // 3) Verify that the bytes are located as intended - NL_TEST_ASSERT(apSuite, memcmp(storageTestData, &sNewValue, sizeof(sNewValue)) == 0); + EXPECT_EQ(memcmp(storageTestData, &sNewValue, sizeof(sNewValue)), 0); // Set Storage value to Null IntType::SetNull(sNullValue); wNullValue = IntType::StorageToWorking(sNullValue); - NL_TEST_ASSERT(apSuite, wNullValue == workingTestUnsignedNullValue); - NL_TEST_ASSERT(apSuite, (IntType::IsNullValue(sNullValue) == true)); + EXPECT_EQ(wNullValue, workingTestUnsignedNullValue); + EXPECT_TRUE(IntType::IsNullValue(sNullValue)); // Verify that null values can fit into not nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, sNullValue) == true)); + EXPECT_TRUE(IntType::CanRepresentValue(false, sNullValue)); // Verify that null values can't fit into nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, sNullValue) == false)); + EXPECT_FALSE(IntType::CanRepresentValue(true, sNullValue)); } -void Test_SINT56_LE(nlTestSuite * apSuite, void * apContext) +TEST(TestNumericAttributeTraits, Test_SINT56_LE) { // Signed 56-bit Integer : 6 bytes - little-endian using IntType = NumericAttributeTraits, false>; @@ -1028,10 +1028,10 @@ void Test_SINT56_LE(nlTestSuite * apSuite, void * apContext) const WorkingType workingTestSignedNullValue = -36028797018963968; // -0x80000000000000 // 1) Verify the size of the types - NL_TEST_ASSERT(apSuite, sizeof(sValuePos) == 7); - NL_TEST_ASSERT(apSuite, sizeof(wValuePos) >= 7); - NL_TEST_ASSERT(apSuite, sizeof(sValueNeg) == 7); - NL_TEST_ASSERT(apSuite, sizeof(wValueNeg) >= 7); + EXPECT_EQ(sizeof(sValuePos), 7u); + EXPECT_GE(sizeof(wValuePos), 7u); + EXPECT_EQ(sizeof(sValueNeg), 7u); + EXPECT_GE(sizeof(wValueNeg), 7u); // Initialize the Storage Values with the test-buffer memcpy(&sValuePos, storageTestDataPos, sizeof(sValuePos)); @@ -1042,8 +1042,8 @@ void Test_SINT56_LE(nlTestSuite * apSuite, void * apContext) wValueNeg = IntType::StorageToWorking(sValueNeg); // 2) Verify that the correct storage format has been used - NL_TEST_ASSERT(apSuite, wValuePos == workingDataPos); - NL_TEST_ASSERT(apSuite, wValueNeg == workingDataNeg); + EXPECT_EQ(wValuePos, workingDataPos); + EXPECT_EQ(wValueNeg, workingDataNeg); StorageType sNewValuePos; StorageType sNewValueNeg; @@ -1053,8 +1053,8 @@ void Test_SINT56_LE(nlTestSuite * apSuite, void * apContext) IntType::WorkingToStorage(wValueNeg, sNewValueNeg); // 3) Verify that the bytes are located as intended - NL_TEST_ASSERT(apSuite, memcmp(storageTestDataPos, &sNewValuePos, sizeof(sNewValuePos)) == 0); - NL_TEST_ASSERT(apSuite, memcmp(storageTestDataNeg, &sNewValueNeg, sizeof(sNewValueNeg)) == 0); + EXPECT_EQ(memcmp(storageTestDataPos, &sNewValuePos, sizeof(sNewValuePos)), 0); + EXPECT_EQ(memcmp(storageTestDataNeg, &sNewValueNeg, sizeof(sNewValueNeg)), 0); StorageType sNullValue; WorkingType wNullValue; @@ -1062,19 +1062,19 @@ void Test_SINT56_LE(nlTestSuite * apSuite, void * apContext) // Set Storage value to Null IntType::SetNull(sNullValue); wNullValue = IntType::StorageToWorking(sNullValue); - NL_TEST_ASSERT(apSuite, wNullValue == workingTestSignedNullValue); - NL_TEST_ASSERT(apSuite, (IntType::IsNullValue(sNullValue) == true)); + EXPECT_EQ(wNullValue, workingTestSignedNullValue); + EXPECT_TRUE(IntType::IsNullValue(sNullValue)); // Verify that null values can fit into not nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, sNullValue) == true)); - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, wNullValue) == true)); + EXPECT_TRUE(IntType::CanRepresentValue(false, sNullValue)); + EXPECT_TRUE(IntType::CanRepresentValue(false, wNullValue)); // Verify that null values can't fit into nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, sNullValue) == false)); - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, wNullValue) == false)); + EXPECT_FALSE(IntType::CanRepresentValue(true, sNullValue)); + EXPECT_FALSE(IntType::CanRepresentValue(true, wNullValue)); } -void Test_SINT56_BE(nlTestSuite * apSuite, void * apContext) +TEST(TestNumericAttributeTraits, Test_SINT56_BE) { // Signed 56-bit Integer : 7 bytes - big-endian using IntType = NumericAttributeTraits, true>; @@ -1093,10 +1093,10 @@ void Test_SINT56_BE(nlTestSuite * apSuite, void * apContext) const WorkingType workingTestSignedNullValue = -36028797018963968; // -0x80000000000000 // 1) Verify the size of the types - NL_TEST_ASSERT(apSuite, sizeof(sValuePos) == 7); - NL_TEST_ASSERT(apSuite, sizeof(wValuePos) >= 7); - NL_TEST_ASSERT(apSuite, sizeof(sValueNeg) == 7); - NL_TEST_ASSERT(apSuite, sizeof(wValueNeg) >= 7); + EXPECT_EQ(sizeof(sValuePos), 7u); + EXPECT_GE(sizeof(wValuePos), 7u); + EXPECT_EQ(sizeof(sValueNeg), 7u); + EXPECT_GE(sizeof(wValueNeg), 7u); // Initialize the Storage Values with the test-buffer memcpy(&sValuePos, storageTestDataPos, sizeof(sValuePos)); @@ -1107,8 +1107,8 @@ void Test_SINT56_BE(nlTestSuite * apSuite, void * apContext) wValueNeg = IntType::StorageToWorking(sValueNeg); // 2) Verify that the correct storage format has been used - NL_TEST_ASSERT(apSuite, wValuePos == workingDataPos); - NL_TEST_ASSERT(apSuite, wValueNeg == workingDataNeg); + EXPECT_EQ(wValuePos, workingDataPos); + EXPECT_EQ(wValueNeg, workingDataNeg); StorageType sNewValuePos; StorageType sNewValueNeg; @@ -1118,8 +1118,8 @@ void Test_SINT56_BE(nlTestSuite * apSuite, void * apContext) IntType::WorkingToStorage(wValueNeg, sNewValueNeg); // 3) Verify that the bytes are located as intended - NL_TEST_ASSERT(apSuite, memcmp(storageTestDataPos, &sNewValuePos, sizeof(sNewValuePos)) == 0); - NL_TEST_ASSERT(apSuite, memcmp(storageTestDataNeg, &sNewValueNeg, sizeof(sNewValueNeg)) == 0); + EXPECT_EQ(memcmp(storageTestDataPos, &sNewValuePos, sizeof(sNewValuePos)), 0); + EXPECT_EQ(memcmp(storageTestDataNeg, &sNewValueNeg, sizeof(sNewValueNeg)), 0); StorageType sNullValue; WorkingType wNullValue; @@ -1127,82 +1127,16 @@ void Test_SINT56_BE(nlTestSuite * apSuite, void * apContext) // Set Storage value to Null IntType::SetNull(sNullValue); wNullValue = IntType::StorageToWorking(sNullValue); - NL_TEST_ASSERT(apSuite, wNullValue == workingTestSignedNullValue); - NL_TEST_ASSERT(apSuite, (IntType::IsNullValue(sNullValue) == true)); + EXPECT_EQ(wNullValue, workingTestSignedNullValue); + EXPECT_TRUE(IntType::IsNullValue(sNullValue)); // Verify that null values can fit into not nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, sNullValue) == true)); - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(false, wNullValue) == true)); + EXPECT_TRUE(IntType::CanRepresentValue(false, sNullValue)); + EXPECT_TRUE(IntType::CanRepresentValue(false, wNullValue)); // Verify that null values can't fit into nullable - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, sNullValue) == false)); - NL_TEST_ASSERT(apSuite, (IntType::CanRepresentValue(true, wNullValue) == false)); + EXPECT_FALSE(IntType::CanRepresentValue(true, sNullValue)); + EXPECT_FALSE(IntType::CanRepresentValue(true, wNullValue)); } -static int TestSetup(void * inContext) -{ - return SUCCESS; -} - -/** - * Tear down the test suite. - */ -static int TestTeardown(void * inContext) -{ - return SUCCESS; -} - -/** - * Test Suite. It lists all the test functions. - */ - -// clang-format off -const nlTest sTests[] = -{ - NL_TEST_DEF("Test_UINT8", Test_UINT8), - NL_TEST_DEF("Test_SINT8", Test_SINT8), - NL_TEST_DEF("Test_SimpleEnum", Test_SimpleEnum), - - NL_TEST_DEF("Test_UINT24_LE",Test_UINT24_LE), - NL_TEST_DEF("Test_SINT24_LE",Test_SINT24_LE), - NL_TEST_DEF("Test_UINT24_BE",Test_UINT24_BE), - NL_TEST_DEF("Test_SINT24_BE",Test_SINT24_BE), - - NL_TEST_DEF("Test_UINT40_LE",Test_UINT40_LE), - NL_TEST_DEF("Test_SINT40_LE",Test_SINT40_LE), - NL_TEST_DEF("Test_UINT40_BE",Test_UINT40_BE), - NL_TEST_DEF("Test_SINT40_BE",Test_SINT40_BE), - - NL_TEST_DEF("Test_UINT48_LE",Test_UINT48_LE), - NL_TEST_DEF("Test_SINT48_LE",Test_SINT48_LE), - NL_TEST_DEF("Test_UINT48_BE",Test_UINT48_BE), - NL_TEST_DEF("Test_SINT48_BE",Test_SINT48_BE), - - NL_TEST_DEF("Test_UINT56_LE",Test_UINT56_LE), - NL_TEST_DEF("Test_SINT56_LE",Test_SINT56_LE), - NL_TEST_DEF("Test_UINT56_BE",Test_UINT56_BE), - NL_TEST_DEF("Test_SINT56_BE",Test_SINT56_BE), - - NL_TEST_SENTINEL() -}; -// clang-format on - -// clang-format off -nlTestSuite theSuite = -{ - "TestNumericAttributeTraits", - &sTests[0], - TestSetup, - TestTeardown -}; -// clang-format on - } // namespace - -int TestNumericAttributeTraits() -{ - nlTestRunner(&theSuite, nullptr); - return (nlTestRunnerStats(&theSuite)); -} - -CHIP_REGISTER_TEST_SUITE(TestNumericAttributeTraits) diff --git a/src/app/tests/TestOperationalStateClusterObjects.cpp b/src/app/tests/TestOperationalStateClusterObjects.cpp index 9f7d1e1efcadac..2b305949d8fe8d 100644 --- a/src/app/tests/TestOperationalStateClusterObjects.cpp +++ b/src/app/tests/TestOperationalStateClusterObjects.cpp @@ -17,9 +17,8 @@ #include #include -#include - -#include +#include +#include using namespace chip; using namespace chip::DeviceLayer; @@ -27,31 +26,38 @@ using namespace chip::app::Clusters::OperationalState; namespace { -void TestStructGenericOperationalStateConstructorWithOnlyStateID(nlTestSuite * inSuite, void * inContext) +class TestOperationalStateClusterObjects : public ::testing::Test +{ +public: + static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); } + static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); } +}; + +TEST_F(TestOperationalStateClusterObjects, TestStructGenericOperationalStateConstructorWithOnlyStateID) { using namespace chip::app::Clusters::OperationalState; // General state: Stopped GenericOperationalState operationalStateStopped(to_underlying(OperationalStateEnum::kStopped)); - NL_TEST_ASSERT(inSuite, operationalStateStopped.operationalStateID == to_underlying(OperationalStateEnum::kStopped)); - NL_TEST_ASSERT(inSuite, operationalStateStopped.operationalStateLabel.HasValue() == false); + EXPECT_EQ(operationalStateStopped.operationalStateID, to_underlying(OperationalStateEnum::kStopped)); + EXPECT_FALSE(operationalStateStopped.operationalStateLabel.HasValue()); // General state: Running GenericOperationalState operationalStateRunning(to_underlying(OperationalStateEnum::kRunning)); - NL_TEST_ASSERT(inSuite, operationalStateRunning.operationalStateID == to_underlying(OperationalStateEnum::kRunning)); - NL_TEST_ASSERT(inSuite, operationalStateRunning.operationalStateLabel.HasValue() == false); + EXPECT_EQ(operationalStateRunning.operationalStateID, to_underlying(OperationalStateEnum::kRunning)); + EXPECT_FALSE(operationalStateRunning.operationalStateLabel.HasValue()); // General state: Paused GenericOperationalState operationalStatePaused(to_underlying(OperationalStateEnum::kPaused)); - NL_TEST_ASSERT(inSuite, operationalStatePaused.operationalStateID == to_underlying(OperationalStateEnum::kPaused)); - NL_TEST_ASSERT(inSuite, operationalStatePaused.operationalStateLabel.HasValue() == false); + EXPECT_EQ(operationalStatePaused.operationalStateID, to_underlying(OperationalStateEnum::kPaused)); + EXPECT_FALSE(operationalStatePaused.operationalStateLabel.HasValue()); // General state: Error GenericOperationalState operationalStateError(to_underlying(OperationalStateEnum::kError)); - NL_TEST_ASSERT(inSuite, operationalStateError.operationalStateID == to_underlying(OperationalStateEnum::kError)); - NL_TEST_ASSERT(inSuite, operationalStateError.operationalStateLabel.HasValue() == false); + EXPECT_EQ(operationalStateError.operationalStateID, to_underlying(OperationalStateEnum::kError)); + EXPECT_FALSE(operationalStateError.operationalStateLabel.HasValue()); } -void TestStructGenericOperationalStateConstructorWithStateIDAndStateLabel(nlTestSuite * inSuite, void * inContext) +TEST_F(TestOperationalStateClusterObjects, TestStructGenericOperationalStateConstructorWithStateIDAndStateLabel) { using namespace chip::app::Clusters::OperationalState; @@ -66,14 +72,13 @@ void TestStructGenericOperationalStateConstructorWithStateIDAndStateLabel(nlTest GenericOperationalState operationalState(to_underlying(ManufactureOperationalStateEnum::kRebooting), Optional(CharSpan::fromCharString(buffer))); - NL_TEST_ASSERT(inSuite, operationalState.operationalStateID == to_underlying(ManufactureOperationalStateEnum::kRebooting)); - NL_TEST_ASSERT(inSuite, operationalState.operationalStateLabel.HasValue() == true); - NL_TEST_ASSERT(inSuite, operationalState.operationalStateLabel.Value().size() == strlen(buffer)); - NL_TEST_ASSERT(inSuite, - memcmp(const_cast(operationalState.operationalStateLabel.Value().data()), buffer, strlen(buffer)) == 0); + EXPECT_EQ(operationalState.operationalStateID, to_underlying(ManufactureOperationalStateEnum::kRebooting)); + EXPECT_TRUE(operationalState.operationalStateLabel.HasValue()); + EXPECT_EQ(operationalState.operationalStateLabel.Value().size(), strlen(buffer)); + EXPECT_EQ(memcmp(const_cast(operationalState.operationalStateLabel.Value().data()), buffer, strlen(buffer)), 0); } -void TestStructGenericOperationalStateCopyConstructor(nlTestSuite * inSuite, void * inContext) +TEST_F(TestOperationalStateClusterObjects, TestStructGenericOperationalStateCopyConstructor) { using namespace chip::app::Clusters::OperationalState; @@ -89,18 +94,16 @@ void TestStructGenericOperationalStateCopyConstructor(nlTestSuite * inSuite, voi GenericOperationalState desOperationalState(srcOperationalState); - NL_TEST_ASSERT(inSuite, desOperationalState.operationalStateID == srcOperationalState.operationalStateID); - NL_TEST_ASSERT(inSuite, desOperationalState.operationalStateLabel.HasValue() == true); - NL_TEST_ASSERT(inSuite, - desOperationalState.operationalStateLabel.Value().size() == - srcOperationalState.operationalStateLabel.Value().size()); - NL_TEST_ASSERT(inSuite, - memcmp(const_cast(desOperationalState.operationalStateLabel.Value().data()), - const_cast(srcOperationalState.operationalStateLabel.Value().data()), - desOperationalState.operationalStateLabel.Value().size()) == 0); + EXPECT_EQ(desOperationalState.operationalStateID, srcOperationalState.operationalStateID); + EXPECT_TRUE(desOperationalState.operationalStateLabel.HasValue()); + EXPECT_EQ(desOperationalState.operationalStateLabel.Value().size(), srcOperationalState.operationalStateLabel.Value().size()); + EXPECT_EQ(memcmp(const_cast(desOperationalState.operationalStateLabel.Value().data()), + const_cast(srcOperationalState.operationalStateLabel.Value().data()), + desOperationalState.operationalStateLabel.Value().size()), + 0); } -void TestStructGenericOperationalStateCopyAssignment(nlTestSuite * inSuite, void * inContext) +TEST_F(TestOperationalStateClusterObjects, TestStructGenericOperationalStateCopyAssignment) { using namespace chip::app::Clusters::OperationalState; @@ -116,18 +119,16 @@ void TestStructGenericOperationalStateCopyAssignment(nlTestSuite * inSuite, void GenericOperationalState desOperationalState = srcOperationalState; - NL_TEST_ASSERT(inSuite, desOperationalState.operationalStateID == srcOperationalState.operationalStateID); - NL_TEST_ASSERT(inSuite, desOperationalState.operationalStateLabel.HasValue() == true); - NL_TEST_ASSERT(inSuite, - desOperationalState.operationalStateLabel.Value().size() == - srcOperationalState.operationalStateLabel.Value().size()); - NL_TEST_ASSERT(inSuite, - memcmp(const_cast(desOperationalState.operationalStateLabel.Value().data()), - const_cast(srcOperationalState.operationalStateLabel.Value().data()), - desOperationalState.operationalStateLabel.Value().size()) == 0); + EXPECT_EQ(desOperationalState.operationalStateID, srcOperationalState.operationalStateID); + EXPECT_TRUE(desOperationalState.operationalStateLabel.HasValue()); + EXPECT_EQ(desOperationalState.operationalStateLabel.Value().size(), srcOperationalState.operationalStateLabel.Value().size()); + EXPECT_EQ(memcmp(const_cast(desOperationalState.operationalStateLabel.Value().data()), + const_cast(srcOperationalState.operationalStateLabel.Value().data()), + desOperationalState.operationalStateLabel.Value().size()), + 0); } -void TestStructGenericOperationalStateFuncSet(nlTestSuite * inSuite, void * inContext) +TEST_F(TestOperationalStateClusterObjects, TestStructGenericOperationalStateFuncSet) { using namespace chip::app::Clusters::OperationalState; @@ -144,17 +145,16 @@ void TestStructGenericOperationalStateFuncSet(nlTestSuite * inSuite, void * inCo // change state without label operationalState.Set(to_underlying(OperationalStateEnum::kStopped)); - NL_TEST_ASSERT(inSuite, operationalState.operationalStateID == to_underlying(OperationalStateEnum::kStopped)); - NL_TEST_ASSERT(inSuite, operationalState.operationalStateLabel.HasValue() == false); + EXPECT_EQ(operationalState.operationalStateID, to_underlying(OperationalStateEnum::kStopped)); + EXPECT_FALSE(operationalState.operationalStateLabel.HasValue()); // change state with label operationalState.Set(to_underlying(ManufactureOperationalStateEnum::kRebooting), Optional(CharSpan::fromCharString(buffer))); - NL_TEST_ASSERT(inSuite, operationalState.operationalStateID == to_underlying(ManufactureOperationalStateEnum::kRebooting)); - NL_TEST_ASSERT(inSuite, operationalState.operationalStateLabel.HasValue() == true); - NL_TEST_ASSERT(inSuite, operationalState.operationalStateLabel.Value().size() == strlen(buffer)); - NL_TEST_ASSERT(inSuite, - memcmp(const_cast(operationalState.operationalStateLabel.Value().data()), buffer, strlen(buffer)) == 0); + EXPECT_EQ(operationalState.operationalStateID, to_underlying(ManufactureOperationalStateEnum::kRebooting)); + EXPECT_TRUE(operationalState.operationalStateLabel.HasValue()); + EXPECT_EQ(operationalState.operationalStateLabel.Value().size(), strlen(buffer)); + EXPECT_EQ(memcmp(const_cast(operationalState.operationalStateLabel.Value().data()), buffer, strlen(buffer)), 0); // change state with label, label len = kOperationalStateLabelMaxSize for (size_t i = 0; i < sizeof(buffer); i++) @@ -163,11 +163,10 @@ void TestStructGenericOperationalStateFuncSet(nlTestSuite * inSuite, void * inCo } operationalState.Set(to_underlying(ManufactureOperationalStateEnum::kRebooting), Optional(CharSpan(buffer, sizeof(buffer)))); - NL_TEST_ASSERT(inSuite, operationalState.operationalStateID == to_underlying(ManufactureOperationalStateEnum::kRebooting)); - NL_TEST_ASSERT(inSuite, operationalState.operationalStateLabel.HasValue() == true); - NL_TEST_ASSERT(inSuite, operationalState.operationalStateLabel.Value().size() == sizeof(buffer)); - NL_TEST_ASSERT(inSuite, - memcmp(const_cast(operationalState.operationalStateLabel.Value().data()), buffer, sizeof(buffer)) == 0); + EXPECT_EQ(operationalState.operationalStateID, to_underlying(ManufactureOperationalStateEnum::kRebooting)); + EXPECT_TRUE(operationalState.operationalStateLabel.HasValue()); + EXPECT_EQ(operationalState.operationalStateLabel.Value().size(), sizeof(buffer)); + EXPECT_EQ(memcmp(const_cast(operationalState.operationalStateLabel.Value().data()), buffer, sizeof(buffer)), 0); // change state with label, label len larger than kOperationalStateLabelMaxSize char buffer2[kOperationalStateLabelMaxSize + 1]; @@ -178,51 +177,47 @@ void TestStructGenericOperationalStateFuncSet(nlTestSuite * inSuite, void * inCo } operationalState.Set(to_underlying(ManufactureOperationalStateEnum::kRebooting), Optional(CharSpan(buffer2, sizeof(buffer2)))); - NL_TEST_ASSERT(inSuite, operationalState.operationalStateID == to_underlying(ManufactureOperationalStateEnum::kRebooting)); - NL_TEST_ASSERT(inSuite, operationalState.operationalStateLabel.HasValue() == true); - NL_TEST_ASSERT(inSuite, operationalState.operationalStateLabel.Value().size() == kOperationalStateLabelMaxSize); - NL_TEST_ASSERT(inSuite, - memcmp(const_cast(operationalState.operationalStateLabel.Value().data()), buffer2, - kOperationalStateLabelMaxSize) == 0); + EXPECT_EQ(operationalState.operationalStateID, to_underlying(ManufactureOperationalStateEnum::kRebooting)); + EXPECT_TRUE(operationalState.operationalStateLabel.HasValue()); + EXPECT_EQ(operationalState.operationalStateLabel.Value().size(), kOperationalStateLabelMaxSize); + EXPECT_EQ( + memcmp(const_cast(operationalState.operationalStateLabel.Value().data()), buffer2, kOperationalStateLabelMaxSize), + 0); } -void TestStructGenericOperationalErrorConstructorWithOnlyStateID(nlTestSuite * inSuite, void * inContext) +TEST_F(TestOperationalStateClusterObjects, TestStructGenericOperationalErrorConstructorWithOnlyStateID) { using namespace chip::app::Clusters::OperationalState; // General errors: NoError GenericOperationalError operationalErrorNoErr(to_underlying(ErrorStateEnum::kNoError)); - NL_TEST_ASSERT(inSuite, operationalErrorNoErr.errorStateID == to_underlying(ErrorStateEnum::kNoError)); - NL_TEST_ASSERT(inSuite, operationalErrorNoErr.errorStateLabel.HasValue() == false); - NL_TEST_ASSERT(inSuite, operationalErrorNoErr.errorStateDetails.HasValue() == false); + EXPECT_EQ(operationalErrorNoErr.errorStateID, to_underlying(ErrorStateEnum::kNoError)); + EXPECT_FALSE(operationalErrorNoErr.errorStateLabel.HasValue()); + EXPECT_FALSE(operationalErrorNoErr.errorStateDetails.HasValue()); // General errors: UnableToStartOrResume GenericOperationalError operationalErrorUnableToStartOrResume(to_underlying(ErrorStateEnum::kUnableToStartOrResume)); - NL_TEST_ASSERT(inSuite, - operationalErrorUnableToStartOrResume.errorStateID == to_underlying(ErrorStateEnum::kUnableToStartOrResume)); - NL_TEST_ASSERT(inSuite, operationalErrorUnableToStartOrResume.errorStateLabel.HasValue() == false); - NL_TEST_ASSERT(inSuite, operationalErrorUnableToStartOrResume.errorStateDetails.HasValue() == false); + EXPECT_EQ(operationalErrorUnableToStartOrResume.errorStateID, to_underlying(ErrorStateEnum::kUnableToStartOrResume)); + EXPECT_FALSE(operationalErrorUnableToStartOrResume.errorStateLabel.HasValue()); + EXPECT_FALSE(operationalErrorUnableToStartOrResume.errorStateDetails.HasValue()); // General errors: UnableToCompleteOperation GenericOperationalError operationalErrorkUnableToCompleteOperation(to_underlying(ErrorStateEnum::kUnableToCompleteOperation)); - NL_TEST_ASSERT(inSuite, - operationalErrorkUnableToCompleteOperation.errorStateID == - to_underlying(ErrorStateEnum::kUnableToCompleteOperation)); - NL_TEST_ASSERT(inSuite, operationalErrorkUnableToCompleteOperation.errorStateLabel.HasValue() == false); - NL_TEST_ASSERT(inSuite, operationalErrorkUnableToCompleteOperation.errorStateDetails.HasValue() == false); + EXPECT_EQ(operationalErrorkUnableToCompleteOperation.errorStateID, to_underlying(ErrorStateEnum::kUnableToCompleteOperation)); + EXPECT_FALSE(operationalErrorkUnableToCompleteOperation.errorStateLabel.HasValue()); + EXPECT_FALSE(operationalErrorkUnableToCompleteOperation.errorStateDetails.HasValue()); // General errors: CommandInvalidInState GenericOperationalError operationalErrorCommandInvalidInState(to_underlying(ErrorStateEnum::kCommandInvalidInState)); - NL_TEST_ASSERT(inSuite, - operationalErrorCommandInvalidInState.errorStateID == to_underlying(ErrorStateEnum::kCommandInvalidInState)); - NL_TEST_ASSERT(inSuite, operationalErrorCommandInvalidInState.errorStateLabel.HasValue() == false); - NL_TEST_ASSERT(inSuite, operationalErrorCommandInvalidInState.errorStateDetails.HasValue() == false); + EXPECT_EQ(operationalErrorCommandInvalidInState.errorStateID, to_underlying(ErrorStateEnum::kCommandInvalidInState)); + EXPECT_FALSE(operationalErrorCommandInvalidInState.errorStateLabel.HasValue()); + EXPECT_FALSE(operationalErrorCommandInvalidInState.errorStateDetails.HasValue()); } -void TestStructGenericOperationalErrorConstructorWithStateIDAndStateLabel(nlTestSuite * inSuite, void * inContext) +TEST_F(TestOperationalStateClusterObjects, TestStructGenericOperationalErrorConstructorWithStateIDAndStateLabel) { using namespace chip::app::Clusters::OperationalState; @@ -237,16 +232,14 @@ void TestStructGenericOperationalErrorConstructorWithStateIDAndStateLabel(nlTest GenericOperationalError operationalError(to_underlying(ManufactureOperationalErrorEnum::kLowBattery), Optional(CharSpan::fromCharString(labelBuffer))); - NL_TEST_ASSERT(inSuite, operationalError.errorStateID == to_underlying(ManufactureOperationalErrorEnum::kLowBattery)); - NL_TEST_ASSERT(inSuite, operationalError.errorStateLabel.HasValue() == true); - NL_TEST_ASSERT(inSuite, operationalError.errorStateLabel.Value().size() == strlen(labelBuffer)); - NL_TEST_ASSERT(inSuite, - memcmp(const_cast(operationalError.errorStateLabel.Value().data()), labelBuffer, strlen(labelBuffer)) == - 0); - NL_TEST_ASSERT(inSuite, operationalError.errorStateDetails.HasValue() == false); + EXPECT_EQ(operationalError.errorStateID, to_underlying(ManufactureOperationalErrorEnum::kLowBattery)); + EXPECT_TRUE(operationalError.errorStateLabel.HasValue()); + EXPECT_EQ(operationalError.errorStateLabel.Value().size(), strlen(labelBuffer)); + EXPECT_EQ(memcmp(const_cast(operationalError.errorStateLabel.Value().data()), labelBuffer, strlen(labelBuffer)), 0); + EXPECT_FALSE(operationalError.errorStateDetails.HasValue()); } -void TestStructGenericOperationalErrorConstructorWithFullParam(nlTestSuite * inSuite, void * inContext) +TEST_F(TestOperationalStateClusterObjects, TestStructGenericOperationalErrorConstructorWithFullParam) { using namespace chip::app::Clusters::OperationalState; @@ -263,21 +256,17 @@ void TestStructGenericOperationalErrorConstructorWithFullParam(nlTestSuite * inS Optional(CharSpan::fromCharString(labelBuffer)), Optional(CharSpan::fromCharString(detailBuffer))); - NL_TEST_ASSERT(inSuite, operationalError.errorStateID == to_underlying(ManufactureOperationalErrorEnum::kLowBattery)); - NL_TEST_ASSERT(inSuite, operationalError.errorStateLabel.HasValue() == true); - NL_TEST_ASSERT(inSuite, operationalError.errorStateLabel.Value().size() == strlen(labelBuffer)); - NL_TEST_ASSERT(inSuite, - memcmp(const_cast(operationalError.errorStateLabel.Value().data()), labelBuffer, strlen(labelBuffer)) == - 0); - - NL_TEST_ASSERT(inSuite, operationalError.errorStateDetails.HasValue() == true); - NL_TEST_ASSERT(inSuite, operationalError.errorStateDetails.Value().size() == strlen(detailBuffer)); - NL_TEST_ASSERT( - inSuite, - memcmp(const_cast(operationalError.errorStateDetails.Value().data()), detailBuffer, strlen(detailBuffer)) == 0); + EXPECT_EQ(operationalError.errorStateID, to_underlying(ManufactureOperationalErrorEnum::kLowBattery)); + EXPECT_TRUE(operationalError.errorStateLabel.HasValue()); + EXPECT_EQ(operationalError.errorStateLabel.Value().size(), strlen(labelBuffer)); + EXPECT_EQ(memcmp(const_cast(operationalError.errorStateLabel.Value().data()), labelBuffer, strlen(labelBuffer)), 0); + + EXPECT_TRUE(operationalError.errorStateDetails.HasValue()); + EXPECT_EQ(operationalError.errorStateDetails.Value().size(), strlen(detailBuffer)); + EXPECT_EQ(memcmp(const_cast(operationalError.errorStateDetails.Value().data()), detailBuffer, strlen(detailBuffer)), 0); } -void TestStructGenericOperationalErrorCopyConstructor(nlTestSuite * inSuite, void * inContext) +TEST_F(TestOperationalStateClusterObjects, TestStructGenericOperationalErrorCopyConstructor) { using namespace chip::app::Clusters::OperationalState; @@ -296,25 +285,23 @@ void TestStructGenericOperationalErrorCopyConstructor(nlTestSuite * inSuite, voi // call copy constructor GenericOperationalError desOperationalError(srcOperationalError); - NL_TEST_ASSERT(inSuite, desOperationalError.errorStateID == srcOperationalError.errorStateID); - NL_TEST_ASSERT(inSuite, desOperationalError.errorStateLabel.HasValue() == true); - NL_TEST_ASSERT(inSuite, - desOperationalError.errorStateLabel.Value().size() == srcOperationalError.errorStateLabel.Value().size()); - NL_TEST_ASSERT(inSuite, - memcmp(const_cast(desOperationalError.errorStateLabel.Value().data()), - const_cast(srcOperationalError.errorStateLabel.Value().data()), - desOperationalError.errorStateLabel.Value().size()) == 0); - - NL_TEST_ASSERT(inSuite, desOperationalError.errorStateDetails.HasValue() == true); - NL_TEST_ASSERT(inSuite, - desOperationalError.errorStateDetails.Value().size() == srcOperationalError.errorStateDetails.Value().size()); - NL_TEST_ASSERT(inSuite, - memcmp(const_cast(desOperationalError.errorStateDetails.Value().data()), - const_cast(srcOperationalError.errorStateDetails.Value().data()), - desOperationalError.errorStateDetails.Value().size()) == 0); + EXPECT_EQ(desOperationalError.errorStateID, srcOperationalError.errorStateID); + EXPECT_TRUE(desOperationalError.errorStateLabel.HasValue()); + EXPECT_EQ(desOperationalError.errorStateLabel.Value().size(), srcOperationalError.errorStateLabel.Value().size()); + EXPECT_EQ(memcmp(const_cast(desOperationalError.errorStateLabel.Value().data()), + const_cast(srcOperationalError.errorStateLabel.Value().data()), + desOperationalError.errorStateLabel.Value().size()), + 0); + + EXPECT_TRUE(desOperationalError.errorStateDetails.HasValue()); + EXPECT_EQ(desOperationalError.errorStateDetails.Value().size(), srcOperationalError.errorStateDetails.Value().size()); + EXPECT_EQ(memcmp(const_cast(desOperationalError.errorStateDetails.Value().data()), + const_cast(srcOperationalError.errorStateDetails.Value().data()), + desOperationalError.errorStateDetails.Value().size()), + 0); } -void TestStructGenericOperationalErrorCopyAssignment(nlTestSuite * inSuite, void * inContext) +TEST_F(TestOperationalStateClusterObjects, TestStructGenericOperationalErrorCopyAssignment) { using namespace chip::app::Clusters::OperationalState; @@ -333,25 +320,23 @@ void TestStructGenericOperationalErrorCopyAssignment(nlTestSuite * inSuite, void // call copy assignment GenericOperationalError desOperationalError = srcOperationalError; - NL_TEST_ASSERT(inSuite, desOperationalError.errorStateID == srcOperationalError.errorStateID); - NL_TEST_ASSERT(inSuite, desOperationalError.errorStateLabel.HasValue() == true); - NL_TEST_ASSERT(inSuite, - desOperationalError.errorStateLabel.Value().size() == srcOperationalError.errorStateLabel.Value().size()); - NL_TEST_ASSERT(inSuite, - memcmp(const_cast(desOperationalError.errorStateLabel.Value().data()), - const_cast(srcOperationalError.errorStateLabel.Value().data()), - desOperationalError.errorStateLabel.Value().size()) == 0); - - NL_TEST_ASSERT(inSuite, desOperationalError.errorStateDetails.HasValue() == true); - NL_TEST_ASSERT(inSuite, - desOperationalError.errorStateDetails.Value().size() == srcOperationalError.errorStateDetails.Value().size()); - NL_TEST_ASSERT(inSuite, - memcmp(const_cast(desOperationalError.errorStateDetails.Value().data()), - const_cast(srcOperationalError.errorStateDetails.Value().data()), - desOperationalError.errorStateDetails.Value().size()) == 0); + EXPECT_EQ(desOperationalError.errorStateID, srcOperationalError.errorStateID); + EXPECT_TRUE(desOperationalError.errorStateLabel.HasValue()); + EXPECT_EQ(desOperationalError.errorStateLabel.Value().size(), srcOperationalError.errorStateLabel.Value().size()); + EXPECT_EQ(memcmp(const_cast(desOperationalError.errorStateLabel.Value().data()), + const_cast(srcOperationalError.errorStateLabel.Value().data()), + desOperationalError.errorStateLabel.Value().size()), + 0); + + EXPECT_TRUE(desOperationalError.errorStateDetails.HasValue()); + EXPECT_EQ(desOperationalError.errorStateDetails.Value().size(), srcOperationalError.errorStateDetails.Value().size()); + EXPECT_EQ(memcmp(const_cast(desOperationalError.errorStateDetails.Value().data()), + const_cast(srcOperationalError.errorStateDetails.Value().data()), + desOperationalError.errorStateDetails.Value().size()), + 0); } -void TestStructGenericOperationalErrorFuncSet(nlTestSuite * inSuite, void * inContext) +TEST_F(TestOperationalStateClusterObjects, TestStructGenericOperationalErrorFuncSet) { using namespace chip::app::Clusters::OperationalState; enum class ManufactureOperationalErrorEnum : uint8_t @@ -366,46 +351,40 @@ void TestStructGenericOperationalErrorFuncSet(nlTestSuite * inSuite, void * inCo // General errors: NoError GenericOperationalError operationalError(to_underlying(ErrorStateEnum::kNoError)); - NL_TEST_ASSERT(inSuite, operationalError.errorStateID == to_underlying(ErrorStateEnum::kNoError)); - NL_TEST_ASSERT(inSuite, operationalError.errorStateLabel.HasValue() == false); - NL_TEST_ASSERT(inSuite, operationalError.errorStateDetails.HasValue() == false); + EXPECT_EQ(operationalError.errorStateID, to_underlying(ErrorStateEnum::kNoError)); + EXPECT_FALSE(operationalError.errorStateLabel.HasValue()); + EXPECT_FALSE(operationalError.errorStateDetails.HasValue()); // call Set with stateId operationalError.Set(to_underlying(ErrorStateEnum::kUnableToStartOrResume)); - NL_TEST_ASSERT(inSuite, operationalError.errorStateID == to_underlying(ErrorStateEnum::kUnableToStartOrResume)); - NL_TEST_ASSERT(inSuite, operationalError.errorStateLabel.HasValue() == false); - NL_TEST_ASSERT(inSuite, operationalError.errorStateDetails.HasValue() == false); + EXPECT_EQ(operationalError.errorStateID, to_underlying(ErrorStateEnum::kUnableToStartOrResume)); + EXPECT_FALSE(operationalError.errorStateLabel.HasValue()); + EXPECT_FALSE(operationalError.errorStateDetails.HasValue()); // call Set with stateId and StateLabel operationalError.Set(to_underlying(ErrorStateEnum::kUnableToStartOrResume), Optional(CharSpan::fromCharString(labelBuffer))); - NL_TEST_ASSERT(inSuite, operationalError.errorStateID == to_underlying(ErrorStateEnum::kUnableToStartOrResume)); - NL_TEST_ASSERT(inSuite, operationalError.errorStateLabel.HasValue() == true); - NL_TEST_ASSERT(inSuite, operationalError.errorStateLabel.Value().size() == strlen(labelBuffer)); - NL_TEST_ASSERT(inSuite, - memcmp(const_cast(operationalError.errorStateLabel.Value().data()), labelBuffer, strlen(labelBuffer)) == - 0); - NL_TEST_ASSERT(inSuite, operationalError.errorStateDetails.HasValue() == false); + EXPECT_EQ(operationalError.errorStateID, to_underlying(ErrorStateEnum::kUnableToStartOrResume)); + EXPECT_TRUE(operationalError.errorStateLabel.HasValue()); + EXPECT_EQ(operationalError.errorStateLabel.Value().size(), strlen(labelBuffer)); + EXPECT_EQ(memcmp(const_cast(operationalError.errorStateLabel.Value().data()), labelBuffer, strlen(labelBuffer)), 0); + EXPECT_FALSE(operationalError.errorStateDetails.HasValue()); // call Set with stateId, StateLabel and StateDetails operationalError.Set(to_underlying(ErrorStateEnum::kUnableToStartOrResume), Optional(CharSpan::fromCharString(labelBuffer)), Optional(CharSpan::fromCharString(detailBuffer))); - NL_TEST_ASSERT(inSuite, operationalError.errorStateID == to_underlying(ErrorStateEnum::kUnableToStartOrResume)); - NL_TEST_ASSERT(inSuite, operationalError.errorStateLabel.HasValue() == true); - NL_TEST_ASSERT(inSuite, operationalError.errorStateLabel.Value().size() == strlen(labelBuffer)); - NL_TEST_ASSERT(inSuite, - memcmp(const_cast(operationalError.errorStateLabel.Value().data()), labelBuffer, strlen(labelBuffer)) == - 0); + EXPECT_EQ(operationalError.errorStateID, to_underlying(ErrorStateEnum::kUnableToStartOrResume)); + EXPECT_TRUE(operationalError.errorStateLabel.HasValue()); + EXPECT_EQ(operationalError.errorStateLabel.Value().size(), strlen(labelBuffer)); + EXPECT_EQ(memcmp(const_cast(operationalError.errorStateLabel.Value().data()), labelBuffer, strlen(labelBuffer)), 0); - NL_TEST_ASSERT(inSuite, operationalError.errorStateDetails.HasValue() == true); - NL_TEST_ASSERT(inSuite, operationalError.errorStateDetails.Value().size() == strlen(detailBuffer)); - NL_TEST_ASSERT( - inSuite, - memcmp(const_cast(operationalError.errorStateDetails.Value().data()), detailBuffer, strlen(detailBuffer)) == 0); + EXPECT_TRUE(operationalError.errorStateDetails.HasValue()); + EXPECT_EQ(operationalError.errorStateDetails.Value().size(), strlen(detailBuffer)); + EXPECT_EQ(memcmp(const_cast(operationalError.errorStateDetails.Value().data()), detailBuffer, strlen(detailBuffer)), 0); // change state with label, label len = kOperationalStateLabelMaxSize for (size_t i = 0; i < sizeof(labelBuffer); i++) @@ -415,13 +394,11 @@ void TestStructGenericOperationalErrorFuncSet(nlTestSuite * inSuite, void * inCo operationalError.Set(to_underlying(ErrorStateEnum::kUnableToStartOrResume), Optional(CharSpan(labelBuffer, sizeof(labelBuffer)))); - NL_TEST_ASSERT(inSuite, operationalError.errorStateID == to_underlying(ErrorStateEnum::kUnableToStartOrResume)); - NL_TEST_ASSERT(inSuite, operationalError.errorStateLabel.HasValue() == true); - NL_TEST_ASSERT(inSuite, operationalError.errorStateLabel.Value().size() == sizeof(labelBuffer)); - NL_TEST_ASSERT(inSuite, - memcmp(const_cast(operationalError.errorStateLabel.Value().data()), labelBuffer, sizeof(labelBuffer)) == - 0); - NL_TEST_ASSERT(inSuite, operationalError.errorStateDetails.HasValue() == false); + EXPECT_EQ(operationalError.errorStateID, to_underlying(ErrorStateEnum::kUnableToStartOrResume)); + EXPECT_TRUE(operationalError.errorStateLabel.HasValue()); + EXPECT_EQ(operationalError.errorStateLabel.Value().size(), sizeof(labelBuffer)); + EXPECT_EQ(memcmp(const_cast(operationalError.errorStateLabel.Value().data()), labelBuffer, sizeof(labelBuffer)), 0); + EXPECT_FALSE(operationalError.errorStateDetails.HasValue()); // change state with label, label len = kOperationalStateLabelMaxSize + 1 char labelBuffer2[kOperationalErrorLabelMaxSize + 1]; @@ -432,13 +409,13 @@ void TestStructGenericOperationalErrorFuncSet(nlTestSuite * inSuite, void * inCo operationalError.Set(to_underlying(ErrorStateEnum::kUnableToStartOrResume), Optional(CharSpan(labelBuffer2, sizeof(labelBuffer2)))); - NL_TEST_ASSERT(inSuite, operationalError.errorStateID == to_underlying(ErrorStateEnum::kUnableToStartOrResume)); - NL_TEST_ASSERT(inSuite, operationalError.errorStateLabel.HasValue() == true); - NL_TEST_ASSERT(inSuite, operationalError.errorStateLabel.Value().size() == kOperationalErrorLabelMaxSize); - NL_TEST_ASSERT(inSuite, - memcmp(const_cast(operationalError.errorStateLabel.Value().data()), labelBuffer2, - kOperationalErrorLabelMaxSize) == 0); - NL_TEST_ASSERT(inSuite, operationalError.errorStateDetails.HasValue() == false); + EXPECT_EQ(operationalError.errorStateID, to_underlying(ErrorStateEnum::kUnableToStartOrResume)); + EXPECT_TRUE(operationalError.errorStateLabel.HasValue()); + EXPECT_EQ(operationalError.errorStateLabel.Value().size(), kOperationalErrorLabelMaxSize); + EXPECT_EQ( + memcmp(const_cast(operationalError.errorStateLabel.Value().data()), labelBuffer2, kOperationalErrorLabelMaxSize), + 0); + EXPECT_FALSE(operationalError.errorStateDetails.HasValue()); // change state with label and details, details len = kOperationalErrorDetailsMaxSize + 1 char detailBuffer2[kOperationalErrorDetailsMaxSize + 1]; @@ -450,62 +427,19 @@ void TestStructGenericOperationalErrorFuncSet(nlTestSuite * inSuite, void * inCo Optional(CharSpan(labelBuffer2, sizeof(labelBuffer2))), Optional(CharSpan(detailBuffer2, sizeof(detailBuffer2)))); - NL_TEST_ASSERT(inSuite, operationalError.errorStateID == to_underlying(ErrorStateEnum::kUnableToStartOrResume)); - NL_TEST_ASSERT(inSuite, operationalError.errorStateLabel.HasValue() == true); - NL_TEST_ASSERT(inSuite, operationalError.errorStateLabel.Value().size() == kOperationalErrorLabelMaxSize); - NL_TEST_ASSERT(inSuite, - memcmp(const_cast(operationalError.errorStateLabel.Value().data()), labelBuffer2, - kOperationalErrorLabelMaxSize) == 0); - - NL_TEST_ASSERT(inSuite, operationalError.errorStateDetails.HasValue() == true); - - NL_TEST_ASSERT(inSuite, operationalError.errorStateDetails.Value().size() == kOperationalErrorDetailsMaxSize); - NL_TEST_ASSERT(inSuite, - memcmp(const_cast(operationalError.errorStateDetails.Value().data()), detailBuffer2, - kOperationalErrorDetailsMaxSize) == 0); -} - -const nlTest sTests[] = { - NL_TEST_DEF("Test struct GenericOperationalState: constructor with only StateID", - TestStructGenericOperationalStateConstructorWithOnlyStateID), - NL_TEST_DEF("Test struct GenericOperationalState: constructor with StateID and StateLabel", - TestStructGenericOperationalStateConstructorWithStateIDAndStateLabel), - NL_TEST_DEF("Test struct GenericOperationalState: copy constructor", TestStructGenericOperationalStateCopyConstructor), - NL_TEST_DEF("Test struct GenericOperationalState: copy assignment", TestStructGenericOperationalStateCopyAssignment), - NL_TEST_DEF("Test struct GenericOperationalState: member function 'Set'", TestStructGenericOperationalStateFuncSet), - NL_TEST_DEF("Test struct GenericOperationalError: constructor with only StateID", - TestStructGenericOperationalErrorConstructorWithOnlyStateID), - NL_TEST_DEF("Test struct GenericOperationalError: constructor with StateID and StateLabel", - TestStructGenericOperationalErrorConstructorWithStateIDAndStateLabel), - NL_TEST_DEF("Test struct GenericOperationalError: constructor with StateID, StateLabel and StateDetail", - TestStructGenericOperationalErrorConstructorWithFullParam), - NL_TEST_DEF("Test struct GenericOperationalError: copy constructor", TestStructGenericOperationalErrorCopyConstructor), - NL_TEST_DEF("Test struct GenericOperationalError: copy assignment", TestStructGenericOperationalErrorCopyAssignment), - NL_TEST_DEF("Test struct GenericOperationalError: member function 'Set'", TestStructGenericOperationalErrorFuncSet), - NL_TEST_SENTINEL() -}; + EXPECT_EQ(operationalError.errorStateID, to_underlying(ErrorStateEnum::kUnableToStartOrResume)); + EXPECT_TRUE(operationalError.errorStateLabel.HasValue()); + EXPECT_EQ(operationalError.errorStateLabel.Value().size(), kOperationalErrorLabelMaxSize); + EXPECT_EQ( + memcmp(const_cast(operationalError.errorStateLabel.Value().data()), labelBuffer2, kOperationalErrorLabelMaxSize), + 0); -int TestSetup(void * inContext) -{ - VerifyOrReturnError(CHIP_NO_ERROR == chip::Platform::MemoryInit(), FAILURE); - return SUCCESS; -} + EXPECT_TRUE(operationalError.errorStateDetails.HasValue()); -int TestTearDown(void * inContext) -{ - chip::Platform::MemoryShutdown(); - return SUCCESS; + EXPECT_EQ(operationalError.errorStateDetails.Value().size(), kOperationalErrorDetailsMaxSize); + EXPECT_EQ(memcmp(const_cast(operationalError.errorStateDetails.Value().data()), detailBuffer2, + kOperationalErrorDetailsMaxSize), + 0); } } // namespace - -int TestOperationalStateClusterObjects() -{ - nlTestSuite theSuite = { "Test Operational State Cluster Objects tests", &sTests[0], TestSetup, TestTearDown }; - - // Run test suite against one context. - nlTestRunner(&theSuite, nullptr); - return nlTestRunnerStats(&theSuite); -} - -CHIP_REGISTER_TEST_SUITE(TestOperationalStateClusterObjects) diff --git a/src/app/tests/TestPendingNotificationMap.cpp b/src/app/tests/TestPendingNotificationMap.cpp index 98e27cb5f7b45a..94089e372d367e 100644 --- a/src/app/tests/TestPendingNotificationMap.cpp +++ b/src/app/tests/TestPendingNotificationMap.cpp @@ -18,9 +18,9 @@ #include #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..556bf3d87e2b30 100644 --- a/src/app/tests/TestPendingResponseTrackerImpl.cpp +++ b/src/app/tests/TestPendingResponseTrackerImpl.cpp @@ -15,75 +15,76 @@ * limitations under the License. */ -#include -#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_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 +92,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) diff --git a/src/app/tests/TestPowerSourceCluster.cpp b/src/app/tests/TestPowerSourceCluster.cpp index 374b9619d38684..0ec0b6e14a801c 100644 --- a/src/app/tests/TestPowerSourceCluster.cpp +++ b/src/app/tests/TestPowerSourceCluster.cpp @@ -15,50 +15,39 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "lib/support/CHIPMem.h" #include #include +#include #include #include +#include #include #include #include #include -#include -#include #include #include -#include #include - -#include - -namespace { -chip::EndpointId numEndpoints = 0; -} -extern uint16_t emberAfGetClusterServerEndpointIndex(chip::EndpointId endpoint, chip::ClusterId cluster, - uint16_t fixedClusterServerEndpointCount) -{ - // Very simple mapping here, we're just going to return the endpoint that matches the given endpoint index because the test - // uses the endpoints in order. - if (endpoint >= numEndpoints) - { - return kEmberInvalidEndpointIndex; - } - return endpoint; -} +#include namespace chip { namespace app { -class TestPowerSourceCluster +class TestPowerSourceCluster : public ::testing::Test { public: - static void TestEndpointList(nlTestSuite * apSuite, void * apContext); + static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); } + static void TearDownTestSuite() + { + chip::app::Clusters::PowerSourceServer::Instance().Shutdown(); + chip::Platform::MemoryShutdown(); + } }; -std::vector ReadEndpointsThroughAttributeReader(nlTestSuite * apSuite, EndpointId endpoint) +std::vector ReadEndpointsThroughAttributeReader(EndpointId endpoint) { Clusters::PowerSourceAttrAccess & attrAccess = Clusters::TestOnlyGetPowerSourceAttrAccess(); CHIP_ERROR err = CHIP_NO_ERROR; @@ -85,7 +74,7 @@ std::vector ReadEndpointsThroughAttributeReader(nlTestSuite * apSuit err = attrAccess.Read(readPath, aEncoder); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); // Read out from the buffer. This comes back as a nested struct // AttributeReportIBs is a list of @@ -114,13 +103,13 @@ std::vector ReadEndpointsThroughAttributeReader(nlTestSuite * apSuit { attrDataReader.Next(); } - NL_TEST_ASSERT(apSuite, IsContextTag(attrDataReader.GetTag())); - NL_TEST_ASSERT(apSuite, TagNumFromTag(attrDataReader.GetTag()) == 2); + EXPECT_TRUE(IsContextTag(attrDataReader.GetTag())); + EXPECT_EQ(TagNumFromTag(attrDataReader.GetTag()), 2u); // OK, we should be in the right spot now, let's decode the list. Clusters::PowerSource::Attributes::EndpointList::TypeInfo::DecodableType list; err = list.Decode(attrDataReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); std::vector ret; auto iter = list.begin(); while (iter.Next()) @@ -130,7 +119,7 @@ std::vector ReadEndpointsThroughAttributeReader(nlTestSuite * apSuit return ret; } -void TestPowerSourceCluster::TestEndpointList(nlTestSuite * apSuite, void * apContext) +TEST_F(TestPowerSourceCluster, TestEndpointList) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -139,8 +128,8 @@ void TestPowerSourceCluster::TestEndpointList(nlTestSuite * apSuite, void * apCo // test that when we read everything we get an empty list as nothing has been set up yet for (EndpointId i = 0; i < 11; ++i) { - std::vector vec = ReadEndpointsThroughAttributeReader(apSuite, i); - NL_TEST_ASSERT(apSuite, vec.size() == 0); + std::vector vec = ReadEndpointsThroughAttributeReader(i); + EXPECT_EQ(vec.size(), 0u); } if (powerSourceServer.GetNumSupportedEndpointLists() < 2 || @@ -159,42 +148,42 @@ void TestPowerSourceCluster::TestEndpointList(nlTestSuite * apSuite, void * apCo // we checked earlier that this fit // This test just uses endpoints in order, so we want to set endpoints from - // 0 to numEndpoints - 1, and use this for overflow checking - numEndpoints = static_cast(powerSourceServer.GetNumSupportedEndpointLists()); + // 0 to chip::Test::numEndpoints - 1, and use this for overflow checking + chip::Test::numEndpoints = static_cast(powerSourceServer.GetNumSupportedEndpointLists()); // Endpoint 0 - list of 5 err = powerSourceServer.SetEndpointList(0, Span(list0)); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); const Span * readBack = powerSourceServer.GetEndpointList(0); - NL_TEST_EXIT_ON_FAILED_ASSERT(apSuite, readBack != nullptr); - NL_TEST_ASSERT(apSuite, readBack->size() == 5); + ASSERT_NE(readBack, nullptr); + EXPECT_EQ(readBack->size(), 5u); for (size_t i = 0; i < readBack->size(); ++i) { - NL_TEST_ASSERT(apSuite, readBack->data()[i] == list0[i]); + EXPECT_EQ(readBack->data()[i], list0[i]); } // Endpoint 1 - list of 10 err = powerSourceServer.SetEndpointList(1, Span(list1)); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); readBack = powerSourceServer.GetEndpointList(1); - NL_TEST_EXIT_ON_FAILED_ASSERT(apSuite, readBack != nullptr); - NL_TEST_ASSERT(apSuite, readBack->size() == 10); + ASSERT_NE(readBack, nullptr); + EXPECT_EQ(readBack->size(), 10u); for (size_t i = 0; i < readBack->size(); ++i) { - NL_TEST_ASSERT(apSuite, readBack->data()[i] == list1[i]); + EXPECT_EQ(readBack->data()[i], list1[i]); } // Remaining endpoints - list of 1 - for (EndpointId ep = 2; ep < numEndpoints; ++ep) + for (EndpointId ep = 2; ep < chip::Test::numEndpoints; ++ep) { err = powerSourceServer.SetEndpointList(ep, Span(listRest)); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); readBack = powerSourceServer.GetEndpointList(ep); - NL_TEST_EXIT_ON_FAILED_ASSERT(apSuite, readBack != nullptr); - NL_TEST_ASSERT(apSuite, readBack->size() == 1); + ASSERT_NE(readBack, nullptr); + EXPECT_EQ(readBack->size(), 1u); if (readBack->size() == 1) { - NL_TEST_ASSERT(apSuite, readBack->data()[0] == listRest[0]); + EXPECT_EQ(readBack->data()[0], listRest[0]); } } @@ -203,38 +192,38 @@ void TestPowerSourceCluster::TestEndpointList(nlTestSuite * apSuite, void * apCo // ***************** // pick a random endpoint number for the power cluster - it doesn't matter, we don't have space anyway. err = powerSourceServer.SetEndpointList(55, Span(listRest)); - NL_TEST_ASSERT(apSuite, err == CHIP_ERROR_NO_MEMORY); + EXPECT_EQ(err, CHIP_ERROR_NO_MEMORY); // ***************** // Recheck getting and reading after OOM // ***************** // EP0 readBack = powerSourceServer.GetEndpointList(0); - NL_TEST_EXIT_ON_FAILED_ASSERT(apSuite, readBack != nullptr); - NL_TEST_ASSERT(apSuite, readBack->size() == 5); + ASSERT_NE(readBack, nullptr); + EXPECT_EQ(readBack->size(), 5u); for (size_t i = 0; i < readBack->size(); ++i) { - NL_TEST_ASSERT(apSuite, readBack->data()[i] == list0[i]); + EXPECT_EQ(readBack->data()[i], list0[i]); } // EP1 readBack = powerSourceServer.GetEndpointList(1); - NL_TEST_EXIT_ON_FAILED_ASSERT(apSuite, readBack != nullptr); - NL_TEST_ASSERT(apSuite, readBack->size() == 10); + ASSERT_NE(readBack, nullptr); + EXPECT_EQ(readBack->size(), 10u); for (size_t i = 0; i < readBack->size(); ++i) { - NL_TEST_ASSERT(apSuite, readBack->data()[i] == list1[i]); + EXPECT_EQ(readBack->data()[i], list1[i]); } // Remaining endpoints - for (EndpointId ep = 2; ep < numEndpoints; ++ep) + for (EndpointId ep = 2; ep < chip::Test::numEndpoints; ++ep) { readBack = powerSourceServer.GetEndpointList(ep); - NL_TEST_EXIT_ON_FAILED_ASSERT(apSuite, readBack != nullptr); - NL_TEST_ASSERT(apSuite, readBack->size() == 1); + ASSERT_NE(readBack, nullptr); + EXPECT_EQ(readBack->size(), 1u); if (readBack->size() == 1) { - NL_TEST_ASSERT(apSuite, readBack->data()[0] == listRest[0]); + EXPECT_EQ(readBack->data()[0], listRest[0]); } } @@ -243,36 +232,36 @@ void TestPowerSourceCluster::TestEndpointList(nlTestSuite * apSuite, void * apCo // ***************** // Overwrite a list err = powerSourceServer.SetEndpointList(1, Span(listRest)); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); readBack = powerSourceServer.GetEndpointList(1); - NL_TEST_ASSERT(apSuite, readBack->size() == 1); + EXPECT_EQ(readBack->size(), 1u); if (readBack->size() == 1) { - NL_TEST_ASSERT(apSuite, readBack->data()[0] == listRest[0]); + EXPECT_EQ(readBack->data()[0], listRest[0]); } // Ensure only the overwritten list was changed, using read interface - for (EndpointId ep = 0; ep < numEndpoints + 1; ++ep) + for (EndpointId ep = 0; ep < chip::Test::numEndpoints + 1; ++ep) { - std::vector vec = ReadEndpointsThroughAttributeReader(apSuite, ep); + std::vector vec = ReadEndpointsThroughAttributeReader(ep); if (ep == 0) { - NL_TEST_ASSERT(apSuite, vec.size() == 5); + EXPECT_EQ(vec.size(), 5u); for (size_t j = 0; j < vec.size(); ++j) { - NL_TEST_ASSERT(apSuite, vec[j] == list0[j]); + EXPECT_EQ(vec[j], list0[j]); } } - else if (ep == numEndpoints) + else if (ep == chip::Test::numEndpoints) { - NL_TEST_ASSERT(apSuite, vec.size() == 0); + EXPECT_EQ(vec.size(), 0u); } else { - NL_TEST_ASSERT(apSuite, vec.size() == 1); + EXPECT_EQ(vec.size(), 1u); if (vec.size() == 1) { - NL_TEST_ASSERT(apSuite, vec[0] == listRest[0]); + EXPECT_EQ(vec[0], listRest[0]); } } } @@ -280,76 +269,21 @@ void TestPowerSourceCluster::TestEndpointList(nlTestSuite * apSuite, void * apCo // ***************** // Test removal // ***************** - for (EndpointId ep = 0; ep < numEndpoints; ++ep) + for (EndpointId ep = 0; ep < chip::Test::numEndpoints; ++ep) { err = powerSourceServer.SetEndpointList(ep, Span()); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); readBack = powerSourceServer.GetEndpointList(ep); - NL_TEST_ASSERT(apSuite, readBack == nullptr); + EXPECT_EQ(readBack, nullptr); } // Check through the read interface - for (EndpointId ep = 0; ep < numEndpoints + 1; ++ep) + for (EndpointId ep = 0; ep < chip::Test::numEndpoints + 1; ++ep) { - std::vector vec = ReadEndpointsThroughAttributeReader(apSuite, ep); - NL_TEST_ASSERT(apSuite, vec.size() == 0); + std::vector vec = ReadEndpointsThroughAttributeReader(ep); + EXPECT_EQ(vec.size(), 0u); } } } // namespace app } // namespace chip - -namespace { - -/** - * Test Suite. It lists all the test functions. - */ - -// clang-format off -const nlTest sTests[] = -{ - NL_TEST_DEF("TestEndpointList", chip::app::TestPowerSourceCluster::TestEndpointList), - NL_TEST_SENTINEL() -}; -// clang-format on - -/** - * Set up the test suite. - */ -int TestPowerSourceClusterContext_Setup(void * inContext) -{ - CHIP_ERROR error = chip::Platform::MemoryInit(); - if (error != CHIP_NO_ERROR) - return FAILURE; - return SUCCESS; -} - -/** - * Tear down the test suite. - */ -int TestPowerSourceClusterContext_Teardown(void * inContext) -{ - chip::app::Clusters::PowerSourceServer::Instance().Shutdown(); - chip::Platform::MemoryShutdown(); - return SUCCESS; -} - -// clang-format off -nlTestSuite sSuite = -{ - "TestPowerSourceCluster", - &sTests[0], - TestPowerSourceClusterContext_Setup, - TestPowerSourceClusterContext_Teardown -}; -// clang-format on - -} // namespace - -int TestPowerSource() -{ - nlTestRunner(&sSuite, nullptr); - return nlTestRunnerStats(&sSuite); -} - -CHIP_REGISTER_TEST_SUITE(TestPowerSource) diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index e06721806732f6..8d1d2e686896fa 100644 --- a/src/app/tests/TestReadInteraction.cpp +++ b/src/app/tests/TestReadInteraction.cpp @@ -22,6 +22,8 @@ * */ +#include "app/tests/test-interaction-model-api.h" + #include "lib/support/CHIPMem.h" #include #include @@ -61,7 +63,6 @@ chip::EndpointId kTestEndpointId = 1; chip::EndpointId kTestEventEndpointId = chip::Test::kMockEndpoint1; chip::EventId kTestEventIdDebug = chip::Test::MockEventId(1); chip::EventId kTestEventIdCritical = chip::Test::MockEventId(2); -uint8_t kTestFieldValue1 = 1; chip::TLV::Tag kTestEventTag = chip::TLV::ContextTag(1); chip::EndpointId kInvalidTestEndpointId = 3; chip::DataVersion kTestDataVersion1 = 3; @@ -301,54 +302,6 @@ using ReadHandlerNode = chip::app::reporting::ReportScheduler::ReadHandlerNo namespace chip { namespace app { -CHIP_ERROR ReadSingleClusterData(const Access::SubjectDescriptor & aSubjectDescriptor, bool aIsFabricFiltered, - const ConcreteReadAttributePath & aPath, AttributeReportIBs::Builder & aAttributeReports, - AttributeEncodeState * apEncoderState) -{ - if (aPath.mClusterId >= Test::kMockEndpointMin) - { - return Test::ReadSingleMockClusterData(aSubjectDescriptor.fabricIndex, aPath, aAttributeReports, apEncoderState); - } - - if (!(aPath.mClusterId == kTestClusterId && aPath.mEndpointId == kTestEndpointId)) - { - AttributeReportIB::Builder & attributeReport = aAttributeReports.CreateAttributeReport(); - ReturnErrorOnFailure(aAttributeReports.GetError()); - ChipLogDetail(DataManagement, "TEST Cluster %" PRIx32 ", Field %" PRIx32 " is dirty", aPath.mClusterId, aPath.mAttributeId); - - AttributeStatusIB::Builder & attributeStatus = attributeReport.CreateAttributeStatus(); - ReturnErrorOnFailure(attributeReport.GetError()); - AttributePathIB::Builder & attributePath = attributeStatus.CreatePath(); - ReturnErrorOnFailure(attributeStatus.GetError()); - - attributePath.Endpoint(aPath.mEndpointId).Cluster(aPath.mClusterId).Attribute(aPath.mAttributeId).EndOfAttributePathIB(); - ReturnErrorOnFailure(attributePath.GetError()); - StatusIB::Builder & errorStatus = attributeStatus.CreateErrorStatus(); - ReturnErrorOnFailure(attributeStatus.GetError()); - errorStatus.EncodeStatusIB(StatusIB(Protocols::InteractionModel::Status::UnsupportedAttribute)); - ReturnErrorOnFailure(errorStatus.GetError()); - ReturnErrorOnFailure(attributeStatus.EndOfAttributeStatusIB()); - return attributeReport.EndOfAttributeReportIB(); - } - - return AttributeValueEncoder(aAttributeReports, aSubjectDescriptor, aPath, 0 /* dataVersion */).Encode(kTestFieldValue1); -} - -bool IsClusterDataVersionEqual(const ConcreteClusterPath & aConcreteClusterPath, DataVersion aRequiredVersion) -{ - if (kTestDataVersion1 == aRequiredVersion) - { - return true; - } - - return false; -} - -bool IsDeviceTypeOnEndpoint(DeviceTypeId deviceType, EndpointId endpoint) -{ - return false; -} - class TestReadInteraction { using Seconds16 = System::Clock::Seconds16; diff --git a/src/app/tests/TestSimpleSubscriptionResumptionStorage.cpp b/src/app/tests/TestSimpleSubscriptionResumptionStorage.cpp index 8725acd755afd9..9f9b164e87cc07 100644 --- a/src/app/tests/TestSimpleSubscriptionResumptionStorage.cpp +++ b/src/app/tests/TestSimpleSubscriptionResumptionStorage.cpp @@ -15,13 +15,18 @@ * limitations under the License. */ -#include -#include - #include +#include +#include #include +#include -#include +class TestSimpleSubscriptionResumptionStorage : public ::testing::Test +{ +public: + static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); } + static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); } +}; class SimpleSubscriptionResumptionStorageTest : public chip::app::SimpleSubscriptionResumptionStorage { @@ -71,7 +76,7 @@ struct TestSubscriptionInfo : public chip::app::SubscriptionResumptionStorage::S } }; -void TestSubscriptionCount(nlTestSuite * inSuite, void * inContext) +TEST_F(TestSimpleSubscriptionResumptionStorage, TestSubscriptionCount) { chip::TestPersistentStorageDelegate storage; SimpleSubscriptionResumptionStorageTest subscriptionStorage; @@ -88,7 +93,7 @@ void TestSubscriptionCount(nlTestSuite * inSuite, void * inContext) // Make sure iterator counts correctly auto * iterator = subscriptionStorage.IterateSubscriptions(); - NL_TEST_ASSERT(inSuite, iterator->Count() == (CHIP_IM_MAX_NUM_SUBSCRIPTIONS / 2)); + EXPECT_EQ(iterator->Count(), std::make_unsigned_t(CHIP_IM_MAX_NUM_SUBSCRIPTIONS / 2)); // Verify subscriptions manually count correctly size_t count = 0; @@ -97,13 +102,13 @@ void TestSubscriptionCount(nlTestSuite * inSuite, void * inContext) count++; } iterator->Release(); - NL_TEST_ASSERT(inSuite, count == (CHIP_IM_MAX_NUM_SUBSCRIPTIONS / 2)); + EXPECT_EQ(count, std::make_unsigned_t(CHIP_IM_MAX_NUM_SUBSCRIPTIONS / 2)); // Delete all and verify iterator counts 0 CHIP_ERROR err = subscriptionStorage.DeleteAll(46); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); iterator = subscriptionStorage.IterateSubscriptions(); - NL_TEST_ASSERT(inSuite, iterator->Count() == 0); + EXPECT_EQ(iterator->Count(), 0u); // Verify subscriptions manually count correctly count = 0; @@ -112,10 +117,10 @@ void TestSubscriptionCount(nlTestSuite * inSuite, void * inContext) count++; } iterator->Release(); - NL_TEST_ASSERT(inSuite, count == 0); + EXPECT_EQ(count, 0u); } -void TestSubscriptionMaxCount(nlTestSuite * inSuite, void * inContext) +TEST_F(TestSimpleSubscriptionResumptionStorage, TestSubscriptionMaxCount) { // Force large MacCount value and check that Init resets it properly, and deletes extra subs: @@ -126,16 +131,16 @@ void TestSubscriptionMaxCount(nlTestSuite * inSuite, void * inContext) uint16_t countMaxToSave = 2 * CHIP_IM_MAX_NUM_SUBSCRIPTIONS; CHIP_ERROR err = storage.SyncSetKeyValue(chip::DefaultStorageKeyAllocator::SubscriptionResumptionMaxCount().KeyName(), &countMaxToSave, sizeof(uint16_t)); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); // Then write something beyond CHIP_IM_MAX_NUM_SUBSCRIPTIONS chip::Platform::ScopedMemoryBuffer junkBytes; junkBytes.Calloc(subscriptionStorage.TestMaxSubscriptionSize() / 2); - NL_TEST_ASSERT(inSuite, junkBytes.Get() != nullptr); - NL_TEST_ASSERT(inSuite, - storage.SyncSetKeyValue( - chip::DefaultStorageKeyAllocator::SubscriptionResumption(CHIP_IM_MAX_NUM_SUBSCRIPTIONS + 1).KeyName(), - junkBytes.Get(), static_cast(subscriptionStorage.TestMaxSubscriptionSize() / 2)) == CHIP_NO_ERROR); + ASSERT_NE(junkBytes.Get(), nullptr); + EXPECT_EQ(storage.SyncSetKeyValue( + chip::DefaultStorageKeyAllocator::SubscriptionResumption(CHIP_IM_MAX_NUM_SUBSCRIPTIONS + 1).KeyName(), + junkBytes.Get(), static_cast(subscriptionStorage.TestMaxSubscriptionSize() / 2)), + CHIP_NO_ERROR); subscriptionStorage.Init(&storage); @@ -143,16 +148,15 @@ void TestSubscriptionMaxCount(nlTestSuite * inSuite, void * inContext) uint16_t countMax = 0; uint16_t len = sizeof(countMax); err = storage.SyncGetKeyValue(chip::DefaultStorageKeyAllocator::SubscriptionResumptionMaxCount().KeyName(), &countMax, len); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, countMax == CHIP_IM_MAX_NUM_SUBSCRIPTIONS); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(countMax, CHIP_IM_MAX_NUM_SUBSCRIPTIONS); // Then check the fake sub is no more - NL_TEST_ASSERT(inSuite, - !storage.SyncDoesKeyExist( - chip::DefaultStorageKeyAllocator::SubscriptionResumption(CHIP_IM_MAX_NUM_SUBSCRIPTIONS + 1).KeyName())); + EXPECT_FALSE(storage.SyncDoesKeyExist( + chip::DefaultStorageKeyAllocator::SubscriptionResumption(CHIP_IM_MAX_NUM_SUBSCRIPTIONS + 1).KeyName())); } -void TestSubscriptionState(nlTestSuite * inSuite, void * inContext) +TEST_F(TestSimpleSubscriptionResumptionStorage, TestSubscriptionState) { chip::TestPersistentStorageDelegate storage; SimpleSubscriptionResumptionStorageTest subscriptionStorage; @@ -219,25 +223,25 @@ void TestSubscriptionState(nlTestSuite * inSuite, void * inContext) CHIP_ERROR err; err = subscriptionStorage.Save(subscriptionInfo1); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = subscriptionStorage.Save(subscriptionInfo2); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = subscriptionStorage.Save(subscriptionInfo3); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); auto * iterator = subscriptionStorage.IterateSubscriptions(); - NL_TEST_ASSERT(inSuite, iterator->Count() == 3); + EXPECT_EQ(iterator->Count(), 3u); // Verify subscriptions manually count correctly TestSubscriptionInfo subscriptionInfo; - NL_TEST_ASSERT(inSuite, iterator->Next(subscriptionInfo)); - NL_TEST_ASSERT(inSuite, subscriptionInfo == subscriptionInfo1); - NL_TEST_ASSERT(inSuite, iterator->Next(subscriptionInfo)); - NL_TEST_ASSERT(inSuite, subscriptionInfo == subscriptionInfo2); - NL_TEST_ASSERT(inSuite, iterator->Next(subscriptionInfo)); - NL_TEST_ASSERT(inSuite, subscriptionInfo == subscriptionInfo3); + EXPECT_TRUE(iterator->Next(subscriptionInfo)); + EXPECT_EQ(subscriptionInfo, subscriptionInfo1); + EXPECT_TRUE(iterator->Next(subscriptionInfo)); + EXPECT_EQ(subscriptionInfo, subscriptionInfo2); + EXPECT_TRUE(iterator->Next(subscriptionInfo)); + EXPECT_EQ(subscriptionInfo, subscriptionInfo3); // Verify at end of list - NL_TEST_ASSERT(inSuite, !iterator->Next(subscriptionInfo)); + EXPECT_FALSE(iterator->Next(subscriptionInfo)); iterator->Release(); // Delete fabric 1 and subscription 2 and check only 3 remains. @@ -245,30 +249,30 @@ void TestSubscriptionState(nlTestSuite * inSuite, void * inContext) subscriptionStorage.DeleteAll(subscriptionInfo2.mFabricIndex); iterator = subscriptionStorage.IterateSubscriptions(); - NL_TEST_ASSERT(inSuite, iterator->Count() == 1); - NL_TEST_ASSERT(inSuite, iterator->Next(subscriptionInfo)); - NL_TEST_ASSERT(inSuite, subscriptionInfo == subscriptionInfo3); + EXPECT_EQ(iterator->Count(), 1u); + EXPECT_TRUE(iterator->Next(subscriptionInfo)); + EXPECT_EQ(subscriptionInfo, subscriptionInfo3); // Verify at end of list - NL_TEST_ASSERT(inSuite, !iterator->Next(subscriptionInfo)); + EXPECT_FALSE(iterator->Next(subscriptionInfo)); iterator->Release(); // Delete 3 also, and see that both count is 0 and MaxCount is removed from storage subscriptionStorage.DeleteAll(subscriptionInfo3.mFabricIndex); iterator = subscriptionStorage.IterateSubscriptions(); - NL_TEST_ASSERT(inSuite, iterator->Count() == 0); - NL_TEST_ASSERT(inSuite, !iterator->Next(subscriptionInfo)); + EXPECT_EQ(iterator->Count(), 0u); + EXPECT_FALSE(iterator->Next(subscriptionInfo)); iterator->Release(); uint16_t countMax = 0; uint16_t len = sizeof(countMax); err = storage.SyncGetKeyValue(chip::DefaultStorageKeyAllocator::SubscriptionResumptionMaxCount().KeyName(), &countMax, len); - NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + EXPECT_EQ(err, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); } static constexpr chip::TLV::Tag kTestValue1Tag = chip::TLV::ContextTag(30); static constexpr chip::TLV::Tag kTestValue2Tag = chip::TLV::ContextTag(31); -void TestSubscriptionStateUnexpectedFields(nlTestSuite * inSuite, void * inContext) +TEST_F(TestSimpleSubscriptionResumptionStorage, TestSubscriptionStateUnexpectedFields) { chip::TestPersistentStorageDelegate storage; SimpleSubscriptionResumptionStorageTest subscriptionStorage; @@ -293,39 +297,38 @@ void TestSubscriptionStateUnexpectedFields(nlTestSuite * inSuite, void * inConte chip::Platform::ScopedMemoryBuffer backingBuffer; backingBuffer.Calloc(subscriptionStorage.TestMaxSubscriptionSize()); - NL_TEST_ASSERT(inSuite, backingBuffer.Get() != nullptr); + ASSERT_NE(backingBuffer.Get(), nullptr); chip::TLV::ScopedBufferTLVWriter writer(std::move(backingBuffer), subscriptionStorage.TestMaxSubscriptionSize()); - NL_TEST_ASSERT(inSuite, subscriptionStorage.TestSave(writer, subscriptionInfo1) == CHIP_NO_ERROR); + EXPECT_EQ(subscriptionStorage.TestSave(writer, subscriptionInfo1), CHIP_NO_ERROR); // Additional stuff chip::TLV::TLVType containerType; - NL_TEST_ASSERT(inSuite, - writer.StartContainer(chip::TLV::AnonymousTag(), chip::TLV::kTLVType_Structure, containerType) == CHIP_NO_ERROR); + EXPECT_EQ(writer.StartContainer(chip::TLV::AnonymousTag(), chip::TLV::kTLVType_Structure, containerType), CHIP_NO_ERROR); uint32_t value1 = 1; uint32_t value2 = 2; - NL_TEST_ASSERT(inSuite, writer.Put(kTestValue1Tag, value1) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, writer.Put(kTestValue2Tag, value2) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, writer.EndContainer(containerType) == CHIP_NO_ERROR); + EXPECT_EQ(writer.Put(kTestValue1Tag, value1), CHIP_NO_ERROR); + EXPECT_EQ(writer.Put(kTestValue2Tag, value2), CHIP_NO_ERROR); + EXPECT_EQ(writer.EndContainer(containerType), CHIP_NO_ERROR); const auto len = writer.GetLengthWritten(); writer.Finalize(backingBuffer); - NL_TEST_ASSERT(inSuite, - storage.SyncSetKeyValue(chip::DefaultStorageKeyAllocator::SubscriptionResumption(0).KeyName(), - backingBuffer.Get(), static_cast(len)) == CHIP_NO_ERROR); + EXPECT_EQ(storage.SyncSetKeyValue(chip::DefaultStorageKeyAllocator::SubscriptionResumption(0).KeyName(), backingBuffer.Get(), + static_cast(len)), + CHIP_NO_ERROR); // Now read back and verify auto * iterator = subscriptionStorage.IterateSubscriptions(); - NL_TEST_ASSERT(inSuite, iterator->Count() == 1); + EXPECT_EQ(iterator->Count(), 1u); TestSubscriptionInfo subscriptionInfo; - NL_TEST_ASSERT(inSuite, iterator->Next(subscriptionInfo)); - NL_TEST_ASSERT(inSuite, subscriptionInfo == subscriptionInfo1); + EXPECT_TRUE(iterator->Next(subscriptionInfo)); + EXPECT_EQ(subscriptionInfo, subscriptionInfo1); iterator->Release(); } -void TestSubscriptionStateTooBigToLoad(nlTestSuite * inSuite, void * inContext) +TEST_F(TestSimpleSubscriptionResumptionStorage, TestSubscriptionStateTooBigToLoad) { chip::TestPersistentStorageDelegate storage; SimpleSubscriptionResumptionStorageTest subscriptionStorage; @@ -350,42 +353,41 @@ void TestSubscriptionStateTooBigToLoad(nlTestSuite * inSuite, void * inContext) chip::Platform::ScopedMemoryBuffer backingBuffer; backingBuffer.Calloc(subscriptionStorage.TestMaxSubscriptionSize() * 2); - NL_TEST_ASSERT(inSuite, backingBuffer.Get() != nullptr); + ASSERT_NE(backingBuffer.Get(), nullptr); chip::TLV::ScopedBufferTLVWriter writer(std::move(backingBuffer), subscriptionStorage.TestMaxSubscriptionSize() * 2); - NL_TEST_ASSERT(inSuite, subscriptionStorage.TestSave(writer, subscriptionInfo1) == CHIP_NO_ERROR); + EXPECT_EQ(subscriptionStorage.TestSave(writer, subscriptionInfo1), CHIP_NO_ERROR); // Additional too-many bytes chip::TLV::TLVType containerType; - NL_TEST_ASSERT(inSuite, - writer.StartContainer(chip::TLV::AnonymousTag(), chip::TLV::kTLVType_Structure, containerType) == CHIP_NO_ERROR); + EXPECT_EQ(writer.StartContainer(chip::TLV::AnonymousTag(), chip::TLV::kTLVType_Structure, containerType), CHIP_NO_ERROR); // Write MaxSubscriptionSize() to guarantee Load failure chip::Platform::ScopedMemoryBuffer additionalBytes; additionalBytes.Calloc(subscriptionStorage.TestMaxSubscriptionSize()); - NL_TEST_ASSERT(inSuite, additionalBytes.Get() != nullptr); - NL_TEST_ASSERT(inSuite, - writer.PutBytes(kTestValue1Tag, additionalBytes.Get(), - static_cast(subscriptionStorage.TestMaxSubscriptionSize())) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, writer.EndContainer(containerType) == CHIP_NO_ERROR); + ASSERT_NE(additionalBytes.Get(), nullptr); + EXPECT_EQ(writer.PutBytes(kTestValue1Tag, additionalBytes.Get(), + static_cast(subscriptionStorage.TestMaxSubscriptionSize())), + CHIP_NO_ERROR); + EXPECT_EQ(writer.EndContainer(containerType), CHIP_NO_ERROR); const auto len = writer.GetLengthWritten(); writer.Finalize(backingBuffer); - NL_TEST_ASSERT(inSuite, - storage.SyncSetKeyValue(chip::DefaultStorageKeyAllocator::SubscriptionResumption(0).KeyName(), - backingBuffer.Get(), static_cast(len)) == CHIP_NO_ERROR); + EXPECT_EQ(storage.SyncSetKeyValue(chip::DefaultStorageKeyAllocator::SubscriptionResumption(0).KeyName(), backingBuffer.Get(), + static_cast(len)), + CHIP_NO_ERROR); // Now read back and verify auto * iterator = subscriptionStorage.IterateSubscriptions(); - NL_TEST_ASSERT(inSuite, iterator->Count() == 1); + EXPECT_EQ(iterator->Count(), 1u); TestSubscriptionInfo subscriptionInfo; - NL_TEST_ASSERT(inSuite, !iterator->Next(subscriptionInfo)); - NL_TEST_ASSERT(inSuite, iterator->Count() == 0); + EXPECT_FALSE(iterator->Next(subscriptionInfo)); + EXPECT_EQ(iterator->Count(), 0u); iterator->Release(); } -void TestSubscriptionStateJunkData(nlTestSuite * inSuite, void * inContext) +TEST_F(TestSimpleSubscriptionResumptionStorage, TestSubscriptionStateJunkData) { chip::TestPersistentStorageDelegate storage; SimpleSubscriptionResumptionStorageTest subscriptionStorage; @@ -393,76 +395,16 @@ void TestSubscriptionStateJunkData(nlTestSuite * inSuite, void * inContext) chip::Platform::ScopedMemoryBuffer junkBytes; junkBytes.Calloc(subscriptionStorage.TestMaxSubscriptionSize() / 2); - NL_TEST_ASSERT(inSuite, junkBytes.Get() != nullptr); - NL_TEST_ASSERT(inSuite, - storage.SyncSetKeyValue(chip::DefaultStorageKeyAllocator::SubscriptionResumption(0).KeyName(), junkBytes.Get(), - static_cast(subscriptionStorage.TestMaxSubscriptionSize() / 2)) == - CHIP_NO_ERROR); + ASSERT_NE(junkBytes.Get(), nullptr); + EXPECT_EQ(storage.SyncSetKeyValue(chip::DefaultStorageKeyAllocator::SubscriptionResumption(0).KeyName(), junkBytes.Get(), + static_cast(subscriptionStorage.TestMaxSubscriptionSize() / 2)), + CHIP_NO_ERROR); // Now read back and verify auto * iterator = subscriptionStorage.IterateSubscriptions(); - NL_TEST_ASSERT(inSuite, iterator->Count() == 1); + EXPECT_EQ(iterator->Count(), 1u); TestSubscriptionInfo subscriptionInfo; - NL_TEST_ASSERT(inSuite, !iterator->Next(subscriptionInfo)); - NL_TEST_ASSERT(inSuite, iterator->Count() == 0); + EXPECT_FALSE(iterator->Next(subscriptionInfo)); + EXPECT_EQ(iterator->Count(), 0u); iterator->Release(); } -/** - * Set up the test suite. - */ -int TestSubscription_Setup(void * inContext) -{ - VerifyOrReturnError(CHIP_NO_ERROR == chip::Platform::MemoryInit(), FAILURE); - - return SUCCESS; -} - -/** - * Tear down the test suite. - */ -int TestSubscription_Teardown(void * inContext) -{ - chip::Platform::MemoryShutdown(); - return SUCCESS; -} - -// Test Suite - -/** - * Test Suite that lists all the test functions. - */ -// clang-format off -static const nlTest sTests[] = -{ - NL_TEST_DEF("TestSubscriptionCount", TestSubscriptionCount), - NL_TEST_DEF("TestSubscriptionMaxCount", TestSubscriptionMaxCount), - NL_TEST_DEF("TestSubscriptionState", TestSubscriptionState), - NL_TEST_DEF("TestSubscriptionStateUnexpectedFields", TestSubscriptionStateUnexpectedFields), - NL_TEST_DEF("TestSubscriptionStateTooBigToLoad", TestSubscriptionStateTooBigToLoad), - NL_TEST_DEF("TestSubscriptionStateJunkData", TestSubscriptionStateJunkData), - - NL_TEST_SENTINEL() -}; -// clang-format on - -// clang-format off -static nlTestSuite sSuite = -{ - "Test-CHIP-SimpleSubscriptionResumptionStorage", - &sTests[0], - &TestSubscription_Setup, &TestSubscription_Teardown -}; -// clang-format on - -/** - * Main - */ -int TestSimpleSubscriptionResumptionStorage() -{ - // Run test suit against one context - nlTestRunner(&sSuite, nullptr); - - return (nlTestRunnerStats(&sSuite)); -} - -CHIP_REGISTER_TEST_SUITE(TestSimpleSubscriptionResumptionStorage) diff --git a/src/app/tests/TestStatusIB.cpp b/src/app/tests/TestStatusIB.cpp index 2e5f78f7da64f7..8da643d2b71a31 100644 --- a/src/app/tests/TestStatusIB.cpp +++ b/src/app/tests/TestStatusIB.cpp @@ -20,11 +20,10 @@ #include #include #include +#include #include -#include #include - -#include +#include namespace { @@ -32,67 +31,78 @@ using namespace chip; using namespace chip::app; using namespace chip::Protocols::InteractionModel; +class TestStatusIB : public ::testing::Test +{ +public: + static void SetUpTestSuite() + { + ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); + StatusIB::RegisterErrorFormatter(); + } + static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); } +}; + // Macro so failures will blame the right line. #define VERIFY_ROUNDTRIP(err, status) \ do \ { \ StatusIB newStatus; \ newStatus.InitFromChipError(err); \ - NL_TEST_ASSERT(aSuite, newStatus.mStatus == status.mStatus); \ - NL_TEST_ASSERT(aSuite, newStatus.mClusterStatus == status.mClusterStatus); \ + EXPECT_EQ(newStatus.mStatus, status.mStatus); \ + EXPECT_EQ(newStatus.mClusterStatus, status.mClusterStatus); \ } while (0); -void TestStatusIBToFromChipError(nlTestSuite * aSuite, void * aContext) +TEST_F(TestStatusIB, TestStatusIBToFromChipError) { StatusIB status; status.mStatus = Status::Success; CHIP_ERROR err = status.ToChipError(); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); VERIFY_ROUNDTRIP(err, status); status.mStatus = Status::Failure; err = status.ToChipError(); - NL_TEST_ASSERT(aSuite, err != CHIP_NO_ERROR); + EXPECT_NE(err, CHIP_NO_ERROR); VERIFY_ROUNDTRIP(err, status); status.mStatus = Status::InvalidAction; err = status.ToChipError(); - NL_TEST_ASSERT(aSuite, err != CHIP_NO_ERROR); + EXPECT_NE(err, CHIP_NO_ERROR); VERIFY_ROUNDTRIP(err, status); status.mClusterStatus = MakeOptional(static_cast(5)); status.mStatus = Status::Success; err = status.ToChipError(); - NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); status.mStatus = Status::Failure; err = status.ToChipError(); - NL_TEST_ASSERT(aSuite, err != CHIP_NO_ERROR); + EXPECT_NE(err, CHIP_NO_ERROR); VERIFY_ROUNDTRIP(err, status); status.mStatus = Status::InvalidAction; err = status.ToChipError(); - NL_TEST_ASSERT(aSuite, err != CHIP_NO_ERROR); + EXPECT_NE(err, CHIP_NO_ERROR); { StatusIB newStatus; newStatus.InitFromChipError(err); - NL_TEST_ASSERT(aSuite, newStatus.mStatus == Status::Failure); - NL_TEST_ASSERT(aSuite, newStatus.mClusterStatus == status.mClusterStatus); + EXPECT_EQ(newStatus.mStatus, Status::Failure); + EXPECT_EQ(newStatus.mClusterStatus, status.mClusterStatus); } err = CHIP_ERROR_NO_MEMORY; { StatusIB newStatus; newStatus.InitFromChipError(err); - NL_TEST_ASSERT(aSuite, newStatus.mStatus == Status::Failure); - NL_TEST_ASSERT(aSuite, !newStatus.mClusterStatus.HasValue()); + EXPECT_EQ(newStatus.mStatus, Status::Failure); + EXPECT_FALSE(newStatus.mClusterStatus.HasValue()); } } #if !CHIP_CONFIG_SHORT_ERROR_STR -void TestStatusIBErrorToString(nlTestSuite * aSuite, void * aContext) +TEST_F(TestStatusIB, TestStatusIBErrorToString) { StatusIB status; status.mStatus = Status::InvalidAction; @@ -100,108 +110,55 @@ void TestStatusIBErrorToString(nlTestSuite * aSuite, void * aContext) const char * str = ErrorStr(err); #if CHIP_CONFIG_IM_STATUS_CODE_VERBOSE_FORMAT - NL_TEST_ASSERT(aSuite, strcmp(str, "IM Error 0x00000580: General error: 0x80 (INVALID_ACTION)") == 0); + EXPECT_STREQ(str, "IM Error 0x00000580: General error: 0x80 (INVALID_ACTION)"); #else // CHIP_CONFIG_IM_STATUS_CODE_VERBOSE_FORMAT - NL_TEST_ASSERT(aSuite, strcmp(str, "IM Error 0x00000580: General error: 0x80") == 0); + EXPECT_STREQ(str, "IM Error 0x00000580: General error: 0x80"); #endif // CHIP_CONFIG_IM_STATUS_CODE_VERBOSE_FORMAT status.mStatus = Status::Failure; status.mClusterStatus = MakeOptional(static_cast(5)); err = status.ToChipError(); str = ErrorStr(err); - NL_TEST_ASSERT(aSuite, strcmp(str, "IM Error 0x00000605: Cluster-specific error: 0x05") == 0); + EXPECT_STREQ(str, "IM Error 0x00000605: Cluster-specific error: 0x05"); } #endif // !CHIP_CONFIG_SHORT_ERROR_STR -void TestStatusIBEqualityOperator(nlTestSuite * aSuite, void * /*aContext*/) +TEST_F(TestStatusIB, TestStatusIBEqualityOperator) { // Equality against self is true. StatusIB one; - NL_TEST_ASSERT(aSuite, one == one); + EXPECT_EQ(one, one); // Default constructors are equal. - NL_TEST_ASSERT(aSuite, one == StatusIB()); + EXPECT_EQ(one, StatusIB()); // Different imStatus is not equal. StatusIB with_imstatus(Status::Failure); - NL_TEST_ASSERT(aSuite, one != with_imstatus); + EXPECT_NE(one, with_imstatus); // Same imStatus are equal. - NL_TEST_ASSERT(aSuite, with_imstatus == StatusIB(Status::Failure)); + EXPECT_EQ(with_imstatus, StatusIB(Status::Failure)); // Same imStatus but different clusterStatus are not equal. StatusIB with_cluster_status(Status::Failure, /*clusterStatus=*/2); - NL_TEST_ASSERT(aSuite, with_imstatus != with_cluster_status); + EXPECT_NE(with_imstatus, with_cluster_status); // Different imStatus but same clusterStatus are not equal. - NL_TEST_ASSERT(aSuite, with_cluster_status != StatusIB(Status::Success, /*clusterStatus=*/2)); + EXPECT_NE(with_cluster_status, StatusIB(Status::Success, /*clusterStatus=*/2)); // Same imStatus and clusterStatus are equal. - NL_TEST_ASSERT(aSuite, with_cluster_status == StatusIB(Status::Failure, /*clusterStatus=*/2)); + EXPECT_EQ(with_cluster_status, StatusIB(Status::Failure, /*clusterStatus=*/2)); // From same CHIP_ERROR are equal. StatusIB invalid_argument(CHIP_ERROR_INVALID_ARGUMENT); - NL_TEST_ASSERT(aSuite, invalid_argument == StatusIB(CHIP_ERROR_INVALID_ARGUMENT)); + EXPECT_EQ(invalid_argument, StatusIB(CHIP_ERROR_INVALID_ARGUMENT)); // Different CHIP_ERROR are equal if they are not from kIMClusterStatus or // kIMGlobalStatus. - NL_TEST_ASSERT(aSuite, invalid_argument == StatusIB(CHIP_ERROR_INCORRECT_STATE)); + EXPECT_EQ(invalid_argument, StatusIB(CHIP_ERROR_INCORRECT_STATE)); // Error never equals NO_ERROR - NL_TEST_ASSERT(aSuite, invalid_argument != StatusIB(CHIP_NO_ERROR)); + EXPECT_NE(invalid_argument, StatusIB(CHIP_NO_ERROR)); } -// clang-format off -const nlTest sTests[] = -{ - NL_TEST_DEF("StatusIBToFromChipError", TestStatusIBToFromChipError), -#if !CHIP_CONFIG_SHORT_ERROR_STR - NL_TEST_DEF("StatusIBErrorToString", TestStatusIBErrorToString), -#endif // !CHIP_CONFIG_SHORT_ERROR_STR - NL_TEST_DEF("StatusIBEqualityOperator", TestStatusIBEqualityOperator), - NL_TEST_SENTINEL() -}; -// clang-format on } // namespace - -/** - * Set up the test suite. - */ -static int TestSetup(void * inContext) -{ - CHIP_ERROR error = chip::Platform::MemoryInit(); - if (error != CHIP_NO_ERROR) - return FAILURE; - // Hand-register the error formatter. Normally it's registered by - // InteractionModelEngine::Init, but we don't want to mess with that here. - StatusIB::RegisterErrorFormatter(); - return SUCCESS; -} - -/** - * Tear down the test suite. - */ -static int TestTeardown(void * inContext) -{ - chip::Platform::MemoryShutdown(); - return SUCCESS; -} - -int TestStatusIB() -{ - // clang-format off - nlTestSuite theSuite = - { - "StatusIB", - &sTests[0], - TestSetup, - TestTeardown, - }; - // clang-format on - - nlTestRunner(&theSuite, nullptr); - - return (nlTestRunnerStats(&theSuite)); -} - -CHIP_REGISTER_TEST_SUITE(TestStatusIB) diff --git a/src/app/tests/TestStatusResponseMessage.cpp b/src/app/tests/TestStatusResponseMessage.cpp index 565ed85dfe8af0..72cf8685d9bfff 100644 --- a/src/app/tests/TestStatusResponseMessage.cpp +++ b/src/app/tests/TestStatusResponseMessage.cpp @@ -16,40 +16,41 @@ * limitations under the License. */ -/** - * @file - * This file implements a test for CHIP Interaction Model Message Def - * - */ +#include +#include #include #include #include #include -#include #include -#include - namespace { using namespace chip::app; constexpr chip::Protocols::InteractionModel::Status statusValue = chip::Protocols::InteractionModel::Status::Success; constexpr chip::Protocols::InteractionModel::Status invalidStatusValue = chip::Protocols::InteractionModel::Status::Failure; -void BuildStatusResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWriter) +class TestStatusResponseMessage : public ::testing::Test +{ +public: + static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); } + static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); } +}; + +void BuildStatusResponseMessage(chip::TLV::TLVWriter & aWriter) { CHIP_ERROR err = CHIP_NO_ERROR; StatusResponseMessage::Builder statusResponse; err = statusResponse.Init(&aWriter); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); statusResponse.Status(statusValue); - NL_TEST_ASSERT(apSuite, statusResponse.GetError() == CHIP_NO_ERROR); + EXPECT_EQ(statusResponse.GetError(), CHIP_NO_ERROR); } -void ParseStatusResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader, bool aTestPositiveCase) +void ParseStatusResponseMessage(chip::TLV::TLVReader & aReader, bool aTestPositiveCase) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -57,7 +58,7 @@ void ParseStatusResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aR chip::Protocols::InteractionModel::Status status; err = statusResponse.Init(aReader); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); #if CHIP_CONFIG_IM_PRETTY_PRINT statusResponse.PrettyPrint(); #endif @@ -65,87 +66,42 @@ void ParseStatusResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aR err = statusResponse.GetStatus(status); if (aTestPositiveCase) { - NL_TEST_ASSERT(apSuite, status == statusValue && err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_EQ(status, statusValue); } else { - NL_TEST_ASSERT(apSuite, status != invalidStatusValue && err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_NE(status, invalidStatusValue); } } -void StatusResponseMessagePositiveTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestStatusResponseMessage, TestStatusResponseMessagePositive) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); - BuildStatusResponseMessage(apSuite, writer); + BuildStatusResponseMessage(writer); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); reader.Init(std::move(buf)); - ParseStatusResponseMessage(apSuite, reader, true /*aTestPositiveCase*/); + ParseStatusResponseMessage(reader, true /*aTestPositiveCase*/); } -void StatusResponseMessageNegativeTest(nlTestSuite * apSuite, void * apContext) +TEST_F(TestStatusResponseMessage, TestStatusResponseMessageNegative) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); - BuildStatusResponseMessage(apSuite, writer); + BuildStatusResponseMessage(writer); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); reader.Init(std::move(buf)); - ParseStatusResponseMessage(apSuite, reader, false /*aTestPositiveCase*/); + ParseStatusResponseMessage(reader, false /*aTestPositiveCase*/); } -// clang-format off -const nlTest sTests[] = - { - NL_TEST_DEF("StatusResponseMessagePositiveTest", StatusResponseMessagePositiveTest), - NL_TEST_DEF("StatusResponseMessageNegativeTest", StatusResponseMessageNegativeTest), - NL_TEST_SENTINEL() - }; -// clang-format on } // namespace - -/** - * Set up the test suite. - */ -static int TestSetup(void * inContext) -{ - CHIP_ERROR error = chip::Platform::MemoryInit(); - if (error != CHIP_NO_ERROR) - return FAILURE; - return SUCCESS; -} - -/** - * Tear down the test suite. - */ -static int TestTeardown(void * inContext) -{ - chip::Platform::MemoryShutdown(); - return SUCCESS; -} - -int TestStatusResponseMessage() -{ - // clang-format off - nlTestSuite theSuite = - { - "StatusResponseMessage", - &sTests[0], - TestSetup, - TestTeardown, - }; - // clang-format on - - nlTestRunner(&theSuite, nullptr); - - return (nlTestRunnerStats(&theSuite)); -} - -CHIP_REGISTER_TEST_SUITE(TestStatusResponseMessage) diff --git a/src/app/tests/TestTestEventTriggerDelegate.cpp b/src/app/tests/TestTestEventTriggerDelegate.cpp index cd7f3ae9cd7be3..09e513a3d87afb 100644 --- a/src/app/tests/TestTestEventTriggerDelegate.cpp +++ b/src/app/tests/TestTestEventTriggerDelegate.cpp @@ -19,9 +19,9 @@ #include #include +#include #include -#include -#include +#include using namespace chip; @@ -66,20 +66,20 @@ class TestEventDelegate : public TestEventTriggerDelegate ByteSpan mEnableKey; }; -void TestKeyChecking(nlTestSuite * aSuite, void * aContext) +TEST(TestTestEventTriggerDelegate, TestKeyChecking) { const uint8_t kTestKey[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; const uint8_t kBadKey[16] = { 255, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; const uint8_t kDiffLenBadKey[17] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; TestEventDelegate delegate{ ByteSpan{ kTestKey } }; - NL_TEST_ASSERT(aSuite, delegate.DoesEnableKeyMatch(ByteSpan{ kTestKey }) == true); - NL_TEST_ASSERT(aSuite, delegate.DoesEnableKeyMatch(ByteSpan{ kBadKey }) == false); - NL_TEST_ASSERT(aSuite, delegate.DoesEnableKeyMatch(ByteSpan{ kDiffLenBadKey }) == false); - NL_TEST_ASSERT(aSuite, delegate.DoesEnableKeyMatch(ByteSpan{}) == false); + EXPECT_TRUE(delegate.DoesEnableKeyMatch(ByteSpan{ kTestKey })); + EXPECT_FALSE(delegate.DoesEnableKeyMatch(ByteSpan{ kBadKey })); + EXPECT_FALSE(delegate.DoesEnableKeyMatch(ByteSpan{ kDiffLenBadKey })); + EXPECT_FALSE(delegate.DoesEnableKeyMatch(ByteSpan{})); } -void TestHandlerManagement(nlTestSuite * aSuite, void * aContext) +TEST(TestTestEventTriggerDelegate, TestHandlerManagement) { const uint8_t kTestKey[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; @@ -89,31 +89,31 @@ void TestHandlerManagement(nlTestSuite * aSuite, void * aContext) TestEventHandler event2Handler{ 2 }; // Add 2, check 2 works 1 doesn't. - NL_TEST_ASSERT(aSuite, delegate.HandleEventTriggers(1) != CHIP_NO_ERROR); + EXPECT_NE(delegate.HandleEventTriggers(1), CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, delegate.AddHandler(&event2Handler) == CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, delegate.AddHandler(&event2Handler) != CHIP_NO_ERROR); + EXPECT_EQ(delegate.AddHandler(&event2Handler), CHIP_NO_ERROR); + EXPECT_NE(delegate.AddHandler(&event2Handler), CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, delegate.HandleEventTriggers(2) == CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, delegate.HandleEventTriggers(1) != CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, delegate.HandleEventTriggers(2) == CHIP_NO_ERROR); + EXPECT_EQ(delegate.HandleEventTriggers(2), CHIP_NO_ERROR); + EXPECT_NE(delegate.HandleEventTriggers(1), CHIP_NO_ERROR); + EXPECT_EQ(delegate.HandleEventTriggers(2), CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, event1Handler.GetCount() == 0); - NL_TEST_ASSERT(aSuite, event2Handler.GetCount() == 2); + EXPECT_EQ(event1Handler.GetCount(), 0); + EXPECT_EQ(event2Handler.GetCount(), 2); event1Handler.ClearCount(); event2Handler.ClearCount(); // Add 1, check 1 and 2 work. - NL_TEST_ASSERT(aSuite, delegate.AddHandler(&event1Handler) == CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, delegate.AddHandler(&event1Handler) != CHIP_NO_ERROR); + EXPECT_EQ(delegate.AddHandler(&event1Handler), CHIP_NO_ERROR); + EXPECT_NE(delegate.AddHandler(&event1Handler), CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, delegate.HandleEventTriggers(1) == CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, delegate.HandleEventTriggers(2) == CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, delegate.HandleEventTriggers(1) == CHIP_NO_ERROR); + EXPECT_EQ(delegate.HandleEventTriggers(1), CHIP_NO_ERROR); + EXPECT_EQ(delegate.HandleEventTriggers(2), CHIP_NO_ERROR); + EXPECT_EQ(delegate.HandleEventTriggers(1), CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, event1Handler.GetCount() == 2); - NL_TEST_ASSERT(aSuite, event2Handler.GetCount() == 1); + EXPECT_EQ(event1Handler.GetCount(), 2); + EXPECT_EQ(event2Handler.GetCount(), 1); event1Handler.ClearCount(); event2Handler.ClearCount(); @@ -121,29 +121,29 @@ void TestHandlerManagement(nlTestSuite * aSuite, void * aContext) // Remove 2, check 1 works. delegate.RemoveHandler(&event2Handler); - NL_TEST_ASSERT(aSuite, delegate.HandleEventTriggers(1) == CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, delegate.HandleEventTriggers(2) != CHIP_NO_ERROR); + EXPECT_EQ(delegate.HandleEventTriggers(1), CHIP_NO_ERROR); + EXPECT_NE(delegate.HandleEventTriggers(2), CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, event1Handler.GetCount() == 1); - NL_TEST_ASSERT(aSuite, event2Handler.GetCount() == 0); + EXPECT_EQ(event1Handler.GetCount(), 1); + EXPECT_EQ(event2Handler.GetCount(), 0); // Remove again, should be NO-OP. delegate.RemoveHandler(&event2Handler); - NL_TEST_ASSERT(aSuite, delegate.HandleEventTriggers(2) != CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, event2Handler.GetCount() == 0); + EXPECT_NE(delegate.HandleEventTriggers(2), CHIP_NO_ERROR); + EXPECT_EQ(event2Handler.GetCount(), 0); event1Handler.ClearCount(); event2Handler.ClearCount(); // Add 2 again, check 1 and 2 work. - NL_TEST_ASSERT(aSuite, delegate.AddHandler(&event2Handler) == CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, delegate.AddHandler(&event2Handler) != CHIP_NO_ERROR); + EXPECT_EQ(delegate.AddHandler(&event2Handler), CHIP_NO_ERROR); + EXPECT_NE(delegate.AddHandler(&event2Handler), CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, delegate.HandleEventTriggers(1) == CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, delegate.HandleEventTriggers(2) == CHIP_NO_ERROR); + EXPECT_EQ(delegate.HandleEventTriggers(1), CHIP_NO_ERROR); + EXPECT_EQ(delegate.HandleEventTriggers(2), CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, event1Handler.GetCount() == 1); - NL_TEST_ASSERT(aSuite, event2Handler.GetCount() == 1); + EXPECT_EQ(event1Handler.GetCount(), 1); + EXPECT_EQ(event2Handler.GetCount(), 1); event1Handler.ClearCount(); event2Handler.ClearCount(); @@ -151,42 +151,14 @@ void TestHandlerManagement(nlTestSuite * aSuite, void * aContext) // Remove all handlers, check neither works. delegate.ClearAllHandlers(); - NL_TEST_ASSERT(aSuite, delegate.HandleEventTriggers(1) != CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, delegate.HandleEventTriggers(2) != CHIP_NO_ERROR); + EXPECT_NE(delegate.HandleEventTriggers(1), CHIP_NO_ERROR); + EXPECT_NE(delegate.HandleEventTriggers(2), CHIP_NO_ERROR); - NL_TEST_ASSERT(aSuite, event1Handler.GetCount() == 0); - NL_TEST_ASSERT(aSuite, event2Handler.GetCount() == 0); + EXPECT_EQ(event1Handler.GetCount(), 0); + EXPECT_EQ(event2Handler.GetCount(), 0); // Add a handler at the end: having it remaining should not cause crashes/leaks. - NL_TEST_ASSERT(aSuite, delegate.AddHandler(&event2Handler) == CHIP_NO_ERROR); -} - -int TestSetup(void * inContext) -{ - return SUCCESS; -} - -int TestTeardown(void * inContext) -{ - return SUCCESS; + EXPECT_EQ(delegate.AddHandler(&event2Handler), CHIP_NO_ERROR); } } // namespace - -int TestTestEventTriggerDelegate() -{ - static nlTest sTests[] = { NL_TEST_DEF("TestKeyChecking", TestKeyChecking), - NL_TEST_DEF("TestHandlerManagement", TestHandlerManagement), NL_TEST_SENTINEL() }; - - nlTestSuite theSuite = { - "TestTestEventTriggerDelegate", - &sTests[0], - TestSetup, - TestTeardown, - }; - - nlTestRunner(&theSuite, nullptr); - return (nlTestRunnerStats(&theSuite)); -} - -CHIP_REGISTER_TEST_SUITE(TestTestEventTriggerDelegate) diff --git a/src/app/tests/TestTimeSyncDataProvider.cpp b/src/app/tests/TestTimeSyncDataProvider.cpp index 3ea30d5582a642..bc73f03e55a386 100644 --- a/src/app/tests/TestTimeSyncDataProvider.cpp +++ b/src/app/tests/TestTimeSyncDataProvider.cpp @@ -17,11 +17,10 @@ #include #include +#include #include #include -#include - -#include +#include using namespace chip; using namespace chip::DeviceLayer; @@ -36,7 +35,14 @@ using DSTOffset = app::Clusters::TimeSynchronization::Structs::DSTOffset namespace { -void TestTrustedTimeSourceStoreLoad(nlTestSuite * inSuite, void * inContext) +class TestTimeSyncDataProvider : public ::testing::Test +{ +public: + static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); } + static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); } +}; + +TEST_F(TestTimeSyncDataProvider, TestTrustedTimeSourceStoreLoad) { TestPersistentStorageDelegate persistentStorage; TimeSyncDataProvider timeSyncDataProv; @@ -44,16 +50,16 @@ void TestTrustedTimeSourceStoreLoad(nlTestSuite * inSuite, void * inContext) TrustedTimeSource tts = { chip::FabricIndex(1), chip::NodeId(20), chip::EndpointId(0) }; - NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == timeSyncDataProv.StoreTrustedTimeSource(tts)); + EXPECT_EQ(CHIP_NO_ERROR, timeSyncDataProv.StoreTrustedTimeSource(tts)); TrustedTimeSource retrievedTrustedTimeSource; - NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == timeSyncDataProv.LoadTrustedTimeSource(retrievedTrustedTimeSource)); - NL_TEST_ASSERT(inSuite, retrievedTrustedTimeSource.fabricIndex == chip::FabricIndex(1)); - NL_TEST_ASSERT(inSuite, retrievedTrustedTimeSource.nodeID == chip::NodeId(20)); - NL_TEST_ASSERT(inSuite, retrievedTrustedTimeSource.endpoint == chip::EndpointId(0)); + EXPECT_EQ(CHIP_NO_ERROR, timeSyncDataProv.LoadTrustedTimeSource(retrievedTrustedTimeSource)); + EXPECT_EQ(retrievedTrustedTimeSource.fabricIndex, chip::FabricIndex(1)); + EXPECT_EQ(retrievedTrustedTimeSource.nodeID, chip::NodeId(20)); + EXPECT_EQ(retrievedTrustedTimeSource.endpoint, chip::EndpointId(0)); } -void TestTrustedTimeSourceEmpty(nlTestSuite * inSuite, void * inContext) +TEST_F(TestTimeSyncDataProvider, TestTrustedTimeSourceEmpty) { TestPersistentStorageDelegate persistentStorage; TimeSyncDataProvider timeSyncDataProv; @@ -61,10 +67,10 @@ void TestTrustedTimeSourceEmpty(nlTestSuite * inSuite, void * inContext) TrustedTimeSource tts; - NL_TEST_ASSERT(inSuite, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND == timeSyncDataProv.LoadTrustedTimeSource(tts)); + EXPECT_EQ(CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND, timeSyncDataProv.LoadTrustedTimeSource(tts)); } -void TestDefaultNTPStoreLoad(nlTestSuite * inSuite, void * inContext) +TEST_F(TestTimeSyncDataProvider, TestDefaultNTPStoreLoad) { TestPersistentStorageDelegate persistentStorage; TimeSyncDataProvider timeSyncDataProv; @@ -73,22 +79,22 @@ void TestDefaultNTPStoreLoad(nlTestSuite * inSuite, void * inContext) char ntp[10] = "localhost"; chip::CharSpan defaultNTP(ntp); - NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == timeSyncDataProv.StoreDefaultNtp(defaultNTP)); + EXPECT_EQ(CHIP_NO_ERROR, timeSyncDataProv.StoreDefaultNtp(defaultNTP)); char buf[5]; chip::MutableCharSpan getDefaultNtp(buf); - NL_TEST_ASSERT(inSuite, CHIP_ERROR_BUFFER_TOO_SMALL == timeSyncDataProv.LoadDefaultNtp(getDefaultNtp)); - NL_TEST_ASSERT(inSuite, getDefaultNtp.size() == 5); + EXPECT_EQ(CHIP_ERROR_BUFFER_TOO_SMALL, timeSyncDataProv.LoadDefaultNtp(getDefaultNtp)); + EXPECT_EQ(getDefaultNtp.size(), 5u); char buf1[20]; chip::MutableCharSpan getDefaultNtp1(buf1); - NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == timeSyncDataProv.LoadDefaultNtp(getDefaultNtp1)); - NL_TEST_ASSERT(inSuite, getDefaultNtp1.size() == 10); + EXPECT_EQ(CHIP_NO_ERROR, timeSyncDataProv.LoadDefaultNtp(getDefaultNtp1)); + EXPECT_EQ(getDefaultNtp1.size(), 10u); } -void TestDefaultNTPEmpty(nlTestSuite * inSuite, void * inContext) +TEST_F(TestTimeSyncDataProvider, TestDefaultNTPEmpty) { TestPersistentStorageDelegate persistentStorage; TimeSyncDataProvider timeSyncDataProv; @@ -96,10 +102,10 @@ void TestDefaultNTPEmpty(nlTestSuite * inSuite, void * inContext) chip::MutableCharSpan defaultNTP; - NL_TEST_ASSERT(inSuite, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND == timeSyncDataProv.LoadDefaultNtp(defaultNTP)); + EXPECT_EQ(CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND, timeSyncDataProv.LoadDefaultNtp(defaultNTP)); } -void TestTimeZoneStoreLoad(nlTestSuite * inSuite, void * inContext) +TEST_F(TestTimeSyncDataProvider, TestTimeZoneStoreLoad) { TestPersistentStorageDelegate persistentStorage; TimeSyncDataProvider timeSyncDataProv; @@ -122,26 +128,26 @@ void TestTimeZoneStoreLoad(nlTestSuite * inSuite, void * inContext) TimeSyncDataProvider::TimeZoneStore tzS[3] = { makeTimeZone(1, 1, tzShort), makeTimeZone(2, 2, tzLong), makeTimeZone(3, 3, tzBerlin) }; TimeZoneList tzL(tzS); - NL_TEST_ASSERT(inSuite, tzL.size() == 3); - NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == timeSyncDataProv.StoreTimeZone(tzL)); + EXPECT_EQ(tzL.size(), 3u); + EXPECT_EQ(CHIP_NO_ERROR, timeSyncDataProv.StoreTimeZone(tzL)); TimeSyncDataProvider::TimeZoneStore emptyTzS[3] = { makeTimeZone(), makeTimeZone(), makeTimeZone() }; tzL = TimeZoneList(emptyTzS); TimeSyncDataProvider::TimeZoneObj tzObj{ tzL, 3 }; - NL_TEST_ASSERT(inSuite, tzL.size() == 3); - NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == timeSyncDataProv.LoadTimeZone(tzObj)); - NL_TEST_ASSERT(inSuite, tzObj.validSize == 3); + EXPECT_EQ(tzL.size(), 3u); + EXPECT_EQ(CHIP_NO_ERROR, timeSyncDataProv.LoadTimeZone(tzObj)); + EXPECT_EQ(tzObj.validSize, 3u); - NL_TEST_ASSERT(inSuite, !tzL.empty()); + EXPECT_FALSE(tzL.empty()); if (!tzL.empty()) { auto & tz = tzL[0].timeZone; - NL_TEST_ASSERT(inSuite, tz.offset == 1); - NL_TEST_ASSERT(inSuite, tz.validAt == 1); - NL_TEST_ASSERT(inSuite, tz.name.HasValue()); - NL_TEST_ASSERT(inSuite, tz.name.Value().size() == 2); + EXPECT_EQ(tz.offset, 1); + EXPECT_EQ(tz.validAt, 1u); + EXPECT_TRUE(tz.name.HasValue()); + EXPECT_EQ(tz.name.Value().size(), 2u); tzL = tzL.SubSpan(1); } @@ -149,10 +155,10 @@ void TestTimeZoneStoreLoad(nlTestSuite * inSuite, void * inContext) if (!tzL.empty()) { auto & tz = tzL[0].timeZone; - NL_TEST_ASSERT(inSuite, tz.offset == 2); - NL_TEST_ASSERT(inSuite, tz.validAt == 2); - NL_TEST_ASSERT(inSuite, tz.name.HasValue()); - NL_TEST_ASSERT(inSuite, tz.name.Value().size() == 63); + EXPECT_EQ(tz.offset, 2); + EXPECT_EQ(tz.validAt, 2u); + EXPECT_TRUE(tz.name.HasValue()); + EXPECT_EQ(tz.name.Value().size(), 63u); tzL = tzL.SubSpan(1); } @@ -160,18 +166,18 @@ void TestTimeZoneStoreLoad(nlTestSuite * inSuite, void * inContext) if (!tzL.empty()) { auto & tz = tzL[0].timeZone; - NL_TEST_ASSERT(inSuite, tz.offset == 3); - NL_TEST_ASSERT(inSuite, tz.validAt == 3); - NL_TEST_ASSERT(inSuite, tz.name.HasValue()); - NL_TEST_ASSERT(inSuite, tz.name.Value().size() == 6); + EXPECT_EQ(tz.offset, 3); + EXPECT_EQ(tz.validAt, 3u); + EXPECT_TRUE(tz.name.HasValue()); + EXPECT_EQ(tz.name.Value().size(), 6u); tzL = tzL.SubSpan(1); } - NL_TEST_ASSERT(inSuite, tzL.empty()); + EXPECT_TRUE(tzL.empty()); } -void TestTimeZoneEmpty(nlTestSuite * inSuite, void * inContext) +TEST_F(TestTimeSyncDataProvider, TestTimeZoneEmpty) { TestPersistentStorageDelegate persistentStorage; TimeSyncDataProvider timeSyncDataProv; @@ -179,12 +185,12 @@ void TestTimeZoneEmpty(nlTestSuite * inSuite, void * inContext) TimeSyncDataProvider::TimeZoneObj timeZoneObj; - NL_TEST_ASSERT(inSuite, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND == timeSyncDataProv.LoadTimeZone(timeZoneObj)); - NL_TEST_ASSERT(inSuite, !timeZoneObj.timeZoneList.begin()); - NL_TEST_ASSERT(inSuite, timeZoneObj.validSize == 0); + EXPECT_EQ(CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND, timeSyncDataProv.LoadTimeZone(timeZoneObj)); + EXPECT_FALSE(timeZoneObj.timeZoneList.begin()); + EXPECT_EQ(timeZoneObj.validSize, 0u); } -void TestDSTOffset(nlTestSuite * inSuite, void * inContext) +TEST_F(TestTimeSyncDataProvider, TestDSTOffset) { TestPersistentStorageDelegate persistentStorage; TimeSyncDataProvider timeSyncDataProv; @@ -201,26 +207,26 @@ void TestDSTOffset(nlTestSuite * inSuite, void * inContext) DSTOffset dstS[3] = { makeDSTOffset(1, 1, 2), makeDSTOffset(2, 2, 3), makeDSTOffset(3, 3) }; DSTOffsetList dstL(dstS); TimeSyncDataProvider::DSTOffsetObj dstObj{ dstL, 3 }; - NL_TEST_ASSERT(inSuite, dstObj.validSize == 3); - NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == timeSyncDataProv.StoreDSTOffset(dstL)); + EXPECT_EQ(dstObj.validSize, 3u); + EXPECT_EQ(CHIP_NO_ERROR, timeSyncDataProv.StoreDSTOffset(dstL)); DSTOffset emtpyDstS[3] = { makeDSTOffset(), makeDSTOffset(), makeDSTOffset() }; dstObj.dstOffsetList = DSTOffsetList(emtpyDstS); dstObj.validSize = 0; - NL_TEST_ASSERT(inSuite, dstObj.dstOffsetList.size() == 3); - NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == timeSyncDataProv.LoadDSTOffset(dstObj)); - NL_TEST_ASSERT(inSuite, dstObj.validSize == 3); + EXPECT_EQ(dstObj.dstOffsetList.size(), 3u); + EXPECT_EQ(CHIP_NO_ERROR, timeSyncDataProv.LoadDSTOffset(dstObj)); + EXPECT_EQ(dstObj.validSize, 3u); - NL_TEST_ASSERT(inSuite, !dstObj.dstOffsetList.empty()); + EXPECT_FALSE(dstObj.dstOffsetList.empty()); if (!dstObj.dstOffsetList.empty()) { auto & dst = dstObj.dstOffsetList.data()[0]; - NL_TEST_ASSERT(inSuite, dst.offset == 1); - NL_TEST_ASSERT(inSuite, dst.validStarting == 1); - NL_TEST_ASSERT(inSuite, !dst.validUntil.IsNull()); - NL_TEST_ASSERT(inSuite, dst.validUntil.Value() == 2); + EXPECT_EQ(dst.offset, 1); + EXPECT_EQ(dst.validStarting, 1u); + EXPECT_FALSE(dst.validUntil.IsNull()); + EXPECT_EQ(dst.validUntil.Value(), 2u); dstObj.dstOffsetList = dstObj.dstOffsetList.SubSpan(1); } @@ -228,10 +234,10 @@ void TestDSTOffset(nlTestSuite * inSuite, void * inContext) if (!dstObj.dstOffsetList.empty()) { auto & dst = dstObj.dstOffsetList.data()[0]; - NL_TEST_ASSERT(inSuite, dst.offset == 2); - NL_TEST_ASSERT(inSuite, dst.validStarting == 2); - NL_TEST_ASSERT(inSuite, !dst.validUntil.IsNull()); - NL_TEST_ASSERT(inSuite, dst.validUntil.Value() == 3); + EXPECT_EQ(dst.offset, 2); + EXPECT_EQ(dst.validStarting, 2u); + EXPECT_FALSE(dst.validUntil.IsNull()); + EXPECT_EQ(dst.validUntil.Value(), 3u); dstObj.dstOffsetList = dstObj.dstOffsetList.SubSpan(1); } @@ -239,17 +245,17 @@ void TestDSTOffset(nlTestSuite * inSuite, void * inContext) if (!dstObj.dstOffsetList.empty()) { auto & dst = dstObj.dstOffsetList.data()[0]; - NL_TEST_ASSERT(inSuite, dst.offset == 3); - NL_TEST_ASSERT(inSuite, dst.validStarting == 3); - NL_TEST_ASSERT(inSuite, dst.validUntil.IsNull()); + EXPECT_EQ(dst.offset, 3); + EXPECT_EQ(dst.validStarting, 3u); + EXPECT_TRUE(dst.validUntil.IsNull()); dstObj.dstOffsetList = dstObj.dstOffsetList.SubSpan(1); } - NL_TEST_ASSERT(inSuite, dstObj.dstOffsetList.empty()); + EXPECT_TRUE(dstObj.dstOffsetList.empty()); } -void TestDSTOffsetEmpty(nlTestSuite * inSuite, void * inContext) +TEST_F(TestTimeSyncDataProvider, TestDSTOffsetEmpty) { TestPersistentStorageDelegate persistentStorage; TimeSyncDataProvider timeSyncDataProv; @@ -257,42 +263,9 @@ void TestDSTOffsetEmpty(nlTestSuite * inSuite, void * inContext) TimeSyncDataProvider::DSTOffsetObj dstObj; - NL_TEST_ASSERT(inSuite, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND == timeSyncDataProv.LoadDSTOffset(dstObj)); - NL_TEST_ASSERT(inSuite, !dstObj.dstOffsetList.begin()); - NL_TEST_ASSERT(inSuite, dstObj.validSize == 0); -} - -const nlTest sTests[] = { NL_TEST_DEF("Test TrustedTimeSource store load", TestTrustedTimeSourceStoreLoad), - NL_TEST_DEF("Test TrustedTimeSource empty", TestTrustedTimeSourceEmpty), - NL_TEST_DEF("Test default NTP store load", TestDefaultNTPStoreLoad), - NL_TEST_DEF("Test default NTP empty", TestDefaultNTPEmpty), - NL_TEST_DEF("Test time zone store load", TestTimeZoneStoreLoad), - NL_TEST_DEF("Test time zone (empty list)", TestTimeZoneEmpty), - NL_TEST_DEF("Test DSTOffset", TestDSTOffset), - NL_TEST_DEF("Test DSTOffset (empty list)", TestDSTOffsetEmpty), - NL_TEST_SENTINEL() }; - -int TestSetup(void * inContext) -{ - VerifyOrReturnError(CHIP_NO_ERROR == chip::Platform::MemoryInit(), FAILURE); - return SUCCESS; -} - -int TestTearDown(void * inContext) -{ - chip::Platform::MemoryShutdown(); - return SUCCESS; + EXPECT_EQ(CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND, timeSyncDataProv.LoadDSTOffset(dstObj)); + EXPECT_TRUE(dstObj.dstOffsetList.empty()); + EXPECT_EQ(dstObj.validSize, 0u); } } // namespace - -int TestTimeSyncDataProvider() -{ - nlTestSuite theSuite = { "Time Sync data provider tests", &sTests[0], TestSetup, TestTearDown }; - - // Run test suite against one context. - nlTestRunner(&theSuite, nullptr); - return nlTestRunnerStats(&theSuite); -} - -CHIP_REGISTER_TEST_SUITE(TestTimeSyncDataProvider) diff --git a/src/app/tests/TestWriteInteraction.cpp b/src/app/tests/TestWriteInteraction.cpp index 795c52a9030f99..7aa2dba303bf0f 100644 --- a/src/app/tests/TestWriteInteraction.cpp +++ b/src/app/tests/TestWriteInteraction.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -40,9 +41,6 @@ namespace { -uint8_t attributeDataTLV[CHIP_CONFIG_DEFAULT_UDP_MTU_SIZE]; -size_t attributeDataTLVLen = 0; -constexpr chip::DataVersion kRejectedDataVersion = 1; constexpr chip::DataVersion kAcceptedDataVersion = 5; constexpr uint16_t kMaxGroupsPerFabric = 5; constexpr uint16_t kMaxGroupKeysPerFabric = 8; @@ -363,28 +361,6 @@ void TestWriteInteraction::TestWriteHandler(nlTestSuite * apSuite, void * apCont } } -const EmberAfAttributeMetadata * GetAttributeMetadata(const ConcreteAttributePath & aConcreteClusterPath) -{ - // Note: This test does not make use of the real attribute metadata. - static EmberAfAttributeMetadata stub = { .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(uint32_t(0)) }; - return &stub; -} - -CHIP_ERROR WriteSingleClusterData(const Access::SubjectDescriptor & aSubjectDescriptor, const ConcreteDataAttributePath & aPath, - TLV::TLVReader & aReader, WriteHandler * aWriteHandler) -{ - if (aPath.mDataVersion.HasValue() && aPath.mDataVersion.Value() == kRejectedDataVersion) - { - return aWriteHandler->AddStatus(aPath, Protocols::InteractionModel::Status::DataVersionMismatch); - } - - TLV::TLVWriter writer; - writer.Init(attributeDataTLV); - writer.CopyElement(TLV::AnonymousTag(), aReader); - attributeDataTLVLen = writer.GetLengthWritten(); - return aWriteHandler->AddStatus(aPath, Protocols::InteractionModel::Status::Success); -} - void TestWriteInteraction::TestWriteRoundtripWithClusterObjects(nlTestSuite * apSuite, void * apContext) { TestContext & ctx = *static_cast(apContext); @@ -434,7 +410,7 @@ void TestWriteInteraction::TestWriteRoundtripWithClusterObjects(nlTestSuite * ap { app::Clusters::UnitTesting::Structs::SimpleStruct::Type dataRx; TLV::TLVReader reader; - reader.Init(attributeDataTLV, attributeDataTLVLen); + reader.Init(chip::Test::attributeDataTLV, chip::Test::attributeDataTLVLen); reader.Next(); NL_TEST_ASSERT(apSuite, CHIP_NO_ERROR == DataModel::Decode(reader, dataRx)); NL_TEST_ASSERT(apSuite, dataRx.a == dataTx.a); @@ -531,7 +507,7 @@ void TestWriteInteraction::TestWriteRoundtripWithClusterObjectsVersionMismatch(n dataTxValue.b = true; DataModel::Nullable dataTx; dataTx.SetNonNull(dataTxValue); - Optional version(kRejectedDataVersion); + Optional version(chip::Test::kRejectedDataVersion); writeClient.EncodeAttribute(attributePathParams, dataTx, version); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); diff --git a/src/app/tests/test-ember-api.cpp b/src/app/tests/test-ember-api.cpp new file mode 100644 index 00000000000000..2b630327a21897 --- /dev/null +++ b/src/app/tests/test-ember-api.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +chip::EndpointId chip::Test::numEndpoints = 0; + +// Used by the code in TestPowerSourceCluster.cpp (and generally things using mock ember functions may need this). +uint16_t emberAfGetClusterServerEndpointIndex(chip::EndpointId endpoint, chip::ClusterId cluster, + uint16_t fixedClusterServerEndpointCount) +{ + // Very simple mapping here, we're just going to return the endpoint that matches the given endpoint index because the test + // uses the endpoints in order. + if (endpoint >= chip::Test::numEndpoints) + { + return kEmberInvalidEndpointIndex; + } + return endpoint; +} diff --git a/src/app/tests/test-ember-api.h b/src/app/tests/test-ember-api.h new file mode 100644 index 00000000000000..66b1afc2ebe2f6 --- /dev/null +++ b/src/app/tests/test-ember-api.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include + +/// test-ember-api was created to consolidate and centralize stub functions that are related to ember and are used by the unit-tests + +namespace chip { +namespace Test { +extern chip::EndpointId numEndpoints; +} +} // namespace chip + +// Used by the code in TestPowerSourceCluster.cpp (and generally things using mock ember functions may need this). +uint16_t emberAfGetClusterServerEndpointIndex(chip::EndpointId endpoint, chip::ClusterId cluster, + uint16_t fixedClusterServerEndpointCount); diff --git a/src/app/tests/test-interaction-model-api.cpp b/src/app/tests/test-interaction-model-api.cpp new file mode 100644 index 00000000000000..ae3f559424f97c --- /dev/null +++ b/src/app/tests/test-interaction-model-api.cpp @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2024 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "lib/support/CHIPMem.h" +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace chip { +uint8_t Test::attributeDataTLV[CHIP_CONFIG_DEFAULT_UDP_MTU_SIZE]; +size_t Test::attributeDataTLVLen = 0; + +namespace app { + +// Used by the code in TestWriteInteraction.cpp (and generally tests that interact with the WriteHandler may need this). +const EmberAfAttributeMetadata * GetAttributeMetadata(const ConcreteAttributePath & aConcreteClusterPath) +{ + // Note: This test does not make use of the real attribute metadata. + static EmberAfAttributeMetadata stub = { .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(uint32_t(0)) }; + return &stub; +} + +// Used by the code in TestWriteInteraction.cpp (and generally tests that interact with the WriteHandler may need this). +CHIP_ERROR WriteSingleClusterData(const Access::SubjectDescriptor & aSubjectDescriptor, const ConcreteDataAttributePath & aPath, + TLV::TLVReader & aReader, WriteHandler * aWriteHandler) +{ + if (aPath.mDataVersion.HasValue() && aPath.mDataVersion.Value() == Test::kRejectedDataVersion) + { + return aWriteHandler->AddStatus(aPath, Protocols::InteractionModel::Status::DataVersionMismatch); + } + + TLV::TLVWriter writer; + writer.Init(chip::Test::attributeDataTLV); + writer.CopyElement(TLV::AnonymousTag(), aReader); + chip::Test::attributeDataTLVLen = writer.GetLengthWritten(); + return aWriteHandler->AddStatus(aPath, Protocols::InteractionModel::Status::Success); +} + +// Used by the code in TestAclAttribute.cpp (and generally tests that interact with the InteractionModelEngine may need this). +bool ConcreteAttributePathExists(const ConcreteAttributePath & aPath) +{ + return aPath.mClusterId != Test::kTestDeniedClusterId1; +} + +// Used by the code in TestAclAttribute.cpp (and generally tests that interact with the InteractionModelEngine may need this). +Protocols::InteractionModel::Status CheckEventSupportStatus(const ConcreteEventPath & aPath) +{ + if (aPath.mClusterId == Test::kTestDeniedClusterId1) + { + return Protocols::InteractionModel::Status::UnsupportedCluster; + } + + return Protocols::InteractionModel::Status::Success; +} + +// strong defintion in TestCommandInteraction.cpp +__attribute__((weak)) Protocols::InteractionModel::Status +ServerClusterCommandExists(const ConcreteCommandPath & aRequestCommandPath) +{ + // Mock cluster catalog, only support commands on one cluster on one endpoint. + using Protocols::InteractionModel::Status; + + return Status::Success; +} + +// strong defintion in TestCommandInteraction.cpp +__attribute__((weak)) void DispatchSingleClusterCommand(const ConcreteCommandPath & aRequestCommandPath, + chip::TLV::TLVReader & aReader, CommandHandler * apCommandObj) +{} + +// Used by the code in TestReadInteraction.cpp (and generally tests that interact with the Reporting Engine may need this). +bool IsClusterDataVersionEqual(const ConcreteClusterPath & aConcreteClusterPath, DataVersion aRequiredVersion) +{ + return (Test::kTestDataVersion1 == aRequiredVersion); +} + +// Used by the code in TestReadInteraction.cpp. +bool IsDeviceTypeOnEndpoint(DeviceTypeId deviceType, EndpointId endpoint) +{ + return false; +} + +// Used by the code in TestReadInteraction.cpp (and generally tests that interact with the Reporting Engine may need this). +CHIP_ERROR ReadSingleClusterData(const Access::SubjectDescriptor & aSubjectDescriptor, bool aIsFabricFiltered, + const ConcreteReadAttributePath & aPath, AttributeReportIBs::Builder & aAttributeReports, + AttributeEncodeState * apEncoderState) +{ + if (aPath.mClusterId >= Test::kMockEndpointMin) + { + return Test::ReadSingleMockClusterData(aSubjectDescriptor.fabricIndex, aPath, aAttributeReports, apEncoderState); + } + + if (!(aPath.mClusterId == Test::kTestClusterId && aPath.mEndpointId == Test::kTestEndpointId)) + { + AttributeReportIB::Builder & attributeReport = aAttributeReports.CreateAttributeReport(); + ReturnErrorOnFailure(aAttributeReports.GetError()); + ChipLogDetail(DataManagement, "TEST Cluster %" PRIx32 ", Field %" PRIx32 " is dirty", aPath.mClusterId, aPath.mAttributeId); + + AttributeStatusIB::Builder & attributeStatus = attributeReport.CreateAttributeStatus(); + ReturnErrorOnFailure(attributeReport.GetError()); + AttributePathIB::Builder & attributePath = attributeStatus.CreatePath(); + ReturnErrorOnFailure(attributeStatus.GetError()); + + attributePath.Endpoint(aPath.mEndpointId).Cluster(aPath.mClusterId).Attribute(aPath.mAttributeId).EndOfAttributePathIB(); + ReturnErrorOnFailure(attributePath.GetError()); + StatusIB::Builder & errorStatus = attributeStatus.CreateErrorStatus(); + ReturnErrorOnFailure(attributeStatus.GetError()); + errorStatus.EncodeStatusIB(StatusIB(Protocols::InteractionModel::Status::UnsupportedAttribute)); + ReturnErrorOnFailure(errorStatus.GetError()); + ReturnErrorOnFailure(attributeStatus.EndOfAttributeStatusIB()); + return attributeReport.EndOfAttributeReportIB(); + } + + return AttributeValueEncoder(aAttributeReports, aSubjectDescriptor, aPath, 0 /* dataVersion */).Encode(Test::kTestFieldValue1); +} + +} // namespace app + +} // namespace chip diff --git a/src/app/tests/test-interaction-model-api.h b/src/app/tests/test-interaction-model-api.h new file mode 100644 index 00000000000000..88e861b267b63b --- /dev/null +++ b/src/app/tests/test-interaction-model-api.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2024 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +/// test-interaction-model-api was created to consolidate and centralize stub functions that are used by the Interaction Model +/// during unit-testing. + +#include +#include +#include +#include +#include +#include + +namespace chip { + +namespace Test { + +constexpr chip::ClusterId kTestDeniedClusterId1 = 1000; +constexpr chip::ClusterId kTestDeniedClusterId2 = 3; + +constexpr chip::ClusterId kTestClusterId = 6; +constexpr uint8_t kTestFieldValue1 = 1; +constexpr chip::EndpointId kTestEndpointId = 1; +constexpr chip::DataVersion kTestDataVersion1 = 3; + +constexpr chip::DataVersion kRejectedDataVersion = 1; +extern uint8_t attributeDataTLV[CHIP_CONFIG_DEFAULT_UDP_MTU_SIZE]; +extern size_t attributeDataTLVLen; + +} // namespace Test +namespace app { + +CHIP_ERROR ReadSingleClusterData(const Access::SubjectDescriptor & aSubjectDescriptor, bool aIsFabricFiltered, + const ConcreteReadAttributePath & aPath, AttributeReportIBs::Builder & aAttributeReports, + AttributeEncodeState * apEncoderState); + +bool IsClusterDataVersionEqual(const ConcreteClusterPath & aConcreteClusterPath, DataVersion aRequiredVersion); + +CHIP_ERROR WriteSingleClusterData(const Access::SubjectDescriptor & aSubjectDescriptor, const ConcreteDataAttributePath & aPath, + TLV::TLVReader & aReader, WriteHandler * aWriteHandler); +const EmberAfAttributeMetadata * GetAttributeMetadata(const ConcreteAttributePath & aConcreteClusterPath); + +bool ConcreteAttributePathExists(const ConcreteAttributePath & aPath); +Protocols::InteractionModel::Status CheckEventSupportStatus(const ConcreteEventPath & aPath); + +Protocols::InteractionModel::Status ServerClusterCommandExists(const ConcreteCommandPath & aRequestCommandPath); + +void DispatchSingleClusterCommand(const ConcreteCommandPath & aRequestCommandPath, chip::TLV::TLVReader & aReader, + CommandHandler * apCommandObj); + +bool IsDeviceTypeOnEndpoint(DeviceTypeId deviceType, EndpointId endpoint); + +} // namespace app +} // namespace chip diff --git a/src/test_driver/openiotsdk/unit-tests/test_components.txt b/src/test_driver/openiotsdk/unit-tests/test_components.txt index 35ba62bc492d6d..54f47dfa47c557 100644 --- a/src/test_driver/openiotsdk/unit-tests/test_components.txt +++ b/src/test_driver/openiotsdk/unit-tests/test_components.txt @@ -20,4 +20,5 @@ SecureChannelTests ICDServerTests DataModelTests InetLayerTests +AppTests MessagingLayerTests diff --git a/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt b/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt index d57fda14efe12f..925be3fdd2b499 100644 --- a/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt +++ b/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt @@ -1,2 +1,2 @@ -AppTests +AppTestsNL SecureChannelTestsNL