diff --git a/old/services/core/test/unittest/event_subscribe_test.cpp b/old/services/core/test/unittest/event_subscribe_test.cpp index a605f2e51c68bffe757cde7cd7de487262e75c16..2cfaab34d87103748230c998b3d0cc75699aab4c 100644 --- a/old/services/core/test/unittest/event_subscribe_test.cpp +++ b/old/services/core/test/unittest/event_subscribe_test.cpp @@ -29,6 +29,9 @@ using namespace std::chrono_literals; using namespace testing; using namespace testing::ext; +namespace { +const int32_t UT_ERROR = -1; +} class EventSubscribeTest : public testing::Test { public: static void SetUpTestCase(); @@ -117,6 +120,9 @@ int32_t PutFakeSystem() int32_t MockSubscribeEvents(const std::shared_ptr& eventCb, const std::list& serviceIds, const std::string& deviceId) { + if (eventCb == nullptr) { + return UT_ERROR; + } eventCb->SetSubServiceIds(serviceIds); ExtraInfo extraInfo; extraInfo["deviceId"] = deviceId; @@ -139,6 +145,9 @@ int32_t MockSubscribeEvents(const std::shared_ptr& eventCb int32_t MockUnsubscribeEvents(const std::shared_ptr& eventCb) { + if (eventCb == nullptr) { + return UT_ERROR; + } std::list profileEvents; profileEvents.emplace_back(ProfileEvent::EVENT_PROFILE_CHANGED); profileEvents.emplace_back(ProfileEvent::EVENT_SYNC_COMPLETED); @@ -150,6 +159,9 @@ int32_t MockUnsubscribeEvents(const std::shared_ptr& event int32_t MockSubscribeEvent(const std::shared_ptr& eventCb, const std::list& serviceIds, const std::string& deviceId) { + if (eventCb == nullptr) { + return UT_ERROR; + } eventCb->SetSubServiceIds(serviceIds); ExtraInfo extraInfo; extraInfo["deviceId"] = deviceId; diff --git a/old/services/core/test/unittest/profile_event_notifier_proxy_test.cpp b/old/services/core/test/unittest/profile_event_notifier_proxy_test.cpp index 5813e964fe37d009de423199dcb148d6685454fc..8ab53223f421dffe820136d82fca26a0c3ee7be2 100644 --- a/old/services/core/test/unittest/profile_event_notifier_proxy_test.cpp +++ b/old/services/core/test/unittest/profile_event_notifier_proxy_test.cpp @@ -69,6 +69,7 @@ HWTEST_F(ProfileEventNotifierProxyTest, OnSyncCompleted_001, TestSize.Level3) auto syncCb = std::make_shared(); sptr stub(new ProfileEventNotifierStub(syncCb)); sptr proxy(new ProfileEventNotifierProxy(stub)); + ASSERT_NE(proxy, nullptr); SyncResult syncResults; proxy->OnSyncCompleted(syncResults); EXPECT_EQ(syncCb->result, 0); @@ -85,6 +86,7 @@ HWTEST_F(ProfileEventNotifierProxyTest, OnSyncCompleted_002, TestSize.Level3) auto syncCb = std::make_shared(); sptr stub(new ProfileEventNotifierStub(syncCb)); sptr proxy(new ProfileEventNotifierProxy(stub)); + ASSERT_NE(proxy, nullptr); SyncResult syncResults; syncResults.emplace("testdeviceid", SUCCEEDED); proxy->OnSyncCompleted(syncResults); @@ -102,6 +104,7 @@ HWTEST_F(ProfileEventNotifierProxyTest, OnProfileChanged_001, TestSize.Level3) auto syncCb = std::make_shared(); sptr stub(new ProfileEventNotifierStub(syncCb)); sptr proxy(new ProfileEventNotifierProxy(stub)); + ASSERT_NE(proxy, nullptr); ProfileChangeNotification notification; proxy->OnProfileChanged(notification); EXPECT_EQ(syncCb->result, 0); diff --git a/services/core/src/distributed_device_profile_service_new.cpp b/services/core/src/distributed_device_profile_service_new.cpp index bbe8f574c5973e1c8028d102464fa7fc26b2602c..4f4d2a1243b3edc6af036b7216c3f6ae996a3fb8 100644 --- a/services/core/src/distributed_device_profile_service_new.cpp +++ b/services/core/src/distributed_device_profile_service_new.cpp @@ -545,6 +545,9 @@ void DistributedDeviceProfileServiceNew::DelayUnloadTask() } HILOGI("kill dp svr success!"); }; + if (unloadHandler_ == nullptr) { + return; + } unloadHandler_->RemoveTask(UNLOAD_TASK_ID); HILOGI("delay unload task post task"); unloadHandler_->PostTask(task, UNLOAD_TASK_ID, DELAY_TIME); diff --git a/services/core/test/unittest/distributed_device_profile_client_rdb_test.cpp b/services/core/test/unittest/distributed_device_profile_client_rdb_test.cpp index 82e9cd17aa0c6f08a24d2b01276aa2dbcc243a2d..25b4adea3a98f37abd3ac2c4fe93c136e6e8912d 100644 --- a/services/core/test/unittest/distributed_device_profile_client_rdb_test.cpp +++ b/services/core/test/unittest/distributed_device_profile_client_rdb_test.cpp @@ -136,7 +136,7 @@ void DistributedDeviceProfileClientRdbTest::TearDown() int DistributedDeviceProfileClientRdbTest::ResultSize(std::shared_ptr &resultSet) { - if (resultSet->GoToFirstRow() != E_OK) { + if (resultSet == nullptr || resultSet->GoToFirstRow() != E_OK) { return 0; } int count; diff --git a/services/core/test/unittest/dp_subscribe_info_test.cpp b/services/core/test/unittest/dp_subscribe_info_test.cpp index b7896d96dffd35b52aa44fc77668ab57cfea8036..2387093ab11f0e764d07a21da8d9c091d79795e1 100644 --- a/services/core/test/unittest/dp_subscribe_info_test.cpp +++ b/services/core/test/unittest/dp_subscribe_info_test.cpp @@ -250,6 +250,7 @@ HWTEST_F(DPSubscribeInfoTest, Stub_001, TestSize.Level1) OHOS::sptr proxy = OHOS::iface_cast(subscribeInfo.GetListener()); TrustDeviceProfile oldTrustProfile; TrustDeviceProfile newTrustProfile; + ASSERT_NE(proxy, nullptr); int32_t ret = proxy->OnTrustDeviceProfileAdd(oldTrustProfile); EXPECT_EQ(ret, DP_SUCCESS); ret = proxy->OnTrustDeviceProfileDelete(oldTrustProfile); diff --git a/services/core/test/unittest/sync_completed_callback_test.cpp b/services/core/test/unittest/sync_completed_callback_test.cpp index 5983d54a6ab5c8e6cb8c0ed9ea48b4337f8170d9..b25733024a1b25d31b8e2ed4341c5e6b7f8571a3 100644 --- a/services/core/test/unittest/sync_completed_callback_test.cpp +++ b/services/core/test/unittest/sync_completed_callback_test.cpp @@ -142,6 +142,7 @@ HWTEST_F(SyncCompletedCallbackStubTest, OnRemoteRequest_003, TestSize.Level3) sptr stub(new SyncCompletedListener()); sptr proxy(new SyncCompletedCallbackProxy(stub)); + ASSERT_NE(proxy, nullptr); syncResults.emplace("testdeviceid", SUCCEEDED); proxy->OnSyncCompleted(syncResults); }