diff --git a/tools/test/mock/mock_ans_manager_stub.cpp b/tools/test/mock/mock_ans_manager_stub.cpp index 5f66ac3be61ae8e8ff6e1347e79b6f95be7f676b..0e060f19baa71065ecdd724c698e345cb53ea033 100644 --- a/tools/test/mock/mock_ans_manager_stub.cpp +++ b/tools/test/mock/mock_ans_manager_stub.cpp @@ -29,6 +29,11 @@ std::string MockAnsManagerStub::GetBundle() return bundle_; } +int32_t MockAnsManagerStub::GetUserId() +{ + return userId_; +} + ErrCode MockAnsManagerStub::ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId, std::vector &dumpInfo) { diff --git a/tools/test/mock/mock_ans_manager_stub.h b/tools/test/mock/mock_ans_manager_stub.h index 1cb8eb3285ff8cbe587251a1198d2ed01a07dc2a..3d0ad8d9daa5b6e962c97dc1db1686f75165ec33 100644 --- a/tools/test/mock/mock_ans_manager_stub.h +++ b/tools/test/mock/mock_ans_manager_stub.h @@ -28,6 +28,7 @@ public: std::string GetCmd(); std::string GetBundle(); + int32_t GetUserId(); /** * @brief Obtains specific datas via specified dump option. 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 21a1cf43a5ed740382b70bf78adabed7a30f64ec..71bf671e714cd995509ada068789b323b7ddbe39 100644 --- a/tools/test/unittest/dump/notification_shell_command_dump_test.cpp +++ b/tools/test/unittest/dump/notification_shell_command_dump_test.cpp @@ -32,18 +32,29 @@ namespace { "usage: anm dump []\n" "options list:\n" " --help, -h help menu\n" - " --active, -A list all active notifications\n" - " --recent, -R list recent notifications\n" - " --bundle, -b specified a bundle filter\n"; + " --active, -A list all active notifications\n" + " --recent, -R list recent notifications\n" + " --bundle, -b dump the info filter by the specified bundle name\n" + " --user-id, -u dump the info filter by the specified userId\n"; static char DUMP_ACTIVE_BOUND[] = "error: option 'b' requires a value.\n" + "usage: anm dump []\noptions list:\n" + " --help, -h help menu\n" + " --active, -A list all active notifications\n" + " --recent, -R list recent notifications\n" + " --bundle, -b dump the info filter by the specified bundle name\n" + " --user-id, -u dump the info filter by the specified userId\n"; + + static char DUMP_ACTIVE_USER[] = + "error: option 'u' requires a value.\n" "usage: anm dump []\n" "options list:\n" " --help, -h help menu\n" - " --active, -A list all active notifications\n" - " --recent, -R list recent notifications\n" - " --bundle, -b specified a bundle filter\n"; + " --active, -A list all active notifications\n" + " --recent, -R list recent notifications\n" + " --bundle, -b dump the info filter by the specified bundle name\n" + " --user-id, -u dump the info filter by the specified userId\n"; static char BUNDLE_NAME[] = "example"; static char COMMAND_ACTIVE[] = "active"; @@ -251,3 +262,96 @@ HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_0700, Function | Medium EXPECT_EQ(stubPtr_->GetCmd(), COMMAND_RECENT); EXPECT_EQ(stubPtr_->GetBundle(), BUNDLE_NAME); } + +/** + * @tc.number: Anm_Command_Dump_0800 + * @tc.name: ExecCommand + * @tc.desc: Verify the "anm dump -R -u" command. + */ +HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_0800, Function | MediumTest | Level1) +{ + char *argv[] = { + (char *)toolName_.c_str(), + (char *)cmd_.c_str(), + (char *)"-R", + (char *)"-u", + (char *)"", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + + NotificationShellCommand cmd(argc, argv); + + EXPECT_EQ(cmd.ExecCommand(), DUMP_ACTIVE_USER); +} + +/** + * @tc.number: Anm_Command_Dump_0900 + * @tc.name: ExecCommand + * @tc.desc: Verify the "anm dump -A -u" command. + */ +HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_0900, Function | MediumTest | Level1) +{ + char *argv[] = { + (char *)toolName_.c_str(), + (char *)cmd_.c_str(), + (char *)"-A", + (char *)"-u", + (char *)"", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + + NotificationShellCommand cmd(argc, argv); + + EXPECT_EQ(cmd.ExecCommand(), DUMP_ACTIVE_USER); +} + +/** + * @tc.number: Anm_Command_Dump_1000 + * @tc.name: ExecCommand + * @tc.desc: Verify the "anm dump -A -u 33" command. + */ +HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_1000, Function | MediumTest | Level1) +{ + char *argv[] = { + (char *)toolName_.c_str(), + (char *)cmd_.c_str(), + (char *)"-A", + (char *)"-u", + (char *)"33", + (char *)"", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + + NotificationShellCommand cmd(argc, argv); + + cmd.ExecCommand(); + + EXPECT_EQ(stubPtr_->GetCmd(), COMMAND_ACTIVE); + EXPECT_EQ(stubPtr_->GetUserId(), 33); +} + +/** + * @tc.number: Anm_Command_Dump_1100 + * @tc.name: ExecCommand + * @tc.desc: Verify the "anm dump -R -u 33" command. + */ +HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_1100, Function | MediumTest | Level1) +{ + char *argv[] = { + (char *)toolName_.c_str(), + (char *)cmd_.c_str(), + (char *)"-R", + (char *)"-u", + (char *)"33", + (char *)"", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + + NotificationShellCommand cmd(argc, argv); + + cmd.ExecCommand(); + + EXPECT_EQ(stubPtr_->GetCmd(), COMMAND_RECENT); + EXPECT_EQ(stubPtr_->GetUserId(), 33); +} +