diff --git a/services/distributedhardwarefwkservice/test/unittest/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/BUILD.gn index e120f0d70a2c44eaa0fbae62472c1f82851017da..36eef053abd7da96c0c2d297cd793832e6b9c2f8 100644 --- a/services/distributedhardwarefwkservice/test/unittest/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/unittest/BUILD.gn @@ -22,8 +22,11 @@ group("test") { "common/dbadapter:db_adapter_test", "common/distributedhardwaremanager:distributed_hardware_manager_test", "common/distributedhardwareservice:distributed_hardware_service_test", + "common/distributedhardwarestub:distributed_hardware_stub_test", "common/hidumphelper:enabled_comps_dump_test", "common/localhardwaremanager:local_hardware_manager_test", + "common/lowlatency/lowlatency:low_latency_test", + "common/lowlatency/lowlatencylistener:low_latency_listener_test", "common/resourcemanager:resource_manager_test", "common/task:dh_task_test", "common/versioninfomanager:versioninfo_manager_test", diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentloader/src/component_loader_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/componentloader/src/component_loader_test.cpp index 2b10a7b6b0f401816e73bae73833e22e16d9ec44..cfd064ce6d39e1d9d620fb4a244c133043c85be2 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentloader/src/component_loader_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentloader/src/component_loader_test.cpp @@ -42,6 +42,7 @@ void ComponentLoaderTest::TearDown() { ComponentLoader::GetInstance().UnInit(); g_compHandlerMap.clear(); + ComponentLoader::GetInstance().compHandlerMap_.clear(); } /** @@ -81,6 +82,7 @@ HWTEST_F(ComponentLoaderTest, component_loader_test_002, TestSize.Level0) */ HWTEST_F(ComponentLoaderTest, component_loader_test_003, TestSize.Level0) { + ComponentLoader::GetInstance().compHandlerMap_.clear(); DHType dhType = DHType::AUDIO; IHardwareHandler *hardwareHandlerPtr = nullptr; auto ret = ComponentLoader::GetInstance().GetHardwareHandler(dhType, hardwareHandlerPtr); @@ -127,6 +129,7 @@ HWTEST_F(ComponentLoaderTest, component_loader_test_005, TestSize.Level0) */ HWTEST_F(ComponentLoaderTest, component_loader_test_006, TestSize.Level0) { + ComponentLoader::GetInstance().compHandlerMap_.clear(); DHType dhType = DHType::AUDIO; IDistributedHardwareSource *sourcePtr = nullptr; auto ret = ComponentLoader::GetInstance().GetSource(dhType, sourcePtr); @@ -173,6 +176,7 @@ HWTEST_F(ComponentLoaderTest, component_loader_test_008, TestSize.Level0) */ HWTEST_F(ComponentLoaderTest, component_loader_test_009, TestSize.Level0) { + ComponentLoader::GetInstance().compHandlerMap_.clear(); DHType dhType = DHType::AUDIO; IDistributedHardwareSink *sinkPtr = nullptr; auto ret = ComponentLoader::GetInstance().GetSink(dhType, sinkPtr); diff --git a/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..209b03494313e87d01d74baba2f422d3dedfa647 --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/BUILD.gn @@ -0,0 +1,67 @@ +# 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/distributed_hardware_stub_test" + +config("module_private_config") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "${utils_path}/include", + "${utils_path}/include/log", + "${utils_path}/include/eventbus", + "${common_path}/log/include", + "${common_path}/utils/include", + "${services_path}/distributedhardwarefwkservice/include", + "${services_path}/distributedhardwarefwkservice/include/task", + "${services_path}/distributedhardwarefwkservice/include/utils", + "//third_party/json/include", + "//commonlibrary/c_utils/base/include", + "//base/notification/eventhandler/interfaces/inner_api", + ] +} + +ohos_unittest("DistributedHardwareStubTest") { + module_out_path = module_out_path + + sources = [ "src/distributed_hardware_stub_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=\"DistributedHardwareStubTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + "safwk:system_ability_fwk", + ] +} + +group("distributed_hardware_stub_test") { + testonly = true + deps = [ ":DistributedHardwareStubTest" ] +} diff --git a/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/include/distributed_hardware_stub_test.h b/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/include/distributed_hardware_stub_test.h new file mode 100644 index 0000000000000000000000000000000000000000..6648f6ae0f0d586f96df222e896c686d1f4e6ef9 --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/include/distributed_hardware_stub_test.h @@ -0,0 +1,62 @@ +/* + * 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_STUB_TEST_H +#define OHOS_DISTRIBUTED_HARDWARE_STUB_TEST_H + +#include + +#include "distributed_hardware_errno.h" +#define private public +#include "distributed_hardware_stub.h" +#undef private + +namespace OHOS { +namespace DistributedHardware { +class DistributedHardwareStubTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + std::shared_ptr stubTest_ = nullptr; +}; + +class MockDistributedHardwareStub : public DistributedHardwareStub { +public: + int32_t RegisterPublisherListener(const DHTopic topic, const sptr &listener) + { + (void)topic; + (void)listener; + return DH_FWK_SUCCESS; + } + + int32_t UnregisterPublisherListener(const DHTopic topic, const sptr &listener) + { + (void)topic; + (void)listener; + return DH_FWK_SUCCESS; + } + + int32_t PublishMessage(const DHTopic topic, const std::string &msg) + { + (void)topic; + (void)msg; + return DH_FWK_SUCCESS; + } +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/src/distributed_hardware_stub_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/src/distributed_hardware_stub_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1649b28dccf42f01ac76256fd0c0f74b78a06b81 --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/src/distributed_hardware_stub_test.cpp @@ -0,0 +1,93 @@ +/* + * 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 "distributed_hardware_stub_test.h" + +#include + +#include "iremote_stub.h" +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +void DistributedHardwareStubTest::SetUpTestCase(void) {} + +void DistributedHardwareStubTest::TearDownTestCase(void) {} + +void DistributedHardwareStubTest::SetUp() +{ + stubTest_ = std::make_shared(); +} + +void DistributedHardwareStubTest::TearDown() +{ + stubTest_ = nullptr; +} + +/** + * @tc.name: OnRemoteRequest_001 + * @tc.desc: Verify the OnRemoteRequest function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_001, TestSize.Level0) +{ + uint32_t code = 0; + MessageParcel data; + MessageParcel reply; + MessageOption option; + EXPECT_NE(DH_FWK_SUCCESS, stubTest_->OnRemoteRequest(code, data, reply, option)); +} + +/** + * @tc.name: RegisterPublisherListenerInner_001 + * @tc.desc: Verify the RegisterPublisherListenerInner function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(DistributedHardwareStubTest, RegisterPublisherListenerInner_001, TestSize.Level0) +{ + MessageParcel data; + MessageParcel reply; + EXPECT_NE(DH_FWK_SUCCESS, stubTest_->RegisterPublisherListenerInner(data, reply)); +} + +/** + * @tc.name: UnregisterPublisherListenerInner_001 + * @tc.desc: Verify the UnregisterPublisherListenerInner function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(DistributedHardwareStubTest, UnregisterPublisherListenerInner_001, TestSize.Level0) +{ + MessageParcel data; + MessageParcel reply; + EXPECT_NE(DH_FWK_SUCCESS, stubTest_->UnregisterPublisherListenerInner(data, reply)); +} + +/** + * @tc.name: PublishMessageInner_001 + * @tc.desc: Verify the PublishMessageInner function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(DistributedHardwareStubTest, PublishMessageInner_001, TestSize.Level0) +{ + MessageParcel data; + MessageParcel reply; + EXPECT_NE(DH_FWK_SUCCESS, stubTest_->PublishMessageInner(data, reply)); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/src/local_hardware_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/src/local_hardware_manager_test.cpp index deccf44c60c46e87ce0a841ff4da4b8e7ab33673..b233c0f84de1229e3a386c387240c792f59e664d 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/src/local_hardware_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/src/local_hardware_manager_test.cpp @@ -18,6 +18,7 @@ #define private public #include "capability_info_manager.h" #include "component_loader.h" +#include "dh_context.h" #include "local_hardware_manager.h" #undef private @@ -60,5 +61,62 @@ HWTEST_F(LocalHardwareManagerTest, local_hardware_manager_test_002, TestSize.Lev { LocalHardwareManager::GetInstance().UnInit(); } + +/** + * @tc.name: Init_001 + * @tc.desc: Verify the Init function. + * @tc.type: FUNC + * @tc.require: AR000GHSK3 + */ +HWTEST_F(LocalHardwareManagerTest, Init_001, TestSize.Level0) +{ + ComponentLoader::GetInstance().UnInit(); + LocalHardwareManager::GetInstance().Init(); + EXPECT_EQ(true, LocalHardwareManager::GetInstance().pluginListenerMap_.empty()); +} + +/** + * @tc.name: CheckNonExistCapabilityInfo_001 + * @tc.desc: Verify the CheckNonExistCapabilityInfo function. + * @tc.type: FUNC + * @tc.require: AR000GHSK3 + */ +HWTEST_F(LocalHardwareManagerTest, CheckNonExistCapabilityInfo_001, TestSize.Level0) +{ + std::vector dhItems; + DHType dhType = DHType::INPUT; + LocalHardwareManager::GetInstance().CheckNonExistCapabilityInfo(dhItems, dhType); + EXPECT_EQ(true, LocalHardwareManager::GetInstance().pluginListenerMap_.empty()); +} + +/** + * @tc.name: GetLocalCapabilityMapByPrefix_001 + * @tc.desc: Verify the GetLocalCapabilityMapByPrefix function. + * @tc.type: FUNC + * @tc.require: AR000GHSK3 + */ +HWTEST_F(LocalHardwareManagerTest, GetLocalCapabilityMapByPrefix_001, TestSize.Level0) +{ + DHType dhType = DHType::INPUT; + CapabilityInfoMap capabilityInfoMap; + LocalHardwareManager::GetInstance().GetLocalCapabilityMapByPrefix(dhType, capabilityInfoMap); + EXPECT_EQ(true, LocalHardwareManager::GetInstance().pluginListenerMap_.empty()); +} + +/** + * @tc.name: GetLocalCapabilityMapByPrefix_002 + * @tc.desc: Verify the GetLocalCapabilityMapByPrefix function. + * @tc.type: FUNC + * @tc.require: AR000GHSK3 + */ +HWTEST_F(LocalHardwareManagerTest, GetLocalCapabilityMapByPrefix_002, TestSize.Level0) +{ + uint32_t invalid = 0x09; + DHType dhType = static_cast(invalid); + CapabilityInfoMap capabilityInfoMap; + DHContext::GetInstance().devInfo_.deviceId = "deviceId"; + LocalHardwareManager::GetInstance().GetLocalCapabilityMapByPrefix(dhType, capabilityInfoMap); + EXPECT_EQ(true, LocalHardwareManager::GetInstance().pluginListenerMap_.empty()); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/src/plugin_listener_impl_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/src/plugin_listener_impl_test.cpp index 4a26a0413af6bb2b44d18eca98b3ce792105262e..ac3bb1bc3fdbc37aa1662cdb36bd5d561b99da04 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/src/plugin_listener_impl_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/src/plugin_listener_impl_test.cpp @@ -65,5 +65,36 @@ HWTEST_F(PluginListenerImplTest, plugin_listener_impl_test_002, TestSize.Level0) EXPECT_EQ(g_mockHardwareHandler->UnPluginHardware(dhId), DH_FWK_SUCCESS); g_mockHardwareHandler->UnRegisterPluginListener(); } + +/** + * @tc.name: PluginHardware_001 + * @tc.desc: Verify the PluginHardware function. + * @tc.type: FUNC + * @tc.require: AR000GHSK3 + */ +HWTEST_F(PluginListenerImplTest, PluginHardware_001, TestSize.Level0) +{ + DHType type; + std::shared_ptr listener = std::make_shared(type); + std::string dhId; + std::string attrs; + listener->PluginHardware(dhId, attrs); + EXPECT_EQ(true, dhId.empty()); +} + +/** + * @tc.name: UnPluginHardware_001 + * @tc.desc: Verify the UnPluginHardware function. + * @tc.type: FUNC + * @tc.require: AR000GHSK3 + */ +HWTEST_F(PluginListenerImplTest, UnPluginHardware_001, TestSize.Level0) +{ + DHType type; + std::shared_ptr listener = std::make_shared(type); + std::string dhId; + listener->UnPluginHardware(dhId); + EXPECT_EQ(true, dhId.empty()); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d87a88dd9c6e163fd3c81de9d377341d4d33e25f --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/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/low_latency_test" + +config("module_private_config") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "//commonlibrary/c_utils/base/include", + "//utils/system/safwk/native/include", + "//third_party/json/include", + "${common_path}/utils/include", + "${services_path}/distributedhardwarefwkservice/include/lowlatency", + "${services_path}/distributedhardwarefwkservice/include/utils", + ] +} + +ohos_unittest("LowLatencyTest") { + module_out_path = module_out_path + + sources = [ "src/low_latency_test.cpp" ] + + configs = [ ":module_private_config" ] + + deps = [ + "${innerkits_path}:libdhfwk_sdk", + "${services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr", + "//third_party/googletest:gtest_main", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"LowLatencyTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] +} + +group("low_latency_test") { + testonly = true + deps = [ ":LowLatencyTest" ] +} diff --git a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/include/low_latency_test.h b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/include/low_latency_test.h new file mode 100644 index 0000000000000000000000000000000000000000..914222113ea742df6f3a51bee53f6e020e297187 --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/include/low_latency_test.h @@ -0,0 +1,39 @@ +/* + * 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_LOW_LATENCY_TEST_H +#define OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_TEST_H + +#include +#include +#include + +#define private public +#include "low_latency.h" +#undef private +#include "distributed_hardware_errno.h" + +namespace OHOS { +namespace DistributedHardware { +class LowLatencyTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_TEST_H \ No newline at end of file diff --git a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/src/low_latency_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/src/low_latency_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4eb918ee2a91f43378be227068cf7ffa0051d576 --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/src/low_latency_test.cpp @@ -0,0 +1,135 @@ +/* + * 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 "low_latency_test.h" + +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +void LowLatencyTest::SetUpTestCase() +{ +} + +void LowLatencyTest::TearDownTestCase() +{ +} + +void LowLatencyTest::SetUp() +{ +} + +void LowLatencyTest::TearDown() +{ + LowLatency::GetInstance().lowLatencySwitchSet_.clear(); +} + +/** + * @tc.name: EnableLowLatency_001 + * @tc.desc: Verify the EnableLowLatency function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(LowLatencyTest, EnableLowLatency_001, TestSize.Level0) +{ + DHType dhType = DHType::UNKNOWN; + LowLatency::GetInstance().EnableLowLatency(dhType); + EXPECT_EQ(true, LowLatency::GetInstance().lowLatencySwitchSet_.empty()); +} + +/** + * @tc.name: EnableLowLatency_002 + * @tc.desc: Verify the EnableLowLatency function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(LowLatencyTest, EnableLowLatency_002, TestSize.Level0) +{ + DHType dhType = DHType::CAMERA; + LowLatency::GetInstance().EnableLowLatency(dhType); + EXPECT_EQ(false, LowLatency::GetInstance().lowLatencySwitchSet_.empty()); +} + +/** + * @tc.name: EnableLowLatency_003 + * @tc.desc: Verify the EnableLowLatency function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(LowLatencyTest, EnableLowLatency_003, TestSize.Level0) +{ + LowLatency::GetInstance().lowLatencySwitchSet_.insert(DHType::AUDIO); + DHType dhType = DHType::CAMERA; + LowLatency::GetInstance().EnableLowLatency(dhType); + EXPECT_EQ(false, LowLatency::GetInstance().lowLatencySwitchSet_.empty()); +} + +/** + * @tc.name: EnableLowLatency_004 + * @tc.desc: Verify the EnableLowLatency function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(LowLatencyTest, EnableLowLatency_004, TestSize.Level0) +{ + uint32_t MAX_SWITCH_SIZE = 256; + for (uint32_t i = 0; i <= MAX_SWITCH_SIZE; ++i) { + LowLatency::GetInstance().lowLatencySwitchSet_.insert(static_cast(i)); + } + DHType dhType = DHType::CAMERA; + LowLatency::GetInstance().EnableLowLatency(dhType); + EXPECT_EQ(false, LowLatency::GetInstance().lowLatencySwitchSet_.empty()); +} + +/** + * @tc.name: DisableLowLatency_001 + * @tc.desc: Verify the DisableLowLatency function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(LowLatencyTest, DisableLowLatency_001, TestSize.Level0) +{ + DHType dhType = DHType::UNKNOWN; + LowLatency::GetInstance().DisableLowLatency(dhType); + EXPECT_EQ(true, LowLatency::GetInstance().lowLatencySwitchSet_.empty()); +} + +/** + * @tc.name: DisableLowLatency_002 + * @tc.desc: Verify the DisableLowLatency function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(LowLatencyTest, DisableLowLatency_002, TestSize.Level0) +{ + DHType dhType = DHType::CAMERA; + LowLatency::GetInstance().lowLatencySwitchSet_.insert(dhType); + LowLatency::GetInstance().DisableLowLatency(dhType); + EXPECT_EQ(true, LowLatency::GetInstance().lowLatencySwitchSet_.empty()); +} + +/** + * @tc.name: CloseLowLatency_001 + * @tc.desc: Verify the CloseLowLatency function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(LowLatencyTest, CloseLowLatency_001, TestSize.Level0) +{ + LowLatency::GetInstance().CloseLowLatency(); + EXPECT_EQ(true, LowLatency::GetInstance().lowLatencySwitchSet_.empty()); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a1dcc5587c1babc27595f679c0ba23ccabf50139 --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/BUILD.gn @@ -0,0 +1,60 @@ +# 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/low_latency_listener_test" + +config("module_private_config") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "//commonlibrary/c_utils/base/include", + "//utils/system/safwk/native/include", + "//third_party/json/include", + "${common_path}/utils/include", + "${services_path}/distributedhardwarefwkservice/include/lowlatency", + ] +} + +ohos_unittest("LowLatencyListenerTest") { + module_out_path = module_out_path + + sources = [ "src/low_latency_listener_test.cpp" ] + + configs = [ ":module_private_config" ] + + deps = [ + "${innerkits_path}:libdhfwk_sdk", + "${services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr", + "//third_party/googletest:gtest_main", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"LowLatencyListenerTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] +} + +group("low_latency_listener_test") { + testonly = true + deps = [ ":LowLatencyListenerTest" ] +} diff --git a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/include/low_latency_listener_test.h b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/include/low_latency_listener_test.h new file mode 100644 index 0000000000000000000000000000000000000000..eac7531e0a7d3f62bc263993b34154c7089ca6be --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/include/low_latency_listener_test.h @@ -0,0 +1,40 @@ +/* + * 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_LOW_LATENCY_LISTENER_TEST_H +#define OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_LISTENER_TEST_H + +#include +#include +#include + +#define private public +#include "low_latency_listener.h" +#undef private +#include "distributed_hardware_errno.h" + +namespace OHOS { +namespace DistributedHardware { +class LowLatencyListenerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + sptr Listener_ = nullptr; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_LISTENER_TEST_H \ No newline at end of file diff --git a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/src/low_latency_listener_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/src/low_latency_listener_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..526b57eb355e6cd8ca035f2669ef22d30fcf1e8a --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/src/low_latency_listener_test.cpp @@ -0,0 +1,82 @@ +/* + * 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 "low_latency_listener_test.h" + +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +void LowLatencyListenerTest::SetUpTestCase() +{ +} + +void LowLatencyListenerTest::TearDownTestCase() +{ +} + +void LowLatencyListenerTest::SetUp() +{ + Listener_ = new(std::nothrow) LowLatencyListener; +} + +void LowLatencyListenerTest::TearDown() +{ + Listener_ = nullptr; +} + +/** + * @tc.name: OnMessage_001 + * @tc.desc: Verify the OnMessage function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(LowLatencyListenerTest, OnMessage_001, TestSize.Level0) +{ + DHTopic topic = DHTopic::TOPIC_MIN; + std::string message; + Listener_->OnMessage(topic, message); + EXPECT_EQ(nullptr, Listener_->AsObject()); +} + +/** + * @tc.name: OnMessage_002 + * @tc.desc: Verify the OnMessage function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(LowLatencyListenerTest, OnMessage_002, TestSize.Level0) +{ + DHTopic topic = DHTopic::TOPIC_START_DSCREEN; + std::string message; + Listener_->OnMessage(topic, message); + EXPECT_EQ(nullptr, Listener_->AsObject()); +} + +/** + * @tc.name: OnMessage_003 + * @tc.desc: Verify the OnMessage function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(LowLatencyListenerTest, OnMessage_003, TestSize.Level0) +{ + DHTopic topic = DHTopic::TOPIC_START_DSCREEN; + std::string message = "message"; + Listener_->OnMessage(topic, message); + EXPECT_EQ(nullptr, Listener_->AsObject()); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/include/version_info_manager_test.h b/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/include/version_info_manager_test.h index b2c20ca5534f73e3b2c0a73183aab3239e513161..d7f74f64dca474d9ebfd799b79aa8b995f9b6f79 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/include/version_info_manager_test.h +++ b/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/include/version_info_manager_test.h @@ -19,6 +19,8 @@ #include #include +#include "db_adapter.h" +#include "distributed_hardware_errno.h" #include "version_info.h" namespace OHOS { @@ -30,6 +32,45 @@ public: void SetUp(); void TearDown(); }; + +class MockDBAdapter : public DBAdapter { +public: + MockDBAdapter(const std::string &appId, const std::string &storeId, + const std::shared_ptr &changeListener) + : DBAdapter(appId, storeId, changeListener) {} + + int32_t RemoveCapabilityInfoByKey(const std::string &key) + { + (void)key; + return DH_FWK_SUCCESS; + } + + int32_t GetDataByKey(const std::string &key, std::string &data) + { + (void)key; + (void)data; + return DH_FWK_SUCCESS; + } + + int32_t RemoveDataByKey(const std::string &key) + { + (void)key; + return DH_FWK_SUCCESS; + } + + int32_t GetDataByKeyPrefix(const std::string &keyPrefix, std::vector &values) + { + (void)keyPrefix; + (void)values; + return DH_FWK_SUCCESS; + } + + int32_t ManualSync(const std::string &networkId) + { + (void)networkId; + return DH_FWK_SUCCESS; + } +}; } // namespace DistributedHardware } // namespace OHOS #endif diff --git a/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/src/version_info_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/src/version_info_manager_test.cpp index b943b2f4057cf54a5b4cab87a3a9ec4a5eb3665a..75bce78366b46694f187b70f3b9af7ae5eb0ef81 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/src/version_info_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/src/version_info_manager_test.cpp @@ -24,7 +24,6 @@ #include "version_manager.h" #undef private #include "dh_context.h" -#include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" using namespace testing::ext; @@ -185,5 +184,232 @@ HWTEST_F(VersionInfoManagerTest, version_info_manager_test_005, TestSize.Level0) { EXPECT_EQ(VersionInfoManager::GetInstance()->UnInit(), DH_FWK_SUCCESS); } + +/** + * @tc.name: UpdateVersionCache_001 + * @tc.desc: Verify the UpdateVersionCache function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(VersionInfoManagerTest, UpdateVersionCache_001, TestSize.Level0) +{ + VersionInfo versionInfo; + versionInfo.deviceId = "deviceId"; + VersionInfoManager::GetInstance()->UpdateVersionCache(versionInfo); + EXPECT_EQ(DH_FWK_SUCCESS, VersionInfoManager::GetInstance()->Init()); +} + +/** + * @tc.name: UpdateVersionCache_002 + * @tc.desc: Verify the UpdateVersionCache function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(VersionInfoManagerTest, UpdateVersionCache_002, TestSize.Level0) +{ + VersionInfo versionInfo; + VersionInfoManager::GetInstance()->UpdateVersionCache(versionInfo); + EXPECT_EQ(DH_FWK_SUCCESS, VersionInfoManager::GetInstance()->Init()); +} + +/** + * @tc.name: RemoveVersionInfoByDeviceId_001 + * @tc.desc: Verify the RemoveVersionInfoByDeviceId function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(VersionInfoManagerTest, RemoveVersionInfoByDeviceId_001, TestSize.Level0) +{ + std::string deviceId; + VersionInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; + int32_t ret = VersionInfoManager::GetInstance()->RemoveVersionInfoByDeviceId(deviceId); + EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret); +} + +/** + * @tc.name: RemoveVersionInfoByDeviceId_002 + * @tc.desc: Verify the RemoveVersionInfoByDeviceId function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(VersionInfoManagerTest, RemoveVersionInfoByDeviceId_002, TestSize.Level0) +{ + std::string deviceId = "deviceId"; + std::string appId; + std::string storeId; + std::shared_ptr changeListener = nullptr; + VersionInfoManager::GetInstance()->dbAdapterPtr_ = std::make_shared(appId, storeId, changeListener); + int32_t ret = VersionInfoManager::GetInstance()->RemoveVersionInfoByDeviceId(deviceId); + EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret); +} + +/** + * @tc.name: SyncVersionInfoFromDB_001 + * @tc.desc: Verify the SyncVersionInfoFromDB function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(VersionInfoManagerTest, SyncVersionInfoFromDB_001, TestSize.Level0) +{ + std::string deviceId; + VersionInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; + int32_t ret = VersionInfoManager::GetInstance()->SyncVersionInfoFromDB(deviceId); + EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret); +} + +/** + * @tc.name: SyncVersionInfoFromDB_002 + * @tc.desc: Verify the SyncVersionInfoFromDB function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(VersionInfoManagerTest, SyncVersionInfoFromDB_002, TestSize.Level0) +{ + std::string deviceId = "deviceId"; + std::string appId; + std::string storeId; + std::shared_ptr changeListener = nullptr; + VersionInfoManager::GetInstance()->dbAdapterPtr_ = std::make_shared(appId, storeId, changeListener); + int32_t ret = VersionInfoManager::GetInstance()->SyncVersionInfoFromDB(deviceId); + EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret); +} + +/** + * @tc.name: SyncVersionInfoFromDB_003 + * @tc.desc: Verify the SyncVersionInfoFromDB function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(VersionInfoManagerTest, SyncVersionInfoFromDB_003, TestSize.Level0) +{ + std::string deviceId = "device"; + int32_t ret = VersionInfoManager::GetInstance()->SyncVersionInfoFromDB(deviceId); + EXPECT_NE(DH_FWK_SUCCESS, ret); +} + +/** + * @tc.name: SyncRemoteVersionInfos_001 + * @tc.desc: Verify the SyncRemoteVersionInfos function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(VersionInfoManagerTest, SyncRemoteVersionInfos_001, TestSize.Level0) +{ + VersionInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; + int32_t ret = VersionInfoManager::GetInstance()->SyncRemoteVersionInfos(); + EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret); +} + +/** + * @tc.name: CreateManualSyncCount_001 + * @tc.desc: Verify the CreateManualSyncCount function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(VersionInfoManagerTest, CreateManualSyncCount_001, TestSize.Level0) +{ + std::string deviceId; + VersionInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; + VersionInfoManager::GetInstance()->CreateManualSyncCount(deviceId); + EXPECT_EQ(nullptr, VersionInfoManager::GetInstance()->dbAdapterPtr_); +} + +/** + * @tc.name: RemoveManualSyncCount_001 + * @tc.desc: Verify the RemoveManualSyncCount function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(VersionInfoManagerTest, RemoveManualSyncCount_001, TestSize.Level0) +{ + std::string deviceId; + VersionInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; + VersionInfoManager::GetInstance()->RemoveManualSyncCount(deviceId); + EXPECT_EQ(nullptr, VersionInfoManager::GetInstance()->dbAdapterPtr_); +} + +/** + * @tc.name: ManualSync_001 + * @tc.desc: Verify the ManualSync function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(VersionInfoManagerTest, ManualSync_001, TestSize.Level0) +{ + std::string deviceId; + VersionInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; + int32_t ret = VersionInfoManager::GetInstance()->ManualSync(deviceId); + EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret); +} + +/** + * @tc.name: ManualSync_002 + * @tc.desc: Verify the ManualSync function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(VersionInfoManagerTest, ManualSync_002, TestSize.Level0) +{ + std::string appId; + std::string storeId; + std::shared_ptr changeListener = nullptr; + VersionInfoManager::GetInstance()->dbAdapterPtr_ = std::make_shared(appId, storeId, changeListener); + std::string deviceId; + int32_t ret = VersionInfoManager::GetInstance()->ManualSync(deviceId); + EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret); +} + +/** + * @tc.name: HandleVersionAddChange_001 + * @tc.desc: Verify the HandleVersionAddChange function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(VersionInfoManagerTest, HandleVersionAddChange_001, TestSize.Level0) +{ + std::vector insertRecords; + VersionInfoManager::GetInstance()->HandleVersionAddChange(insertRecords); + EXPECT_EQ(DH_FWK_SUCCESS, VersionInfoManager::GetInstance()->Init()); +} + +/** + * @tc.name: HandleVersionUpdateChange_001 + * @tc.desc: Verify the HandleVersionUpdateChange function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(VersionInfoManagerTest, HandleVersionUpdateChange_001, TestSize.Level0) +{ + std::vector updateRecords; + VersionInfoManager::GetInstance()->HandleVersionUpdateChange(updateRecords); + EXPECT_EQ(DH_FWK_SUCCESS, VersionInfoManager::GetInstance()->Init()); +} + +/** + * @tc.name: HandleVersionDeleteChange_001 + * @tc.desc: Verify the HandleVersionDeleteChange function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(VersionInfoManagerTest, HandleVersionDeleteChange_001, TestSize.Level0) +{ + std::vector deleteRecords; + VersionInfoManager::GetInstance()->HandleVersionDeleteChange(deleteRecords); + EXPECT_EQ(DH_FWK_SUCCESS, VersionInfoManager::GetInstance()->Init()); +} + +/** + * @tc.name: VersionInfoEvent_001 + * @tc.desc: Verify the VersionInfoEvent function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(VersionInfoManagerTest, VersionInfoEvent_001, TestSize.Level0) +{ + EventSender sender; + VersionInfoEvent ev(sender); + VersionInfoManager::GetInstance()->OnEvent(ev); + EXPECT_EQ(DH_FWK_SUCCESS, VersionInfoManager::GetInstance()->Init()); +} } // namespace DistributedHardware } // namespace OHOS