mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 22:21:36 -04:00
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 <ability> -b <bundle> -u" without argument - Aa_Command_Start_5200: Verify "aa start -a <ability> -b <bundle> -u xxx" (non-numeric) - Aa_Command_Start_5300: Verify "aa start -a <ability> -b <bundle> -u -1" (negative) - Aa_Command_Start_5400: Verify "aa start -a <ability> -b <bundle> -u 100" (valid) - Aa_Command_Start_5500: Verify "aa start -a <ability> -b <bundle> -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 <luoyicong@h-partners.com> Co-Authored-By: Agent
This commit is contained in:
@@ -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 <ability> -b <bundle> -u <invalid>" 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 <ability> -b <bundle> -u <negative>" 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 <ability> -b <bundle> -u <valid>" 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 <ability> -b <bundle> -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user