!2419 补充端云接口分支覆盖率UT

Merge pull request !2419 from Jeam.wang/master
This commit is contained in:
openharmony_ci 2024-11-22 10:17:21 +00:00 committed by Gitee
commit 90ac4c083b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 150 additions and 3 deletions

View File

@ -529,6 +529,7 @@ ohos_unittest("RdbServiceTest") {
"-Dprotected=public", "-Dprotected=public",
"-Wno-multichar", "-Wno-multichar",
"-Wno-c99-designator", "-Wno-c99-designator",
"-fno-access-control", # Ignore Private Member Access Control
] ]
external_deps = [ external_deps = [

View File

@ -49,6 +49,7 @@
#include "store/auto_cache.h" #include "store/auto_cache.h"
#include "store/general_value.h" #include "store/general_value.h"
#include "store/store_info.h" #include "store/store_info.h"
#include "sync_manager.h"
#include "token_setproc.h" #include "token_setproc.h"
using namespace testing::ext; using namespace testing::ext;
@ -2002,5 +2003,36 @@ HWTEST_F(CloudDataTest, Report, TestSize.Level0)
auto ret = cloudReport->Report(reportParam); auto ret = cloudReport->Report(reportParam);
EXPECT_TRUE(ret); 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<CloudServerMock>();
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<CloudServerMock>();
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 DistributedDataTest
} // namespace OHOS::Test } // namespace OHOS::Test

View File

@ -180,13 +180,13 @@ HWTEST_F(RdbAssetLoaderTest, RemoveLocalAssets, TestSize.Level0)
} }
/** /**
* @tc.name: PostEvent * @tc.name: PostEvent001
* @tc.desc: RdbAssetLoader PostEvent abnormal * @tc.desc: RdbAssetLoader PostEvent001 test
* @tc.type: FUNC * @tc.type: FUNC
* @tc.require: * @tc.require:
* @tc.author: SQL * @tc.author: SQL
*/ */
HWTEST_F(RdbAssetLoaderTest, PostEvent, TestSize.Level0) HWTEST_F(RdbAssetLoaderTest, PostEvent001, TestSize.Level0)
{ {
BindAssets bindAssets; BindAssets bindAssets;
bindAssets.bindAssets = nullptr; bindAssets.bindAssets = nullptr;
@ -201,6 +201,53 @@ HWTEST_F(RdbAssetLoaderTest, PostEvent, TestSize.Level0)
EXPECT_EQ(result, DistributedDB::DBStatus::CLOUD_ERROR); 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> assetLoader = std::make_shared<AssetLoader>();
DistributedRdb::RdbAssetLoader rdbAssetLoader(assetLoader, &bindAssets);
std::set<std::string> skipAssets;
std::set<std::string> 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.name: RdbWatcher
* @tc.desc: RdbWatcher function test. * @tc.desc: RdbWatcher function test.

View File

@ -136,6 +136,30 @@ HWTEST_F(RdbCloudTest, RdbCloudTest003, TestSize.Level1)
EXPECT_EQ(result, DBStatus::CLOUD_ERROR); 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> cloudDB = std::make_shared<CloudDB>();
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<OHOS::DistributedRdb::RdbCloud::FLAG>(0));
EXPECT_EQ(err, GeneralError::E_OK);
}
/** /**
* @tc.name: ConvertStatus * @tc.name: ConvertStatus
* @tc.desc: RdbCloud ConvertStatus function test. * @tc.desc: RdbCloud ConvertStatus function test.
@ -160,6 +184,16 @@ HWTEST_F(RdbCloudTest, ConvertStatus, TestSize.Level1)
EXPECT_EQ(result, DBStatus::CLOUD_ASSET_SPACE_INSUFFICIENT); EXPECT_EQ(result, DBStatus::CLOUD_ASSET_SPACE_INSUFFICIENT);
result = rdbCloud.ConvertStatus(GeneralError::E_RECORD_EXIST_CONFLICT); result = rdbCloud.ConvertStatus(GeneralError::E_RECORD_EXIST_CONFLICT);
EXPECT_EQ(result, DBStatus::CLOUD_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); auto results = rdbTranslate.BlobToAssets(blob);
EXPECT_EQ(results, assets); 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 DistributedRDBTest
} // namespace OHOS::Test } // namespace OHOS::Test