From 14ea771a1f990fad01a9e52af0005c50bd0c14fb Mon Sep 17 00:00:00 2001 From: li-tiangang4 Date: Sat, 6 Jul 2024 18:02:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A1=86=E6=9E=B6=E5=AE=89=E5=85=A8=E7=BC=96?= =?UTF-8?q?=E7=A0=81=E9=97=AE=E9=A2=98=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-tiangang4 --- .../include/distributed_hardware_errno.h | 7 ++ .../inner_kits/include/ipc/dhfwk_sa_manager.h | 6 +- .../inner_kits/src/ipc/dhfwk_sa_manager.cpp | 22 ++--- .../src/ipc/distributed_hardware_proxy.cpp | 5 + .../distributedhardwarefwkstub_fuzzer.cpp | 3 + .../src/distributed_hardware_fwk_kit_test.cpp | 19 ++++ .../src/dhfwk_sa_manager_test.cpp | 28 +++--- .../src/distributed_hardware_proxy_test.cpp | 18 ++++ .../src/publisher_listener_stub_test.cpp | 3 +- .../src/componentloader/component_loader.cpp | 10 +- .../componentmanager/component_manager.cpp | 97 ++++++++++++++++--- .../componentmanager/component_monitor.cpp | 2 +- .../componentmanager/component_privacy.cpp | 22 +++++ .../dh_data_sync_trigger_listener.cpp | 4 + .../src/hidumphelper/hidump_helper.cpp | 4 + .../local_hardware_manager.cpp | 16 ++- .../plugin_listener_impl.cpp | 9 +- .../src/lowlatency/low_latency.cpp | 4 +- .../src/component_manager_test.cpp | 5 + .../src/component_monitor_test.cpp | 11 ++- .../component_privacy_test.cpp | 5 + .../common/dbadapter/src/db_adapter_test.cpp | 22 +++++ .../src/distributed_hardware_stub_test.cpp | 20 ++++ .../hidumphelper/src/hidump_helper_test.cpp | 1 + .../ipc/src/publisher_listener_proxy_test.cpp | 3 + .../src/plugin_listener_impl_test.cpp | 4 +- .../src/low_latency_listener_test.cpp | 9 ++ .../src/resource_manager_test.cpp | 57 +++++++++++ .../unittest/common/task/src/task_test.cpp | 13 ++- .../common/transport/dh_comm_tool_test.cpp | 3 + .../common/transport/dh_transport_test.cpp | 8 ++ .../src/version_info_manager_test.cpp | 19 ++++ 32 files changed, 402 insertions(+), 57 deletions(-) diff --git a/common/utils/include/distributed_hardware_errno.h b/common/utils/include/distributed_hardware_errno.h index 998aba9e..536fbca9 100644 --- a/common/utils/include/distributed_hardware_errno.h +++ b/common/utils/include/distributed_hardware_errno.h @@ -31,6 +31,8 @@ namespace DistributedHardware { constexpr int32_t ERR_DH_FWK_TYPE_NOT_EXIST = -10003; constexpr int32_t ERR_DH_FWK_JSON_PARSE_FAILED = -10004; constexpr int32_t ERR_DH_FWK_POINTER_IS_NULL = -10005; + constexpr int32_t ERR_DH_FWK_SINK_HANDLE_IS_NULL = -10006; + constexpr int32_t ERR_DH_FWK_GET_INSTANCE_IS_NULL = -10007; /* VersionManager errno, range: [-10200, -10299] */ constexpr int32_t ERR_DH_FWK_VERSION_DEVICE_ID_NOT_EXIST = -10200; @@ -50,6 +52,10 @@ namespace DistributedHardware { constexpr int32_t ERR_DH_FWK_COMPONENT_MONITOR_NULL = -10011; constexpr int32_t ERR_DH_FWK_COMPONENT_TRANSPORT_OPT_FAILED = -10012; constexpr int32_t ERR_DH_FWK_COMPONENT_GET_ENABLE_PARAM_FAILED = -10013; + constexpr int32_t ERR_DH_FWK_COMPONENT_CAP_GET_INSTANCE_IS_NULL = -10014; + constexpr int32_t ERR_DH_FWK_COMPONENT_MATE_GET_INSTANCE_IS_NULL = -10015; + constexpr int32_t ERR_DH_FWK_COMPONENT_LOCAL_GET_INSTANCE_IS_NULL = -10016; + constexpr int32_t ERR_DH_FWK_COMPONENT_VERSION_GET_INSTANCE_IS_NULL = -10017; /* ResourceManager errno, range: [-10400, -10499] */ constexpr int32_t ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL = -10400; @@ -95,6 +101,7 @@ namespace DistributedHardware { constexpr int32_t ERR_DH_FWK_SERVICE_WRITE_INFO_FAIL = -10807; constexpr int32_t ERR_DH_FWK_PUBLISHER_LISTENER_IS_NULL = -10808; constexpr int32_t ERR_DH_FWK_SERVICE_MSG_INVALID = -10809; + constexpr int32_t ERR_DH_FWK_AVTRANS_CALLBACK_IS_NULL = -10810; /* AccessManager errno, range: [-10900, -10999] */ constexpr int32_t ERR_DH_FWK_ACCESS_INIT_DM_FAILED = -10900; diff --git a/interfaces/inner_kits/include/ipc/dhfwk_sa_manager.h b/interfaces/inner_kits/include/ipc/dhfwk_sa_manager.h index ecf21521..4f27093e 100644 --- a/interfaces/inner_kits/include/ipc/dhfwk_sa_manager.h +++ b/interfaces/inner_kits/include/ipc/dhfwk_sa_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -57,12 +57,12 @@ private: private: std::atomic dhfwkOnLine_; - std::atomic isSubscribeDHFWKSAChangeListener; + std::atomic isSubscribeDHFWKSAChangeListener_; std::mutex proxyMutex_; sptr dhfwkProxy_; sptr saListener_; std::mutex saStatCbMutex_; - DHFWKSAStateCb saStateCallback; + DHFWKSAStateCb saStateCallback_; std::mutex publisherListenersMutex_; std::unordered_map>> publisherListenersCache_; std::mutex avTransControlCenterCbMutex_; diff --git a/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp b/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp index ae595b0a..2d5008a9 100644 --- a/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp +++ b/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp @@ -29,8 +29,8 @@ namespace OHOS { namespace DistributedHardware { IMPLEMENT_SINGLE_INSTANCE(DHFWKSAManager); DHFWKSAManager::DHFWKSAManager() - : dhfwkOnLine_(false), isSubscribeDHFWKSAChangeListener(false), dhfwkProxy_(nullptr), - saListener_(new SystemAbilityListener()), saStateCallback(nullptr), + : dhfwkOnLine_(false), isSubscribeDHFWKSAChangeListener_(false), dhfwkProxy_(nullptr), + saListener_(new SystemAbilityListener()), saStateCallback_(nullptr), publisherListenersCache_({}), avTransControlCenterCbCache_({}) { DHLOGI("Ctor DHFWKSAManager"); @@ -39,7 +39,7 @@ DHFWKSAManager::~DHFWKSAManager() { DHLOGI("Dtor DHFWKSAManager"); dhfwkOnLine_ = false; - isSubscribeDHFWKSAChangeListener = false; + isSubscribeDHFWKSAChangeListener_ = false; dhfwkProxy_ = nullptr; saListener_ = nullptr; } @@ -53,20 +53,20 @@ void DHFWKSAManager::RegisterAbilityListener() return; } - if (!isSubscribeDHFWKSAChangeListener) { + if (!isSubscribeDHFWKSAChangeListener_) { DHLOGI("try subscribe sa change listener, sa id: %{public}d", DISTRIBUTED_HARDWARE_SA_ID); int32_t ret = saMgr->SubscribeSystemAbility(DISTRIBUTED_HARDWARE_SA_ID, saListener_); if (ret != 0) { DHLOGE("subscribe DHFWK sa change listener failed, ret: %{public}d", ret); return; } - isSubscribeDHFWKSAChangeListener = true; + isSubscribeDHFWKSAChangeListener_ = true; } } sptr DHFWKSAManager::GetDHFWKProxy() { - if (!isSubscribeDHFWKSAChangeListener) { + if (!isSubscribeDHFWKSAChangeListener_) { RegisterAbilityListener(); } @@ -97,7 +97,7 @@ sptr DHFWKSAManager::GetDHFWKProxy() void DHFWKSAManager::RegisterSAStateCallback(DHFWKSAStateCb callback) { std::lock_guard lock(saStatCbMutex_); - saStateCallback = callback; + saStateCallback_ = callback; } void DHFWKSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) @@ -111,8 +111,8 @@ void DHFWKSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAbi DHFWKSAManager::GetInstance().dhfwkOnLine_ = true; { std::lock_guard lock(DHFWKSAManager::GetInstance().saStatCbMutex_); - if (DHFWKSAManager::GetInstance().saStateCallback != nullptr) { - DHFWKSAManager::GetInstance().saStateCallback(true); + if (DHFWKSAManager::GetInstance().saStateCallback_ != nullptr) { + DHFWKSAManager::GetInstance().saStateCallback_(true); } } if (DHFWKSAManager::GetInstance().RestoreListener() != DH_FWK_SUCCESS) { @@ -136,8 +136,8 @@ void DHFWKSAManager::SystemAbilityListener::OnRemoveSystemAbility(int32_t system } { std::lock_guard lock(DHFWKSAManager::GetInstance().saStatCbMutex_); - if (DHFWKSAManager::GetInstance().saStateCallback != nullptr) { - DHFWKSAManager::GetInstance().saStateCallback(false); + if (DHFWKSAManager::GetInstance().saStateCallback_ != nullptr) { + DHFWKSAManager::GetInstance().saStateCallback_(false); } } DHLOGI("sa %{public}" PRId32 " stopped", systemAbilityId); diff --git a/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp b/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp index a1abe8eb..875f85f2 100644 --- a/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp +++ b/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp @@ -360,6 +360,11 @@ int32_t DistributedHardwareProxy::RegisterCtlCenterCallback(int32_t engineId, return ERR_DH_AVT_SERVICE_REMOTE_IS_NULL; } + if (callback == nullptr) { + DHLOGE("callback is null"); + return ERR_DH_FWK_AVTRANS_CALLBACK_IS_NULL; + } + MessageParcel data; MessageParcel reply; MessageOption option; diff --git a/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkstub_fuzzer/distributedhardwarefwkstub_fuzzer.cpp b/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkstub_fuzzer/distributedhardwarefwkstub_fuzzer.cpp index 3ec3c956..27f5a987 100644 --- a/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkstub_fuzzer/distributedhardwarefwkstub_fuzzer.cpp +++ b/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkstub_fuzzer/distributedhardwarefwkstub_fuzzer.cpp @@ -56,6 +56,9 @@ void DistributedHardwareFwkStubFuzzTest(const uint8_t *data, size_t size) } sptr publisherListenerStub(new (std::nothrow) MyPublisherListenerStub()); + if (publisherListenerStub == nullptr) { + return; + } publisherListenerStub->OnRemoteRequest(code, pdata, reply, option); } } // namespace DistributedHardware diff --git a/interfaces/inner_kits/test/unittest/common/distributedhardwarefwkkit/src/distributed_hardware_fwk_kit_test.cpp b/interfaces/inner_kits/test/unittest/common/distributedhardwarefwkkit/src/distributed_hardware_fwk_kit_test.cpp index e7b1eb55..7d52109a 100644 --- a/interfaces/inner_kits/test/unittest/common/distributedhardwarefwkkit/src/distributed_hardware_fwk_kit_test.cpp +++ b/interfaces/inner_kits/test/unittest/common/distributedhardwarefwkkit/src/distributed_hardware_fwk_kit_test.cpp @@ -81,6 +81,7 @@ uint32_t DistributedHardwareFwkKitTest::TestPublisherListener::GetTopicMsgCnt(co */ HWTEST_F(DistributedHardwareFwkKitTest, RegisterPublisherListener_001, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, dhfwkPtr_); sptr listener1 = new TestPublisherListener(); int32_t ret = dhfwkPtr_->RegisterPublisherListener(DHTopic::TOPIC_START_DSCREEN, listener1); EXPECT_EQ(DH_FWK_SUCCESS, ret); @@ -118,6 +119,7 @@ HWTEST_F(DistributedHardwareFwkKitTest, RegisterPublisherListener_001, testing:: */ HWTEST_F(DistributedHardwareFwkKitTest, PublishMessage_001, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, dhfwkPtr_); uint32_t invalid = 7; DHTopic topic = static_cast(invalid); std::string message; @@ -132,6 +134,7 @@ HWTEST_F(DistributedHardwareFwkKitTest, PublishMessage_001, testing::ext::TestSi */ HWTEST_F(DistributedHardwareFwkKitTest, PublishMessage_002, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, dhfwkPtr_); DHTopic topic = DHTopic::TOPIC_STOP_DSCREEN; std::string message; EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, dhfwkPtr_->PublishMessage(topic, message)); @@ -145,6 +148,7 @@ HWTEST_F(DistributedHardwareFwkKitTest, PublishMessage_002, testing::ext::TestSi */ HWTEST_F(DistributedHardwareFwkKitTest, PublishMessage_003, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, dhfwkPtr_); DHTopic topic = DHTopic::TOPIC_STOP_DSCREEN; std::string message = "TOPIC_STOP_DSCREEN"; EXPECT_EQ(ERR_DH_FWK_PUBLISH_MSG_FAILED, dhfwkPtr_->PublishMessage(topic, message)); @@ -158,6 +162,7 @@ HWTEST_F(DistributedHardwareFwkKitTest, PublishMessage_003, testing::ext::TestSi */ HWTEST_F(DistributedHardwareFwkKitTest, PublishMessage_004, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, dhfwkPtr_); DHTopic topic = DHTopic::TOPIC_STOP_DSCREEN; std::string message; uint32_t MAX_MESSAGE_LEN = 40 * 1024 * 1024 + 10; @@ -173,6 +178,7 @@ HWTEST_F(DistributedHardwareFwkKitTest, PublishMessage_004, testing::ext::TestSi */ HWTEST_F(DistributedHardwareFwkKitTest, OnDHFWKOnLine_001, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, dhfwkPtr_); bool isOnLine = true; dhfwkPtr_->OnDHFWKOnLine(isOnLine); EXPECT_EQ(nullptr, DHFWKSAManager::GetInstance().GetDHFWKProxy()); @@ -186,6 +192,7 @@ HWTEST_F(DistributedHardwareFwkKitTest, OnDHFWKOnLine_001, testing::ext::TestSiz */ HWTEST_F(DistributedHardwareFwkKitTest, RegisterPublisherListener_002, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, dhfwkPtr_); DHTopic topic = DHTopic::TOPIC_MIN; sptr listener = nullptr; int32_t ret = dhfwkPtr_->RegisterPublisherListener(topic, listener); @@ -200,6 +207,7 @@ HWTEST_F(DistributedHardwareFwkKitTest, RegisterPublisherListener_002, testing:: */ HWTEST_F(DistributedHardwareFwkKitTest, RegisterPublisherListener_003, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, dhfwkPtr_); DHTopic topic = DHTopic::TOPIC_START_DSCREEN; sptr listener = nullptr; int32_t ret = dhfwkPtr_->RegisterPublisherListener(topic, listener); @@ -214,6 +222,7 @@ HWTEST_F(DistributedHardwareFwkKitTest, RegisterPublisherListener_003, testing:: */ HWTEST_F(DistributedHardwareFwkKitTest, UnregisterPublisherListener_001, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, dhfwkPtr_); DHTopic topic = DHTopic::TOPIC_MIN; sptr listener = nullptr; int32_t ret = dhfwkPtr_->UnregisterPublisherListener(topic, listener); @@ -228,6 +237,7 @@ HWTEST_F(DistributedHardwareFwkKitTest, UnregisterPublisherListener_001, testing */ HWTEST_F(DistributedHardwareFwkKitTest, UnregisterPublisherListener_002, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, dhfwkPtr_); DHTopic topic = DHTopic::TOPIC_START_DSCREEN; sptr listener = nullptr; int32_t ret = dhfwkPtr_->UnregisterPublisherListener(topic, listener); @@ -242,6 +252,7 @@ HWTEST_F(DistributedHardwareFwkKitTest, UnregisterPublisherListener_002, testing */ HWTEST_F(DistributedHardwareFwkKitTest, QueryLocalSysSpec_001, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, dhfwkPtr_); QueryLocalSysSpecType spec = QueryLocalSysSpecType::MIN; std::string ret = dhfwkPtr_->QueryLocalSysSpec(spec); EXPECT_EQ(true, ret.empty()); @@ -255,6 +266,7 @@ HWTEST_F(DistributedHardwareFwkKitTest, QueryLocalSysSpec_001, testing::ext::Tes */ HWTEST_F(DistributedHardwareFwkKitTest, QueryLocalSysSpec_002, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, dhfwkPtr_); QueryLocalSysSpecType spec = QueryLocalSysSpecType::HISTREAMER_AUDIO_ENCODER; std::string ret = dhfwkPtr_->QueryLocalSysSpec(spec); EXPECT_EQ(true, ret.empty()); @@ -268,6 +280,7 @@ HWTEST_F(DistributedHardwareFwkKitTest, QueryLocalSysSpec_002, testing::ext::Tes */ HWTEST_F(DistributedHardwareFwkKitTest, InitializeAVCenter_001, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, dhfwkPtr_); TransRole transRole = TransRole::UNKNOWN; int32_t engineId = 0; int32_t ret = dhfwkPtr_->InitializeAVCenter(transRole, engineId); @@ -282,6 +295,7 @@ HWTEST_F(DistributedHardwareFwkKitTest, InitializeAVCenter_001, testing::ext::Te */ HWTEST_F(DistributedHardwareFwkKitTest, ReleaseAVCenter_001, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, dhfwkPtr_); int32_t engineId = 0; int32_t ret = dhfwkPtr_->ReleaseAVCenter(engineId); EXPECT_EQ(ERR_DH_FWK_POINTER_IS_NULL, ret); @@ -295,6 +309,7 @@ HWTEST_F(DistributedHardwareFwkKitTest, ReleaseAVCenter_001, testing::ext::TestS */ HWTEST_F(DistributedHardwareFwkKitTest, CreateControlChannel_001, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, dhfwkPtr_); int32_t engineId = 0; std::string peerDevId = "peerDevId_test"; int32_t ret = dhfwkPtr_->CreateControlChannel(engineId, peerDevId); @@ -309,6 +324,7 @@ HWTEST_F(DistributedHardwareFwkKitTest, CreateControlChannel_001, testing::ext:: */ HWTEST_F(DistributedHardwareFwkKitTest, NotifyAVCenter_001, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, dhfwkPtr_); int32_t engineId = 0; AVTransEvent event; int32_t ret = dhfwkPtr_->NotifyAVCenter(engineId, event); @@ -323,6 +339,7 @@ HWTEST_F(DistributedHardwareFwkKitTest, NotifyAVCenter_001, testing::ext::TestSi */ HWTEST_F(DistributedHardwareFwkKitTest, PauseDistributedHardware_001, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, dhfwkPtr_); DHType dhType = DHType::CAMERA; std::string networkId = "networkId_test"; int32_t ret = dhfwkPtr_->PauseDistributedHardware(dhType, networkId); @@ -337,6 +354,7 @@ HWTEST_F(DistributedHardwareFwkKitTest, PauseDistributedHardware_001, testing::e */ HWTEST_F(DistributedHardwareFwkKitTest, ResumeDistributedHardware_001, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, dhfwkPtr_); DHType dhType = DHType::CAMERA; std::string networkId = "networkId_test"; int32_t ret = dhfwkPtr_->ResumeDistributedHardware(dhType, networkId); @@ -351,6 +369,7 @@ HWTEST_F(DistributedHardwareFwkKitTest, ResumeDistributedHardware_001, testing:: */ HWTEST_F(DistributedHardwareFwkKitTest, StopDistributedHardware_001, testing::ext::TestSize.Level0) { + ASSERT_NE(nullptr, dhfwkPtr_); DHType dhType = DHType::CAMERA; std::string networkId = "networkId_test"; int32_t ret = dhfwkPtr_->StopDistributedHardware(dhType, networkId); diff --git a/interfaces/inner_kits/test/unittest/common/ipc/dhfwk_sa_manager/src/dhfwk_sa_manager_test.cpp b/interfaces/inner_kits/test/unittest/common/ipc/dhfwk_sa_manager/src/dhfwk_sa_manager_test.cpp index bcd5ac4b..53d1e46b 100644 --- a/interfaces/inner_kits/test/unittest/common/ipc/dhfwk_sa_manager/src/dhfwk_sa_manager_test.cpp +++ b/interfaces/inner_kits/test/unittest/common/ipc/dhfwk_sa_manager/src/dhfwk_sa_manager_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -50,10 +50,10 @@ void DHFWKSaStateCallback(bool callback) */ HWTEST_F(DHFWKSAManagerTest, RegisterAbilityListener_001, TestSize.Level0) { - DHFWKSAManager::GetInstance().isSubscribeDHFWKSAChangeListener.store(false); + DHFWKSAManager::GetInstance().isSubscribeDHFWKSAChangeListener_.store(false); DHFWKSAManager::GetInstance().saListener_ = nullptr; DHFWKSAManager::GetInstance().RegisterAbilityListener(); - EXPECT_EQ(false, DHFWKSAManager::GetInstance().isSubscribeDHFWKSAChangeListener.load()); + EXPECT_EQ(false, DHFWKSAManager::GetInstance().isSubscribeDHFWKSAChangeListener_.load()); } /** @@ -64,9 +64,9 @@ HWTEST_F(DHFWKSAManagerTest, RegisterAbilityListener_001, TestSize.Level0) */ HWTEST_F(DHFWKSAManagerTest, RegisterAbilityListener_002, TestSize.Level0) { - DHFWKSAManager::GetInstance().isSubscribeDHFWKSAChangeListener.store(true); + DHFWKSAManager::GetInstance().isSubscribeDHFWKSAChangeListener_.store(true); DHFWKSAManager::GetInstance().RegisterAbilityListener(); - EXPECT_EQ(true, DHFWKSAManager::GetInstance().isSubscribeDHFWKSAChangeListener.load()); + EXPECT_EQ(true, DHFWKSAManager::GetInstance().isSubscribeDHFWKSAChangeListener_.load()); } /** @@ -77,7 +77,7 @@ HWTEST_F(DHFWKSAManagerTest, RegisterAbilityListener_002, TestSize.Level0) */ HWTEST_F(DHFWKSAManagerTest, GetDHFWKProxy_001, TestSize.Level0) { - DHFWKSAManager::GetInstance().isSubscribeDHFWKSAChangeListener.store(false); + DHFWKSAManager::GetInstance().isSubscribeDHFWKSAChangeListener_.store(false); DHFWKSAManager::GetInstance().dhfwkProxy_ = nullptr; DHFWKSAManager::GetInstance().GetDHFWKProxy(); EXPECT_EQ(nullptr, DHFWKSAManager::GetInstance().dhfwkProxy_); @@ -91,7 +91,7 @@ HWTEST_F(DHFWKSAManagerTest, GetDHFWKProxy_001, TestSize.Level0) */ HWTEST_F(DHFWKSAManagerTest, GetDHFWKProxy_002, TestSize.Level0) { - DHFWKSAManager::GetInstance().isSubscribeDHFWKSAChangeListener.store(true); + DHFWKSAManager::GetInstance().isSubscribeDHFWKSAChangeListener_.store(true); DHFWKSAManager::GetInstance().dhfwkProxy_ = new OHOS::DistributedHardware::MockIDistributedHardware(); DHFWKSAManager::GetInstance().GetDHFWKProxy(); EXPECT_NE(nullptr, DHFWKSAManager::GetInstance().dhfwkProxy_); @@ -106,9 +106,9 @@ HWTEST_F(DHFWKSAManagerTest, GetDHFWKProxy_002, TestSize.Level0) HWTEST_F(DHFWKSAManagerTest, RegisterSAStateCallback_001, TestSize.Level0) { DHFWKSAStateCb callback; - DHFWKSAManager::GetInstance().isSubscribeDHFWKSAChangeListener.store(true); + DHFWKSAManager::GetInstance().isSubscribeDHFWKSAChangeListener_.store(true); DHFWKSAManager::GetInstance().RegisterSAStateCallback(callback); - EXPECT_EQ(true, DHFWKSAManager::GetInstance().isSubscribeDHFWKSAChangeListener.load()); + EXPECT_EQ(true, DHFWKSAManager::GetInstance().isSubscribeDHFWKSAChangeListener_.load()); } /** @@ -120,6 +120,7 @@ HWTEST_F(DHFWKSAManagerTest, RegisterSAStateCallback_001, TestSize.Level0) HWTEST_F(DHFWKSAManagerTest, OnAddSystemAbility_001, TestSize.Level0) { DHFWKSAManager::GetInstance().saListener_ = new DHFWKSAManager::SystemAbilityListener(); + ASSERT_NE(nullptr, DHFWKSAManager::GetInstance().saListener_); int32_t systemAbilityId = 1; std::string deviceId = "deviceId"; DHFWKSAManager::GetInstance().saListener_->OnAddSystemAbility(systemAbilityId, deviceId); @@ -135,6 +136,7 @@ HWTEST_F(DHFWKSAManagerTest, OnAddSystemAbility_001, TestSize.Level0) HWTEST_F(DHFWKSAManagerTest, OnAddSystemAbility_002, TestSize.Level0) { DHFWKSAManager::GetInstance().saListener_ = new DHFWKSAManager::SystemAbilityListener(); + ASSERT_NE(nullptr, DHFWKSAManager::GetInstance().saListener_); int32_t systemAbilityId = DISTRIBUTED_HARDWARE_SA_ID; std::string deviceId = "deviceId"; DHFWKSAManager::GetInstance().saListener_->OnAddSystemAbility(systemAbilityId, deviceId); @@ -150,10 +152,11 @@ HWTEST_F(DHFWKSAManagerTest, OnAddSystemAbility_002, TestSize.Level0) HWTEST_F(DHFWKSAManagerTest, OnAddSystemAbility_003, TestSize.Level0) { DHFWKSAManager::GetInstance().saListener_ = new DHFWKSAManager::SystemAbilityListener(); + ASSERT_NE(nullptr, DHFWKSAManager::GetInstance().saListener_); int32_t systemAbilityId = DISTRIBUTED_HARDWARE_SA_ID; std::string deviceId = "deviceId"; DHFWKSAManager::GetInstance().dhfwkProxy_ = new MockIDistributedHardware(); - DHFWKSAManager::GetInstance().saStateCallback = DHFWKSaStateCallback; + DHFWKSAManager::GetInstance().saStateCallback_ = DHFWKSaStateCallback; DHFWKSAManager::GetInstance().saListener_->OnAddSystemAbility(systemAbilityId, deviceId); EXPECT_NE(nullptr, DHFWKSAManager::GetInstance().saListener_); } @@ -167,6 +170,7 @@ HWTEST_F(DHFWKSAManagerTest, OnAddSystemAbility_003, TestSize.Level0) HWTEST_F(DHFWKSAManagerTest, OnRemoveSystemAbility_001, TestSize.Level0) { DHFWKSAManager::GetInstance().saListener_ = new DHFWKSAManager::SystemAbilityListener(); + ASSERT_NE(nullptr, DHFWKSAManager::GetInstance().saListener_); int32_t systemAbilityId = 1; std::string deviceId = "deviceId"; DHFWKSAManager::GetInstance().saListener_->OnRemoveSystemAbility(systemAbilityId, deviceId); @@ -182,6 +186,7 @@ HWTEST_F(DHFWKSAManagerTest, OnRemoveSystemAbility_001, TestSize.Level0) HWTEST_F(DHFWKSAManagerTest, OnRemoveSystemAbility_002, TestSize.Level0) { DHFWKSAManager::GetInstance().saListener_ = new DHFWKSAManager::SystemAbilityListener(); + ASSERT_NE(nullptr, DHFWKSAManager::GetInstance().saListener_); int32_t systemAbilityId = DISTRIBUTED_HARDWARE_SA_ID; std::string deviceId = "deviceId"; DHFWKSAManager::GetInstance().saListener_->OnRemoveSystemAbility(systemAbilityId, deviceId); @@ -197,10 +202,11 @@ HWTEST_F(DHFWKSAManagerTest, OnRemoveSystemAbility_002, TestSize.Level0) HWTEST_F(DHFWKSAManagerTest, OnRemoveSystemAbility_003, TestSize.Level0) { DHFWKSAManager::GetInstance().saListener_ = new DHFWKSAManager::SystemAbilityListener(); + ASSERT_NE(nullptr, DHFWKSAManager::GetInstance().saListener_); int32_t systemAbilityId = DISTRIBUTED_HARDWARE_SA_ID; std::string deviceId = "deviceId"; DHFWKSAManager::GetInstance().dhfwkProxy_ = new OHOS::DistributedHardware::MockIDistributedHardware(); - DHFWKSAManager::GetInstance().saStateCallback = DHFWKSaStateCallback; + DHFWKSAManager::GetInstance().saStateCallback_ = DHFWKSaStateCallback; DHFWKSAManager::GetInstance().saListener_->OnAddSystemAbility(systemAbilityId, deviceId); EXPECT_NE(nullptr, DHFWKSAManager::GetInstance().saListener_); } 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 b0f02380..ce2a2b85 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 @@ -46,6 +46,7 @@ void DistributedHardwareProxyTest::TearDown() */ HWTEST_F(DistributedHardwareProxyTest, RegisterPublisherListener_001, TestSize.Level0) { + ASSERT_NE(nullptr, hardwareProxy_); DHTopic topic = DHTopic::TOPIC_STOP_DSCREEN; sptr listener = nullptr; int32_t ret = hardwareProxy_->RegisterPublisherListener(topic, listener); @@ -60,6 +61,7 @@ HWTEST_F(DistributedHardwareProxyTest, RegisterPublisherListener_001, TestSize.L */ HWTEST_F(DistributedHardwareProxyTest, RegisterAbilityListener_002, TestSize.Level0) { + ASSERT_NE(nullptr, hardwareProxy_); int32_t invalid = 7; DHTopic topic = static_cast(invalid); sptr listener = new MockIPublisherListener(); @@ -75,6 +77,7 @@ HWTEST_F(DistributedHardwareProxyTest, RegisterAbilityListener_002, TestSize.Lev */ HWTEST_F(DistributedHardwareProxyTest, RegisterAbilityListener_003, TestSize.Level0) { + ASSERT_NE(nullptr, hardwareProxy_); DHTopic topic = DHTopic::TOPIC_STOP_DSCREEN; sptr listener = new MockIPublisherListener(); int32_t ret = hardwareProxy_->RegisterPublisherListener(topic, listener); @@ -89,6 +92,7 @@ HWTEST_F(DistributedHardwareProxyTest, RegisterAbilityListener_003, TestSize.Lev */ HWTEST_F(DistributedHardwareProxyTest, UnregisterPublisherListener_001, TestSize.Level0) { + ASSERT_NE(nullptr, hardwareProxy_); DHTopic topic = DHTopic::TOPIC_STOP_DSCREEN; sptr listener = nullptr; int32_t ret = hardwareProxy_->UnregisterPublisherListener(topic, listener); @@ -103,6 +107,7 @@ HWTEST_F(DistributedHardwareProxyTest, UnregisterPublisherListener_001, TestSize */ HWTEST_F(DistributedHardwareProxyTest, UnregisterPublisherListener_002, TestSize.Level0) { + ASSERT_NE(nullptr, hardwareProxy_); int32_t invalid = 7; DHTopic topic = static_cast(invalid); sptr listener = new MockIPublisherListener(); @@ -118,6 +123,7 @@ HWTEST_F(DistributedHardwareProxyTest, UnregisterPublisherListener_002, TestSize */ HWTEST_F(DistributedHardwareProxyTest, UnregisterPublisherListener_003, TestSize.Level0) { + ASSERT_NE(nullptr, hardwareProxy_); DHTopic topic = DHTopic::TOPIC_STOP_DSCREEN; sptr listener = new MockIPublisherListener(); int32_t ret = hardwareProxy_->UnregisterPublisherListener(topic, listener); @@ -132,6 +138,7 @@ HWTEST_F(DistributedHardwareProxyTest, UnregisterPublisherListener_003, TestSize */ HWTEST_F(DistributedHardwareProxyTest, PublishMessage_001, TestSize.Level0) { + ASSERT_NE(nullptr, hardwareProxy_); int32_t invalid = 7; std::string msg; DHTopic topic = static_cast(invalid); @@ -147,6 +154,7 @@ HWTEST_F(DistributedHardwareProxyTest, PublishMessage_001, TestSize.Level0) */ HWTEST_F(DistributedHardwareProxyTest, PublishMessage_002, TestSize.Level0) { + ASSERT_NE(nullptr, hardwareProxy_); DHTopic topic = DHTopic::TOPIC_STOP_DSCREEN; std::string msg; int32_t ret = hardwareProxy_->PublishMessage(topic, msg); @@ -161,6 +169,7 @@ HWTEST_F(DistributedHardwareProxyTest, PublishMessage_002, TestSize.Level0) */ HWTEST_F(DistributedHardwareProxyTest, PublishMessage_003, TestSize.Level0) { + ASSERT_NE(nullptr, hardwareProxy_); DHTopic topic = DHTopic::TOPIC_STOP_DSCREEN; std::string msg = "msg"; int32_t ret = hardwareProxy_->PublishMessage(topic, msg); @@ -175,6 +184,7 @@ HWTEST_F(DistributedHardwareProxyTest, PublishMessage_003, TestSize.Level0) */ HWTEST_F(DistributedHardwareProxyTest, QueryLocalSysSpec_001, TestSize.Level0) { + ASSERT_NE(nullptr, hardwareProxy_); QueryLocalSysSpecType spec = QueryLocalSysSpecType::MIN; std::string ret = hardwareProxy_->QueryLocalSysSpec(spec); EXPECT_EQ(true, ret.empty()); @@ -188,6 +198,7 @@ HWTEST_F(DistributedHardwareProxyTest, QueryLocalSysSpec_001, TestSize.Level0) */ HWTEST_F(DistributedHardwareProxyTest, InitializeAVCenter_001, TestSize.Level0) { + ASSERT_NE(nullptr, hardwareProxy_); TransRole transRole = TransRole::UNKNOWN;; int32_t engineId = 0; int32_t ret = hardwareProxy_->InitializeAVCenter(transRole, engineId); @@ -202,6 +213,7 @@ HWTEST_F(DistributedHardwareProxyTest, InitializeAVCenter_001, TestSize.Level0) */ HWTEST_F(DistributedHardwareProxyTest, ReleaseAVCenter_001, TestSize.Level0) { + ASSERT_NE(nullptr, hardwareProxy_); int32_t engineId = 0; int32_t ret = hardwareProxy_->ReleaseAVCenter(engineId); EXPECT_EQ(ERR_DH_AVT_SERVICE_REMOTE_IS_NULL, ret); @@ -215,6 +227,7 @@ HWTEST_F(DistributedHardwareProxyTest, ReleaseAVCenter_001, TestSize.Level0) */ HWTEST_F(DistributedHardwareProxyTest, CreateControlChannel_001, TestSize.Level0) { + ASSERT_NE(nullptr, hardwareProxy_); int32_t engineId = 0; std::string peerDevId = "peerDevId_test"; int32_t ret = hardwareProxy_->CreateControlChannel(engineId, peerDevId); @@ -229,6 +242,7 @@ HWTEST_F(DistributedHardwareProxyTest, CreateControlChannel_001, TestSize.Level0 */ HWTEST_F(DistributedHardwareProxyTest, NotifyAVCenter_001, TestSize.Level0) { + ASSERT_NE(nullptr, hardwareProxy_); int32_t engineId = 0; AVTransEvent event; int32_t ret = hardwareProxy_->NotifyAVCenter(engineId, event); @@ -243,6 +257,7 @@ HWTEST_F(DistributedHardwareProxyTest, NotifyAVCenter_001, TestSize.Level0) */ HWTEST_F(DistributedHardwareProxyTest, NotifySourceRemoteSinkStarted_001, TestSize.Level0) { + ASSERT_NE(nullptr, hardwareProxy_); std::string deviceId = "devid_test"; int32_t ret = hardwareProxy_->NotifySourceRemoteSinkStarted(deviceId); EXPECT_EQ(ERR_DH_AVT_SERVICE_REMOTE_IS_NULL, ret); @@ -256,6 +271,7 @@ HWTEST_F(DistributedHardwareProxyTest, NotifySourceRemoteSinkStarted_001, TestSi */ HWTEST_F(DistributedHardwareProxyTest, PauseDistributedHardware_001, TestSize.Level0) { + ASSERT_NE(nullptr, hardwareProxy_); DHType dhType = DHType::CAMERA; std::string networkId = "networkId_test"; int32_t ret = hardwareProxy_->PauseDistributedHardware(dhType, networkId); @@ -270,6 +286,7 @@ HWTEST_F(DistributedHardwareProxyTest, PauseDistributedHardware_001, TestSize.Le */ HWTEST_F(DistributedHardwareProxyTest, ResumeDistributedHardware_001, TestSize.Level0) { + ASSERT_NE(nullptr, hardwareProxy_); DHType dhType = DHType::CAMERA; std::string networkId = "networkId_test"; int32_t ret = hardwareProxy_->ResumeDistributedHardware(dhType, networkId); @@ -284,6 +301,7 @@ HWTEST_F(DistributedHardwareProxyTest, ResumeDistributedHardware_001, TestSize.L */ HWTEST_F(DistributedHardwareProxyTest, StopDistributedHardware_001, TestSize.Level0) { + ASSERT_NE(nullptr, hardwareProxy_); DHType dhType = DHType::CAMERA; std::string networkId = "networkId_test"; int32_t ret = hardwareProxy_->StopDistributedHardware(dhType, networkId); 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 f0a63f64..b68ae6c5 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 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -45,6 +45,7 @@ void PublisherListenerStubTest::TearDown() */ HWTEST_F(PublisherListenerStubTest, OnRemoteRequest_001, TestSize.Level0) { + ASSERT_NE(nullptr, listenerStub_); uint32_t code = 0; MessageParcel data; MessageParcel reply; diff --git a/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp b/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp index 7159803e..8f537f65 100644 --- a/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp +++ b/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp @@ -245,7 +245,7 @@ bool ComponentLoader::CheckComponentEnable(const CompConfig &config) DHLOGE("sys para: %{public}s get failed.", (item->second).c_str()); return false; } - DHLOGI("Component type: %{public}u, enable flag: %{public}d.", config.type, isEnable); + DHLOGI("Component type: %{public}#X, enable flag: %{public}d.", config.type, isEnable); return isEnable; } @@ -408,7 +408,7 @@ void ComponentLoader::GetAllHandler(std::map &dhtypeMap) int32_t ComponentLoader::GetHardwareHandler(const DHType dhType, IHardwareHandler *&hardwareHandlerPtr) { if (compHandlerMap_.find(dhType) == compHandlerMap_.end()) { - DHLOGE("DHType not exist, dhType: %{public}" PRIu32, (uint32_t)dhType); + DHLOGE("DHType not exist, dhType: %{public}#X", dhType); return ERR_DH_FWK_LOADER_HANDLER_IS_NULL; } @@ -432,7 +432,7 @@ int32_t ComponentLoader::GetHardwareHandler(const DHType dhType, IHardwareHandle int32_t ComponentLoader::GetSource(const DHType dhType, IDistributedHardwareSource *&sourcePtr) { if (compHandlerMap_.find(dhType) == compHandlerMap_.end()) { - DHLOGE("DHType not exist, dhType: %{public}" PRIu32, (uint32_t)dhType); + DHLOGE("DHType not exist, dhType: %{public}#X", dhType); return ERR_DH_FWK_LOADER_HANDLER_IS_NULL; } @@ -456,7 +456,7 @@ int32_t ComponentLoader::GetSource(const DHType dhType, IDistributedHardwareSour int32_t ComponentLoader::GetSink(const DHType dhType, IDistributedHardwareSink *&sinkPtr) { if (compHandlerMap_.find(dhType) == compHandlerMap_.end()) { - DHLOGE("DHType not exist, dhType: %{public}" PRIu32, (uint32_t)dhType); + DHLOGE("DHType not exist, dhType: %{public}#X", dhType); return ERR_DH_FWK_LOADER_HANDLER_IS_NULL; } @@ -611,7 +611,7 @@ bool ComponentLoader::IsDHTypeExist(DHType dhType) int32_t ComponentLoader::GetSourceSaId(const DHType dhType) { if (compHandlerMap_.find(dhType) == compHandlerMap_.end()) { - DHLOGE("DHType not exist, dhType: %{public}" PRIu32, (uint32_t)dhType); + DHLOGE("DHType not exist, dhType: %{public}#X", dhType); return DEFAULT_SA_ID; } return compHandlerMap_[dhType].sourceSaId; diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp index 9354b925..81fa6ca6 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp @@ -163,7 +163,7 @@ void ComponentManager::StartComponent() void ComponentManager::RegisterDHStateListener() { for (const auto &item : compSource_) { - DHLOGI("Register DH State listener, dhType: %{public}" PRIu32, (uint32_t)item.first); + DHLOGI("Register DH State listener, dhType: %{public}#X", item.first); if (item.second == nullptr) { DHLOGE("comp source ptr is null"); continue; @@ -178,7 +178,7 @@ void ComponentManager::RegisterDataSyncTriggerListener() eventHandler_ = std::make_shared(runner); for (const auto &item : compSource_) { - DHLOGI("Register Data Sync Trigger listener, dhType: %{public}" PRIu32, (uint32_t)item.first); + DHLOGI("Register Data Sync Trigger listener, dhType: %{public}#X", item.first); if (item.second == nullptr) { DHLOGE("comp source ptr is null"); continue; @@ -239,7 +239,7 @@ void ComponentManager::UnInitSAMonitor() void ComponentManager::UnregisterDHStateListener() { for (const auto &item : compSource_) { - DHLOGI("Unregister DH State listener, dhType: %{public}" PRIu32, (uint32_t)item.first); + DHLOGI("Unregister DH State listener, dhType: %{public}#X", item.first); if (item.second == nullptr) { DHLOGE("comp source ptr is null"); continue; @@ -251,7 +251,7 @@ void ComponentManager::UnregisterDHStateListener() void ComponentManager::UnregisterDataSyncTriggerListener() { for (const auto &item : compSource_) { - DHLOGI("Unregister Data Sync Trigger listener, dhType: %{public}" PRIu32, (uint32_t)item.first); + DHLOGI("Unregister Data Sync Trigger listener, dhType: %{public}#X", item.first); if (item.second == nullptr) { DHLOGE("comp source ptr is null"); continue; @@ -307,6 +307,10 @@ ActionResult ComponentManager::StartSource() std::unordered_map> futures; std::string uuid = DHContext::GetInstance().GetDeviceInfo().uuid; for (const auto &item : compSource_) { + if (item.second == nullptr) { + DHLOGE("comp source ptr is null"); + continue; + } CompVersion compversion; VersionManager::GetInstance().GetCompVersion(uuid, item.first, compversion); auto params = compversion.sourceVersion; @@ -318,13 +322,16 @@ ActionResult ComponentManager::StartSource() ActionResult ComponentManager::StartSource(DHType dhType) { - DHLOGI("Start Source, dhType: %{public}" PRIu32, (uint32_t)dhType); + DHLOGI("Start Source, dhType: %{public}#X", dhType); std::unordered_map> futures; if (compSource_.find(dhType) == compSource_.end()) { - DHLOGE("Component for DHType: %{public}" PRIu32 " not init source handler", (uint32_t)dhType); + DHLOGE("Component for DHType: %{public}#X not init source handler", dhType); + return futures; + } + if (compSource_[dhType] == nullptr) { + DHLOGE("comp source ptr is null"); return futures; } - std::string uuid = DHContext::GetInstance().GetDeviceInfo().uuid; CompVersion compVersion; VersionManager::GetInstance().GetCompVersion(uuid, dhType, compVersion); @@ -343,6 +350,10 @@ ActionResult ComponentManager::StartSink() std::unordered_map> futures; std::string uuid = DHContext::GetInstance().GetDeviceInfo().uuid; for (const auto &item : compSink_) { + if (item.second == nullptr) { + DHLOGE("comp sink ptr is null"); + continue; + } CompVersion compversion; VersionManager::GetInstance().GetCompVersion(uuid, item.first, compversion); auto params = compversion.sinkVersion; @@ -362,13 +373,16 @@ ActionResult ComponentManager::StartSink() ActionResult ComponentManager::StartSink(DHType dhType) { - DHLOGI("Start Sink, dhType: %{public}" PRIu32, (uint32_t)dhType); + DHLOGI("Start Sink, dhType: %{public}#X", dhType); std::unordered_map> futures; if (compSink_.find(dhType) == compSink_.end()) { - DHLOGE("Component for DHType: %{public}" PRIu32 " not init sink handler", (uint32_t)dhType); + DHLOGE("Component for DHType: %{public}#X not init sink handler", dhType); + return futures; + } + if (compSink_[dhType] == nullptr) { + DHLOGE("comp sink ptr is null"); return futures; } - std::string uuid = DHContext::GetInstance().GetDeviceInfo().uuid; CompVersion compVersion; VersionManager::GetInstance().GetCompVersion(uuid, dhType, compVersion); @@ -394,6 +408,10 @@ ActionResult ComponentManager::StopSource() DHLOGI("start."); std::unordered_map> futures; for (const auto &item : compSource_) { + if (item.second == nullptr) { + DHLOGE("comp source ptr is null"); + continue; + } auto future = std::async(std::launch::async, [item]() { return item.second->ReleaseSource(); }); futures.emplace(item.first, future.share()); } @@ -405,6 +423,10 @@ ActionResult ComponentManager::StopSink() DHLOGI("start."); std::unordered_map> futures; for (const auto &item : compSink_) { + if (item.second == nullptr) { + DHLOGE("comp sink ptr is null"); + continue; + } auto future = std::async(std::launch::async, [item]() { int32_t status = item.second->ReleaseSink(); IHardwareHandler *hardwareHandler = nullptr; @@ -607,6 +629,10 @@ int32_t ComponentManager::Disable(const std::string &networkId, const std::strin DHType ComponentManager::GetDHType(const std::string &uuid, const std::string &dhId) const { std::shared_ptr capability = nullptr; + if (CapabilityInfoManager::GetInstance() == nullptr) { + DHLOGE("cap getinstance is nullptr"); + return DHType::UNKNOWN; + } auto ret = CapabilityInfoManager::GetInstance()->GetCapability(GetDeviceIdByUUID(uuid), dhId, capability); if ((ret == DH_FWK_SUCCESS) && (capability != nullptr)) { return capability->GetDHType(); @@ -622,6 +648,10 @@ int32_t ComponentManager::GetEnableCapParam(const std::string &networkId, const DeviceInfo sourceDeviceInfo = GetLocalDeviceInfo(); std::vector> sourceCapInfos; std::string sourceDHId; + if (CapabilityInfoManager::GetInstance() == nullptr) { + DHLOGE("cap getinstance is nullptr"); + return ERR_DH_FWK_COMPONENT_CAP_GET_INSTANCE_IS_NULL; + } CapabilityInfoManager::GetInstance()->GetCapabilitiesByDeviceId(sourceDeviceInfo.deviceId, sourceCapInfos); for (const auto &capInfo : sourceCapInfos) { if (dhType == capInfo->GetDHType()) { @@ -637,6 +667,10 @@ int32_t ComponentManager::GetEnableCapParam(const std::string &networkId, const } param.sourceVersion = sourceVersion; + if (MetaInfoManager::GetInstance() == nullptr) { + DHLOGE("meta getinstance is nullptr"); + return ERR_DH_FWK_COMPONENT_MATE_GET_INSTANCE_IS_NULL; + } param.sinkAttrs = capability->GetDHAttrs(); std::string sinkVersion(""); ret = GetVersion(uuid, dhType, sinkVersion, true); @@ -665,6 +699,10 @@ int32_t ComponentManager::GetEnableCapParam(const std::string &networkId, const int32_t ComponentManager::GetEnableMetaParam(const std::string &networkId, const std::string &uuid, DHType dhType, EnableParam ¶m, std::shared_ptr &metaCapPtr) { + if (MetaInfoManager::GetInstance() == nullptr) { + DHLOGE("meta getinstance is nullptr"); + return ERR_DH_FWK_COMPONENT_MATE_GET_INSTANCE_IS_NULL; + } DeviceInfo sourceDeviceInfo = GetLocalDeviceInfo(); std::vector> sourceMetaInfos; std::string sourceDHId; @@ -697,6 +735,10 @@ int32_t ComponentManager::GetEnableMetaParam(const std::string &networkId, const int32_t ComponentManager::GetCapParam(const std::string &uuid, const std::string &dhId, std::shared_ptr &capability) { + if (CapabilityInfoManager::GetInstance() == nullptr) { + DHLOGE("cap getinstance is nullptr"); + return ERR_DH_FWK_COMPONENT_CAP_GET_INSTANCE_IS_NULL; + } std::string deviceId = GetDeviceIdByUUID(uuid); auto ret = CapabilityInfoManager::GetInstance()->GetCapability(deviceId, dhId, capability); if ((ret == DH_FWK_SUCCESS) && (capability != nullptr)) { @@ -704,7 +746,10 @@ int32_t ComponentManager::GetCapParam(const std::string &uuid, const std::string GetAnonyString(deviceId).c_str(), GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str(), ret); return ret; } - + if (LocalCapabilityInfoManager::GetInstance() == nullptr) { + DHLOGE("local getinstance is nullptr"); + return ERR_DH_FWK_COMPONENT_LOCAL_GET_INSTANCE_IS_NULL; + } ret = LocalCapabilityInfoManager::GetInstance()->GetCapability(deviceId, dhId, capability); if ((ret == DH_FWK_SUCCESS) && (capability != nullptr)) { DHLOGI("Local GetCaps success, deviceId: %{public}s, uuid: %{public}s, dhId: %{public}s, ret: %{public}d", @@ -718,6 +763,10 @@ int32_t ComponentManager::GetCapParam(const std::string &uuid, const std::string int32_t ComponentManager::GetMetaParam(const std::string &uuid, const std::string &dhId, std::shared_ptr &metaCapPtr) { + if (MetaInfoManager::GetInstance() == nullptr) { + DHLOGE("meta getinstance is nullptr"); + return ERR_DH_FWK_COMPONENT_MATE_GET_INSTANCE_IS_NULL; + } auto ret = MetaInfoManager::GetInstance()->GetMetaCapInfo(DHContext::GetInstance().GetUdidHashIdByUUID(uuid), dhId, metaCapPtr); if ((ret == DH_FWK_SUCCESS) && (metaCapPtr != nullptr)) { @@ -774,6 +823,10 @@ int32_t ComponentManager::GetVersionFromVerMgr(const std::string &uuid, const DH int32_t ComponentManager::GetVersionFromVerInfoMgr(const std::string &uuid, const DHType dhType, std::string &version, bool isSink) { + if (VersionInfoManager::GetInstance() == nullptr) { + DHLOGE("version getinstance is nullptr"); + return ERR_DH_FWK_COMPONENT_VERSION_GET_INSTANCE_IS_NULL; + } VersionInfo versionInfo; int32_t ret = VersionInfoManager::GetInstance()->GetVersionInfoByDeviceId(GetDeviceIdByUUID(uuid), versionInfo); if (ret != DH_FWK_SUCCESS) { @@ -783,7 +836,7 @@ int32_t ComponentManager::GetVersionFromVerInfoMgr(const std::string &uuid, cons } auto iter = versionInfo.compVersions.find(dhType); if (iter == versionInfo.compVersions.end()) { - DHLOGE("can not find component version for dhType = %{public}d", dhType); + DHLOGE("can not find component version for dhType = %{public}#X", dhType); return ERR_DH_FWK_COMPONENT_DHTYPE_NOT_FOUND; } DHLOGI("Get version info mgr success, sinkVersion = %{public}s, sourceVersion = %{public}s, uuid = %{public}s, " @@ -847,22 +900,26 @@ void ComponentManager::DoRecover(DHType dhType) void ComponentManager::ReStartSA(DHType dhType) { - DHLOGI("Restart SA for DHType %{public}" PRIu32, (uint32_t)dhType); + DHLOGI("Restart SA for DHType %{public}#X", dhType); auto sourceResult = StartSource(dhType); auto sinkResult = StartSink(dhType); if (!WaitForResult(Action::START_SOURCE, sourceResult)) { - DHLOGE("ReStartSource failed, DHType: %{public}" PRIu32, (uint32_t)dhType); + DHLOGE("ReStartSource failed, DHType: %{public}#X", dhType); } if (!WaitForResult(Action::START_SINK, sinkResult)) { - DHLOGE("ReStartSink failed, DHType: %{public}" PRIu32, (uint32_t)dhType); + DHLOGE("ReStartSink failed, DHType: %{public}#X", dhType); } DHLOGI("Finish Restart"); } void ComponentManager::RecoverDistributedHardware(DHType dhType) { + if (CapabilityInfoManager::GetInstance() == nullptr) { + DHLOGE("cap getinstance is nullptr"); + return; + } CapabilityInfoMap capabilityMap; CapabilityInfoManager::GetInstance()->GetDataByDHType(dhType, capabilityMap); for (const auto &capInfo : capabilityMap) { @@ -919,7 +976,7 @@ bool ComponentManager::IsIdenticalAccount(const std::string &networkId) void ComponentManager::UpdateBusinessState(const std::string &networkId, const std::string &dhId, BusinessState state) { DHLOGI("UpdateBusinessState, networkId: %{public}s, dhId: %{public}s, state: %{public}" PRIu32, - GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str(), (uint32_t)state); + GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str(), static_cast(state)); { std::lock_guard lock(bizStateMtx_); dhBizStates_[{networkId, dhId}] = state; @@ -954,6 +1011,10 @@ void ComponentManager::TriggerFullCapsSync(const std::string &networkId) DHLOGE("Remote networkid is null"); return; } + if (dhCommToolPtr_ == nullptr) { + DHLOGE("DH communication tool ptr is null"); + return; + } dhCommToolPtr_->TriggerReqFullDHCaps(networkId); } @@ -984,6 +1045,10 @@ ComponentManager::ComponentManagerEventHandler::ComponentManagerEventHandler( void ComponentManager::ComponentManagerEventHandler::ProcessEvent( const AppExecFwk::InnerEvent::Pointer &event) { + if (event == nullptr) { + DHLOGE("event is nullptr"); + return; + } uint32_t eventId = event->GetInnerEventId(); switch (eventId) { case EVENT_DATA_SYNC_MANUAL: { diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_monitor.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_monitor.cpp index f80e6d68..ff35f4dc 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_monitor.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_monitor.cpp @@ -67,7 +67,7 @@ void ComponentMonitor::CompSystemAbilityListener::OnRemoveSystemAbility(int32_t ServiceWaitForStatus(((*processNameIter).second).c_str(), ServiceStatus::SERVICE_STOPPED, WAIT_SERVICE_STATUS_TIMEOUT); - DHLOGI("Try Recover Component, dhType: %{public}" PRIu32, (uint32_t)dhType); + DHLOGI("Try Recover Component, dhType: %{public}#X", dhType); ComponentManager::GetInstance().Recover(dhType); } diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp index a740fbb8..bffeeb4b 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp @@ -254,6 +254,10 @@ bool ComponentPrivacy::GetPageFlag() void ComponentPrivacy::ComponentEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) { + if (event == nullptr) { + DHLOGE("event is nullptr"); + return; + } auto iter = eventFuncMap_.find(event->GetInnerEventId()); if (iter == eventFuncMap_.end()) { DHLOGE("ComponentEventHandler Event Id %{public}d is undefined.", event->GetInnerEventId()); @@ -282,6 +286,10 @@ ComponentPrivacy::ComponentEventHandler::~ComponentEventHandler() void ComponentPrivacy::ComponentEventHandler::ProcessStartPage(const AppExecFwk::InnerEvent::Pointer &event) { DHLOGI("ProcessStartPage enter."); + if (event == nullptr) { + DHLOGE("event is nullptr"); + return; + } std::shared_ptr dataMsg = event->GetSharedObject(); cJSON *innerMsg = cJSON_GetArrayItem(dataMsg.get(), 0); if (!IsString(innerMsg, PRIVACY_SUBTYPE)) { @@ -294,12 +302,21 @@ void ComponentPrivacy::ComponentEventHandler::ProcessStartPage(const AppExecFwk: return; } std::string networkId = cJSON_GetObjectItem(innerMsg, PRIVACY_NETWORKID.c_str())->valuestring; + + if (comPrivacyObj_ == nullptr) { + DHLOGE("comPrivacyObj_ is nullptr"); + return; + } comPrivacyObj_->StartPrivacePage(subtype, networkId); } void ComponentPrivacy::ComponentEventHandler::ProcessStopPage(const AppExecFwk::InnerEvent::Pointer &event) { DHLOGI("ProcessStopPage enter."); + if (event == nullptr) { + DHLOGE("event is nullptr"); + return; + } std::shared_ptr dataMsg = event->GetSharedObject(); cJSON *innerMsg = cJSON_GetArrayItem(dataMsg.get(), 0); if (!IsString(innerMsg, PRIVACY_SUBTYPE)) { @@ -307,6 +324,11 @@ void ComponentPrivacy::ComponentEventHandler::ProcessStopPage(const AppExecFwk:: return; } std::string subtype = cJSON_GetObjectItem(innerMsg, PRIVACY_SUBTYPE.c_str())->valuestring; + + if (comPrivacyObj_ == nullptr) { + DHLOGE("comPrivacyObj_ is nullptr"); + return; + } comPrivacyObj_->StopPrivacePage(subtype); } } // namespace DistributedHardware diff --git a/services/distributedhardwarefwkservice/src/componentmanager/dh_data_sync_trigger_listener.cpp b/services/distributedhardwarefwkservice/src/componentmanager/dh_data_sync_trigger_listener.cpp index 74ebc3ed..0ad5586f 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/dh_data_sync_trigger_listener.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/dh_data_sync_trigger_listener.cpp @@ -44,6 +44,10 @@ void DHDataSyncTriggerListener::OnDataSyncTrigger(const std::string &networkId) DHLOGE("OnDataSyncTrigger networkId is empty"); return; } + if (ComponentManager::GetInstance().GetEventHandler() == nullptr) { + DHLOGE("EventHandler is nullptr"); + return; + } std::shared_ptr networkIdPtr = std::make_shared(networkId); AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(EVENT_DATA_SYNC_MANUAL, networkIdPtr); ComponentManager::GetInstance().GetEventHandler()->SendEvent(msgEvent, diff --git a/services/distributedhardwarefwkservice/src/hidumphelper/hidump_helper.cpp b/services/distributedhardwarefwkservice/src/hidumphelper/hidump_helper.cpp index 86fed7ec..976c6a01 100644 --- a/services/distributedhardwarefwkservice/src/hidumphelper/hidump_helper.cpp +++ b/services/distributedhardwarefwkservice/src/hidumphelper/hidump_helper.cpp @@ -257,6 +257,10 @@ int32_t HidumpHelper::ShowAllTaskInfos(std::string &result) int32_t HidumpHelper::ShowAllCapabilityInfos(std::string &result) { DHLOGI("Dump all capability infos."); + if (CapabilityInfoManager::GetInstance() == nullptr) { + DHLOGE("cap getinstance is nullptr"); + return ERR_DH_FWK_COMPONENT_CAP_GET_INSTANCE_IS_NULL; + } std::vector capInfos; CapabilityInfoManager::GetInstance()->DumpCapabilityInfos(capInfos); diff --git a/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp b/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp index 1146c1d9..0b6a2258 100644 --- a/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp +++ b/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp @@ -89,6 +89,10 @@ void LocalHardwareManager::Init() AddLocalCapabilityInfo(localDHItems.second, localDHItems.first, capabilityInfos); AddLocalMetaCapInfo(localDHItems.second, localDHItems.first, metaCapInfos); } + if (CapabilityInfoManager::GetInstance() == nullptr || MetaInfoManager::GetInstance() == nullptr) { + DHLOGE("getinstance is nullptr"); + return; + } CapabilityInfoManager::GetInstance()->AddCapability(capabilityInfos); MetaInfoManager::GetInstance()->AddMetaCapInfos(metaCapInfos); } @@ -106,7 +110,9 @@ void LocalHardwareManager::QueryLocalHardware(const DHType dhType, IHardwareHand int32_t retryTimes = QUERY_RETRY_MAX_TIMES; while (retryTimes > 0) { DHLOGI("Query hardwareHandler retry times left: %{public}d, dhType: %{public}#X", retryTimes, dhType); - dhItems = hardwareHandler->Query(); + if (hardwareHandler != nullptr) { + dhItems = hardwareHandler->Query(); + } if (dhItems.empty()) { DHLOGE("Query hardwareHandler and obtain empty, dhType: %{public}#X", dhType); usleep(QUERY_INTERVAL_TIME); @@ -187,7 +193,9 @@ void LocalHardwareManager::CheckNonExistCapabilityInfo(const std::vector if (!isExist) { DHLOGI("This data is non-exist, it should be removed, key: %{public}s", capabilityValue->GetAnonymousKey().c_str()); - CapabilityInfoManager::GetInstance()->RemoveCapabilityInfoByKey(capabilityValue->GetKey()); + if (CapabilityInfoManager::GetInstance() != nullptr) { + CapabilityInfoManager::GetInstance()->RemoveCapabilityInfoByKey(capabilityValue->GetKey()); + } } } DHLOGI("end"); @@ -206,7 +214,9 @@ void LocalHardwareManager::GetLocalCapabilityMapByPrefix(const DHType dhType, Ca } std::string prefix = DHTypePrefixMap.find(dhType)->second; std::string localCapabilityPrefix = localDeviceId + RESOURCE_SEPARATOR + prefix; - CapabilityInfoManager::GetInstance()->GetDataByKeyPrefix(localCapabilityPrefix, capabilityInfoMap); + if (CapabilityInfoManager::GetInstance() != nullptr) { + CapabilityInfoManager::GetInstance()->GetDataByKeyPrefix(localCapabilityPrefix, capabilityInfoMap); + } } } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/localhardwaremanager/plugin_listener_impl.cpp b/services/distributedhardwarefwkservice/src/localhardwaremanager/plugin_listener_impl.cpp index 103b836c..1e270bd3 100644 --- a/services/distributedhardwarefwkservice/src/localhardwaremanager/plugin_listener_impl.cpp +++ b/services/distributedhardwarefwkservice/src/localhardwaremanager/plugin_listener_impl.cpp @@ -47,7 +47,10 @@ void PluginListenerImpl::PluginHardware(const std::string &dhId, const std::stri std::shared_ptr dhCapabilityInfo = std::make_shared(dhId, deviceId, devName, devType, dhType_, attrs, subtype); capabilityInfos.push_back(dhCapabilityInfo); - + if (CapabilityInfoManager::GetInstance() == nullptr) { + DHLOGE("cap getinstance is nullptr"); + return; + } CapabilityInfoManager::GetInstance()->AddCapability(capabilityInfos); Publisher::GetInstance().PublishMessage(DHTopic::TOPIC_PHY_DEV_PLUGIN, dhId); DHLOGI("plugin end, dhId: %{public}s", GetAnonyString(dhId).c_str()); @@ -64,6 +67,10 @@ void PluginListenerImpl::UnPluginHardware(const std::string &dhId) DHLOGI("System is in sleeping, drop it"); return; } + if (CapabilityInfoManager::GetInstance() == nullptr) { + DHLOGE("cap getinstance is nullptr"); + return; + } std::string deviceId = DHContext::GetInstance().GetDeviceInfo().deviceId; std::shared_ptr capability = nullptr; auto ret = CapabilityInfoManager::GetInstance()->GetCapability(deviceId, dhId, capability); diff --git a/services/distributedhardwarefwkservice/src/lowlatency/low_latency.cpp b/services/distributedhardwarefwkservice/src/lowlatency/low_latency.cpp index d8a6ba67..21653183 100644 --- a/services/distributedhardwarefwkservice/src/lowlatency/low_latency.cpp +++ b/services/distributedhardwarefwkservice/src/lowlatency/low_latency.cpp @@ -49,7 +49,7 @@ void LowLatency::EnableLowLatency(DHType dhType) { DHLOGI("Start EnableLowLatency dhType: %{public}#X", dhType); if (dhType <= DHType::UNKNOWN || dhType >= DHType::MAX_DH) { - DHLOGE("DHType is invalid, dhType: %{public}" PRIu32, (uint32_t)dhType); + DHLOGE("DHType is invalid, dhType: %{public}#X", dhType); return; } std::lock_guard lock(lowLatencyMutex_); @@ -70,7 +70,7 @@ void LowLatency::DisableLowLatency(DHType dhType) { DHLOGI("Start DisableLowLatency dhType: %{public}#X", dhType); if (dhType <= DHType::UNKNOWN || dhType >= DHType::MAX_DH) { - DHLOGE("DHType is invalid, dhType: %{public}" PRIu32, (uint32_t)dhType); + DHLOGE("DHType is invalid, dhType: %{public}#X", dhType); return; } std::lock_guard lock(lowLatencyMutex_); diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp index 0693a52c..938160ec 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp @@ -238,6 +238,7 @@ HWTEST_F(ComponentManagerTest, get_enableparam_test_001, TestSize.Level0) std::make_shared(DH_ID_1, devInfo.deviceId, DEVICE_NAME, TEST_DEV_TYPE_PAD, DHType::CAMERA, DH_ATTR_1, DH_SUBTYPE_TEST); + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); CapabilityInfoManager::GetInstance()->Init(); std::vector> resInfos { CAP_INFO_1 }; CapabilityInfoManager::GetInstance()->AddCapability(resInfos); @@ -254,6 +255,7 @@ HWTEST_F(ComponentManagerTest, get_enableparam_test_001, TestSize.Level0) verInfo1.dhVersion = VERSION_1; verInfo1.compVersions.insert(std::pair(compVersions1.dhType, compVersions1)); + ASSERT_NE(nullptr, VersionInfoManager::GetInstance()); VersionInfoManager::GetInstance()->Init(); VersionInfoManager::GetInstance()->AddVersion(verInfo1); @@ -520,6 +522,7 @@ HWTEST_F(ComponentManagerTest, GetDHType_001, TestSize.Level0) */ HWTEST_F(ComponentManagerTest, GetDHType_002, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); std::string key = Sha256(UUID_TEST) + RESOURCE_SEPARATOR + DH_ID_1; CapabilityInfoManager::GetInstance()->globalCapInfoMap_[key] = CAP_INFO_TEST; auto ret = ComponentManager::GetInstance().GetDHType(UUID_TEST, DH_ID_1); @@ -551,6 +554,7 @@ HWTEST_F(ComponentManagerTest, GetEnableParam_001, TestSize.Level0) */ HWTEST_F(ComponentManagerTest, GetEnableParam_002, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); DHType dhType = DHType::CAMERA; EnableParam param; CapabilityInfoManager::GetInstance()->globalCapInfoMap_.clear(); @@ -631,6 +635,7 @@ HWTEST_F(ComponentManagerTest, GetVersionFromVerInfoMgr_001, TestSize.Level0) */ HWTEST_F(ComponentManagerTest, GetVersionFromVerInfoMgr_002, TestSize.Level0) { + ASSERT_NE(nullptr, VersionInfoManager::GetInstance()); DHType dhType = DHType::CAMERA; std::string sinkVersion; VersionInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_monitior/src/component_monitor_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_monitior/src/component_monitor_test.cpp index fd957429..6b7fa5e4 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_monitior/src/component_monitor_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_monitior/src/component_monitor_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -41,6 +41,7 @@ void ComponentMonitorTest::SetUp() void ComponentMonitorTest::TearDown() { + ASSERT_NE(nullptr, compMonitorPtr_); compMonitorPtr_->saListeners_.clear(); compMonitorPtr_ = nullptr; } @@ -53,6 +54,7 @@ void ComponentMonitorTest::TearDown() */ HWTEST_F(ComponentMonitorTest, AddSAMonitor_001, TestSize.Level0) { + ASSERT_NE(nullptr, compMonitorPtr_); int32_t saId = static_cast(DHType::AUDIO); compMonitorPtr_->AddSAMonitor(saId); EXPECT_EQ(false, compMonitorPtr_->saListeners_.empty()); @@ -66,6 +68,7 @@ HWTEST_F(ComponentMonitorTest, AddSAMonitor_001, TestSize.Level0) */ HWTEST_F(ComponentMonitorTest, AddSAMonitor_002, TestSize.Level0) { + ASSERT_NE(nullptr, compMonitorPtr_); int32_t saId = static_cast(DHType::CAMERA); sptr listener = new ComponentMonitor::CompSystemAbilityListener(); compMonitorPtr_->saListeners_.insert(std::make_pair(saId, listener)); @@ -81,6 +84,7 @@ HWTEST_F(ComponentMonitorTest, AddSAMonitor_002, TestSize.Level0) */ HWTEST_F(ComponentMonitorTest, RemoveSAMonitor_001, TestSize.Level0) { + ASSERT_NE(nullptr, compMonitorPtr_); int32_t saId = static_cast(DHType::GPS); compMonitorPtr_->RemoveSAMonitor(saId); EXPECT_EQ(true, compMonitorPtr_->saListeners_.empty()); @@ -94,6 +98,7 @@ HWTEST_F(ComponentMonitorTest, RemoveSAMonitor_001, TestSize.Level0) */ HWTEST_F(ComponentMonitorTest, RemoveSAMonitor_002, TestSize.Level0) { + ASSERT_NE(nullptr, compMonitorPtr_); int32_t saId = static_cast(DHType::CAMERA); sptr listener = new ComponentMonitor::CompSystemAbilityListener(); compMonitorPtr_->saListeners_.insert(std::make_pair(saId, listener)); @@ -110,6 +115,8 @@ HWTEST_F(ComponentMonitorTest, RemoveSAMonitor_002, TestSize.Level0) HWTEST_F(ComponentMonitorTest, OnRemoveSystemAbility_001, TestSize.Level0) { sptr listener = new ComponentMonitor::CompSystemAbilityListener(); + ASSERT_NE(nullptr, compMonitorPtr_); + ASSERT_NE(nullptr, listener); int32_t saId = static_cast(DHType::UNKNOWN); std::string deviceId; compMonitorPtr_->AddSAMonitor(saId); @@ -126,6 +133,8 @@ HWTEST_F(ComponentMonitorTest, OnRemoveSystemAbility_001, TestSize.Level0) HWTEST_F(ComponentMonitorTest, OnRemoveSystemAbility_002, TestSize.Level0) { sptr listener = new ComponentMonitor::CompSystemAbilityListener(); + ASSERT_NE(nullptr, compMonitorPtr_); + ASSERT_NE(nullptr, listener); int32_t saId = static_cast(DHType::CAMERA); std::string deviceId; compMonitorPtr_->AddSAMonitor(saId); diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_privacy/component_privacy_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_privacy/component_privacy_test.cpp index ee105696..4c07f6cb 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_privacy/component_privacy_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_privacy/component_privacy_test.cpp @@ -58,6 +58,7 @@ void ComponentPrivacyTest::TearDown() HWTEST_F(ComponentPrivacyTest, OnPrivaceResourceMessage_001, TestSize.Level0) { + ASSERT_NE(nullptr, compPrivacy_); ResourceEventType type = ResourceEventType::EVENT_TYPE_QUERY_RESOURCE; std::string subtype = "mic"; std::string networkId = "networkId_test"; @@ -69,6 +70,7 @@ HWTEST_F(ComponentPrivacyTest, OnPrivaceResourceMessage_001, TestSize.Level0) HWTEST_F(ComponentPrivacyTest, OnPrivaceResourceMessage_002, TestSize.Level0) { + ASSERT_NE(nullptr, compPrivacy_); ResourceEventType type = ResourceEventType::EVENT_TYPE_PULL_UP_PAGE; std::string subtype = "mic"; std::string networkId = "networkId_test"; @@ -80,6 +82,7 @@ HWTEST_F(ComponentPrivacyTest, OnPrivaceResourceMessage_002, TestSize.Level0) HWTEST_F(ComponentPrivacyTest, OnPrivaceResourceMessage_003, TestSize.Level0) { + ASSERT_NE(nullptr, compPrivacy_); ResourceEventType type = ResourceEventType::EVENT_TYPE_CLOSE_PAGE; std::string subtype = "mic"; std::string networkId = "networkId_test"; @@ -91,6 +94,7 @@ HWTEST_F(ComponentPrivacyTest, OnPrivaceResourceMessage_003, TestSize.Level0) HWTEST_F(ComponentPrivacyTest, OnResourceInfoCallback_001, TestSize.Level0) { + ASSERT_NE(nullptr, compPrivacy_); std::string subtype = "mic"; std::string networkId = "networkId_test"; bool isSensitive = true; @@ -102,6 +106,7 @@ HWTEST_F(ComponentPrivacyTest, OnResourceInfoCallback_001, TestSize.Level0) HWTEST_F(ComponentPrivacyTest, DeviceTypeToString_001, TestSize.Level0) { + ASSERT_NE(nullptr, compPrivacy_); uint16_t deviceTypeId = 0x08; std::string ret = compPrivacy_->DeviceTypeToString(deviceTypeId); EXPECT_EQ("camera", ret); diff --git a/services/distributedhardwarefwkservice/test/unittest/common/dbadapter/src/db_adapter_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/dbadapter/src/db_adapter_test.cpp index cb8a6ab9..f3e412ae 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/dbadapter/src/db_adapter_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/dbadapter/src/db_adapter_test.cpp @@ -137,6 +137,7 @@ void DbAdapterTest::TearDown() */ HWTEST_F(DbAdapterTest, db_adapter_test_000, TestSize.Level0) { + ASSERT_NE(nullptr, g_dbAdapterPtr); EXPECT_EQ(DH_FWK_SUCCESS, g_dbAdapterPtr->Init(true, DistributedKv::DataType::TYPE_DYNAMICAL)); } @@ -148,6 +149,7 @@ HWTEST_F(DbAdapterTest, db_adapter_test_000, TestSize.Level0) */ HWTEST_F(DbAdapterTest, db_adapter_test_001, TestSize.Level0) { + ASSERT_NE(nullptr, g_dbAdapterPtr); vector> resInfos { CAP_INFO_0, CAP_INFO_1, CAP_INFO_2, CAP_INFO_3, CAP_INFO_4, CAP_INFO_5, CAP_INFO_6, CAP_INFO_7, CAP_INFO_8, CAP_INFO_9 }; @@ -173,6 +175,7 @@ HWTEST_F(DbAdapterTest, db_adapter_test_001, TestSize.Level0) */ HWTEST_F(DbAdapterTest, db_adapter_test_002, TestSize.Level0) { + ASSERT_NE(nullptr, g_dbAdapterPtr); std::vector keys { std::string(TEST_DEV_ID_2 + TEST_DH_ID_0) }; std::vector values { TEST_DH_ATTR_0 }; @@ -188,6 +191,7 @@ HWTEST_F(DbAdapterTest, db_adapter_test_002, TestSize.Level0) */ HWTEST_F(DbAdapterTest, db_adapter_test_003, TestSize.Level0) { + ASSERT_NE(nullptr, g_dbAdapterPtr); std::vector keys { std::string(TEST_DEV_ID_2 + TEST_DH_ID_0) }; std::vector valuesEmpty; @@ -202,6 +206,7 @@ HWTEST_F(DbAdapterTest, db_adapter_test_003, TestSize.Level0) */ HWTEST_F(DbAdapterTest, db_adapter_test_004, TestSize.Level0) { + ASSERT_NE(nullptr, g_dbAdapterPtr); std::vector keysEmpty; std::vector values { TEST_DH_ATTR_0 }; @@ -216,6 +221,7 @@ HWTEST_F(DbAdapterTest, db_adapter_test_004, TestSize.Level0) */ HWTEST_F(DbAdapterTest, db_adapter_test_005, TestSize.Level0) { + ASSERT_NE(nullptr, g_dbAdapterPtr); std::vector keysEmpty; std::vector valuesEmpty; @@ -230,6 +236,7 @@ HWTEST_F(DbAdapterTest, db_adapter_test_005, TestSize.Level0) */ HWTEST_F(DbAdapterTest, db_adapter_test_006, TestSize.Level0) { + ASSERT_NE(nullptr, g_dbAdapterPtr); std::vector keys { std::string(TEST_DEV_ID_2 + TEST_DH_ID_0) }; std::vector values { TEST_DH_ATTR_0, TEST_DH_ATTR_1 }; @@ -244,6 +251,7 @@ HWTEST_F(DbAdapterTest, db_adapter_test_006, TestSize.Level0) */ HWTEST_F(DbAdapterTest, db_adapter_test_007, TestSize.Level0) { + ASSERT_NE(nullptr, g_dbAdapterPtr); g_dbAdapterPtr->kvStoragePtr_ = nullptr; std::vector keys { std::string(TEST_DEV_ID_2 + TEST_DH_ID_0) }; std::vector values { TEST_DH_ATTR_0 }; @@ -259,6 +267,7 @@ HWTEST_F(DbAdapterTest, db_adapter_test_007, TestSize.Level0) */ HWTEST_F(DbAdapterTest, db_adapter_test_008, TestSize.Level0) { + ASSERT_NE(nullptr, g_dbAdapterPtr); g_dbAdapterPtr->kvStoragePtr_ = nullptr; EXPECT_EQ(ERR_DH_FWK_RESOURCE_KV_STORAGE_POINTER_NULL, g_dbAdapterPtr->ReInit(true)); } @@ -271,6 +280,7 @@ HWTEST_F(DbAdapterTest, db_adapter_test_008, TestSize.Level0) */ HWTEST_F(DbAdapterTest, db_adapter_test_009, TestSize.Level0) { + ASSERT_NE(nullptr, g_dbAdapterPtr); g_dbAdapterPtr->kvStoragePtr_ = nullptr; EXPECT_EQ(ERR_DH_FWK_RESOURCE_KV_STORAGE_POINTER_NULL, g_dbAdapterPtr->RemoveDeviceData(TEST_DEV_ID_0)); } @@ -283,6 +293,7 @@ HWTEST_F(DbAdapterTest, db_adapter_test_009, TestSize.Level0) */ HWTEST_F(DbAdapterTest, db_adapter_test_010, TestSize.Level0) { + ASSERT_NE(nullptr, g_dbAdapterPtr); g_dbAdapterPtr->kvStoragePtr_ = nullptr; EXPECT_EQ(ERR_DH_FWK_RESOURCE_KV_STORAGE_POINTER_NULL, g_dbAdapterPtr->RemoveDataByKey("key")); } @@ -295,6 +306,7 @@ HWTEST_F(DbAdapterTest, db_adapter_test_010, TestSize.Level0) */ HWTEST_F(DbAdapterTest, db_adapter_test_012, TestSize.Level0) { + ASSERT_NE(nullptr, g_dbAdapterPtr); g_dbAdapterPtr->kvStoragePtr_ = nullptr; EXPECT_EQ(ERR_DH_FWK_RESOURCE_KV_STORAGE_POINTER_NULL, g_dbAdapterPtr->UnRegisterChangeListener()); } @@ -307,6 +319,7 @@ HWTEST_F(DbAdapterTest, db_adapter_test_012, TestSize.Level0) */ HWTEST_F(DbAdapterTest, db_adapter_test_013, TestSize.Level0) { + ASSERT_NE(nullptr, g_dbAdapterPtr); std::string key = std::string(TEST_DEV_ID_1 + TEST_DH_ID_1); std::string value = TEST_DH_ATTR_0; g_dbAdapterPtr->kvStoragePtr_ = nullptr; @@ -321,6 +334,7 @@ HWTEST_F(DbAdapterTest, db_adapter_test_013, TestSize.Level0) */ HWTEST_F(DbAdapterTest, db_adapter_test_014, TestSize.Level0) { + ASSERT_NE(nullptr, g_dbAdapterPtr); std::string networkId = DEV_NETWORK_ID_1; g_dbAdapterPtr->kvStoragePtr_ = nullptr; EXPECT_EQ(ERR_DH_FWK_RESOURCE_KV_STORAGE_POINTER_NULL, g_dbAdapterPtr->RegisterChangeListener()); @@ -334,6 +348,7 @@ HWTEST_F(DbAdapterTest, db_adapter_test_014, TestSize.Level0) */ HWTEST_F(DbAdapterTest, db_adapter_test_015, TestSize.Level0) { + ASSERT_NE(nullptr, g_dbAdapterPtr); g_dbAdapterPtr->kvStoragePtr_ = nullptr; EXPECT_EQ(ERR_DH_FWK_RESOURCE_KV_STORAGE_POINTER_NULL, g_dbAdapterPtr->UnRegisterChangeListener()); } @@ -346,6 +361,7 @@ HWTEST_F(DbAdapterTest, db_adapter_test_015, TestSize.Level0) */ HWTEST_F(DbAdapterTest, ReInit_001, TestSize.Level0) { + ASSERT_NE(nullptr, g_dbAdapterPtr); g_dbAdapterPtr->GetKvStorePtr(true, DistributedKv::DataType::TYPE_DYNAMICAL); EXPECT_EQ(DH_FWK_SUCCESS, g_dbAdapterPtr->ReInit(true)); } @@ -358,6 +374,7 @@ HWTEST_F(DbAdapterTest, ReInit_001, TestSize.Level0) */ HWTEST_F(DbAdapterTest, RemoveDeviceData_001, TestSize.Level0) { + ASSERT_NE(nullptr, g_dbAdapterPtr); g_dbAdapterPtr->GetKvStorePtr(true, DistributedKv::DataType::TYPE_DYNAMICAL); EXPECT_EQ(ERR_DH_FWK_RESOURCE_KV_STORAGE_OPERATION_FAIL, g_dbAdapterPtr->RemoveDeviceData(TEST_DEV_ID_0)); } @@ -370,6 +387,7 @@ HWTEST_F(DbAdapterTest, RemoveDeviceData_001, TestSize.Level0) */ HWTEST_F(DbAdapterTest, PutData_01, TestSize.Level0) { + ASSERT_NE(nullptr, g_dbAdapterPtr); std::string key; std::string value; EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, g_dbAdapterPtr->PutData(key, value)); @@ -383,6 +401,7 @@ HWTEST_F(DbAdapterTest, PutData_01, TestSize.Level0) */ HWTEST_F(DbAdapterTest, PutData_02, TestSize.Level0) { + ASSERT_NE(nullptr, g_dbAdapterPtr); uint32_t MAX_MESSAGE_LEN = 40 * 1024 * 1024 +1 ; std::string key = "key"; key.resize(MAX_MESSAGE_LEN); @@ -398,6 +417,7 @@ HWTEST_F(DbAdapterTest, PutData_02, TestSize.Level0) */ HWTEST_F(DbAdapterTest, PutData_03, TestSize.Level0) { + ASSERT_NE(nullptr, g_dbAdapterPtr); std::string key = "key"; std::string value; EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, g_dbAdapterPtr->PutData(key, value)); @@ -411,6 +431,7 @@ HWTEST_F(DbAdapterTest, PutData_03, TestSize.Level0) */ HWTEST_F(DbAdapterTest, PutData_04, TestSize.Level0) { + ASSERT_NE(nullptr, g_dbAdapterPtr); uint32_t MAX_MESSAGE_LEN = 40 * 1024 * 1024 + 1; std::string key = "key"; std::string value; @@ -426,6 +447,7 @@ HWTEST_F(DbAdapterTest, PutData_04, TestSize.Level0) */ HWTEST_F(DbAdapterTest, PutData_05, TestSize.Level0) { + ASSERT_NE(nullptr, g_dbAdapterPtr); std::string key = "key"; std::string value = "value"; g_dbAdapterPtr->kvStoragePtr_ = nullptr; 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 8bea9a48..12b5b493 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 @@ -45,6 +45,7 @@ void DistributedHardwareStubTest::TearDown() */ HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_001, TestSize.Level0) { + ASSERT_NE(nullptr, stubTest_); uint32_t code = 0; MessageParcel data; MessageParcel reply; @@ -60,6 +61,7 @@ HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_001, TestSize.Level0) */ HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_002, TestSize.Level0) { + ASSERT_NE(nullptr, stubTest_); uint32_t code = 0; MessageParcel data; MessageParcel reply; @@ -69,6 +71,7 @@ HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_002, TestSize.Level0) HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_003, TestSize.Level0) { + ASSERT_NE(nullptr, stubTest_); uint32_t code = static_cast(DHMsgInterfaceCode::REG_PUBLISHER_LISTNER); MessageParcel data; MessageParcel reply; @@ -82,6 +85,7 @@ HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_003, TestSize.Level0) HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_004, TestSize.Level0) { + ASSERT_NE(nullptr, stubTest_); uint32_t code = static_cast(DHMsgInterfaceCode::PUBLISH_MESSAGE); MessageParcel data; MessageParcel reply; @@ -95,6 +99,7 @@ HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_004, TestSize.Level0) HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_005, TestSize.Level0) { + ASSERT_NE(nullptr, stubTest_); uint32_t code = static_cast(DHMsgInterfaceCode::INIT_CTL_CEN); MessageParcel data; MessageParcel reply; @@ -108,6 +113,7 @@ HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_005, TestSize.Level0) HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_006, TestSize.Level0) { + ASSERT_NE(nullptr, stubTest_); uint32_t code = static_cast(DHMsgInterfaceCode::RELEASE_CTL_CEN); MessageParcel data; MessageParcel reply; @@ -121,6 +127,7 @@ HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_006, TestSize.Level0) HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_007, TestSize.Level0) { + ASSERT_NE(nullptr, stubTest_); uint32_t code = static_cast(DHMsgInterfaceCode::CREATE_CTL_CEN_CHANNEL); MessageParcel data; MessageParcel reply; @@ -136,6 +143,7 @@ HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_007, TestSize.Level0) HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_008, TestSize.Level0) { + ASSERT_NE(nullptr, stubTest_); uint32_t code = static_cast(DHMsgInterfaceCode::NOTIFY_AV_EVENT); MessageParcel data; MessageParcel reply; @@ -155,6 +163,7 @@ HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_008, TestSize.Level0) HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_009, TestSize.Level0) { + ASSERT_NE(nullptr, stubTest_); uint32_t code = static_cast(DHMsgInterfaceCode::QUERY_LOCAL_SYS_SPEC); MessageParcel data; MessageParcel reply; @@ -168,6 +177,7 @@ HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_009, TestSize.Level0) HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_010, TestSize.Level0) { + ASSERT_NE(nullptr, stubTest_); uint32_t code = static_cast(DHMsgInterfaceCode::NOTIFY_SOURCE_DEVICE_REMOTE_DMSDP_STARTED); MessageParcel data; MessageParcel reply; @@ -181,6 +191,7 @@ HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_010, TestSize.Level0) HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_011, TestSize.Level0) { + ASSERT_NE(nullptr, stubTest_); uint32_t code = static_cast(DHMsgInterfaceCode::PAUSE_DISTRIBUTED_HARDWARE); MessageParcel data; MessageParcel reply; @@ -192,6 +203,7 @@ HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_011, TestSize.Level0) HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_012, TestSize.Level0) { + ASSERT_NE(nullptr, stubTest_); uint32_t code = static_cast(DHMsgInterfaceCode::RESUME_DISTRIBUTED_HARDWARE); MessageParcel data; MessageParcel reply; @@ -203,6 +215,7 @@ HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_012, TestSize.Level0) HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_013, TestSize.Level0) { + ASSERT_NE(nullptr, stubTest_); uint32_t code = static_cast(DHMsgInterfaceCode::STOP_DISTRIBUTED_HARDWARE); MessageParcel data; MessageParcel reply; @@ -214,6 +227,7 @@ HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_013, TestSize.Level0) HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_014, TestSize.Level0) { + ASSERT_NE(nullptr, stubTest_); uint32_t code = static_cast(DHMsgInterfaceCode::UNREG_PUBLISHER_LISTENER); MessageParcel data; MessageParcel reply; @@ -233,6 +247,7 @@ HWTEST_F(DistributedHardwareStubTest, OnRemoteRequest_014, TestSize.Level0) */ HWTEST_F(DistributedHardwareStubTest, RegisterPublisherListenerInner_001, TestSize.Level0) { + ASSERT_NE(nullptr, stubTest_); MessageParcel data; MessageParcel reply; EXPECT_NE(DH_FWK_SUCCESS, stubTest_->RegisterPublisherListenerInner(data, reply)); @@ -246,6 +261,7 @@ HWTEST_F(DistributedHardwareStubTest, RegisterPublisherListenerInner_001, TestSi */ HWTEST_F(DistributedHardwareStubTest, UnregisterPublisherListenerInner_001, TestSize.Level0) { + ASSERT_NE(nullptr, stubTest_); MessageParcel data; MessageParcel reply; EXPECT_NE(DH_FWK_SUCCESS, stubTest_->UnregisterPublisherListenerInner(data, reply)); @@ -259,6 +275,7 @@ HWTEST_F(DistributedHardwareStubTest, UnregisterPublisherListenerInner_001, Test */ HWTEST_F(DistributedHardwareStubTest, PublishMessageInner_001, TestSize.Level0) { + ASSERT_NE(nullptr, stubTest_); MessageParcel data; MessageParcel reply; EXPECT_NE(DH_FWK_SUCCESS, stubTest_->PublishMessageInner(data, reply)); @@ -272,6 +289,7 @@ HWTEST_F(DistributedHardwareStubTest, PublishMessageInner_001, TestSize.Level0) */ HWTEST_F(DistributedHardwareStubTest, ValidTopic_001, TestSize.Level0) { + ASSERT_NE(nullptr, stubTest_); uint32_t topic = static_cast(DHTopic::TOPIC_MIN); EXPECT_EQ(false, stubTest_->ValidTopic(topic)); @@ -290,6 +308,7 @@ HWTEST_F(DistributedHardwareStubTest, ValidTopic_001, TestSize.Level0) */ HWTEST_F(DistributedHardwareStubTest, ValidQueryLocalSpec_001, TestSize.Level0) { + ASSERT_NE(nullptr, stubTest_); uint32_t spec = 1; EXPECT_EQ(true, stubTest_->ValidQueryLocalSpec(spec)); } @@ -302,6 +321,7 @@ HWTEST_F(DistributedHardwareStubTest, ValidQueryLocalSpec_001, TestSize.Level0) */ HWTEST_F(DistributedHardwareStubTest, ValidQueryLocalSpec_002, TestSize.Level0) { + ASSERT_NE(nullptr, stubTest_); uint32_t spec = 0; EXPECT_EQ(false, stubTest_->ValidQueryLocalSpec(spec)); spec = 5; diff --git a/services/distributedhardwarefwkservice/test/unittest/common/hidumphelper/hidumphelper/src/hidump_helper_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/hidumphelper/hidumphelper/src/hidump_helper_test.cpp index 1e5442c4..5b956e4e 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/hidumphelper/hidumphelper/src/hidump_helper_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/hidumphelper/hidumphelper/src/hidump_helper_test.cpp @@ -214,6 +214,7 @@ HWTEST_F(HidumpHelperTest, ShowAllCapabilityInfos_001, TestSize.Level0) */ HWTEST_F(HidumpHelperTest, ShowAllCapabilityInfos_002, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); std::string result; std::string key = "1"; std::string devId = "devId_test"; 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 index f8005e6f..a99eafc0 100644 --- 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 @@ -46,6 +46,7 @@ void PublisherListenerProxyTest::TearDown() */ HWTEST_F(PublisherListenerProxyTest, OnMessage_001, TestSize.Level0) { + ASSERT_NE(nullptr, proxy_); uint32_t invalid = 8; DHTopic topic = static_cast(invalid); std::string message; @@ -61,6 +62,7 @@ HWTEST_F(PublisherListenerProxyTest, OnMessage_001, TestSize.Level0) */ HWTEST_F(PublisherListenerProxyTest, OnMessage_002, TestSize.Level0) { + ASSERT_NE(nullptr, proxy_); DHTopic topic = DHTopic::TOPIC_START_DSCREEN; std::string message; proxy_->OnMessage(topic, message); @@ -75,6 +77,7 @@ HWTEST_F(PublisherListenerProxyTest, OnMessage_002, TestSize.Level0) */ HWTEST_F(PublisherListenerProxyTest, OnMessage_003, TestSize.Level0) { + ASSERT_NE(nullptr, proxy_); DHTopic topic = DHTopic::TOPIC_START_DSCREEN; std::string message = "message"; proxy_->OnMessage(topic, message); 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 2ea50727..872d9bcd 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -51,6 +51,7 @@ void PluginListenerImplTest::TearDown() {} */ HWTEST_F(PluginListenerImplTest, plugin_listener_impl_test_001, TestSize.Level0) { + ASSERT_NE(nullptr, g_mockHardwareHandler); g_mockHardwareHandler->RegisterPluginListener(g_listener); EXPECT_EQ(g_mockHardwareHandler->PluginHardware(dhId, attrs, subtype), DH_FWK_SUCCESS); } @@ -63,6 +64,7 @@ HWTEST_F(PluginListenerImplTest, plugin_listener_impl_test_001, TestSize.Level0) */ HWTEST_F(PluginListenerImplTest, plugin_listener_impl_test_002, TestSize.Level0) { + ASSERT_NE(nullptr, g_mockHardwareHandler); EXPECT_EQ(g_mockHardwareHandler->UnPluginHardware(dhId), DH_FWK_SUCCESS); g_mockHardwareHandler->UnRegisterPluginListener(); } diff --git a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/src/low_latency_listener_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/src/low_latency_listener_test.cpp index d790496b..e16c9424 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/src/low_latency_listener_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/src/low_latency_listener_test.cpp @@ -46,6 +46,7 @@ void LowLatencyListenerTest::TearDown() */ HWTEST_F(LowLatencyListenerTest, OnMessage_001, TestSize.Level0) { + ASSERT_NE(nullptr, listener_); DHTopic topic = DHTopic::TOPIC_MIN; std::string message; listener_->OnMessage(topic, message); @@ -60,6 +61,7 @@ HWTEST_F(LowLatencyListenerTest, OnMessage_001, TestSize.Level0) */ HWTEST_F(LowLatencyListenerTest, OnMessage_002, TestSize.Level0) { + ASSERT_NE(nullptr, listener_); DHTopic topic = DHTopic::TOPIC_START_DSCREEN; std::string message; listener_->OnMessage(topic, message); @@ -74,6 +76,7 @@ HWTEST_F(LowLatencyListenerTest, OnMessage_002, TestSize.Level0) */ HWTEST_F(LowLatencyListenerTest, OnMessage_003, TestSize.Level0) { + ASSERT_NE(nullptr, listener_); DHTopic topic = DHTopic::TOPIC_START_DSCREEN; std::string message = "message"; listener_->OnMessage(topic, message); @@ -88,6 +91,7 @@ HWTEST_F(LowLatencyListenerTest, OnMessage_003, TestSize.Level0) */ HWTEST_F(LowLatencyListenerTest, OnMessage_004, TestSize.Level0) { + ASSERT_NE(nullptr, listener_); DHTopic topic = DHTopic::TOPIC_START_DSCREEN; cJSON* json = cJSON_CreateObject(); @@ -112,6 +116,7 @@ HWTEST_F(LowLatencyListenerTest, OnMessage_004, TestSize.Level0) */ HWTEST_F(LowLatencyListenerTest, OnMessage_005, TestSize.Level0) { + ASSERT_NE(nullptr, listener_); DHTopic topic = DHTopic::TOPIC_START_DSCREEN; std::string message; uint32_t MAX_MESSAGE_LEN = 40 * 1024 * 1024; @@ -128,6 +133,7 @@ HWTEST_F(LowLatencyListenerTest, OnMessage_005, TestSize.Level0) */ HWTEST_F(LowLatencyListenerTest, OnMessage_006, TestSize.Level0) { + ASSERT_NE(nullptr, listener_); DHTopic topic = DHTopic::TOPIC_START_DSCREEN; cJSON* json = cJSON_CreateObject(); const char* DH_TYPE = "dh_type"; @@ -150,6 +156,7 @@ HWTEST_F(LowLatencyListenerTest, OnMessage_006, TestSize.Level0) */ HWTEST_F(LowLatencyListenerTest, OnMessage_007, TestSize.Level0) { + ASSERT_NE(nullptr, listener_); DHTopic topic = DHTopic::TOPIC_START_DSCREEN; cJSON* json = cJSON_CreateObject(); const char* DH_TYPE = "dh_type"; @@ -172,6 +179,7 @@ HWTEST_F(LowLatencyListenerTest, OnMessage_007, TestSize.Level0) */ HWTEST_F(LowLatencyListenerTest, ExecuteInner_008, TestSize.Level0) { + ASSERT_NE(nullptr, listener_); std::string timerId; int32_t delayTimeMs = 1; LowLatencyTimer timer(timerId, delayTimeMs); @@ -187,6 +195,7 @@ HWTEST_F(LowLatencyListenerTest, ExecuteInner_008, TestSize.Level0) */ HWTEST_F(LowLatencyListenerTest, HandleStopTimer_008, TestSize.Level0) { + ASSERT_NE(nullptr, listener_); std::string timerId; int32_t delayTimeMs = 1; LowLatencyTimer timer(timerId, delayTimeMs); diff --git a/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp index 7d842a73..c996774a 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp @@ -120,6 +120,7 @@ void ResourceManagerTest::TearDownTestCase(void) void ResourceManagerTest::SetUp() { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); vector> resInfos { CAP_INFO_0, CAP_INFO_1, CAP_INFO_2, CAP_INFO_3, CAP_INFO_4, CAP_INFO_5, CAP_INFO_6, CAP_INFO_7, CAP_INFO_8, CAP_INFO_9 }; CapabilityInfoManager::GetInstance()->AddCapability(resInfos); @@ -127,6 +128,7 @@ void ResourceManagerTest::SetUp() void ResourceManagerTest::TearDown() { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); CapabilityInfoManager::GetInstance()->RemoveCapabilityInfoByKey(CAP_INFO_0->GetKey()); CapabilityInfoManager::GetInstance()->RemoveCapabilityInfoByKey(CAP_INFO_1->GetKey()); CapabilityInfoManager::GetInstance()->RemoveCapabilityInfoByKey(CAP_INFO_2->GetKey()); @@ -147,6 +149,7 @@ void ResourceManagerTest::TearDown() */ HWTEST_F(ResourceManagerTest, resource_manager_test_001, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); EXPECT_EQ(CapabilityInfoManager::GetInstance()->Init(), DH_FWK_SUCCESS); EXPECT_EQ(CapabilityInfoManager::GetInstance()->UnInit(), DH_FWK_SUCCESS); } @@ -159,6 +162,7 @@ HWTEST_F(ResourceManagerTest, resource_manager_test_001, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, resource_manager_test_002, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); EXPECT_EQ(CapabilityInfoManager::GetInstance()->Init(), DH_FWK_SUCCESS); } @@ -170,6 +174,7 @@ HWTEST_F(ResourceManagerTest, resource_manager_test_002, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, resource_manager_test_003, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); CapabilityInfoManager::GetInstance()->globalCapInfoMap_.clear(); EXPECT_EQ(CapabilityInfoManager::GetInstance()->SyncDeviceInfoFromDB(DEV_ID_0), DH_FWK_SUCCESS); EXPECT_EQ(CapabilityInfoManager::GetInstance()->globalCapInfoMap_.size(), TEST_SIZE_5); @@ -185,6 +190,7 @@ HWTEST_F(ResourceManagerTest, resource_manager_test_003, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, resource_manager_test_004, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); CapabilityInfoManager::GetInstance()->globalCapInfoMap_.clear(); EXPECT_EQ(CapabilityInfoManager::GetInstance()->SyncRemoteCapabilityInfos(), DH_FWK_SUCCESS); } @@ -197,6 +203,7 @@ HWTEST_F(ResourceManagerTest, resource_manager_test_004, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, resource_manager_test_005, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); vector> resInfos { CAP_INFO_0, CAP_INFO_1, CAP_INFO_2, CAP_INFO_3, CAP_INFO_4, CAP_INFO_5, CAP_INFO_6, CAP_INFO_7, CAP_INFO_8, CAP_INFO_9 }; EXPECT_EQ(CapabilityInfoManager::GetInstance()->AddCapability(resInfos), DH_FWK_SUCCESS); @@ -211,6 +218,7 @@ HWTEST_F(ResourceManagerTest, resource_manager_test_005, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, resource_manager_test_006, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); vector> resInfos { CAP_INFO_0, CAP_INFO_1, CAP_INFO_2, CAP_INFO_3, CAP_INFO_4, CAP_INFO_5, CAP_INFO_6, CAP_INFO_7, CAP_INFO_8, CAP_INFO_9 }; EXPECT_EQ(CapabilityInfoManager::GetInstance()->AddCapabilityInMem(resInfos), DH_FWK_SUCCESS); @@ -226,6 +234,7 @@ HWTEST_F(ResourceManagerTest, resource_manager_test_006, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, resource_manager_test_007, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); EXPECT_EQ(CapabilityInfoManager::GetInstance()->RemoveCapabilityInfoByKey(CAP_INFO_0->GetKey()), DH_FWK_SUCCESS); EXPECT_EQ(CapabilityInfoManager::GetInstance()->RemoveCapabilityInfoByKey(CAP_INFO_1->GetKey()), DH_FWK_SUCCESS); EXPECT_EQ(CapabilityInfoManager::GetInstance()->RemoveCapabilityInfoByKey(CAP_INFO_2->GetKey()), DH_FWK_SUCCESS); @@ -247,6 +256,7 @@ HWTEST_F(ResourceManagerTest, resource_manager_test_007, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, resource_manager_test_008, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); map queryMap0 { { CapabilityInfoFilter::FILTER_DEVICE_ID, DEV_ID_0 } }; map queryMap1 { { CapabilityInfoFilter::FILTER_DEVICE_ID, DEV_ID_1 } }; map queryMap2 { { CapabilityInfoFilter::FILTER_DEVICE_NAME, TEST_DEV_NAME } }; @@ -291,6 +301,7 @@ HWTEST_F(ResourceManagerTest, resource_manager_test_008, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, resource_manager_test_009, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); EXPECT_EQ(CapabilityInfoManager::GetInstance()->HasCapability(DEV_ID_0, DH_ID_0), true); EXPECT_EQ(CapabilityInfoManager::GetInstance()->HasCapability(DEV_ID_0, DH_ID_1), true); EXPECT_EQ(CapabilityInfoManager::GetInstance()->HasCapability(DEV_ID_0, DH_ID_2), true); @@ -311,6 +322,7 @@ HWTEST_F(ResourceManagerTest, resource_manager_test_009, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, resource_manager_test_010, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); vector> capInfos; CapabilityInfoManager::GetInstance()->GetCapabilitiesByDeviceId(DEV_ID_0, capInfos); EXPECT_EQ(capInfos.size(), TEST_SIZE_5); @@ -326,6 +338,7 @@ HWTEST_F(ResourceManagerTest, resource_manager_test_010, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, resource_manager_test_011, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); shared_ptr capInfo; EXPECT_EQ(CapabilityInfoManager::GetInstance()->GetCapability(DEV_ID_0, DH_ID_0, capInfo), DH_FWK_SUCCESS); EXPECT_EQ(CapabilityInfoManager::GetInstance()->GetCapability(DEV_ID_0, DH_ID_1, capInfo), DH_FWK_SUCCESS); @@ -347,6 +360,7 @@ HWTEST_F(ResourceManagerTest, resource_manager_test_011, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, resource_manager_test_012, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); shared_ptr capInfo; EXPECT_EQ(CapabilityInfoManager::GetInstance()->GetDataByKey(CAP_INFO_0->GetKey(), capInfo), DH_FWK_SUCCESS); EXPECT_EQ(CapabilityInfoManager::GetInstance()->GetDataByKey(CAP_INFO_1->GetKey(), capInfo), DH_FWK_SUCCESS); @@ -368,6 +382,7 @@ HWTEST_F(ResourceManagerTest, resource_manager_test_012, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, resource_manager_test_013, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); CapabilityInfoMap capMap; EXPECT_EQ(CapabilityInfoManager::GetInstance()->GetDataByKeyPrefix(CAP_INFO_0->GetDeviceId(), capMap), DH_FWK_SUCCESS); @@ -400,6 +415,7 @@ HWTEST_F(ResourceManagerTest, resource_manager_test_013, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, resource_manager_test_014, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); std::string deviceIdEmpty = ""; int32_t ret = CapabilityInfoManager::GetInstance()->RemoveCapabilityInfoInDB(deviceIdEmpty); EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); @@ -495,6 +511,7 @@ HWTEST_F(ResourceManagerTest, resource_manager_test_020, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, OnChange_001, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); DistributedKv::Entry insert, update, del; insert.key = "strBase"; update.key = "strBase"; @@ -521,6 +538,7 @@ HWTEST_F(ResourceManagerTest, OnChange_001, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, OnChange_002, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); DistributedKv::DataOrigin origin; origin.id = {}; origin.store = ""; @@ -540,6 +558,7 @@ HWTEST_F(ResourceManagerTest, OnChange_002, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, HandleCapabilityAddChange_001, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); std::vector insertRecords; DistributedKv::Entry entry; entry.key = "strBase"; @@ -557,6 +576,7 @@ HWTEST_F(ResourceManagerTest, HandleCapabilityAddChange_001, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, HandleCapabilityUpdateChange_001, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); std::vector updateRecords; DistributedKv::Entry entry; entry.key = "strBase"; @@ -574,6 +594,7 @@ HWTEST_F(ResourceManagerTest, HandleCapabilityUpdateChange_001, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, IsCapabilityMatchFilter_001, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); std::shared_ptr cap = nullptr; CapabilityInfoFilter filter = CapabilityInfoFilter::FILTER_DH_ID; std::string value; @@ -589,6 +610,7 @@ HWTEST_F(ResourceManagerTest, IsCapabilityMatchFilter_001, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, IsCapabilityMatchFilter_002, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); std::shared_ptr cap = std::make_shared("", "", "", 0, DHType::UNKNOWN, "", ""); CapabilityInfoFilter filter = CapabilityInfoFilter::FILTER_DH_ID; std::string value; @@ -604,6 +626,7 @@ HWTEST_F(ResourceManagerTest, IsCapabilityMatchFilter_002, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, IsCapabilityMatchFilter_003, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); std::shared_ptr cap = std::make_shared("", "", "", 0, DHType::UNKNOWN, "", ""); CapabilityInfoFilter filter = CapabilityInfoFilter::FILTER_DEVICE_ID; std::string value; @@ -619,6 +642,7 @@ HWTEST_F(ResourceManagerTest, IsCapabilityMatchFilter_003, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, IsCapabilityMatchFilter_004, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); std::shared_ptr cap = std::make_shared("", "", "", 0, DHType::UNKNOWN, "", ""); CapabilityInfoFilter filter = CapabilityInfoFilter::FILTER_DEVICE_NAME; std::string value; @@ -634,6 +658,7 @@ HWTEST_F(ResourceManagerTest, IsCapabilityMatchFilter_004, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, IsCapabilityMatchFilter_005, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); std::shared_ptr cap = std::make_shared("", "", "", 0, DHType::UNKNOWN, "", ""); CapabilityInfoFilter filter = CapabilityInfoFilter::FILTER_DEVICE_TYPE; uint16_t devType = 123; @@ -650,6 +675,7 @@ HWTEST_F(ResourceManagerTest, IsCapabilityMatchFilter_005, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, IsCapabilityMatchFilter_006, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); std::shared_ptr cap = std::make_shared("", "", "", 0, DHType::UNKNOWN, "", ""); CapabilityInfoFilter filter = CapabilityInfoFilter::FILTER_DH_TYPE; DHType dhType = DHType::AUDIO; @@ -666,6 +692,7 @@ HWTEST_F(ResourceManagerTest, IsCapabilityMatchFilter_006, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, IsCapabilityMatchFilter_007, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); std::shared_ptr cap = std::make_shared("", "", "", 0, DHType::UNKNOWN, "", ""); CapabilityInfoFilter filter = CapabilityInfoFilter::FILTER_DH_ATTRS; std::string value; @@ -681,6 +708,7 @@ HWTEST_F(ResourceManagerTest, IsCapabilityMatchFilter_007, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, IsCapabilityMatchFilter_008, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); std::shared_ptr cap = std::make_shared("", "", "", 0, DHType::UNKNOWN, "", ""); uint32_t invalid = 6; CapabilityInfoFilter filter = static_cast(invalid); @@ -697,6 +725,7 @@ HWTEST_F(ResourceManagerTest, IsCapabilityMatchFilter_008, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, GetCapabilitiesByDeviceId_001, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); std::string deviceId; std::vector> resInfos; CapabilityInfoManager::GetInstance()->GetCapabilitiesByDeviceId(deviceId, resInfos); @@ -711,6 +740,7 @@ HWTEST_F(ResourceManagerTest, GetCapabilitiesByDeviceId_001, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, HasCapability_001, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); std::string deviceId; std::string dhId; bool ret = CapabilityInfoManager::GetInstance()->HasCapability(deviceId, dhId); @@ -725,6 +755,7 @@ HWTEST_F(ResourceManagerTest, HasCapability_001, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, SyncRemoteCapabilityInfos_001, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); CapabilityInfoManager::GetInstance()->globalCapInfoMap_.clear(); CapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; int32_t ret = CapabilityInfoManager::GetInstance()->SyncRemoteCapabilityInfos(); @@ -739,6 +770,7 @@ HWTEST_F(ResourceManagerTest, SyncRemoteCapabilityInfos_001, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, RemoveCapabilityInfoInDB_001, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); std::string deviceIdEmpty; uint32_t MAX_ID_LEN = 257; deviceIdEmpty.resize(MAX_ID_LEN); @@ -754,6 +786,7 @@ HWTEST_F(ResourceManagerTest, RemoveCapabilityInfoInDB_001, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, RemoveCapabilityInfoInDB_002, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); std::string deviceIdEmpty = "deviceIdEmpty"; CapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; int32_t ret = CapabilityInfoManager::GetInstance()->RemoveCapabilityInfoInDB(deviceIdEmpty); @@ -768,6 +801,7 @@ HWTEST_F(ResourceManagerTest, RemoveCapabilityInfoInDB_002, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, HandleCapabilityDeleteChange_001, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); std::vector deleteRecords; DistributedKv::Entry entry; entry.key = "strBase"; @@ -785,6 +819,7 @@ HWTEST_F(ResourceManagerTest, HandleCapabilityDeleteChange_001, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, GetDataByKey_001, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); std::string key; std::shared_ptr capInfoPtr; CapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; @@ -800,6 +835,7 @@ HWTEST_F(ResourceManagerTest, GetDataByKey_001, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, GetDataByKeyPrefix_001, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); std::string keyPrefix; CapabilityInfoMap capabilityMap; CapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; @@ -815,6 +851,7 @@ HWTEST_F(ResourceManagerTest, GetDataByKeyPrefix_001, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, DumpCapabilityInfos_001, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); std::vector capInfos; std::string dhId; std::string devId; @@ -878,6 +915,7 @@ HWTEST_F(ResourceManagerTest, FromJson_001, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, GetEntriesByKeys_001, TestSize.Level0) { + ASSERT_NE(nullptr, CapabilityInfoManager::GetInstance()); std::vector keys {}; auto entries = CapabilityInfoManager::GetInstance()->GetEntriesByKeys(keys); EXPECT_EQ(0, entries.size()); @@ -885,12 +923,14 @@ HWTEST_F(ResourceManagerTest, GetEntriesByKeys_001, TestSize.Level0) HWTEST_F(ResourceManagerTest, Init_001, TestSize.Level0) { + ASSERT_NE(nullptr, LocalCapabilityInfoManager::GetInstance()); auto ret = LocalCapabilityInfoManager::GetInstance()->Init(); EXPECT_EQ(DH_FWK_SUCCESS, ret); } HWTEST_F(ResourceManagerTest, UnInit_001, TestSize.Level0) { + ASSERT_NE(nullptr, LocalCapabilityInfoManager::GetInstance()); LocalCapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; auto ret = LocalCapabilityInfoManager::GetInstance()->UnInit(); EXPECT_EQ(ERR_DH_FWK_RESOURCE_UNINIT_DB_FAILED, ret); @@ -898,6 +938,7 @@ HWTEST_F(ResourceManagerTest, UnInit_001, TestSize.Level0) HWTEST_F(ResourceManagerTest, UnInit_002, TestSize.Level0) { + ASSERT_NE(nullptr, LocalCapabilityInfoManager::GetInstance()); LocalCapabilityInfoManager::GetInstance()->Init(); auto ret = LocalCapabilityInfoManager::GetInstance()->UnInit(); EXPECT_EQ(DH_FWK_SUCCESS, ret); @@ -905,6 +946,7 @@ HWTEST_F(ResourceManagerTest, UnInit_002, TestSize.Level0) HWTEST_F(ResourceManagerTest, SyncDeviceInfoFromDB_001, TestSize.Level0) { + ASSERT_NE(nullptr, LocalCapabilityInfoManager::GetInstance()); std::string deviceId = "deviceId_test"; LocalCapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; auto ret = LocalCapabilityInfoManager::GetInstance()->SyncDeviceInfoFromDB(deviceId); @@ -917,6 +959,7 @@ HWTEST_F(ResourceManagerTest, SyncDeviceInfoFromDB_001, TestSize.Level0) HWTEST_F(ResourceManagerTest, RemoveCapabilityInfoByKey_001, TestSize.Level0) { + ASSERT_NE(nullptr, LocalCapabilityInfoManager::GetInstance()); std::string key = "deviceId_test"; LocalCapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; auto ret = LocalCapabilityInfoManager::GetInstance()->RemoveCapabilityInfoByKey(key); @@ -929,6 +972,7 @@ HWTEST_F(ResourceManagerTest, RemoveCapabilityInfoByKey_001, TestSize.Level0) HWTEST_F(ResourceManagerTest, GetCapability_001, TestSize.Level0) { + ASSERT_NE(nullptr, LocalCapabilityInfoManager::GetInstance()); std::string deviceId = "deviceId_test"; std::string dhId = "dhId_test"; std::shared_ptr capPtr; @@ -947,6 +991,7 @@ HWTEST_F(ResourceManagerTest, GetCapability_001, TestSize.Level0) HWTEST_F(ResourceManagerTest, GetDataByKey_002, TestSize.Level0) { + ASSERT_NE(nullptr, LocalCapabilityInfoManager::GetInstance()); std::string key = "key_test"; std::shared_ptr capPtr; LocalCapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; @@ -960,6 +1005,7 @@ HWTEST_F(ResourceManagerTest, GetDataByKey_002, TestSize.Level0) HWTEST_F(ResourceManagerTest, GetDataByDHType_001, TestSize.Level0) { + ASSERT_NE(nullptr, LocalCapabilityInfoManager::GetInstance()); CapabilityInfoMap capabilityMap; std::string deviceId = "deviceId_test"; std::shared_ptr capbilityInfo = std::make_shared( @@ -976,6 +1022,7 @@ HWTEST_F(ResourceManagerTest, GetDataByDHType_001, TestSize.Level0) HWTEST_F(ResourceManagerTest, GetDataByKeyPrefix_002, TestSize.Level0) { + ASSERT_NE(nullptr, LocalCapabilityInfoManager::GetInstance()); std::string keyPrefix = "keyPrefix_test"; CapabilityInfoMap capabilityMap; LocalCapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; @@ -989,6 +1036,7 @@ HWTEST_F(ResourceManagerTest, GetDataByKeyPrefix_002, TestSize.Level0) HWTEST_F(ResourceManagerTest, UnInit_003, TestSize.Level0) { + ASSERT_NE(nullptr, MetaInfoManager::GetInstance()); MetaInfoManager::GetInstance()->Init(); auto ret = MetaInfoManager::GetInstance()->UnInit(); EXPECT_EQ(DH_FWK_SUCCESS, ret); @@ -996,6 +1044,7 @@ HWTEST_F(ResourceManagerTest, UnInit_003, TestSize.Level0) HWTEST_F(ResourceManagerTest, AddMetaCapInfos_001, TestSize.Level0) { + ASSERT_NE(nullptr, MetaInfoManager::GetInstance()); std::string deviceId = "deviceId_test"; std::string udidHash = "udidHash_test"; std::string dhId = "dhId_test"; @@ -1010,6 +1059,7 @@ HWTEST_F(ResourceManagerTest, AddMetaCapInfos_001, TestSize.Level0) HWTEST_F(ResourceManagerTest, SyncMetaInfoFromDB_001, TestSize.Level0) { + ASSERT_NE(nullptr, MetaInfoManager::GetInstance()); std::string deviceId = "deviceId_test"; MetaInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; auto ret = MetaInfoManager::GetInstance()->SyncMetaInfoFromDB(deviceId); @@ -1022,6 +1072,7 @@ HWTEST_F(ResourceManagerTest, SyncMetaInfoFromDB_001, TestSize.Level0) HWTEST_F(ResourceManagerTest, SyncRemoteMetaInfos_001, TestSize.Level0) { + ASSERT_NE(nullptr, MetaInfoManager::GetInstance()); MetaInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; auto ret = MetaInfoManager::GetInstance()->SyncRemoteMetaInfos(); EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret); @@ -1033,6 +1084,7 @@ HWTEST_F(ResourceManagerTest, SyncRemoteMetaInfos_001, TestSize.Level0) HWTEST_F(ResourceManagerTest, GetDataByKeyPrefix_003, TestSize.Level0) { + ASSERT_NE(nullptr, MetaInfoManager::GetInstance()); std::string keyPrefix = "keyPrefix_test"; MetaCapInfoMap metaCapMap; MetaInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; @@ -1046,6 +1098,7 @@ HWTEST_F(ResourceManagerTest, GetDataByKeyPrefix_003, TestSize.Level0) HWTEST_F(ResourceManagerTest, RemoveMetaInfoByKey_001, TestSize.Level0) { + ASSERT_NE(nullptr, MetaInfoManager::GetInstance()); std::string key = "key_test"; MetaInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; auto ret = MetaInfoManager::GetInstance()->RemoveMetaInfoByKey(key); @@ -1058,6 +1111,7 @@ HWTEST_F(ResourceManagerTest, RemoveMetaInfoByKey_001, TestSize.Level0) HWTEST_F(ResourceManagerTest, GetMetaCapInfo_001, TestSize.Level0) { + ASSERT_NE(nullptr, MetaInfoManager::GetInstance()); std::string deviceId = "deviceId_test"; std::string udidHash = "udidHash_test"; std::string dhId = "dhId_test"; @@ -1086,6 +1140,7 @@ HWTEST_F(ResourceManagerTest, GetMetaCapInfo_001, TestSize.Level0) HWTEST_F(ResourceManagerTest, GetMetaCapByValue_001, TestSize.Level0) { + ASSERT_NE(nullptr, MetaInfoManager::GetInstance()); std::string value = ""; std::shared_ptr metaCapPtr = nullptr; auto ret = MetaInfoManager::GetInstance()->GetMetaCapByValue(value, metaCapPtr); @@ -1102,6 +1157,7 @@ HWTEST_F(ResourceManagerTest, GetMetaCapByValue_001, TestSize.Level0) HWTEST_F(ResourceManagerTest, GetEntriesByKeys_002, TestSize.Level0) { + ASSERT_NE(nullptr, MetaInfoManager::GetInstance()); std::vector keys; auto ret = MetaInfoManager::GetInstance()->GetEntriesByKeys(keys); EXPECT_EQ(0, ret.size()); @@ -1118,6 +1174,7 @@ HWTEST_F(ResourceManagerTest, GetEntriesByKeys_002, TestSize.Level0) HWTEST_F(ResourceManagerTest, FromJson_002, TestSize.Level0) { + ASSERT_NE(nullptr, MetaInfoManager::GetInstance()); MetaCapabilityInfo metaCapInfo; std::string dhId = "dhId_test"; std::string dveId = "devId_test"; diff --git a/services/distributedhardwarefwkservice/test/unittest/common/task/src/task_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/task/src/task_test.cpp index a4ab9d81..ec8d771b 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/task/src/task_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/task/src/task_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -91,6 +91,7 @@ HWTEST_F(TaskTest, task_test_001, TestSize.Level0) std::shared_ptr onlineTask = std::static_pointer_cast( MockTaskFactory::GetInstance().CreateTask(TaskType::ON_LINE, TASK_PARAM_1, nullptr)); + ASSERT_NE(nullptr, onlineTask); onlineTask->SetOnLineDevInfos({ DEV_INFO_11, DEV_INFO_12, DEV_INFO_13, DEV_INFO_14, DEV_INFO_15 }); TaskExecutor::GetInstance().PushTask(onlineTask); @@ -108,10 +109,12 @@ HWTEST_F(TaskTest, task_test_002, TestSize.Level0) { std::shared_ptr onlineTask1 = std::static_pointer_cast( MockTaskFactory::GetInstance().CreateTask(TaskType::ON_LINE, TASK_PARAM_1, nullptr)); + ASSERT_NE(nullptr, onlineTask1); onlineTask1->SetOnLineDevInfos({ DEV_INFO_11, DEV_INFO_12, DEV_INFO_13, DEV_INFO_14, DEV_INFO_15 }); std::shared_ptr onlineTask2 = std::static_pointer_cast( MockTaskFactory::GetInstance().CreateTask(TaskType::ON_LINE, TASK_PARAM_2, nullptr)); + ASSERT_NE(nullptr, onlineTask2); onlineTask2->SetOnLineDevInfos({ DEV_INFO_21, DEV_INFO_22, DEV_INFO_23, DEV_INFO_24, DEV_INFO_25 }); TaskExecutor::GetInstance().PushTask(onlineTask1); @@ -132,6 +135,7 @@ HWTEST_F(TaskTest, task_test_003, TestSize.Level0) std::shared_ptr offlineTask = std::static_pointer_cast( MockTaskFactory::GetInstance().CreateTask(TaskType::OFF_LINE, TASK_PARAM_1, nullptr)); + ASSERT_NE(nullptr, offlineTask); offlineTask->SetOffLineDevInfos({ DEV_INFO_11, DEV_INFO_12, DEV_INFO_13, DEV_INFO_14, DEV_INFO_15 }); TaskExecutor::GetInstance().PushTask(offlineTask); @@ -150,11 +154,13 @@ HWTEST_F(TaskTest, task_test_004, TestSize.Level0) std::shared_ptr onlineTask = std::static_pointer_cast( MockTaskFactory::GetInstance().CreateTask(TaskType::ON_LINE, TASK_PARAM_1, nullptr)); + ASSERT_NE(nullptr, onlineTask); onlineTask->SetOnLineDevInfos({ DEV_INFO_11, DEV_INFO_12, DEV_INFO_13, DEV_INFO_14, DEV_INFO_15 }); std::shared_ptr offlineTask = std::static_pointer_cast( MockTaskFactory::GetInstance().CreateTask(TaskType::OFF_LINE, TASK_PARAM_1, nullptr)); + ASSERT_NE(nullptr, offlineTask); offlineTask->SetOffLineDevInfos({ DEV_INFO_11, DEV_INFO_12, DEV_INFO_13, DEV_INFO_14, DEV_INFO_15 }); TaskExecutor::GetInstance().PushTask(onlineTask); @@ -325,6 +331,7 @@ HWTEST_F(TaskTest, task_test_016, TestSize.Level0) { TaskParam taskParam; auto task = TaskFactory::GetInstance().CreateTask(TaskType::DISABLE, taskParam, nullptr); + ASSERT_NE(nullptr, task); task->DoTask(); ASSERT_TRUE(task->childrenTasks_.empty()); } @@ -339,6 +346,7 @@ HWTEST_F(TaskTest, task_test_017, TestSize.Level0) { TaskParam taskParam; auto task = TaskFactory::GetInstance().CreateTask(TaskType::ENABLE, taskParam, nullptr); + ASSERT_NE(nullptr, task); task->DoTask(); ASSERT_TRUE(task->childrenTasks_.empty()); } @@ -353,6 +361,7 @@ HWTEST_F(TaskTest, task_test_018, TestSize.Level0) { TaskParam taskParam; auto task = TaskFactory::GetInstance().CreateTask(TaskType::OFF_LINE, taskParam, nullptr); + ASSERT_NE(nullptr, task); std::vector taskSteps; taskSteps.push_back(TaskStep::UNREGISTER_OFFLINE_DISTRIBUTED_HARDWARE); task->SetTaskSteps(taskSteps); @@ -370,6 +379,7 @@ HWTEST_F(TaskTest, task_test_019, TestSize.Level0) { TaskParam taskParam; auto task = TaskFactory::GetInstance().CreateTask(TaskType::OFF_LINE, taskParam, nullptr); + ASSERT_NE(nullptr, task); std::vector taskSteps; taskSteps.push_back(TaskStep::CLEAR_OFFLINE_INFO); task->SetTaskSteps(taskSteps); @@ -389,6 +399,7 @@ HWTEST_F(TaskTest, task_test_020, TestSize.Level0) DHType::AUDIO); TaskParam taskParam; auto task = TaskFactory::GetInstance().CreateTask(TaskType::OFF_LINE, taskParam, nullptr); + ASSERT_NE(nullptr, task); task->AddChildrenTask(childrenTask); ASSERT_TRUE(task->childrenTasks_.empty()); } diff --git a/services/distributedhardwarefwkservice/test/unittest/common/transport/dh_comm_tool_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/transport/dh_comm_tool_test.cpp index 15445599..9a94ecb5 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/transport/dh_comm_tool_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/transport/dh_comm_tool_test.cpp @@ -59,6 +59,7 @@ void DhCommToolTest::TearDown() HWTEST_F(DhCommToolTest, TriggerReqFullDHCaps_001, TestSize.Level0) { + ASSERT_NE(nullptr, dhCommToolTest_); std::string remoteNetworkId = ""; dhCommToolTest_->TriggerReqFullDHCaps(remoteNetworkId); @@ -76,6 +77,7 @@ HWTEST_F(DhCommToolTest, TriggerReqFullDHCaps_001, TestSize.Level0) HWTEST_F(DhCommToolTest, GetAndSendLocalFullCaps_001, TestSize.Level0) { + ASSERT_NE(nullptr, dhCommToolTest_); std::string reqNetworkId = ""; dhCommToolTest_->dhTransportPtr_ = nullptr; dhCommToolTest_->GetAndSendLocalFullCaps(reqNetworkId); @@ -87,6 +89,7 @@ HWTEST_F(DhCommToolTest, GetAndSendLocalFullCaps_001, TestSize.Level0) HWTEST_F(DhCommToolTest, ParseAndSaveRemoteDHCaps_001, TestSize.Level0) { + ASSERT_NE(nullptr, dhCommToolTest_); std::string remoteCaps = ""; FullCapsRsp ret = dhCommToolTest_->ParseAndSaveRemoteDHCaps(remoteCaps); EXPECT_EQ("", ret.networkId); diff --git a/services/distributedhardwarefwkservice/test/unittest/common/transport/dh_transport_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/transport/dh_transport_test.cpp index d7c42264..8617eda2 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/transport/dh_transport_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/transport/dh_transport_test.cpp @@ -60,6 +60,7 @@ void DhTransportTest::TearDown() HWTEST_F(DhTransportTest, OnSocketClosed_001, TestSize.Level0) { + ASSERT_NE(nullptr, dhTransportTest_); ShutdownReason reason = ShutdownReason::SHUTDOWN_REASON_UNKNOWN; dhTransportTest_->remoteDevSocketIds_[g_networkid] = g_socketid; dhTransportTest_->OnSocketClosed(2, reason); @@ -70,6 +71,7 @@ HWTEST_F(DhTransportTest, OnSocketClosed_001, TestSize.Level0) HWTEST_F(DhTransportTest, OnBytesReceived_001, TestSize.Level0) { + ASSERT_NE(nullptr, dhTransportTest_); int32_t sessionId = -1; char *data = nullptr; uint32_t dataLen = 0; @@ -101,6 +103,7 @@ HWTEST_F(DhTransportTest, OnBytesReceived_001, TestSize.Level0) HWTEST_F(DhTransportTest, Init_001, TestSize.Level0) { + ASSERT_NE(nullptr, dhTransportTest_); dhTransportTest_->isSocketSvrCreateFlag_ = true; auto ret = dhTransportTest_->Init(); EXPECT_EQ(DH_FWK_SUCCESS, ret); @@ -112,6 +115,7 @@ HWTEST_F(DhTransportTest, Init_001, TestSize.Level0) HWTEST_F(DhTransportTest, UnInit_001, TestSize.Level0) { + ASSERT_NE(nullptr, dhTransportTest_); auto ret = dhTransportTest_->UnInit(); EXPECT_EQ(DH_FWK_SUCCESS, ret); @@ -122,6 +126,7 @@ HWTEST_F(DhTransportTest, UnInit_001, TestSize.Level0) HWTEST_F(DhTransportTest, IsDeviceSessionOpened_001, TestSize.Level0) { + ASSERT_NE(nullptr, dhTransportTest_); dhTransportTest_->remoteDevSocketIds_.clear(); auto ret = dhTransportTest_->IsDeviceSessionOpened(g_networkid, g_socketid); EXPECT_EQ(false, ret); @@ -133,6 +138,7 @@ HWTEST_F(DhTransportTest, IsDeviceSessionOpened_001, TestSize.Level0) HWTEST_F(DhTransportTest, StartSocket_001, TestSize.Level0) { + ASSERT_NE(nullptr, dhTransportTest_); dhTransportTest_->remoteDevSocketIds_[g_networkid] = g_socketid; auto ret = dhTransportTest_->StartSocket(g_networkid); EXPECT_EQ(DH_FWK_SUCCESS, ret); @@ -144,6 +150,7 @@ HWTEST_F(DhTransportTest, StartSocket_001, TestSize.Level0) HWTEST_F(DhTransportTest, StopSocket_001, TestSize.Level0) { + ASSERT_NE(nullptr, dhTransportTest_); dhTransportTest_->remoteDevSocketIds_.clear(); auto ret = dhTransportTest_->StopSocket(g_networkid); EXPECT_EQ(ERR_DH_FWK_COMPONENT_TRANSPORT_OPT_FAILED, ret); @@ -155,6 +162,7 @@ HWTEST_F(DhTransportTest, StopSocket_001, TestSize.Level0) HWTEST_F(DhTransportTest, Send_001, TestSize.Level0) { + ASSERT_NE(nullptr, dhTransportTest_); std::string payload = "payload_test"; dhTransportTest_->remoteDevSocketIds_.clear(); auto ret = dhTransportTest_->Send(g_networkid, payload); diff --git a/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/versioninfomanager/src/version_info_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/versioninfomanager/src/version_info_manager_test.cpp index 8a60817f..832922dc 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/versioninfomanager/src/version_info_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/versioninfomanager/src/version_info_manager_test.cpp @@ -131,6 +131,7 @@ void VersionInfoManagerTest::TearDown() */ HWTEST_F(VersionInfoManagerTest, version_info_manager_test_001, TestSize.Level0) { + ASSERT_NE(nullptr, VersionInfoManager::GetInstance()); EXPECT_EQ(VersionInfoManager::GetInstance()->Init(), DH_FWK_SUCCESS); } @@ -142,6 +143,7 @@ HWTEST_F(VersionInfoManagerTest, version_info_manager_test_001, TestSize.Level0) */ HWTEST_F(VersionInfoManagerTest, version_info_manager_test_002, TestSize.Level0) { + ASSERT_NE(nullptr, VersionInfoManager::GetInstance()); for (const auto& verInfo : g_versionInfos) { EXPECT_EQ(VersionInfoManager::GetInstance()->AddVersion(verInfo), DH_FWK_SUCCESS); } @@ -155,6 +157,7 @@ HWTEST_F(VersionInfoManagerTest, version_info_manager_test_002, TestSize.Level0) */ HWTEST_F(VersionInfoManagerTest, version_info_manager_test_003, TestSize.Level0) { + ASSERT_NE(nullptr, VersionInfoManager::GetInstance()); VersionInfo versionInfo; for (const auto& verInfo : g_versionInfos) { EXPECT_EQ(VersionInfoManager::GetInstance()->GetVersionInfoByDeviceId(verInfo.deviceId, versionInfo), @@ -170,6 +173,7 @@ HWTEST_F(VersionInfoManagerTest, version_info_manager_test_003, TestSize.Level0) */ HWTEST_F(VersionInfoManagerTest, version_info_manager_test_004, TestSize.Level0) { + ASSERT_NE(nullptr, VersionInfoManager::GetInstance()); EXPECT_EQ(VersionInfoManager::GetInstance()->SyncVersionInfoFromDB(DEV_ID_1), DH_FWK_SUCCESS); } @@ -181,6 +185,7 @@ HWTEST_F(VersionInfoManagerTest, version_info_manager_test_004, TestSize.Level0) */ HWTEST_F(VersionInfoManagerTest, version_info_manager_test_005, TestSize.Level0) { + ASSERT_NE(nullptr, VersionInfoManager::GetInstance()); EXPECT_EQ(VersionInfoManager::GetInstance()->UnInit(), DH_FWK_SUCCESS); } @@ -192,6 +197,7 @@ HWTEST_F(VersionInfoManagerTest, version_info_manager_test_005, TestSize.Level0) */ HWTEST_F(VersionInfoManagerTest, UpdateVersionCache_001, TestSize.Level0) { + ASSERT_NE(nullptr, VersionInfoManager::GetInstance()); VersionInfo versionInfo; versionInfo.deviceId = "deviceId"; versionInfo.dhVersion = "dhVersion"; @@ -207,6 +213,7 @@ HWTEST_F(VersionInfoManagerTest, UpdateVersionCache_001, TestSize.Level0) */ HWTEST_F(VersionInfoManagerTest, UpdateVersionCache_002, TestSize.Level0) { + ASSERT_NE(nullptr, VersionInfoManager::GetInstance()); VersionInfo versionInfo; VersionInfoManager::GetInstance()->UpdateVersionCache(versionInfo); EXPECT_EQ(DH_FWK_SUCCESS, VersionInfoManager::GetInstance()->Init()); @@ -220,6 +227,7 @@ HWTEST_F(VersionInfoManagerTest, UpdateVersionCache_002, TestSize.Level0) */ HWTEST_F(VersionInfoManagerTest, RemoveVersionInfoByDeviceId_001, TestSize.Level0) { + ASSERT_NE(nullptr, VersionInfoManager::GetInstance()); std::string deviceId; VersionInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; int32_t ret = VersionInfoManager::GetInstance()->RemoveVersionInfoByDeviceId(deviceId); @@ -234,6 +242,7 @@ HWTEST_F(VersionInfoManagerTest, RemoveVersionInfoByDeviceId_001, TestSize.Level */ HWTEST_F(VersionInfoManagerTest, RemoveVersionInfoByDeviceId_002, TestSize.Level0) { + ASSERT_NE(nullptr, VersionInfoManager::GetInstance()); std::string deviceId = "deviceId"; std::string appId; std::string storeId; @@ -251,6 +260,7 @@ HWTEST_F(VersionInfoManagerTest, RemoveVersionInfoByDeviceId_002, TestSize.Level */ HWTEST_F(VersionInfoManagerTest, SyncVersionInfoFromDB_001, TestSize.Level0) { + ASSERT_NE(nullptr, VersionInfoManager::GetInstance()); std::string deviceId; VersionInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; int32_t ret = VersionInfoManager::GetInstance()->SyncVersionInfoFromDB(deviceId); @@ -265,6 +275,7 @@ HWTEST_F(VersionInfoManagerTest, SyncVersionInfoFromDB_001, TestSize.Level0) */ HWTEST_F(VersionInfoManagerTest, SyncVersionInfoFromDB_002, TestSize.Level0) { + ASSERT_NE(nullptr, VersionInfoManager::GetInstance()); std::string deviceId = "deviceId"; std::string appId; std::string storeId; @@ -282,6 +293,7 @@ HWTEST_F(VersionInfoManagerTest, SyncVersionInfoFromDB_002, TestSize.Level0) */ HWTEST_F(VersionInfoManagerTest, SyncVersionInfoFromDB_003, TestSize.Level0) { + ASSERT_NE(nullptr, VersionInfoManager::GetInstance()); std::string deviceId = "device"; int32_t ret = VersionInfoManager::GetInstance()->SyncVersionInfoFromDB(deviceId); EXPECT_NE(DH_FWK_SUCCESS, ret); @@ -295,6 +307,7 @@ HWTEST_F(VersionInfoManagerTest, SyncVersionInfoFromDB_003, TestSize.Level0) */ HWTEST_F(VersionInfoManagerTest, SyncRemoteVersionInfos_001, TestSize.Level0) { + ASSERT_NE(nullptr, VersionInfoManager::GetInstance()); VersionInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; int32_t ret = VersionInfoManager::GetInstance()->SyncRemoteVersionInfos(); EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret); @@ -308,6 +321,7 @@ HWTEST_F(VersionInfoManagerTest, SyncRemoteVersionInfos_001, TestSize.Level0) */ HWTEST_F(VersionInfoManagerTest, SyncRemoteVersionInfos_002, TestSize.Level0) { + ASSERT_NE(nullptr, VersionInfoManager::GetInstance()); std::string appId; std::string storeId; std::shared_ptr changeListener = nullptr; @@ -324,6 +338,7 @@ HWTEST_F(VersionInfoManagerTest, SyncRemoteVersionInfos_002, TestSize.Level0) */ HWTEST_F(VersionInfoManagerTest, OnChange_001, TestSize.Level0) { + ASSERT_NE(nullptr, VersionInfoManager::GetInstance()); DistributedKv::Entry insert, update, del; insert.key = "strBase"; update.key = "strBase"; @@ -350,6 +365,7 @@ HWTEST_F(VersionInfoManagerTest, OnChange_001, TestSize.Level0) */ HWTEST_F(VersionInfoManagerTest, HandleVersionAddChange_001, TestSize.Level0) { + ASSERT_NE(nullptr, VersionInfoManager::GetInstance()); std::vector insertRecords; DistributedKv::Entry entry; entry.key = "strBase"; @@ -367,6 +383,7 @@ HWTEST_F(VersionInfoManagerTest, HandleVersionAddChange_001, TestSize.Level0) */ HWTEST_F(VersionInfoManagerTest, HandleVersionUpdateChange_001, TestSize.Level0) { + ASSERT_NE(nullptr, VersionInfoManager::GetInstance()); std::vector updateRecords; DistributedKv::Entry entry; entry.key = "strBase"; @@ -384,6 +401,7 @@ HWTEST_F(VersionInfoManagerTest, HandleVersionUpdateChange_001, TestSize.Level0) */ HWTEST_F(VersionInfoManagerTest, HandleVersionDeleteChange_001, TestSize.Level0) { + ASSERT_NE(nullptr, VersionInfoManager::GetInstance()); std::vector deleteRecords; DistributedKv::Entry entry; entry.key = "strBase"; @@ -401,6 +419,7 @@ HWTEST_F(VersionInfoManagerTest, HandleVersionDeleteChange_001, TestSize.Level0) */ HWTEST_F(VersionInfoManagerTest, GetVersionInfoByDeviceId_001, TestSize.Level0) { + ASSERT_NE(nullptr, VersionInfoManager::GetInstance()); std::string deviceId; VersionInfo versionInfo; VersionInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; -- Gitee