| /* |
| * Copyright (c) 2025 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 <pw_unit_test/framework.h> |
| |
| #include <app/clusters/bindings/BindingCluster.h> |
| #include <app/data-model-provider/MetadataTypes.h> |
| #include <app/server-cluster/DefaultServerCluster.h> |
| #include <app/server-cluster/testing/AttributeTesting.h> |
| #include <clusters/Binding/Enums.h> |
| #include <clusters/Binding/Metadata.h> |
| #include <lib/core/CHIPError.h> |
| #include <lib/core/DataModelTypes.h> |
| #include <lib/support/ReadOnlyBuffer.h> |
| |
| namespace { |
| |
| using namespace chip; |
| using namespace chip::app::Clusters; |
| using namespace chip::app::Clusters::Binding; |
| |
| using chip::app::DataModel::AcceptedCommandEntry; |
| using chip::app::DataModel::AttributeEntry; |
| |
| // initialize memory as ReadOnlyBufferBuilder may allocate |
| struct TestBindingCluster : public ::testing::Test |
| { |
| static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); } |
| static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); } |
| }; |
| |
| TEST_F(TestBindingCluster, TestAttributes) |
| { |
| BindingCluster cluster(1); |
| |
| ReadOnlyBufferBuilder<AttributeEntry> builder; |
| ASSERT_EQ(cluster.Attributes({ 1, Binding::Id }, builder), CHIP_NO_ERROR); |
| |
| ReadOnlyBufferBuilder<AttributeEntry> expectedBuilder; |
| ASSERT_EQ(expectedBuilder.AppendElements({ Binding::Attributes::Binding::kMetadataEntry }), CHIP_NO_ERROR); |
| ASSERT_EQ(expectedBuilder.ReferenceExisting(app::DefaultServerCluster::GlobalAttributes()), CHIP_NO_ERROR); |
| |
| ASSERT_TRUE(Testing::EqualAttributeSets(builder.TakeBuffer(), expectedBuilder.TakeBuffer())); |
| } |
| |
| } // namespace |