Skip to content

Commit

Permalink
Delete Concrete(Read|Data)AttributePath equality operator (project-ch…
Browse files Browse the repository at this point in the history
…ip#32131)

* Delete Concrete(Read|Data)AttributePath equality operator

Right now these default to using the ConcreteAttributePath equality
operator, which is misleading because it will return true for objects
which are not actually equal.

Replace this with the MatchesConcreteAttributePath
function.

A new equality operator for these classes will be introduced in a
follow-up PR. I'm introducing this change separately to ensure that CI
catches any current usage of the equality operator.

* Restyled by clang-format

* Add unit tests

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
mwswartwout and restyled-commits committed Feb 23, 2024
1 parent ccdc4d3 commit 3965549
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/app/ConcreteAttributePath.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ struct ConcreteReadAttributePath : public ConcreteAttributePath

bool operator!=(const ConcreteReadAttributePath & aOther) const { return !(*this == aOther); }

bool operator<(const ConcreteReadAttributePath & path) const = delete;

bool operator==(const ConcreteReadAttributePath & aOther) const = delete;
bool operator!=(const ConcreteReadAttributePath & aOther) const = delete;
bool operator<(const ConcreteReadAttributePath & aOther) const = delete;
bool operator<(const ConcreteReadAttributePath & aOther) const = delete;

Optional<uint16_t> mListIndex;
};
Expand Down Expand Up @@ -159,7 +155,7 @@ struct ConcreteDataAttributePath : public ConcreteAttributePath

bool operator!=(const ConcreteDataAttributePath & aOther) const { return !(*this == aOther); }

bool operator<(const ConcreteDataAttributePath & path) const = delete;
bool operator<(const ConcreteDataAttributePath & aOther) const = delete;

//
// This index is only valid if `mListOp` is set to a list item operation, i.e
Expand Down
27 changes: 27 additions & 0 deletions src/app/tests/TestConcreteAttributePath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,29 @@ void TestConcreteDataAttributePathInequalityDifferentListIndex(nlTestSuite * aSu
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", TestConcreteAttributePathDefaultConstructorEquality),
NL_TEST_DEF("TestConcreteAttributePathEquality", TestConcreteAttributePathEquality),
Expand All @@ -132,6 +155,10 @@ const nlTest sTests[] = {
NL_TEST_DEF("TestConcreteDataAttributePathInequalityDifferentListOp", TestConcreteDataAttributePathInequalityDifferentListOp),
NL_TEST_DEF("TestConcreteDataAttributePathInequalityDifferentListIndex",
TestConcreteDataAttributePathInequalityDifferentListIndex),
NL_TEST_DEF("TestConcreteDataAttributePathMatchesConcreteAttributePathEquality",
TestConcreteDataAttributePathMatchesConcreteAttributePathEquality),
NL_TEST_DEF("TestConcreteDataAttributePathMatchesConcreteAttributePathInequality",
TestConcreteDataAttributePathMatchesConcreteAttributePathInequality),
NL_TEST_SENTINEL()
};

Expand Down

0 comments on commit 3965549

Please sign in to comment.