1 /*
2  * Copyright (c) 2021-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 "utils_tool_test.h"
17 
18 #include <chrono>
19 #include <cstdint>
20 #include <gtest/gtest.h>
21 #include <set>
22 #include <string>
23 #include <thread>
24 
25 #include "anonymous_string.h"
26 #include "dh_utils_tool.h"
27 #include "dh_utils_hitrace.h"
28 
29 using namespace testing::ext;
30 
31 namespace OHOS {
32 namespace DistributedHardware {
33 namespace {
34     constexpr int32_t UUID_LENGTH = 257;
35 }
SetUpTestCase(void)36 void UtilsToolTest::SetUpTestCase(void)
37 {
38 }
39 
TearDownTestCase(void)40 void UtilsToolTest::TearDownTestCase(void)
41 {
42 }
43 
SetUp()44 void UtilsToolTest::SetUp()
45 {
46 }
47 
TearDown()48 void UtilsToolTest::TearDown()
49 {
50 }
51 
52 /**
53  * @tc.name: GetAnonyString_001
54  * @tc.desc: Verify the GetAnonyString function
55  * @tc.type: FUNC
56  * @tc.require: AR000GHSK0
57  */
58 HWTEST_F(UtilsToolTest, GetAnonyString_001, TestSize.Level0)
59 {
60     std::string value = "";
61     auto ret = GetAnonyString(value);
62     EXPECT_EQ("", ret);
63 
64     value = "11";
65     ret = GetAnonyString(value);
66     EXPECT_EQ("******", ret);
67 
68     value = "123456789";
69     ret = GetAnonyString(value);
70     EXPECT_EQ("1******9", ret);
71 
72     value = "111222333444555666777888999";
73     ret = GetAnonyString(value);
74     EXPECT_EQ("1112******8999", ret);
75 }
76 
77 /**
78  * @tc.name: GetAnonyInt32_001
79  * @tc.desc: Verify the GetAnnoyInt32 function
80  * @tc.type: FUNC
81  * @tc.require: AR000GHSK0
82  */
83 HWTEST_F(UtilsToolTest, GetAnonyInt32_001, TestSize.Level0)
84 {
85     int32_t value = 123456;
86     auto ret = GetAnonyInt32(value);
87     EXPECT_EQ("1*****", ret);
88 }
89 
90 /**
91  * @tc.name: GetUUIDByDm_001
92  * @tc.desc: Verify the GetUUIDBySoftBus function
93  * @tc.type: FUNC
94  * @tc.require: AR000GHSK0
95  */
96 HWTEST_F(UtilsToolTest, GetUUIDByDm_001, TestSize.Level0)
97 {
98     std::string networkId = "";
99     std::string ret = GetUUIDByDm(networkId);
100     EXPECT_EQ(0, ret.size());
101 }
102 
103 /**
104  * @tc.name: GetDeviceIdByUUID_001
105  * @tc.desc: Verify the GetDeviceIdByUUID function
106  * @tc.type: FUNC
107  * @tc.require: AR000GHSK0
108  */
109 HWTEST_F(UtilsToolTest, GetDeviceIdByUUID_001, TestSize.Level0)
110 {
111     std::string uuidEmpty = "";
112     std::string ret = GetDeviceIdByUUID(uuidEmpty);
113     EXPECT_EQ(0, ret.size());
114 
115     std::string uuid(UUID_LENGTH, '1');
116     ret = GetDeviceIdByUUID(uuid);
117     EXPECT_EQ(0, ret.size());
118 }
119 
120 /**
121  * @tc.name: GetDeviceIdByUUID_002
122  * @tc.desc: Verify the GetDeviceIdByUUID function
123  * @tc.type: FUNC
124  * @tc.require: AR000GHSK0
125  */
126 HWTEST_F(UtilsToolTest, GetDeviceIdByUUID_002, TestSize.Level0)
127 {
128     DHType dhType = DHType::CAMERA;
129     DHQueryTraceStart(dhType);
130 
131     std::string uuid = "bb536a637105409e904d4da78290ab1";
132     std::string ret = GetDeviceIdByUUID(uuid);
133     EXPECT_NE(0, ret.size());
134 }
135 } // namespace DistributedHardware
136 } // namespace OHOS
137