• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "gtest/gtest.h"
17 
18 #include "utils.h"
19 
20 #include <sys/types.h>
21 #include <sys/wait.h>
22 #include <unistd.h>
23 
24 #define private public
25 #define protected public
26 #include "device_profile_errors.h"
27 #include "device_profile_log.h"
28 #include "device_profile_storage.h"
29 #include "device_profile_storage_manager.h"
30 #include "distributed_device_profile_client.h"
31 #include "hisysevent.h"
32 #include "nlohmann/json.hpp"
33 #include "online_sync_table.h"
34 #include "sync_coordinator.h"
35 #include "syscap_info_collector.h"
36 #include "syscap_interface.h"
37 #undef private
38 #undef protected
39 
40 namespace OHOS {
41 namespace DeviceProfile {
42 using namespace OHOS::HiviewDFX;
43 using namespace OHOS::DistributedKv;
44 namespace {
45     const std::string TAG = "SyscapInfoCollector";
46     const std::string SERVICE_ID = "test";
47     const std::string SERVICE_TYPE = "test";
48     const std::string CHARACTER_PRIVATE_SYSCAP = "privatesyscap";
49     const std::string CHARACTER_OS_SYSCAP = "ossyscap";
50     const std::string DEVICE_PROFILE_SYNC_FAILED = "DEVICE_PROFILE_SYNC_FAILED";
51     const std::string FAULT_CODE_KEY = "FAULT_CODE";
52     const std::string DOMAIN_NAME = std::string(HiSysEvent::Domain::DEVICE_PROFILE);
53     const std::string APP_ID = "distributed_device_profile_service";
54     const std::string STORE_ID = "online_sync_storage_test";
55 }
56 using namespace testing;
57 using namespace testing::ext;
58 
59 class ProfileStorageTest : public testing::Test {
60 public:
61     ProfileStorageTest();
62     static void SetUpTestCase();
63     static void TearDownTestCase();
64     void SetUp();
65     void TearDown();
66 
67 public:
68     std::shared_ptr<DeviceProfileStorage> deviceProfileStorage;
69     std::shared_ptr<DistributedKv::SingleKvStore> kvStorePtr_;
70 };
71 
ProfileStorageTest()72 ProfileStorageTest::ProfileStorageTest()
73 {
74     std::string baseDir = "/data/service/el1/public/database/test";
75     mkdir(baseDir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
76     Options options = {
77         .createIfMissing = true,
78         .encrypt = false,
79         .autoSync = false,
80         .kvStoreType = KvStoreType::SINGLE_VERSION,
81         .area = 1,
82         .baseDir = baseDir
83     };
84     // clean the IMMEDIATE_SYNC_ON_CHANGE
85     SyncPolicy syncPolicy {
86         .type = PolicyType::IMMEDIATE_SYNC_ON_ONLINE
87     };
88     options.policies.emplace_back(syncPolicy);
89     deviceProfileStorage = std::make_shared<DeviceProfileStorage>(APP_ID, STORE_ID);
90     if (deviceProfileStorage != nullptr) {
91         deviceProfileStorage->SetOptions(options);
92     }
93 }
94 
SetUpTestCase()95 void ProfileStorageTest::SetUpTestCase()
96 {
97     DTEST_LOG << "SetUpTestCase" << std::endl;
98 }
99 
TearDownTestCase()100 void ProfileStorageTest::TearDownTestCase()
101 {
102     DTEST_LOG << "TearDownTestCase" << std::endl;
103 }
104 
SetUp()105 void ProfileStorageTest::SetUp()
106 {
107     DTEST_LOG << "SetUp" << std::endl;
108 }
109 
TearDown()110 void ProfileStorageTest::TearDown()
111 {
112     DTEST_LOG << "TearDown" << std::endl;
113 }
114 
115 class StorageProfileEventCallback : public IProfileEventCallback {
116 };
117 
118 class ProfileSyncHandler : public DistributedKv::KvStoreSyncCallback {
119 public:
SyncCompleted(const std::map<std::string,DistributedKv::Status> & results)120     void SyncCompleted(const std::map<std::string, DistributedKv::Status>& results) override
121     {
122     }
123 };
124 
125 /**
126  * @tc.name: TryGetKvStore_001
127  * @tc.desc: put device profile with empty service id
128  * @tc.type: FUNC
129  * @tc.require: I4NY23
130  */
131 HWTEST_F(ProfileStorageTest, TryGetKvStore_001, TestSize.Level3)
132 {
133     ServiceCharacteristicProfile profile;
134     DeviceProfileStorageManager::GetInstance().onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
135     bool result = DeviceProfileStorageManager::GetInstance().onlineSyncTbl_->TryGetKvStore();
136     EXPECT_EQ(false, result);
137 }
138 
139 /**
140  * @tc.name: PutDeviceProfile_001
141  * @tc.desc: put device profile with empty service id
142  * @tc.type: FUNC
143  * @tc.require: I4NY23
144  */
145 HWTEST_F(ProfileStorageTest, PutDeviceProfile_001, TestSize.Level3)
146 {
147     ServiceCharacteristicProfile profile;
148     int32_t result = DeviceProfileStorageManager::GetInstance().PutDeviceProfile(profile);
149     EXPECT_EQ(ERR_DP_INIT_DB_FAILED, result);
150 }
151 
152 /**
153  * @tc.name: GetDeviceProfile_001
154  * @tc.desc: get device profile with empty service id
155  * @tc.type: FUNC
156  * @tc.require: I4NY23
157  */
158 HWTEST_F(ProfileStorageTest, GetDeviceProfile_001, TestSize.Level3)
159 {
160     ServiceCharacteristicProfile profile;
161     int32_t result = DeviceProfileStorageManager::GetInstance().GetDeviceProfile("", "", profile);
162     EXPECT_EQ(ERR_DP_INIT_DB_FAILED, result);
163 }
164 
165 /**
166  * @tc.name: DeleteDeviceProfile_001
167  * @tc.desc: delete device profile with empty service id
168  * @tc.type: FUNC
169  * @tc.require: I4NY23
170  */
171 HWTEST_F(ProfileStorageTest, DeleteDeviceProfile_001, TestSize.Level3)
172 {
173     int32_t result = DeviceProfileStorageManager::GetInstance().DeleteDeviceProfile("");
174     EXPECT_EQ(ERR_DP_INIT_DB_FAILED, result);
175 }
176 
177 /**
178  * @tc.name: RemoveUnBoundDeviceProfile_001
179  * @tc.desc: delete device profile with empty service id
180  * @tc.type: FUNC
181  * @tc.require: I4NY23
182  */
183 HWTEST_F(ProfileStorageTest, RemoveUnBoundDeviceProfile_001, TestSize.Level3)
184 {
185     int32_t result = DeviceProfileStorageManager::GetInstance().RemoveUnBoundDeviceProfile("");
186     EXPECT_EQ(ERR_DP_INIT_DB_FAILED, result);
187 }
188 
189 /**
190  * @tc.name: SyncDeviceProfile_001
191  * @tc.desc: sync device profile
192  * @tc.type: FUNC
193  * @tc.require: I4NY1U
194  */
195 HWTEST_F(ProfileStorageTest, SyncDeviceProfile_001, TestSize.Level3)
196 {
197     wptr<IRemoteObject> remote;
198     DistributedDeviceProfileClient::DeviceProfileDeathRecipient obj;
199     obj.OnRemoteDied(remote);
200     auto syncCb = std::make_shared<StorageProfileEventCallback>();
201     SyncOptions syncOptions;
202     sptr<IRemoteObject> notifier =
203         sptr<ProfileEventNotifierStub>(new ProfileEventNotifierStub(syncCb));
204     int result = DeviceProfileStorageManager::GetInstance().SyncDeviceProfile(syncOptions, notifier);
205     EXPECT_EQ(ERR_DP_INIT_DB_FAILED, result);
206 }
207 
208 /**
209  * @tc.name: RestoreServiceItemLocked_001
210  * @tc.desc: RestoreServiceItemLocked
211  * @tc.type: FUNC
212  * @tc.require: I4NY1U
213  */
214 HWTEST_F(ProfileStorageTest, RestoreServiceItemLocked_001, TestSize.Level3)
215 {
216     int result = 0;
217     DeviceProfileStorageManager::GetInstance().RestoreServiceItemLocked("");
218     EXPECT_EQ(0, result);
219 }
220 
221 /**
222  * @tc.name: SetServiceType_001
223  * @tc.desc: set service type
224  * @tc.type: FUNC
225  * @tc.require: I4NY23
226  */
227 HWTEST_F(ProfileStorageTest, SetServiceType_001, TestSize.Level3)
228 {
229     ServiceCharacteristicProfile profile;
230     int result = 0;
231     DeviceProfileStorageManager::GetInstance().SetServiceType("", "", profile);
232     EXPECT_EQ(0, result);
233 }
234 
235 /**
236  * @tc.name: SetServiceType_002
237  * @tc.desc: set service type
238  * @tc.type: FUNC
239  * @tc.require: I4NY23
240  */
241 HWTEST_F(ProfileStorageTest, SetServiceType_002, TestSize.Level3)
242 {
243     ServiceCharacteristicProfile profile;
244     int result = 0;
245     std::string udid = "1111test1111";
246     DeviceProfileStorageManager::GetInstance().SetServiceType(udid, "", profile);
247     EXPECT_EQ(0, result);
248 }
249 
250 /**
251  * @tc.name: SetServiceType_003
252  * @tc.desc: set service type
253  * @tc.type: FUNC
254  * @tc.require: I4NY23
255  */
256 HWTEST_F(ProfileStorageTest, SetServiceType_003, TestSize.Level3)
257 {
258     ServiceCharacteristicProfile profile;
259     int result = 0;
260     std::string serviceId = "2222test2222";
261     DeviceProfileStorageManager::GetInstance().SetServiceType("", serviceId, profile);
262     EXPECT_EQ(0, result);
263 }
264 
265 /**
266  * @tc.name: SetServiceType_004
267  * @tc.desc: set service type
268  * @tc.type: FUNC
269  * @tc.require: I4NY23
270  */
271 HWTEST_F(ProfileStorageTest, SetServiceType_004, TestSize.Level3)
272 {
273     ServiceCharacteristicProfile profile;
274     int result = 0;
275     std::string udid = "1111test1111";
276     std::string serviceId = "2222test2222";
277     DeviceProfileStorageManager::GetInstance().SetServiceType(udid, serviceId, profile);
278     EXPECT_EQ(0, result);
279 }
280 
281 /**
282  * @tc.name: PutDeviceProfile_001
283  * @tc.desc: put device profile with empty service id
284  * @tc.type: FUNC
285  * @tc.require: I4NY23
286  */
287 HWTEST_F(ProfileStorageTest, WaitKvDataService_001, TestSize.Level3)
288 {
289     ServiceCharacteristicProfile profile;
290     bool result = DeviceProfileStorageManager::GetInstance().WaitKvDataService();
291     EXPECT_EQ(true, result);
292 }
293 
294 /**
295  * @tc.name: RemoveUnBoundDeviceProfile_002
296  * @tc.desc: delete device profile with empty service id
297  * @tc.type: FUNC
298  * @tc.require: I4NY23
299  */
300 HWTEST_F(ProfileStorageTest, RemoveUnBoundDeviceProfile_002, TestSize.Level3)
301 {
302     DeviceProfileStorageManager::GetInstance().onlineSyncTbl_->initStatus_ = StorageInitStatus::UNINITED;
303     int32_t result = DeviceProfileStorageManager::GetInstance().RemoveUnBoundDeviceProfile("");
304     EXPECT_EQ(ERR_DP_NOT_INIT_DB, result);
305 }
306 
307 /**
308  * @tc.name: PutDeviceProfile_002
309  * @tc.desc: put device profile with empty service id
310  * @tc.type: FUNC
311  * @tc.require: I4NY23
312  */
313 HWTEST_F(ProfileStorageTest, PutDeviceProfile_002, TestSize.Level3)
314 {
315     ServiceCharacteristicProfile profile;
316     profile.SetServiceId("test");
317     profile.SetServiceType("test");
318     nlohmann::json j;
319     j["testVersion"] = "3.0.0";
320     j["testApiLevel"] = 8;
321     profile.SetCharacteristicProfileJson(j.dump());
322     int32_t result = DeviceProfileStorageManager::GetInstance().PutDeviceProfile(profile);
323     EXPECT_EQ(0, result);
324 }
325 
326 /**
327  * @tc.name: PutDeviceProfile_003
328  * @tc.desc: put device profile with empty service id
329  * @tc.type: FUNC
330  * @tc.require: I4NY23
331  */
332 HWTEST_F(ProfileStorageTest, PutDeviceProfile_003, TestSize.Level3)
333 {
334     ServiceCharacteristicProfile profile;
335     profile.SetServiceId("");
336     profile.SetServiceType("test");
337     nlohmann::json j;
338     j["testVersion"] = "3.0.0";
339     j["testApiLevel"] = 8;
340     profile.SetCharacteristicProfileJson(j.dump());
341     int32_t result = DeviceProfileStorageManager::GetInstance().PutDeviceProfile(profile);
342     EXPECT_EQ(0, result);
343 }
344 
345 /**
346  * @tc.name: PutDeviceProfile_004
347  * @tc.desc: put device profile with empty service id
348  * @tc.type: FUNC
349  * @tc.require: I4NY23
350  */
351 HWTEST_F(ProfileStorageTest, PutDeviceProfile_004, TestSize.Level3)
352 {
353     ServiceCharacteristicProfile profile;
354     profile.SetServiceId("test");
355     profile.SetServiceType("");
356     nlohmann::json j;
357     j["testVersion"] = "3.0.0";
358     j["testApiLevel"] = 8;
359     profile.SetCharacteristicProfileJson(j.dump());
360     int32_t result = DeviceProfileStorageManager::GetInstance().PutDeviceProfile(profile);
361     EXPECT_EQ(0, result);
362 }
363 
364 /**
365  * @tc.name: PutDeviceProfile_005
366  * @tc.desc: get device profile
367  * @tc.type: FUNC
368  * @tc.require: I4OH93
369  */
370 HWTEST_F(ProfileStorageTest, PutDeviceProfile_005, TestSize.Level2)
371 {
372     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
373     int32_t res = onlineSyncTbl_->PutDeviceProfile("test", "test");
374     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
375 }
376 
377 /**
378  * @tc.name: GetDeviceProfile_002
379  * @tc.desc: get device profile with syscap
380  * @tc.type: FUNC
381  * @tc.require: I59PZ3
382  */
383 HWTEST_F(ProfileStorageTest, GetDeviceProfile_002, TestSize.Level3)
384 {
385     ServiceCharacteristicProfile profile;
386     profile.SetServiceId(SERVICE_ID);
387     profile.SetServiceType(SERVICE_TYPE);
388     int32_t result = DeviceProfileStorageManager::GetInstance().GetDeviceProfile("", SERVICE_ID, profile);
389     EXPECT_EQ(0, result);
390     std::string jsonData = profile.GetCharacteristicProfileJson();
391     DTEST_LOG << "jsonData:" << jsonData << std::endl;
392 }
393 
394 /**
395  * @tc.name: GetDeviceProfile_003
396  * @tc.desc: get device profile with syscap
397  * @tc.type: FUNC
398  * @tc.require: I59PZ3
399  */
400 HWTEST_F(ProfileStorageTest, GetDeviceProfile_003, TestSize.Level3)
401 {
402     ServiceCharacteristicProfile profile;
403     profile.SetServiceId(SERVICE_ID);
404     profile.SetServiceType(SERVICE_TYPE);
405     int32_t result = DeviceProfileStorageManager::GetInstance().GetDeviceProfile("test", "", profile);
406     EXPECT_EQ(ERR_DP_INVALID_PARAMS, result);
407 }
408 
409 /**
410  * @tc.name: GetDeviceProfile_004
411  * @tc.desc: get device profile with syscap
412  * @tc.type: FUNC
413  * @tc.require: I59PZ3
414  */
415 HWTEST_F(ProfileStorageTest, GetDeviceProfile_004, TestSize.Level3)
416 {
417     ServiceCharacteristicProfile profile;
418     profile.SetServiceId(SERVICE_ID);
419     profile.SetServiceType(SERVICE_TYPE);
420     int32_t result = DeviceProfileStorageManager::GetInstance().GetDeviceProfile("test", SERVICE_ID, profile);
421     EXPECT_EQ(ERR_DP_INVALID_PARAMS, result);
422 }
423 
424 /**
425  * @tc.name: DeleteDeviceProfile_002
426  * @tc.desc: delete an empty profile
427  * @tc.type: FUNC
428  * @tc.require: I4NY21
429  */
430 HWTEST_F(ProfileStorageTest, DeleteDeviceProfile_002, TestSize.Level3)
431 {
432     int32_t result = DeviceProfileStorageManager::GetInstance().DeleteDeviceProfile("test");
433     EXPECT_EQ(0, result);
434 }
435 
436 /**
437  * @tc.name: DeleteDeviceProfile_003
438  * @tc.desc: delete device profile with empty service id after init
439  * @tc.type: FUNC
440  * @tc.require: I4NY23
441  */
442 HWTEST_F(ProfileStorageTest, DeleteDeviceProfile_003, TestSize.Level3)
443 {
444     int32_t result = DeviceProfileStorageManager::GetInstance().DeleteDeviceProfile("");
445     EXPECT_EQ(0, result);
446 }
447 
448 /**
449  * @tc.name: DeleteDeviceProfile_004
450  * @tc.desc: put device profile batch
451  * @tc.type: FUNC
452  * @tc.require: I4OH93
453  */
454 HWTEST_F(ProfileStorageTest, DeleteDeviceProfile_004, TestSize.Level2)
455 {
456     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
457     int32_t res = onlineSyncTbl_->DeleteDeviceProfile("test");
458     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
459 }
460 
461 /**
462  * @tc.name: RemoveDeviceData_001
463  * @tc.desc: put device profile batch
464  * @tc.type: FUNC
465  * @tc.require: I4OH93
466  */
467 HWTEST_F(ProfileStorageTest, RemoveDeviceData_001, TestSize.Level2)
468 {
469     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
470     int32_t res = onlineSyncTbl_->RemoveDeviceData("networkid11111");
471     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
472 }
473 
474 /**
475  * @tc.name: SubscribeKvStore_002
476  * @tc.desc: SubscribeKvStore
477  * @tc.type: FUNC
478  * @tc.require: I4NY21
479  */
480 HWTEST_F(ProfileStorageTest, SubscribeKvStore_002, TestSize.Level3)
481 {
482     int32_t result = DeviceProfileStorageManager::GetInstance().SubscribeKvStore(nullptr);
483     EXPECT_EQ(0, result);
484 }
485 
486 /**
487  * @tc.name: UnSubscribeKvStore_001
488  * @tc.desc: UnSubscribeKvStore
489  * @tc.type: FUNC
490  * @tc.require: I4NY21
491  */
492 HWTEST_F(ProfileStorageTest, UnSubscribeKvStore_001, TestSize.Level3)
493 {
494     int32_t result = DeviceProfileStorageManager::GetInstance().UnSubscribeKvStore(nullptr);
495     EXPECT_EQ(ERR_DP_INVALID_PARAMS, result);
496 }
497 
498 /**
499  * @tc.name: RegisterSyncCallback_002
500  * @tc.desc: RegisterSyncCallback
501  * @tc.type: FUNC
502  * @tc.require: I4NY21
503  */
504 HWTEST_F(ProfileStorageTest, RegisterSyncCallback_002, TestSize.Level3)
505 {
506     int32_t result = DeviceProfileStorageManager::GetInstance().RegisterSyncCallback(nullptr);
507     EXPECT_EQ(0, result);
508 }
509 
510 /**
511  * @tc.name: UnRegisterSyncCallback_001
512  * @tc.desc: UnRegisterSyncCallback
513  * @tc.type: FUNC
514  * @tc.require: I4NY21
515  */
516 HWTEST_F(ProfileStorageTest, UnRegisterSyncCallback_001, TestSize.Level3)
517 {
518     int32_t result = DeviceProfileStorageManager::GetInstance().UnRegisterSyncCallback();
519     EXPECT_EQ(0, result);
520 }
521 
522 /**
523  * @tc.name: SyncDeviceProfile_002
524  * @tc.desc: sync device profile
525  * @tc.type: FUNC
526  * @tc.require: I5QPGN
527  */
528 HWTEST_F(ProfileStorageTest, SyncDeviceProfile_002, TestSize.Level3)
529 {
530     wptr<IRemoteObject> remote;
531     DistributedDeviceProfileClient::DeviceProfileDeathRecipient obj;
532     obj.OnRemoteDied(remote);
533     auto syncCb = std::make_shared<StorageProfileEventCallback>();
534     SyncOptions syncOptions;
535     sptr<IRemoteObject> notifier =
536         sptr<ProfileEventNotifierStub>(new ProfileEventNotifierStub(syncCb));
537     int result = DeviceProfileStorageManager::GetInstance().SyncDeviceProfile(syncOptions, notifier);
538     EXPECT_EQ(ERR_DP_SUBSCRIBE_FAILED, result);
539 }
540 
541 /**
542  * @tc.name: SyncDeviceProfile_003
543  * @tc.desc: sync device profile
544  * @tc.type: FUNC
545  * @tc.require: I5QPGN
546  */
547 HWTEST_F(ProfileStorageTest, SyncDeviceProfile_003, TestSize.Level3)
548 {
549     wptr<IRemoteObject> remote;
550     DistributedDeviceProfileClient::DeviceProfileDeathRecipient obj;
551     obj.OnRemoteDied(remote);
552     auto syncCb = std::make_shared<StorageProfileEventCallback>();
553     syncCb = nullptr;
554     SyncOptions syncOptions;
555     sptr<IRemoteObject> notifier =
556         sptr<ProfileEventNotifierStub>(new ProfileEventNotifierStub(syncCb));
557     notifier = nullptr;
558     int result = DeviceProfileStorageManager::GetInstance().SyncDeviceProfile(syncOptions, notifier);
559     EXPECT_EQ(ERR_DP_SUBSCRIBE_FAILED, result);
560 }
561 
562 /**
563  * @tc.name: RemoveUnBoundDeviceProfile_003
564  * @tc.desc: remove unBound device profile
565  * @tc.type: FUNC
566  * @tc.require: I4NY23
567  */
568 HWTEST_F(ProfileStorageTest, RemoveUnBoundDeviceProfile_003, TestSize.Level3)
569 {
570     DeviceProfileStorageManager::GetInstance().onlineSyncTbl_->initStatus_ = StorageInitStatus::INIT_SUCCEED;
571     int32_t result = DeviceProfileStorageManager::GetInstance().RemoveUnBoundDeviceProfile("");
572     EXPECT_EQ(ERR_DP_GET_NETWORKID_FAILED, result);
573 }
574 
575 /**
576  * @tc.name: RemoveUnBoundDeviceProfile_004
577  * @tc.desc: remove unBound device profile
578  * @tc.type: FUNC
579  * @tc.require: I4NY23
580  */
581 HWTEST_F(ProfileStorageTest, RemoveUnBoundDeviceProfile_004, TestSize.Level3)
582 {
583     std::string event = "EVENT_TEST";
584     std::string key = "EVENT_KEY";
585     int32_t result = 0;
586     std::string strResult = "returnresult";
587     DeviceProfileStorageManager::GetInstance().DumpLocalProfile(strResult);
588     DeviceProfileStorageManager::GetInstance().ReportFaultEvent(event, key, result);
589     DeviceProfileStorageManager::GetInstance().ReportBehaviorEvent(event);
590     result = DeviceProfileStorageManager::GetInstance().RemoveUnBoundDeviceProfile("test");
591     EXPECT_EQ(ERR_DP_GET_NETWORKID_FAILED, result);
592 }
593 
594 /**
595  * @tc.name: CheckSyncOption_001
596  * @tc.desc: report fault event
597  * @tc.type: FUNC
598  * @tc.require: I4NY23
599  */
600 HWTEST_F(ProfileStorageTest, CheckSyncOption_001, TestSize.Level3)
601 {
602     SyncOptions syncOptions;
603     std::string deviceId = "1111test2222";
604     syncOptions.AddDevice(deviceId);
605     DeviceProfileStorageManager::GetInstance().NotifySyncCompleted();
606     auto syncCb = std::make_shared<StorageProfileEventCallback>();
607     sptr<IRemoteObject> notifier =
608         sptr<ProfileEventNotifierStub>(new ProfileEventNotifierStub(syncCb));
609     DeviceProfileStorageManager::GetInstance().NotifySubscriberDied(notifier);
610     notifier = nullptr;
611     DeviceProfileStorageManager::GetInstance().NotifySubscriberDied(notifier);
612     bool res = DeviceProfileStorageManager::GetInstance().CheckSyncOption(syncOptions);
613     EXPECT_EQ(false, res);
614 }
615 
616 /**
617  * @tc.name: NotifySyncStart_001
618  * @tc.desc: notify sync start
619  * @tc.type: FUNC
620  * @tc.require: I4NY23
621  */
622 HWTEST_F(ProfileStorageTest, NotifySyncStart_001, TestSize.Level3)
623 {
624     auto syncCb = std::make_shared<StorageProfileEventCallback>();
625     sptr<IRemoteObject> notifier =
626         sptr<ProfileEventNotifierStub>(new ProfileEventNotifierStub(syncCb));
627     SyncCoordinator::GetInstance().isOnSync_ = true;
628     int32_t res = DeviceProfileStorageManager::GetInstance().NotifySyncStart(notifier);
629     EXPECT_EQ(ERR_DP_DEVICE_SYNC_BUSY, res);
630 }
631 
632 /**
633  * @tc.name: SubscribeKvStore_003
634  * @tc.desc: subscribe kvstore
635  * @tc.type: FUNC
636  * @tc.require: I4OH93
637  */
638 HWTEST_F(ProfileStorageTest, SubscribeKvStore_003, TestSize.Level2)
639 {
640     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
641     std::shared_ptr<DistributedKv::KvStoreObserver> kvStoreObserver_ = nullptr;
642     int32_t res = onlineSyncTbl_->SubscribeKvStore(kvStoreObserver_);
643     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
644 }
645 
646 /**
647  * @tc.name: GetDeviceProfile_005
648  * @tc.desc: get device profile
649  * @tc.type: FUNC
650  * @tc.require: I4OH93
651  */
652 HWTEST_F(ProfileStorageTest, GetDeviceProfile_005, TestSize.Level2)
653 {
654     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
655     std::string key = "";
656     std::string value = "";
657     int32_t res = onlineSyncTbl_->GetDeviceProfile(key, value);
658     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
659 }
660 
661 /**
662  * @tc.name: SubscribeKvStore_004
663  * @tc.desc: subscribe kvstore
664  * @tc.type: FUNC
665  * @tc.require: I4OH93
666  */
667 HWTEST_F(ProfileStorageTest, SubscribeKvStore_004, TestSize.Level2)
668 {
669     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
670     std::shared_ptr<DistributedKv::KvStoreObserver> kvStoreObserver_ =
671         std::make_shared<DistributedKv::KvStoreObserver>();
672     int32_t res = onlineSyncTbl_->SubscribeKvStore(kvStoreObserver_);
673     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
674 }
675 
676 /**
677  * @tc.name: UnSubscribeKvStore_002
678  * @tc.desc: subscribe kvstore
679  * @tc.type: FUNC
680  * @tc.require: I4OH93
681  */
682 HWTEST_F(ProfileStorageTest, UnSubscribeKvStore_002, TestSize.Level2)
683 {
684     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
685     std::shared_ptr<DistributedKv::KvStoreObserver> kvStoreObserver_ = nullptr;
686     int32_t res = onlineSyncTbl_->UnSubscribeKvStore(kvStoreObserver_);
687     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
688 }
689 
690 /**
691  * @tc.name: UnSubscribeKvStore_003
692  * @tc.desc: subscribe kvstore
693  * @tc.type: FUNC
694  * @tc.require: I4OH93
695  */
696 HWTEST_F(ProfileStorageTest, UnSubscribeKvStore_003, TestSize.Level2)
697 {
698     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
699     std::shared_ptr<DistributedKv::KvStoreObserver> kvStoreObserver_ =
700         std::make_shared<DistributedKv::KvStoreObserver>();
701     int32_t res = onlineSyncTbl_->UnSubscribeKvStore(kvStoreObserver_);
702     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
703 }
704 
705 /**
706  * @tc.name: RegisterSyncCallback_003
707  * @tc.desc: subscribe kvstore
708  * @tc.type: FUNC
709  * @tc.require: I4OH93
710  */
711 HWTEST_F(ProfileStorageTest, RegisterSyncCallback_003, TestSize.Level2)
712 {
713     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
714     std::shared_ptr<DistributedKv::KvStoreSyncCallback> syncCallback = nullptr;
715     int32_t res = onlineSyncTbl_->RegisterSyncCallback(syncCallback);
716     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
717 }
718 
719 /**
720  * @tc.name: RegisterSyncCallback_004
721  * @tc.desc: subscribe kvstore
722  * @tc.type: FUNC
723  * @tc.require: I4OH93
724  */
725 HWTEST_F(ProfileStorageTest, RegisterSyncCallback_004, TestSize.Level2)
726 {
727     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
728     std::shared_ptr<DistributedKv::KvStoreSyncCallback> syncCallback =
729       std::make_shared<ProfileSyncHandler>();
730     int32_t res = onlineSyncTbl_->RegisterSyncCallback(syncCallback);
731     EXPECT_EQ(0, res);
732 }
733 
734 /**
735  * @tc.name: UnRegisterSyncCallback_002
736  * @tc.desc: subscribe kvstore
737  * @tc.type: FUNC
738  * @tc.require: I4OH93
739  */
740 HWTEST_F(ProfileStorageTest, UnRegisterSyncCallback_002, TestSize.Level2)
741 {
742     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
743     int32_t res = onlineSyncTbl_->UnRegisterSyncCallback();
744     EXPECT_EQ(0, res);
745 }
746 
747 /**
748  * @tc.name: GetKvStore_001
749  * @tc.desc: get kvstore
750  * @tc.type: FUNC
751  * @tc.require: I4OH93
752  */
753 HWTEST_F(ProfileStorageTest, GetKvStore_001, TestSize.Level2)
754 {
755     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
756     onlineSyncTbl_->DeleteKvStore();
757     int32_t res = onlineSyncTbl_->GetKvStore();
758     EXPECT_EQ(27459585, res);
759 }
760 
761 /**
762  * @tc.name: PutDeviceProfile_006
763  * @tc.desc: get device profile
764  * @tc.type: FUNC
765  * @tc.require: I4OH93
766  */
767 HWTEST_F(ProfileStorageTest, PutDeviceProfile_006, TestSize.Level2)
768 {
769     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
770     onlineSyncTbl_->kvStorePtr_ = nullptr;
771     int32_t res = onlineSyncTbl_->PutDeviceProfile("test", "test");
772     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
773 }
774 
775 /**
776  * @tc.name: SubscribeKvStore_005
777  * @tc.desc: subscribe kvstore
778  * @tc.type: FUNC
779  * @tc.require: I4OH93
780  */
781 HWTEST_F(ProfileStorageTest, SubscribeKvStore_005, TestSize.Level2)
782 {
783     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
784     onlineSyncTbl_->kvStorePtr_ = nullptr;
785     std::shared_ptr<DistributedKv::KvStoreObserver> kvStoreObserver_ =
786         std::make_shared<DistributedKv::KvStoreObserver>();
787     int32_t res = onlineSyncTbl_->SubscribeKvStore(kvStoreObserver_);
788     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
789 }
790 
791 /**
792  * @tc.name: SubscribeKvStore_006
793  * @tc.desc: subscribe kvstore
794  * @tc.type: FUNC
795  * @tc.require: I4OH93
796  */
797 HWTEST_F(ProfileStorageTest, SubscribeKvStore_006, TestSize.Level2)
798 {
799     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
800     onlineSyncTbl_->kvStorePtr_ = nullptr;
801     std::shared_ptr<DistributedKv::KvStoreObserver> kvStoreObserver_ = nullptr;
802     int32_t res = onlineSyncTbl_->SubscribeKvStore(kvStoreObserver_);
803     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
804 }
805 
806 /**
807  * @tc.name: UnSubscribeKvStore_004
808  * @tc.desc: subscribe kvstore
809  * @tc.type: FUNC
810  * @tc.require: I4OH93
811  */
812 HWTEST_F(ProfileStorageTest, UnSubscribeKvStore_004, TestSize.Level2)
813 {
814     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
815     onlineSyncTbl_->kvStorePtr_ = nullptr;
816     std::shared_ptr<DistributedKv::KvStoreObserver> kvStoreObserver_ =
817         std::make_shared<DistributedKv::KvStoreObserver>();
818     int32_t res = onlineSyncTbl_->UnSubscribeKvStore(kvStoreObserver_);
819     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
820 }
821 
822 /**
823  * @tc.name: UnSubscribeKvStore_005
824  * @tc.desc: subscribe kvstore
825  * @tc.type: FUNC
826  * @tc.require: I4OH93
827  */
828 HWTEST_F(ProfileStorageTest, UnSubscribeKvStore_005, TestSize.Level2)
829 {
830     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
831     onlineSyncTbl_->kvStorePtr_ = nullptr;
832     std::shared_ptr<DistributedKv::KvStoreObserver> kvStoreObserver_ = nullptr;
833     int32_t res = onlineSyncTbl_->UnSubscribeKvStore(kvStoreObserver_);
834     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
835 }
836 
837 /**
838  * @tc.name: RegisterSyncCallback_005
839  * @tc.desc: subscribe kvstore
840  * @tc.type: FUNC
841  * @tc.require: I4OH93
842  */
843 HWTEST_F(ProfileStorageTest, RegisterSyncCallback_005, TestSize.Level2)
844 {
845     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
846     onlineSyncTbl_->kvStorePtr_ = nullptr;
847     std::shared_ptr<DistributedKv::KvStoreSyncCallback> syncCallback =
848       std::make_shared<ProfileSyncHandler>();
849     int32_t res = onlineSyncTbl_->RegisterSyncCallback(syncCallback);
850     EXPECT_EQ(0, res);
851 }
852 
853 /**
854  * @tc.name: RegisterSyncCallback_006
855  * @tc.desc: subscribe kvstore
856  * @tc.type: FUNC
857  * @tc.require: I4OH93
858  */
859 HWTEST_F(ProfileStorageTest, RegisterSyncCallback_006, TestSize.Level2)
860 {
861     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
862     onlineSyncTbl_->kvStorePtr_ = nullptr;
863     std::shared_ptr<DistributedKv::KvStoreSyncCallback> syncCallback = nullptr;
864     int32_t res = onlineSyncTbl_->RegisterSyncCallback(syncCallback);
865     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
866 }
867 
868 /**
869  * @tc.name: UnRegisterSyncCallback_003
870  * @tc.desc: subscribe kvstore
871  * @tc.type: FUNC
872  * @tc.require: I4OH93
873  */
874 HWTEST_F(ProfileStorageTest, UnRegisterSyncCallback_003, TestSize.Level2)
875 {
876     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
877     onlineSyncTbl_->kvStorePtr_ = nullptr;
878     int32_t res = onlineSyncTbl_->UnRegisterSyncCallback();
879     EXPECT_EQ(0, res);
880 }
881 
882 /**
883  * @tc.name: PutDeviceProfileBatch_001
884  * @tc.desc: put device profile batch
885  * @tc.type: FUNC
886  * @tc.require: I4OH93
887  */
888 HWTEST_F(ProfileStorageTest, PutDeviceProfileBatch_001, TestSize.Level2)
889 {
890     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
891     onlineSyncTbl_->kvStorePtr_ = nullptr;
892     vector<std::string> keys = {"test"};
893     vector<std::string> values = {"test"};
894     int32_t res = onlineSyncTbl_->PutDeviceProfileBatch(keys, values);
895     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
896 }
897 
898 /**
899  * @tc.name: DeleteDeviceProfile_005
900  * @tc.desc: put device profile batch
901  * @tc.type: FUNC
902  * @tc.require: I4OH93
903  */
904 HWTEST_F(ProfileStorageTest, DeleteDeviceProfile_005, TestSize.Level2)
905 {
906     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
907     onlineSyncTbl_->kvStorePtr_ = nullptr;
908     int32_t res = onlineSyncTbl_->DeleteDeviceProfile("test");
909     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
910 }
911 
912 /**
913  * @tc.name: RemoveDeviceData_002
914  * @tc.desc: remove device data
915  * @tc.type: FUNC
916  * @tc.require: I4OH93
917  */
918 HWTEST_F(ProfileStorageTest, RemoveDeviceData_002, TestSize.Level2)
919 {
920     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
921     onlineSyncTbl_->kvStorePtr_ = nullptr;
922     int32_t res = onlineSyncTbl_->RemoveDeviceData("network1111111");
923     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
924 }
925 
926 /**
927  * @tc.name: CheckTrustGroup_001
928  * @tc.desc: check trust group
929  * @tc.type: FUNC
930  * @tc.require: I4OH93
931  */
932 HWTEST_F(ProfileStorageTest, CheckTrustGroup_001, TestSize.Level2)
933 {
934     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
935     std::vector<std::string> deviceIdList = {};
936     bool res = onlineSyncTbl_->CheckTrustGroup(deviceIdList);
937     EXPECT_EQ(false, res);
938 }
939 
940 /**
941  * @tc.name: CheckTrustGroup_002
942  * @tc.desc: check trust group
943  * @tc.type: FUNC
944  * @tc.require: I4OH93
945  */
946 HWTEST_F(ProfileStorageTest, CheckTrustGroup_002, TestSize.Level2)
947 {
948     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
949     std::vector<std::string> deviceIdList = {"did1111111"};
950     bool res = onlineSyncTbl_->CheckTrustGroup(deviceIdList);
951     EXPECT_EQ(false, res);
952 }
953 
954 /**
955  * @tc.name: SubscribeKvStore_007
956  * @tc.desc: subscribe kvstore
957  * @tc.type: FUNC
958  * @tc.require: I4OH93
959  */
960 HWTEST_F(ProfileStorageTest, SubscribeKvStore_007, TestSize.Level2)
961 {
962     DeviceProfileStorageManager::GetInstance().onlineSyncTbl_->initStatus_ = StorageInitStatus::INIT_SUCCEED;
963     std::shared_ptr<DistributedKv::KvStoreObserver> kvStoreObserver_ = nullptr;
964     int32_t res = DeviceProfileStorageManager::GetInstance().SubscribeKvStore(kvStoreObserver_);
965     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
966 }
967 
968 /**
969  * @tc.name: UnSubscribeKvStore_006
970  * @tc.desc: subscribe kvstore
971  * @tc.type: FUNC
972  * @tc.require: I4OH93
973  */
974 HWTEST_F(ProfileStorageTest, UnSubscribeKvStore_006, TestSize.Level2)
975 {
976     DeviceProfileStorageManager::GetInstance().onlineSyncTbl_->initStatus_ = StorageInitStatus::INIT_SUCCEED;
977     std::shared_ptr<DistributedKv::KvStoreObserver> kvStoreObserver_ = nullptr;
978     DeviceProfileStorageManager::GetInstance().profileItems_.clear();
979     DeviceProfileStorageManager::GetInstance().FlushProfileItems();
980     int32_t res = DeviceProfileStorageManager::GetInstance().UnSubscribeKvStore(kvStoreObserver_);
981     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
982 }
983 
984 /**
985  * @tc.name: DeleteDeviceProfile_006
986  * @tc.desc: delete device profile with empty service id after init
987  * @tc.type: FUNC
988  * @tc.require: I4NY23
989  */
990 HWTEST_F(ProfileStorageTest, DeleteDeviceProfile_006, TestSize.Level3)
991 {
992     DeviceProfileStorageManager::GetInstance().onlineSyncTbl_->initStatus_ = StorageInitStatus::INIT_SUCCEED;
993     DeviceProfileStorageManager::GetInstance().servicesJson_.clear();
994     int32_t result = DeviceProfileStorageManager::GetInstance().DeleteDeviceProfile("test");
995     EXPECT_EQ(ERR_DP_INVALID_PARAMS, result);
996 }
997 
998 /**
999  * @tc.name: DeleteDeviceProfile_007
1000  * @tc.desc: delete device profile with empty service id after init
1001  * @tc.type: FUNC
1002  * @tc.require: I4NY23
1003  */
1004 HWTEST_F(ProfileStorageTest, DeleteDeviceProfile_007, TestSize.Level3)
1005 {
1006     DeviceProfileStorageManager::GetInstance().onlineSyncTbl_->initStatus_ = StorageInitStatus::INIT_SUCCEED;
1007     nlohmann::json j;
1008     j[SERVICE_TYPE] = "567";
1009     DeviceProfileStorageManager::GetInstance().servicesJson_["test"] = j;
1010     int32_t result = DeviceProfileStorageManager::GetInstance().DeleteDeviceProfile("test");
1011     EXPECT_EQ(ERR_DP_INVALID_PARAMS, result);
1012 }
1013 
1014 /**
1015  * @tc.name: PutDeviceProfile_007
1016  * @tc.desc: put device profile with empty service id
1017  * @tc.type: FUNC
1018  * @tc.require: I4NY23
1019  */
1020 HWTEST_F(ProfileStorageTest, PutDeviceProfile_007, TestSize.Level3)
1021 {
1022     DeviceProfileStorageManager::GetInstance().onlineSyncTbl_->initStatus_ = StorageInitStatus::INIT_SUCCEED;
1023     ServiceCharacteristicProfile profile;
1024     profile.SetServiceId("");
1025     profile.SetServiceType("test");
1026     nlohmann::json j;
1027     j["testVersion"] = "3.0.0";
1028     j["testApiLevel"] = 8;
1029     profile.SetCharacteristicProfileJson(j.dump());
1030     int32_t result = DeviceProfileStorageManager::GetInstance().PutDeviceProfile(profile);
1031     EXPECT_EQ(ERR_DP_INVALID_PARAMS, result);
1032 }
1033 
1034 /**
1035  * @tc.name: RegisterSyncCallback_007
1036  * @tc.desc: put device profile with empty service id
1037  * @tc.type: FUNC
1038  * @tc.require: I4NY23
1039  */
1040 HWTEST_F(ProfileStorageTest, RegisterSyncCallback_007, TestSize.Level3)
1041 {
1042     ServiceCharacteristicProfile profile;
1043     std::shared_ptr<DistributedKv::KvStoreSyncCallback> syncCallback =
1044       std::make_shared<ProfileSyncHandler>();
1045     std::shared_ptr<OnlineSyncTable> onlineSyncTblTest_ = std::make_shared<OnlineSyncTable>();
1046     std::map<std::string, DistributedKv::Status> results;
1047     onlineSyncTblTest_->syncCallback_ = nullptr;
1048     onlineSyncTblTest_->NotifySyncCompleted(results);
1049     onlineSyncTblTest_->syncCallback_ = syncCallback;
1050     onlineSyncTblTest_->NotifySyncCompleted(results);
1051     SyncCoordinator::GetInstance().isOnlineTrigger_ = true;
1052     onlineSyncTblTest_->SyncCompleted(results);
1053     SyncCoordinator::GetInstance().isOnlineTrigger_ = false;
1054     onlineSyncTblTest_->SyncCompleted(results);
1055     bool result = onlineSyncTblTest_->RegisterSyncCallback(syncCallback);
1056     EXPECT_EQ(false, result);
1057 }
1058 
1059 /**
1060  * @tc.name: AcquireSync_001
1061  * @tc.desc: put device profile with empty service id
1062  * @tc.type: FUNC
1063  * @tc.require: I4NY23
1064  */
1065 HWTEST_F(ProfileStorageTest, AcquireSync_001, TestSize.Level3)
1066 {
1067     SyncCoordinator::GetInstance().isOnSync_ = true;
1068     bool result = SyncCoordinator::GetInstance().AcquireSync();
1069     EXPECT_EQ(false, result);
1070 }
1071 
1072 /**
1073  * @tc.name: UnRegisterSyncCallback_004
1074  * @tc.desc: put device profile with empty service id
1075  * @tc.type: FUNC
1076  * @tc.require: I4NY23
1077  */
1078 HWTEST_F(ProfileStorageTest, UnRegisterSyncCallback_004, TestSize.Level3)
1079 {
1080     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<DeviceProfileStorage>(APP_ID, STORE_ID);
1081     int32_t result = onlineSyncTbl_->UnRegisterSyncCallback();
1082     EXPECT_EQ(ERR_DP_INVALID_PARAMS, result);
1083 }
1084 
1085 /**
1086  * @tc.name: UnRegisterSyncCallback_005
1087  * @tc.desc: put device profile with empty service id
1088  * @tc.type: FUNC
1089  * @tc.require: I4NY23
1090  */
1091 HWTEST_F(ProfileStorageTest, UnRegisterSyncCallback_005, TestSize.Level3)
1092 {
1093     deviceProfileStorage->Init();
1094     if (deviceProfileStorage != nullptr) {
1095         int32_t result = deviceProfileStorage->UnRegisterSyncCallback();
1096         EXPECT_EQ(0, result);
1097     }
1098 }
1099 
1100 /**
1101  * @tc.name: PutDeviceProfile_008
1102  * @tc.desc: put device profile with empty service id
1103  * @tc.type: FUNC
1104  * @tc.require: I4NY23
1105  */
1106 HWTEST_F(ProfileStorageTest, PutDeviceProfile_008, TestSize.Level3)
1107 {
1108     deviceProfileStorage->Init();
1109     ServiceCharacteristicProfile profile;
1110     nlohmann::json j;
1111     j["testVersion"] = "3.0.0";
1112     j["testApiLevel"] = 8;
1113     profile.SetCharacteristicProfileJson(j.dump());
1114     std::vector<std::string> keys;
1115     std::vector<std::string> values;
1116     keys.emplace_back(DeviceProfileStorageManager::GetInstance().GenerateKey("test123udid", "test", KeyType::SERVICE));
1117     values.emplace_back(profile.GetCharacteristicProfileJson());
1118     if (deviceProfileStorage->kvStorePtr_ == nullptr) {
1119         deviceProfileStorage->kvStorePtr_ = kvStorePtr_;
1120     }
1121     if (deviceProfileStorage != nullptr) {
1122         int32_t result = deviceProfileStorage->PutDeviceProfile(keys[0], values[0]);
1123         EXPECT_EQ(0, result);
1124     }
1125 }
1126 
1127 /**
1128  * @tc.name: PutDeviceProfileBatch_002
1129  * @tc.desc: put device profile with empty service id
1130  * @tc.type: FUNC
1131  * @tc.require: I4NY23
1132  */
1133 HWTEST_F(ProfileStorageTest, PutDeviceProfileBatch_002, TestSize.Level3)
1134 {
1135     deviceProfileStorage->Init();
1136     std::vector<std::string> keys;
1137     std::vector<std::string> values;
1138     keys.emplace_back("key");
1139     values.emplace_back("value1");
1140     values.emplace_back("value2");
1141     if (deviceProfileStorage != nullptr) {
1142         int32_t result = deviceProfileStorage->PutDeviceProfileBatch(keys, values);
1143         EXPECT_EQ(ERR_DP_INVALID_PARAMS, result);
1144     }
1145 }
1146 
1147 /**
1148  * @tc.name: DeleteDeviceProfile_008
1149  * @tc.desc: put device profile with empty service id
1150  * @tc.type: FUNC
1151  * @tc.require: I4NY23
1152  */
1153 HWTEST_F(ProfileStorageTest, DeleteDeviceProfile_008, TestSize.Level3)
1154 {
1155     deviceProfileStorage->Init();
1156     std::string key =
1157         DeviceProfileStorageManager::GetInstance().GenerateKey("test123udid", "test", KeyType::SERVICE);
1158     if (deviceProfileStorage != nullptr) {
1159         int32_t result = deviceProfileStorage->DeleteDeviceProfile(key);
1160         EXPECT_EQ(0, result);
1161     }
1162 }
1163 
1164 /**
1165  * @tc.name: SubscribeKvStore_008
1166  * @tc.desc: put device profile with empty service id
1167  * @tc.type: FUNC
1168  * @tc.require: I4NY23
1169  */
1170 HWTEST_F(ProfileStorageTest, SubscribeKvStore_008, TestSize.Level3)
1171 {
1172     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<DeviceProfileStorage>(APP_ID, STORE_ID);
1173     int32_t res = onlineSyncTbl_->SubscribeKvStore(nullptr);
1174     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
1175 }
1176 
1177 /**
1178  * @tc.name: SubscribeKvStore_009
1179  * @tc.desc: put device profile with empty service id
1180  * @tc.type: FUNC
1181  * @tc.require: I4NY23
1182  */
1183 HWTEST_F(ProfileStorageTest, SubscribeKvStore_009, TestSize.Level3)
1184 {
1185     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<DeviceProfileStorage>(APP_ID, STORE_ID);
1186     std::shared_ptr<DistributedKv::KvStoreObserver> kvStoreObserver_ =
1187         std::make_shared<DistributedKv::KvStoreObserver>();
1188     int32_t res = onlineSyncTbl_->SubscribeKvStore(kvStoreObserver_);
1189     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
1190 }
1191 
1192 /**
1193  * @tc.name: SubscribeKvStore_0010
1194  * @tc.desc: put device profile with empty service id
1195  * @tc.type: FUNC
1196  * @tc.require: I4NY23
1197  */
1198 HWTEST_F(ProfileStorageTest, SubscribeKvStore_0010, TestSize.Level3)
1199 {
1200     deviceProfileStorage->Init();
1201     std::shared_ptr<DistributedKv::KvStoreObserver> kvStoreObserver_ =
1202         std::make_shared<DistributedKv::KvStoreObserver>();
1203     int32_t res = deviceProfileStorage->SubscribeKvStore(nullptr);
1204     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
1205 }
1206 
1207 /**
1208  * @tc.name: SubscribeKvStore_0011
1209  * @tc.desc: put device profile with empty service id
1210  * @tc.type: FUNC
1211  * @tc.require: I4NY23
1212  */
1213 HWTEST_F(ProfileStorageTest, SubscribeKvStore_0011, TestSize.Level3)
1214 {
1215     deviceProfileStorage->Init();
1216     std::shared_ptr<DistributedKv::KvStoreObserver> kvStoreObserver_ =
1217         std::make_shared<DistributedKv::KvStoreObserver>();
1218     int32_t res = deviceProfileStorage->SubscribeKvStore(kvStoreObserver_);
1219     EXPECT_EQ(0, res);
1220 }
1221 
1222 /**
1223  * @tc.name: UnSubscribeKvStore_007
1224  * @tc.desc: put device profile with empty service id
1225  * @tc.type: FUNC
1226  * @tc.require: I4NY23
1227  */
1228 HWTEST_F(ProfileStorageTest, UnSubscribeKvStore_007, TestSize.Level3)
1229 {
1230     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<DeviceProfileStorage>(APP_ID, STORE_ID);
1231     int32_t res = onlineSyncTbl_->UnSubscribeKvStore(nullptr);
1232     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
1233 }
1234 
1235 /**
1236  * @tc.name: UnSubscribeKvStore_008
1237  * @tc.desc: put device profile with empty service id
1238  * @tc.type: FUNC
1239  * @tc.require: I4NY23
1240  */
1241 HWTEST_F(ProfileStorageTest, UnSubscribeKvStore_008, TestSize.Level3)
1242 {
1243     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<DeviceProfileStorage>(APP_ID, STORE_ID);
1244     std::shared_ptr<DistributedKv::KvStoreObserver> kvStoreObserver_ =
1245         std::make_shared<DistributedKv::KvStoreObserver>();
1246     int32_t res = onlineSyncTbl_->UnSubscribeKvStore(nullptr);
1247     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
1248 }
1249 
1250 /**
1251  * @tc.name: UnSubscribeKvStore_009
1252  * @tc.desc: put device profile with empty service id
1253  * @tc.type: FUNC
1254  * @tc.require: I4NY23
1255  */
1256 HWTEST_F(ProfileStorageTest, UnSubscribeKvStore_009, TestSize.Level3)
1257 {
1258     deviceProfileStorage->Init();
1259     std::shared_ptr<DistributedKv::KvStoreObserver> kvStoreObserver_ =
1260         std::make_shared<DistributedKv::KvStoreObserver>();
1261     int32_t res = deviceProfileStorage->UnSubscribeKvStore(nullptr);
1262     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
1263 }
1264 
1265 /**
1266  * @tc.name: UnSubscribeKvStore_0010
1267  * @tc.desc: put device profile with empty service id
1268  * @tc.type: FUNC
1269  * @tc.require: I4NY23
1270  */
1271 HWTEST_F(ProfileStorageTest, UnSubscribeKvStore_0010, TestSize.Level3)
1272 {
1273     deviceProfileStorage->Init();
1274     std::shared_ptr<DistributedKv::KvStoreObserver> kvStoreObserver_ =
1275         std::make_shared<DistributedKv::KvStoreObserver>();
1276     int32_t res = deviceProfileStorage->UnSubscribeKvStore(kvStoreObserver_);
1277     EXPECT_EQ(27459590, res);
1278 }
1279 
1280 /**
1281  * @tc.name: RegisterSyncCallback_008
1282  * @tc.desc: subscribe kvstore
1283  * @tc.type: FUNC
1284  * @tc.require: I4OH93
1285  */
1286 HWTEST_F(ProfileStorageTest, RegisterSyncCallback_008, TestSize.Level2)
1287 {
1288     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<DeviceProfileStorage>(APP_ID, STORE_ID);
1289     int32_t res = onlineSyncTbl_->RegisterSyncCallback(nullptr);
1290     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
1291 }
1292 
1293 /**
1294  * @tc.name: RegisterSyncCallback_009
1295  * @tc.desc: subscribe kvstore
1296  * @tc.type: FUNC
1297  * @tc.require: I4OH93
1298  */
1299 HWTEST_F(ProfileStorageTest, RegisterSyncCallback_009, TestSize.Level2)
1300 {
1301     std::shared_ptr<DeviceProfileStorage> onlineSyncTbl_ = std::make_shared<DeviceProfileStorage>(APP_ID, STORE_ID);
1302     std::shared_ptr<DistributedKv::KvStoreSyncCallback> syncCallback =
1303       std::make_shared<ProfileSyncHandler>();
1304     int32_t res = onlineSyncTbl_->RegisterSyncCallback(syncCallback);
1305     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
1306 }
1307 
1308 /**
1309  * @tc.name: RegisterSyncCallback_010
1310  * @tc.desc: subscribe kvstore
1311  * @tc.type: FUNC
1312  * @tc.require: I4OH93
1313  */
1314 HWTEST_F(ProfileStorageTest, RegisterSyncCallback_010, TestSize.Level2)
1315 {
1316     deviceProfileStorage->Init();
1317     int32_t res = deviceProfileStorage->RegisterSyncCallback(nullptr);
1318     EXPECT_EQ(ERR_DP_INVALID_PARAMS, res);
1319 }
1320 
1321 /**
1322  * @tc.name: RegisterSyncCallback_011
1323  * @tc.desc: subscribe kvstore
1324  * @tc.type: FUNC
1325  * @tc.require: I4OH93
1326  */
1327 HWTEST_F(ProfileStorageTest, RegisterSyncCallback_011, TestSize.Level2)
1328 {
1329     deviceProfileStorage->Init();
1330     std::shared_ptr<DistributedKv::KvStoreSyncCallback> syncCallback =
1331       std::make_shared<ProfileSyncHandler>();
1332     int32_t res = deviceProfileStorage->RegisterSyncCallback(syncCallback);
1333     EXPECT_EQ(0, res);
1334 }
1335 
1336 /**
1337  * @tc.name: RemoveDeviceData_003
1338  * @tc.desc: remove device data
1339  * @tc.type: FUNC
1340  * @tc.require: I4OH93
1341  */
1342 HWTEST_F(ProfileStorageTest, RemoveDeviceData_003, TestSize.Level2)
1343 {
1344     deviceProfileStorage->Init();
1345     int32_t res = deviceProfileStorage->RemoveDeviceData("network1111111");
1346     EXPECT_EQ(27459585, res);
1347 }
1348 
1349 /**
1350  * @tc.name: SyncDeviceProfile_004
1351  * @tc.desc: sync device profile
1352  * @tc.type: FUNC
1353  * @tc.require: I5QPGN
1354  */
1355 HWTEST_F(ProfileStorageTest, SyncDeviceProfile_004, TestSize.Level3)
1356 {
1357     deviceProfileStorage->Init();
1358     DeviceProfileStorageManager::GetInstance().RegisterCallbacks();
1359     DeviceProfileStorageManager::GetInstance().kvStoreObserver_ = std::make_shared<DistributedKv::KvStoreObserver>();
1360     std::vector<std::string> deviceIds = {"", std::move("testudid123"), ""};
1361     int result = deviceProfileStorage->SyncDeviceProfile(deviceIds, SyncMode::PUSH);
1362     EXPECT_EQ(ERR_DP_UNTRUSTED_GROUP, result);
1363 }
1364 
1365 /**
1366  * @tc.name: SyncDeviceProfile_005
1367  * @tc.desc: sync device profile
1368  * @tc.type: FUNC
1369  * @tc.require: I5QPGN
1370  */
1371 HWTEST_F(ProfileStorageTest, SyncDeviceProfile_005, TestSize.Level3)
1372 {
1373     std::shared_ptr<OnlineSyncTable> onlineSyncTbl_ = std::make_shared<OnlineSyncTable>();
1374     std::vector<std::string> deviceIds = {"", std::move("testudid123"), ""};
1375     std::map<std::string, DistributedKv::Status> results;
1376     SyncCoordinator::GetInstance().Init();
1377     SyncCoordinator::GetInstance().isOnlineTrigger_ = false;
1378     onlineSyncTbl_->SyncCompleted(results);
1379     SyncCoordinator::GetInstance().isOnlineTrigger_ = true;
1380     onlineSyncTbl_->SyncCompleted(results);
1381     results["success123"] = Status::SUCCESS;
1382     results["test1"] = Status::ERROR;
1383     onlineSyncTbl_->SyncCompleted(results);
1384     results.clear();
1385     results["success123"] = Status::SUCCESS;
1386     results["test1"] = Status::ERROR;
1387     results["test2"] = Status::ERROR;
1388     results["test3"] = Status::ERROR;
1389     results["test4"] = Status::ERROR;
1390     std::vector<std::string> deviceIds1;
1391     deviceIds1.emplace_back("test1");
1392     deviceIds1.emplace_back("test2");
1393     deviceIds1.emplace_back("test3");
1394     deviceIds1.emplace_back("test4");
1395     DpDeviceManager::GetInstance().deviceIdsList_.emplace_back(deviceIds1);
1396     onlineSyncTbl_->SyncCompleted(results);
1397     int result = onlineSyncTbl_->SyncDeviceProfile(deviceIds, SyncMode::PUSH);
1398     EXPECT_EQ(0, result);
1399 }
1400 
1401 /**
1402  * @tc.name: PutDeviceProfile_009
1403  * @tc.desc: put device profile with empty service id
1404  * @tc.type: FUNC
1405  * @tc.require: I4NY23
1406  */
1407 HWTEST_F(ProfileStorageTest, PutDeviceProfile_009, TestSize.Level3)
1408 {
1409     DeviceProfileStorageManager::GetInstance().onlineSyncTbl_->initStatus_ = StorageInitStatus::INIT_SUCCEED;
1410     ServiceCharacteristicProfile profile;
1411     profile.SetServiceId("testttt");
1412     profile.SetServiceType("testttt");
1413     nlohmann::json j;
1414     j["testVersion"] = "3.0.0";
1415     j["testApiLevel"] = 8;
1416     profile.SetCharacteristicProfileJson(j.dump());
1417     nlohmann::json j1;
1418     j1["type"] = "testttt";
1419     DeviceProfileStorageManager::GetInstance().servicesJson_["testttt"] = j1;
1420     int32_t result = DeviceProfileStorageManager::GetInstance().PutDeviceProfile(profile);
1421     EXPECT_EQ(ERR_DP_INVALID_PARAMS, result);
1422 }
1423 
1424 /**
1425  * @tc.name: SetServiceType_005
1426  * @tc.desc: set service type
1427  * @tc.type: FUNC
1428  * @tc.require: I4NY23
1429  */
1430 HWTEST_F(ProfileStorageTest, SetServiceType_005, TestSize.Level3)
1431 {
1432     deviceProfileStorage->Init();
1433     ServiceCharacteristicProfile profile;
1434     nlohmann::json j;
1435     j["testVersion"] = "3.0.0";
1436     j["testApiLevel"] = 8;
1437     profile.SetCharacteristicProfileJson(j.dump());
1438     std::vector<std::string> keys;
1439     std::vector<std::string> values;
1440     keys.emplace_back(DeviceProfileStorageManager::GetInstance().GenerateKey(
1441         "test123udid", "services", KeyType::SERVICE_LIST));
1442     values.emplace_back(profile.GetCharacteristicProfileJson());
1443     int result = -1;
1444     if (deviceProfileStorage->kvStorePtr_ == nullptr) {
1445         deviceProfileStorage->kvStorePtr_ = kvStorePtr_;
1446     }
1447     if (deviceProfileStorage != nullptr) {
1448         result = deviceProfileStorage->PutDeviceProfile(keys[0], values[0]);
1449     }
1450     DeviceProfileStorageManager::GetInstance().onlineSyncTbl_ = deviceProfileStorage;
1451 
1452     std::string udid = "test123udid";
1453     std::string serviceId = "test";
1454     DeviceProfileStorageManager::GetInstance().SetServiceType(udid, serviceId, profile);
1455     std::shared_ptr<DistributedKv::KvStoreSyncCallback> syncCallback =
1456         std::make_shared<ProfileSyncHandler>();
1457     DeviceProfileStorageManager::GetInstance().kvStoreObserver_ = std::make_shared<DistributedKv::KvStoreObserver>();
1458     DeviceProfileStorageManager::GetInstance().kvStoreSyncCallback_ = syncCallback;
1459     DeviceProfileStorageManager::GetInstance().RegisterCallbacks();
1460     EXPECT_EQ(0, result);
1461 }
1462 }
1463 }