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 <gtest/gtest.h>
17 #include <string>
18 #include <map>
19 
20 #define private public
21 #include "ability_delegator_args.h"
22 #undef private
23 
24 #include "hilog_tag_wrapper.h"
25 #include "want.h"
26 
27 using namespace testing::ext;
28 using namespace OHOS;
29 using namespace OHOS::AppExecFwk;
30 using namespace OHOS::AAFwk;
31 
32 namespace {
33 const std::string KEY_TEST_BUNDLE_NAME = "-b";
34 const std::string VALUE_TEST_BUNDLE_NAME = "com.example.myapplication111";
35 const std::string CHANGE_VALUE_TEST_BUNDLE_NAME = "com.example.myapplication222";
36 const std::string KEY_TEST_RUNNER_CLASS = "-s unittest";
37 const std::string VALUE_TEST_RUNNER_CLASS = "JSUserTestRunner111";
38 const std::string CHANGE_VALUE_TEST_RUNNER_CLASS = "JSUserTestRunner222";
39 const std::string KEY_TEST_CASE = "-s class";
40 const std::string VALUE_TEST_CASE = "ohos.acts.aafwk.ability.test.ConstructorTest#testDataAbilityOtherFunction0010_111";
41 const std::string CHANGE_VALUE_TEST_CASE =
42     "ohos.acts.aafwk.ability.test.ConstructorTest#testDataAbilityOtherFunction00101_222";
43 const std::string KEY_TEST_WAIT_TIMEOUT = "-w";
44 const std::string VALUE_TEST_WAIT_TIMEOUT = "35";
45 const std::string CHANGE_VALUE_TEST_WAIT_TIMEOUT = "67";
46 const std::string SET_VALUE_TEST_BUNDLE_NAME = "com.example.myapplicationset_aaa";
47 }  // namespace
48 
49 class AbilityDelegatorArgsModuleTest : public ::testing::Test {
50 public:
51     static void SetUpTestCase();
52     static void TearDownTestCase();
53     void SetUp() override;
54     void TearDown() override;
55 };
56 
SetUpTestCase()57 void AbilityDelegatorArgsModuleTest::SetUpTestCase()
58 {}
59 
TearDownTestCase()60 void AbilityDelegatorArgsModuleTest::TearDownTestCase()
61 {}
62 
SetUp()63 void AbilityDelegatorArgsModuleTest::SetUp()
64 {}
65 
TearDown()66 void AbilityDelegatorArgsModuleTest::TearDown()
67 {}
68 
69 /**
70  * @tc.number: Ability_Delegator_Args_Module_Test_0100
71  * @tc.name: GetTestBundleName and GetTestRunnerClassName and GetTestCaseName and GetTestRunnerClassName
72  * @tc.desc: Verify the GetTestBundleName and GetTestRunnerClassName and GetTestCaseName and GetTestRunnerClassName.
73  */
74 HWTEST_F(AbilityDelegatorArgsModuleTest, Ability_Delegator_Args_Module_Test_0100, Function | MediumTest | Level1)
75 {
76     TAG_LOGI(AAFwkTag::TEST, "Ability_Delegator_Args_Module_Test_0100 is called");
77     std::map<std::string, std::string> paras;
78     paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME);
79     paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS);
80     paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE);
81     paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT);
82 
83     Want want;
84     for (auto para : paras) {
85         want.SetParam(para.first, para.second);
86     }
87 
88     AbilityDelegatorArgs delegatorArgs(want);
89     std::map<std::string, std::string>::iterator iter = delegatorArgs.params_.find(KEY_TEST_WAIT_TIMEOUT);
90     std::string valueTimeout = iter->second;
91 
92     EXPECT_EQ(delegatorArgs.GetTestBundleName(), VALUE_TEST_BUNDLE_NAME);
93     EXPECT_EQ(delegatorArgs.GetTestRunnerClassName(), VALUE_TEST_RUNNER_CLASS);
94     EXPECT_EQ(delegatorArgs.GetTestCaseName(), VALUE_TEST_CASE);
95     EXPECT_EQ(valueTimeout, VALUE_TEST_WAIT_TIMEOUT);
96 }
97