1 /*
2 * Copyright (c) 2023 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 "gtest/hwext/gtest-multithread.h"
18
19 #include "standby_config_manager.h"
20 #include "nlohmann/json.hpp"
21
22 #include "standby_service_log.h"
23 #include "json_utils.h"
24 #include "common_constant.h"
25 #include "mock_common_event.h"
26
27 using namespace testing::ext;
28 using namespace testing::mt;
29
30 namespace OHOS {
31 namespace DevStandbyMgr {
32 namespace {
33 const std::string JSON_KEY = "key";
34 const std::string JSON_ERROR_KEY = "error_key";
35 const std::string TAG_APPS_LIMIT = "apps_limit";
36 const std::string TAG_BATTERY_THRESHOLD = "battery_threshold";
37 }
38 class StandbyUtilsUnitTest : public testing::Test {
39 public:
40 static void SetUpTestCase();
TearDownTestCase()41 static void TearDownTestCase() {}
SetUp()42 void SetUp() override
43 {
44 g_mockFunctionCallCount = 0;
45 }
TearDown()46 void TearDown() override {}
47 };
48
SetUpTestCase()49 void StandbyUtilsUnitTest::SetUpTestCase()
50 {
51 StandbyConfigManager::GetInstance()->Init();
52 }
53
54 /**
55 * @tc.name: StandbyUtilsUnitTest_002
56 * @tc.desc: test GetInt32FromJsonValue.
57 * @tc.type: FUNC
58 * @tc.require:
59 */
60 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_002, TestSize.Level1)
61 {
62 nlohmann::json jsonValue {};
63 int32_t value {0};
64 bool ret = JsonUtils::GetInt32FromJsonValue(jsonValue, "", value);
65 EXPECT_FALSE(ret);
66 jsonValue = nlohmann::json::parse("{\"key\":1}", nullptr, false);
67 JsonUtils::GetInt32FromJsonValue(jsonValue, "", value);
68 JsonUtils::GetInt32FromJsonValue(jsonValue, JSON_KEY, value);
69 JsonUtils::GetInt32FromJsonValue(jsonValue, JSON_ERROR_KEY, value);
70 jsonValue = nlohmann::json::parse("{\"key\":\"1\"}", nullptr, false);
71 ret = JsonUtils::GetInt32FromJsonValue(jsonValue, JSON_ERROR_KEY, value);
72 EXPECT_FALSE(ret);
73 JsonUtils::GetInt32FromJsonValue(jsonValue, JSON_KEY, value);
74 }
75
76 /**
77 * @tc.name: StandbyUtilsUnitTest_003
78 * @tc.desc: test GetBoolFromJsonValue.
79 * @tc.type: FUNC
80 * @tc.require:
81 */
82 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_003, TestSize.Level1)
83 {
84 nlohmann::json jsonValue {};
85 bool value {false};
86 bool ret = JsonUtils::GetBoolFromJsonValue(jsonValue, "", value);
87 EXPECT_FALSE(ret);
88 jsonValue = nlohmann::json::parse("{\"key\":true}", nullptr, false);
89 JsonUtils::GetBoolFromJsonValue(jsonValue, "", value);
90 JsonUtils::GetBoolFromJsonValue(jsonValue, JSON_KEY, value);
91 JsonUtils::GetBoolFromJsonValue(jsonValue, JSON_ERROR_KEY, value);
92 jsonValue = nlohmann::json::parse("{\"key\":\"true\"}", nullptr, false);
93 ret = JsonUtils::GetBoolFromJsonValue(jsonValue, JSON_ERROR_KEY, value);
94 EXPECT_FALSE(ret);
95 JsonUtils::GetBoolFromJsonValue(jsonValue, JSON_KEY, value);
96 }
97
98 /**
99 * @tc.name: StandbyUtilsUnitTest_004
100 * @tc.desc: test GetStringFromJsonValue.
101 * @tc.type: FUNC
102 * @tc.require:
103 */
104 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_004, TestSize.Level1)
105 {
106 nlohmann::json jsonValue {};
107 std::string value {""};
108 bool ret = JsonUtils::GetStringFromJsonValue(jsonValue, "", value);
109 EXPECT_FALSE(ret);
110 jsonValue = nlohmann::json::parse("{\"key\":\"str\"}", nullptr, false);
111 JsonUtils::GetStringFromJsonValue(jsonValue, "", value);
112 JsonUtils::GetStringFromJsonValue(jsonValue, JSON_KEY, value);
113 JsonUtils::GetStringFromJsonValue(jsonValue, JSON_ERROR_KEY, value);
114 jsonValue = nlohmann::json::parse("{\"key\":1}", nullptr, false);
115 ret = JsonUtils::GetStringFromJsonValue(jsonValue, JSON_ERROR_KEY, value);
116 EXPECT_FALSE(ret);
117 }
118
119 /**
120 * @tc.name: StandbyUtilsUnitTest_005
121 * @tc.desc: test GetObjFromJsonValue.
122 * @tc.type: FUNC
123 * @tc.require:
124 */
125 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_005, TestSize.Level1)
126 {
127 nlohmann::json jsonValue {};
128 nlohmann::json value {};
129 bool ret = JsonUtils::GetObjFromJsonValue(jsonValue, "", value);
130 EXPECT_FALSE(ret);
131 jsonValue = nlohmann::json::parse("{\"key\":{\"value\":1}}", nullptr, false);
132 JsonUtils::GetObjFromJsonValue(jsonValue, "", value);
133 JsonUtils::GetObjFromJsonValue(jsonValue, JSON_KEY, value);
134 JsonUtils::GetObjFromJsonValue(jsonValue, JSON_ERROR_KEY, value);
135 jsonValue = nlohmann::json::parse("{\"key\":\"str\"}", nullptr, false);
136 ret = JsonUtils::GetObjFromJsonValue(jsonValue, JSON_ERROR_KEY, value);
137 EXPECT_FALSE(ret);
138 }
139
140 /**
141 * @tc.name: StandbyUtilsUnitTest_006
142 * @tc.desc: test GetArrayFromJsonValue.
143 * @tc.type: FUNC
144 * @tc.require:
145 */
146 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_006, TestSize.Level1)
147 {
148 nlohmann::json jsonValue {};
149 nlohmann::json value {};
150 bool ret = JsonUtils::GetArrayFromJsonValue(jsonValue, "", value);
151 EXPECT_FALSE(ret);
152 jsonValue = nlohmann::json::parse("{\"key\":[1,2.3]}", nullptr, false);
153 JsonUtils::GetArrayFromJsonValue(jsonValue, "", value);
154 JsonUtils::GetArrayFromJsonValue(jsonValue, JSON_KEY, value);
155 JsonUtils::GetArrayFromJsonValue(jsonValue, JSON_ERROR_KEY, value);
156 jsonValue = nlohmann::json::parse("{\"key\":true}", nullptr, false);
157 ret = JsonUtils::GetArrayFromJsonValue(jsonValue, JSON_ERROR_KEY, value);
158 EXPECT_FALSE(ret);
159 }
160
161 /**
162 * @tc.name: StandbyUtilsUnitTest_007
163 * @tc.desc: test GetStrArrFromJsonValue.
164 * @tc.type: FUNC
165 * @tc.require:
166 */
167 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_007, TestSize.Level1)
168 {
169 nlohmann::json jsonValue {};
170 std::vector<std::string> value {};
171 bool ret = JsonUtils::GetStrArrFromJsonValue(jsonValue, "", value);
172 EXPECT_FALSE(ret);
173 jsonValue = nlohmann::json::parse("{\"key\":[\"1\",\"2\"]}", nullptr, false);
174 JsonUtils::GetStrArrFromJsonValue(jsonValue, "", value);
175 JsonUtils::GetStrArrFromJsonValue(jsonValue, JSON_KEY, value);
176 JsonUtils::GetStrArrFromJsonValue(jsonValue, JSON_ERROR_KEY, value);
177 jsonValue = nlohmann::json::parse("{\"key\":true}", nullptr, false);
178 ret = JsonUtils::GetStrArrFromJsonValue(jsonValue, JSON_ERROR_KEY, value);
179 EXPECT_FALSE(ret);
180 jsonValue = nlohmann::json::parse("{\"key\":[1,2]}", nullptr, false);
181 JsonUtils::GetStrArrFromJsonValue(jsonValue, JSON_KEY, value);
182 }
183
184 /**
185 * @tc.name: StandbyUtilsUnitTest_008
186 * @tc.desc: test GetRealPath.
187 * @tc.type: FUNC
188 * @tc.require:
189 */
190 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_008, TestSize.Level1)
191 {
192 std::string partialPath (PATH_MAX + 1, 'a');
193 std::string fullPath;
194 EXPECT_FALSE(JsonUtils::GetRealPath(partialPath, fullPath));
195 JsonUtils::CreateNodeFile("/data/service/el1/public/device_standby/allow_record");
196 JsonUtils::CreateNodeFile("/data/service/el1/public/device_standby/allow_record");
197 nlohmann::json jsonValue;
198 JsonUtils::DumpJsonValueToFile(jsonValue, "/data/service/el1/public/device_standby/record");
199 }
200
201 /**
202 * @tc.name: StandbyUtilsUnitTest_009
203 * @tc.desc: test ParseCondition.
204 * @tc.type: FUNC
205 * @tc.require:
206 */
207 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_009, TestSize.Level1)
208 {
209 EXPECT_TRUE(StandbyConfigManager::GetInstance()->ParseCondition("test") == 0);
210 }
211
212 /**
213 * @tc.name: StandbyUtilsUnitTest_010
214 * @tc.desc: test DUMP.
215 * @tc.type: FUNC
216 * @tc.require:
217 */
218 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_010, TestSize.Level1)
219 {
220 std::string result {""};
221 StandbyConfigManager::GetInstance()->DumpSetDebugMode(true);
222 StandbyConfigManager::GetInstance()->DumpSetDebugMode(false);
223 StandbyConfigManager::GetInstance()->DumpSetSwitch("test", true, result);
224 StandbyConfigManager::GetInstance()->DumpSetSwitch(NAP_SWITCH, true, result);
225 StandbyConfigManager::GetInstance()->DumpSetParameter("test", 0, result);
226 StandbyConfigManager::GetInstance()->DumpSetParameter(NAP_TIMEOUT, 0, result);
227
228 StandbyConfigManager::GetInstance()->DumpStandbyConfigInfo(result);
229 EXPECT_FALSE(result.empty());
230 }
231
232 /**
233 * @tc.name: StandbyUtilsUnitTest_011
234 * @tc.desc: test ParseTimeLimitedConfig.
235 * @tc.type: FUNC
236 * @tc.require:
237 */
238 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_011, TestSize.Level1)
239 {
240 nlohmann::json jsonValue = nlohmann::json::parse("{\"apps_limit\":[\"1\",\"2\"]}", nullptr, false);
241 std::vector<TimeLtdProcess> timeLimitedConfig {};
242 StandbyConfigManager::GetInstance()->ParseTimeLimitedConfig(jsonValue, TAG_APPS_LIMIT, timeLimitedConfig);
243 EXPECT_TRUE(timeLimitedConfig.empty());
244 jsonValue = nlohmann::json::parse("{\"apps_limit\":[{\"name\":\"bundleName\"}]}", nullptr, false);
245 StandbyConfigManager::GetInstance()->ParseTimeLimitedConfig(jsonValue, TAG_APPS_LIMIT, timeLimitedConfig);
246 jsonValue = nlohmann::json::parse("{\"apps_limit\":[{\"name\":\"bundleName\", \"duration\":0}]}", nullptr, false);
247 StandbyConfigManager::GetInstance()->ParseTimeLimitedConfig(jsonValue, TAG_APPS_LIMIT, timeLimitedConfig);
248 }
249
250 /**
251 * @tc.name: StandbyUtilsUnitTest_012
252 * @tc.desc: test ParseCommonResCtrlConfig.
253 * @tc.type: FUNC
254 * @tc.require:
255 */
256 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_012, TestSize.Level1)
257 {
258 nlohmann::json jsonValue = nlohmann::json::parse("{}", nullptr, false);
259 DefaultResourceConfig resCtrlConfig {};
260 StandbyConfigManager::GetInstance()->ParseCommonResCtrlConfig(jsonValue, resCtrlConfig);
261 EXPECT_TRUE(resCtrlConfig.conditions_.empty());
262 jsonValue = nlohmann::json::parse("{\"action\":\"allow\"}", nullptr, false);
263 StandbyConfigManager::GetInstance()->ParseCommonResCtrlConfig(jsonValue, resCtrlConfig);
264
265 jsonValue = nlohmann::json::parse("{\"condition\":[\"day_standby\"], \"action\":\"allow\"}",
266 nullptr, false);
267 StandbyConfigManager::GetInstance()->ParseCommonResCtrlConfig(jsonValue, resCtrlConfig);
268 jsonValue = nlohmann::json::parse("{\"condition\":0, \"action\":0}",
269 nullptr, false);
270 StandbyConfigManager::GetInstance()->ParseCommonResCtrlConfig(jsonValue, resCtrlConfig);
271 jsonValue = nlohmann::json::parse("{\"condition\":[\"day\"], \"action\":\"allow\"}", nullptr, false);
272 StandbyConfigManager::GetInstance()->ParseCommonResCtrlConfig(jsonValue, resCtrlConfig);
273 }
274
275 /**
276 * @tc.name: StandbyUtilsUnitTest_013
277 * @tc.desc: test ParseDefaultResCtrlConfig.
278 * @tc.type: FUNC
279 * @tc.require:
280 */
281 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_013, TestSize.Level1)
282 {
283 nlohmann::json defaultConfig = nlohmann::json::parse("{\"test\":true}", nullptr, false);
284 StandbyConfigManager::GetInstance()->ParseResCtrlConfig(defaultConfig);
285 nlohmann::json testValue = StandbyConfigManager::GetInstance()->GetDefaultConfig("test");
286 EXPECT_TRUE(testValue.get<bool>());
287
288 nlohmann::json resConfigArray = nlohmann::json::parse("{}", nullptr, false);
289 EXPECT_FALSE(StandbyConfigManager::GetInstance()->ParseDefaultResCtrlConfig("test", resConfigArray));
290 StandbyConfigManager::GetInstance()->ParseStrategyListConfig(resConfigArray);
291 StandbyConfigManager::GetInstance()->ParseResCtrlConfig(resConfigArray);
292 StandbyConfigManager::GetInstance()->ParseTimerResCtrlConfig(resConfigArray);
293 resConfigArray = nlohmann::json::parse("{\"condition\":[]}", nullptr, false);
294 StandbyConfigManager::GetInstance()->ParseDefaultResCtrlConfig("test", resConfigArray);
295 StandbyConfigManager::GetInstance()->ParseTimerResCtrlConfig(resConfigArray);
296
297 std::string content = "{\"condition\":[\"day\"], \"action\":\"allow\"}";
298 resConfigArray = nlohmann::json::parse(content, nullptr, false);
299 StandbyConfigManager::GetInstance()->ParseDefaultResCtrlConfig("test", resConfigArray);
300 StandbyConfigManager::GetInstance()->ParseTimerResCtrlConfig(resConfigArray);
301
302 content = "{\"condition\":[\"day\"], \"action\":\"allow\",\"time_clock_apps\":[]}";
303 resConfigArray = nlohmann::json::parse(content, nullptr, false);
304 StandbyConfigManager::GetInstance()->ParseTimerResCtrlConfig(resConfigArray);
305
306 content = "{\"condition\":[\"day\"], \"action\":\"allow\",\"time_clock_apps\":[{\"name\":\"bundleName\"}]}";
307 resConfigArray = nlohmann::json::parse(content, nullptr, false);
308 StandbyConfigManager::GetInstance()->ParseTimerResCtrlConfig(resConfigArray);
309
310 content = "{\"condition\":[\"day\"], \"action\":\"allow\",\"time_clock_apps\":[{\"name\":\"bundleName\","\
311 "\"timer_clock\":true, \"timer_period\":0}]}";
312 resConfigArray = nlohmann::json::parse(content, nullptr, false);
313 StandbyConfigManager::GetInstance()->ParseTimerResCtrlConfig(resConfigArray);
314 }
315
316 /**
317 * @tc.name: StandbyUtilsUnitTest_014
318 * @tc.desc: test ParseDeviceStanbyConfig.
319 * @tc.type: FUNC
320 * @tc.require:
321 */
322 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_014, TestSize.Level1)
323 {
324 nlohmann::json devStandbyConfigRoot = nlohmann::json::parse("{}", nullptr, false);
325 EXPECT_TRUE(StandbyConfigManager::GetInstance()->ParseDeviceStanbyConfig(devStandbyConfigRoot));
326 std::string content = "{\"halfhour_switch_setting\":[\"test\":0]}";
327 devStandbyConfigRoot = nlohmann::json::parse(content, nullptr, false);
328 StandbyConfigManager::GetInstance()->ParseDeviceStanbyConfig(devStandbyConfigRoot);
329 StandbyConfigManager::GetInstance()->ParseHalfHourSwitchConfig(devStandbyConfigRoot);
330 content = "{\"halfhour_switch_setting\":[\"test\":true]}";
331 devStandbyConfigRoot = nlohmann::json::parse(content, nullptr, false);
332 StandbyConfigManager::GetInstance()->ParseHalfHourSwitchConfig(devStandbyConfigRoot);
333 content = "{\"standby\":[\"test\":0]}";
334 devStandbyConfigRoot = nlohmann::json::parse(content, nullptr, false);
335 StandbyConfigManager::GetInstance()->ParseDeviceStanbyConfig(devStandbyConfigRoot);
336 content = "{\"detect_list\":[\"test\":0]}";
337 devStandbyConfigRoot = nlohmann::json::parse(content, nullptr, false);
338 StandbyConfigManager::GetInstance()->ParseDeviceStanbyConfig(devStandbyConfigRoot);
339 content = "{\"maintenance_list\":[\"test\":[1, 2, 3]]}";
340 devStandbyConfigRoot = nlohmann::json::parse(content, nullptr, false);
341 StandbyConfigManager::GetInstance()->ParseDeviceStanbyConfig(devStandbyConfigRoot);
342 content = "{\"ladder_battery_threshold_list\":[\"test\":[4, 3, 2, 1]]}";
343 devStandbyConfigRoot = nlohmann::json::parse(content, nullptr, false);
344 StandbyConfigManager::GetInstance()->ParseDeviceStanbyConfig(devStandbyConfigRoot);
345 }
346
347 /**
348 * @tc.name: StandbyUtilsUnitTest_015
349 * @tc.desc: test StandbyConfigManager.
350 * @tc.type: FUNC
351 * @tc.require:
352 */
353 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_015, TestSize.Level1)
354 {
355 StandbyConfigManager::GetInstance()->GetStrategySwitch("test");
356 StandbyConfigManager::GetInstance()->GetTimerResConfig();
357 TimeLtdProcess process1 {"process1", 10};
358 TimeLtdProcess process2 {"process2", 20};
359 EXPECT_TRUE(process1 < process2);
360 }
361
362 /**
363 * @tc.name: StandbyUtilsUnitTest_016
364 * @tc.desc: test SplitVersion.
365 * @tc.type: FUNC
366 * @tc.require:
367 */
368 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_016, TestSize.Level1)
369 {
370 std::string versionStr = "1.20.20.012";
371 char versionDelim = '.';
372 auto tokens = JsonUtils::SplitVersion(versionStr, versionDelim);
373 ASSERT_TRUE(tokens.size() != 0);
374 for (const auto& token : tokens) {
375 EXPECT_TRUE(token.size() != 0);
376 }
377 }
378
379 /**
380 * @tc.name: StandbyUtilsUnitTest_017
381 * @tc.desc: test GetCloudConfig.
382 * @tc.type: FUNC
383 * @tc.require:
384 */
385 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_017, TestSize.Level1)
386 {
387 StandbyConfigManager::GetInstance()->getSingleExtConfigFunc_ = MockUtils::MockGetSingleExtConfigFunc;
388 StandbyConfigManager::GetInstance()->GetCloudConfig();
389 EXPECT_EQ(g_mockFunctionCallCount, 1);
390 }
391
392 /**
393 * @tc.name: StandbyUtilsUnitTest_018
394 * @tc.desc: test getSingleExtConfigFunc_ == nullptr.
395 * @tc.type: FUNC
396 * @tc.require:
397 */
398 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_018, TestSize.Level1)
399 {
400 StandbyConfigManager::GetInstance()->getSingleExtConfigFunc_ = nullptr;
401 StandbyConfigManager::GetInstance()->GetCloudConfig();
402 EXPECT_EQ(g_mockFunctionCallCount, 0);
403 }
404
405 /**
406 * @tc.name: StandbyUtilsUnitTest_019
407 * @tc.desc: test GetCloudVersion.
408 * @tc.type: FUNC
409 * @tc.require:
410 */
411 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_019, TestSize.Level1)
412 {
413 int32_t CLOUD_CONFIG_INDEX = 7;
414 std::string version;
415 StandbyConfigManager::GetInstance()->getSingleExtConfigFunc_ = MockUtils::MockGetSingleExtConfigFunc;
416 StandbyConfigManager::GetInstance()->GetCloudVersion(CLOUD_CONFIG_INDEX, version);
417 EXPECT_EQ(version, "1.1.1.1");
418 }
419
420 /**
421 * @tc.name: StandbyUtilsUnitTest_020
422 * @tc.desc: test CompareVersion when only configVerA is empty.
423 * @tc.type: FUNC
424 * @tc.require:
425 */
426 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_020, TestSize.Level1)
427 {
428 std::string configVerA = "";
429 std::string configVerB = "1.0.0.0";
430 int result = StandbyConfigManager::GetInstance()->CompareVersion(configVerA, configVerB);
431 EXPECT_EQ(result, 0);
432 }
433
434 /**
435 * @tc.name: StandbyUtilsUnitTest_021
436 * @tc.desc: test CompareVersion when only configVerB is empty.
437 * @tc.type: FUNC
438 * @tc.require:
439 */
440 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_021, TestSize.Level1)
441 {
442 std::string configVerA = "1.0.0.0";
443 std::string configVerB = "";
444 int result = StandbyConfigManager::GetInstance()->CompareVersion(configVerA, configVerB);
445 EXPECT_EQ(result, 1);
446 }
447
448 /**
449 * @tc.name: StandbyUtilsUnitTest_022
450 * @tc.desc: test CompareVersion when configVerA and configVerB are both empty.
451 * @tc.type: FUNC
452 * @tc.require:
453 */
454 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_022, TestSize.Level1)
455 {
456 std::string configVerA = "";
457 std::string configVerB = "";
458 int result = StandbyConfigManager::GetInstance()->CompareVersion(configVerA, configVerB);
459 EXPECT_EQ(result, -1);
460 }
461
462 /**
463 * @tc.name: StandbyUtilsUnitTest_023
464 * @tc.desc: test CompareVersion when the VERSION_LEN of configVer is invaild.
465 * @tc.type: FUNC
466 * @tc.require:
467 */
468 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_023, TestSize.Level1)
469 {
470 std::string configVerA = "1.0";
471 std::string configVerB = "1.0.0.0";
472 int result = StandbyConfigManager::GetInstance()->CompareVersion(configVerA, configVerB);
473 EXPECT_EQ(result, -1);
474 }
475
476 /**
477 * @tc.name: StandbyUtilsUnitTest_024
478 * @tc.desc: test CompareVersion when the configVerB is invaild.
479 * @tc.type: FUNC
480 * @tc.require:
481 */
482 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_024, TestSize.Level1)
483 {
484 std::string configVerA = "1.0.0.a";
485 std::string configVerB = "1.0.0.b";
486 int result = StandbyConfigManager::GetInstance()->CompareVersion(configVerA, configVerB);
487 EXPECT_EQ(result, -1);
488 }
489
490 /**
491 * @tc.name: StandbyUtilsUnitTest_025
492 * @tc.desc: test CompareVersion when configVerA is bigger than configVerB.
493 * @tc.type: FUNC
494 * @tc.require:
495 */
496 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_025, TestSize.Level1)
497 {
498 std::string configVerA = "1.0.0.1";
499 std::string configVerB = "1.0.0.0";
500 int result = StandbyConfigManager::GetInstance()->CompareVersion(configVerA, configVerB);
501 EXPECT_EQ(result, 1);
502 }
503
504 /**
505 * @tc.name: StandbyUtilsUnitTest_026
506 * @tc.desc: test CompareVersion when configVerB is bigger than configVerA.
507 * @tc.type: FUNC
508 * @tc.require:
509 */
510 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_026, TestSize.Level1)
511 {
512 std::string configVerA = "1.0.0.0";
513 std::string configVerB = "1.0.0.1";
514 int result = StandbyConfigManager::GetInstance()->CompareVersion(configVerA, configVerB);
515 EXPECT_EQ(result, 0);
516 }
517
518 /**
519 * @tc.name: StandbyUtilsUnitTest_027
520 * @tc.desc: test CompareVersion when configVerA is equal to configVerB.
521 * @tc.type: FUNC
522 * @tc.require:
523 */
524 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_027, TestSize.Level1)
525 {
526 std::string configVerA = "1.0.0.0";
527 std::string configVerB = "1.0.0.0";
528 int result = StandbyConfigManager::GetInstance()->CompareVersion(configVerA, configVerB);
529 EXPECT_EQ(result, 1);
530 }
531
532 /**
533 * @tc.name: StandbyUtilsUnitTest_028
534 * @tc.desc: test GetStandbyLadderBatteryList of StandbyConfigManager.
535 * @tc.type: FUNC
536 * @tc.require:
537 */
538 HWTEST_F(StandbyUtilsUnitTest, StandbyUtilsUnitTest_028, TestSize.Level1)
539 {
540 StandbyConfigManager::GetInstance()->ladderBatteryListMap_ = {
541 {"battery_threshold", {90, 40}}
542 };
543 auto result = StandbyConfigManager::GetInstance()->GetStandbyLadderBatteryList(TAG_BATTERY_THRESHOLD);
544 EXPECT_EQ(result.size(), 2);
545 StandbyConfigManager::GetInstance()->ladderBatteryListMap_.clear();
546 result = StandbyConfigManager::GetInstance()->GetStandbyLadderBatteryList(TAG_BATTERY_THRESHOLD);
547 EXPECT_EQ(result.size(), 0);
548 }
549 } // namespace DevStandbyMgr
550 } // namespace OHOS
551