Skip to content

Commit 5facba8

Browse files
committed
Add more tests for full coverage (not that useful, but ok)
1 parent 13f8f2a commit 5facba8

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

src/app/server-cluster/tests/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ chip_test_suite("tests") {
2727

2828
public_deps = [
2929
"${chip_root}/src/app/common:ids",
30+
"${chip_root}/src/app/data-model-provider/tests:encode-decode",
3031
"${chip_root}/src/app/server-cluster:registry",
3132
"${chip_root}/src/lib/core:string-builder-adapters",
3233
]

src/app/server-cluster/tests/TestServerClusterInterface.cpp

+37-6
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
#include "access/Privilege.h"
18-
#include "app/data-model-provider/MetadataList.h"
19-
#include "app/data-model-provider/MetadataTypes.h"
20-
#include "app/data-model/List.h"
17+
#include "app/data-model-provider/OperationTypes.h"
18+
#include "lib/core/TLVReader.h"
19+
#include <optional>
2120
#include <pw_unit_test/framework.h>
2221

22+
#include <access/Privilege.h>
2323
#include <app-common/zap-generated/ids/Attributes.h>
24+
#include <app/data-model-provider/MetadataList.h>
25+
#include <app/data-model-provider/MetadataTypes.h>
26+
#include <app/data-model-provider/tests/ReadTesting.h>
27+
#include <app/data-model-provider/tests/WriteTesting.h>
2428
#include <app/server-cluster/ServerClusterInterface.h>
2529
#include <lib/core/CHIPError.h>
2630
#include <lib/core/DataModelTypes.h>
@@ -30,8 +34,10 @@
3034

3135
using namespace chip;
3236
using namespace chip::app;
33-
using namespace chip::app::DataModel;
3437
using namespace chip::app::Clusters;
38+
using namespace chip::app::DataModel;
39+
using namespace chip::app::Testing;
40+
using namespace chip::Protocols::InteractionModel;
3541

3642
namespace {
3743

@@ -204,8 +210,33 @@ TEST(TestServerClusterInterface, CommandsDefault)
204210
ASSERT_EQ(cluster.AcceptedCommands({ 1, 1 }, acceptedCommands), CHIP_NO_ERROR);
205211
ASSERT_TRUE(acceptedCommands.TakeBuffer().empty());
206212

207-
208213
DataModel::ListBuilder<CommandId> generatedCommands;
209214
ASSERT_EQ(cluster.GeneratedCommands({ 1, 1 }, generatedCommands), CHIP_NO_ERROR);
210215
ASSERT_TRUE(generatedCommands.TakeBuffer().empty());
211216
}
217+
218+
TEST(TestServerClusterInterface, WriteAttributeDefault)
219+
{
220+
FakeServerClusterInterface cluster(1);
221+
222+
WriteOperation test(0 /* endpoint */, 1 /* cluster */, 1234 /* attribute */);
223+
test.SetSubjectDescriptor(kAdminSubjectDescriptor);
224+
225+
AttributeValueDecoder decoder = test.DecoderFor<uint32_t>(12345);
226+
227+
ASSERT_EQ(cluster.WriteAttribute(test.GetRequest(), decoder), Status::UnsupportedWrite);
228+
ASSERT_FALSE(decoder.TriedDecode());
229+
}
230+
231+
TEST(TestServerClusterInterface, InvokeDefault)
232+
{
233+
FakeServerClusterInterface cluster(1);
234+
235+
TLV::TLVReader tlvReader;
236+
InvokeRequest request;
237+
238+
request.path = { 0 /* endpoint */, 1 /* cluster */, 1234 /* command */ };
239+
240+
ASSERT_EQ(cluster.Invoke(request, tlvReader, nullptr /* command handler, assumed unused here */),
241+
Status::UnsupportedCommand);
242+
}

src/app/server-cluster/tests/TestServerClusterInterfaceRegistry.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,18 @@ TEST_F(TestServerClusterInterfaceRegistry, StressTest)
266266
}
267267
}
268268
}
269+
270+
TEST_F(TestServerClusterInterfaceRegistry, InstanceUsage)
271+
{
272+
// This tests uses the instance member, to get coverage
273+
// instance is assumed to be empty
274+
FakeServerClusterInterface cluster(1234);
275+
276+
ASSERT_EQ(ServerClusterInterfaceRegistry::Instance().Get({ kEp1, 1234 }), nullptr);
277+
ASSERT_EQ(ServerClusterInterfaceRegistry::Instance().Register(kEp1, &cluster), CHIP_NO_ERROR);
278+
ASSERT_EQ(ServerClusterInterfaceRegistry::Instance().Get({ kEp1, 1234 }), &cluster);
279+
ASSERT_EQ(ServerClusterInterfaceRegistry::Instance().Unregister({ kEp1, 1234 }), &cluster);
280+
ASSERT_EQ(ServerClusterInterfaceRegistry::Instance().Get({ kEp1, 1234 }), nullptr);
281+
ASSERT_EQ(ServerClusterInterfaceRegistry::Instance().Unregister({ kEp1, 1234 }), nullptr);
282+
ASSERT_EQ(ServerClusterInterfaceRegistry::Instance().Get({ kEp1, 1234 }), nullptr);
283+
}

0 commit comments

Comments
 (0)