• 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 <gtest/gtest.h>
17 #define private public
18 #define protected public
19 #include "ability_manager.h"
20 #include "ability_manager_stub_mock.h"
21 #undef private
22 #undef protected
23 #include "hilog_wrapper.h"
24 using namespace testing::ext;
25 using namespace testing;
26 namespace OHOS {
27 namespace AAFwk {
28 namespace {
29     constexpr int32_t NEGATIVE = -1;
30 }
31 using namespace OHOS::AppExecFwk;
32 class AbilityManagerTest : public testing::Test {
33 public:
SetUpTestCase(void)34     static void SetUpTestCase(void) {};
TearDownTestCase(void)35     static void TearDownTestCase(void) {};
SetUp()36     void SetUp() {};
TearDown()37     void TearDown() {};
38 };
39 
40 /*
41  * @tc.number    : AbilityManagerTest_0100
42  * @tc.name      : AbilityManager
43  * @tc.desc      : Test Function AbilityManager::GetInstance() and AbilityManager::StartAbility
44  */
45 HWTEST_F(AbilityManagerTest, AbilityManagerTest_0100, TestSize.Level1)
46 {
47     HILOG_INFO("AbilityManagerTest_0100 is start");
48     int32_t requestCode = NEGATIVE;
49     Want want;
50     ElementName element("device", "com.ix.hiMusic", "MusicSAbility");
51     want.SetElement(element);
52     sptr<AAFwk::AbilityManagerStubTestMock> mock = new AAFwk::AbilityManagerStubTestMock();
53     AAFwk::AbilityManagerClient::GetInstance()->proxy_ = mock;
54     ErrCode error = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, requestCode);
55     EXPECT_EQ(error, ERR_OK);
56     AbilityManager::GetInstance().StartAbility(want, requestCode);
57     AAFwk::AbilityManagerClient::GetInstance()->proxy_ = nullptr;
58     HILOG_INFO("AbilityManagerTest_0100 is end");
59 }
60 
61 /*
62  * @tc.number    : AbilityManagerTest_0200
63  * @tc.name      : AbilityManager
64  * @tc.desc      : Test Function AbilityManager::GetInstance() and AbilityManager::StartAbility
65  */
66 HWTEST_F(AbilityManagerTest, AbilityManagerTest_0200, TestSize.Level1)
67 {
68     HILOG_INFO("AbilityManagerTest_0200 is start");
69     int32_t requestCode = NEGATIVE;
70     Want want;
71     ElementName element("device", "com.ix.hiMusic", "MusicSAbility");
72     want.SetElement(element);
73     ErrCode error = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, requestCode);
74     EXPECT_NE(error, ERR_OK);
75     AbilityManager::GetInstance().StartAbility(want, requestCode);
76     HILOG_INFO("AbilityManagerTest_0200 is end");
77 }
78 
79 /*
80  * @tc.number    : AbilityManagerTest_0300
81  * @tc.name      : AbilityManager
82  * @tc.desc      : Test Function AbilityManager::ClearUpApplicationData
83  */
84 HWTEST_F(AbilityManagerTest, AbilityManagerTest_0300, TestSize.Level1)
85 {
86     HILOG_INFO("AbilityManagerTest_0300 is start");
87     const std::string bundleName = "test";
88     auto res = AbilityManager::GetInstance().ClearUpApplicationData(bundleName);
89     EXPECT_EQ(res, ERR_INVALID_OPERATION);
90     HILOG_INFO("AbilityManagerTest_0300 is end");
91 }
92 
93 /*
94  * @tc.number    : AbilityManagerTest_0500
95  * @tc.name      : AbilityManager
96  * @tc.desc      : Test Function AbilityManager::KillProcessesByBundleName
97  */
98 HWTEST_F(AbilityManagerTest, AbilityManagerTest_0500, TestSize.Level1)
99 {
100     HILOG_INFO("AbilityManagerTest_0500 is start");
101     const std::string bundleName = "test";
102     auto res = AbilityManager::GetInstance().KillProcessesByBundleName(bundleName);
103     EXPECT_NE(res, ERR_OK);
104     HILOG_INFO("AbilityManagerTest_0500 is end");
105 }
106 
107 /*
108  * @tc.number    : AbilityManagerTest_0600
109  * @tc.name      : AbilityManager
110  * @tc.desc      : Test Function AbilityManager::KillProcessesByBundleName
111  */
112 HWTEST_F(AbilityManagerTest, AbilityManagerTest_0600, TestSize.Level1)
113 {
114     HILOG_INFO("AbilityManagerTest_0600 is start");
115     const std::string bundleName = "test";
116     sptr<AAFwk::AbilityManagerStubTestMock> mock = new AAFwk::AbilityManagerStubTestMock();
117     AAFwk::AbilityManagerClient::GetInstance()->proxy_ = mock;
118     auto res = AbilityManager::GetInstance().KillProcessesByBundleName(bundleName);
119     EXPECT_EQ(res, ERR_OK);
120     AAFwk::AbilityManagerClient::GetInstance()->proxy_ = nullptr;
121     HILOG_INFO("AbilityManagerTest_0600 is end");
122 }
123 } // namespace AAFwk
124 } // namespace OHOS