From d471824ed12302d9f7350807d92a7b68fd9e36bd Mon Sep 17 00:00:00 2001 From: wuxiaodong02 Date: Mon, 12 Dec 2022 19:30:37 +0800 Subject: [PATCH 1/9] add ut Signed-off-by: wuxiaodong02 --- .../test/unittest/BUILD.gn | 2 + .../common/lowlatency/lowlatency/BUILD.gn | 60 ++++++++ .../lowlatency/include/low_latency_text.h | 39 +++++ .../lowlatency/src/low_latency_text.cpp | 134 ++++++++++++++++++ .../lowlatency/lowlatencylistener/BUILD.gn | 60 ++++++++ .../include/low_latency_listener_text.h | 40 ++++++ .../src/low_latency_listener_text.cpp | 82 +++++++++++ 7 files changed, 417 insertions(+) create mode 100644 services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/BUILD.gn create mode 100644 services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/include/low_latency_text.h create mode 100644 services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/src/low_latency_text.cpp create mode 100644 services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/BUILD.gn create mode 100644 services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/include/low_latency_listener_text.h create mode 100644 services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/src/low_latency_listener_text.cpp diff --git a/services/distributedhardwarefwkservice/test/unittest/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/BUILD.gn index e120f0d7..74f8c2ac 100644 --- a/services/distributedhardwarefwkservice/test/unittest/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/unittest/BUILD.gn @@ -28,5 +28,7 @@ group("test") { "common/task:dh_task_test", "common/versioninfomanager:versioninfo_manager_test", "common/versionmanager:version_manager_test", + "common/lowlatency/lowlatency:low_latency_text", + "common/lowlatency/lowlatencylistener:low_latency_listener_text", ] } 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 00000000..dc054fae --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/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_text" + +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("LowLatencyText") { + module_out_path = module_out_path + + sources = [ "src/low_latency_text.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=\"LowLatencyText\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] +} + +group("low_latency_text") { + testonly = true + deps = [ ":LowLatencyText" ] +} diff --git a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/include/low_latency_text.h b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/include/low_latency_text.h new file mode 100644 index 00000000..28e5b70a --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/include/low_latency_text.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_TEXT_H +#define OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_TEXT_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_TEXT_H \ No newline at end of file diff --git a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/src/low_latency_text.cpp b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/src/low_latency_text.cpp new file mode 100644 index 00000000..dfe34c4c --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/src/low_latency_text.cpp @@ -0,0 +1,134 @@ +/* + * 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_text.h" + +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +void LowLatencyTest::SetUpTestCase() +{ +} + +void LowLatencyTest::TearDownTestCase() +{ +} + +void LowLatencyTest::SetUp() +{ +} + +void LowLatencyTest::TearDown() +{ +} + +/** + * @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(false, 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(false, 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 00000000..cf8a731a --- /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_text" + +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("LowLatencyListenerText") { + module_out_path = module_out_path + + sources = [ "src/low_latency_listener_text.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=\"LowLatencyListenerText\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] +} + +group("low_latency_listener_text") { + testonly = true + deps = [ ":LowLatencyListenerText" ] +} diff --git a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/include/low_latency_listener_text.h b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/include/low_latency_listener_text.h new file mode 100644 index 00000000..22173330 --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/include/low_latency_listener_text.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_TEXT_H +#define OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_LISTENER_TEXT_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_TEXT_H \ No newline at end of file diff --git a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/src/low_latency_listener_text.cpp b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/src/low_latency_listener_text.cpp new file mode 100644 index 00000000..42d81866 --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/src/low_latency_listener_text.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_text.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 -- Gitee From c2209dcca0019c7fda985555d9769362ea6367b6 Mon Sep 17 00:00:00 2001 From: wuxiaodong02 Date: Mon, 12 Dec 2022 19:44:10 +0800 Subject: [PATCH 2/9] add ut Signed-off-by: wuxiaodong02 --- services/distributedhardwarefwkservice/test/unittest/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/services/distributedhardwarefwkservice/test/unittest/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/BUILD.gn index 74f8c2ac..945afe3b 100644 --- a/services/distributedhardwarefwkservice/test/unittest/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/unittest/BUILD.gn @@ -28,6 +28,7 @@ group("test") { "common/task:dh_task_test", "common/versioninfomanager:versioninfo_manager_test", "common/versionmanager:version_manager_test", + "common/ipc:publisher_listener_proxy_text", "common/lowlatency/lowlatency:low_latency_text", "common/lowlatency/lowlatencylistener:low_latency_listener_text", ] -- Gitee From 93d701beb9223949d03771d50e4838cec90c5001 Mon Sep 17 00:00:00 2001 From: wuxiaodong02 Date: Mon, 12 Dec 2022 19:48:14 +0800 Subject: [PATCH 3/9] BUILD.gn Signed-off-by: wuxiaodong02 --- .../distributedhardwarefwkservice/test/unittest/BUILD.gn | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/services/distributedhardwarefwkservice/test/unittest/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/BUILD.gn index 945afe3b..f87b66b8 100644 --- a/services/distributedhardwarefwkservice/test/unittest/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/unittest/BUILD.gn @@ -24,12 +24,11 @@ group("test") { "common/distributedhardwareservice:distributed_hardware_service_test", "common/hidumphelper:enabled_comps_dump_test", "common/localhardwaremanager:local_hardware_manager_test", + "common/lowlatency/lowlatency:low_latency_text", + "common/lowlatency/lowlatencylistener:low_latency_listener_text", "common/resourcemanager:resource_manager_test", "common/task:dh_task_test", "common/versioninfomanager:versioninfo_manager_test", "common/versionmanager:version_manager_test", - "common/ipc:publisher_listener_proxy_text", - "common/lowlatency/lowlatency:low_latency_text", - "common/lowlatency/lowlatencylistener:low_latency_listener_text", ] } -- Gitee From c8b0de17e56b6986c352f9cbf1100c4300d8b0ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A6=E5=B0=8F=E4=B8=9C?= Date: Mon, 12 Dec 2022 12:36:51 +0000 Subject: [PATCH 4/9] update low_latency_text.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 武小东 --- .../common/lowlatency/lowlatency/src/low_latency_text.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/src/low_latency_text.cpp b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/src/low_latency_text.cpp index dfe34c4c..16259197 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/src/low_latency_text.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/src/low_latency_text.cpp @@ -84,7 +84,7 @@ HWTEST_F(LowLatencyTest, EnableLowLatency_003, TestSize.Level0) HWTEST_F(LowLatencyTest, EnableLowLatency_004, TestSize.Level0) { uint32_t MAX_SWITCH_SIZE = 256; - for(uint32_t i = 0; i <= MAX_SWITCH_SIZE; ++i) { + for (uint32_t i = 0; i <= MAX_SWITCH_SIZE; ++i) { LowLatency::GetInstance().lowLatencySwitchSet_.insert(static_cast(i)); } DHType dhType = DHType::CAMERA; -- Gitee From 6e4e95e4f43855ebe3fa61cca6d587bbc9f6eb1f Mon Sep 17 00:00:00 2001 From: wuxiaodong02 Date: Tue, 13 Dec 2022 09:57:02 +0800 Subject: [PATCH 5/9] add ut Signed-off-by: wuxiaodong02 --- .../common/lowlatency/lowlatency/src/low_latency_text.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/src/low_latency_text.cpp b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/src/low_latency_text.cpp index 16259197..d8cd9c7a 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/src/low_latency_text.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/src/low_latency_text.cpp @@ -33,6 +33,7 @@ void LowLatencyTest::SetUp() void LowLatencyTest::TearDown() { + LowLatency::GetInstance().lowLatencySwitchSet_.clear(); } /** @@ -102,7 +103,7 @@ HWTEST_F(LowLatencyTest, DisableLowLatency_001, TestSize.Level0) { DHType dhType = DHType::UNKNOWN; LowLatency::GetInstance().DisableLowLatency(dhType); - EXPECT_EQ(false, LowLatency::GetInstance().lowLatencySwitchSet_.empty()); + EXPECT_EQ(true, LowLatency::GetInstance().lowLatencySwitchSet_.empty()); } /** @@ -116,7 +117,7 @@ HWTEST_F(LowLatencyTest, DisableLowLatency_002, TestSize.Level0) DHType dhType = DHType::CAMERA; LowLatency::GetInstance().lowLatencySwitchSet_.insert(dhType); LowLatency::GetInstance().DisableLowLatency(dhType); - EXPECT_EQ(false, LowLatency::GetInstance().lowLatencySwitchSet_.empty()); + EXPECT_EQ(true, LowLatency::GetInstance().lowLatencySwitchSet_.empty()); } /** -- Gitee From 003eb12b47591abfa70b11f16f1ca2823142130c Mon Sep 17 00:00:00 2001 From: wuxiaodong02 Date: Tue, 13 Dec 2022 20:10:17 +0800 Subject: [PATCH 6/9] add ut Signed-off-by: wuxiaodong02 --- .../test/unittest/BUILD.gn | 5 +- .../src/component_loader_test.cpp | 1 + .../common/distributedhardwarestub/BUILD.gn | 67 +++++ .../include/distributed_hardware_stub_test.h | 62 +++++ .../src/distributed_hardware_stub_test.cpp | 93 +++++++ .../src/local_hardware_manager_test.cpp | 58 +++++ .../src/plugin_listener_impl_test.cpp | 31 +++ .../common/lowlatency/lowlatency/BUILD.gn | 12 +- ...{low_latency_text.h => low_latency_test.h} | 6 +- ..._latency_text.cpp => low_latency_test.cpp} | 2 +- .../lowlatency/lowlatencylistener/BUILD.gn | 12 +- ...ner_text.h => low_latency_listener_test.h} | 6 +- ...text.cpp => low_latency_listener_test.cpp} | 2 +- .../include/version_info_manager_test.h | 41 ++++ .../src/version_info_manager_test.cpp | 228 +++++++++++++++++- 15 files changed, 603 insertions(+), 23 deletions(-) create mode 100644 services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/BUILD.gn create mode 100644 services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/include/distributed_hardware_stub_test.h create mode 100644 services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/src/distributed_hardware_stub_test.cpp rename services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/include/{low_latency_text.h => low_latency_test.h} (86%) rename services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/src/{low_latency_text.cpp => low_latency_test.cpp} (99%) rename services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/include/{low_latency_listener_text.h => low_latency_listener_test.h} (85%) rename services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/src/{low_latency_listener_text.cpp => low_latency_listener_test.cpp} (98%) diff --git a/services/distributedhardwarefwkservice/test/unittest/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/BUILD.gn index f87b66b8..36eef053 100644 --- a/services/distributedhardwarefwkservice/test/unittest/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/unittest/BUILD.gn @@ -22,10 +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_text", - "common/lowlatency/lowlatencylistener:low_latency_listener_text", + "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 2b10a7b6..f6034668 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(); } /** 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 00000000..209b0349 --- /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 00000000..6648f6ae --- /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 00000000..1649b28d --- /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 deccf44c..b233c0f8 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 4a26a041..ac3bb1bc 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 index dc054fae..e0c91067 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/BUILD.gn @@ -15,7 +15,7 @@ import("//build/test.gni") import( "//foundation/distributedhardware/distributed_hardware_fwk/distributedhardwarefwk.gni") -module_out_path = "distributed_hardware_fwk/low_latency_text" +module_out_path = "distributed_hardware_fwk/low_latency_test" config("module_private_config") { visibility = [ ":*" ] @@ -29,10 +29,10 @@ config("module_private_config") { ] } -ohos_unittest("LowLatencyText") { +ohos_unittest("LowLatencyTest") { module_out_path = module_out_path - sources = [ "src/low_latency_text.cpp" ] + sources = [ "src/low_latency_test.cpp" ] configs = [ ":module_private_config" ] @@ -44,7 +44,7 @@ ohos_unittest("LowLatencyText") { defines = [ "HI_LOG_ENABLE", - "DH_LOG_TAG=\"LowLatencyText\"", + "DH_LOG_TAG=\"LowLatencyTest\"", "LOG_DOMAIN=0xD004100", ] @@ -54,7 +54,7 @@ ohos_unittest("LowLatencyText") { ] } -group("low_latency_text") { +group("low_latency_test") { testonly = true - deps = [ ":LowLatencyText" ] + deps = [ ":LowLatencyTest" ] } diff --git a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/include/low_latency_text.h b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/include/low_latency_test.h similarity index 86% rename from services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/include/low_latency_text.h rename to services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/include/low_latency_test.h index 28e5b70a..91422211 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/include/low_latency_text.h +++ b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/include/low_latency_test.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_TEXT_H -#define OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_TEXT_H +#ifndef OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_TEST_H +#define OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_TEST_H #include #include @@ -36,4 +36,4 @@ public: }; } // namespace DistributedHardware } // namespace OHOS -#endif // OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_TEXT_H \ No newline at end of file +#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_text.cpp b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/src/low_latency_test.cpp similarity index 99% rename from services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/src/low_latency_text.cpp rename to services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/src/low_latency_test.cpp index d8cd9c7a..4eb918ee 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/src/low_latency_text.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/src/low_latency_test.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "low_latency_text.h" +#include "low_latency_test.h" using namespace testing::ext; diff --git a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/BUILD.gn index cf8a731a..a1dcc558 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/BUILD.gn @@ -15,7 +15,7 @@ import("//build/test.gni") import( "//foundation/distributedhardware/distributed_hardware_fwk/distributedhardwarefwk.gni") -module_out_path = "distributed_hardware_fwk/low_latency_listener_text" +module_out_path = "distributed_hardware_fwk/low_latency_listener_test" config("module_private_config") { visibility = [ ":*" ] @@ -29,10 +29,10 @@ config("module_private_config") { ] } -ohos_unittest("LowLatencyListenerText") { +ohos_unittest("LowLatencyListenerTest") { module_out_path = module_out_path - sources = [ "src/low_latency_listener_text.cpp" ] + sources = [ "src/low_latency_listener_test.cpp" ] configs = [ ":module_private_config" ] @@ -44,7 +44,7 @@ ohos_unittest("LowLatencyListenerText") { defines = [ "HI_LOG_ENABLE", - "DH_LOG_TAG=\"LowLatencyListenerText\"", + "DH_LOG_TAG=\"LowLatencyListenerTest\"", "LOG_DOMAIN=0xD004100", ] @@ -54,7 +54,7 @@ ohos_unittest("LowLatencyListenerText") { ] } -group("low_latency_listener_text") { +group("low_latency_listener_test") { testonly = true - deps = [ ":LowLatencyListenerText" ] + deps = [ ":LowLatencyListenerTest" ] } diff --git a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/include/low_latency_listener_text.h b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/include/low_latency_listener_test.h similarity index 85% rename from services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/include/low_latency_listener_text.h rename to services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/include/low_latency_listener_test.h index 22173330..eac7531e 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/include/low_latency_listener_text.h +++ b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/include/low_latency_listener_test.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_LISTENER_TEXT_H -#define OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_LISTENER_TEXT_H +#ifndef OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_LISTENER_TEST_H +#define OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_LISTENER_TEST_H #include #include @@ -37,4 +37,4 @@ public: }; } // namespace DistributedHardware } // namespace OHOS -#endif // OHOS_DISTRIBUTED_HARDWARE_LOW_LATENCY_LISTENER_TEXT_H \ No newline at end of file +#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_text.cpp b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/src/low_latency_listener_test.cpp similarity index 98% rename from services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/src/low_latency_listener_text.cpp rename to services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/src/low_latency_listener_test.cpp index 42d81866..526b57eb 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/src/low_latency_listener_text.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/src/low_latency_listener_test.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "low_latency_listener_text.h" +#include "low_latency_listener_test.h" using namespace testing::ext; 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 b2c20ca5..d494a18d 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 b943b2f4..75bce783 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 -- Gitee From 4c2f2886b621af4aa56d39c1ae5d46a04d053601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A6=E5=B0=8F=E4=B8=9C?= Date: Tue, 13 Dec 2022 12:53:53 +0000 Subject: [PATCH 7/9] update version_info_manager_test.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 武小东 --- .../versioninfomanager/include/version_info_manager_test.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d494a18d..37251cb7 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 @@ -37,7 +37,7 @@ class MockDBAdapter : public DBAdapter { public: MockDBAdapter(const std::string &appId, const std::string &storeId, const std::shared_ptr &changeListener) : - DBAdapter(appId, storeId, changeListener) {} + DBAdapter(appId, storeId, changeListener) {} int32_t RemoveCapabilityInfoByKey(const std::string &key) { -- Gitee From 541a9d9ed2567f30df5d5a19e8cf2d0602342e71 Mon Sep 17 00:00:00 2001 From: wuxiaodong02 Date: Tue, 13 Dec 2022 22:05:05 +0800 Subject: [PATCH 8/9] add ut Signed-off-by: wuxiaodong02 --- .../common/componentloader/src/component_loader_test.cpp | 3 +++ .../versioninfomanager/include/version_info_manager_test.h | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) 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 f6034668..cfd064ce 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 @@ -82,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); @@ -128,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); @@ -174,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/versioninfomanager/include/version_info_manager_test.h b/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/include/version_info_manager_test.h index 37251cb7..d7f74f64 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 @@ -36,8 +36,8 @@ public: class MockDBAdapter : public DBAdapter { public: MockDBAdapter(const std::string &appId, const std::string &storeId, - const std::shared_ptr &changeListener) : - DBAdapter(appId, storeId, changeListener) {} + const std::shared_ptr &changeListener) + : DBAdapter(appId, storeId, changeListener) {} int32_t RemoveCapabilityInfoByKey(const std::string &key) { -- Gitee From 34e2f53cfa01a07ccc29df311ea3770f7cff7ffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A6=E5=B0=8F=E4=B8=9C?= Date: Wed, 14 Dec 2022 10:05:26 +0000 Subject: [PATCH 9/9] update lowlatency/BUILD.gn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 武小东 --- .../test/unittest/common/lowlatency/lowlatency/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/BUILD.gn index e0c91067..d87a88dd 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatency/BUILD.gn @@ -26,6 +26,7 @@ config("module_private_config") { "//third_party/json/include", "${common_path}/utils/include", "${services_path}/distributedhardwarefwkservice/include/lowlatency", + "${services_path}/distributedhardwarefwkservice/include/utils", ] } -- Gitee