Skip to content

Commit

Permalink
Add user input to UserPrompt function. (#16190)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh V [Apple] authored and pull[bot] committed Sep 9, 2023
1 parent 1033090 commit 4112513
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
22 changes: 22 additions & 0 deletions src/app/tests/suites/TestLogCommands.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@ tests:
- name: "message"
value: "This is a simple message"

- label: "Do a simple user prompt message. Expect 'y' to pass."
cluster: "LogCommands"
command: "UserPrompt"
disabled: true
arguments:
values:
- name: "message"
value: "Please enter 'y' for success"
- name: "expectedValue"
value: "y"

- label: "Do a simple user prompt message. Use enter to coninue."
cluster: "LogCommands"
command: "UserPrompt"
disabled: true
arguments:
values:
- name: "message"
value: "Please enter enter to continue"
- name: "expectedValue"
value: ""

- label: "Do a simple user prompt message"
cluster: "LogCommands"
command: "UserPrompt"
Expand Down
17 changes: 15 additions & 2 deletions src/app/tests/suites/commands/log/LogCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,28 @@
*/

#include "LogCommands.h"
#include <iostream>

CHIP_ERROR LogCommands::Log(const char * message)
{
ChipLogDetail(chipTool, "%s", message);
return ContinueOnChipMainThread(CHIP_NO_ERROR);
}

CHIP_ERROR LogCommands::UserPrompt(const char * message)
CHIP_ERROR LogCommands::UserPrompt(const char * message, const char * expectedValue)
{
CHIP_ERROR err = CHIP_NO_ERROR;
std::string line;
ChipLogDetail(chipTool, "USER_PROMPT: %s", message);
return ContinueOnChipMainThread(CHIP_NO_ERROR);
if (expectedValue == nullptr)
{
return ContinueOnChipMainThread(err);
}

std::getline(std::cin, line);
if (line != expectedValue)
{
err = CHIP_ERROR_INVALID_ARGUMENT;
}
return ContinueOnChipMainThread(err);
}
2 changes: 1 addition & 1 deletion src/app/tests/suites/commands/log/LogCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ class LogCommands
virtual CHIP_ERROR ContinueOnChipMainThread(CHIP_ERROR err) = 0;

CHIP_ERROR Log(const char * message);
CHIP_ERROR UserPrompt(const char * message);
CHIP_ERROR UserPrompt(const char * message, const char * expectedValue = nullptr);
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const Log = {

const UserPrompt = {
name : 'UserPrompt',
arguments : [ { type : 'CHAR_STRING', name : 'message' } ],
arguments : [ { type : 'CHAR_STRING', name : 'message' }, { type : 'CHAR_STRING', name : 'expectedValue', isOptional : true } ],
response : { arguments : [] }
};

Expand Down

0 comments on commit 4112513

Please sign in to comment.