diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index 5b51cedf7..32a4692f7 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -529,6 +529,7 @@ ohos_unittest("RdbServiceTest") { "-Dprotected=public", "-Wno-multichar", "-Wno-c99-designator", + "-fno-access-control", # Ignore Private Member Access Control ] external_deps = [ diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp index 7f54d05f0..e35e1efce 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -49,6 +49,7 @@ #include "store/auto_cache.h" #include "store/general_value.h" #include "store/store_info.h" +#include "sync_manager.h" #include "token_setproc.h" using namespace testing::ext; @@ -2002,5 +2003,36 @@ HWTEST_F(CloudDataTest, Report, TestSize.Level0) auto ret = cloudReport->Report(reportParam); EXPECT_TRUE(ret); } + +/** +* @tc.name: IsOn +* @tc.desc: Test IsOn. +* @tc.type: FUNC +* @tc.require: + */ +HWTEST_F(CloudDataTest, IsOn, TestSize.Level0) +{ + auto cloudServerMock = std::make_shared(); + auto user = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(OHOS::IPCSkeleton::GetCallingTokenID()); + auto cloudInfo = cloudServerMock->GetServerInfo(user, true); + int32_t instanceId = 0; + auto ret = cloudInfo.IsOn("", instanceId); + EXPECT_FALSE(ret); +} + +/** +* @tc.name: IsAllSwitchOff +* @tc.desc: Test IsAllSwitchOff. +* @tc.type: FUNC +* @tc.require: + */ +HWTEST_F(CloudDataTest, IsAllSwitchOff, TestSize.Level0) +{ + auto cloudServerMock = std::make_shared(); + auto user = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(OHOS::IPCSkeleton::GetCallingTokenID()); + auto cloudInfo = cloudServerMock->GetServerInfo(user, true); + auto ret = cloudInfo.IsAllSwitchOff(); + EXPECT_FALSE(ret); +} } // namespace DistributedDataTest } // namespace OHOS::Test \ No newline at end of file diff --git a/services/distributeddataservice/service/test/rdb_asset_loader_test.cpp b/services/distributeddataservice/service/test/rdb_asset_loader_test.cpp index 0b7ac22b3..1bf6c5159 100644 --- a/services/distributeddataservice/service/test/rdb_asset_loader_test.cpp +++ b/services/distributeddataservice/service/test/rdb_asset_loader_test.cpp @@ -180,13 +180,13 @@ HWTEST_F(RdbAssetLoaderTest, RemoveLocalAssets, TestSize.Level0) } /** -* @tc.name: PostEvent -* @tc.desc: RdbAssetLoader PostEvent abnormal +* @tc.name: PostEvent001 +* @tc.desc: RdbAssetLoader PostEvent001 test * @tc.type: FUNC * @tc.require: * @tc.author: SQL */ -HWTEST_F(RdbAssetLoaderTest, PostEvent, TestSize.Level0) +HWTEST_F(RdbAssetLoaderTest, PostEvent001, TestSize.Level0) { BindAssets bindAssets; bindAssets.bindAssets = nullptr; @@ -201,6 +201,53 @@ HWTEST_F(RdbAssetLoaderTest, PostEvent, TestSize.Level0) EXPECT_EQ(result, DistributedDB::DBStatus::CLOUD_ERROR); } +/** +* @tc.name: PostEvent002 +* @tc.desc: RdbAssetLoader PostEvent002 test +* @tc.type: FUNC +* @tc.require: +* @tc.author: SQL +*/ +HWTEST_F(RdbAssetLoaderTest, PostEvent002, TestSize.Level0) +{ + DistributedData::Asset asset = { + .name = "", + .id = "", + .path = "", + .uri = "", + .modifyTime = "", + .createTime = "", + .size = "", + .hash = "", + .status = DistributedData::Asset::STATUS_DELETE, + }; + DistributedData::Assets assets; + assets.push_back(asset); + BindAssets bindAssets; + bindAssets.bindAssets = nullptr; + std::shared_ptr assetLoader = std::make_shared(); + DistributedRdb::RdbAssetLoader rdbAssetLoader(assetLoader, &bindAssets); + std::set skipAssets; + std::set deleteAssets; + rdbAssetLoader.PostEvent(DistributedData::AssetEvent::DOWNLOAD, assets, skipAssets, deleteAssets); + EXPECT_EQ(deleteAssets.size(), 1); +} + +/** +* @tc.name: ConvertStatus +* @tc.desc: RdbAssetLoader ConvertStatus abnormal +* @tc.type: FUNC +* @tc.require: +* @tc.author: SQL +*/ +HWTEST_F(RdbAssetLoaderTest, ConvertStatus, TestSize.Level0) +{ + auto status = RdbAssetLoader::ConvertStatus(DistributedRdb::RdbAssetLoader::AssetStatus::STATUS_DOWNLOADING); + EXPECT_EQ(status, DistributedDB::DBStatus::OK); + status = RdbAssetLoader::ConvertStatus(DistributedRdb::RdbAssetLoader::AssetStatus::STATUS_BUTT); + EXPECT_EQ(status, DistributedDB::DBStatus::CLOUD_ERROR); +} + /** * @tc.name: RdbWatcher * @tc.desc: RdbWatcher function test. diff --git a/services/distributeddataservice/service/test/rdb_cloud_test.cpp b/services/distributeddataservice/service/test/rdb_cloud_test.cpp index 8a87ae32b..603d1b928 100644 --- a/services/distributeddataservice/service/test/rdb_cloud_test.cpp +++ b/services/distributeddataservice/service/test/rdb_cloud_test.cpp @@ -136,6 +136,30 @@ HWTEST_F(RdbCloudTest, RdbCloudTest003, TestSize.Level1) EXPECT_EQ(result, DBStatus::CLOUD_ERROR); } +/** +* @tc.name: RdbCloudTest004 +* @tc.desc: RdbCloud UnLockCloudDB LockCloudDB InnerUnLock test. +* @tc.type: FUNC +* @tc.require: +* @tc.author: SQL +*/ +HWTEST_F(RdbCloudTest, RdbCloudTest004, TestSize.Level1) +{ + BindAssets bindAssets; + std::shared_ptr cloudDB = std::make_shared(); + RdbCloud rdbCloud(cloudDB, &bindAssets); + + auto err = rdbCloud.UnLockCloudDB(OHOS::DistributedRdb::RdbCloud::FLAG::SYSTEM_ABILITY); + EXPECT_EQ(err, GeneralError::E_NOT_SUPPORT); + + auto result = rdbCloud.LockCloudDB(OHOS::DistributedRdb::RdbCloud::FLAG::SYSTEM_ABILITY); + EXPECT_EQ(result.first, GeneralError::E_NOT_SUPPORT); + + rdbCloud.flag_ = 1; + err = rdbCloud.InnerUnLock(static_cast(0)); + EXPECT_EQ(err, GeneralError::E_OK); +} + /** * @tc.name: ConvertStatus * @tc.desc: RdbCloud ConvertStatus function test. @@ -160,6 +184,16 @@ HWTEST_F(RdbCloudTest, ConvertStatus, TestSize.Level1) EXPECT_EQ(result, DBStatus::CLOUD_ASSET_SPACE_INSUFFICIENT); result = rdbCloud.ConvertStatus(GeneralError::E_RECORD_EXIST_CONFLICT); EXPECT_EQ(result, DBStatus::CLOUD_RECORD_EXIST_CONFLICT); + result = rdbCloud.ConvertStatus(GeneralError::E_VERSION_CONFLICT); + EXPECT_EQ(result, DBStatus::CLOUD_VERSION_CONFLICT); + result = rdbCloud.ConvertStatus(GeneralError::E_RECORD_NOT_FOUND); + EXPECT_EQ(result, DBStatus::CLOUD_RECORD_NOT_FOUND); + result = rdbCloud.ConvertStatus(GeneralError::E_RECORD_ALREADY_EXISTED); + EXPECT_EQ(result, DBStatus::CLOUD_RECORD_ALREADY_EXISTED); + result = rdbCloud.ConvertStatus(GeneralError::E_FILE_NOT_EXIST); + EXPECT_EQ(result, DBStatus::LOCAL_ASSET_NOT_FOUND); + result = rdbCloud.ConvertStatus(GeneralError::E_TIME_OUT); + EXPECT_EQ(result, DBStatus::TIME_OUT); } /** @@ -191,5 +225,38 @@ HWTEST_F(RdbCloudTest, BlobToAssets, TestSize.Level1) auto results = rdbTranslate.BlobToAssets(blob); EXPECT_EQ(results, assets); } + +/** +* @tc.name: ConvertQuery +* @tc.desc: RdbCloud ConvertQuery function test. +* @tc.type: FUNC +* @tc.require: +* @tc.author: SQL +*/ +HWTEST_F(RdbCloudTest, ConvertQuery, TestSize.Level1) +{ + RdbCloud::DBQueryNodes nodes; + DistributedDB::QueryNode node = { DistributedDB::QueryNodeType::IN, "", {int64_t(1)} }; + nodes.push_back(node); + node = { DistributedDB::QueryNodeType::OR, "", {int64_t(1)} }; + nodes.push_back(node); + node = { DistributedDB::QueryNodeType::AND, "", {int64_t(1)} }; + nodes.push_back(node); + node = { DistributedDB::QueryNodeType::EQUAL_TO, "", {int64_t(1)} }; + nodes.push_back(node); + node = { DistributedDB::QueryNodeType::BEGIN_GROUP, "", {int64_t(1)} }; + nodes.push_back(node); + node = { DistributedDB::QueryNodeType::END_GROUP, "", {int64_t(1)} }; + nodes.push_back(node); + + auto result = RdbCloud::ConvertQuery(std::move(nodes)); + EXPECT_EQ(result.size(), 6); + + nodes.clear(); + node = { DistributedDB::QueryNodeType::ILLEGAL, "", {int64_t(1)} }; + nodes.push_back(node); + result = RdbCloud::ConvertQuery(std::move(nodes)); + EXPECT_EQ(result.size(), 0); +} } // namespace DistributedRDBTest } // namespace OHOS::Test \ No newline at end of file