From 7a881e69465f8d5f7bd51c79372d1cdd40895e5c Mon Sep 17 00:00:00 2001 From: liuyanzhi2020 Date: Fri, 23 Sep 2022 09:00:52 +0000 Subject: [PATCH 1/4] update tools/test/unittest/dump/notification_shell_command_dump_test.cpp. Signed-off-by: liuyanzhi2020 --- .../dump/notification_shell_command_dump_test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 73a22b3b5..4fce48294 100644 --- a/tools/test/unittest/dump/notification_shell_command_dump_test.cpp +++ b/tools/test/unittest/dump/notification_shell_command_dump_test.cpp @@ -60,15 +60,15 @@ static char g_dumpActiveUser[] = static char g_enableErrorInformation[] = "error: option 'e' requires a value.\nusage: anm setting []\noptions 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"; +" --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_enableBundleNameNull[] = "error: setting information error\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"; +" --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"; -- Gitee From 0870526fa3c673f1bad1e011d7947380c5988e43 Mon Sep 17 00:00:00 2001 From: wwx1143030 Date: Mon, 26 Sep 2022 20:52:56 +0800 Subject: [PATCH 2/4] =?UTF-8?q?IssueNo:https://gitee.com/openharmony/notif?= =?UTF-8?q?ication=5Fcommon=5Fevent=5Fservice/issues/I1T8PA=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 | 32 +++++++++++ tools/test/unittest/dump/BUILD.gn | 1 + .../notification_shell_command_dump_test.cpp | 55 +++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 tools/test/mock/mock_ans_notification.cpp diff --git a/tools/test/mock/mock_ans_notification.cpp b/tools/test/mock/mock_ans_notification.cpp new file mode 100644 index 000000000..75a8097c1 --- /dev/null +++ b/tools/test/mock/mock_ans_notification.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2021-2022 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 "ans_notification.h" +#include "ans_inner_errors.h" + +namespace OHOS { +namespace Notification { + +ErrCode AnsNotification::SetNotificationsEnabledForSpecifiedBundle( + const NotificationBundleOption &bundleOption, const std::string &deviceId, bool enabled) +{ + if (bundleOption.GetBundleName() == "gg") { + return ERR_OK; + } else { + 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 0891923de..27b6717fa 100644 --- a/tools/test/unittest/dump/BUILD.gn +++ b/tools/test/unittest/dump/BUILD.gn @@ -36,6 +36,7 @@ ohos_unittest("notification_shell_command_dump_test") { "${tools_path}/dump/src/notification_shell_command.cpp", "${tools_path}/dump/src/shell_command.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 4fce48294..0ef829a7f 100644 --- a/tools/test/unittest/dump/notification_shell_command_dump_test.cpp +++ b/tools/test/unittest/dump/notification_shell_command_dump_test.cpp @@ -70,6 +70,14 @@ static char g_enableBundleNameNull[] = " --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"; @@ -534,4 +542,51 @@ HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_1900, Function | Medium EXPECT_EQ(cmd.ExecCommand(), g_enableBundleNameNull); } +<<<<<<< HEAD +======= + +/** + * @tc.number: Anm_Command_Dump_2000 + * @tc.name: RunAsSettingCommand + * @tc.desc: Verify the "anm setting -e bundleName:uid:enable" command. + */ +HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_2000, Function | MediumTest | Level1) +{ + char *argv[] = { + (char *)toolName_.c_str(), + (char *)enable_.c_str(), + (char *)"-e", + (char *)"22", + (char *)"", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + + NotificationShellCommand cmd(argc, argv); + + EXPECT_EQ(cmd.RunSetEnableCmd(), cmd.RunAsSettingCommand()); + EXPECT_EQ(cmd.ExecCommand(), g_enableObjectNull); +} + +/** + * @tc.number: Anm_Command_Dump_2100 + * @tc.name: RunAsSettingCommand + * @tc.desc: Verify the "anm setting -e bundleName:uid:enable" command. + */ +HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_2100, Function | MediumTest | Level1) +{ + char *argv[] = { + (char *)toolName_.c_str(), + (char *)enable_.c_str(), + (char *)"-e", + (char *)"gg:ss:aa", + (char *)"22", + (char *)"", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + + NotificationShellCommand cmd(argc, argv); + + EXPECT_EQ(cmd.ExecCommand(), "set notification enabled success\n"); +} +>>>>>>> IssueNo:https://gitee.com/openharmony/notification_common_event_service/issues/I1T8PA } // namespace \ No newline at end of file -- Gitee From b6a8968fb8de3f9a8bacc49c6b9b2468f135092b Mon Sep 17 00:00:00 2001 From: wwx1143030 Date: Mon, 26 Sep 2022 21:10:24 +0800 Subject: [PATCH 3/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: I300ee5c39899c15c4e12f9ffa0989468906dcb62 --- tools/test/unittest/dump/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/test/unittest/dump/BUILD.gn b/tools/test/unittest/dump/BUILD.gn index 27b6717fa..dab5f1246 100644 --- a/tools/test/unittest/dump/BUILD.gn +++ b/tools/test/unittest/dump/BUILD.gn @@ -35,8 +35,8 @@ ohos_unittest("notification_shell_command_dump_test") { sources = [ "${tools_path}/dump/src/notification_shell_command.cpp", "${tools_path}/dump/src/shell_command.cpp", - "notification_shell_command_dump_test.cpp", "${tools_path}/test/mock/mock_ans_notification.cpp", + "notification_shell_command_dump_test.cpp", ] sources += tools_dump_mock_sources -- Gitee From 838d28ef16a89502e92bcc1c2afd0e32040fa6a5 Mon Sep 17 00:00:00 2001 From: wwx1143030 Date: Mon, 26 Sep 2022 21:14:11 +0800 Subject: [PATCH 4/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 +++--- .../unittest/dump/notification_shell_command_dump_test.cpp | 7 ++----- 2 files changed, 5 insertions(+), 8 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 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 0ef829a7f..ab7c2f0a6 100644 --- a/tools/test/unittest/dump/notification_shell_command_dump_test.cpp +++ b/tools/test/unittest/dump/notification_shell_command_dump_test.cpp @@ -75,8 +75,8 @@ static char g_enableObjectNull[] = "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"; +" --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"; @@ -542,8 +542,6 @@ HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_1900, Function | Medium EXPECT_EQ(cmd.ExecCommand(), g_enableBundleNameNull); } -<<<<<<< HEAD -======= /** * @tc.number: Anm_Command_Dump_2000 @@ -588,5 +586,4 @@ HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_2100, Function | Medium EXPECT_EQ(cmd.ExecCommand(), "set notification enabled success\n"); } ->>>>>>> IssueNo:https://gitee.com/openharmony/notification_common_event_service/issues/I1T8PA } // namespace \ No newline at end of file -- Gitee