!277 增加主干版本UT

Merge pull request !277 from 武小东/master
This commit is contained in:
openharmony_ci 2022-12-30 09:26:16 +00:00 committed by Gitee
commit e4482041c3
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
18 changed files with 701 additions and 110 deletions

View File

@ -29,9 +29,11 @@ group("test") {
"common/localhardwaremanager/pluginlistenerimpl:plugin_listener_impl_test",
"common/lowlatency/lowlatency:low_latency_test",
"common/lowlatency/lowlatencylistener:low_latency_listener_test",
"common/publisher:publisher_item_test",
"common/resourcemanager:resource_manager_test",
"common/task:dh_task_test",
"common/versioninfomanager:versioninfo_manager_test",
"common/versioninfomanager/versioninfo:version_info_test",
"common/versioninfomanager/versioninfomanager:versioninfo_manager_test",
"common/versionmanager:version_manager_test",
]
}

View File

@ -23,10 +23,10 @@
#define private public
#include "access_manager.h"
#include "distributed_hardware_manager_factory.h"
#undef private
#include "dm_device_info.h"
#include "distributed_hardware_errno.h"
#include "distributed_hardware_manager_factory.h"
using namespace testing::ext;
namespace OHOS {
@ -408,5 +408,53 @@ HWTEST_F(AccessManagerTest, UnRegisterDevStateCallback_001, TestSize.Level0)
{
EXPECT_EQ(DH_FWK_SUCCESS, AccessManager::GetInstance()->UnRegisterDevStateCallback());
}
/**
* @tc.name: SendOffLineEvent_004
* @tc.desc: Verify the SendOffLineEvent function
* @tc.type: FUNC
* @tc.require: AR000GHSJM
*/
HWTEST_F(AccessManagerTest, SendOffLineEvent_004, TestSize.Level0)
{
ASSERT_TRUE(DistributedHardwareManagerFactory::GetInstance().IsInit());
uint32_t maxIdLen = 257;
std::string networkId;
std::string networkId1;
networkId1.resize(maxIdLen);
std::string networkId2 = "networkId3";
std::string uuid;
std::string uuid1;
uuid1.resize(maxIdLen);
std::string uuid2 = "uuid3";
uint16_t deviceType = 1;
int32_t ret = DistributedHardwareManagerFactory::GetInstance().SendOffLineEvent(networkId, uuid, deviceType);
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
int32_t ret1 = DistributedHardwareManagerFactory::GetInstance().SendOffLineEvent(networkId1, uuid, deviceType);
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret1);
int32_t ret2 = DistributedHardwareManagerFactory::GetInstance().SendOffLineEvent(networkId2, uuid, deviceType);
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret2);
int32_t ret3 = DistributedHardwareManagerFactory::GetInstance().SendOffLineEvent(networkId2, uuid1, deviceType);
EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret3);
int32_t ret4 = DistributedHardwareManagerFactory::GetInstance().SendOffLineEvent(networkId2, uuid2, deviceType);
EXPECT_EQ(ERR_DH_FWK_HARDWARE_MANAGER_DEVICE_REPEAT_OFFLINE, ret4);
}
/**
* @tc.name: GetComponentVersion_001
* @tc.desc: Verify the GetComponentVersion function
* @tc.type: FUNC
* @tc.require: AR000GHSJM
*/
HWTEST_F(AccessManagerTest, GetComponentVersion_001, TestSize.Level0)
{
std::unordered_map<DHType, std::string> versionMap;
int32_t ret = DistributedHardwareManagerFactory::GetInstance().GetComponentVersion(versionMap);
EXPECT_EQ(DH_FWK_SUCCESS, ret);
}
} // namespace DistributedHardware
} // namespace OHOS

View File

@ -360,6 +360,27 @@ HWTEST_F(DbAdapterTest, SyncCompleted_001, TestSize.Level0)
HWTEST_F(DbAdapterTest, SyncCompleted_002, TestSize.Level0)
{
std::map<std::string, DistributedKv::Status> results;
uint32_t MAX_DB_RECORD_SIZE = 10002;
for (uint32_t i = 0; i < MAX_DB_RECORD_SIZE; ++i) {
results.insert(std::pair<std::string, DistributedKv::Status>(to_string(i), DistributedKv::Status::SUCCESS));
}
g_dbAdapterPtr->SyncCompleted(results);
EXPECT_EQ(true, g_dbAdapterPtr->manualSyncCountMap_.empty());
}
/**
* @tc.name: SyncCompleted_003
* @tc.desc: Verify the SyncCompleted function
* @tc.type: FUNC
* @tc.require: AR000GHSJM
*/
HWTEST_F(DbAdapterTest, SyncCompleted_003, TestSize.Level0)
{
std::map<std::string, DistributedKv::Status> results;
uint32_t MAX_DB_RECORD_SIZE = 500;
for (uint32_t i = 0; i < MAX_DB_RECORD_SIZE; ++i) {
results.insert(std::pair<std::string, DistributedKv::Status>(to_string(i), DistributedKv::Status::SUCCESS));
}
g_dbAdapterPtr->SyncCompleted(results);
EXPECT_EQ(true, g_dbAdapterPtr->manualSyncCountMap_.empty());
}
@ -501,5 +522,41 @@ HWTEST_F(DbAdapterTest, OnRemoteDied_001, TestSize.Level0)
g_dbAdapterPtr->OnRemoteDied();
EXPECT_EQ(true, g_dbAdapterPtr->manualSyncCountMap_.empty());
}
/**
* @tc.name: DeleteKvStore_001
* @tc.desc: Verify the DeleteKvStore function
* @tc.type: FUNC
* @tc.require: AR000GHSCV
*/
HWTEST_F(DbAdapterTest, DeleteKvStore_001, TestSize.Level0)
{
g_dbAdapterPtr->DeleteKvStore();
EXPECT_EQ(true, g_dbAdapterPtr->manualSyncCountMap_.empty());
}
/**
* @tc.name: ReInit_001
* @tc.desc: Verify the ReInit_001 function.
* @tc.type: FUNC
* @tc.require: AR000GHSCV
*/
HWTEST_F(DbAdapterTest, ReInit_001, TestSize.Level0)
{
g_dbAdapterPtr->GetKvStorePtr();
EXPECT_EQ(DH_FWK_SUCCESS, g_dbAdapterPtr->ReInit());
}
/**
* @tc.name: RemoveDeviceData_001
* @tc.desc: Verify the RemoveDeviceData function.
* @tc.type: FUNC
* @tc.require: AR000GHSJM
*/
HWTEST_F(DbAdapterTest, RemoveDeviceData_001, TestSize.Level0)
{
g_dbAdapterPtr->GetKvStorePtr();
EXPECT_EQ(ERR_DH_FWK_RESOURCE_KV_STORAGE_OPERATION_FAIL, g_dbAdapterPtr->RemoveDeviceData(TEST_DEV_ID_0));
}
} // namespace DistributedHardware
} // namespace OHOS

View File

@ -51,6 +51,21 @@ HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_001, TestSize.Level0)
EXPECT_NE(DH_FWK_SUCCESS, stubTest_->OnRemoteRequest(code, data, reply, option));
}
/**
* @tc.name: OnRemoteRequest_002
* @tc.desc: Verify the OnRemoteRequest function
* @tc.type: FUNC
* @tc.require: AR000GHSJM
*/
HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_002, TestSize.Level0)
{
uint32_t code = 0;
MessageParcel data;
MessageParcel reply;
MessageOption option;
EXPECT_EQ(ERR_INVALID_DATA, stubTest_->OnRemoteRequest(code, data, reply, option));
}
/**
* @tc.name: RegisterPublisherListenerInner_001
* @tc.desc: Verify the RegisterPublisherListenerInner function
@ -89,5 +104,23 @@ HWTEST_F(DistributedHardwareStubTest, PublishMessageInner_001, TestSize.Level0)
MessageParcel reply;
EXPECT_NE(DH_FWK_SUCCESS, stubTest_->PublishMessageInner(data, reply));
}
/**
* @tc.name: ValidTopic_001
* @tc.desc: Verify the ValidTopic function
* @tc.type: FUNC
* @tc.require: AR000GHSJM
*/
HWTEST_F(DistributedHardwareStubTest, ValidTopic_001, TestSize.Level0)
{
uint32_t topic = static_cast<uint32_t>(DHTopic::TOPIC_MIN);
EXPECT_EQ(false, stubTest_->ValidTopic(topic));
uint32_t topic1 = static_cast<uint32_t>(DHTopic::TOPIC_MAX);
EXPECT_EQ(false, stubTest_->ValidTopic(topic1));
uint32_t topic2 = static_cast<uint32_t>(DHTopic::TOPIC_START_DSCREEN);
EXPECT_EQ(true, stubTest_->ValidTopic(topic2));
}
} // namespace DistributedHardware
} // namespace OHOS

View File

@ -49,6 +49,21 @@ HWTEST_F(HidumpHelperTest, Dump_001, TestSize.Level0)
EXPECT_EQ(DH_FWK_SUCCESS, ret);
}
/**
* @tc.name: Dump_002
* @tc.desc: Verify the Dump function
* @tc.type: FUNC
* @tc.require: AR000GHSK0
*/
HWTEST_F(HidumpHelperTest, Dump_002, TestSize.Level0)
{
std::vector<std::string> args;
args.push_back("ARGS_HELP");
std::string result;
int32_t ret = HidumpHelper::GetInstance().Dump(args, result);
EXPECT_EQ(ERR_DH_FWK_HIDUMP_INVALID_ARGS, ret);
}
/**
* @tc.name: ProcessDump_001
* @tc.desc: Verify the ProcessDump function

View File

@ -14,6 +14,7 @@
*/
#include "low_latency_listener_test.h"
#include "nlohmann/json.hpp"
using namespace testing::ext;
@ -78,5 +79,26 @@ HWTEST_F(LowLatencyListenerTest, OnMessage_003, TestSize.Level0)
Listener_->OnMessage(topic, message);
EXPECT_EQ(nullptr, Listener_->AsObject());
}
/**
* @tc.name: OnMessage_004
* @tc.desc: Verify the OnMessage function
* @tc.type: FUNC
* @tc.require: AR000GHSJM
*/
HWTEST_F(LowLatencyListenerTest, OnMessage_004, TestSize.Level0)
{
DHTopic topic = DHTopic::TOPIC_START_DSCREEN;
nlohmann::json json;
const std::string DH_TYPE = "dh_type";
const std::string LOW_LATENCY_ENABLE = "low_latency_enable";
json[DH_TYPE] = "dh_type";
json[LOW_LATENCY_ENABLE] = "low_latency_enable";
std::string message = json.dump();
Listener_->OnMessage(topic, message);
EXPECT_EQ(nullptr, Listener_->AsObject());
}
} // namespace DistributedHardware
} // namespace OHOS

View File

@ -0,0 +1,51 @@
# Copyright (c) 2021-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.
import("//build/test.gni")
import(
"//foundation/distributedhardware/distributed_hardware_fwk/distributedhardwarefwk.gni")
module_out_path = "distributed_hardware_fwk/publisher_item_test"
config("module_private_config") {
visibility = [ ":*" ]
include_dirs = [
"include",
"${services_path}/distributedhardwarefwkservice/include/publisher",
"//foundation/distributedhardware/distributed_hardware_fwk/common/utils/include",
]
}
ohos_unittest("PublisherItemTest") {
module_out_path = module_out_path
sources = [ "src/publisher_item_test.cpp" ]
configs = [ ":module_private_config" ]
deps = [
"${services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr",
"//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk:system_ability_fwk",
"//third_party/googletest:gtest_main",
]
external_deps = [
"c_utils:utils",
"kv_store:distributeddata_inner",
]
}
group("publisher_item_test") {
testonly = true
deps = [ ":PublisherItemTest" ]
}

View File

@ -0,0 +1,51 @@
/*
* 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_PUBLISHER_ITEM_TEST_H
#define OHOS_PUBLISHER_ITEM_TEST_H
#include <gtest/gtest.h>
#include <iremote_broker.h>
#define private public
#include "publisher_item.h"
#undef private
namespace OHOS {
namespace DistributedHardware {
class PublisherItemTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
class MockIPublisherListener : public IPublisherListener {
public:
sptr<IRemoteObject> AsObject()
{
return nullptr;
}
void OnMessage(const DHTopic topic, const std::string& message)
{
(void)topic;
(void)message;
}
};
} // namespace DistributedHardware
} // namespace OHOS
#endif

View File

@ -0,0 +1,148 @@
/*
* 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.
*/
#include "publisher_item_test.h"
using namespace testing::ext;
using namespace std;
namespace OHOS {
namespace DistributedHardware {
void PublisherItemTest::SetUpTestCase(void) {}
void PublisherItemTest::TearDownTestCase(void) {}
void PublisherItemTest::SetUp() {}
void PublisherItemTest::TearDown() {}
/**
* @tc.name: AddListener_001
* @tc.desc: Verify the AddListener ToJson function.
* @tc.type: FUNC
* @tc.require: AR000GHSCV
*/
HWTEST_F(PublisherItemTest, AddListener_001, TestSize.Level0)
{
PublisherItem item;
sptr<IPublisherListener> listener = nullptr;
item.AddListener(listener);
EXPECT_EQ(true, item.listeners_.empty());
}
/**
* @tc.name: AddListener_002
* @tc.desc: Verify the AddListener ToJson function.
* @tc.type: FUNC
* @tc.require: AR000GHSCV
*/
HWTEST_F(PublisherItemTest, AddListener_002, TestSize.Level0)
{
PublisherItem item(DHTopic::TOPIC_MIN);
sptr<IPublisherListener> listener = nullptr;
item.AddListener(listener);
EXPECT_EQ(true, item.listeners_.empty());
}
/**
* @tc.name: AddListener_003
* @tc.desc: Verify the AddListener ToJson function.
* @tc.type: FUNC
* @tc.require: AR000GHSCV
*/
HWTEST_F(PublisherItemTest, AddListener_003, TestSize.Level0)
{
PublisherItem item(DHTopic::TOPIC_MIN);
sptr<IPublisherListener> listener = new MockIPublisherListener();
item.AddListener(listener);
EXPECT_EQ(false, item.listeners_.empty());
}
/**
* @tc.name: RemoveListener_001
* @tc.desc: Verify the RemoveListener ToJson function.
* @tc.type: FUNC
* @tc.require: AR000GHSCV
*/
HWTEST_F(PublisherItemTest, RemoveListener_001, TestSize.Level0)
{
PublisherItem item(DHTopic::TOPIC_MIN);
sptr<IPublisherListener> listener = nullptr;
item.RemoveListener(listener);
EXPECT_EQ(true, item.listeners_.empty());
}
/**
* @tc.name: RemoveListener_002
* @tc.desc: Verify the RemoveListener ToJson function.
* @tc.type: FUNC
* @tc.require: AR000GHSCV
*/
HWTEST_F(PublisherItemTest, RemoveListener_002, TestSize.Level0)
{
PublisherItem item(DHTopic::TOPIC_MIN);
sptr<IPublisherListener> listener = new MockIPublisherListener();
item.RemoveListener(listener);
EXPECT_EQ(true, item.listeners_.empty());
}
/**
* @tc.name: PublishMessage_001
* @tc.desc: Verify the PublishMessage ToJson function.
* @tc.type: FUNC
* @tc.require: AR000GHSCV
*/
HWTEST_F(PublisherItemTest, PublishMessage_001, TestSize.Level0)
{
PublisherItem item(DHTopic::TOPIC_MIN);
std::string message;
item.PublishMessage(message);
EXPECT_EQ(true, item.listeners_.empty());
}
/**
* @tc.name: PublishMessage_002
* @tc.desc: Verify the PublishMessage ToJson function.
* @tc.type: FUNC
* @tc.require: AR000GHSCV
*/
HWTEST_F(PublisherItemTest, PublishMessage_002, TestSize.Level0)
{
PublisherItem item(DHTopic::TOPIC_MIN);
std::string message;
uint32_t MAX_MESSAGE_LEN = 40 * 1024 * 1024 + 10;
message.resize(MAX_MESSAGE_LEN);
item.PublishMessage(message);
EXPECT_EQ(true, item.listeners_.empty());
}
/**
* @tc.name: PublishMessage_003
* @tc.desc: Verify the PublishMessage ToJson function.
* @tc.type: FUNC
* @tc.require: AR000GHSCV
*/
HWTEST_F(PublisherItemTest, PublishMessage_003, TestSize.Level0)
{
PublisherItem item(DHTopic::TOPIC_MIN);
std::string message = "message";
sptr<IPublisherListener> listener = new MockIPublisherListener();
item.listeners_.insert(listener);
item.PublishMessage(message);
EXPECT_EQ(false, item.listeners_.empty());
}
} // namespace DistributedHardware
} // namespace OHOS

View File

@ -52,7 +52,10 @@ ohos_unittest("ResourceManagerTest") {
"//third_party/googletest:gtest_main",
]
external_deps = [ "c_utils:utils" ]
external_deps = [
"c_utils:utils",
"kv_store:distributeddata_inner",
]
}
group("resource_manager_test") {

View File

@ -20,13 +20,15 @@
#include <sys/types.h>
#include <vector>
#include "capability_info.h"
#define private public
#include "capability_info.h"
#include "capability_info_manager.h"
#include "version_info_event.h"
#undef private
#include "dh_context.h"
#include "distributed_hardware_errno.h"
#include "distributed_hardware_log.h"
#include "nlohmann/json.hpp"
using namespace testing::ext;
using namespace std;
@ -467,6 +469,32 @@ HWTEST_F(ResourceManagerTest, resource_manager_test_020, TestSize.Level0)
EXPECT_EQ(false, ret);
}
/**
* @tc.name: OnChange_001
* @tc.desc: Verify the OnChange function
* @tc.type: FUNC
* @tc.require: AR000GHSJE
*/
HWTEST_F(ResourceManagerTest, OnChange_001, TestSize.Level0)
{
DistributedKv::Entry insert, update, del;
insert.key = "strBase";
update.key = "strBase";
del.key = "strBase";
insert.value = "strBase";
update.value = "strBase";
del.value = "strBase";
std::vector<DistributedKv::Entry> inserts, updates, deleteds;
inserts.push_back(insert);
updates.push_back(update);
deleteds.push_back(del);
DistributedKv::ChangeNotification changeIn(std::move(inserts), std::move(updates), std::move(deleteds), "", true);
CapabilityInfoManager::GetInstance()->OnChange(changeIn);
EXPECT_NE(nullptr, CapabilityInfoManager::GetInstance()->dbAdapterPtr_);
}
/**
* @tc.name: OnEvent_001
* @tc.desc: Verify the OnEvent function
@ -481,6 +509,21 @@ HWTEST_F(ResourceManagerTest, OnEvent_001, TestSize.Level0)
EXPECT_NE(nullptr, CapabilityInfoManager::GetInstance()->dbAdapterPtr_);
}
/**
* @tc.name: OnEvent_002
* @tc.desc: Verify the OnEvent function
* @tc.type: FUNC
* @tc.require: AR000GHSJM
*/
HWTEST_F(ResourceManagerTest, OnEvent_002, TestSize.Level0)
{
EventSender sender;
CapabilityInfoEvent ev(sender);
ev.action_ = CapabilityInfoEvent::EventType::RECOVER;
CapabilityInfoManager::GetInstance()->OnEvent(ev);
EXPECT_NE(nullptr, CapabilityInfoManager::GetInstance()->dbAdapterPtr_);
}
/**
* @tc.name: HandleCapabilityAddChange_001
* @tc.desc: Verify the HandleCapabilityAddChange function
@ -490,6 +533,10 @@ HWTEST_F(ResourceManagerTest, OnEvent_001, TestSize.Level0)
HWTEST_F(ResourceManagerTest, HandleCapabilityAddChange_001, TestSize.Level0)
{
std::vector<DistributedKv::Entry> insertRecords;
DistributedKv::Entry entry;
entry.key = "strBase";
entry.value = "strBase";
insertRecords.push_back(entry);
CapabilityInfoManager::GetInstance()->HandleCapabilityAddChange(insertRecords);
EXPECT_NE(nullptr, CapabilityInfoManager::GetInstance()->dbAdapterPtr_);
}
@ -503,6 +550,10 @@ HWTEST_F(ResourceManagerTest, HandleCapabilityAddChange_001, TestSize.Level0)
HWTEST_F(ResourceManagerTest, HandleCapabilityUpdateChange_001, TestSize.Level0)
{
std::vector<DistributedKv::Entry> updateRecords;
DistributedKv::Entry entry;
entry.key = "strBase";
entry.value = "strBase";
updateRecords.push_back(entry);
CapabilityInfoManager::GetInstance()->HandleCapabilityUpdateChange(updateRecords);
EXPECT_NE(nullptr, CapabilityInfoManager::GetInstance()->dbAdapterPtr_);
}
@ -710,6 +761,10 @@ HWTEST_F(ResourceManagerTest, RemoveCapabilityInfoInDB_002, TestSize.Level0)
HWTEST_F(ResourceManagerTest, HandleCapabilityDeleteChange_001, TestSize.Level0)
{
std::vector<DistributedKv::Entry> deleteRecords;
DistributedKv::Entry entry;
entry.key = "strBase";
entry.value = "strBase";
deleteRecords.push_back(entry);
CapabilityInfoManager::GetInstance()->HandleCapabilityDeleteChange(deleteRecords);
EXPECT_EQ(nullptr, CapabilityInfoManager::GetInstance()->dbAdapterPtr_);
}
@ -764,5 +819,38 @@ HWTEST_F(ResourceManagerTest, DumpCapabilityInfos_001, TestSize.Level0)
CapabilityInfoManager::GetInstance()->DumpCapabilityInfos(capInfos);
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;
CapabilityInfo info(dhId, devId, devName, devType, dhType, dhAttrs);
nlohmann::json jsonObject;
const std::string DH_ID = "dh_id";
const std::string DEV_ID = "dev_id";
const std::string DEV_NAME = "dev_name";
const std::string DEV_TYPE = "dev_type";
const std::string DH_TYPE = "dh_type";
const std::string DH_ATTRS = "dh_attrs";
jsonObject[DH_ID] = "dh_id";
jsonObject[DEV_ID] = "dev_id";
jsonObject[DEV_NAME] = "dev_name";
jsonObject[DEV_TYPE] = "dev_type";
jsonObject[DH_TYPE] = "dh_type";
jsonObject[DH_ATTRS] = "dh_attrs";
CapabilityInfo capability;
std::string jsonStr = jsonObject.dump();
EXPECT_EQ(DH_FWK_SUCCESS, info.FromJsonString(jsonStr));
}
} // namespace DistributedHardware
} // namespace OHOS

View File

@ -251,107 +251,5 @@ HWTEST_F(TaskTest, task_test_010, TestSize.Level0)
auto task = TaskFactory::GetInstance().CreateTask(TaskType::UNKNOWN, taskParam, nullptr);
ASSERT_EQ(nullptr, task);
}
/**
* @tc.name: DisableTask_001
* @tc.desc: Verify the DoTask function
* @tc.type: FUNC
* @tc.require: AR000GHSJE
*/
HWTEST_F(TaskTest, DisableTask_001, TestSize.Level0)
{
std::string networkId;
std::string uuid;
std::string dhId;
DHType dhType = DHType::CAMERA;
DisableTask task(networkId, uuid, dhId, dhType);
task.DoTask();
ASSERT_EQ(true, networkId.empty());
}
/**
* @tc.name: DisableTask_002
* @tc.desc: Verify the DoTaskInner function
* @tc.type: FUNC
* @tc.require: AR000GHSJE
*/
HWTEST_F(TaskTest, DisableTask_002, TestSize.Level0)
{
std::string networkId;
std::string uuid;
std::string dhId;
DHType dhType = DHType::CAMERA;
DisableTask task(networkId, uuid, dhId, dhType);
task.DoTaskInner();
ASSERT_EQ(true, networkId.empty());
}
/**
* @tc.name: DisableTask_003
* @tc.desc: Verify the DoTaskInner function
* @tc.type: FUNC
* @tc.require: AR000GHSJE
*/
HWTEST_F(TaskTest, DisableTask_003, TestSize.Level0)
{
std::string networkId;
std::string uuid;
std::string dhId;
DHType dhType = DHType::CAMERA;
DisableTask task(networkId, uuid, dhId, dhType);
int32_t ret = task.UnRegisterHardware();
ASSERT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
}
/**
* @tc.name: EnableTask_001
* @tc.desc: Verify the DoTask function
* @tc.type: FUNC
* @tc.require: AR000GHSJE
*/
HWTEST_F(TaskTest, EnableTask_001, TestSize.Level0)
{
std::string networkId;
std::string uuid;
std::string dhId;
DHType dhType = DHType::CAMERA;
EnableTask task(networkId, uuid, dhId, dhType);
task.DoTask();
ASSERT_EQ(true, networkId.empty());
}
/**
* @tc.name: EnableTask_002
* @tc.desc: Verify the DoTaskInner function
* @tc.type: FUNC
* @tc.require: AR000GHSJE
*/
HWTEST_F(TaskTest, EnableTask_002, TestSize.Level0)
{
std::string networkId;
std::string uuid;
std::string dhId;
DHType dhType = DHType::CAMERA;
EnableTask task(networkId, uuid, dhId, dhType);
task.DoTaskInner();
ASSERT_EQ(true, networkId.empty());
}
/**
* @tc.name: EnableTask_003
* @tc.desc: Verify the RegisterHardware function
* @tc.type: FUNC
* @tc.require: AR000GHSJE
*/
HWTEST_F(TaskTest, EnableTask_003, TestSize.Level0)
{
std::string networkId;
std::string uuid;
std::string dhId;
DHType dhType = DHType::CAMERA;
EnableTask task(networkId, uuid, dhId, dhType);
int32_t ret = task.RegisterHardware();
ASSERT_EQ(ERR_DH_FWK_PARA_INVALID, ret);
}
} // namespace DistributedHardware
} // namespace OHOS

View File

@ -0,0 +1,63 @@
# 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.
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",
"//base/notification/eventhandler/interfaces/inner_api",
"//commonlibrary/c_utils/base/include",
"//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/include",
"//third_party/json/include",
"//utils/system/safwk/native/include",
]
}
ohos_unittest("VersionInfoTest") {
module_out_path = module_out_path
sources = [ "src/version_info_test.cpp" ]
configs = [ ":module_private_config" ]
deps = [
"//foundation/distributedhardware/distributed_hardware_fwk/services/distributedhardwarefwkservice:distributedhardwarefwksvr",
"//foundation/distributedhardware/distributed_hardware_fwk/utils:distributedhardwareutils",
"//third_party/googletest:gtest_main",
]
external_deps = [
"c_utils:utils",
"kv_store:distributeddata_inner",
]
}
group("version_info_test") {
testonly = true
deps = [ ":VersionInfoTest" ]
}

View File

@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef OHOS_DISTRIBUTED_HARDWARE_VERSION_INFO_MANAGER_TEST_H
#define OHOS_DISTRIBUTED_HARDWARE_VERSION_INFO_MANAGER_TEST_H
#ifndef OHOS_DISTRIBUTED_HARDWARE_VERSION_INFO_TEST_H
#define OHOS_DISTRIBUTED_HARDWARE_VERSION_INFO_TEST_H
#include <gtest/gtest.h>
#include <vector>

View File

@ -86,5 +86,59 @@ HWTEST_F(VersionInfoTest, version_info_test_001, TestSize.Level0)
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 std::string DH_ID = "dh_id";
const std::string DEV_ID = "dev_id";
const std::string DEV_NAME = "dev_name";
const std::string DEV_TYPE = "dev_type";
const std::string DH_TYPE = "dh_type";
const std::string DH_ATTRS = "dh_attrs";
nlohmann::json jsonObject;
jsonObject[DH_ID] = "dh_id";
jsonObject[DEV_ID] = "dev_id";
jsonObject[DEV_NAME] = "dev_name";
jsonObject[DEV_TYPE] = "dev_type";
jsonObject[DH_TYPE] = "dh_type";
jsonObject[DH_ATTRS] = "dh_attrs";
CompVersion compVer;
std::string jsonStr = jsonObject.dump();
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 std::string DH_ID = "dh_id";
const std::string DEV_ID = "dev_id";
const std::string DEV_NAME = "dev_name";
const std::string DEV_TYPE = "dev_type";
const std::string DH_TYPE = "dh_type";
const std::string DH_ATTRS = "dh_attrs";
nlohmann::json jsonObject;
jsonObject[DH_ID] = "dh_id";
jsonObject[DEV_ID] = "dev_id";
jsonObject[DEV_NAME] = "dev_name";
jsonObject[DEV_TYPE] = "dev_type";
jsonObject[DH_TYPE] = "dh_type";
jsonObject[DH_ATTRS] = "dh_attrs";
VersionInfo versionInfo;
std::string jsonStr = jsonObject.dump();
EXPECT_EQ(DH_FWK_SUCCESS, verInfo.FromJsonString(jsonStr));
}
} // namespace DistributedHardware
} // namespace OHOS

View File

@ -44,7 +44,6 @@ ohos_unittest("VersioninfoManagerTest") {
sources = [
"src/version_info_manager_test.cpp",
"src/version_info_test.cpp",
]
configs = [ ":module_private_config" ]
@ -55,7 +54,10 @@ ohos_unittest("VersioninfoManagerTest") {
"//third_party/googletest:gtest_main",
]
external_deps = [ "c_utils:utils" ]
external_deps = [
"c_utils:utils",
"kv_store:distributeddata_inner",
]
}
group("versioninfo_manager_test") {

View File

@ -22,6 +22,7 @@
#define private public
#include "version_info_manager.h"
#include "version_manager.h"
#include "version_info_event.h"
#undef private
#include "dh_context.h"
#include "distributed_hardware_log.h"
@ -301,6 +302,22 @@ HWTEST_F(VersionInfoManagerTest, SyncRemoteVersionInfos_001, TestSize.Level0)
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
}
/**
* @tc.name: SyncRemoteVersionInfos_002
* @tc.desc: Verify the SyncRemoteVersionInfos function
* @tc.type: FUNC
* @tc.require: AR000GHSJM
*/
HWTEST_F(VersionInfoManagerTest, SyncRemoteVersionInfos_002, TestSize.Level0)
{
std::string appId;
std::string storeId;
std::shared_ptr<DistributedKv::KvStoreObserver> changeListener = nullptr;
VersionInfoManager::GetInstance()->dbAdapterPtr_ = std::make_shared<MockDBAdapter>(appId, storeId, changeListener);
int32_t ret = VersionInfoManager::GetInstance()->SyncRemoteVersionInfos();
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret);
}
/**
* @tc.name: CreateManualSyncCount_001
* @tc.desc: Verify the CreateManualSyncCount function
@ -360,6 +377,32 @@ HWTEST_F(VersionInfoManagerTest, ManualSync_002, TestSize.Level0)
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret);
}
/**
* @tc.name: OnChange_001
* @tc.desc: Verify the OnChange function
* @tc.type: FUNC
* @tc.require: AR000GHSJM
*/
HWTEST_F(VersionInfoManagerTest, OnChange_001, TestSize.Level0)
{
DistributedKv::Entry insert, update, del;
insert.key = "strBase";
update.key = "strBase";
del.key = "strBase";
insert.value = "strBase";
update.value = "strBase";
del.value = "strBase";
std::vector<DistributedKv::Entry> inserts, updates, deleteds;
inserts.push_back(insert);
updates.push_back(update);
deleteds.push_back(del);
DistributedKv::ChangeNotification changeIn(std::move(inserts), std::move(updates), std::move(deleteds), "", true);
VersionInfoManager::GetInstance()->OnChange(changeIn);
EXPECT_EQ(DH_FWK_SUCCESS, VersionInfoManager::GetInstance()->Init());
}
/**
* @tc.name: HandleVersionAddChange_001
* @tc.desc: Verify the HandleVersionAddChange function
@ -369,6 +412,10 @@ HWTEST_F(VersionInfoManagerTest, ManualSync_002, TestSize.Level0)
HWTEST_F(VersionInfoManagerTest, HandleVersionAddChange_001, TestSize.Level0)
{
std::vector<DistributedKv::Entry> insertRecords;
DistributedKv::Entry entry;
entry.key = "strBase";
entry.value = "strBase";
insertRecords.push_back(entry);
VersionInfoManager::GetInstance()->HandleVersionAddChange(insertRecords);
EXPECT_EQ(DH_FWK_SUCCESS, VersionInfoManager::GetInstance()->Init());
}
@ -382,6 +429,10 @@ HWTEST_F(VersionInfoManagerTest, HandleVersionAddChange_001, TestSize.Level0)
HWTEST_F(VersionInfoManagerTest, HandleVersionUpdateChange_001, TestSize.Level0)
{
std::vector<DistributedKv::Entry> updateRecords;
DistributedKv::Entry entry;
entry.key = "strBase";
entry.value = "strBase";
updateRecords.push_back(entry);
VersionInfoManager::GetInstance()->HandleVersionUpdateChange(updateRecords);
EXPECT_EQ(DH_FWK_SUCCESS, VersionInfoManager::GetInstance()->Init());
}
@ -395,6 +446,10 @@ HWTEST_F(VersionInfoManagerTest, HandleVersionUpdateChange_001, TestSize.Level0)
HWTEST_F(VersionInfoManagerTest, HandleVersionDeleteChange_001, TestSize.Level0)
{
std::vector<DistributedKv::Entry> deleteRecords;
DistributedKv::Entry entry;
entry.key = "strBase";
entry.value = "strBase";
deleteRecords.push_back(entry);
VersionInfoManager::GetInstance()->HandleVersionDeleteChange(deleteRecords);
EXPECT_EQ(DH_FWK_SUCCESS, VersionInfoManager::GetInstance()->Init());
}
@ -409,6 +464,7 @@ HWTEST_F(VersionInfoManagerTest, VersionInfoEvent_001, TestSize.Level0)
{
EventSender sender;
VersionInfoEvent ev(sender);
ev.action_ = VersionInfoEvent::EventType::RECOVER;
VersionInfoManager::GetInstance()->OnEvent(ev);
EXPECT_EQ(DH_FWK_SUCCESS, VersionInfoManager::GetInstance()->Init());
}