|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright (c) 2024 Project CHIP Authors |
| 4 | + * All rights reserved. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +#include <app/ConcreteAttributePath.h> |
| 20 | +#include <lib/support/UnitTestRegistration.h> |
| 21 | +#include <nlunit-test.h> |
| 22 | + |
| 23 | +using namespace chip; |
| 24 | +using namespace chip::app; |
| 25 | + |
| 26 | +namespace { |
| 27 | + |
| 28 | +void TestConcreteAttributePathEqualityDefaultConstructor(nlTestSuite * aSuite, void * aContext) |
| 29 | +{ |
| 30 | + ConcreteAttributePath path_one; |
| 31 | + ConcreteAttributePath path_two; |
| 32 | + NL_TEST_ASSERT(aSuite, path_one == path_two); |
| 33 | +} |
| 34 | + |
| 35 | +void TestConcreteAttributePathEquality(nlTestSuite * aSuite, void * aContext) |
| 36 | +{ |
| 37 | + ConcreteAttributePath path_one(/*aEndpointId=*/1, /*aClusterId=*/2, /*aAttributeId=*/3); |
| 38 | + ConcreteAttributePath path_two(/*aEndpointId=*/1, /*aClusterId=*/2, /*aAttributeId=*/3); |
| 39 | + NL_TEST_ASSERT(aSuite, path_one == path_two); |
| 40 | +} |
| 41 | + |
| 42 | +void TestConcreteAttributePathInequalityDifferentAttributeId(nlTestSuite * aSuite, void * aContext) |
| 43 | +{ |
| 44 | + ConcreteAttributePath path_one(/*aEndpointId=*/1, /*aClusterId=*/2, /*aAttributeId=*/3); |
| 45 | + ConcreteAttributePath path_two(/*aEndpointId=*/1, /*aClusterId=*/2, /*aAttributeId=*/4); |
| 46 | + NL_TEST_ASSERT(aSuite, path_one != path_two); |
| 47 | +} |
| 48 | + |
| 49 | +void TestConcreteDataAttributePathMatchesConcreteAttributePathEquality(nlTestSuite * aSuite, void * aContext) |
| 50 | +{ |
| 51 | + ConcreteAttributePath path(/*aEndpointId=*/1, /*aClusterId=*/2, /*aAttributeId=*/3); |
| 52 | + ConcreteDataAttributePath data_path(/*aEndpointId=*/1, /*aClusterId=*/2, /*aAttributeId=*/3); |
| 53 | + ConcreteDataAttributePath data_path_with_version(/*aEndpointId=*/1, /*aClusterId=*/2, /*aAttributeId=*/3, |
| 54 | + /*aDataVersion=*/MakeOptional(4U)); |
| 55 | + ConcreteDataAttributePath data_path_with_list(/*aEndpointId=*/1, /*aClusterId=*/2, /*aAttributeId=*/3, |
| 56 | + /*aListOp=*/ConcreteDataAttributePath::ListOperation::ReplaceAll, |
| 57 | + /*aListIndex=*/5U); |
| 58 | + |
| 59 | + NL_TEST_ASSERT(aSuite, data_path.MatchesConcreteAttributePath(path)); |
| 60 | + NL_TEST_ASSERT(aSuite, data_path_with_version.MatchesConcreteAttributePath(path)); |
| 61 | + NL_TEST_ASSERT(aSuite, data_path_with_list.MatchesConcreteAttributePath(path)); |
| 62 | +} |
| 63 | + |
| 64 | +void TestConcreteDataAttributePathMatchesConcreteAttributePathInequality(nlTestSuite * aSuite, void * aContext) |
| 65 | +{ |
| 66 | + ConcreteAttributePath path(/*aEndpointId=*/1, /*aClusterId=*/2, /*aAttributeId=*/3); |
| 67 | + ConcreteDataAttributePath data_path(/*aEndpointId=*/1, /*aClusterId=*/2, /*aAttributeId=*/4); |
| 68 | + |
| 69 | + NL_TEST_ASSERT(aSuite, !data_path.MatchesConcreteAttributePath(path)); |
| 70 | +} |
| 71 | + |
| 72 | +const nlTest sTests[] = { |
| 73 | + NL_TEST_DEF("TestConcreteAttributePathEqualityDefaultConstructor", TestConcreteAttributePathEqualityDefaultConstructor), |
| 74 | + NL_TEST_DEF("TestConcreteAttributePathEquality", TestConcreteAttributePathEquality), |
| 75 | + NL_TEST_DEF("TestConcreteAttributePathInequalityDifferentAttributeId", TestConcreteAttributePathInequalityDifferentAttributeId), |
| 76 | + NL_TEST_DEF("TestConcreteDataAttributePathMatchesConcreteAttributePathEquality", |
| 77 | + TestConcreteDataAttributePathMatchesConcreteAttributePathEquality), |
| 78 | + NL_TEST_DEF("TestConcreteDataAttributePathMatchesConcreteAttributePathInequality", |
| 79 | + TestConcreteDataAttributePathMatchesConcreteAttributePathInequality), |
| 80 | + NL_TEST_SENTINEL() |
| 81 | +}; |
| 82 | + |
| 83 | +} // anonymous namespace |
| 84 | + |
| 85 | +int TestConcreteAttributePath() |
| 86 | +{ |
| 87 | + nlTestSuite theSuite = { "ConcreteAttributePath", &sTests[0], nullptr, nullptr }; |
| 88 | + |
| 89 | + nlTestRunner(&theSuite, nullptr); |
| 90 | + |
| 91 | + return (nlTestRunnerStats(&theSuite)); |
| 92 | +} |
| 93 | + |
| 94 | +CHIP_REGISTER_TEST_SUITE(TestConcreteAttributePath) |
0 commit comments