/* * 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 #include "account_command.h" using namespace testing::ext; using namespace OHOS; using namespace OHOS::AAFwk; using namespace OHOS::AccountSA; namespace { const std::string HELP_MSG_UNKNOWN_OPTION = "error: unknown option."; const std::string STRING_LOCAL_ACCOUNT_ID = "1024"; const std::string STRING_CONSTRAINT = "constraint.bluetooth"; } // namespace class AccountCommandSetTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); void SetUp() override; void TearDown() override; std::string cmd_ = "set"; }; void AccountCommandSetTest::SetUpTestCase() {} void AccountCommandSetTest::TearDownTestCase() {} void AccountCommandSetTest::SetUp() { // reset optind to 0 optind = 0; } void AccountCommandSetTest::TearDown() {} /** * @tc.name: Acm_Command_Set_0100 * @tc.desc: Verify the "acm set" command. * @tc.type: FUNC * @tc.require: SR000GGVFO */ HWTEST_F(AccountCommandSetTest, Acm_Command_Set_0100, TestSize.Level1) { char *argv[] = { (char *)TOOL_NAME.c_str(), (char *)cmd_.c_str(), (char *)"", }; int argc = sizeof(argv) / sizeof(argv[0]) - 1; AccountCommand cmd(argc, argv); EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_SET); } /** * @tc.name: Acm_Command_Set_0200 * @tc.desc: Verify the "acm set xxx" command. * @tc.type: FUNC * @tc.require: SR000GGVFO */ HWTEST_F(AccountCommandSetTest, Acm_Command_Set_0200, TestSize.Level1) { char *argv[] = { (char *)TOOL_NAME.c_str(), (char *)cmd_.c_str(), (char *)"xxx", (char *)"", }; int argc = sizeof(argv) / sizeof(argv[0]) - 1; AccountCommand cmd(argc, argv); EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_SET); } /** * @tc.name: Acm_Command_Set_0300 * @tc.desc: Verify the "acm set -x" command. * @tc.type: FUNC * @tc.require: SR000GGVFO */ HWTEST_F(AccountCommandSetTest, Acm_Command_Set_0300, TestSize.Level1) { char *argv[] = { (char *)TOOL_NAME.c_str(), (char *)cmd_.c_str(), (char *)"-x", (char *)"", }; int argc = sizeof(argv) / sizeof(argv[0]) - 1; AccountCommand cmd(argc, argv); EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_UNKNOWN_OPTION + "\n" + HELP_MSG_SET); } /** * @tc.name: Acm_Command_Set_0400 * @tc.desc: Verify the "acm set -xxx" command. * @tc.type: FUNC * @tc.require: SR000GGVFO */ HWTEST_F(AccountCommandSetTest, Acm_Command_Set_0400, TestSize.Level1) { char *argv[] = { (char *)TOOL_NAME.c_str(), (char *)cmd_.c_str(), (char *)"-xxx", (char *)"", }; int argc = sizeof(argv) / sizeof(argv[0]) - 1; AccountCommand cmd(argc, argv); EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_UNKNOWN_OPTION + "\n" + HELP_MSG_SET); } /** * @tc.name: Acm_Command_Set_0500 * @tc.desc: Verify the "acm set --x" command. * @tc.type: FUNC * @tc.require: SR000GGVFO */ HWTEST_F(AccountCommandSetTest, Acm_Command_Set_0500, TestSize.Level1) { char *argv[] = { (char *)TOOL_NAME.c_str(), (char *)cmd_.c_str(), (char *)"--x", (char *)"", }; int argc = sizeof(argv) / sizeof(argv[0]) - 1; AccountCommand cmd(argc, argv); EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_UNKNOWN_OPTION + "\n" + HELP_MSG_SET); } /** * @tc.name: Acm_Command_Set_0600 * @tc.desc: Verify the "acm set --xxx" command. * @tc.type: FUNC * @tc.require: SR000GGVFO */ HWTEST_F(AccountCommandSetTest, Acm_Command_Set_0600, TestSize.Level1) { char *argv[] = { (char *)TOOL_NAME.c_str(), (char *)cmd_.c_str(), (char *)"--xxx", (char *)"", }; int argc = sizeof(argv) / sizeof(argv[0]) - 1; AccountCommand cmd(argc, argv); EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_UNKNOWN_OPTION + "\n" + HELP_MSG_SET); } /** * @tc.name: Acm_Command_Set_0700 * @tc.desc: Verify the "acm set -h" command. * @tc.type: FUNC * @tc.require: SR000GGVFO */ HWTEST_F(AccountCommandSetTest, Acm_Command_Set_0700, TestSize.Level1) { char *argv[] = { (char *)TOOL_NAME.c_str(), (char *)cmd_.c_str(), (char *)"-h", (char *)"", }; int argc = sizeof(argv) / sizeof(argv[0]) - 1; AccountCommand cmd(argc, argv); EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_SET); } /** * @tc.name: Acm_Command_Set_0800 * @tc.desc: Verify the "acm set --help" command. * @tc.type: FUNC * @tc.require: SR000GGVFO */ HWTEST_F(AccountCommandSetTest, Acm_Command_Set_0800, TestSize.Level1) { char *argv[] = { (char *)TOOL_NAME.c_str(), (char *)cmd_.c_str(), (char *)"--help", (char *)"", }; int argc = sizeof(argv) / sizeof(argv[0]) - 1; AccountCommand cmd(argc, argv); EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_SET); } /** * @tc.name: Acm_Command_Set_0900 * @tc.desc: Verify the "acm set -i" command. * @tc.type: FUNC * @tc.require: SR000GGVFO */ HWTEST_F(AccountCommandSetTest, Acm_Command_Set_0900, TestSize.Level1) { char *argv[] = { (char *)TOOL_NAME.c_str(), (char *)cmd_.c_str(), (char *)"-i", (char *)"", }; int argc = sizeof(argv) / sizeof(argv[0]) - 1; AccountCommand cmd(argc, argv); EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_OPTION_REQUIRES_AN_ARGUMENT + "\n" + HELP_MSG_SET); } /** * @tc.name: Acm_Command_Set_1000 * @tc.desc: Verify the "acm set -i " command. * @tc.type: FUNC * @tc.require: SR000GGVFO */ HWTEST_F(AccountCommandSetTest, Acm_Command_Set_1000, TestSize.Level1) { char *argv[] = { (char *)TOOL_NAME.c_str(), (char *)cmd_.c_str(), (char *)"-i", (char *)STRING_LOCAL_ACCOUNT_ID.c_str(), (char *)"", }; int argc = sizeof(argv) / sizeof(argv[0]) - 1; AccountCommand cmd(argc, argv); EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_CONSTRAINTS_OPTION + "\n" + HELP_MSG_SET); } /** * @tc.name: Acm_Command_Set_1100 * @tc.desc: Verify the "acm set -c" command. * @tc.type: FUNC * @tc.require: SR000GGVFO */ HWTEST_F(AccountCommandSetTest, Acm_Command_Set_1100, TestSize.Level1) { char *argv[] = { (char *)TOOL_NAME.c_str(), (char *)cmd_.c_str(), (char *)"-c", (char *)"", }; int argc = sizeof(argv) / sizeof(argv[0]) - 1; AccountCommand cmd(argc, argv); EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_OPTION_REQUIRES_AN_ARGUMENT + "\n" + HELP_MSG_SET); } /** * @tc.name: Acm_Command_Set_1200 * @tc.desc: Verify the "acm set -c " command. * @tc.type: FUNC * @tc.require: SR000GGVFO */ HWTEST_F(AccountCommandSetTest, Acm_Command_Set_1200, TestSize.Level1) { char *argv[] = { (char *)TOOL_NAME.c_str(), (char *)cmd_.c_str(), (char *)"-c", (char *)STRING_CONSTRAINT.c_str(), (char *)"", }; int argc = sizeof(argv) / sizeof(argv[0]) - 1; AccountCommand cmd(argc, argv); EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_ID_OPTION + "\n" + HELP_MSG_SET); } /** * @tc.name: Acm_Command_Set_1300 * @tc.desc: Verify the "acm set -i -c" command. * @tc.type: FUNC * @tc.require: SR000GGVFO */ HWTEST_F(AccountCommandSetTest, Acm_Command_Set_1300, TestSize.Level1) { char *argv[] = { (char *)TOOL_NAME.c_str(), (char *)cmd_.c_str(), (char *)"-i", (char *)STRING_LOCAL_ACCOUNT_ID.c_str(), (char *)"-c", (char *)"", }; int argc = sizeof(argv) / sizeof(argv[0]) - 1; AccountCommand cmd(argc, argv); EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_OPTION_REQUIRES_AN_ARGUMENT + "\n" + HELP_MSG_SET); } /** * @tc.name: Acm_Command_Set_1400 * @tc.desc: Verify the "acm set -c -i" command. * @tc.type: FUNC * @tc.require: SR000GGVFO */ HWTEST_F(AccountCommandSetTest, Acm_Command_Set_1400, TestSize.Level1) { char *argv[] = { (char *)TOOL_NAME.c_str(), (char *)cmd_.c_str(), (char *)"-c", (char *)STRING_CONSTRAINT.c_str(), (char *)"-i", (char *)"", }; int argc = sizeof(argv) / sizeof(argv[0]) - 1; AccountCommand cmd(argc, argv); EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_OPTION_REQUIRES_AN_ARGUMENT + "\n" + HELP_MSG_SET); }