mirror of
https://gitee.com/openharmony/distributeddatamgr_datamgr_service
synced 2024-11-27 00:51:12 +00:00
!2410 修改差异
Merge pull request !2410 from caozhijun/OpenHarmony-5.0.1-Release
This commit is contained in:
commit
fb72878688
@ -70,7 +70,6 @@
|
||||
"hitrace",
|
||||
"huks",
|
||||
"kv_store",
|
||||
"image_framework",
|
||||
"ipc",
|
||||
"memmgr",
|
||||
"napi",
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "app_data_change_listener.h"
|
||||
#include "app_device_change_listener.h"
|
||||
#include "block_data.h"
|
||||
#include "session.h"
|
||||
#include "socket.h"
|
||||
#include "softbus_bus_center.h"
|
||||
#include "softbus_client.h"
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include "commu_types.h"
|
||||
#include "executor_pool.h"
|
||||
#include "session.h"
|
||||
#include "socket.h"
|
||||
#include "softbus_bus_center.h"
|
||||
namespace OHOS::AppDistributedKv {
|
||||
|
@ -79,6 +79,7 @@ void InstallEventSubscriber::OnUninstall(const std::string &bundleName, int32_t
|
||||
ZLOGI("uninstalled bundleName:%{public}s storeId:%{public}s, userId:%{public}d, appIndex:%{public}d",
|
||||
bundleName.c_str(), Anonymous::Change(meta.storeId).c_str(), userId, appIndex);
|
||||
MetaDataManager::GetInstance().DelMeta(meta.GetKey());
|
||||
MetaDataManager::GetInstance().DelMeta(meta.GetKey(), true);
|
||||
MetaDataManager::GetInstance().DelMeta(meta.GetKeyLocal(), true);
|
||||
MetaDataManager::GetInstance().DelMeta(meta.GetSecretKey(), true);
|
||||
MetaDataManager::GetInstance().DelMeta(meta.GetStrategyKey());
|
||||
|
@ -524,6 +524,7 @@ Status KvStoreDataService::InitNbDbOption(const Options &options, const std::vec
|
||||
dbOption.createIfNecessary = options.createIfMissing;
|
||||
dbOption.isMemoryDb = (!options.persistent);
|
||||
dbOption.isEncryptedDb = options.encrypt;
|
||||
dbOption.isNeedCompressOnSync = options.isNeedCompress;
|
||||
if (options.encrypt) {
|
||||
dbOption.cipher = DistributedDB::CipherType::AES_256_GCM;
|
||||
dbOption.passwd = password;
|
||||
@ -805,8 +806,9 @@ int32_t KvStoreDataService::OnScreenUnlocked(int32_t user)
|
||||
int32_t KvStoreDataService::ClearAppStorage(const std::string &bundleName, int32_t userId, int32_t appIndex,
|
||||
int32_t tokenId)
|
||||
{
|
||||
auto callerToken = IPCSkeleton::GetCallingTokenID();
|
||||
NativeTokenInfo nativeTokenInfo;
|
||||
if (AccessTokenKit::GetNativeTokenInfo(tokenId, nativeTokenInfo) != RET_SUCCESS ||
|
||||
if (AccessTokenKit::GetNativeTokenInfo(callerToken, nativeTokenInfo) != RET_SUCCESS ||
|
||||
nativeTokenInfo.processName != FOUNDATION_PROCESS_NAME) {
|
||||
ZLOGE("passed wrong, tokenId: %{public}u, bundleName:%{public}s, user:%{public}d, appIndex:%{public}d",
|
||||
tokenId, bundleName.c_str(), userId, appIndex);
|
||||
|
@ -47,7 +47,7 @@ private:
|
||||
|
||||
static constexpr int32_t NO_ACCOUNT = 0;
|
||||
static constexpr int32_t IDENTICAL_ACCOUNT = 1;
|
||||
static constexpr const char *defaultAccountId = "default";
|
||||
static constexpr const char *defaultAccountId = "ohosAnonymousUid";
|
||||
};
|
||||
} // namespace OHOS::DistributedData
|
||||
#endif // DISTRIBUTEDDATAMGR_UPGRADE_MANAGER_H
|
||||
|
@ -45,11 +45,8 @@ class KvStoreDataServiceClearTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
|
||||
NativeTokenInfoParams infoInstance {0};
|
||||
protected:
|
||||
static constexpr const char *TEST_USER = "100";
|
||||
static constexpr const char *TEST_BUNDLE = "ohos.test.demo";
|
||||
@ -57,16 +54,10 @@ protected:
|
||||
static constexpr int32_t TEST_UID = 2000000;
|
||||
static constexpr int32_t TEST_USERID = 100;
|
||||
static constexpr const char *BUNDLE_NAME = "ohos.test.demo";
|
||||
static constexpr const char *BUNDLENAME_NO = "com.sample.helloworld";
|
||||
static constexpr int32_t USER_ID = 100;
|
||||
static constexpr int32_t USERID_NO = 10;
|
||||
static constexpr int32_t APP_INDEX = 0;
|
||||
static constexpr int32_t APPINDEX_NO = 2;
|
||||
static constexpr int32_t INVALID_TOKEN = 222;
|
||||
|
||||
DistributedData::StoreMetaData metaData_;
|
||||
DistributedData::StoreMetaDataLocal localMeta_;
|
||||
|
||||
void InitMetaData();
|
||||
};
|
||||
|
||||
@ -80,55 +71,12 @@ void KvStoreDataServiceClearTest::TearDownTestCase(void)
|
||||
|
||||
void KvStoreDataServiceClearTest::SetUp(void)
|
||||
{
|
||||
DistributedData::Bootstrap::GetInstance().LoadComponents();
|
||||
DistributedData::Bootstrap::GetInstance().LoadDirectory();
|
||||
DistributedData::Bootstrap::GetInstance().LoadCheckers();
|
||||
|
||||
infoInstance.dcapsNum = 0;
|
||||
infoInstance.permsNum = 0;
|
||||
infoInstance.aclsNum = 0;
|
||||
infoInstance.dcaps = nullptr;
|
||||
infoInstance.perms = nullptr;
|
||||
infoInstance.acls = nullptr;
|
||||
infoInstance.processName = "KvStoreDataServiceClearTest";
|
||||
infoInstance.aplStr = "system_core";
|
||||
|
||||
HapInfoParams info = {
|
||||
.userID = TEST_USERID,
|
||||
.bundleName = TEST_BUNDLE,
|
||||
.instIndex = 0,
|
||||
.appIDDesc = TEST_BUNDLE
|
||||
};
|
||||
PermissionDef infoManagerTestPermDef = {
|
||||
.permissionName = "ohos.permission.test",
|
||||
.bundleName = TEST_BUNDLE,
|
||||
.grantMode = 1,
|
||||
.availableLevel = APL_NORMAL,
|
||||
.label = "label",
|
||||
.labelId = 1,
|
||||
.description = "open the door",
|
||||
.descriptionId = 1
|
||||
};
|
||||
PermissionStateFull infoManagerTestState = {
|
||||
.permissionName = "ohos.permission.test",
|
||||
.isGeneral = true,
|
||||
.resDeviceID = {"local"},
|
||||
.grantStatus = {PermissionState::PERMISSION_GRANTED},
|
||||
.grantFlags = {1}
|
||||
};
|
||||
HapPolicyParams policy = {
|
||||
.apl = APL_NORMAL,
|
||||
.domain = "test.domain",
|
||||
.permList = {infoManagerTestPermDef},
|
||||
.permStateList = {infoManagerTestState}
|
||||
};
|
||||
AccessTokenKit::AllocHapToken(info, policy);
|
||||
}
|
||||
|
||||
void KvStoreDataServiceClearTest::TearDown(void)
|
||||
{
|
||||
auto tokenId = AccessTokenKit::GetHapTokenID(TEST_USERID, TEST_BUNDLE, 0);
|
||||
AccessTokenKit::DeleteToken(tokenId);
|
||||
}
|
||||
|
||||
void KvStoreDataServiceClearTest::InitMetaData()
|
||||
@ -155,7 +103,7 @@ void KvStoreDataServiceClearTest::InitMetaData()
|
||||
|
||||
/**
|
||||
* @tc.name: ClearAppStorage001
|
||||
* @tc.desc: Test that the parameters are entered correctly
|
||||
* @tc.desc: The parameters are valid but have no metaData
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author: suoqilong
|
||||
@ -163,49 +111,23 @@ void KvStoreDataServiceClearTest::InitMetaData()
|
||||
HWTEST_F(KvStoreDataServiceClearTest, ClearAppStorage001, TestSize.Level1)
|
||||
{
|
||||
auto kvDataService = OHOS::DistributedKv::KvStoreDataService();
|
||||
auto tokenIdOk = AccessTokenKit::GetHapTokenID(TEST_USERID, TEST_BUNDLE, 0);
|
||||
auto ret =
|
||||
kvDataService.ClearAppStorage(BUNDLE_NAME, USER_ID, APP_INDEX, INVALID_TOKEN);
|
||||
EXPECT_EQ(ret, Status::ERROR);
|
||||
|
||||
ret = kvDataService.ClearAppStorage(BUNDLENAME_NO, USER_ID, APP_INDEX, tokenIdOk);
|
||||
EXPECT_EQ(ret, Status::ERROR);
|
||||
|
||||
ret = kvDataService.ClearAppStorage(BUNDLE_NAME, USERID_NO, APP_INDEX, tokenIdOk);
|
||||
EXPECT_EQ(ret, Status::ERROR);
|
||||
|
||||
ret = kvDataService.ClearAppStorage(BUNDLE_NAME, USER_ID, APPINDEX_NO, tokenIdOk);
|
||||
auto tokenIdOk = AccessTokenKit::GetNativeTokenId("foundation");
|
||||
SetSelfTokenID(tokenIdOk);
|
||||
auto ret = kvDataService.ClearAppStorage(BUNDLE_NAME, USER_ID, APP_INDEX, tokenIdOk);
|
||||
EXPECT_EQ(ret, Status::ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ClearAppStorage002
|
||||
* @tc.desc: The parameters are valid but have no metaData
|
||||
* @tc.desc: Test that the cleanup is implemented
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author: suoqilong
|
||||
*/
|
||||
HWTEST_F(KvStoreDataServiceClearTest, ClearAppStorage002, TestSize.Level1)
|
||||
{
|
||||
auto kvDataService = OHOS::DistributedKv::KvStoreDataService();
|
||||
auto tokenIdOk = AccessTokenKit::GetHapTokenID(TEST_USERID, TEST_BUNDLE, 0);
|
||||
|
||||
auto ret =
|
||||
kvDataService.ClearAppStorage(BUNDLE_NAME, USER_ID, APP_INDEX, tokenIdOk);
|
||||
EXPECT_EQ(ret, Status::ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ClearAppStorage003
|
||||
* @tc.desc: Test that the cleanup is implemented
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author: suoqilong
|
||||
*/
|
||||
HWTEST_F(KvStoreDataServiceClearTest, ClearAppStorage003, TestSize.Level1)
|
||||
{
|
||||
auto executors = std::make_shared<ExecutorPool>(12, 5);
|
||||
// Create an object of the ExecutorPool class and pass 12 and 5 as arguments to the constructor of the class
|
||||
auto executors = std::make_shared<ExecutorPool>(2, 1);
|
||||
// Create an object of the ExecutorPool class and pass 2 and 1 as arguments to the constructor of the class
|
||||
KvStoreMetaManager::GetInstance().BindExecutor(executors);
|
||||
KvStoreMetaManager::GetInstance().InitMetaParameter();
|
||||
DmAdapter::GetInstance().Init(executors);
|
||||
@ -226,17 +148,17 @@ HWTEST_F(KvStoreDataServiceClearTest, ClearAppStorage003, TestSize.Level1)
|
||||
EXPECT_TRUE(MetaDataManager::GetInstance().LoadMeta(metaData_.appId, metaData_, true));
|
||||
EXPECT_TRUE(MetaDataManager::GetInstance().LoadMeta(metaData_.GetKeyLocal(), localMeta_, true));
|
||||
|
||||
auto tokenIdOk = AccessTokenKit::GetHapTokenID(TEST_USERID, TEST_BUNDLE, 0);
|
||||
auto tokenIdOk = AccessTokenKit::GetNativeTokenId("foundation");
|
||||
SetSelfTokenID(tokenIdOk);
|
||||
auto kvDataService = OHOS::DistributedKv::KvStoreDataService();
|
||||
auto ret =
|
||||
kvDataService.ClearAppStorage(BUNDLE_NAME, USER_ID, APP_INDEX, tokenIdOk);
|
||||
EXPECT_EQ(ret, Status::ERROR);
|
||||
auto ret = kvDataService.ClearAppStorage(BUNDLE_NAME, USER_ID, APP_INDEX, tokenIdOk);
|
||||
EXPECT_EQ(ret, Status::SUCCESS);
|
||||
|
||||
EXPECT_TRUE(MetaDataManager::GetInstance().LoadMeta(metaData_.GetKey(), metaData_));
|
||||
EXPECT_TRUE(MetaDataManager::GetInstance().LoadMeta(metaData_.GetSecretKey(), metaData_, true));
|
||||
EXPECT_TRUE(MetaDataManager::GetInstance().LoadMeta(metaData_.GetStrategyKey(), metaData_));
|
||||
EXPECT_TRUE(MetaDataManager::GetInstance().LoadMeta(metaData_.appId, metaData_, true));
|
||||
EXPECT_TRUE(MetaDataManager::GetInstance().LoadMeta(metaData_.GetKeyLocal(), localMeta_, true));
|
||||
EXPECT_FALSE(MetaDataManager::GetInstance().LoadMeta(metaData_.GetKey(), metaData_));
|
||||
EXPECT_FALSE(MetaDataManager::GetInstance().LoadMeta(metaData_.GetSecretKey(), metaData_, true));
|
||||
EXPECT_FALSE(MetaDataManager::GetInstance().LoadMeta(metaData_.GetStrategyKey(), metaData_));
|
||||
EXPECT_FALSE(MetaDataManager::GetInstance().LoadMeta(metaData_.appId, metaData_, true));
|
||||
EXPECT_FALSE(MetaDataManager::GetInstance().LoadMeta(metaData_.GetKeyLocal(), localMeta_, true));
|
||||
|
||||
MetaDataManager::GetInstance().DelMeta(metaData_.GetKey());
|
||||
EXPECT_FALSE(MetaDataManager::GetInstance().LoadMeta(metaData_.GetKey(), metaData_));
|
||||
|
@ -65,8 +65,8 @@ public:
|
||||
API_EXPORT virtual void UnsubscribeAccountEvent() = 0;
|
||||
API_EXPORT virtual bool QueryUsers(std::vector<int> &users) = 0;
|
||||
API_EXPORT virtual bool QueryForegroundUsers(std::vector<int> &users) = 0;
|
||||
API_EXPORT virtual bool IsLoginAccount() = 0;
|
||||
API_EXPORT virtual bool QueryForegroundUserId(int &foregroundUserId) = 0;
|
||||
API_EXPORT virtual bool IsLoginAccount() = 0;
|
||||
API_EXPORT virtual bool IsVerified(int userId) = 0;
|
||||
API_EXPORT virtual bool RegisterHashFunc(HashFunc hash) = 0;
|
||||
API_EXPORT virtual void BindExecutor(std::shared_ptr<ExecutorPool> executors) = 0;
|
||||
|
@ -33,8 +33,8 @@ public:
|
||||
std::string storeId;
|
||||
std::string deviceId;
|
||||
std::string bundleName;
|
||||
int changeType = 0; // 0 means CLOUD_DATA_CHANGE
|
||||
std::vector<std::string> tables;
|
||||
int changeType = 0; // 0 means CLOUD_DATA_CHANGE
|
||||
};
|
||||
|
||||
RemoteChangeEvent(int32_t evtId, DataInfo&& info);
|
||||
|
@ -20,7 +20,7 @@
|
||||
namespace OHOS::DistributedData {
|
||||
class API_EXPORT VersionMetaData final : public Serializable {
|
||||
public:
|
||||
static constexpr int32_t CURRENT_VERSION = 3;
|
||||
static constexpr int32_t CURRENT_VERSION = 4;
|
||||
static constexpr int32_t INVALID_VERSION = -1;
|
||||
int32_t version = INVALID_VERSION;
|
||||
|
||||
|
@ -127,6 +127,11 @@ ohos_unittest("ServiceUtilsTest") {
|
||||
|
||||
configs = [ ":module_private_config" ]
|
||||
|
||||
cflags = [
|
||||
"-Dprivate=public",
|
||||
"-Dprotected=public",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libnativetoken",
|
||||
@ -207,6 +212,20 @@ ohos_unittest("CloudInfoTest") {
|
||||
deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ]
|
||||
}
|
||||
|
||||
ohos_unittest("ConstantTest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "constant_test.cpp" ]
|
||||
configs = [ ":module_private_config" ]
|
||||
deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ]
|
||||
}
|
||||
|
||||
ohos_unittest("CryptoTest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "crypto_test.cpp" ]
|
||||
configs = [ ":module_private_config" ]
|
||||
deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ]
|
||||
}
|
||||
|
||||
ohos_unittest("EventTest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "event_test.cpp" ]
|
||||
@ -214,20 +233,6 @@ ohos_unittest("EventTest") {
|
||||
deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ]
|
||||
}
|
||||
|
||||
ohos_unittest("GeneralStoreTest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "general_store_test.cpp" ]
|
||||
configs = [ ":module_private_config" ]
|
||||
deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ]
|
||||
}
|
||||
|
||||
ohos_unittest("SubscriptionTest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "subscription_test.cpp" ]
|
||||
configs = [ ":module_private_config" ]
|
||||
deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ]
|
||||
}
|
||||
|
||||
ohos_unittest("FeatureTest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "feature_test.cpp" ]
|
||||
@ -258,6 +263,20 @@ ohos_unittest("MetaDataManagerTest") {
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("GeneralStoreTest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "general_store_test.cpp" ]
|
||||
configs = [ ":module_private_config" ]
|
||||
deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ]
|
||||
}
|
||||
|
||||
ohos_unittest("SubscriptionTest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "subscription_test.cpp" ]
|
||||
configs = [ ":module_private_config" ]
|
||||
deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ]
|
||||
}
|
||||
|
||||
ohos_unittest("StoreMetaDataLocalTest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "store_meta_data_local_test.cpp" ]
|
||||
@ -265,20 +284,6 @@ ohos_unittest("StoreMetaDataLocalTest") {
|
||||
deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ]
|
||||
}
|
||||
|
||||
ohos_unittest("ConstantTest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "constant_test.cpp" ]
|
||||
configs = [ ":module_private_config" ]
|
||||
deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ]
|
||||
}
|
||||
|
||||
ohos_unittest("CryptoTest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "crypto_test.cpp" ]
|
||||
configs = [ ":module_private_config" ]
|
||||
deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ]
|
||||
}
|
||||
|
||||
ohos_unittest("ServiceMetaDataTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
|
@ -257,4 +257,20 @@ HWTEST_F(FeatureSystemTest, FeatureTest002, TestSize.Level1)
|
||||
ret = mockFeature.OnSessionReady(device);
|
||||
EXPECT_EQ(ret, E_OK);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @tc.name: OnScreenUnlockedTest
|
||||
* @tc.desc: test OnScreenUnlocked
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(FeatureSystemTest, OnScreenUnlockedTest, TestSize.Level1)
|
||||
{
|
||||
MockFeature mockFeature;
|
||||
int32_t user = 0;
|
||||
int32_t ret = mockFeature.OnScreenUnlocked(user);
|
||||
EXPECT_EQ(ret, E_OK);
|
||||
}
|
||||
} // namespace OHOS::Test
|
@ -45,7 +45,6 @@ public:
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
std::shared_ptr<ExecutorPool> executors = std::make_shared<ExecutorPool>(NUM_MAX, NUM_MIN);
|
||||
Bootstrap::GetInstance().LoadComponents();
|
||||
Bootstrap::GetInstance().LoadDirectory();
|
||||
Bootstrap::GetInstance().LoadCheckers();
|
||||
KvStoreMetaManager::GetInstance().BindExecutor(executors);
|
||||
@ -462,6 +461,16 @@ HWTEST_F(ServiceMetaDataTest, StoreMetaData006, TestSize.Level1)
|
||||
EXPECT_FALSE(storemetaData1 == storemetaData2);
|
||||
storemetaData2.isNeedCompress = true;
|
||||
EXPECT_TRUE(storemetaData1 == storemetaData2);
|
||||
|
||||
storemetaData1.enableCloud = true;
|
||||
EXPECT_FALSE(storemetaData1 == storemetaData2);
|
||||
storemetaData2.enableCloud = true;
|
||||
EXPECT_TRUE(storemetaData1 == storemetaData2);
|
||||
|
||||
storemetaData1.cloudAutoSync = true;
|
||||
EXPECT_FALSE(storemetaData1 == storemetaData2);
|
||||
storemetaData2.cloudAutoSync = true;
|
||||
EXPECT_TRUE(storemetaData1 == storemetaData2);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -508,6 +517,16 @@ HWTEST_F(ServiceMetaDataTest, StoreMetaData007, TestSize.Level1)
|
||||
EXPECT_TRUE(storemetaData1 != storemetaData2);
|
||||
storemetaData2.isNeedCompress = true;
|
||||
EXPECT_FALSE(storemetaData1 != storemetaData2);
|
||||
|
||||
storemetaData1.enableCloud = true;
|
||||
EXPECT_TRUE(storemetaData1 != storemetaData2);
|
||||
storemetaData2.enableCloud = true;
|
||||
EXPECT_FALSE(storemetaData1 != storemetaData2);
|
||||
|
||||
storemetaData1.cloudAutoSync = true;
|
||||
EXPECT_TRUE(storemetaData1 != storemetaData2);
|
||||
storemetaData2.cloudAutoSync = true;
|
||||
EXPECT_FALSE(storemetaData1 != storemetaData2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,22 +37,45 @@ public:
|
||||
HWTEST_F(StoreMetaDataLocalTest, EqualityOperatorTest, TestSize.Level1)
|
||||
{
|
||||
StoreMetaDataLocal metaData1;
|
||||
metaData1.isAutoSync = true;
|
||||
metaData1.isBackup = true;
|
||||
StoreMetaDataLocal metaData2;
|
||||
metaData2.isAutoSync = true;
|
||||
metaData2.isBackup = false;
|
||||
StoreMetaDataLocal metaData3;
|
||||
|
||||
ASSERT_TRUE(metaData1 == metaData2);
|
||||
metaData3.isAutoSync = true;
|
||||
ASSERT_FALSE(metaData1 == metaData3);
|
||||
metaData3.isBackup = true;
|
||||
ASSERT_FALSE(metaData1 == metaData3);
|
||||
ASSERT_TRUE(metaData1 != metaData3);
|
||||
ASSERT_FALSE(metaData1 != metaData2);
|
||||
metaData3.isDirty = true;
|
||||
ASSERT_FALSE(metaData1 == metaData3);
|
||||
metaData3.isEncrypt = true;
|
||||
ASSERT_FALSE(metaData1 == metaData3);
|
||||
metaData3.isPublic = true;
|
||||
ASSERT_FALSE(metaData1 == metaData3);
|
||||
|
||||
ASSERT_FALSE(metaData1 == metaData2);
|
||||
ASSERT_TRUE(metaData1 == metaData3);
|
||||
metaData2.isAutoSync = true;
|
||||
ASSERT_FALSE(metaData2 == metaData3);
|
||||
metaData2.isBackup = true;
|
||||
ASSERT_FALSE(metaData2 == metaData3);
|
||||
metaData2.isDirty = true;
|
||||
ASSERT_FALSE(metaData2 == metaData3);
|
||||
metaData2.isEncrypt = true;
|
||||
ASSERT_FALSE(metaData2 == metaData3);
|
||||
metaData2.isPublic = true;
|
||||
ASSERT_TRUE(metaData2 == metaData3);
|
||||
|
||||
ASSERT_TRUE(metaData1 != metaData2);
|
||||
ASSERT_FALSE(metaData1 != metaData3);
|
||||
ASSERT_TRUE(metaData2 != metaData3);
|
||||
metaData2.isBackup = false;
|
||||
ASSERT_FALSE(metaData2 == metaData3);
|
||||
metaData2.isBackup = true;
|
||||
metaData2.isDirty = false;
|
||||
ASSERT_FALSE(metaData2 == metaData3);
|
||||
metaData2.isBackup = true;
|
||||
metaData2.isEncrypt = false;
|
||||
ASSERT_FALSE(metaData2 == metaData3);
|
||||
metaData2.isBackup = true;
|
||||
metaData2.isPublic = false;
|
||||
ASSERT_FALSE(metaData2 == metaData3);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,5 +118,8 @@ HWTEST_F(StoreMetaDataLocalTest, GetPolicy, TestSize.Level1)
|
||||
policy.index = 1;
|
||||
EXPECT_FALSE(metaData.HasPolicy(type));
|
||||
EXPECT_TRUE(policy.IsValueEffect());
|
||||
type = UINT32_MAX;
|
||||
policy = metaData.GetPolicy(type);
|
||||
EXPECT_EQ(policy.type, type);
|
||||
}
|
||||
} // namespace OHOS::Test
|
@ -21,6 +21,7 @@
|
||||
#include "ipc_skeleton.h"
|
||||
#include "log_print.h"
|
||||
#include "utils/block_integer.h"
|
||||
#include "utils/constant.h"
|
||||
#include "utils/converter.h"
|
||||
#include "utils/ref_count.h"
|
||||
#include "utils/endian_converter.h"
|
||||
@ -130,6 +131,10 @@ HWTEST_F(RefCountTest, Constructortest, TestSize.Level2)
|
||||
std::function<void()> action = []() { };
|
||||
RefCount refCountWithAction(action);
|
||||
EXPECT_TRUE(refCountWithAction);
|
||||
|
||||
std::function<void()> actions;
|
||||
RefCount refCountWithActions(actions);
|
||||
EXPECT_TRUE(refCountWithActions);
|
||||
int num = 0;
|
||||
{
|
||||
RefCount refCount([&num]() {
|
||||
@ -158,6 +163,8 @@ HWTEST_F(RefCountTest, Constructortest, TestSize.Level2)
|
||||
RefCount refCount6 = std::move(refCount2);
|
||||
refCount6 = std::move(refCount4);
|
||||
ASSERT_TRUE(refCount6);
|
||||
|
||||
EXPECT_TRUE(refCount5 = refCount5);
|
||||
}
|
||||
ASSERT_EQ(num, 10);
|
||||
}
|
||||
@ -189,4 +196,34 @@ HWTEST_F(ServiceUtilsTest, HostToNet, TestSize.Level1)
|
||||
uint64_t hostValue64 = NetToHost(NET_VALUE64);
|
||||
EXPECT_EQ(hostValue64, le64toh(NET_VALUE64));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DCopy
|
||||
* @tc.desc: test Constant::DCopy function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author: SQL
|
||||
*/
|
||||
HWTEST_F(ServiceUtilsTest, DCopy, TestSize.Level1)
|
||||
{
|
||||
Constant constant;
|
||||
uint8_t *tag = nullptr;
|
||||
size_t tagLen = 1;
|
||||
uint8_t *src = nullptr;
|
||||
size_t srcLen = 0;
|
||||
|
||||
uint8_t tags[10];
|
||||
size_t tagsLen = 10;
|
||||
uint8_t srcs[10];
|
||||
size_t srcsLen = 10;
|
||||
|
||||
EXPECT_FALSE(constant.DCopy(tag, tagLen, src, srcLen));
|
||||
EXPECT_FALSE(constant.DCopy(tag, tagsLen, src, srcsLen));
|
||||
EXPECT_FALSE(constant.DCopy(tags, tagLen, src, srcLen));
|
||||
EXPECT_FALSE(constant.DCopy(tag, tagLen, srcs, srcLen));
|
||||
EXPECT_FALSE(constant.DCopy(tags, tagsLen, src, srcsLen));
|
||||
EXPECT_FALSE(constant.DCopy(tag, tagsLen, srcs, srcsLen));
|
||||
EXPECT_FALSE(constant.DCopy(tags, tagLen, srcs, srcLen));
|
||||
EXPECT_TRUE(constant.DCopy(tags, tagsLen, srcs, srcsLen));
|
||||
}
|
||||
} // namespace OHOS::Test
|
@ -56,7 +56,6 @@ ohos_shared_library("opencloudextension") {
|
||||
external_deps = [
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"hilog:libhilog",
|
||||
"json:nlohmann_json_static",
|
||||
"kv_store:distributeddata_inner",
|
||||
]
|
||||
subsystem_name = "distributeddatamgr"
|
||||
|
@ -178,11 +178,6 @@ void SchedulerManager::ExecuteSchedulerSQL(const std::string &rdbDir, const int3
|
||||
count);
|
||||
return;
|
||||
}
|
||||
errCode = resultSet->GoToFirstRow();
|
||||
if (errCode != E_OK) {
|
||||
ZLOGE("GoToFirstRow error, %{public}s, %{public}" PRId64 ", %{public}s, errCode is %{public}d",
|
||||
DistributedData::Anonymous::Change(key.uri).c_str(), key.subscriberId, key.bundleName.c_str(), errCode);
|
||||
}
|
||||
}
|
||||
|
||||
void SchedulerManager::GenRemindTimerFuncParams(
|
||||
|
@ -259,7 +259,7 @@ static void MergeAssetData(VBucket& record, const Asset& newAsset, const AssetBi
|
||||
auto* asset = Traits::get_if<DistributedData::Asset>(&value);
|
||||
if (asset->name != newAsset.name) {
|
||||
ZLOGD("Asset not same, old uri: %{public}s, new uri: %{public}s",
|
||||
Anonymous::Change(asset->uri).c_str(), Anonymous::Change(newAsset.uri).c_str());
|
||||
Anonymous::Change(asset->uri, true).c_str(), Anonymous::Change(newAsset.uri, true).c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ int32_t ObjectSnapshot::BindAsset(const Asset& asset, const DistributedData::Ass
|
||||
const StoreInfo& storeInfo)
|
||||
{
|
||||
if (IsBoundAsset(asset)) {
|
||||
ZLOGD("Asset is bound. asset.uri:%{public}s :", Anonymous::Change(asset.uri).c_str());
|
||||
ZLOGD("Asset is bound. asset.uri:%{public}s :", Anonymous::Change(asset.uri, true).c_str());
|
||||
return E_OK;
|
||||
}
|
||||
changedAssets_[asset.uri] = ChangedAssetInfo(asset, bindInfo, storeInfo);
|
||||
|
@ -904,6 +904,7 @@ ohos_unittest("DataShareServiceImplTest") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"ability_runtime:dataobs_manager",
|
||||
@ -1000,6 +1001,37 @@ ohos_unittest("KvdbServiceImplTest") {
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("DumpHelperTest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [
|
||||
"${data_service_path}/service/dumper/src/dump_helper.cpp",
|
||||
"dump_helper_test.cpp",
|
||||
]
|
||||
|
||||
include_dirs = [ "${data_service_path}/service/dumper/include" ]
|
||||
|
||||
configs = [ ":module_private_config" ]
|
||||
|
||||
cflags = [
|
||||
"-Dprivate=public",
|
||||
"-Dprotected=public",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"kv_store:distributeddata_inner",
|
||||
"kv_store:distributeddb",
|
||||
"relational_store:native_rdb",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${data_service_path}/framework:distributeddatasvcfwk",
|
||||
"${data_service_path}/service:distributeddatasvc",
|
||||
"//third_party/googletest:gtest_main",
|
||||
]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
@ -1017,6 +1049,7 @@ group("unittest") {
|
||||
":DataShareServiceImplTest",
|
||||
":DeviceMatrixTest",
|
||||
":DirectoryManagerTest",
|
||||
":DumpHelperTest",
|
||||
":KVDBGeneralStoreTest",
|
||||
":KvdbServiceImplTest",
|
||||
":MetaDataTest",
|
||||
|
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#define LOG_TAG "DumpHelperTest "
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "log_print.h"
|
||||
#include "dump_helper.h"
|
||||
#include "dump/dump_manager.h"
|
||||
#include "types.h"
|
||||
|
||||
using namespace OHOS;
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::DistributedData;
|
||||
namespace OHOS::Test {
|
||||
namespace DistributedDataTest {
|
||||
class DumpHelperTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void){};
|
||||
static void TearDownTestCase(void){};
|
||||
void SetUp();
|
||||
void TearDown(){};
|
||||
};
|
||||
|
||||
void DumpHelperTest::SetUp(void)
|
||||
{
|
||||
DumpManager &dumpManager = DumpManager::GetInstance();
|
||||
DumpManager::Config config;
|
||||
config.dumpName = "test_dump";
|
||||
config.fullCmd = "test_full_cmd";
|
||||
config.abbrCmd = "test_abbr_cmd";
|
||||
config.countPrintf = 1;
|
||||
config.infoName = "test_info";
|
||||
config.minParamsNum = 2; //minParamsNum is 2
|
||||
config.maxParamsNum = 5; //maxParamsNum is 5
|
||||
config.parentNode = "test_parent";
|
||||
config.childNode = "test_child";
|
||||
config.dumpCaption = {"test_caption1", "test_caption2"};
|
||||
|
||||
dumpManager.AddConfig("111", config);
|
||||
dumpManager.GetHandler(config.infoName);
|
||||
DumpManager::Config result = dumpManager.GetConfig("111");
|
||||
ASSERT_EQ(result.dumpName, config.dumpName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetInstanceTest
|
||||
* @tc.desc: GetInstance test.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author: SQL
|
||||
*/
|
||||
HWTEST_F(DumpHelperTest, GetInstanceTest, TestSize.Level0)
|
||||
{
|
||||
DumpHelper &dumpHelper = DumpHelper::GetInstance();
|
||||
EXPECT_NE(&dumpHelper, nullptr);
|
||||
|
||||
int fd = 1;
|
||||
std::vector<std::string> args;
|
||||
EXPECT_TRUE(dumpHelper.Dump(fd, args));
|
||||
|
||||
args = {"COMMAND_A", "ARG_1", "ARG_2"};
|
||||
EXPECT_TRUE(dumpHelper.Dump(fd, args));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AddErrorInfoTest
|
||||
* @tc.desc: AddErrorInfo test.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author: SQL
|
||||
*/
|
||||
HWTEST_F(DumpHelperTest, AddErrorInfoTest, TestSize.Level0)
|
||||
{
|
||||
DumpHelper &dumpHelper = DumpHelper::GetInstance();
|
||||
EXPECT_NE(&dumpHelper, nullptr);
|
||||
int32_t errorCode = 1001;
|
||||
std::string errorInfo = "Test error information";
|
||||
|
||||
dumpHelper.AddErrorInfo(errorCode, errorInfo);
|
||||
|
||||
const OHOS::DistributedData::DumpHelper::ErrorInfo& lastError = dumpHelper.errorInfo_.back();
|
||||
EXPECT_EQ(lastError.errorCode, errorCode);
|
||||
EXPECT_EQ(lastError.errorInfo, errorInfo);
|
||||
}
|
||||
} // namespace DistributedDataTest
|
||||
} // namespace OHOS::Test
|
@ -569,6 +569,7 @@ HWTEST_F(KVDBGeneralStoreTest, Release, TestSize.Level0)
|
||||
auto ret = store->Release();
|
||||
EXPECT_EQ(ret, 0);
|
||||
store = new (std::nothrow) KVDBGeneralStore(metaData_);
|
||||
store->ref_ = 0;
|
||||
ret = store->Release();
|
||||
EXPECT_EQ(ret, 0);
|
||||
store->ref_ = 2;
|
||||
|
@ -16,11 +16,9 @@
|
||||
#define LOG_TAG "ObjectAssetLoaderTest"
|
||||
|
||||
#include "object_asset_loader.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "executor_pool.h"
|
||||
#include "snapshot/machine_status.h"
|
||||
#include "executor_pool.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::DistributedObject;
|
||||
|
@ -19,9 +19,9 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "executor_pool.h"
|
||||
#include "object_asset_loader.h"
|
||||
#include "snapshot/machine_status.h"
|
||||
#include "object_asset_loader.h"
|
||||
#include "executor_pool.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::DistributedObject;
|
||||
|
@ -16,14 +16,12 @@
|
||||
#define LOG_TAG "ObjectManagerTest"
|
||||
|
||||
#include "object_manager.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <ipc_skeleton.h>
|
||||
|
||||
#include "executor_pool.h"
|
||||
#include "kv_store_nb_delegate_mock.h"
|
||||
#include "object_types.h"
|
||||
#include "snapshot/machine_status.h"
|
||||
#include "executor_pool.h"
|
||||
#include "object_types.h"
|
||||
#include "kv_store_nb_delegate_mock.h"
|
||||
#include <ipc_skeleton.h>
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::DistributedObject;
|
||||
|
@ -16,11 +16,9 @@
|
||||
#define LOG_TAG "ObjectSnapshotTest"
|
||||
|
||||
#include "object_snapshot.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "executor_pool.h"
|
||||
#include "snapshot/machine_status.h"
|
||||
#include "executor_pool.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::DistributedObject;
|
||||
|
Loading…
Reference in New Issue
Block a user