Skip to content

Commit afd568c

Browse files
Added SceneMockNodeConfig to define test Noce in TestSceneTable
1 parent de77c52 commit afd568c

File tree

5 files changed

+162
-65
lines changed

5 files changed

+162
-65
lines changed

src/app/tests/TestSceneTable.cpp

+53-10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <app/clusters/scenes-server/SceneTableImpl.h>
2020
#include <app/util/mock/Constants.h>
21+
#include <app/util/mock/MockNodeConfigImpl.h>
2122
#include <crypto/DefaultSessionKeystore.h>
2223
#include <lib/core/TLV.h>
2324
#include <lib/support/Span.h>
@@ -26,6 +27,8 @@
2627
#include <nlunit-test.h>
2728

2829
using namespace chip;
30+
using namespace chip::Test;
31+
using namespace chip::app::Clusters::Globals::Attributes;
2932

3033
using SceneTable = scenes::SceneTable<scenes::ExtensionFieldSetsImpl>;
3134
using SceneTableEntry = scenes::DefaultSceneTableImpl::SceneTableEntry;
@@ -45,6 +48,7 @@ constexpr uint8_t defaultTestFabricCapacity = (defaultTestTableSize - 1) / 2;
4548
constexpr chip::ClusterId kOnOffClusterId = 0x0006;
4649
constexpr chip::ClusterId kLevelControlClusterId = 0x0008;
4750
constexpr chip::ClusterId kColorControlClusterId = 0x0300;
51+
constexpr chip::ClusterId kScenesClusterId = 0x0062;
4852

4953
// Test Endpoint ID
5054
constexpr chip::EndpointId kTestEndpoint1 = chip::Test::kMockEndpoint1;
@@ -152,6 +156,43 @@ static uint32_t OO_buffer_serialized_length = 0;
152156
static uint32_t LC_buffer_serialized_length = 0;
153157
static uint32_t CC_buffer_serialized_length = 0;
154158

159+
// clang-format off
160+
static const MockNodeConfig SceneMockNodeConfig({
161+
MockEndpointConfig(kTestEndpoint1, {
162+
MockClusterConfig(kScenesClusterId, {}),
163+
MockClusterConfig(kOnOffClusterId, {
164+
kOnOffAttId
165+
}),
166+
MockClusterConfig(kLevelControlClusterId, {
167+
kCurrentLevelId, kCurrentFrequencyId
168+
}),
169+
}),
170+
MockEndpointConfig(kTestEndpoint2, {
171+
MockClusterConfig(kScenesClusterId, {}),
172+
MockClusterConfig(kOnOffClusterId, {
173+
kOnOffAttId
174+
}),
175+
MockClusterConfig(kColorControlClusterId, {
176+
kCurrentSaturationId, kCurrentXId,kCurrentYId, kColorTemperatureMiredsId,
177+
kEnhancedCurrentHueId,kColorLoopActiveId, kColorLoopDirectionId, kColorLoopTimeId
178+
}),
179+
}),
180+
MockEndpointConfig(kTestEndpoint3, {
181+
MockClusterConfig(kScenesClusterId, {}),
182+
MockClusterConfig(kOnOffClusterId, {
183+
kOnOffAttId
184+
}),
185+
MockClusterConfig(kLevelControlClusterId, {
186+
kCurrentLevelId, kCurrentFrequencyId
187+
}),
188+
MockClusterConfig(kColorControlClusterId, {
189+
kCurrentSaturationId, kCurrentXId,kCurrentYId, kColorTemperatureMiredsId,
190+
kEnhancedCurrentHueId,kColorLoopActiveId, kColorLoopDirectionId, kColorLoopTimeId
191+
}),
192+
}),
193+
});
194+
// clang-format on
195+
155196
/// @brief Simulates a Handler where Endpoint 1 supports onoff and level control and Endpoint 2 supports onoff and color control
156197
class TestSceneHandler : public scenes::DefaultSceneHandlerImpl
157198
{
@@ -208,15 +249,15 @@ class TestSceneHandler : public scenes::DefaultSceneHandlerImpl
208249
}
209250
}
210251

211-
if (endpoint == kTestEndpoint1)
252+
if (endpoint == kTestEndpoint2)
212253
{
213254
if (cluster == kOnOffClusterId || cluster == kColorControlClusterId)
214255
{
215256
return true;
216257
}
217258
}
218259

219-
if (endpoint == kTestEndpoint1)
260+
if (endpoint == kTestEndpoint3)
220261
{
221262
if (cluster == kOnOffClusterId || cluster == kLevelControlClusterId || cluster == kColorControlClusterId)
222263
{
@@ -258,7 +299,7 @@ class TestSceneHandler : public scenes::DefaultSceneHandlerImpl
258299
break;
259300
}
260301
}
261-
if (endpoint == kTestEndpoint1)
302+
if (endpoint == kTestEndpoint2)
262303
{
263304
switch (cluster)
264305
{
@@ -280,7 +321,7 @@ class TestSceneHandler : public scenes::DefaultSceneHandlerImpl
280321
break;
281322
}
282323
}
283-
if (endpoint == kTestEndpoint1)
324+
if (endpoint == kTestEndpoint3)
284325
{
285326
switch (cluster)
286327
{
@@ -347,7 +388,7 @@ class TestSceneHandler : public scenes::DefaultSceneHandlerImpl
347388
}
348389

349390
// Takes values from cluster in Endpoint 2
350-
if (endpoint == kTestEndpoint1)
391+
if (endpoint == kTestEndpoint2)
351392
{
352393
switch (cluster)
353394
{
@@ -369,7 +410,7 @@ class TestSceneHandler : public scenes::DefaultSceneHandlerImpl
369410
}
370411

371412
// Takes values from cluster in Endpoint 3
372-
if (endpoint == kTestEndpoint1)
413+
if (endpoint == kTestEndpoint3)
373414
{
374415
switch (cluster)
375416
{
@@ -600,8 +641,8 @@ void TestHandlerFunctions(nlTestSuite * aSuite, void * aContext)
600641
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == reader.Next());
601642
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == extensionFieldSetIn.attributeValueList.Decode(reader));
602643

603-
NL_TEST_ASSERT(aSuite, sHandler.SupportsCluster(kTestEndpoint1, extensionFieldSetIn.clusterID));
604-
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sHandler.SerializeAdd(kTestEndpoint1, extensionFieldSetIn, buff_span));
644+
NL_TEST_ASSERT(aSuite, sHandler.SupportsCluster(kTestEndpoint2, extensionFieldSetIn.clusterID));
645+
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sHandler.SerializeAdd(kTestEndpoint2, extensionFieldSetIn, buff_span));
605646

606647
// Verify the handler extracted buffer matches the initial field sets
607648
NL_TEST_ASSERT(aSuite, 0 == memcmp(CC_list.data(), buff_span.data(), buff_span.size()));
@@ -632,9 +673,9 @@ void TestHandlerFunctions(nlTestSuite * aSuite, void * aContext)
632673
memset(buffer, 0, buff_span.size());
633674

634675
// Verify Deserializing is properly filling out output extension field set for color control
635-
NL_TEST_ASSERT(aSuite, sHandler.SupportsCluster(kTestEndpoint1, kColorControlClusterId));
676+
NL_TEST_ASSERT(aSuite, sHandler.SupportsCluster(kTestEndpoint2, kColorControlClusterId));
636677
NL_TEST_ASSERT(aSuite,
637-
CHIP_NO_ERROR == sHandler.Deserialize(kTestEndpoint1, kColorControlClusterId, CC_list, extensionFieldSetOut));
678+
CHIP_NO_ERROR == sHandler.Deserialize(kTestEndpoint2, kColorControlClusterId, CC_list, extensionFieldSetOut));
638679

639680
// Verify Encoding the Extension field set returns the same data as the one serialized for color control previously
640681
writer.Init(buff_span);
@@ -1818,6 +1859,8 @@ int TestSetup(void * inContext)
18181859
{
18191860
VerifyOrReturnError(CHIP_NO_ERROR == chip::Platform::MemoryInit(), FAILURE);
18201861

1862+
SetMockNodeConfig(&TestScenes::SceneMockNodeConfig);
1863+
18211864
// Initialize Scene Table
18221865
SceneTable * sceneTable = scenes::GetSceneTableImpl();
18231866
VerifyOrReturnError(nullptr != sceneTable, FAILURE);

src/app/util/mock/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ source_set("mock_ember") {
2424
"Functions.h",
2525
"MockNodeConfig.cpp",
2626
"MockNodeConfig.h",
27+
"MockNodeConfigImpl.cpp",
28+
"MockNodeConfigImpl.h",
2729
"attribute-storage.cpp",
2830
]
2931

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include <app/util/mock/Constants.h>
20+
#include <app/util/mock/MockNodeConfigImpl.h>
21+
22+
using namespace chip::Test;
23+
using namespace chip::app::Clusters::Globals::Attributes;
24+
25+
static const MockNodeConfig * mockConfig = nullptr;
26+
27+
const MockNodeConfig & DefaultMockNodeConfig()
28+
{
29+
// clang-format off
30+
static const MockNodeConfig config({
31+
MockEndpointConfig(kMockEndpoint1, {
32+
MockClusterConfig(MockClusterId(1), {
33+
ClusterRevision::Id, FeatureMap::Id,
34+
}, {
35+
MockEventId(1), MockEventId(2),
36+
}),
37+
MockClusterConfig(MockClusterId(2), {
38+
ClusterRevision::Id, FeatureMap::Id, MockAttributeId(1),
39+
}),
40+
}),
41+
MockEndpointConfig(kMockEndpoint2, {
42+
MockClusterConfig(MockClusterId(1), {
43+
ClusterRevision::Id, FeatureMap::Id,
44+
}),
45+
MockClusterConfig(MockClusterId(2), {
46+
ClusterRevision::Id, FeatureMap::Id, MockAttributeId(1), MockAttributeId(2),
47+
}),
48+
MockClusterConfig(MockClusterId(3), {
49+
ClusterRevision::Id, FeatureMap::Id, MockAttributeId(1), MockAttributeId(2), MockAttributeId(3),
50+
}),
51+
}),
52+
MockEndpointConfig(kMockEndpoint3, {
53+
MockClusterConfig(MockClusterId(1), {
54+
ClusterRevision::Id, FeatureMap::Id, MockAttributeId(1),
55+
}),
56+
MockClusterConfig(MockClusterId(2), {
57+
ClusterRevision::Id, FeatureMap::Id, MockAttributeId(1), MockAttributeId(2), MockAttributeId(3), MockAttributeId(4),
58+
}),
59+
MockClusterConfig(MockClusterId(3), {
60+
ClusterRevision::Id, FeatureMap::Id,
61+
}),
62+
MockClusterConfig(MockClusterId(4), {
63+
ClusterRevision::Id, FeatureMap::Id,
64+
}),
65+
}),
66+
});
67+
// clang-format on
68+
return config;
69+
}
70+
71+
const MockNodeConfig & GetMockNodeConfig()
72+
{
73+
return (mockConfig != nullptr) ? *mockConfig : DefaultMockNodeConfig();
74+
}
75+
76+
void SetMockNodeConfig(const MockNodeConfig * config)
77+
{
78+
mockConfig = config;
79+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include <app/util/mock/MockNodeConfig.h>
22+
23+
const chip::Test::MockNodeConfig & GetMockNodeConfig();
24+
25+
void SetMockNodeConfig(const chip::Test::MockNodeConfig * config);

src/app/util/mock/attribute-storage.cpp

+3-55
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include <app/util/af.h>
3737
#include <app/util/att-storage.h>
3838
#include <app/util/mock/Constants.h>
39-
#include <app/util/mock/MockNodeConfig.h>
39+
#include <app/util/mock/MockNodeConfigImpl.h>
4040

4141
#include <app/AttributeAccessInterface.h>
4242
#include <app/ConcreteAttributePath.h>
@@ -61,58 +61,7 @@ using namespace Clusters::Globals::Attributes;
6161

6262
namespace {
6363

64-
DataVersion dataVersion = 0;
65-
const MockNodeConfig * mockConfig = nullptr;
66-
67-
const MockNodeConfig & DefaultMockNodeConfig()
68-
{
69-
// clang-format off
70-
static const MockNodeConfig config({
71-
MockEndpointConfig(kMockEndpoint1, {
72-
MockClusterConfig(MockClusterId(1), {
73-
ClusterRevision::Id, FeatureMap::Id,
74-
}, {
75-
MockEventId(1), MockEventId(2),
76-
}),
77-
MockClusterConfig(MockClusterId(2), {
78-
ClusterRevision::Id, FeatureMap::Id, MockAttributeId(1),
79-
}),
80-
}),
81-
MockEndpointConfig(kMockEndpoint2, {
82-
MockClusterConfig(MockClusterId(1), {
83-
ClusterRevision::Id, FeatureMap::Id,
84-
}),
85-
MockClusterConfig(MockClusterId(2), {
86-
ClusterRevision::Id, FeatureMap::Id, MockAttributeId(1), MockAttributeId(2),
87-
}),
88-
MockClusterConfig(MockClusterId(3), {
89-
ClusterRevision::Id, FeatureMap::Id, MockAttributeId(1), MockAttributeId(2), MockAttributeId(3),
90-
}),
91-
}),
92-
MockEndpointConfig(kMockEndpoint3, {
93-
MockClusterConfig(MockClusterId(1), {
94-
ClusterRevision::Id, FeatureMap::Id, MockAttributeId(1),
95-
}),
96-
MockClusterConfig(MockClusterId(2), {
97-
ClusterRevision::Id, FeatureMap::Id, MockAttributeId(1), MockAttributeId(2), MockAttributeId(3), MockAttributeId(4),
98-
}),
99-
MockClusterConfig(MockClusterId(3), {
100-
ClusterRevision::Id, FeatureMap::Id,
101-
}),
102-
MockClusterConfig(MockClusterId(4), {
103-
ClusterRevision::Id, FeatureMap::Id,
104-
}),
105-
}),
106-
});
107-
// clang-format on
108-
return config;
109-
}
110-
111-
const MockNodeConfig & GetMockNodeConfig()
112-
{
113-
return (mockConfig != nullptr) ? *mockConfig : DefaultMockNodeConfig();
114-
}
115-
64+
DataVersion dataVersion = 0;
11665
uint16_t mockClusterRevision = 1;
11766
uint32_t mockFeatureMap = 0x1234;
11867
bool mockAttribute1 = true;
@@ -239,8 +188,7 @@ bool emberAfContainsServerFromIndex(uint16_t index, ClusterId clusterId)
239188
{
240189
auto config = GetMockNodeConfig();
241190
VerifyOrReturnValue(index < config.endpoints.size(), false);
242-
return true; // TODO: TestSceneTable relies on returning true here: https://github.com/project-chip/connectedhomeip/issues/30696
243-
// return config.endpoints[index].clusterById(clusterId) != nullptr;
191+
return config.endpoints[index].clusterById(clusterId) != nullptr;
244192
}
245193

246194
const EmberAfEndpointType * emberAfFindEndpointType(EndpointId endpointId)

0 commit comments

Comments
 (0)