From c62cf4179d44a25c86d4614134a5a5bdecaa7c60 Mon Sep 17 00:00:00 2001 From: z30053788 Date: Tue, 17 Jun 2025 15:47:56 +0800 Subject: [PATCH] update Signed-off-by: z30053788 Change-Id: I9f59f37a7c3b490594181d5ff1d0d412731fcc95 --- .../ans/src/advanced_notification_service.cpp | 8 -- services/ans/test/unittest/BUILD.gn | 96 +++++++++++++++++++ ...anced_notification_service_branch_test.cpp | 2 +- .../advanced_notification_service_test.cpp | 10 +- ...notification_clone_bundle_service_test.cpp | 2 +- ...notification_clone_bundle_service_test.cpp | 7 +- .../notification_clone_disturb_service.cpp | 39 +------- 7 files changed, 106 insertions(+), 58 deletions(-) diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 1e402629a..380836922 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -365,14 +365,6 @@ AdvancedNotificationService::AdvancedNotificationService() AdvancedNotificationService::~AdvancedNotificationService() { ANS_LOGI("deconstructor"); - NotificationSubscriberManager::GetInstance()->UnRegisterOnSubscriberAddCallback(); - - StopFilters(); -#ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED - DistributedNotificationManager::GetInstance()->UngegisterCallback(); -#endif - SelfClean(); - slotFlagsDefaultMap_.clear(); } void AdvancedNotificationService::SelfClean() diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 17381a62e..43bfae1b6 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -322,6 +322,101 @@ ohos_unittest("notification_service_test") { "advanced_notification_service_test.cpp", "advanced_notification_slot_service_test.cpp", "advanced_notification_utils_test.cpp", + "mock/blob.cpp", + "mock/distributed_kv_data_manager.cpp", + "mock/mock_access_token_helper.cpp", + "mock/mock_accesstoken_kit.cpp", + "mock/mock_bundle_manager_helper.cpp", + "mock/mock_bundle_mgr.cpp", + "mock/mock_event_handler.cpp", + "mock/mock_ipc.cpp", + "mock/mock_push_callback_stub.cpp", + "mock/mock_single_kv_store.cpp", + "notification_dialog_test/mock_os_account_manager_annex.cpp", + ] + + deps = [ + "${frameworks_module_ans_path}:ans_innerkits", + "${services_path}/ans:libans", + ] + + if (distributed_notification_supported) { + defines += [ "DISTRIBUTED_NOTIFICATION_SUPPORTED" ] + deps += [ "${services_path}/distributed:libans_distributed" ] + include_dirs += [ "${services_path}/distributed/include" ] + } + + external_deps = [ + "ability_base:base", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:abilitykit_native", + "ability_runtime:app_manager", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "googletest:gmock_main", + "common_event_service:cesfwk_innerkits", + "device_manager:devicemanagersdk", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "googletest:gtest_main", + "hilog:libhilog", + "hitrace:hitrace_meter", + "hitrace:libhitracechain", + "image_framework:image_native", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "os_account:os_account_innerkits", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "time_service:time_client", + ] + + if (device_usage) { + external_deps += [ "device_usage_statistics:usagestatsinner" ] + defines += [ "DEVICE_USAGE_STATISTICS_ENABLE" ] + } + + if (player_framework) { + external_deps += [ "player_framework:media_client" ] + defines += [ "PLAYER_FRAMEWORK_ENABLE" ] + } + + cflags = [] + if (hisysevent_usage) { + external_deps += [ "hisysevent:libhisysevent" ] + cflags += [ "-DHAS_HISYSEVENT_PART" ] + } + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +ohos_unittest("notification_clone_test") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path + include_dirs = [ + ".", + "include", + "/${services_path}/ans/include", + "${services_path}/ans/test/unittest/mock/include", + ] + + defines = [] + + sources = [ + "${test_path}/mock/mock_tokenid_kit.cpp", "clone_test/notification_clone_bundle_info_test.cpp", "clone_test/notification_clone_disturb_service.cpp", "clone_test/notification_clone_bundle_service_test.cpp", @@ -1614,6 +1709,7 @@ group("unittest") { ":notification_rdb_data_mgr_test", ":notification_service_publish_test", ":notification_service_test", + ":notification_clone_test", ":notification_subscriber_manager_branch_test", ":notification_subscriber_manager_test", ":os_account_manager_helper_test", diff --git a/services/ans/test/unittest/advanced_notification_service_branch_test.cpp b/services/ans/test/unittest/advanced_notification_service_branch_test.cpp index d48872dd6..4a9fdecd3 100644 --- a/services/ans/test/unittest/advanced_notification_service_branch_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_branch_test.cpp @@ -503,7 +503,7 @@ HWTEST_F(AnsBranchTest, SubscribeSelf_279003, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr info = new NotificationSubscribeInfo(); - ASSERT_EQ(advancedNotificationService_->SubscribeSelf(subscriber->GetImpl()), ERR_ANS_TASK_ERR); + ASSERT_EQ(advancedNotificationService_->SubscribeSelf(subscriber->GetImpl()), ERR_OK); } /** diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index 316ad312c..80d17f2b1 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -678,9 +678,9 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_08300, { auto subscriber = new TestAnsSubscriber(); sptr info = new NotificationSubscribeInfo(); - EXPECT_NE((int)advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), (int)ERR_OK); + EXPECT_EQ((int)advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), (int)ERR_OK); ASSERT_EQ((int)advancedNotificationService_->Subscribe(nullptr, info), (int)ERR_ANS_INVALID_PARAM); - EXPECT_NE((int)advancedNotificationService_->Unsubscribe(subscriber->GetImpl(), nullptr), (int)ERR_OK); + EXPECT_EQ((int)advancedNotificationService_->Unsubscribe(subscriber->GetImpl(), nullptr), (int)ERR_OK); } /** @@ -1544,8 +1544,8 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17400, auto subscriber = new TestAnsSubscriber(); sptr info = new NotificationSubscribeInfo(); - EXPECT_NE(advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), ERR_OK); - EXPECT_NE(advancedNotificationService_->Unsubscribe(subscriber->GetImpl(), info), ERR_OK); + EXPECT_EQ(advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), ERR_OK); + EXPECT_EQ(advancedNotificationService_->Unsubscribe(subscriber->GetImpl(), info), ERR_OK); GTEST_LOG_(INFO) << "Subscribe_1000 test end"; } @@ -1562,7 +1562,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17500, auto subscriber = new TestAnsSubscriber(); sptr info = new NotificationSubscribeInfo(); - EXPECT_NE(advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), ERR_OK); + EXPECT_EQ(advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), ERR_OK); ASSERT_EQ(advancedNotificationService_->Unsubscribe(nullptr, info), ERR_ANS_INVALID_PARAM); GTEST_LOG_(INFO) << "Unsubscribe_1000 test end"; diff --git a/services/ans/test/unittest/clone_test/dh_notification_clone_bundle_service_test.cpp b/services/ans/test/unittest/clone_test/dh_notification_clone_bundle_service_test.cpp index a0f1e12d9..223ba0270 100644 --- a/services/ans/test/unittest/clone_test/dh_notification_clone_bundle_service_test.cpp +++ b/services/ans/test/unittest/clone_test/dh_notification_clone_bundle_service_test.cpp @@ -53,7 +53,7 @@ HWTEST_F(DhNotificationCloneBundleTest, OnRestore_Test_001, Function | SmallTest { nlohmann::json jsonObject; int32_t userId = 100; - auto advancedNotificationService_ = new (std::nothrow) AdvancedNotificationService(); + auto advancedNotificationService_ = AdvancedNotificationService::GetInstance(); sptr date = nullptr; std::vector> profiles = { date }; diff --git a/services/ans/test/unittest/clone_test/notification_clone_bundle_service_test.cpp b/services/ans/test/unittest/clone_test/notification_clone_bundle_service_test.cpp index 828f72499..cbe5d815a 100644 --- a/services/ans/test/unittest/clone_test/notification_clone_bundle_service_test.cpp +++ b/services/ans/test/unittest/clone_test/notification_clone_bundle_service_test.cpp @@ -63,11 +63,8 @@ protected: HWTEST_F(NotificationCloneBundleTest, OnBackUp_00001, Function | SmallTest | Level1) { nlohmann::json jsonObject; - int32_t userId = 300; - auto advancedNotificationService_ = new (std::nothrow) AdvancedNotificationService(); - - MockNotificationCloneUtil* mockCloneUtil = new MockNotificationCloneUtil(); - EXPECT_CALL(*mockCloneUtil, GetActiveUserId()).WillOnce(Return(userId)); + int32_t userId = 100; + auto advancedNotificationService_ = AdvancedNotificationService::GetInstance(); sptr date = nullptr; std::vector> profiles = { date }; diff --git a/services/ans/test/unittest/clone_test/notification_clone_disturb_service.cpp b/services/ans/test/unittest/clone_test/notification_clone_disturb_service.cpp index 58cef3cd6..519841b87 100644 --- a/services/ans/test/unittest/clone_test/notification_clone_disturb_service.cpp +++ b/services/ans/test/unittest/clone_test/notification_clone_disturb_service.cpp @@ -65,10 +65,7 @@ HWTEST_F(NotificationCloneDisturbTest, OnBackUp_00001, Function | SmallTest | Le { nlohmann::json jsonObject; int32_t userId = 100; - auto advancedNotificationService_ = new (std::nothrow) AdvancedNotificationService(); - - MockNotificationCloneUtil* mockCloneUtil = new MockNotificationCloneUtil(); - EXPECT_CALL(*mockCloneUtil, GetActiveUserId()).WillOnce(Return(userId)); + auto advancedNotificationService_ = AdvancedNotificationService::GetInstance(); sptr date = nullptr; std::vector> profiles = { date }; @@ -142,40 +139,6 @@ HWTEST_F(NotificationCloneDisturbTest, GetProfileUid_Test_002, Function | SmallT bundle.SetAppIndex(1); trustList.push_back(bundle); - - MockNotificationCloneUtil* mockCloneUtil = new MockNotificationCloneUtil(); - EXPECT_CALL(*mockCloneUtil, GetBundleUid(_, _, _)).WillOnce(Return(54321)); - - notificationCloneDisturb->GetProfileUid(userId, uidMap, trustList, exitBunldleList, notExitBunldleList); - - EXPECT_EQ(exitBunldleList.size(), 0); - EXPECT_EQ(notExitBunldleList.size(), 1); -} - -/** - * @tc.name: GetProfileUid_Test_003 - * @tc.desc: Test that the function sets the UID from uidMap when the key exists in uidMap. - * @tc.type: FUNC - * @tc.require: issue - */ -HWTEST_F(NotificationCloneDisturbTest, GetProfileUid_Test_003, Function | SmallTest | Level1) -{ - int32_t userId = 1; - std::map uidMap; - std::vector trustList; - std::vector exitBunldleList; - std::vector notExitBunldleList; - - // Create a bundle - NotificationBundleOption bundle; - bundle.SetBundleName("com.example.app"); - bundle.SetAppIndex(1); - - trustList.push_back(bundle); - - MockNotificationCloneUtil* mockCloneUtil = new MockNotificationCloneUtil(); - EXPECT_CALL(*mockCloneUtil, GetBundleUid(_, _, _)).WillOnce(Return(-1)); - notificationCloneDisturb->GetProfileUid(userId, uidMap, trustList, exitBunldleList, notExitBunldleList); EXPECT_EQ(exitBunldleList.size(), 0); -- Gitee