From 7b1bd449fecb81f4194b2c404160c83af8f43bf6 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Thu, 3 Mar 2022 17:34:20 +0100 Subject: [PATCH] [placeholder] Allow placeholder examples to emit dnssd requests (#15785) --- examples/placeholder/linux/include/TestCommand.h | 11 +++++++++-- examples/placeholder/templates/templates.json | 13 +++++++++++++ .../suites/commands/discovery/DiscoveryCommands.cpp | 2 ++ .../suites/commands/discovery/DiscoveryCommands.h | 6 +++++- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/examples/placeholder/linux/include/TestCommand.h b/examples/placeholder/linux/include/TestCommand.h index ee4fb8ee21df5f..ad11ab80015936 100644 --- a/examples/placeholder/linux/include/TestCommand.h +++ b/examples/placeholder/linux/include/TestCommand.h @@ -26,7 +26,9 @@ #include #include #include +#include #include +#include #include #include @@ -36,7 +38,12 @@ constexpr const char kIdentityAlpha[] = ""; constexpr const char kIdentityBeta[] = ""; constexpr const char kIdentityGamma[] = ""; -class TestCommand : public PICSChecker, public LogCommands, public DiscoveryCommands, public DelayCommands +class TestCommand : public PICSChecker, + public LogCommands, + public DiscoveryCommands, + public DelayCommands, + public ValueChecker, + public ConstraintsChecker { public: TestCommand(const char * commandName) : mCommandPath(0, 0, 0), mAttributePath(0, 0, 0) {} @@ -75,7 +82,7 @@ class TestCommand : public PICSChecker, public LogCommands, public DiscoveryComm return CHIP_NO_ERROR; } - void Exit(std::string message) + void Exit(std::string message) override { ChipLogError(chipTool, " ***** Test Failure: %s\n", message.c_str()); SetCommandExitStatus(CHIP_ERROR_INTERNAL); diff --git a/examples/placeholder/templates/templates.json b/examples/placeholder/templates/templates.json index 3944367e9e4d10..9df7b8de4e2b60 100644 --- a/examples/placeholder/templates/templates.json +++ b/examples/placeholder/templates/templates.json @@ -8,6 +8,7 @@ "../../../src/app/zap-templates/templates/chip/helper.js", "../../../src/app/zap-templates/common/ClusterTestGeneration.js", "../../../examples/chip-tool/templates/helper.js", + "../../../examples/chip-tool/templates/tests/helper.js", "helper.js" ], "override": "../../../src/app/zap-templates/common/override.js", @@ -20,6 +21,18 @@ "name": "test_cluster", "path": "../../../examples/chip-tool/templates/tests/partials/test_cluster.zapt" }, + { + "name": "maybeCheckExpectedValue", + "path": "../../../examples/chip-tool/templates/tests/partials/checks/maybeCheckExpectedValue.zapt" + }, + { + "name": "maybeCheckExpectedConstraints", + "path": "../../../examples/chip-tool/templates/tests/partials/checks/maybeCheckExpectedConstraints.zapt" + }, + { + "name": "maybeSaveAs", + "path": "../../../examples/chip-tool/templates/tests/partials/saveAs/maybeSaveAs.zapt" + }, { "name": "setupSaveAs", "path": "../../../examples/chip-tool/templates/tests/partials/saveAs/setupSaveAs.zapt" diff --git a/src/app/tests/suites/commands/discovery/DiscoveryCommands.cpp b/src/app/tests/suites/commands/discovery/DiscoveryCommands.cpp index 5aefcb8112a9b9..1af491838f20e0 100644 --- a/src/app/tests/suites/commands/discovery/DiscoveryCommands.cpp +++ b/src/app/tests/suites/commands/discovery/DiscoveryCommands.cpp @@ -103,12 +103,14 @@ CHIP_ERROR DiscoveryCommands::SetupDiscoveryCommands() ReturnErrorOnFailure(mDNSResolver.Init(chip::DeviceLayer::UDPEndPointManager())); mReady = true; } + mDNSResolver.SetOperationalDelegate(this); mDNSResolver.SetCommissioningDelegate(this); return CHIP_NO_ERROR; } CHIP_ERROR DiscoveryCommands::TearDownDiscoveryCommands() { + mDNSResolver.SetOperationalDelegate(nullptr); mDNSResolver.SetCommissioningDelegate(nullptr); return CHIP_NO_ERROR; } diff --git a/src/app/tests/suites/commands/discovery/DiscoveryCommands.h b/src/app/tests/suites/commands/discovery/DiscoveryCommands.h index 848bcaef2c8806..729136e2093bff 100644 --- a/src/app/tests/suites/commands/discovery/DiscoveryCommands.h +++ b/src/app/tests/suites/commands/discovery/DiscoveryCommands.h @@ -43,7 +43,7 @@ struct DiscoveryCommandResult chip::Optional mrpRetryIntervalActive; }; -class DiscoveryCommands : public chip::Dnssd::CommissioningResolveDelegate +class DiscoveryCommands : public chip::Dnssd::CommissioningResolveDelegate, public chip::Dnssd::OperationalResolveDelegate { public: DiscoveryCommands(){}; @@ -69,6 +69,10 @@ class DiscoveryCommands : public chip::Dnssd::CommissioningResolveDelegate /////////// CommissioningDelegate Interface ///////// void OnNodeDiscovered(const chip::Dnssd::DiscoveredNodeData & nodeData) override; + /////////// OperationalDelegate Interface ///////// + void OnOperationalNodeResolved(const chip::Dnssd::ResolvedNodeData & nodeData) override{}; + void OnOperationalNodeResolutionFailed(const chip::PeerId & peerId, CHIP_ERROR error) override{}; + private: bool mReady = false; chip::Dnssd::ResolverProxy mDNSResolver;