Skip to content

Commit

Permalink
Addressed comments on using ID, added RAII for MockConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
lpbeliveau-silabs committed Apr 22, 2024
1 parent f824c6c commit 1140506
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 23 deletions.
9 changes: 4 additions & 5 deletions src/app/clusters/scenes-server/SceneHandlerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,15 @@ void CapAttributeID(AttributeValuePairType & aVPair, const EmberAfAttributeMetad
// https://github.com/project-chip/connectedhomeip/issues/24177
CHIP_ERROR ValidateAttributePath(EndpointId endpoint, ClusterId cluster, AttributeValuePairType & aVPair)
{
bool attIndex = emberAfContainsAttribute(endpoint, cluster, aVPair.attributeID);
if (!attIndex)
const EmberAfAttributeMetadata * metadata = emberAfLocateAttributeMetadata(endpoint, cluster, aVPair.attributeID);

if (nullptr == metadata)
{
return CHIP_ERROR_UNSUPPORTED_ATTRIBUTE;
}

EmberAfAttributeMetadata metadata = *emberAfLocateAttributeMetadata(endpoint, cluster, aVPair.attributeID);

// Cap value based on the attribute type size
CapAttributeID(aVPair, &metadata);
CapAttributeID(aVPair, metadata);

return CHIP_NO_ERROR;
}
Expand Down
22 changes: 11 additions & 11 deletions src/app/tests/TestSceneTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ constexpr chip::EndpointId kTestEndpoint2 = chip::Test::kMockEndpoint2;
constexpr chip::EndpointId kTestEndpoint3 = chip::Test::kMockEndpoint3;

// Test Attribute ID
constexpr uint32_t kOnOffAttId = 0x0000;
constexpr uint32_t kCurrentLevelId = 0x0000;
constexpr uint32_t kCurrentFrequencyId = 0x0004;
constexpr uint32_t kCurrentSaturationId = 0x0001;
constexpr uint32_t kCurrentXId = 0x0003;
constexpr uint32_t kCurrentYId = 0x0004;
constexpr uint32_t kColorTemperatureMiredsId = 0x0007;
constexpr uint32_t kEnhancedCurrentHueId = 0x4000;
constexpr uint32_t kColorLoopActiveId = 0x4002;
constexpr uint32_t kColorLoopDirectionId = 0x4003;
constexpr uint32_t kColorLoopTimeId = 0x4004;
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 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;
Expand Down
3 changes: 0 additions & 3 deletions src/app/util/mock/Functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,5 @@ void ResetVersion();
/// be returned by emberAfDataVersionStorage
DataVersion GetVersion();

/// Resets the mock attribute storage to the default configuration.
void ResetMockNodeConfig();

} // namespace Test
} // namespace chip
21 changes: 17 additions & 4 deletions src/app/util/mock/MockNodeConfigImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
using namespace chip::Test;
using namespace chip::app::Clusters::Globals::Attributes;

static const MockNodeConfig * mockConfig = nullptr;

const MockNodeConfig & DefaultMockNodeConfig()
{
// clang-format off
Expand Down Expand Up @@ -68,12 +66,27 @@ const MockNodeConfig & DefaultMockNodeConfig()
return config;
}

// Getter function to access the config
const MockNodeConfig & MockNodeConfigRAII::GetConfig() const
{
return (configHandle != nullptr) ? *configHandle : DefaultMockNodeConfig();
}

// Setter function to set the config
void MockNodeConfigRAII::SetConfig(const MockNodeConfig * newConfig)
{
configHandle = newConfig;
}

// Instance of RAII wrapper
static MockNodeConfigRAII mockNodeConfigRAII;

const MockNodeConfig & GetMockNodeConfig()
{
return (mockConfig != nullptr) ? *mockConfig : DefaultMockNodeConfig();
return mockNodeConfigRAII.GetConfig();
}

void SetMockNodeConfig(const MockNodeConfig * config)
{
mockConfig = config;
mockNodeConfigRAII.SetConfig(config);
}
16 changes: 16 additions & 0 deletions src/app/util/mock/MockNodeConfigImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@

#include <app/util/mock/MockNodeConfig.h>

// RAII wrapper class for MockNodeConfig
class MockNodeConfigRAII
{
using MockNodeConfig = chip::Test::MockNodeConfig;

public:
explicit MockNodeConfigRAII(const MockNodeConfig * config = nullptr) : configHandle(config) {}
~MockNodeConfigRAII() { configHandle = nullptr; };

const MockNodeConfig & GetConfig() const;
void SetConfig(const MockNodeConfig * newConfig);

private:
const chip::Test::MockNodeConfig * configHandle;
};

const chip::Test::MockNodeConfig & GetMockNodeConfig();

void SetMockNodeConfig(const chip::Test::MockNodeConfig * config);

0 comments on commit 1140506

Please sign in to comment.