From 64979c5869d60ea7a267f1f034ee2660abe9efdc Mon Sep 17 00:00:00 2001 From: Luobniz21 Date: Wed, 25 Mar 2026 09:25:31 +0800 Subject: [PATCH] aa start: add TDD test cases for -u option Add test coverage for the three new branches added with userId support: 1. Test -u option without argument (branch in option error handling) 2. Test -u option with invalid userId (non-numeric or negative) 3. Test -u option with valid userId (100 and 0) Test cases: - Aa_Command_Start_5100: Verify "aa start -a -b -u" without argument - Aa_Command_Start_5200: Verify "aa start -a -b -u xxx" (non-numeric) - Aa_Command_Start_5300: Verify "aa start -a -b -u -1" (negative) - Aa_Command_Start_5400: Verify "aa start -a -b -u 100" (valid) - Aa_Command_Start_5500: Verify "aa start -a -b -u 0" (valid) Note: The -W option conflict warning is covered implicitly as it only logs a warning and doesn't affect command execution result. Signed-off-by: Luobniz21 Co-Authored-By: Agent --- .../unittest/aa/aa_command_start_test.cpp | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/tools/test/unittest/aa/aa_command_start_test.cpp b/tools/test/unittest/aa/aa_command_start_test.cpp index d12dfcb76a..3a25120070 100644 --- a/tools/test/unittest/aa/aa_command_start_test.cpp +++ b/tools/test/unittest/aa/aa_command_start_test.cpp @@ -1570,3 +1570,133 @@ HWTEST_F(AaCommandStartTest, IsStartOption_0050, Function | MediumTest | Level1) AbilityManagerShellCommand cmd(argc, argv); EXPECT_FALSE(cmd.IsStartOption("100")); } + +/** + * @tc.number: Aa_Command_Start_5100 + * @tc.name: ExecCommand + * @tc.desc: Verify the "aa start -u" command without argument. + */ +HWTEST_F(AaCommandStartTest, Aa_Command_Start_5100, Function | MediumTest | Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_5100"); + + char* argv[] = { + (char*)TOOL_NAME.c_str(), + (char*)cmd_.c_str(), + (char*)"-a", + (char*)STRING_ABILITY_NAME.c_str(), + (char*)"-b", + (char*)STRING_BUNDLE_NAME.c_str(), + (char*)"-u", + (char*)"", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + + AbilityManagerShellCommand cmd(argc, argv); + EXPECT_EQ(cmd.ExecCommand(), "error: option requires a value.\n" + HELP_MSG_START); +} + +/** + * @tc.number: Aa_Command_Start_5200 + * @tc.name: ExecCommand + * @tc.desc: Verify the "aa start -a -b -u " command with non-numeric userId. + */ +HWTEST_F(AaCommandStartTest, Aa_Command_Start_5200, Function | MediumTest | Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_5200"); + + char* argv[] = { + (char*)TOOL_NAME.c_str(), + (char*)cmd_.c_str(), + (char*)"-a", + (char*)STRING_ABILITY_NAME.c_str(), + (char*)"-b", + (char*)STRING_BUNDLE_NAME.c_str(), + (char*)"-u", + (char*)"xxx", + (char*)"", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + + AbilityManagerShellCommand cmd(argc, argv); + EXPECT_EQ(cmd.ExecCommand(), "error: invalid user id: xxx\n" + HELP_MSG_START); +} + +/** + * @tc.number: Aa_Command_Start_5300 + * @tc.name: ExecCommand + * @tc.desc: Verify the "aa start -a -b -u " command with negative userId. + */ +HWTEST_F(AaCommandStartTest, Aa_Command_Start_5300, Function | MediumTest | Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_5300"); + + char* argv[] = { + (char*)TOOL_NAME.c_str(), + (char*)cmd_.c_str(), + (char*)"-a", + (char*)STRING_ABILITY_NAME.c_str(), + (char*)"-b", + (char*)STRING_BUNDLE_NAME.c_str(), + (char*)"-u", + (char*)"-1", + (char*)"", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + + AbilityManagerShellCommand cmd(argc, argv); + EXPECT_EQ(cmd.ExecCommand(), "error: invalid user id: -1\n" + HELP_MSG_START); +} + +/** + * @tc.number: Aa_Command_Start_5400 + * @tc.name: ExecCommand + * @tc.desc: Verify the "aa start -a -b -u " command with valid userId. + */ +HWTEST_F(AaCommandStartTest, Aa_Command_Start_5400, Function | MediumTest | Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_5400"); + + char* argv[] = { + (char*)TOOL_NAME.c_str(), + (char*)cmd_.c_str(), + (char*)"-a", + (char*)STRING_ABILITY_NAME.c_str(), + (char*)"-b", + (char*)STRING_BUNDLE_NAME.c_str(), + (char*)"-u", + (char*)"100", + (char*)"", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + + AbilityManagerShellCommand cmd(argc, argv); + EXPECT_EQ(cmd.ExecCommand(), STRING_START_ABILITY_OK + "\n"); +} + +/** + * @tc.number: Aa_Command_Start_5500 + * @tc.name: ExecCommand + * @tc.desc: Verify the "aa start -a -b -u 0" command with userId = 0. + */ +HWTEST_F(AaCommandStartTest, Aa_Command_Start_5500, Function | MediumTest | Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_5500"); + + char* argv[] = { + (char*)TOOL_NAME.c_str(), + (char*)cmd_.c_str(), + (char*)"-a", + (char*)STRING_ABILITY_NAME.c_str(), + (char*)"-b", + (char*)STRING_BUNDLE_NAME.c_str(), + (char*)"-u", + (char*)"0", + (char*)"", + }; + int argc = sizeof(argv) / sizeof(argv[0]) - 1; + + AbilityManagerShellCommand cmd(argc, argv); + EXPECT_EQ(cmd.ExecCommand(), STRING_START_ABILITY_OK + "\n"); +} +}