From 3c488e5145db0f3823fc32ce4e6af363039d8cd5 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Wed, 2 Mar 2022 10:41:36 +0100 Subject: [PATCH] [placeholder] Allow placeholder examples to emit dnssd requests --- examples/placeholder/linux/include/TestCommand.h | 6 ++++-- examples/placeholder/templates/templates.json | 13 +++++++++++++ .../suites/commands/discovery/DiscoveryCommands.cpp | 2 ++ .../suites/commands/discovery/DiscoveryCommands.h | 6 +++++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/examples/placeholder/linux/include/TestCommand.h b/examples/placeholder/linux/include/TestCommand.h index ee4fb8ee21df5f..d6e5a919c70b83 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,7 @@ 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 +77,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 5afa23e2d9c87c..c12445e24e1b9a 100644 --- a/src/app/tests/suites/commands/discovery/DiscoveryCommands.cpp +++ b/src/app/tests/suites/commands/discovery/DiscoveryCommands.cpp @@ -104,12 +104,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 d5cfebd9cd4821..774c38934a5b10 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{}; + protected: // This function initialize a random discriminator once and returns it all the time afterwards uint16_t GetUniqueDiscriminator();