1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "ability_delegator_args.h" 17 18 namespace OHOS { 19 namespace AppExecFwk { 20 const std::string AbilityDelegatorArgs::KEY_TEST_BUNDLE_NAME {"-b"}; 21 const std::string AbilityDelegatorArgs::KEY_TEST_PACKAGE_NAME {"-p"}; 22 const std::string AbilityDelegatorArgs::KEY_TEST_MODULE_NAME {"-m"}; 23 const std::string AbilityDelegatorArgs::KEY_TEST_RUNNER_CLASS {"-s unittest"}; 24 const std::string AbilityDelegatorArgs::KEY_TEST_CASE {"-s class"}; 25 const std::string AbilityDelegatorArgs::KEY_TEST_WAIT_TIMEOUT {"-w"}; 26 27 const std::string AbilityDelegatorArgs::KEY_TEST_DEBUG {"-D"}; 28 const std::string AbilityDelegatorArgs::VALUE_TEST_DEBUG {"true"}; 29 AbilityDelegatorArgs(const AAFwk::Want & want)30AbilityDelegatorArgs::AbilityDelegatorArgs(const AAFwk::Want &want) 31 { 32 bundleName_ = want.GetStringParam(AbilityDelegatorArgs::KEY_TEST_BUNDLE_NAME); 33 34 auto wantParams(want.GetParams()); 35 if (wantParams.HasParam("debugApp")) { 36 wantParams.Remove("debugApp"); 37 } 38 39 std::set<std::string> keys = wantParams.KeySet(); 40 for (auto key : keys) { 41 params_[key] = want.GetStringParam(key); 42 } 43 } 44 GetTestBundleName() const45std::string AbilityDelegatorArgs::GetTestBundleName() const 46 { 47 return bundleName_; 48 } 49 GetTestPackageName() const50std::string AbilityDelegatorArgs::GetTestPackageName() const 51 { 52 return GetParamValue(AbilityDelegatorArgs::KEY_TEST_PACKAGE_NAME); 53 } 54 GetTestModuleName() const55std::string AbilityDelegatorArgs::GetTestModuleName() const 56 { 57 return GetParamValue(AbilityDelegatorArgs::KEY_TEST_MODULE_NAME); 58 } 59 GetTestRunnerClassName() const60std::string AbilityDelegatorArgs::GetTestRunnerClassName() const 61 { 62 return GetParamValue(AbilityDelegatorArgs::KEY_TEST_RUNNER_CLASS); 63 } 64 GetTestCaseName() const65std::string AbilityDelegatorArgs::GetTestCaseName() const 66 { 67 return GetParamValue(AbilityDelegatorArgs::KEY_TEST_CASE); 68 } 69 GetTestParam() const70std::map<std::string, std::string> AbilityDelegatorArgs::GetTestParam() const 71 { 72 return params_; 73 } 74 FindDebugFlag() const75bool AbilityDelegatorArgs::FindDebugFlag() const 76 { 77 auto pos = params_.find(KEY_TEST_DEBUG); 78 if (pos == params_.end()) { 79 return false; 80 } 81 82 return !pos->second.compare(VALUE_TEST_DEBUG); 83 } 84 GetParamValue(const std::string & key) const85std::string AbilityDelegatorArgs::GetParamValue(const std::string &key) const 86 { 87 auto target = params_.find(key); 88 return (target != params_.end()) ? target->second : std::string(); 89 } 90 } // namespace AppExecFwk 91 } // namespace OHOS 92