diff --git a/tools/test/mock/mock_ans_notification.cpp b/tools/test/mock/mock_ans_notification.cpp new file mode 100644 index 0000000000000000000000000000000000000000..071d92d7e22b125f0f571f96facaf1878c945dd5 --- /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 0891923de76a237ac63313166c87e705d14aa5dd..dab5f124614f9ca4cd7d4a574dd371b1ad2e73f3 100644 --- a/tools/test/unittest/dump/BUILD.gn +++ b/tools/test/unittest/dump/BUILD.gn @@ -35,6 +35,7 @@ ohos_unittest("notification_shell_command_dump_test") { sources = [ "${tools_path}/dump/src/notification_shell_command.cpp", "${tools_path}/dump/src/shell_command.cpp", + "${tools_path}/test/mock/mock_ans_notification.cpp", "notification_shell_command_dump_test.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 73a22b3b58f2affb9beac69e05e66af6111eec86..ab7c2f0a65b1a6250c2bdd202bde205cb487552c 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,23 @@ 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_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"; @@ -534,4 +542,48 @@ HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_1900, Function | Medium EXPECT_EQ(cmd.ExecCommand(), g_enableBundleNameNull); } + +/** + * @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"); +} } // namespace \ No newline at end of file