diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/cloud_syncer_progress_manager_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/cloud_syncer_progress_manager_test.cpp index 59ca64d9ca1897048c3b5d6e928067eb2bd8d017..6a6c4754a42a34bc6e6563896b4b0ef8f1f07b3c 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/cloud_syncer_progress_manager_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/cloud_syncer_progress_manager_test.cpp @@ -61,7 +61,8 @@ void CloudSyncerProgressManagerTest::TearDown(void) HWTEST_F(CloudSyncerProgressManagerTest, SyncerMgrCheck001, TestSize.Level1) { // Synchronization parameter checks - MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + std::shared_ptr storageProxy = std::make_shared(iCloud); TestCloudSyncer cloudSyncer(storageProxy); std::shared_ptr idb = std::make_shared(); @@ -117,7 +118,8 @@ HWTEST_F(CloudSyncerProgressManagerTest, SyncerMgrCheck001, TestSize.Level1) */ HWTEST_F(CloudSyncerProgressManagerTest, SyncerMgrCheck002, TestSize.Level1) { - MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + std::shared_ptr storageProxy = std::make_shared(iCloud); std::shared_ptr idb = std::make_shared(); TestCloudSyncer cloudSyncer3(storageProxy); @@ -172,7 +174,8 @@ HWTEST_F(CloudSyncerProgressManagerTest, SyncerMgrCheck002, TestSize.Level1) */ HWTEST_F(CloudSyncerProgressManagerTest, SyncerMgrCheck003, TestSize.Level1) { - MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + std::shared_ptr storageProxy = std::make_shared(iCloud); TestCloudSyncer cloudSyncer5(storageProxy); std::shared_ptr idb = std::make_shared(); @@ -217,7 +220,8 @@ HWTEST_F(CloudSyncerProgressManagerTest, SyncerMgrCheck003, TestSize.Level1) HWTEST_F(CloudSyncerProgressManagerTest, SyncerMgrCheck004, TestSize.Level1) { // Check the number of queues - MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + std::shared_ptr storageProxy = std::make_shared(iCloud); TestCloudSyncer cloudSyncer(storageProxy); std::shared_ptr idb = std::make_shared(); @@ -257,7 +261,8 @@ HWTEST_F(CloudSyncerProgressManagerTest, SyncerMgrCheck004, TestSize.Level1) HWTEST_F(CloudSyncerProgressManagerTest, SyncerMgrCheck005, TestSize.Level1) { // Single-threaded execution of tasks - MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + std::shared_ptr storageProxy = std::make_shared(iCloud); TestCloudSyncer cloudSyncer(storageProxy); std::shared_ptr idb = std::make_shared(); @@ -289,7 +294,8 @@ HWTEST_F(CloudSyncerProgressManagerTest, SyncerMgrCheck005, TestSize.Level1) */ // HWTEST_F(CloudSyncerProgressManagerTest, SyncerMgrCheck004, TestSize.Level1) // { -// MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); +// MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + // // std::shared_ptr storageProxy = std::make_shared(iCloud); // TestCloudSyncer cloudSyncer(storageProxy); // MockICloudDB *idb = new MockICloudDB(); diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/cloud_syncer_upload_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/cloud_syncer_upload_test.cpp index 924f6154815c2920acaf31aeba86a25fe2138897..862ec270719037580cca551deebe9cd72f257e37 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/cloud_syncer_upload_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/cloud_syncer_upload_test.cpp @@ -74,7 +74,8 @@ void CloudSyncerUploadTest::TearDown(void) */ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck001, TestSize.Level1) { - MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + std::shared_ptr storageProxy = std::make_shared(iCloud); TestCloudSyncer cloudSyncer(storageProxy); std::shared_ptr idb = std::make_shared(); @@ -131,7 +132,8 @@ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck001, TestSize.Level1) */ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck002, TestSize.Level1) { - MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + std::shared_ptr storageProxy = std::make_shared(iCloud); TestCloudSyncer cloudSyncer(storageProxy); std::shared_ptr idb = std::make_shared(); @@ -166,7 +168,8 @@ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck002, TestSize.Level1) */ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck003, TestSize.Level1) { - MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + std::shared_ptr storageProxy = std::make_shared(iCloud); TestCloudSyncer cloudSyncer(storageProxy); std::shared_ptr idb = std::make_shared(); @@ -233,7 +236,8 @@ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck003, TestSize.Level1) */ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck004, TestSize.Level1) { - MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + std::shared_ptr storageProxy = std::make_shared(iCloud); TestCloudSyncer cloudSyncer(storageProxy); std::shared_ptr idb = std::make_shared(); @@ -292,7 +296,8 @@ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck004, TestSize.Level1) */ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck005, TestSize.Level1) { - MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + std::shared_ptr storageProxy = std::make_shared(iCloud); TestCloudSyncer cloudSyncer(storageProxy); std::shared_ptr idb = std::make_shared(); @@ -339,7 +344,8 @@ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck005, TestSize.Level1) */ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck006, TestSize.Level1) { - MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + std::shared_ptr storageProxy = std::make_shared(iCloud); TestCloudSyncer cloudSyncer(storageProxy); std::shared_ptr idb = std::make_shared(); @@ -394,7 +400,8 @@ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck006, TestSize.Level1) */ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck007, TestSize.Level1) { - MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + std::shared_ptr storageProxy = std::make_shared(iCloud); TestCloudSyncer cloudSyncer(storageProxy); std::shared_ptr idb = std::make_shared(); @@ -460,7 +467,8 @@ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck007, TestSize.Level1) */ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck008, TestSize.Level1) { - MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + std::shared_ptr storageProxy = std::make_shared(iCloud); TestCloudSyncer cloudSyncer(storageProxy); std::shared_ptr idb = std::make_shared(); @@ -519,7 +527,8 @@ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck008, TestSize.Level1) HWTEST_F(CloudSyncerUploadTest, UploadModeCheck009, TestSize.Level1) { // ClouSyncData format is ok - MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + std::shared_ptr storageProxy = std::make_shared(iCloud); TestCloudSyncer cloudSyncer(storageProxy); std::shared_ptr idb = std::make_shared(); @@ -582,7 +591,8 @@ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck009, TestSize.Level1) HWTEST_F(CloudSyncerUploadTest, UploadModeCheck017, TestSize.Level1) { // ClouSyncData format is ok - MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + std::shared_ptr storageProxy = std::make_shared(iCloud); TestCloudSyncer cloudSyncer(storageProxy); std::shared_ptr idb = std::make_shared(); @@ -632,7 +642,8 @@ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck017, TestSize.Level1) HWTEST_F(CloudSyncerUploadTest, UploadModeCheck010, TestSize.Level1) { // insert has data, update has data, delete has data (check whether it is running normally and info count) - MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + std::shared_ptr storageProxy = std::make_shared(iCloud); TestCloudSyncer cloudSyncer(storageProxy); std::shared_ptr idb = std::make_shared(); @@ -691,7 +702,8 @@ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck010, TestSize.Level1) */ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck011, TestSize.Level1) { - MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + std::shared_ptr storageProxy = std::make_shared(iCloud); TestCloudSyncer cloudSyncer(storageProxy); std::shared_ptr idb = std::make_shared(); @@ -753,7 +765,8 @@ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck011, TestSize.Level1) */ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck012, TestSize.Level1) { - MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + std::shared_ptr storageProxy = std::make_shared(iCloud); TestCloudSyncer cloudSyncer(storageProxy); std::shared_ptr idb = std::make_shared(); @@ -816,7 +829,8 @@ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck012, TestSize.Level1) HWTEST_F(CloudSyncerUploadTest, UploadModeCheck013, TestSize.Level1) { // batch api all success. - MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + std::shared_ptr storageProxy = std::make_shared(iCloud); TestCloudSyncer cloudSyncer(storageProxy); std::shared_ptr idb = std::make_shared(); @@ -879,7 +893,8 @@ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck013, TestSize.Level1) */ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck014, TestSize.Level1) { - MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + std::shared_ptr storageProxy = std::make_shared(iCloud); TestCloudSyncer cloudSyncer2(storageProxy); std::shared_ptr idb2 = std::make_shared(); @@ -937,7 +952,8 @@ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck014, TestSize.Level1) */ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck015, TestSize.Level1) { - MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + std::shared_ptr storageProxy = std::make_shared(iCloud); TestCloudSyncer cloudSyncer3(storageProxy); std::shared_ptr idb3 = std::make_shared(); @@ -1003,7 +1019,8 @@ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck015, TestSize.Level1) HWTEST_F(CloudSyncerUploadTest, UploadModeCheck016, TestSize.Level1) { // update water level successful - MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + std::shared_ptr storageProxy = std::make_shared(iCloud); TestCloudSyncer cloudSyncer(storageProxy); std::shared_ptr idb = std::make_shared(); @@ -1070,7 +1087,8 @@ HWTEST_F(CloudSyncerUploadTest, UploadModeCheck016, TestSize.Level1) */ // HWTEST_F(CloudSyncerUploadTest, UploadModeCheck016, TestSize.Level1) // { -// MockICloudSyncStorageInterface *iCloud = new MockICloudSyncStorageInterface(); +// MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + // std::shared_ptr storageProxy = std::make_shared(iCloud); // TestCloudSyncer cloudSyncer(storageProxy); // MockICloudDB *idb = new MockICloudDB(); diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_db_proxy_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_db_proxy_test.cpp index d89b104e670822d4776564688f3c63eb00564fd4..7f47194aa32531dc3e5d9acc33563b655786e843 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_db_proxy_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_db_proxy_test.cpp @@ -278,8 +278,9 @@ HWTEST_F(DistributedDBCloudDBProxyTest, CloudDBProxyTest004, TestSize.Level3) * @tc.steps: step1. set cloud db to proxy and sleep 5s when download * @tc.expected: step1. E_OK */ - auto iCloud = std::make_shared(); - auto cloudSyncer = new(std::nothrow) VirtualCloudSyncer(StorageProxy::GetCloudDb(iCloud.get())); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + std::shared_ptr storageProxy1 = std::make_shared(iCloud); + auto cloudSyncer = new(std::nothrow) VirtualCloudSyncer(storageProxy1); EXPECT_CALL(*iCloud, StartTransaction).WillRepeatedly(testing::Return(E_OK)); EXPECT_CALL(*iCloud, Commit).WillRepeatedly(testing::Return(E_OK)); ASSERT_NE(cloudSyncer, nullptr); @@ -325,6 +326,7 @@ HWTEST_F(DistributedDBCloudDBProxyTest, CloudDBProxyTest004, TestSize.Level3) virtualCloudDb_->ClearHeartbeatCount(); cloudSyncer->Close(); RefObject::KillAndDecObjRef(cloudSyncer); + delete iCloud; } /** @@ -340,8 +342,10 @@ HWTEST_F(DistributedDBCloudDBProxyTest, CloudDBProxyTest005, TestSize.Level0) * @tc.steps: step1. set cloud db to proxy and sleep 5s when download * @tc.expected: step1. E_OK */ - auto iCloud = std::make_shared(); - auto cloudSyncer = new(std::nothrow) VirtualCloudSyncer(StorageProxy::GetCloudDb(iCloud.get())); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + + std::shared_ptr storageProxy1 = std::make_shared(iCloud); + auto cloudSyncer = new(std::nothrow) VirtualCloudSyncer(storageProxy1); EXPECT_CALL(*iCloud, StartTransaction).WillRepeatedly(testing::Return(E_OK)); EXPECT_CALL(*iCloud, Commit).WillRepeatedly(testing::Return(E_OK)); ASSERT_NE(cloudSyncer, nullptr); @@ -362,6 +366,7 @@ HWTEST_F(DistributedDBCloudDBProxyTest, CloudDBProxyTest005, TestSize.Level0) virtualCloudDb_->ClearHeartbeatCount(); cloudSyncer->Close(); RefObject::KillAndDecObjRef(cloudSyncer); + delete iCloud; } /** @@ -377,8 +382,10 @@ HWTEST_F(DistributedDBCloudDBProxyTest, CloudDBProxyTest006, TestSize.Level3) * @tc.steps: step1. set cloud db to proxy and sleep 5s when download * @tc.expected: step1. E_OK */ - auto iCloud = std::make_shared(); - auto cloudSyncer = new(std::nothrow) VirtualCloudSyncer(StorageProxy::GetCloudDb(iCloud.get())); + MockICloudSyncStorageInterface *iCloud = new(std::nothrow) MockICloudSyncStorageInterface(); + + std::shared_ptr storageProxy1 = std::make_shared(iCloud); + auto cloudSyncer = new(std::nothrow) VirtualCloudSyncer(storageProxy1); EXPECT_CALL(*iCloud, StartTransaction).WillRepeatedly(testing::Return(E_OK)); EXPECT_CALL(*iCloud, Commit).WillRepeatedly(testing::Return(E_OK)); EXPECT_CALL(*iCloud, Rollback).WillRepeatedly(testing::Return(E_OK)); @@ -404,5 +411,6 @@ HWTEST_F(DistributedDBCloudDBProxyTest, CloudDBProxyTest006, TestSize.Level3) virtualCloudDb_->ClearHeartbeatCount(); cloudSyncer->Close(); RefObject::KillAndDecObjRef(cloudSyncer); + delete iCloud; } } \ No newline at end of file diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/mock_icloud_sync_storage_interface.h b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/mock_icloud_sync_storage_interface.h index e2824fe098d0de370248a5ba7cfdf82d1f1d468f..2dc15df9bb32b636318801db196bfff8a8dd6af1 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/mock_icloud_sync_storage_interface.h +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/mock_icloud_sync_storage_interface.h @@ -21,6 +21,7 @@ namespace DistributedDB { class MockICloudSyncStorageInterface : public ICloudSyncStorageInterface { public: + MockICloudSyncStorageInterface() = default; MOCK_CONST_METHOD2(GetMetaData, int(const Key &, Value &)); MOCK_METHOD2(PutMetaData, int(const Key &, const Value &)); MOCK_METHOD1(ChkSchema, int(const TableName &));