@@ -754,6 +754,12 @@ class FakeDefaultServerCluster : public DefaultServerCluster
754
754
static constexpr uint32_t kFakeFeatureMap = 0x35 ;
755
755
static constexpr uint32_t kFakeClusterRevision = 1234 ;
756
756
757
+ static constexpr CommandId kGeneratedCommands [] = { 1 , 2 , 3 , 100 , 200 };
758
+ static constexpr AcceptedCommandEntry kAcceptedCommands [] = {
759
+ { 101 },
760
+ { 102 },
761
+ };
762
+
757
763
FakeDefaultServerCluster (ConcreteClusterPath path) : mPath (path) {}
758
764
759
765
[[nodiscard]] ConcreteClusterPath GetPath () const override { return mPath ; }
@@ -763,6 +769,30 @@ class FakeDefaultServerCluster : public DefaultServerCluster
763
769
return DataModel::ClusterQualityFlags::kDiagnosticsData ;
764
770
}
765
771
772
+ CHIP_ERROR AcceptedCommands (const ConcreteClusterPath & path,
773
+ DataModel::ListBuilder<DataModel::AcceptedCommandEntry> & builder) override
774
+ {
775
+ return builder.ReferenceExisting (Span<const AcceptedCommandEntry>(kAcceptedCommands ));
776
+ }
777
+
778
+ CHIP_ERROR GeneratedCommands (const ConcreteClusterPath & path, DataModel::ListBuilder<CommandId> & builder) override
779
+ {
780
+ return builder.ReferenceExisting (Span<const CommandId>(kGeneratedCommands ));
781
+ }
782
+
783
+ std::optional<DataModel::ActionReturnStatus> InvokeCommand (const DataModel::InvokeRequest & request,
784
+ chip::TLV::TLVReader & input_arguments,
785
+ CommandHandler * handler) override
786
+ {
787
+ return CHIP_ERROR_INCORRECT_STATE;
788
+ }
789
+
790
+ DataModel::ActionReturnStatus WriteAttribute (const DataModel::WriteAttributeRequest & request,
791
+ AttributeValueDecoder & decoder) override
792
+ {
793
+ return CHIP_ERROR_INCORRECT_STATE;
794
+ }
795
+
766
796
DataModel::ActionReturnStatus ReadAttribute (const DataModel::ReadAttributeRequest & request,
767
797
AttributeValueEncoder & encoder) override
768
798
{
@@ -2567,7 +2597,7 @@ static CHIP_ERROR ReadU32Attribute(DataModel::Provider & provider, const Concret
2567
2597
return chip::app::DataModel::Decode<uint32_t >(encodedData.dataReader , value);
2568
2598
}
2569
2599
2570
- TEST_F (TestCodegenModelViaMocks, ServerClusterInterfacesReadAttribute )
2600
+ TEST_F (TestCodegenModelViaMocks, ServerClusterInterfacesRegistration )
2571
2601
{
2572
2602
UseMockNodeConfig config (gTestNodeConfig );
2573
2603
CodegenDataModelProviderWithContext model;
@@ -2595,6 +2625,51 @@ TEST_F(TestCodegenModelViaMocks, ServerClusterInterfacesReadAttribute)
2595
2625
revision),
2596
2626
CHIP_NO_ERROR);
2597
2627
EXPECT_EQ (revision, FakeDefaultServerCluster::kFakeClusterRevision );
2628
+
2629
+ // now that registration looks ok and DIFFERENT from ember, invoke various methods on the registered cluster
2630
+ // to ensure behavior is redirected correctly
2631
+ {
2632
+ DataModel::ListBuilder<AttributeEntry> builder;
2633
+ ASSERT_EQ (model.Attributes (kTestClusterPath , builder), CHIP_NO_ERROR);
2634
+
2635
+ // Attributes will be just global attributes
2636
+ ASSERT_TRUE (DefaultServerCluster::GlobalAttributes ().data_equal (builder.TakeBuffer ()));
2637
+ }
2638
+
2639
+ {
2640
+ DataModel::ListBuilder<AcceptedCommandEntry> builder;
2641
+ ASSERT_EQ (model.AcceptedCommands (kTestClusterPath , builder), CHIP_NO_ERROR);
2642
+ ASSERT_TRUE (Span<const AcceptedCommandEntry>(FakeDefaultServerCluster::kAcceptedCommands ).data_equal (builder.TakeBuffer ()));
2643
+ }
2644
+
2645
+ {
2646
+ DataModel::ListBuilder<CommandId> builder;
2647
+ ASSERT_EQ (model.GeneratedCommands (kTestClusterPath , builder), CHIP_NO_ERROR);
2648
+ ASSERT_TRUE (Span<const CommandId>(FakeDefaultServerCluster::kGeneratedCommands ).data_equal (builder.TakeBuffer ()));
2649
+ }
2650
+
2651
+ // Invoke specifically on the fake server returns a unique (and non-spec really) error
2652
+ // so we can see the right method is called.
2653
+ {
2654
+ const ConcreteCommandPath kCommandPath (kTestClusterPath .mEndpointId , kTestClusterPath .mClusterId , kMockCommandId1 );
2655
+ const InvokeRequest kInvokeRequest { .path = kCommandPath };
2656
+ chip::TLV::TLVReader tlvReader;
2657
+
2658
+ // Using a handler set to nullptr as it is not used by the impl
2659
+ std::optional<ActionReturnStatus> result = model.InvokeCommand (kInvokeRequest , tlvReader, /* handler = */ nullptr );
2660
+ ASSERT_TRUE (result.has_value () && result->GetUnderlyingError () == CHIP_ERROR_INCORRECT_STATE);
2661
+ }
2662
+
2663
+ // Write attribute also has a specific error to know the right code is called
2664
+ {
2665
+ WriteOperation test (kTestClusterPath .mEndpointId , kTestClusterPath .mClusterId , kAttributeIdReadOnly );
2666
+ test.SetSubjectDescriptor (kAdminSubjectDescriptor );
2667
+
2668
+ AttributeValueDecoder decoder = test.DecoderFor <uint32_t >(1234 );
2669
+
2670
+ std::optional<ActionReturnStatus> result = model.WriteAttribute (test.GetRequest (), decoder);
2671
+ ASSERT_TRUE (result.has_value () && result->GetUnderlyingError () == CHIP_ERROR_INCORRECT_STATE);
2672
+ }
2598
2673
}
2599
2674
2600
2675
TEST_F (TestCodegenModelViaMocks, ServerClusterInterfacesListClusters)
0 commit comments