mirror of
https://gitee.com/openharmony/distributedhardware_distributed_hardware_fwk
synced 2024-11-23 07:40:26 +00:00
commit
2aeb6a5e57
@ -36,8 +36,7 @@ group("test") {
|
||||
"common/task:dh_task_test",
|
||||
"common/transport:transport_test",
|
||||
"common/utils:dh_context_test",
|
||||
"common/versioninfomanager/versioninfo:version_info_test",
|
||||
"common/versioninfomanager/versioninfomanager:versioninfo_manager_test",
|
||||
"common/versioninfomanager:versioninfo_manager_test",
|
||||
"common/versionmanager:version_manager_test",
|
||||
]
|
||||
}
|
||||
|
@ -108,5 +108,12 @@ HWTEST_F(LocalHardwareManagerTest, QueryLocalHardware_001, TestSize.Level0)
|
||||
EXPECT_EQ(true, LocalHardwareManager::GetInstance().pluginListenerMap_.empty());
|
||||
}
|
||||
|
||||
HWTEST_F(LocalHardwareManagerTest, QueryLocalHardware_002, TestSize.Level0)
|
||||
{
|
||||
DHType dhType = DHType::INPUT;
|
||||
IHardwareHandler *hardwareHandler = nullptr;
|
||||
LocalHardwareManager::GetInstance().QueryLocalHardware(dhType, hardwareHandler);
|
||||
EXPECT_EQ(true, LocalHardwareManager::GetInstance().pluginListenerMap_.empty());
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
@ -33,10 +33,37 @@ config("module_private_config") {
|
||||
}
|
||||
|
||||
## UnitTest resource_manager_test
|
||||
ohos_unittest("ResourceManagerTest") {
|
||||
ohos_unittest("CapabilityInfoTest") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
sources = [ "src/resource_manager_test.cpp" ]
|
||||
sources = [ "capability_info_test.cpp" ]
|
||||
|
||||
configs = [ ":module_private_config" ]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
"-Dprivate=public",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr",
|
||||
"${utils_path}:distributedhardwareutils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"cJSON:cjson",
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"kv_store:distributeddata_inner",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("LocalCapInfoMgrTest") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
sources = [ "local_capability_info_manager_test.cpp" ]
|
||||
|
||||
configs = [ ":module_private_config" ]
|
||||
|
||||
@ -62,7 +89,126 @@ ohos_unittest("ResourceManagerTest") {
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("MetaCapInfoTest") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
sources = [ "meta_cap_info_test.cpp" ]
|
||||
|
||||
configs = [ ":module_private_config" ]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
"-Dprivate=public",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr",
|
||||
"${utils_path}:distributedhardwareutils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"cJSON:cjson",
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"kv_store:distributeddata_inner",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("MetaInfoMgrTest") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
sources = [ "meta_info_manager_test.cpp" ]
|
||||
|
||||
configs = [ ":module_private_config" ]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
"-Dprivate=public",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr",
|
||||
"${utils_path}:distributedhardwareutils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"cJSON:cjson",
|
||||
"c_utils:utils",
|
||||
"eventhandler:libeventhandler",
|
||||
"hilog:libhilog",
|
||||
"kv_store:distributeddata_inner",
|
||||
"safwk:system_ability_fwk",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("ResourceManagerTest") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
sources = [ "resource_manager_test.cpp" ]
|
||||
|
||||
configs = [ ":module_private_config" ]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
"-Dprivate=public",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr",
|
||||
"${utils_path}:distributedhardwareutils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"cJSON:cjson",
|
||||
"c_utils:utils",
|
||||
"eventhandler:libeventhandler",
|
||||
"hilog:libhilog",
|
||||
"kv_store:distributeddata_inner",
|
||||
"safwk:system_ability_fwk",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("VersionInfoTest") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
sources = [ "version_info_test.cpp" ]
|
||||
|
||||
configs = [ ":module_private_config" ]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
"-Dprivate=public",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr",
|
||||
"${utils_path}:distributedhardwareutils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"cJSON:cjson",
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"kv_store:distributeddata_inner",
|
||||
]
|
||||
}
|
||||
|
||||
group("resource_manager_test") {
|
||||
testonly = true
|
||||
deps = [ ":ResourceManagerTest" ]
|
||||
deps = [
|
||||
":CapabilityInfoTest",
|
||||
":LocalCapInfoMgrTest",
|
||||
":MetaCapInfoTest",
|
||||
":MetaInfoMgrTest",
|
||||
":ResourceManagerTest",
|
||||
":VersionInfoTest",
|
||||
]
|
||||
}
|
||||
|
@ -0,0 +1,238 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "cJSON.h"
|
||||
|
||||
#include "constants.h"
|
||||
#include "meta_capability_info.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace std;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class CapabilityInfoTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void CapabilityInfoTest::SetUp() {}
|
||||
|
||||
void CapabilityInfoTest::TearDown() {}
|
||||
|
||||
void CapabilityInfoTest::SetUpTestCase() {}
|
||||
|
||||
void CapabilityInfoTest::TearDownTestCase() {}
|
||||
|
||||
HWTEST_F(CapabilityInfoTest, ToJson_001, TestSize.Level0)
|
||||
{
|
||||
cJSON *jsonObject = nullptr;
|
||||
CapabilityInfo capability;
|
||||
ToJson(jsonObject, capability);
|
||||
EXPECT_TRUE(capability.GetDHId().empty());
|
||||
}
|
||||
|
||||
HWTEST_F(CapabilityInfoTest, FromJson_001, TestSize.Level0)
|
||||
{
|
||||
cJSON *jsonObject = nullptr;
|
||||
CapabilityInfo capability;
|
||||
FromJson(jsonObject, capability);
|
||||
EXPECT_TRUE(capability.GetDHId().empty());
|
||||
}
|
||||
|
||||
HWTEST_F(CapabilityInfoTest, FromJson_002, TestSize.Level0)
|
||||
{
|
||||
cJSON *jsonObj = cJSON_CreateObject();
|
||||
ASSERT_TRUE(jsonObj != nullptr);
|
||||
cJSON_AddNumberToObject(jsonObj, DH_ID.c_str(), 1);
|
||||
char* cjson = cJSON_PrintUnformatted(jsonObj);
|
||||
if (cjson == nullptr) {
|
||||
cJSON_Delete(jsonObj);
|
||||
return;
|
||||
}
|
||||
std::string jsonStr(cjson);
|
||||
CapabilityInfo capability;
|
||||
FromJson(jsonObj, capability);
|
||||
cJSON_free(cjson);
|
||||
cJSON_Delete(jsonObj);
|
||||
EXPECT_TRUE(capability.GetDeviceId().empty());
|
||||
}
|
||||
|
||||
HWTEST_F(CapabilityInfoTest, FromJson_003, TestSize.Level0)
|
||||
{
|
||||
cJSON *jsonObj = cJSON_CreateObject();
|
||||
ASSERT_TRUE(jsonObj != nullptr);
|
||||
cJSON_AddStringToObject(jsonObj, DH_ID.c_str(), "dhid_test");
|
||||
cJSON_AddNumberToObject(jsonObj, DEV_ID.c_str(), 1);
|
||||
char* cjson = cJSON_PrintUnformatted(jsonObj);
|
||||
if (cjson == nullptr) {
|
||||
cJSON_Delete(jsonObj);
|
||||
return;
|
||||
}
|
||||
std::string jsonStr(cjson);
|
||||
CapabilityInfo capability;
|
||||
FromJson(jsonObj, capability);
|
||||
cJSON_free(cjson);
|
||||
cJSON_Delete(jsonObj);
|
||||
EXPECT_FALSE(capability.GetDHId().empty());
|
||||
}
|
||||
|
||||
HWTEST_F(CapabilityInfoTest, FromJson_004, TestSize.Level0)
|
||||
{
|
||||
cJSON *jsonObj = cJSON_CreateObject();
|
||||
ASSERT_TRUE(jsonObj != nullptr);
|
||||
cJSON_AddStringToObject(jsonObj, DH_ID.c_str(), "dhid_test");
|
||||
cJSON_AddStringToObject(jsonObj, DEV_ID.c_str(), "devid_test");
|
||||
cJSON_AddNumberToObject(jsonObj, DEV_NAME.c_str(), 1);
|
||||
char* cjson = cJSON_PrintUnformatted(jsonObj);
|
||||
if (cjson == nullptr) {
|
||||
cJSON_Delete(jsonObj);
|
||||
return;
|
||||
}
|
||||
std::string jsonStr(cjson);
|
||||
CapabilityInfo capability;
|
||||
FromJson(jsonObj, capability);
|
||||
cJSON_free(cjson);
|
||||
cJSON_Delete(jsonObj);
|
||||
EXPECT_FALSE(capability.GetDHId().empty());
|
||||
}
|
||||
|
||||
HWTEST_F(CapabilityInfoTest, FromJson_005, TestSize.Level0)
|
||||
{
|
||||
cJSON *jsonObj = cJSON_CreateObject();
|
||||
ASSERT_TRUE(jsonObj != nullptr);
|
||||
cJSON_AddStringToObject(jsonObj, DH_ID.c_str(), "dhid_test");
|
||||
cJSON_AddStringToObject(jsonObj, DEV_ID.c_str(), "devid_test");
|
||||
cJSON_AddStringToObject(jsonObj, DEV_NAME.c_str(), "devname_test");
|
||||
cJSON_AddStringToObject(jsonObj, DEV_TYPE.c_str(), "devtype_test");
|
||||
char* cjson = cJSON_PrintUnformatted(jsonObj);
|
||||
if (cjson == nullptr) {
|
||||
cJSON_Delete(jsonObj);
|
||||
return;
|
||||
}
|
||||
std::string jsonStr(cjson);
|
||||
CapabilityInfo capability;
|
||||
FromJson(jsonObj, capability);
|
||||
cJSON_free(cjson);
|
||||
cJSON_Delete(jsonObj);
|
||||
EXPECT_FALSE(capability.GetDHId().empty());
|
||||
}
|
||||
|
||||
HWTEST_F(CapabilityInfoTest, FromJson_006, TestSize.Level0)
|
||||
{
|
||||
const uint16_t devType = 1;
|
||||
cJSON *jsonObj = cJSON_CreateObject();
|
||||
ASSERT_TRUE(jsonObj != nullptr);
|
||||
cJSON_AddStringToObject(jsonObj, DH_ID.c_str(), "dhid_test");
|
||||
cJSON_AddStringToObject(jsonObj, DEV_ID.c_str(), "devid_test");
|
||||
cJSON_AddStringToObject(jsonObj, DEV_NAME.c_str(), "devname_test");
|
||||
cJSON_AddNumberToObject(jsonObj, DEV_TYPE.c_str(), devType);
|
||||
cJSON_AddStringToObject(jsonObj, DH_TYPE.c_str(), "dhtype_test");
|
||||
char* cjson = cJSON_PrintUnformatted(jsonObj);
|
||||
if (cjson == nullptr) {
|
||||
cJSON_Delete(jsonObj);
|
||||
return;
|
||||
}
|
||||
std::string jsonStr(cjson);
|
||||
CapabilityInfo capability;
|
||||
FromJson(jsonObj, capability);
|
||||
cJSON_free(cjson);
|
||||
cJSON_Delete(jsonObj);
|
||||
EXPECT_FALSE(capability.GetDHId().empty());
|
||||
}
|
||||
|
||||
HWTEST_F(CapabilityInfoTest, FromJson_007, TestSize.Level0)
|
||||
{
|
||||
const uint16_t devType = 1;
|
||||
const uint32_t dhType = 1;
|
||||
cJSON *jsonObj = cJSON_CreateObject();
|
||||
ASSERT_TRUE(jsonObj != nullptr);
|
||||
cJSON_AddStringToObject(jsonObj, DH_ID.c_str(), "dhid_test");
|
||||
cJSON_AddStringToObject(jsonObj, DEV_ID.c_str(), "devid_test");
|
||||
cJSON_AddStringToObject(jsonObj, DEV_NAME.c_str(), "devname_test");
|
||||
cJSON_AddNumberToObject(jsonObj, DEV_TYPE.c_str(), devType);
|
||||
cJSON_AddNumberToObject(jsonObj, DH_TYPE.c_str(), dhType);
|
||||
cJSON_AddNumberToObject(jsonObj, DH_ATTRS.c_str(), 1);
|
||||
char* cjson = cJSON_PrintUnformatted(jsonObj);
|
||||
if (cjson == nullptr) {
|
||||
cJSON_Delete(jsonObj);
|
||||
return;
|
||||
}
|
||||
std::string jsonStr(cjson);
|
||||
CapabilityInfo capability;
|
||||
FromJson(jsonObj, capability);
|
||||
cJSON_free(cjson);
|
||||
cJSON_Delete(jsonObj);
|
||||
EXPECT_FALSE(capability.GetDHId().empty());
|
||||
}
|
||||
|
||||
HWTEST_F(CapabilityInfoTest, FromJson_008, TestSize.Level0)
|
||||
{
|
||||
const uint16_t devType = 1;
|
||||
const uint32_t dhType = 1;
|
||||
cJSON *jsonObj = cJSON_CreateObject();
|
||||
ASSERT_TRUE(jsonObj != nullptr);
|
||||
cJSON_AddStringToObject(jsonObj, DH_ID.c_str(), "dhid_test");
|
||||
cJSON_AddStringToObject(jsonObj, DEV_ID.c_str(), "devid_test");
|
||||
cJSON_AddStringToObject(jsonObj, DEV_NAME.c_str(), "devname_test");
|
||||
cJSON_AddNumberToObject(jsonObj, DEV_TYPE.c_str(), devType);
|
||||
cJSON_AddNumberToObject(jsonObj, DH_TYPE.c_str(), dhType);
|
||||
cJSON_AddStringToObject(jsonObj, DH_ATTRS.c_str(), "dhattrs_test");
|
||||
cJSON_AddNumberToObject(jsonObj, DH_SUBTYPE.c_str(), 1);
|
||||
char* cjson = cJSON_PrintUnformatted(jsonObj);
|
||||
if (cjson == nullptr) {
|
||||
cJSON_Delete(jsonObj);
|
||||
return;
|
||||
}
|
||||
std::string jsonStr(cjson);
|
||||
CapabilityInfo capability;
|
||||
FromJson(jsonObj, capability);
|
||||
cJSON_free(cjson);
|
||||
cJSON_Delete(jsonObj);
|
||||
EXPECT_FALSE(capability.GetDHId().empty());
|
||||
}
|
||||
|
||||
HWTEST_F(CapabilityInfoTest, FromJson_009, TestSize.Level0)
|
||||
{
|
||||
const uint16_t devType = 1;
|
||||
const uint32_t dhType = 1;
|
||||
cJSON *jsonObj = cJSON_CreateObject();
|
||||
ASSERT_TRUE(jsonObj != nullptr);
|
||||
cJSON_AddStringToObject(jsonObj, DH_ID.c_str(), "dhid_test");
|
||||
cJSON_AddStringToObject(jsonObj, DEV_ID.c_str(), "devid_test");
|
||||
cJSON_AddStringToObject(jsonObj, DEV_NAME.c_str(), "devname_test");
|
||||
cJSON_AddNumberToObject(jsonObj, DEV_TYPE.c_str(), devType);
|
||||
cJSON_AddNumberToObject(jsonObj, DH_TYPE.c_str(), dhType);
|
||||
cJSON_AddStringToObject(jsonObj, DH_ATTRS.c_str(), "dhattrs_test");
|
||||
cJSON_AddStringToObject(jsonObj, DH_SUBTYPE.c_str(), "dhsubtype_test");
|
||||
char* cjson = cJSON_PrintUnformatted(jsonObj);
|
||||
if (cjson == nullptr) {
|
||||
cJSON_Delete(jsonObj);
|
||||
return;
|
||||
}
|
||||
std::string jsonStr(cjson);
|
||||
CapabilityInfo capability;
|
||||
FromJson(jsonObj, capability);
|
||||
cJSON_free(cjson);
|
||||
cJSON_Delete(jsonObj);
|
||||
EXPECT_FALSE(capability.GetDHId().empty());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_DISTRIBUTED_HARDWARE_RESOURCE_MANAGER_TEST_H
|
||||
#define OHOS_DISTRIBUTED_HARDWARE_RESOURCE_MANAGER_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class ResourceManagerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
@ -0,0 +1,244 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "cJSON.h"
|
||||
|
||||
#include "constants.h"
|
||||
#include "capability_info.h"
|
||||
#include "distributed_hardware_errno.h"
|
||||
#include "local_capability_info_manager.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace std;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace {
|
||||
constexpr uint16_t DEV_TYPE_TEST = 14;
|
||||
}
|
||||
class LocalCapInfoMgrTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void LocalCapInfoMgrTest::SetUp() {}
|
||||
|
||||
void LocalCapInfoMgrTest::TearDown() {}
|
||||
|
||||
void LocalCapInfoMgrTest::SetUpTestCase() {}
|
||||
|
||||
void LocalCapInfoMgrTest::TearDownTestCase() {}
|
||||
|
||||
HWTEST_F(LocalCapInfoMgrTest, Init_001, TestSize.Level0)
|
||||
{
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->Init();
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
|
||||
ret = LocalCapabilityInfoManager::GetInstance()->UnInit();
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(LocalCapInfoMgrTest, UnInit_001, TestSize.Level0)
|
||||
{
|
||||
LocalCapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr;
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->UnInit();
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_UNINIT_DB_FAILED, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(LocalCapInfoMgrTest, SyncDeviceInfoFromDB_001, TestSize.Level0)
|
||||
{
|
||||
std::string deviceId = "deviceId_test";
|
||||
LocalCapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr;
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->SyncDeviceInfoFromDB(deviceId);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
|
||||
LocalCapabilityInfoManager::GetInstance()->Init();
|
||||
ret = LocalCapabilityInfoManager::GetInstance()->SyncDeviceInfoFromDB(deviceId);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(LocalCapInfoMgrTest, AddCapability_001, TestSize.Level0)
|
||||
{
|
||||
std::vector<std::shared_ptr<CapabilityInfo>> resInfos;
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->AddCapability(resInfos);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(LocalCapInfoMgrTest, AddCapability_002, TestSize.Level0)
|
||||
{
|
||||
std::shared_ptr<CapabilityInfo> capInfo = std::make_shared<CapabilityInfo>("", "", "", 0, DHType::UNKNOWN, "", "");
|
||||
std::vector<std::shared_ptr<CapabilityInfo>> resInfos;
|
||||
resInfos.push_back(capInfo);
|
||||
LocalCapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr;
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->AddCapability(resInfos);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(LocalCapInfoMgrTest, AddCapability_003, TestSize.Level0)
|
||||
{
|
||||
std::shared_ptr<CapabilityInfo> capInfo = std::make_shared<CapabilityInfo>("", "", "", 0, DHType::UNKNOWN, "", "");
|
||||
std::vector<std::shared_ptr<CapabilityInfo>> resInfos;
|
||||
resInfos.push_back(capInfo);
|
||||
LocalCapabilityInfoManager::GetInstance()->Init();
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->AddCapability(resInfos);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(LocalCapInfoMgrTest, RemoveCapabilityInfoByKey_001, TestSize.Level0)
|
||||
{
|
||||
std::string key = "";
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->RemoveCapabilityInfoByKey(key);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(LocalCapInfoMgrTest, RemoveCapabilityInfoByKey_002, TestSize.Level0)
|
||||
{
|
||||
std::string key = "deviceId_test";
|
||||
LocalCapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr;
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->RemoveCapabilityInfoByKey(key);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
|
||||
LocalCapabilityInfoManager::GetInstance()->Init();
|
||||
ret = LocalCapabilityInfoManager::GetInstance()->RemoveCapabilityInfoByKey(key);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(LocalCapInfoMgrTest, GetCapabilitiesByDeviceId_001, TestSize.Level0)
|
||||
{
|
||||
std::string deviceId = "";
|
||||
std::vector<std::shared_ptr<CapabilityInfo>> resInfos;
|
||||
LocalCapabilityInfoManager::GetInstance()->GetCapabilitiesByDeviceId(deviceId, resInfos);
|
||||
|
||||
deviceId = "123456789";
|
||||
std::string dhid = "111111";
|
||||
std::shared_ptr<CapabilityInfo> capInfo = std::make_shared<CapabilityInfo>(
|
||||
"dhid", deviceId, "devName_test", DEV_TYPE_TEST, DHType::AUDIO, "attrs", "subtype");
|
||||
std::string key = deviceId + "###" + dhid;
|
||||
LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_[key] = capInfo;
|
||||
LocalCapabilityInfoManager::GetInstance()->GetCapabilitiesByDeviceId(deviceId, resInfos);
|
||||
EXPECT_TRUE(resInfos.empty());
|
||||
}
|
||||
|
||||
HWTEST_F(LocalCapInfoMgrTest, GetCapability_001, TestSize.Level0)
|
||||
{
|
||||
std::string deviceId = "";
|
||||
std::string dhId = "";
|
||||
std::shared_ptr<CapabilityInfo> capPtr;
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->GetCapability(deviceId, dhId, capPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
|
||||
deviceId = "deviceId_test";
|
||||
ret = LocalCapabilityInfoManager::GetInstance()->GetCapability(deviceId, dhId, capPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
|
||||
dhId = "dhId_test";
|
||||
deviceId = "";
|
||||
ret = LocalCapabilityInfoManager::GetInstance()->GetCapability(deviceId, dhId, capPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(LocalCapInfoMgrTest, GetCapability_002, TestSize.Level0)
|
||||
{
|
||||
std::string deviceId = "deviceId_test";
|
||||
std::string dhId = "dhId_test";
|
||||
std::shared_ptr<CapabilityInfo> capPtr;
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->GetCapability(deviceId, dhId, capPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_CAPABILITY_MAP_NOT_FOUND, ret);
|
||||
|
||||
std::shared_ptr<CapabilityInfo> capbilityInfo = std::make_shared<CapabilityInfo>(
|
||||
dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::AUDIO, "attrs", "subtype");
|
||||
std::string key = deviceId + "###" + dhId;
|
||||
LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_[key] = capbilityInfo;
|
||||
ret = LocalCapabilityInfoManager::GetInstance()->GetCapability(deviceId, dhId, capPtr);
|
||||
LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_.clear();
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(LocalCapInfoMgrTest, GetDataByKey_001, TestSize.Level0)
|
||||
{
|
||||
std::string key = "";
|
||||
std::shared_ptr<CapabilityInfo> capPtr;
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->GetDataByKey(key, capPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(LocalCapInfoMgrTest, GetDataByKey_002, TestSize.Level0)
|
||||
{
|
||||
std::string key = "key_test";
|
||||
std::shared_ptr<CapabilityInfo> capPtr;
|
||||
LocalCapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr;
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->GetDataByKey(key, capPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
|
||||
LocalCapabilityInfoManager::GetInstance()->Init();
|
||||
ret = LocalCapabilityInfoManager::GetInstance()->GetDataByKey(key, capPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(LocalCapInfoMgrTest, GetDataByDHType_001, TestSize.Level0)
|
||||
{
|
||||
CapabilityInfoMap capabilityMap;
|
||||
std::string deviceId = "deviceId_test";
|
||||
std::shared_ptr<CapabilityInfo> capbilityInfo = std::make_shared<CapabilityInfo>(
|
||||
"dhId_test", deviceId, "devName_test", 14, DHType::AUDIO, "attrs", "subtype");
|
||||
std::string key = deviceId + "###" + "dhId_test";
|
||||
LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_[key] = capbilityInfo;
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->GetDataByDHType(DHType::CAMERA, capabilityMap);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
|
||||
ret = LocalCapabilityInfoManager::GetInstance()->GetDataByDHType(DHType::AUDIO, capabilityMap);
|
||||
LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_.clear();
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(LocalCapInfoMgrTest, GetDataByKeyPrefix_001, TestSize.Level0)
|
||||
{
|
||||
std::string keyPrefix = "";
|
||||
CapabilityInfoMap capabilityMap;
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->GetDataByKeyPrefix(keyPrefix, capabilityMap);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(LocalCapInfoMgrTest, GetDataByKeyPrefix_002, TestSize.Level0)
|
||||
{
|
||||
std::string keyPrefix = "keyPrefix_test";
|
||||
CapabilityInfoMap capabilityMap;
|
||||
LocalCapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr;
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->GetDataByKeyPrefix(keyPrefix, capabilityMap);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
|
||||
LocalCapabilityInfoManager::GetInstance()->Init();
|
||||
ret = LocalCapabilityInfoManager::GetInstance()->GetDataByKeyPrefix(keyPrefix, capabilityMap);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(LocalCapInfoMgrTest, ClearRemoteDeviceLocalInfoData_001, TestSize.Level0)
|
||||
{
|
||||
std::string peeruuid = "";
|
||||
LocalCapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr;
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->ClearRemoteDeviceLocalInfoData(peeruuid);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
|
||||
LocalCapabilityInfoManager::GetInstance()->Init();
|
||||
ret = LocalCapabilityInfoManager::GetInstance()->ClearRemoteDeviceLocalInfoData(peeruuid);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,329 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "cJSON.h"
|
||||
|
||||
#include "constants.h"
|
||||
#include "dh_utils_tool.h"
|
||||
#include "distributed_hardware_errno.h"
|
||||
#include "meta_capability_info.h"
|
||||
#include "meta_info_manager.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace std;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace {
|
||||
constexpr uint16_t DEV_TYPE_TEST = 14;
|
||||
}
|
||||
|
||||
class MetaInfoMgrTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void MetaInfoMgrTest::SetUp() {}
|
||||
|
||||
void MetaInfoMgrTest::TearDown() {}
|
||||
|
||||
void MetaInfoMgrTest::SetUpTestCase() {}
|
||||
|
||||
void MetaInfoMgrTest::TearDownTestCase() {}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, Init_001, TestSize.Level0)
|
||||
{
|
||||
auto ret = MetaInfoManager::GetInstance()->Init();
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
ret = MetaInfoManager::GetInstance()->UnInit();
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, UnInit_001, TestSize.Level0)
|
||||
{
|
||||
MetaInfoManager::GetInstance()->dbAdapterPtr_ = nullptr;
|
||||
auto ret = MetaInfoManager::GetInstance()->UnInit();
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_UNINIT_DB_FAILED, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, AddMetaCapInfos_001, TestSize.Level0)
|
||||
{
|
||||
std::vector<std::shared_ptr<MetaCapabilityInfo>> metaCapInfos;
|
||||
auto ret = MetaInfoManager::GetInstance()->AddMetaCapInfos(metaCapInfos);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, AddMetaCapInfos_002, TestSize.Level0)
|
||||
{
|
||||
std::string deviceId = "deviceId_test";
|
||||
std::string udidHash = "udidHash_test";
|
||||
std::string dhId = "dhId_test";
|
||||
std::shared_ptr<MetaCapabilityInfo> metaCapInfo = std::make_shared<MetaCapabilityInfo>(
|
||||
dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0");
|
||||
std::vector<std::shared_ptr<MetaCapabilityInfo>> metaCapInfos;
|
||||
metaCapInfos.push_back(metaCapInfo);
|
||||
auto ret = MetaInfoManager::GetInstance()->AddMetaCapInfos(metaCapInfos);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
ret = MetaInfoManager::GetInstance()->AddMetaCapInfos(metaCapInfos);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
MetaInfoManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, SyncMetaInfoFromDB_001, TestSize.Level0)
|
||||
{
|
||||
std::string udidHash = "";
|
||||
auto ret = MetaInfoManager::GetInstance()->SyncMetaInfoFromDB(udidHash);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, SyncMetaInfoFromDB_002, TestSize.Level0)
|
||||
{
|
||||
std::string udidHash = "132456798";
|
||||
auto ret = MetaInfoManager::GetInstance()->SyncMetaInfoFromDB(udidHash);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, SyncMetaInfoFromDB_003, TestSize.Level0)
|
||||
{
|
||||
std::string udidHash = "132456798";
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
auto ret = MetaInfoManager::GetInstance()->SyncMetaInfoFromDB(udidHash);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret);
|
||||
MetaInfoManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, SyncRemoteMetaInfos_001, TestSize.Level0)
|
||||
{
|
||||
auto ret = MetaInfoManager::GetInstance()->SyncRemoteMetaInfos();
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
ret = MetaInfoManager::GetInstance()->SyncRemoteMetaInfos();
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
MetaInfoManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, GetDataByKeyPrefix_001, TestSize.Level0)
|
||||
{
|
||||
std::string keyPrefix = "";
|
||||
MetaCapInfoMap metaCapMap;
|
||||
auto ret = MetaInfoManager::GetInstance()->GetDataByKeyPrefix(keyPrefix, metaCapMap);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
|
||||
keyPrefix = "keyPrefix_test";
|
||||
ret = MetaInfoManager::GetInstance()->GetDataByKeyPrefix(keyPrefix, metaCapMap);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, GetDataByKeyPrefix_002, TestSize.Level0)
|
||||
{
|
||||
std::string keyPrefix = "keyPrefix_test";
|
||||
MetaCapInfoMap metaCapMap;
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
auto ret = MetaInfoManager::GetInstance()->GetDataByKeyPrefix(keyPrefix, metaCapMap);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret);
|
||||
MetaInfoManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, RemoveMetaInfoByKey_001, TestSize.Level0)
|
||||
{
|
||||
std::string key = "";
|
||||
auto ret = MetaInfoManager::GetInstance()->RemoveMetaInfoByKey(key);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
|
||||
key = "key_test";
|
||||
ret = MetaInfoManager::GetInstance()->RemoveMetaInfoByKey(key);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, RemoveMetaInfoByKey_002, TestSize.Level0)
|
||||
{
|
||||
std::string key = "key_test";
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
auto ret = MetaInfoManager::GetInstance()->RemoveMetaInfoByKey(key);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
MetaInfoManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, GetMetaCapInfo_001, TestSize.Level0)
|
||||
{
|
||||
std::string udidHash = "";
|
||||
std::string dhId = "";
|
||||
std::shared_ptr<MetaCapabilityInfo> metaCapPtr;
|
||||
auto ret = MetaInfoManager::GetInstance()->GetMetaCapInfo(udidHash, dhId, metaCapPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
|
||||
udidHash = "123456789";
|
||||
ret = MetaInfoManager::GetInstance()->GetMetaCapInfo(udidHash, dhId, metaCapPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
|
||||
udidHash = "";
|
||||
dhId = "123456789";
|
||||
ret = MetaInfoManager::GetInstance()->GetMetaCapInfo(udidHash, dhId, metaCapPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, GetMetaCapInfo_002, TestSize.Level0)
|
||||
{
|
||||
std::string deviceId = "deviceId_test";
|
||||
std::string udidHash = "udidHash_test";
|
||||
std::string dhId = "dhId_test";
|
||||
std::shared_ptr<MetaCapabilityInfo> metaCapPtr;
|
||||
std::shared_ptr<MetaCapabilityInfo> dhMetaCapInfo = std::make_shared<MetaCapabilityInfo>(
|
||||
dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0");
|
||||
std::string key = udidHash + "###" + dhId;
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_[key] = dhMetaCapInfo;
|
||||
auto ret = MetaInfoManager::GetInstance()->GetMetaCapInfo(deviceId, dhId, metaCapPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_CAPABILITY_MAP_NOT_FOUND, ret);
|
||||
|
||||
ret = MetaInfoManager::GetInstance()->GetMetaCapInfo(udidHash, dhId, metaCapPtr);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_.clear();
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, GetMetaCapInfosByUdidHash_001, TestSize.Level0)
|
||||
{
|
||||
std::string udidHash = "";
|
||||
std::vector<std::shared_ptr<MetaCapabilityInfo>> metaCapInfos;
|
||||
MetaInfoManager::GetInstance()->GetMetaCapInfosByUdidHash(udidHash, metaCapInfos);
|
||||
|
||||
udidHash = "udidHash_test";
|
||||
std::string deviceId = "deviceId_test";
|
||||
std::string dhId = "dhId_test";
|
||||
std::shared_ptr<MetaCapabilityInfo> metaCapInfo = std::make_shared<MetaCapabilityInfo>(
|
||||
dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0");
|
||||
std::string key = udidHash + "###" + dhId;
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_[key] = metaCapInfo;
|
||||
MetaInfoManager::GetInstance()->GetMetaCapInfosByUdidHash(deviceId, metaCapInfos);
|
||||
EXPECT_TRUE(metaCapInfos.empty());
|
||||
|
||||
MetaInfoManager::GetInstance()->GetMetaCapInfosByUdidHash(udidHash, metaCapInfos);
|
||||
EXPECT_FALSE(metaCapInfos.empty());
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_.clear();
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, GetMetaCapByValue_001, TestSize.Level0)
|
||||
{
|
||||
std::string value = "";
|
||||
std::shared_ptr<MetaCapabilityInfo> metaCapPtr = nullptr;
|
||||
auto ret = MetaInfoManager::GetInstance()->GetMetaCapByValue(value, metaCapPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
|
||||
value = "invalid JSON string";
|
||||
ret = MetaInfoManager::GetInstance()->GetMetaCapByValue(value, metaCapPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_JSON_PARSE_FAILED, ret);
|
||||
|
||||
std::string deviceId = "deviceId_test";
|
||||
std::string udidHash = "udidHash_test";
|
||||
std::string dhId = "dhId_test";
|
||||
metaCapPtr = std::make_shared<MetaCapabilityInfo>(
|
||||
dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0");
|
||||
ret = MetaInfoManager::GetInstance()->GetMetaCapByValue(value, metaCapPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_JSON_PARSE_FAILED, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, GetMetaDataByDHType_001, TestSize.Level0)
|
||||
{
|
||||
std::string deviceId = "deviceId_test";
|
||||
std::string udidHash = "udidHash_test";
|
||||
std::string dhId = "dhId_test";
|
||||
MetaCapInfoMap metaInfoMap;
|
||||
std::shared_ptr<MetaCapabilityInfo> dhMetaCapInfo = std::make_shared<MetaCapabilityInfo>(
|
||||
dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0");
|
||||
std::string key = udidHash + "###" + dhId;
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_[key] = dhMetaCapInfo;
|
||||
auto ret = MetaInfoManager::GetInstance()->GetMetaDataByDHType(DHType::AUDIO, metaInfoMap);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
|
||||
ret = MetaInfoManager::GetInstance()->GetMetaDataByDHType(DHType::CAMERA, metaInfoMap);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_.clear();
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, SyncDataByNetworkId_001, TestSize.Level0)
|
||||
{
|
||||
std::string networkId = "";
|
||||
auto ret = MetaInfoManager::GetInstance()->SyncDataByNetworkId(networkId);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
|
||||
networkId = "networkId_test";
|
||||
ret = MetaInfoManager::GetInstance()->SyncDataByNetworkId(networkId);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, SyncDataByNetworkId_002, TestSize.Level0)
|
||||
{
|
||||
std::string networkId = "networkId_test";
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
auto ret = MetaInfoManager::GetInstance()->SyncDataByNetworkId(networkId);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
MetaInfoManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, RemoveMetaInfoInMemByUdid_001, TestSize.Level0)
|
||||
{
|
||||
std::string peerudid = "123456789";
|
||||
std::string peerudIdHash = Sha256(peerudid);
|
||||
std::string deviceId = "deviceId_test";
|
||||
std::string udidHash = "udidHash_test";
|
||||
std::string dhId = "dhId_test";
|
||||
std::shared_ptr<MetaCapabilityInfo> metaCapPtr = std::make_shared<MetaCapabilityInfo>(
|
||||
dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0");
|
||||
std::string key = peerudIdHash + "###" + dhId;
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_[key] = metaCapPtr;
|
||||
auto ret = MetaInfoManager::GetInstance()->RemoveMetaInfoInMemByUdid(deviceId);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
|
||||
ret = MetaInfoManager::GetInstance()->RemoveMetaInfoInMemByUdid(peerudid);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, ClearRemoteDeviceMetaInfoData_001, TestSize.Level0)
|
||||
{
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
std::string peerudid = "peerudid_test";
|
||||
std::string peeruuid = "peeruuid_test";
|
||||
auto ret = MetaInfoManager::GetInstance()->ClearRemoteDeviceMetaInfoData(peerudid, peeruuid);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret);
|
||||
|
||||
MetaInfoManager::GetInstance()->UnInit();
|
||||
ret = MetaInfoManager::GetInstance()->ClearRemoteDeviceMetaInfoData(peerudid, peeruuid);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, GetEntriesByKeys_001, TestSize.Level0)
|
||||
{
|
||||
std::vector<std::string> keys;
|
||||
auto ret = MetaInfoManager::GetInstance()->GetEntriesByKeys(keys);
|
||||
EXPECT_EQ(0, ret.size());
|
||||
|
||||
keys.push_back("key_test");
|
||||
ret = MetaInfoManager::GetInstance()->GetEntriesByKeys(keys);
|
||||
EXPECT_EQ(0, ret.size());
|
||||
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
ret = MetaInfoManager::GetInstance()->GetEntriesByKeys(keys);
|
||||
EXPECT_EQ(0, ret.size());
|
||||
MetaInfoManager::GetInstance()->UnInit();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,329 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "cJSON.h"
|
||||
|
||||
#include "constants.h"
|
||||
#include "dh_utils_tool.h"
|
||||
#include "distributed_hardware_errno.h"
|
||||
#include "meta_capability_info.h"
|
||||
#include "meta_info_manager.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace std;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace {
|
||||
constexpr uint16_t DEV_TYPE_TEST = 14;
|
||||
}
|
||||
|
||||
class MetaInfoMgrTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void MetaInfoMgrTest::SetUp() {}
|
||||
|
||||
void MetaInfoMgrTest::TearDown() {}
|
||||
|
||||
void MetaInfoMgrTest::SetUpTestCase() {}
|
||||
|
||||
void MetaInfoMgrTest::TearDownTestCase() {}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, Init_001, TestSize.Level0)
|
||||
{
|
||||
auto ret = MetaInfoManager::GetInstance()->Init();
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
ret = MetaInfoManager::GetInstance()->UnInit();
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, UnInit_001, TestSize.Level0)
|
||||
{
|
||||
MetaInfoManager::GetInstance()->dbAdapterPtr_ = nullptr;
|
||||
auto ret = MetaInfoManager::GetInstance()->UnInit();
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_UNINIT_DB_FAILED, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, AddMetaCapInfos_001, TestSize.Level0)
|
||||
{
|
||||
std::vector<std::shared_ptr<MetaCapabilityInfo>> metaCapInfos;
|
||||
auto ret = MetaInfoManager::GetInstance()->AddMetaCapInfos(metaCapInfos);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, AddMetaCapInfos_002, TestSize.Level0)
|
||||
{
|
||||
std::string deviceId = "deviceId_test";
|
||||
std::string udidHash = "udidHash_test";
|
||||
std::string dhId = "dhId_test";
|
||||
std::shared_ptr<MetaCapabilityInfo> metaCapInfo = std::make_shared<MetaCapabilityInfo>(
|
||||
dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0");
|
||||
std::vector<std::shared_ptr<MetaCapabilityInfo>> metaCapInfos;
|
||||
metaCapInfos.push_back(metaCapInfo);
|
||||
auto ret = MetaInfoManager::GetInstance()->AddMetaCapInfos(metaCapInfos);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
ret = MetaInfoManager::GetInstance()->AddMetaCapInfos(metaCapInfos);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
MetaInfoManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, SyncMetaInfoFromDB_001, TestSize.Level0)
|
||||
{
|
||||
std::string udidHash = "";
|
||||
auto ret = MetaInfoManager::GetInstance()->SyncMetaInfoFromDB(udidHash);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, SyncMetaInfoFromDB_002, TestSize.Level0)
|
||||
{
|
||||
std::string udidHash = "132456798";
|
||||
auto ret = MetaInfoManager::GetInstance()->SyncMetaInfoFromDB(udidHash);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, SyncMetaInfoFromDB_003, TestSize.Level0)
|
||||
{
|
||||
std::string udidHash = "132456798";
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
auto ret = MetaInfoManager::GetInstance()->SyncMetaInfoFromDB(udidHash);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret);
|
||||
MetaInfoManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, SyncRemoteMetaInfos_001, TestSize.Level0)
|
||||
{
|
||||
auto ret = MetaInfoManager::GetInstance()->SyncRemoteMetaInfos();
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
ret = MetaInfoManager::GetInstance()->SyncRemoteMetaInfos();
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
MetaInfoManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, GetDataByKeyPrefix_001, TestSize.Level0)
|
||||
{
|
||||
std::string keyPrefix = "";
|
||||
MetaCapInfoMap metaCapMap;
|
||||
auto ret = MetaInfoManager::GetInstance()->GetDataByKeyPrefix(keyPrefix, metaCapMap);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
|
||||
keyPrefix = "keyPrefix_test";
|
||||
ret = MetaInfoManager::GetInstance()->GetDataByKeyPrefix(keyPrefix, metaCapMap);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, GetDataByKeyPrefix_002, TestSize.Level0)
|
||||
{
|
||||
std::string keyPrefix = "keyPrefix_test";
|
||||
MetaCapInfoMap metaCapMap;
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
auto ret = MetaInfoManager::GetInstance()->GetDataByKeyPrefix(keyPrefix, metaCapMap);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret);
|
||||
MetaInfoManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, RemoveMetaInfoByKey_001, TestSize.Level0)
|
||||
{
|
||||
std::string key = "";
|
||||
auto ret = MetaInfoManager::GetInstance()->RemoveMetaInfoByKey(key);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
|
||||
key = "key_test";
|
||||
ret = MetaInfoManager::GetInstance()->RemoveMetaInfoByKey(key);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, RemoveMetaInfoByKey_002, TestSize.Level0)
|
||||
{
|
||||
std::string key = "key_test";
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
auto ret = MetaInfoManager::GetInstance()->RemoveMetaInfoByKey(key);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
MetaInfoManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, GetMetaCapInfo_001, TestSize.Level0)
|
||||
{
|
||||
std::string udidHash = "";
|
||||
std::string dhId = "";
|
||||
std::shared_ptr<MetaCapabilityInfo> metaCapPtr;
|
||||
auto ret = MetaInfoManager::GetInstance()->GetMetaCapInfo(udidHash, dhId, metaCapPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
|
||||
udidHash = "123456789";
|
||||
ret = MetaInfoManager::GetInstance()->GetMetaCapInfo(udidHash, dhId, metaCapPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
|
||||
udidHash = "";
|
||||
dhId = "123456789";
|
||||
ret = MetaInfoManager::GetInstance()->GetMetaCapInfo(udidHash, dhId, metaCapPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, GetMetaCapInfo_002, TestSize.Level0)
|
||||
{
|
||||
std::string deviceId = "deviceId_test";
|
||||
std::string udidHash = "udidHash_test";
|
||||
std::string dhId = "dhId_test";
|
||||
std::shared_ptr<MetaCapabilityInfo> metaCapPtr;
|
||||
std::shared_ptr<MetaCapabilityInfo> dhMetaCapInfo = std::make_shared<MetaCapabilityInfo>(
|
||||
dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0");
|
||||
std::string key = udidHash + "###" + dhId;
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_[key] = dhMetaCapInfo;
|
||||
auto ret = MetaInfoManager::GetInstance()->GetMetaCapInfo(deviceId, dhId, metaCapPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_CAPABILITY_MAP_NOT_FOUND, ret);
|
||||
|
||||
ret = MetaInfoManager::GetInstance()->GetMetaCapInfo(udidHash, dhId, metaCapPtr);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_.clear();
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, GetMetaCapInfosByUdidHash_001, TestSize.Level0)
|
||||
{
|
||||
std::string udidHash = "";
|
||||
std::vector<std::shared_ptr<MetaCapabilityInfo>> metaCapInfos;
|
||||
MetaInfoManager::GetInstance()->GetMetaCapInfosByUdidHash(udidHash, metaCapInfos);
|
||||
|
||||
udidHash = "udidHash_test";
|
||||
std::string deviceId = "deviceId_test";
|
||||
std::string dhId = "dhId_test";
|
||||
std::shared_ptr<MetaCapabilityInfo> metaCapInfo = std::make_shared<MetaCapabilityInfo>(
|
||||
dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0");
|
||||
std::string key = udidHash + "###" + dhId;
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_[key] = metaCapInfo;
|
||||
MetaInfoManager::GetInstance()->GetMetaCapInfosByUdidHash(deviceId, metaCapInfos);
|
||||
EXPECT_TRUE(metaCapInfos.empty());
|
||||
|
||||
MetaInfoManager::GetInstance()->GetMetaCapInfosByUdidHash(udidHash, metaCapInfos);
|
||||
EXPECT_FALSE(metaCapInfos.empty());
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_.clear();
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, GetMetaCapByValue_001, TestSize.Level0)
|
||||
{
|
||||
std::string value = "";
|
||||
std::shared_ptr<MetaCapabilityInfo> metaCapPtr = nullptr;
|
||||
auto ret = MetaInfoManager::GetInstance()->GetMetaCapByValue(value, metaCapPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
|
||||
value = "invalid JSON string";
|
||||
ret = MetaInfoManager::GetInstance()->GetMetaCapByValue(value, metaCapPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_JSON_PARSE_FAILED, ret);
|
||||
|
||||
std::string deviceId = "deviceId_test";
|
||||
std::string udidHash = "udidHash_test";
|
||||
std::string dhId = "dhId_test";
|
||||
metaCapPtr = std::make_shared<MetaCapabilityInfo>(
|
||||
dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0");
|
||||
ret = MetaInfoManager::GetInstance()->GetMetaCapByValue(value, metaCapPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_JSON_PARSE_FAILED, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, GetMetaDataByDHType_001, TestSize.Level0)
|
||||
{
|
||||
std::string deviceId = "deviceId_test";
|
||||
std::string udidHash = "udidHash_test";
|
||||
std::string dhId = "dhId_test";
|
||||
MetaCapInfoMap metaInfoMap;
|
||||
std::shared_ptr<MetaCapabilityInfo> dhMetaCapInfo = std::make_shared<MetaCapabilityInfo>(
|
||||
dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0");
|
||||
std::string key = udidHash + "###" + dhId;
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_[key] = dhMetaCapInfo;
|
||||
auto ret = MetaInfoManager::GetInstance()->GetMetaDataByDHType(DHType::AUDIO, metaInfoMap);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
|
||||
ret = MetaInfoManager::GetInstance()->GetMetaDataByDHType(DHType::CAMERA, metaInfoMap);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_.clear();
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, SyncDataByNetworkId_001, TestSize.Level0)
|
||||
{
|
||||
std::string networkId = "";
|
||||
auto ret = MetaInfoManager::GetInstance()->SyncDataByNetworkId(networkId);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
|
||||
networkId = "networkId_test";
|
||||
ret = MetaInfoManager::GetInstance()->SyncDataByNetworkId(networkId);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, SyncDataByNetworkId_002, TestSize.Level0)
|
||||
{
|
||||
std::string networkId = "networkId_test";
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
auto ret = MetaInfoManager::GetInstance()->SyncDataByNetworkId(networkId);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
MetaInfoManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, RemoveMetaInfoInMemByUdid_001, TestSize.Level0)
|
||||
{
|
||||
std::string peerudid = "123456789";
|
||||
std::string peerudIdHash = Sha256(peerudid);
|
||||
std::string deviceId = "deviceId_test";
|
||||
std::string udidHash = "udidHash_test";
|
||||
std::string dhId = "dhId_test";
|
||||
std::shared_ptr<MetaCapabilityInfo> metaCapPtr = std::make_shared<MetaCapabilityInfo>(
|
||||
dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0");
|
||||
std::string key = peerudIdHash + "###" + dhId;
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_[key] = metaCapPtr;
|
||||
auto ret = MetaInfoManager::GetInstance()->RemoveMetaInfoInMemByUdid(deviceId);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
|
||||
ret = MetaInfoManager::GetInstance()->RemoveMetaInfoInMemByUdid(peerudid);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, ClearRemoteDeviceMetaInfoData_001, TestSize.Level0)
|
||||
{
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
std::string peerudid = "peerudid_test";
|
||||
std::string peeruuid = "peeruuid_test";
|
||||
auto ret = MetaInfoManager::GetInstance()->ClearRemoteDeviceMetaInfoData(peerudid, peeruuid);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret);
|
||||
|
||||
MetaInfoManager::GetInstance()->UnInit();
|
||||
ret = MetaInfoManager::GetInstance()->ClearRemoteDeviceMetaInfoData(peerudid, peeruuid);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(MetaInfoMgrTest, GetEntriesByKeys_001, TestSize.Level0)
|
||||
{
|
||||
std::vector<std::string> keys;
|
||||
auto ret = MetaInfoManager::GetInstance()->GetEntriesByKeys(keys);
|
||||
EXPECT_EQ(0, ret.size());
|
||||
|
||||
keys.push_back("key_test");
|
||||
ret = MetaInfoManager::GetInstance()->GetEntriesByKeys(keys);
|
||||
EXPECT_EQ(0, ret.size());
|
||||
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
ret = MetaInfoManager::GetInstance()->GetEntriesByKeys(keys);
|
||||
EXPECT_EQ(0, ret.size());
|
||||
MetaInfoManager::GetInstance()->UnInit();
|
||||
}
|
||||
}
|
||||
}
|
@ -13,23 +13,20 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "resource_manager_test.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cerrno>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <vector>
|
||||
|
||||
#include "cJSON.h"
|
||||
|
||||
#include "constants.h"
|
||||
#include "capability_info.h"
|
||||
#include "capability_info_manager.h"
|
||||
#include "local_capability_info_manager.h"
|
||||
#include "meta_capability_info.h"
|
||||
#include "meta_info_manager.h"
|
||||
#include "dh_context.h"
|
||||
#include "distributed_hardware_errno.h"
|
||||
#include "distributed_hardware_log.h"
|
||||
#include "cJSON.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace std;
|
||||
@ -101,6 +98,14 @@ const shared_ptr<CapabilityInfo> CAP_INFO_9 =
|
||||
DH_SUBTYPE_4);
|
||||
}
|
||||
|
||||
class ResourceManagerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void ResourceManagerTest::SetUpTestCase(void)
|
||||
{
|
||||
auto ret = mkdir(DATABASE_DIR.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||
@ -849,54 +854,6 @@ HWTEST_F(ResourceManagerTest, DumpCapabilityInfos_001, TestSize.Level0)
|
||||
EXPECT_EQ(nullptr, CapabilityInfoManager::GetInstance()->dbAdapterPtr_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: FromJson_001
|
||||
* @tc.desc: Verify the FromJson function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GHSJE
|
||||
*/
|
||||
HWTEST_F(ResourceManagerTest, FromJson_001, TestSize.Level0)
|
||||
{
|
||||
std::string dhId;
|
||||
std::string devId;
|
||||
std::string devName;
|
||||
uint16_t devType = 0;
|
||||
DHType dhType = DHType::GPS;
|
||||
std::string dhAttrs;
|
||||
std::string dhSubtype;
|
||||
CapabilityInfo info(dhId, devId, devName, devType, dhType, dhAttrs, dhSubtype);
|
||||
|
||||
cJSON* json = cJSON_CreateObject();
|
||||
if (json == nullptr) {
|
||||
return;
|
||||
}
|
||||
const char* DH_ID = "dh_id";
|
||||
const char* DEV_ID = "dev_id";
|
||||
const char* DEV_NAME = "dev_name";
|
||||
const char* DEV_TYPE = "dev_type";
|
||||
const char* DH_TYPE = "dh_type";
|
||||
const char* DH_ATTRS = "dh_attrs";
|
||||
const char* DH_SUBTYPE = "dh_subtype";
|
||||
|
||||
cJSON_AddStringToObject(json, DH_ID, "dh_id");
|
||||
cJSON_AddStringToObject(json, DEV_ID, "dev_id");
|
||||
cJSON_AddStringToObject(json, DEV_NAME, "dev_name");
|
||||
cJSON_AddNumberToObject(json, DEV_TYPE, devType);
|
||||
cJSON_AddStringToObject(json, DH_TYPE, "dh_type");
|
||||
cJSON_AddStringToObject(json, DH_ATTRS, "dh_attrs");
|
||||
cJSON_AddStringToObject(json, DH_SUBTYPE, "dh_subtype");
|
||||
|
||||
char* cjson = cJSON_PrintUnformatted(json);
|
||||
if (cjson == nullptr) {
|
||||
cJSON_Delete(json);
|
||||
return;
|
||||
}
|
||||
std::string jsonStr(cjson);
|
||||
cJSON_free(cjson);
|
||||
cJSON_Delete(json);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, info.FromJsonString(jsonStr));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetEntriesByKeys_001
|
||||
* @tc.desc: Verify the GetEntriesByKeys function.
|
||||
@ -909,328 +866,5 @@ HWTEST_F(ResourceManagerTest, GetEntriesByKeys_001, TestSize.Level0)
|
||||
auto entries = CapabilityInfoManager::GetInstance()->GetEntriesByKeys(keys);
|
||||
EXPECT_EQ(0, entries.size());
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, Init_001, TestSize.Level0)
|
||||
{
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->Init();
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, UnInit_001, TestSize.Level0)
|
||||
{
|
||||
LocalCapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr;
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->UnInit();
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_UNINIT_DB_FAILED, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, UnInit_002, TestSize.Level0)
|
||||
{
|
||||
LocalCapabilityInfoManager::GetInstance()->Init();
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->UnInit();
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, SyncDeviceInfoFromDB_001, TestSize.Level0)
|
||||
{
|
||||
std::string deviceId = "deviceId_test";
|
||||
LocalCapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr;
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->SyncDeviceInfoFromDB(deviceId);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
|
||||
LocalCapabilityInfoManager::GetInstance()->Init();
|
||||
ret = LocalCapabilityInfoManager::GetInstance()->SyncDeviceInfoFromDB(deviceId);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, RemoveCapabilityInfoByKey_001, TestSize.Level0)
|
||||
{
|
||||
std::string key = "deviceId_test";
|
||||
LocalCapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr;
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->RemoveCapabilityInfoByKey(key);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
|
||||
LocalCapabilityInfoManager::GetInstance()->Init();
|
||||
ret = LocalCapabilityInfoManager::GetInstance()->RemoveCapabilityInfoByKey(key);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, GetCapability_001, TestSize.Level0)
|
||||
{
|
||||
std::string deviceId = "deviceId_test";
|
||||
std::string dhId = "dhId_test";
|
||||
std::shared_ptr<CapabilityInfo> capPtr;
|
||||
LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_.clear();
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->GetCapability(deviceId, dhId, capPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_CAPABILITY_MAP_NOT_FOUND, ret);
|
||||
|
||||
std::shared_ptr<CapabilityInfo> capbilityInfo = std::make_shared<CapabilityInfo>(
|
||||
dhId, deviceId, "devName_test", 14, DHType::AUDIO, "attrs", "subtype");
|
||||
std::string key = deviceId + "###" + dhId;
|
||||
LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_[key] = capbilityInfo;
|
||||
ret = LocalCapabilityInfoManager::GetInstance()->GetCapability(deviceId, dhId, capPtr);
|
||||
LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_.clear();
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, GetDataByKey_002, TestSize.Level0)
|
||||
{
|
||||
std::string key = "key_test";
|
||||
std::shared_ptr<CapabilityInfo> capPtr;
|
||||
LocalCapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr;
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->GetDataByKey(key, capPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
|
||||
LocalCapabilityInfoManager::GetInstance()->Init();
|
||||
ret = LocalCapabilityInfoManager::GetInstance()->GetDataByKey(key, capPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, GetDataByDHType_001, TestSize.Level0)
|
||||
{
|
||||
CapabilityInfoMap capabilityMap;
|
||||
std::string deviceId = "deviceId_test";
|
||||
std::shared_ptr<CapabilityInfo> capbilityInfo = std::make_shared<CapabilityInfo>(
|
||||
"dhId_test", deviceId, "devName_test", 14, DHType::AUDIO, "attrs", "subtype");
|
||||
std::string key = deviceId + "###" + "dhId_test";
|
||||
LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_[key] = capbilityInfo;
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->GetDataByDHType(DHType::CAMERA, capabilityMap);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
|
||||
ret = LocalCapabilityInfoManager::GetInstance()->GetDataByDHType(DHType::AUDIO, capabilityMap);
|
||||
LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_.clear();
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, GetDataByKeyPrefix_002, TestSize.Level0)
|
||||
{
|
||||
std::string keyPrefix = "keyPrefix_test";
|
||||
CapabilityInfoMap capabilityMap;
|
||||
LocalCapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr;
|
||||
auto ret = LocalCapabilityInfoManager::GetInstance()->GetDataByKeyPrefix(keyPrefix, capabilityMap);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
|
||||
LocalCapabilityInfoManager::GetInstance()->Init();
|
||||
ret = LocalCapabilityInfoManager::GetInstance()->GetDataByKeyPrefix(keyPrefix, capabilityMap);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, UnInit_003, TestSize.Level0)
|
||||
{
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
auto ret = MetaInfoManager::GetInstance()->UnInit();
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, AddMetaCapInfos_001, TestSize.Level0)
|
||||
{
|
||||
std::string deviceId = "deviceId_test";
|
||||
std::string udidHash = "udidHash_test";
|
||||
std::string dhId = "dhId_test";
|
||||
MetaInfoManager::GetInstance()->dbAdapterPtr_ = nullptr;
|
||||
std::shared_ptr<MetaCapabilityInfo> dhMetaCapInfo = std::make_shared<MetaCapabilityInfo>(
|
||||
dhId, deviceId, "devName_test", 14, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0");
|
||||
std::vector<std::shared_ptr<MetaCapabilityInfo>> metaCapInfos;
|
||||
metaCapInfos.push_back(dhMetaCapInfo);
|
||||
auto ret = MetaInfoManager::GetInstance()->AddMetaCapInfos(metaCapInfos);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, SyncMetaInfoFromDB_001, TestSize.Level0)
|
||||
{
|
||||
std::string deviceId = "deviceId_test";
|
||||
MetaInfoManager::GetInstance()->dbAdapterPtr_ = nullptr;
|
||||
auto ret = MetaInfoManager::GetInstance()->SyncMetaInfoFromDB(deviceId);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
ret = MetaInfoManager::GetInstance()->SyncMetaInfoFromDB(deviceId);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, SyncRemoteMetaInfos_001, TestSize.Level0)
|
||||
{
|
||||
MetaInfoManager::GetInstance()->dbAdapterPtr_ = nullptr;
|
||||
auto ret = MetaInfoManager::GetInstance()->SyncRemoteMetaInfos();
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
ret = MetaInfoManager::GetInstance()->SyncRemoteMetaInfos();
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, GetDataByKeyPrefix_003, TestSize.Level0)
|
||||
{
|
||||
std::string keyPrefix = "keyPrefix_test";
|
||||
MetaCapInfoMap metaCapMap;
|
||||
MetaInfoManager::GetInstance()->dbAdapterPtr_ = nullptr;
|
||||
auto ret = MetaInfoManager::GetInstance()->GetDataByKeyPrefix(keyPrefix, metaCapMap);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
ret = MetaInfoManager::GetInstance()->GetDataByKeyPrefix(keyPrefix, metaCapMap);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, RemoveMetaInfoByKey_001, TestSize.Level0)
|
||||
{
|
||||
std::string key = "key_test";
|
||||
MetaInfoManager::GetInstance()->dbAdapterPtr_ = nullptr;
|
||||
auto ret = MetaInfoManager::GetInstance()->RemoveMetaInfoByKey(key);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
ret = MetaInfoManager::GetInstance()->RemoveMetaInfoByKey(key);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, GetMetaCapInfo_001, TestSize.Level0)
|
||||
{
|
||||
std::string deviceId = "deviceId_test";
|
||||
std::string udidHash = "udidHash_test";
|
||||
std::string dhId = "dhId_test";
|
||||
std::shared_ptr<MetaCapabilityInfo> metaCapPtr;
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_.clear();
|
||||
auto ret = MetaInfoManager::GetInstance()->GetMetaCapInfo(deviceId, dhId, metaCapPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_CAPABILITY_MAP_NOT_FOUND, ret);
|
||||
|
||||
std::shared_ptr<MetaCapabilityInfo> dhMetaCapInfo = std::make_shared<MetaCapabilityInfo>(
|
||||
dhId, deviceId, "devName_test", 14, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0");
|
||||
std::string key = udidHash + "###" + dhId;
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_[key] = dhMetaCapInfo;
|
||||
ret = MetaInfoManager::GetInstance()->GetMetaCapInfo(udidHash, dhId, metaCapPtr);
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_.clear();
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_[key] = dhMetaCapInfo;
|
||||
std::vector<std::shared_ptr<MetaCapabilityInfo>> metaCapInfos;
|
||||
MetaInfoManager::GetInstance()->GetMetaCapInfosByUdidHash(udidHash, metaCapInfos);
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_.clear();
|
||||
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_[key] = dhMetaCapInfo;
|
||||
MetaInfoManager::GetInstance()->GetMetaCapInfosByUdidHash(udidHash, metaCapInfos);
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_.clear();
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, GetMetaCapByValue_001, TestSize.Level0)
|
||||
{
|
||||
std::string value = "";
|
||||
std::shared_ptr<MetaCapabilityInfo> metaCapPtr = nullptr;
|
||||
auto ret = MetaInfoManager::GetInstance()->GetMetaCapByValue(value, metaCapPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
|
||||
std::string deviceId = "deviceId_test";
|
||||
std::string udidHash = "udidHash_test";
|
||||
std::string dhId = "dhId_test";
|
||||
metaCapPtr = std::make_shared<MetaCapabilityInfo>(
|
||||
dhId, deviceId, "devName_test", 14, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0");
|
||||
ret = MetaInfoManager::GetInstance()->GetMetaCapByValue(value, metaCapPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
|
||||
value = "invalid JSON string";
|
||||
ret = MetaInfoManager::GetInstance()->GetMetaCapByValue(value, metaCapPtr);
|
||||
EXPECT_EQ(ERR_DH_FWK_JSON_PARSE_FAILED, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, GetEntriesByKeys_002, TestSize.Level0)
|
||||
{
|
||||
std::vector<std::string> keys;
|
||||
auto ret = MetaInfoManager::GetInstance()->GetEntriesByKeys(keys);
|
||||
EXPECT_EQ(0, ret.size());
|
||||
|
||||
MetaInfoManager::GetInstance()->dbAdapterPtr_ = nullptr;
|
||||
keys.push_back("key_test");
|
||||
ret = MetaInfoManager::GetInstance()->GetEntriesByKeys(keys);
|
||||
EXPECT_EQ(0, ret.size());
|
||||
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
ret = MetaInfoManager::GetInstance()->GetEntriesByKeys(keys);
|
||||
EXPECT_EQ(0, ret.size());
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, FromJson_002, TestSize.Level0)
|
||||
{
|
||||
MetaCapabilityInfo metaCapInfo;
|
||||
std::string dhId = "dhId_test";
|
||||
std::string dveId = "devId_test";
|
||||
std::string devName = "devName_test";
|
||||
uint16_t devType = 14;
|
||||
DHType dhType = DHType::AUDIO;
|
||||
std::string dhAttrs = "dhAttrs_test";
|
||||
std::string dhSubtype = "dhSubtype_test";
|
||||
std::string sinkVersion = "sinkVersion_test";
|
||||
cJSON *jsonObj = cJSON_CreateObject();
|
||||
if (jsonObj == nullptr) {
|
||||
return;
|
||||
}
|
||||
cJSON_AddStringToObject(jsonObj, DH_ID.c_str(), dhId.c_str());
|
||||
cJSON_AddStringToObject(jsonObj, DEV_ID.c_str(), dveId.c_str());
|
||||
cJSON_AddStringToObject(jsonObj, DEV_NAME.c_str(), devName.c_str());
|
||||
cJSON_AddNumberToObject(jsonObj, DEV_TYPE.c_str(), (double)devType);
|
||||
cJSON_AddNumberToObject(jsonObj, DH_TYPE.c_str(), (double)dhType);
|
||||
cJSON_AddStringToObject(jsonObj, DH_ATTRS.c_str(), dhAttrs.c_str());
|
||||
cJSON_AddStringToObject(jsonObj, DH_SUBTYPE.c_str(), sinkVersion.c_str());
|
||||
cJSON_AddStringToObject(jsonObj, SINK_VER.c_str(), sinkVersion.c_str());
|
||||
FromJson(jsonObj, metaCapInfo);
|
||||
EXPECT_EQ(0, MetaInfoManager::GetInstance()->globalMetaInfoMap_.size());
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, GetMetaDataByDHType_001, TestSize.Level0)
|
||||
{
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_.clear();
|
||||
std::string deviceId = "deviceId_test";
|
||||
std::string udidHash = "udidHash_test";
|
||||
std::string dhId = "dhId_test";
|
||||
MetaCapInfoMap metaInfoMap;
|
||||
std::shared_ptr<MetaCapabilityInfo> dhMetaCapInfo = std::make_shared<MetaCapabilityInfo>(
|
||||
dhId, deviceId, "devName_test", 14, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0");
|
||||
std::string key = udidHash + "###" + dhId;
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_[key] = dhMetaCapInfo;
|
||||
auto ret = MetaInfoManager::GetInstance()->GetMetaDataByDHType(DHType::AUDIO, metaInfoMap);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, GetMetaDataByDHType_002, TestSize.Level0)
|
||||
{
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_.clear();
|
||||
std::string deviceId = "deviceId_test";
|
||||
std::string udidHash = "udidHash_test";
|
||||
std::string dhId = "dhId_test";
|
||||
MetaCapInfoMap metaInfoMap;
|
||||
std::shared_ptr<MetaCapabilityInfo> dhMetaCapInfo = std::make_shared<MetaCapabilityInfo>(
|
||||
dhId, deviceId, "devName_test", 14, DHType::AUDIO, "attrs_test", "subtype", udidHash, "1.0");
|
||||
std::string key = udidHash + "###" + dhId;
|
||||
MetaInfoManager::GetInstance()->globalMetaInfoMap_[key] = dhMetaCapInfo;
|
||||
auto ret = MetaInfoManager::GetInstance()->GetMetaDataByDHType(DHType::AUDIO, metaInfoMap);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, SyncDataByNetworkId_001, TestSize.Level0)
|
||||
{
|
||||
std::string networkId = "";
|
||||
auto ret = MetaInfoManager::GetInstance()->SyncDataByNetworkId(networkId);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
|
||||
networkId = "networkId_test";
|
||||
ret = MetaInfoManager::GetInstance()->SyncDataByNetworkId(networkId);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
|
||||
|
||||
MetaInfoManager::GetInstance()->dbAdapterPtr_ = nullptr;
|
||||
ret = MetaInfoManager::GetInstance()->SyncDataByNetworkId(networkId);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, ClearRemoteDeviceMetaInfoData_001, TestSize.Level0)
|
||||
{
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
std::string peerudid = "peerudid_test";
|
||||
std::string peeruuid = "peeruuid_test";
|
||||
auto ret = MetaInfoManager::GetInstance()->ClearRemoteDeviceMetaInfoData(peerudid, peeruuid);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret);
|
||||
|
||||
MetaInfoManager::GetInstance()->dbAdapterPtr_ = nullptr;
|
||||
ret = MetaInfoManager::GetInstance()->ClearRemoteDeviceMetaInfoData(peerudid, peeruuid);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
@ -0,0 +1,140 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "cJSON.h"
|
||||
|
||||
#include "constants.h"
|
||||
#include "distributed_hardware_errno.h"
|
||||
#include "version_info.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace std;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class VersionInfoTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void VersionInfoTest::SetUp() {}
|
||||
|
||||
void VersionInfoTest::TearDown() {}
|
||||
|
||||
void VersionInfoTest::SetUpTestCase() {}
|
||||
|
||||
void VersionInfoTest::TearDownTestCase() {}
|
||||
|
||||
HWTEST_F(VersionInfoTest, FromJsonString_001, TestSize.Level0)
|
||||
{
|
||||
std::shared_ptr<VersionInfo> versionInfoPtr = std::make_shared<VersionInfo>();
|
||||
std::string jsonStr = "";
|
||||
auto ret = versionInfoPtr->FromJsonString(jsonStr);
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(VersionInfoTest, ToJson_001, TestSize.Level0)
|
||||
{
|
||||
cJSON *jsonObj = nullptr;
|
||||
VersionInfo verInfo;
|
||||
ToJson(jsonObj, verInfo);
|
||||
EXPECT_TRUE(verInfo.deviceId.empty());
|
||||
}
|
||||
|
||||
HWTEST_F(VersionInfoTest, FromJson_CompVersion_001, TestSize.Level0)
|
||||
{
|
||||
cJSON *jsonObj = nullptr;
|
||||
CompVersion compVer;
|
||||
FromJson(jsonObj, compVer);
|
||||
EXPECT_TRUE(compVer.name.empty());
|
||||
}
|
||||
|
||||
HWTEST_F(VersionInfoTest, FromJson_CompVersion_002, TestSize.Level0)
|
||||
{
|
||||
const uint32_t dhType = 1;
|
||||
cJSON *jsonObj = cJSON_CreateObject();
|
||||
ASSERT_TRUE(jsonObj != nullptr);
|
||||
cJSON_AddStringToObject(jsonObj, NAME.c_str(), "name_test");
|
||||
cJSON_AddNumberToObject(jsonObj, TYPE.c_str(), dhType);
|
||||
cJSON_AddStringToObject(jsonObj, HANDLER.c_str(), "handler_ver_1.0");
|
||||
cJSON_AddStringToObject(jsonObj, SOURCE_VER.c_str(), "source_ver_1.0");
|
||||
cJSON_AddStringToObject(jsonObj, SINK_VER.c_str(), "sink_ver_1.0");
|
||||
CompVersion compVer;
|
||||
FromJson(jsonObj, compVer);
|
||||
cJSON_Delete(jsonObj);
|
||||
EXPECT_FALSE(compVer.name.empty());
|
||||
}
|
||||
|
||||
HWTEST_F(VersionInfoTest, FromJson_CompVersion_003, TestSize.Level0)
|
||||
{
|
||||
cJSON *jsonObj = cJSON_CreateObject();
|
||||
ASSERT_TRUE(jsonObj != nullptr);
|
||||
cJSON_AddNumberToObject(jsonObj, NAME.c_str(), 1);
|
||||
cJSON_AddStringToObject(jsonObj, TYPE.c_str(), "dhType_audio");
|
||||
cJSON_AddNumberToObject(jsonObj, HANDLER.c_str(), 1);
|
||||
cJSON_AddNumberToObject(jsonObj, SOURCE_VER.c_str(), 1);
|
||||
cJSON_AddNumberToObject(jsonObj, SINK_VER.c_str(), 1);
|
||||
CompVersion compVer;
|
||||
FromJson(jsonObj, compVer);
|
||||
cJSON_Delete(jsonObj);
|
||||
EXPECT_TRUE(compVer.name.empty());
|
||||
}
|
||||
|
||||
HWTEST_F(VersionInfoTest, FromJson_VersionInfo_001, TestSize.Level0)
|
||||
{
|
||||
cJSON *jsonObj = nullptr;
|
||||
VersionInfo verInfo;
|
||||
FromJson(jsonObj, verInfo);
|
||||
EXPECT_TRUE(verInfo.deviceId.empty());
|
||||
}
|
||||
|
||||
HWTEST_F(VersionInfoTest, FromJson_VersionInfo_002, TestSize.Level0)
|
||||
{
|
||||
cJSON *jsonObj = cJSON_CreateObject();
|
||||
ASSERT_TRUE(jsonObj != nullptr);
|
||||
cJSON_AddStringToObject(jsonObj, DEV_ID.c_str(), "devid_123");
|
||||
cJSON_AddStringToObject(jsonObj, DH_VER.c_str(), "dhver_1.0");
|
||||
|
||||
cJSON * jsonArr = cJSON_CreateArray();
|
||||
if (jsonArr == nullptr) {
|
||||
cJSON_Delete(jsonObj);
|
||||
return;
|
||||
}
|
||||
cJSON_AddItemToArray(jsonArr, cJSON_CreateString("com_ver_test"));
|
||||
cJSON_AddItemToObject(jsonObj, COMP_VER.c_str(), jsonArr);
|
||||
VersionInfo verInfo;
|
||||
FromJson(jsonObj, verInfo);
|
||||
cJSON_Delete(jsonObj);
|
||||
EXPECT_FALSE(verInfo.deviceId.empty());
|
||||
}
|
||||
|
||||
HWTEST_F(VersionInfoTest, FromJson_VersionInfo_003, TestSize.Level0)
|
||||
{
|
||||
cJSON *jsonObj = cJSON_CreateObject();
|
||||
ASSERT_TRUE(jsonObj != nullptr);
|
||||
cJSON_AddNumberToObject(jsonObj, DEV_ID.c_str(), 1);
|
||||
cJSON_AddNumberToObject(jsonObj, DH_VER.c_str(), 1);
|
||||
VersionInfo verInfo;
|
||||
FromJson(jsonObj, verInfo);
|
||||
cJSON_Delete(jsonObj);
|
||||
EXPECT_TRUE(verInfo.deviceId.empty());
|
||||
}
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@
|
||||
#include "version_manager.h"
|
||||
#include "dh_context.h"
|
||||
#include "distributed_hardware_log.h"
|
||||
#include "dh_utils_tool.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace std;
|
||||
@ -183,6 +184,13 @@ HWTEST_F(VersionInfoManagerTest, version_info_manager_test_005, TestSize.Level0)
|
||||
EXPECT_EQ(VersionInfoManager::GetInstance()->UnInit(), DH_FWK_SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST_F(VersionInfoManagerTest, version_info_manager_test_006, TestSize.Level0)
|
||||
{
|
||||
VersionInfoManager::GetInstance()->dbAdapterPtr_= nullptr;
|
||||
auto ret = VersionInfoManager::GetInstance()->UnInit();
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_UNINIT_DB_FAILED, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UpdateVersionCache_001
|
||||
* @tc.desc: Verify the UpdateVersionCache function
|
||||
@ -206,9 +214,17 @@ HWTEST_F(VersionInfoManagerTest, UpdateVersionCache_001, TestSize.Level0)
|
||||
*/
|
||||
HWTEST_F(VersionInfoManagerTest, UpdateVersionCache_002, TestSize.Level0)
|
||||
{
|
||||
VersionInfo versionInfo;
|
||||
std::string testUdid = "111111";
|
||||
std::string testUuid = "222222";
|
||||
std::string testNetworkId = "333333";
|
||||
std::string testDeviceId = Sha256(testUuid);
|
||||
VersionInfo versionInfo = {
|
||||
.deviceId = testDeviceId,
|
||||
.dhVersion = "1.0"
|
||||
};
|
||||
DHContext::GetInstance().AddOnlineDevice(testUdid, testUuid, testNetworkId);
|
||||
VersionInfoManager::GetInstance()->UpdateVersionCache(versionInfo);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, VersionInfoManager::GetInstance()->Init());
|
||||
EXPECT_FALSE(versionInfo.dhVersion.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -426,5 +442,14 @@ HWTEST_F(VersionInfoManagerTest, GetVersionInfoByDeviceId_001, TestSize.Level0)
|
||||
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(VersionInfoManagerTest, GetVersionInfoByDeviceId_002, TestSize.Level0)
|
||||
{
|
||||
std::string deviceId = DEV_ID_1;
|
||||
VersionInfo versionInfo;
|
||||
VersionInfoManager::GetInstance()->Init();
|
||||
int32_t ret = VersionInfoManager::GetInstance()->GetVersionInfoByDeviceId(deviceId, versionInfo);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
}
|
||||
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
@ -1,67 +0,0 @@
|
||||
# Copyright (c) 2022-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.
|
||||
|
||||
import("//build/test.gni")
|
||||
import(
|
||||
"//foundation/distributedhardware/distributed_hardware_fwk/distributedhardwarefwk.gni")
|
||||
|
||||
module_out_path = "distributed_hardware_fwk/version_info_test"
|
||||
|
||||
config("module_private_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [
|
||||
"include",
|
||||
"${utils_path}/include",
|
||||
"${utils_path}/include/log",
|
||||
"${utils_path}/include/eventbus",
|
||||
"${services_path}/distributedhardwarefwkservice/include",
|
||||
"${services_path}/distributedhardwarefwkservice/include/resourcemanager",
|
||||
"${services_path}/distributedhardwarefwkservice/include/utils",
|
||||
"${services_path}/distributedhardwarefwkservice/include/versionmanager",
|
||||
"${common_path}/utils/include",
|
||||
"${common_path}/log/include",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("VersionInfoTest") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
sources = [ "src/version_info_test.cpp" ]
|
||||
|
||||
configs = [ ":module_private_config" ]
|
||||
|
||||
deps = [
|
||||
"${services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr",
|
||||
"${utils_path}:distributedhardwareutils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"cJSON:cjson",
|
||||
"c_utils:utils",
|
||||
"eventhandler:libeventhandler",
|
||||
"kv_store:distributeddata_inner",
|
||||
"safwk:system_ability_fwk",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
"-Dprivate=public",
|
||||
]
|
||||
}
|
||||
|
||||
group("version_info_test") {
|
||||
testonly = true
|
||||
deps = [ ":VersionInfoTest" ]
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_DISTRIBUTED_HARDWARE_VERSION_INFO_TEST_H
|
||||
#define OHOS_DISTRIBUTED_HARDWARE_VERSION_INFO_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <vector>
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class VersionInfoTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
@ -1,161 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022-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.
|
||||
*/
|
||||
|
||||
#include "version_info_test.h"
|
||||
|
||||
#include <cerrno>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "version_info_manager.h"
|
||||
#include "version_manager.h"
|
||||
#include "version_info.h"
|
||||
#include "dh_context.h"
|
||||
#include "distributed_hardware_errno.h"
|
||||
#include "distributed_hardware_log.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace std;
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
#undef DH_LOG_TAG
|
||||
#define DH_LOG_TAG "VersionInfoTest"
|
||||
|
||||
namespace {
|
||||
const string DEV_ID_1 = "bb536a637105409e904d4da83790a4a7";
|
||||
const string NAME_SCREEN = "distributed_screen";
|
||||
const string VERSION_1 = "1.0";
|
||||
}
|
||||
|
||||
void VersionInfoTest::SetUpTestCase(void)
|
||||
{
|
||||
}
|
||||
|
||||
void VersionInfoTest::TearDownTestCase(void)
|
||||
{
|
||||
}
|
||||
|
||||
void VersionInfoTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void VersionInfoTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name:version_info_test_001
|
||||
* @tc.desc: Verify the VersionInfoTest ToJson function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GHSCV
|
||||
*/
|
||||
HWTEST_F(VersionInfoTest, version_info_test_001, TestSize.Level0)
|
||||
{
|
||||
CompVersion compVersions1 = {
|
||||
.name = NAME_SCREEN,
|
||||
.dhType = DHType::SCREEN,
|
||||
.handlerVersion = VERSION_1,
|
||||
.sourceVersion = VERSION_1,
|
||||
.sinkVersion = VERSION_1
|
||||
};
|
||||
|
||||
VersionInfo verInfo1;
|
||||
verInfo1.deviceId = DEV_ID_1;
|
||||
verInfo1.dhVersion = VERSION_1;
|
||||
verInfo1.compVersions.insert(std::pair<DHType, CompVersion>(compVersions1.dhType, compVersions1));
|
||||
|
||||
std::string jsonStr = verInfo1.ToJsonString();
|
||||
EXPECT_NE(jsonStr.empty(), true);
|
||||
|
||||
VersionInfo verInfo2;
|
||||
verInfo2.FromJsonString(jsonStr);
|
||||
|
||||
EXPECT_EQ(verInfo2.ToJsonString(), jsonStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: FromJson_001
|
||||
* @tc.desc: Verify the FromJson ToJson function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GHSCV
|
||||
*/
|
||||
HWTEST_F(VersionInfoTest, FromJson_001, TestSize.Level0)
|
||||
{
|
||||
VersionInfo verInfo;
|
||||
const char* DH_ID = "dh_id";
|
||||
const char* DEV_ID = "dev_id";
|
||||
const char* DEV_NAME = "dev_name";
|
||||
const char* DEV_TYPE = "dev_type";
|
||||
const char* DH_TYPE = "dh_type";
|
||||
const char* DH_ATTRS = "dh_attrs";
|
||||
|
||||
cJSON* json = cJSON_CreateObject();
|
||||
if (json == nullptr) {
|
||||
return;
|
||||
}
|
||||
cJSON_AddStringToObject(json, DH_ID, "dh_id");
|
||||
cJSON_AddStringToObject(json, DEV_ID, "dev_id");
|
||||
cJSON_AddStringToObject(json, DEV_NAME, "dev_name");
|
||||
cJSON_AddStringToObject(json, DEV_TYPE, "dev_type");
|
||||
cJSON_AddStringToObject(json, DH_TYPE, "dh_type");
|
||||
cJSON_AddStringToObject(json, DH_ATTRS, "dh_attrs");
|
||||
char* cjson = cJSON_PrintUnformatted(json);
|
||||
if (cjson == nullptr) {
|
||||
cJSON_Delete(json);
|
||||
return;
|
||||
}
|
||||
std::string jsonStr(cjson);
|
||||
cJSON_free(cjson);
|
||||
cJSON_Delete(json);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, verInfo.FromJsonString(jsonStr));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: FromJson_002
|
||||
* @tc.desc: Verify the FromJson ToJson function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GHSCV
|
||||
*/
|
||||
HWTEST_F(VersionInfoTest, FromJson_002, TestSize.Level0)
|
||||
{
|
||||
VersionInfo verInfo;
|
||||
const char* DH_ID = "dh_id";
|
||||
const char* DEV_ID = "dev_id";
|
||||
const char* DEV_NAME = "dev_name";
|
||||
const char* DEV_TYPE = "dev_type";
|
||||
const char* DH_TYPE = "dh_type";
|
||||
const char* DH_ATTRS = "dh_attrs";
|
||||
cJSON* json = cJSON_CreateObject();
|
||||
if (json == nullptr) {
|
||||
return;
|
||||
}
|
||||
cJSON_AddStringToObject(json, DH_ID, "dh_id");
|
||||
cJSON_AddStringToObject(json, DEV_ID, "dev_id");
|
||||
cJSON_AddStringToObject(json, DEV_NAME, "dev_name");
|
||||
cJSON_AddStringToObject(json, DEV_TYPE, "dev_type");
|
||||
cJSON_AddStringToObject(json, DH_TYPE, "dh_type");
|
||||
cJSON_AddStringToObject(json, DH_ATTRS, "dh_attrs");
|
||||
char* cjson = cJSON_PrintUnformatted(json);
|
||||
if (cjson == nullptr) {
|
||||
cJSON_Delete(json);
|
||||
return;
|
||||
}
|
||||
std::string jsonStr(cjson);
|
||||
cJSON_free(cjson);
|
||||
cJSON_Delete(json);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, verInfo.FromJsonString(jsonStr));
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
Loading…
Reference in New Issue
Block a user