• 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::AAFwk;
23 using namespace OHOS::AccountSA;
24 
25 namespace {
26 const std::string HELP_MSG_UNKNOWN_OPTION = "error: unknown option.";
27 
28 const std::string STRING_LOCAL_ACCOUNT_ID = "1024";
29 const std::string STRING_CONSTRAINT = "constraint.bluetooth";
30 }  // namespace
31 
32 class AccountCommandSetTest : public testing::Test {
33 public:
34     static void SetUpTestCase();
35     static void TearDownTestCase();
36     void SetUp() override;
37     void TearDown() override;
38 
39     std::string cmd_ = "set";
40 };
41 
SetUpTestCase()42 void AccountCommandSetTest::SetUpTestCase()
43 {}
44 
TearDownTestCase()45 void AccountCommandSetTest::TearDownTestCase()
46 {}
47 
SetUp()48 void AccountCommandSetTest::SetUp()
49 {
50     // reset optind to 0
51     optind = 0;
52 }
53 
TearDown()54 void AccountCommandSetTest::TearDown()
55 {}
56 
57 /**
58  * @tc.name: Acm_Command_Set_0100
59  * @tc.desc: Verify the "acm set" command.
60  * @tc.type: FUNC
61  * @tc.require: SR000GGVFO
62  */
63 HWTEST_F(AccountCommandSetTest, Acm_Command_Set_0100, TestSize.Level1)
64 {
65     char *argv[] = {
66         (char *)TOOL_NAME.c_str(),
67         (char *)cmd_.c_str(),
68         (char *)"",
69     };
70     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
71 
72     AccountCommand cmd(argc, argv);
73     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_SET);
74 }
75 
76 /**
77  * @tc.name: Acm_Command_Set_0200
78  * @tc.desc: Verify the "acm set xxx" command.
79  * @tc.type: FUNC
80  * @tc.require: SR000GGVFO
81  */
82 HWTEST_F(AccountCommandSetTest, Acm_Command_Set_0200, TestSize.Level1)
83 {
84     char *argv[] = {
85         (char *)TOOL_NAME.c_str(),
86         (char *)cmd_.c_str(),
87         (char *)"xxx",
88         (char *)"",
89     };
90     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
91 
92     AccountCommand cmd(argc, argv);
93     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_SET);
94 }
95 
96 /**
97  * @tc.name: Acm_Command_Set_0300
98  * @tc.desc: Verify the "acm set -x" command.
99  * @tc.type: FUNC
100  * @tc.require: SR000GGVFO
101  */
102 HWTEST_F(AccountCommandSetTest, Acm_Command_Set_0300, TestSize.Level1)
103 {
104     char *argv[] = {
105         (char *)TOOL_NAME.c_str(),
106         (char *)cmd_.c_str(),
107         (char *)"-x",
108         (char *)"",
109     };
110     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
111 
112     AccountCommand cmd(argc, argv);
113     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_UNKNOWN_OPTION + "\n" + HELP_MSG_SET);
114 }
115 
116 /**
117  * @tc.name: Acm_Command_Set_0400
118  * @tc.desc: Verify the "acm set -xxx" command.
119  * @tc.type: FUNC
120  * @tc.require: SR000GGVFO
121  */
122 HWTEST_F(AccountCommandSetTest, Acm_Command_Set_0400, TestSize.Level1)
123 {
124     char *argv[] = {
125         (char *)TOOL_NAME.c_str(),
126         (char *)cmd_.c_str(),
127         (char *)"-xxx",
128         (char *)"",
129     };
130     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
131 
132     AccountCommand cmd(argc, argv);
133     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_UNKNOWN_OPTION + "\n" + HELP_MSG_SET);
134 }
135 
136 /**
137  * @tc.name: Acm_Command_Set_0500
138  * @tc.desc: Verify the "acm set --x" command.
139  * @tc.type: FUNC
140  * @tc.require: SR000GGVFO
141  */
142 HWTEST_F(AccountCommandSetTest, Acm_Command_Set_0500, TestSize.Level1)
143 {
144     char *argv[] = {
145         (char *)TOOL_NAME.c_str(),
146         (char *)cmd_.c_str(),
147         (char *)"--x",
148         (char *)"",
149     };
150     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
151 
152     AccountCommand cmd(argc, argv);
153     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_UNKNOWN_OPTION + "\n" + HELP_MSG_SET);
154 }
155 
156 /**
157  * @tc.name: Acm_Command_Set_0600
158  * @tc.desc: Verify the "acm set --xxx" command.
159  * @tc.type: FUNC
160  * @tc.require: SR000GGVFO
161  */
162 HWTEST_F(AccountCommandSetTest, Acm_Command_Set_0600, TestSize.Level1)
163 {
164     char *argv[] = {
165         (char *)TOOL_NAME.c_str(),
166         (char *)cmd_.c_str(),
167         (char *)"--xxx",
168         (char *)"",
169     };
170     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
171 
172     AccountCommand cmd(argc, argv);
173     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_UNKNOWN_OPTION + "\n" + HELP_MSG_SET);
174 }
175 
176 /**
177  * @tc.name: Acm_Command_Set_0700
178  * @tc.desc: Verify the "acm set -h" command.
179  * @tc.type: FUNC
180  * @tc.require: SR000GGVFO
181  */
182 HWTEST_F(AccountCommandSetTest, Acm_Command_Set_0700, TestSize.Level1)
183 {
184     char *argv[] = {
185         (char *)TOOL_NAME.c_str(),
186         (char *)cmd_.c_str(),
187         (char *)"-h",
188         (char *)"",
189     };
190     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
191 
192     AccountCommand cmd(argc, argv);
193     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_SET);
194 }
195 
196 /**
197  * @tc.name: Acm_Command_Set_0800
198  * @tc.desc: Verify the "acm set --help" command.
199  * @tc.type: FUNC
200  * @tc.require: SR000GGVFO
201  */
202 HWTEST_F(AccountCommandSetTest, Acm_Command_Set_0800, TestSize.Level1)
203 {
204     char *argv[] = {
205         (char *)TOOL_NAME.c_str(),
206         (char *)cmd_.c_str(),
207         (char *)"--help",
208         (char *)"",
209     };
210     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
211 
212     AccountCommand cmd(argc, argv);
213     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_SET);
214 }
215 
216 /**
217  * @tc.name: Acm_Command_Set_0900
218  * @tc.desc: Verify the "acm set -i" command.
219  * @tc.type: FUNC
220  * @tc.require: SR000GGVFO
221  */
222 HWTEST_F(AccountCommandSetTest, Acm_Command_Set_0900, TestSize.Level1)
223 {
224     char *argv[] = {
225         (char *)TOOL_NAME.c_str(),
226         (char *)cmd_.c_str(),
227         (char *)"-i",
228         (char *)"",
229     };
230     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
231 
232     AccountCommand cmd(argc, argv);
233     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_OPTION_REQUIRES_AN_ARGUMENT + "\n" + HELP_MSG_SET);
234 }
235 
236 /**
237  * @tc.name: Acm_Command_Set_1000
238  * @tc.desc: Verify the "acm set -i <local-account-id>" command.
239  * @tc.type: FUNC
240  * @tc.require: SR000GGVFO
241  */
242 HWTEST_F(AccountCommandSetTest, Acm_Command_Set_1000, TestSize.Level1)
243 {
244     char *argv[] = {
245         (char *)TOOL_NAME.c_str(),
246         (char *)cmd_.c_str(),
247         (char *)"-i",
248         (char *)STRING_LOCAL_ACCOUNT_ID.c_str(),
249         (char *)"",
250     };
251     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
252 
253     AccountCommand cmd(argc, argv);
254     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_CONSTRAINTS_OPTION + "\n" + HELP_MSG_SET);
255 }
256 
257 /**
258  * @tc.name: Acm_Command_Set_1100
259  * @tc.desc: Verify the "acm set -c" command.
260  * @tc.type: FUNC
261  * @tc.require: SR000GGVFO
262  */
263 HWTEST_F(AccountCommandSetTest, Acm_Command_Set_1100, TestSize.Level1)
264 {
265     char *argv[] = {
266         (char *)TOOL_NAME.c_str(),
267         (char *)cmd_.c_str(),
268         (char *)"-c",
269         (char *)"",
270     };
271     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
272 
273     AccountCommand cmd(argc, argv);
274     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_OPTION_REQUIRES_AN_ARGUMENT + "\n" + HELP_MSG_SET);
275 }
276 
277 /**
278  * @tc.name: Acm_Command_Set_1200
279  * @tc.desc: Verify the "acm set -c <constraints>" command.
280  * @tc.type: FUNC
281  * @tc.require: SR000GGVFO
282  */
283 HWTEST_F(AccountCommandSetTest, Acm_Command_Set_1200, TestSize.Level1)
284 {
285     char *argv[] = {
286         (char *)TOOL_NAME.c_str(),
287         (char *)cmd_.c_str(),
288         (char *)"-c",
289         (char *)STRING_CONSTRAINT.c_str(),
290         (char *)"",
291     };
292     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
293 
294     AccountCommand cmd(argc, argv);
295     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_ID_OPTION + "\n" + HELP_MSG_SET);
296 }
297 
298 /**
299  * @tc.name: Acm_Command_Set_1300
300  * @tc.desc: Verify the "acm set -i <local-account-id> -c" command.
301  * @tc.type: FUNC
302  * @tc.require: SR000GGVFO
303  */
304 HWTEST_F(AccountCommandSetTest, Acm_Command_Set_1300, TestSize.Level1)
305 {
306     char *argv[] = {
307         (char *)TOOL_NAME.c_str(),
308         (char *)cmd_.c_str(),
309         (char *)"-i",
310         (char *)STRING_LOCAL_ACCOUNT_ID.c_str(),
311         (char *)"-c",
312         (char *)"",
313     };
314     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
315 
316     AccountCommand cmd(argc, argv);
317     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_OPTION_REQUIRES_AN_ARGUMENT + "\n" + HELP_MSG_SET);
318 }
319 
320 /**
321  * @tc.name: Acm_Command_Set_1400
322  * @tc.desc: Verify the "acm set -c <constraints> -i" command.
323  * @tc.type: FUNC
324  * @tc.require: SR000GGVFO
325  */
326 HWTEST_F(AccountCommandSetTest, Acm_Command_Set_1400, TestSize.Level1)
327 {
328     char *argv[] = {
329         (char *)TOOL_NAME.c_str(),
330         (char *)cmd_.c_str(),
331         (char *)"-c",
332         (char *)STRING_CONSTRAINT.c_str(),
333         (char *)"-i",
334         (char *)"",
335     };
336     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
337 
338     AccountCommand cmd(argc, argv);
339     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_OPTION_REQUIRES_AN_ARGUMENT + "\n" + HELP_MSG_SET);
340 }
341