Skip to content

Commit 02a2554

Browse files
ksperling-appleaustina-csa
authored andcommitted
Disentangle data model tests by moving fixtures into their own file (project-chip#34154)
* Disentangle data model tests by moving fixtures into their own file The data model tests all had linker dependencies on each other, which meant that running any of Test{Read,Write,Commands} would run the tests from all of them, because the global fixture function from that test was required. This change moves all those fixture functions into DataModelFixtures.cpp. Also disambiguate the enum types and control variable names involved. * Address review comments - Add more comments to DataModelFixtures.h - Use ScopedChangeOnly for the fixture control variables - Extend ScopedChange to allow assignments within the scope
1 parent eab1dc2 commit 02a2554

File tree

9 files changed

+744
-637
lines changed

9 files changed

+744
-637
lines changed

src/app/util/mock/Constants.h

+19
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,24 @@ constexpr EventId MockEventId(const uint16_t & id)
5050
{
5151
return (0xFFF1'0000 | id);
5252
}
53+
54+
// Cluster Revision value returned by mock clusters
55+
extern const uint16_t mockClusterRevision;
56+
57+
// Feature Map value returned by mock clusters
58+
extern const uint32_t mockFeatureMap;
59+
60+
// Scalar value returned by mock clusters for MockAttributeId(1)
61+
extern const bool mockAttribute1;
62+
63+
// Scalar value returned by mock clusters for MockAttributeId(2)
64+
extern const int16_t mockAttribute2;
65+
66+
// Scalar value returned by mock clusters for MockAttributeId(3)
67+
extern const uint64_t mockAttribute3;
68+
69+
// MockAttributeId(4) returns a list of octstr with this value
70+
extern const uint8_t mockAttribute4[256];
71+
5372
} // namespace Test
5473
} // namespace chip

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

+13-7
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,17 @@ const MockNodeConfig & GetMockNodeConfig()
113113
return (mockConfig != nullptr) ? *mockConfig : DefaultMockNodeConfig();
114114
}
115115

116-
uint16_t mockClusterRevision = 1;
117-
uint32_t mockFeatureMap = 0x1234;
118-
bool mockAttribute1 = true;
119-
int16_t mockAttribute2 = 42;
120-
uint64_t mockAttribute3 = 0xdeadbeef0000cafe;
121-
uint8_t mockAttribute4[256] = {
116+
} // namespace
117+
118+
namespace chip {
119+
namespace Test {
120+
121+
const uint16_t mockClusterRevision = 1;
122+
const uint32_t mockFeatureMap = 0x1234;
123+
const bool mockAttribute1 = true;
124+
const int16_t mockAttribute2 = 42;
125+
const uint64_t mockAttribute3 = 0xdeadbeef0000cafe;
126+
const uint8_t mockAttribute4[256] = {
122127
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
123128
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
124129
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
@@ -129,7 +134,8 @@ uint8_t mockAttribute4[256] = {
129134
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
130135
};
131136

132-
} // namespace
137+
} // namespace Test
138+
} // namespace chip
133139

134140
uint16_t emberAfEndpointCount()
135141
{

src/controller/tests/data_model/BUILD.gn

+11-3
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,19 @@ import("${chip_root}/src/platform/device.gni")
2222
chip_test_suite("data_model") {
2323
output_name = "libDataModelTests"
2424

25+
sources = [
26+
"DataModelFixtures.cpp",
27+
"DataModelFixtures.h",
28+
]
29+
30+
test_sources = []
2531
if (chip_device_platform != "mbed" && chip_device_platform != "efr32" &&
2632
chip_device_platform != "esp32" && chip_device_platform != "fake") {
27-
test_sources = [ "TestCommands.cpp" ]
28-
test_sources += [ "TestWrite.cpp" ]
29-
test_sources += [ "TestRead.cpp" ]
33+
test_sources += [
34+
"TestCommands.cpp",
35+
"TestRead.cpp",
36+
"TestWrite.cpp",
37+
]
3038
}
3139

3240
public_deps = [

0 commit comments

Comments
 (0)