• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_second.h"
17 
18 #include "dm_constants.h"
19 #include "deviceprofile_connector.h"
20 #include <iterator>
21 #include "dp_inited_callback_stub.h"
22 #include "dm_error_type.h"
23 
24 using namespace testing;
25 using namespace testing::ext;
26 namespace OHOS {
27 namespace DistributedHardware {
28 
SetUp()29 void DeviceProfileConnectorSecondTest::SetUp()
30 {
31 }
32 
TearDown()33 void DeviceProfileConnectorSecondTest::TearDown()
34 {
35 }
36 
SetUpTestCase()37 void DeviceProfileConnectorSecondTest::SetUpTestCase()
38 {
39     DistributedDeviceProfile::DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient =
40         distributedDeviceProfileClientMock_;
41 }
42 
TearDownTestCase()43 void DeviceProfileConnectorSecondTest::TearDownTestCase()
44 {
45     DistributedDeviceProfile::DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient = nullptr;
46     distributedDeviceProfileClientMock_ = nullptr;
47 }
48 
49 class DpInitedCallback : public DistributedDeviceProfile::DpInitedCallbackStub {
50 public:
DpInitedCallback()51     DpInitedCallback()
52     {
53     }
~DpInitedCallback()54     ~DpInitedCallback()
55     {
56     }
OnDpInited()57     int32_t OnDpInited()
58     {
59         return 0;
60     }
61 };
62 
AddAccessControlProfile(std::vector<DistributedDeviceProfile::AccessControlProfile> & accessControlProfiles)63 void AddAccessControlProfile(std::vector<DistributedDeviceProfile::AccessControlProfile>& accessControlProfiles)
64 {
65     int32_t userId = 123456;
66     int32_t bindType = 256;
67     int32_t deviceIdType = 1;
68     uint32_t bindLevel = 1;
69     uint32_t status = 1;
70     uint32_t authenticationType = 2;
71     uint32_t accesserId = 1;
72     uint32_t tokenId = 1001;
73 
74     std::string oldAccountId = "oldAccountId";
75     std::string newAccountId = "newAccountId";
76     std::string deviceIdEr = "remoteDeviceId";
77     std::string deviceIdEe = "localDeviceId";
78     std::string trustDeviceId = "123456";
79 
80     DistributedDeviceProfile::Accesser accesser;
81     accesser.SetAccesserId(accesserId);
82     accesser.SetAccesserDeviceId(deviceIdEr);
83     accesser.SetAccesserUserId(userId);
84     accesser.SetAccesserAccountId(oldAccountId);
85     accesser.SetAccesserTokenId(tokenId);
86     accesser.SetAccesserBundleName("bundleName");
87     accesser.SetAccesserHapSignature("uph1");
88     accesser.SetAccesserBindLevel(bindLevel);
89 
90     DistributedDeviceProfile::Accessee accessee;
91     accessee.SetAccesseeId(accesserId);
92     accessee.SetAccesseeDeviceId(deviceIdEe);
93     accessee.SetAccesseeUserId(userId);
94     accessee.SetAccesseeAccountId(newAccountId);
95     accessee.SetAccesseeTokenId(tokenId);
96     accessee.SetAccesseeBundleName("bundleName");
97     accessee.SetAccesseeHapSignature("uph1");
98     accessee.SetAccesseeBindLevel(bindLevel);
99 
100     DistributedDeviceProfile::AccessControlProfile profileFifth;
101     profileFifth.SetAccessControlId(accesserId);
102     profileFifth.SetAccesserId(accesserId);
103     profileFifth.SetAccesseeId(accesserId);
104     profileFifth.SetTrustDeviceId(trustDeviceId);
105     profileFifth.SetBindType(bindType);
106     profileFifth.SetAuthenticationType(authenticationType);
107     profileFifth.SetDeviceIdType(deviceIdType);
108     profileFifth.SetStatus(status);
109     profileFifth.SetBindLevel(bindLevel);
110     profileFifth.SetAccesser(accesser);
111     profileFifth.SetAccessee(accessee);
112     accessControlProfiles.push_back(profileFifth);
113 }
114 
115 HWTEST_F(DeviceProfileConnectorSecondTest, GetAccessControlProfile_201, testing::ext::TestSize.Level0)
116 {
117     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAccessControlProfile(_, _)).WillOnce(Return(ERR_DM_FAILED));
118     auto ret = DeviceProfileConnector::GetInstance().GetAccessControlProfile();
119     EXPECT_TRUE(ret.empty());
120 }
121 
122 HWTEST_F(DeviceProfileConnectorSecondTest, GetAccessControlProfileByUserId_201, testing::ext::TestSize.Level0)
123 {
124     int32_t userId = DEVICE;
125     std::vector<DistributedDeviceProfile::AccessControlProfile> profiles;
126     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAccessControlProfile(_, _)).WillOnce(Return(ERR_DM_FAILED));
127     profiles = DeviceProfileConnector::GetInstance().GetAccessControlProfileByUserId(userId);
128     EXPECT_TRUE(profiles.empty());
129 }
130 
131 HWTEST_F(DeviceProfileConnectorSecondTest, CheckAuthForm_201, testing::ext::TestSize.Level0)
132 {
133     DmAuthForm form = DmAuthForm::ACROSS_ACCOUNT;
134     DistributedDeviceProfile::AccessControlProfile profiles;
135     profiles.SetBindType(DM_ACROSS_ACCOUNT);
136     profiles.SetBindLevel(APP);
137     profiles.accessee_.SetAccesseeBundleName("pkgName");
138     profiles.accessee_.SetAccesseeDeviceId("localDeviceId");
139     DmDiscoveryInfo discoveryInfo;
140     discoveryInfo.pkgname = "pkgName";
141     discoveryInfo.localDeviceId = "localDeviceId";
142     int32_t ret = DeviceProfileConnector::GetInstance().CheckAuthForm(form, profiles, discoveryInfo);
143     EXPECT_EQ(ret, DmAuthForm::ACROSS_ACCOUNT);
144 
145     profiles.accesser_.SetAccesserBundleName("pkgName");
146     profiles.accesser_.SetAccesserDeviceId("localDeviceId");
147     ret = DeviceProfileConnector::GetInstance().CheckAuthForm(form, profiles, discoveryInfo);
148     EXPECT_EQ(ret, DmAuthForm::ACROSS_ACCOUNT);
149 
150     profiles.SetBindLevel(SERVICE);
151     ret = DeviceProfileConnector::GetInstance().CheckAuthForm(form, profiles, discoveryInfo);
152     EXPECT_EQ(ret, DmAuthForm::INVALID_TYPE);
153 
154     profiles.SetBindLevel(DEVICE);
155     ret = DeviceProfileConnector::GetInstance().CheckAuthForm(form, profiles, discoveryInfo);
156     EXPECT_EQ(ret, DmAuthForm::ACROSS_ACCOUNT);
157 }
158 
159 HWTEST_F(DeviceProfileConnectorSecondTest, PutAccessControlList_201, testing::ext::TestSize.Level0)
160 {
161     DmAclInfo aclInfo;
162     DmAccesser dmAccesser;
163     DmAccessee dmAccessee;
164     EXPECT_CALL(*distributedDeviceProfileClientMock_, PutAccessControlProfile(_)).WillOnce(Return(ERR_DM_FAILED));
165     int32_t ret = DeviceProfileConnector::GetInstance().PutAccessControlList(aclInfo, dmAccesser, dmAccessee);
166     EXPECT_EQ(ret, ERR_DM_FAILED);
167 }
168 
169 HWTEST_F(DeviceProfileConnectorSecondTest, CheckIdenticalAccount_201, testing::ext::TestSize.Level0)
170 {
171     int32_t userId = 0;
172     std::string accountId;
173     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAccessControlProfile(_, _)).WillOnce(Return(ERR_DM_FAILED));
174     bool ret = DeviceProfileConnector::GetInstance().CheckIdenticalAccount(userId, accountId);
175     EXPECT_FALSE(ret);
176 
177     userId = 1;
178     int32_t bindType = 1;
179     std::string deviceIdEr = "deviceId";
180     std::string deviceIdEe = "deviceIdEe";
181     uint32_t accesserId = 1;
182     DistributedDeviceProfile::Accesser accesser;
183     accesser.SetAccesserDeviceId(deviceIdEr);
184     accesser.SetAccesserUserId(userId);
185     DistributedDeviceProfile::Accessee accessee;
186     accessee.SetAccesseeDeviceId(deviceIdEe);
187     accessee.SetAccesseeUserId(userId);
188     DistributedDeviceProfile::AccessControlProfile profile;
189     profile.SetAccessControlId(accesserId);
190     profile.SetBindType(bindType);
191     profile.SetAccesser(accesser);
192     profile.SetAccessee(accessee);
193 
194     int userIds = 12356;
195     std::string remoteUdid = "deviceId";
196     std::vector<int32_t> remoteFrontUserIds;
197     remoteFrontUserIds.push_back(userIds);
198     std::vector<int32_t> remoteBackUserIds;
199     remoteBackUserIds.push_back(userIds);
200     DeviceProfileConnector::GetInstance().DeleteSigTrustACL(profile, remoteUdid, remoteFrontUserIds, remoteBackUserIds);
201 
202     remoteUdid = "deviceIdEe";
203     DeviceProfileConnector::GetInstance().DeleteSigTrustACL(profile, remoteUdid, remoteFrontUserIds, remoteBackUserIds);
204 
205     int32_t userIdee = 0;
206     accessee.SetAccesseeUserId(userIdee);
207     DistributedDeviceProfile::AccessControlProfile profilesecond;
208     profilesecond.SetAccessControlId(accesserId);
209     profilesecond.SetBindType(bindType);
210     profilesecond.SetAccesser(accesser);
211     profilesecond.SetAccessee(accessee);
212     std::string localUdid = "deviceId";
213     std::vector<int32_t> localUserIds;
214     int32_t localUserId = 1;
215     localUserIds.push_back(localUserId);
216     DeviceProfileConnector::GetInstance().UpdatePeerUserId(profilesecond, localUdid, localUserIds,
217         remoteUdid, remoteFrontUserIds);
218 }
219 
220 HWTEST_F(DeviceProfileConnectorSecondTest, GetAllAccessControlProfile_201, testing::ext::TestSize.Level0)
221 {
222     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(ERR_DM_FAILED));
223     auto ret = DeviceProfileConnector::GetInstance().GetAllAccessControlProfile();
224     EXPECT_TRUE(ret.empty());
225 }
226 
227 HWTEST_F(DeviceProfileConnectorSecondTest, GetAclProfileByDeviceIdAndUserId_201, testing::ext::TestSize.Level0)
228 {
229     std::string deviceId = "deviceId";
230     int32_t userId = 123456;
231     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAccessControlProfile(_, _)).WillOnce(Return(ERR_DM_FAILED));
232     auto ret = DeviceProfileConnector::GetInstance().GetAclProfileByDeviceIdAndUserId(deviceId, userId);
233     EXPECT_TRUE(ret.empty());
234 }
235 
236 HWTEST_F(DeviceProfileConnectorSecondTest, DeleteAclForAccountLogOut_001, testing::ext::TestSize.Level0)
237 {
238     std::string localUdid = "local_device_id";
239     int32_t localUserId = 1;
240     std::string peerUdid = "peer_device_id";
241     int32_t peerUserId = 2;
242     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
243     int32_t result = connector.DeleteAclForAccountLogOut(localUdid, localUserId, peerUdid, peerUserId);
244 
245     EXPECT_EQ(result, false);
246 }
247 
248 HWTEST_F(DeviceProfileConnectorSecondTest, DeleteAppBindLevel_001, testing::ext::TestSize.Level0)
249 {
250     DmOfflineParam offlineParam;
251     std::string pkgName = "com.example.app";
252     std::vector<DistributedDeviceProfile::AccessControlProfile> profiles = {};
253     std::string localUdid = "local_udid";
254     std::string remoteUdid = "remote_udid";
255     connector.DeleteAppBindLevel(offlineParam, pkgName, profiles, localUdid, remoteUdid);
256 
257     EXPECT_EQ(offlineParam.processVec.size(), 0);
258 }
259 
260 HWTEST_F(DeviceProfileConnectorSecondTest, CheckIsSameAccount_001, testing::ext::TestSize.Level0)
261 {
262     DmAccessCaller caller;
263     caller.pkgName = "test_pkg";
264     std::string srcUdid = "src_udid";
265     DmAccessCallee callee;
266     std::string sinkUdid = "non_identical_udid";
267     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
268     EXPECT_EQ(connector.CheckIsSameAccount(caller, srcUdid, callee, sinkUdid), ERR_DM_FAILED);
269 }
270 
271 HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceIdAndBindLevel_001, testing::ext::TestSize.Level0)
272 {
273     std::vector<int32_t> userIds = {4, 5, 6};
274     std::string localUdid = "local_udid";
275     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_))
276         .Times(::testing::AtLeast(2)).WillOnce(Return(DM_OK));
277     auto result = connector.GetDeviceIdAndBindLevel(userIds, localUdid);
278     EXPECT_TRUE(result.empty());
279 }
280 
281 HWTEST_F(DeviceProfileConnectorSecondTest, GetAclProfileByUserId_001, testing::ext::TestSize.Level0)
282 {
283     std::string localUdid = "localDevice";
284     int32_t userId = -1;
285     std::string remoteUdid = "remoteDevice";
286     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
287     auto result = connector.GetAclProfileByUserId(localUdid, userId, remoteUdid);
288 
289     EXPECT_TRUE(result.empty());
290 }
291 
292 HWTEST_F(DeviceProfileConnectorSecondTest, GetAclProfileByUserId_002, testing::ext::TestSize.Level0)
293 {
294     std::string localUdid = "localDevice";
295     int32_t userId = 1;
296     std::string remoteUdid = "nonExistentDevice";
297     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
298     auto result = connector.GetAclProfileByUserId(localUdid, userId, remoteUdid);
299 
300     EXPECT_TRUE(result.empty());
301 }
302 
303 HWTEST_F(DeviceProfileConnectorSecondTest, GetAclProfileByUserId_003, testing::ext::TestSize.Level0)
304 {
305     std::string localUdid = "";
306     int32_t userId = 0;
307     std::string remoteUdid = "";
308     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
309     auto result = connector.GetAclProfileByUserId(localUdid, userId, remoteUdid);
310 
311     EXPECT_TRUE(result.empty());
312 }
313 
314 HWTEST_F(DeviceProfileConnectorSecondTest, GetOfflineProcessInfo_001, testing::ext::TestSize.Level0)
315 {
316     std::string localUdid = "invalid_device";
317     std::vector<int32_t> localUserIds = {1, 2};
318     std::string remoteUdid = "remote_device";
319     std::vector<int32_t> remoteUserIds = {3, 4};
320     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
321     std::vector<ProcessInfo> result =
322         connector.GetOfflineProcessInfo(localUdid, localUserIds, remoteUdid, remoteUserIds);
323 
324     EXPECT_TRUE(result.empty());
325 }
326 
327 HWTEST_F(DeviceProfileConnectorSecondTest, GetOfflineProcessInfo_002, testing::ext::TestSize.Level0)
328 {
329     std::string localUdid = "local_device";
330     std::vector<int32_t> localUserIds = {1, 2};
331     std::string remoteUdid = "remote_device";
332     std::vector<int32_t> remoteUserIds = {99, 100};
333     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
334     std::vector<ProcessInfo> result =
335         connector.GetOfflineProcessInfo(localUdid, localUserIds, remoteUdid, remoteUserIds);
336 
337     EXPECT_TRUE(result.empty());
338 }
339 
340 HWTEST_F(DeviceProfileConnectorSecondTest, GetOfflineProcessInfo_003, testing::ext::TestSize.Level0)
341 {
342     std::string localUdid = "local_device";
343     std::vector<int32_t> localUserIds = {};
344     std::string remoteUdid = "remote_device";
345     std::vector<int32_t> remoteUserIds = {3, 4};
346     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
347     std::vector<ProcessInfo> result =
348         connector.GetOfflineProcessInfo(localUdid, localUserIds, remoteUdid, remoteUserIds);
349 
350     EXPECT_TRUE(result.empty());
351 }
352 
353 HWTEST_F(DeviceProfileConnectorSecondTest, GetUserIdAndBindLevel_001, testing::ext::TestSize.Level0)
354 {
355     std::string localUdid = "local_udid";
356     std::string peerUdid = "peer_udid";
357     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
358     std::map<int32_t, int32_t> result = connector.GetUserIdAndBindLevel(localUdid, peerUdid);
359 
360     EXPECT_TRUE(result.empty());
361 }
362 
363 HWTEST_F(DeviceProfileConnectorSecondTest, GetUserIdAndBindLevel_002, testing::ext::TestSize.Level0)
364 {
365     std::string localUdid = "local_udid";
366     std::string peerUdid = "peer_udid";
367         EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
368     std::map<int32_t, int32_t> result = connector.GetUserIdAndBindLevel(localUdid, peerUdid);
369 
370     EXPECT_TRUE(result.empty());
371 }
372 
373 HWTEST_F(DeviceProfileConnectorSecondTest, GetDevIdAndUserIdByActHash_001, testing::ext::TestSize.Level0)
374 {
375     std::string localUdid = "local_udid_123";
376     std::string peerUdid = "peer_udid_456";
377     int32_t peerUserId = 789;
378     std::string peerAccountHash = "invalid_hash";
379     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
380     std::multimap<std::string, int32_t> result =
381         connector.GetDevIdAndUserIdByActHash(localUdid, peerUdid, peerUserId, peerAccountHash);
382 
383     EXPECT_TRUE(result.empty());
384 }
385 
386 HWTEST_F(DeviceProfileConnectorSecondTest, GetDevIdAndUserIdByActHash_002, testing::ext::TestSize.Level0)
387 {
388     std::string localUdid = "local_udid_123";
389     std::string peerUdid = "non_matching_udid";
390     int32_t peerUserId = 789;
391     std::string peerAccountHash = "valid_hash";
392     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
393     std::multimap<std::string, int32_t> result =
394         connector.GetDevIdAndUserIdByActHash(localUdid, peerUdid, peerUserId, peerAccountHash);
395 
396     EXPECT_TRUE(result.empty());
397 }
398 
399 HWTEST_F(DeviceProfileConnectorSecondTest, GetDevIdAndUserIdByActHash_003, testing::ext::TestSize.Level0)
400 {
401     std::string localUdid = "local_udid_123";
402     std::string peerUdid = "peer_udid_456";
403     int32_t peerUserId = -1;
404     std::string peerAccountHash = "valid_hash";
405     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
406     std::multimap<std::string, int32_t> result =
407         connector.GetDevIdAndUserIdByActHash(localUdid, peerUdid, peerUserId, peerAccountHash);
408 
409     EXPECT_TRUE(result.empty());
410 }
411 
412 HWTEST_F(DeviceProfileConnectorSecondTest, GetDevIdAndUserIdByActHash_004, testing::ext::TestSize.Level0)
413 {
414     std::string localUdid = "";
415     std::string peerUdid = "";
416     int32_t peerUserId = 0;
417     std::string peerAccountHash = "";
418     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
419     std::multimap<std::string, int32_t> result =
420         connector.GetDevIdAndUserIdByActHash(localUdid, peerUdid, peerUserId, peerAccountHash);
421 
422     EXPECT_TRUE(result.empty());
423 }
424 
425 HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceIdAndUserId_001, testing::ext::TestSize.Level0)
426 {
427     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
428     auto result = connector.GetDeviceIdAndUserId("device4", 4);
429     EXPECT_EQ(result.size(), 0);
430 }
431 
432 HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceIdAndUserId_002, testing::ext::TestSize.Level0)
433 {
434     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
435     auto result = connector.GetDeviceIdAndUserId("", 0);
436     EXPECT_EQ(result.size(), 0);
437 }
438 
439 HWTEST_F(DeviceProfileConnectorSecondTest, SubscribeDeviceProfileInited_201, testing::ext::TestSize.Level0)
440 {
441     OHOS::sptr<DistributedDeviceProfile::IDpInitedCallback> dpInitedCallback = nullptr;
442     int32_t ret = DeviceProfileConnector::GetInstance().SubscribeDeviceProfileInited(dpInitedCallback);
443     EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
444 
445     dpInitedCallback = sptr<DistributedDeviceProfile::IDpInitedCallback>(new DpInitedCallback());
446     EXPECT_CALL(*distributedDeviceProfileClientMock_, SubscribeDeviceProfileInited(_, _))
447         .WillOnce(Return(ERR_DM_FAILED));
448     ret = DeviceProfileConnector::GetInstance().SubscribeDeviceProfileInited(dpInitedCallback);
449     EXPECT_EQ(ret, ERR_DM_FAILED);
450 
451     EXPECT_CALL(*distributedDeviceProfileClientMock_, SubscribeDeviceProfileInited(_, _))
452         .WillOnce(Return(DM_OK));
453     ret = DeviceProfileConnector::GetInstance().SubscribeDeviceProfileInited(dpInitedCallback);
454     EXPECT_EQ(ret, DM_OK);
455 }
456 
457 HWTEST_F(DeviceProfileConnectorSecondTest, UnSubscribeDeviceProfileInited_201, testing::ext::TestSize.Level0)
458 {
459     EXPECT_CALL(*distributedDeviceProfileClientMock_, UnSubscribeDeviceProfileInited(_))
460         .WillOnce(Return(ERR_DM_FAILED));
461     int32_t ret = DeviceProfileConnector::GetInstance().UnSubscribeDeviceProfileInited();
462     EXPECT_EQ(ret, ERR_DM_FAILED);
463 
464     EXPECT_CALL(*distributedDeviceProfileClientMock_, UnSubscribeDeviceProfileInited(_))
465         .WillOnce(Return(DM_OK));
466     ret = DeviceProfileConnector::GetInstance().UnSubscribeDeviceProfileInited();
467     EXPECT_EQ(ret, DM_OK);
468 }
469 
470 HWTEST_F(DeviceProfileConnectorSecondTest, PutAllTrustedDevices_201, testing::ext::TestSize.Level0)
471 {
472     std::vector<DistributedDeviceProfile::TrustedDeviceInfo> deviceInfos;
473     EXPECT_CALL(*distributedDeviceProfileClientMock_, PutAllTrustedDevices(_))
474         .WillOnce(Return(ERR_DM_FAILED));
475     int32_t ret = DeviceProfileConnector::GetInstance().PutAllTrustedDevices(deviceInfos);
476     EXPECT_EQ(ret, ERR_DM_FAILED);
477 
478     EXPECT_CALL(*distributedDeviceProfileClientMock_, PutAllTrustedDevices(_))
479         .WillOnce(Return(DM_OK));
480     ret = DeviceProfileConnector::GetInstance().PutAllTrustedDevices(deviceInfos);
481     EXPECT_EQ(ret, DM_OK);
482 
483     int32_t bindType = 0;
484     std::string peerUdid = "";
485     std::string localUdid = "";
486     int32_t localUserId = 1234;
487     std::string localAccountId = "";
488     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
489     DeviceProfileConnector::GetInstance().HandleDeviceUnBind(bindType, peerUdid, localUdid, localUserId,
490         localAccountId);
491 }
492 
493 HWTEST_F(DeviceProfileConnectorSecondTest, DeleteAccessControlList_201, testing::ext::TestSize.Level0)
494 {
495     std::string pkgName;
496     std::string localDeviceId = "";
497     std::string remoteDeviceId = "";
498     int32_t bindLevel = 2;
499     std::string extra = "";
500     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAccessControlProfile(_, _)).WillOnce(Return(ERR_DM_FAILED));
501     DmOfflineParam offlineParam = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId,
502         remoteDeviceId, bindLevel, extra);
503     EXPECT_EQ(offlineParam.bindType, INVALIED_TYPE);
504 }
505 
506 HWTEST_F(DeviceProfileConnectorSecondTest, PutSessionKey_201, testing::ext::TestSize.Level0)
507 {
508     std::vector<unsigned char> sessionKeyArray;
509     int32_t sessionKeyId = 1;
510     int32_t ret = DeviceProfileConnector::GetInstance().PutSessionKey(sessionKeyArray, sessionKeyId);
511     EXPECT_EQ(ret, ERR_DM_FAILED);
512 
513     sessionKeyArray.push_back('1');
514     sessionKeyArray.push_back('2');
515     sessionKeyArray.push_back('3');
516     sessionKeyArray.push_back('4');
517     sessionKeyArray.push_back('5');
518     EXPECT_CALL(*distributedDeviceProfileClientMock_, PutSessionKey(_, _, _)).WillOnce(Return(ERR_DM_FAILED));
519     ret = DeviceProfileConnector::GetInstance().PutSessionKey(sessionKeyArray, sessionKeyId);
520     EXPECT_EQ(ret, ERR_DM_FAILED);
521 
522     EXPECT_CALL(*distributedDeviceProfileClientMock_, PutSessionKey(_, _, _)).WillOnce(Return(DM_OK));
523     ret = DeviceProfileConnector::GetInstance().PutSessionKey(sessionKeyArray, sessionKeyId);
524     EXPECT_EQ(ret, DM_OK);
525 }
526 
527 HWTEST_F(DeviceProfileConnectorSecondTest, PutLocalServiceInfo_201, testing::ext::TestSize.Level0)
528 {
529     DistributedDeviceProfile::LocalServiceInfo localServiceInfo;
530     EXPECT_CALL(*distributedDeviceProfileClientMock_, PutLocalServiceInfo(_)).WillOnce(Return(DM_OK));
531     int32_t ret = DeviceProfileConnector::GetInstance().PutLocalServiceInfo(localServiceInfo);
532     EXPECT_EQ(ret, DM_OK);
533 
534     EXPECT_CALL(*distributedDeviceProfileClientMock_, PutLocalServiceInfo(_)).WillOnce(Return(ERR_DM_FAILED));
535     ret = DeviceProfileConnector::GetInstance().PutLocalServiceInfo(localServiceInfo);
536     EXPECT_EQ(ret, ERR_DM_FAILED);
537 }
538 
539 HWTEST_F(DeviceProfileConnectorSecondTest, DeleteLocalServiceInfo_201, testing::ext::TestSize.Level0)
540 {
541     std::string bundleName = "b********pl";
542     int32_t pinExchangeType = 1;
543     EXPECT_CALL(*distributedDeviceProfileClientMock_, DeleteLocalServiceInfo(_, _)).WillOnce(Return(DM_OK));
544     int32_t ret = DeviceProfileConnector::GetInstance().DeleteLocalServiceInfo(bundleName, pinExchangeType);
545     EXPECT_EQ(ret, DM_OK);
546 
547     EXPECT_CALL(*distributedDeviceProfileClientMock_, DeleteLocalServiceInfo(_, _)).WillOnce(Return(ERR_DM_FAILED));
548     ret = DeviceProfileConnector::GetInstance().DeleteLocalServiceInfo(bundleName, pinExchangeType);
549     EXPECT_EQ(ret, ERR_DM_FAILED);
550 }
551 
552 HWTEST_F(DeviceProfileConnectorSecondTest, UpdateLocalServiceInfo_201, testing::ext::TestSize.Level0)
553 {
554     DistributedDeviceProfile::LocalServiceInfo localServiceInfo;
555     EXPECT_CALL(*distributedDeviceProfileClientMock_, UpdateLocalServiceInfo(_)).WillOnce(Return(DM_OK));
556     int32_t ret = DeviceProfileConnector::GetInstance().UpdateLocalServiceInfo(localServiceInfo);
557     EXPECT_EQ(ret, DM_OK);
558 
559     EXPECT_CALL(*distributedDeviceProfileClientMock_, UpdateLocalServiceInfo(_)).WillOnce(Return(ERR_DM_FAILED));
560     ret = DeviceProfileConnector::GetInstance().UpdateLocalServiceInfo(localServiceInfo);
561     EXPECT_EQ(ret, ERR_DM_FAILED);
562 }
563 
564 HWTEST_F(DeviceProfileConnectorSecondTest, GetLocalServiceInfoByBundleNameAndPinExchangeType_201,
565         testing::ext::TestSize.Level0)
566 {
567     std::string bundleName = "b********pl";
568     int32_t pinExchangeType = 1;
569     DistributedDeviceProfile::LocalServiceInfo localServiceInfo;
570     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetLocalServiceInfoByBundleAndPinType(_, _, _))
571         .WillOnce(Return(DM_OK));
572     int32_t ret = DeviceProfileConnector::GetInstance().GetLocalServiceInfoByBundleNameAndPinExchangeType(bundleName,
573         pinExchangeType, localServiceInfo);
574     EXPECT_EQ(ret, DM_OK);
575 
576     EXPECT_CALL(*distributedDeviceProfileClientMock_, GetLocalServiceInfoByBundleAndPinType(_, _, _))
577         .WillOnce(Return(ERR_DM_FAILED));
578     ret = DeviceProfileConnector::GetInstance().GetLocalServiceInfoByBundleNameAndPinExchangeType(bundleName,
579         pinExchangeType, localServiceInfo);
580     EXPECT_EQ(ret, ERR_DM_FAILED);
581 }
582 } // namespace DistributedHardware
583 } // namespace OHOS
584