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 <gmock/gmock.h>
17 #include <gtest/gtest.h>
18
19 #include "system_load.h"
20 #include "dfs_error.h"
21 #include "parameters.h"
22 #include "utils_log.h"
23 #include "res_sched_client.h"
24 #include "task_state_manager.h"
25
26 namespace OHOS::FileManagement::CloudSync::Test {
27 using namespace testing;
28 using namespace testing::ext;
29 using namespace std;
30
31 class SytemLoadTest : public testing::Test {
32 public:
33 static void SetUpTestCase(void);
34 static void TearDownTestCase(void);
35 void SetUp();
36 void TearDown();
37 shared_ptr<SystemLoadStatus> SystemLoadStatus_ = nullptr;
38 shared_ptr<SystemLoadListener> SystemLoadListener_ = nullptr;
39 };
40
SetUpTestCase(void)41 void SytemLoadTest::SetUpTestCase(void)
42 {
43 GTEST_LOG_(INFO) << "SetUpTestCase";
44 }
45
TearDownTestCase(void)46 void SytemLoadTest::TearDownTestCase(void)
47 {
48 GTEST_LOG_(INFO) << "TearDownTestCase";
49 }
50
SetUp(void)51 void SytemLoadTest::SetUp(void)
52 {
53 GTEST_LOG_(INFO) << "SetUp";
54 SystemLoadStatus_ = make_shared<SystemLoadStatus>();
55 SystemLoadListener_ = make_shared<SystemLoadListener>();
56 }
57
TearDown(void)58 void SytemLoadTest::TearDown(void)
59 {
60 GTEST_LOG_(INFO) << "TearDown";
61 TaskStateManager::GetInstance().CancelUnloadTask();
62 SystemLoadStatus_ = nullptr;
63 SystemLoadListener_ = nullptr;
64 }
65
66 /**
67 * @tc.name: RegisterSystemloadCallbackTest
68 * @tc.desc: Verify the RegisterSystemloadCallback function
69 * @tc.type: FUNC
70 * @tc.require: I6JPKG
71 */
72 HWTEST_F(SytemLoadTest, RegisterSystemloadCallbackTest, TestSize.Level1)
73 {
74 GTEST_LOG_(INFO) << "RegisterSystemloadCallbackTest Start";
75 try {
76 std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager;
77 SystemLoadStatus_->RegisterSystemloadCallback(dataSyncManager);
78 } catch (...) {
79 EXPECT_TRUE(false);
80 GTEST_LOG_(INFO) << "RegisterSystemloadCallbackTest FAILED";
81 }
82 GTEST_LOG_(INFO) << "RegisterSystemloadCallbackTest End";
83 }
84
85 /**
86 * @tc.name: OnSystemloadLevelTest001
87 * @tc.desc: Verify the OnSystemloadLevel function
88 * @tc.type: FUNC
89 * @tc.require: I6JPKG
90 */
91 HWTEST_F(SytemLoadTest, OnSystemloadLevelTest001, TestSize.Level1)
92 {
93 GTEST_LOG_(INFO) << "OnSystemloadLevelTest001 Start";
94 try {
95 int32_t level = 10;
96 SystemLoadListener_->OnSystemloadLevel(level);
97 } catch (...) {
98 EXPECT_TRUE(false);
99 GTEST_LOG_(INFO) << "OnSystemloadLevelTest001 FAILED";
100 }
101 GTEST_LOG_(INFO) << "OnSystemloadLevelTest001 End";
102 }
103
104 /**
105 * @tc.name: OnSystemloadLevelTest002
106 * @tc.desc: Verify the OnSystemloadLevel function
107 * @tc.type: FUNC
108 * @tc.require: I6JPKG
109 */
110 HWTEST_F(SytemLoadTest, OnSystemloadLevelTest002, TestSize.Level1)
111 {
112 GTEST_LOG_(INFO) << "OnSystemloadLevelTest001 Start";
113 try {
114 int32_t level = 1;
115 std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager;
116 SystemLoadListener_->dataSyncManager_ = make_shared<CloudFile::DataSyncManager>();
117 SystemLoadListener_->OnSystemloadLevel(level);
118 } catch (...) {
119 EXPECT_TRUE(false);
120 GTEST_LOG_(INFO) << "OnSystemloadLevelTest001 FAILED";
121 }
122 GTEST_LOG_(INFO) << "OnSystemloadLevelTest001 End";
123 }
124
125 /**
126 * @tc.name: OnSystemloadLevelTest003
127 * @tc.desc: Verify the OnSystemloadLevel function
128 * @tc.type: FUNC
129 * @tc.require: I6JPKG
130 */
131 HWTEST_F(SytemLoadTest, OnSystemloadLevelTest003, TestSize.Level1)
132 {
133 GTEST_LOG_(INFO) << "OnSystemloadLevelTest003 Start";
134 try {
135 int32_t level = 1;
136 system::SetParameter(TEMPERATURE_SYSPARAM_SYNC, "true");
137 auto dataSyncManager = std::make_shared<CloudFile::DataSyncManager>();
138 SystemLoadListener_->SetDataSycner(dataSyncManager);
139 SystemLoadListener_->OnSystemloadLevel(level);
140 } catch (...) {
141 EXPECT_TRUE(false);
142 GTEST_LOG_(INFO) << "OnSystemloadLevelTest003 FAILED";
143 }
144 GTEST_LOG_(INFO) << "OnSystemloadLevelTest003 End";
145 }
146
147 /**
148 * @tc.name: OnSystemloadLevelTest004
149 * @tc.desc: Verify the OnSystemloadLevel function
150 * @tc.type: FUNC
151 * @tc.require: I6JPKG
152 */
153 HWTEST_F(SytemLoadTest, OnSystemloadLevelTest004, TestSize.Level1)
154 {
155 GTEST_LOG_(INFO) << "OnSystemloadLevelTest004 Start";
156 try {
157 int32_t level = 1;
158 system::SetParameter(TEMPERATURE_SYSPARAM_THUMB, "true");
159 auto dataSyncManager = std::make_shared<CloudFile::DataSyncManager>();
160 SystemLoadListener_->SetDataSycner(dataSyncManager);
161 SystemLoadListener_->OnSystemloadLevel(level);
162 } catch (...) {
163 EXPECT_TRUE(false);
164 GTEST_LOG_(INFO) << "OnSystemloadLevelTest004 FAILED";
165 }
166 GTEST_LOG_(INFO) << "OnSystemloadLevelTest004 End";
167 }
168
169 /**
170 * @tc.name: IsLoadStatusUnderHotTest001
171 * @tc.desc: Verify the IsLoadStatusUnderHot function
172 * @tc.type: FUNC
173 * @tc.require: I6JPKG
174 */
175 HWTEST_F(SytemLoadTest, IsLoadStatusUnderHotTest001, TestSize.Level1)
176 {
177 GTEST_LOG_(INFO) << "IsLoadStatusUnderHotTest001 Start";
178 try {
179 SystemLoadStatus_->Setload(10);
180 bool ret = SystemLoadStatus_->IsLoadStatusUnderHot();
181 EXPECT_EQ(ret, false);
182 } catch (...) {
183 EXPECT_TRUE(false);
184 GTEST_LOG_(INFO) << "IsLoadStatusUnderHotTest001 FAILED";
185 }
186 GTEST_LOG_(INFO) << "IsLoadStatusUnderHotTest001 End";
187 }
188
189 /**
190 * @tc.name: IsLoadStatusUnderHotTest002
191 * @tc.desc: Verify the IsLoadStatusUnderHot function
192 * @tc.type: FUNC
193 * @tc.require: I6JPKG
194 */
195 HWTEST_F(SytemLoadTest, IsLoadStatusUnderHotTest002, TestSize.Level1)
196 {
197 GTEST_LOG_(INFO) << "IsLoadStatusUnderHotTest001 Start";
198 try {
199 SystemLoadStatus_->Setload(10);
200 bool ret = SystemLoadStatus_->IsLoadStatusUnderHot();
201 EXPECT_EQ(ret, false);
202 } catch (...) {
203 EXPECT_TRUE(false);
204 GTEST_LOG_(INFO) << "IsLoadStatusUnderHotTest001 FAILED";
205 }
206 GTEST_LOG_(INFO) << "IsLoadStatusUnderHotTest001 End";
207 }
208
209 /**
210 * @tc.name: IsLoadStatusUnderHotTest003
211 * @tc.desc: Verify the IsLoadStatusUnderHot function
212 * @tc.type: FUNC
213 * @tc.require: I6JPKG
214 */
215 HWTEST_F(SytemLoadTest, IsLoadStatusUnderHotTest003, TestSize.Level1)
216 {
217 GTEST_LOG_(INFO) << "IsLoadStatusUnderHotTest001 Start";
218 try {
219 SystemLoadStatus_->Setload(1);
220 bool ret = SystemLoadStatus_->IsLoadStatusUnderHot();
221 EXPECT_EQ(ret, true);
222 } catch (...) {
223 EXPECT_TRUE(false);
224 GTEST_LOG_(INFO) << "IsLoadStatusUnderHotTest001 FAILED";
225 }
226 GTEST_LOG_(INFO) << "IsLoadStatusUnderHotTest001 End";
227 }
228
229 /**
230 * @tc.name: IsLoadStatusUnderHotTest004
231 * @tc.desc: Verify the IsLoadStatusUnderHot function
232 * @tc.type: FUNC
233 * @tc.require: I6JPKG
234 */
235 HWTEST_F(SytemLoadTest, IsLoadStatusUnderHotTest004, TestSize.Level1)
236 {
237 GTEST_LOG_(INFO) << "IsLoadStatusUnderHotTest004 Start";
238 SystemLoadStatus_->Setload(10);
239 STOPPED_TYPE process = STOPPED_IN_THUMB;
240 bool ret = SystemLoadStatus_->IsLoadStatusUnderHot(process);
241 EXPECT_EQ(ret, false);
242 GTEST_LOG_(INFO) << "IsLoadStatusUnderHotTest004 End";
243 }
244
245 /**
246 * @tc.name: IsLoadStatusUnderHotTest005
247 * @tc.desc: Verify the IsLoadStatusUnderHot function
248 * @tc.type: FUNC
249 * @tc.require: I6JPKG
250 */
251 HWTEST_F(SytemLoadTest, IsLoadStatusUnderHotTest005, TestSize.Level1)
252 {
253 GTEST_LOG_(INFO) << "IsLoadStatusUnderHotTest005 Start";
254 SystemLoadStatus_->Setload(10);
255 STOPPED_TYPE process = STOPPED_IN_SYNC;
256 bool ret = SystemLoadStatus_->IsLoadStatusUnderHot(process);
257 EXPECT_EQ(ret, false);
258 GTEST_LOG_(INFO) << "IsLoadStatusUnderHotTest005 End";
259 }
260
261 HWTEST_F(SytemLoadTest, IsLoadStatusUnderNormalTest001, TestSize.Level1)
262 {
263 SystemLoadStatus_->Setload(SYSTEMLOADLEVEL_NORMAL);
264 bool ret = SystemLoadStatus_->IsLoadStatusUnderNormal();
265 EXPECT_TRUE(ret);
266 }
267
268 HWTEST_F(SytemLoadTest, IsLoadStatusUnderNormalTest002, TestSize.Level1)
269 {
270 SystemLoadStatus_->Setload(SYSTEMLOADLEVEL_NORMAL + 1);
271 bool ret = SystemLoadStatus_->IsLoadStatusUnderNormal();
272 EXPECT_FALSE(ret);
273 }
274
275 HWTEST_F(SytemLoadTest, IsLoadStatusUnderNormalTest003, TestSize.Level1)
276 {
277 SystemLoadStatus_->Setload(SYSTEMLOADLEVEL_NORMAL - 1);
278 bool ret = SystemLoadStatus_->IsLoadStatusUnderNormal();
279 EXPECT_TRUE(ret);
280 }
281
282 } // namespace OHOS::FileManagement::CloudSync::Test