From f6c1458fecfc7275ab07670111def6b7dba17475 Mon Sep 17 00:00:00 2001 From: liuyanzhi Date: Thu, 2 Feb 2023 00:52:53 +0000 Subject: [PATCH] add UT test Signed-off-by: liuyanzhi Change-Id: I7b6351ac230806750fcf46753a785a78a4e92504 --- services/ans/test/unittest/BUILD.gn | 18 +- .../mock_access_token_helper.cpp | 48 ++ .../mock_notification.cpp | 51 ++ ...ication_subscriber_manager_branch_test.cpp | 448 +++++++++++++++++- 4 files changed, 562 insertions(+), 3 deletions(-) create mode 100755 services/ans/test/unittest/notification_subscriber_manager_branch_test/mock_access_token_helper.cpp create mode 100755 services/ans/test/unittest/notification_subscriber_manager_branch_test/mock_notification.cpp diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 855487248..e980dca00 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 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 @@ -331,7 +331,15 @@ ohos_unittest("notification_subscriber_manager_branch_test") { "${services_path}/ans/test/unittest/mock/include", ] - sources = [ "notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp" ] + defines = [] + + sources = [ + "mock/mock_bundle_manager_helper.cpp", + "mock/mock_ipc.cpp", + "notification_subscriber_manager_branch_test/mock_access_token_helper.cpp", + "notification_subscriber_manager_branch_test/mock_notification.cpp", + "notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp", + ] deps = [ "${core_path}:ans_core", @@ -341,6 +349,12 @@ ohos_unittest("notification_subscriber_manager_branch_test") { "//third_party/googletest:gtest_main", ] + if (distributed_notification_supported) { + defines += [ "DISTRIBUTED_NOTIFICATION_SUPPORTED" ] + deps += [ "${services_path}/distributed:libans_distributed" ] + include_dirs += [ "${services_path}/distributed/include" ] + } + external_deps = [ "ability_base:want", "ability_base:zuri", diff --git a/services/ans/test/unittest/notification_subscriber_manager_branch_test/mock_access_token_helper.cpp b/services/ans/test/unittest/notification_subscriber_manager_branch_test/mock_access_token_helper.cpp new file mode 100755 index 000000000..67288f3ca --- /dev/null +++ b/services/ans/test/unittest/notification_subscriber_manager_branch_test/mock_access_token_helper.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "access_token_helper.h" + +namespace { + bool g_mockVerifyNativeTokenRet = true; + bool g_mockVerifyCallerPermissionRet = true; +} + +void MockVerifyNativeToken(bool mockRet) +{ + g_mockVerifyNativeTokenRet = mockRet; +} + +void MockVerifyCallerPermission(bool mockRet) +{ + g_mockVerifyCallerPermissionRet = mockRet; +} + +using namespace OHOS::Security::AccessToken; + +namespace OHOS { +namespace Notification { +bool AccessTokenHelper::VerifyNativeToken(const AccessTokenID &callerToken) +{ + return g_mockVerifyNativeTokenRet; +} + +bool AccessTokenHelper::VerifyCallerPermission( + const AccessTokenID &tokenCaller, const std::string &permission) +{ + return g_mockVerifyCallerPermissionRet; +} +} // namespace Notification +} // namespace OHOS \ No newline at end of file diff --git a/services/ans/test/unittest/notification_subscriber_manager_branch_test/mock_notification.cpp b/services/ans/test/unittest/notification_subscriber_manager_branch_test/mock_notification.cpp new file mode 100755 index 000000000..660075b98 --- /dev/null +++ b/services/ans/test/unittest/notification_subscriber_manager_branch_test/mock_notification.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "notification.h" + +namespace { + bool g_mockGetUserIdRet = true; + bool g_mockGetBundleNameRet = true; +} + +void MockGetUserId(bool mockRet) +{ + g_mockGetUserIdRet = mockRet; +} + +void MockGetBundleName(bool mockRet) +{ + g_mockGetBundleNameRet = mockRet; +} + +namespace OHOS { +namespace Notification { +int32_t Notification::GetUserId() const +{ + if (g_mockGetUserIdRet == false) { + return -1; + } + return 1; +} + +std::string Notification::GetBundleName() const +{ + if (g_mockGetBundleNameRet == false) { + return ""; + } + return ""; +} +} // namespace Notification +} // namespace OHOS \ No newline at end of file diff --git a/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp b/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp index 5107e4374..b4ab19631 100755 --- a/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp +++ b/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -16,13 +16,21 @@ #include #include +#include "ans_inner_errors.h" #include "ans_ut_constant.h" #define private public #define protected public +#include "advanced_notification_service.h" #include "notification_subscriber_manager.h" #undef private #undef protected #include "ans_inner_errors.h" +#include "mock_ipc_skeleton.h" + +extern void MockGetUserId(bool mockRet); +extern void MockGetBundleName(bool mockRet); +extern void MockVerifyNativeToken(bool mockRet); +extern void MockVerifyCallerPermission(bool mockRet); using namespace testing::ext; namespace OHOS { @@ -141,5 +149,443 @@ HWTEST_F(NotificationSubscriberManagerBranchTest, NotificationSubscriberManager_ sptr subscribeInfo = nullptr; EXPECT_EQ(ERR_ANS_INVALID_PARAM, notificationSubscriberManager.RemoveSubscriberInner(subscriber, subscribeInfo)); } + +/** + * @tc.number : AdvancedNotificationService_00100 + * @tc.name : AdvancedNotificationService_00100 + * @tc.desc : test ActiveNotificationDump function and record->notification == nullptr record->request == nullptr + */ +HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_00100, Function | SmallTest | Level1) +{ + std::string bundle = ""; + int32_t userId = 1; + std::vector dumpInfo; + AdvancedNotificationService advancedNotificationService; + std::shared_ptr record = std::make_shared(); + record->notification = nullptr; + record->request = nullptr; + advancedNotificationService.notificationList_.push_back(record); + EXPECT_EQ(advancedNotificationService.ActiveNotificationDump(bundle, userId, dumpInfo), ERR_OK); +} + +/** + * @tc.number : AdvancedNotificationService_00200 + * @tc.name : AdvancedNotificationService_00200 + * @tc.desc : test ActiveNotificationDump function and userId != SUBSCRIBE_USER_INIT + */ +HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_00200, Function | SmallTest | Level1) +{ + std::string bundle = ""; + int32_t userId = 1; + std::vector dumpInfo; + AdvancedNotificationService advancedNotificationService; + std::shared_ptr record = std::make_shared(); + record->notification = new Notification(); + record->request = new NotificationRequest(); + advancedNotificationService.notificationList_.push_back(record); + MockGetUserId(false); + EXPECT_EQ(advancedNotificationService.ActiveNotificationDump(bundle, userId, dumpInfo), ERR_OK); +} + +/** + * @tc.number : AdvancedNotificationService_00300 + * @tc.name : AdvancedNotificationService_00300 + * @tc.desc : test ActiveNotificationDump function and bundle != record->notification->GetBundleName(). + */ +HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_00300, Function | SmallTest | Level1) +{ + std::string bundle = ""; + int32_t userId = -1; + std::vector dumpInfo; + AdvancedNotificationService advancedNotificationService; + std::shared_ptr record = std::make_shared(); + record->notification = new Notification(); + record->request = new NotificationRequest(); + advancedNotificationService.notificationList_.push_back(record); + MockGetUserId(false); + MockGetBundleName(false); + EXPECT_EQ(advancedNotificationService.ActiveNotificationDump(bundle, userId, dumpInfo), ERR_OK); +} + +/** + * @tc.number : AdvancedNotificationService_00400 + * @tc.name : AdvancedNotificationService_00400 + * @tc.desc : test ActiveNotificationDump function and record->deviceId is not empty. + */ +HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_00400, Function | SmallTest | Level1) +{ + std::string bundle = ""; + int32_t userId = -1; + std::vector dumpInfo; + AdvancedNotificationService advancedNotificationService; + std::shared_ptr record = std::make_shared(); + record->notification = new Notification(); + record->request = new NotificationRequest(); + record->deviceId = ""; + advancedNotificationService.notificationList_.push_back(record); + MockGetUserId(false); + MockGetBundleName(false); + EXPECT_EQ(advancedNotificationService.ActiveNotificationDump(bundle, userId, dumpInfo), ERR_OK); +} + +/** + * @tc.number : AdvancedNotificationService_00500 + * @tc.name : AdvancedNotificationService_00500 + * @tc.desc : test ActiveNotificationDump function and record->request->GetOwnerUid() > 0. + */ +HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_00500, Function | SmallTest | Level1) +{ + std::string bundle = ""; + int32_t userId = -1; + std::vector dumpInfo; + AdvancedNotificationService advancedNotificationService; + std::shared_ptr record = std::make_shared(); + record->notification = new Notification(); + record->request = new NotificationRequest(); + int32_t uid = 1; + record->request->SetOwnerUid(uid); + record->deviceId = ""; + advancedNotificationService.notificationList_.push_back(record); + MockGetUserId(false); + MockGetBundleName(false); + EXPECT_EQ(advancedNotificationService.ActiveNotificationDump(bundle, userId, dumpInfo), ERR_OK); +} + +/** + * @tc.number : AdvancedNotificationService_00600 + * @tc.name : AdvancedNotificationService_00600 + * @tc.desc : test ActiveNotificationDump function and record->request->GetOwnerUid() < 0. + */ +HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_00600, Function | SmallTest | Level1) +{ + std::string bundle = ""; + int32_t userId = -1; + std::vector dumpInfo; + AdvancedNotificationService advancedNotificationService; + std::shared_ptr record = std::make_shared(); + record->notification = new Notification(); + record->request = new NotificationRequest(); + int32_t uid = -1; + record->request->SetOwnerUid(uid); + record->deviceId = ""; + advancedNotificationService.notificationList_.push_back(record); + MockGetUserId(false); + MockGetBundleName(false); + EXPECT_EQ(advancedNotificationService.ActiveNotificationDump(bundle, userId, dumpInfo), ERR_OK); +} + +/** + * @tc.number : AdvancedNotificationService_00700 + * @tc.name : AdvancedNotificationService_00700 + * @tc.desc : test DistributedNotificationDump function and record->notification == nullptr. + */ +HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_00700, Function | SmallTest | Level1) +{ + std::string bundle = ""; + int32_t userId = 1; + std::vector dumpInfo; + AdvancedNotificationService advancedNotificationService; + std::shared_ptr record = std::make_shared(); + record->notification = nullptr; + advancedNotificationService.notificationList_.push_back(record); + EXPECT_EQ(advancedNotificationService.DistributedNotificationDump(bundle, userId, dumpInfo), ERR_OK); +} + +/** + * @tc.number : AdvancedNotificationService_00800 + * @tc.name : AdvancedNotificationService_00800 + * @tc.desc : test DistributedNotificationDump function and userId != SUBSCRIBE_USER_INIT. + */ +HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_00800, Function | SmallTest | Level1) +{ + std::string bundle = ""; + int32_t userId = 1; + std::vector dumpInfo; + AdvancedNotificationService advancedNotificationService; + std::shared_ptr record = std::make_shared(); + record->notification = new Notification(); + MockGetUserId(false); + advancedNotificationService.notificationList_.push_back(record); + EXPECT_EQ(advancedNotificationService.DistributedNotificationDump(bundle, userId, dumpInfo), ERR_OK); +} + +/** + * @tc.number : AdvancedNotificationService_00900 + * @tc.name : AdvancedNotificationService_00900 + * @tc.desc : test DistributedNotificationDump function and bundle is not empty. + */ +HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_00900, Function | SmallTest | Level1) +{ + std::string bundle = ""; + int32_t userId = -1; + std::vector dumpInfo; + AdvancedNotificationService advancedNotificationService; + std::shared_ptr record = std::make_shared(); + record->notification = new Notification(); + MockGetUserId(false); + MockGetBundleName(false); + advancedNotificationService.notificationList_.push_back(record); + EXPECT_EQ(advancedNotificationService.DistributedNotificationDump(bundle, userId, dumpInfo), ERR_OK); +} + +/** + * @tc.number : AdvancedNotificationService_01000 + * @tc.name : AdvancedNotificationService_01000 + * @tc.desc : test DistributedNotificationDump function and record->deviceId is empty. + */ +HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_01000, Function | SmallTest | Level1) +{ + std::string bundle = ""; + int32_t userId = -1; + std::vector dumpInfo; + AdvancedNotificationService advancedNotificationService; + std::shared_ptr record = std::make_shared(); + record->notification = new Notification(); + record->deviceId = ""; + MockGetUserId(false); + MockGetBundleName(false); + advancedNotificationService.notificationList_.push_back(record); + EXPECT_EQ(advancedNotificationService.DistributedNotificationDump(bundle, userId, dumpInfo), ERR_OK); +} + +/** + * @tc.number : AdvancedNotificationService_01100 + * @tc.name : AdvancedNotificationService_01100 + * @tc.desc : test DistributedNotificationDump function and record->request->GetOwnerUid() > 0. + */ +HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_01100, Function | SmallTest | Level1) +{ + std::string bundle = ""; + int32_t userId = -1; + std::vector dumpInfo; + AdvancedNotificationService advancedNotificationService; + std::shared_ptr record = std::make_shared(); + record->notification = new Notification(); + record->request = new NotificationRequest(); + int32_t uid = 1; + record->request->SetOwnerUid(uid); + record->deviceId = ""; + MockGetUserId(false); + MockGetBundleName(false); + advancedNotificationService.notificationList_.push_back(record); + EXPECT_EQ(advancedNotificationService.DistributedNotificationDump(bundle, userId, dumpInfo), ERR_OK); +} + +/** + * @tc.number : AdvancedNotificationService_01200 + * @tc.name : AdvancedNotificationService_01200 + * @tc.desc : test DistributedNotificationDump function and record->request->GetOwnerUid() < 0. + */ +HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_01200, Function | SmallTest | Level1) +{ + std::string bundle = ""; + int32_t userId = -1; + std::vector dumpInfo; + AdvancedNotificationService advancedNotificationService; + std::shared_ptr record = std::make_shared(); + record->notification = new Notification(); + record->request = new NotificationRequest(); + int32_t uid = -1; + record->request->SetOwnerUid(uid); + record->deviceId = ""; + MockGetUserId(false); + MockGetBundleName(false); + advancedNotificationService.notificationList_.push_back(record); + EXPECT_EQ(advancedNotificationService.DistributedNotificationDump(bundle, userId, dumpInfo), ERR_OK); +} + +/** + * @tc.number : AdvancedNotificationService_01300 + * @tc.name : AdvancedNotificationService_01300 + * @tc.desc : Test CheckPermission function and result is false + */ +HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_01300, Function | SmallTest | Level1) +{ + std::string permission = ""; + AdvancedNotificationService advancedNotificationService; + MockVerifyNativeToken(false); + MockVerifyCallerPermission(false); + EXPECT_EQ(advancedNotificationService.CheckPermission(permission), false); +} + +/** + * @tc.number : AdvancedNotificationService_01400 + * @tc.name : AdvancedNotificationService_01400 + * @tc.desc : Test PrepareNotificationRequest function and CheckPermission is false + */ +HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_01400, Function | SmallTest | Level1) +{ + IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); + + sptr req = new NotificationRequest(); + bool isAgentTrue = true; + req->SetIsAgentNotification(isAgentTrue); + + MockVerifyNativeToken(false); + MockVerifyCallerPermission(false); + AdvancedNotificationService advancedNotificationService; + EXPECT_EQ(advancedNotificationService.PrepareNotificationRequest(req), ERR_ANS_PERMISSION_DENIED); +} + +/** + * @tc.number : AdvancedNotificationService_01500 + * @tc.name : AdvancedNotificationService_01500 + * @tc.desc : Test CancelAsBundle function and CheckPermission is false + */ +HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_01500, Function | SmallTest | Level1) +{ + IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); + + int32_t notificationId = 1; + std::string representativeBundle = ""; + int32_t userId = 2; + + MockVerifyNativeToken(false); + MockVerifyCallerPermission(false); + AdvancedNotificationService advancedNotificationService; + EXPECT_EQ(advancedNotificationService.CancelAsBundle(notificationId, representativeBundle, userId), + ERR_ANS_PERMISSION_DENIED); +} + +/** + * @tc.number : AdvancedNotificationService_01600 + * @tc.name : AdvancedNotificationService_01600 + * @tc.desc : Test AddSlots function and CheckPermission is false + */ +HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_01600, Function | SmallTest | Level1) +{ + IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); + + std::vector> slots; + + MockVerifyNativeToken(false); + MockVerifyCallerPermission(false); + AdvancedNotificationService advancedNotificationService; + EXPECT_EQ(advancedNotificationService.AddSlots(slots), ERR_ANS_PERMISSION_DENIED); +} + +/** + * @tc.number : AdvancedNotificationService_01700 + * @tc.name : AdvancedNotificationService_01700 + * @tc.desc : Test Delete function and CheckPermission is false + */ +HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_01700, Function | SmallTest | Level1) +{ + IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); + + std::string key = ""; + int32_t removeReason = 1; + + MockVerifyNativeToken(false); + MockVerifyCallerPermission(false); + AdvancedNotificationService advancedNotificationService; + EXPECT_EQ(advancedNotificationService.Delete(key, removeReason), ERR_ANS_PERMISSION_DENIED); +} + +/** + * @tc.number : AdvancedNotificationService_01800 + * @tc.name : AdvancedNotificationService_01800 + * @tc.desc : Test DeleteByBundle function and CheckPermission is false + */ +HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_01800, Function | SmallTest | Level1) +{ + IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); + + sptr bundleOption = nullptr; + + MockVerifyNativeToken(false); + MockVerifyCallerPermission(false); + AdvancedNotificationService advancedNotificationService; + EXPECT_EQ(advancedNotificationService.DeleteByBundle(bundleOption), ERR_ANS_PERMISSION_DENIED); +} + +/** + * @tc.number : AdvancedNotificationService_01900 + * @tc.name : AdvancedNotificationService_01900 + * @tc.desc : Test DeleteAll function and CheckPermission is false + */ +HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_01900, Function | SmallTest | Level1) +{ + IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); + + MockVerifyNativeToken(false); + MockVerifyCallerPermission(false); + AdvancedNotificationService advancedNotificationService; + EXPECT_EQ(advancedNotificationService.DeleteAll(), ERR_ANS_PERMISSION_DENIED); +} + +/** + * @tc.number : AdvancedNotificationService_02000 + * @tc.name : AdvancedNotificationService_02000 + * @tc.desc : Test GetSlotsByBundle function and CheckPermission is false + */ +HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_02000, Function | SmallTest | Level1) +{ + IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); + + sptr bundleOption = nullptr; + std::vector> slots; + + MockVerifyNativeToken(false); + MockVerifyCallerPermission(false); + AdvancedNotificationService advancedNotificationService; + EXPECT_EQ(advancedNotificationService.GetSlotsByBundle(bundleOption, slots), ERR_ANS_PERMISSION_DENIED); +} + +/** + * @tc.number : AdvancedNotificationService_02100 + * @tc.name : AdvancedNotificationService_02100 + * @tc.desc : Test UpdateSlots function and CheckPermission is false + */ +HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_02100, Function | SmallTest | Level1) +{ + IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); + + sptr bundleOption = nullptr; + std::vector> slots; + + MockVerifyNativeToken(false); + MockVerifyCallerPermission(false); + AdvancedNotificationService advancedNotificationService; + EXPECT_EQ(advancedNotificationService.UpdateSlots(bundleOption, slots), ERR_ANS_PERMISSION_DENIED); +} + +/** + * @tc.number : AdvancedNotificationService_02200 + * @tc.name : AdvancedNotificationService_02200 + * @tc.desc : Test SetShowBadgeEnabledForBundle function and CheckPermission is false + */ +HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_02200, Function | SmallTest | Level1) +{ + IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); + + sptr bundleOption = nullptr; + bool enabled = true; + + MockVerifyNativeToken(false); + MockVerifyCallerPermission(false); + AdvancedNotificationService advancedNotificationService; + EXPECT_EQ(advancedNotificationService.SetShowBadgeEnabledForBundle(bundleOption, enabled), + ERR_ANS_PERMISSION_DENIED); +} + +/** + * @tc.number : AdvancedNotificationService_02300 + * @tc.name : AdvancedNotificationService_02300 + * @tc.desc : Test GetShowBadgeEnabledForBundle function and CheckPermission is false + */ +HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_02300, Function | SmallTest | Level1) +{ + IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); + + sptr bundleOption = nullptr; + bool enabled = true; + + MockVerifyNativeToken(false); + MockVerifyCallerPermission(false); + AdvancedNotificationService advancedNotificationService; + EXPECT_EQ(advancedNotificationService.GetShowBadgeEnabledForBundle(bundleOption, enabled), + ERR_ANS_PERMISSION_DENIED); +} } // namespace Notification } // namespace OHOS -- Gitee