Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mwswartwout committed Feb 15, 2024
1 parent 4d7bb97 commit 3855b65
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/app/ReadClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ CHIP_ERROR ReadClient::ProcessAttributeReportIBs(TLV::TLVReader & aAttributeRepo
attributePath.mListOp = ConcreteDataAttributePath::ListOperation::ReplaceAll;
}

if (attributePath.MatchesConcreteAttributePath(ConcreteDataAttributePath(
if (attributePath.MatchesConcreteAttributePath(ConcreteAttributePath(
kRootEndpointId, Clusters::IcdManagement::Id, Clusters::IcdManagement::Attributes::OperatingMode::Id)))
{
PeerType peerType;
Expand Down
1 change: 1 addition & 0 deletions src/app/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ chip_test_suite_using_nltest("tests") {
"TestClusterInfo.cpp",
"TestCommandInteraction.cpp",
"TestCommandPathParams.cpp",
"TestConcreteAttributePath.cpp",
"TestDataModelSerialization.cpp",
"TestDefaultOTARequestorStorage.cpp",
"TestEventLoggingNoUTCTime.cpp",
Expand Down
89 changes: 89 additions & 0 deletions src/app/tests/TestConcreteAttributePath.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* 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 <app/ConcreteAttributePath.h>
#include <lib/support/UnitTestRegistration.h>
#include <nlunit-test.h>

using namespace chip;
using namespace chip::app;

namespace {

void TestConcreteAttributePathEqualityDefaultConstructor(nlTestSuite * aSuite, void * aContext)
{
ConcreteAttributePath path_one;
ConcreteAttributePath path_two;
NL_TEST_ASSERT(aSuite, path_one == path_two);
}

void TestConcreteAttributePathEquality(nlTestSuite * aSuite, void * aContext)
{
ConcreteAttributePath path_one(/*aEndpointId=*/1, /*aClusterId=*/2, /*aAttributeId=*/3);
ConcreteAttributePath path_two(/*aEndpointId=*/1, /*aClusterId=*/2, /*aAttributeId=*/3);
NL_TEST_ASSERT(aSuite, path_one == path_two);
}

void TestConcreteAttributePathInequalityDifferentAttributeId(nlTestSuite * aSuite, void * aContext)
{
ConcreteAttributePath path_one(/*aEndpointId=*/1, /*aClusterId=*/2, /*aAttributeId=*/3);
ConcreteAttributePath path_two(/*aEndpointId=*/1, /*aClusterId=*/2, /*aAttributeId=*/4);
NL_TEST_ASSERT(aSuite, path_one != path_two);
}

void TestConcreteDataAttributePathMatchesConcreteAttributePathEquality(nlTestSuite* aSuite, void* aContext) {
ConcreteAttributePath path(/*aEndpointId=*/1, /*aClusterId=*/2, /*aAttributeId=*/3);
ConcreteDataAttributePath data_path(/*aEndpointId=*/1, /*aClusterId=*/2, /*aAttributeId=*/3);
ConcreteDataAttributePath data_path_with_version(/*aEndpointId=*/1, /*aClusterId=*/2, /*aAttributeId=*/3, /*aDataVersion=*/MakeOptional(4U));
ConcreteDataAttributePath data_path_with_list(/*aEndpointId=*/1, /*aClusterId=*/2, /*aAttributeId=*/3, /*aListOp=*/ ConcreteDataAttributePath::ListOperation::ReplaceAll, /*aListIndex=*/ 5U);

NL_TEST_ASSERT(aSuite, data_path.MatchesConcreteAttributePath(path));
NL_TEST_ASSERT(aSuite, data_path_with_version.MatchesConcreteAttributePath(path));
NL_TEST_ASSERT(aSuite, data_path_with_list.MatchesConcreteAttributePath(path));
}

void TestConcreteDataAttributePathMatchesConcreteAttributePathInequality(nlTestSuite* aSuite, void* aContext) {
ConcreteAttributePath path(/*aEndpointId=*/1, /*aClusterId=*/2, /*aAttributeId=*/3);
ConcreteDataAttributePath data_path(/*aEndpointId=*/1, /*aClusterId=*/2, /*aAttributeId=*/4);

NL_TEST_ASSERT(aSuite, !data_path.MatchesConcreteAttributePath(path));
}

const nlTest sTests[] = {
NL_TEST_DEF("TestConcreteAttributePathEqualityDefaultConstructor", TestConcreteAttributePathEqualityDefaultConstructor),
NL_TEST_DEF("TestConcreteAttributePathEquality", TestConcreteAttributePathEquality),
NL_TEST_DEF("TestConcreteAttributePathInequalityDifferentAttributeId", TestConcreteAttributePathInequalityDifferentAttributeId),
NL_TEST_DEF("TestConcreteDataAttributePathMatchesConcreteAttributePathEquality",
TestConcreteDataAttributePathMatchesConcreteAttributePathEquality),
NL_TEST_DEF("TestConcreteDataAttributePathMatchesConcreteAttributePathInequality",
TestConcreteDataAttributePathMatchesConcreteAttributePathInequality),
NL_TEST_SENTINEL()
};

} // anonymous namespace

int TestConcreteAttributePath()
{
nlTestSuite theSuite = { "ConcreteAttributePath", &sTests[0], nullptr, nullptr };

nlTestRunner(&theSuite, nullptr);

return (nlTestRunnerStats(&theSuite));
}

CHIP_REGISTER_TEST_SUITE(TestConcreteAttributePath)

0 comments on commit 3855b65

Please sign in to comment.