diff --git a/services/distributedhardwarefwkservice/test/unittest/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/BUILD.gn index a2466aebe5a516c061bbf233629fb7cfca4bd60e..38fc2303bc3286c8fc03a1f53afa446743c25541 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 0000000000000000000000000000000000000000..ec62fd7c3f4c1b38e1d48a1da5d90815daf99fea --- /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 0000000000000000000000000000000000000000..e7afb95c5ad902a51c74216cf89f37e5f44dac4e --- /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 0000000000000000000000000000000000000000..efda36b6a446f4fdc6b5e04cfac10232b4487abb --- /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