• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 
18 #include "account_command.h"
19 
20 using namespace testing::ext;
21 using namespace OHOS;
22 using namespace OHOS::AccountSA;
23 
24 class AccountCommandTest : public testing::Test {
25 public:
26     static void SetUpTestCase();
27     static void TearDownTestCase();
28     void SetUp() override;
29     void TearDown() override;
30 };
31 
SetUpTestCase()32 void AccountCommandTest::SetUpTestCase()
33 {}
34 
TearDownTestCase()35 void AccountCommandTest::TearDownTestCase()
36 {}
37 
SetUp()38 void AccountCommandTest::SetUp()
39 {
40     // reset optind to 0
41     optind = 0;
42 }
43 
TearDown()44 void AccountCommandTest::TearDown()
45 {}
46 
47 /**
48  * @tc.name: Acm_Command_0100
49  * @tc.desc: Verify the "acm" command.
50  * @tc.type: FUNC
51  * @tc.require: SR000GGVFO
52  */
53 HWTEST_F(AccountCommandTest, Acm_Command_0100, TestSize.Level1)
54 {
55     char *argv[] = {
56         (char *)TOOL_NAME.c_str(),
57         (char *)"",
58     };
59     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
60 
61     AccountCommand cmd(argc, argv);
62     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG);
63 }
64 
65 /**
66  * @tc.name: Acm_Command_0200
67  * @tc.desc: Verify the "acm xxx" command.
68  * @tc.type: FUNC
69  * @tc.require: SR000GGVFO
70  */
71 HWTEST_F(AccountCommandTest, Acm_Command_0200, TestSize.Level1)
72 {
73     char *argv[] = {
74         (char *)TOOL_NAME.c_str(),
75         (char *)"xxx",
76         (char *)"",
77     };
78     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
79 
80     AccountCommand cmd(argc, argv);
81     EXPECT_EQ(cmd.ExecCommand(), cmd.GetCommandErrorMsg() + HELP_MSG);
82 }
83 
84 /**
85  * @tc.name: Acm_Command_0300
86  * @tc.desc: Verify the "acm -xxx" command.
87  * @tc.type: FUNC
88  * @tc.require: SR000GGVFO
89  */
90 HWTEST_F(AccountCommandTest, Acm_Command_0300, TestSize.Level1)
91 {
92     char *argv[] = {
93         (char *)TOOL_NAME.c_str(),
94         (char *)"-xxx",
95         (char *)"",
96     };
97     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
98 
99     AccountCommand cmd(argc, argv);
100     EXPECT_EQ(cmd.ExecCommand(), cmd.GetCommandErrorMsg() + HELP_MSG);
101 }
102 
103 /**
104  * @tc.name: Acm_Command_0400
105  * @tc.desc: Verify the "acm --xxx" command.
106  * @tc.type: FUNC
107  * @tc.require: SR000GGVFO
108  */
109 HWTEST_F(AccountCommandTest, Acm_Command_0400, TestSize.Level1)
110 {
111     char *argv[] = {
112         (char *)TOOL_NAME.c_str(),
113         (char *)"--xxx",
114         (char *)"",
115     };
116     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
117 
118     AccountCommand cmd(argc, argv);
119     EXPECT_EQ(cmd.ExecCommand(), cmd.GetCommandErrorMsg() + HELP_MSG);
120 }
121 
122 /**
123  * @tc.name: Acm_Command_0500
124  * @tc.desc: Verify the "acm help" command.
125  * @tc.type: FUNC
126  * @tc.require: SR000GGVFO
127  */
128 HWTEST_F(AccountCommandTest, Acm_Command_0500, TestSize.Level1)
129 {
130     char *argv[] = {
131         (char *)TOOL_NAME.c_str(),
132         (char *)"help",
133         (char *)"",
134     };
135     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
136 
137     AccountCommand cmd(argc, argv);
138     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG);
139 }
140