diff --git a/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp b/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp index 68135245616bb038084456ace1c3c153433e4f12..8c49e1bb06dc91808082b79cf77fe1a8bf81a30d 100644 --- a/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp +++ b/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -49,7 +49,7 @@ int32_t DistributedHardwareProxy::RegisterPublisherListener(const DHTopic topic, DHLOGE("remote service is null"); return ERR_DH_FWK_SERVICE_REMOTE_IS_NULL; } - if (topic < DHTopic::TOPIC_MIN || topic > DHTopic::TOPIC_MAX) { + if (topic <= DHTopic::TOPIC_MIN || topic >= DHTopic::TOPIC_MAX) { DHLOGE("Topic is invalid!"); return ERR_DH_FWK_PARA_INVALID; } @@ -98,7 +98,7 @@ int32_t DistributedHardwareProxy::UnregisterPublisherListener(const DHTopic topi DHLOGE("remote service is null"); return ERR_DH_FWK_SERVICE_REMOTE_IS_NULL; } - if (topic < DHTopic::TOPIC_MIN || topic > DHTopic::TOPIC_MAX) { + if (topic <= DHTopic::TOPIC_MIN || topic >= DHTopic::TOPIC_MAX) { DHLOGE("Topic is invalid!"); return ERR_DH_FWK_PARA_INVALID; } @@ -141,7 +141,7 @@ int32_t DistributedHardwareProxy::PublishMessage(const DHTopic topic, const std: DHLOGE("remote service is null"); return ERR_DH_FWK_SERVICE_REMOTE_IS_NULL; } - if (topic < DHTopic::TOPIC_MIN || topic > DHTopic::TOPIC_MAX) { + if (topic <= DHTopic::TOPIC_MIN || topic >= DHTopic::TOPIC_MAX) { DHLOGE("Topic is invalid!"); return ERR_DH_FWK_PARA_INVALID; } @@ -187,7 +187,7 @@ std::string DistributedHardwareProxy::QueryLocalSysSpec(QueryLocalSysSpecType sp DHLOGE("remote service is null"); return ""; } - if (spec < QueryLocalSysSpecType::MIN || spec > QueryLocalSysSpecType::MAX) { + if (spec <= QueryLocalSysSpecType::MIN || spec >= QueryLocalSysSpecType::MAX) { DHLOGE("Sys spec type is invalid!"); return ""; } diff --git a/interfaces/inner_kits/src/ipc/publisher_listener_stub.cpp b/interfaces/inner_kits/src/ipc/publisher_listener_stub.cpp index db73fa8a6c3876d5174ca8f9d6f848910ab53e3d..e56e56f77ca41dee9da8b8191f2876343866cb73 100644 --- a/interfaces/inner_kits/src/ipc/publisher_listener_stub.cpp +++ b/interfaces/inner_kits/src/ipc/publisher_listener_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -40,7 +40,7 @@ int32_t PublisherListenerStub::OnRemoteRequest( switch (msgCode) { case IPublisherListener::Message::ON_MESSAGE: { DHTopic topic = static_cast(data.ReadUint32()); - if (topic < DHTopic::TOPIC_MIN || topic > DHTopic::TOPIC_MAX) { + if (topic <= DHTopic::TOPIC_MIN || topic >= DHTopic::TOPIC_MAX) { DHLOGE("Topic is invalid!"); return ERR_INVALID_DATA; } diff --git a/interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/BUILD.gn b/interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/BUILD.gn index 54a5f8089e5e5fde13d731fc3b72c199be9a283f..df8fb411e22707c67bbad444d9d05790e8ecb860 100644 --- a/interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/BUILD.gn +++ b/interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024 Huawei Device Co., Ltd. +# Copyright (c) 2022-2025 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 @@ -28,13 +28,19 @@ config("module_private_config") { "${common_path}/log/include", "${innerkits_path}/include", "${innerkits_path}/include/ipc", + "${services_path}/distributedhardwarefwkservice/include", + "${services_path}/distributedhardwarefwkservice/include/utils", + "${services_path}/distributedhardwarefwkservice/include/ipc", ] } ohos_unittest("DistributedHardwareProxyTest") { module_out_path = module_out_path - sources = [ "src/distributed_hardware_proxy_test.cpp" ] + sources = [ + "${services_path}/distributedhardwarefwkservice/src/distributed_hardware_stub.cpp", + "src/distributed_hardware_proxy_test.cpp", + ] configs = [ ":module_private_config" ] @@ -51,11 +57,15 @@ ohos_unittest("DistributedHardwareProxyTest") { ] external_deps = [ + "ability_base:want", + "ability_runtime:ability_manager", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", "cJSON:cjson", "c_utils:utils", + "device_manager:devicemanagersdk", + "hilog:libhilog", "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", ] cflags = [ diff --git a/interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/include/distributed_hardware_proxy_test.h b/interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/include/distributed_hardware_proxy_test.h index a1f75ea9949d63eadf5833e957721e2f260f1a25..3be4ea15212bb8b207c51f0b29575b70803229fe 100644 --- a/interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/include/distributed_hardware_proxy_test.h +++ b/interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/include/distributed_hardware_proxy_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -24,6 +24,7 @@ #include "distributed_hardware_errno.h" #include "idistributed_hardware.h" #include "distributed_hardware_proxy.h" +#include "distributed_hardware_stub.h" namespace OHOS { namespace DistributedHardware { @@ -34,97 +35,26 @@ public: virtual void SetUp(); virtual void TearDown(); - std::shared_ptr hardwareProxy_ = nullptr; -}; - -class MockIDistributedHardware : public IDistributedHardware { -public: - sptr AsObject() - { - return nullptr; - } - - 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; - } - - std::string QueryLocalSysSpec(QueryLocalSysSpecType spec) - { - (void)spec; - return 0; - } - - int32_t InitializeAVCenter(const TransRole &transRole, int32_t &engineId) - { - (void)transRole; - (void)engineId; - return DH_FWK_SUCCESS; - } - - int32_t ReleaseAVCenter(int32_t engineId) - { - (void)engineId; - return DH_FWK_SUCCESS; - } - - int32_t CreateControlChannel(int32_t engineId, const std::string &peerDevId) - { - (void)engineId; - (void)peerDevId; - return DH_FWK_SUCCESS; - } - - int32_t NotifyAVCenter(int32_t engineId, const AVTransEvent &event) - { - (void)engineId; - (void)event; - return DH_FWK_SUCCESS; - } - - int32_t RegisterCtlCenterCallback(int32_t engineId, const sptr callback) - { - (void)engineId; - (void)callback; - return DH_FWK_SUCCESS; - } - - int32_t PauseDistributedHardware(DHType dhType, const std::string &networkId) - { - (void)dhType; - (void)networkId; - return DH_FWK_SUCCESS; - } - - int32_t ResumeDistributedHardware(DHType dhType, const std::string &networkId) - { - (void)dhType; - (void)networkId; - return DH_FWK_SUCCESS; - } - - int32_t StopDistributedHardware(DHType dhType, const std::string &networkId) - { - (void)dhType; - (void)networkId; - return DH_FWK_SUCCESS; - } + class TestDistributedHardwareStub : public + OHOS::DistributedHardware::DistributedHardwareStub { + public: + TestDistributedHardwareStub() = default; + virtual ~TestDistributedHardwareStub() = default; + int32_t RegisterPublisherListener(const DHTopic topic, const sptr listener); + int32_t UnregisterPublisherListener(const DHTopic topic, const sptr listener); + int32_t PublishMessage(const DHTopic topic, const std::string &msg); + std::string QueryLocalSysSpec(QueryLocalSysSpecType spec); + + int32_t InitializeAVCenter(const TransRole &transRole, int32_t &engineId); + int32_t ReleaseAVCenter(int32_t engineId); + int32_t CreateControlChannel(int32_t engineId, const std::string &peerDevId); + int32_t NotifyAVCenter(int32_t engineId, const AVTransEvent &event); + int32_t RegisterCtlCenterCallback(int32_t engineId, const sptr callback); + int32_t NotifySourceRemoteSinkStarted(std::string &deviceId); + int32_t PauseDistributedHardware(DHType dhType, const std::string &networkId); + int32_t ResumeDistributedHardware(DHType dhType, const std::string &networkId); + int32_t StopDistributedHardware(DHType dhType, const std::string &networkId); + }; }; class MockIPublisherListener : public IPublisherListener { diff --git a/interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/src/distributed_hardware_proxy_test.cpp b/interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/src/distributed_hardware_proxy_test.cpp index 46f97dc6fa83530d49e4d559aeaa98bd143cf9a1..04d47c924dab4d97227a72d408ebbcb627765b43 100644 --- a/interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/src/distributed_hardware_proxy_test.cpp +++ b/interfaces/inner_kits/test/unittest/common/ipc/distributed_hardware_proxy/src/distributed_hardware_proxy_test.cpp @@ -27,15 +27,106 @@ void DistributedHardwareProxyTest::TearDownTestCase() { } -void DistributedHardwareProxyTest::SetUp() +void DistributedHardwareProxyTest::SetUp() {} + +void DistributedHardwareProxyTest::TearDown() {} + +int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::RegisterPublisherListener(const DHTopic topic, + const sptr listener) +{ + (void)topic; + (void)listener; + return DH_FWK_SUCCESS; +} + +int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::UnregisterPublisherListener(const DHTopic topic, + const sptr listener) +{ + (void)topic; + (void)listener; + return DH_FWK_SUCCESS; +} + +int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::PublishMessage(const DHTopic topic, + const std::string &msg) +{ + (void)topic; + (void)msg; + return DH_FWK_SUCCESS; +} + +std::string DistributedHardwareProxyTest::TestDistributedHardwareStub::QueryLocalSysSpec(QueryLocalSysSpecType spec) +{ + (void)spec; + return ""; +} + +int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::InitializeAVCenter(const TransRole &transRole, + int32_t &engineId) +{ + (void)transRole; + (void)engineId; + return DH_FWK_SUCCESS; +} + +int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::ReleaseAVCenter(int32_t engineId) +{ + (void)engineId; + return DH_FWK_SUCCESS; +} + +int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::CreateControlChannel(int32_t engineId, + const std::string &peerDevId) +{ + (void)engineId; + (void)peerDevId; + return DH_FWK_SUCCESS; +} + +int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::NotifyAVCenter(int32_t engineId, + const AVTransEvent &event) { - sptr impl = nullptr; - hardwareProxy_ = std::make_shared(impl); + (void)engineId; + (void)event; + return DH_FWK_SUCCESS; } -void DistributedHardwareProxyTest::TearDown() +int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::RegisterCtlCenterCallback(int32_t engineId, + const sptr callback) { - hardwareProxy_ = nullptr; + (void)engineId; + (void)callback; + return DH_FWK_SUCCESS; +} + +int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::NotifySourceRemoteSinkStarted(std::string &deviceId) +{ + (void)deviceId; + return DH_FWK_SUCCESS; +} + +int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::PauseDistributedHardware(DHType dhType, + const std::string &networkId) +{ + (void)dhType; + (void)networkId; + return DH_FWK_SUCCESS; +} + +int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::ResumeDistributedHardware(DHType dhType, + const std::string &networkId) +{ + (void)dhType; + (void)networkId; + return DH_FWK_SUCCESS; +} + +int32_t DistributedHardwareProxyTest::TestDistributedHardwareStub::StopDistributedHardware(DHType dhType, + const std::string &networkId) +{ + (void)dhType; + (void)networkId; + return DH_FWK_SUCCESS; } /** @@ -46,42 +137,40 @@ void DistributedHardwareProxyTest::TearDown() */ HWTEST_F(DistributedHardwareProxyTest, RegisterPublisherListener_001, TestSize.Level0) { - ASSERT_TRUE(hardwareProxy_ != nullptr); - DHTopic topic = DHTopic::TOPIC_STOP_DSCREEN; + DHTopic topic = DHTopic::TOPIC_MIN; sptr listener = nullptr; - int32_t ret = hardwareProxy_->RegisterPublisherListener(topic, listener); + sptr dhStubPtr(new TestDistributedHardwareStub()); + ASSERT_TRUE(dhStubPtr != nullptr); + DistributedHardwareProxy dhProxy(dhStubPtr); + auto ret = dhProxy.RegisterPublisherListener(topic, listener); EXPECT_EQ(ERR_DH_FWK_PUBLISHER_LISTENER_IS_NULL, ret); -} -/** - * @tc.name: RegisterAbilityListener_002 - * @tc.desc: Verify the RegisterAbilityListener function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareProxyTest, RegisterAbilityListener_002, TestSize.Level0) -{ - ASSERT_TRUE(hardwareProxy_ != nullptr); - int32_t invalid = 7; - DHTopic topic = static_cast(invalid); - sptr listener(new MockIPublisherListener()); - int32_t ret = hardwareProxy_->RegisterPublisherListener(topic, listener); - EXPECT_EQ(ERR_DH_FWK_SERVICE_REMOTE_IS_NULL, ret); + sptr listener1(new MockIPublisherListener()); + ASSERT_TRUE(listener1 != nullptr); + ret = dhProxy.RegisterPublisherListener(topic, listener1); + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); + + topic = DHTopic::TOPIC_MAX; + ret = dhProxy.RegisterPublisherListener(topic, listener1); + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); } /** - * @tc.name: RegisterAbilityListener_003 + * @tc.name: RegisterAbilityListener_002 * @tc.desc: Verify the RegisterAbilityListener function * @tc.type: FUNC * @tc.require: AR000GHSJM */ -HWTEST_F(DistributedHardwareProxyTest, RegisterAbilityListener_003, TestSize.Level0) +HWTEST_F(DistributedHardwareProxyTest, RegisterPublisherListener_002, TestSize.Level0) { - ASSERT_TRUE(hardwareProxy_ != nullptr); - DHTopic topic = DHTopic::TOPIC_STOP_DSCREEN; + DHTopic topic = DHTopic::TOPIC_LOW_LATENCY; sptr listener(new MockIPublisherListener()); - int32_t ret = hardwareProxy_->RegisterPublisherListener(topic, listener); - EXPECT_NE(DH_FWK_SUCCESS, ret); + ASSERT_TRUE(listener != nullptr); + sptr dhStubPtr(new TestDistributedHardwareStub()); + ASSERT_TRUE(dhStubPtr != nullptr); + DistributedHardwareProxy dhProxy(dhStubPtr); + auto ret = dhProxy.RegisterPublisherListener(topic, listener); + EXPECT_EQ(ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL, ret); } /** @@ -92,42 +181,39 @@ HWTEST_F(DistributedHardwareProxyTest, RegisterAbilityListener_003, TestSize.Lev */ HWTEST_F(DistributedHardwareProxyTest, UnregisterPublisherListener_001, TestSize.Level0) { - ASSERT_TRUE(hardwareProxy_ != nullptr); - DHTopic topic = DHTopic::TOPIC_STOP_DSCREEN; + DHTopic topic = DHTopic::TOPIC_MIN; sptr listener = nullptr; - int32_t ret = hardwareProxy_->UnregisterPublisherListener(topic, listener); + sptr dhStubPtr(new TestDistributedHardwareStub()); + ASSERT_TRUE(dhStubPtr != nullptr); + DistributedHardwareProxy dhProxy(dhStubPtr); + auto ret = dhProxy.UnregisterPublisherListener(topic, listener); EXPECT_EQ(ERR_DH_FWK_PUBLISHER_LISTENER_IS_NULL, ret); -} -/** - * @tc.name: UnregisterPublisherListener_002 - * @tc.desc: Verify the UnregisterPublisherListener function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareProxyTest, UnregisterPublisherListener_002, TestSize.Level0) -{ - ASSERT_TRUE(hardwareProxy_ != nullptr); - int32_t invalid = 7; - DHTopic topic = static_cast(invalid); - sptr listener(new MockIPublisherListener()); - int32_t ret = hardwareProxy_->UnregisterPublisherListener(topic, listener); - EXPECT_EQ(ERR_DH_FWK_SERVICE_REMOTE_IS_NULL, ret); + sptr listener1(new MockIPublisherListener()); + ASSERT_TRUE(listener1 != nullptr); + ret = dhProxy.UnregisterPublisherListener(topic, listener1); + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); + + topic = DHTopic::TOPIC_MAX; + ret = dhProxy.RegisterPublisherListener(topic, listener1); + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); } /** - * @tc.name: UnregisterPublisherListener_003 + * @tc.name: UnregisterPublisherListener_002 * @tc.desc: Verify the UnregisterPublisherListener function * @tc.type: FUNC * @tc.require: AR000GHSJM */ HWTEST_F(DistributedHardwareProxyTest, UnregisterPublisherListener_003, TestSize.Level0) { - ASSERT_TRUE(hardwareProxy_ != nullptr); - DHTopic topic = DHTopic::TOPIC_STOP_DSCREEN; + DHTopic topic = DHTopic::TOPIC_LOW_LATENCY; sptr listener(new MockIPublisherListener()); - int32_t ret = hardwareProxy_->UnregisterPublisherListener(topic, listener); - EXPECT_NE(DH_FWK_SUCCESS, ret); + sptr dhStubPtr(new TestDistributedHardwareStub()); + ASSERT_TRUE(dhStubPtr != nullptr); + DistributedHardwareProxy dhProxy(dhStubPtr); + int32_t ret = dhProxy.UnregisterPublisherListener(topic, listener); + EXPECT_EQ(ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL, ret); } /** @@ -138,12 +224,17 @@ HWTEST_F(DistributedHardwareProxyTest, UnregisterPublisherListener_003, TestSize */ HWTEST_F(DistributedHardwareProxyTest, PublishMessage_001, TestSize.Level0) { - ASSERT_TRUE(hardwareProxy_ != nullptr); - int32_t invalid = 7; - std::string msg; - DHTopic topic = static_cast(invalid); - int32_t ret = hardwareProxy_->PublishMessage(topic, msg); - EXPECT_EQ(ERR_DH_FWK_SERVICE_REMOTE_IS_NULL, ret); + DHTopic topic = DHTopic::TOPIC_MIN; + std::string msg = ""; + sptr dhStubPtr(new TestDistributedHardwareStub()); + ASSERT_TRUE(dhStubPtr != nullptr); + DistributedHardwareProxy dhProxy(dhStubPtr); + auto ret = dhProxy.PublishMessage(topic, msg); + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); + + topic = DHTopic::TOPIC_MAX; + ret = dhProxy.PublishMessage(topic, msg); + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); } /** @@ -154,158 +245,210 @@ HWTEST_F(DistributedHardwareProxyTest, PublishMessage_001, TestSize.Level0) */ HWTEST_F(DistributedHardwareProxyTest, PublishMessage_002, TestSize.Level0) { - ASSERT_TRUE(hardwareProxy_ != nullptr); - DHTopic topic = DHTopic::TOPIC_STOP_DSCREEN; - std::string msg; - int32_t ret = hardwareProxy_->PublishMessage(topic, msg); - EXPECT_EQ(ERR_DH_FWK_SERVICE_REMOTE_IS_NULL, ret); -} + DHTopic topic = DHTopic::TOPIC_LOW_LATENCY; + std::string msg = ""; + sptr dhStubPtr(new TestDistributedHardwareStub()); + ASSERT_TRUE(dhStubPtr != nullptr); + DistributedHardwareProxy dhProxy(dhStubPtr); + auto ret = dhProxy.PublishMessage(topic, msg); + EXPECT_EQ(ERR_DH_FWK_SERVICE_MSG_INVALID, ret); -/** - * @tc.name: PublishMessage_003 - * @tc.desc: Verify the PublishMessage function - * @tc.type: FUNC - * @tc.require: AR000GHSJM - */ -HWTEST_F(DistributedHardwareProxyTest, PublishMessage_003, TestSize.Level0) -{ - ASSERT_TRUE(hardwareProxy_ != nullptr); - DHTopic topic = DHTopic::TOPIC_STOP_DSCREEN; - std::string msg = "msg"; - int32_t ret = hardwareProxy_->PublishMessage(topic, msg); - EXPECT_NE(DH_FWK_SUCCESS, ret); + msg = "msg_test"; + ret = dhProxy.PublishMessage(topic, msg); + EXPECT_EQ(ERR_DH_FWK_SERVICE_IPC_SEND_REQUEST_FAIL, ret); } /** * @tc.name: QueryLocalSysSpec_001 - * @tc.desc: Verify the PublishMessage function + * @tc.desc: Verify the QueryLocalSysSpec function * @tc.type: FUNC * @tc.require: AR000GHSJM */ HWTEST_F(DistributedHardwareProxyTest, QueryLocalSysSpec_001, TestSize.Level0) { - ASSERT_TRUE(hardwareProxy_ != nullptr); QueryLocalSysSpecType spec = QueryLocalSysSpecType::MIN; - std::string ret = hardwareProxy_->QueryLocalSysSpec(spec); - EXPECT_EQ(true, ret.empty()); + sptr dhStubPtr(new TestDistributedHardwareStub()); + ASSERT_TRUE(dhStubPtr != nullptr); + DistributedHardwareProxy dhProxy(dhStubPtr); + auto ret = dhProxy.QueryLocalSysSpec(spec); + EXPECT_EQ("", ret); + + spec = QueryLocalSysSpecType::MAX; + ret = dhProxy.QueryLocalSysSpec(spec); + EXPECT_EQ("", ret); +} + +HWTEST_F(DistributedHardwareProxyTest, QueryLocalSysSpec_002, TestSize.Level0) +{ + QueryLocalSysSpecType spec = QueryLocalSysSpecType::HISTREAMER_AUDIO_ENCODER; + sptr dhStubPtr(new TestDistributedHardwareStub()); + ASSERT_TRUE(dhStubPtr != nullptr); + DistributedHardwareProxy dhProxy(dhStubPtr); + auto ret = dhProxy.QueryLocalSysSpec(spec); + EXPECT_EQ("", ret); } /** * @tc.name: InitializeAVCenter_001 - * @tc.desc: Verify the PublishMessage function + * @tc.desc: Verify the InitializeAVCenter function * @tc.type: FUNC * @tc.require: AR000GHSJM */ HWTEST_F(DistributedHardwareProxyTest, InitializeAVCenter_001, TestSize.Level0) { - ASSERT_TRUE(hardwareProxy_ != nullptr); - TransRole transRole = TransRole::UNKNOWN;; + TransRole transRole = TransRole::UNKNOWN; int32_t engineId = 0; - int32_t ret = hardwareProxy_->InitializeAVCenter(transRole, engineId); - EXPECT_EQ(ERR_DH_AVT_SERVICE_REMOTE_IS_NULL, ret); + sptr dhStubPtr(new TestDistributedHardwareStub()); + ASSERT_TRUE(dhStubPtr != nullptr); + DistributedHardwareProxy dhProxy(dhStubPtr); + auto ret = dhProxy.InitializeAVCenter(transRole, engineId); + EXPECT_EQ(ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL, ret); } /** * @tc.name: ReleaseAVCenter_001 - * @tc.desc: Verify the PublishMessage function + * @tc.desc: Verify the ReleaseAVCenter function * @tc.type: FUNC * @tc.require: AR000GHSJM */ HWTEST_F(DistributedHardwareProxyTest, ReleaseAVCenter_001, TestSize.Level0) { - ASSERT_TRUE(hardwareProxy_ != nullptr); int32_t engineId = 0; - int32_t ret = hardwareProxy_->ReleaseAVCenter(engineId); - EXPECT_EQ(ERR_DH_AVT_SERVICE_REMOTE_IS_NULL, ret); + sptr dhStubPtr(new TestDistributedHardwareStub()); + ASSERT_TRUE(dhStubPtr != nullptr); + DistributedHardwareProxy dhProxy(dhStubPtr); + auto ret = dhProxy.ReleaseAVCenter(engineId); + EXPECT_EQ(ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL, ret); } /** * @tc.name: CreateControlChannel_001 - * @tc.desc: Verify the PublishMessage function + * @tc.desc: Verify the CreateControlChannel function * @tc.type: FUNC * @tc.require: AR000GHSJM */ HWTEST_F(DistributedHardwareProxyTest, CreateControlChannel_001, TestSize.Level0) { - ASSERT_TRUE(hardwareProxy_ != nullptr); int32_t engineId = 0; std::string peerDevId = "peerDevId_test"; - int32_t ret = hardwareProxy_->CreateControlChannel(engineId, peerDevId); - EXPECT_EQ(ERR_DH_AVT_SERVICE_REMOTE_IS_NULL, ret); + sptr dhStubPtr(new TestDistributedHardwareStub()); + ASSERT_TRUE(dhStubPtr != nullptr); + DistributedHardwareProxy dhProxy(dhStubPtr); + auto ret = dhProxy.CreateControlChannel(engineId, peerDevId); + EXPECT_EQ(ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL, ret); } /** * @tc.name: NotifyAVCenter_001 - * @tc.desc: Verify the PublishMessage function + * @tc.desc: Verify the NotifyAVCenter function * @tc.type: FUNC * @tc.require: AR000GHSJM */ HWTEST_F(DistributedHardwareProxyTest, NotifyAVCenter_001, TestSize.Level0) { - ASSERT_TRUE(hardwareProxy_ != nullptr); int32_t engineId = 0; AVTransEvent event; - int32_t ret = hardwareProxy_->NotifyAVCenter(engineId, event); - EXPECT_EQ(ERR_DH_AVT_SERVICE_REMOTE_IS_NULL, ret); + sptr dhStubPtr(new TestDistributedHardwareStub()); + ASSERT_TRUE(dhStubPtr != nullptr); + DistributedHardwareProxy dhProxy(dhStubPtr); + auto ret = dhProxy.NotifyAVCenter(engineId, event); + EXPECT_EQ(ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL, ret); +} + +/** + * @tc.name: RegisterCtlCenterCallback_001 + * @tc.desc: Verify the RegisterCtlCenterCallback function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(DistributedHardwareProxyTest, RegisterCtlCenterCallback_001, TestSize.Level0) +{ + int32_t engineId = 0; + sptr callback = nullptr; + sptr dhStubPtr(new TestDistributedHardwareStub()); + ASSERT_TRUE(dhStubPtr != nullptr); + DistributedHardwareProxy dhProxy(dhStubPtr); + auto ret = dhProxy.RegisterCtlCenterCallback(engineId, callback); + EXPECT_EQ(ERR_DH_FWK_AVTRANS_CALLBACK_IS_NULL, ret); } /** * @tc.name: NotifySourceRemoteSinkStarted_001 - * @tc.desc: Verify the PublishMessage function + * @tc.desc: Verify the NotifySourceRemoteSinkStarted function * @tc.type: FUNC * @tc.require: AR000GHSJM */ HWTEST_F(DistributedHardwareProxyTest, NotifySourceRemoteSinkStarted_001, TestSize.Level0) { - ASSERT_TRUE(hardwareProxy_ != nullptr); std::string deviceId = "devid_test"; - int32_t ret = hardwareProxy_->NotifySourceRemoteSinkStarted(deviceId); - EXPECT_EQ(ERR_DH_AVT_SERVICE_REMOTE_IS_NULL, ret); + sptr dhStubPtr(new TestDistributedHardwareStub()); + ASSERT_TRUE(dhStubPtr != nullptr); + DistributedHardwareProxy dhProxy(dhStubPtr); + auto ret = dhProxy.NotifySourceRemoteSinkStarted(deviceId); + EXPECT_EQ(ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL, ret); } /** * @tc.name: PauseDistributedHardware_001 - * @tc.desc: Verify the PublishMessage function + * @tc.desc: Verify the PauseDistributedHardware function * @tc.type: FUNC * @tc.require: AR000GHSJM */ HWTEST_F(DistributedHardwareProxyTest, PauseDistributedHardware_001, TestSize.Level0) { - ASSERT_TRUE(hardwareProxy_ != nullptr); DHType dhType = DHType::CAMERA; - std::string networkId = "networkId_test"; - int32_t ret = hardwareProxy_->PauseDistributedHardware(dhType, networkId); - EXPECT_EQ(ERR_DH_AVT_SERVICE_REMOTE_IS_NULL, ret); + std::string networkId = ""; + sptr dhStubPtr(new TestDistributedHardwareStub()); + ASSERT_TRUE(dhStubPtr != nullptr); + DistributedHardwareProxy dhProxy(dhStubPtr); + auto ret = dhProxy.PauseDistributedHardware(dhType, networkId); + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); + + networkId = "123456789"; + ret = dhProxy.PauseDistributedHardware(dhType, networkId); + EXPECT_EQ(ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL, ret); } /** * @tc.name: ResumeDistributedHardware_001 - * @tc.desc: Verify the PublishMessage function + * @tc.desc: Verify the ResumeDistributedHardware function * @tc.type: FUNC * @tc.require: AR000GHSJM */ HWTEST_F(DistributedHardwareProxyTest, ResumeDistributedHardware_001, TestSize.Level0) { - ASSERT_TRUE(hardwareProxy_ != nullptr); DHType dhType = DHType::CAMERA; - std::string networkId = "networkId_test"; - int32_t ret = hardwareProxy_->ResumeDistributedHardware(dhType, networkId); - EXPECT_EQ(ERR_DH_AVT_SERVICE_REMOTE_IS_NULL, ret); + std::string networkId = ""; + sptr dhStubPtr(new TestDistributedHardwareStub()); + ASSERT_TRUE(dhStubPtr != nullptr); + DistributedHardwareProxy dhProxy(dhStubPtr); + auto ret = dhProxy.ResumeDistributedHardware(dhType, networkId); + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); + + networkId = "123456789"; + ret = dhProxy.ResumeDistributedHardware(dhType, networkId); + EXPECT_EQ(ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL, ret); } /** * @tc.name: StopDistributedHardware_001 - * @tc.desc: Verify the PublishMessage function + * @tc.desc: Verify the StopDistributedHardware function * @tc.type: FUNC * @tc.require: AR000GHSJM */ HWTEST_F(DistributedHardwareProxyTest, StopDistributedHardware_001, TestSize.Level0) { - ASSERT_TRUE(hardwareProxy_ != nullptr); DHType dhType = DHType::CAMERA; - std::string networkId = "networkId_test"; - int32_t ret = hardwareProxy_->StopDistributedHardware(dhType, networkId); - EXPECT_EQ(ERR_DH_AVT_SERVICE_REMOTE_IS_NULL, ret); + std::string networkId = ""; + sptr dhStubPtr(new TestDistributedHardwareStub()); + ASSERT_TRUE(dhStubPtr != nullptr); + DistributedHardwareProxy dhProxy(dhStubPtr); + auto ret = dhProxy.StopDistributedHardware(dhType, networkId); + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); + + networkId = "123456789"; + ret = dhProxy.StopDistributedHardware(dhType, networkId); + EXPECT_EQ(ERR_DH_AVT_SERVICE_IPC_SEND_REQUEST_FAIL, ret); } } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/test/unittest/common/ipc/publisher_listener_stub/src/publisher_listener_stub_test.cpp b/interfaces/inner_kits/test/unittest/common/ipc/publisher_listener_stub/src/publisher_listener_stub_test.cpp index 8d92f8899cbb0a08ec89675895738638985bdbc2..d8a6829fd748d08f193bf4309cdedb2892c3b0ba 100644 --- a/interfaces/inner_kits/test/unittest/common/ipc/publisher_listener_stub/src/publisher_listener_stub_test.cpp +++ b/interfaces/inner_kits/test/unittest/common/ipc/publisher_listener_stub/src/publisher_listener_stub_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -19,6 +19,10 @@ using namespace testing::ext; namespace OHOS { namespace DistributedHardware { +namespace { + const uint32_t MAX_MESSAGE_LEN = 40 * 1024 * 1024 + 10; +} + void PublisherListenerStubTest::SetUpTestCase() { } @@ -45,14 +49,83 @@ void PublisherListenerStubTest::TearDown() */ HWTEST_F(PublisherListenerStubTest, OnRemoteRequest_001, TestSize.Level0) { - if (listenerStub_ == nullptr) { - return; - } + ASSERT_TRUE(listenerStub_ != nullptr); uint32_t code = 0; MessageParcel data; MessageParcel reply; MessageOption option; EXPECT_EQ(ERR_INVALID_DATA, listenerStub_->OnRemoteRequest(code, data, reply, option)); } + +HWTEST_F(PublisherListenerStubTest, OnRemoteRequest_002, TestSize.Level0) +{ + ASSERT_TRUE(listenerStub_ != nullptr); + uint32_t code = static_cast(IPublisherListener::Message::ON_MESSAGE); + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInterfaceToken(listenerStub_->GetDescriptor()); + uint32_t topicInt = static_cast(DHTopic::TOPIC_MIN); + data.WriteUint32(topicInt); + EXPECT_EQ(ERR_INVALID_DATA, listenerStub_->OnRemoteRequest(code, data, reply, option)); +} + +HWTEST_F(PublisherListenerStubTest, OnRemoteRequest_003, TestSize.Level0) +{ + ASSERT_TRUE(listenerStub_ != nullptr); + uint32_t code = static_cast(IPublisherListener::Message::ON_MESSAGE); + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInterfaceToken(listenerStub_->GetDescriptor()); + uint32_t topicInt = static_cast(DHTopic::TOPIC_MAX); + data.WriteUint32(topicInt); + EXPECT_EQ(ERR_INVALID_DATA, listenerStub_->OnRemoteRequest(code, data, reply, option)); +} + +HWTEST_F(PublisherListenerStubTest, OnRemoteRequest_004, TestSize.Level0) +{ + ASSERT_TRUE(listenerStub_ != nullptr); + uint32_t code = static_cast(IPublisherListener::Message::ON_MESSAGE); + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInterfaceToken(listenerStub_->GetDescriptor()); + uint32_t topicInt = static_cast(DHTopic::TOPIC_LOW_LATENCY); + data.WriteUint32(topicInt); + std::string message = ""; + data.WriteString(message); + EXPECT_EQ(ERR_INVALID_DATA, listenerStub_->OnRemoteRequest(code, data, reply, option)); +} + +HWTEST_F(PublisherListenerStubTest, OnRemoteRequest_005, TestSize.Level0) +{ + ASSERT_TRUE(listenerStub_ != nullptr); + uint32_t code = static_cast(IPublisherListener::Message::ON_MESSAGE); + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInterfaceToken(listenerStub_->GetDescriptor()); + uint32_t topicInt = static_cast(DHTopic::TOPIC_LOW_LATENCY); + data.WriteUint32(topicInt); + std::string message(MAX_MESSAGE_LEN, 'a'); + data.WriteString(message); + EXPECT_EQ(ERR_INVALID_DATA, listenerStub_->OnRemoteRequest(code, data, reply, option)); +} + +HWTEST_F(PublisherListenerStubTest, OnRemoteRequest_006, TestSize.Level0) +{ + ASSERT_TRUE(listenerStub_ != nullptr); + uint32_t code = static_cast(IPublisherListener::Message::ON_MESSAGE); + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInterfaceToken(listenerStub_->GetDescriptor()); + uint32_t topicInt = static_cast(DHTopic::TOPIC_LOW_LATENCY); + data.WriteUint32(topicInt); + std::string message = "message"; + data.WriteString(message); + EXPECT_EQ(DH_FWK_SUCCESS, listenerStub_->OnRemoteRequest(code, data, reply, option)); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/ipc/publisher_listener_proxy.cpp b/services/distributedhardwarefwkservice/src/ipc/publisher_listener_proxy.cpp index fc281609e99cd28a8e013f95ea7e7d274db84891..117c74e25371aafed56ec1400d46ce469d602740 100644 --- a/services/distributedhardwarefwkservice/src/ipc/publisher_listener_proxy.cpp +++ b/services/distributedhardwarefwkservice/src/ipc/publisher_listener_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -36,7 +36,7 @@ void PublisherListenerProxy::OnMessage(const DHTopic topic, const std::string& m DHLOGE("Get Remote IRemoteObject failed"); return; } - if (topic < DHTopic::TOPIC_MIN || topic > DHTopic::TOPIC_MAX) { + if (topic <= DHTopic::TOPIC_MIN || topic >= DHTopic::TOPIC_MAX) { DHLOGE("Topic is invalid!"); return; } 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 index 9b9eafafdb88b015fcb123af71a07c9fe347392a..9be7aaf192864bbde16e0d834e83b20dfe3017de 100644 --- 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 @@ -239,6 +239,18 @@ HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_014, TestSize.Level0) EXPECT_EQ(ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL, ret); } +HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_015, TestSize.Level0) +{ + ASSERT_TRUE(stubTest_ != nullptr); + uint32_t code = static_cast(DHMsgInterfaceCode::REGISTER_CTL_CEN_CALLBACK); + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInterfaceToken(stubTest_->GetDescriptor()); + auto ret = stubTest_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ERR_DH_FWK_ACCESS_PERMISSION_CHECK_FAIL, ret); +} + /** * @tc.name: RegisterPublisherListenerInner_001 * @tc.desc: Verify the RegisterPublisherListenerInner function @@ -327,7 +339,5 @@ HWTEST_F(DistributedHardwareStubTest, ValidQueryLocalSpec_002, TestSize.Level0) spec = 5; EXPECT_EQ(false, stubTest_->ValidQueryLocalSpec(spec)); } - - } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/localhardwaremanager/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/localhardwaremanager/BUILD.gn index 14d9894e8a1a145d70e8d1d6cb914e1348ea38fb..e6dcd6a9e172559307b05cefb07195c4e7619431 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/localhardwaremanager/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/localhardwaremanager/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024 Huawei Device Co., Ltd. +# Copyright (c) 2022-2025 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 @@ -30,7 +30,6 @@ config("module_private_config") { "${services_path}/distributedhardwarefwkservice/include/resourcemanager", "${services_path}/distributedhardwarefwkservice/include/localhardwaremanager", "${services_path}/distributedhardwarefwkservice/include/utils", - "${services_path}/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/include", "${common_path}/utils/include", "${common_path}/log/include", ] @@ -39,10 +38,7 @@ config("module_private_config") { ohos_unittest("LocalHardwareManagerTest") { module_out_path = module_out_path - sources = [ - "${services_path}/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/src/mock_hardware_handler.cpp", - "src/local_hardware_manager_test.cpp", - ] + sources = [ "src/local_hardware_manager_test.cpp" ] configs = [ ":module_private_config" ] diff --git a/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/localhardwaremanager/src/local_hardware_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/localhardwaremanager/src/local_hardware_manager_test.cpp index 8fea341763773d0079a1ab35974b52af1eb4d1d8..4cc03248d919291d5917f47e8551fed0b48a9821 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/localhardwaremanager/src/local_hardware_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/localhardwaremanager/src/local_hardware_manager_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -18,7 +18,7 @@ #include "capability_info_manager.h" #include "dh_context.h" #include "local_hardware_manager.h" -#include "mock_hardware_handler.h" + using namespace testing::ext; namespace OHOS { diff --git a/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/BUILD.gn index a884518a0d908cd92b8e023d7a28b510eaa085f2..3ddbcd92ab697aee47db9e940d22b218cef003a8 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024 Huawei Device Co., Ltd. +# Copyright (c) 2022-2025 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 @@ -38,10 +38,7 @@ config("module_private_config") { ohos_unittest("PluginListenerImplTest") { module_out_path = module_out_path - sources = [ - "src/mock_hardware_handler.cpp", - "src/plugin_listener_impl_test.cpp", - ] + sources = [ "src/plugin_listener_impl_test.cpp" ] configs = [ ":module_private_config" ] diff --git a/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/include/mock_hardware_handler.h b/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/include/mock_hardware_handler.h deleted file mode 100644 index b9b348ebac353bf3dd659d240b4f6671f4b1e246..0000000000000000000000000000000000000000 --- a/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/include/mock_hardware_handler.h +++ /dev/null @@ -1,45 +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. - */ -#ifndef OHOS_DISTRIBUTED_HARDWARE_MCOK_HARDWARE_HANDLER_H -#define OHOS_DISTRIBUTED_HARDWARE_MCOK_HARDWARE_HANDLER_H - -#include - -#include "ihardware_handler.h" - -namespace OHOS { -namespace DistributedHardware { -class MockHardwareHandler : public IHardwareHandler { -public: - MockHardwareHandler() = default; - virtual ~MockHardwareHandler() = default; - - int32_t Initialize() override; - std::vector QueryMeta() override; - std::vector Query() override; - std::map QueryExtraInfo() override; - bool IsSupportPlugin() override; - void RegisterPluginListener(std::shared_ptr listener) override; - void UnRegisterPluginListener() override; - - int32_t PluginHardware(const std::string &dhId, const std::string &attr, const std::string &subtype); - int32_t UnPluginHardware(const std::string &dhId); - - std::shared_ptr listener_ = nullptr; - std::vector> listenerVec; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif diff --git a/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/src/mock_hardware_handler.cpp b/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/src/mock_hardware_handler.cpp deleted file mode 100644 index 0f35b1044f5b7687462d796c1016252598c10bbd..0000000000000000000000000000000000000000 --- a/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/src/mock_hardware_handler.cpp +++ /dev/null @@ -1,78 +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. - */ - -#include "mock_hardware_handler.h" - -#include "distributed_hardware_errno.h" -#include "distributed_hardware_log.h" - -namespace OHOS { -namespace DistributedHardware { -int32_t MockHardwareHandler::Initialize() -{ - return DH_FWK_SUCCESS; -} - -std::vector MockHardwareHandler::QueryMeta() -{ - DHItem item; - return std::vector { item }; -} - -std::vector MockHardwareHandler::Query() -{ - DHItem item; - return std::vector { item }; -} - -std::map MockHardwareHandler::QueryExtraInfo() -{ - std::map extraInfo; - return extraInfo; -} - -bool MockHardwareHandler::IsSupportPlugin() -{ - return true; -} - -void MockHardwareHandler::RegisterPluginListener(std::shared_ptr listener) -{ - listener_ = listener; -} - -void MockHardwareHandler::UnRegisterPluginListener() -{ - listener_ = nullptr; -} - -int32_t MockHardwareHandler::PluginHardware(const std::string &dhId, const std::string &attr, - const std::string &subtype) -{ - if (listener_ != nullptr) { - listener_->PluginHardware(dhId, attr, subtype); - } - return DH_FWK_SUCCESS; -} - -int32_t MockHardwareHandler::UnPluginHardware(const std::string &dhId) -{ - if (listener_ != nullptr) { - listener_->UnPluginHardware(dhId); - } - return DH_FWK_SUCCESS; -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/src/plugin_listener_impl_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/src/plugin_listener_impl_test.cpp index f523ed26121206ae8eafea1b9423c38535891a99..dd8d6dfc78a5ed9a53ba21a456324de805a1eb0e 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/src/plugin_listener_impl_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/src/plugin_listener_impl_test.cpp @@ -15,27 +15,17 @@ #include "plugin_listener_impl_test.h" -#include "distributed_hardware_errno.h" -#include "mock_hardware_handler.h" - using namespace testing::ext; namespace OHOS { namespace DistributedHardware { namespace { -const std::string dhId = "00000000000000000"; -const std::string attrs = "11111111111111111"; -const std::string subtype = "subtype"; -std::shared_ptr g_listener; -std::shared_ptr g_mockHardwareHandler; +const std::string DHID_TEST = "audio_1234564"; +const std::string ATTRS_TEST = "attrs_0"; +const std::string SUBTYPE_TEST = "subtype"; } -void PluginListenerImplTest::SetUpTestCase(void) -{ - DHType dhType = DHType::CAMERA; - g_listener = std::make_shared(dhType); - g_mockHardwareHandler = std::make_shared(); -} +void PluginListenerImplTest::SetUpTestCase(void) {} void PluginListenerImplTest::TearDownTestCase(void) {} @@ -44,72 +34,48 @@ void PluginListenerImplTest::SetUp() {} void PluginListenerImplTest::TearDown() {} /** - * @tc.name: plugin_listener_impl_test_001 + * @tc.name: PluginHardware_001 * @tc.desc: Verify the PluginHardware function. * @tc.type: FUNC * @tc.require: AR000GHSK3 */ -HWTEST_F(PluginListenerImplTest, plugin_listener_impl_test_001, TestSize.Level0) -{ - ASSERT_TRUE(g_mockHardwareHandler != nullptr); - g_mockHardwareHandler->RegisterPluginListener(g_listener); - EXPECT_EQ(g_mockHardwareHandler->PluginHardware(dhId, attrs, subtype), DH_FWK_SUCCESS); -} - -/** - * @tc.name: plugin_listener_impl_test_002 - * @tc.desc: Verify the UnPluginHardware function. - * @tc.type: FUNC - * @tc.require: AR000GHSK3 - */ -HWTEST_F(PluginListenerImplTest, plugin_listener_impl_test_002, TestSize.Level0) +HWTEST_F(PluginListenerImplTest, PluginHardware_001, TestSize.Level0) { - ASSERT_TRUE(g_mockHardwareHandler != nullptr); - EXPECT_EQ(g_mockHardwareHandler->UnPluginHardware(dhId), DH_FWK_SUCCESS); - g_mockHardwareHandler->UnRegisterPluginListener(); + DHType type = DHType::AUDIO; + std::shared_ptr listener = std::make_shared(type); + std::string dhId = ""; + std::string attrs = ""; + ASSERT_NO_FATAL_FAILURE(listener->PluginHardware(dhId, attrs, SUBTYPE_TEST)); } /** - * @tc.name: PluginHardware_001 + * @tc.name: PluginHardware_002 * @tc.desc: Verify the PluginHardware function. * @tc.type: FUNC * @tc.require: AR000GHSK3 */ -HWTEST_F(PluginListenerImplTest, PluginHardware_001, TestSize.Level0) +HWTEST_F(PluginListenerImplTest, PluginHardware_002, TestSize.Level0) { DHType type = DHType::AUDIO; std::shared_ptr listener = std::make_shared(type); - std::string dhId; - std::string attrs; - listener->PluginHardware(dhId, attrs, subtype); - EXPECT_EQ(true, dhId.empty()); + std::string dhId = ""; + ASSERT_NO_FATAL_FAILURE(listener->PluginHardware(dhId, ATTRS_TEST, SUBTYPE_TEST)); } /** - * @tc.name: PluginHardware_002 + * @tc.name: PluginHardware_003 * @tc.desc: Verify the PluginHardware function. * @tc.type: FUNC * @tc.require: AR000GHSK3 */ -HWTEST_F(PluginListenerImplTest, PluginHardware_002, TestSize.Level0) +HWTEST_F(PluginListenerImplTest, PluginHardware_003, TestSize.Level0) { - uint32_t MAX_ID_LEN = 257; DHType type = DHType::AUDIO; - std::shared_ptr listener = std::make_shared(type); - std::string dhId1; - std::string dhId2; - dhId2.resize(MAX_ID_LEN); - std::string dhId3 = "dhId3"; - std::string attrs1; - std::string attrs2; - attrs2.resize(MAX_ID_LEN); - std::string attrs3 = "attrs3"; - listener->PluginHardware(dhId1, attrs1, subtype); - listener->PluginHardware(dhId2, attrs1, subtype); - listener->PluginHardware(dhId3, attrs1, subtype); - listener->PluginHardware(dhId3, attrs2, subtype); - listener->PluginHardware(dhId3, attrs3, subtype); - EXPECT_EQ(true, dhId1.empty()); + std::shared_ptr listener = std::make_shared(type); + std::string attrs = ""; + ASSERT_NO_FATAL_FAILURE(listener->PluginHardware(DHID_TEST, attrs, SUBTYPE_TEST)); + + ASSERT_NO_FATAL_FAILURE(listener->PluginHardware(DHID_TEST, ATTRS_TEST, SUBTYPE_TEST)); } /** @@ -120,11 +86,10 @@ HWTEST_F(PluginListenerImplTest, PluginHardware_002, TestSize.Level0) */ HWTEST_F(PluginListenerImplTest, UnPluginHardware_001, TestSize.Level0) { + std::string dhId = ""; DHType type = DHType::AUDIO; - std::shared_ptr listener = std::make_shared(type); - std::string dhId; - listener->UnPluginHardware(dhId); - EXPECT_EQ(true, dhId.empty()); + std::shared_ptr listener = std::make_shared(type); + ASSERT_NO_FATAL_FAILURE(listener->UnPluginHardware(dhId)); } /** @@ -135,17 +100,9 @@ HWTEST_F(PluginListenerImplTest, UnPluginHardware_001, TestSize.Level0) */ HWTEST_F(PluginListenerImplTest, UnPluginHardware_002, TestSize.Level0) { - uint32_t MAX_ID_LEN = 257; DHType type = DHType::AUDIO; std::shared_ptr listener = std::make_shared(type); - std::string dhId1; - std::string dhId2; - dhId2.resize(MAX_ID_LEN); - std::string dhId3 = "dhId3"; - listener->UnPluginHardware(dhId1); - listener->UnPluginHardware(dhId2); - listener->UnPluginHardware(dhId3); - EXPECT_EQ(true, dhId1.empty()); + ASSERT_NO_FATAL_FAILURE(listener->UnPluginHardware(DHID_TEST)); } } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/local_capability_info_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/local_capability_info_manager_test.cpp index 16cfd8a46749a443cb8e6972efb98d0324883592..a4b11334b1cbfc1e5de9111796e23e3c9414393f 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/local_capability_info_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/local_capability_info_manager_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 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 @@ -19,6 +19,7 @@ #include "constants.h" #include "capability_info.h" +#include "dh_utils_tool.h" #include "distributed_hardware_errno.h" #include "local_capability_info_manager.h" @@ -29,6 +30,7 @@ namespace OHOS { namespace DistributedHardware { namespace { constexpr uint16_t DEV_TYPE_TEST = 14; + constexpr uint32_t MAX_DB_RECORD_LENGTH = 10005; } class LocalCapInfoMgrTest : public testing::Test { public: @@ -72,6 +74,9 @@ HWTEST_F(LocalCapInfoMgrTest, SyncDeviceInfoFromDB_001, TestSize.Level0) LocalCapabilityInfoManager::GetInstance()->Init(); ret = LocalCapabilityInfoManager::GetInstance()->SyncDeviceInfoFromDB(deviceId); EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret); + + ret = LocalCapabilityInfoManager::GetInstance()->SyncDeviceInfoFromDB(""); + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); } HWTEST_F(LocalCapInfoMgrTest, AddCapability_001, TestSize.Level0) @@ -79,6 +84,14 @@ HWTEST_F(LocalCapInfoMgrTest, AddCapability_001, TestSize.Level0) std::vector> resInfos; auto ret = LocalCapabilityInfoManager::GetInstance()->AddCapability(resInfos); EXPECT_EQ(ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID, ret); + + for (int32_t i = 1; i < MAX_DB_RECORD_LENGTH; i++) { + std::shared_ptr capInfoTest = make_shared(std::to_string(i), std::to_string(i), + "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs", "subtype"); + resInfos.push_back(capInfoTest); + } + ret = LocalCapabilityInfoManager::GetInstance()->AddCapability(resInfos); + EXPECT_EQ(ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID, ret); } HWTEST_F(LocalCapInfoMgrTest, AddCapability_002, TestSize.Level0) @@ -94,8 +107,10 @@ HWTEST_F(LocalCapInfoMgrTest, AddCapability_002, TestSize.Level0) HWTEST_F(LocalCapInfoMgrTest, AddCapability_003, TestSize.Level0) { std::shared_ptr capInfo = std::make_shared("", "", "", 0, DHType::UNKNOWN, "", ""); + std::shared_ptr capInfo1 = nullptr; std::vector> resInfos; resInfos.push_back(capInfo); + resInfos.push_back(capInfo1); LocalCapabilityInfoManager::GetInstance()->Init(); auto ret = LocalCapabilityInfoManager::GetInstance()->AddCapability(resInfos); EXPECT_EQ(DH_FWK_SUCCESS, ret); @@ -240,5 +255,22 @@ HWTEST_F(LocalCapInfoMgrTest, ClearRemoteDeviceLocalInfoData_001, TestSize.Level ret = LocalCapabilityInfoManager::GetInstance()->ClearRemoteDeviceLocalInfoData(peeruuid); EXPECT_EQ(DH_FWK_SUCCESS, ret); } + +HWTEST_F(LocalCapInfoMgrTest, RemoveLocalInfoInMemByUuid_001, TestSize.Level0) +{ + std::string peeruuid = "123456789"; + std::string dhid = "audio_132"; + std::string deviceId = Sha256(peeruuid); + + std::shared_ptr capInfo = std::make_shared( + dhid, deviceId, "devName_test", DEV_TYPE_TEST, DHType::AUDIO, "attrs", "subtype"); + std::string key = deviceId + "###" + dhid; + LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_[key] = capInfo; + auto ret = LocalCapabilityInfoManager::GetInstance()->RemoveLocalInfoInMemByUuid("111222333"); + EXPECT_EQ(DH_FWK_SUCCESS, ret); + + ret = LocalCapabilityInfoManager::GetInstance()->RemoveLocalInfoInMemByUuid(peeruuid); + EXPECT_EQ(DH_FWK_SUCCESS, ret); +} } } \ No newline at end of file