| /* |
| * |
| * Copyright (c) 2023 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/clusters/scenes-server/SceneTableImpl.h> |
| #include <app/util/attribute-metadata.h> |
| #include <app/util/mock/Constants.h> |
| #include <app/util/mock/Functions.h> |
| #include <app/util/mock/MockNodeConfig.h> |
| #include <app/util/odd-sized-integers.h> |
| #include <crypto/DefaultSessionKeystore.h> |
| #include <lib/core/TLV.h> |
| #include <lib/support/Span.h> |
| #include <lib/support/TestPersistentStorageDelegate.h> |
| |
| #include <lib/core/StringBuilderAdapters.h> |
| #include <pw_unit_test/framework.h> |
| using namespace chip; |
| using namespace chip::Test; |
| using namespace chip::app::Clusters::Globals::Attributes; |
| |
| using SceneTable = scenes::SceneTable<scenes::ExtensionFieldSetsImpl>; |
| using SceneTableEntry = scenes::DefaultSceneTableImpl::SceneTableEntry; |
| using SceneTableImpl = scenes::DefaultSceneTableImpl; |
| using SceneStorageId = scenes::DefaultSceneTableImpl::SceneStorageId; |
| using SceneData = scenes::DefaultSceneTableImpl::SceneData; |
| using ExtensionFieldSet = scenes::ExtensionFieldSet; |
| using TransitionTimeMs = scenes::TransitionTimeMs; |
| |
| namespace TestScenes { |
| |
| // TestTableSize |
| constexpr uint8_t defaultTestTableSize = 16; |
| constexpr uint8_t defaultTestFabricCapacity = (defaultTestTableSize - 1) / 2; |
| |
| // Test Cluster ID |
| constexpr chip::ClusterId kOnOffClusterId = 0x0006; |
| constexpr chip::ClusterId kLevelControlClusterId = 0x0008; |
| constexpr chip::ClusterId kFakeClusterId = 0x0007; |
| constexpr chip::ClusterId kColorControlClusterId = 0x0300; |
| constexpr chip::ClusterId kScenesClusterId = 0x0062; |
| |
| // Test Endpoint ID |
| constexpr chip::EndpointId kTestEndpoint1 = chip::Test::kMockEndpoint1; |
| constexpr chip::EndpointId kTestEndpoint2 = chip::Test::kMockEndpoint2; |
| constexpr chip::EndpointId kTestEndpoint3 = chip::Test::kMockEndpoint3; |
| constexpr chip::EndpointId kTestEndpoint4 = kMockEndpointMin; |
| |
| // Test Attribute ID |
| constexpr uint32_t kOnOffAttId = app::Clusters::OnOff::Attributes::OnOff::Id; |
| constexpr uint32_t kCurrentLevelId = app::Clusters::LevelControl::Attributes::CurrentLevel::Id; |
| constexpr uint32_t kCurrentFrequencyId = app::Clusters::LevelControl::Attributes::CurrentFrequency::Id; |
| constexpr uint32_t kCurrentSaturationId = app::Clusters::ColorControl::Attributes::CurrentSaturation::Id; |
| constexpr uint32_t kCurrentXId = app::Clusters::ColorControl::Attributes::CurrentX::Id; |
| constexpr uint32_t kCurrentYId = app::Clusters::ColorControl::Attributes::CurrentY::Id; |
| constexpr uint32_t kColorTemperatureMiredsId = app::Clusters::ColorControl::Attributes::ColorTemperatureMireds::Id; |
| constexpr uint32_t kEnhancedCurrentHueId = app::Clusters::ColorControl::Attributes::EnhancedCurrentHue::Id; |
| constexpr uint32_t kEnhancedColorMode = app::Clusters::ColorControl::Attributes::EnhancedColorMode::Id; |
| constexpr uint32_t kColorLoopActiveId = app::Clusters::ColorControl::Attributes::ColorLoopActive::Id; |
| constexpr uint32_t kColorLoopDirectionId = app::Clusters::ColorControl::Attributes::ColorLoopDirection::Id; |
| constexpr uint32_t kColorLoopTimeId = app::Clusters::ColorControl::Attributes::ColorLoopTime::Id; |
| |
| // Test Group ID |
| constexpr chip::GroupId kGroup1 = 0x101; |
| constexpr chip::GroupId kGroup2 = 0x102; |
| constexpr chip::GroupId kGroup3 = 0x103; |
| constexpr chip::GroupId kGroup4 = 0x00; |
| |
| // Test Scene ID |
| constexpr chip::SceneId kScene1 = 0xAA; |
| constexpr chip::SceneId kScene2 = 0x45; |
| constexpr chip::SceneId kScene3 = 0x77; |
| constexpr chip::SceneId kScene4 = 0xED; |
| constexpr chip::SceneId kScene5 = 0xDE; |
| constexpr chip::SceneId kScene6 = 0xAB; |
| constexpr chip::SceneId kScene7 = 0xBB; |
| constexpr chip::SceneId kScene8 = 0x22; |
| |
| // Test fabrics, adding more requires to modify the "ResetSceneTable" function |
| constexpr chip::FabricIndex kFabric1 = 1; |
| constexpr chip::FabricIndex kFabric2 = 7; |
| constexpr chip::FabricIndex kFabric3 = 77; |
| |
| // Scene storage ID |
| static const SceneStorageId sceneId1(kScene1, kGroup1); |
| static const SceneStorageId sceneId2(kScene2, kGroup1); |
| static const SceneStorageId sceneId3(kScene3, kGroup1); |
| static const SceneStorageId sceneId4(kScene4, kGroup1); |
| static const SceneStorageId sceneId5(kScene5, kGroup2); |
| static const SceneStorageId sceneId6(kScene6, kGroup2); |
| static const SceneStorageId sceneId7(kScene7, kGroup3); |
| static const SceneStorageId sceneId8(kScene8, kGroup4); |
| static const SceneStorageId sceneId9(kScene1, kGroup4); |
| static const SceneStorageId sceneId10(kScene4, kGroup4); |
| static const SceneStorageId sceneId11(kScene5, kGroup4); |
| static const SceneStorageId sceneId12(kScene6, kGroup4); |
| |
| CharSpan empty; |
| |
| // Scene data |
| static const SceneData sceneData1("Scene #1"_span); |
| static const SceneData sceneData2("Scene #2"_span, 2000); |
| static const SceneData sceneData3("Scene #3"_span, 250); |
| static const SceneData sceneData4("Scene num4"_span, 5000); |
| static const SceneData sceneData5(empty); |
| static const SceneData sceneData6("Scene #6"_span, 3000); |
| static const SceneData sceneData7("Scene #7"_span, 20000); |
| static const SceneData sceneData8("NAME TOO LOOONNG!"_span, 15000); |
| static const SceneData sceneData9("Scene #9"_span, 3000); |
| static const SceneData sceneData10("Scene #10"_span, 1000); |
| static const SceneData sceneData11("Scene #11"_span, 50); |
| static const SceneData sceneData12("Scene #12"_span, 100); |
| static const SceneData sceneData13("Scene #13"_span, 100); |
| static const SceneData sceneData14("Scene #14"_span, 100); |
| static const SceneData sceneData15("Scene #15"_span, 100); |
| |
| // Scenes |
| SceneTableEntry scene1(sceneId1, sceneData1); |
| SceneTableEntry scene2(sceneId2, sceneData2); |
| SceneTableEntry scene3(sceneId3, sceneData3); |
| SceneTableEntry scene4(sceneId4, sceneData4); |
| SceneTableEntry scene5(sceneId5, sceneData5); |
| SceneTableEntry scene6(sceneId6, sceneData6); |
| SceneTableEntry scene7(sceneId7, sceneData7); |
| SceneTableEntry scene8(sceneId8, sceneData8); |
| SceneTableEntry scene9(sceneId9, sceneData9); |
| SceneTableEntry scene10(sceneId1, sceneData10); |
| SceneTableEntry scene11(sceneId5, sceneData11); |
| SceneTableEntry scene12(sceneId7, sceneData12); |
| SceneTableEntry scene13(sceneId10, sceneData13); |
| SceneTableEntry scene14(sceneId11, sceneData14); |
| SceneTableEntry scene15(sceneId12, sceneData15); |
| |
| // Clusters EFS data |
| static app::Clusters::ScenesManagement::Structs::ExtensionFieldSet::Type OOextensionFieldSet; |
| static app::Clusters::ScenesManagement::Structs::ExtensionFieldSet::Type LCextensionFieldSet; |
| static app::Clusters::ScenesManagement::Structs::ExtensionFieldSet::Type CCextensionFieldSet; |
| |
| static app::Clusters::ScenesManagement::Structs::AttributeValuePairStruct::Type OOPairs[1]; |
| static app::Clusters::ScenesManagement::Structs::AttributeValuePairStruct::Type LCPairs[2]; |
| static app::Clusters::ScenesManagement::Structs::AttributeValuePairStruct::Type CCPairs[9]; |
| |
| static uint8_t OO_buffer[scenes::kMaxFieldBytesPerCluster] = { 0 }; |
| static uint8_t LC_buffer[scenes::kMaxFieldBytesPerCluster] = { 0 }; |
| static uint8_t CC_buffer[scenes::kMaxFieldBytesPerCluster] = { 0 }; |
| |
| static uint32_t OO_buffer_serialized_length = 0; |
| static uint32_t LC_buffer_serialized_length = 0; |
| static uint32_t CC_buffer_serialized_length = 0; |
| |
| static const uint8_t defaultValueData64[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
| |
| static EmberAfAttributeMinMaxValue minMaxValueBool = { false, false, true }; |
| static EmberAfAttributeMinMaxValue minMaxValue8 = { static_cast<uint8_t>(0), static_cast<uint8_t>(1), static_cast<uint8_t>(0xFE) }; |
| static EmberAfAttributeMinMaxValue minMaxValue8S = { static_cast<uint8_t>(0), static_cast<uint8_t>(-1), |
| static_cast<uint8_t>(0x7F) }; |
| static EmberAfAttributeMinMaxValue minMaxValue16S = { static_cast<uint16_t>(0), static_cast<uint16_t>(-1), |
| static_cast<uint16_t>(0x7FFD) }; |
| |
| static EmberAfAttributeMetadata mockMetadataBool = { |
| .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(&minMaxValueBool), |
| .attributeId = 0, |
| .size = 1, |
| .attributeType = ZCL_BOOLEAN_ATTRIBUTE_TYPE, |
| .mask = ATTRIBUTE_MASK_WRITABLE, |
| }; |
| |
| static EmberAfAttributeMetadata mockMetadataUint8 = { |
| .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(static_cast<uint8_t>(0)), |
| .attributeId = 0, |
| .size = 1, |
| .attributeType = ZCL_INT8U_ATTRIBUTE_TYPE, |
| .mask = ATTRIBUTE_MASK_WRITABLE | ATTRIBUTE_MASK_NULLABLE, |
| }; |
| |
| static EmberAfAttributeMetadata mockMetadataUint8Max = { |
| .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(&minMaxValue8), |
| .attributeId = 0, |
| .size = 1, |
| .attributeType = ZCL_INT8U_ATTRIBUTE_TYPE, |
| .mask = ATTRIBUTE_MASK_WRITABLE | ATTRIBUTE_MASK_NULLABLE | ATTRIBUTE_MASK_MIN_MAX, |
| }; |
| |
| static EmberAfAttributeMetadata mockMetadataUint16 = { |
| .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(static_cast<uint32_t>(0)), |
| .attributeId = 0, |
| .size = 2, |
| .attributeType = ZCL_INT16U_ATTRIBUTE_TYPE, |
| .mask = ATTRIBUTE_MASK_WRITABLE, |
| }; |
| |
| static EmberAfAttributeMetadata mockMetadataUint24 = { |
| .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(static_cast<uint32_t>(0)), |
| .attributeId = 0, |
| .size = 3, |
| .attributeType = ZCL_INT24U_ATTRIBUTE_TYPE, |
| .mask = ATTRIBUTE_MASK_WRITABLE, |
| }; |
| |
| static EmberAfAttributeMetadata mockMetadataUint32 = { |
| .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(static_cast<uint32_t>(0)), |
| .attributeId = 0, |
| .size = 4, |
| .attributeType = ZCL_INT32U_ATTRIBUTE_TYPE, |
| .mask = ATTRIBUTE_MASK_WRITABLE, |
| }; |
| |
| static EmberAfAttributeMetadata mockMetadataUint40 = { |
| .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(defaultValueData64), |
| .attributeId = 0, |
| .size = 5, |
| .attributeType = ZCL_INT40U_ATTRIBUTE_TYPE, |
| .mask = ATTRIBUTE_MASK_WRITABLE, |
| }; |
| |
| static EmberAfAttributeMetadata mockMetadataUint48 = { |
| .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(defaultValueData64), |
| .attributeId = 0, |
| .size = 6, |
| .attributeType = ZCL_INT48U_ATTRIBUTE_TYPE, |
| .mask = ATTRIBUTE_MASK_WRITABLE, |
| }; |
| |
| static EmberAfAttributeMetadata mockMetadataUint56 = { |
| .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(defaultValueData64), |
| .attributeId = 0, |
| .size = 7, |
| .attributeType = ZCL_INT56U_ATTRIBUTE_TYPE, |
| .mask = ATTRIBUTE_MASK_WRITABLE, |
| }; |
| |
| static EmberAfAttributeMetadata mockMetadataUint64 = { |
| .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(defaultValueData64), |
| .attributeId = 0, |
| .size = 8, |
| .attributeType = ZCL_INT64U_ATTRIBUTE_TYPE, |
| .mask = ATTRIBUTE_MASK_WRITABLE, |
| }; |
| |
| static EmberAfAttributeMetadata mockMetadataInt8 = { |
| .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(&minMaxValue8S), |
| .attributeId = 0, |
| .size = 1, |
| .attributeType = ZCL_INT8S_ATTRIBUTE_TYPE, |
| .mask = ATTRIBUTE_MASK_WRITABLE | ATTRIBUTE_MASK_MIN_MAX, |
| }; |
| |
| static EmberAfAttributeMetadata mockMetadataInt16 = { |
| .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(&minMaxValue16S), |
| .attributeId = 0, |
| .size = 2, |
| .attributeType = ZCL_INT16S_ATTRIBUTE_TYPE, |
| .mask = ATTRIBUTE_MASK_WRITABLE | ATTRIBUTE_MASK_MIN_MAX, |
| }; |
| |
| static EmberAfAttributeMetadata mockMetadataInt24 = { |
| .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(static_cast<uint32_t>(0)), |
| .attributeId = 0, |
| .size = 3, |
| .attributeType = ZCL_INT24S_ATTRIBUTE_TYPE, |
| .mask = ATTRIBUTE_MASK_WRITABLE, |
| }; |
| |
| static EmberAfAttributeMetadata mockMetadataInt32 = { |
| .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(static_cast<uint32_t>(0)), |
| .attributeId = 0, |
| .size = 4, |
| .attributeType = ZCL_INT32S_ATTRIBUTE_TYPE, |
| .mask = ATTRIBUTE_MASK_WRITABLE, |
| }; |
| |
| static EmberAfAttributeMetadata mockMetadataInt40 = { |
| .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(defaultValueData64), |
| .attributeId = 0, |
| .size = 5, |
| .attributeType = ZCL_INT40S_ATTRIBUTE_TYPE, |
| .mask = ATTRIBUTE_MASK_WRITABLE, |
| }; |
| |
| static EmberAfAttributeMetadata mockMetadataInt48 = { |
| .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(defaultValueData64), |
| .attributeId = 0, |
| .size = 6, |
| .attributeType = ZCL_INT48S_ATTRIBUTE_TYPE, |
| .mask = ATTRIBUTE_MASK_WRITABLE, |
| }; |
| |
| static EmberAfAttributeMetadata mockMetadataInt56 = { |
| .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(defaultValueData64), |
| .attributeId = 0, |
| .size = 7, |
| .attributeType = ZCL_INT56S_ATTRIBUTE_TYPE, |
| .mask = ATTRIBUTE_MASK_WRITABLE, |
| }; |
| |
| static EmberAfAttributeMetadata mockMetadataInt64 = { |
| .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(defaultValueData64), |
| .attributeId = 0, |
| .size = 8, |
| .attributeType = ZCL_INT64S_ATTRIBUTE_TYPE, |
| .mask = ATTRIBUTE_MASK_WRITABLE, |
| }; |
| |
| // clang-format off |
| static const MockNodeConfig SceneMockNodeConfig({ |
| MockEndpointConfig(kTestEndpoint1, { |
| MockClusterConfig(kScenesClusterId, {}), |
| MockClusterConfig(kOnOffClusterId, { |
| MockAttributeConfig(kOnOffAttId, mockMetadataBool) |
| }), |
| MockClusterConfig(kLevelControlClusterId, { |
| MockAttributeConfig(kCurrentLevelId, mockMetadataUint8Max), MockAttributeConfig(kCurrentFrequencyId, mockMetadataUint16) |
| }), |
| }), |
| MockEndpointConfig(kTestEndpoint2, { |
| MockClusterConfig(kScenesClusterId, {}), |
| MockClusterConfig(kOnOffClusterId, { |
| MockAttributeConfig(kOnOffAttId, mockMetadataBool) |
| }), |
| MockClusterConfig(kColorControlClusterId, { |
| MockAttributeConfig(kCurrentSaturationId, mockMetadataUint8), MockAttributeConfig(kCurrentXId, mockMetadataUint16), |
| MockAttributeConfig(kCurrentYId, mockMetadataUint16), MockAttributeConfig(kColorTemperatureMiredsId, mockMetadataUint16), |
| MockAttributeConfig(kEnhancedCurrentHueId, mockMetadataUint16), MockAttributeConfig(kEnhancedColorMode, mockMetadataUint8), |
| MockAttributeConfig(kColorLoopActiveId, mockMetadataUint8), MockAttributeConfig(kColorLoopDirectionId, mockMetadataUint8), |
| MockAttributeConfig(kColorLoopTimeId, mockMetadataUint16) |
| }), |
| }), |
| MockEndpointConfig(kTestEndpoint3, { |
| MockClusterConfig(kScenesClusterId, {}), |
| MockClusterConfig(kOnOffClusterId, { |
| MockAttributeConfig(kOnOffAttId, mockMetadataBool) |
| }), |
| MockClusterConfig(kLevelControlClusterId, { |
| MockAttributeConfig(kCurrentLevelId, mockMetadataUint8Max), MockAttributeConfig(kCurrentFrequencyId, mockMetadataUint16) |
| }), |
| MockClusterConfig(kColorControlClusterId, { |
| MockAttributeConfig(kCurrentSaturationId, mockMetadataUint8), MockAttributeConfig(kCurrentXId, mockMetadataUint16), |
| MockAttributeConfig(kCurrentYId, mockMetadataUint16), MockAttributeConfig(kColorTemperatureMiredsId, mockMetadataUint16), |
| MockAttributeConfig(kEnhancedCurrentHueId, mockMetadataUint16), MockAttributeConfig(kEnhancedColorMode, mockMetadataUint8), |
| MockAttributeConfig(kColorLoopActiveId, mockMetadataUint8), MockAttributeConfig(kColorLoopDirectionId, mockMetadataUint8), |
| MockAttributeConfig(kColorLoopTimeId, mockMetadataUint8) |
| }), |
| }), |
| |
| MockEndpointConfig(kTestEndpoint4, { |
| MockClusterConfig(kScenesClusterId, {}), |
| MockClusterConfig(MockClusterId(kColorControlClusterId), { |
| MockAttributeConfig(MockAttributeId(kCurrentSaturationId), mockMetadataUint24), MockAttributeConfig(MockAttributeId(kCurrentXId), mockMetadataUint32), |
| MockAttributeConfig(MockAttributeId(kCurrentYId), mockMetadataUint48), MockAttributeConfig(MockAttributeId(kColorTemperatureMiredsId), mockMetadataUint56), |
| MockAttributeConfig(MockAttributeId(kEnhancedCurrentHueId), mockMetadataUint64), MockAttributeConfig(MockAttributeId(kEnhancedColorMode), mockMetadataInt8), |
| MockAttributeConfig(MockAttributeId(kColorLoopActiveId), mockMetadataInt16), MockAttributeConfig(MockAttributeId(kColorLoopDirectionId), mockMetadataInt24), |
| MockAttributeConfig(MockAttributeId(kColorLoopTimeId), mockMetadataInt32) |
| }), |
| MockClusterConfig(MockClusterId(kOnOffClusterId), { |
| MockAttributeConfig(MockAttributeId(kOnOffAttId), mockMetadataInt48) |
| }), |
| MockClusterConfig(MockClusterId(kLevelControlClusterId), { |
| MockAttributeConfig(MockAttributeId(kCurrentLevelId), mockMetadataInt56), MockAttributeConfig(MockAttributeId(kCurrentFrequencyId), mockMetadataInt64) |
| }), |
| MockClusterConfig(MockClusterId(kFakeClusterId), { |
| MockAttributeConfig(MockAttributeId(kCurrentLevelId), mockMetadataUint40), MockAttributeConfig(MockAttributeId(kCurrentFrequencyId), mockMetadataInt40) |
| }), |
| }), |
| }); |
| // clang-format on |
| |
| /// @brief Simulates a Handler where Endpoint 1 supports onoff and level control and Endpoint 2 supports onoff and color control |
| class TestSceneHandler : public scenes::DefaultSceneHandlerImpl |
| { |
| public: |
| TestSceneHandler() = default; |
| ~TestSceneHandler() override {} |
| |
| // Fills in cluster buffer and adjusts its size to lower than the maximum number of cluster per scenes |
| virtual void GetSupportedClusters(EndpointId endpoint, Span<ClusterId> & clusterBuffer) override |
| { |
| ClusterId * buffer = clusterBuffer.data(); |
| if (endpoint == kTestEndpoint1) |
| { |
| if (clusterBuffer.size() >= 2) |
| { |
| buffer[0] = kOnOffClusterId; |
| buffer[1] = kLevelControlClusterId; |
| clusterBuffer.reduce_size(2); |
| } |
| } |
| else if (endpoint == kTestEndpoint2) |
| { |
| if (clusterBuffer.size() >= 2) |
| { |
| buffer[0] = kOnOffClusterId; |
| buffer[1] = kColorControlClusterId; |
| clusterBuffer.reduce_size(2); |
| } |
| } |
| else if (endpoint == kTestEndpoint3) |
| { |
| if (clusterBuffer.size() >= 3) |
| { |
| buffer[0] = kOnOffClusterId; |
| buffer[1] = kLevelControlClusterId; |
| buffer[2] = kColorControlClusterId; |
| clusterBuffer.reduce_size(3); |
| } |
| } |
| else if (endpoint == kTestEndpoint4) |
| { |
| if (clusterBuffer.size() >= 3) |
| { |
| buffer[0] = MockClusterId(kOnOffClusterId); |
| buffer[1] = MockClusterId(kLevelControlClusterId); |
| buffer[2] = MockClusterId(kColorControlClusterId); |
| clusterBuffer.reduce_size(3); |
| } |
| } |
| else |
| { |
| clusterBuffer.reduce_size(0); |
| } |
| } |
| |
| // Default function only checks if endpoint and clusters are valid |
| bool SupportsCluster(EndpointId endpoint, ClusterId cluster) override |
| { |
| if (endpoint == kTestEndpoint1) |
| { |
| if (cluster == kOnOffClusterId || cluster == kLevelControlClusterId) |
| { |
| return true; |
| } |
| } |
| |
| if (endpoint == kTestEndpoint2) |
| { |
| if (cluster == kOnOffClusterId || cluster == kColorControlClusterId) |
| { |
| return true; |
| } |
| } |
| |
| if (endpoint == kTestEndpoint3) |
| { |
| if (cluster == kOnOffClusterId || cluster == kLevelControlClusterId || cluster == kColorControlClusterId) |
| { |
| return true; |
| } |
| } |
| |
| if (endpoint == kTestEndpoint4) |
| { |
| if (cluster == MockClusterId(kColorControlClusterId) || cluster == MockClusterId(kLevelControlClusterId) || |
| cluster == MockClusterId(kColorControlClusterId) || cluster == MockClusterId(kFakeClusterId)) |
| { |
| return true; |
| } |
| } |
| |
| return false; |
| } |
| |
| /// @brief Simulates save from cluster, data is already in an EFS struct but this isn't mandatory |
| /// @param endpoint target endpoint |
| /// @param cluster target cluster |
| /// @param serialisedBytes data to serialize into EFS |
| /// @return success if successfully serialized the data, CHIP_ERROR_INVALID_ARGUMENT if endpoint or cluster not supported |
| CHIP_ERROR SerializeSave(EndpointId endpoint, ClusterId cluster, MutableByteSpan & serialisedBytes) override |
| { |
| CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; |
| |
| if (endpoint == kTestEndpoint1) |
| { |
| switch (cluster) |
| { |
| case kOnOffClusterId: |
| err = CHIP_NO_ERROR; |
| // Warning: OO_buffer needs to be populated before calling this function |
| memcpy(serialisedBytes.data(), OO_buffer, scenes::kMaxFieldBytesPerCluster); |
| // Warning: serialized size of the buffer must also be computed before calling this function |
| serialisedBytes.reduce_size(OO_buffer_serialized_length); // Used memory for OnOff TLV |
| break; |
| case kLevelControlClusterId: |
| err = CHIP_NO_ERROR; |
| // Warning: LC_buffer needs to be populated before calling this function |
| memcpy(serialisedBytes.data(), LC_buffer, scenes::kMaxFieldBytesPerCluster); |
| // Warning: serialized size of the buffer must also be computed before calling this function |
| serialisedBytes.reduce_size(LC_buffer_serialized_length); // Used memory for Level Control TLV |
| break; |
| default: |
| break; |
| } |
| } |
| if (endpoint == kTestEndpoint2) |
| { |
| switch (cluster) |
| { |
| case kOnOffClusterId: |
| err = CHIP_NO_ERROR; |
| // Warning: OO_buffer needs to be populated before calling this function |
| memcpy(serialisedBytes.data(), OO_buffer, scenes::kMaxFieldBytesPerCluster); |
| // Warning: serialized size of the buffer must also be computed before calling this function |
| serialisedBytes.reduce_size(OO_buffer_serialized_length); // Used memory for OnOff TLV |
| break; |
| case kColorControlClusterId: |
| err = CHIP_NO_ERROR; |
| // Warning: CC_buffer needs to be populated before calling this function |
| memcpy(serialisedBytes.data(), CC_buffer, scenes::kMaxFieldBytesPerCluster); |
| // Warning: serialized size of the buffer must also be computed before calling this function |
| serialisedBytes.reduce_size(CC_buffer_serialized_length); // Used memory for Color Control TLV |
| break; |
| default: |
| break; |
| } |
| } |
| if (endpoint == kTestEndpoint3) |
| { |
| switch (cluster) |
| { |
| case kOnOffClusterId: |
| err = CHIP_NO_ERROR; |
| // Warning: OO_buffer needs to be populated before calling this function |
| memcpy(serialisedBytes.data(), OO_buffer, scenes::kMaxFieldBytesPerCluster); |
| // Warning: serialized size of the buffer must also be computed before calling this function |
| serialisedBytes.reduce_size(OO_buffer_serialized_length); // Used memory for OnOff TLV |
| break; |
| case kLevelControlClusterId: |
| err = CHIP_NO_ERROR; |
| // Warning: LC_buffer needs to be populated before calling this function |
| memcpy(serialisedBytes.data(), LC_buffer, scenes::kMaxFieldBytesPerCluster); |
| // Warning: serialized size of the buffer must also be computed before calling this function |
| serialisedBytes.reduce_size(LC_buffer_serialized_length); // Used memory for Level Control TLV |
| break; |
| case kColorControlClusterId: |
| err = CHIP_NO_ERROR; |
| // Warning: CC_buffer needs to be populated before calling this function |
| memcpy(serialisedBytes.data(), CC_buffer, scenes::kMaxFieldBytesPerCluster); |
| // Warning: serialized size of the buffer must also be computed before calling this function |
| serialisedBytes.reduce_size(CC_buffer_serialized_length); // Used memory for Color Control TLV |
| break; |
| default: |
| break; |
| } |
| } |
| return err; |
| } |
| |
| /// @brief Simulates EFS being applied to a scene, here just validates that the data is as expected, no action taken by the |
| /// "cluster" |
| /// @param endpoint target endpoint |
| /// @param cluster target cluster |
| /// @param serialisedBytes Data from nvm |
| /// @param timeMs transition time in ms |
| /// @return CHIP_NO_ERROR if value as expected, CHIP_ERROR_INVALID_ARGUMENT otherwise |
| CHIP_ERROR |
| ApplyScene(EndpointId endpoint, ClusterId cluster, const ByteSpan & serialisedBytes, TransitionTimeMs timeMs) override |
| { |
| CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; |
| |
| // Takes values from cluster in Endpoint 1 |
| if (endpoint == kTestEndpoint1) |
| { |
| switch (cluster) |
| { |
| case kOnOffClusterId: |
| if (!memcmp(serialisedBytes.data(), OO_buffer, serialisedBytes.size())) |
| { |
| err = CHIP_NO_ERROR; |
| } |
| break; |
| case kLevelControlClusterId: |
| if (!memcmp(serialisedBytes.data(), LC_buffer, serialisedBytes.size())) |
| { |
| err = CHIP_NO_ERROR; |
| } |
| break; |
| default: |
| break; |
| } |
| } |
| |
| // Takes values from cluster in Endpoint 2 |
| if (endpoint == kTestEndpoint2) |
| { |
| switch (cluster) |
| { |
| case kOnOffClusterId: |
| if (!memcmp(serialisedBytes.data(), OO_buffer, serialisedBytes.size())) |
| { |
| err = CHIP_NO_ERROR; |
| } |
| break; |
| case kColorControlClusterId: |
| if (!memcmp(serialisedBytes.data(), CC_buffer, serialisedBytes.size())) |
| { |
| err = CHIP_NO_ERROR; |
| } |
| break; |
| default: |
| break; |
| } |
| } |
| |
| // Takes values from cluster in Endpoint 3 |
| if (endpoint == kTestEndpoint3) |
| { |
| switch (cluster) |
| { |
| case kOnOffClusterId: |
| if (!memcmp(serialisedBytes.data(), OO_buffer, serialisedBytes.size())) |
| { |
| err = CHIP_NO_ERROR; |
| } |
| break; |
| case kLevelControlClusterId: |
| if (!memcmp(serialisedBytes.data(), LC_buffer, serialisedBytes.size())) |
| { |
| err = CHIP_NO_ERROR; |
| } |
| break; |
| case kColorControlClusterId: |
| if (!memcmp(serialisedBytes.data(), CC_buffer, serialisedBytes.size())) |
| { |
| err = CHIP_NO_ERROR; |
| } |
| break; |
| default: |
| break; |
| } |
| } |
| |
| return err; |
| } |
| }; |
| |
| class TestSceneTableImpl : public SceneTableImpl |
| { |
| public: |
| TestSceneTableImpl(uint16_t maxScenesPerFabric = defaultTestFabricCapacity, uint16_t maxScenesGlobal = defaultTestTableSize) : |
| SceneTableImpl(maxScenesPerFabric, maxScenesGlobal) |
| {} |
| ~TestSceneTableImpl() override {} |
| |
| protected: |
| uint8_t GetClustersFromEndpoint(ClusterId * clusterList, uint8_t listLen) override |
| { |
| if (listLen >= 3) |
| { |
| clusterList[0] = kOnOffClusterId; |
| clusterList[1] = kLevelControlClusterId; |
| clusterList[2] = kColorControlClusterId; |
| return 3; |
| } |
| |
| return 0; |
| } |
| |
| uint8_t GetClusterCountFromEndpoint() override { return 3; } |
| }; |
| |
| // Test Fixture Class |
| class TestSceneTable : public ::testing::Test |
| { |
| public: |
| static void SetUpTestSuite() |
| { |
| mpTestStorage = new chip::TestPersistentStorageDelegate; |
| mpSceneHandler = new TestSceneHandler; |
| |
| ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); |
| |
| // Initialize Scene Table |
| SceneTable * sceneTable = scenes::GetSceneTableImpl(); |
| ASSERT_NE(sceneTable, nullptr); |
| ASSERT_EQ(sceneTable->Init(mpTestStorage), CHIP_NO_ERROR); |
| SetMockNodeConfig(SceneMockNodeConfig); |
| } |
| |
| static void TearDownTestSuite() |
| { |
| // Terminate Scene Table |
| SceneTable * sceneTable = scenes::GetSceneTableImpl(); |
| ASSERT_NE(sceneTable, nullptr); |
| sceneTable->Finish(); |
| delete mpTestStorage; |
| delete mpSceneHandler; |
| chip::Platform::MemoryShutdown(); |
| } |
| |
| // Storage |
| static chip::TestPersistentStorageDelegate * mpTestStorage; |
| // Scene |
| static TestSceneHandler * mpSceneHandler; |
| }; |
| |
| chip::TestPersistentStorageDelegate * TestSceneTable::mpTestStorage = nullptr; |
| TestSceneHandler * TestSceneTable::mpSceneHandler = nullptr; |
| |
| void ResetSceneTable(SceneTable * sceneTable) |
| { |
| sceneTable->RemoveFabric(kFabric1); |
| sceneTable->RemoveFabric(kFabric2); |
| sceneTable->RemoveFabric(kFabric3); |
| } |
| |
| TEST_F(TestSceneTable, TestHandlerRegistration) |
| { |
| SceneTable * sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| TestSceneHandler tmpHandler[scenes::kMaxClustersPerScene]; |
| |
| for (uint8_t i = 0; i < scenes::kMaxClustersPerScene; i++) |
| { |
| sceneTable->RegisterHandler(&tmpHandler[i]); |
| } |
| |
| // Emptying Handler array |
| sceneTable->UnregisterAllHandlers(); |
| |
| // Verify the handler num has been updated properly |
| EXPECT_TRUE(sceneTable->HandlerListEmpty()); |
| |
| for (uint8_t i = 0; i < scenes::kMaxClustersPerScene; i++) |
| { |
| sceneTable->RegisterHandler(&tmpHandler[i]); |
| } |
| |
| // Hanlder order in table : [H0, H1, H2] |
| |
| EXPECT_FALSE(sceneTable->HandlerListEmpty()); |
| // Removal at beginning |
| sceneTable->UnregisterHandler(&tmpHandler[0]); |
| EXPECT_FALSE(sceneTable->HandlerListEmpty()); |
| // Re-insert |
| sceneTable->RegisterHandler(&tmpHandler[0]); |
| EXPECT_FALSE(sceneTable->HandlerListEmpty()); |
| // Hanlder order in table : [H0, H1, H2] |
| |
| // Removal at the middle |
| sceneTable->UnregisterHandler(&tmpHandler[2]); |
| EXPECT_FALSE(sceneTable->HandlerListEmpty()); |
| // Re-insert |
| sceneTable->RegisterHandler(&tmpHandler[2]); |
| EXPECT_FALSE(sceneTable->HandlerListEmpty()); |
| // Hanlder order in table : [H1, H0, H2] |
| |
| // Removal at the end |
| sceneTable->UnregisterHandler(&tmpHandler[2]); |
| EXPECT_FALSE(sceneTable->HandlerListEmpty()); |
| |
| // Emptying Handler array |
| sceneTable->UnregisterAllHandlers(); |
| |
| // Verify the handler num has been updated properly |
| EXPECT_TRUE(sceneTable->HandlerListEmpty()); |
| } |
| |
| TEST_F(TestSceneTable, TestHandlerFunctions) |
| { |
| SceneTable * sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| app::Clusters::ScenesManagement::Structs::ExtensionFieldSet::Type extensionFieldSetOut; |
| app::Clusters::ScenesManagement::Structs::ExtensionFieldSet::DecodableType extensionFieldSetIn; |
| |
| TLV::TLVReader reader; |
| TLV::TLVWriter writer; |
| |
| OOPairs[0].attributeID = kOnOffAttId; |
| OOPairs[0].valueUnsigned8.SetValue(0x01); |
| |
| LCPairs[0].attributeID = kCurrentLevelId; |
| LCPairs[0].valueUnsigned8.SetValue(0x64); |
| LCPairs[1].attributeID = kCurrentFrequencyId; |
| LCPairs[1].valueUnsigned16.SetValue(0x01F0); |
| |
| CCPairs[0].attributeID = kCurrentSaturationId; |
| CCPairs[0].valueUnsigned8.SetValue(0); |
| CCPairs[1].attributeID = kCurrentXId; |
| CCPairs[1].valueUnsigned16.SetValue(0); |
| CCPairs[2].attributeID = kCurrentYId; |
| CCPairs[2].valueUnsigned16.SetValue(0); |
| CCPairs[3].attributeID = kColorTemperatureMiredsId; |
| CCPairs[3].valueUnsigned16.SetValue(0); |
| CCPairs[4].attributeID = kEnhancedCurrentHueId; |
| CCPairs[4].valueUnsigned16.SetValue(0); |
| CCPairs[5].attributeID = kEnhancedColorMode; |
| CCPairs[5].valueUnsigned8.SetValue(0); |
| CCPairs[6].attributeID = kColorLoopActiveId; |
| CCPairs[6].valueUnsigned8.SetValue(0); |
| CCPairs[7].attributeID = kColorLoopDirectionId; |
| CCPairs[7].valueUnsigned8.SetValue(0); |
| CCPairs[8].attributeID = kColorLoopTimeId; |
| CCPairs[8].valueUnsigned16.SetValue(0); |
| |
| // Initialize Extension Field sets as if they were received by add commands |
| OOextensionFieldSet.clusterID = kOnOffClusterId; |
| OOextensionFieldSet.attributeValueList = OOPairs; |
| LCextensionFieldSet.clusterID = kLevelControlClusterId; |
| LCextensionFieldSet.attributeValueList = LCPairs; |
| CCextensionFieldSet.clusterID = kColorControlClusterId; |
| CCextensionFieldSet.attributeValueList = CCPairs; |
| |
| ByteSpan OO_list(OO_buffer); |
| ByteSpan LC_list(LC_buffer); |
| ByteSpan CC_list(CC_buffer); |
| |
| constexpr uint16_t bufferSize = 1024; |
| uint8_t buffer[bufferSize] = { 0 }; |
| MutableByteSpan buff_span(buffer); |
| |
| // Serialize Extension Field sets as if they were recovered from memory |
| writer.Init(OO_buffer); |
| EXPECT_EQ(CHIP_NO_ERROR, app::DataModel::Encode(writer, TLV::AnonymousTag(), OOextensionFieldSet.attributeValueList)); |
| OO_buffer_serialized_length = writer.GetLengthWritten(); |
| |
| writer.Init(LC_buffer); |
| EXPECT_EQ(CHIP_NO_ERROR, app::DataModel::Encode(writer, TLV::AnonymousTag(), LCextensionFieldSet.attributeValueList)); |
| LC_buffer_serialized_length = writer.GetLengthWritten(); |
| |
| writer.Init(CC_buffer); |
| EXPECT_EQ(CHIP_NO_ERROR, app::DataModel::Encode(writer, TLV::AnonymousTag(), CCextensionFieldSet.attributeValueList)); |
| CC_buffer_serialized_length = writer.GetLengthWritten(); |
| |
| // Test Registering SceneHandler |
| sceneTable->RegisterHandler(mpSceneHandler); |
| EXPECT_FALSE(sceneTable->HandlerListEmpty()); |
| |
| // Setup the On Off Extension field set in the expected state from a command |
| reader.Init(OO_list); |
| extensionFieldSetIn.clusterID = kOnOffClusterId; |
| EXPECT_EQ(CHIP_NO_ERROR, reader.Next()); |
| EXPECT_EQ(CHIP_NO_ERROR, extensionFieldSetIn.attributeValueList.Decode(reader)); |
| |
| EXPECT_TRUE(mpSceneHandler->SupportsCluster(kTestEndpoint1, extensionFieldSetIn.clusterID)); |
| EXPECT_EQ(CHIP_NO_ERROR, mpSceneHandler->SerializeAdd(kTestEndpoint1, extensionFieldSetIn, buff_span)); |
| |
| // Verify the handler extracted buffer matches the initial field sets |
| EXPECT_EQ(0, memcmp(OO_list.data(), buff_span.data(), buff_span.size())); |
| memset(buffer, 0, buff_span.size()); |
| buff_span = MutableByteSpan(buffer); |
| |
| // Setup the Level Control Extension field set in the expected state from a command |
| reader.Init(LC_list); |
| extensionFieldSetIn.clusterID = kLevelControlClusterId; |
| EXPECT_EQ(CHIP_NO_ERROR, reader.Next()); |
| EXPECT_EQ(CHIP_NO_ERROR, extensionFieldSetIn.attributeValueList.Decode(reader)); |
| |
| EXPECT_TRUE(mpSceneHandler->SupportsCluster(kTestEndpoint1, extensionFieldSetIn.clusterID)); |
| EXPECT_EQ(CHIP_NO_ERROR, mpSceneHandler->SerializeAdd(kTestEndpoint1, extensionFieldSetIn, buff_span)); |
| |
| // Verify the handler extracted buffer matches the initial field sets |
| EXPECT_EQ(0, memcmp(LC_list.data(), buff_span.data(), buff_span.size())); |
| memset(buffer, 0, buff_span.size()); |
| buff_span = MutableByteSpan(buffer); |
| |
| // Setup the Color control Extension field set in the expected state from a command |
| reader.Init(CC_list); |
| extensionFieldSetIn.clusterID = kColorControlClusterId; |
| EXPECT_EQ(CHIP_NO_ERROR, reader.Next()); |
| EXPECT_EQ(CHIP_NO_ERROR, extensionFieldSetIn.attributeValueList.Decode(reader)); |
| |
| EXPECT_TRUE(mpSceneHandler->SupportsCluster(kTestEndpoint2, extensionFieldSetIn.clusterID)); |
| EXPECT_EQ(CHIP_NO_ERROR, mpSceneHandler->SerializeAdd(kTestEndpoint2, extensionFieldSetIn, buff_span)); |
| |
| // Verify the handler extracted buffer matches the initial field sets |
| EXPECT_EQ(0, memcmp(CC_list.data(), buff_span.data(), CC_list.size())); |
| memset(buffer, 0, buff_span.size()); |
| buff_span = MutableByteSpan(buffer); |
| |
| // Verify Deserializing is properly filling out output extension field set for on off |
| EXPECT_TRUE(mpSceneHandler->SupportsCluster(kTestEndpoint1, kOnOffClusterId)); |
| EXPECT_EQ(CHIP_NO_ERROR, mpSceneHandler->Deserialize(kTestEndpoint1, kOnOffClusterId, OO_list, extensionFieldSetOut)); |
| |
| // Verify Encoding the Extension field set returns the same data as the one serialized for on off previously |
| writer.Init(buff_span); |
| EXPECT_EQ(CHIP_NO_ERROR, app::DataModel::Encode(writer, TLV::AnonymousTag(), extensionFieldSetOut.attributeValueList)); |
| EXPECT_EQ(0, memcmp(OO_list.data(), buff_span.data(), OO_list.size())); |
| memset(buffer, 0, buff_span.size()); |
| |
| // Verify Deserializing is properly filling out output extension field set for level control |
| EXPECT_TRUE(mpSceneHandler->SupportsCluster(kTestEndpoint1, kLevelControlClusterId)); |
| EXPECT_EQ(CHIP_NO_ERROR, mpSceneHandler->Deserialize(kTestEndpoint1, kLevelControlClusterId, LC_list, extensionFieldSetOut)); |
| |
| // Verify Encoding the Extension field set returns the same data as the one serialized for level control previously |
| writer.Init(buff_span); |
| EXPECT_EQ(CHIP_NO_ERROR, app::DataModel::Encode(writer, TLV::AnonymousTag(), extensionFieldSetOut.attributeValueList)); |
| EXPECT_EQ(0, memcmp(LC_list.data(), buff_span.data(), LC_list.size())); |
| memset(buffer, 0, buff_span.size()); |
| |
| // Verify Deserializing is properly filling out output extension field set for color control |
| EXPECT_TRUE(mpSceneHandler->SupportsCluster(kTestEndpoint2, kColorControlClusterId)); |
| EXPECT_EQ(CHIP_NO_ERROR, mpSceneHandler->Deserialize(kTestEndpoint2, kColorControlClusterId, CC_list, extensionFieldSetOut)); |
| |
| // Verify Encoding the Extension field set returns the same data as the one serialized for color control previously |
| writer.Init(buff_span); |
| EXPECT_EQ(CHIP_NO_ERROR, app::DataModel::Encode(writer, TLV::AnonymousTag(), extensionFieldSetOut.attributeValueList)); |
| EXPECT_EQ(0, memcmp(CC_list.data(), buff_span.data(), CC_list.size())); |
| memset(buffer, 0, buff_span.size()); |
| |
| // To test failure on serialize and deserialize when too many pairs are in the field sets |
| app::Clusters::ScenesManagement::Structs::ExtensionFieldSet::Type extensionFieldFailTestOut; |
| app::Clusters::ScenesManagement::Structs::ExtensionFieldSet::DecodableType extensionFieldFailTestIn; |
| app::Clusters::ScenesManagement::Structs::AttributeValuePairStruct::Type TooManyPairs[16]; |
| |
| for (uint8_t i = 0; i < 16; i++) |
| { |
| TooManyPairs[i].valueUnsigned8.SetValue(0); |
| } |
| |
| extensionFieldFailTestOut.clusterID = kColorControlClusterId; |
| extensionFieldFailTestOut.attributeValueList = TooManyPairs; |
| |
| // Give a bigger buffer given we are using too many pairs on purpose |
| uint8_t failBuffer[2 * scenes::kMaxFieldBytesPerCluster] = { 0 }; |
| ByteSpan fail_list(failBuffer); |
| |
| // Serialize Extension Field sets as if they were recovered from memory |
| writer.Init(failBuffer); |
| EXPECT_EQ(CHIP_NO_ERROR, app::DataModel::Encode(writer, TLV::AnonymousTag(), extensionFieldFailTestOut.attributeValueList)); |
| |
| // Setup the On Off Extension field set in the expected state from a command |
| reader.Init(fail_list); |
| extensionFieldFailTestIn.clusterID = kColorControlClusterId; |
| EXPECT_EQ(CHIP_NO_ERROR, reader.Next()); |
| EXPECT_EQ(CHIP_NO_ERROR, extensionFieldFailTestIn.attributeValueList.Decode(reader)); |
| |
| // Verify failure on both serialize and deserialize |
| EXPECT_EQ(CHIP_ERROR_BUFFER_TOO_SMALL, mpSceneHandler->SerializeAdd(kTestEndpoint1, extensionFieldFailTestIn, buff_span)); |
| EXPECT_EQ(CHIP_ERROR_BUFFER_TOO_SMALL, |
| mpSceneHandler->Deserialize(kTestEndpoint1, kColorControlClusterId, fail_list, extensionFieldFailTestOut)); |
| |
| memset(failBuffer, 0, fail_list.size()); |
| memset(buffer, 0, buff_span.size()); |
| |
| // Test Serialize Add of an attribute value that is greater than the mock attribute max (Max bool value) |
| OOPairs[0].valueUnsigned8.SetValue(0xFF); |
| |
| // EFS to test caping of value once a variable above the mock attribute size is serialized |
| app::Clusters::ScenesManagement::Structs::ExtensionFieldSet::Type extensionFieldValueCapOut; |
| app::Clusters::ScenesManagement::Structs::ExtensionFieldSet::DecodableType extensionFieldValueCapIn; |
| |
| extensionFieldValueCapOut.clusterID = kOnOffClusterId; |
| extensionFieldValueCapOut.attributeValueList = OOPairs; |
| |
| /// Setup of input EFS (by temporary using the output one) |
| writer.Init(buff_span); |
| EXPECT_EQ(CHIP_NO_ERROR, app::DataModel::Encode(writer, TLV::AnonymousTag(), extensionFieldValueCapOut.attributeValueList)); |
| |
| reader.Init(buffer); |
| extensionFieldValueCapIn.clusterID = kOnOffClusterId; |
| EXPECT_EQ(CHIP_NO_ERROR, reader.Next()); |
| EXPECT_EQ(CHIP_NO_ERROR, extensionFieldValueCapIn.attributeValueList.Decode(reader)); |
| |
| // Verify that the initial value is not capped |
| auto pair_iterator = extensionFieldValueCapIn.attributeValueList.begin(); |
| pair_iterator.Next(); |
| app::Clusters::ScenesManagement::Structs::AttributeValuePairStruct::Type pair = pair_iterator.GetValue(); |
| EXPECT_EQ(pair.valueUnsigned8.Value(), OOPairs[0].valueUnsigned8.Value()); |
| |
| // Verify that we cap the value to the mock attribute size when serializing |
| EXPECT_EQ(CHIP_NO_ERROR, mpSceneHandler->SerializeAdd(kTestEndpoint1, extensionFieldValueCapIn, buff_span)); |
| EXPECT_EQ(CHIP_NO_ERROR, mpSceneHandler->Deserialize(kTestEndpoint1, kOnOffClusterId, buff_span, extensionFieldValueCapOut)); |
| |
| // Verify that the output value is capped to 1 |
| EXPECT_EQ(1, extensionFieldValueCapOut.attributeValueList[0].valueUnsigned8.Value()); |
| |
| // Clear buffer |
| memset(buffer, 0, buff_span.size()); |
| |
| // Test Serialize Add of an attribute value that is smaller than the mock attribute min (1) for LC current level |
| LCPairs[0].valueUnsigned8.SetValue(0); |
| |
| extensionFieldValueCapOut.clusterID = kLevelControlClusterId; |
| extensionFieldValueCapOut.attributeValueList = LCPairs; |
| |
| /// Setup of input EFS (by temporary using the output one) |
| buff_span = MutableByteSpan(buffer); |
| writer.Init(buff_span); |
| EXPECT_EQ(CHIP_NO_ERROR, app::DataModel::Encode(writer, TLV::AnonymousTag(), extensionFieldValueCapOut.attributeValueList)); |
| |
| reader.Init(buffer); |
| extensionFieldValueCapIn.clusterID = kLevelControlClusterId; |
| EXPECT_EQ(CHIP_NO_ERROR, reader.Next()); |
| EXPECT_EQ(CHIP_NO_ERROR, extensionFieldValueCapIn.attributeValueList.Decode(reader)); |
| |
| // Verify that the initial value is not capped |
| auto iteratorMin = extensionFieldValueCapIn.attributeValueList.begin(); |
| iteratorMin.Next(); |
| pair = iteratorMin.GetValue(); |
| EXPECT_EQ(pair.valueUnsigned8.Value(), LCPairs[0].valueUnsigned8.Value()); |
| |
| // Verify that we cap the value to the mock attribute size when serializing |
| EXPECT_EQ(CHIP_NO_ERROR, mpSceneHandler->SerializeAdd(kTestEndpoint1, extensionFieldValueCapIn, buff_span)); |
| EXPECT_EQ(CHIP_NO_ERROR, |
| mpSceneHandler->Deserialize(kTestEndpoint1, kLevelControlClusterId, buff_span, extensionFieldValueCapOut)); |
| |
| // Verify that the output value is capped to 255 (NULL) as Level Control Current Level is a nullable uint8_t |
| EXPECT_EQ(255, extensionFieldValueCapOut.attributeValueList[0].valueUnsigned8.Value()); |
| |
| // Clear buffer |
| memset(buffer, 0, buff_span.size()); |
| |
| // Test Serialize Add of an attribute value that is higher than the mock attribute max (0xFE) for LC current level |
| LCPairs[0].valueUnsigned8.SetValue(0xFF); |
| |
| extensionFieldValueCapOut.clusterID = kLevelControlClusterId; |
| extensionFieldValueCapOut.attributeValueList = LCPairs; |
| |
| /// Setup of input EFS (by temporary using the output one) |
| buff_span = MutableByteSpan(buffer); |
| writer.Init(buff_span); |
| EXPECT_EQ(CHIP_NO_ERROR, app::DataModel::Encode(writer, TLV::AnonymousTag(), extensionFieldValueCapOut.attributeValueList)); |
| |
| reader.Init(buffer); |
| extensionFieldValueCapIn.clusterID = kLevelControlClusterId; |
| EXPECT_EQ(CHIP_NO_ERROR, reader.Next()); |
| EXPECT_EQ(CHIP_NO_ERROR, extensionFieldValueCapIn.attributeValueList.Decode(reader)); |
| |
| // Verify that the initial value is not capped |
| auto iteratorMax = extensionFieldValueCapIn.attributeValueList.begin(); |
| iteratorMax.Next(); |
| pair = iteratorMax.GetValue(); |
| EXPECT_EQ(pair.valueUnsigned8.Value(), LCPairs[0].valueUnsigned8.Value()); |
| EXPECT_EQ(CHIP_NO_ERROR, mpSceneHandler->SerializeAdd(kTestEndpoint1, extensionFieldValueCapIn, buff_span)); |
| EXPECT_EQ(CHIP_NO_ERROR, |
| mpSceneHandler->Deserialize(kTestEndpoint1, kLevelControlClusterId, buff_span, extensionFieldValueCapOut)); |
| |
| // Verify that the output value is 0xFF (NULL) as Level Control Current Level is a nullable uint8_t |
| EXPECT_EQ(0xFF, extensionFieldValueCapOut.attributeValueList[0].valueUnsigned8.Value()); |
| |
| // Clear buffer |
| memset(buffer, 0, buff_span.size()); |
| buff_span = MutableByteSpan(buffer); |
| |
| // Test for attribtues types that are in no Real clusters yet but are supported in scenes |
| { |
| // Setup EFS for mock cluster testing all attributes types |
| app::Clusters::ScenesManagement::Structs::AttributeValuePairStruct::Type MockOOPairs[1]; |
| app::Clusters::ScenesManagement::Structs::AttributeValuePairStruct::Type MockLCPairs[2]; |
| app::Clusters::ScenesManagement::Structs::AttributeValuePairStruct::Type MockCCPairs[9]; |
| app::Clusters::ScenesManagement::Structs::AttributeValuePairStruct::Type MockFKPairs[2]; |
| // Mock CC |
| MockCCPairs[0].attributeID = MockAttributeId(kCurrentSaturationId); |
| MockCCPairs[0].valueUnsigned32.SetValue(UINT32_MAX); // will cap to 0x00FFFFFF (uint24) |
| MockCCPairs[1].attributeID = MockAttributeId(kCurrentXId); |
| MockCCPairs[1].valueUnsigned32.SetValue(UINT32_MAX); // not capped |
| MockCCPairs[2].attributeID = MockAttributeId(kCurrentYId); |
| MockCCPairs[2].valueUnsigned64.SetValue(UINT64_MAX); // will cap to 0x0000FFFFFFFFFFFF (uint48) |
| MockCCPairs[3].attributeID = MockAttributeId(kColorTemperatureMiredsId); |
| MockCCPairs[3].valueUnsigned64.SetValue(UINT64_MAX); // will cap to 0x00FFFFFFFFFFFFFF (uint56) |
| MockCCPairs[4].attributeID = MockAttributeId(kEnhancedCurrentHueId); |
| MockCCPairs[4].valueUnsigned64.SetValue(UINT64_MAX); // not capped |
| MockCCPairs[5].attributeID = MockAttributeId(kEnhancedColorMode); |
| MockCCPairs[5].valueSigned8.SetValue(static_cast<int8_t>(-2)); // will cap to -1 |
| MockCCPairs[6].attributeID = MockAttributeId(kColorLoopActiveId); |
| MockCCPairs[6].valueSigned16.SetValue( |
| static_cast<int16_t>(0x7FFE)); // will cap to 0x7FFD in int16 due to declared maximum in the attribute's mock metadata |
| MockCCPairs[7].attributeID = MockAttributeId(kColorLoopDirectionId); |
| MockCCPairs[7].valueSigned32.SetValue(-1); // will cap to -1 in int24 |
| MockCCPairs[8].attributeID = MockAttributeId(kColorLoopTimeId); |
| MockCCPairs[8].valueSigned32.SetValue(-1); // not capped |
| // Mock OO |
| MockOOPairs[0].attributeID = MockAttributeId(kOnOffAttId); |
| MockOOPairs[0].valueSigned64.SetValue(INT64_MAX); // will cap to 0x00007FFFFFFFFFFF (int48) |
| // Mock LC |
| MockLCPairs[0].attributeID = MockAttributeId(kCurrentLevelId); |
| MockLCPairs[0].valueSigned64.SetValue(INT64_MIN); // will cap to 0x0080000000000000 (int56 min) |
| MockLCPairs[1].attributeID = MockAttributeId(kCurrentFrequencyId); |
| MockLCPairs[1].valueSigned64.SetValue(INT64_MIN); // not capped |
| // Mock Fake |
| MockFKPairs[0].attributeID = MockAttributeId(kCurrentLevelId); |
| MockFKPairs[0].valueUnsigned64.SetValue(UINT64_MAX); // will cap to UINT40_MAX |
| MockFKPairs[1].attributeID = MockAttributeId(kCurrentFrequencyId); |
| MockFKPairs[1].valueSigned64.SetValue(INT64_MAX); // will cap to INT40_MIN |
| |
| // Initialize Extension Field sets as if they were received by add commands |
| OOextensionFieldSet.clusterID = MockClusterId(kOnOffClusterId); |
| OOextensionFieldSet.attributeValueList = MockOOPairs; |
| LCextensionFieldSet.clusterID = MockClusterId(kLevelControlClusterId); |
| LCextensionFieldSet.attributeValueList = MockLCPairs; |
| CCextensionFieldSet.clusterID = MockClusterId(kColorControlClusterId); |
| CCextensionFieldSet.attributeValueList = MockCCPairs; |
| |
| uint8_t mock_OO_buffer[scenes::kMaxFieldBytesPerCluster] = { 0 }; |
| uint8_t mock_LC_buffer[scenes::kMaxFieldBytesPerCluster] = { 0 }; |
| uint8_t mock_CC_buffer[scenes::kMaxFieldBytesPerCluster * 2] = { |
| 0 |
| }; // Using mock attributes way bigger than the real ones so we increase the buffer size for this test |
| ByteSpan Mock_OO_list(mock_OO_buffer); |
| ByteSpan Mock_LC_list(mock_LC_buffer); |
| ByteSpan Mock_CC_list(mock_CC_buffer); |
| |
| // Serialize Extension Field sets as if they were recovered from memory |
| writer.Init(mock_OO_buffer); |
| EXPECT_EQ(CHIP_NO_ERROR, app::DataModel::Encode(writer, TLV::AnonymousTag(), OOextensionFieldSet.attributeValueList)); |
| OO_buffer_serialized_length = writer.GetLengthWritten(); |
| |
| writer.Init(mock_LC_buffer); |
| EXPECT_EQ(CHIP_NO_ERROR, app::DataModel::Encode(writer, TLV::AnonymousTag(), LCextensionFieldSet.attributeValueList)); |
| LC_buffer_serialized_length = writer.GetLengthWritten(); |
| |
| writer.Init(mock_CC_buffer); |
| EXPECT_EQ(CHIP_NO_ERROR, app::DataModel::Encode(writer, TLV::AnonymousTag(), CCextensionFieldSet.attributeValueList)); |
| CC_buffer_serialized_length = writer.GetLengthWritten(); |
| |
| // Setup the On Off Extension field set in the expected state from a command |
| reader.Init(Mock_OO_list); |
| extensionFieldValueCapIn.clusterID = MockClusterId(kOnOffClusterId); |
| EXPECT_EQ(CHIP_NO_ERROR, reader.Next()); |
| EXPECT_EQ(CHIP_NO_ERROR, extensionFieldValueCapIn.attributeValueList.Decode(reader)); |
| |
| // Verify that the initial value is not capped |
| auto iteratorOO = extensionFieldValueCapIn.attributeValueList.begin(); |
| iteratorOO.Next(); |
| pair = iteratorOO.GetValue(); |
| EXPECT_EQ(pair.valueSigned64.Value(), MockOOPairs[0].valueSigned64.Value()); |
| |
| // Verify that we cap the value to the mock attribute size when serializing |
| EXPECT_EQ(CHIP_NO_ERROR, mpSceneHandler->SerializeAdd(kTestEndpoint4, extensionFieldValueCapIn, buff_span)); |
| EXPECT_EQ( |
| CHIP_NO_ERROR, |
| mpSceneHandler->Deserialize(kTestEndpoint4, MockClusterId(kOnOffClusterId), buff_span, extensionFieldValueCapOut)); |
| |
| // Verify that the output value is capped to int48 max value |
| int64_t int48Max = static_cast<int64_t>(0x00007FFFFFFFFFFF); |
| EXPECT_EQ(int48Max, extensionFieldValueCapOut.attributeValueList[0].valueSigned64.Value()); |
| |
| // Clear buffer |
| memset(buffer, 0, buff_span.size()); |
| // Reinit buffer |
| buff_span = MutableByteSpan(buffer); |
| |
| reader.Init(Mock_LC_list); |
| extensionFieldValueCapIn.clusterID = MockClusterId(kLevelControlClusterId); |
| EXPECT_EQ(CHIP_NO_ERROR, reader.Next()); |
| EXPECT_EQ(CHIP_NO_ERROR, extensionFieldValueCapIn.attributeValueList.Decode(reader)); |
| |
| // Verify that the initial values are not capped |
| auto iteratorLC = extensionFieldValueCapIn.attributeValueList.begin(); |
| iteratorLC.Next(); |
| pair = iteratorLC.GetValue(); |
| EXPECT_EQ(pair.valueSigned64.Value(), MockLCPairs[0].valueSigned64.Value()); |
| iteratorLC.Next(); |
| pair = iteratorLC.GetValue(); |
| EXPECT_EQ(pair.valueSigned64.Value(), MockLCPairs[1].valueSigned64.Value()); |
| |
| // Verify that we cap the value to the mock attribute size when serializing |
| EXPECT_EQ(CHIP_NO_ERROR, mpSceneHandler->SerializeAdd(kTestEndpoint4, extensionFieldValueCapIn, buff_span)); |
| EXPECT_EQ(CHIP_NO_ERROR, |
| mpSceneHandler->Deserialize(kTestEndpoint4, MockClusterId(kLevelControlClusterId), buff_span, |
| extensionFieldValueCapOut)); |
| |
| // Verify that the output value is capped to int56 min value |
| int64_t int56Min = static_cast<int64_t>(0xFF80000000000000); |
| EXPECT_EQ(int56Min, static_cast<int64_t>(extensionFieldValueCapOut.attributeValueList[0].valueSigned64.Value())); |
| |
| // Verify that the output value is not capped |
| EXPECT_EQ(INT64_MIN, extensionFieldValueCapOut.attributeValueList[1].valueSigned64.Value()); |
| |
| // Clear buffer |
| memset(buffer, 0, buff_span.size()); |
| // Reinit buffer |
| buff_span = MutableByteSpan(buffer); |
| |
| reader.Init(Mock_CC_list); |
| extensionFieldValueCapIn.clusterID = MockClusterId(kColorControlClusterId); |
| EXPECT_EQ(CHIP_NO_ERROR, reader.Next()); |
| EXPECT_EQ(CHIP_NO_ERROR, extensionFieldValueCapIn.attributeValueList.Decode(reader)); |
| |
| // Verify that the initial values are not capped |
| auto iteratorCC = extensionFieldValueCapIn.attributeValueList.begin(); |
| iteratorCC.Next(); |
| pair = iteratorCC.GetValue(); |
| EXPECT_EQ(pair.valueUnsigned32.Value(), MockCCPairs[0].valueUnsigned32.Value()); |
| iteratorCC.Next(); |
| pair = iteratorCC.GetValue(); |
| EXPECT_EQ(pair.valueUnsigned32.Value(), MockCCPairs[1].valueUnsigned32.Value()); |
| iteratorCC.Next(); |
| pair = iteratorCC.GetValue(); |
| EXPECT_EQ(pair.valueUnsigned64.Value(), MockCCPairs[2].valueUnsigned64.Value()); |
| iteratorCC.Next(); |
| pair = iteratorCC.GetValue(); |
| EXPECT_EQ(pair.valueUnsigned64.Value(), MockCCPairs[3].valueUnsigned64.Value()); |
| iteratorCC.Next(); |
| pair = iteratorCC.GetValue(); |
| EXPECT_EQ(pair.valueUnsigned64.Value(), MockCCPairs[4].valueUnsigned64.Value()); |
| iteratorCC.Next(); |
| pair = iteratorCC.GetValue(); |
| EXPECT_EQ(pair.valueSigned8.Value(), MockCCPairs[5].valueSigned8.Value()); |
| iteratorCC.Next(); |
| pair = iteratorCC.GetValue(); |
| EXPECT_EQ(pair.valueSigned16.Value(), MockCCPairs[6].valueSigned16.Value()); |
| iteratorCC.Next(); |
| pair = iteratorCC.GetValue(); |
| EXPECT_EQ(pair.valueSigned32.Value(), MockCCPairs[7].valueSigned32.Value()); |
| iteratorCC.Next(); |
| pair = iteratorCC.GetValue(); |
| EXPECT_EQ(pair.valueSigned32.Value(), MockCCPairs[8].valueSigned32.Value()); |
| |
| // Verify that we cap the value to the mock attribute size when serializing |
| EXPECT_EQ(CHIP_NO_ERROR, mpSceneHandler->SerializeAdd(kTestEndpoint4, extensionFieldValueCapIn, buff_span)); |
| EXPECT_EQ(CHIP_NO_ERROR, |
| mpSceneHandler->Deserialize(kTestEndpoint4, MockClusterId(kColorControlClusterId), buff_span, |
| extensionFieldValueCapOut)); |
| |
| // Verify that the output value is capped to uint24t max value |
| uint32_t uint24Max = static_cast<uint32_t>(0x00FFFFFF); |
| EXPECT_EQ(uint24Max, extensionFieldValueCapOut.attributeValueList[0].valueUnsigned32.Value()); |
| |
| // Verify that the output value is not capped |
| EXPECT_EQ(UINT32_MAX, extensionFieldValueCapOut.attributeValueList[1].valueUnsigned32.Value()); |
| |
| // Verify that the output value is capped to int48_t max value |
| uint64_t uint48Max = static_cast<uint64_t>(0x0000FFFFFFFFFFFF); |
| EXPECT_EQ(uint48Max, extensionFieldValueCapOut.attributeValueList[2].valueUnsigned64.Value()); |
| |
| // Verify that the output value is capped to int56_t max value |
| uint64_t uint56Max = static_cast<uint64_t>(0x00FFFFFFFFFFFFFF); |
| EXPECT_EQ(uint56Max, extensionFieldValueCapOut.attributeValueList[3].valueUnsigned64.Value()); |
| |
| // Verify that the output value is not capped |
| EXPECT_EQ(UINT64_MAX, extensionFieldValueCapOut.attributeValueList[4].valueUnsigned64.Value()); |
| |
| // Verify that the output value is capped to the defined min for this attribute |
| EXPECT_EQ(static_cast<int8_t>(-1), extensionFieldValueCapOut.attributeValueList[5].valueSigned8.Value()); |
| |
| // Verify that the output value is capped to the defined max for this attribute |
| EXPECT_EQ(0x7FFD, extensionFieldValueCapOut.attributeValueList[6].valueSigned16.Value()); |
| |
| // Verify that the output value is not capped to -1 in int24t |
| using Int24Type = app::NumericAttributeTraits<app::OddSizedInteger<3, true>>::WorkingType; |
| EXPECT_EQ(static_cast<Int24Type>(-1), extensionFieldValueCapOut.attributeValueList[7].valueSigned32.Value()); |
| |
| // Verify that the output value will not cap |
| EXPECT_EQ(-1, extensionFieldValueCapOut.attributeValueList[8].valueSigned32.Value()); |
| |
| // Clear buffer |
| memset(buffer, 0, buff_span.size()); |
| |
| LCextensionFieldSet.clusterID = MockClusterId(kFakeClusterId); |
| LCextensionFieldSet.attributeValueList = MockFKPairs; |
| |
| writer.Init(mock_LC_buffer); |
| EXPECT_EQ(CHIP_NO_ERROR, app::DataModel::Encode(writer, TLV::AnonymousTag(), LCextensionFieldSet.attributeValueList)); |
| LC_buffer_serialized_length = writer.GetLengthWritten(); |
| |
| // Reinit buffer |
| buff_span = MutableByteSpan(buffer); |
| |
| reader.Init(Mock_LC_list); |
| extensionFieldValueCapIn.clusterID = MockClusterId(kFakeClusterId); |
| EXPECT_EQ(CHIP_NO_ERROR, reader.Next()); |
| EXPECT_EQ(CHIP_NO_ERROR, extensionFieldValueCapIn.attributeValueList.Decode(reader)); |
| |
| // Verify that the initial values are not capped |
| auto iteratorFK = extensionFieldValueCapIn.attributeValueList.begin(); |
| iteratorFK.Next(); |
| pair = iteratorFK.GetValue(); |
| EXPECT_EQ(pair.valueUnsigned64.Value(), MockFKPairs[0].valueUnsigned64.Value()); |
| iteratorFK.Next(); |
| pair = iteratorFK.GetValue(); |
| EXPECT_EQ(pair.valueSigned64.Value(), MockFKPairs[1].valueSigned64.Value()); |
| |
| // Verify that we cap the value to the mock attribute size when serializing |
| EXPECT_EQ(CHIP_NO_ERROR, mpSceneHandler->SerializeAdd(kTestEndpoint4, extensionFieldValueCapIn, buff_span)); |
| EXPECT_EQ(CHIP_NO_ERROR, |
| mpSceneHandler->Deserialize(kTestEndpoint4, MockClusterId(kFakeClusterId), buff_span, extensionFieldValueCapOut)); |
| |
| // Verify that the output value is capped to uint40 max value |
| uint64_t uint40Max = static_cast<uint64_t>(0x000000FFFFFFFFFF); |
| EXPECT_EQ(uint40Max, extensionFieldValueCapOut.attributeValueList[0].valueUnsigned64.Value()); |
| |
| // Verify that the output value is capped to int40 max value |
| int64_t int40Max = static_cast<int64_t>(0x0000007FFFFFFFFF); |
| EXPECT_EQ(int40Max, extensionFieldValueCapOut.attributeValueList[1].valueSigned64.Value()); |
| |
| // Clear buffer |
| memset(buffer, 0, buff_span.size()); |
| // Reinit buffer |
| } |
| }; |
| |
| TEST_F(TestSceneTable, TestStoreScenes) |
| { |
| SceneTable * sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| SceneId sceneList[defaultTestFabricCapacity]; |
| |
| // Reset test |
| ResetSceneTable(sceneTable); |
| |
| // Populate scene1's EFS (Endpoint1) |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SceneSaveEFS(scene1)); |
| |
| // Populate scene2's EFS (Endpoint1) |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SceneSaveEFS(scene2)); |
| |
| // Populate scene3's EFS (Endpoint2) |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SceneSaveEFS(scene3)); |
| |
| // Populate scene4's EFS (Endpoint2) |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SceneSaveEFS(scene4)); |
| |
| // Populate scene8's EFS (Endpoint3) |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SceneSaveEFS(scene8)); |
| |
| SceneTableEntry scene; |
| Span<SceneId> sceneListSpan = Span<SceneId>(sceneList); |
| Span<SceneId> emptyListSpan = Span<SceneId>(sceneList, 0); |
| Span<SceneId> smallListSpan = Span<SceneId>(sceneList, 1); |
| |
| // Test Get All scenes in Group in empty scene table |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetAllSceneIdsInGroup(kFabric1, kGroup1, emptyListSpan)); |
| EXPECT_EQ(0u, emptyListSpan.size()); |
| |
| // Set test |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene1)); |
| |
| // Test single scene in table with 0 size span |
| EXPECT_EQ(CHIP_ERROR_BUFFER_TOO_SMALL, sceneTable->GetAllSceneIdsInGroup(kFabric1, kGroup1, emptyListSpan)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetAllSceneIdsInGroup(kFabric1, kGroup1, smallListSpan)); |
| EXPECT_EQ(1u, smallListSpan.size()); |
| |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene2)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene3)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene4)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene5)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene6)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene7)); |
| |
| // Too many scenes for 1 fabric |
| EXPECT_EQ(CHIP_ERROR_NO_MEMORY, sceneTable->SetSceneTableEntry(kFabric1, scene9)); |
| |
| // Not Found |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId9, scene)); |
| EXPECT_EQ(CHIP_ERROR_BUFFER_TOO_SMALL, sceneTable->GetAllSceneIdsInGroup(kFabric1, kGroup1, emptyListSpan)); |
| |
| // Get test |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId1, scene)); |
| EXPECT_EQ(scene, scene1); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SceneApplyEFS(scene)); |
| |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId2, scene)); |
| EXPECT_EQ(scene, scene2); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SceneApplyEFS(scene)); |
| |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId3, scene)); |
| EXPECT_EQ(scene, scene3); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SceneApplyEFS(scene)); |
| |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId4, scene)); |
| EXPECT_EQ(scene, scene4); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SceneApplyEFS(scene)); |
| |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId5, scene)); |
| EXPECT_EQ(scene, scene5); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId6, scene)); |
| EXPECT_EQ(scene, scene6); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId7, scene)); |
| EXPECT_EQ(scene, scene7); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SceneApplyEFS(scene)); |
| |
| // Test error when list too small in a full table |
| // Test failure for 3 spaces in 4 scenes list |
| EXPECT_EQ(CHIP_ERROR_BUFFER_TOO_SMALL, sceneTable->GetAllSceneIdsInGroup(kFabric1, kGroup1, smallListSpan)); |
| // Test failure for no space in a 4 scenes list |
| EXPECT_EQ(CHIP_ERROR_BUFFER_TOO_SMALL, sceneTable->GetAllSceneIdsInGroup(kFabric1, kGroup1, emptyListSpan)); |
| // Test failure for no space in a 1 scene list |
| EXPECT_EQ(CHIP_ERROR_BUFFER_TOO_SMALL, sceneTable->GetAllSceneIdsInGroup(kFabric1, kGroup3, emptyListSpan)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetAllSceneIdsInGroup(kFabric1, kGroup3, smallListSpan)); |
| EXPECT_EQ(1u, smallListSpan.size()); |
| |
| // Test successfully getting Ids from various groups |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetAllSceneIdsInGroup(kFabric1, kGroup1, sceneListSpan)); |
| EXPECT_EQ(4u, sceneListSpan.size()); |
| EXPECT_EQ(kScene1, sceneList[0]); |
| EXPECT_EQ(kScene2, sceneList[1]); |
| EXPECT_EQ(kScene3, sceneList[2]); |
| EXPECT_EQ(kScene4, sceneList[3]); |
| |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetAllSceneIdsInGroup(kFabric1, kGroup2, sceneListSpan)); |
| EXPECT_EQ(2u, sceneListSpan.size()); |
| EXPECT_EQ(kScene5, sceneList[0]); |
| EXPECT_EQ(kScene6, sceneList[1]); |
| |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetAllSceneIdsInGroup(kFabric1, kGroup3, sceneListSpan)); |
| EXPECT_EQ(1u, sceneListSpan.size()); |
| EXPECT_EQ(kScene7, sceneList[0]); |
| |
| uint8_t sceneCount = 0; |
| sceneTable->GetEndpointSceneCount(sceneCount); |
| sceneTable->GetFabricSceneCount(kFabric1, sceneCount); |
| } |
| |
| TEST_F(TestSceneTable, TestOverwriteScenes) |
| { |
| SceneTable * sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| |
| uint8_t sceneCount = 0; |
| sceneTable->GetEndpointSceneCount(sceneCount); |
| sceneTable->GetFabricSceneCount(kFabric1, sceneCount); |
| SceneTableEntry scene; |
| // Overwriting the first entry |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene10)); |
| // Overwriting in the middle |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene11)); |
| // Overwriting the last entry |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene12)); |
| |
| // Scene 10 has the same sceneId as scene 1, Get->sceneId1 should thus return scene 10, etc. |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId1, scene)); |
| EXPECT_EQ(scene, scene10); |
| |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId5, scene)); |
| EXPECT_EQ(scene, scene11); |
| |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId7, scene)); |
| EXPECT_EQ(scene, scene12); |
| } |
| |
| TEST_F(TestSceneTable, TestIterateScenes) |
| { |
| SceneTable * sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| |
| SceneTableEntry scene; |
| auto * iterator = sceneTable->IterateSceneEntries(kFabric1); |
| |
| ASSERT_NE(iterator, nullptr); |
| |
| if (iterator) |
| { |
| EXPECT_EQ(iterator->Count(), 7u); |
| EXPECT_TRUE(iterator->Next(scene)); |
| EXPECT_EQ(scene, scene10); |
| EXPECT_TRUE(iterator->Next(scene)); |
| EXPECT_EQ(scene, scene2); |
| EXPECT_TRUE(iterator->Next(scene)); |
| EXPECT_EQ(scene, scene3); |
| EXPECT_TRUE(iterator->Next(scene)); |
| EXPECT_EQ(scene, scene4); |
| EXPECT_TRUE(iterator->Next(scene)); |
| EXPECT_EQ(scene, scene11); |
| EXPECT_TRUE(iterator->Next(scene)); |
| EXPECT_EQ(scene, scene6); |
| EXPECT_TRUE(iterator->Next(scene)); |
| EXPECT_EQ(scene, scene12); |
| |
| EXPECT_FALSE(iterator->Next(scene)); |
| |
| iterator->Release(); |
| } |
| } |
| |
| TEST_F(TestSceneTable, TestRemoveScenes) |
| { |
| SceneTableImpl * sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| |
| SceneTableEntry scene; |
| |
| // Removing non-existing entry should not return errors |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->RemoveSceneTableEntry(kFabric1, scene9.mStorageId)); |
| |
| // Remove middle |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->RemoveSceneTableEntry(kFabric1, scene5.mStorageId)); |
| auto * iterator = sceneTable->IterateSceneEntries(kFabric1); |
| EXPECT_EQ(iterator->Count(), 6u); |
| EXPECT_TRUE(iterator->Next(scene)); |
| EXPECT_EQ(scene, scene10); |
| iterator->Release(); |
| |
| // Add scene in middle, a spot should have been freed |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene9)); |
| iterator = sceneTable->IterateSceneEntries(kFabric1); |
| EXPECT_EQ(iterator->Count(), 7u); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId9, scene)); |
| EXPECT_EQ(scene, scene9); |
| iterator->Release(); |
| |
| // Remove the recently added scene 9 |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->RemoveSceneTableEntry(kFabric1, scene9.mStorageId)); |
| iterator = sceneTable->IterateSceneEntries(kFabric1); |
| EXPECT_EQ(iterator->Count(), 6u); |
| EXPECT_TRUE(iterator->Next(scene)); |
| EXPECT_EQ(scene, scene10); |
| iterator->Release(); |
| |
| // Remove first |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->RemoveSceneTableEntryAtPosition(kTestEndpoint1, kFabric1, 0)); |
| iterator = sceneTable->IterateSceneEntries(kFabric1); |
| EXPECT_EQ(iterator->Count(), 5u); |
| EXPECT_TRUE(iterator->Next(scene)); |
| EXPECT_EQ(scene, scene2); |
| iterator->Release(); |
| |
| // Remove Next |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->RemoveSceneTableEntry(kFabric1, scene3.mStorageId)); |
| iterator = sceneTable->IterateSceneEntries(kFabric1); |
| EXPECT_EQ(iterator->Count(), 4u); |
| EXPECT_TRUE(iterator->Next(scene)); |
| EXPECT_EQ(scene, scene2); |
| EXPECT_TRUE(iterator->Next(scene)); |
| EXPECT_EQ(scene, scene4); |
| iterator->Release(); |
| |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->RemoveSceneTableEntry(kFabric1, scene2.mStorageId)); |
| iterator = sceneTable->IterateSceneEntries(kFabric1); |
| EXPECT_EQ(iterator->Count(), 3u); |
| EXPECT_TRUE(iterator->Next(scene)); |
| EXPECT_EQ(scene, scene4); |
| iterator->Release(); |
| |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->RemoveSceneTableEntry(kFabric1, scene4.mStorageId)); |
| iterator = sceneTable->IterateSceneEntries(kFabric1); |
| EXPECT_EQ(iterator->Count(), 2u); |
| EXPECT_TRUE(iterator->Next(scene)); |
| EXPECT_EQ(scene, scene6); |
| iterator->Release(); |
| |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->RemoveSceneTableEntry(kFabric1, scene6.mStorageId)); |
| iterator = sceneTable->IterateSceneEntries(kFabric1); |
| EXPECT_EQ(iterator->Count(), 1u); |
| EXPECT_TRUE(iterator->Next(scene)); |
| EXPECT_EQ(scene, scene12); |
| iterator->Release(); |
| |
| // Remove last |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->RemoveSceneTableEntry(kFabric1, scene7.mStorageId)); |
| iterator = sceneTable->IterateSceneEntries(kFabric1); |
| EXPECT_EQ(iterator->Count(), 0u); |
| EXPECT_FALSE(iterator->Next(scene)); |
| iterator->Release(); |
| |
| // Remove at empty position, shouldn't trigger error |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->RemoveSceneTableEntryAtPosition(kTestEndpoint1, kFabric1, defaultTestFabricCapacity - 1)); |
| |
| iterator = sceneTable->IterateSceneEntries(kFabric1); |
| EXPECT_EQ(iterator->Count(), 0u); |
| iterator->Release(); |
| |
| // Test Remove all scenes in Group |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene1)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene2)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene3)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene4)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene5)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene6)); |
| iterator = sceneTable->IterateSceneEntries(kFabric1); |
| EXPECT_EQ(iterator->Count(), 6u); |
| iterator->Release(); |
| |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->DeleteAllScenesInGroup(kFabric1, kGroup1)); |
| iterator = sceneTable->IterateSceneEntries(kFabric1); |
| EXPECT_EQ(iterator->Count(), 2u); |
| EXPECT_TRUE(iterator->Next(scene)); |
| EXPECT_EQ(scene, scene5); |
| EXPECT_TRUE(iterator->Next(scene)); |
| EXPECT_EQ(scene, scene6); |
| iterator->Release(); |
| |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->DeleteAllScenesInGroup(kFabric1, kGroup2)); |
| iterator = sceneTable->IterateSceneEntries(kFabric1); |
| EXPECT_EQ(iterator->Count(), 0u); |
| iterator->Release(); |
| } |
| |
| TEST_F(TestSceneTable, TestFabricScenes) |
| { |
| SceneTable * sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| |
| // Reset test |
| ResetSceneTable(sceneTable); |
| |
| SceneTableEntry scene; |
| uint8_t fabric_capacity = 0; |
| |
| // Verify capacities are at max |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric2, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric3, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity, fabric_capacity); |
| |
| // Fabric 1 inserts |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene1)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene2)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene3)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene4)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene5)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene6)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene7)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(0, fabric_capacity); |
| |
| uint8_t scene_count = 0; |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetFabricSceneCount(kFabric1, scene_count)); |
| EXPECT_EQ(defaultTestFabricCapacity, scene_count); |
| |
| // Fabric 2 inserts |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric2, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene1)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene2)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene3)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene4)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric2, fabric_capacity)); |
| EXPECT_EQ((defaultTestFabricCapacity - 4), fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetFabricSceneCount(kFabric2, scene_count)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetEndpointSceneCount(scene_count)); |
| EXPECT_EQ(11, scene_count); |
| |
| // Fabric 3 inserts, should only be 4 spaces left at this point since 12 got taken |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric3, fabric_capacity)); |
| EXPECT_EQ(defaultTestTableSize - 11, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric3, scene1)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric3, scene2)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric3, scene3)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric3, scene4)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric3, scene5)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetFabricSceneCount(kFabric3, scene_count)); |
| EXPECT_EQ(5, scene_count); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetEndpointSceneCount(scene_count)); |
| EXPECT_EQ(defaultTestTableSize, scene_count); |
| |
| // Checks capacity is now 0 accross all fabrics |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(0, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric2, fabric_capacity)); |
| EXPECT_EQ(0, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric3, fabric_capacity)); |
| EXPECT_EQ(0, fabric_capacity); |
| |
| // To many scenes accross fabrics (Max scenes accross fabrics == 16) |
| EXPECT_EQ(CHIP_ERROR_NO_MEMORY, sceneTable->SetSceneTableEntry(kFabric3, scene6)); |
| EXPECT_EQ(CHIP_ERROR_NO_MEMORY, sceneTable->SetSceneTableEntry(kFabric2, scene5)); |
| |
| // Verifying all inserted scenes are accessible |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId1, scene)); |
| EXPECT_EQ(scene, scene1); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId2, scene)); |
| EXPECT_EQ(scene, scene2); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId3, scene)); |
| EXPECT_EQ(scene, scene3); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId4, scene)); |
| EXPECT_EQ(scene, scene4); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId5, scene)); |
| EXPECT_EQ(scene, scene5); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId6, scene)); |
| EXPECT_EQ(scene, scene6); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId7, scene)); |
| EXPECT_EQ(scene, scene7); |
| |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric2, sceneId1, scene)); |
| EXPECT_EQ(scene, scene1); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric2, sceneId2, scene)); |
| EXPECT_EQ(scene, scene2); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric2, sceneId3, scene)); |
| EXPECT_EQ(scene, scene3); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric2, sceneId4, scene)); |
| EXPECT_EQ(scene, scene4); |
| |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric3, sceneId1, scene)); |
| EXPECT_EQ(scene, scene1); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric3, sceneId2, scene)); |
| EXPECT_EQ(scene, scene2); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric3, sceneId3, scene)); |
| EXPECT_EQ(scene, scene3); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric3, sceneId4, scene)); |
| EXPECT_EQ(scene, scene4); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric3, sceneId5, scene)); |
| EXPECT_EQ(scene, scene5); |
| |
| // Remove Fabric 1 |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->RemoveFabric(kFabric1)); |
| // Verify Fabric 1 removed |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetFabricSceneCount(kFabric1, scene_count)); |
| EXPECT_EQ(0, scene_count); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetEndpointSceneCount(scene_count)); |
| EXPECT_EQ(9, scene_count); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId1, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId2, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId3, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId4, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId5, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId6, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId7, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId8, scene)); |
| |
| // Verify Fabric 2 still there |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetFabricSceneCount(kFabric2, scene_count)); |
| EXPECT_EQ(4, scene_count); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric2, sceneId1, scene)); |
| EXPECT_EQ(scene, scene1); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric2, sceneId2, scene)); |
| EXPECT_EQ(scene, scene2); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric2, sceneId3, scene)); |
| EXPECT_EQ(scene, scene3); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric2, sceneId4, scene)); |
| EXPECT_EQ(scene, scene4); |
| |
| // Verify capacity updated for all fabrics |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric2, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity - 4, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric3, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity - 5, fabric_capacity); |
| |
| // Verify we can now write more scenes in scene fabric 2 |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene5)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene6)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene7)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric2, sceneId5, scene)); |
| EXPECT_EQ(scene, scene5); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric2, sceneId6, scene)); |
| EXPECT_EQ(scene, scene6); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric2, sceneId7, scene)); |
| EXPECT_EQ(scene, scene7); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetFabricSceneCount(kFabric2, scene_count)); |
| EXPECT_EQ(7, scene_count); |
| |
| // Verify capacity updated properly |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(4, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric3, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity - 5, fabric_capacity); |
| |
| // Verify Fabric 3 still there |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric3, sceneId1, scene)); |
| EXPECT_EQ(scene, scene1); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric3, sceneId2, scene)); |
| EXPECT_EQ(scene, scene2); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric3, sceneId3, scene)); |
| EXPECT_EQ(scene, scene3); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric3, sceneId4, scene)); |
| EXPECT_EQ(scene, scene4); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric3, sceneId5, scene)); |
| EXPECT_EQ(scene, scene5); |
| |
| // Remove Fabric 2 |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->RemoveFabric(kFabric2)); |
| // Verify Fabric 2 removed |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetFabricSceneCount(kFabric2, scene_count)); |
| EXPECT_EQ(0, scene_count); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetEndpointSceneCount(scene_count)); |
| EXPECT_EQ(5, scene_count); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric2, sceneId1, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric2, sceneId2, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric2, sceneId3, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric2, sceneId4, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric2, sceneId5, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric2, sceneId6, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric2, sceneId7, scene)); |
| |
| // Verify Fabric 3 still there |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetFabricSceneCount(kFabric3, scene_count)); |
| EXPECT_EQ(5, scene_count); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric3, sceneId1, scene)); |
| EXPECT_EQ(scene, scene1); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric3, sceneId2, scene)); |
| EXPECT_EQ(scene, scene2); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric3, sceneId3, scene)); |
| EXPECT_EQ(scene, scene3); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric3, sceneId4, scene)); |
| EXPECT_EQ(scene, scene4); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric3, sceneId5, scene)); |
| EXPECT_EQ(scene, scene5); |
| |
| // Remove Fabric 3 |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->RemoveFabric(kFabric3)); |
| // Verify Fabric 3 removed |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetFabricSceneCount(kFabric2, scene_count)); |
| EXPECT_EQ(0, scene_count); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetEndpointSceneCount(scene_count)); |
| EXPECT_EQ(0, scene_count); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric3, sceneId1, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric3, sceneId2, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric3, sceneId3, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric3, sceneId4, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric3, sceneId5, scene)); |
| |
| // Confirm all counts are at 0 |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetFabricSceneCount(kFabric1, scene_count)); |
| EXPECT_EQ(0, scene_count); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetFabricSceneCount(kFabric2, scene_count)); |
| EXPECT_EQ(0, scene_count); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetFabricSceneCount(kFabric3, scene_count)); |
| EXPECT_EQ(0, scene_count); |
| |
| // Verify capacity updated for all fabrics |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric2, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric3, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity, fabric_capacity); |
| } |
| |
| TEST_F(TestSceneTable, TestEndpointScenes) |
| { |
| // Get Count for Endpoint 1 |
| SceneTable * sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| |
| // Reset test |
| ResetSceneTable(sceneTable); |
| SceneTableEntry scene; |
| |
| // Verify all endpoints are empty |
| uint8_t endpoint_scene_count = 0; |
| |
| // Get Count for Endpoint 1 |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetEndpointSceneCount(endpoint_scene_count)); |
| EXPECT_EQ(0, endpoint_scene_count); |
| // Get Count for Endpoint 2 |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint2, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetEndpointSceneCount(endpoint_scene_count)); |
| EXPECT_EQ(0, endpoint_scene_count); |
| // Get Count for Endpoint 3 |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint3, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetEndpointSceneCount(endpoint_scene_count)); |
| EXPECT_EQ(0, endpoint_scene_count); |
| |
| // Test Scenes insertion not accessible accross all endpoints |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene1)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene1)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetEndpointSceneCount(endpoint_scene_count)); |
| EXPECT_EQ(2, endpoint_scene_count); |
| |
| uint8_t fabric_capacity = 0; |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity - 1, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric2, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity - 1, fabric_capacity); |
| |
| // Endpoint2 |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint2, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetEndpointSceneCount(endpoint_scene_count)); |
| EXPECT_EQ(0, endpoint_scene_count); |
| // Endpoint3 |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint3, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetEndpointSceneCount(endpoint_scene_count)); |
| EXPECT_EQ(0, endpoint_scene_count); |
| |
| // Check if scene present in Endpoint 1 |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId1, scene)); |
| EXPECT_EQ(scene, scene1); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric2, sceneId1, scene)); |
| EXPECT_EQ(scene, scene1); |
| |
| // Check if scene present in Endpoint 2 |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint2, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId1, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric2, sceneId1, scene)); |
| // Check if scene present in Endpoint 3 |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint3, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId1, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric2, sceneId1, scene)); |
| |
| // Test removal on different endpoints do not affect each endpoints |
| // Insertion on Endpoint2 |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint2, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene1)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId1, scene)); |
| EXPECT_EQ(scene, scene1); |
| |
| // Removal on Endpoint1 |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->RemoveSceneTableEntry(kFabric1, sceneId1)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId1, scene)); |
| |
| // Scene present on Endpoint2 |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint2, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId1, scene)); |
| EXPECT_EQ(scene, scene1); |
| |
| // Removal on Endpoint 2 |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->RemoveSceneTableEntry(kFabric1, sceneId1)); |
| |
| // Removal on Endpoint 1 |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->RemoveSceneTableEntry(kFabric2, sceneId1)); |
| |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetEndpointSceneCount(endpoint_scene_count)); |
| EXPECT_EQ(0, endpoint_scene_count); |
| // Endpoint 2 |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint2, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetEndpointSceneCount(endpoint_scene_count)); |
| EXPECT_EQ(0, endpoint_scene_count); |
| // Endpoint 3 |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint3, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetEndpointSceneCount(endpoint_scene_count)); |
| EXPECT_EQ(0, endpoint_scene_count); |
| |
| // Test the fabric capacity accross endpoint |
| // Fill fabric 1 endpoint 1 |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene1)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene2)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene3)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene4)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene5)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene6)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene7)); |
| |
| // Fill fabric 2 endpoint 1 |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene1)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene2)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene3)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene4)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene5)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene6)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene7)); |
| |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(0, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric2, fabric_capacity)); |
| EXPECT_EQ(0, fabric_capacity); |
| |
| // Endpoints 2 and 3 should be unaffected |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint2, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric2, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity, fabric_capacity); |
| |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint3, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric2, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity, fabric_capacity); |
| |
| // Verify filling Fabric on endpoint 2 does not affect on endpoint 3 despite Max per fabric being reached by adding Endpoint1 |
| // and Endpoint2 |
| // Fill fabric 1 endpoint 2 |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint2, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene1)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene2)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene3)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene4)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene5)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene6)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene7)); |
| |
| // Fill fabric 2 endpoint 2 |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint2, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene1)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene2)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene3)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene4)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene5)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene6)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene7)); |
| // scene count to Endpoint |
| |
| // Endpoint 3 still unafected |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint3, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric2, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity, fabric_capacity); |
| |
| // Fill fabric 1 endpoint 3 |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene1)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene2)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene3)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene4)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene5)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene6)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene7)); |
| |
| // Test removal of Endpoint clears scene on all fabrics for that endpoint |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint2, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->RemoveEndpoint()); |
| |
| // Check Fabric1 on Endpoint 2 |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId1, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId2, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId3, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId4, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId5, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId6, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId7, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric2, sceneId1, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric2, sceneId2, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric2, sceneId3, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric2, sceneId4, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric2, sceneId5, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric2, sceneId6, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric2, sceneId7, scene)); |
| |
| // Check Fabric 1 and 2 on Endpoint 1 |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId1, scene)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId2, scene)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId3, scene)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId4, scene)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId5, scene)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId6, scene)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId7, scene)); |
| |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric2, sceneId1, scene)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric2, sceneId2, scene)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric2, sceneId3, scene)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric2, sceneId4, scene)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric2, sceneId5, scene)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric2, sceneId6, scene)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric2, sceneId7, scene)); |
| |
| // Check Fabric 1 on Endpoint 3 |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint3, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId1, scene)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId2, scene)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId3, scene)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId4, scene)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId5, scene)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId6, scene)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetSceneTableEntry(kFabric1, sceneId7, scene)); |
| |
| // Test removal of fabric clears scene fabric on all endpoints |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| sceneTable->RemoveFabric(kFabric1); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId1, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId2, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId3, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId4, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId5, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId6, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId7, scene)); |
| |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint2, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId1, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId2, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId3, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId4, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId5, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId6, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId7, scene)); |
| |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint3, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId1, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId2, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId3, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId4, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId5, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId6, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId7, scene)); |
| |
| sceneTable->RemoveFabric(kFabric2); |
| |
| // Validate endpoints are empty |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetEndpointSceneCount(endpoint_scene_count)); |
| EXPECT_EQ(0, endpoint_scene_count); |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint2, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetEndpointSceneCount(endpoint_scene_count)); |
| EXPECT_EQ(0, endpoint_scene_count); |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint3, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetEndpointSceneCount(endpoint_scene_count)); |
| EXPECT_EQ(0, endpoint_scene_count); |
| |
| // Validate Fabric capacities at maximum accross all endpoints |
| |
| // Endpoint 1 |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric2, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity, fabric_capacity); |
| // Endpoint 2 |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint2, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric2, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity, fabric_capacity); |
| // Endpoint 3 |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint3, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric2, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity, fabric_capacity); |
| |
| // Test of Get with changes to Endpoint capacity |
| // Endpoint 1 |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestTableSize - 2); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity - 1, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric2, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity - 1, fabric_capacity); |
| |
| // Test Endpoint 2's capacity remains unaffected |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint2, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric2, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity, fabric_capacity); |
| ASSERT_NE(nullptr, sceneTable); |
| |
| // Test Insertion then change of capacity |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene1)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene2)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene3)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene4)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity - 4, fabric_capacity); |
| |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestFabricCapacity - 2); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(defaultTestFabricCapacity - 6, fabric_capacity); |
| |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestFabricCapacity - 4); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(0, fabric_capacity); |
| |
| // Test making the endpoint scene table smaller than the actual number of scenes on it |
| sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestFabricCapacity - 5); |
| ASSERT_NE(nullptr, sceneTable); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(0, fabric_capacity); |
| } |
| |
| TEST_F(TestSceneTable, TestOTAChanges) |
| { |
| SceneTable * sceneTable = scenes::GetSceneTableImpl(kTestEndpoint1, defaultTestTableSize); |
| ASSERT_NE(nullptr, sceneTable); |
| |
| // Reset test |
| ResetSceneTable(sceneTable); |
| |
| SceneTableEntry scene; |
| uint8_t fabric_capacity = 0; |
| uint8_t fabricsFullCount = defaultTestTableSize - 2; |
| |
| // Fill scene table |
| // Fill fabric 1 to capacity |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene1)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene2)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene3)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene4)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene5)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene6)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric1, scene7)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(0, fabric_capacity); |
| uint8_t scene_table_fabric1_capacity = fabric_capacity; |
| auto * iterator = sceneTable->IterateSceneEntries(kFabric1); |
| EXPECT_EQ(defaultTestFabricCapacity, iterator->Count()); |
| iterator->Release(); |
| |
| // Fill fabric 2 to capacity |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene1)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene2)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene3)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene4)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene5)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene6)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->SetSceneTableEntry(kFabric2, scene7)); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(0, fabric_capacity); |
| uint8_t scene_table_fabric2_capacity = fabric_capacity; |
| iterator = sceneTable->IterateSceneEntries(kFabric2); |
| EXPECT_EQ(defaultTestFabricCapacity, iterator->Count()); |
| iterator->Release(); |
| // SceneTable should be full at this point |
| uint8_t scene_count; |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetEndpointSceneCount(scene_count)); |
| // Global count should not have been modified |
| EXPECT_EQ(fabricsFullCount, scene_count); |
| |
| // Create a scene table with a greater capacity than the original one (Max allowed capacity from gen_config.h) |
| TestSceneTableImpl ExpandedSceneTable(scenes::kMaxScenesPerFabric, scenes::kMaxScenesPerEndpoint); |
| EXPECT_EQ(CHIP_NO_ERROR, ExpandedSceneTable.Init(mpTestStorage)); |
| ExpandedSceneTable.SetEndpoint(kTestEndpoint1); |
| |
| EXPECT_EQ(CHIP_NO_ERROR, ExpandedSceneTable.GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(scene_table_fabric1_capacity + (scenes::kMaxScenesPerFabric - defaultTestFabricCapacity), fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, ExpandedSceneTable.GetRemainingCapacity(kFabric2, fabric_capacity)); |
| EXPECT_EQ(scene_table_fabric2_capacity + (scenes::kMaxScenesPerFabric - defaultTestFabricCapacity), fabric_capacity); |
| |
| // We should be able to insert 4 scenes into fabric 2 |
| EXPECT_EQ(CHIP_NO_ERROR, ExpandedSceneTable.SetSceneTableEntry(kFabric2, scene9)); |
| EXPECT_EQ(CHIP_NO_ERROR, ExpandedSceneTable.SetSceneTableEntry(kFabric2, scene13)); |
| EXPECT_EQ(CHIP_NO_ERROR, ExpandedSceneTable.SetSceneTableEntry(kFabric2, scene14)); |
| EXPECT_EQ(CHIP_NO_ERROR, ExpandedSceneTable.SetSceneTableEntry(kFabric2, scene15)); |
| EXPECT_EQ(CHIP_NO_ERROR, ExpandedSceneTable.GetRemainingCapacity(kFabric2, fabric_capacity)); |
| EXPECT_EQ(0, fabric_capacity); |
| |
| // Fabric 1's capacity should have remain unchanged |
| EXPECT_EQ(CHIP_NO_ERROR, ExpandedSceneTable.GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(scene_table_fabric1_capacity + (scenes::kMaxScenesPerFabric - defaultTestFabricCapacity), fabric_capacity); |
| |
| // Global count should have increased by (scenes::kMaxScenesPerFarbic - defaultTestFabricCapacity) |
| EXPECT_EQ(CHIP_NO_ERROR, ExpandedSceneTable.GetEndpointSceneCount(scene_count)); |
| EXPECT_EQ(fabricsFullCount + (scenes::kMaxScenesPerFabric - defaultTestFabricCapacity), scene_count); |
| |
| // Same test for 4 insertion in fabric 1 |
| EXPECT_EQ(CHIP_NO_ERROR, ExpandedSceneTable.SetSceneTableEntry(kFabric1, scene9)); |
| EXPECT_EQ(CHIP_NO_ERROR, ExpandedSceneTable.SetSceneTableEntry(kFabric1, scene13)); |
| EXPECT_EQ(CHIP_NO_ERROR, ExpandedSceneTable.SetSceneTableEntry(kFabric1, scene14)); |
| EXPECT_EQ(CHIP_NO_ERROR, ExpandedSceneTable.SetSceneTableEntry(kFabric1, scene15)); |
| EXPECT_EQ(CHIP_NO_ERROR, ExpandedSceneTable.GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(0, fabric_capacity); |
| |
| // Global count should be at defaultTestTableSize + (scenes::kMaxScenesPerEndpoint - defaultTestTableSize) |
| EXPECT_EQ(CHIP_NO_ERROR, ExpandedSceneTable.GetEndpointSceneCount(scene_count)); |
| EXPECT_EQ(fabricsFullCount + (scenes::kMaxScenesPerEndpoint - defaultTestTableSize), scene_count); |
| |
| // Test failure to init a SceneTable with sizes above the defined max scenes per fabric or globaly |
| TestSceneTableImpl SceneTableTooManyPerFabric(scenes::kMaxScenesPerFabric + 1, scenes::kMaxScenesPerEndpoint); |
| EXPECT_EQ(CHIP_ERROR_INVALID_INTEGER_VALUE, SceneTableTooManyPerFabric.Init(mpTestStorage)); |
| SceneTableTooManyPerFabric.Finish(); |
| |
| TestSceneTableImpl SceneTableTooManyGlobal(scenes::kMaxScenesPerFabric, scenes::kMaxScenesPerEndpoint + 1); |
| EXPECT_EQ(CHIP_ERROR_INVALID_INTEGER_VALUE, SceneTableTooManyGlobal.Init(mpTestStorage)); |
| SceneTableTooManyGlobal.Finish(); |
| |
| // Create a new table with a lower limit of scenes per fabric |
| uint8_t newCapacity = defaultTestFabricCapacity - 1; |
| uint8_t newTableSize = defaultTestTableSize - 2; |
| uint8_t capacityDifference = static_cast<uint8_t>(scenes::kMaxScenesPerFabric - newCapacity); |
| TestSceneTableImpl ReducedSceneTable(newCapacity, newTableSize); |
| EXPECT_EQ(CHIP_NO_ERROR, ReducedSceneTable.Init(mpTestStorage)); |
| ReducedSceneTable.SetEndpoint(kTestEndpoint1); |
| |
| // Global count should not have been modified |
| EXPECT_EQ(CHIP_NO_ERROR, ReducedSceneTable.GetEndpointSceneCount(scene_count)); |
| EXPECT_EQ(scenes::kMaxScenesPerEndpoint - 2, scene_count); |
| EXPECT_EQ(CHIP_NO_ERROR, ReducedSceneTable.GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(0, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, ReducedSceneTable.GetRemainingCapacity(kFabric2, fabric_capacity)); |
| EXPECT_EQ(0, fabric_capacity); |
| |
| // Load a scene from fabric 1, this should adjust fabric 1 scene count in flash |
| EXPECT_EQ(CHIP_NO_ERROR, ReducedSceneTable.GetSceneTableEntry(kFabric1, sceneId1, scene)); |
| EXPECT_EQ(scene, scene1); |
| |
| // The number count of scenes in Fabric 1 should have been adjusted here |
| iterator = ReducedSceneTable.IterateSceneEntries(kFabric1); |
| EXPECT_EQ(newCapacity, iterator->Count()); |
| iterator->Release(); |
| // Capacity should still be 0 in fabric 1 |
| EXPECT_EQ(CHIP_NO_ERROR, ReducedSceneTable.GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(0, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, ReducedSceneTable.GetEndpointSceneCount(scene_count)); |
| // Global count should have been reduced by the difference between the max fabric capacity of a fabric and the |
| // new fabric capacity since we haven't loaded from fabric 2 yet |
| EXPECT_EQ(scenes::kMaxScenesPerEndpoint - 2 - capacityDifference, scene_count); |
| |
| // Remove a Scene from the Fabric 1 |
| EXPECT_EQ(CHIP_NO_ERROR, ReducedSceneTable.RemoveSceneTableEntry(kFabric1, scene1.mStorageId)); |
| // Check count updated for fabric |
| iterator = ReducedSceneTable.IterateSceneEntries(kFabric1); |
| EXPECT_EQ(static_cast<uint8_t>(newCapacity - 1), iterator->Count()); |
| iterator->Release(); |
| // Check fabric still doesn't have capacity because fabric 2 still have a higher number of scene than allowed |
| EXPECT_EQ(CHIP_NO_ERROR, ReducedSceneTable.GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(0, fabric_capacity); |
| // Remove another scene from fabric 1 |
| EXPECT_EQ(CHIP_NO_ERROR, ReducedSceneTable.RemoveSceneTableEntry(kFabric1, scene2.mStorageId)); |
| EXPECT_EQ(CHIP_NO_ERROR, ReducedSceneTable.RemoveSceneTableEntry(kFabric1, scene3.mStorageId)); |
| EXPECT_EQ(CHIP_NO_ERROR, ReducedSceneTable.RemoveSceneTableEntry(kFabric1, scene4.mStorageId)); |
| // Check count updated for fabric |
| iterator = ReducedSceneTable.IterateSceneEntries(kFabric1); |
| EXPECT_EQ(2u, iterator->Count()); |
| iterator->Release(); |
| |
| // Confirm global count has been updated |
| EXPECT_EQ(CHIP_NO_ERROR, ReducedSceneTable.GetEndpointSceneCount(scene_count)); |
| EXPECT_EQ(13, scene_count); |
| // Confirm we now have capacity in fabric one |
| EXPECT_EQ(CHIP_NO_ERROR, ReducedSceneTable.GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(1, fabric_capacity); |
| |
| // Load a scene from fabric 2, this should adjust fabric 2 scene count in flash |
| EXPECT_EQ(CHIP_NO_ERROR, ReducedSceneTable.GetSceneTableEntry(kFabric2, sceneId1, scene)); |
| EXPECT_EQ(scene, scene1); |
| |
| // The number count of scenes in Fabric 2 should have been adjusted here |
| iterator = ReducedSceneTable.IterateSceneEntries(kFabric2); |
| EXPECT_EQ(defaultTestFabricCapacity - 1u, iterator->Count()); |
| iterator->Release(); |
| // Global count should also have been adjusted |
| EXPECT_EQ(CHIP_NO_ERROR, ReducedSceneTable.GetEndpointSceneCount(scene_count)); |
| // had 22 scenes, truncated 5 from both (10) and deleted 4 from fabric 1: 8 scenes left |
| EXPECT_EQ(8, scene_count); |
| // Confirm we now have capacity of 6 in the first fabric since we previously removed 6 scenes form there |
| EXPECT_EQ(CHIP_NO_ERROR, ReducedSceneTable.GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(4, fabric_capacity); |
| // Fabric 2 should still be at capacity |
| EXPECT_EQ(CHIP_NO_ERROR, ReducedSceneTable.GetRemainingCapacity(kFabric2, fabric_capacity)); |
| EXPECT_EQ(0, fabric_capacity); |
| |
| ReducedSceneTable.Finish(); |
| |
| // The Scene 8 should now have been truncated from the memory and thus not be accessible from both fabrics in the |
| // original scene table |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric1, sceneId8, scene)); |
| EXPECT_EQ(CHIP_ERROR_NOT_FOUND, sceneTable->GetSceneTableEntry(kFabric2, sceneId8, scene)); |
| // The Remaining capacity in the original scene table therefore have been modified as well |
| // Fabric 2 should still be almost at capacity |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric1, fabric_capacity)); |
| EXPECT_EQ(5, fabric_capacity); |
| EXPECT_EQ(CHIP_NO_ERROR, sceneTable->GetRemainingCapacity(kFabric2, fabric_capacity)); |
| |
| EXPECT_EQ(1, fabric_capacity); |
| } |
| |
| } // namespace TestScenes |