1 /*
2 * Copyright (c) 2024-2025 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 "UTTest_dm_distributed_hardware_load.h"
17
18 #include <iostream>
19
20 #include "dm_log.h"
21 #include "dm_constants.h"
22
23 namespace OHOS {
24 namespace DistributedHardware {
SetUp()25 void DmDistributedHardwareLoadTest::SetUp() {}
26
TearDown()27 void DmDistributedHardwareLoadTest::TearDown() {}
28
SetUpTestCase()29 void DmDistributedHardwareLoadTest::SetUpTestCase() {}
30
TearDownTestCase()31 void DmDistributedHardwareLoadTest::TearDownTestCase() {}
32
33 HWTEST_F(DmDistributedHardwareLoadTest, LoadDistributedHardwareFwk_001, testing::ext::TestSize.Level0)
34 {
35 DmDistributedHardwareLoad::GetInstance().LoadDistributedHardwareFwk();
36 DmDistributedHardwareLoad::GetInstance().InitDistributedHardwareLoadCount();
37 uint32_t ret = DmDistributedHardwareLoad::GetInstance().GetDistributedHardwareLoadCount();
38 EXPECT_EQ(ret, DM_OK);
39 }
40
41 HWTEST_F(DmDistributedHardwareLoadTest, InitDistributedHardwareLoadCount_001, testing::ext::TestSize.Level0)
42 {
43 DmDistributedHardwareLoad::GetInstance().InitDistributedHardwareLoadCount();
44 uint32_t ret = DmDistributedHardwareLoad::GetInstance().distributedHardwareLoadCount_;
45 EXPECT_EQ(ret, DM_OK);
46 }
47
48 HWTEST_F(DmDistributedHardwareLoadTest, GetDistributedHardwareLoadCount_001, testing::ext::TestSize.Level0)
49 {
50 DmDistributedHardwareLoad::GetInstance().GetDistributedHardwareLoadCount();
51 uint32_t ret = DmDistributedHardwareLoad::GetInstance().distributedHardwareLoadCount_;
52 EXPECT_EQ(ret, DM_OK);
53 }
54
55 HWTEST_F(DmDistributedHardwareLoadTest, OnLoadSystemAbilitySuccess_001, testing::ext::TestSize.Level0)
56 {
57 int32_t systemAbilityId = 4800;
58 sptr<IRemoteObject> remoteObject = nullptr;
59 sptr<DistributedHardwareLoadCallback> distributedHardwareLoadCallback_(new DistributedHardwareLoadCallback());
60 distributedHardwareLoadCallback_->OnLoadSystemAbilitySuccess(systemAbilityId, remoteObject);
61 uint32_t ret = DmDistributedHardwareLoad::GetInstance().distributedHardwareLoadCount_;
62 EXPECT_EQ(ret, DM_OK);
63 }
64
65 HWTEST_F(DmDistributedHardwareLoadTest, Sha256_001, testing::ext::TestSize.Level0)
66 {
67 std::shared_ptr<Crypto> crypto = std::make_shared<Crypto>();
68 std::string text;
69 bool isUpper = false;
70 std::string ret = crypto->Sha256(text, isUpper);
71 EXPECT_NE(ret.empty(), true);
72 }
73
74 HWTEST_F(DmDistributedHardwareLoadTest, GetCryptoAdapter_001, testing::ext::TestSize.Level0)
75 {
76 std::string soName = "soName";
77 auto ret = DmAdapterManager::GetInstance().GetCryptoAdapter(soName);
78 EXPECT_EQ(ret, nullptr);
79 }
80
81 HWTEST_F(DmDistributedHardwareLoadTest, GetUdidHash_001, testing::ext::TestSize.Level0)
82 {
83 std::string deviceId;
84 char deviceIdHash[DM_MAX_DEVICE_ID_LEN] = {0};
85 auto ret = Crypto::GetUdidHash(deviceId, reinterpret_cast<uint8_t *>(deviceIdHash));
86 EXPECT_EQ(ret, DM_OK);
87 }
88
89 HWTEST_F(DmDistributedHardwareLoadTest, GetUdidHash_002, testing::ext::TestSize.Level0)
90 {
91 std::string deviceId;
92 unsigned char *udidHash = nullptr;
93 auto ret = Crypto::GetUdidHash(deviceId, udidHash);
94 EXPECT_EQ(ret, ERR_DM_FAILED);
95 }
96
97 HWTEST_F(DmDistributedHardwareLoadTest, GetGroupIdHash_001, testing::ext::TestSize.Level0)
98 {
99 std::string groupId = "123456789";
100 std::string str = Crypto::GetGroupIdHash(groupId);
101 EXPECT_EQ(str.empty(), false);
102 }
103
104 /**
105 * @tc.name: ConvertHexStringToBytes_001
106 * @tc.desc: Test ConvertHexStringToBytes
107 * @tc.type: FUNC
108 * @tc.require:
109 */
110 HWTEST_F(DmDistributedHardwareLoadTest, ConvertHexStringToBytes_001, testing::ext::TestSize.Level0)
111 {
112 uint32_t inLen = 2;
113 uint32_t outBufLen = 0;
114 const char *inBuf = "12";
115 unsigned char *outBuf = nullptr;
116 auto ret = Crypto::ConvertHexStringToBytes(outBuf, outBufLen, inBuf, inLen);
117 EXPECT_EQ(ret, ERR_DM_FAILED);
118 }
119
120 /**
121 * @tc.name: ConvertHexStringToBytes_002
122 * @tc.desc: Test ConvertHexStringToBytes
123 * @tc.type: FUNC
124 * @tc.require:
125 */
126 HWTEST_F(DmDistributedHardwareLoadTest, ConvertHexStringToBytes_002, testing::ext::TestSize.Level0)
127 {
128 uint32_t inLen = 0;
129 uint32_t outBufLen = 1;
130 const char *inBuf = nullptr;
131 unsigned char outBuf[1] = {0};
132 auto ret = Crypto::ConvertHexStringToBytes(outBuf, outBufLen, inBuf, inLen);
133 EXPECT_EQ(ret, ERR_DM_FAILED);
134 }
135
136 /**
137 * @tc.name: ConvertHexStringToBytes_003
138 * @tc.desc: Test ConvertHexStringToBytes
139 * @tc.type: FUNC
140 * @tc.require:
141 */
142 HWTEST_F(DmDistributedHardwareLoadTest, ConvertHexStringToBytes_003, testing::ext::TestSize.Level0)
143 {
144 uint32_t inLen = 1;
145 uint32_t outBufLen = 1;
146 const char *inBuf = "1";
147 unsigned char outBuf[1] = {0};
148 auto ret = Crypto::ConvertHexStringToBytes(outBuf, outBufLen, inBuf, inLen);
149 EXPECT_EQ(ret, ERR_DM_FAILED);
150 }
151
152 /**
153 * @tc.name: ConvertHexStringToBytes_004
154 * @tc.desc: Test ConvertHexStringToBytes
155 * @tc.type: FUNC
156 * @tc.require:
157 */
158 HWTEST_F(DmDistributedHardwareLoadTest, ConvertHexStringToBytes_004, testing::ext::TestSize.Level0)
159 {
160 uint32_t inLen = 2;
161 uint32_t outBufLen = 2;
162 const char *inBuf = "1G";
163 unsigned char outBuf[2] = {0};
164 auto ret = Crypto::ConvertHexStringToBytes(outBuf, outBufLen, inBuf, inLen);
165 EXPECT_EQ(ret, ERR_DM_FAILED);
166 }
167
168 /**
169 * @tc.name: ConvertHexStringToBytes_005
170 * @tc.desc: Test ConvertHexStringToBytes
171 * @tc.type: FUNC
172 * @tc.require:
173 */
174 HWTEST_F(DmDistributedHardwareLoadTest, ConvertHexStringToBytes_005, testing::ext::TestSize.Level0)
175 {
176 uint32_t inLen = 2;
177 uint32_t outBufLen = 2;
178 const char *inBuf = "G1";
179 unsigned char outBuf[2] = {0};
180 auto ret = Crypto::ConvertHexStringToBytes(outBuf, outBufLen, inBuf, inLen);
181 EXPECT_EQ(ret, ERR_DM_FAILED);
182 }
183
184 /**
185 * @tc.name: ConvertHexStringToBytes_006
186 * @tc.desc: Test ConvertHexStringToBytes
187 * @tc.type: FUNC
188 * @tc.require:
189 */
190 HWTEST_F(DmDistributedHardwareLoadTest, ConvertHexStringToBytes_006, testing::ext::TestSize.Level0)
191 {
192 uint32_t inLen = 2;
193 uint32_t outBufLen = 2;
194 const char *inBuf = "a1";
195 unsigned char outBuf[2] = {0};
196 auto ret = Crypto::ConvertHexStringToBytes(outBuf, outBufLen, inBuf, inLen);
197 EXPECT_EQ(ret, DM_OK);
198 }
199
200 /**
201 * @tc.name: ConvertHexStringToBytes_007
202 * @tc.desc: Test ConvertHexStringToBytes
203 * @tc.type: FUNC
204 * @tc.require:
205 */
206 HWTEST_F(DmDistributedHardwareLoadTest, ConvertHexStringToBytes_007, testing::ext::TestSize.Level0)
207 {
208 uint32_t inLen = 2;
209 uint32_t outBufLen = 2;
210 const char *inBuf = "Aa";
211 unsigned char outBuf[2] = {0};
212 auto ret = Crypto::ConvertHexStringToBytes(outBuf, outBufLen, inBuf, inLen);
213 EXPECT_EQ(ret, DM_OK);
214 }
215
216 /**
217 * @tc.name: ConvertHexStringToBytes_008
218 * @tc.desc: Test ConvertHexStringToBytes
219 * @tc.type: FUNC
220 * @tc.require:
221 */
222 HWTEST_F(DmDistributedHardwareLoadTest, ConvertHexStringToBytes_008, testing::ext::TestSize.Level0)
223 {
224 uint32_t inLen = 2;
225 uint32_t outBufLen = 2;
226 const char *inBuf = "AA";
227 unsigned char outBuf[2] = {0};
228 auto ret = Crypto::ConvertHexStringToBytes(outBuf, outBufLen, inBuf, inLen);
229 EXPECT_EQ(ret, DM_OK);
230 }
231 } // namespace DistributedHardware
232 } // namespace OHOS
233