From ee28d37571e5b014f0a6b180b90b6c46a945985f Mon Sep 17 00:00:00 2001 From: wuxiaodong02 Date: Mon, 30 Jan 2023 09:47:36 +0800 Subject: [PATCH 1/3] add ut Signed-off-by: wuxiaodong02 --- .../test/unittest/BUILD.gn | 1 + .../test/unittest/common/ipc/BUILD.gn | 60 +++++++++++++ .../include/publisher_listener_proxy_test.h | 87 +++++++++++++++++++ .../ipc/src/publisher_listener_proxy_test.cpp | 84 ++++++++++++++++++ 4 files changed, 232 insertions(+) create mode 100644 services/distributedhardwarefwkservice/test/unittest/common/ipc/BUILD.gn create mode 100644 services/distributedhardwarefwkservice/test/unittest/common/ipc/include/publisher_listener_proxy_test.h create mode 100644 services/distributedhardwarefwkservice/test/unittest/common/ipc/src/publisher_listener_proxy_test.cpp diff --git a/services/distributedhardwarefwkservice/test/unittest/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/BUILD.gn index a2466aeb..38fc2303 100644 --- a/services/distributedhardwarefwkservice/test/unittest/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/unittest/BUILD.gn @@ -25,6 +25,7 @@ group("test") { "common/distributedhardwarestub:distributed_hardware_stub_test", "common/hidumphelper/enabledcompsdump:enabled_comps_dump_test", "common/hidumphelper/hidumphelper:hidump_helper_test", + "common/ipc:publisher_listener_proxy_test", "common/localhardwaremanager/localhardwaremanager:local_hardware_manager_test", "common/localhardwaremanager/pluginlistenerimpl:plugin_listener_impl_test", "common/lowlatency/lowlatency:low_latency_test", diff --git a/services/distributedhardwarefwkservice/test/unittest/common/ipc/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/common/ipc/BUILD.gn new file mode 100644 index 00000000..adeb820d --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/ipc/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/publisher_listener_proxy_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/ipc", + ] +} + +ohos_unittest("PublisherListenerProxyTest") { + module_out_path = module_out_path + + sources = [ "src/publisher_listener_proxy_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=\"PublisherListenerProxyTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] +} + +group("publisher_listener_proxy_test") { + testonly = true + deps = [ ":PublisherListenerProxyTest" ] +} diff --git a/services/distributedhardwarefwkservice/test/unittest/common/ipc/include/publisher_listener_proxy_test.h b/services/distributedhardwarefwkservice/test/unittest/common/ipc/include/publisher_listener_proxy_test.h new file mode 100644 index 00000000..e7afb95c --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/ipc/include/publisher_listener_proxy_test.h @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_PUBLISHER_LISTENER_PROXY_TEST_H +#define OHOS_PUBLISHER_LISTENER_PROXY_TEST_H + +#include +#include +#include + +#define private public +#include "publisher_listener_proxy.h" +#undef private +#include "distributed_hardware_errno.h" + +namespace OHOS { +namespace DistributedHardware { +class PublisherListenerProxyTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + std::shared_ptr proxy_ = nullptr; +}; + +class MockIRemoteObject : public IRemoteObject { +public: +sptr AsObject() +{ + return nullptr; +} + +void OnMessage(const DHTopic topic, const std::string& message) +{ + (void)topic; + (void)message; +} + +int32_t GetObjectRefCount() +{ + return DH_FWK_SUCCESS; +} + +int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + (void)code; + (void)data; + (void)reply; + (void)option; + return DH_FWK_SUCCESS; +} + +bool AddDeathRecipient(const sptr &recipient) +{ + (void)recipient; + return true; +} + +bool RemoveDeathRecipient(const sptr &recipient) +{ + (void)recipient; + return true; +} + +int Dump(int fd, const std::vector &args) +{ + (void)fd; + (void)args; + return DH_FWK_SUCCESS; +} +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_PUBLISHER_LISTENER_PROXY_TEST_H \ No newline at end of file diff --git a/services/distributedhardwarefwkservice/test/unittest/common/ipc/src/publisher_listener_proxy_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/ipc/src/publisher_listener_proxy_test.cpp new file mode 100644 index 00000000..efda36b6 --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/ipc/src/publisher_listener_proxy_test.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "publisher_listener_proxy_test.h" + +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +void PublisherListenerProxyTest::SetUpTestCase() +{ +} + +void PublisherListenerProxyTest::TearDownTestCase() +{ +} + +void PublisherListenerProxyTest::SetUp() +{ + sptr object = nullptr; + proxy_ = std::make_shared(object); +} + +void PublisherListenerProxyTest::TearDown() +{ + proxy_ = nullptr; +} + +/** + * @tc.name: OnMessage_001 + * @tc.desc: Verify the OnMessage function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(PublisherListenerProxyTest, OnMessage_001, TestSize.Level0) +{ + uint32_t invalid = 7; + DHTopic topic = static_cast(invalid); + std::string message; + proxy_->OnMessage(topic, message); + EXPECT_EQ(true, message.empty()); +} + +/** + * @tc.name: OnMessage_002 + * @tc.desc: Verify the OnMessage function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(PublisherListenerProxyTest, OnMessage_002, TestSize.Level0) +{ + DHTopic topic = DHTopic::TOPIC_START_DSCREEN; + std::string message; + proxy_->OnMessage(topic, message); + EXPECT_EQ(true, message.empty()); +} + +/** + * @tc.name: OnMessage_003 + * @tc.desc: Verify the OnMessage function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(PublisherListenerProxyTest, OnMessage_003, TestSize.Level0) +{ + DHTopic topic = DHTopic::TOPIC_START_DSCREEN; + std::string message = "message"; + proxy_->OnMessage(topic, message); + EXPECT_EQ(false, message.empty()); +} +} // namespace DistributedHardware +} // namespace OHOS -- Gitee From 370a9b40c9b55495fdf8489426edf86e6762b0e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A6=E5=B0=8F=E4=B8=9C?= Date: Tue, 31 Jan 2023 07:29:41 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20serv?= =?UTF-8?q?ices/distributedhardwarefwkservice/test/unittest/common/ipc/BUI?= =?UTF-8?q?LD.gn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/unittest/common/ipc/BUILD.gn | 60 ------------------- 1 file changed, 60 deletions(-) delete mode 100644 services/distributedhardwarefwkservice/test/unittest/common/ipc/BUILD.gn diff --git a/services/distributedhardwarefwkservice/test/unittest/common/ipc/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/common/ipc/BUILD.gn deleted file mode 100644 index adeb820d..00000000 --- a/services/distributedhardwarefwkservice/test/unittest/common/ipc/BUILD.gn +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_hardware_fwk/distributedhardwarefwk.gni") - -module_out_path = "distributed_hardware_fwk/publisher_listener_proxy_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/ipc", - ] -} - -ohos_unittest("PublisherListenerProxyTest") { - module_out_path = module_out_path - - sources = [ "src/publisher_listener_proxy_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=\"PublisherListenerProxyTest\"", - "LOG_DOMAIN=0xD004100", - ] - - external_deps = [ - "c_utils:utils", - "ipc:ipc_core", - ] -} - -group("publisher_listener_proxy_test") { - testonly = true - deps = [ ":PublisherListenerProxyTest" ] -} -- Gitee From 948a5fb7fc57ada1e6f2d047cdb49695769c7973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A6=E5=B0=8F=E4=B8=9C?= Date: Tue, 31 Jan 2023 07:30:03 +0000 Subject: [PATCH 3/3] Modify BUILD.gn MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 武小东 --- .../test/unittest/common/ipc/BUILD.gn | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 services/distributedhardwarefwkservice/test/unittest/common/ipc/BUILD.gn diff --git a/services/distributedhardwarefwkservice/test/unittest/common/ipc/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/common/ipc/BUILD.gn new file mode 100644 index 00000000..ec62fd7c --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/ipc/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/publisher_listener_proxy_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/ipc", + ] +} + +ohos_unittest("PublisherListenerProxyTest") { + module_out_path = module_out_path + + sources = [ "src/publisher_listener_proxy_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=\"PublisherListenerProxyTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] +} + +group("publisher_listener_proxy_test") { + testonly = true + deps = [ ":PublisherListenerProxyTest" ] +} -- Gitee