diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 1e402629adc16431df81735f725f8a967c2cb848..380836922efd11161c1f9556efa45fabb0a0c6a3 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 17381a62eea6c037a6106a56b46a99f183fd8758..43bfae1b6844c4515b5d9bb21c13ee71e94a1a1f 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 d48872dd6860b1d433b53ed4cdc2beeede01b7ae..4a9fdecd333f561696dc1fab572414a1db9831fe 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 316ad312ca061f86d50137ac31db17c3ed08183d..80d17f2b109fd3e0de8f8703db7114db383bb0bd 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 a0f1e12d9fc9bfd0c134cefe6db4a086ee3e817a..223ba0270570f8763ac707cf5889ad10d04183cb 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 828f72499767d9f6525cd8b4ee39bb0f76689507..cbe5d815a4ff580eec51dfd8c59cfe83498530fc 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 58cef3cd6f9e486f6ab183aab4ad9c621781e3b5..519841b874aa74f5c173b1149b552d5d7dc221a8 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);