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.SetDeviceTypeName("anything");
166 deviceProfile.SetDeviceTypeId(0);
167 deviceProfile.SetDeviceName("anything");
168 deviceProfile.SetManufactureName("anything");
169 deviceProfile.SetDeviceModel("anything");
170 deviceProfile.SetStorageCapability(1);
171 deviceProfile.SetOsSysCap("anything");
172 deviceProfile.SetOsApiLevel(1);
173 deviceProfile.SetOsVersion("anything");
174 deviceProfile.SetOsType(1);
175
176 int32_t ret = DeviceProfileManager::GetInstance().PutDeviceProfile(deviceProfile);
177 EXPECT_EQ(ret, DP_SUCCESS);
178 }
179
180 /**
181 * @tc.name: PutDeviceProfile002
182 * @tc.desc: PutDeviceProfile failed, the profile is invalid.
183 * @tc.type: FUNC
184 * @tc.require:
185 */
186 HWTEST_F(DeviceProfileManagerTest, PutDeviceProfile002, TestSize.Level1)
187 {
188 DeviceProfile deviceProfile;
189 deviceProfile.SetDeviceId("");
190 deviceProfile.SetDeviceTypeName("anything");
191 deviceProfile.SetDeviceTypeId(0);
192 deviceProfile.SetDeviceName("anything");
193 deviceProfile.SetManufactureName("anything");
194 deviceProfile.SetDeviceModel("anything");
195 deviceProfile.SetStorageCapability(1);
196 deviceProfile.SetOsSysCap("anything");
197 deviceProfile.SetOsApiLevel(1);
198 deviceProfile.SetOsVersion("anything");
199 deviceProfile.SetOsType(1);
200
201 int32_t ret = DeviceProfileManager::GetInstance().PutDeviceProfile(deviceProfile);
202 EXPECT_EQ(ret, DP_INVALID_PARAMS);
203 }
204
205 /**
206 * @tc.name: PutDeviceProfile003
207 * @tc.desc: PutDeviceProfile failed, the profile is exist.
208 * @tc.type: FUNC
209 * @tc.require:
210 */
211 HWTEST_F(DeviceProfileManagerTest, PutDeviceProfile003, TestSize.Level1)
212 {
213 DeviceProfile deviceProfile1;
214 ContentSensorManagerUtils::GetInstance().localUdid_ = "anything1";
215 deviceProfile1.SetDeviceId("anything1");
216 deviceProfile1.SetDeviceTypeName("anything");
217 deviceProfile1.SetDeviceTypeId(0);
218 deviceProfile1.SetDeviceName("anything");
219 deviceProfile1.SetManufactureName("anything");
220 deviceProfile1.SetDeviceModel("anything");
221 deviceProfile1.SetStorageCapability(1);
222 deviceProfile1.SetOsSysCap("anything");
223 deviceProfile1.SetOsApiLevel(1);
224 deviceProfile1.SetOsVersion("anything");
225 deviceProfile1.SetOsType(1);
226
227 DeviceProfile deviceProfile2;
228 deviceProfile2.SetDeviceId("anything1");
229 deviceProfile2.SetDeviceTypeName("anything");
230 deviceProfile2.SetDeviceTypeId(0);
231 deviceProfile2.SetDeviceName("anything");
232 deviceProfile2.SetManufactureName("anything");
233 deviceProfile2.SetDeviceModel("anything");
234 deviceProfile2.SetStorageCapability(1);
235 deviceProfile2.SetOsSysCap("anything");
236 deviceProfile2.SetOsApiLevel(1);
237 deviceProfile2.SetOsVersion("anything");
238 deviceProfile2.SetOsType(1);
239
240 DeviceProfileManager::GetInstance().PutDeviceProfile(deviceProfile1);
241 int32_t ret = DeviceProfileManager::GetInstance().PutDeviceProfile(deviceProfile2);
242 EXPECT_EQ(ret, DP_SUCCESS);
243 }
244
245 /**
246 * @tc.name: PutDeviceProfile004
247 * @tc.desc: PutDeviceProfile failed, deviceProfileStore is nullptr.
248 * @tc.type: FUNC
249 * @tc.require:
250 */
251 HWTEST_F(DeviceProfileManagerTest, PutDeviceProfile004, TestSize.Level1)
252 {
253 DeviceProfile deviceProfile10;
254 deviceProfile10.SetDeviceId("anything10");
255 deviceProfile10.SetDeviceTypeName("anything");
256 deviceProfile10.SetDeviceTypeId(0);
257 deviceProfile10.SetDeviceName("anything");
258 deviceProfile10.SetManufactureName("anything");
259 deviceProfile10.SetDeviceModel("anything");
260 deviceProfile10.SetStorageCapability(1);
261 deviceProfile10.SetOsSysCap("anything");
262 deviceProfile10.SetOsApiLevel(1);
263 deviceProfile10.SetOsVersion("anything");
264 deviceProfile10.SetOsType(1);
265
266 DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
267 int32_t ret = DeviceProfileManager::GetInstance().PutDeviceProfile(deviceProfile10);
268 EXPECT_EQ(ret, DP_INVALID_PARAMS);
269 }
270
271 /**
272 * @tc.name: PutDeviceProfile005
273 * @tc.desc: PutDeviceProfile failed, PutDeviceProfile fail.
274 * @tc.type: FUNC
275 * @tc.require:
276 */
277 HWTEST_F(DeviceProfileManagerTest, PutDeviceProfile005, TestSize.Level1)
278 {
279 DeviceProfile deviceProfile11;
280 ContentSensorManagerUtils::GetInstance().localUdid_ = "anything11";
281 deviceProfile11.SetDeviceId("anything11");
282 deviceProfile11.SetDeviceTypeName("anything");
283 deviceProfile11.SetDeviceTypeId(0);
284 deviceProfile11.SetDeviceName("anything");
285 deviceProfile11.SetManufactureName("anything");
286 deviceProfile11.SetDeviceModel("anything");
287 deviceProfile11.SetStorageCapability(1);
288 deviceProfile11.SetOsSysCap("anything");
289 deviceProfile11.SetOsApiLevel(1);
290 deviceProfile11.SetOsVersion("anything");
291 deviceProfile11.SetOsType(1);
292
293 DeviceProfileManager::GetInstance().deviceProfileStore_->UnInit();
294 DeviceProfileManager::GetInstance().isFirst_.store(false);
295 int32_t ret = DeviceProfileManager::GetInstance().PutDeviceProfile(deviceProfile11);
296 EXPECT_EQ(ret, DP_PUT_KV_DB_FAIL);
297 DeviceProfileManager::GetInstance().Init();
298 DeviceProfileManager::GetInstance().isFirst_.store(false);
299 }
300
301 /**
302 * @tc.name: PutDeviceProfile006
303 * @tc.desc: PutDeviceProfile succeed.
304 * @tc.type: FUNC
305 * @tc.require:
306 */
307 HWTEST_F(DeviceProfileManagerTest, PutDeviceProfile006, TestSize.Level1)
308 {
309 DeviceProfile deviceProfile;
310 ContentSensorManagerUtils::GetInstance().localUdid_ = "anything111";
311 deviceProfile.SetDeviceId("anything111");
312 deviceProfile.SetDeviceTypeName("anything");
313 deviceProfile.SetDeviceTypeId(0);
314 deviceProfile.SetDeviceName("anything");
315 deviceProfile.SetManufactureName("anything");
316 deviceProfile.SetDeviceModel("anything");
317 deviceProfile.SetStorageCapability(1);
318 deviceProfile.SetOsSysCap("anything");
319 deviceProfile.SetOsApiLevel(1);
320 deviceProfile.SetOsVersion("anything");
321 deviceProfile.SetOsType(1);
322 DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
323 int32_t ret = DeviceProfileManager::GetInstance().PutDeviceProfile(deviceProfile);
324 EXPECT_EQ(ret, DP_KV_DB_PTR_NULL);
325 }
326
327 /**
328 * @tc.name: PutServiceProfile001
329 * @tc.desc: PutServiceProfile succeed.
330 * @tc.type: FUNC
331 * @tc.require:
332 */
333 HWTEST_F(DeviceProfileManagerTest, PutServiceProfile001, TestSize.Level1)
334 {
335 ServiceProfile serviceProfile;
336 ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId";
337 serviceProfile.SetDeviceId("deviceId");
338 serviceProfile.SetServiceName("serviceName");
339 serviceProfile.SetServiceType("serviceType");
340
341 int32_t ret = DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile);
342 EXPECT_EQ(ret, DP_SUCCESS);
343 }
344
345 /**
346 * @tc.name: PutServiceProfile002
347 * @tc.desc: PutServiceProfile failed, the profile is invalid.
348 * @tc.type: FUNC
349 * @tc.require:
350 */
351 HWTEST_F(DeviceProfileManagerTest, PutServiceProfile002, TestSize.Level1)
352 {
353 ServiceProfile serviceProfile;
354 serviceProfile.SetDeviceId("");
355 serviceProfile.SetServiceName("serviceName");
356 serviceProfile.SetServiceType("serviceType");
357
358 int32_t ret = DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile);
359 EXPECT_EQ(ret, DP_INVALID_PARAMS);
360 }
361
362 /**
363 * @tc.name: PutServiceProfile003
364 * @tc.desc: PutServiceProfile failed, the profile is exist.
365 * @tc.type: FUNC
366 * @tc.require:
367 */
368 HWTEST_F(DeviceProfileManagerTest, PutServiceProfile003, TestSize.Level1)
369 {
370 ServiceProfile serviceProfile1;
371 ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId1";
372 serviceProfile1.SetDeviceId("deviceId1");
373 serviceProfile1.SetServiceName("serviceName");
374 serviceProfile1.SetServiceType("serviceType");
375
376 ServiceProfile serviceProfile2;
377 serviceProfile2.SetDeviceId("deviceId1");
378 serviceProfile2.SetServiceName("serviceName");
379 serviceProfile2.SetServiceType("serviceType");
380
381 DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile1);
382 int32_t ret = DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile2);
383 EXPECT_EQ(ret, DP_SUCCESS);
384 }
385
386 /**
387 * @tc.name: PutServiceProfile004
388 * @tc.desc: PutServiceProfile failed, deviceProfileStore is nullptr.
389 * @tc.type: FUNC
390 * @tc.require:
391 */
392 HWTEST_F(DeviceProfileManagerTest, PutServiceProfile004, TestSize.Level1)
393 {
394 ServiceProfile serviceProfile10;
395 serviceProfile10.SetDeviceId("deviceId10");
396 serviceProfile10.SetServiceName("serviceName10");
397 serviceProfile10.SetServiceType("serviceType10");
398
399 DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
400 int32_t ret = DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile10);
401 EXPECT_EQ(ret, DP_INVALID_PARAMS);
402 DeviceProfileManager::GetInstance().Init();
403 }
404
405 /**
406 * @tc.name: PutServiceProfile005
407 * @tc.desc: PutServiceProfile failed, PutServiceProfile fail.
408 * @tc.type: FUNC
409 * @tc.require:
410 */
411 HWTEST_F(DeviceProfileManagerTest, PutServiceProfile005, TestSize.Level1)
412 {
413 ServiceProfile serviceProfile11;
414 ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId11";
415 serviceProfile11.SetDeviceId("deviceId11");
416 serviceProfile11.SetServiceName("serviceName11");
417 serviceProfile11.SetServiceType("serviceType11");
418
419 DeviceProfileManager::GetInstance().deviceProfileStore_->UnInit();
420 DeviceProfileManager::GetInstance().isFirst_.store(false);
421 int32_t ret = DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile11);
422 EXPECT_EQ(ret, DP_PUT_KV_DB_FAIL);
423 DeviceProfileManager::GetInstance().Init();
424 DeviceProfileManager::GetInstance().isFirst_.store(false);
425 }
426
427 /**
428 * @tc.name: PutServiceProfile006
429 * @tc.desc: isFirst_.load() == true
430 * @tc.type: FUNC
431 * @tc.require:
432 */
433 HWTEST_F(DeviceProfileManagerTest, PutServiceProfile006, TestSize.Level1)
434 {
435 ServiceProfile serviceProfile;
436 ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId112";
437 serviceProfile.SetDeviceId("deviceId112");
438 serviceProfile.SetServiceName("serviceName");
439 serviceProfile.SetServiceType("serviceType");
440 DeviceProfileManager::GetInstance().isFirst_.store(true);
441 int32_t ret = DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile);
442 DeviceProfileManager::GetInstance().isFirst_.store(false);
443 EXPECT_EQ(ret, DP_SUCCESS);
444 }
445
446 /**
447 * @tc.name: PutServiceProfile007
448 * @tc.desc: deviceProfileStore_ == nullptr
449 * @tc.type: FUNC
450 * @tc.require:
451 */
452 HWTEST_F(DeviceProfileManagerTest, PutServiceProfile007, TestSize.Level1)
453 {
454 ServiceProfile serviceProfile;
455 ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId113";
456 serviceProfile.SetDeviceId("deviceId113");
457 serviceProfile.SetServiceName("serviceName");
458 serviceProfile.SetServiceType("serviceType");
459 DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
460 int32_t ret = DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile);
461 EXPECT_EQ(ret, DP_KV_DB_PTR_NULL);
462 }
463
464 /**
465 * @tc.name: PutServiceProfileBatch001
466 * @tc.desc: PutServiceProfileBatch succeed.
467 * @tc.type: FUNC
468 * @tc.require:
469 */
470 HWTEST_F(DeviceProfileManagerTest, PutServiceProfileBatch001, TestSize.Level1)
471 {
472 vector<ServiceProfile> serviceProfiles;
473 ServiceProfile serviceProfile1;
474 ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId2";
475 serviceProfile1.SetDeviceId("deviceId2");
476 serviceProfile1.SetServiceName("serviceName2");
477 serviceProfile1.SetServiceType("serviceType2");
478 serviceProfiles.push_back(serviceProfile1);
479
480 ServiceProfile serviceProfile2;
481 serviceProfile2.SetDeviceId("deviceId3");
482 serviceProfile2.SetServiceName("serviceName3");
483 serviceProfile2.SetServiceType("serviceType3");
484 serviceProfiles.push_back(serviceProfile2);
485
486 int32_t ret = DeviceProfileManager::GetInstance().PutServiceProfileBatch(serviceProfiles);
487 EXPECT_EQ(ret, DP_SUCCESS);
488 DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
489 ret = DeviceProfileManager::GetInstance().PutServiceProfileBatch(serviceProfiles);
490 EXPECT_EQ(ret, DP_KV_DB_PTR_NULL);
491 }
492
493 /**
494 * @tc.name: PutServiceProfileBatch002
495 * @tc.desc: PutServiceProfileBatch succeed, but first profile is invalid.
496 * @tc.type: FUNC
497 * @tc.require:
498 */
499 HWTEST_F(DeviceProfileManagerTest, PutServiceProfileBatch002, TestSize.Level1)
500 {
501 vector<ServiceProfile> serviceProfiles;
502 ServiceProfile serviceProfile1;
503 serviceProfile1.SetDeviceId("");
504 serviceProfile1.SetServiceName("serviceName");
505 serviceProfile1.SetServiceType("serviceType");
506 serviceProfiles.push_back(serviceProfile1);
507
508 ServiceProfile serviceProfile4;
509 ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId4";
510 serviceProfile4.SetDeviceId("deviceId4");
511 serviceProfile4.SetServiceName("serviceName4");
512 serviceProfile4.SetServiceType("serviceType4");
513 serviceProfiles.push_back(serviceProfile4);
514
515 int32_t ret = DeviceProfileManager::GetInstance().PutServiceProfileBatch(serviceProfiles);
516 EXPECT_EQ(ret, DP_SUCCESS);
517 }
518
519 /**
520 * @tc.name: PutCharacteristicProfile001
521 * @tc.desc: PutCharacteristicProfile succeed.
522 * @tc.type: FUNC
523 * @tc.require:
524 */
525 HWTEST_F(DeviceProfileManagerTest, PutCharacteristicProfile001, TestSize.Level1)
526 {
527 CharacteristicProfile charProfile;
528 ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId";
529 charProfile.SetDeviceId("deviceId");
530 charProfile.SetServiceName("serviceName");
531 charProfile.SetCharacteristicKey("characteristicKey");
532 charProfile.SetCharacteristicValue("characteristicValue");
533
534 int32_t ret = DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile);
535 EXPECT_EQ(ret, DP_SUCCESS);
536 }
537
538 /**
539 * @tc.name: PutCharacteristicProfile002
540 * @tc.desc: PutCharacteristicProfile failed, the profile is invalid.
541 * @tc.type: FUNC
542 * @tc.require:
543 */
544 HWTEST_F(DeviceProfileManagerTest, PutCharacteristicProfile002, TestSize.Level1)
545 {
546 CharacteristicProfile charProfile;
547 charProfile.SetDeviceId("");
548 charProfile.SetServiceName("serviceName");
549 charProfile.SetCharacteristicKey("characteristicKey");
550 charProfile.SetCharacteristicValue("characteristicValue");
551
552 int32_t ret = DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile);
553 EXPECT_EQ(ret, DP_INVALID_PARAMS);
554 }
555
556 /**
557 * @tc.name: PutCharacteristicProfile003
558 * @tc.desc: PutCharacteristicProfile failed, the profile is exist.
559 * @tc.type: FUNC
560 * @tc.require:
561 */
562 HWTEST_F(DeviceProfileManagerTest, PutCharacteristicProfile003, TestSize.Level1)
563 {
564 CharacteristicProfile charProfile1;
565 ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId1";
566 charProfile1.SetDeviceId("deviceId1");
567 charProfile1.SetServiceName("serviceName");
568 charProfile1.SetCharacteristicKey("characteristicKey");
569 charProfile1.SetCharacteristicValue("characteristicValue");
570
571 CharacteristicProfile charProfile2;
572 charProfile2.SetDeviceId("deviceId1");
573 charProfile2.SetServiceName("serviceName");
574 charProfile2.SetCharacteristicKey("characteristicKey");
575 charProfile2.SetCharacteristicValue("characteristicValue");
576
577 DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile1);
578 int32_t ret = DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile2);
579 EXPECT_EQ(ret, DP_SUCCESS);
580 }
581
582 /**
583 * @tc.name: PutCharacteristicProfile004
584 * @tc.desc: PutCharacteristicProfile failed, deviceProfileStore is nullptr.
585 * @tc.type: FUNC
586 * @tc.require:
587 */
588 HWTEST_F(DeviceProfileManagerTest, PutCharacteristicProfile004, TestSize.Level1)
589 {
590 ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId10";
591 CharacteristicProfile charProfile10;
592 charProfile10.SetDeviceId("deviceId10");
593 charProfile10.SetServiceName("serviceName10");
594 charProfile10.SetCharacteristicKey("characteristicKey10");
595 charProfile10.SetCharacteristicValue("characteristicValue10");
596
597 DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
598 int32_t ret = DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile10);
599 EXPECT_EQ(ret, DP_KV_DB_PTR_NULL);
600 DeviceProfileManager::GetInstance().Init();
601 }
602
603 /**
604 * @tc.name: PutCharacteristicProfile005
605 * @tc.desc: PutCharacteristicProfile failed, PutCharacteristicProfile fail.
606 * @tc.type: FUNC
607 * @tc.require:
608 */
609 HWTEST_F(DeviceProfileManagerTest, PutCharacteristicProfile005, TestSize.Level1)
610 {
611 CharacteristicProfile charProfile11;
612 ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId11";
613 charProfile11.SetDeviceId("deviceId11");
614 charProfile11.SetServiceName("serviceName11");
615 charProfile11.SetCharacteristicKey("characteristicKey11");
616 charProfile11.SetCharacteristicValue("characteristicValue11");
617
618 DeviceProfileManager::GetInstance().deviceProfileStore_->UnInit();
619 DeviceProfileManager::GetInstance().isFirst_.store(false);
620 int32_t ret = DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile11);
621 EXPECT_EQ(ret, DP_PUT_KV_DB_FAIL);
622 DeviceProfileManager::GetInstance().Init();
623 DeviceProfileManager::GetInstance().isFirst_.store(false);
624 }
625
626 /**
627 * @tc.name: PutCharacteristicProfile006
628 * @tc.desc: isFirst_.load() = true
629 * @tc.type: FUNC
630 * @tc.require:
631 */
632 HWTEST_F(DeviceProfileManagerTest, PutCharacteristicProfile006, TestSize.Level1)
633 {
634 CharacteristicProfile charProfile;
635 ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId111";
636 charProfile.SetDeviceId("deviceId111");
637 charProfile.SetServiceName("serviceName");
638 charProfile.SetCharacteristicKey("characteristicKey");
639 charProfile.SetCharacteristicValue("characteristicValue");
640 DeviceProfileManager::GetInstance().isFirst_.store(true);
641 int32_t ret = DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile);
642 EXPECT_EQ(ret, DP_SUCCESS);
643 DeviceProfileManager::GetInstance().isFirst_.store(false);
644 }
645
646 /**
647 * @tc.name: PutCharacteristicProfileBatch001
648 * @tc.desc: PutCharacteristicProfileBatch succeed.
649 * @tc.type: FUNC
650 * @tc.require:
651 */
652 HWTEST_F(DeviceProfileManagerTest, PutCharacteristicProfileBatch001, TestSize.Level1)
653 {
654 vector<CharacteristicProfile> charProfiles;
655 CharacteristicProfile charProfile1;
656 ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId2";
657 charProfile1.SetDeviceId("deviceId2");
658 charProfile1.SetServiceName("serviceName2");
659 charProfile1.SetCharacteristicKey("characteristicKey2");
660 charProfile1.SetCharacteristicValue("characteristicValue2");
661 charProfiles.push_back(charProfile1);
662
663 CharacteristicProfile charProfile2;
664 charProfile2.SetDeviceId("deviceId3");
665 charProfile2.SetServiceName("serviceName3");
666 charProfile2.SetCharacteristicKey("characteristicKey3");
667 charProfile2.SetCharacteristicValue("characteristicValue3");
668 charProfiles.push_back(charProfile2);
669
670 int32_t ret = DeviceProfileManager::GetInstance().PutCharacteristicProfileBatch(charProfiles);
671 EXPECT_EQ(ret, DP_SUCCESS);
672
673 DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
674 ret = DeviceProfileManager::GetInstance().PutCharacteristicProfileBatch(charProfiles);
675 EXPECT_EQ(ret, DP_KV_DB_PTR_NULL);
676 }
677
678 /**
679 * @tc.name: PutCharacteristicProfileBatch002
680 * @tc.desc: PutCharacteristicProfileBatch succeed, but first profile is invalid.
681 * @tc.type: FUNC
682 * @tc.require:
683 */
684 HWTEST_F(DeviceProfileManagerTest, PutCharacteristicProfileBatch002, TestSize.Level1)
685 {
686 vector<CharacteristicProfile> charProfiles;
687 CharacteristicProfile charProfile1;
688 charProfile1.SetDeviceId("");
689 charProfile1.SetServiceName("serviceName");
690 charProfile1.SetCharacteristicKey("characteristicKey");
691 charProfile1.SetCharacteristicValue("characteristicValue");
692 charProfiles.push_back(charProfile1);
693
694 CharacteristicProfile charProfile4;
695 ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId4";
696 charProfile4.SetDeviceId("deviceId4");
697 charProfile4.SetServiceName("serviceName4");
698 charProfile4.SetCharacteristicKey("characteristicKey4");
699 charProfile4.SetCharacteristicValue("characteristicValue4");
700 charProfiles.push_back(charProfile4);
701
702 int32_t ret = DeviceProfileManager::GetInstance().PutCharacteristicProfileBatch(charProfiles);
703 EXPECT_EQ(ret, DP_SUCCESS);
704 }
705
706 /**
707 * @tc.name: GetDeviceProfile001
708 * @tc.desc: GetDeviceProfile succeed, GetDeviceProfile in cache.
709 * @tc.type: FUNC
710 * @tc.require:
711 */
712 HWTEST_F(DeviceProfileManagerTest, GetDeviceProfile001, TestSize.Level1)
713 {
714 DeviceProfile deviceProfile2;
715 ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId";
716 string deviceId = ContentSensorManagerUtils::GetInstance().ObtainLocalUdid();
717 deviceProfile2.SetDeviceId(deviceId);
718 deviceProfile2.SetDeviceTypeName("anything");
719 deviceProfile2.SetDeviceTypeId(0);
720 deviceProfile2.SetDeviceName("anything");
721 deviceProfile2.SetManufactureName("anything");
722 deviceProfile2.SetDeviceModel("anything");
723 deviceProfile2.SetStorageCapability(1);
724 deviceProfile2.SetOsSysCap("anything");
725 deviceProfile2.SetOsApiLevel(1);
726 deviceProfile2.SetOsVersion("anything");
727 deviceProfile2.SetOsType(1);
728
729 DeviceProfileManager::GetInstance().PutDeviceProfile(deviceProfile2);
730
731 DeviceProfile outDeviceProfile;
732 int32_t ret = DeviceProfileManager::GetInstance().GetDeviceProfile(deviceId, outDeviceProfile);
733 EXPECT_EQ(ret, DP_SUCCESS);
734 outDeviceProfile.SetDeviceId(deviceId);
735 string outDeviceId = outDeviceProfile.GetDeviceId();
736 outDeviceProfile.GetDeviceTypeName();
737 outDeviceProfile.GetDeviceTypeId();
738 outDeviceProfile.GetDeviceName();
739 outDeviceProfile.GetManufactureName();
740 outDeviceProfile.GetDeviceModel();
741 outDeviceProfile.GetStorageCapability();
742 outDeviceProfile.GetOsSysCap();
743 outDeviceProfile.GetOsApiLevel();
744 outDeviceProfile.GetOsVersion();
745 outDeviceProfile.GetOsType();
746 EXPECT_EQ(outDeviceId, deviceId);
747 }
748
749 /**
750 * @tc.name: GetDeviceProfile002
751 * @tc.desc: GetDeviceProfile failed, the profile is invalid.
752 * @tc.type: FUNC
753 * @tc.require:
754 */
755 HWTEST_F(DeviceProfileManagerTest, GetDeviceProfile002, TestSize.Level1)
756 {
757 string deviceId = "";
758 DeviceProfile outDeviceProfile;
759 int32_t ret = DeviceProfileManager::GetInstance().GetDeviceProfile(deviceId, outDeviceProfile);
760 EXPECT_EQ(ret, DP_INVALID_PARAMS);
761 }
762
763 /**
764 * @tc.name: GetDeviceProfile003
765 * @tc.desc: GetDeviceProfile failed, deviceProfileStore is nullptr.
766 * @tc.type: FUNC
767 * @tc.require:
768 */
769 HWTEST_F(DeviceProfileManagerTest, GetDeviceProfile003, TestSize.Level1)
770 {
771 string deviceId = "anything12";
772 DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
773 DeviceProfile outDeviceProfile;
774 int32_t ret = DeviceProfileManager::GetInstance().GetDeviceProfile(deviceId, outDeviceProfile);
775 EXPECT_EQ(ret, DP_INVALID_PARAMS);
776 DeviceProfileManager::GetInstance().Init();
777 }
778
779 /**
780 * @tc.name: GetDeviceProfile004
781 * @tc.desc: GetDeviceProfile failed, Get data fail.
782 * @tc.type: FUNC
783 * @tc.require:
784 */
785 HWTEST_F(DeviceProfileManagerTest, GetDeviceProfile004, TestSize.Level1)
786 {
787 string deviceId = "#anything13";
788 DeviceProfileManager::GetInstance().deviceProfileStore_->UnInit();
789 DeviceProfileManager::GetInstance().isFirst_.store(false);
790 DeviceProfile outDeviceProfile;
791 int32_t ret = DeviceProfileManager::GetInstance().GetDeviceProfile(deviceId, outDeviceProfile);
792 EXPECT_EQ(ret, DP_INVALID_PARAMS);
793 DeviceProfileManager::GetInstance().Init();
794 DeviceProfileManager::GetInstance().isFirst_.store(false);
795 }
796
797 /**
798 * @tc.name: GetServiceProfile001
799 * @tc.desc: GetServiceProfile succeed, GetServiceProfile in cache.
800 * @tc.type: FUNC
801 * @tc.require:
802 */
803 HWTEST_F(DeviceProfileManagerTest, GetServiceProfile001, TestSize.Level1)
804 {
805 string deviceId = ContentSensorManagerUtils::GetInstance().ObtainLocalUdid();
806 ServiceProfile serviceProfile5;
807 serviceProfile5.SetDeviceId(deviceId);
808 serviceProfile5.SetServiceName("serviceName5");
809 serviceProfile5.SetServiceType("serviceType5");
810 DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile5);
811
812 string serviceName = "serviceName5";
813 ServiceProfile outServiceProfile;
814 int32_t ret = DeviceProfileManager::GetInstance().GetServiceProfile(deviceId, serviceName, outServiceProfile);
815 EXPECT_EQ(ret, DP_SUCCESS);
816
817 string outDeviceId = outServiceProfile.GetDeviceId();
818 outServiceProfile.GetServiceName();
819 outServiceProfile.GetServiceType();
820 EXPECT_EQ(outDeviceId, deviceId);
821 }
822
823 /**
824 * @tc.name: GetServiceProfile002
825 * @tc.desc: GetServiceProfile failed, the profile is invalid.
826 * @tc.type: FUNC
827 * @tc.require:
828 */
829 HWTEST_F(DeviceProfileManagerTest, GetServiceProfile002, TestSize.Level1)
830 {
831 string deviceId = "";
832 string serviceName = "serviceName";
833 ServiceProfile outServiceProfile;
834 int32_t ret = DeviceProfileManager::GetInstance().GetServiceProfile(deviceId, serviceName, outServiceProfile);
835 EXPECT_EQ(ret, DP_INVALID_PARAMS);
836
837 deviceId = "deviceId";
838 serviceName = "";
839 ret = DeviceProfileManager::GetInstance().GetServiceProfile(deviceId, serviceName, outServiceProfile);
840 EXPECT_EQ(ret, DP_INVALID_PARAMS);
841 }
842
843 /**
844 * @tc.name: GetServiceProfile003
845 * @tc.desc: GetServiceProfile failed, deviceProfileStore is nullptr.
846 * @tc.type: FUNC
847 * @tc.require:
848 */
849 HWTEST_F(DeviceProfileManagerTest, GetServiceProfile003, TestSize.Level1)
850 {
851 string deviceId = "deviceId12";
852 string serviceName = "serviceName12";
853 DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
854 ServiceProfile outServiceProfile;
855 int32_t ret = DeviceProfileManager::GetInstance().GetServiceProfile(deviceId, serviceName, outServiceProfile);
856 EXPECT_EQ(ret, DP_INVALID_PARAMS);
857 DeviceProfileManager::GetInstance().Init();
858 }
859
860 /**
861 * @tc.name: GetServiceProfile004
862 * @tc.desc: GetServiceProfile failed, Get data fail.
863 * @tc.type: FUNC
864 * @tc.require:
865 */
866 HWTEST_F(DeviceProfileManagerTest, GetServiceProfile004, TestSize.Level1)
867 {
868 string deviceId = ContentSensorManagerUtils::GetInstance().ObtainLocalUdid();
869 string serviceName = "serviceName13";
870 DeviceProfileManager::GetInstance().deviceProfileStore_->UnInit();
871 DeviceProfileManager::GetInstance().isFirst_.store(false);
872 ServiceProfile outServiceProfile;
873 int32_t ret = DeviceProfileManager::GetInstance().GetServiceProfile(deviceId, serviceName, outServiceProfile);
874 EXPECT_EQ(ret, DP_GET_KV_DB_FAIL);
875 DeviceProfileManager::GetInstance().Init();
876 DeviceProfileManager::GetInstance().isFirst_.store(false);
877 }
878
879 /**
880 * @tc.name: GetCharacteristicProfile001
881 * @tc.desc: GetCharacteristicProfile succeed, GetCharProfile in cache.
882 * @tc.type: FUNC
883 * @tc.require:
884 */
885 HWTEST_F(DeviceProfileManagerTest, GetCharacteristicProfile001, TestSize.Level1)
886 {
887 string deviceId = ContentSensorManagerUtils::GetInstance().ObtainLocalUdid();
888 CharacteristicProfile charProfile5;
889 charProfile5.SetDeviceId(deviceId);
890 charProfile5.SetServiceName("serviceName5");
891 charProfile5.SetCharacteristicKey("characteristicKey5");
892 charProfile5.SetCharacteristicValue("characteristicValue5");
893 DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile5);
894
895 string serviceName = "serviceName5";
896 string characteristicKey = "characteristicKey5";
897 CharacteristicProfile outCharProfile;
898 int32_t ret = DeviceProfileManager::GetInstance().GetCharacteristicProfile(deviceId, serviceName,
899 characteristicKey, outCharProfile);
900 EXPECT_EQ(ret, DP_SUCCESS);
901
902 string outDeviceId = outCharProfile.GetDeviceId();
903 outCharProfile.GetServiceName();
904 outCharProfile.GetCharacteristicKey();
905 outCharProfile.GetCharacteristicValue();
906 EXPECT_EQ(outDeviceId, deviceId);
907 }
908
909 /**
910 * @tc.name: GetCharacteristicProfile002
911 * @tc.desc: GetCharacteristicProfile failed, the profile is invalid.
912 * @tc.type: FUNC
913 * @tc.require:
914 */
915 HWTEST_F(DeviceProfileManagerTest, GetCharacteristicProfile002, TestSize.Level1)
916 {
917 string deviceId = "";
918 string serviceName = "serviceName";
919 string characteristicKey = "characteristicKey";
920 CharacteristicProfile outCharProfile;
921 int32_t ret = DeviceProfileManager::GetInstance().GetCharacteristicProfile(deviceId, serviceName,
922 characteristicKey, outCharProfile);
923 EXPECT_EQ(ret, DP_INVALID_PARAMS);
924
925 deviceId = "deviceId";
926 serviceName = "serviceName";
927 characteristicKey = "";
928 ret = DeviceProfileManager::GetInstance().GetCharacteristicProfile(deviceId, serviceName,
929 characteristicKey, outCharProfile);
930 EXPECT_EQ(ret, DP_INVALID_PARAMS);
931 }
932
933 /**
934 * @tc.name: GetCharacteristicProfile003
935 * @tc.desc: GetCharacteristicProfile failed, deviceProfileStore is nullptr.
936 * @tc.type: FUNC
937 * @tc.require:
938 */
939 HWTEST_F(DeviceProfileManagerTest, GetCharacteristicProfile003, TestSize.Level1)
940 {
941 string deviceId = "deviceId12";
942 string serviceName = "serviceName12";
943 string characteristicKey = "characteristicKey12";
944 DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
945 CharacteristicProfile outCharProfile;
946 int32_t ret = DeviceProfileManager::GetInstance().GetCharacteristicProfile(deviceId, serviceName,
947 characteristicKey, outCharProfile);
948 EXPECT_EQ(ret, DP_INVALID_PARAMS);
949 DeviceProfileManager::GetInstance().Init();
950 }
951
952 /**
953 * @tc.name: GetCharacteristicProfile004
954 * @tc.desc: GetCharacteristicProfile failed, Get data fail.
955 * @tc.type: FUNC
956 * @tc.require:
957 */
958 HWTEST_F(DeviceProfileManagerTest, GetCharacteristicProfile004, TestSize.Level1)
959 {
960 string deviceId = ContentSensorManagerUtils::GetInstance().ObtainLocalUdid();
961 string serviceName = "serviceName13";
962 string characteristicKey = "characteristicKey13";
963 DeviceProfileManager::GetInstance().deviceProfileStore_->UnInit();
964 DeviceProfileManager::GetInstance().isFirst_.store(false);
965 CharacteristicProfile outCharProfile;
966 int32_t ret = DeviceProfileManager::GetInstance().GetCharacteristicProfile(deviceId, serviceName,
967 characteristicKey, outCharProfile);
968 EXPECT_EQ(ret, DP_GET_KV_DB_FAIL);
969 DeviceProfileManager::GetInstance().Init();
970 DeviceProfileManager::GetInstance().isFirst_.store(false);
971 }
972
973 /**
974 * @tc.name: DeleteServiceProfile001
975 * @tc.desc: DeleteServiceProfile succeed.
976 * @tc.type: FUNC
977 * @tc.require:
978 */
979 HWTEST_F(DeviceProfileManagerTest, DeleteServiceProfile001, TestSize.Level1)
980 {
981 ServiceProfile serviceProfile6;
982 ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId6";
983 serviceProfile6.SetDeviceId("deviceId6");
984 serviceProfile6.SetServiceName("serviceName6");
985 serviceProfile6.SetServiceType("serviceType6");
986 DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile6);
987
988 string deviceId = "deviceId6";
989 string serviceName = "serviceName6";
990 int32_t ret = DeviceProfileManager::GetInstance().DeleteServiceProfile(deviceId, serviceName);
991 EXPECT_EQ(ret, DP_SUCCESS);
992 }
993
994 /**
995 * @tc.name: DeleteServiceProfile002
996 * @tc.desc: DeleteServiceProfile failed, the profile is invalid.
997 * @tc.type: FUNC
998 * @tc.require:
999 */
1000 HWTEST_F(DeviceProfileManagerTest, DeleteServiceProfile002, TestSize.Level1)
1001 {
1002 string deviceId = "";
1003 string serviceName = "serviceName";
1004 int32_t ret = DeviceProfileManager::GetInstance().DeleteServiceProfile(deviceId, serviceName);
1005 EXPECT_EQ(ret, DP_INVALID_PARAMS);
1006
1007 deviceId = "deviceId";
1008 serviceName = "";
1009 ret = DeviceProfileManager::GetInstance().DeleteServiceProfile(deviceId, serviceName);
1010 EXPECT_EQ(ret, DP_INVALID_PARAMS);
1011 }
1012
1013 /**
1014 * @tc.name: DeleteServiceProfile003
1015 * @tc.desc: DeleteServiceProfile failed, deviceProfileStore is nullptr.
1016 * @tc.type: FUNC
1017 * @tc.require:
1018 */
1019 HWTEST_F(DeviceProfileManagerTest, DeleteServiceProfile003, TestSize.Level1)
1020 {
1021 string deviceId = "deviceId14";
1022 string serviceName = "serviceName14";
1023 DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
1024 int32_t ret = DeviceProfileManager::GetInstance().DeleteServiceProfile(deviceId, serviceName);
1025 EXPECT_EQ(ret, DP_INVALID_PARAMS);
1026 DeviceProfileManager::GetInstance().Init();
1027 }
1028
1029 /**
1030 * @tc.name: DeleteServiceProfile004
1031 * @tc.desc: DeleteServiceProfile failed, DeleteServiceProfile fail.
1032 * @tc.type: FUNC
1033 * @tc.require:
1034 */
1035 HWTEST_F(DeviceProfileManagerTest, DeleteServiceProfile004, TestSize.Level1)
1036 {
1037 ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId15";
1038 string deviceId = "deviceId15";
1039 string serviceName = "serviceName15";
1040 DeviceProfileManager::GetInstance().deviceProfileStore_->UnInit();
1041 DeviceProfileManager::GetInstance().isFirst_.store(false);
1042 int32_t ret = DeviceProfileManager::GetInstance().DeleteServiceProfile(deviceId, serviceName);
1043 EXPECT_EQ(ret, DP_DEL_KV_DB_FAIL);
1044 DeviceProfileManager::GetInstance().Init();
1045 DeviceProfileManager::GetInstance().isFirst_.store(false);
1046 }
1047
1048 /**
1049 * @tc.name: DeleteCharacteristicProfile001
1050 * @tc.desc: DeleteCharacteristicProfile succeed.
1051 * @tc.type: FUNC
1052 * @tc.require:
1053 */
1054 HWTEST_F(DeviceProfileManagerTest, DeleteCharacteristicProfile001, TestSize.Level1)
1055 {
1056 CharacteristicProfile charProfile6;
1057 ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId6";
1058 charProfile6.SetDeviceId("deviceId6");
1059 charProfile6.SetServiceName("serviceName6");
1060 charProfile6.SetCharacteristicKey("characteristicKey6");
1061 charProfile6.SetCharacteristicValue("characteristicValue6");
1062 DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile6);
1063
1064 string deviceId = "deviceId6";
1065 string serviceName = "serviceName6";
1066 string characteristicKey = "characteristicKey6";
1067 int32_t ret = DeviceProfileManager::GetInstance().DeleteCharacteristicProfile(deviceId, serviceName,
1068 characteristicKey);
1069 EXPECT_EQ(ret, DP_SUCCESS);
1070 }
1071
1072 /**
1073 * @tc.name: DeleteCharacteristicProfile002
1074 * @tc.desc: DeleteCharacteristicProfile failed, the profile is invalid.
1075 * @tc.type: FUNC
1076 * @tc.require:
1077 */
1078 HWTEST_F(DeviceProfileManagerTest, DeleteCharacteristicProfile002, TestSize.Level1)
1079 {
1080 string deviceId = "";
1081 string serviceName = "serviceName";
1082 string characteristicKey = "characteristicKey";
1083 int32_t ret = DeviceProfileManager::GetInstance().DeleteCharacteristicProfile(deviceId, serviceName,
1084 characteristicKey);
1085 EXPECT_EQ(ret, DP_INVALID_PARAMS);
1086
1087 deviceId = "deviceId";
1088 serviceName = "serviceName";
1089 characteristicKey = "";
1090 ret = DeviceProfileManager::GetInstance().DeleteCharacteristicProfile(deviceId, serviceName,
1091 characteristicKey);
1092 EXPECT_EQ(ret, DP_INVALID_PARAMS);
1093 }
1094
1095 /**
1096 * @tc.name: DeleteCharacteristicProfile003
1097 * @tc.desc: DeleteCharacteristicProfile failed, deviceProfileStore is nullptr.
1098 * @tc.type: FUNC
1099 * @tc.require:
1100 */
1101 HWTEST_F(DeviceProfileManagerTest, DeleteCharacteristicProfile003, TestSize.Level1)
1102 {
1103 string deviceId = "deviceId14";
1104 string serviceName = "serviceName14";
1105 string characteristicKey = "characteristicKey14";
1106 DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
1107 int32_t ret = DeviceProfileManager::GetInstance().DeleteCharacteristicProfile(deviceId, serviceName,
1108 characteristicKey);
1109 EXPECT_EQ(ret, DP_INVALID_PARAMS);
1110 DeviceProfileManager::GetInstance().Init();
1111 }
1112
1113 /**
1114 * @tc.name: DeleteCharacteristicProfile004
1115 * @tc.desc: DeleteCharacteristicProfile failed, DeleteServiceProfile fail.
1116 * @tc.type: FUNC
1117 * @tc.require:
1118 */
1119 HWTEST_F(DeviceProfileManagerTest, DeleteCharacteristicProfile004, TestSize.Level1)
1120 {
1121 ContentSensorManagerUtils::GetInstance().localUdid_ = "deviceId15";
1122 string deviceId = "deviceId15";
1123 string serviceName = "serviceName15";
1124 string characteristicKey = "characteristicKey15";
1125 DeviceProfileManager::GetInstance().deviceProfileStore_->UnInit();
1126 DeviceProfileManager::GetInstance().isFirst_.store(false);
1127 int32_t ret = DeviceProfileManager::GetInstance().DeleteCharacteristicProfile(deviceId, serviceName,
1128 characteristicKey);
1129 EXPECT_EQ(ret, DP_DEL_KV_DB_FAIL);
1130 DeviceProfileManager::GetInstance().Init();
1131 DeviceProfileManager::GetInstance().isFirst_.store(false);
1132 }
1133
1134 /**
1135 * @tc.name: GetAllDeviceProfile001
1136 * @tc.desc: GetAllDeviceProfile succeed.
1137 * @tc.type: FUNC
1138 * @tc.require:
1139 */
1140 HWTEST_F(DeviceProfileManagerTest, GetAllDeviceProfile001, TestSize.Level1)
1141 {
1142 vector<DeviceProfile> deviceProfiles;
1143 int32_t ret = DeviceProfileManager::GetInstance().GetAllDeviceProfile(deviceProfiles);
1144 EXPECT_EQ(ret, DP_SUCCESS);
1145 }
1146
1147 /**
1148 * @tc.name: GetAllDeviceProfile002
1149 * @tc.desc: GetAllDeviceProfile failed, deviceProfileStore is nullptr.
1150 * @tc.type: FUNC
1151 * @tc.require:
1152 */
1153 HWTEST_F(DeviceProfileManagerTest, GetAllDeviceProfile002, TestSize.Level1)
1154 {
1155 DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
1156 vector<DeviceProfile> deviceProfiles;
1157 int32_t ret = DeviceProfileManager::GetInstance().GetAllDeviceProfile(deviceProfiles);
1158 EXPECT_EQ(ret, DP_INVALID_PARAMS);
1159 DeviceProfileManager::GetInstance().Init();
1160 }
1161
1162 /**
1163 * @tc.name: GetAllDeviceProfile003
1164 * @tc.desc: GetAllDeviceProfile failed, Get data fail.
1165 * @tc.type: FUNC
1166 * @tc.require:
1167 */
1168 HWTEST_F(DeviceProfileManagerTest, GetAllDeviceProfile003, TestSize.Level1)
1169 {
1170 DeviceProfileManager::GetInstance().deviceProfileStore_->UnInit();
1171 DeviceProfileManager::GetInstance().isFirst_.store(false);
1172 vector<DeviceProfile> deviceProfiles;
1173 int32_t ret = DeviceProfileManager::GetInstance().GetAllDeviceProfile(deviceProfiles);
1174 EXPECT_EQ(ret, DP_GET_KV_DB_FAIL);
1175 DeviceProfileManager::GetInstance().Init();
1176 DeviceProfileManager::GetInstance().isFirst_.store(false);
1177 }
1178
1179 /**
1180 * @tc.name: GetAllServiceProfile001
1181 * @tc.desc: GetAllServiceProfile succeed.
1182 * @tc.type: FUNC
1183 * @tc.require:
1184 */
1185 HWTEST_F(DeviceProfileManagerTest, GetAllServiceProfile001, TestSize.Level1)
1186 {
1187 vector<ServiceProfile> serviceProfiles;
1188 int32_t ret = DeviceProfileManager::GetInstance().GetAllServiceProfile(serviceProfiles);
1189 EXPECT_EQ(ret, DP_SUCCESS);
1190 }
1191
1192 /**
1193 * @tc.name: GetAllServiceProfile002
1194 * @tc.desc: GetAllServiceProfile failed, deviceProfileStore is nullptr.
1195 * @tc.type: FUNC
1196 * @tc.require:
1197 */
1198 HWTEST_F(DeviceProfileManagerTest, GetAllServiceProfile002, TestSize.Level1)
1199 {
1200 DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
1201 vector<ServiceProfile> serviceProfiles;
1202 int32_t ret = DeviceProfileManager::GetInstance().GetAllServiceProfile(serviceProfiles);
1203 EXPECT_EQ(ret, DP_INVALID_PARAMS);
1204 DeviceProfileManager::GetInstance().Init();
1205 }
1206
1207 /**
1208 * @tc.name: GetAllServiceProfile003
1209 * @tc.desc: GetAllServiceProfile failed, Get data fail.
1210 * @tc.type: FUNC
1211 * @tc.require:
1212 */
1213 HWTEST_F(DeviceProfileManagerTest, GetAllServiceProfile003, TestSize.Level1)
1214 {
1215 DeviceProfileManager::GetInstance().deviceProfileStore_->UnInit();
1216 DeviceProfileManager::GetInstance().isFirst_.store(false);
1217 vector<ServiceProfile> serviceProfiles;
1218 int32_t ret = DeviceProfileManager::GetInstance().GetAllServiceProfile(serviceProfiles);
1219 EXPECT_EQ(ret, DP_GET_KV_DB_FAIL);
1220 DeviceProfileManager::GetInstance().Init();
1221 DeviceProfileManager::GetInstance().isFirst_.store(false);
1222 }
1223
1224 /**
1225 * @tc.name: GetAllCharacteristicProfile001
1226 * @tc.desc: GetAllCharacteristicProfile succeed.
1227 * @tc.type: FUNC
1228 * @tc.require:
1229 */
1230 HWTEST_F(DeviceProfileManagerTest, GetAllCharacteristicProfile001, TestSize.Level1)
1231 {
1232 vector<CharacteristicProfile> charProfiles;
1233 int32_t ret = DeviceProfileManager::GetInstance().GetAllCharacteristicProfile(charProfiles);
1234 EXPECT_EQ(ret, DP_SUCCESS);
1235 }
1236
1237 /**
1238 * @tc.name: GetAllCharacteristicProfile002
1239 * @tc.desc: GetAllCharacteristicProfile failed, deviceProfileStore is nullptr.
1240 * @tc.type: FUNC
1241 * @tc.require:
1242 */
1243 HWTEST_F(DeviceProfileManagerTest, GetAllCharacteristicProfile002, TestSize.Level1)
1244 {
1245 DeviceProfileManager::GetInstance().deviceProfileStore_ = nullptr;
1246 vector<CharacteristicProfile> charProfiles;
1247 int32_t ret = DeviceProfileManager::GetInstance().GetAllCharacteristicProfile(charProfiles);
1248 EXPECT_EQ(ret, DP_INVALID_PARAMS);
1249 DeviceProfileManager::GetInstance().Init();
1250 }
1251
1252 /**
1253 * @tc.name: GetAllCharacteristicProfile003
1254 * @tc.desc: GetAllCharacteristicProfile failed, Get data fail.
1255 * @tc.type: FUNC
1256 * @tc.require:
1257 */
1258 HWTEST_F(DeviceProfileManagerTest, GetAllCharacteristicProfile003, TestSize.Level1)
1259 {
1260 DeviceProfileManager::GetInstance().deviceProfileStore_->UnInit();
1261 DeviceProfileManager::GetInstance().isFirst_.store(false);
1262 vector<CharacteristicProfile> charProfiles;
1263 int32_t ret = DeviceProfileManager::GetInstance().GetAllCharacteristicProfile(charProfiles);
1264 EXPECT_EQ(ret, DP_GET_KV_DB_FAIL);
1265 DeviceProfileManager::GetInstance().Init();
1266 DeviceProfileManager::GetInstance().isFirst_.store(false);
1267 }
1268
1269 /**
1270 * @tc.name: SyncDeviceProfile001
1271 * @tc.desc: SyncDeviceProfile failed, Params is invalid.
1272 * @tc.type: FUNC
1273 * @tc.require:
1274 */
1275 HWTEST_F(DeviceProfileManagerTest, SyncDeviceProfile001, TestSize.Level1)
1276 {
1277 DistributedDeviceProfile::DpSyncOptions syncOptions;
1278 OHOS::sptr<OHOS::IRemoteObject> syncCb = nullptr;
1279
1280 syncOptions.AddDevice("deviceId1");
1281 syncOptions.AddDevice("deviceId2");
1282 syncOptions.SetSyncMode(SyncMode::MIN);
1283
1284 int32_t errCode = DeviceProfileManager::GetInstance().SyncDeviceProfile(syncOptions, syncCb);
1285 EXPECT_EQ(errCode, DP_INVALID_PARAMS);
1286 }
1287
1288 /**
1289 * @tc.name: SyncDeviceProfile002
1290 * @tc.desc: SyncDeviceProfile failed, Params is invalid.
1291 * @tc.type: FUNC
1292 * @tc.require:
1293 */
1294 HWTEST_F(DeviceProfileManagerTest, SyncDeviceProfile002, TestSize.Level1)
1295 {
1296 DistributedDeviceProfile::DpSyncOptions syncOptions;
1297 OHOS::sptr<OHOS::IRemoteObject> syncCb = OHOS::sptr<SyncCompletedCallbackStub>(new SyncCallback());
1298
1299 syncOptions.AddDevice("deviceId1");
1300 syncOptions.AddDevice("deviceId2");
1301 syncOptions.SetSyncMode(SyncMode::MAX);
1302
1303 int32_t errCode = DeviceProfileManager::GetInstance().SyncDeviceProfile(syncOptions, syncCb);
1304 EXPECT_EQ(errCode, DP_INVALID_PARAMS);
1305 }
1306
1307 /**
1308 * @tc.name: DeviceProfileMarshalling001
1309 * @tc.desc: DeviceProfile Marshalling and UnMarshalling succeed.
1310 * @tc.type: FUNC
1311 * @tc.require:
1312 */
1313 HWTEST_F(DeviceProfileManagerTest, DeviceProfileMarshalling001, TestSize.Level1)
1314 {
1315 OHOS::MessageParcel data;
1316 DeviceProfile deviceProfile;
1317 deviceProfile.SetDeviceId("anything");
1318 deviceProfile.SetDeviceTypeName("anything");
1319 deviceProfile.SetDeviceTypeId(0);
1320 deviceProfile.SetDeviceName("anything");
1321 deviceProfile.SetManufactureName("anything");
1322 deviceProfile.SetDeviceModel("anything");
1323 deviceProfile.SetStorageCapability(1);
1324 deviceProfile.SetOsSysCap("anything");
1325 deviceProfile.SetOsApiLevel(1);
1326 deviceProfile.SetOsVersion("anything");
1327 deviceProfile.SetOsType(1);
1328
1329 bool res1 = deviceProfile.Marshalling(data);
1330 EXPECT_EQ(true, res1);
1331
1332 bool res2 = deviceProfile.UnMarshalling(data);
1333 EXPECT_EQ(true, res2);
1334 }
1335
1336 /**
1337 * @tc.name: DeviceProfileOperator001
1338 * @tc.desc: DeviceProfileOperator true.
1339 * @tc.type: FUNC
1340 * @tc.require:
1341 */
1342 HWTEST_F(DeviceProfileManagerTest, DeviceProfileOperator001, TestSize.Level1)
1343 {
1344 DeviceProfile deviceProfile1;
1345 deviceProfile1.SetDeviceId("anything1");
1346 deviceProfile1.SetDeviceTypeName("anything1");
1347 deviceProfile1.SetDeviceTypeId(0);
1348 deviceProfile1.SetDeviceName("anything1");
1349 deviceProfile1.SetManufactureName("anything1");
1350 deviceProfile1.SetDeviceModel("anything1");
1351 deviceProfile1.SetStorageCapability(1);
1352 deviceProfile1.SetOsSysCap("anything1");
1353 deviceProfile1.SetOsApiLevel(1);
1354 deviceProfile1.SetOsVersion("anything1");
1355 deviceProfile1.SetOsType(1);
1356
1357 DeviceProfile deviceProfile2;
1358 deviceProfile2.SetDeviceId("anything2");
1359 deviceProfile2.SetDeviceTypeName("anything2");
1360 deviceProfile2.SetDeviceTypeId(0);
1361 deviceProfile2.SetDeviceName("anything2");
1362 deviceProfile2.SetManufactureName("anything2");
1363 deviceProfile2.SetDeviceModel("anything2");
1364 deviceProfile2.SetStorageCapability(1);
1365 deviceProfile2.SetOsSysCap("anything2");
1366 deviceProfile2.SetOsApiLevel(1);
1367 deviceProfile2.SetOsVersion("anything2");
1368 deviceProfile2.SetOsType(1);
1369
1370 bool res = deviceProfile1 != deviceProfile2;
1371 EXPECT_EQ(true, res);
1372 }
1373
1374 /**
1375 * @tc.name: DeviceProfileDump001
1376 * @tc.desc: DeviceProfileDump succeed.
1377 * @tc.type: FUNC
1378 * @tc.require:
1379 */
1380 HWTEST_F(DeviceProfileManagerTest, DeviceProfileDump001, TestSize.Level1)
1381 {
1382 DeviceProfile deviceProfile;
1383 deviceProfile.SetDeviceId("anything");
1384 deviceProfile.SetDeviceTypeName("anything");
1385 deviceProfile.SetDeviceTypeId(0);
1386 deviceProfile.SetDeviceName("anything");
1387 deviceProfile.SetManufactureName("anything");
1388 deviceProfile.SetDeviceModel("anything");
1389 deviceProfile.SetStorageCapability(1);
1390 deviceProfile.SetOsSysCap("anything");
1391 deviceProfile.SetOsApiLevel(1);
1392 deviceProfile.SetOsVersion("anything");
1393 deviceProfile.SetOsType(1);
1394
1395 string strJson = deviceProfile.dump();
1396 char fistChar = strJson.front();
1397 char lastChar = strJson.back();
1398 EXPECT_EQ('{', fistChar);
1399 EXPECT_EQ('}', lastChar);
1400 }
1401
1402 /**
1403 * @tc.name: ServiceProfileConstructor001
1404 * @tc.desc: ServiceProfileConstructor succeed.
1405 * @tc.type: FUNC
1406 * @tc.require:
1407 */
1408 HWTEST_F(DeviceProfileManagerTest, ServiceProfileConstructor001, TestSize.Level1)
1409 {
1410 ServiceProfile serviceProfile = ServiceProfile("deviceId", "serviceName", "serviceType");
1411 EXPECT_EQ("deviceId", serviceProfile.GetDeviceId());
1412 }
1413
1414 /**
1415 * @tc.name: LoadDpSyncAdapter001
1416 * @tc.desc: LoadDpSyncAdapter first branch.
1417 * @tc.type: FUNC
1418 * @tc.require:
1419 */
1420 HWTEST_F(DeviceProfileManagerTest, LoadDpSyncAdapter001, TestSize.Level1)
1421 {
1422 char path[PATH_MAX + 1] = {0x00};
1423 std::string soName = "/system/lib/libdeviceprofileadapter.z.so";
1424 bool ret = false;
1425 if ((soName.length() == 0) || (soName.length() > PATH_MAX) || (realpath(soName.c_str(), path) == nullptr)) {
1426 ret = true;
1427 } else {
1428 DeviceProfileManager::GetInstance().isAdapterSoLoaded_ = true;
1429 ret = DeviceProfileManager::GetInstance().LoadDpSyncAdapter();
1430 }
1431 EXPECT_EQ(true, ret);
1432 }
1433
1434 /**
1435 * @tc.name: GetInKvDB001
1436 * @tc.desc: GetDeviceProfile,GetServiceProfile, GetCharacteristicProfile succeed, in KV DB.
1437 * @tc.type: FUNC
1438 * @tc.require:
1439 */
1440 HWTEST_F(DeviceProfileManagerTest, GetInKvDB001, TestSize.Level1)
1441 {
1442 string deviceId = ContentSensorManagerUtils::GetInstance().ObtainLocalUdid();
1443 DeviceProfile deviceProfile2;
1444 deviceProfile2.SetDeviceId(deviceId);
1445 deviceProfile2.SetDeviceTypeName("GetInKvDB001_DeviceTypeName");
1446 deviceProfile2.SetDeviceTypeId(0);
1447 deviceProfile2.SetDeviceName("GetInKvDB001_DeviceName");
1448 deviceProfile2.SetManufactureName("GetInKvDB001_ManufactureName");
1449 deviceProfile2.SetDeviceModel("GetInKvDB001_DeviceModel");
1450 deviceProfile2.SetStorageCapability(1);
1451 deviceProfile2.SetOsSysCap("GetInKvDB001_OsSysCap");
1452 deviceProfile2.SetOsApiLevel(1);
1453 deviceProfile2.SetOsVersion("GetInKvDB001_OsVersion");
1454 deviceProfile2.SetOsType(1);
1455 DeviceProfileManager::GetInstance().PutDeviceProfile(deviceProfile2);
1456
1457 ServiceProfile serviceProfile5;
1458 serviceProfile5.SetDeviceId(deviceId);
1459 serviceProfile5.SetServiceName("GetInKvDB001_ServiceName");
1460 serviceProfile5.SetServiceType("GetInKvDB001_ServiceType");
1461 DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile5);
1462
1463 CharacteristicProfile charProfile5;
1464 charProfile5.SetDeviceId(deviceId);
1465 charProfile5.SetServiceName("GetInKvDB001_ServiceName");
1466 charProfile5.SetCharacteristicKey("GetInKvDB001_CharacteristicKey");
1467 charProfile5.SetCharacteristicValue("GetInKvDB001_CharacteristicValue");
1468 DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile5);
1469
1470 ProfileCache::GetInstance().DeleteDeviceProfile(deviceId);
1471 ProfileCache::GetInstance().DeleteServiceProfile("GetInKvDB001_DeviceId", "GetInKvDB001_ServiceName");
1472 ProfileCache::GetInstance().DeleteCharProfile("GetInKvDB001_DeviceId", "GetInKvDB001_ServiceName",
1473 "GetInKvDB001_CharacteristicKey");
1474
1475 DeviceProfile outDeviceProfile;
1476 int32_t ret1 = DeviceProfileManager::GetInstance().GetDeviceProfile(deviceId, outDeviceProfile);
1477 EXPECT_EQ(ret1, DP_SUCCESS);
1478
1479 string serviceName2 = "GetInKvDB001_ServiceName";
1480 ServiceProfile outServiceProfile;
1481 int32_t ret2 = DeviceProfileManager::GetInstance().GetServiceProfile(deviceId, serviceName2, outServiceProfile);
1482 EXPECT_EQ(ret2, DP_SUCCESS);
1483
1484 string serviceName3 = "GetInKvDB001_ServiceName";
1485 string characteristicKey3 = "GetInKvDB001_CharacteristicKey";
1486 CharacteristicProfile outCharProfile;
1487 int32_t ret3 = DeviceProfileManager::GetInstance().GetCharacteristicProfile(deviceId, serviceName3,
1488 characteristicKey3, outCharProfile);
1489 EXPECT_EQ(ret3, DP_SUCCESS);
1490 }
1491
1492 /**
1493 * @tc.name: RunloadedFunction001
1494 * @tc.desc: RunloadedFunction001
1495 * @tc.type: FUNC
1496 * @tc.require:
1497 */
1498 HWTEST_F(DeviceProfileManagerTest, RunloadedFunction001, TestSize.Level1)
1499 {
1500 OHOS::sptr<OHOS::IRemoteObject> syncCb = OHOS::sptr<SyncCompletedCallbackStub>(new SyncCallback());
1501 string deviceId = "DeviceId";
1502 int32_t ret = DeviceProfileManager::GetInstance().RunloadedFunction(deviceId, syncCb);
1503 EXPECT_EQ(ret, DP_LOAD_SYNC_ADAPTER_FAILED);
1504 }
1505 /**
1506 * @tc.name: RunloadedFunction002
1507 * @tc.desc: RunloadedFunction002
1508 * @tc.type: FUNC
1509 * @tc.require:
1510 */
1511 HWTEST_F(DeviceProfileManagerTest, RunloadedFunction002, TestSize.Level1)
1512 {
1513 OHOS::sptr<OHOS::IRemoteObject> syncCb = OHOS::sptr<SyncCompletedCallbackStub>(new SyncCallback());
1514 string deviceId = ProfileUtils::GetLocalUdidFromDM();
1515 int32_t ret = DeviceProfileManager::GetInstance().RunloadedFunction(deviceId, syncCb);
1516 EXPECT_EQ(ret, DP_LOAD_SYNC_ADAPTER_FAILED);
1517 }
1518
1519 HWTEST_F(DeviceProfileManagerTest, GetInKvDB002, TestSize.Level1)
1520 {
1521 string deviceId = ContentSensorManagerUtils::GetInstance().ObtainLocalUdid();
1522 DeviceProfile deviceProfile2;
1523 deviceProfile2.SetDeviceId(deviceId);
1524 deviceProfile2.SetDeviceTypeName("GetInKvDB001_DeviceTypeName2");
1525 deviceProfile2.SetDeviceTypeId(0);
1526 deviceProfile2.SetDeviceName("GetInKvDB001_DeviceName2");
1527 deviceProfile2.SetManufactureName("GetInKvDB001_ManufactureName2");
1528 deviceProfile2.SetDeviceModel("GetInKvDB001_DeviceModel2");
1529 deviceProfile2.SetStorageCapability(1);
1530 deviceProfile2.SetOsSysCap("GetInKvDB001_OsSysCap2");
1531 deviceProfile2.SetOsApiLevel(1);
1532 deviceProfile2.SetOsVersion("GetInKvDB001_OsVersion2");
1533 deviceProfile2.SetOsType(1);
1534 DeviceProfileManager::GetInstance().PutDeviceProfile(deviceProfile2);
1535
1536 ServiceProfile serviceProfile5;
1537 serviceProfile5.SetDeviceId(deviceId);
1538 serviceProfile5.SetServiceName("GetInKvDB001_ServiceName2");
1539 serviceProfile5.SetServiceType("GetInKvDB001_ServiceType2");
1540 DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile5);
1541
1542 CharacteristicProfile charProfile5;
1543 charProfile5.SetDeviceId(deviceId);
1544 charProfile5.SetServiceName("GetInKvDB001_ServiceName2");
1545 charProfile5.SetCharacteristicKey("GetInKvDB001_CharacteristicKey2");
1546 charProfile5.SetCharacteristicValue("GetInKvDB001_CharacteristicValue2");
1547 DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile5);
1548
1549 ProfileCache::GetInstance().DeleteDeviceProfile(deviceId);
1550 ProfileCache::GetInstance().DeleteServiceProfile("GetInKvDB001_DeviceId2", "GetInKvDB001_ServiceName");
1551 ProfileCache::GetInstance().DeleteCharProfile("GetInKvDB001_DeviceId2", "GetInKvDB001_ServiceName",
1552 "GetInKvDB001_CharacteristicKey2");
1553
1554 DeviceProfile outDeviceProfile;
1555 DeviceProfileManager::GetInstance().GetDeviceProfile(deviceId, outDeviceProfile);
1556
1557 string serviceName2 = "GetInKvDB001_ServiceName2";
1558 ServiceProfile outServiceProfile;
1559 DeviceProfileManager::GetInstance().GetServiceProfile(deviceId, serviceName2, outServiceProfile);
1560
1561 string serviceName3 = "GetInKvDB001_ServiceName2";
1562 string characteristicKey3 = "GetInKvDB001_CharacteristicKey2";
1563 CharacteristicProfile outCharProfile;
1564 int32_t ret = DeviceProfileManager::GetInstance().GetCharacteristicProfile(deviceId, serviceName3,
1565 characteristicKey3, outCharProfile);
1566 EXPECT_EQ(ret, DP_SUCCESS);
1567 }
1568 } // namespace DistributedDeviceProfile
1569 } // namespace OHOS
1570