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