63
63
#include < lib/support/Span.h>
64
64
#include < protocols/interaction_model/StatusCode.h>
65
65
66
+ #include < optional>
66
67
#include < vector>
67
68
68
69
using namespace chip ;
@@ -86,6 +87,15 @@ constexpr EndpointId kEndpointIdThatIsMissing = kMockEndpointMin - 1;
86
87
87
88
constexpr AttributeId kReadOnlyAttributeId = 0x5001 ;
88
89
90
+ constexpr DeviceTypeId kDeviceTypeId1 = 123 ;
91
+ constexpr uint8_t kDeviceTypeId1Version = 10 ;
92
+
93
+ constexpr DeviceTypeId kDeviceTypeId2 = 1122 ;
94
+ constexpr uint8_t kDeviceTypeId2Version = 11 ;
95
+
96
+ constexpr DeviceTypeId kDeviceTypeId3 = 3 ;
97
+ constexpr uint8_t kDeviceTypeId3Version = 33 ;
98
+
89
99
static_assert (kEndpointIdThatIsMissing != kInvalidEndpointId );
90
100
static_assert (kEndpointIdThatIsMissing != kMockEndpoint1 );
91
101
static_assert (kEndpointIdThatIsMissing != kMockEndpoint2 );
@@ -270,6 +280,10 @@ const MockNodeConfig gTestNodeConfig({
270
280
MockClusterConfig (MockClusterId (2 ), {
271
281
ClusterRevision::Id, FeatureMap::Id, MockAttributeId (1 ),
272
282
}),
283
+ }, {
284
+ { kDeviceTypeId1 , kDeviceTypeId1Version },
285
+ { kDeviceTypeId2 , kDeviceTypeId2Version },
286
+ { kDeviceTypeId3 , kDeviceTypeId3Version },
273
287
}),
274
288
MockEndpointConfig (kMockEndpoint2 , {
275
289
MockClusterConfig (MockClusterId (1 ), {
@@ -296,6 +310,8 @@ const MockNodeConfig gTestNodeConfig({
296
310
{11 }, /* acceptedCommands */
297
311
{4 , 6 } /* generatedCommands */
298
312
),
313
+ }, {
314
+ { kDeviceTypeId2 , kDeviceTypeId2Version },
299
315
}),
300
316
MockEndpointConfig (kMockEndpoint3 , {
301
317
MockClusterConfig (MockClusterId (1 ), {
@@ -2580,3 +2596,48 @@ TEST(TestCodegenModelViaMocks, EmberWriteInvalidDataType)
2580
2596
ASSERT_EQ (model.WriteAttribute (test.GetRequest (), decoder), Status::Failure);
2581
2597
ASSERT_TRUE (model.ChangeListener ().DirtyList ().empty ());
2582
2598
}
2599
+
2600
+ TEST (TestCodegenModelViaMocks, DeviceTypeIteration)
2601
+ {
2602
+ UseMockNodeConfig config (gTestNodeConfig );
2603
+ CodegenDataModelProviderWithContext model;
2604
+
2605
+ // Mock endpoint 1 has 3 device types
2606
+ std::optional<DeviceTypeEntry> entry = model.FirstDeviceType (kMockEndpoint1 );
2607
+ ASSERT_EQ (entry,
2608
+ std::make_optional (DeviceTypeEntry{ .deviceTypeId = kDeviceTypeId1 , .deviceTypeVersion = kDeviceTypeId1Version }));
2609
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access): Assert above that this is not none
2610
+ entry = model.NextDeviceType (kMockEndpoint1 , *entry);
2611
+ ASSERT_EQ (entry,
2612
+ std::make_optional (DeviceTypeEntry{ .deviceTypeId = kDeviceTypeId2 , .deviceTypeVersion = kDeviceTypeId2Version }));
2613
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access): Assert above that this is not none
2614
+ entry = model.NextDeviceType (kMockEndpoint1 , *entry);
2615
+ ASSERT_EQ (entry,
2616
+ std::make_optional (DeviceTypeEntry{ .deviceTypeId = kDeviceTypeId3 , .deviceTypeVersion = kDeviceTypeId3Version }));
2617
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access): Assert above that this is not none
2618
+ entry = model.NextDeviceType (kMockEndpoint1 , *entry);
2619
+ ASSERT_FALSE (entry.has_value ());
2620
+
2621
+ // Mock endpoint 2 has 1 device types
2622
+ entry = model.FirstDeviceType (kMockEndpoint2 );
2623
+ ASSERT_EQ (entry,
2624
+ std::make_optional (DeviceTypeEntry{ .deviceTypeId = kDeviceTypeId2 , .deviceTypeVersion = kDeviceTypeId2Version }));
2625
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access): Assert above that this is not none
2626
+ entry = model.NextDeviceType (kMockEndpoint2 , *entry);
2627
+ ASSERT_FALSE (entry.has_value ());
2628
+
2629
+ // out of order query works
2630
+ entry = std::make_optional (DeviceTypeEntry{ .deviceTypeId = kDeviceTypeId2 , .deviceTypeVersion = kDeviceTypeId2Version });
2631
+ entry = model.NextDeviceType (kMockEndpoint1 , *entry);
2632
+ ASSERT_EQ (entry,
2633
+ std::make_optional (DeviceTypeEntry{ .deviceTypeId = kDeviceTypeId3 , .deviceTypeVersion = kDeviceTypeId3Version }));
2634
+
2635
+ // invalid query fails
2636
+ entry = std::make_optional (DeviceTypeEntry{ .deviceTypeId = kDeviceTypeId1 , .deviceTypeVersion = kDeviceTypeId1Version });
2637
+ entry = model.NextDeviceType (kMockEndpoint2 , *entry);
2638
+ ASSERT_FALSE (entry.has_value ());
2639
+
2640
+ // empty endpoint works
2641
+ entry = model.FirstDeviceType (kMockEndpoint3 );
2642
+ ASSERT_FALSE (entry.has_value ());
2643
+ }
0 commit comments