From 586058b077117b7f8edd4e6288f16106a044428f Mon Sep 17 00:00:00 2001 From: wuxiaodong02 Date: Wed, 30 Nov 2022 20:27:29 +0800 Subject: [PATCH] fixed 6237b40 from https://gitee.com/wuxiaodong02/distributedhardware_distributed_hardware_fwk/pulls/253 add ut Signed-off-by: wuxiaodong02 --- .../src/distributed_hardware_fwk_kit_test.cpp | 69 +++++++- .../test/unittest/BUILD.gn | 4 +- .../accessmanager/access_manager_test.cpp | 150 ++++++++++++++++++ .../{ => component_manager}/BUILD.gn | 0 .../include/component_manager_test.h | 0 .../include/mock_idistributed_hardware_sink.h | 0 .../mock_idistributed_hardware_source.h | 0 .../src/component_manager_test.cpp | 0 .../component_monitior/BUILD.gn | 68 ++++++++ .../include/component_monitor_test.h | 38 +++++ .../src/component_monitor_test.cpp | 59 +++++++ .../unittest/common/hidumphelper/BUILD.gn | 61 +++++++ .../include/enabled_comps_dump_test.h | 32 ++++ .../src/enabled_comps_dump_test.cpp | 80 ++++++++++ 14 files changed, 556 insertions(+), 5 deletions(-) rename services/distributedhardwarefwkservice/test/unittest/common/componentmanager/{ => component_manager}/BUILD.gn (100%) rename services/distributedhardwarefwkservice/test/unittest/common/componentmanager/{ => component_manager}/include/component_manager_test.h (100%) rename services/distributedhardwarefwkservice/test/unittest/common/componentmanager/{ => component_manager}/include/mock_idistributed_hardware_sink.h (100%) rename services/distributedhardwarefwkservice/test/unittest/common/componentmanager/{ => component_manager}/include/mock_idistributed_hardware_source.h (100%) rename services/distributedhardwarefwkservice/test/unittest/common/componentmanager/{ => component_manager}/src/component_manager_test.cpp (100%) create mode 100644 services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_monitior/BUILD.gn create mode 100644 services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_monitior/include/component_monitor_test.h create mode 100644 services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_monitior/src/component_monitor_test.cpp create mode 100644 services/distributedhardwarefwkservice/test/unittest/common/hidumphelper/BUILD.gn create mode 100644 services/distributedhardwarefwkservice/test/unittest/common/hidumphelper/include/enabled_comps_dump_test.h create mode 100644 services/distributedhardwarefwkservice/test/unittest/common/hidumphelper/src/enabled_comps_dump_test.cpp diff --git a/interfaces/inner_kits/test/unittest/common/distributedhardwarefwkkit/src/distributed_hardware_fwk_kit_test.cpp b/interfaces/inner_kits/test/unittest/common/distributedhardwarefwkkit/src/distributed_hardware_fwk_kit_test.cpp index ba667792..ad5fba4a 100644 --- a/interfaces/inner_kits/test/unittest/common/distributedhardwarefwkkit/src/distributed_hardware_fwk_kit_test.cpp +++ b/interfaces/inner_kits/test/unittest/common/distributedhardwarefwkkit/src/distributed_hardware_fwk_kit_test.cpp @@ -20,12 +20,14 @@ #include #include +#include "distributed_hardware_errno.h" +#include "dhfwk_sa_manager.h" +#include "distributed_hardware_log.h" #include "iservice_registry.h" #include "system_ability_definition.h" - +#define private public #include "distributed_hardware_fwk_kit.h" -#include "distributed_hardware_log.h" -#include "distributed_hardware_errno.h" +#undef private using OHOS::DistributedHardware::DHTopic; @@ -73,7 +75,13 @@ uint32_t DistributedHardwareFwkKitTest::TestPublisherListener::GetTopicMsgCnt(co return msgCnts_[topic]; } -HWTEST_F(DistributedHardwareFwkKitTest, RegisterListener01, testing::ext::TestSize.Level0) +/** + * @tc.name: RegisterPublisherListener_001 + * @tc.desc: Verify the RegisterPublisherListener function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(DistributedHardwareFwkKitTest, RegisterPublisherListener_001, testing::ext::TestSize.Level0) { sptr listener1 = new TestPublisherListener(); int32_t ret = dhfwkPtr_->RegisterPublisherListener(DHTopic::TOPIC_START_DSCREEN, listener1); @@ -103,5 +111,58 @@ HWTEST_F(DistributedHardwareFwkKitTest, RegisterListener01, testing::ext::TestSi ret = dhfwkPtr_->UnregisterPublisherListener(DHTopic::TOPIC_DEV_OFFLINE, listener4); EXPECT_EQ(DH_FWK_SUCCESS, ret); } + +/** + * @tc.name: PublishMessage_001 + * @tc.desc: Verify the PublishMessage function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(DistributedHardwareFwkKitTest, PublishMessage_001, testing::ext::TestSize.Level0) +{ + uint32_t invalid = 7; + DHTopic topic = static_cast(invalid); + std::string message; + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, dhfwkPtr_->PublishMessage(topic, message)); +} + +/** + * @tc.name: PublishMessage_002 + * @tc.desc: Verify the PublishMessage function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(DistributedHardwareFwkKitTest, PublishMessage_002, testing::ext::TestSize.Level0) +{ + DHTopic topic = DHTopic::TOPIC_STOP_DSCREEN; + std::string message; + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, dhfwkPtr_->PublishMessage(topic, message)); +} + +/** + * @tc.name: PublishMessage_003 + * @tc.desc: Verify the PublishMessage function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(DistributedHardwareFwkKitTest, PublishMessage_003, testing::ext::TestSize.Level0) +{ + DHTopic topic = DHTopic::TOPIC_STOP_DSCREEN; + std::string message = "TOPIC_STOP_DSCREEN"; + EXPECT_EQ(ERR_DH_FWK_PUBLISH_MSG_FAILED, dhfwkPtr_->PublishMessage(topic, message)); +} + +/** + * @tc.name: OnDHFWKOnLine_001 + * @tc.desc: Verify the OnDHFWKOnLine function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(DistributedHardwareFwkKitTest, OnDHFWKOnLine_001, testing::ext::TestSize.Level0) +{ + bool isOnLine = true; + dhfwkPtr_->OnDHFWKOnLine(isOnLine); + EXPECT_EQ(nullptr, DHFWKSAManager::GetInstance().GetDHFWKProxy()); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/distributedhardwarefwkservice/test/unittest/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/BUILD.gn index eb44ec1b..e120f0d7 100644 --- a/services/distributedhardwarefwkservice/test/unittest/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/unittest/BUILD.gn @@ -17,10 +17,12 @@ group("test") { deps = [ "common/accessmanager:AccessManagerTest", "common/componentloader:component_loader_test", - "common/componentmanager:component_manager_test", + "common/componentmanager/component_manager:component_manager_test", + "common/componentmanager/component_monitior:component_monitor_test", "common/dbadapter:db_adapter_test", "common/distributedhardwaremanager:distributed_hardware_manager_test", "common/distributedhardwareservice:distributed_hardware_service_test", + "common/hidumphelper:enabled_comps_dump_test", "common/localhardwaremanager:local_hardware_manager_test", "common/resourcemanager:resource_manager_test", "common/task:dh_task_test", diff --git a/services/distributedhardwarefwkservice/test/unittest/common/accessmanager/access_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/accessmanager/access_manager_test.cpp index 299db1e3..e735cdf2 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/accessmanager/access_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/accessmanager/access_manager_test.cpp @@ -240,5 +240,155 @@ HWTEST_F(AccessManagerTest, AccessManagerInit, TestSize.Level0) { EXPECT_EQ(DH_FWK_SUCCESS, AccessManager::GetInstance()->Init()); } + +/** + * @tc.name: OnRemoteDied_001 + * @tc.desc: Verify the OnRemoteDied function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(AccessManagerTest, OnRemoteDied_001, TestSize.Level0) +{ + AccessManager::GetInstance()->OnRemoteDied(); + EXPECT_EQ(DH_FWK_SUCCESS, AccessManager::GetInstance()->Init()); +} + +/** + * @tc.name: OnDeviceOnline_001 + * @tc.desc: Verify the OnDeviceOnline function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(AccessManagerTest, OnDeviceOnline_001, TestSize.Level0) +{ + DmDeviceInfo deviceInfo; + AccessManager::GetInstance()->OnDeviceOnline(deviceInfo); + EXPECT_EQ(DH_FWK_SUCCESS, AccessManager::GetInstance()->Init()); +} + +/** + * @tc.name: OnDeviceOffline_001 + * @tc.desc: Verify the OnDeviceOffline function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(AccessManagerTest, OnDeviceOffline_001, TestSize.Level0) +{ + DmDeviceInfo deviceInfo; + AccessManager::GetInstance()->OnDeviceOffline(deviceInfo); + EXPECT_EQ(DH_FWK_SUCCESS, AccessManager::GetInstance()->Init()); +} + +/** + * @tc.name: OnDeviceOffline_002 + * @tc.desc: Verify the OnDeviceOffline function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(AccessManagerTest, OnDeviceOffline_002, TestSize.Level0) +{ + DmDeviceInfo deviceInfo; + std::string devId = "000001"; + EXPECT_EQ(EOK, memcpy_s(deviceInfo.deviceId, DM_MAX_DEVICE_ID_LEN, devId.c_str(), devId.length())); + AccessManager::GetInstance()->OnDeviceOffline(deviceInfo); + EXPECT_EQ(DH_FWK_SUCCESS, AccessManager::GetInstance()->Init()); +} + +/** + * @tc.name: OnDeviceOffline_003 + * @tc.desc: Verify the OnDeviceOffline function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(AccessManagerTest, OnDeviceOffline_003, TestSize.Level0) +{ + DmDeviceInfo deviceInfo; + std::string devId = "000001"; + EXPECT_EQ(EOK, memcpy_s(deviceInfo.deviceId, DM_MAX_DEVICE_ID_LEN, devId.c_str(), devId.length())); + std::string netId = "000002"; + EXPECT_EQ(EOK, memcpy_s(deviceInfo.networkId, DM_MAX_DEVICE_ID_LEN, netId.c_str(), netId.length())); + AccessManager::GetInstance()->OnDeviceOffline(deviceInfo); + EXPECT_EQ(DH_FWK_SUCCESS, AccessManager::GetInstance()->Init()); +} + +/** + * @tc.name: OnDeviceReady_001 + * @tc.desc: Verify the OnDeviceReady function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(AccessManagerTest, OnDeviceReady_001, TestSize.Level0) +{ + DmDeviceInfo deviceInfo; + AccessManager::GetInstance()->OnDeviceReady(deviceInfo); + EXPECT_EQ(DH_FWK_SUCCESS, AccessManager::GetInstance()->Init()); +} + +/** + * @tc.name: OnDeviceReady_002 + * @tc.desc: Verify the OnDeviceReady function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(AccessManagerTest, OnDeviceReady_002, TestSize.Level0) +{ + DmDeviceInfo deviceInfo; + std::string devId = "000001"; + EXPECT_EQ(EOK, memcpy_s(deviceInfo.deviceId, DM_MAX_DEVICE_ID_LEN, devId.c_str(), devId.length())); + AccessManager::GetInstance()->OnDeviceReady(deviceInfo); + EXPECT_EQ(DH_FWK_SUCCESS, AccessManager::GetInstance()->Init()); +} + +/** + * @tc.name: OnDeviceReady_003 + * @tc.desc: Verify the OnDeviceReady function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(AccessManagerTest, OnDeviceReady_003, TestSize.Level0) +{ + DmDeviceInfo deviceInfo; + std::string devId = "000001"; + EXPECT_EQ(EOK, memcpy_s(deviceInfo.deviceId, DM_MAX_DEVICE_ID_LEN, devId.c_str(), devId.length())); + std::string netId = "000002"; + EXPECT_EQ(EOK, memcpy_s(deviceInfo.networkId, DM_MAX_DEVICE_ID_LEN, netId.c_str(), netId.length())); + AccessManager::GetInstance()->OnDeviceReady(deviceInfo); + EXPECT_EQ(DH_FWK_SUCCESS, AccessManager::GetInstance()->Init()); +} + +/** + * @tc.name: OnDeviceChanged_001 + * @tc.desc: Verify the OnDeviceChanged function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(AccessManagerTest, OnDeviceChanged_001, TestSize.Level0) +{ + DmDeviceInfo deviceInfo; + AccessManager::GetInstance()->OnDeviceChanged(deviceInfo); + EXPECT_EQ(DH_FWK_SUCCESS, AccessManager::GetInstance()->Init()); +} + +/** + * @tc.name: UnInit_001 + * @tc.desc: Verify the UnInit function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(AccessManagerTest, UnInit_001, TestSize.Level0) +{ + EXPECT_EQ(DH_FWK_SUCCESS, AccessManager::GetInstance()->UnInit()); +} + +/** + * @tc.name: UnRegisterDevStateCallback_001 + * @tc.desc: Verify the UnRegisterDevStateCallback function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(AccessManagerTest, UnRegisterDevStateCallback_001, TestSize.Level0) +{ + EXPECT_EQ(DH_FWK_SUCCESS, AccessManager::GetInstance()->UnRegisterDevStateCallback()); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/BUILD.gn similarity index 100% rename from services/distributedhardwarefwkservice/test/unittest/common/componentmanager/BUILD.gn rename to services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/BUILD.gn diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/include/component_manager_test.h b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/component_manager_test.h similarity index 100% rename from services/distributedhardwarefwkservice/test/unittest/common/componentmanager/include/component_manager_test.h rename to services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/component_manager_test.h diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/include/mock_idistributed_hardware_sink.h b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/mock_idistributed_hardware_sink.h similarity index 100% rename from services/distributedhardwarefwkservice/test/unittest/common/componentmanager/include/mock_idistributed_hardware_sink.h rename to services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/mock_idistributed_hardware_sink.h diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/include/mock_idistributed_hardware_source.h b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/mock_idistributed_hardware_source.h similarity index 100% rename from services/distributedhardwarefwkservice/test/unittest/common/componentmanager/include/mock_idistributed_hardware_source.h rename to services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/mock_idistributed_hardware_source.h diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/src/component_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp similarity index 100% rename from services/distributedhardwarefwkservice/test/unittest/common/componentmanager/src/component_manager_test.cpp rename to services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_monitior/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_monitior/BUILD.gn new file mode 100644 index 00000000..488d0450 --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_monitior/BUILD.gn @@ -0,0 +1,68 @@ +# 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/component_monitor_test" + +config("module_private_config") { + visibility = [ ":*" ] + include_dirs = [ + "//base/notification/eventhandler/interfaces/inner_api", + "//commonlibrary/c_utils/base/include", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", + "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/include", + "//third_party/json/include", + "include", + "${utils_path}/include", + "${utils_path}/include/log", + "${utils_path}/include/eventbus", + "${services_path}/distributedhardwarefwkservice/include", + "${services_path}/distributedhardwarefwkservice/include/componentloader", + "${services_path}/distributedhardwarefwkservice/include/componentmanager", + "${services_path}/distributedhardwarefwkservice/include/lowlatency", + "${services_path}/distributedhardwarefwkservice/include/resourcemanager", + "${services_path}/distributedhardwarefwkservice/include/versionmanager", + "${services_path}/distributedhardwarefwkservice/include/utils", + "${common_path}/utils/include", + "${common_path}/log/include", + ] +} + +ohos_unittest("ComponentMonitorTest") { + module_out_path = module_out_path + + sources = [ "src/component_monitor_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:gmock_main", + "//third_party/googletest:gtest_main", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"ComponentMonitorTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +group("component_monitor_test") { + testonly = true + deps = [ ":ComponentMonitorTest" ] +} diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_monitior/include/component_monitor_test.h b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_monitior/include/component_monitor_test.h new file mode 100644 index 00000000..634e5a01 --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_monitior/include/component_monitor_test.h @@ -0,0 +1,38 @@ +/* + * 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_COMPONENT_MONITOR_TEST_H +#define OHOS_DISTRIBUTED_HARDWARE_COMPONENT_MONITOR_TEST_H + +#include "gtest/gtest.h" + +#define private public +#include "component_monitor.h" +#undef private + +namespace OHOS { +namespace DistributedHardware { +class ComponentMonitorTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + + std::shared_ptr compMonitorPtr_ = nullptr; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_monitior/src/component_monitor_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_monitior/src/component_monitor_test.cpp new file mode 100644 index 00000000..0a265574 --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_monitior/src/component_monitor_test.cpp @@ -0,0 +1,59 @@ +/* + * 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 "component_monitor_test.h" + +#include +#include +#include +#include +#include + +#include "component_loader.h" +#include "system_ability_status_change_stub.h" +#include "single_instance.h" + +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +void ComponentMonitorTest::SetUpTestCase(void) {} + +void ComponentMonitorTest::TearDownTestCase(void) {} + +void ComponentMonitorTest::SetUp() +{ + compMonitorPtr_ = std::make_shared(); +} + +void ComponentMonitorTest::TearDown() +{ + compMonitorPtr_ = nullptr; +} + +/** + * @tc.name: RemoveSAMonitor_001 + * @tc.desc: Verify the RemoveSAMonitor function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(ComponentMonitorTest, RemoveSAMonitor_001, TestSize.Level0) +{ + int32_t saId = static_cast(DHType::GPS); + compMonitorPtr_->RemoveSAMonitor(saId); + EXPECT_EQ(compMonitorPtr_->saListeners_.find(saId), compMonitorPtr_->saListeners_.end()); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/distributedhardwarefwkservice/test/unittest/common/hidumphelper/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/common/hidumphelper/BUILD.gn new file mode 100644 index 00000000..f47017a0 --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/hidumphelper/BUILD.gn @@ -0,0 +1,61 @@ +# 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/enabled_comps_dump_test" + +config("module_private_config") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "//base/notification/eventhandler/interfaces/inner_api", + "//third_party/json/include", + "//commonlibrary/c_utils/base/include", + "${common_path}/utils/include", + "${services_path}/distributedhardwarefwkservice/include/hidumphelper" + ] +} + +ohos_unittest("EnabledCompsDumpTest") { + module_out_path = module_out_path + + sources = [ "src/enabled_comps_dump_test.cpp" ] + + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributedhardware/distributed_hardware_fwk/services/distributedhardwarefwkservice:distributedhardwarefwksvr", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"EnabledCompsDumpTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + "safwk:system_ability_fwk", + ] +} + +group("enabled_comps_dump_test") { + testonly = true + deps = [ ":EnabledCompsDumpTest" ] +} diff --git a/services/distributedhardwarefwkservice/test/unittest/common/hidumphelper/include/enabled_comps_dump_test.h b/services/distributedhardwarefwkservice/test/unittest/common/hidumphelper/include/enabled_comps_dump_test.h new file mode 100644 index 00000000..db52150a --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/hidumphelper/include/enabled_comps_dump_test.h @@ -0,0 +1,32 @@ +/* + * 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_ENABLED_COMPS_DUMP_TEST_H +#define OHOS_DISTRIBUTED_ENABLED_COMPS_DUMP_TEST_H + +#include + +namespace OHOS { +namespace DistributedHardware { +class EnabledCompsDumpTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/services/distributedhardwarefwkservice/test/unittest/common/hidumphelper/src/enabled_comps_dump_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/hidumphelper/src/enabled_comps_dump_test.cpp new file mode 100644 index 00000000..f09f933a --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/hidumphelper/src/enabled_comps_dump_test.cpp @@ -0,0 +1,80 @@ +/* + * 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 "enabled_comps_dump_test.h" + +#include +#include +#include + +#define private public +#include "enabled_comps_dump.h" +#undef private + +using namespace testing::ext; +namespace OHOS { +namespace DistributedHardware { +void EnabledCompsDumpTest::SetUpTestCase(void) {} + +void EnabledCompsDumpTest::TearDownTestCase(void) {} + +void EnabledCompsDumpTest::SetUp() {} + +void EnabledCompsDumpTest::TearDown() {} + +/** + * @tc.name: DumpEnabledComp_001 + * @tc.desc: Verify the DumpEnabledComp function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(EnabledCompsDumpTest, DumpEnabledComp_001, TestSize.Level0) +{ + std::string networkId; + DHType dhType = DHType::CAMERA; + std::string dhId; + EnabledCompsDump::GetInstance().DumpEnabledComp(networkId, dhType, dhId); + EXPECT_EQ(false, EnabledCompsDump::GetInstance().compInfoSet_.empty()); +} + +/** + * @tc.name: DumpDisabledComp_001 + * @tc.desc: Verify the DumpDisabledComp function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(EnabledCompsDumpTest, DumpDisabledComp_001, TestSize.Level0) +{ + std::string networkId; + DHType dhType = DHType::CAMERA; + std::string dhId; + EnabledCompsDump::GetInstance().DumpEnabledComp(networkId, dhType, dhId); + EXPECT_EQ(false, EnabledCompsDump::GetInstance().compInfoSet_.empty()); +} + +/** + * @tc.name: Dump_001 + * @tc.desc: Verify the Dump function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(EnabledCompsDumpTest, Dump_001, TestSize.Level0) +{ + std::set compInfoSet; + EnabledCompsDump::GetInstance().Dump(compInfoSet); + EXPECT_EQ(false, EnabledCompsDump::GetInstance().compInfoSet_.empty()); +} +} // namespace DistributedHardware +} // namespace OHOS -- Gitee