From 7f01b79cf28355f145a399767dfa8a8a347bd59b Mon Sep 17 00:00:00 2001 From: njupthan Date: Fri, 4 Mar 2022 14:24:40 +0000 Subject: [PATCH] Adapt to aa test dynamic key-value parameters Signed-off-by: njupthan --- .../src/ability_delegator_args.cpp | 14 ++++---------- tools/aa/include/ability_command.h | 14 +++++++++----- tools/aa/src/ability_command.cpp | 6 +----- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_args.cpp b/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_args.cpp index 0f8c069a80..0b7fe770d7 100644 --- a/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_args.cpp +++ b/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_args.cpp @@ -28,16 +28,10 @@ AbilityDelegatorArgs::AbilityDelegatorArgs() AbilityDelegatorArgs::AbilityDelegatorArgs(const AAFwk::Want &want) { bundleName_ = want.GetStringParam(AbilityDelegatorArgs::KEY_TEST_BUNDLE_NAME); - params_[AbilityDelegatorArgs::KEY_TEST_BUNDLE_NAME] = - want.GetStringParam(AbilityDelegatorArgs::KEY_TEST_BUNDLE_NAME); - params_[AbilityDelegatorArgs::KEY_TEST_RUNNER_CLASS] = - want.GetStringParam(AbilityDelegatorArgs::KEY_TEST_RUNNER_CLASS); - if (!want.GetStringParam(AbilityDelegatorArgs::KEY_TEST_CASE).empty()) { - params_[AbilityDelegatorArgs::KEY_TEST_CASE] = want.GetStringParam(AbilityDelegatorArgs::KEY_TEST_CASE); - } - if (!want.GetStringParam(AbilityDelegatorArgs::KEY_TEST_WAIT_TIMEOUT).empty()) { - params_[AbilityDelegatorArgs::KEY_TEST_WAIT_TIMEOUT] = - want.GetStringParam(AbilityDelegatorArgs::KEY_TEST_WAIT_TIMEOUT); + auto wantParams = want.GetParams(); + std::set keys = wantParams.KeySet(); + for (auto key : keys) { + params_[key] = want.GetStringParam(key); } } diff --git a/tools/aa/include/ability_command.h b/tools/aa/include/ability_command.h index 52b6a74de3..94f64e84e4 100644 --- a/tools/aa/include/ability_command.h +++ b/tools/aa/include/ability_command.h @@ -85,14 +85,18 @@ const std::string HELP_MSG_DUMPSYS = "usage: aa dump \n" " The original -s parameter is invalid\n" " The original -m parameter is invalid\n"; - const std::string HELP_MSG_TEST = "usage: aa test \n" "options list:\n" - " -h, --help \ - list available commands\n" - " -p -s unittest [-s class ] [-w ] \ - start the test framework with options\n"; + " -h, --help list available commands\n" + " -p -s unittest start the test framework with options\n" + " [-s class ]\n" + " [-s level ]\n" + " [-s size ]\n" + " [-s testType ]\n" + " [-s timeout ]\n" + " [-s ]\n" + " [-w ]\n"; const std::string HELP_MSG_FORCE_STOP = "usage: aa force-stop \n"; const std::string HELP_MSG_FORCE_TIMEOUT = diff --git a/tools/aa/src/ability_command.cpp b/tools/aa/src/ability_command.cpp index c4f93205d8..fe4ce575e9 100644 --- a/tools/aa/src/ability_command.cpp +++ b/tools/aa/src/ability_command.cpp @@ -1239,14 +1239,10 @@ ErrCode AbilityManagerShellCommand::RunAsTestCommand() params[opt] = argv; } else if (opt == "-s") { if (i >= argc_ - USER_TEST_COMMAND_PARAMS_NUM) { - return TestCommandError( - "error: option Should be [-s unittest ] or [-s class ].\n"); + return TestCommandError("error: option [-s] is incorrect.\n"); } std::string argKey = argv_[++i]; std::string argValue = argv_[++i]; - if (!(argKey == "unittest" || argKey == "class")) { - return TestCommandError("error: option Should be [-s unittest] or [-s class].\n"); - } params[opt + " " + argKey] = argValue; } else if (opt.at(0) == '-') { return TestCommandError("error: unknown option: " + opt + "\n");