• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 <mutex>
18 
19 #define private public
20 #include "exit_resident_process_manager.h"
21 #undef private
22 
23 #include "ability_manager_errors.h"
24 #include "hilog_tag_wrapper.h"
25 #include "in_process_call_wrapper.h"
26 #include "remote_client_manager.h"
27 
28 using namespace testing;
29 using namespace testing::ext;
30 
31 namespace OHOS {
32 namespace AppExecFwk {
33 class ExitResidentProcessManagerTest : public testing::Test {
34 public:
35     static void SetUpTestCase();
36     static void TearDownTestCase();
37     void SetUp() override;
38     void TearDown() override;
39 };
40 
SetUpTestCase()41 void ExitResidentProcessManagerTest::SetUpTestCase()
42 {}
43 
TearDownTestCase()44 void ExitResidentProcessManagerTest::TearDownTestCase()
45 {}
46 
SetUp()47 void ExitResidentProcessManagerTest::SetUp()
48 {}
49 
TearDown()50 void ExitResidentProcessManagerTest::TearDown()
51 {}
52 
53 /**
54  * @tc.name: IsMemorySizeSufficent_001
55  * @tc.desc: Verify that the IsMemorySizeSufficient interface calls normally
56  * @tc.type: FUNC
57  */
58 HWTEST_F(ExitResidentProcessManagerTest, IsMemorySizeSufficent_001, TestSize.Level1)
59 {
60     auto exitResidentProcessManager = std::make_shared<ExitResidentProcessManager>();
61     EXPECT_EQ(exitResidentProcessManager->IsMemorySizeSufficient(), true);
62 }
63 
64 /**
65  * @tc.name: RecordExitResidentBundleName_001
66  * @tc.desc: Verify that the RecordExitResidentBundleName interface calls normally
67  * @tc.type: FUNC
68  */
69 HWTEST_F(ExitResidentProcessManagerTest, RecordExitResidentBundleName_001, TestSize.Level1)
70 {
71     std::string bundleName = "bundleName";
72     auto exitResidentProcessManager = std::make_shared<ExitResidentProcessManager>();
73     int32_t uid = 0;
74     EXPECT_EQ(exitResidentProcessManager->RecordExitResidentBundleName(bundleName, uid), false);
75 }
76 
77 /**
78  * @tc.name: RecordExitResidentBundleDependedOnWeb_001
79  * @tc.desc: Verify that the RecordExitResidentBundleDependedOnWeb interface calls normally
80  * @tc.type: FUNC
81  */
82 HWTEST_F(ExitResidentProcessManagerTest, RecordExitResidentBundleDependedOnWeb_001, TestSize.Level1)
83 {
84     std::string bundleName = "bundleName";
85     auto exitResidentProcessManager = std::make_shared<ExitResidentProcessManager>();
86     int32_t uid = 0;
87     exitResidentProcessManager->RecordExitResidentBundleDependedOnWeb(bundleName, uid);
88     auto flag = exitResidentProcessManager->exitResidentBundlesDependedOnWeb_;
89     EXPECT_EQ(flag.empty(), false);
90 }
91 
92 /**
93  * @tc.name: HandleMemorySizeInSufficent_001
94  * @tc.desc: Verify that the HandleMemorySizeInSufficent interface calls normally
95  * @tc.type: FUNC
96  */
97 HWTEST_F(ExitResidentProcessManagerTest, HandleMemorySizeInSufficent_001, TestSize.Level1)
98 {
99     auto exitResidentProcessManager = std::make_shared<ExitResidentProcessManager>();
100     exitResidentProcessManager->HandleMemorySizeInSufficent();
101     EXPECT_EQ(exitResidentProcessManager->HandleMemorySizeInSufficent(),
102         AAFwk::ERR_NATIVE_MEMORY_SIZE_STATE_UNCHANGED);
103 }
104 
105 /**
106  * @tc.name: HandleMemorySizeInSufficent_002
107  * @tc.desc: Verify that the HandleMemorySizeInSufficent interface calls normally
108  * @tc.type: FUNC
109  */
110 HWTEST_F(ExitResidentProcessManagerTest, HandleMemorySizeInSufficent_002, TestSize.Level1)
111 {
112     auto exitResidentProcessManager = std::make_shared<ExitResidentProcessManager>();
113     EXPECT_EQ(exitResidentProcessManager->HandleMemorySizeInSufficent(), ERR_OK);
114 }
115 
116 /**
117  * @tc.name: HandleExitResidentBundleDependedOnWeb_001
118  * @tc.desc: Verify that the HandleExitResidentBundleDependedOnWeb interface calls normally
119  * @tc.type: FUNC
120  */
121 HWTEST_F(ExitResidentProcessManagerTest, HandleExitResidentBundleDependedOnWeb_001, TestSize.Level1)
122 {
123     std::vector<ExitResidentProcessInfo> bundleNames;
124     auto exitResidentProcessManager = std::make_shared<ExitResidentProcessManager>();
125     exitResidentProcessManager->HandleExitResidentBundleDependedOnWeb(bundleNames);
126     auto flag = exitResidentProcessManager->exitResidentBundlesDependedOnWeb_;
127     EXPECT_EQ(flag.empty(), true);
128 }
129 
130 /**
131  * @tc.name: QueryExitBundleInfos_001
132  * @tc.desc: Verify that the QueryExitBundleInfos interface calls normally
133  * @tc.type: FUNC
134  */
135 HWTEST_F(ExitResidentProcessManagerTest, QueryExitBundleInfos_001, TestSize.Level1)
136 {
137     std::vector<ExitResidentProcessInfo> exitBundleNames;
138     std::vector<AppExecFwk::BundleInfo> exitBundleInfos;
139     auto exitResidentProcessManager = std::make_shared<ExitResidentProcessManager>();
140     std::shared_ptr<RemoteClientManager> remoteClientManager = std::make_shared<RemoteClientManager>();
141     auto bundleMgrHelper = remoteClientManager->GetBundleManagerHelper();
142     exitResidentProcessManager->QueryExitBundleInfos(exitBundleNames, exitBundleInfos);
143     EXPECT_NE(remoteClientManager, nullptr);
144     EXPECT_NE(bundleMgrHelper, nullptr);
145 }
146 
147 /**
148  * @tc.name: IsKilledForUpgradeWeb_001
149  * @tc.desc: Verify that the IsKilledForUpgradeWeb interface calls normally
150  * @tc.type: FUNC
151  */
152 HWTEST_F(ExitResidentProcessManagerTest, IsKilledForUpgradeWeb_001, TestSize.Level1)
153 {
154     std::string bundleName = "bundleName";
155     auto exitResidentProcessManager = std::make_shared<ExitResidentProcessManager>();
156     // exitResidentProcessManager->exitResidentBundlesDependedOnWeb_;
157     EXPECT_EQ(exitResidentProcessManager->IsKilledForUpgradeWeb(bundleName), false);
158 }
159 } // namespace AppExecFwk
160 } // namespace OHOS
161