| /* |
| * |
| * Copyright (c) 2026 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 "PowerSourceClusterTestCommon.h" |
| |
| #include <app/server-cluster/AttributeListBuilder.h> |
| #include <app/server-cluster/testing/ClusterTester.h> |
| #include <app/server-cluster/testing/ValidateGlobalAttributes.h> |
| #include <clusters/PowerSource/Metadata.h> |
| |
| namespace { |
| |
| using namespace chip; |
| using namespace chip::app; |
| using namespace chip::app::Clusters; |
| using namespace chip::app::Clusters::PowerSource; |
| using namespace chip::app::Clusters::PowerSource::Attributes; |
| using namespace chip::Testing; |
| using namespace chip::app::Clusters::PowerSource::TestSupport; |
| |
| struct TestMinimalBatteryPowerSourceCluster : public TestBase |
| { |
| }; |
| |
| TEST_F(TestMinimalBatteryPowerSourceCluster, AttributeTest) |
| { |
| MinimalBatteryPowerSourceConfig config(CharSpan{}, BatReplaceabilityEnum::kUnspecified, timerDelegate); |
| MinimalBatteryPowerSourceCluster cluster(kTestEndpointId, config); |
| ASSERT_EQ(cluster.Startup(testContext.Get()), CHIP_NO_ERROR); |
| |
| EXPECT_TRUE(IsAttributesListEqualTo(cluster, |
| { Status::kMetadataEntry, Order::kMetadataEntry, Description::kMetadataEntry, |
| BatChargeLevel::kMetadataEntry, BatReplacementNeeded::kMetadataEntry, |
| BatReplaceability::kMetadataEntry, EndpointList::kMetadataEntry })); |
| |
| cluster.Shutdown(ClusterShutdownType::kClusterShutdown); |
| } |
| |
| TEST_F(TestMinimalBatteryPowerSourceCluster, ReadAttributeTest) |
| { |
| MinimalBatteryPowerSourceConfig config(CharSpan{}, BatReplaceabilityEnum::kUnspecified, timerDelegate); |
| MinimalBatteryPowerSourceCluster cluster(kTestEndpointId, config); |
| ASSERT_EQ(cluster.Startup(testContext.Get()), CHIP_NO_ERROR); |
| |
| ClusterTester tester(cluster); |
| ReadAttribute<Status::TypeInfo>(tester); |
| ReadAttribute<Order::TypeInfo>(tester); |
| ReadAttribute<Description::TypeInfo>(tester); |
| ReadAttribute<BatChargeLevel::TypeInfo>(tester); |
| ReadAttribute<BatReplacementNeeded::TypeInfo>(tester); |
| ReadAttribute<BatReplaceability::TypeInfo>(tester); |
| ReadAttribute<EndpointList::TypeInfo>(tester); |
| |
| cluster.Shutdown(ClusterShutdownType::kClusterShutdown); |
| } |
| |
| TEST_F(TestMinimalBatteryPowerSourceCluster, TestGetters) |
| { |
| MinimalBatteryPowerSourceConfig config(CharSpan{}, BatReplaceabilityEnum::kUnspecified, timerDelegate); |
| MinimalBatteryPowerSourceCluster cluster(kTestEndpointId, config); |
| |
| cluster.GetStatus(); |
| cluster.GetOrder(); |
| cluster.GetDescription(); |
| cluster.GetBatChargeLevel(); |
| cluster.GetBatReplacementNeeded(); |
| cluster.GetBatReplaceability(); |
| cluster.GetEndpointList(); |
| } |
| |
| TEST_F(TestMinimalBatteryPowerSourceCluster, TestSetters) |
| { |
| MinimalBatteryPowerSourceConfig config(CharSpan{}, BatReplaceabilityEnum::kUnspecified, timerDelegate); |
| MinimalBatteryPowerSourceCluster cluster(kTestEndpointId, config); |
| |
| EXPECT_EQ(cluster.SetStatus({}), CHIP_NO_ERROR); |
| cluster.SetOrder({}); |
| EXPECT_EQ(cluster.SetBatChargeLevel({}), CHIP_NO_ERROR); |
| cluster.SetBatReplacementNeeded({}); |
| EXPECT_EQ(cluster.SetEndpointList({}), CHIP_NO_ERROR); |
| } |
| |
| TEST_F(TestMinimalBatteryPowerSourceCluster, TestBounds) |
| { |
| CharSpan longTestText = |
| "Very very long text used for descriptions and designations, totally longer than one hundred bytes. For testing purposes"_span; |
| |
| MinimalBatteryPowerSourceConfig config(longTestText, BatReplaceabilityEnum::kUnspecified, timerDelegate); |
| MinimalBatteryPowerSourceCluster cluster(kTestEndpointId, config); |
| ClusterTester tester(cluster); |
| TestStringAttributeReadLength<Description::TypeInfo>(tester); |
| } |
| |
| } // namespace |