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 <future>
17 #include <optional>
18 #include <unistd.h>
19 #include <utility>
20 #include <vector>
21
22 #include <gtest/gtest.h>
23
24 #include "devicestatus_define.h"
25 #include "devicestatus_errors.h"
26 #include "utility.h"
27
28 #undef LOG_TAG
29 #define LOG_TAG "UtilityTest"
30
31 namespace OHOS {
32 namespace Msdp {
33 namespace DeviceStatus {
34 using namespace testing::ext;
35 namespace {
36 constexpr int32_t TIME_WAIT_FOR_OP_MS { 20 };
37 const std::string STR_INFO { "abc12345" };
38 const std::string STR_PREFIX { "abc" };
39 const std::string NETWORK_ID = { "abcd123456ef" };
40 const std::string EXPECT_ID = { "abcd1*****456ef" };
41 const std::string COPY_DRAG_PATH { "/system/etc/device_status/drag_icon/Copy_Drag.svg" };
42 constexpr int32_t FILE_SIZE_MAX { 0x5000 };
43 constexpr size_t SIZE1 {10};
44 constexpr size_t SIZE2 {20};
45 } // namespace
46
47 class UtilityTest : public testing::Test {
48 public:
49 void SetUp();
50 void TearDown();
51 static void SetUpTestCase();
52 static void TearDownTestCase(void);
53 };
54
SetUpTestCase()55 void UtilityTest::SetUpTestCase() {}
56
TearDownTestCase()57 void UtilityTest::TearDownTestCase() {}
58
SetUp()59 void UtilityTest::SetUp() {}
60
TearDown()61 void UtilityTest::TearDown()
62 {
63 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP_MS));
64 }
65
66 /**
67 * @tc.name: UtityTest_IsInteger_001
68 * @tc.desc: Checks whether a string is an integer.
69 * @tc.type: FUNC
70 * @tc.require:
71 */
72 HWTEST_F(UtilityTest, UtityTest_IsInteger_001, TestSize.Level1)
73 {
74 CALL_TEST_DEBUG;
75 std::string target = "0";
76 bool ret = Utility::IsInteger(target);
77 ASSERT_TRUE(ret);
78 }
79
80 /**
81 * @tc.name: UtityTest_IsInteger_002
82 * @tc.desc: Checks whether a string is an integer.
83 * @tc.type: FUNC
84 * @tc.require:
85 */
86 HWTEST_F(UtilityTest, UtityTest_IsInteger_002, TestSize.Level1)
87 {
88 CALL_TEST_DEBUG;
89 std::string target = "123";
90 bool ret = Utility::IsInteger(target);
91 ASSERT_TRUE(ret);
92 }
93
94 /**
95 * @tc.name: UtityTest_IsInteger_003
96 * @tc.desc: Checks whether a string is an integer.
97 * @tc.type: FUNC
98 * @tc.require:
99 */
100 HWTEST_F(UtilityTest, UtityTest_IsInteger_003, TestSize.Level1)
101 {
102 CALL_TEST_DEBUG;
103 std::string target = " 0";
104 bool ret = Utility::IsInteger(target);
105 ASSERT_TRUE(ret);
106 }
107
108 /**
109 * @tc.name: UtityTest_IsInteger_004
110 * @tc.desc: Checks whether a string is an integer.
111 * @tc.type: FUNC
112 * @tc.require:
113 */
114 HWTEST_F(UtilityTest, UtityTest_IsInteger_004, TestSize.Level1)
115 {
116 CALL_TEST_DEBUG;
117 std::string target = "-0";
118 bool ret = Utility::IsInteger(target);
119 ASSERT_TRUE(ret);
120 }
121
122 /**
123 * @tc.name: UtityTest_IsInteger_005
124 * @tc.desc: Checks whether a string is an integer.
125 * @tc.type: FUNC
126 * @tc.require:
127 */
128 HWTEST_F(UtilityTest, UtityTest_IsInteger_005, TestSize.Level1)
129 {
130 CALL_TEST_DEBUG;
131 std::string target = "-1";
132 bool ret = Utility::IsInteger(target);
133 ASSERT_TRUE(ret);
134 }
135
136 /**
137 * @tc.name: UtityTest_IsInteger_006
138 * @tc.desc: Checks whether a string is an integer.
139 * @tc.type: FUNC
140 * @tc.require:
141 */
142 HWTEST_F(UtilityTest, UtityTest_IsInteger_006, TestSize.Level1)
143 {
144 CALL_TEST_DEBUG;
145 std::string target = "-10";
146 bool ret = Utility::IsInteger(target);
147 ASSERT_TRUE(ret);
148 }
149
150 /**
151 * @tc.name: UtityTest_IsInteger_007
152 * @tc.desc: Checks whether a string is an integer.
153 * @tc.type: FUNC
154 * @tc.require:
155 */
156 HWTEST_F(UtilityTest, UtityTest_IsInteger_007, TestSize.Level1)
157 {
158 CALL_TEST_DEBUG;
159 std::string target = "123";
160 bool ret = Utility::IsInteger(target);
161 ASSERT_TRUE(ret);
162 }
163
164 /**
165 * @tc.name: UtityTest_IsInteger_008
166 * @tc.desc: Checks whether a string is an integer.
167 * @tc.type: FUNC
168 * @tc.require:
169 */
170 HWTEST_F(UtilityTest, UtityTest_IsInteger_008, TestSize.Level1)
171 {
172 CALL_TEST_DEBUG;
173 std::string target = "-123";
174 bool ret = Utility::IsInteger(target);
175 ASSERT_TRUE(ret);
176 }
177
178 /**
179 * @tc.name: UtityTest_IsInteger_009
180 * @tc.desc: Checks whether a string is an integer.
181 * @tc.type: FUNC
182 * @tc.require:
183 */
184 HWTEST_F(UtilityTest, UtityTest_IsInteger_009, TestSize.Level1)
185 {
186 CALL_TEST_DEBUG;
187 std::string target = "0123";
188 bool ret = Utility::IsInteger(target);
189 ASSERT_FALSE(ret);
190 }
191
192 /**
193 * @tc.name: UtityTest_IsInteger_010
194 * @tc.desc: Checks whether a string is an integer.
195 * @tc.type: FUNC
196 * @tc.require:
197 */
198 HWTEST_F(UtilityTest, UtityTest_IsInteger_010, TestSize.Level1)
199 {
200 CALL_TEST_DEBUG;
201 std::string target = "A01";
202 bool ret = Utility::IsInteger(target);
203 ASSERT_FALSE(ret);
204 }
205
206 /**
207 * @tc.name: UtityTest_IsInteger_011
208 * @tc.desc: Checks whether a string is an integer.
209 * @tc.type: FUNC
210 * @tc.require:
211 */
212 HWTEST_F(UtilityTest, UtityTest_IsInteger_011, TestSize.Level1)
213 {
214 CALL_TEST_DEBUG;
215 std::string target = "A-10";
216 bool ret = Utility::IsInteger(target);
217 ASSERT_FALSE(ret);
218 }
219
220 /**
221 * @tc.name: UtityTest_IsInteger_012
222 * @tc.desc: Checks whether a string is an integer.
223 * @tc.type: FUNC
224 * @tc.require:
225 */
226 HWTEST_F(UtilityTest, UtityTest_IsInteger_012, TestSize.Level1)
227 {
228 CALL_TEST_DEBUG;
229 std::string target = " 123A";
230 bool ret = Utility::IsInteger(target);
231 ASSERT_FALSE(ret);
232 }
233
234 /**
235 * @tc.name: UtityTest_IsInteger_013
236 * @tc.desc: Checks whether a string is an integer.
237 * @tc.type: FUNC
238 * @tc.require:
239 */
240 HWTEST_F(UtilityTest, UtityTest_IsInteger_013, TestSize.Level1)
241 {
242 CALL_TEST_DEBUG;
243 std::string target = " 123 A";
244 bool ret = Utility::IsInteger(target);
245 ASSERT_FALSE(ret);
246 }
247
248 /**
249 * @tc.name: UtityTest_GetFileSize1_001
250 * @tc.desc: Enter an existing file and read the length.
251 * @tc.type: FUNC
252 * @tc.require:
253 */
254 HWTEST_F(UtilityTest, UtityTest_GetFileSize1_001, TestSize.Level1)
255 {
256 CALL_TEST_DEBUG;
257 ssize_t fileSize = Utility::GetFileSize(COPY_DRAG_PATH.c_str());
258 if ((fileSize <= 0) || (fileSize > FILE_SIZE_MAX)) {
259 FI_HILOGW("File size out of read range, filseSize: %{public}zd.", fileSize);
260 } else {
261 FI_HILOGI("%{public}d: File is %{public}s, and file size is %{public}zd.",
262 __LINE__, COPY_DRAG_PATH.c_str(), fileSize);
263 }
264 EXPECT_GT(fileSize, 0);
265 }
266
267 /**
268 * @tc.name: UtityTest_GetFileSize1_002
269 * @tc.desc: Enter a nonexistent file and read the length.
270 * @tc.type: FUNC
271 * @tc.require:
272 */
273 HWTEST_F(UtilityTest, UtityTest_GetFileSize1_002, TestSize.Level1)
274 {
275 CALL_TEST_DEBUG;
276 const char *filePath = "xxx/not_exist_file.txt";
277 ssize_t fileSize = Utility::GetFileSize(filePath);
278 if ((fileSize <= 0) || (fileSize > FILE_SIZE_MAX)) {
279 FI_HILOGW("File size out of read range, filseSize: %{public}zd.", fileSize);
280 }
281 EXPECT_EQ(fileSize, 0);
282 }
283
284 /**
285 * @tc.name: UtityTest_GetFileSize1_003
286 * @tc.desc: Enter an empty string and read the length.
287 * @tc.type: FUNC
288 * @tc.require:
289 */
290 HWTEST_F(UtilityTest, UtityTest_GetFileSize1_003, TestSize.Level1)
291 {
292 CALL_TEST_DEBUG;
293 const char *filePath = "";
294 ssize_t fileSize = Utility::GetFileSize(filePath);
295 if ((fileSize <= 0) || (fileSize > FILE_SIZE_MAX)) {
296 FI_HILOGW("File size out of read range, filseSize: %{public}zd.", fileSize);
297 }
298 EXPECT_EQ(fileSize, 0);
299 }
300
301 /**
302 * @tc.name: UtityTest_GetFileSize1_004
303 * @tc.desc: Enter a null pointer and read the length.
304 * @tc.type: FUNC
305 * @tc.require:
306 */
307 HWTEST_F(UtilityTest, UtityTest_GetFileSize1_004, TestSize.Level1)
308 {
309 CALL_TEST_DEBUG;
310 const char *filePath = nullptr;
311 ssize_t fileSize = Utility::GetFileSize(filePath);
312 if ((fileSize <= 0) || (fileSize > FILE_SIZE_MAX)) {
313 FI_HILOGW("File size out of read range, filseSize: %{public}zd.", fileSize);
314 }
315 EXPECT_EQ(fileSize, 0);
316 }
317
318 /**
319 * @tc.name: UtityTest_GetFileSize2_001
320 * @tc.desc: Enter an existing file and read the length.
321 * @tc.type: FUNC
322 * @tc.require:
323 */
324 HWTEST_F(UtilityTest, UtityTest_GetFileSize2_001, TestSize.Level1)
325 {
326 CALL_TEST_DEBUG;
327 ssize_t fileSize = Utility::GetFileSize(COPY_DRAG_PATH);
328 if ((fileSize <= 0) || (fileSize > FILE_SIZE_MAX)) {
329 FI_HILOGW("File size out of read range, filseSize: %{public}zd.", fileSize);
330 } else {
331 FI_HILOGI("%{public}d: File is %{public}s, and file size is %{public}zd.",
332 __LINE__, COPY_DRAG_PATH.c_str(), fileSize);
333 }
334 EXPECT_GT(fileSize, 0);
335 }
336
337 /**
338 * @tc.name: UtityTest_GetFileSize2_002
339 * @tc.desc: Enter a nonexistent file and read the length.
340 * @tc.type: FUNC
341 * @tc.require:
342 */
343 HWTEST_F(UtilityTest, UtityTest_GetFileSize2_002, TestSize.Level1)
344 {
345 CALL_TEST_DEBUG;
346 std::string filePath = "xxx/not_exist_file.txt";
347 ssize_t fileSize = Utility::GetFileSize(filePath);
348 if ((fileSize <= 0) || (fileSize > FILE_SIZE_MAX)) {
349 FI_HILOGW("File size out of read range, filseSize: %{public}zd.", fileSize);
350 }
351 EXPECT_EQ(fileSize, 0);
352 }
353
354 /**
355 * @tc.name: UtityTest_GetFileSize_003
356 * @tc.desc: Enter an empty string and read the length.
357 * @tc.type: FUNC
358 * @tc.require:
359 */
360 HWTEST_F(UtilityTest, UtityTest_GetFileSize2_003, TestSize.Level1)
361 {
362 CALL_TEST_DEBUG;
363 std::string filePath = "";
364 ssize_t fileSize = Utility::GetFileSize(filePath);
365 if ((fileSize <= 0) || (fileSize > FILE_SIZE_MAX)) {
366 FI_HILOGW("File size out of read range, filseSize: %{public}zd.", fileSize);
367 }
368 EXPECT_EQ(fileSize, 0);
369 }
370
371 /**
372 * @tc.name: UtityTest_Anonymize1_001
373 * @tc.desc: Enter a normal 12-string network ID, anonymising the middle part to 6 '*' in addition to the first
374 * and last 4 characters.
375 * @tc.type: FUNC
376 * @tc.require:
377 */
378 HWTEST_F(UtilityTest, UtityTest_Anonymize1_001, TestSize.Level1)
379 {
380 CALL_TEST_DEBUG;
381 FI_HILOGI("%{public}d: Before anonymous processing, it is %{public}s, and after processing, it is %{public}s.",
382 __LINE__, NETWORK_ID.c_str(), Utility::Anonymize(NETWORK_ID).c_str());
383 bool isEqual = Utility::IsEqual(EXPECT_ID.c_str(), Utility::Anonymize(NETWORK_ID).c_str());
384 ASSERT_TRUE(isEqual);
385 }
386
387 /**
388 * @tc.name: UtityTest_Anonymize1_002
389 * @tc.desc: Enter an empty network ID string, anonymized by 6 digits.
390 * @tc.type: FUNC
391 * @tc.require:
392 */
393 HWTEST_F(UtilityTest, UtityTest_Anonymize1_002, TestSize.Level1)
394 {
395 CALL_TEST_DEBUG;
396 const char *id = "";
397 FI_HILOGI("%{public}d: Before anonymous processing, it is %{public}s, and after processing, it is %{public}s.",
398 __LINE__, id, Utility::Anonymize(id).c_str());
399 bool isEqual = Utility::IsEqual("**********", Utility::Anonymize(id).c_str());
400 ASSERT_TRUE(isEqual);
401 }
402
403 /**
404 * @tc.name: UtityTest_Anonymize1_003
405 * @tc.desc: Enter a network ID string less than 12 in length, anonymized to 6 *.
406 * @tc.type: FUNC
407 * @tc.require:
408 */
409 HWTEST_F(UtilityTest, UtityTest_Anonymize1_003, TestSize.Level1)
410 {
411 CALL_TEST_DEBUG;
412 const char *id = "abcd123456";
413 FI_HILOGI("%{public}d: Before anonymous processing, it is %{public}s, and after processing, it is %{public}s.",
414 __LINE__, id, Utility::Anonymize(id).c_str());
415 bool isEqual = Utility::IsEqual("abcd1*****23456", Utility::Anonymize(id).c_str());
416 ASSERT_TRUE(isEqual);
417 }
418
419 /**
420 * @tc.name: UtityTest_Anonymize1_004
421 * @tc.desc: Anonymisation of strings longer than 32 characters
422 * @tc.type: FUNC
423 * @tc.require:
424 */
425 HWTEST_F(UtilityTest, UtityTest_Anonymize1_004, TestSize.Level1)
426 {
427 CALL_TEST_DEBUG;
428 const char *id = "abcd123456efghijklmnopqrstuvwxyzabcd";
429 FI_HILOGI("%{public}d: Before anonymous processing, it is %{public}s, and after processing, it is %{public}s.",
430 __LINE__, id, Utility::Anonymize(id).c_str());
431 bool isEqual = Utility::IsEqual("abcd1*****zabcd", Utility::Anonymize(id).c_str());
432 ASSERT_TRUE(isEqual);
433 }
434
435 /**
436 * @tc.name: UtityTest_Anonymize1_005
437 * @tc.desc: Enter null pointer network ID, anonymized to 6 '*'.
438 * @tc.type: FUNC
439 * @tc.require:
440 */
441 HWTEST_F(UtilityTest, UtityTest_Anonymize1_005, TestSize.Level1)
442 {
443 CALL_TEST_DEBUG;
444 const char *id = nullptr;
445 FI_HILOGI("%{public}d: Before anonymous processing, it is %{public}s, and after processing, it is %{public}s.",
446 __LINE__, id, Utility::Anonymize(id).c_str());
447 bool isEqual = Utility::IsEqual("**********", Utility::Anonymize(id).c_str());
448 ASSERT_TRUE(isEqual);
449 }
450
451 /**
452 * @tc.name: UtityTest_Anonymize2_001
453 * @tc.desc: Enter a normal 12-string network ID, anonymising the middle part to 6 '*' in addition to the first
454 * and last 4 characters.
455 * @tc.type: FUNC
456 * @tc.require:
457 */
458 HWTEST_F(UtilityTest, UtityTest_Anonymize2_001, TestSize.Level1)
459 {
460 CALL_TEST_DEBUG;
461 FI_HILOGI("%{public}d: Before anonymous processing, it is %{public}s, and after processing, it is %{public}s.",
462 __LINE__, NETWORK_ID.c_str(), Utility::Anonymize(NETWORK_ID).c_str());
463 bool isEqual = Utility::IsEqual(EXPECT_ID.c_str(), Utility::Anonymize(NETWORK_ID).c_str());
464 ASSERT_TRUE(isEqual);
465 }
466
467 /**
468 * @tc.name: UtityTest_Anonymize2_002
469 * @tc.desc: Enter an empty network ID string, anonymized by 6 digits.
470 * @tc.type: FUNC
471 * @tc.require:
472 */
473 HWTEST_F(UtilityTest, UtityTest_Anonymize2_002, TestSize.Level1)
474 {
475 CALL_TEST_DEBUG;
476 std::string id = "";
477 FI_HILOGI("%{public}d: Before anonymous processing, it is %{public}s, and after processing, it is %{public}s.",
478 __LINE__, id.c_str(), Utility::Anonymize(id).c_str());
479 bool isEqual = Utility::IsEqual("**********", Utility::Anonymize(id).c_str());
480 ASSERT_TRUE(isEqual);
481 }
482
483 /**
484 * @tc.name: UtityTest_Anonymize2_003
485 * @tc.desc: Enter a network ID string less than 12 in length, anonymized to 6 *.
486 * @tc.type: FUNC
487 * @tc.require:
488 */
489 HWTEST_F(UtilityTest, UtityTest_Anonymize2_003, TestSize.Level1)
490 {
491 CALL_TEST_DEBUG;
492 std::string id = "abcd123456";
493 FI_HILOGI("%{public}d: Before anonymous processing, it is %{public}s, and after processing, it is %{public}s.",
494 __LINE__, id.c_str(), Utility::Anonymize(id).c_str());
495 bool isEqual = Utility::IsEqual("abcd1*****23456", Utility::Anonymize(id).c_str());
496 ASSERT_TRUE(isEqual);
497 }
498
499 /**
500 * @tc.name: UtityTest_Anonymize2_004
501 * @tc.desc: Anonymisation of strings longer than 32 characters.
502 * @tc.type: FUNC
503 * @tc.require:
504 */
505 HWTEST_F(UtilityTest, UtityTest_Anonymize2_004, TestSize.Level1)
506 {
507 CALL_TEST_DEBUG;
508 std::string id = "abcd123456efghijklmnopqrstuvwxyzabcd";
509 FI_HILOGI("%{public}d: Before anonymous processing, it is %{public}s, and after processing, it is %{public}s.",
510 __LINE__, id.c_str(), Utility::Anonymize(id).c_str());
511 bool isEqual = Utility::IsEqual("abcd1*****zabcd", Utility::Anonymize(id).c_str());
512 ASSERT_TRUE(isEqual);
513 }
514
515 /**
516 * @tc.name: UtityTest_DoesFileExist_001
517 * @tc.desc: Check the file is or not exist
518 * @tc.type: FUNC
519 * @tc.require:
520 */
521 HWTEST_F(UtilityTest, UtityTest_DoesFileExist_001, TestSize.Level1)
522 {
523 CALL_TEST_DEBUG;
524 const char *filePath = "/system/etc/device_status/drag_icon/Copy_Drag.svg";
525 bool isExist = Utility::DoesFileExist(filePath);
526 ASSERT_TRUE(isExist);
527 }
528
529 /**
530 * @tc.name: UtityTest_DoesFileExist_002
531 * @tc.desc: Check the file is or not exist
532 * @tc.type: FUNC
533 * @tc.require:
534 */
535 HWTEST_F(UtilityTest, UtityTest_DoesFileExist_002, TestSize.Level1)
536 {
537 CALL_TEST_DEBUG;
538 const char *filePath = "";
539 bool isExist = Utility::DoesFileExist(filePath);
540 ASSERT_FALSE(isExist);
541 }
542
543 /**
544 * @tc.name: UtityTest_DoesFileExist_003
545 * @tc.desc: Check the file is or not exist
546 * @tc.type: FUNC
547 * @tc.require:
548 */
549 HWTEST_F(UtilityTest, UtityTest_DoesFileExist_003, TestSize.Level1)
550 {
551 CALL_TEST_DEBUG;
552 const char *filePath = "xxx/not_exist_file.txt";
553 bool isExist = Utility::DoesFileExist(filePath);
554 ASSERT_FALSE(isExist);
555 }
556
557 /**
558 * @tc.name: UtityTest_DoesFileExist_004
559 * @tc.desc: Check the file is or not exist
560 * @tc.type: FUNC
561 * @tc.require:
562 */
563 HWTEST_F(UtilityTest, UtityTest_DoesFileExist_004, TestSize.Level1)
564 {
565 CALL_TEST_DEBUG;
566 const char *filePath = nullptr;
567 bool isExist = Utility::DoesFileExist(filePath);
568 ASSERT_FALSE(isExist);
569 }
570
571 /**
572 * @tc.name: UtityTest_IsEmpty_001
573 * @tc.desc: Check string is or not empty
574 * @tc.type: FUNC
575 * @tc.require:
576 */
577 HWTEST_F(UtilityTest, UtityTest_IsEmpty_001, TestSize.Level1)
578 {
579 CALL_TEST_DEBUG;
580 const char *str = "isempty";
581 bool isEmpty = Utility::IsEmpty(str);
582 ASSERT_FALSE(isEmpty);
583 }
584
585 /**
586 * @tc.name: UtityTest_IsEmpty_002
587 * @tc.desc: Check string is or not empty
588 * @tc.type: FUNC
589 * @tc.require:
590 */
591 HWTEST_F(UtilityTest, UtityTest_IsEmpty_002, TestSize.Level1)
592 {
593 CALL_TEST_DEBUG;
594 const char *str = "";
595 bool isEmpty = Utility::IsEmpty(str);
596 ASSERT_TRUE(isEmpty);
597 }
598
599 /**
600 * @tc.name: UtityTest_IsEmpty_003
601 * @tc.desc: Check string is or not empty
602 * @tc.type: FUNC
603 * @tc.require:
604 */
605 HWTEST_F(UtilityTest, UtityTest_IsEmpty_003, TestSize.Level1)
606 {
607 CALL_TEST_DEBUG;
608 const char *str = nullptr;
609 bool isEmpty = Utility::IsEmpty(str);
610 ASSERT_TRUE(isEmpty);
611 }
612
613 /**
614 * @tc.name: UtityTest_IsEqual_001
615 * @tc.desc: Check string is or not equal
616 * @tc.type: FUNC
617 * @tc.require:
618 */
619 HWTEST_F(UtilityTest, UtityTest_IsEqual_001, TestSize.Level1)
620 {
621 CALL_TEST_DEBUG;
622 const char *str1 = "abcde";
623 const char *str2 = "abcde";
624 bool isEqual = Utility::IsEqual(str1, str2);
625 ASSERT_TRUE(isEqual);
626 }
627
628 /**
629 * @tc.name: UtityTest_IsEqual_002
630 * @tc.desc: Check string is or not equal
631 * @tc.type: FUNC
632 * @tc.require:
633 */
634 HWTEST_F(UtilityTest, UtityTest_IsEqual_002, TestSize.Level1)
635 {
636 CALL_TEST_DEBUG;
637 const char *str1 = "abcde";
638 const char *str2 = "edcba";
639 bool isEqual = Utility::IsEqual(str1, str2);
640 ASSERT_FALSE(isEqual);
641 }
642
643 /**
644 * @tc.name: UtityTest_IsEqual_003
645 * @tc.desc: Check string is or not equal
646 * @tc.type: FUNC
647 * @tc.require:
648 */
649 HWTEST_F(UtilityTest, UtityTest_IsEqual_003, TestSize.Level1)
650 {
651 CALL_TEST_DEBUG;
652 const char *str1 = "";
653 const char *str2 = "";
654 bool isEqual = Utility::IsEqual(str1, str2);
655 ASSERT_TRUE(isEqual);
656 }
657
658 /**
659 * @tc.name: UtityTest_IsEqual_004
660 * @tc.desc: Check string is or not equal
661 * @tc.type: FUNC
662 * @tc.require:
663 */
664 HWTEST_F(UtilityTest, UtityTest_IsEqual_004, TestSize.Level1)
665 {
666 CALL_TEST_DEBUG;
667 const char *str1 = "abcde";
668 const char *str2 = "";
669 bool isEqual = Utility::IsEqual(str1, str2);
670 ASSERT_FALSE(isEqual);
671 }
672
673 /**
674 * @tc.name: UtityTest_IsEqual_005
675 * @tc.desc: Check string is or not equal
676 * @tc.type: FUNC
677 * @tc.require:
678 */
679 HWTEST_F(UtilityTest, UtityTest_IsEqual_005, TestSize.Level1)
680 {
681 CALL_TEST_DEBUG;
682 const char *str1 = "";
683 const char *str2 = nullptr;
684 bool isEqual = Utility::IsEqual(str1, str2);
685 ASSERT_TRUE(isEqual);
686 }
687
688 /**
689 * @tc.name: UtityTest_IsEqual_006
690 * @tc.desc: Check string is or not equal
691 * @tc.type: FUNC
692 * @tc.require:
693 */
694 HWTEST_F(UtilityTest, UtityTest_IsEqual_006, TestSize.Level1)
695 {
696 CALL_TEST_DEBUG;
697 const char *str1 = nullptr;
698 const char *str2 = nullptr;
699 bool isEqual = Utility::IsEqual(str1, str2);
700 ASSERT_TRUE(isEqual);
701 }
702
703 /**
704 * @tc.name: UtityTest_IsEqual_007
705 * @tc.desc: Check string is or not equal
706 * @tc.type: FUNC
707 * @tc.require:
708 */
709 HWTEST_F(UtilityTest, UtityTest_IsEqual_007, TestSize.Level1)
710 {
711 CALL_TEST_DEBUG;
712 const char *str1 = "abcde";
713 const char *str2 = nullptr;
714 bool isEqual = Utility::IsEqual(str1, str2);
715 ASSERT_FALSE(isEqual);
716 }
717
718 /**
719 * @tc.name: UtityTest_ConcatAsString_001
720 * @tc.desc: Splicing strings
721 * @tc.type: FUNC
722 * @tc.require:
723 */
724 HWTEST_F(UtilityTest, UtityTest_ConcatAsString_001, TestSize.Level1)
725 {
726 CALL_TEST_DEBUG;
727 std::string str1 = "abcde";
728 std::string str = Utility::ConcatAsString(str1);
729 EXPECT_STREQ(str.c_str(), str1.c_str());
730 }
731
732 /**
733 * @tc.name: UtityTest_ConcatAsString_002
734 * @tc.desc: Splicing strings
735 * @tc.type: FUNC
736 * @tc.require:
737 */
738 HWTEST_F(UtilityTest, UtityTest_ConcatAsString_002, TestSize.Level1)
739 {
740 CALL_TEST_DEBUG;
741 std::string str1 = "abcde";
742 std::string str2 = "fghij";
743 std::string str = Utility::ConcatAsString(str1, str2);
744 EXPECT_STREQ(str.c_str(), "abcdefghij");
745 }
746
747 /**
748 * @tc.name: UtityTest_ConcatAsString_003
749 * @tc.desc: Splicing strings
750 * @tc.type: FUNC
751 * @tc.require:
752 */
753 HWTEST_F(UtilityTest, UtityTest_ConcatAsString_003, TestSize.Level1)
754 {
755 CALL_TEST_DEBUG;
756 std::string str1 = "abcde";
757 std::string str2 = "fghij";
758 std::string str3 = "klmno";
759 std::string str = Utility::ConcatAsString(str1, str2, str3);
760 EXPECT_STREQ(str.c_str(), "abcdefghijklmno");
761 }
762
763 /**
764 * @tc.name: UtityTest_ConcatAsString_004
765 * @tc.desc: Splicing strings
766 * @tc.type: FUNC
767 * @tc.require:
768 */
769 HWTEST_F(UtilityTest, UtityTest_ConcatAsString_004, TestSize.Level1)
770 {
771 CALL_TEST_DEBUG;
772 std::string str1 = "abcde";
773 std::string str2 = "fghij";
774 std::string str3 = "";
775 std::string str = Utility::ConcatAsString(str1, str2, str3);
776 EXPECT_STREQ(str.c_str(), "abcdefghij");
777 }
778
779 /**
780 * @tc.name: UtityTest_RemoveSpace_001
781 * @tc.desc: Remove string space
782 * @tc.type: FUNC
783 * @tc.require:
784 */
785 HWTEST_F(UtilityTest, UtityTest_RemoveSpace_001, TestSize.Level1)
786 {
787 CALL_TEST_DEBUG;
788 std::string str = "abc de";
789 Utility::RemoveSpace(str);
790 EXPECT_STREQ(str.c_str(), "abcde");
791 }
792
793 /**
794 * @tc.name: UtityTest_RemoveSpace_002
795 * @tc.desc: Remove string space
796 * @tc.type: FUNC
797 * @tc.require:
798 */
799 HWTEST_F(UtilityTest, UtityTest_RemoveSpace_002, TestSize.Level1)
800 {
801 CALL_TEST_DEBUG;
802 std::string str = "abcde";
803 Utility::RemoveSpace(str);
804 EXPECT_STREQ(str.c_str(), "abcde");
805 }
806
807 /**
808 * @tc.name: UtityTest_RemoveSpace_003
809 * @tc.desc: Remove string space
810 * @tc.type: FUNC
811 * @tc.require:
812 */
813 HWTEST_F(UtilityTest, UtityTest_RemoveSpace_003, TestSize.Level1)
814 {
815 CALL_TEST_DEBUG;
816 std::string str = " abcde";
817 Utility::RemoveSpace(str);
818 EXPECT_STREQ(str.c_str(), "abcde");
819 }
820
821 /**
822 * @tc.name: UtityTest_RemoveSpace_004
823 * @tc.desc: Remove string space
824 * @tc.type: FUNC
825 * @tc.require:
826 */
827 HWTEST_F(UtilityTest, UtityTest_RemoveSpace_004, TestSize.Level1)
828 {
829 CALL_TEST_DEBUG;
830 std::string str = "abcde ";
831 Utility::RemoveSpace(str);
832 EXPECT_STREQ(str.c_str(), "abcde");
833 }
834
835 /**
836 * @tc.name: UtityTest_RemoveSpace_005
837 * @tc.desc: Remove string space
838 * @tc.type: FUNC
839 * @tc.require:
840 */
841 HWTEST_F(UtilityTest, UtityTest_RemoveSpace_005, TestSize.Level1)
842 {
843 CALL_TEST_DEBUG;
844 std::string str = " ";
845 Utility::RemoveSpace(str);
846 EXPECT_STREQ(str.c_str(), "");
847 }
848
849 /**
850 * @tc.name: UtityTest_CopyNulstr_001
851 * @tc.desc: Copy string to target
852 * @tc.type: FUNC
853 * @tc.require:
854 */
855 HWTEST_F(UtilityTest, UtityTest_CopyNulstr_001, TestSize.Level1)
856 {
857 CALL_TEST_DEBUG;
858 char dest[] = "0";
859 size_t size = SIZE1;
860 char src[] = "abcdefghijklmnopqrst";
861 size_t len = Utility::CopyNulstr(dest, size, src);
862 EXPECT_EQ(len, size - 1);
863 }
864
865 /**
866 * @tc.name: UtityTest_CopyNulstr_002
867 * @tc.desc: Copy string to target
868 * @tc.type: FUNC
869 * @tc.require:
870 */
871 HWTEST_F(UtilityTest, UtityTest_CopyNulstr_002, TestSize.Level1)
872 {
873 CALL_TEST_DEBUG;
874 char *dest = nullptr;
875 size_t size = SIZE2;
876 char *src = nullptr;
877 size_t len = Utility::CopyNulstr(dest, size, src);
878 EXPECT_EQ(len, 0);
879 }
880
881 /**
882 * @tc.name: UtityTest_CopyNulstr_003
883 * @tc.desc: Copy string to target
884 * @tc.type: FUNC
885 * @tc.require:
886 */
887 HWTEST_F(UtilityTest, UtityTest_CopyNulstr_003, TestSize.Level1)
888 {
889 CALL_TEST_DEBUG;
890 char dest[] = {0};
891 size_t size = SIZE2;
892 char *src = nullptr;
893 size_t len = Utility::CopyNulstr(dest, size, src);
894 EXPECT_EQ(len, 0);
895 }
896
897 /**
898 * @tc.name: UtityTest_CopyNulstr_004
899 * @tc.desc: Copy string to target
900 * @tc.type: FUNC
901 * @tc.require:
902 */
903 HWTEST_F(UtilityTest, UtityTest_CopyNulstr_004, TestSize.Level1)
904 {
905 CALL_TEST_DEBUG;
906 char *dest = nullptr;
907 size_t size = SIZE2;
908 char src[] = "dadaaaaaaaddsadada";
909 size_t len = Utility::CopyNulstr(dest, size, src);
910 EXPECT_EQ(len, 0);
911 }
912
913 /**
914 * @tc.name: UtityTest_GetSysClockTime_001
915 * @tc.desc: Get system time
916 * @tc.type: FUNC
917 * @tc.require:
918 */
919 HWTEST_F(UtilityTest, UtityTest_GetSysClockTime_001, TestSize.Level1)
920 {
921 CALL_TEST_DEBUG;
922 int64_t time = Utility::GetSysClockTime();
923 EXPECT_NE(time, 0);
924 }
925
926 /**
927 * @tc.name: UtityTest_StartWith1_001
928 * @tc.desc:
929 * @tc.type: FUNC
930 * @tc.require:
931 */
932 HWTEST_F(UtilityTest, UtityTest_StartWith1_001, TestSize.Level1)
933 {
934 CALL_TEST_DEBUG;
935 const char *exampleStr = "HelloWorld";
936 const char *examplePrefix = "Hello";
937 bool ret = Utility::StartWith(exampleStr, examplePrefix);
938 ASSERT_TRUE(ret);
939 }
940
941 /**
942 * @tc.name: UtityTest_StartWith1_002
943 * @tc.desc:
944 * @tc.type: FUNC
945 * @tc.require:
946 */
947 HWTEST_F(UtilityTest, UtityTest_StartWith1_002, TestSize.Level1)
948 {
949 CALL_TEST_DEBUG;
950 const char *exampleStr = "HelloWorld";
951 const char *examplePrefix = "HelloWorld";
952 bool ret = Utility::StartWith(exampleStr, examplePrefix);
953 ASSERT_TRUE(ret);
954 }
955
956 /**
957 * @tc.name: UtityTest_StartWith1_003
958 * @tc.desc:
959 * @tc.type: FUNC
960 * @tc.require:
961 */
962 HWTEST_F(UtilityTest, UtityTest_StartWith1_003, TestSize.Level1)
963 {
964 CALL_TEST_DEBUG;
965 const char *exampleStr = "HelloWorld";
966 const char *examplePrefix = "";
967 bool ret = Utility::StartWith(exampleStr, examplePrefix);
968 ASSERT_FALSE(ret);
969 }
970
971 /**
972 * @tc.name: UtityTest_StartWith1_004
973 * @tc.desc:
974 * @tc.type: FUNC
975 * @tc.require:
976 */
977 HWTEST_F(UtilityTest, UtityTest_StartWith1_004, TestSize.Level1)
978 {
979 CALL_TEST_DEBUG;
980 const char *exampleStr = "Hello";
981 const char *examplePrefix = "HelloWorld";
982 bool ret = Utility::StartWith(exampleStr, examplePrefix);
983 ASSERT_FALSE(ret);
984 }
985
986 /**
987 * @tc.name: UtityTest_StartWith1_005
988 * @tc.desc:
989 * @tc.type: FUNC
990 * @tc.require:
991 */
992 HWTEST_F(UtilityTest, UtityTest_StartWith1_005, TestSize.Level1)
993 {
994 CALL_TEST_DEBUG;
995 const char *exampleStr = "";
996 const char *examplePrefix = "HelloWorld";
997 bool ret = Utility::StartWith(exampleStr, examplePrefix);
998 ASSERT_FALSE(ret);
999 }
1000
1001 /**
1002 * @tc.name: UtityTest_StartWith1_006
1003 * @tc.desc:
1004 * @tc.type: FUNC
1005 * @tc.require:
1006 */
1007 HWTEST_F(UtilityTest, UtityTest_StartWith1_006, TestSize.Level1)
1008 {
1009 CALL_TEST_DEBUG;
1010 const char *exampleStr = "";
1011 const char *examplePrefix = "";
1012 bool ret = Utility::StartWith(exampleStr, examplePrefix);
1013 ASSERT_FALSE(ret);
1014 }
1015
1016 /**
1017 * @tc.name: UtityTest_StartWith2_001
1018 * @tc.desc:
1019 * @tc.type: FUNC
1020 * @tc.require:
1021 */
1022 HWTEST_F(UtilityTest, UtityTest_StartWith2_001, TestSize.Level1)
1023 {
1024 CALL_TEST_DEBUG;
1025 std::string exampleStr = "abc12345";
1026 std::string examplePrefix = "abc";
1027 bool ret = Utility::StartWith(exampleStr, examplePrefix);
1028 ASSERT_TRUE(ret);
1029 }
1030
1031 /**
1032 * @tc.name: UtityTest_StartWith2_002
1033 * @tc.desc:
1034 * @tc.type: FUNC
1035 * @tc.require:
1036 */
1037 HWTEST_F(UtilityTest, UtityTest_StartWith2_002, TestSize.Level1)
1038 {
1039 CALL_TEST_DEBUG;
1040 std::string exampleStr = "abc";
1041 std::string examplePrefix = "abc";
1042 bool ret = Utility::StartWith(exampleStr, examplePrefix);
1043 ASSERT_TRUE(ret);
1044 }
1045
1046 /**
1047 * @tc.name: UtityTest_StartWith2_003
1048 * @tc.desc:
1049 * @tc.type: FUNC
1050 * @tc.require:
1051 */
1052 HWTEST_F(UtilityTest, UtityTest_StartWith2_003, TestSize.Level1)
1053 {
1054 CALL_TEST_DEBUG;
1055 std::string exampleStr = "abc12345";
1056 std::string examplePrefix = "";
1057 bool ret = Utility::StartWith(exampleStr, examplePrefix);
1058 ASSERT_TRUE(ret);
1059 }
1060
1061 /**
1062 * @tc.name: UtityTest_StartWith2_004
1063 * @tc.desc:
1064 * @tc.type: FUNC
1065 * @tc.require:
1066 */
1067 HWTEST_F(UtilityTest, UtityTest_StartWith2_004, TestSize.Level1)
1068 {
1069 CALL_TEST_DEBUG;
1070 std::string exampleStr = "abc";
1071 std::string examplePrefix = "abcdefg";
1072 bool ret = Utility::StartWith(exampleStr, examplePrefix);
1073 ASSERT_FALSE(ret);
1074 }
1075
1076 /**
1077 * @tc.name: UtityTest_StartWith2_005
1078 * @tc.desc:
1079 * @tc.type: FUNC
1080 * @tc.require:
1081 */
1082 HWTEST_F(UtilityTest, UtityTest_StartWith2_005, TestSize.Level1)
1083 {
1084 CALL_TEST_DEBUG;
1085 std::string exampleStr = "";
1086 std::string examplePrefix = "abc";
1087 bool ret = Utility::StartWith(exampleStr, examplePrefix);
1088 ASSERT_FALSE(ret);
1089 }
1090
1091 /**
1092 * @tc.name: UtityTest_StartWith2_006
1093 * @tc.desc:
1094 * @tc.type: FUNC
1095 * @tc.require:
1096 */
1097 HWTEST_F(UtilityTest, UtityTest_StartWith2_006, TestSize.Level1)
1098 {
1099 CALL_TEST_DEBUG;
1100 std::string exampleStr = "";
1101 std::string examplePrefix = "";
1102 bool ret = Utility::StartWith(exampleStr, examplePrefix);
1103 ASSERT_TRUE(ret);
1104 }
1105
1106 /**
1107 * @tc.name: UtityTest_RemoveTrailingChars1_001
1108 * @tc.desc:
1109 * @tc.type: FUNC
1110 * @tc.require:
1111 */
1112 HWTEST_F(UtilityTest, UtityTest_RemoveTrailingChars1_001, TestSize.Level1)
1113 {
1114 CALL_TEST_DEBUG;
1115 char path2[] = "abcd";
1116 Utility::RemoveTrailingChars('d', path2);
1117 ASSERT_STREQ(path2, "abc");
1118 }
1119
1120 /**
1121 * @tc.name: UtityTest_RemoveTrailingChars1_002
1122 * @tc.desc:
1123 * @tc.type: FUNC
1124 * @tc.require:
1125 */
1126 HWTEST_F(UtilityTest, UtityTest_RemoveTrailingChars1_002, TestSize.Level1)
1127 {
1128 CALL_TEST_DEBUG;
1129 char path2[] = "abcd";
1130 Utility::RemoveTrailingChars('d', path2);
1131 ASSERT_STREQ(path2, "abc");
1132 }
1133
1134 /**
1135 * @tc.name: UtityTest_RemoveTrailingChars1_003
1136 * @tc.desc:
1137 * @tc.type: FUNC
1138 * @tc.require:
1139 */
1140 HWTEST_F(UtilityTest, UtityTest_RemoveTrailingChars1_003, TestSize.Level1)
1141 {
1142 CALL_TEST_DEBUG;
1143 char path2[] = "abacda";
1144 Utility::RemoveTrailingChars('a', path2);
1145 ASSERT_STREQ(path2, "abacd");
1146 }
1147
1148 /**
1149 * @tc.name: UtityTest_RemoveTrailingChars1_004
1150 * @tc.desc:
1151 * @tc.type: FUNC
1152 * @tc.require:
1153 */
1154 HWTEST_F(UtilityTest, UtityTest_RemoveTrailingChars1_004, TestSize.Level1)
1155 {
1156 CALL_TEST_DEBUG;
1157 char path2[] = "abacda";
1158 Utility::RemoveTrailingChars('f', path2);
1159 ASSERT_STREQ(path2, "abacda");
1160 }
1161
1162 /**
1163 * @tc.name: UtityTest_RemoveTrailingChars1_005
1164 * @tc.desc:
1165 * @tc.type: FUNC
1166 * @tc.require:
1167 */
1168 HWTEST_F(UtilityTest, UtityTest_RemoveTrailingChars1_005, TestSize.Level1)
1169 {
1170 CALL_TEST_DEBUG;
1171 char path2[] = "";
1172 Utility::RemoveTrailingChars('f', path2);
1173 ASSERT_STREQ(path2, "");
1174 }
1175
1176 /**
1177 * @tc.name: UtityTest_RemoveTrailingChars2_001
1178 * @tc.desc:
1179 * @tc.type: FUNC
1180 * @tc.require:
1181 */
1182 HWTEST_F(UtilityTest, UtityTest_RemoveTrailingChars2_001, TestSize.Level1)
1183 {
1184 CALL_TEST_DEBUG;
1185 const std::string path1 = "cd";
1186 std::string path2 = "abcd";
1187 Utility::RemoveTrailingChars(path1, path2);
1188 ASSERT_STREQ(path2.c_str(), "ab");
1189 }
1190
1191 /**
1192 * @tc.name: UtityTest_RemoveTrailingChars2_002
1193 * @tc.desc:
1194 * @tc.type: FUNC
1195 * @tc.require:
1196 */
1197 HWTEST_F(UtilityTest, UtityTest_RemoveTrailingChars2_002, TestSize.Level1)
1198 {
1199 CALL_TEST_DEBUG;
1200 const std::string path1 = "c";
1201 std::string path2 = "abdc";
1202 Utility::RemoveTrailingChars(path1, path2);
1203 ASSERT_STREQ(path2.c_str(), "abd");
1204 }
1205
1206
1207 /**
1208 * @tc.name: UtityTest_RemoveTrailingChars2_003
1209 * @tc.desc:
1210 * @tc.type: FUNC
1211 * @tc.require:
1212 */
1213 HWTEST_F(UtilityTest, UtityTest_RemoveTrailingChars2_003, TestSize.Level1)
1214 {
1215 CALL_TEST_DEBUG;
1216 const std::string path1 = "a";
1217 std::string path2 = "abacda";
1218 Utility::RemoveTrailingChars(path1, path2);
1219 ASSERT_STREQ(path2.c_str(), "abacd");
1220 }
1221
1222 /**
1223 * @tc.name: UtityTest_RemoveTrailingChars2_004
1224 * @tc.desc:
1225 * @tc.type: FUNC
1226 * @tc.require:
1227 */
1228 HWTEST_F(UtilityTest, UtityTest_RemoveTrailingChars2_004, TestSize.Level1)
1229 {
1230 CALL_TEST_DEBUG;
1231 const std::string path1 = "e";
1232 std::string path2 = "abc";
1233 Utility::RemoveTrailingChars(path1, path2);
1234 ASSERT_STREQ(path2.c_str(), "abc");
1235 }
1236
1237 /**
1238 * @tc.name: UtityTest_RemoveTrailingChars2_005
1239 * @tc.desc:
1240 * @tc.type: FUNC
1241 * @tc.require:
1242 */
1243 HWTEST_F(UtilityTest, UtityTest_RemoveTrailingChars2_005, TestSize.Level1)
1244 {
1245 CALL_TEST_DEBUG;
1246 const std::string path1 = "";
1247 std::string path2 = "abc";
1248 Utility::RemoveTrailingChars(path1, path2);
1249 ASSERT_STREQ(path2.c_str(), "abc");
1250 }
1251 } // namespace DeviceStatus
1252 } // namespace Msdp
1253 } // namespace OHOS
1254