• 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 "accesstoken_kit.h"
17 #include "nativetoken_kit.h"
18 #include "token_setproc.h"
19 
20 #define private   public
21 #define protected public
22 #include <string>
23 #include <vector>
24 #include <new>
25 #include "gtest/gtest.h"
26 #include "refbase.h"
27 #include "iremote_stub.h"
28 #include "distributed_device_profile_constants.h"
29 #include "distributed_device_profile_errors.h"
30 #include "distributed_device_profile_log.h"
31 #include "distributed_device_profile_enums.h"
32 #include "device_profile.h"
33 #include "service_profile.h"
34 #include "content_sensor_manager_utils.h"
35 #include "characteristic_profile.h"
36 #include "i_sync_completed_callback.h"
37 #include "sync_completed_callback_stub.h"
38 #include "device_profile_manager.h"
39 #include "kv_adapter.h"
40 #include "profile_cache.h"
41 #undef private
42 #undef protected
43 
44 namespace OHOS {
45 namespace DistributedDeviceProfile {
46 namespace {
47 const int32_t PERMS_NUM = 2;
48 }
49 using namespace testing::ext;
50 using namespace std;
51 
52 class DeviceProfileManagerTest : public testing::Test {
53 public:
54     static void SetUpTestCase(void);
55     static void TearDownTestCase(void);
56     void SetUp();
57     void TearDown();
58 };
59 
SetUpTestCase(void)60 void DeviceProfileManagerTest::SetUpTestCase(void) {
61 }
62 
TearDownTestCase(void)63 void DeviceProfileManagerTest::TearDownTestCase(void) {
64 }
65 
SetUp()66 void DeviceProfileManagerTest::SetUp()
67 {
68     const char *perms[PERMS_NUM] = {
69         "ohos.permission.DISTRIBUTED_DATASYNC",
70         "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER"
71     };
72     uint64_t tokenId;
73     NativeTokenInfoParams infoInstance = {
74         .dcapsNum = 0,
75         .permsNum = PERMS_NUM,
76         .aclsNum = 0,
77         .dcaps = nullptr,
78         .perms = perms,
79         .acls = nullptr,
80         .processName = "deviceprofile",
81         .aplStr = "system_core",
82     };
83     tokenId = GetAccessTokenId(&infoInstance);
84     SetSelfTokenID(tokenId);
85     OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
86     DeviceProfileManager::GetInstance().Init();
87     DeviceProfileManager::GetInstance().isFirst_.store(false);
88 }
89 
TearDown()90 void DeviceProfileManagerTest::TearDown() {
91 }
92 
93 class SyncCallback : public SyncCompletedCallbackStub {
94 public:
OnSyncCompleted(const map<string,SyncStatus> & syncResults)95     void OnSyncCompleted(const map<string, SyncStatus>& syncResults) {
96     }
97 };
98 
99 /**
100  * @tc.name: Init001
101  * @tc.desc: Init succeed.
102  * @tc.type: FUNC
103  * @tc.require:
104  */
105 HWTEST_F(DeviceProfileManagerTest, Init001, TestSize.Level1)
106 {
107     DeviceProfileManager::GetInstance().UnInit();
108     int32_t ret = DeviceProfileManager::GetInstance().Init();
109     EXPECT_EQ(ret, DP_SUCCESS);
110     DeviceProfileManager::GetInstance().isFirst_.store(false);
111 }
112 
113 /**
114  * @tc.name: UnInit001
115  * @tc.desc: UnInit succeed.
116  * @tc.type: FUNC
117  * @tc.require:
118  */
119 HWTEST_F(DeviceProfileManagerTest, UnInit001, TestSize.Level1)
120 {
121     int32_t ret = DeviceProfileManager::GetInstance().UnInit();
122     EXPECT_EQ(ret, DP_SUCCESS);
123     DeviceProfileManager::GetInstance().Init();
124     DeviceProfileManager::GetInstance().isFirst_.store(false);
125 }
126 
127 /**
128  * @tc.name: UnInit002
129  * @tc.desc: deviceProfileStore_ is nullptr
130  * @tc.type: FUNC
131  * @tc.require:
132  */
133 HWTEST_F(DeviceProfileManagerTest, UnInit002, TestSize.Level1)
134 {
135     DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
136     int32_t ret = DeviceProfileManager::GetInstance().UnInit();
137     EXPECT_EQ(ret, DP_KV_DB_PTR_NULL);
138     DeviceProfileManager::GetInstance().Init();
139     DeviceProfileManager::GetInstance().isFirst_.store(false);
140 }
141 
142 /**
143  * @tc.name: ReInit001
144  * @tc.desc: ReInit succeed.
145  * @tc.type: FUNC
146  * @tc.require:
147  */
148 HWTEST_F(DeviceProfileManagerTest, ReInit001, TestSize.Level1)
149 {
150     int32_t ret = DeviceProfileManager::GetInstance().ReInit();
151     EXPECT_EQ(ret, DP_SUCCESS);
152 }
153 
154 /**
155  * @tc.name: PutDeviceProfile001
156  * @tc.desc: PutDeviceProfile succeed.
157  * @tc.type: FUNC
158  * @tc.require:
159  */
160 HWTEST_F(DeviceProfileManagerTest, PutDeviceProfile001, TestSize.Level1)
161 {
162     DeviceProfile deviceProfile;
163     ContentSensorManagerUtils::GetInstance().localUdid_ = "anything";
164     deviceProfile.SetDeviceId("anything");
165     deviceProfile.SetDeviceName("anything");
166     deviceProfile.SetManufactureName("anything");
167     deviceProfile.SetDeviceModel("anything");
168     deviceProfile.SetStorageCapability(1);
169     deviceProfile.SetOsSysCap("anything");
170     deviceProfile.SetOsApiLevel(1);
171     deviceProfile.SetOsVersion("anything");
172     deviceProfile.SetOsType(1);
173 
174     int32_t ret = DeviceProfileManager::GetInstance().PutDeviceProfile(deviceProfile);
175     EXPECT_EQ(ret, DP_SUCCESS);
176 }
177 
178 /**
179  * @tc.name: PutDeviceProfile002
180  * @tc.desc: PutDeviceProfile failed, the profile is invalid.
181  * @tc.type: FUNC
182  * @tc.require:
183  */
184 HWTEST_F(DeviceProfileManagerTest, PutDeviceProfile002, TestSize.Level1)
185 {
186     DeviceProfile deviceProfile;
187     deviceProfile.SetDeviceId("");
188     deviceProfile.SetDeviceName("anything");
189     deviceProfile.SetManufactureName("anything");
190     deviceProfile.SetDeviceModel("anything");
191     deviceProfile.SetStorageCapability(1);
192     deviceProfile.SetOsSysCap("anything");
193     deviceProfile.SetOsApiLevel(1);
194     deviceProfile.SetOsVersion("anything");
195     deviceProfile.SetOsType(1);
196 
197     int32_t ret = DeviceProfileManager::GetInstance().PutDeviceProfile(deviceProfile);
198     EXPECT_EQ(ret, DP_INVALID_PARAMS);
199 }
200 
201 /**
202  * @tc.name: PutDeviceProfile003
203  * @tc.desc: PutDeviceProfile failed, the profile is exist.
204  * @tc.type: FUNC
205  * @tc.require:
206  */
207 HWTEST_F(DeviceProfileManagerTest, PutDeviceProfile003, TestSize.Level1)
208 {
209     DeviceProfile deviceProfile1;
210     ContentSensorManagerUtils::GetInstance().localUdid_ = "anything1";
211     deviceProfile1.SetDeviceId("anything1");
212     deviceProfile1.SetDeviceName("anything");
213     deviceProfile1.SetManufactureName("anything");
214     deviceProfile1.SetDeviceModel("anything");
215     deviceProfile1.SetStorageCapability(1);
216     deviceProfile1.SetOsSysCap("anything");
217     deviceProfile1.SetOsApiLevel(1);
218     deviceProfile1.SetOsVersion("anything");
219     deviceProfile1.SetOsType(1);
220 
221     DeviceProfile deviceProfile2;
222     deviceProfile2.SetDeviceId("anything1");
223     deviceProfile2.SetDeviceName("anything");
224     deviceProfile2.SetManufactureName("anything");
225     deviceProfile2.SetDeviceModel("anything");
226     deviceProfile2.SetStorageCapability(1);
227     deviceProfile2.SetOsSysCap("anything");
228     deviceProfile2.SetOsApiLevel(1);
229     deviceProfile2.SetOsVersion("anything");
230     deviceProfile2.SetOsType(1);
231 
232     DeviceProfileManager::GetInstance().PutDeviceProfile(deviceProfile1);
233     int32_t ret = DeviceProfileManager::GetInstance().PutDeviceProfile(deviceProfile2);
234     EXPECT_EQ(ret, DP_SUCCESS);
235 }
236 
237 /**
238  * @tc.name: PutDeviceProfile004
239  * @tc.desc: PutDeviceProfile failed, deviceProfileStore is nullptr.
240  * @tc.type: FUNC
241  * @tc.require:
242  */
243 HWTEST_F(DeviceProfileManagerTest, PutDeviceProfile004, TestSize.Level1)
244 {
245     DeviceProfile deviceProfile10;
246     deviceProfile10.SetDeviceId("anything10");
247     deviceProfile10.SetDeviceName("anything");
248     deviceProfile10.SetManufactureName("anything");
249     deviceProfile10.SetDeviceModel("anything");
250     deviceProfile10.SetStorageCapability(1);
251     deviceProfile10.SetOsSysCap("anything");
252     deviceProfile10.SetOsApiLevel(1);
253     deviceProfile10.SetOsVersion("anything");
254     deviceProfile10.SetOsType(1);
255 
256     DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
257     int32_t ret = DeviceProfileManager::GetInstance().PutDeviceProfile(deviceProfile10);
258     EXPECT_EQ(ret, DP_INVALID_PARAMS);
259 }
260 
261 /**
262  * @tc.name: PutDeviceProfile005
263  * @tc.desc: PutDeviceProfile failed, PutDeviceProfile fail.
264  * @tc.type: FUNC
265  * @tc.require:
266  */
267 HWTEST_F(DeviceProfileManagerTest, PutDeviceProfile005, TestSize.Level1)
268 {
269     DeviceProfile deviceProfile11;
270     ContentSensorManagerUtils::GetInstance().localUdid_ = "anything11";
271     deviceProfile11.SetDeviceId("anything11");
272     deviceProfile11.SetDeviceName("anything");
273     deviceProfile11.SetManufactureName("anything");
274     deviceProfile11.SetDeviceModel("anything");
275     deviceProfile11.SetStorageCapability(1);
276     deviceProfile11.SetOsSysCap("anything");
277     deviceProfile11.SetOsApiLevel(1);
278     deviceProfile11.SetOsVersion("anything");
279     deviceProfile11.SetOsType(1);
280 
281     DeviceProfileManager::GetInstance().deviceProfileStore_->UnInit();
282     DeviceProfileManager::GetInstance().isFirst_.store(false);
283     int32_t ret = DeviceProfileManager::GetInstance().PutDeviceProfile(deviceProfile11);
284     EXPECT_EQ(ret, DP_PUT_KV_DB_FAIL);
285     DeviceProfileManager::GetInstance().Init();
286     DeviceProfileManager::GetInstance().isFirst_.store(false);
287 }
288 
289 /**
290  * @tc.name: PutDeviceProfile006
291  * @tc.desc: PutDeviceProfile succeed.
292  * @tc.type: FUNC
293  * @tc.require:
294  */
295 HWTEST_F(DeviceProfileManagerTest, PutDeviceProfile006, TestSize.Level1)
296 {
297     DeviceProfile deviceProfile;
298     ContentSensorManagerUtils::GetInstance().localUdid_ = "anything111";
299     deviceProfile.SetDeviceId("anything111");
300     deviceProfile.SetDeviceName("anything");
301     deviceProfile.SetManufactureName("anything");
302     deviceProfile.SetDeviceModel("anything");
303     deviceProfile.SetStorageCapability(1);
304     deviceProfile.SetOsSysCap("anything");
305     deviceProfile.SetOsApiLevel(1);
306     deviceProfile.SetOsVersion("anything");
307     deviceProfile.SetOsType(1);
308     DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
309     int32_t ret = DeviceProfileManager::GetInstance().PutDeviceProfile(deviceProfile);
310     EXPECT_EQ(ret, DP_KV_DB_PTR_NULL);
311 }
312 
313 /**
314  * @tc.name: PutServiceProfile001
315  * @tc.desc: PutServiceProfile succeed.
316  * @tc.type: FUNC
317  * @tc.require:
318  */
319 HWTEST_F(DeviceProfileManagerTest, PutServiceProfile001, TestSize.Level1)
320 {
321     ServiceProfile serviceProfile;
322     ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId";
323     serviceProfile.SetDeviceId("deviceId");
324     serviceProfile.SetServiceName("serviceName");
325     serviceProfile.SetServiceType("serviceType");
326 
327     int32_t ret = DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile);
328     EXPECT_EQ(ret, DP_SUCCESS);
329 }
330 
331 /**
332  * @tc.name: PutServiceProfile002
333  * @tc.desc: PutServiceProfile failed, the profile is invalid.
334  * @tc.type: FUNC
335  * @tc.require:
336  */
337 HWTEST_F(DeviceProfileManagerTest, PutServiceProfile002, TestSize.Level1)
338 {
339     ServiceProfile serviceProfile;
340     serviceProfile.SetDeviceId("");
341     serviceProfile.SetServiceName("serviceName");
342     serviceProfile.SetServiceType("serviceType");
343 
344     int32_t ret = DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile);
345     EXPECT_EQ(ret, DP_INVALID_PARAMS);
346 }
347 
348 /**
349  * @tc.name: PutServiceProfile003
350  * @tc.desc: PutServiceProfile failed, the profile is exist.
351  * @tc.type: FUNC
352  * @tc.require:
353  */
354 HWTEST_F(DeviceProfileManagerTest, PutServiceProfile003, TestSize.Level1)
355 {
356     ServiceProfile serviceProfile1;
357     ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId1";
358     serviceProfile1.SetDeviceId("deviceId1");
359     serviceProfile1.SetServiceName("serviceName");
360     serviceProfile1.SetServiceType("serviceType");
361 
362     ServiceProfile serviceProfile2;
363     serviceProfile2.SetDeviceId("deviceId1");
364     serviceProfile2.SetServiceName("serviceName");
365     serviceProfile2.SetServiceType("serviceType");
366 
367     DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile1);
368     int32_t ret = DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile2);
369     EXPECT_EQ(ret, DP_SUCCESS);
370 }
371 
372 /**
373  * @tc.name: PutServiceProfile004
374  * @tc.desc: PutServiceProfile failed, deviceProfileStore is nullptr.
375  * @tc.type: FUNC
376  * @tc.require:
377  */
378 HWTEST_F(DeviceProfileManagerTest, PutServiceProfile004, TestSize.Level1)
379 {
380     ServiceProfile serviceProfile10;
381     serviceProfile10.SetDeviceId("deviceId10");
382     serviceProfile10.SetServiceName("serviceName10");
383     serviceProfile10.SetServiceType("serviceType10");
384 
385     DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
386     int32_t ret = DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile10);
387     EXPECT_EQ(ret, DP_INVALID_PARAMS);
388     DeviceProfileManager::GetInstance().Init();
389 }
390 
391 /**
392  * @tc.name: PutServiceProfile005
393  * @tc.desc: PutServiceProfile failed, PutServiceProfile fail.
394  * @tc.type: FUNC
395  * @tc.require:
396  */
397 HWTEST_F(DeviceProfileManagerTest, PutServiceProfile005, TestSize.Level1)
398 {
399     ServiceProfile serviceProfile11;
400     ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId11";
401     serviceProfile11.SetDeviceId("deviceId11");
402     serviceProfile11.SetServiceName("serviceName11");
403     serviceProfile11.SetServiceType("serviceType11");
404 
405     DeviceProfileManager::GetInstance().deviceProfileStore_->UnInit();
406     DeviceProfileManager::GetInstance().isFirst_.store(false);
407     int32_t ret = DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile11);
408     EXPECT_EQ(ret, DP_PUT_KV_DB_FAIL);
409     DeviceProfileManager::GetInstance().Init();
410     DeviceProfileManager::GetInstance().isFirst_.store(false);
411 }
412 
413 /**
414  * @tc.name: PutServiceProfile006
415  * @tc.desc: isFirst_.load() == true
416  * @tc.type: FUNC
417  * @tc.require:
418  */
419 HWTEST_F(DeviceProfileManagerTest, PutServiceProfile006, TestSize.Level1)
420 {
421     ServiceProfile serviceProfile;
422     ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId112";
423     serviceProfile.SetDeviceId("deviceId112");
424     serviceProfile.SetServiceName("serviceName");
425     serviceProfile.SetServiceType("serviceType");
426     DeviceProfileManager::GetInstance().isFirst_.store(true);
427     int32_t ret = DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile);
428     DeviceProfileManager::GetInstance().isFirst_.store(false);
429     EXPECT_EQ(ret, DP_SUCCESS);
430 }
431 
432 /**
433  * @tc.name: PutServiceProfile007
434  * @tc.desc: deviceProfileStore_ == nullptr
435  * @tc.type: FUNC
436  * @tc.require:
437  */
438 HWTEST_F(DeviceProfileManagerTest, PutServiceProfile007, TestSize.Level1)
439 {
440     ServiceProfile serviceProfile;
441     ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId113";
442     serviceProfile.SetDeviceId("deviceId113");
443     serviceProfile.SetServiceName("serviceName");
444     serviceProfile.SetServiceType("serviceType");
445     DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
446     int32_t ret = DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile);
447     EXPECT_EQ(ret, DP_KV_DB_PTR_NULL);
448 }
449 
450 /**
451  * @tc.name: PutServiceProfileBatch001
452  * @tc.desc: PutServiceProfileBatch succeed.
453  * @tc.type: FUNC
454  * @tc.require:
455  */
456 HWTEST_F(DeviceProfileManagerTest, PutServiceProfileBatch001, TestSize.Level1)
457 {
458     vector<ServiceProfile> serviceProfiles;
459     ServiceProfile serviceProfile1;
460     ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId2";
461     serviceProfile1.SetDeviceId("deviceId2");
462     serviceProfile1.SetServiceName("serviceName2");
463     serviceProfile1.SetServiceType("serviceType2");
464     serviceProfiles.push_back(serviceProfile1);
465 
466     ServiceProfile serviceProfile2;
467     serviceProfile2.SetDeviceId("deviceId3");
468     serviceProfile2.SetServiceName("serviceName3");
469     serviceProfile2.SetServiceType("serviceType3");
470     serviceProfiles.push_back(serviceProfile2);
471 
472     int32_t ret = DeviceProfileManager::GetInstance().PutServiceProfileBatch(serviceProfiles);
473     EXPECT_EQ(ret, DP_SUCCESS);
474     DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
475     ret = DeviceProfileManager::GetInstance().PutServiceProfileBatch(serviceProfiles);
476     EXPECT_EQ(ret, DP_KV_DB_PTR_NULL);
477 }
478 
479 /**
480  * @tc.name: PutServiceProfileBatch002
481  * @tc.desc: PutServiceProfileBatch succeed, but first profile is invalid.
482  * @tc.type: FUNC
483  * @tc.require:
484  */
485 HWTEST_F(DeviceProfileManagerTest, PutServiceProfileBatch002, TestSize.Level1)
486 {
487     vector<ServiceProfile> serviceProfiles;
488     ServiceProfile serviceProfile1;
489     serviceProfile1.SetDeviceId("");
490     serviceProfile1.SetServiceName("serviceName");
491     serviceProfile1.SetServiceType("serviceType");
492     serviceProfiles.push_back(serviceProfile1);
493 
494     ServiceProfile serviceProfile4;
495     ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId4";
496     serviceProfile4.SetDeviceId("deviceId4");
497     serviceProfile4.SetServiceName("serviceName4");
498     serviceProfile4.SetServiceType("serviceType4");
499     serviceProfiles.push_back(serviceProfile4);
500 
501     int32_t ret = DeviceProfileManager::GetInstance().PutServiceProfileBatch(serviceProfiles);
502     EXPECT_EQ(ret, DP_SUCCESS);
503 }
504 
505 /**
506  * @tc.name: PutCharacteristicProfile001
507  * @tc.desc: PutCharacteristicProfile succeed.
508  * @tc.type: FUNC
509  * @tc.require:
510  */
511 HWTEST_F(DeviceProfileManagerTest, PutCharacteristicProfile001, TestSize.Level1)
512 {
513     CharacteristicProfile charProfile;
514     ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId";
515     charProfile.SetDeviceId("deviceId");
516     charProfile.SetServiceName("serviceName");
517     charProfile.SetCharacteristicKey("characteristicKey");
518     charProfile.SetCharacteristicValue("characteristicValue");
519 
520     int32_t ret = DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile);
521     EXPECT_EQ(ret, DP_SUCCESS);
522 }
523 
524 /**
525  * @tc.name: PutCharacteristicProfile002
526  * @tc.desc: PutCharacteristicProfile failed, the profile is invalid.
527  * @tc.type: FUNC
528  * @tc.require:
529  */
530 HWTEST_F(DeviceProfileManagerTest, PutCharacteristicProfile002, TestSize.Level1)
531 {
532     CharacteristicProfile charProfile;
533     charProfile.SetDeviceId("");
534     charProfile.SetServiceName("serviceName");
535     charProfile.SetCharacteristicKey("characteristicKey");
536     charProfile.SetCharacteristicValue("characteristicValue");
537 
538     int32_t ret = DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile);
539     EXPECT_EQ(ret, DP_INVALID_PARAMS);
540 }
541 
542 /**
543  * @tc.name: PutCharacteristicProfile003
544  * @tc.desc: PutCharacteristicProfile failed, the profile is exist.
545  * @tc.type: FUNC
546  * @tc.require:
547  */
548 HWTEST_F(DeviceProfileManagerTest, PutCharacteristicProfile003, TestSize.Level1)
549 {
550     CharacteristicProfile charProfile1;
551     ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId1";
552     charProfile1.SetDeviceId("deviceId1");
553     charProfile1.SetServiceName("serviceName");
554     charProfile1.SetCharacteristicKey("characteristicKey");
555     charProfile1.SetCharacteristicValue("characteristicValue");
556 
557     CharacteristicProfile charProfile2;
558     charProfile2.SetDeviceId("deviceId1");
559     charProfile2.SetServiceName("serviceName");
560     charProfile2.SetCharacteristicKey("characteristicKey");
561     charProfile2.SetCharacteristicValue("characteristicValue");
562 
563     DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile1);
564     int32_t ret = DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile2);
565     EXPECT_EQ(ret, DP_SUCCESS);
566 }
567 
568 /**
569  * @tc.name: PutCharacteristicProfile004
570  * @tc.desc: PutCharacteristicProfile failed, deviceProfileStore is nullptr.
571  * @tc.type: FUNC
572  * @tc.require:
573  */
574 HWTEST_F(DeviceProfileManagerTest, PutCharacteristicProfile004, TestSize.Level1)
575 {
576     ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId10";
577     CharacteristicProfile charProfile10;
578     charProfile10.SetDeviceId("deviceId10");
579     charProfile10.SetServiceName("serviceName10");
580     charProfile10.SetCharacteristicKey("characteristicKey10");
581     charProfile10.SetCharacteristicValue("characteristicValue10");
582 
583     DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
584     int32_t ret = DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile10);
585     EXPECT_EQ(ret, DP_KV_DB_PTR_NULL);
586     DeviceProfileManager::GetInstance().Init();
587 }
588 
589 /**
590  * @tc.name: PutCharacteristicProfile005
591  * @tc.desc: PutCharacteristicProfile failed, PutCharacteristicProfile fail.
592  * @tc.type: FUNC
593  * @tc.require:
594  */
595 HWTEST_F(DeviceProfileManagerTest, PutCharacteristicProfile005, TestSize.Level1)
596 {
597     CharacteristicProfile charProfile11;
598     ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId11";
599     charProfile11.SetDeviceId("deviceId11");
600     charProfile11.SetServiceName("serviceName11");
601     charProfile11.SetCharacteristicKey("characteristicKey11");
602     charProfile11.SetCharacteristicValue("characteristicValue11");
603 
604     DeviceProfileManager::GetInstance().deviceProfileStore_->UnInit();
605     DeviceProfileManager::GetInstance().isFirst_.store(false);
606     int32_t ret = DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile11);
607     EXPECT_EQ(ret, DP_PUT_KV_DB_FAIL);
608     DeviceProfileManager::GetInstance().Init();
609     DeviceProfileManager::GetInstance().isFirst_.store(false);
610 }
611 
612 /**
613  * @tc.name: PutCharacteristicProfile006
614  * @tc.desc: isFirst_.load() = true
615  * @tc.type: FUNC
616  * @tc.require:
617  */
618 HWTEST_F(DeviceProfileManagerTest, PutCharacteristicProfile006, TestSize.Level1)
619 {
620     CharacteristicProfile charProfile;
621     ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId111";
622     charProfile.SetDeviceId("deviceId111");
623     charProfile.SetServiceName("serviceName");
624     charProfile.SetCharacteristicKey("characteristicKey");
625     charProfile.SetCharacteristicValue("characteristicValue");
626     DeviceProfileManager::GetInstance().isFirst_.store(true);
627     int32_t ret = DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile);
628     EXPECT_EQ(ret, DP_SUCCESS);
629     DeviceProfileManager::GetInstance().isFirst_.store(false);
630 }
631 
632 /**
633  * @tc.name: PutCharacteristicProfileBatch001
634  * @tc.desc: PutCharacteristicProfileBatch succeed.
635  * @tc.type: FUNC
636  * @tc.require:
637  */
638 HWTEST_F(DeviceProfileManagerTest, PutCharacteristicProfileBatch001, TestSize.Level1)
639 {
640     vector<CharacteristicProfile> charProfiles;
641     CharacteristicProfile charProfile1;
642     ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId2";
643     charProfile1.SetDeviceId("deviceId2");
644     charProfile1.SetServiceName("serviceName2");
645     charProfile1.SetCharacteristicKey("characteristicKey2");
646     charProfile1.SetCharacteristicValue("characteristicValue2");
647     charProfiles.push_back(charProfile1);
648 
649     CharacteristicProfile charProfile2;
650     charProfile2.SetDeviceId("deviceId3");
651     charProfile2.SetServiceName("serviceName3");
652     charProfile2.SetCharacteristicKey("characteristicKey3");
653     charProfile2.SetCharacteristicValue("characteristicValue3");
654     charProfiles.push_back(charProfile2);
655 
656     int32_t ret = DeviceProfileManager::GetInstance().PutCharacteristicProfileBatch(charProfiles);
657     EXPECT_EQ(ret, DP_SUCCESS);
658 
659     DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
660     ret = DeviceProfileManager::GetInstance().PutCharacteristicProfileBatch(charProfiles);
661     EXPECT_EQ(ret, DP_KV_DB_PTR_NULL);
662 }
663 
664 /**
665  * @tc.name: PutCharacteristicProfileBatch002
666  * @tc.desc: PutCharacteristicProfileBatch succeed, but first profile is invalid.
667  * @tc.type: FUNC
668  * @tc.require:
669  */
670 HWTEST_F(DeviceProfileManagerTest, PutCharacteristicProfileBatch002, TestSize.Level1)
671 {
672     vector<CharacteristicProfile> charProfiles;
673     CharacteristicProfile charProfile1;
674     charProfile1.SetDeviceId("");
675     charProfile1.SetServiceName("serviceName");
676     charProfile1.SetCharacteristicKey("characteristicKey");
677     charProfile1.SetCharacteristicValue("characteristicValue");
678     charProfiles.push_back(charProfile1);
679 
680     CharacteristicProfile charProfile4;
681     ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId4";
682     charProfile4.SetDeviceId("deviceId4");
683     charProfile4.SetServiceName("serviceName4");
684     charProfile4.SetCharacteristicKey("characteristicKey4");
685     charProfile4.SetCharacteristicValue("characteristicValue4");
686     charProfiles.push_back(charProfile4);
687 
688     int32_t ret = DeviceProfileManager::GetInstance().PutCharacteristicProfileBatch(charProfiles);
689     EXPECT_EQ(ret, DP_SUCCESS);
690 }
691 
692 /**
693  * @tc.name: GetDeviceProfile001
694  * @tc.desc: GetDeviceProfile succeed, GetDeviceProfile in cache.
695  * @tc.type: FUNC
696  * @tc.require:
697  */
698 HWTEST_F(DeviceProfileManagerTest, GetDeviceProfile001, TestSize.Level1)
699 {
700     DeviceProfile deviceProfile2;
701     ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId";
702     string deviceId = ContentSensorManagerUtils::GetInstance().ObtainLocalUdid();
703     deviceProfile2.SetDeviceId(deviceId);
704     deviceProfile2.SetDeviceName("anything");
705     deviceProfile2.SetManufactureName("anything");
706     deviceProfile2.SetDeviceModel("anything");
707     deviceProfile2.SetStorageCapability(1);
708     deviceProfile2.SetOsSysCap("anything");
709     deviceProfile2.SetOsApiLevel(1);
710     deviceProfile2.SetOsVersion("anything");
711     deviceProfile2.SetOsType(1);
712 
713     DeviceProfileManager::GetInstance().PutDeviceProfile(deviceProfile2);
714 
715     DeviceProfile outDeviceProfile;
716     int32_t ret = DeviceProfileManager::GetInstance().GetDeviceProfile(deviceId, outDeviceProfile);
717     EXPECT_EQ(ret, DP_SUCCESS);
718     outDeviceProfile.SetDeviceId(deviceId);
719     string outDeviceId = outDeviceProfile.GetDeviceId();
720     outDeviceProfile.GetDeviceName();
721     outDeviceProfile.GetManufactureName();
722     outDeviceProfile.GetDeviceModel();
723     outDeviceProfile.GetStorageCapability();
724     outDeviceProfile.GetOsSysCap();
725     outDeviceProfile.GetOsApiLevel();
726     outDeviceProfile.GetOsVersion();
727     outDeviceProfile.GetOsType();
728     EXPECT_EQ(outDeviceId, deviceId);
729 }
730 
731 /**
732  * @tc.name: GetDeviceProfile002
733  * @tc.desc: GetDeviceProfile failed, the profile is invalid.
734  * @tc.type: FUNC
735  * @tc.require:
736  */
737 HWTEST_F(DeviceProfileManagerTest, GetDeviceProfile002, TestSize.Level1)
738 {
739     string deviceId = "";
740     DeviceProfile outDeviceProfile;
741     int32_t ret = DeviceProfileManager::GetInstance().GetDeviceProfile(deviceId, outDeviceProfile);
742     EXPECT_NE(ret, DP_SUCCESS);
743 }
744 
745 /**
746  * @tc.name: GetDeviceProfile003
747  * @tc.desc: GetDeviceProfile failed, deviceProfileStore is nullptr.
748  * @tc.type: FUNC
749  * @tc.require:
750  */
751 HWTEST_F(DeviceProfileManagerTest, GetDeviceProfile003, TestSize.Level1)
752 {
753     string deviceId = "anything12";
754     DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
755     DeviceProfile outDeviceProfile;
756     int32_t ret = DeviceProfileManager::GetInstance().GetDeviceProfile(deviceId, outDeviceProfile);
757     EXPECT_EQ(ret, DP_INVALID_PARAMS);
758     DeviceProfileManager::GetInstance().Init();
759 }
760 
761 /**
762  * @tc.name: GetDeviceProfile004
763  * @tc.desc: GetDeviceProfile failed, Get data fail.
764  * @tc.type: FUNC
765  * @tc.require:
766  */
767 HWTEST_F(DeviceProfileManagerTest, GetDeviceProfile004, TestSize.Level1)
768 {
769     string deviceId = "#anything13";
770     DeviceProfileManager::GetInstance().deviceProfileStore_->UnInit();
771     DeviceProfileManager::GetInstance().isFirst_.store(false);
772     DeviceProfile outDeviceProfile;
773     int32_t ret = DeviceProfileManager::GetInstance().GetDeviceProfile(deviceId, outDeviceProfile);
774     EXPECT_EQ(ret, DP_INVALID_PARAMS);
775     DeviceProfileManager::GetInstance().Init();
776     DeviceProfileManager::GetInstance().isFirst_.store(false);
777 }
778 
779 /**
780  * @tc.name: GetServiceProfile001
781  * @tc.desc: GetServiceProfile succeed, GetServiceProfile in cache.
782  * @tc.type: FUNC
783  * @tc.require:
784  */
785 HWTEST_F(DeviceProfileManagerTest, GetServiceProfile001, TestSize.Level1)
786 {
787     string deviceId = ContentSensorManagerUtils::GetInstance().ObtainLocalUdid();
788     ServiceProfile serviceProfile5;
789     serviceProfile5.SetDeviceId(deviceId);
790     serviceProfile5.SetServiceName("serviceName5");
791     serviceProfile5.SetServiceType("serviceType5");
792     DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile5);
793 
794     string serviceName = "serviceName5";
795     ServiceProfile outServiceProfile;
796     int32_t ret = DeviceProfileManager::GetInstance().GetServiceProfile(deviceId, serviceName, outServiceProfile);
797     EXPECT_EQ(ret, DP_SUCCESS);
798 
799     string outDeviceId = outServiceProfile.GetDeviceId();
800     outServiceProfile.GetServiceName();
801     outServiceProfile.GetServiceType();
802     EXPECT_EQ(outDeviceId, deviceId);
803 }
804 
805 /**
806  * @tc.name: GetServiceProfile002
807  * @tc.desc: GetServiceProfile failed, the profile is invalid.
808  * @tc.type: FUNC
809  * @tc.require:
810  */
811 HWTEST_F(DeviceProfileManagerTest, GetServiceProfile002, TestSize.Level1)
812 {
813     string deviceId = "";
814     string serviceName = "serviceName";
815     ServiceProfile outServiceProfile;
816     int32_t ret = DeviceProfileManager::GetInstance().GetServiceProfile(deviceId, serviceName, outServiceProfile);
817     EXPECT_NE(ret, DP_SUCCESS);
818 
819     deviceId = "deviceId";
820     serviceName = "";
821     ret = DeviceProfileManager::GetInstance().GetServiceProfile(deviceId, serviceName, outServiceProfile);
822     EXPECT_NE(ret, DP_SUCCESS);
823 }
824 
825 /**
826  * @tc.name: GetServiceProfile003
827  * @tc.desc: GetServiceProfile failed, deviceProfileStore is nullptr.
828  * @tc.type: FUNC
829  * @tc.require:
830  */
831 HWTEST_F(DeviceProfileManagerTest, GetServiceProfile003, TestSize.Level1)
832 {
833     string deviceId = "deviceId12";
834     string serviceName = "serviceName12";
835     DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
836     ServiceProfile outServiceProfile;
837     int32_t ret = DeviceProfileManager::GetInstance().GetServiceProfile(deviceId, serviceName, outServiceProfile);
838     EXPECT_EQ(ret, DP_INVALID_PARAMS);
839     DeviceProfileManager::GetInstance().Init();
840 }
841 
842 /**
843  * @tc.name: GetServiceProfile004
844  * @tc.desc: GetServiceProfile failed, Get data fail.
845  * @tc.type: FUNC
846  * @tc.require:
847  */
848 HWTEST_F(DeviceProfileManagerTest, GetServiceProfile004, TestSize.Level1)
849 {
850     string deviceId = ContentSensorManagerUtils::GetInstance().ObtainLocalUdid();
851     string serviceName = "serviceName13";
852     DeviceProfileManager::GetInstance().deviceProfileStore_->UnInit();
853     DeviceProfileManager::GetInstance().isFirst_.store(false);
854     ServiceProfile outServiceProfile;
855     int32_t ret = DeviceProfileManager::GetInstance().GetServiceProfile(deviceId, serviceName, outServiceProfile);
856     EXPECT_EQ(ret, DP_GET_KV_DB_FAIL);
857     DeviceProfileManager::GetInstance().Init();
858     DeviceProfileManager::GetInstance().isFirst_.store(false);
859 }
860 
861 /**
862  * @tc.name: GetCharacteristicProfile001
863  * @tc.desc: GetCharacteristicProfile succeed, GetCharProfile in cache.
864  * @tc.type: FUNC
865  * @tc.require:
866  */
867 HWTEST_F(DeviceProfileManagerTest, GetCharacteristicProfile001, TestSize.Level1)
868 {
869     string deviceId = ContentSensorManagerUtils::GetInstance().ObtainLocalUdid();
870     CharacteristicProfile charProfile5;
871     charProfile5.SetDeviceId(deviceId);
872     charProfile5.SetServiceName("serviceName5");
873     charProfile5.SetCharacteristicKey("characteristicKey5");
874     charProfile5.SetCharacteristicValue("characteristicValue5");
875     DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile5);
876 
877     string serviceName = "serviceName5";
878     string characteristicKey = "characteristicKey5";
879     CharacteristicProfile outCharProfile;
880     int32_t ret = DeviceProfileManager::GetInstance().GetCharacteristicProfile(deviceId, serviceName,
881         characteristicKey, outCharProfile);
882     EXPECT_EQ(ret, DP_SUCCESS);
883 
884     string outDeviceId = outCharProfile.GetDeviceId();
885     outCharProfile.GetServiceName();
886     outCharProfile.GetCharacteristicKey();
887     outCharProfile.GetCharacteristicValue();
888     EXPECT_EQ(outDeviceId, deviceId);
889 }
890 
891 /**
892  * @tc.name: GetCharacteristicProfile002
893  * @tc.desc: GetCharacteristicProfile failed, the profile is invalid.
894  * @tc.type: FUNC
895  * @tc.require:
896  */
897 HWTEST_F(DeviceProfileManagerTest, GetCharacteristicProfile002, TestSize.Level1)
898 {
899     string deviceId = "";
900     string serviceName = "serviceName";
901     string characteristicKey = "characteristicKey";
902     CharacteristicProfile outCharProfile;
903     int32_t ret = DeviceProfileManager::GetInstance().GetCharacteristicProfile(deviceId, serviceName,
904         characteristicKey, outCharProfile);
905     EXPECT_NE(ret, DP_SUCCESS);
906 
907     deviceId = "deviceId";
908     serviceName = "serviceName";
909     characteristicKey = "";
910     ret = DeviceProfileManager::GetInstance().GetCharacteristicProfile(deviceId, serviceName,
911         characteristicKey, outCharProfile);
912     EXPECT_NE(ret, DP_SUCCESS);
913 }
914 
915 /**
916  * @tc.name: GetCharacteristicProfile003
917  * @tc.desc: GetCharacteristicProfile failed, deviceProfileStore is nullptr.
918  * @tc.type: FUNC
919  * @tc.require:
920  */
921 HWTEST_F(DeviceProfileManagerTest, GetCharacteristicProfile003, TestSize.Level1)
922 {
923     string deviceId = "deviceId12";
924     string serviceName = "serviceName12";
925     string characteristicKey = "characteristicKey12";
926     DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
927     CharacteristicProfile outCharProfile;
928     int32_t ret = DeviceProfileManager::GetInstance().GetCharacteristicProfile(deviceId, serviceName,
929         characteristicKey, outCharProfile);
930     EXPECT_EQ(ret, DP_INVALID_PARAMS);
931     DeviceProfileManager::GetInstance().Init();
932 }
933 
934 /**
935  * @tc.name: GetCharacteristicProfile004
936  * @tc.desc: GetCharacteristicProfile failed, Get data fail.
937  * @tc.type: FUNC
938  * @tc.require:
939  */
940 HWTEST_F(DeviceProfileManagerTest, GetCharacteristicProfile004, TestSize.Level1)
941 {
942     string deviceId = ContentSensorManagerUtils::GetInstance().ObtainLocalUdid();
943     string serviceName = "serviceName13";
944     string characteristicKey = "characteristicKey13";
945     DeviceProfileManager::GetInstance().deviceProfileStore_->UnInit();
946     DeviceProfileManager::GetInstance().isFirst_.store(false);
947     CharacteristicProfile outCharProfile;
948     int32_t ret = DeviceProfileManager::GetInstance().GetCharacteristicProfile(deviceId, serviceName,
949         characteristicKey, outCharProfile);
950     EXPECT_EQ(ret, DP_GET_KV_DB_FAIL);
951     DeviceProfileManager::GetInstance().Init();
952     DeviceProfileManager::GetInstance().isFirst_.store(false);
953 }
954 
955 /**
956  * @tc.name: DeleteServiceProfile001
957  * @tc.desc: DeleteServiceProfile succeed.
958  * @tc.type: FUNC
959  * @tc.require:
960  */
961 HWTEST_F(DeviceProfileManagerTest, DeleteServiceProfile001, TestSize.Level1)
962 {
963     ServiceProfile serviceProfile6;
964     ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId6";
965     serviceProfile6.SetDeviceId("deviceId6");
966     serviceProfile6.SetServiceName("serviceName6");
967     serviceProfile6.SetServiceType("serviceType6");
968     DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile6);
969 
970     string deviceId = "deviceId6";
971     string serviceName = "serviceName6";
972     int32_t ret = DeviceProfileManager::GetInstance().DeleteServiceProfile(deviceId, serviceName);
973     EXPECT_EQ(ret, DP_SUCCESS);
974 }
975 
976 /**
977  * @tc.name: DeleteServiceProfile002
978  * @tc.desc: DeleteServiceProfile failed, the profile is invalid.
979  * @tc.type: FUNC
980  * @tc.require:
981  */
982 HWTEST_F(DeviceProfileManagerTest, DeleteServiceProfile002, TestSize.Level1)
983 {
984     string deviceId = "";
985     string serviceName = "serviceName";
986     int32_t ret = DeviceProfileManager::GetInstance().DeleteServiceProfile(deviceId, serviceName);
987     EXPECT_EQ(ret, DP_INVALID_PARAMS);
988 
989     deviceId = "deviceId";
990     serviceName = "";
991     ret = DeviceProfileManager::GetInstance().DeleteServiceProfile(deviceId, serviceName);
992     EXPECT_EQ(ret, DP_INVALID_PARAMS);
993 }
994 
995 /**
996  * @tc.name: DeleteServiceProfile003
997  * @tc.desc: DeleteServiceProfile failed, deviceProfileStore is nullptr.
998  * @tc.type: FUNC
999  * @tc.require:
1000  */
1001 HWTEST_F(DeviceProfileManagerTest, DeleteServiceProfile003, TestSize.Level1)
1002 {
1003     string deviceId = "deviceId14";
1004     string serviceName = "serviceName14";
1005     DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
1006     int32_t ret = DeviceProfileManager::GetInstance().DeleteServiceProfile(deviceId, serviceName);
1007     EXPECT_EQ(ret, DP_INVALID_PARAMS);
1008     DeviceProfileManager::GetInstance().Init();
1009 }
1010 
1011 /**
1012  * @tc.name: DeleteServiceProfile004
1013  * @tc.desc: DeleteServiceProfile failed, DeleteServiceProfile fail.
1014  * @tc.type: FUNC
1015  * @tc.require:
1016  */
1017 HWTEST_F(DeviceProfileManagerTest, DeleteServiceProfile004, TestSize.Level1)
1018 {
1019     ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId15";
1020     string deviceId = "deviceId15";
1021     string serviceName = "serviceName15";
1022     DeviceProfileManager::GetInstance().deviceProfileStore_->UnInit();
1023     DeviceProfileManager::GetInstance().isFirst_.store(false);
1024     int32_t ret = DeviceProfileManager::GetInstance().DeleteServiceProfile(deviceId, serviceName);
1025     EXPECT_EQ(ret, DP_DEL_KV_DB_FAIL);
1026     DeviceProfileManager::GetInstance().Init();
1027     DeviceProfileManager::GetInstance().isFirst_.store(false);
1028 }
1029 
1030 /**
1031  * @tc.name: SetIsMultiUser001
1032  * @tc.desc: SetIsMultiUser Success, SetIsMultiUser Success.
1033  * @tc.type: FUNC
1034  * @tc.require:
1035  */
1036 HWTEST_F(DeviceProfileManagerTest, SetIsMultiUser001, TestSize.Level1)
1037 {
1038     ServiceProfile serviceProfile7;
1039     bool isMultiUser = true;
1040     serviceProfile7.SetIsMultiUser(isMultiUser);
1041     EXPECT_EQ(true, serviceProfile7.isMultiUser_);
1042 }
1043 
1044 /**
1045  * @tc.name: IsMultiUser001
1046  * @tc.desc: IsMultiUser Success, IsMultiUser Success.
1047  * @tc.type: FUNC
1048  * @tc.require:
1049  */
1050 HWTEST_F(DeviceProfileManagerTest, IsMultiUser001, TestSize.Level1)
1051 {
1052     ServiceProfile serviceProfile8;
1053     bool isMultiUser = true;
1054     serviceProfile8.SetIsMultiUser(isMultiUser);
1055     bool ret = serviceProfile8.IsMultiUser();
1056     EXPECT_EQ(true, ret);
1057 }
1058 
1059 /**
1060  * @tc.name: SetUserId001
1061  * @tc.desc: SetUserId Success, SetUserId Success.
1062  * @tc.type: FUNC
1063  * @tc.require:
1064  */
1065 HWTEST_F(DeviceProfileManagerTest, SetUserId001, TestSize.Level1)
1066 {
1067     ServiceProfile serviceProfile9;
1068     int32_t userId = 1;
1069     serviceProfile9.SetUserId(userId);
1070     EXPECT_EQ(1, serviceProfile9.userId_);
1071 }
1072 
1073 /**
1074  * @tc.name: GetUserId001
1075  * @tc.desc: GetUserId Success, GetUserId Success.
1076  * @tc.type: FUNC
1077  * @tc.require:
1078  */
1079 HWTEST_F(DeviceProfileManagerTest, GetUserId001, TestSize.Level1)
1080 {
1081     ServiceProfile serviceProfile9;
1082     int32_t userId = 1;
1083     serviceProfile9.SetUserId(userId);
1084     int32_t outUserId = serviceProfile9.GetUserId();
1085     EXPECT_EQ(outUserId, userId);
1086 }
1087 
1088 /**
1089  * @tc.name: DeleteCharacteristicProfile001
1090  * @tc.desc: DeleteCharacteristicProfile succeed.
1091  * @tc.type: FUNC
1092  * @tc.require:
1093  */
1094 HWTEST_F(DeviceProfileManagerTest, DeleteCharacteristicProfile001, TestSize.Level1)
1095 {
1096     CharacteristicProfile charProfile6;
1097     ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId6";
1098     charProfile6.SetDeviceId("deviceId6");
1099     charProfile6.SetServiceName("serviceName6");
1100     charProfile6.SetCharacteristicKey("characteristicKey6");
1101     charProfile6.SetCharacteristicValue("characteristicValue6");
1102     DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile6);
1103 
1104     string deviceId = "deviceId6";
1105     string serviceName = "serviceName6";
1106     string characteristicKey = "characteristicKey6";
1107     int32_t ret = DeviceProfileManager::GetInstance().DeleteCharacteristicProfile(deviceId, serviceName,
1108         characteristicKey);
1109     EXPECT_EQ(ret, DP_SUCCESS);
1110 }
1111 
1112 /**
1113  * @tc.name: DeleteCharacteristicProfile002
1114  * @tc.desc: DeleteCharacteristicProfile failed, the profile is invalid.
1115  * @tc.type: FUNC
1116  * @tc.require:
1117  */
1118 HWTEST_F(DeviceProfileManagerTest, DeleteCharacteristicProfile002, TestSize.Level1)
1119 {
1120     string deviceId = "";
1121     string serviceName = "serviceName";
1122     string characteristicKey = "characteristicKey";
1123     int32_t ret = DeviceProfileManager::GetInstance().DeleteCharacteristicProfile(deviceId, serviceName,
1124         characteristicKey);
1125     EXPECT_EQ(ret, DP_INVALID_PARAMS);
1126 
1127     deviceId = "deviceId";
1128     serviceName = "serviceName";
1129     characteristicKey = "";
1130     ret = DeviceProfileManager::GetInstance().DeleteCharacteristicProfile(deviceId, serviceName,
1131         characteristicKey);
1132     EXPECT_EQ(ret, DP_INVALID_PARAMS);
1133 }
1134 
1135 /**
1136  * @tc.name: DeleteCharacteristicProfile003
1137  * @tc.desc: DeleteCharacteristicProfile failed, deviceProfileStore is nullptr.
1138  * @tc.type: FUNC
1139  * @tc.require:
1140  */
1141 HWTEST_F(DeviceProfileManagerTest, DeleteCharacteristicProfile003, TestSize.Level1)
1142 {
1143     string deviceId = "deviceId14";
1144     string serviceName = "serviceName14";
1145     string characteristicKey = "characteristicKey14";
1146     DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
1147     int32_t ret = DeviceProfileManager::GetInstance().DeleteCharacteristicProfile(deviceId, serviceName,
1148         characteristicKey);
1149     EXPECT_EQ(ret, DP_INVALID_PARAMS);
1150     DeviceProfileManager::GetInstance().Init();
1151 }
1152 
1153 /**
1154  * @tc.name: DeleteCharacteristicProfile004
1155  * @tc.desc: DeleteCharacteristicProfile failed, DeleteServiceProfile fail.
1156  * @tc.type: FUNC
1157  * @tc.require:
1158  */
1159 HWTEST_F(DeviceProfileManagerTest, DeleteCharacteristicProfile004, TestSize.Level1)
1160 {
1161     ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId15";
1162     string deviceId = "deviceId15";
1163     string serviceName = "serviceName15";
1164     string characteristicKey = "characteristicKey15";
1165     DeviceProfileManager::GetInstance().deviceProfileStore_->UnInit();
1166     DeviceProfileManager::GetInstance().isFirst_.store(false);
1167     int32_t ret = DeviceProfileManager::GetInstance().DeleteCharacteristicProfile(deviceId, serviceName,
1168         characteristicKey);
1169     EXPECT_EQ(ret, DP_DEL_KV_DB_FAIL);
1170     DeviceProfileManager::GetInstance().Init();
1171     DeviceProfileManager::GetInstance().isFirst_.store(false);
1172 }
1173 
1174 /**
1175  * @tc.name: GetAllDeviceProfile001
1176  * @tc.desc: GetAllDeviceProfile succeed.
1177  * @tc.type: FUNC
1178  * @tc.require:
1179  */
1180 HWTEST_F(DeviceProfileManagerTest, GetAllDeviceProfile001, TestSize.Level1)
1181 {
1182     vector<DeviceProfile> deviceProfiles;
1183     int32_t ret = DeviceProfileManager::GetInstance().GetAllDeviceProfile(deviceProfiles);
1184     EXPECT_EQ(ret, DP_SUCCESS);
1185 }
1186 
1187 /**
1188  * @tc.name: GetAllDeviceProfile002
1189  * @tc.desc: GetAllDeviceProfile failed, deviceProfileStore is nullptr.
1190  * @tc.type: FUNC
1191  * @tc.require:
1192  */
1193 HWTEST_F(DeviceProfileManagerTest, GetAllDeviceProfile002, TestSize.Level1)
1194 {
1195     DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
1196     vector<DeviceProfile> deviceProfiles;
1197     int32_t ret = DeviceProfileManager::GetInstance().GetAllDeviceProfile(deviceProfiles);
1198     EXPECT_EQ(ret, DP_INVALID_PARAMS);
1199     DeviceProfileManager::GetInstance().Init();
1200 }
1201 
1202 /**
1203  * @tc.name: GetAllDeviceProfile003
1204  * @tc.desc: GetAllDeviceProfile failed, Get data fail.
1205  * @tc.type: FUNC
1206  * @tc.require:
1207  */
1208 HWTEST_F(DeviceProfileManagerTest, GetAllDeviceProfile003, TestSize.Level1)
1209 {
1210     DeviceProfileManager::GetInstance().deviceProfileStore_->UnInit();
1211     DeviceProfileManager::GetInstance().isFirst_.store(false);
1212     vector<DeviceProfile> deviceProfiles;
1213     int32_t ret = DeviceProfileManager::GetInstance().GetAllDeviceProfile(deviceProfiles);
1214     EXPECT_EQ(ret, DP_GET_KV_DB_FAIL);
1215     DeviceProfileManager::GetInstance().Init();
1216     DeviceProfileManager::GetInstance().isFirst_.store(false);
1217 }
1218 
1219 /**
1220  * @tc.name: GetAllServiceProfile001
1221  * @tc.desc: GetAllServiceProfile succeed.
1222  * @tc.type: FUNC
1223  * @tc.require:
1224  */
1225 HWTEST_F(DeviceProfileManagerTest, GetAllServiceProfile001, TestSize.Level1)
1226 {
1227     vector<ServiceProfile> serviceProfiles;
1228     int32_t ret = DeviceProfileManager::GetInstance().GetAllServiceProfile(serviceProfiles);
1229     EXPECT_EQ(ret, DP_SUCCESS);
1230 }
1231 
1232 /**
1233  * @tc.name: GetAllServiceProfile002
1234  * @tc.desc: GetAllServiceProfile failed, deviceProfileStore is nullptr.
1235  * @tc.type: FUNC
1236  * @tc.require:
1237  */
1238 HWTEST_F(DeviceProfileManagerTest, GetAllServiceProfile002, TestSize.Level1)
1239 {
1240     DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
1241     vector<ServiceProfile> serviceProfiles;
1242     int32_t ret = DeviceProfileManager::GetInstance().GetAllServiceProfile(serviceProfiles);
1243     EXPECT_EQ(ret, DP_INVALID_PARAMS);
1244     DeviceProfileManager::GetInstance().Init();
1245 }
1246 
1247 /**
1248  * @tc.name: GetAllServiceProfile003
1249  * @tc.desc: GetAllServiceProfile failed, Get data fail.
1250  * @tc.type: FUNC
1251  * @tc.require:
1252  */
1253 HWTEST_F(DeviceProfileManagerTest, GetAllServiceProfile003, TestSize.Level1)
1254 {
1255     DeviceProfileManager::GetInstance().deviceProfileStore_->UnInit();
1256     DeviceProfileManager::GetInstance().isFirst_.store(false);
1257     vector<ServiceProfile> serviceProfiles;
1258     int32_t ret = DeviceProfileManager::GetInstance().GetAllServiceProfile(serviceProfiles);
1259     EXPECT_EQ(ret, DP_GET_KV_DB_FAIL);
1260     DeviceProfileManager::GetInstance().Init();
1261     DeviceProfileManager::GetInstance().isFirst_.store(false);
1262 }
1263 
1264 /**
1265  * @tc.name: GetAllCharacteristicProfile001
1266  * @tc.desc: GetAllCharacteristicProfile succeed.
1267  * @tc.type: FUNC
1268  * @tc.require:
1269  */
1270 HWTEST_F(DeviceProfileManagerTest, GetAllCharacteristicProfile001, TestSize.Level1)
1271 {
1272     vector<CharacteristicProfile> charProfiles;
1273     int32_t ret = DeviceProfileManager::GetInstance().GetAllCharacteristicProfile(charProfiles);
1274     EXPECT_EQ(ret, DP_SUCCESS);
1275 }
1276 
1277 /**
1278  * @tc.name: GetAllCharacteristicProfile002
1279  * @tc.desc: GetAllCharacteristicProfile failed, deviceProfileStore is nullptr.
1280  * @tc.type: FUNC
1281  * @tc.require:
1282  */
1283 HWTEST_F(DeviceProfileManagerTest, GetAllCharacteristicProfile002, TestSize.Level1)
1284 {
1285     DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
1286     vector<CharacteristicProfile> charProfiles;
1287     int32_t ret = DeviceProfileManager::GetInstance().GetAllCharacteristicProfile(charProfiles);
1288     EXPECT_EQ(ret, DP_INVALID_PARAMS);
1289     DeviceProfileManager::GetInstance().Init();
1290 }
1291 
1292 /**
1293  * @tc.name: GetAllCharacteristicProfile003
1294  * @tc.desc: GetAllCharacteristicProfile failed, Get data fail.
1295  * @tc.type: FUNC
1296  * @tc.require:
1297  */
1298 HWTEST_F(DeviceProfileManagerTest, GetAllCharacteristicProfile003, TestSize.Level1)
1299 {
1300     DeviceProfileManager::GetInstance().deviceProfileStore_->UnInit();
1301     DeviceProfileManager::GetInstance().isFirst_.store(false);
1302     vector<CharacteristicProfile> charProfiles;
1303     int32_t ret = DeviceProfileManager::GetInstance().GetAllCharacteristicProfile(charProfiles);
1304     EXPECT_EQ(ret, DP_GET_KV_DB_FAIL);
1305     DeviceProfileManager::GetInstance().Init();
1306     DeviceProfileManager::GetInstance().isFirst_.store(false);
1307 }
1308 
1309 /**
1310  * @tc.name: SyncDeviceProfile001
1311  * @tc.desc: SyncDeviceProfile failed, Params is invalid.
1312  * @tc.type: FUNC
1313  * @tc.require:
1314  */
1315 HWTEST_F(DeviceProfileManagerTest, SyncDeviceProfile001, TestSize.Level1)
1316 {
1317     DistributedDeviceProfile::DpSyncOptions syncOptions;
1318     OHOS::sptr<OHOS::IRemoteObject> syncCb = nullptr;
1319 
1320     syncOptions.AddDevice("deviceId1");
1321     syncOptions.AddDevice("deviceId2");
1322     syncOptions.SetSyncMode(SyncMode::MIN);
1323 
1324     int32_t errCode = DeviceProfileManager::GetInstance().SyncDeviceProfile(syncOptions, syncCb);
1325     EXPECT_EQ(errCode, DP_INVALID_PARAMS);
1326 }
1327 
1328 /**
1329  * @tc.name: SyncDeviceProfile002
1330  * @tc.desc: SyncDeviceProfile failed, Params is invalid.
1331  * @tc.type: FUNC
1332  * @tc.require:
1333  */
1334 HWTEST_F(DeviceProfileManagerTest, SyncDeviceProfile002, TestSize.Level1)
1335 {
1336     DistributedDeviceProfile::DpSyncOptions syncOptions;
1337     OHOS::sptr<OHOS::IRemoteObject> syncCb = OHOS::sptr<SyncCompletedCallbackStub>(new SyncCallback());
1338 
1339     syncOptions.AddDevice("deviceId1");
1340     syncOptions.AddDevice("deviceId2");
1341     syncOptions.SetSyncMode(SyncMode::MAX);
1342 
1343     int32_t errCode = DeviceProfileManager::GetInstance().SyncDeviceProfile(syncOptions, syncCb);
1344     EXPECT_EQ(errCode, DP_INVALID_PARAMS);
1345 }
1346 
1347 /**
1348  * @tc.name: DeviceProfileMarshalling001
1349  * @tc.desc: DeviceProfile Marshalling and UnMarshalling succeed.
1350  * @tc.type: FUNC
1351  * @tc.require:
1352  */
1353 HWTEST_F(DeviceProfileManagerTest, DeviceProfileMarshalling001, TestSize.Level1)
1354 {
1355     OHOS::MessageParcel data;
1356     DeviceProfile deviceProfile;
1357     deviceProfile.SetDeviceId("anything");
1358     deviceProfile.SetDeviceName("anything");
1359     deviceProfile.SetManufactureName("anything");
1360     deviceProfile.SetDeviceModel("anything");
1361     deviceProfile.SetStorageCapability(1);
1362     deviceProfile.SetOsSysCap("anything");
1363     deviceProfile.SetOsApiLevel(1);
1364     deviceProfile.SetOsVersion("anything");
1365     deviceProfile.SetOsType(1);
1366 
1367     bool res1 = deviceProfile.Marshalling(data);
1368     EXPECT_EQ(true, res1);
1369 
1370     bool res2 = deviceProfile.UnMarshalling(data);
1371     EXPECT_EQ(true, res2);
1372 }
1373 
1374 /**
1375  * @tc.name: DeviceProfileOperator001
1376  * @tc.desc: DeviceProfileOperator true.
1377  * @tc.type: FUNC
1378  * @tc.require:
1379  */
1380 HWTEST_F(DeviceProfileManagerTest, DeviceProfileOperator001, TestSize.Level1)
1381 {
1382     DeviceProfile deviceProfile1;
1383     deviceProfile1.SetDeviceId("anything1");
1384     deviceProfile1.SetDeviceName("anything1");
1385     deviceProfile1.SetManufactureName("anything1");
1386     deviceProfile1.SetDeviceModel("anything1");
1387     deviceProfile1.SetStorageCapability(1);
1388     deviceProfile1.SetOsSysCap("anything1");
1389     deviceProfile1.SetOsApiLevel(1);
1390     deviceProfile1.SetOsVersion("anything1");
1391     deviceProfile1.SetOsType(1);
1392 
1393     DeviceProfile deviceProfile2;
1394     deviceProfile2.SetDeviceId("anything2");
1395     deviceProfile2.SetDeviceName("anything2");
1396     deviceProfile2.SetManufactureName("anything2");
1397     deviceProfile2.SetDeviceModel("anything2");
1398     deviceProfile2.SetStorageCapability(1);
1399     deviceProfile2.SetOsSysCap("anything2");
1400     deviceProfile2.SetOsApiLevel(1);
1401     deviceProfile2.SetOsVersion("anything2");
1402     deviceProfile2.SetOsType(1);
1403 
1404     bool res = deviceProfile1 != deviceProfile2;
1405     EXPECT_EQ(true, res);
1406 }
1407 
1408 /**
1409  * @tc.name: DeviceProfileDump001
1410  * @tc.desc: DeviceProfileDump succeed.
1411  * @tc.type: FUNC
1412  * @tc.require:
1413  */
1414 HWTEST_F(DeviceProfileManagerTest, DeviceProfileDump001, TestSize.Level1)
1415 {
1416     DeviceProfile deviceProfile;
1417     deviceProfile.SetDeviceId("anything");
1418     deviceProfile.SetDeviceName("anything");
1419     deviceProfile.SetManufactureName("anything");
1420     deviceProfile.SetDeviceModel("anything");
1421     deviceProfile.SetStorageCapability(1);
1422     deviceProfile.SetOsSysCap("anything");
1423     deviceProfile.SetOsApiLevel(1);
1424     deviceProfile.SetOsVersion("anything");
1425     deviceProfile.SetOsType(1);
1426 
1427     string strJson = deviceProfile.dump();
1428     char fistChar = strJson.front();
1429     char lastChar = strJson.back();
1430     EXPECT_EQ('{', fistChar);
1431     EXPECT_EQ('}', lastChar);
1432 }
1433 
1434 /**
1435  * @tc.name: ServiceProfileConstructor001
1436  * @tc.desc: ServiceProfileConstructor succeed.
1437  * @tc.type: FUNC
1438  * @tc.require:
1439  */
1440 HWTEST_F(DeviceProfileManagerTest, ServiceProfileConstructor001, TestSize.Level1)
1441 {
1442     ServiceProfile serviceProfile = ServiceProfile("deviceId", "serviceName", "serviceType");
1443     EXPECT_EQ("deviceId", serviceProfile.GetDeviceId());
1444 }
1445 
1446 /**
1447  * @tc.name: LoadDpSyncAdapter001
1448  * @tc.desc: LoadDpSyncAdapter first branch.
1449  * @tc.type: FUNC
1450  * @tc.require:
1451  */
1452 HWTEST_F(DeviceProfileManagerTest, LoadDpSyncAdapter001, TestSize.Level1)
1453 {
1454     char path[PATH_MAX + 1] = {0x00};
1455     std::string soName = "/system/lib/libdeviceprofileadapter.z.so";
1456     bool ret = false;
1457     if ((soName.length() == 0) || (soName.length() > PATH_MAX) || (realpath(soName.c_str(), path) == nullptr)) {
1458         ret = true;
1459     } else {
1460         DeviceProfileManager::GetInstance().isAdapterSoLoaded_ = true;
1461         ret = DeviceProfileManager::GetInstance().LoadDpSyncAdapter();
1462     }
1463     EXPECT_EQ(true, ret);
1464 }
1465 
1466 /**
1467  * @tc.name: GetInKvDB001
1468  * @tc.desc: GetDeviceProfile,GetServiceProfile, GetCharacteristicProfile succeed, in KV DB.
1469  * @tc.type: FUNC
1470  * @tc.require:
1471  */
1472 HWTEST_F(DeviceProfileManagerTest, GetInKvDB001, TestSize.Level1)
1473 {
1474     string deviceId = ContentSensorManagerUtils::GetInstance().ObtainLocalUdid();
1475     DeviceProfile deviceProfile2;
1476     deviceProfile2.SetDeviceId(deviceId);
1477     deviceProfile2.SetDeviceName("GetInKvDB001_DeviceName");
1478     deviceProfile2.SetManufactureName("GetInKvDB001_ManufactureName");
1479     deviceProfile2.SetDeviceModel("GetInKvDB001_DeviceModel");
1480     deviceProfile2.SetStorageCapability(1);
1481     deviceProfile2.SetOsSysCap("GetInKvDB001_OsSysCap");
1482     deviceProfile2.SetOsApiLevel(1);
1483     deviceProfile2.SetOsVersion("GetInKvDB001_OsVersion");
1484     deviceProfile2.SetOsType(1);
1485     DeviceProfileManager::GetInstance().PutDeviceProfile(deviceProfile2);
1486 
1487     ServiceProfile serviceProfile5;
1488     serviceProfile5.SetDeviceId(deviceId);
1489     serviceProfile5.SetServiceName("GetInKvDB001_ServiceName");
1490     serviceProfile5.SetServiceType("GetInKvDB001_ServiceType");
1491     DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile5);
1492 
1493     CharacteristicProfile charProfile5;
1494     charProfile5.SetDeviceId(deviceId);
1495     charProfile5.SetServiceName("GetInKvDB001_ServiceName");
1496     charProfile5.SetCharacteristicKey("GetInKvDB001_CharacteristicKey");
1497     charProfile5.SetCharacteristicValue("GetInKvDB001_CharacteristicValue");
1498     DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile5);
1499 
1500     ProfileCache::GetInstance().DeleteDeviceProfile(deviceId);
1501     ProfileCache::GetInstance().DeleteServiceProfile("GetInKvDB001_DeviceId", "GetInKvDB001_ServiceName");
1502     ProfileCache::GetInstance().DeleteCharProfile("GetInKvDB001_DeviceId", "GetInKvDB001_ServiceName",
1503                                                             "GetInKvDB001_CharacteristicKey");
1504 
1505     DeviceProfile outDeviceProfile;
1506     int32_t ret1 = DeviceProfileManager::GetInstance().GetDeviceProfile(deviceId, outDeviceProfile);
1507     EXPECT_EQ(ret1, DP_SUCCESS);
1508 
1509     string serviceName2 = "GetInKvDB001_ServiceName";
1510     ServiceProfile outServiceProfile;
1511     int32_t ret2 = DeviceProfileManager::GetInstance().GetServiceProfile(deviceId, serviceName2, outServiceProfile);
1512     EXPECT_EQ(ret2, DP_SUCCESS);
1513 
1514     string serviceName3 = "GetInKvDB001_ServiceName";
1515     string characteristicKey3 = "GetInKvDB001_CharacteristicKey";
1516     CharacteristicProfile outCharProfile;
1517     int32_t ret3 = DeviceProfileManager::GetInstance().GetCharacteristicProfile(deviceId, serviceName3,
1518                                                                                characteristicKey3, outCharProfile);
1519     EXPECT_EQ(ret3, DP_SUCCESS);
1520 }
1521 
1522 /**
1523  * @tc.name: RunloadedFunction001
1524  * @tc.desc: RunloadedFunction001
1525  * @tc.type: FUNC
1526  * @tc.require:
1527  */
1528 HWTEST_F(DeviceProfileManagerTest, RunloadedFunction001, TestSize.Level1)
1529 {
1530     OHOS::sptr<OHOS::IRemoteObject> syncCb = OHOS::sptr<SyncCompletedCallbackStub>(new SyncCallback());
1531     string peerNetworkId = "peerNetworkId";
1532     int32_t ret = DeviceProfileManager::GetInstance().RunloadedFunction(peerNetworkId, syncCb);
1533     EXPECT_EQ(ret, DP_LOAD_SYNC_ADAPTER_FAILED);
1534 }
1535 /**
1536  * @tc.name: RunloadedFunction002
1537  * @tc.desc: RunloadedFunction002
1538  * @tc.type: FUNC
1539  * @tc.require:
1540  */
1541 HWTEST_F(DeviceProfileManagerTest, RunloadedFunction002, TestSize.Level1)
1542 {
1543     OHOS::sptr<OHOS::IRemoteObject> syncCb = OHOS::sptr<SyncCompletedCallbackStub>(new SyncCallback());
1544     string peerNetworkId = "peerNetworkId";
1545     int32_t ret = DeviceProfileManager::GetInstance().RunloadedFunction(peerNetworkId, syncCb);
1546     EXPECT_EQ(ret, DP_LOAD_SYNC_ADAPTER_FAILED);
1547 }
1548 
1549 HWTEST_F(DeviceProfileManagerTest, GetInKvDB002, TestSize.Level1)
1550 {
1551     string deviceId = ContentSensorManagerUtils::GetInstance().ObtainLocalUdid();
1552     DeviceProfile deviceProfile2;
1553     deviceProfile2.SetDeviceId(deviceId);
1554     deviceProfile2.SetDeviceName("GetInKvDB001_DeviceName2");
1555     deviceProfile2.SetManufactureName("GetInKvDB001_ManufactureName2");
1556     deviceProfile2.SetDeviceModel("GetInKvDB001_DeviceModel2");
1557     deviceProfile2.SetStorageCapability(1);
1558     deviceProfile2.SetOsSysCap("GetInKvDB001_OsSysCap2");
1559     deviceProfile2.SetOsApiLevel(1);
1560     deviceProfile2.SetOsVersion("GetInKvDB001_OsVersion2");
1561     deviceProfile2.SetOsType(1);
1562     DeviceProfileManager::GetInstance().PutDeviceProfile(deviceProfile2);
1563 
1564     ServiceProfile serviceProfile5;
1565     serviceProfile5.SetDeviceId(deviceId);
1566     serviceProfile5.SetServiceName("GetInKvDB001_ServiceName2");
1567     serviceProfile5.SetServiceType("GetInKvDB001_ServiceType2");
1568     DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile5);
1569 
1570     CharacteristicProfile charProfile5;
1571     charProfile5.SetDeviceId(deviceId);
1572     charProfile5.SetServiceName("GetInKvDB001_ServiceName2");
1573     charProfile5.SetCharacteristicKey("GetInKvDB001_CharacteristicKey2");
1574     charProfile5.SetCharacteristicValue("GetInKvDB001_CharacteristicValue2");
1575     DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile5);
1576 
1577     ProfileCache::GetInstance().DeleteDeviceProfile(deviceId);
1578     ProfileCache::GetInstance().DeleteServiceProfile("GetInKvDB001_DeviceId2", "GetInKvDB001_ServiceName");
1579     ProfileCache::GetInstance().DeleteCharProfile("GetInKvDB001_DeviceId2", "GetInKvDB001_ServiceName",
1580     "GetInKvDB001_CharacteristicKey2");
1581 
1582     DeviceProfile outDeviceProfile;
1583     DeviceProfileManager::GetInstance().GetDeviceProfile(deviceId, outDeviceProfile);
1584 
1585     string serviceName2 = "GetInKvDB001_ServiceName2";
1586     ServiceProfile outServiceProfile;
1587     DeviceProfileManager::GetInstance().GetServiceProfile(deviceId, serviceName2, outServiceProfile);
1588 
1589     string serviceName3 = "GetInKvDB001_ServiceName2";
1590     string characteristicKey3 = "GetInKvDB001_CharacteristicKey2";
1591     CharacteristicProfile outCharProfile;
1592     int32_t ret = DeviceProfileManager::GetInstance().GetCharacteristicProfile(deviceId, serviceName3,
1593                                                                                 characteristicKey3, outCharProfile);
1594     EXPECT_EQ(ret, DP_SUCCESS);
1595 }
1596 
1597 /**
1598  * @tc.name: HasTrustP2PRelation001
1599  * @tc.desc: param is invalid
1600  * @tc.type: FUNC
1601  * @tc.require:
1602  */
1603 HWTEST_F(DeviceProfileManagerTest, HasTrustP2PRelation001, TestSize.Level1)
1604 {
1605     bool ret = DeviceProfileManager::GetInstance().HasTrustP2PRelation("", 100);
1606     EXPECT_EQ(ret, false);
1607 }
1608 
1609 /**
1610  * @tc.name: HasTrustP2PRelation002
1611  * @tc.desc: HasTrustP2PRelation failed
1612  * @tc.type: FUNC
1613  * @tc.require:
1614  */
1615 HWTEST_F(DeviceProfileManagerTest, HasTrustP2PRelation002, TestSize.Level1)
1616 {
1617     bool ret = DeviceProfileManager::GetInstance().HasTrustP2PRelation("deviceId", 100);
1618     EXPECT_EQ(ret, false);
1619 }
1620 
1621 /**
1622  * @tc.name: IsSameAccount001
1623  * @tc.desc: param is invalid
1624  * @tc.type: FUNC
1625  * @tc.require:
1626  */
1627 HWTEST_F(DeviceProfileManagerTest, IsSameAccount001, TestSize.Level1)
1628 {
1629     bool ret = DeviceProfileManager::GetInstance().IsSameAccount("", 100);
1630     EXPECT_EQ(ret, false);
1631 }
1632 
1633 /**
1634  * @tc.name: IsSameAccount002
1635  * @tc.desc: GetAccessControlProfile failed
1636  * @tc.type: FUNC
1637  * @tc.require:
1638  */
1639 HWTEST_F(DeviceProfileManagerTest, IsSameAccount002, TestSize.Level1)
1640 {
1641     bool ret = DeviceProfileManager::GetInstance().IsSameAccount("deviceId", 100);
1642     EXPECT_EQ(ret, false);
1643 }
1644 
1645 /**
1646  * @tc.name: IsMultiUserValid001
1647  * @tc.desc:
1648  * @tc.type: FUNC
1649  * @tc.require:
1650  */
1651 HWTEST_F(DeviceProfileManagerTest, IsMultiUserValid001, TestSize.Level1)
1652 {
1653     ServiceProfile profile("", "serviceName", "serviceType");
1654     profile.SetIsMultiUser(false);
1655     profile.SetUserId(DEFAULT_USER_ID);
1656 
1657     int32_t result = DeviceProfileManager::GetInstance().IsMultiUserValid(profile);
1658     EXPECT_NE(result, DP_SUCCESS);
1659 }
1660 
1661 /**
1662  * @tc.name: IsMultiUserValid002
1663  * @tc.desc:
1664  * @tc.type: FUNC
1665  * @tc.require:
1666  */
1667 HWTEST_F(DeviceProfileManagerTest, IsMultiUserValid002, TestSize.Level1)
1668 {
1669     ServiceProfile profile("deviceId", "serviceName", "serviceType");
1670     profile.SetIsMultiUser(true);
1671     profile.SetUserId(0);
1672 
1673     int32_t result = DeviceProfileManager::GetInstance().IsMultiUserValid(profile);
1674     EXPECT_NE(result, DP_SUCCESS);
1675 }
1676 
1677 /**
1678  * @tc.name: IsMultiUserValid003
1679  * @tc.desc:
1680  * @tc.type: FUNC
1681  * @tc.require:
1682  */
1683 HWTEST_F(DeviceProfileManagerTest, IsMultiUserValid003, TestSize.Level1)
1684 {
1685     ServiceProfile profile("deviceId", "serviceName", "serviceType");
1686     profile.SetIsMultiUser(false);
1687     profile.SetUserId(DEFAULT_USER_ID + 1);
1688 
1689     int32_t result = DeviceProfileManager::GetInstance().IsMultiUserValid(profile);
1690     EXPECT_NE(result, DP_SUCCESS);
1691 }
1692 
1693 /**
1694  * @tc.name: IsMultiUserValid004
1695  * @tc.desc:
1696  * @tc.type: FUNC
1697  * @tc.require:
1698  */
1699 HWTEST_F(DeviceProfileManagerTest, IsMultiUserValid004, TestSize.Level1)
1700 {
1701     ServiceProfile profile(ProfileCache::GetInstance().GetLocalUdid(), "serviceName", "serviceType");
1702     profile.SetIsMultiUser(true);
1703     profile.SetUserId(333);
1704 
1705     int32_t result = DeviceProfileManager::GetInstance().IsMultiUserValid(profile);
1706     EXPECT_NE(result, DP_SUCCESS);
1707 }
1708 
1709 /**
1710  * @tc.name: IsMultiUserValid005
1711  * @tc.desc:
1712  * @tc.type: FUNC
1713  * @tc.require:
1714  */
1715 HWTEST_F(DeviceProfileManagerTest, IsMultiUserValid005, TestSize.Level1)
1716 {
1717     ServiceProfile profile("deviceId", "serviceName", "serviceType");
1718     profile.SetIsMultiUser(false);
1719     profile.SetUserId(DEFAULT_USER_ID);
1720 
1721     int32_t result = DeviceProfileManager::GetInstance().IsMultiUserValid(profile);
1722     EXPECT_EQ(result, DP_SUCCESS);
1723 }
1724 
1725 /**
1726  * @tc.name: SaveBatchByKeys001
1727  * @tc.desc: entries is empty
1728  * @tc.type: FUNC
1729  * @tc.require:
1730  */
1731 HWTEST_F(DeviceProfileManagerTest, SaveBatchByKeys001, TestSize.Level1)
1732 {
1733     std::map<std::string, std::string> entries;
1734     int32_t result = DeviceProfileManager::GetInstance().SaveBatchByKeys(entries);
1735     EXPECT_EQ(result, DP_SUCCESS);
1736 }
1737 
1738 /**
1739  * @tc.name: SaveBatchByKeys002
1740  * @tc.desc: succeed
1741  * @tc.type: FUNC
1742  * @tc.require:
1743  */
1744 HWTEST_F(DeviceProfileManagerTest, SaveBatchByKeys002, TestSize.Level1)
1745 {
1746     std::map<std::string, std::string> entries;
1747     entries.insert(std::make_pair("key1", "value1"));
1748     int32_t result = DeviceProfileManager::GetInstance().SaveBatchByKeys(entries);
1749     EXPECT_EQ(result, DP_SUCCESS);
1750 }
1751 
1752 /**
1753  * @tc.name: SaveBatchByKeys003
1754  * @tc.desc: deviceProfileStore is nullptr
1755  * @tc.type: FUNC
1756  * @tc.require:
1757  */
1758 HWTEST_F(DeviceProfileManagerTest, SaveBatchByKeys003, TestSize.Level1)
1759 {
1760     std::map<std::string, std::string> entries;
1761     entries.insert(std::make_pair("key1", "value1"));
1762     DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
1763     int32_t result = DeviceProfileManager::GetInstance().SaveBatchByKeys(entries);
1764     EXPECT_NE(result, DP_SUCCESS);
1765     DeviceProfileManager::GetInstance().FixDiffProfiles();
1766     DeviceProfileManager::GetInstance().dpSyncAdapter_ = nullptr;
1767     DeviceProfileManager::GetInstance().FixDiffProfiles();
1768     DeviceProfileManager::GetInstance().FixRemoteDataWhenPeerIsOHBase("remoteUdid", entries);
1769     DeviceProfileManager::GetInstance().FixRemoteDataWhenPeerIsNonOH("remoteUdid");
1770 }
1771 
1772 /**
1773  * @tc.name: GetProfilesByKeyPrefix001
1774  * @tc.desc: DP_INVALID_PARAM
1775  * @tc.type: FUNC
1776  * @tc.require:
1777  */
1778 HWTEST_F(DeviceProfileManagerTest, GetProfilesByKeyPrefix001, TestSize.Level1)
1779 {
1780     std::string udid = "";
1781     std::map<std::string, std::string> values;
1782     int32_t result = DeviceProfileManager::GetInstance().GetProfilesByKeyPrefix(udid, values);
1783     EXPECT_NE(result, DP_SUCCESS);
1784 }
1785 
1786 /**
1787  * @tc.name: GetProfilesByKeyPrefix002
1788  * @tc.desc:
1789  * @tc.type: FUNC
1790  * @tc.require:
1791  */
1792 HWTEST_F(DeviceProfileManagerTest, GetProfilesByKeyPrefix002, TestSize.Level1)
1793 {
1794     std::string udid = "udid";
1795     std::map<std::string, std::string> values;
1796     DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
1797     int32_t result = DeviceProfileManager::GetInstance().GetProfilesByKeyPrefix(udid, values);
1798     EXPECT_NE(result, DP_SUCCESS);
1799 }
1800 
1801 /**
1802  * @tc.name: DeleteRemovedUserData001
1803  * @tc.desc: DeleteRemovedUserData001
1804  * @tc.type: FUNC
1805  * @tc.require:
1806  */
1807 HWTEST_F(DeviceProfileManagerTest, DeleteRemovedUserData001, TestSize.Level1)
1808 {
1809     int32_t userId = -1;
1810     int32_t ret = DeviceProfileManager::GetInstance().DeleteRemovedUserData(userId);
1811     EXPECT_EQ(ret, DP_INVALID_PARAM);
1812 }
1813 
1814 /**
1815  * @tc.name: DeleteRemovedUserData002
1816  * @tc.desc: DeleteRemovedUserData002
1817  * @tc.type: FUNC
1818  * @tc.require:
1819  */
1820 HWTEST_F(DeviceProfileManagerTest, DeleteRemovedUserData002, TestSize.Level1)
1821 {
1822     int32_t userId = 100001;
1823     int32_t ret = DeviceProfileManager::GetInstance().DeleteRemovedUserData(userId);
1824     EXPECT_EQ(ret, DP_INVALID_PARAM);
1825 }
1826 
1827 /**
1828  * @tc.name: DeleteRemovedUserData003
1829  * @tc.desc: DeleteRemovedUserData003
1830  * @tc.type: FUNC
1831  * @tc.require:
1832  */
1833 HWTEST_F(DeviceProfileManagerTest, DeleteRemovedUserData003, TestSize.Level1)
1834 {
1835     int32_t userId = 1;
1836     int32_t ret = DeviceProfileManager::GetInstance().DeleteRemovedUserData(userId);
1837     EXPECT_EQ(ret, DP_SUCCESS);
1838 }
1839 
1840 /**
1841  * @tc.name: DeleteRemovedUserData005
1842  * @tc.desc: DeleteRemovedUserData005
1843  * @tc.type: FUNC
1844  * @tc.require:
1845  */
1846 HWTEST_F(DeviceProfileManagerTest, DeleteRemovedUserData005, TestSize.Level1)
1847 {
1848     int32_t userId = 1;
1849     ContentSensorManagerUtils::GetInstance().localUdid_ = "localUdid";
1850     int32_t ret = DeviceProfileManager::GetInstance().DeleteRemovedUserData(userId);
1851     EXPECT_EQ(ret, DP_GET_KV_DB_FAIL);
1852 }
1853 
1854 /**
1855  * @tc.name: SyncWithNotOHBasedDevice001
1856  * @tc.type: FUNC
1857  * @tc.require:
1858  */
1859 HWTEST_F(DeviceProfileManagerTest, SyncWithNotOHBasedDevice001, TestSize.Level1)
1860 {
1861     std::vector<std::string> notOHBasedDevices;
1862     const std::string callerDescriptor;
1863     sptr<IRemoteObject> syncCompletedCallback;
1864     int32_t ret = DeviceProfileManager::GetInstance().SyncWithNotOHBasedDevice(
1865         notOHBasedDevices, callerDescriptor, syncCompletedCallback);
1866     DeviceProfileManager::GetInstance().SyncWithNotOHBasedDeviceFailed(notOHBasedDevices, syncCompletedCallback);
1867     EXPECT_EQ(ret, DP_LOAD_SYNC_ADAPTER_FAILED);
1868 }
1869 
1870 /**
1871  * @tc.name: GetEntriesByKeys001
1872  * @tc.type: FUNC
1873  * @tc.require:
1874  */
1875 HWTEST_F(DeviceProfileManagerTest, GetEntriesByKeys001, TestSize.Level1)
1876 {
1877     std::unique_ptr<DeviceProfileManager> manager_;
1878     manager_ = std::make_unique<DeviceProfileManager>();
1879     std::vector<std::string> keys;
1880     TrustedDeviceInfo deviceInfo;
1881     deviceInfo.SetNetworkId("networkId");
1882     std::vector<DistributedKv::Entry> ret = manager_->GetEntriesByKeys(keys);
1883     DeviceProfileManager::GetInstance().FixDataOnDeviceOnline(deviceInfo);
1884     DeviceProfileManager::GetInstance().NotifyNotOHBaseOnline(deviceInfo);
1885     DeviceProfileManager::GetInstance().E2ESyncDynamicProfile(deviceInfo);
1886     EXPECT_TRUE(ret.empty());
1887 }
1888 
1889 /**
1890  * @tc.name: GetEntriesByKeys002
1891  * @tc.type: FUNC
1892  * @tc.require:
1893  */
1894 HWTEST_F(DeviceProfileManagerTest, GetEntriesByKeys002, TestSize.Level1)
1895 {
1896     std::unique_ptr<DeviceProfileManager> manager_;
1897     manager_ = std::make_unique<DeviceProfileManager>();
1898     manager_->deviceProfileStore_ = nullptr;
1899     std::vector<std::string> keys = {"key1"};
1900     TrustedDeviceInfo deviceInfo;
1901     std::vector<DistributedKv::Entry> ret = manager_->GetEntriesByKeys(keys);
1902     DeviceProfileManager::GetInstance().OnDeviceOnline(deviceInfo);
1903     DeviceProfileManager::GetInstance().FixDataOnDeviceOnline(deviceInfo);
1904     DeviceProfileManager::GetInstance().NotifyNotOHBaseOnline(deviceInfo);
1905     DeviceProfileManager::GetInstance().E2ESyncDynamicProfile(deviceInfo);
1906     EXPECT_TRUE(ret.empty());
1907 }
1908 
1909 /**
1910  * @tc.name: GetEntriesByKeys003
1911  * @tc.type: FUNC
1912  * @tc.require:
1913  */
1914 HWTEST_F(DeviceProfileManagerTest, GetEntriesByKeys003, TestSize.Level1)
1915 {
1916     std::unique_ptr<DeviceProfileManager> manager_;
1917     std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>("111",
1918         "222",
1919         std::make_shared<KvDataChangeListener>("333"),
1920         std::make_shared<KvSyncCompletedListener>("444"),
1921         std::make_shared<KvDeathRecipient>("555"),
1922         DistributedKv::TYPE_DYNAMICAL);
1923     manager_ = std::make_unique<DeviceProfileManager>();
1924     manager_->deviceProfileStore_ = kvStore;
1925     std::vector<std::string> keys = {"key1"};
1926     TrustedDeviceInfo deviceInfo;
1927     deviceInfo.SetNetworkId("networkId");
1928     deviceInfo.SetOsType(OHOS_TYPE);
1929     std::vector<DistributedKv::Entry> ret = manager_->GetEntriesByKeys(keys);
1930     DeviceProfileManager::GetInstance().OnDeviceOnline(deviceInfo);
1931     DeviceProfileManager::GetInstance().FixDataOnDeviceOnline(deviceInfo);
1932     DeviceProfileManager::GetInstance().NotifyNotOHBaseOnline(deviceInfo);
1933     DeviceProfileManager::GetInstance().E2ESyncDynamicProfile(deviceInfo);
1934     EXPECT_TRUE(ret.empty());
1935 }
1936 
1937 /**
1938  * @tc.name: GetProfilesByOwner001
1939  * @tc.type: FUNC
1940  * @tc.require:
1941  */
1942 HWTEST_F(DeviceProfileManagerTest, GetProfilesByOwner001, TestSize.Level1)
1943 {
1944     std::string uuid;
1945     std::map<std::string, std::string> values;
1946     int32_t ret = DeviceProfileManager::GetInstance().GetProfilesByOwner(uuid, values);
1947     EXPECT_EQ(ret, DP_INVALID_PARAM);
1948 }
1949 
1950 /**
1951  * @tc.name: GetProfilesByOwner002
1952  * @tc.type: FUNC
1953  * @tc.require:
1954  */
1955 HWTEST_F(DeviceProfileManagerTest, GetProfilesByOwner002, TestSize.Level1)
1956 {
1957     std::string uuid = "uuid";
1958     std::map<std::string, std::string> values;
1959     std::unique_ptr<DeviceProfileManager> manager_;
1960     std::shared_ptr<IKVAdapter> kvStore = std::make_shared<KVAdapter>("111",
1961         "222",
1962         std::make_shared<KvDataChangeListener>("333"),
1963         std::make_shared<KvSyncCompletedListener>("444"),
1964         std::make_shared<KvDeathRecipient>("555"),
1965         DistributedKv::TYPE_DYNAMICAL);
1966     manager_ = std::make_unique<DeviceProfileManager>();
1967     manager_->deviceProfileStore_ = kvStore;
1968     int32_t ret = manager_->GetProfilesByOwner(uuid, values);
1969     EXPECT_EQ(ret, DP_GET_DEVICE_ENTRIES_FAIL);
1970 }
1971 
1972 /**
1973  * @tc.name: GetProfilesByOwner003
1974  * @tc.type: FUNC
1975  * @tc.require:
1976  */
1977 HWTEST_F(DeviceProfileManagerTest, GetProfilesByOwner003, TestSize.Level1)
1978 {
1979     std::string uuid = "uuid";
1980     std::map<std::string, std::string> values;
1981     int32_t ret = DeviceProfileManager::GetInstance().GetProfilesByOwner(uuid, values);
1982     EXPECT_EQ(ret, 0);
1983 }
1984 } // namespace DistributedDeviceProfile
1985 } // namespace OHOS
1986