From 41125134c0adda5c06a625a94f30cf0c912099bf Mon Sep 17 00:00:00 2001 From: "Josh V [Apple]" Date: Tue, 15 Mar 2022 21:48:27 -0700 Subject: [PATCH] Add user input to UserPrompt function. (#16190) --- src/app/tests/suites/TestLogCommands.yaml | 22 +++++++++++++++++++ .../tests/suites/commands/log/LogCommands.cpp | 17 ++++++++++++-- .../tests/suites/commands/log/LogCommands.h | 2 +- .../clusters/LogCommands.js | 2 +- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/app/tests/suites/TestLogCommands.yaml b/src/app/tests/suites/TestLogCommands.yaml index fc9a1ebf37c1a0..8d9a1b61f5239a 100644 --- a/src/app/tests/suites/TestLogCommands.yaml +++ b/src/app/tests/suites/TestLogCommands.yaml @@ -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" diff --git a/src/app/tests/suites/commands/log/LogCommands.cpp b/src/app/tests/suites/commands/log/LogCommands.cpp index 1aa8ef3b0de5b2..b19bf857bc9d5e 100644 --- a/src/app/tests/suites/commands/log/LogCommands.cpp +++ b/src/app/tests/suites/commands/log/LogCommands.cpp @@ -17,6 +17,7 @@ */ #include "LogCommands.h" +#include CHIP_ERROR LogCommands::Log(const char * message) { @@ -24,8 +25,20 @@ CHIP_ERROR LogCommands::Log(const char * 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); } diff --git a/src/app/tests/suites/commands/log/LogCommands.h b/src/app/tests/suites/commands/log/LogCommands.h index 3e6159921525f3..7eed6a09b3dbd5 100644 --- a/src/app/tests/suites/commands/log/LogCommands.h +++ b/src/app/tests/suites/commands/log/LogCommands.h @@ -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); }; diff --git a/src/app/zap-templates/common/simulated-clusters/clusters/LogCommands.js b/src/app/zap-templates/common/simulated-clusters/clusters/LogCommands.js index aba2675c345582..107a2548fbec3f 100644 --- a/src/app/zap-templates/common/simulated-clusters/clusters/LogCommands.js +++ b/src/app/zap-templates/common/simulated-clusters/clusters/LogCommands.js @@ -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 : [] } };