1 /*
2 * Copyright (c) 2023-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 "UTTest_dm_deviceprofile_connector.h"
17
18 #include "dm_constants.h"
19 #include "deviceprofile_connector.h"
20
21 namespace OHOS {
22 namespace DistributedHardware {
SetUp()23 void DeviceProfileConnectorTest::SetUp()
24 {
25 }
26
TearDown()27 void DeviceProfileConnectorTest::TearDown()
28 {
29 }
30
SetUpTestCase()31 void DeviceProfileConnectorTest::SetUpTestCase()
32 {
33 }
34
TearDownTestCase()35 void DeviceProfileConnectorTest::TearDownTestCase()
36 {
37 }
38
39 HWTEST_F(DeviceProfileConnectorTest, GetAccessControlProfile_001, testing::ext::TestSize.Level0)
40 {
41 auto ret = DeviceProfileConnector::GetInstance().GetAccessControlProfile();
42 EXPECT_EQ(ret.empty(), true);
43 }
44
45 HWTEST_F(DeviceProfileConnectorTest, GetAppTrustDeviceList_001, testing::ext::TestSize.Level0)
46 {
47 std::string pkgName;
48 std::string deviceId;
49 auto ret = DeviceProfileConnector::GetInstance().GetAppTrustDeviceList(pkgName, deviceId);
50 EXPECT_EQ(ret.empty(), true);
51 }
52
53 HWTEST_F(DeviceProfileConnectorTest, GetDeviceAclParam_001, testing::ext::TestSize.Level0)
54 {
55 DmDiscoveryInfo discoveryInfo;
56 bool isonline = true;
57 int32_t authForm = 0;
58 int32_t ret = DeviceProfileConnector::GetInstance().GetDeviceAclParam(discoveryInfo, isonline, authForm);
59 EXPECT_EQ(ret, DM_OK);
60 }
61
62 HWTEST_F(DeviceProfileConnectorTest, HandleDmAuthForm_001, testing::ext::TestSize.Level0)
63 {
64 DistributedDeviceProfile::AccessControlProfile profiles;
65 profiles.SetBindType(DM_IDENTICAL_ACCOUNT);
66 DmDiscoveryInfo discoveryInfo;
67 int32_t ret = DeviceProfileConnector::GetInstance().HandleDmAuthForm(profiles, discoveryInfo);
68 EXPECT_EQ(ret, IDENTICAL_ACCOUNT);
69 }
70
71 HWTEST_F(DeviceProfileConnectorTest, HandleDmAuthForm_002, testing::ext::TestSize.Level0)
72 {
73 DistributedDeviceProfile::AccessControlProfile profiles;
74 profiles.SetBindType(DM_POINT_TO_POINT);
75 profiles.SetBindLevel(DEVICE);
76 DmDiscoveryInfo discoveryInfo;
77 int32_t ret = DeviceProfileConnector::GetInstance().HandleDmAuthForm(profiles, discoveryInfo);
78 EXPECT_EQ(ret, PEER_TO_PEER);
79 }
80
81 HWTEST_F(DeviceProfileConnectorTest, HandleDmAuthForm_003, testing::ext::TestSize.Level0)
82 {
83 DistributedDeviceProfile::AccessControlProfile profiles;
84 profiles.SetBindType(DM_ACROSS_ACCOUNT);
85 profiles.SetBindLevel(DEVICE);
86 DmDiscoveryInfo discoveryInfo;
87 int32_t ret = DeviceProfileConnector::GetInstance().HandleDmAuthForm(profiles, discoveryInfo);
88 EXPECT_EQ(ret, ACROSS_ACCOUNT);
89 }
90
91
92 HWTEST_F(DeviceProfileConnectorTest, HandleDmAuthForm_004, testing::ext::TestSize.Level0)
93 {
94 DistributedDeviceProfile::AccessControlProfile profiles;
95 uint32_t invalidType = 3;
96 profiles.SetBindType(invalidType);
97 profiles.SetBindLevel(APP);
98 profiles.GetAccessee().SetAccesseeBundleName("pkgName");
99 profiles.GetAccessee().SetAccesseeDeviceId("localDeviceId");
100 DmDiscoveryInfo discoveryInfo;
101 discoveryInfo.pkgname = "pkgName";
102 discoveryInfo.localDeviceId = "localDeviceId";
103 int32_t ret = DeviceProfileConnector::GetInstance().HandleDmAuthForm(profiles, discoveryInfo);
104 EXPECT_EQ(ret, INVALID_TYPE);
105 }
106
107 HWTEST_F(DeviceProfileConnectorTest, CheckBindType_001, testing::ext::TestSize.Level0)
108 {
109 std::string trustDeviceId;
110 std::string requestDeviceId;
111 uint32_t ret = DeviceProfileConnector::GetInstance().CheckBindType(trustDeviceId, requestDeviceId);
112 EXPECT_EQ(ret, INVALIED_TYPE);
113 }
114
115 HWTEST_F(DeviceProfileConnectorTest, GetBindTypeByPkgName_001, testing::ext::TestSize.Level0)
116 {
117 std::string pkgName;
118 std::string requestDeviceId;
119 std::string trustUdid;
120 auto ret = DeviceProfileConnector::GetInstance().GetBindTypeByPkgName(pkgName, requestDeviceId, trustUdid);
121 EXPECT_EQ(ret.empty(), true);
122 }
123
124 HWTEST_F(DeviceProfileConnectorTest, GetParamBindTypeVec_001, testing::ext::TestSize.Level0)
125 {
126 DistributedDeviceProfile::AccessControlProfile profiles;
127 profiles.SetBindType(DM_IDENTICAL_ACCOUNT);
128 std::string pkgName;
129 std::string requestDeviceId;
130 std::vector<int32_t> bindTypeVec;
131 DeviceProfileConnector::GetInstance().GetParamBindTypeVec(profiles, pkgName, requestDeviceId, bindTypeVec);
132 EXPECT_EQ(bindTypeVec.empty(), false);
133 }
134
135 HWTEST_F(DeviceProfileConnectorTest, GetParamBindTypeVec_002, testing::ext::TestSize.Level0)
136 {
137 DistributedDeviceProfile::AccessControlProfile profiles;
138 profiles.SetBindType(DM_POINT_TO_POINT);
139 profiles.SetBindLevel(DEVICE);
140 std::string pkgName;
141 std::string requestDeviceId;
142 std::vector<int32_t> bindTypeVec;
143 DeviceProfileConnector::GetInstance().GetParamBindTypeVec(profiles, pkgName, requestDeviceId, bindTypeVec);
144 EXPECT_EQ(bindTypeVec.empty(), false);
145 }
146
147 HWTEST_F(DeviceProfileConnectorTest, GetParamBindTypeVec_003, testing::ext::TestSize.Level0)
148 {
149 DistributedDeviceProfile::AccessControlProfile profiles;
150 profiles.SetBindType(DM_POINT_TO_POINT);
151 profiles.SetBindLevel(APP);
152 profiles.GetAccesser().SetAccesserBundleName("pkgName");
153 profiles.GetAccesser().SetAccesserDeviceId("localDeviceId");
154 std::string pkgName = "pkgName";
155 std::string requestDeviceId = "localDeviceId";
156 std::vector<int32_t> bindTypeVec;
157 DeviceProfileConnector::GetInstance().GetParamBindTypeVec(profiles, pkgName, requestDeviceId, bindTypeVec);
158 EXPECT_EQ(bindTypeVec.empty(), true);
159 }
160
161 HWTEST_F(DeviceProfileConnectorTest, GetParamBindTypeVec_004, testing::ext::TestSize.Level0)
162 {
163 DistributedDeviceProfile::AccessControlProfile profiles;
164 profiles.SetBindType(DM_POINT_TO_POINT);
165 profiles.SetBindLevel(APP);
166 profiles.GetAccessee().SetAccesseeBundleName("pkgName");
167 profiles.GetAccessee().SetAccesseeDeviceId("localDeviceId");
168 std::string pkgName = "pkgName";
169 std::string requestDeviceId = "localDeviceId";
170 std::vector<int32_t> bindTypeVec;
171 DeviceProfileConnector::GetInstance().GetParamBindTypeVec(profiles, pkgName, requestDeviceId, bindTypeVec);
172 EXPECT_EQ(bindTypeVec.empty(), true);
173 }
174
175 HWTEST_F(DeviceProfileConnectorTest, GetParamBindTypeVec_005, testing::ext::TestSize.Level0)
176 {
177 DistributedDeviceProfile::AccessControlProfile profiles;
178 profiles.SetBindType(DM_ACROSS_ACCOUNT);
179 profiles.SetBindLevel(DEVICE);
180 std::string pkgName;
181 std::string requestDeviceId;
182 std::vector<int32_t> bindTypeVec;
183 DeviceProfileConnector::GetInstance().GetParamBindTypeVec(profiles, pkgName, requestDeviceId, bindTypeVec);
184 EXPECT_EQ(bindTypeVec.empty(), false);
185 }
186
187 HWTEST_F(DeviceProfileConnectorTest, GetParamBindTypeVec_006, testing::ext::TestSize.Level0)
188 {
189 DistributedDeviceProfile::AccessControlProfile profiles;
190 profiles.SetBindType(DM_ACROSS_ACCOUNT);
191 profiles.SetBindLevel(APP);
192 profiles.GetAccesser().SetAccesserBundleName("pkgName");
193 profiles.GetAccesser().SetAccesserDeviceId("localDeviceId");
194 std::string pkgName = "pkgName";
195 std::string requestDeviceId = "localDeviceId";
196 std::vector<int32_t> bindTypeVec;
197 DeviceProfileConnector::GetInstance().GetParamBindTypeVec(profiles, pkgName, requestDeviceId, bindTypeVec);
198 EXPECT_EQ(bindTypeVec.empty(), true);
199 }
200
201 HWTEST_F(DeviceProfileConnectorTest, GetParamBindTypeVec_007, testing::ext::TestSize.Level0)
202 {
203 DistributedDeviceProfile::AccessControlProfile profiles;
204 profiles.SetBindType(DM_ACROSS_ACCOUNT);
205 profiles.SetBindLevel(APP);
206 profiles.GetAccessee().SetAccesseeBundleName("pkgName");
207 profiles.GetAccessee().SetAccesseeDeviceId("localDeviceId");
208 std::string pkgName = "pkgName";
209 std::string requestDeviceId = "localDeviceId";
210 std::vector<int32_t> bindTypeVec;
211 DeviceProfileConnector::GetInstance().GetParamBindTypeVec(profiles, pkgName, requestDeviceId, bindTypeVec);
212 EXPECT_EQ(bindTypeVec.empty(), true);
213 }
214
215 HWTEST_F(DeviceProfileConnectorTest, CompareBindType_001, testing::ext::TestSize.Level0)
216 {
217 DistributedDeviceProfile::AccessControlProfile profile;
218 profile.SetTrustDeviceId("deviceId");
219 profile.SetStatus(INACTIVE);
220 std::vector<DistributedDeviceProfile::AccessControlProfile> profiles;
221 profiles.push_back(profile);
222 std::string pkgName;
223 std::vector<int32_t> sinkBindType;
224 std::string localDeviceId;
225 std::string targetDeviceId = "targetDeviceId";
226 auto ret = DeviceProfileConnector::GetInstance().CompareBindType(profiles, pkgName, sinkBindType, localDeviceId,
227 targetDeviceId);
228 EXPECT_EQ(ret.empty(), true);
229 }
230
231 HWTEST_F(DeviceProfileConnectorTest, CompareBindType_002, testing::ext::TestSize.Level0)
232 {
233 DistributedDeviceProfile::AccessControlProfile profile;
234 profile.SetTrustDeviceId("targetDeviceId");
235 profile.SetStatus(ACTIVE);
236 std::vector<DistributedDeviceProfile::AccessControlProfile> profiles;
237 profiles.push_back(profile);
238 std::string pkgName;
239 std::vector<int32_t> sinkBindType;
240 std::string localDeviceId;
241 std::string targetDeviceId = "targetDeviceId";
242 auto ret = DeviceProfileConnector::GetInstance().CompareBindType(profiles, pkgName, sinkBindType, localDeviceId,
243 targetDeviceId);
244 EXPECT_EQ(ret.empty(), true);
245 }
246
247 HWTEST_F(DeviceProfileConnectorTest, ProcessBindType_001, testing::ext::TestSize.Level0)
248 {
249 DistributedDeviceProfile::AccessControlProfile profiles;
250 profiles.SetBindType(DM_IDENTICAL_ACCOUNT);
251 DmDiscoveryInfo paramInfo;
252 std::vector<int32_t> sinkBindType;
253 std::vector<int32_t> bindTypeIndex;
254 uint32_t index = 0;
255 DeviceProfileConnector::GetInstance().ProcessBindType(profiles, paramInfo, sinkBindType, bindTypeIndex, index);
256 EXPECT_EQ(sinkBindType.empty(), false);
257 }
258
259 HWTEST_F(DeviceProfileConnectorTest, ProcessBindType_002, testing::ext::TestSize.Level0)
260 {
261 DistributedDeviceProfile::AccessControlProfile profiles;
262 profiles.SetBindType(DM_POINT_TO_POINT);
263 profiles.SetBindLevel(DEVICE);
264 DmDiscoveryInfo paramInfo;
265 std::vector<int32_t> sinkBindType;
266 std::vector<int32_t> bindTypeIndex;
267 uint32_t index = 0;
268 DeviceProfileConnector::GetInstance().ProcessBindType(profiles, paramInfo, sinkBindType, bindTypeIndex, index);
269 EXPECT_EQ(sinkBindType.empty(), false);
270 }
271
272 HWTEST_F(DeviceProfileConnectorTest, ProcessBindType_003, testing::ext::TestSize.Level0)
273 {
274 DistributedDeviceProfile::AccessControlProfile profiles;
275 profiles.SetBindType(DM_POINT_TO_POINT);
276 profiles.SetBindLevel(APP);
277 profiles.GetAccesser().SetAccesserBundleName("pkgName");
278 profiles.GetAccesser().SetAccesserDeviceId("localDeviceId");
279 DmDiscoveryInfo paramInfo;
280 paramInfo.pkgname = "pkgName";
281 paramInfo.localDeviceId = "localDeviceId";
282 std::vector<int32_t> sinkBindType;
283 std::vector<int32_t> bindTypeIndex;
284 uint32_t index = 0;
285 DeviceProfileConnector::GetInstance().ProcessBindType(profiles, paramInfo, sinkBindType, bindTypeIndex, index);
286 EXPECT_EQ(sinkBindType.empty(), true);
287 }
288
289 HWTEST_F(DeviceProfileConnectorTest, ProcessBindType_004, testing::ext::TestSize.Level0)
290 {
291 DistributedDeviceProfile::AccessControlProfile profiles;
292 profiles.SetBindType(DM_POINT_TO_POINT);
293 profiles.SetBindLevel(APP);
294 profiles.GetAccessee().SetAccesseeBundleName("pkgName");
295 profiles.GetAccessee().SetAccesseeDeviceId("localDeviceId");
296 DmDiscoveryInfo paramInfo;
297 paramInfo.pkgname = "pkgName";
298 paramInfo.localDeviceId = "localDeviceId";
299 std::vector<int32_t> sinkBindType;
300 std::vector<int32_t> bindTypeIndex;
301 uint32_t index = 0;
302 DeviceProfileConnector::GetInstance().ProcessBindType(profiles, paramInfo, sinkBindType, bindTypeIndex, index);
303 EXPECT_EQ(sinkBindType.empty(), true);
304 }
305
306 HWTEST_F(DeviceProfileConnectorTest, ProcessBindType_005, testing::ext::TestSize.Level0)
307 {
308 DistributedDeviceProfile::AccessControlProfile profiles;
309 profiles.SetBindType(DM_ACROSS_ACCOUNT);
310 profiles.SetBindLevel(DEVICE);
311 DmDiscoveryInfo paramInfo;
312 std::vector<int32_t> sinkBindType;
313 std::vector<int32_t> bindTypeIndex;
314 uint32_t index = 0;
315 DeviceProfileConnector::GetInstance().ProcessBindType(profiles, paramInfo, sinkBindType, bindTypeIndex, index);
316 EXPECT_EQ(sinkBindType.empty(), false);
317 }
318
319 HWTEST_F(DeviceProfileConnectorTest, ProcessBindType_006, testing::ext::TestSize.Level0)
320 {
321 DistributedDeviceProfile::AccessControlProfile profiles;
322 profiles.SetBindType(DM_ACROSS_ACCOUNT);
323 profiles.SetBindLevel(APP);
324 profiles.GetAccesser().SetAccesserBundleName("pkgName");
325 profiles.GetAccesser().SetAccesserDeviceId("localDeviceId");
326 DmDiscoveryInfo paramInfo;
327 paramInfo.pkgname = "pkgName";
328 paramInfo.localDeviceId = "localDeviceId";
329 std::vector<int32_t> sinkBindType;
330 std::vector<int32_t> bindTypeIndex;
331 uint32_t index = 0;
332 DeviceProfileConnector::GetInstance().ProcessBindType(profiles, paramInfo, sinkBindType, bindTypeIndex, index);
333 EXPECT_EQ(sinkBindType.empty(), true);
334 }
335
336 HWTEST_F(DeviceProfileConnectorTest, ProcessBindType_007, testing::ext::TestSize.Level0)
337 {
338 DistributedDeviceProfile::AccessControlProfile profiles;
339 profiles.SetBindType(DM_ACROSS_ACCOUNT);
340 profiles.SetBindLevel(APP);
341 profiles.GetAccessee().SetAccesseeBundleName("pkgName");
342 profiles.GetAccessee().SetAccesseeDeviceId("localDeviceId");
343 DmDiscoveryInfo paramInfo;
344 paramInfo.pkgname = "pkgName";
345 paramInfo.localDeviceId = "localDeviceId";
346 std::vector<int32_t> sinkBindType;
347 std::vector<int32_t> bindTypeIndex;
348 uint32_t index = 0;
349 DeviceProfileConnector::GetInstance().ProcessBindType(profiles, paramInfo, sinkBindType, bindTypeIndex, index);
350 EXPECT_EQ(sinkBindType.empty(), true);
351 }
352
353 HWTEST_F(DeviceProfileConnectorTest, SyncAclByBindType_001, testing::ext::TestSize.Level0)
354 {
355 std::string pkgName;
356 std::vector<int32_t> bindTypeVec;
357 std::string localDeviceId;
358 std::string targetDeviceId;
359 auto ret = DeviceProfileConnector::GetInstance().SyncAclByBindType(pkgName, bindTypeVec, localDeviceId,
360 targetDeviceId);
361 EXPECT_EQ(ret.empty(), true);
362 }
363
364 HWTEST_F(DeviceProfileConnectorTest, GetPkgNameFromAcl_001, testing::ext::TestSize.Level0)
365 {
366 std::string localDeviceId;
367 std::string targetDeviceId;
368 auto ret = DeviceProfileConnector::GetInstance().GetPkgNameFromAcl(localDeviceId, targetDeviceId);
369 EXPECT_EQ(ret.empty(), true);
370 }
371
372 HWTEST_F(DeviceProfileConnectorTest, GetOfflineParamFromAcl_001, testing::ext::TestSize.Level0)
373 {
374 std::string trustDeviceId;
375 std::string requestDeviceId;
376 auto ret = DeviceProfileConnector::GetInstance().GetOfflineParamFromAcl(trustDeviceId, requestDeviceId);
377 EXPECT_EQ(ret.bindType, INVALIED_TYPE);
378 }
379
380 HWTEST_F(DeviceProfileConnectorTest, PutAccessControlList_001, testing::ext::TestSize.Level0)
381 {
382 DmAclInfo aclInfo;
383 DmAccesser dmAccesser;
384 DmAccessee dmAccessee;
385 int32_t ret = DeviceProfileConnector::GetInstance().PutAccessControlList(aclInfo, dmAccesser, dmAccessee);
386 EXPECT_NE(ret, DM_OK);
387 }
388
389 HWTEST_F(DeviceProfileConnectorTest, DeleteAccessControlList_001, testing::ext::TestSize.Level0)
390 {
391 int32_t userId = 0;
392 std::string accountId;
393 int32_t ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(userId, accountId);
394 EXPECT_EQ(ret, DM_OK);
395 }
396
397 HWTEST_F(DeviceProfileConnectorTest, DeleteAccessControlList_002, testing::ext::TestSize.Level0)
398 {
399 std::string pkgName;
400 std::string localDeviceId;
401 std::string remoteDeviceId;
402 auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId, remoteDeviceId);
403 EXPECT_EQ(ret.bindType, INVALIED_TYPE);
404 }
405
406 HWTEST_F(DeviceProfileConnectorTest, UpdateAccessControlList_001, testing::ext::TestSize.Level0)
407 {
408 int32_t userId = 0;
409 std::string oldAccountId;
410 std::string newAccountId;
411 int32_t ret = DeviceProfileConnector::GetInstance().UpdateAccessControlList(userId, oldAccountId, newAccountId);
412 EXPECT_EQ(ret, DM_OK);
413 }
414
415 HWTEST_F(DeviceProfileConnectorTest, CheckIdenticalAccount_001, testing::ext::TestSize.Level0)
416 {
417 int32_t userId = 0;
418 std::string accountId;
419 bool ret = DeviceProfileConnector::GetInstance().CheckIdenticalAccount(userId, accountId);
420 EXPECT_EQ(ret, false);
421 }
422
423 HWTEST_F(DeviceProfileConnectorTest, DeleteP2PAccessControlList_001, testing::ext::TestSize.Level0)
424 {
425 int32_t userId = 0;
426 std::string accountId;
427 int32_t ret = DeviceProfileConnector::GetInstance().DeleteP2PAccessControlList(userId, accountId);
428 EXPECT_EQ(ret, DM_OK);
429 }
430
431 HWTEST_F(DeviceProfileConnectorTest, CheckSrcDeviceIdInAcl_001, testing::ext::TestSize.Level0)
432 {
433 std::string pkgName;
434 std::string deviceId;
435 bool ret = DeviceProfileConnector::GetInstance().CheckSrcDeviceIdInAcl(pkgName, deviceId);
436 EXPECT_EQ(ret, false);
437 }
438
439 HWTEST_F(DeviceProfileConnectorTest, CheckSinkDeviceIdInAcl_001, testing::ext::TestSize.Level0)
440 {
441 std::string pkgName;
442 std::string deviceId;
443 bool ret = DeviceProfileConnector::GetInstance().CheckSinkDeviceIdInAcl(pkgName, deviceId);
444 EXPECT_EQ(ret, false);
445 }
446
447 HWTEST_F(DeviceProfileConnectorTest, CheckDeviceIdInAcl_001, testing::ext::TestSize.Level0)
448 {
449 std::string pkgName;
450 std::string deviceId;
451 bool ret = DeviceProfileConnector::GetInstance().CheckDeviceIdInAcl(pkgName, deviceId);
452 EXPECT_EQ(ret, false);
453 }
454
455 HWTEST_F(DeviceProfileConnectorTest, DeleteTimeOutAcl_001, testing::ext::TestSize.Level0)
456 {
457 std::string deviceId;
458 uint32_t ret = DeviceProfileConnector::GetInstance().DeleteTimeOutAcl(deviceId);
459 EXPECT_EQ(ret, 0);
460 }
461
462 HWTEST_F(DeviceProfileConnectorTest, GetTrustNumber_001, testing::ext::TestSize.Level0)
463 {
464 std::string deviceId;
465 int32_t ret = DeviceProfileConnector::GetInstance().GetTrustNumber(deviceId);
466 EXPECT_EQ(ret, DM_OK);
467 }
468
469 HWTEST_F(DeviceProfileConnectorTest, CheckPkgnameInAcl_001, testing::ext::TestSize.Level0)
470 {
471 std::string pkgName;
472 std::string localDeviceId;
473 std::string remoteDeviceId;
474 bool ret = DeviceProfileConnector::GetInstance().CheckPkgnameInAcl(pkgName, localDeviceId, remoteDeviceId);
475 EXPECT_EQ(ret, false);
476 }
477 } // namespace DistributedHardware
478 } // namespace OHOS
479