• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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()30 AbilityDelegatorArgs::AbilityDelegatorArgs()
31 {}
32 
AbilityDelegatorArgs(const AAFwk::Want & want)33 AbilityDelegatorArgs::AbilityDelegatorArgs(const AAFwk::Want &want)
34 {
35     bundleName_ = want.GetStringParam(AbilityDelegatorArgs::KEY_TEST_BUNDLE_NAME);
36 
37     auto wantParams(want.GetParams());
38     if (wantParams.HasParam("debugApp")) {
39         wantParams.Remove("debugApp");
40     }
41 
42     std::set<std::string> keys = wantParams.KeySet();
43     for (auto key : keys) {
44         params_[key] = want.GetStringParam(key);
45     }
46 }
47 
~AbilityDelegatorArgs()48 AbilityDelegatorArgs::~AbilityDelegatorArgs()
49 {}
50 
GetTestBundleName() const51 std::string AbilityDelegatorArgs::GetTestBundleName() const
52 {
53     return bundleName_;
54 }
55 
GetTestPackageName() const56 std::string AbilityDelegatorArgs::GetTestPackageName() const
57 {
58     return GetParamValue(AbilityDelegatorArgs::KEY_TEST_PACKAGE_NAME);
59 }
60 
GetTestModuleName() const61 std::string AbilityDelegatorArgs::GetTestModuleName() const
62 {
63     return GetParamValue(AbilityDelegatorArgs::KEY_TEST_MODULE_NAME);
64 }
65 
GetTestRunnerClassName() const66 std::string AbilityDelegatorArgs::GetTestRunnerClassName() const
67 {
68     return GetParamValue(AbilityDelegatorArgs::KEY_TEST_RUNNER_CLASS);
69 }
70 
GetTestCaseName() const71 std::string AbilityDelegatorArgs::GetTestCaseName() const
72 {
73     return GetParamValue(AbilityDelegatorArgs::KEY_TEST_CASE);
74 }
75 
GetTestParam() const76 std::map<std::string, std::string> AbilityDelegatorArgs::GetTestParam() const
77 {
78     return params_;
79 }
80 
FindDebugFlag() const81 bool AbilityDelegatorArgs::FindDebugFlag() const
82 {
83     auto pos = params_.find(KEY_TEST_DEBUG);
84     if (pos == params_.end()) {
85         return false;
86     }
87 
88     return !pos->second.compare(VALUE_TEST_DEBUG);
89 }
90 
GetParamValue(const std::string & key) const91 std::string AbilityDelegatorArgs::GetParamValue(const std::string &key) const
92 {
93     auto target = params_.find(key);
94     return (target != params_.end()) ? target->second : std::string();
95 }
96 }  // namespace AppExecFwk
97 }  // namespace OHOS
98