diff --git a/src/app/util/mock/Functions.h b/src/app/util/mock/Functions.h index 32ba08d316f484..16fe45d9045b9e 100644 --- a/src/app/util/mock/Functions.h +++ b/src/app/util/mock/Functions.h @@ -36,7 +36,15 @@ namespace Test { CHIP_ERROR ReadSingleMockClusterData(FabricIndex aAccessingFabricIndex, const app::ConcreteAttributePath & aPath, app::AttributeReportIBs::Builder & aAttributeReports, app::AttributeValueEncoder::AttributeEncodeState * apEncoderState); + +/// Increase the current value for `GetVersion` void BumpVersion(); + +/// Sets GetVersion to return 0 +void ResetVersion(); + +/// Gets the current value for the version that will +/// be returned by emberAfDataVersionStorage DataVersion GetVersion(); /// Configures the singular global mock attribute storage to use the specified configuration. diff --git a/src/app/util/mock/MockNodeConfig.cpp b/src/app/util/mock/MockNodeConfig.cpp index e7c04fa546e5c9..79c886f532a8a2 100644 --- a/src/app/util/mock/MockNodeConfig.cpp +++ b/src/app/util/mock/MockNodeConfig.cpp @@ -70,6 +70,22 @@ MockClusterConfig::MockClusterConfig(ClusterId aId, std::initializer_list(mEmberEventList.size()); mEmberCluster.eventList = mEmberEventList.data(); + + for (auto & attr : attributes) + { + mAttributeMetaData.push_back(attr.attributeMetaData); + } + + // Make sure ember side has access to attribute metadata + mEmberCluster.attributes = mAttributeMetaData.data(); +} + +MockClusterConfig::MockClusterConfig(const MockClusterConfig & other) : + id(other.id), attributes(other.attributes), events(other.events), mEmberCluster(other.mEmberCluster), + mEmberEventList(other.mEmberEventList), mAttributeMetaData(other.mAttributeMetaData) +{ + // Fix self-referencial dependencies after data copy + mEmberCluster.attributes = mAttributeMetaData.data(); } const MockAttributeConfig * MockClusterConfig::attributeById(AttributeId attributeId, ptrdiff_t * outIndex) const diff --git a/src/app/util/mock/MockNodeConfig.h b/src/app/util/mock/MockNodeConfig.h index fc8f185fd80a56..aa711589eff432 100644 --- a/src/app/util/mock/MockNodeConfig.h +++ b/src/app/util/mock/MockNodeConfig.h @@ -18,6 +18,7 @@ #pragma once +#include #include #include @@ -28,10 +29,35 @@ namespace chip { namespace Test { +namespace internal { + +constexpr EmberAfAttributeMetadata DefaultAttributeMetadata(chip::AttributeId id) +{ + return EmberAfAttributeMetadata{ + .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(static_cast(0)), + .attributeId = id, + .size = 4, + .attributeType = ZCL_INT32U_ATTRIBUTE_TYPE, + .mask = ATTRIBUTE_MASK_WRITABLE | ATTRIBUTE_MASK_NULLABLE, + }; +} + +} // namespace internal + struct MockAttributeConfig { - MockAttributeConfig(AttributeId aId) : id(aId) {} + MockAttributeConfig(AttributeId aId) : id(aId), attributeMetaData(internal::DefaultAttributeMetadata(aId)) {} + MockAttributeConfig(AttributeId aId, EmberAfAttributeType type, + EmberAfAttributeMask mask = ATTRIBUTE_MASK_WRITABLE | ATTRIBUTE_MASK_NULLABLE) : + id(aId), + attributeMetaData(internal::DefaultAttributeMetadata(aId)) + { + attributeMetaData.attributeType = type; + attributeMetaData.mask = mask; + } + const AttributeId id; + EmberAfAttributeMetadata attributeMetaData; }; struct MockEventConfig @@ -45,6 +71,10 @@ struct MockClusterConfig MockClusterConfig(ClusterId aId, std::initializer_list aAttributes = {}, std::initializer_list aEvents = {}); + // Cluster-config is self-referential: mEmberCluster.attributes references mAttributeMetaData.data() + MockClusterConfig(const MockClusterConfig & other); + MockClusterConfig & operator=(const MockClusterConfig &) = delete; + const MockAttributeConfig * attributeById(AttributeId attributeId, ptrdiff_t * outIndex = nullptr) const; const EmberAfCluster * emberCluster() const { return &mEmberCluster; } @@ -55,13 +85,14 @@ struct MockClusterConfig private: EmberAfCluster mEmberCluster; std::vector mEmberEventList; + std::vector mAttributeMetaData; }; struct MockEndpointConfig { MockEndpointConfig(EndpointId aId, std::initializer_list aClusters = {}); - // Cluster-config is self-referntial: mEmberCluster.clusters references mEmberClusters + // Endpoint-config is self-referential: mEmberEndpoint.clusters references mEmberClusters.data() MockEndpointConfig(const MockEndpointConfig & other); MockEndpointConfig & operator=(const MockEndpointConfig &) = delete; diff --git a/src/app/util/mock/attribute-storage.cpp b/src/app/util/mock/attribute-storage.cpp index 6aa872956dbe7a..716460026591ee 100644 --- a/src/app/util/mock/attribute-storage.cpp +++ b/src/app/util/mock/attribute-storage.cpp @@ -307,8 +307,14 @@ void EnabledEndpointsWithServerCluster::EnsureMatchingEndpoint() } } // namespace app + namespace Test { +void ResetVersion() +{ + dataVersion = 0; +} + void BumpVersion() { dataVersion++; @@ -407,5 +413,15 @@ CHIP_ERROR ReadSingleMockClusterData(FabricIndex aAccessingFabricIndex, const Co return attributeReport.EndOfAttributeReportIB(); } +void SetMockNodeConfig(const MockNodeConfig & config) +{ + mockConfig = &config; +} + +void ResetMockNodeConfig() +{ + mockConfig = nullptr; +} + } // namespace Test } // namespace chip