mirror of
https://gitee.com/openharmony/deviceprofile_device_info_manager
synced 2024-11-23 07:30:13 +00:00
commit
71554b3a5c
@ -20,6 +20,7 @@
|
||||
#include "profile_utils.h"
|
||||
#include "distributed_device_profile_log.h"
|
||||
#include "distributed_device_profile_errors.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "device_manager.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
@ -314,16 +315,16 @@ int32_t ProfileUtils::EntriesToTrustDeviceProfile(const ValuesBucket& values, Tr
|
||||
ValueObject valueObject;
|
||||
std::string strValue = "";
|
||||
int32_t intValue = 0;
|
||||
if (values.GetObject(DEVICE_ID, valueObject) && valueObject.GetString(strValue)) {
|
||||
if (values.GetObject(DEVICE_ID, valueObject) && valueObject.GetString(strValue) == NativeRdb::E_OK) {
|
||||
profile.SetDeviceId(strValue);
|
||||
}
|
||||
if (values.GetObject(DEVICE_ID_HASH, valueObject) && valueObject.GetString(strValue)) {
|
||||
if (values.GetObject(DEVICE_ID_HASH, valueObject) && valueObject.GetString(strValue) == NativeRdb::E_OK) {
|
||||
profile.SetDeviceIdHash(strValue);
|
||||
}
|
||||
if (values.GetObject(DEVICE_TYPE_ID, valueObject) && valueObject.GetInt(intValue)) {
|
||||
if (values.GetObject(DEVICE_TYPE_ID, valueObject) && valueObject.GetInt(intValue) == NativeRdb::E_OK) {
|
||||
profile.SetDeviceIdType(intValue);
|
||||
}
|
||||
if (values.GetObject(STATUS, valueObject) && valueObject.GetInt(intValue)) {
|
||||
if (values.GetObject(STATUS, valueObject) && valueObject.GetInt(intValue) == NativeRdb::E_OK) {
|
||||
profile.SetStatus(intValue);
|
||||
}
|
||||
return DP_SUCCESS;
|
||||
@ -382,25 +383,25 @@ int32_t ProfileUtils::EntriesToAccesser(const ValuesBucket& values, Accesser& ac
|
||||
std::string strValue = "";
|
||||
int32_t intValue = 0;
|
||||
int64_t int64Value = 0;
|
||||
if (values.GetObject(ACCESSER_ID, valueObject) && valueObject.GetLong(int64Value)) {
|
||||
if (values.GetObject(ACCESSER_ID, valueObject) && valueObject.GetLong(int64Value) == NativeRdb::E_OK) {
|
||||
accesser.SetAccesserId(int64Value);
|
||||
}
|
||||
if (values.GetObject(ACCESSER_DEVICE_ID, valueObject) && valueObject.GetString(strValue)) {
|
||||
if (values.GetObject(ACCESSER_DEVICE_ID, valueObject) && valueObject.GetString(strValue) == NativeRdb::E_OK) {
|
||||
accesser.SetAccesserDeviceId(strValue);
|
||||
}
|
||||
if (values.GetObject(ACCESSER_USER_ID, valueObject) && valueObject.GetInt(intValue)) {
|
||||
if (values.GetObject(ACCESSER_USER_ID, valueObject) && valueObject.GetInt(intValue) == NativeRdb::E_OK) {
|
||||
accesser.SetAccesserUserId(intValue);
|
||||
}
|
||||
if (values.GetObject(ACCESSER_ACCOUNT_ID, valueObject) && valueObject.GetString(strValue)) {
|
||||
if (values.GetObject(ACCESSER_ACCOUNT_ID, valueObject) && valueObject.GetString(strValue) == NativeRdb::E_OK) {
|
||||
accesser.SetAccesserAccountId(strValue);
|
||||
}
|
||||
if (values.GetObject(ACCESSER_TOKEN_ID, valueObject) && valueObject.GetLong(int64Value)) {
|
||||
if (values.GetObject(ACCESSER_TOKEN_ID, valueObject) && valueObject.GetLong(int64Value) == NativeRdb::E_OK) {
|
||||
accesser.SetAccesserTokenId(int64Value);
|
||||
}
|
||||
if (values.GetObject(ACCESSER_BUNDLE_NAME, valueObject) && valueObject.GetString(strValue)) {
|
||||
if (values.GetObject(ACCESSER_BUNDLE_NAME, valueObject) && valueObject.GetString(strValue) == NativeRdb::E_OK) {
|
||||
accesser.SetAccesserBundleName(strValue);
|
||||
}
|
||||
if (values.GetObject(ACCESSER_BIND_LEVEL, valueObject) && valueObject.GetInt(intValue)) {
|
||||
if (values.GetObject(ACCESSER_BIND_LEVEL, valueObject) && valueObject.GetInt(intValue) == NativeRdb::E_OK) {
|
||||
accesser.SetAccesserBindLevel(intValue);
|
||||
}
|
||||
return DP_SUCCESS;
|
||||
@ -412,25 +413,25 @@ int32_t ProfileUtils::EntriesToAccessee(const ValuesBucket& values, Accessee& ac
|
||||
std::string strValue = "";
|
||||
int32_t intValue = 0;
|
||||
int64_t int64Value = 0;
|
||||
if (values.GetObject(ACCESSEE_ID, valueObject) && valueObject.GetLong(int64Value)) {
|
||||
if (values.GetObject(ACCESSEE_ID, valueObject) && valueObject.GetLong(int64Value) == NativeRdb::E_OK) {
|
||||
accessee.SetAccesseeId(int64Value);
|
||||
}
|
||||
if (values.GetObject(ACCESSER_DEVICE_ID, valueObject) && valueObject.GetString(strValue)) {
|
||||
if (values.GetObject(ACCESSEE_DEVICE_ID, valueObject) && valueObject.GetString(strValue) == NativeRdb::E_OK) {
|
||||
accessee.SetAccesseeDeviceId(strValue);
|
||||
}
|
||||
if (values.GetObject(ACCESSER_USER_ID, valueObject) && valueObject.GetInt(intValue)) {
|
||||
if (values.GetObject(ACCESSEE_USER_ID, valueObject) && valueObject.GetInt(intValue) == NativeRdb::E_OK) {
|
||||
accessee.SetAccesseeUserId(intValue);
|
||||
}
|
||||
if (values.GetObject(ACCESSER_ACCOUNT_ID, valueObject) && valueObject.GetString(strValue)) {
|
||||
if (values.GetObject(ACCESSEE_ACCOUNT_ID, valueObject) && valueObject.GetString(strValue) == NativeRdb::E_OK) {
|
||||
accessee.SetAccesseeAccountId(strValue);
|
||||
}
|
||||
if (values.GetObject(ACCESSER_TOKEN_ID, valueObject) && valueObject.GetLong(int64Value)) {
|
||||
if (values.GetObject(ACCESSEE_TOKEN_ID, valueObject) && valueObject.GetLong(int64Value) == NativeRdb::E_OK) {
|
||||
accessee.SetAccesseeTokenId(int64Value);
|
||||
}
|
||||
if (values.GetObject(ACCESSER_BUNDLE_NAME, valueObject) && valueObject.GetString(strValue)) {
|
||||
if (values.GetObject(ACCESSEE_BUNDLE_NAME, valueObject) && valueObject.GetString(strValue) == NativeRdb::E_OK) {
|
||||
accessee.SetAccesseeBundleName(strValue);
|
||||
}
|
||||
if (values.GetObject(ACCESSER_BIND_LEVEL, valueObject) && valueObject.GetInt(intValue)) {
|
||||
if (values.GetObject(ACCESSEE_BIND_LEVEL, valueObject) && valueObject.GetInt(intValue) == NativeRdb::E_OK) {
|
||||
accessee.SetAccesseeBindLevel(intValue);
|
||||
}
|
||||
return DP_SUCCESS;
|
||||
@ -604,7 +605,7 @@ bool ProfileUtils::IsPropertyValid(const std::map<std::string, std::string>& pro
|
||||
bool ProfileUtils::GetIntValue(const ValuesBucket& values, const std::string& property, int32_t& value)
|
||||
{
|
||||
ValueObject valueObject;
|
||||
if (values.GetObject(property, valueObject) && valueObject.GetInt(value)) {
|
||||
if (values.GetObject(property, valueObject) && valueObject.GetInt(value) == NativeRdb::E_OK) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -613,7 +614,7 @@ bool ProfileUtils::GetIntValue(const ValuesBucket& values, const std::string& pr
|
||||
bool ProfileUtils::GetStringValue(const ValuesBucket& values, const std::string& property, std::string& value)
|
||||
{
|
||||
ValueObject valueObject;
|
||||
if (values.GetObject(property, valueObject) && valueObject.GetString(value)) {
|
||||
if (values.GetObject(property, valueObject) && valueObject.GetString(value) == NativeRdb::E_OK) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -622,7 +623,7 @@ bool ProfileUtils::GetStringValue(const ValuesBucket& values, const std::string&
|
||||
bool ProfileUtils::GetLongValue(const ValuesBucket& values, const std::string& property, int64_t& value)
|
||||
{
|
||||
ValueObject valueObject;
|
||||
if (values.GetObject(property, valueObject) && valueObject.GetLong(value)) {
|
||||
if (values.GetObject(property, valueObject) && valueObject.GetLong(value) == NativeRdb::E_OK) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -208,7 +208,7 @@ bool ProfileCache::IsDeviceProfileExist(const DeviceProfile& deviceProfile)
|
||||
{
|
||||
if (!ProfileUtils::IsKeyValid(deviceProfile.GetDeviceId())) {
|
||||
HILOGE("Params is invalid!");
|
||||
return DP_INVALID_PARAMS;
|
||||
return false;
|
||||
}
|
||||
std::string deviceProfileKey = ProfileUtils::GenerateDeviceProfileKey(deviceProfile.GetDeviceId());
|
||||
{
|
||||
@ -231,7 +231,7 @@ bool ProfileCache::IsServiceProfileExist(const ServiceProfile& serviceProfile)
|
||||
if (!ProfileUtils::IsKeyValid(serviceProfile.GetDeviceId()) ||
|
||||
!ProfileUtils::IsKeyValid(serviceProfile.GetServiceName())) {
|
||||
HILOGE("Params is invalid!");
|
||||
return DP_INVALID_PARAMS;
|
||||
return false;
|
||||
}
|
||||
std::string serviceProfileKey = ProfileUtils::GenerateServiceProfileKey(serviceProfile.GetDeviceId(),
|
||||
serviceProfile.GetServiceName());
|
||||
@ -256,7 +256,7 @@ bool ProfileCache::IsCharProfileExist(const CharacteristicProfile& charProfile)
|
||||
!ProfileUtils::IsKeyValid(charProfile.GetServiceName()) ||
|
||||
!ProfileUtils::IsKeyValid(charProfile.GetCharacteristicKey())) {
|
||||
HILOGE("Params is invalid!");
|
||||
return DP_INVALID_PARAMS;
|
||||
return false;
|
||||
}
|
||||
std::string charProfileKey = ProfileUtils::GenerateCharProfileKey(charProfile.GetDeviceId(),
|
||||
charProfile.GetServiceName(), charProfile.GetCharacteristicKey());
|
||||
|
@ -99,6 +99,66 @@ ohos_unittest("ClientRdbTest") {
|
||||
subsystem_name = "deviceprofile"
|
||||
}
|
||||
|
||||
ohos_unittest("dp_dumper_new_test") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "unittest/dp_dumper_test.cpp" ]
|
||||
configs = device_profile_configs
|
||||
deps = device_profile_deps
|
||||
external_deps = device_profile_external_deps
|
||||
part_name = "device_info_manager"
|
||||
subsystem_name = "deviceprofile"
|
||||
}
|
||||
|
||||
ohos_unittest("profile_cache_new_test") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "unittest/profile_cache_test.cpp" ]
|
||||
configs = device_profile_configs
|
||||
deps = device_profile_deps
|
||||
external_deps = device_profile_external_deps
|
||||
part_name = "device_info_manager"
|
||||
subsystem_name = "deviceprofile"
|
||||
}
|
||||
|
||||
ohos_unittest("profile_utils_new_test") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "unittest/profile_utils_test.cpp" ]
|
||||
configs = device_profile_configs
|
||||
deps = device_profile_deps
|
||||
external_deps = device_profile_external_deps
|
||||
part_name = "device_info_manager"
|
||||
subsystem_name = "deviceprofile"
|
||||
}
|
||||
|
||||
ohos_unittest("kv_adapter_new_test") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "unittest/kv_adapter_test.cpp" ]
|
||||
configs = device_profile_configs
|
||||
deps = device_profile_deps
|
||||
external_deps = device_profile_external_deps
|
||||
part_name = "device_info_manager"
|
||||
subsystem_name = "deviceprofile"
|
||||
}
|
||||
|
||||
ohos_unittest("event_handler_factory_new_test") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "unittest/event_handler_factory_test.cpp" ]
|
||||
configs = device_profile_configs
|
||||
deps = device_profile_deps
|
||||
external_deps = device_profile_external_deps
|
||||
part_name = "device_info_manager"
|
||||
subsystem_name = "deviceprofile"
|
||||
}
|
||||
|
||||
ohos_unittest("sync_options_new_test") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "unittest/sync_options_test.cpp" ]
|
||||
configs = device_profile_configs
|
||||
deps = device_profile_deps
|
||||
external_deps = device_profile_external_deps
|
||||
part_name = "device_info_manager"
|
||||
subsystem_name = "deviceprofile"
|
||||
}
|
||||
|
||||
ohos_unittest("DPSubscribeInfoTest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "unittest/dp_subscribe_info_test.cpp" ]
|
||||
@ -190,10 +250,16 @@ group("unittest") {
|
||||
":content_sensor_manager_test",
|
||||
":device_profile_manager_new_test",
|
||||
":distributed_device_profile_client_kv_new_test",
|
||||
":dp_dumper_new_test",
|
||||
":event_handler_factory_new_test",
|
||||
":kv_adapter_new_test",
|
||||
":kv_data_change_listener_test",
|
||||
":kv_store_death_recipient_test",
|
||||
":kv_sync_completed_listener_test",
|
||||
":profile_cache_new_test",
|
||||
":profile_utils_new_test",
|
||||
":rdb_adapter_new_test",
|
||||
":sync_options_new_test",
|
||||
":sync_subscriber_death_recipient_test",
|
||||
]
|
||||
}
|
||||
|
89
services/core/test/unittest/dp_dumper_test.cpp
Normal file
89
services/core/test/unittest/dp_dumper_test.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 private public
|
||||
#define protected public
|
||||
#include "gtest/gtest.h"
|
||||
#include "device_profile_dumper.h"
|
||||
#undef private
|
||||
#undef protected
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedDeviceProfile {
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
class DpDumperTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void DpDumperTest::SetUpTestCase() {
|
||||
}
|
||||
|
||||
void DpDumperTest::TearDownTestCase() {
|
||||
}
|
||||
|
||||
void DpDumperTest::SetUp() {
|
||||
}
|
||||
|
||||
void DpDumperTest::TearDown() {
|
||||
}
|
||||
|
||||
HWTEST_F(DpDumperTest, Dump_001, TestSize.Level1)
|
||||
{
|
||||
std::vector<std::string> args;
|
||||
std::string result;
|
||||
auto dumper = std::make_shared<DeviceProfileDumper>();
|
||||
bool ret = dumper->Dump(args, result);
|
||||
EXPECT_EQ(false, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DpDumperTest, Dump_002, TestSize.Level1)
|
||||
{
|
||||
setuid(1212);
|
||||
std::string result;
|
||||
std::vector<std::string> args;
|
||||
auto dumper = std::make_shared<DeviceProfileDumper>();
|
||||
bool ret = dumper->Dump(args, result);
|
||||
EXPECT_EQ(true, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DpDumperTest, Dump_003, TestSize.Level1)
|
||||
{
|
||||
setuid(1212);
|
||||
std::string result;
|
||||
std::vector<std::string> args;
|
||||
args.emplace_back("-h");
|
||||
auto dumper = std::make_shared<DeviceProfileDumper>();
|
||||
bool ret = dumper->Dump(args, result);
|
||||
EXPECT_EQ(true, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DpDumperTest, Dump_004, TestSize.Level1)
|
||||
{
|
||||
setuid(1212);
|
||||
std::string result;
|
||||
std::vector<std::string> args;
|
||||
args.emplace_back("-g");
|
||||
auto dumper = std::make_shared<DeviceProfileDumper>();
|
||||
bool ret = dumper->Dump(args, result);
|
||||
EXPECT_EQ(false, ret);
|
||||
}
|
||||
}
|
||||
}
|
57
services/core/test/unittest/event_handler_factory_test.cpp
Normal file
57
services/core/test/unittest/event_handler_factory_test.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "gtest/gtest.h"
|
||||
#include "event_handler_factory.h"
|
||||
#include "distributed_device_profile_constants.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::DistributedDeviceProfile;
|
||||
using namespace std;
|
||||
|
||||
class EventHandlerFactoryTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void EventHandlerFactoryTest::SetUpTestCase(void) {
|
||||
}
|
||||
|
||||
void EventHandlerFactoryTest::TearDownTestCase(void) {
|
||||
}
|
||||
|
||||
void EventHandlerFactoryTest::SetUp() {
|
||||
}
|
||||
|
||||
void EventHandlerFactoryTest::TearDown() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CreateEventHandler001
|
||||
* @tc.desc: CreateEventHandler succeed and failed, handlerName is invalid.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(EventHandlerFactoryTest, CreateEventHandler001, TestSize.Level1)
|
||||
{
|
||||
EventHandlerFactory::GetInstance().CreateEventHandler(UNLOAD_DP_SA_HANDLER);
|
||||
auto eventHandler = EventHandlerFactory::GetInstance().CreateEventHandler("");
|
||||
EXPECT_EQ(nullptr, eventHandler);
|
||||
}
|
330
services/core/test/unittest/kv_adapter_test.cpp
Normal file
330
services/core/test/unittest/kv_adapter_test.cpp
Normal file
@ -0,0 +1,330 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 private public
|
||||
#define protected public
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include "gtest/gtest.h"
|
||||
#include "refbase.h"
|
||||
#include "distributed_device_profile_constants.h"
|
||||
#include "distributed_device_profile_errors.h"
|
||||
#include "distributed_device_profile_enums.h"
|
||||
#include "ikv_adapter.h"
|
||||
#include "kv_adapter.h"
|
||||
#include "kv_data_change_listener.h"
|
||||
#include "kv_sync_completed_listener.h"
|
||||
#include "kv_store_death_recipient.h"
|
||||
#undef private
|
||||
#undef protected
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::DistributedDeviceProfile;
|
||||
using namespace std;
|
||||
|
||||
namespace {
|
||||
const std::string APP_ID = "distributed_device_profile_service";
|
||||
const std::string STORE_ID = "dp_kv_store";
|
||||
shared_ptr<IKVAdapter> kvStore = nullptr;
|
||||
}
|
||||
|
||||
class KVAdapterTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void KVAdapterTest::SetUpTestCase(void)
|
||||
{
|
||||
kvStore = make_shared<KVAdapter>(APP_ID, STORE_ID,
|
||||
make_shared<KvDataChangeListener>(),
|
||||
make_shared<KvSyncCompletedListener>(),
|
||||
make_shared<KvDeathRecipient>());
|
||||
}
|
||||
|
||||
void KVAdapterTest::TearDownTestCase(void) {
|
||||
}
|
||||
|
||||
void KVAdapterTest::SetUp()
|
||||
{
|
||||
kvStore->Init();
|
||||
}
|
||||
|
||||
void KVAdapterTest::TearDown()
|
||||
{
|
||||
kvStore->UnInit();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Init001
|
||||
* @tc.desc: Init succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(KVAdapterTest, Init001, TestSize.Level1)
|
||||
{
|
||||
kvStore->UnInit();
|
||||
EXPECT_EQ(DP_SUCCESS, kvStore->Init());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UnInit001
|
||||
* @tc.desc: UnInit succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(KVAdapterTest, UnInit001, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(DP_SUCCESS, kvStore->UnInit());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Put001
|
||||
* @tc.desc: Put succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(KVAdapterTest, Put001, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(DP_SUCCESS, kvStore->Put("key1", "value1"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Put002
|
||||
* @tc.desc: Put failed, Param is invalid.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(KVAdapterTest, Put002, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, kvStore->Put("", "value1"));
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, kvStore->Put("key1", ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Put003
|
||||
* @tc.desc: Put failed, kvDBPtr is null.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(KVAdapterTest, Put003, TestSize.Level1)
|
||||
{
|
||||
kvStore->UnInit();
|
||||
EXPECT_EQ(DP_KV_DB_PTR_NULL, kvStore->Put("key1", "value1"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PutBatch001
|
||||
* @tc.desc: PutBatch succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(KVAdapterTest, PutBatch001, TestSize.Level1)
|
||||
{
|
||||
map<string, string> values;
|
||||
values.insert(pair<string, string>("key2", "value2"));
|
||||
values.insert(pair<string, string>("key3", "value3"));
|
||||
EXPECT_EQ(DP_SUCCESS, kvStore->PutBatch(values));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PutBatch002
|
||||
* @tc.desc: PutBatch failed, Param is invalid.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(KVAdapterTest, PutBatch002, TestSize.Level1)
|
||||
{
|
||||
map<string, string> values;
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, kvStore->PutBatch(values));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PutBatch003
|
||||
* @tc.desc: PutBatch failed, kvDBPtr is null.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(KVAdapterTest, PutBatch003, TestSize.Level1)
|
||||
{
|
||||
map<string, string> values;
|
||||
values.insert(pair<string, string>("key1", "value1"));
|
||||
values.insert(pair<string, string>("key2", "value2"));
|
||||
kvStore->UnInit();
|
||||
EXPECT_EQ(DP_KV_DB_PTR_NULL, kvStore->PutBatch(values));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Delete001
|
||||
* @tc.desc: Delete succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(KVAdapterTest, Delete001, TestSize.Level1)
|
||||
{
|
||||
kvStore->Put("key4", "value4");
|
||||
EXPECT_EQ(DP_SUCCESS, kvStore->Delete("key4"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Delete002
|
||||
* @tc.desc: Delete failed, kvDBPtr is null.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(KVAdapterTest, Delete002, TestSize.Level1)
|
||||
{
|
||||
kvStore->Put("key5", "value5");
|
||||
kvStore->UnInit();
|
||||
EXPECT_EQ(DP_KV_DB_PTR_NULL, kvStore->Delete("key5"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DeleteByPrefix001
|
||||
* @tc.desc: DeleteByPrefix succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(KVAdapterTest, DeleteByPrefix001, TestSize.Level1)
|
||||
{
|
||||
kvStore->Put("key6", "value6");
|
||||
kvStore->Put("key7", "value7");
|
||||
EXPECT_EQ(DP_SUCCESS, kvStore->DeleteByPrefix("key"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DeleteByPrefix002
|
||||
* @tc.desc: DeleteByPrefix failed, kvDBPtr is null.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(KVAdapterTest, DeleteByPrefix002, TestSize.Level1)
|
||||
{
|
||||
kvStore->Put("key8", "value8");
|
||||
kvStore->Put("key9", "value9");
|
||||
kvStore->UnInit();
|
||||
EXPECT_EQ(DP_KV_DB_PTR_NULL, kvStore->DeleteByPrefix("key"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Get001
|
||||
* @tc.desc: Get succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(KVAdapterTest, Get001, TestSize.Level1)
|
||||
{
|
||||
kvStore->Put("key10", "value10");
|
||||
string value;
|
||||
EXPECT_EQ(DP_SUCCESS, kvStore->Get("key10", value));
|
||||
EXPECT_EQ("value10", value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Get002
|
||||
* @tc.desc: Get failed, kvDBPtr is null.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(KVAdapterTest, Get002, TestSize.Level1)
|
||||
{
|
||||
kvStore->Put("key11", "value11");
|
||||
kvStore->UnInit();
|
||||
string value;
|
||||
EXPECT_EQ(DP_KV_DB_PTR_NULL, kvStore->Get("key11", value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetByPrefix001
|
||||
* @tc.desc: GetByPrefix succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(KVAdapterTest, GetByPrefix001, TestSize.Level1)
|
||||
{
|
||||
kvStore->Put("GetByPrefix001a", "value");
|
||||
kvStore->Put("GetByPrefix001b", "value");
|
||||
map<string, string> values;
|
||||
EXPECT_EQ(DP_SUCCESS, kvStore->GetByPrefix("GetByPrefix001", values));
|
||||
EXPECT_EQ(2, values.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetByPrefix002
|
||||
* @tc.desc: GetByPrefix failed, kvDBPtr is null.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(KVAdapterTest, GetByPrefix002, TestSize.Level1)
|
||||
{
|
||||
kvStore->Put("GetByPrefix002a", "value");
|
||||
kvStore->Put("GetByPrefix002b", "value");
|
||||
kvStore->UnInit();
|
||||
map<string, string> values;
|
||||
EXPECT_EQ(DP_KV_DB_PTR_NULL, kvStore->GetByPrefix("GetByPrefix002", values));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetByPrefix003
|
||||
* @tc.desc: GetByPrefix failed, AllEntries size is invalid.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(KVAdapterTest, GetByPrefix003, TestSize.Level1)
|
||||
{
|
||||
map<string, string> values;
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, kvStore->GetByPrefix("GetByPrefix003", values));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Sync001
|
||||
* @tc.desc: Sync failed, kvStorePtr is nullptr.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(KVAdapterTest, Sync001, TestSize.Level1)
|
||||
{
|
||||
kvStore->UnInit();
|
||||
vector<string> deviceList;
|
||||
EXPECT_EQ(DP_KV_DB_PTR_NULL, kvStore->Sync(deviceList, SyncMode::PUSH));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Sync002
|
||||
* @tc.desc: Sync failed, deviceList is invalid.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(KVAdapterTest, Sync002, TestSize.Level1)
|
||||
{
|
||||
vector<string> deviceList;
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, kvStore->Sync(deviceList, SyncMode::PUSH));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Sync003
|
||||
* @tc.desc: Sync failed, syncMode is invalid.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(KVAdapterTest, Sync003, TestSize.Level1)
|
||||
{
|
||||
vector<string> deviceList;
|
||||
deviceList.push_back("deviceId");
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, kvStore->Sync(deviceList, SyncMode::MIN));
|
||||
}
|
442
services/core/test/unittest/profile_cache_test.cpp
Normal file
442
services/core/test/unittest/profile_cache_test.cpp
Normal file
@ -0,0 +1,442 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 private public
|
||||
#define protected public
|
||||
#include "gtest/gtest.h"
|
||||
#include "profile_cache.h"
|
||||
#include "profile_utils.h"
|
||||
#include "device_profile_manager.h"
|
||||
#undef private
|
||||
#undef protected
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedDeviceProfile {
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
class ProfileCacheTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void ProfileCacheTest::SetUpTestCase() {
|
||||
}
|
||||
|
||||
void ProfileCacheTest::TearDownTestCase() {
|
||||
}
|
||||
|
||||
void ProfileCacheTest::SetUp() {
|
||||
}
|
||||
|
||||
void ProfileCacheTest::TearDown() {
|
||||
}
|
||||
|
||||
HWTEST_F(ProfileCacheTest, AddDeviceProfile_001, TestSize.Level2)
|
||||
{
|
||||
DeviceProfile deviceProfile;
|
||||
int32_t ret = ProfileCache::GetInstance().AddDeviceProfile(deviceProfile);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
std::string devId = "dp_devId";
|
||||
deviceProfile.SetDeviceId(devId);
|
||||
ret = ProfileCache::GetInstance().AddDeviceProfile(deviceProfile);
|
||||
EXPECT_EQ(DP_SUCCESS, ret);
|
||||
|
||||
for (int i = 1; i < MAX_DEVICE_SIZE + 1; ++i) {
|
||||
ProfileCache::GetInstance().deviceProfileMap_[std::to_string(i)] = deviceProfile;
|
||||
}
|
||||
ret = ProfileCache::GetInstance().AddDeviceProfile(deviceProfile);
|
||||
EXPECT_EQ(DP_EXCEED_MAX_SIZE_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ProfileCacheTest, AddServiceProfile_001, TestSize.Level2)
|
||||
{
|
||||
ServiceProfile serviceProfile;
|
||||
int32_t ret = ProfileCache::GetInstance().AddServiceProfile(serviceProfile);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
std::string devId = "dp_devId";
|
||||
serviceProfile.SetDeviceId(devId);
|
||||
ret = ProfileCache::GetInstance().AddServiceProfile(serviceProfile);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
std::string serName = "dp_serName";
|
||||
serviceProfile.SetServiceName(serName);
|
||||
ret = ProfileCache::GetInstance().AddServiceProfile(serviceProfile);
|
||||
EXPECT_EQ(DP_SUCCESS, ret);
|
||||
|
||||
devId = "";
|
||||
serviceProfile.SetDeviceId(devId);
|
||||
ret = ProfileCache::GetInstance().AddServiceProfile(serviceProfile);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
devId = "dp_devId";
|
||||
serviceProfile.SetDeviceId(devId);
|
||||
for (int i = 1; i < MAX_DEVICE_SIZE + 1; ++i) {
|
||||
ProfileCache::GetInstance().serviceProfileMap_[std::to_string(i)] = serviceProfile;
|
||||
}
|
||||
ret = ProfileCache::GetInstance().AddServiceProfile(serviceProfile);
|
||||
EXPECT_EQ(DP_EXCEED_MAX_SIZE_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ProfileCacheTest, AddCharProfile_001, TestSize.Level2)
|
||||
{
|
||||
CharacteristicProfile charProfile;
|
||||
int32_t ret = ProfileCache::GetInstance().AddCharProfile(charProfile);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
std::string devId = "dp_devId";
|
||||
charProfile.SetDeviceId(devId);
|
||||
ret = ProfileCache::GetInstance().AddCharProfile(charProfile);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
std::string serName = "dp_serName";
|
||||
charProfile.SetServiceName(serName);
|
||||
ret = ProfileCache::GetInstance().AddCharProfile(charProfile);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
std::string charKey = "dp_charKey";
|
||||
charProfile.SetCharacteristicKey(charKey);
|
||||
ret = ProfileCache::GetInstance().AddCharProfile(charProfile);
|
||||
EXPECT_EQ(DP_SUCCESS, ret);
|
||||
|
||||
devId = "";
|
||||
charProfile.SetDeviceId(devId);
|
||||
ret = ProfileCache::GetInstance().AddCharProfile(charProfile);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
serName = "";
|
||||
charProfile.SetServiceName(serName);
|
||||
ret = ProfileCache::GetInstance().AddCharProfile(charProfile);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
devId = "dp_devId";
|
||||
charProfile.SetDeviceId(devId);
|
||||
ret = ProfileCache::GetInstance().AddCharProfile(charProfile);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
serName = "dp_serName";
|
||||
charProfile.SetServiceName(serName);
|
||||
charKey = "dp_charKey";
|
||||
charProfile.SetCharacteristicKey(charKey);
|
||||
for (int i = 1; i < MAX_DEVICE_SIZE + 1; ++i) {
|
||||
ProfileCache::GetInstance().charProfileMap_[std::to_string(i)] = charProfile;
|
||||
}
|
||||
ret = ProfileCache::GetInstance().AddCharProfile(charProfile);
|
||||
EXPECT_EQ(DP_EXCEED_MAX_SIZE_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ProfileCacheTest, GetDeviceProfile_001, TestSize.Level2)
|
||||
{
|
||||
std::string devId = "";
|
||||
DeviceProfile deviceProfile;
|
||||
int32_t ret = ProfileCache::GetInstance().GetDeviceProfile(devId, deviceProfile);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
devId = "dp_devId";
|
||||
ret = ProfileCache::GetInstance().GetDeviceProfile(devId, deviceProfile);
|
||||
EXPECT_EQ(DP_SUCCESS, ret);
|
||||
|
||||
ProfileCache::GetInstance().deviceProfileMap_.clear();
|
||||
ret = ProfileCache::GetInstance().GetDeviceProfile(devId, deviceProfile);
|
||||
EXPECT_EQ(DP_NOT_FOUND_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ProfileCacheTest, GetServiceProfile_001, TestSize.Level2)
|
||||
{
|
||||
std::string devId = "";
|
||||
std::string serName = "";
|
||||
ServiceProfile serviceProfile;
|
||||
int32_t ret = ProfileCache::GetInstance().GetServiceProfile(devId, serName, serviceProfile);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
devId = "dp_devId";
|
||||
ret = ProfileCache::GetInstance().GetServiceProfile(devId, serName, serviceProfile);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
serName = "dp_serName";
|
||||
ret = ProfileCache::GetInstance().GetServiceProfile(devId, serName, serviceProfile);
|
||||
EXPECT_EQ(DP_SUCCESS, ret);
|
||||
|
||||
devId = "";
|
||||
ret = ProfileCache::GetInstance().GetServiceProfile(devId, serName, serviceProfile);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
devId = "dp_devId";
|
||||
ProfileCache::GetInstance().serviceProfileMap_.clear();
|
||||
ret = ProfileCache::GetInstance().GetServiceProfile(devId, serName, serviceProfile);
|
||||
EXPECT_EQ(DP_NOT_FOUND_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ProfileCacheTest, GetCharacteristicProfile_001, TestSize.Level2)
|
||||
{
|
||||
std::string devId = "";
|
||||
std::string serName = "";
|
||||
std::string charKey = "";
|
||||
CharacteristicProfile charProfile;
|
||||
int32_t ret = ProfileCache::GetInstance().GetCharacteristicProfile(devId, serName, charKey, charProfile);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
devId = "dp_devId";
|
||||
ret = ProfileCache::GetInstance().GetCharacteristicProfile(devId, serName, charKey, charProfile);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
serName = "dp_serName";
|
||||
ret = ProfileCache::GetInstance().GetCharacteristicProfile(devId, serName, charKey, charProfile);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
charKey = "dp_charKey";
|
||||
ret = ProfileCache::GetInstance().GetCharacteristicProfile(devId, serName, charKey, charProfile);
|
||||
EXPECT_EQ(DP_SUCCESS, ret);
|
||||
|
||||
devId = "";
|
||||
ret = ProfileCache::GetInstance().GetCharacteristicProfile(devId, serName, charKey, charProfile);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
serName = "";
|
||||
ret = ProfileCache::GetInstance().GetCharacteristicProfile(devId, serName, charKey, charProfile);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
devId = "dp_devId";
|
||||
ret = ProfileCache::GetInstance().GetCharacteristicProfile(devId, serName, charKey, charProfile);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
serName = "dp_serName";
|
||||
ProfileCache::GetInstance().charProfileMap_.clear();
|
||||
ret = ProfileCache::GetInstance().GetCharacteristicProfile(devId, serName, charKey, charProfile);
|
||||
EXPECT_EQ(DP_NOT_FOUND_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ProfileCacheTest, DeleteDeviceProfile_001, TestSize.Level2)
|
||||
{
|
||||
std::string devId = "";
|
||||
int32_t ret = ProfileCache::GetInstance().DeleteDeviceProfile(devId);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
devId = "dp_devId";
|
||||
ret = ProfileCache::GetInstance().DeleteDeviceProfile(devId);
|
||||
EXPECT_EQ(DP_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ProfileCacheTest, DeleteServiceProfile_001, TestSize.Level2)
|
||||
{
|
||||
std::string devId = "";
|
||||
std::string serName = "";
|
||||
int32_t ret = ProfileCache::GetInstance().DeleteServiceProfile(devId, serName);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
devId = "dp_devId";
|
||||
ret = ProfileCache::GetInstance().DeleteServiceProfile(devId, serName);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
serName = "dp_serName";
|
||||
ret = ProfileCache::GetInstance().DeleteServiceProfile(devId, serName);
|
||||
EXPECT_EQ(DP_SUCCESS, ret);
|
||||
|
||||
devId = "";
|
||||
ret = ProfileCache::GetInstance().DeleteServiceProfile(devId, serName);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ProfileCacheTest, DeleteCharProfile_001, TestSize.Level2)
|
||||
{
|
||||
std::string devId = "";
|
||||
std::string serName = "";
|
||||
std::string charKey = "";
|
||||
int32_t ret = ProfileCache::GetInstance().DeleteCharProfile(devId, serName, charKey);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
devId = "dp_devId";
|
||||
ret = ProfileCache::GetInstance().DeleteCharProfile(devId, serName, charKey);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
serName = "dp_serName";
|
||||
ret = ProfileCache::GetInstance().DeleteCharProfile(devId, serName, charKey);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
charKey = "dp_charKey";
|
||||
ret = ProfileCache::GetInstance().DeleteCharProfile(devId, serName, charKey);
|
||||
EXPECT_EQ(DP_SUCCESS, ret);
|
||||
|
||||
devId = "";
|
||||
ret = ProfileCache::GetInstance().DeleteCharProfile(devId, serName, charKey);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
serName = "";
|
||||
ret = ProfileCache::GetInstance().DeleteCharProfile(devId, serName, charKey);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
devId = "dp_devId";
|
||||
ret = ProfileCache::GetInstance().DeleteCharProfile(devId, serName, charKey);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ProfileCacheTest, IsDeviceProfileExist_001, TestSize.Level2)
|
||||
{
|
||||
DeviceProfile deviceProfile;
|
||||
bool ret = ProfileCache::GetInstance().IsDeviceProfileExist(deviceProfile);
|
||||
EXPECT_EQ(false, ret);
|
||||
|
||||
std::string devId = "dp_devId";
|
||||
deviceProfile.SetDeviceId(devId);
|
||||
ret = ProfileCache::GetInstance().IsDeviceProfileExist(deviceProfile);
|
||||
EXPECT_EQ(false, ret);
|
||||
|
||||
DeviceProfile deviceProfile1;
|
||||
deviceProfile1.SetDeviceId("anything1");
|
||||
deviceProfile1.SetDeviceTypeName("anything");
|
||||
deviceProfile1.SetDeviceTypeId(0);
|
||||
deviceProfile1.SetDeviceName("anything");
|
||||
deviceProfile1.SetManufactureName("anything");
|
||||
deviceProfile1.SetDeviceModel("anything");
|
||||
deviceProfile1.SetSerialNumberId("anything");
|
||||
deviceProfile1.SetStorageCapability(1);
|
||||
deviceProfile1.SetOsSysCap("anything");
|
||||
deviceProfile1.SetOsApiLevel(1);
|
||||
deviceProfile1.SetOsVersion("anything");
|
||||
deviceProfile1.SetOsType(1);
|
||||
ProfileCache::GetInstance().AddDeviceProfile(deviceProfile1);
|
||||
ret = ProfileCache::GetInstance().IsDeviceProfileExist(deviceProfile1);
|
||||
EXPECT_EQ(true, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ProfileCacheTest, IsServiceProfileExist_001, TestSize.Level2)
|
||||
{
|
||||
ServiceProfile serviceProfile;
|
||||
bool ret = ProfileCache::GetInstance().IsServiceProfileExist(serviceProfile);
|
||||
EXPECT_EQ(false, ret);
|
||||
|
||||
std::string devId = "dp_devId";
|
||||
serviceProfile.SetDeviceId(devId);
|
||||
ret = ProfileCache::GetInstance().IsServiceProfileExist(serviceProfile);
|
||||
EXPECT_EQ(false, ret);
|
||||
|
||||
devId = "";
|
||||
std::string serName = "dp_serName";
|
||||
serviceProfile.SetDeviceId(devId);
|
||||
serviceProfile.SetServiceName(serName);
|
||||
ret = ProfileCache::GetInstance().IsServiceProfileExist(serviceProfile);
|
||||
EXPECT_EQ(false, ret);
|
||||
|
||||
devId = "dp_devId";
|
||||
serviceProfile.SetDeviceId(devId);
|
||||
ret = ProfileCache::GetInstance().IsServiceProfileExist(serviceProfile);
|
||||
EXPECT_EQ(false, ret);
|
||||
|
||||
ServiceProfile serviceProfile1;
|
||||
serviceProfile1.SetDeviceId("deviceId1");
|
||||
serviceProfile1.SetServiceName("serviceName1");
|
||||
serviceProfile1.SetServiceType("serviceType1");
|
||||
ProfileCache::GetInstance().AddServiceProfile(serviceProfile1);
|
||||
ret = ProfileCache::GetInstance().IsServiceProfileExist(serviceProfile1);
|
||||
EXPECT_EQ(true, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ProfileCacheTest, IsCharProfileExist_001, TestSize.Level2)
|
||||
{
|
||||
CharacteristicProfile charProfile;
|
||||
bool ret = ProfileCache::GetInstance().IsCharProfileExist(charProfile);
|
||||
EXPECT_EQ(false, ret);
|
||||
|
||||
std::string devId = "dp_devId";
|
||||
charProfile.SetDeviceId(devId);
|
||||
ret = ProfileCache::GetInstance().IsCharProfileExist(charProfile);
|
||||
EXPECT_EQ(false, ret);
|
||||
|
||||
std::string serName = "dp_serName";
|
||||
charProfile.SetServiceName(serName);
|
||||
ret = ProfileCache::GetInstance().IsCharProfileExist(charProfile);
|
||||
EXPECT_EQ(false, ret);
|
||||
|
||||
devId = "";
|
||||
charProfile.SetDeviceId(devId);
|
||||
std::string charKey = "dp_charKey";
|
||||
charProfile.SetCharacteristicKey(charKey);
|
||||
ret = ProfileCache::GetInstance().IsCharProfileExist(charProfile);
|
||||
EXPECT_EQ(false, ret);
|
||||
|
||||
serName = "";
|
||||
charProfile.SetServiceName(serName);
|
||||
ret = ProfileCache::GetInstance().IsCharProfileExist(charProfile);
|
||||
EXPECT_EQ(false, ret);
|
||||
|
||||
devId = "dp_devId";
|
||||
charProfile.SetDeviceId(devId);
|
||||
ret = ProfileCache::GetInstance().IsCharProfileExist(charProfile);
|
||||
EXPECT_EQ(false, ret);
|
||||
|
||||
CharacteristicProfile charProfile1;
|
||||
charProfile1.SetDeviceId("deviceId1");
|
||||
charProfile1.SetServiceName("serviceName1");
|
||||
charProfile1.SetCharacteristicKey("characteristicKey1");
|
||||
charProfile1.SetCharacteristicValue("characteristicValue1");
|
||||
ProfileCache::GetInstance().AddCharProfile(charProfile1);
|
||||
ret = ProfileCache::GetInstance().IsCharProfileExist(charProfile1);
|
||||
EXPECT_EQ(true, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ProfileCacheTest, RefreshDeviceProfileCache_001, TestSize.Level2)
|
||||
{
|
||||
std::vector<DeviceProfile> deviceProfiles;
|
||||
int32_t ret = ProfileCache::GetInstance().RefreshDeviceProfileCache(deviceProfiles);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
DeviceProfile deviceProfile;
|
||||
std::string devId = "dp_devId";
|
||||
deviceProfile.SetDeviceId(devId);
|
||||
deviceProfiles.push_back(deviceProfile);
|
||||
ret = ProfileCache::GetInstance().RefreshDeviceProfileCache(deviceProfiles);
|
||||
EXPECT_EQ(DP_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ProfileCacheTest, RefreshServiceProfileCache_001, TestSize.Level2)
|
||||
{
|
||||
std::vector<ServiceProfile> serviceProfiles;
|
||||
int32_t ret = ProfileCache::GetInstance().RefreshServiceProfileCache(serviceProfiles);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
ServiceProfile serviceProfile;
|
||||
std::string devId = "dp_devId";
|
||||
std::string serName = "dp_serName";
|
||||
serviceProfile.SetDeviceId(devId);
|
||||
serviceProfile.SetServiceName(serName);
|
||||
serviceProfiles.push_back(serviceProfile);
|
||||
ret = ProfileCache::GetInstance().RefreshServiceProfileCache(serviceProfiles);
|
||||
EXPECT_EQ(DP_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ProfileCacheTest, RefreshCharProfileCache_001, TestSize.Level2)
|
||||
{
|
||||
std::vector<CharacteristicProfile> characteristicProfiles;
|
||||
int32_t ret = ProfileCache::GetInstance().RefreshCharProfileCache(characteristicProfiles);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
|
||||
CharacteristicProfile characteristicProfile;
|
||||
std::string devId = "dp_devId";
|
||||
std::string serName = "dp_serName";
|
||||
std::string charKey = "dp_charKey";
|
||||
characteristicProfile.SetDeviceId(devId);
|
||||
characteristicProfile.SetServiceName(serName);
|
||||
characteristicProfile.SetCharacteristicKey(charKey);
|
||||
characteristicProfiles.push_back(characteristicProfile);
|
||||
ret = ProfileCache::GetInstance().RefreshCharProfileCache(characteristicProfiles);
|
||||
EXPECT_EQ(DP_SUCCESS, ret);
|
||||
}
|
||||
}
|
||||
}
|
827
services/core/test/unittest/profile_utils_test.cpp
Normal file
827
services/core/test/unittest/profile_utils_test.cpp
Normal file
@ -0,0 +1,827 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 private public
|
||||
#define protected public
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "gtest/gtest.h"
|
||||
#include "refbase.h"
|
||||
#include "profile_utils.h"
|
||||
#include "distributed_device_profile_constants.h"
|
||||
#include "distributed_device_profile_errors.h"
|
||||
#include "distributed_device_profile_enums.h"
|
||||
#undef private
|
||||
#undef protected
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::DistributedDeviceProfile;
|
||||
using namespace std;
|
||||
|
||||
class ProfileUtilsTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void ProfileUtilsTest::SetUpTestCase(void) {
|
||||
}
|
||||
|
||||
void ProfileUtilsTest::TearDownTestCase(void) {
|
||||
}
|
||||
|
||||
void ProfileUtilsTest::SetUp() {
|
||||
}
|
||||
|
||||
void ProfileUtilsTest::TearDown() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAnonyString001
|
||||
* @tc.desc: GetAnonyString failed, length < 3.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GetAnonyString001, TestSize.Level1)
|
||||
{
|
||||
string len2 = "ab";
|
||||
string res = ProfileUtils::GetAnonyString(len2);
|
||||
EXPECT_EQ("******", res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAnonyString002
|
||||
* @tc.desc: GetAnonyString succeed, 3 <= length <= 20.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GetAnonyString002, TestSize.Level1)
|
||||
{
|
||||
string len5 = "abcde";
|
||||
string res = ProfileUtils::GetAnonyString(len5);
|
||||
EXPECT_EQ("a******e", res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAnonyString003
|
||||
* @tc.desc: GetAnonyString succeed, length > 20.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GetAnonyString003, TestSize.Level1)
|
||||
{
|
||||
string len_22 = "abcdefghijklmnopqrstuv";
|
||||
string res = ProfileUtils::GetAnonyString(len_22);
|
||||
EXPECT_EQ("abcd******stuv", res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetOnlineDevices001
|
||||
* @tc.desc: GetOnlineDevices succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GetOnlineDevices001, TestSize.Level1)
|
||||
{
|
||||
vector<string> res = ProfileUtils::GetOnlineDevices();
|
||||
EXPECT_EQ(0, res.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: FilterOnlineDevices001
|
||||
* @tc.desc: FilterOnlineDevices failed, deviceList.size() == 0.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, FilterOnlineDevices001, TestSize.Level1)
|
||||
{
|
||||
vector<string> deviceList;
|
||||
vector<string> res = ProfileUtils::FilterOnlineDevices(deviceList);
|
||||
EXPECT_EQ(0, res.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetProfileType001
|
||||
* @tc.desc: GetProfileType succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GetProfileType001, TestSize.Level1)
|
||||
{
|
||||
string minkey = "";
|
||||
ProfileType res = ProfileUtils::GetProfileType(minkey);
|
||||
EXPECT_EQ(ProfileType::PROFILE_TYPE_MIN, res);
|
||||
|
||||
string devKey = "dev111";
|
||||
res = ProfileUtils::GetProfileType(devKey);
|
||||
EXPECT_EQ(ProfileType::DEVICE_PROFILE, res);
|
||||
|
||||
string serKet = "svr111";
|
||||
res = ProfileUtils::GetProfileType(serKet);
|
||||
EXPECT_EQ(ProfileType::SERVICE_PROFILE, res);
|
||||
|
||||
string charKey = "char111";
|
||||
res = ProfileUtils::GetProfileType(charKey);
|
||||
EXPECT_EQ(ProfileType::CHAR_PROFILE, res);
|
||||
|
||||
string lastKey = "other";
|
||||
res = ProfileUtils::GetProfileType(lastKey);
|
||||
EXPECT_EQ(ProfileType::PROFILE_TYPE_MIN, res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StartsWith001
|
||||
* @tc.desc: StartsWith succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, StartsWith001, TestSize.Level1)
|
||||
{
|
||||
string str = "abcdefg";
|
||||
string prefix = "abc";
|
||||
bool res = ProfileUtils::StartsWith(str, prefix);
|
||||
EXPECT_EQ(true, res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IsKeyValid001
|
||||
* @tc.desc: IsKeyValid.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, IsKeyValid001, TestSize.Level1)
|
||||
{
|
||||
string key = "abc";
|
||||
bool res = ProfileUtils::IsKeyValid(key);
|
||||
EXPECT_EQ(true, res);
|
||||
|
||||
key = "";
|
||||
res = ProfileUtils::IsKeyValid(key);
|
||||
EXPECT_EQ(false, res);
|
||||
|
||||
key = "abc#";
|
||||
res = ProfileUtils::IsKeyValid(key);
|
||||
EXPECT_EQ(false, res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GenerateDeviceProfileKey001
|
||||
* @tc.desc: GenerateDeviceProfileKey.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GenerateDeviceProfileKey001, TestSize.Level1)
|
||||
{
|
||||
string deviceId = "111";
|
||||
string res = ProfileUtils::GenerateDeviceProfileKey(deviceId);
|
||||
EXPECT_EQ("dev#111", res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GenerateServiceProfileKey001
|
||||
* @tc.desc: GenerateServiceProfileKey.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GenerateServiceProfileKey001, TestSize.Level1)
|
||||
{
|
||||
string deviceId = "111";
|
||||
string serviceName = "222";
|
||||
string res = ProfileUtils::GenerateServiceProfileKey(deviceId, serviceName);
|
||||
EXPECT_EQ("svr#111#222", res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GenerateCharProfileKey001
|
||||
* @tc.desc: GenerateCharProfileKey.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GenerateCharProfileKey001, TestSize.Level1)
|
||||
{
|
||||
string deviceId = "111";
|
||||
string serviceName = "222";
|
||||
string charKey = "333";
|
||||
string res = ProfileUtils::GenerateCharProfileKey(deviceId, serviceName, charKey);
|
||||
EXPECT_EQ("char#111#222#333", res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TrustDeviceProfileTranslateEntries001
|
||||
* @tc.desc: TrustDeviceProfileToEntries and EntriesToTrustDeviceProfile.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, TrustDeviceProfileTranslateEntries001, TestSize.Level1)
|
||||
{
|
||||
TrustDeviceProfile profile;
|
||||
profile.SetDeviceId("deviceId");
|
||||
profile.SetDeviceIdHash("deviceIdHash");
|
||||
profile.SetDeviceIdType(1);
|
||||
profile.SetStatus(1);
|
||||
|
||||
ValuesBucket values;
|
||||
ValueObject valueObject;
|
||||
string strValue = "";
|
||||
int32_t res1 = ProfileUtils::TrustDeviceProfileToEntries(profile, values);
|
||||
EXPECT_EQ(DP_SUCCESS, res1);
|
||||
values.GetObject(DEVICE_ID, valueObject);
|
||||
valueObject.GetString(strValue);
|
||||
EXPECT_EQ("deviceId", strValue);
|
||||
|
||||
TrustDeviceProfile outProfile;
|
||||
int32_t res2 = res2 = ProfileUtils::EntriesToTrustDeviceProfile(values, outProfile);
|
||||
EXPECT_EQ(DP_SUCCESS, res2);
|
||||
EXPECT_EQ("deviceId", outProfile.GetDeviceId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccessControlProfileTranslateEntries001
|
||||
* @tc.desc: AccessControlProfileToEntries and EntriesToAccessControlProfile.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, AccessControlProfileTranslateEntries001, TestSize.Level1)
|
||||
{
|
||||
Accesser accesser;
|
||||
accesser.SetAccesserDeviceId("acer1");
|
||||
accesser.SetAccesserUserId(11);
|
||||
accesser.SetAccesserAccountId("a1");
|
||||
accesser.SetAccesserTokenId(111);
|
||||
accesser.SetAccesserBundleName("b1");
|
||||
accesser.SetAccesserHapSignature("h1");
|
||||
accesser.SetAccesserBindLevel(1);
|
||||
|
||||
Accessee accessee;
|
||||
accessee.SetAccesseeDeviceId("acee1");
|
||||
accessee.SetAccesseeUserId(22);
|
||||
accessee.SetAccesseeAccountId("a1");
|
||||
accessee.SetAccesseeTokenId(222);
|
||||
accessee.SetAccesseeBundleName("bb1");
|
||||
accessee.SetAccesseeHapSignature("h1");
|
||||
accessee.SetAccesseeBindLevel(1);
|
||||
|
||||
AccessControlProfile profile;
|
||||
profile.SetTrustDeviceId("123456");
|
||||
profile.SetSessionKey("key1");
|
||||
profile.SetBindType(1);
|
||||
profile.SetAuthenticationType(1);
|
||||
profile.SetDeviceIdType(1);
|
||||
profile.SetDeviceIdHash("abcd");
|
||||
profile.SetStatus(0);
|
||||
profile.SetValidPeriod(1);
|
||||
profile.SetLastAuthTime(5);
|
||||
profile.SetBindLevel(0);
|
||||
|
||||
profile.SetAccesser(accesser);
|
||||
profile.SetAccessee(accessee);
|
||||
|
||||
ValuesBucket values;
|
||||
ValueObject valueObject;
|
||||
string strValue = "";
|
||||
int32_t res1 = ProfileUtils::AccessControlProfileToEntries(profile, values);
|
||||
EXPECT_EQ(DP_SUCCESS, res1);
|
||||
values.GetObject(TRUST_DEVICE_ID, valueObject);
|
||||
valueObject.GetString(strValue);
|
||||
EXPECT_EQ("123456", strValue);
|
||||
|
||||
AccessControlProfile outProfile;
|
||||
int32_t res2 = ProfileUtils::EntriesToAccessControlProfile(values, outProfile);
|
||||
EXPECT_EQ(DP_SUCCESS, res2);
|
||||
EXPECT_EQ("123456", outProfile.GetTrustDeviceId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccesserTranslateEntries001
|
||||
* @tc.desc: AccesserToEntries and EntriesToAccesser.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, AccesserTranslateEntries001, TestSize.Level1)
|
||||
{
|
||||
Accesser accesser;
|
||||
accesser.SetAccesserDeviceId("acer1");
|
||||
accesser.SetAccesserUserId(11);
|
||||
accesser.SetAccesserAccountId("a1");
|
||||
accesser.SetAccesserTokenId(111);
|
||||
accesser.SetAccesserBundleName("b1");
|
||||
accesser.SetAccesserHapSignature("h1");
|
||||
accesser.SetAccesserBindLevel(1);
|
||||
|
||||
Accessee accessee;
|
||||
accessee.SetAccesseeDeviceId("acee1");
|
||||
accessee.SetAccesseeUserId(22);
|
||||
accessee.SetAccesseeAccountId("a1");
|
||||
accessee.SetAccesseeTokenId(222);
|
||||
accessee.SetAccesseeBundleName("bb1");
|
||||
accessee.SetAccesseeHapSignature("h1");
|
||||
accessee.SetAccesseeBindLevel(1);
|
||||
|
||||
AccessControlProfile profile;
|
||||
profile.SetTrustDeviceId("123456");
|
||||
profile.SetSessionKey("key1");
|
||||
profile.SetBindType(1);
|
||||
profile.SetAuthenticationType(1);
|
||||
profile.SetDeviceIdType(1);
|
||||
profile.SetDeviceIdHash("abcd");
|
||||
profile.SetStatus(0);
|
||||
profile.SetValidPeriod(1);
|
||||
profile.SetLastAuthTime(5);
|
||||
profile.SetBindLevel(0);
|
||||
|
||||
profile.SetAccesser(accesser);
|
||||
profile.SetAccessee(accessee);
|
||||
|
||||
ValuesBucket values;
|
||||
ValueObject valueObject;
|
||||
string strValue = "";
|
||||
int32_t res1 = ProfileUtils::AccesserToEntries(profile, values);
|
||||
EXPECT_EQ(DP_SUCCESS, res1);
|
||||
values.GetObject(ACCESSER_DEVICE_ID, valueObject);
|
||||
valueObject.GetString(strValue);
|
||||
EXPECT_EQ("acer1", strValue);
|
||||
|
||||
Accesser outAccesser;
|
||||
int32_t res2 = ProfileUtils::EntriesToAccesser(values, outAccesser);
|
||||
EXPECT_EQ(DP_SUCCESS, res2);
|
||||
EXPECT_EQ("acer1", outAccesser.GetAccesserDeviceId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccesseeTranslateEntries001
|
||||
* @tc.desc: AccesseeToEntries and EntriesToAccessee.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, AccesseeTranslateEntries001, TestSize.Level1)
|
||||
{
|
||||
Accesser accesser;
|
||||
accesser.SetAccesserDeviceId("acer1");
|
||||
accesser.SetAccesserUserId(11);
|
||||
accesser.SetAccesserAccountId("a1");
|
||||
accesser.SetAccesserTokenId(111);
|
||||
accesser.SetAccesserBundleName("b1");
|
||||
accesser.SetAccesserHapSignature("h1");
|
||||
accesser.SetAccesserBindLevel(1);
|
||||
|
||||
Accessee accessee;
|
||||
accessee.SetAccesseeDeviceId("acee1");
|
||||
accessee.SetAccesseeUserId(22);
|
||||
accessee.SetAccesseeAccountId("a1");
|
||||
accessee.SetAccesseeTokenId(222);
|
||||
accessee.SetAccesseeBundleName("bb1");
|
||||
accessee.SetAccesseeHapSignature("h1");
|
||||
accessee.SetAccesseeBindLevel(1);
|
||||
|
||||
AccessControlProfile profile;
|
||||
profile.SetTrustDeviceId("123456");
|
||||
profile.SetSessionKey("key1");
|
||||
profile.SetBindType(1);
|
||||
profile.SetAuthenticationType(1);
|
||||
profile.SetDeviceIdType(1);
|
||||
profile.SetDeviceIdHash("abcd");
|
||||
profile.SetStatus(0);
|
||||
profile.SetValidPeriod(1);
|
||||
profile.SetLastAuthTime(5);
|
||||
profile.SetBindLevel(0);
|
||||
|
||||
profile.SetAccesser(accesser);
|
||||
profile.SetAccessee(accessee);
|
||||
|
||||
ValuesBucket values;
|
||||
ValueObject valueObject;
|
||||
string strValue = "";
|
||||
int32_t res1 = ProfileUtils::AccesseeToEntries(profile, values);
|
||||
EXPECT_EQ(DP_SUCCESS, res1);
|
||||
values.GetObject(ACCESSEE_DEVICE_ID, valueObject);
|
||||
valueObject.GetString(strValue);
|
||||
EXPECT_EQ("acee1", strValue);
|
||||
|
||||
Accessee outAccessee;
|
||||
int32_t res2 = ProfileUtils::EntriesToAccessee(values, outAccessee);
|
||||
EXPECT_EQ(DP_SUCCESS, res2);
|
||||
EXPECT_EQ("acee1", outAccessee.GetAccesseeDeviceId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DeviceProfileTranslateEntries001
|
||||
* @tc.desc: DeviceProfileToEntries and EntriesToDeviceProfile.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, DeviceProfileTranslateEntries001, TestSize.Level1)
|
||||
{
|
||||
DeviceProfile deviceProfile;
|
||||
deviceProfile.SetDeviceId("anything");
|
||||
deviceProfile.SetDeviceTypeName("anything");
|
||||
deviceProfile.SetDeviceTypeId(0);
|
||||
deviceProfile.SetDeviceName("anything");
|
||||
deviceProfile.SetManufactureName("anything");
|
||||
deviceProfile.SetDeviceModel("anything");
|
||||
deviceProfile.SetSerialNumberId("anything");
|
||||
deviceProfile.SetStorageCapability(1);
|
||||
deviceProfile.SetOsSysCap("anything");
|
||||
deviceProfile.SetOsApiLevel(1);
|
||||
deviceProfile.SetOsVersion("anything");
|
||||
deviceProfile.SetOsType(1);
|
||||
|
||||
map<string, string> entries;
|
||||
int32_t res1 = ProfileUtils::DeviceProfileToEntries(deviceProfile, entries);
|
||||
EXPECT_EQ(DP_SUCCESS, res1);
|
||||
|
||||
DeviceProfile outDeviceProfile;
|
||||
int32_t res2 = ProfileUtils::EntriesToDeviceProfile(entries, outDeviceProfile);
|
||||
EXPECT_EQ(DP_SUCCESS, res2);
|
||||
EXPECT_EQ("anything", outDeviceProfile.GetDeviceId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ServiceProfileTranslateEntries001
|
||||
* @tc.desc: ServiceProfileToEntries and EntriesToServiceProfile.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, ServiceProfileTranslateEntries001, TestSize.Level1)
|
||||
{
|
||||
ServiceProfile serviceProfile;
|
||||
serviceProfile.SetDeviceId("deviceId");
|
||||
serviceProfile.SetServiceName("serviceName");
|
||||
serviceProfile.SetServiceType("serviceType");
|
||||
|
||||
map<string, string> entries;
|
||||
int32_t res1 = ProfileUtils::ServiceProfileToEntries(serviceProfile, entries);
|
||||
EXPECT_EQ(DP_SUCCESS, res1);
|
||||
|
||||
ServiceProfile outServiceProfile;
|
||||
int32_t res2 = ProfileUtils::EntriesToServiceProfile(entries, outServiceProfile);
|
||||
EXPECT_EQ(DP_SUCCESS, res2);
|
||||
EXPECT_EQ("deviceId", outServiceProfile.GetDeviceId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CharacteristicProfileTranslateEntries001
|
||||
* @tc.desc: CharacteristicProfileToEntries and EntriesToCharProfile.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, CharacteristicProfileTranslateEntries001, TestSize.Level1)
|
||||
{
|
||||
CharacteristicProfile charProfile;
|
||||
charProfile.SetDeviceId("deviceId");
|
||||
charProfile.SetServiceName("serviceName");
|
||||
charProfile.SetCharacteristicKey("characteristicKey");
|
||||
charProfile.SetCharacteristicValue("characteristicValue");
|
||||
|
||||
map<string, string> entries;
|
||||
int32_t res1 = ProfileUtils::CharacteristicProfileToEntries(charProfile, entries);
|
||||
EXPECT_EQ(DP_SUCCESS, res1);
|
||||
|
||||
CharacteristicProfile outCharProfile;
|
||||
int32_t res2 = ProfileUtils::EntriesToCharProfile(entries, outCharProfile);
|
||||
EXPECT_EQ(DP_SUCCESS, res2);
|
||||
EXPECT_EQ("deviceId", outCharProfile.GetDeviceId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: EntriesToDeviceProfile001
|
||||
* @tc.desc: EntriesToDeviceProfile failed, Entries size is invalid.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, EntriesToDeviceProfile001, TestSize.Level1)
|
||||
{
|
||||
map<string, string> entries;
|
||||
DeviceProfile deviceProfile;
|
||||
int32_t res = ProfileUtils::EntriesToDeviceProfile(entries, deviceProfile);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: EntriesToServiceProfile001
|
||||
* @tc.desc: EntriesToServiceProfile failed, Entries size is invalid.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, EntriesToServiceProfile001, TestSize.Level1)
|
||||
{
|
||||
map<string, string> entries;
|
||||
ServiceProfile serviceProfile;
|
||||
int32_t res = ProfileUtils::EntriesToServiceProfile(entries, serviceProfile);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: EntriesToCharProfile001
|
||||
* @tc.desc: EntriesToCharProfile failed, Entries size is invalid.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, EntriesToCharProfile001, TestSize.Level1)
|
||||
{
|
||||
map<string, string> entries;
|
||||
CharacteristicProfile charProfile;
|
||||
int32_t res = ProfileUtils::EntriesToCharProfile(entries, charProfile);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SplitString001
|
||||
* @tc.desc: SplitString failed, str == "".
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, SplitString001, TestSize.Level1)
|
||||
{
|
||||
string str = "";
|
||||
string splits = "#";
|
||||
vector<string> res;
|
||||
int32_t ret = ProfileUtils::SplitString(str, splits, res);
|
||||
EXPECT_EQ(DP_INVALID_PARAMS, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SplitString002
|
||||
* @tc.desc: SplitString succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, SplitString002, TestSize.Level1)
|
||||
{
|
||||
string str = "a#b#c";
|
||||
string splits = "#";
|
||||
vector<string> res;
|
||||
int32_t ret = ProfileUtils::SplitString(str, splits, res);
|
||||
EXPECT_EQ(DP_SUCCESS, ret);
|
||||
EXPECT_EQ(3, res.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GenerateDBKey001
|
||||
* @tc.desc: GenerateDBKey succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GenerateDBKey001, TestSize.Level1)
|
||||
{
|
||||
string profileKey = "profileKey";
|
||||
string profileProperty = "profileProperty";
|
||||
string res = ProfileUtils::GenerateDBKey(profileKey, profileProperty);
|
||||
EXPECT_EQ("profileKey#profileProperty", res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetProfileKey001
|
||||
* @tc.desc: GetProfileKey succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GetProfileKey001, TestSize.Level1)
|
||||
{
|
||||
string dbKey = "profileKey#profileProperty";
|
||||
string res = ProfileUtils::GetProfileKey(dbKey);
|
||||
EXPECT_EQ("profileKey", res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetProfileKey002
|
||||
* @tc.desc: GetProfileKey failed , dbKey.length() == 0.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GetProfileKey002, TestSize.Level1)
|
||||
{
|
||||
string dbKey = "";
|
||||
string res = ProfileUtils::GetProfileKey(dbKey);
|
||||
EXPECT_EQ(0, res.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetProfileProperty001
|
||||
* @tc.desc: GetProfileProperty succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GetProfileProperty001, TestSize.Level1)
|
||||
{
|
||||
string dbKey = "profileKey#profileProperty";
|
||||
string res = ProfileUtils::GetProfileProperty(dbKey);
|
||||
EXPECT_EQ("profileProperty", res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetProfileProperty002
|
||||
* @tc.desc: GetProfileProperty failed , dbKey.length() == 0.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GetProfileProperty002, TestSize.Level1)
|
||||
{
|
||||
string dbKey = "";
|
||||
string res = ProfileUtils::GetProfileProperty(dbKey);
|
||||
EXPECT_EQ(0, res.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetDeviceIdByDBKey001
|
||||
* @tc.desc: GetDeviceIdByDBKey succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GetDeviceIdByDBKey001, TestSize.Level1)
|
||||
{
|
||||
string dbKey = "dev#111";
|
||||
string res = ProfileUtils::GetDeviceIdByDBKey(dbKey);
|
||||
EXPECT_EQ("111", res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetDeviceIdByDBKey002
|
||||
* @tc.desc: GetDeviceIdByDBKey failed , dbKey.length() == 0.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GetDeviceIdByDBKey002, TestSize.Level1)
|
||||
{
|
||||
string dbKey = "";
|
||||
string res = ProfileUtils::GetDeviceIdByDBKey(dbKey);
|
||||
EXPECT_EQ(0, res.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetDeviceIdByDBKey003
|
||||
* @tc.desc: GetDeviceIdByDBKey failed , res.size() < 1.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GetDeviceIdByDBKey003, TestSize.Level1)
|
||||
{
|
||||
string dbKey = "#";
|
||||
string res = ProfileUtils::GetDeviceIdByDBKey(dbKey);
|
||||
EXPECT_EQ(0, res.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetServiceNameByDBKey001
|
||||
* @tc.desc: GetServiceNameByDBKey succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GetServiceNameByDBKey001, TestSize.Level1)
|
||||
{
|
||||
string dbKey = "ser#111#222";
|
||||
string res = ProfileUtils::GetServiceNameByDBKey(dbKey);
|
||||
EXPECT_EQ("222", res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetServiceNameByDBKey002
|
||||
* @tc.desc: GetServiceNameByDBKey failed , dbKey.length() == 0.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GetServiceNameByDBKey002, TestSize.Level1)
|
||||
{
|
||||
string dbKey = "";
|
||||
string res = ProfileUtils::GetServiceNameByDBKey(dbKey);
|
||||
EXPECT_EQ(0, res.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetCharKeyByDBKey001
|
||||
* @tc.desc: GetCharKeyByDBKey succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GetCharKeyByDBKey001, TestSize.Level1)
|
||||
{
|
||||
string dbKey = "char#111#222#333";
|
||||
string res = ProfileUtils::GetCharKeyByDBKey(dbKey);
|
||||
EXPECT_EQ("333", res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetCharKeyByDBKey002
|
||||
* @tc.desc: GetCharKeyByDBKey failed , dbKey.length() == 0.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GetCharKeyByDBKey002, TestSize.Level1)
|
||||
{
|
||||
string dbKey = "";
|
||||
string res = ProfileUtils::GetCharKeyByDBKey(dbKey);
|
||||
EXPECT_EQ(0, res.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetCharKeyByDBKey003
|
||||
* @tc.desc: GetCharKeyByDBKey failed , res.size() < 3.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GetCharKeyByDBKey003, TestSize.Level1)
|
||||
{
|
||||
string dbKey = "char#";
|
||||
string res = ProfileUtils::GetCharKeyByDBKey(dbKey);
|
||||
EXPECT_EQ(0, res.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: toString001
|
||||
* @tc.desc: toString succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, toString001, TestSize.Level1)
|
||||
{
|
||||
u16string str16 = u"abc";
|
||||
string res = ProfileUtils::toString(str16);
|
||||
EXPECT_EQ("abc", res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IsPropertyValid001
|
||||
* @tc.desc: IsPropertyValid failed, propertyMap.size() == 0.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, IsPropertyValid001, TestSize.Level1)
|
||||
{
|
||||
map<string, string> propertyMap;
|
||||
string property = "property";
|
||||
int32_t maxValue = 1;
|
||||
bool res1 = ProfileUtils::IsPropertyValid(propertyMap, property, maxValue);
|
||||
EXPECT_EQ(false, res1);
|
||||
|
||||
int32_t minValue = 0;
|
||||
bool res2 = ProfileUtils::IsPropertyValid(propertyMap, property, minValue, maxValue);
|
||||
EXPECT_EQ(false, res2);
|
||||
|
||||
uint32_t u32MinValue = 0;
|
||||
uint32_t u32MaxValue = 1;
|
||||
bool res3 = ProfileUtils::IsPropertyValid(propertyMap, property, u32MinValue, u32MaxValue);
|
||||
EXPECT_EQ(false, res3);
|
||||
|
||||
int64_t i64MinValue = 0;
|
||||
int64_t i64MaxValue = 1;
|
||||
bool res4 = ProfileUtils::IsPropertyValid(propertyMap, property, i64MinValue, i64MaxValue);
|
||||
EXPECT_EQ(false, res4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetIntValue001
|
||||
* @tc.desc: GetIntValue failed, ValuesBucket is empty.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GetIntValue001, TestSize.Level1)
|
||||
{
|
||||
ValuesBucket values;
|
||||
string property = "property";
|
||||
int32_t value = 0;
|
||||
bool res = ProfileUtils::GetIntValue(values, property, value);
|
||||
EXPECT_EQ(false, res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetStringValue001
|
||||
* @tc.desc: GetStringValue failed, ValuesBucket is empty.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GetStringValue001, TestSize.Level1)
|
||||
{
|
||||
ValuesBucket values;
|
||||
string property = "property";
|
||||
string value = "";
|
||||
bool res = ProfileUtils::GetStringValue(values, property, value);
|
||||
EXPECT_EQ(false, res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetLongValue001
|
||||
* @tc.desc: GetLongValue failed, ValuesBucket is empty.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ProfileUtilsTest, GetLongValue001, TestSize.Level1)
|
||||
{
|
||||
ValuesBucket values;
|
||||
string property = "property";
|
||||
int64_t value = 0;
|
||||
bool res = ProfileUtils::GetLongValue(values, property, value);
|
||||
EXPECT_EQ(false, res);
|
||||
}
|
81
services/core/test/unittest/sync_options_test.cpp
Normal file
81
services/core/test/unittest/sync_options_test.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 private public
|
||||
#define protected public
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include "gtest/gtest.h"
|
||||
#include "sync_options.h"
|
||||
#include "distributed_device_profile_constants.h"
|
||||
#include "distributed_device_profile_errors.h"
|
||||
#include "distributed_device_profile_enums.h"
|
||||
#undef private
|
||||
#undef protected
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::DistributedDeviceProfile;
|
||||
using namespace std;
|
||||
|
||||
namespace {
|
||||
shared_ptr<SyncOptions> syncPtr = make_shared<SyncOptions>();
|
||||
}
|
||||
|
||||
class SyncOptionsTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void SyncOptionsTest::SetUpTestCase(void) {
|
||||
}
|
||||
|
||||
void SyncOptionsTest::TearDownTestCase(void) {
|
||||
}
|
||||
|
||||
void SyncOptionsTest::SetUp() {
|
||||
}
|
||||
|
||||
void SyncOptionsTest::TearDown() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AddGetDevice001
|
||||
* @tc.desc: AddDevice and GetDeviceList succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(SyncOptionsTest, AddGetDevice001, TestSize.Level1)
|
||||
{
|
||||
syncPtr->AddDevice("device1");
|
||||
syncPtr->AddDevice("device2");
|
||||
syncPtr->AddDevice("device3");
|
||||
EXPECT_EQ(3, syncPtr->GetDeviceList().size());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SetGetSyncMode001
|
||||
* @tc.desc: SetSyncMode and GetSyncMode succeed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(SyncOptionsTest, SetGetSyncMode001, TestSize.Level1)
|
||||
{
|
||||
syncPtr->SetSyncMode(SyncMode::PULL);
|
||||
EXPECT_EQ(SyncMode::PULL, syncPtr->GetSyncMode());
|
||||
}
|
Loading…
Reference in New Issue
Block a user