From ffa77f74310851713923294ac3f1c6d2977ee43f Mon Sep 17 00:00:00 2001 From: wangzhaohao Date: Thu, 4 Sep 2025 15:40:38 +0800 Subject: [PATCH] add ut Signed-off-by: wangzhaohao --- ...tributed_device_profile_client_kv_test.cpp | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/services/core/test/unittest/distributed_device_profile_client_kv_test.cpp b/services/core/test/unittest/distributed_device_profile_client_kv_test.cpp index f156d9e4..cd587ebb 100644 --- a/services/core/test/unittest/distributed_device_profile_client_kv_test.cpp +++ b/services/core/test/unittest/distributed_device_profile_client_kv_test.cpp @@ -135,6 +135,21 @@ public: } }; +class SyncCompletedCallbac : public SyncCompletedCallbackStub { +public: + SyncCompletedCallbac() + { + } + ~SyncCompletedCallbac() + { + } + void OnSyncCompleted(const SyncResult& syncResults) + { + (void)syncResults; + return; + } +}; + class MockDpInitedCallbackStub : public DpInitedCallbackStub { public: int32_t OnDpInited() @@ -454,6 +469,44 @@ HWTEST_F(DistributedDeviceProfileClientKvTest, SyncDeviceProfile001, TestSize.Le EXPECT_EQ(errCode, DP_SYNC_DEVICE_FAIL); } +/** + * @tc.name: SyncStaticProfile001 + * @tc.desc: SyncStaticProfile failed, SyncCb is nullptr! + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileClientKvTest, SyncStaticProfile001, TestSize.Level1) +{ + DistributedDeviceProfile::DpSyncOptions syncOptions; + OHOS::sptr syncCb = nullptr; + + syncOptions.AddDevice("deviceId1"); + syncOptions.AddDevice("deviceId2"); + syncOptions.SetSyncMode(SyncMode::MIN); + + int32_t errCode = DistributedDeviceProfileClient::GetInstance().SyncStaticProfile(syncOptions, syncCb); + EXPECT_EQ(errCode, DP_SYNC_DEVICE_FAIL); +} + +/** + * @tc.name: SyncStaticProfile002 + * @tc.desc: SyncStaticProfile failed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistributedDeviceProfileClientKvTest, SyncStaticProfile002, TestSize.Level1) +{ + DistributedDeviceProfile::DpSyncOptions syncOptions; + OHOS::sptr syncCb = sptr(new SyncCompletedCallbac()); + + syncOptions.AddDevice("deviceId1"); + syncOptions.AddDevice("deviceId2"); + syncOptions.SetSyncMode(SyncMode::MIN); + + int32_t errCode = DistributedDeviceProfileClient::GetInstance().SyncStaticProfile(syncOptions, syncCb); + EXPECT_NE(errCode, DP_SUCCESS); +} + /** * @tc.name: OnServiceDied001 * @tc.desc: OnServiceDied -- Gitee