From e33324fb3bb3ed643da3b8aa48edd63961560c1f Mon Sep 17 00:00:00 2001 From: wwx1143030 Date: Mon, 26 Sep 2022 20:52:56 +0800 Subject: [PATCH 1/4] =?UTF-8?q?IssueNo:https://gitee.com/openharmony/notif?= =?UTF-8?q?ication=5Fcommon=5Fevent=5Fservice/issues/I5T8PA=20Description:?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E5=88=86=E6=94=AF=E8=A6=86=E7=9B=96=E7=8E=87?= =?UTF-8?q?=20Sig:SIG=5FApplicationFramework=20Feature=20or=20Bugfix:Bugfi?= =?UTF-8?q?x=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wwx1143030 Change-Id: I30318f668c9adf287d8ae4d490113bf39285ce58 --- tools/test/mock/mock_ans_notification.cpp | 6 +++--- tools/test/unittest/dump/BUILD.gn | 1 + .../dump/notification_shell_command_dump_test.cpp | 8 ++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/test/mock/mock_ans_notification.cpp b/tools/test/mock/mock_ans_notification.cpp index 071d92d7e..75a8097c1 100644 --- a/tools/test/mock/mock_ans_notification.cpp +++ b/tools/test/mock/mock_ans_notification.cpp @@ -23,10 +23,10 @@ ErrCode AnsNotification::SetNotificationsEnabledForSpecifiedBundle( const NotificationBundleOption &bundleOption, const std::string &deviceId, bool enabled) { if (bundleOption.GetBundleName() == "gg") { - return ERR_OK; + return ERR_OK; } else { - return ERR_ANS_SERVICE_NOT_CONNECTED; - } + return ERR_ANS_SERVICE_NOT_CONNECTED; + } } } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/tools/test/unittest/dump/BUILD.gn b/tools/test/unittest/dump/BUILD.gn index dab5f1246..dd2b6df94 100644 --- a/tools/test/unittest/dump/BUILD.gn +++ b/tools/test/unittest/dump/BUILD.gn @@ -37,6 +37,7 @@ ohos_unittest("notification_shell_command_dump_test") { "${tools_path}/dump/src/shell_command.cpp", "${tools_path}/test/mock/mock_ans_notification.cpp", "notification_shell_command_dump_test.cpp", + "${tools_path}/test/mock/mock_ans_notification.cpp", ] sources += tools_dump_mock_sources diff --git a/tools/test/unittest/dump/notification_shell_command_dump_test.cpp b/tools/test/unittest/dump/notification_shell_command_dump_test.cpp index ab7c2f0a6..36cce854a 100644 --- a/tools/test/unittest/dump/notification_shell_command_dump_test.cpp +++ b/tools/test/unittest/dump/notification_shell_command_dump_test.cpp @@ -78,6 +78,14 @@ static char g_enableObjectNull[] = " --recent-count -c set the max count of recent notifications keeping in memory\n --enable-notification" " -e set notification enabled for the bundle, eg: -e com.example:10100:1\n"; +static char g_enableObjectNull[] = +"error: object is null\n" +"error: object is null\n" +"usage: anm setting []\n" +"options list:\n --help, -h help menu\n" +" --recent-count -c set the max count of recent notifications keeping in memory\n" +" --enable-notification -e set notification enabled for the bundle, eg: -e com.example:10100:1\n"; + static char g_bundleName[] = "example"; static char g_commandActive[] = "active"; static char g_commandRecent[] = "recent"; -- Gitee From 20a92a6c46bcbab37ba83370d96f766e29f14af0 Mon Sep 17 00:00:00 2001 From: wwx1143030 Date: Mon, 26 Sep 2022 21:14:11 +0800 Subject: [PATCH 2/4] =?UTF-8?q?IssueNo:https://gitee.com/openharmony/notif?= =?UTF-8?q?ication=5Fcommon=5Fevent=5Fservice/issues/I5T8PA=20Description:?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E5=88=86=E6=94=AF=E8=A6=86=E7=9B=96=E7=8E=87?= =?UTF-8?q?=20Sig:SIG=5FApplicationFramework=20Feature=20or=20Bugfix:Bugfi?= =?UTF-8?q?x=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wwx1143030 Change-Id: I3e2b94a7e1bbce7c3f4f452dc498f97b792d425f --- tools/test/mock/mock_ans_notification.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/test/mock/mock_ans_notification.cpp b/tools/test/mock/mock_ans_notification.cpp index 75a8097c1..071d92d7e 100644 --- a/tools/test/mock/mock_ans_notification.cpp +++ b/tools/test/mock/mock_ans_notification.cpp @@ -23,10 +23,10 @@ ErrCode AnsNotification::SetNotificationsEnabledForSpecifiedBundle( const NotificationBundleOption &bundleOption, const std::string &deviceId, bool enabled) { if (bundleOption.GetBundleName() == "gg") { - return ERR_OK; + return ERR_OK; } else { - return ERR_ANS_SERVICE_NOT_CONNECTED; - } + return ERR_ANS_SERVICE_NOT_CONNECTED; + } } } // namespace Notification } // namespace OHOS \ No newline at end of file -- Gitee From 69c6e2bbac230089c939f0bc83bd602a682c5ad5 Mon Sep 17 00:00:00 2001 From: wwx1143030 Date: Wed, 28 Sep 2022 17:30:03 +0800 Subject: [PATCH 3/4] =?UTF-8?q?IssueNo:https://gitee.com/openharmony/notif?= =?UTF-8?q?ication=5Fcommon=5Fevent=5Fservice/issues/I5TIQP=20Description:?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BA=8B=E4=BB=B6=E9=80=9A=E7=9F=A5=E5=88=86?= =?UTF-8?q?=E6=94=AFTDDOnReceiveEvent111=20Sig:SIG=5FApplicationFramework?= =?UTF-8?q?=20Feature=20or=20Bugfix:Bugfix=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wwx1143030 Change-Id: Ibbd13617db8e289b6aa853b3b0b8b76dcd8b98cd --- .../advanced_notification_service_test.cpp | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index 60b4a295f..5c9738607 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -1996,6 +1996,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15200, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15300, Function | SmallTest | Level1) { + IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN); std::string cmd = "CMD"; std::string bundle = "Bundle"; int32_t userId = 4; @@ -2015,5 +2016,79 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15400, std::vector args; EXPECT_EQ(advancedNotificationService_->Dump(fd, args), (int)ERR_OK); } + +/** + * @tc.number : AdvancedNotificationServiceTest_15500 + * @tc.name : OnReceiveEvent_0100 + * @tc.desc : Test OnReceiveEvent function userid req = new (std::nothrow) NotificationRequest(1); + EXPECT_NE(req, nullptr); + req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetLabel("req's label"); + std::string label = "publish's label"; + std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); + normalContent->SetText("normalContent's text"); + normalContent->SetTitle("normalContent's title"); + std::shared_ptr content = std::make_shared(normalContent); + EXPECT_NE(content, nullptr); + req->SetContent(content); + req->SetCreatorUserId(DEFAULT_USER_ID); + EXPECT_EQ(advancedNotificationService_->Publish(label, req), ERR_OK); + SleepForFC(); + + EventFwk::Want want; + EventFwk::CommonEventData data; + data.SetWant(want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED)); + data.SetCode(50); + advancedNotificationService_->systemEventObserver_->OnReceiveEvent(data); + + std::stringstream key; + key << "_" << req->GetCreatorUserId() << "_" << req->GetCreatorUid() << "_" + << req->GetLabel() << "_" << req->GetNotificationId(); + + EXPECT_EQ(advancedNotificationService_->IsNotificationExists(key.str()), true); +} + +/** + * @tc.number : AdvancedNotificationServiceTest_15600 + * @tc.name : OnReceiveEvent_0200 + * @tc.desc : Test OnReceiveEvent function when userid>DEFAULT_USER_ID + * @tc.require : I5TIQR + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15600, Function | SmallTest | Level1) +{ + sptr req = new (std::nothrow) NotificationRequest(1); + EXPECT_NE(req, nullptr); + req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetLabel("req's label"); + std::string label = "publish's label"; + std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); + normalContent->SetText("normalContent's text"); + normalContent->SetTitle("normalContent's title"); + std::shared_ptr content = std::make_shared(normalContent); + EXPECT_NE(content, nullptr); + req->SetContent(content); + req->SetCreatorUserId(DEFAULT_USER_ID); + EXPECT_EQ(advancedNotificationService_->Publish(label, req), ERR_OK); + SleepForFC(); + + EventFwk::Want want; + EventFwk::CommonEventData data; + data.SetWant(want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED)); + data.SetCode(200); + advancedNotificationService_->systemEventObserver_->OnReceiveEvent(data); + + std::stringstream key; + key << "_" << req->GetCreatorUserId() << "_" << req->GetCreatorUid() << "_" + << req->GetLabel() << "_" << req->GetNotificationId(); + + EXPECT_EQ(advancedNotificationService_->IsNotificationExists(key.str()), true); +} } // namespace Notification } // namespace OHOS \ No newline at end of file -- Gitee From ded6b43e337a283eb20352d194d1e700f7f996c3 Mon Sep 17 00:00:00 2001 From: wwx1143030 Date: Wed, 28 Sep 2022 18:12:42 +0800 Subject: [PATCH 4/4] =?UTF-8?q?IssueNo:https://gitee.com/openharmony/notif?= =?UTF-8?q?ication=5Fcommon=5Fevent=5Fservice/issues/I5TIQP=20Description:?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BA=8B=E4=BB=B6=E9=80=9A=E7=9F=A5=E5=88=86?= =?UTF-8?q?=E6=94=AFTDDOnReceiveEvent22=20Sig:SIG=5FApplicationFramework?= =?UTF-8?q?=20Feature=20or=20Bugfix:Bugfix=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wwx1143030 Change-Id: Ib4935aafa9ce6bf858f839e5fc9061dc8050d95d --- tools/test/unittest/dump/BUILD.gn | 1 - .../dump/notification_shell_command_dump_test.cpp | 8 -------- 2 files changed, 9 deletions(-) diff --git a/tools/test/unittest/dump/BUILD.gn b/tools/test/unittest/dump/BUILD.gn index dd2b6df94..dab5f1246 100644 --- a/tools/test/unittest/dump/BUILD.gn +++ b/tools/test/unittest/dump/BUILD.gn @@ -37,7 +37,6 @@ ohos_unittest("notification_shell_command_dump_test") { "${tools_path}/dump/src/shell_command.cpp", "${tools_path}/test/mock/mock_ans_notification.cpp", "notification_shell_command_dump_test.cpp", - "${tools_path}/test/mock/mock_ans_notification.cpp", ] sources += tools_dump_mock_sources diff --git a/tools/test/unittest/dump/notification_shell_command_dump_test.cpp b/tools/test/unittest/dump/notification_shell_command_dump_test.cpp index 36cce854a..ab7c2f0a6 100644 --- a/tools/test/unittest/dump/notification_shell_command_dump_test.cpp +++ b/tools/test/unittest/dump/notification_shell_command_dump_test.cpp @@ -78,14 +78,6 @@ static char g_enableObjectNull[] = " --recent-count -c set the max count of recent notifications keeping in memory\n --enable-notification" " -e set notification enabled for the bundle, eg: -e com.example:10100:1\n"; -static char g_enableObjectNull[] = -"error: object is null\n" -"error: object is null\n" -"usage: anm setting []\n" -"options list:\n --help, -h help menu\n" -" --recent-count -c set the max count of recent notifications keeping in memory\n" -" --enable-notification -e set notification enabled for the bundle, eg: -e com.example:10100:1\n"; - static char g_bundleName[] = "example"; static char g_commandActive[] = "active"; static char g_commandRecent[] = "recent"; -- Gitee