diff --git a/services/distributeddataservice/service/test/kvdb_general_store_test.cpp b/services/distributeddataservice/service/test/kvdb_general_store_test.cpp index 18b02267a4ba36cbac58fb3d7bbc78b69eb385c8..c34db72a617fcc3173e4615191b60aef0798a614 100644 --- a/services/distributeddataservice/service/test/kvdb_general_store_test.cpp +++ b/services/distributeddataservice/service/test/kvdb_general_store_test.cpp @@ -419,6 +419,7 @@ HWTEST_F(KVDBGeneralStoreTest, SyncTest, TestSize.Level0) EXPECT_NE(ret.first, GeneralError::E_OK); auto status = store->Close(); EXPECT_EQ(status, GeneralError::E_OK); + delete store; } /** @@ -533,7 +534,7 @@ HWTEST_F(KVDBGeneralStoreTest, GetDBSyncCompleteCB, TestSize.Level0) * @tc.desc: Test the scenario where the QueryUsers return false in the CloudSync function. * @tc.type: FUNC * @tc.require: -* @tc.author: SQL +* @tc.author: */ HWTEST_F(KVDBGeneralStoreTest, CloudSync001, TestSize.Level0) { @@ -552,6 +553,8 @@ HWTEST_F(KVDBGeneralStoreTest, CloudSync001, TestSize.Level0) EXPECT_CALL(*accountDelegateMock, QueryUsers(_)).Times(1).WillOnce(DoAll(SetArgReferee<0>(users), Return(false))); auto ret = store->CloudSync(devices, cloudSyncMode, asyncs, 0, prepareTraceId); EXPECT_EQ(ret, DBStatus::DB_ERROR); + store->delegate_ = nullptr; + delete store; } /** @@ -559,7 +562,7 @@ HWTEST_F(KVDBGeneralStoreTest, CloudSync001, TestSize.Level0) * @tc.desc: CloudSync test the functionality of different branches. * @tc.type: FUNC * @tc.require: -* @tc.author: SQL +* @tc.author: */ HWTEST_F(KVDBGeneralStoreTest, CloudSync002, TestSize.Level0) { @@ -586,6 +589,40 @@ HWTEST_F(KVDBGeneralStoreTest, CloudSync002, TestSize.Level0) cloudSyncMode = DistributedDB::SyncMode::SYNC_MODE_CLOUD_FORCE_PUSH; ret = store->CloudSync(devices, cloudSyncMode, asyncs, 0, prepareTraceId); EXPECT_EQ(ret, DBStatus::OK); + store->delegate_ = nullptr; + delete store; +} + +/** +* @tc.name: CloudSync003 +* @tc.desc: Test the scenario where the QueryUsers return true in the CloudSync function. +* @tc.type: FUNC +* @tc.require: +* @tc.author: +*/ +HWTEST_F(KVDBGeneralStoreTest, CloudSync003, TestSize.Level0) +{ + auto store = new (std::nothrow) KVDBGeneralStore(metaData_); + ASSERT_NE(store, nullptr); + store->SetEqualIdentifier(bundleName, storeName); + KvStoreNbDelegateMock mockDelegate; + store->delegate_ = &mockDelegate; + std::vector devices = { "device1", "device2" }; + auto asyncs = [](const GenDetails &result) {}; + store->storeInfo_.user = 0; + auto cloudSyncMode = DistributedDB::SyncMode::SYNC_MODE_PUSH_ONLY; + store->SetEqualIdentifier(bundleName, storeName); + std::string prepareTraceId; + std::vector users = {0, 1}; + EXPECT_CALL(*accountDelegateMock, QueryUsers(_)) + .Times(1) + .WillOnce(DoAll( + SetArgReferee<0>(users), + Return(true))); + auto ret = store->CloudSync(devices, cloudSyncMode, asyncs, 0, prepareTraceId); + EXPECT_EQ(ret, DBStatus::OK); + store->delegate_ = nullptr; + delete store; } /** @@ -613,7 +650,7 @@ HWTEST_F(KVDBGeneralStoreTest, GetIdentifierParams, TestSize.Level0) * @tc.desc: Sync test the functionality of 3 < syncMode < 7 branches. * @tc.type: FUNC * @tc.require: -* @tc.author: SQL +* @tc.author: */ HWTEST_F(KVDBGeneralStoreTest, Sync002, TestSize.Level0) { @@ -639,6 +676,8 @@ HWTEST_F(KVDBGeneralStoreTest, Sync002, TestSize.Level0) store->SetConfig(storeConfig); ret = store->Sync({}, query, [](const GenDetails &result) {}, syncParam); EXPECT_EQ(ret.first, GeneralError::E_OK); + store->delegate_ = nullptr; + delete store; } /** @@ -646,7 +685,7 @@ HWTEST_F(KVDBGeneralStoreTest, Sync002, TestSize.Level0) * @tc.desc: Sync test the functionality of different branches. * @tc.type: FUNC * @tc.require: -* @tc.author: SQL +* @tc.author: */ HWTEST_F(KVDBGeneralStoreTest, Sync003, TestSize.Level0) { @@ -689,6 +728,8 @@ HWTEST_F(KVDBGeneralStoreTest, Sync003, TestSize.Level0) syncParam.mode = mixMode; ret = store->Sync(devices, query, [](const GenDetails &result) {}, syncParam); EXPECT_EQ(ret.first, GeneralError::E_INVALID_ARGS); + store->delegate_ = nullptr; + delete store; } /** diff --git a/services/distributeddataservice/service/test/object_manager_mock_test.cpp b/services/distributeddataservice/service/test/object_manager_mock_test.cpp index 7c395f68cc062d29d19a57fd6f7732bb655a5820..faf7ca79cb6d74afb3c7a792747562ee955ee7f1 100644 --- a/services/distributeddataservice/service/test/object_manager_mock_test.cpp +++ b/services/distributeddataservice/service/test/object_manager_mock_test.cpp @@ -377,5 +377,58 @@ HWTEST_F(ObjectManagerMockTest, UnRegisterAssetsLister001, TestSize.Level1) ret = manager.UnRegisterAssetsLister(); EXPECT_EQ(ret, true); } + +/** +* @tc.name: InitUserMeta001 +* @tc.desc: Test the scenario where the QueryUsers return false in the GetCurrentUser function. +* @tc.type: FUNC +*/ +HWTEST_F(ObjectManagerMockTest, InitUserMeta001, TestSize.Level1) +{ + EXPECT_CALL(*metaDataManagerMock, LoadMeta(_, _, _)) + .WillOnce(testing::Return(false)); + auto &manager = ObjectStoreManager::GetInstance(); + std::vector users; + EXPECT_CALL(*accountDelegateMock, QueryUsers(_)).Times(1).WillOnce(DoAll(SetArgReferee<0>(users), Return(false))); + auto status = manager.InitUserMeta(); + ASSERT_EQ(status, DistributedObject::OBJECT_INNER_ERROR); +} + +/** +* @tc.name: InitUserMeta002 +* @tc.desc: Test the scenario where the QueryUsers users empty in the GetCurrentUser function. +* @tc.type: FUNC +*/ +HWTEST_F(ObjectManagerMockTest, InitUserMeta002, TestSize.Level1) +{ + EXPECT_CALL(*metaDataManagerMock, LoadMeta(_, _, _)) + .WillOnce(testing::Return(false)); + auto &manager = ObjectStoreManager::GetInstance(); + std::vector users; + EXPECT_CALL(*accountDelegateMock, QueryUsers(_)) + .Times(1) + .WillOnce( + DoAll(SetArgReferee<0>(users), Invoke([](std::vector &users) { users.clear(); }), Return(true))); + auto status = manager.InitUserMeta(); + ASSERT_EQ(status, DistributedObject::OBJECT_INNER_ERROR); +} + +/** +* @tc.name: InitUserMeta003 +* @tc.desc: Test the scenario where the QueryUsers return true in the GetCurrentUser function. +* @tc.type: FUNC +*/ +HWTEST_F(ObjectManagerMockTest, InitUserMeta003, TestSize.Level1) +{ + EXPECT_CALL(*metaDataManagerMock, LoadMeta(_, _, _)) + .WillOnce(testing::Return(false)); + DeviceInfo devInfo = { .uuid = "666" }; + EXPECT_CALL(*devMgrAdapterMock, GetLocalDevice()).WillOnce(Return(devInfo)); + auto &manager = ObjectStoreManager::GetInstance(); + std::vector users = { 0, 1 }; + EXPECT_CALL(*accountDelegateMock, QueryUsers(_)).Times(1).WillOnce(DoAll(SetArgReferee<0>(users), Return(true))); + auto status = manager.InitUserMeta(); + ASSERT_EQ(status, DistributedObject::OBJECT_INNER_ERROR); +} }; // namespace DistributedDataTest } // namespace OHOS::Test \ No newline at end of file