Skip to content

Commit

Permalink
[chip-tool-darwin] Use DelayCommands in examples/chip-tool-darwin/com…
Browse files Browse the repository at this point in the history
…mands/tests/TestCommandBridge.h (#18383)

* Use DelayCommands in examples/chip-tool-darwin/commands/tests/TestCommandBridge.h

* Update generated code
  • Loading branch information
vivien-apple authored and pull[bot] committed Aug 17, 2023
1 parent 5944f6c commit e8b4892
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 213 deletions.
31 changes: 14 additions & 17 deletions examples/chip-tool-darwin/commands/tests/TestCommandBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#pragma once

#include "../common/CHIPCommandBridge.h"
#include <app/tests/suites/commands/delay/DelayCommands.h>
#include <app/tests/suites/commands/system/SystemCommands.h>
#include <app/tests/suites/include/ConstraintsChecker.h>
#include <app/tests/suites/include/PICSChecker.h>
Expand Down Expand Up @@ -58,6 +59,7 @@ class TestCommandBridge : public CHIPCommandBridge,
public ValueChecker,
public ConstraintsChecker,
public PICSChecker,
public DelayCommands,
public SystemCommands {
public:
TestCommandBridge(const char * _Nonnull commandName)
Expand Down Expand Up @@ -104,31 +106,24 @@ class TestCommandBridge : public CHIPCommandBridge,
NextTest();
}

/////////// DelayCommands-like Interface /////////
void WaitForMs(unsigned int ms)
void UserPrompt(const char * _Nullable identity, const chip::app::Clusters::LogCommands::Commands::UserPrompt::Type & value)
{
chip::app::Clusters::DelayCommands::Commands::WaitForMs::Type value;
value.ms = ms;
WaitForMs(nil, value);
NextTest();
}

void WaitForMs(const char * _Nullable identity, const chip::app::Clusters::DelayCommands::Commands::WaitForMs::Type & value)
/////////// DelayCommands Interface /////////
void OnWaitForMs() override
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, value.ms * NSEC_PER_MSEC), mCallbackQueue, ^{
dispatch_async(mCallbackQueue, ^{
NextTest();
});
}

void UserPrompt(const char * _Nullable identity, const chip::app::Clusters::LogCommands::Commands::UserPrompt::Type & value)
{
NextTest();
}

void WaitForCommissionee(
const char * _Nullable identity, const chip::app::Clusters::DelayCommands::Commands::WaitForCommissionee::Type & value)
CHIP_ERROR WaitForCommissionee(const char * _Nullable identity,
const chip::app::Clusters::DelayCommands::Commands::WaitForCommissionee::Type & value) override
{
CHIPDeviceController * controller = GetCommissioner(identity);
VerifyOrReturn(controller != nil, SetCommandExitStatus(CHIP_ERROR_INCORRECT_STATE));
VerifyOrReturnError(controller != nil, CHIP_ERROR_INCORRECT_STATE);

SetIdentity(identity);

Expand All @@ -152,6 +147,7 @@ class TestCommandBridge : public CHIPCommandBridge,
mConnectedDevices[identity] = device;
NextTest();
}];
return CHIP_NO_ERROR;
}

/////////// CommissionerCommands-like Interface /////////
Expand Down Expand Up @@ -183,8 +179,9 @@ class TestCommandBridge : public CHIPCommandBridge,
CHIP_ERROR ContinueOnChipMainThread(CHIP_ERROR err) override
{
if (CHIP_NO_ERROR == err) {
WaitForMs(0);

dispatch_async(mCallbackQueue, ^{
NextTest();
});
} else {
Exit(chip::ErrorStr(err), err);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class {{filename}}: public TestCommandBridge
}

// Go on to the next test.
WaitForMs(0);
ContinueOnChipMainThread(CHIP_NO_ERROR);
}

chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(mTimeout.ValueOr({{chip_tests_config_get_default_value "timeout"}})); }
Expand Down Expand Up @@ -272,14 +272,6 @@ class {{filename}}: public TestCommandBridge
{{/if}}
{{#if async}}
NextTest();
{{else}}
{{#*inline "minCommandTimeout"~}}
{{#if (isTestOnlyCluster cluster)~}}
{{#if (isStrEqual command "WaitForMs")~}}
{{#chip_tests_item_parameters}}{{#if (isStrEqual name "ms")}}({{definedValue}} / 1000) + {{/if}}{{/chip_tests_item_parameters}}
{{~/if}}
{{~/if}}
{{~/inline}}
{{/if}}
return CHIP_NO_ERROR;
}
Expand Down
Loading

0 comments on commit e8b4892

Please sign in to comment.