1 /*
2  * Copyright (c) 2021-2024 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 #define protected public
19 #include "ability_command.h"
20 #undef protected
21 #include "mock_ability_manager_stub.h"
22 #define private public
23 #include "ability_manager_client.h"
24 #undef private
25 #include "ability_manager_interface.h"
26 #include "hilog_tag_wrapper.h"
27 
28 using namespace testing::ext;
29 using namespace OHOS;
30 using namespace OHOS::AAFwk;
31 
32 namespace {
33 const std::string STRING_DEVICE = "device";
34 const std::string STRING_ABILITY_NAME = "ability";
35 const std::string STRING_ABILITY_NAME_INVALID = "invalid_ability";
36 const std::string STRING_BUNDLE_NAME = "bundle";
37 const std::string STRING_BUNDLE_NAME_INVALID = "invalid_bundle";
38 const std::string STRING_RECORD_ID = "1024";
39 const std::string STRING_RECORD_ID_INVALID = "2048";
40 const std::string STRING_STATE_ON = "on";
41 const std::string STRING_STATE_ON_INVALID = "invalid_on";
42 const std::string STRING_STATE_OFF = "off";
43 const std::string STRING_STATE_OFF_INVALID = "invalid_off";
44 const std::string STRING_INVALID_PARAMETER_INTEGER_OPTION = "invalid parameter invalid_integer for integer option";
45 const std::string STRING_INVALID_PARAMETER_BOOL_OPTION = "invalid parameter invalid_bool for bool option";
46 const std::string STRING_INVALID_NUMBER_INTEGER_OPTION = "invalid number of parameters for option --pi";
47 const std::string STRING_INVALID_NUMBER_BOOL_OPTION = "invalid number of parameters for option --pb";
48 const std::string STRING_INVALID_NUMBER_STRING_OPTION = "invalid number of parameters for option --ps";
49 const std::string STRING_INVALID_NUMBER_NULL_STRING_OPTION = "invalid number of parameters for option --psn";
50 const std::string STRING_ACTION = "action";
51 const std::string STRING_URI = "https://valid.uri.com";
52 const std::string STRING_TYPE = "type";
53 const std::string STRING_ENTITY = "entity";
54 const std::string STRING_PARAMETER_KEY_INTEGER = "kinteger";
55 const std::string STRING_PARAMETER_KEY_BOOL = "kbool";
56 const std::string STRING_PARAMETER_KEY_STRING = "kstring";
57 const std::string STRING_PARAMETER_KEY_NULL_STRING = "knullstring";
58 const std::string STRING_PARAMETER_VALUE_INTEGER = "100";
59 const std::string STRING_PARAMETER_VALUE_BOOL = "true";
60 const std::string STRING_PARAMETER_VALUE_STRING = "string_value";
61 const std::string STRING_PARAMETER_VALUE_INTEGER_INVALID = "invalid_integer";
62 const std::string STRING_PARAMETER_VALUE_BOOL_INVALID = "invalid_bool";
63 const std::string STRING_PARAMETER_VALUE_STRING_INVALID = "invalid_string_value";
64 }  // namespace
65 
66 class AaCommandStartTest : public ::testing::Test {
67 public:
68     static void SetUpTestCase();
69     static void TearDownTestCase();
70     void SetUp() override;
71     void TearDown() override;
72 
73     void MakeMockObjects() const;
74 
75     std::string cmd_ = "start";
76 };
77 
SetUpTestCase()78 void AaCommandStartTest::SetUpTestCase()
79 {}
80 
TearDownTestCase()81 void AaCommandStartTest::TearDownTestCase()
82 {}
83 
SetUp()84 void AaCommandStartTest::SetUp()
85 {
86     // reset optind to 0
87     optind = 0;
88 
89     // make mock objects
90     MakeMockObjects();
91 }
92 
TearDown()93 void AaCommandStartTest::TearDown()
94 {}
95 
MakeMockObjects() const96 void AaCommandStartTest::MakeMockObjects() const
97 {
98     // mock a stub
99     auto managerStubPtr = sptr<IAbilityManager>(new MockAbilityManagerStub());
100 
101     // set the mock stub
102     auto managerClientPtr = AbilityManagerClient::GetInstance();
103     managerClientPtr->proxy_ = managerStubPtr;
104 }
105 
106 /**
107  * @tc.number: Aa_Command_Start_0100
108  * @tc.name: ExecCommand
109  * @tc.desc: Verify the "aa start" command.
110  */
111 HWTEST_F(AaCommandStartTest, Aa_Command_Start_0100, Function | MediumTest | Level1)
112 {
113     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_0100");
114 
115     char* argv[] = {
116         (char*)TOOL_NAME.c_str(),
117         (char*)cmd_.c_str(),
118         (char*)"",
119     };
120     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
121 
122     AbilityManagerShellCommand cmd(argc, argv);
123     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_START);
124 }
125 
126 /**
127  * @tc.number: Aa_Command_Start_0200
128  * @tc.name: ExecCommand
129  * @tc.desc: Verify the "aa start xxx" command.
130  */
131 HWTEST_F(AaCommandStartTest, Aa_Command_Start_0200, Function | MediumTest | Level1)
132 {
133     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_0200");
134 
135     char* argv[] = {
136         (char*)TOOL_NAME.c_str(),
137         (char*)cmd_.c_str(),
138         (char*)"xxx",
139         (char*)"",
140     };
141     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
142 
143     AbilityManagerShellCommand cmd(argc, argv);
144     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_START);
145 }
146 
147 /**
148  * @tc.number: Aa_Command_Start_0300
149  * @tc.name: ExecCommand
150  * @tc.desc: Verify the "aa start -x" command.
151  */
152 HWTEST_F(AaCommandStartTest, Aa_Command_Start_0300, Function | MediumTest | Level1)
153 {
154     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_0300");
155 
156     char* argv[] = {
157         (char*)TOOL_NAME.c_str(),
158         (char*)cmd_.c_str(),
159         (char*)"-x",
160         (char*)"",
161     };
162     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
163 
164     AbilityManagerShellCommand cmd(argc, argv);
165     EXPECT_EQ(cmd.ExecCommand(), "fail: unknown option.\n" + HELP_MSG_START);
166 }
167 
168 /**
169  * @tc.number: Aa_Command_Start_0400
170  * @tc.name: ExecCommand
171  * @tc.desc: Verify the "aa start -xxx" command.
172  */
173 HWTEST_F(AaCommandStartTest, Aa_Command_Start_0400, Function | MediumTest | Level1)
174 {
175     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_0400");
176 
177     char* argv[] = {
178         (char*)TOOL_NAME.c_str(),
179         (char*)cmd_.c_str(),
180         (char*)"-xxx",
181         (char*)"",
182     };
183     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
184 
185     AbilityManagerShellCommand cmd(argc, argv);
186     EXPECT_EQ(cmd.ExecCommand(), "fail: unknown option.\n" + HELP_MSG_START);
187 }
188 
189 /**
190  * @tc.number: Aa_Command_Start_0500
191  * @tc.name: ExecCommand
192  * @tc.desc: Verify the "aa start --x" command.
193  */
194 HWTEST_F(AaCommandStartTest, Aa_Command_Start_0500, Function | MediumTest | Level1)
195 {
196     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_0500");
197 
198     char* argv[] = {
199         (char*)TOOL_NAME.c_str(),
200         (char*)cmd_.c_str(),
201         (char*)"--x",
202         (char*)"",
203     };
204     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
205 
206     AbilityManagerShellCommand cmd(argc, argv);
207     EXPECT_EQ(cmd.ExecCommand(), "fail: unknown option.\n" + HELP_MSG_START);
208 }
209 
210 /**
211  * @tc.number: Aa_Command_Start_0600
212  * @tc.name: ExecCommand
213  * @tc.desc: Verify the "aa start --xxx" command.
214  */
215 HWTEST_F(AaCommandStartTest, Aa_Command_Start_0600, Function | MediumTest | Level1)
216 {
217     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_0600");
218 
219     char* argv[] = {
220         (char*)TOOL_NAME.c_str(),
221         (char*)cmd_.c_str(),
222         (char*)"--xxx",
223         (char*)"",
224     };
225     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
226 
227     AbilityManagerShellCommand cmd(argc, argv);
228     EXPECT_EQ(cmd.ExecCommand(), "fail: unknown option.\n" + HELP_MSG_START);
229 }
230 
231 /**
232  * @tc.number: Aa_Command_Start_0700
233  * @tc.name: ExecCommand
234  * @tc.desc: Verify the "aa start -h" command.
235  */
236 HWTEST_F(AaCommandStartTest, Aa_Command_Start_0700, Function | MediumTest | Level1)
237 {
238     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_0700");
239 
240     char* argv[] = {
241         (char*)TOOL_NAME.c_str(),
242         (char*)cmd_.c_str(),
243         (char*)"-h",
244         (char*)"",
245     };
246     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
247 
248     AbilityManagerShellCommand cmd(argc, argv);
249     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_START);
250 }
251 
252 /**
253  * @tc.number: Aa_Command_Start_0800
254  * @tc.name: ExecCommand
255  * @tc.desc: Verify the "aa start --help" command.
256  */
257 HWTEST_F(AaCommandStartTest, Aa_Command_Start_0800, Function | MediumTest | Level1)
258 {
259     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_0800");
260 
261     char* argv[] = {
262         (char*)TOOL_NAME.c_str(),
263         (char*)cmd_.c_str(),
264         (char*)"--help",
265         (char*)"",
266     };
267     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
268 
269     AbilityManagerShellCommand cmd(argc, argv);
270     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_START);
271 }
272 
273 /**
274  * @tc.number: Aa_Command_Start_0900
275  * @tc.name: ExecCommand
276  * @tc.desc: Verify the "aa start -d" command.
277  */
278 HWTEST_F(AaCommandStartTest, Aa_Command_Start_0900, Function | MediumTest | Level1)
279 {
280     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_0900");
281 
282     char* argv[] = {
283         (char*)TOOL_NAME.c_str(),
284         (char*)cmd_.c_str(),
285         (char*)"-d",
286         (char*)"",
287     };
288     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
289 
290     AbilityManagerShellCommand cmd(argc, argv);
291     EXPECT_EQ(cmd.ExecCommand(), "error: option requires a value.\n" + HELP_MSG_START);
292 }
293 
294 /**
295  * @tc.number: Aa_Command_Start_1000
296  * @tc.name: ExecCommand
297  * @tc.desc: Verify the "aa start -d <device-id>" command.
298  */
299 HWTEST_F(AaCommandStartTest, Aa_Command_Start_1000, Function | MediumTest | Level1)
300 {
301     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_1000");
302 
303     char* argv[] = {
304         (char*)TOOL_NAME.c_str(),
305         (char*)cmd_.c_str(),
306         (char*)"-d",
307         (char*)STRING_DEVICE.c_str(),
308         (char*)"",
309     };
310     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
311 
312     AbilityManagerShellCommand cmd(argc, argv);
313     EXPECT_EQ(cmd.ExecCommand(), STRING_START_ABILITY_OK + "\n");
314 }
315 
316 /**
317  * @tc.number: Aa_Command_Start_1100
318  * @tc.name: ExecCommand
319  * @tc.desc: Verify the "aa start -d <device-id> -a" command.
320  */
321 HWTEST_F(AaCommandStartTest, Aa_Command_Start_1100, Function | MediumTest | Level1)
322 {
323     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_1100");
324 
325     char* argv[] = {
326         (char*)TOOL_NAME.c_str(),
327         (char*)cmd_.c_str(),
328         (char*)"-d",
329         (char*)STRING_DEVICE.c_str(),
330         (char*)"-a",
331         (char*)"",
332     };
333     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
334 
335     AbilityManagerShellCommand cmd(argc, argv);
336     EXPECT_EQ(cmd.ExecCommand(), "error: option requires a value.\n" + HELP_MSG_START);
337 }
338 
339 /**
340  * @tc.number: Aa_Command_Start_1200
341  * @tc.name: ExecCommand
342  * @tc.desc: Verify the "aa start -d <device-id> -a <ability-name>" command.
343  */
344 HWTEST_F(AaCommandStartTest, Aa_Command_Start_1200, Function | MediumTest | Level1)
345 {
346     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_1200");
347 
348     char* argv[] = {
349         (char*)TOOL_NAME.c_str(),
350         (char*)cmd_.c_str(),
351         (char*)"-d",
352         (char*)STRING_DEVICE.c_str(),
353         (char*)"-a",
354         (char*)STRING_ABILITY_NAME.c_str(),
355         (char*)"",
356     };
357     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
358 
359     AbilityManagerShellCommand cmd(argc, argv);
360     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_BUNDLE_NAME_OPTION + "\n" + HELP_MSG_START);
361 }
362 
363 /**
364  * @tc.number: Aa_Command_Start_1300
365  * @tc.name: ExecCommand
366  * @tc.desc: Verify the "aa start -d <device-id> -b" command.
367  */
368 HWTEST_F(AaCommandStartTest, Aa_Command_Start_1300, Function | MediumTest | Level1)
369 {
370     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_1300");
371 
372     char* argv[] = {
373         (char*)TOOL_NAME.c_str(),
374         (char*)cmd_.c_str(),
375         (char*)"-d",
376         (char*)STRING_DEVICE.c_str(),
377         (char*)"-b",
378         (char*)"",
379     };
380     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
381 
382     AbilityManagerShellCommand cmd(argc, argv);
383     EXPECT_EQ(cmd.ExecCommand(), "error: option requires a value.\n" + HELP_MSG_START);
384 }
385 
386 /**
387  * @tc.number: Aa_Command_Start_1400
388  * @tc.name: ExecCommand
389  * @tc.desc: Verify the "aa start -d <device-id> -b <bundle-name>" command.
390  */
391 HWTEST_F(AaCommandStartTest, Aa_Command_Start_1400, Function | MediumTest | Level1)
392 {
393     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_1400");
394 
395     char* argv[] = {
396         (char*)TOOL_NAME.c_str(),
397         (char*)cmd_.c_str(),
398         (char*)"-d",
399         (char*)STRING_DEVICE.c_str(),
400         (char*)"-b",
401         (char*)STRING_BUNDLE_NAME.c_str(),
402         (char*)"",
403     };
404     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
405 
406     AbilityManagerShellCommand cmd(argc, argv);
407     EXPECT_EQ(cmd.ExecCommand(), STRING_START_ABILITY_OK + "\n");
408 }
409 
410 /**
411  * @tc.number: Aa_Command_Start_1500
412  * @tc.name: ExecCommand
413  * @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b" command.
414  */
415 HWTEST_F(AaCommandStartTest, Aa_Command_Start_1500, Function | MediumTest | Level1)
416 {
417     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_1500");
418 
419     char* argv[] = {
420         (char*)TOOL_NAME.c_str(),
421         (char*)cmd_.c_str(),
422         (char*)"-d",
423         (char*)STRING_DEVICE.c_str(),
424         (char*)"-a",
425         (char*)STRING_ABILITY_NAME.c_str(),
426         (char*)"-b",
427         (char*)"",
428     };
429     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
430 
431     AbilityManagerShellCommand cmd(argc, argv);
432     EXPECT_EQ(cmd.ExecCommand(), "error: option requires a value.\n" + HELP_MSG_START);
433 }
434 
435 /**
436  * @tc.number: Aa_Command_Start_1600
437  * @tc.name: ExecCommand
438  * @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b <bundle-name>" command.
439  */
440 HWTEST_F(AaCommandStartTest, Aa_Command_Start_1600, Function | MediumTest | Level1)
441 {
442     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_1600");
443 
444     char* argv[] = {
445         (char*)TOOL_NAME.c_str(),
446         (char*)cmd_.c_str(),
447         (char*)"-d",
448         (char*)STRING_DEVICE.c_str(),
449         (char*)"-a",
450         (char*)STRING_ABILITY_NAME.c_str(),
451         (char*)"-b",
452         (char*)STRING_BUNDLE_NAME.c_str(),
453         (char*)"",
454     };
455     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
456 
457     AbilityManagerShellCommand cmd(argc, argv);
458     EXPECT_EQ(cmd.ExecCommand(), STRING_START_ABILITY_OK + "\n");
459 }
460 
461 /**
462  * @tc.number: Aa_Command_Start_1700
463  * @tc.name: ExecCommand
464  * @tc.desc: Verify the "aa start -a" command.
465  */
466 HWTEST_F(AaCommandStartTest, Aa_Command_Start_1700, Function | MediumTest | Level1)
467 {
468     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_1700");
469 
470     char* argv[] = {
471         (char*)TOOL_NAME.c_str(),
472         (char*)cmd_.c_str(),
473         (char*)"-a",
474         (char*)"",
475     };
476     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
477 
478     AbilityManagerShellCommand cmd(argc, argv);
479     EXPECT_EQ(cmd.ExecCommand(), "error: option requires a value.\n" + HELP_MSG_START);
480 }
481 
482 /**
483  * @tc.number: Aa_Command_Start_1800
484  * @tc.name: ExecCommand
485  * @tc.desc: Verify the "aa start -a <ability-name> -b" command.
486  */
487 HWTEST_F(AaCommandStartTest, Aa_Command_Start_1800, Function | MediumTest | Level1)
488 {
489     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_1800");
490 
491     char* argv[] = {
492         (char*)TOOL_NAME.c_str(),
493         (char*)cmd_.c_str(),
494         (char*)"-a",
495         (char*)STRING_ABILITY_NAME.c_str(),
496         (char*)"-b",
497         (char*)"",
498     };
499     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
500 
501     AbilityManagerShellCommand cmd(argc, argv);
502     EXPECT_EQ(cmd.ExecCommand(), "error: option requires a value.\n" + HELP_MSG_START);
503 }
504 
505 /**
506  * @tc.number: Aa_Command_Start_1900
507  * @tc.name: ExecCommand
508  * @tc.desc: Verify the "aa start -a <ability-name> -b <bundle-name>" command.
509  */
510 HWTEST_F(AaCommandStartTest, Aa_Command_Start_1900, Function | MediumTest | Level1)
511 {
512     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_1900");
513 
514     char* argv[] = {
515         (char*)TOOL_NAME.c_str(),
516         (char*)cmd_.c_str(),
517         (char*)"-a",
518         (char*)STRING_ABILITY_NAME.c_str(),
519         (char*)"-b",
520         (char*)STRING_BUNDLE_NAME.c_str(),
521         (char*)"",
522     };
523     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
524 
525     AbilityManagerShellCommand cmd(argc, argv);
526     EXPECT_EQ(cmd.ExecCommand(), STRING_START_ABILITY_OK + "\n");
527 }
528 
529 /**
530  * @tc.number: Aa_Command_Start_2000
531  * @tc.name: ExecCommand
532  * @tc.desc: Verify the "aa start -a <ability-name> -b <bundle-name> -D" command.
533  */
534 HWTEST_F(AaCommandStartTest, Aa_Command_Start_2000, Function | MediumTest | Level1)
535 {
536     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_2000");
537 
538     char* argv[] = {
539         (char*)TOOL_NAME.c_str(),
540         (char*)cmd_.c_str(),
541         (char*)"-a",
542         (char*)STRING_ABILITY_NAME.c_str(),
543         (char*)"-b",
544         (char*)STRING_BUNDLE_NAME.c_str(),
545         (char*)"-D",
546         (char*)"",
547     };
548     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
549 
550     AbilityManagerShellCommand cmd(argc, argv);
551     EXPECT_EQ(cmd.ExecCommand(), STRING_START_ABILITY_OK + "\n");
552 }
553 
554 /**
555  * @tc.number: Aa_Command_Start_2100
556  * @tc.name: ExecCommand
557  * @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b <bundle-name>" command.
558  */
559 HWTEST_F(AaCommandStartTest, Aa_Command_Start_2100, Function | MediumTest | Level1)
560 {
561     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_2100");
562 
563     char* argv[] = {
564         (char*)TOOL_NAME.c_str(),
565         (char*)cmd_.c_str(),
566         (char*)"-d",
567         (char*)STRING_DEVICE.c_str(),
568         (char*)"-a",
569         (char*)STRING_ABILITY_NAME_INVALID.c_str(),
570         (char*)"-b",
571         (char*)STRING_BUNDLE_NAME.c_str(),
572         (char*)"",
573     };
574     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
575 
576     AbilityManagerShellCommand cmd(argc, argv);
577     EXPECT_EQ(cmd.ExecCommand(), STRING_START_ABILITY_NG + "\n" + cmd.messageMap_.at(RESOLVE_ABILITY_ERR) + "\n");
578 }
579 
580 /**
581  * @tc.number: Aa_Command_Start_2200
582  * @tc.name: ExecCommand
583  * @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b <bundle-name>" command.
584  */
585 HWTEST_F(AaCommandStartTest, Aa_Command_Start_2200, Function | MediumTest | Level1)
586 {
587     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_2200");
588 
589     char* argv[] = {
590         (char*)TOOL_NAME.c_str(),
591         (char*)cmd_.c_str(),
592         (char*)"-d",
593         (char*)STRING_DEVICE.c_str(),
594         (char*)"-a",
595         (char*)STRING_ABILITY_NAME.c_str(),
596         (char*)"-b",
597         (char*)STRING_BUNDLE_NAME_INVALID.c_str(),
598         (char*)"",
599     };
600     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
601 
602     AbilityManagerShellCommand cmd(argc, argv);
603     EXPECT_EQ(cmd.ExecCommand(), STRING_START_ABILITY_NG + "\n" + cmd.messageMap_.at(RESOLVE_APP_ERR) + "\n");
604 }
605 
606 /**
607  * @tc.number: Aa_Command_Start_2300
608  * @tc.name: ExecCommand
609  * @tc.desc: Verify the "aa start -D" command.
610  * @tc.type: FUNC
611  */
612 HWTEST_F(AaCommandStartTest, Aa_Command_Start_2300, Function | MediumTest | Level1)
613 {
614     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_2300");
615 
616     char* argv[] = {
617         (char*)TOOL_NAME.c_str(),
618         (char*)cmd_.c_str(),
619         (char*)"-D",
620         (char*)"",
621     };
622     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
623 
624     AbilityManagerShellCommand cmd(argc, argv);
625     EXPECT_EQ(cmd.ExecCommand(), STRING_START_ABILITY_OK + "\n");
626 }
627 
628 /**
629  * @tc.number: Aa_Command_Start_2400
630  * @tc.name: ExecCommand
631  * @tc.desc: Verify the "aa start -d <device-id> -D" command.
632  * @tc.type: FUNC
633  */
634 HWTEST_F(AaCommandStartTest, Aa_Command_Start_2400, Function | MediumTest | Level1)
635 {
636     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_2400");
637 
638     char* argv[] = {
639         (char*)TOOL_NAME.c_str(),
640         (char*)cmd_.c_str(),
641         (char*)"-d",
642         (char*)STRING_DEVICE.c_str(),
643         (char*)"-D",
644         (char*)"",
645     };
646     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
647 
648     AbilityManagerShellCommand cmd(argc, argv);
649     EXPECT_EQ(cmd.ExecCommand(), STRING_START_ABILITY_OK + "\n");
650 }
651 
652 /**
653  * @tc.number: Aa_Command_Start_2500
654  * @tc.name: ExecCommand
655  * @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -D" command.
656  * @tc.type: FUNC
657  */
658 HWTEST_F(AaCommandStartTest, Aa_Command_Start_2500, Function | MediumTest | Level1)
659 {
660     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_2500");
661 
662     char* argv[] = {
663         (char*)TOOL_NAME.c_str(),
664         (char*)cmd_.c_str(),
665         (char*)"-d",
666         (char*)STRING_DEVICE.c_str(),
667         (char*)"-a",
668         (char*)STRING_ABILITY_NAME.c_str(),
669         (char*)"-D",
670         (char*)"",
671     };
672     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
673 
674     AbilityManagerShellCommand cmd(argc, argv);
675     EXPECT_EQ(cmd.ExecCommand(), "error: -b <bundle-name> is expected\n" + HELP_MSG_START);
676 }
677 
678 /**
679  * @tc.number: Aa_Command_Start_2600
680  * @tc.name: ExecCommand
681  * @tc.desc: Verify the "aa start -d <device-id> -b <bundle-name> -D" command.
682  * @tc.type: FUNC
683  */
684 HWTEST_F(AaCommandStartTest, Aa_Command_Start_2600, Function | MediumTest | Level1)
685 {
686     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_2600");
687 
688     char* argv[] = {
689         (char*)TOOL_NAME.c_str(),
690         (char*)cmd_.c_str(),
691         (char*)"-d",
692         (char*)STRING_DEVICE.c_str(),
693         (char*)"-b",
694         (char*)STRING_BUNDLE_NAME.c_str(),
695         (char*)"-D",
696         (char*)"",
697     };
698     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
699 
700     AbilityManagerShellCommand cmd(argc, argv);
701     EXPECT_EQ(cmd.ExecCommand(), STRING_START_ABILITY_OK + "\n");
702 }
703 
704 /**
705  * @tc.number: Aa_Command_Start_2700
706  * @tc.name: ExecCommand
707  * @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b <bundle-name> -D" command.
708  * @tc.type: FUNC
709  */
710 HWTEST_F(AaCommandStartTest, Aa_Command_Start_2700, Function | MediumTest | Level1)
711 {
712     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_2700");
713 
714     char* argv[] = {
715         (char*)TOOL_NAME.c_str(),
716         (char*)cmd_.c_str(),
717         (char*)"-d",
718         (char*)STRING_DEVICE.c_str(),
719         (char*)"-a",
720         (char*)STRING_ABILITY_NAME.c_str(),
721         (char*)"-b",
722         (char*)STRING_BUNDLE_NAME.c_str(),
723         (char*)"-D",
724         (char*)"",
725     };
726     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
727 
728     AbilityManagerShellCommand cmd(argc, argv);
729     EXPECT_EQ(cmd.ExecCommand(), STRING_START_ABILITY_OK + "\n");
730 }
731 
732 /**
733  * @tc.number: Aa_Command_Start_2800
734  * @tc.name: ExecCommand
735  * @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b <bundle-name> --pi <key> <integer-value>" command.
736  * @tc.type: FUNC
737  */
738 HWTEST_F(AaCommandStartTest, Aa_Command_Start_2800, Function | MediumTest | Level1)
739 {
740     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_2800");
741 
742     char* argv[] = {
743         (char*)TOOL_NAME.c_str(),
744         (char*)cmd_.c_str(),
745         (char*)"-d",
746         (char*)STRING_DEVICE.c_str(),
747         (char*)"-a",
748         (char*)STRING_ABILITY_NAME.c_str(),
749         (char*)"-b",
750         (char*)STRING_BUNDLE_NAME.c_str(),
751         (char*)"--pi",
752         (char*)STRING_PARAMETER_KEY_INTEGER.c_str(),
753         (char*)STRING_PARAMETER_VALUE_INTEGER.c_str(),
754         (char*)"",
755     };
756     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
757 
758     AbilityManagerShellCommand cmd(argc, argv);
759     EXPECT_EQ(cmd.ExecCommand(), STRING_START_ABILITY_OK + "\n");
760 }
761 
762 /**
763  * @tc.number: Aa_Command_Start_2900
764  * @tc.name: ExecCommand
765  * @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b <bundle-name> --pb <key> <bool-value>" command.
766  * @tc.type: FUNC
767  */
768 HWTEST_F(AaCommandStartTest, Aa_Command_Start_2900, Function | MediumTest | Level1)
769 {
770     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_2900");
771 
772     char* argv[] = {
773         (char*)TOOL_NAME.c_str(),
774         (char*)cmd_.c_str(),
775         (char*)"-d",
776         (char*)STRING_DEVICE.c_str(),
777         (char*)"-a",
778         (char*)STRING_ABILITY_NAME.c_str(),
779         (char*)"-b",
780         (char*)STRING_BUNDLE_NAME.c_str(),
781         (char*)"--pb",
782         (char*)STRING_PARAMETER_KEY_BOOL.c_str(),
783         (char*)STRING_PARAMETER_VALUE_BOOL.c_str(),
784         (char*)"",
785     };
786     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
787 
788     AbilityManagerShellCommand cmd(argc, argv);
789     EXPECT_EQ(cmd.ExecCommand(), STRING_START_ABILITY_OK + "\n");
790 }
791 
792 /**
793  * @tc.number: Aa_Command_Start_3000
794  * @tc.name: ExecCommand
795  * @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b <bundle-name> --ps <key> <value>" command.
796  * @tc.type: FUNC
797  */
798 HWTEST_F(AaCommandStartTest, Aa_Command_Start_3000, Function | MediumTest | Level1)
799 {
800     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_3000");
801 
802     char* argv[] = {
803         (char*)TOOL_NAME.c_str(),
804         (char*)cmd_.c_str(),
805         (char*)"-d",
806         (char*)STRING_DEVICE.c_str(),
807         (char*)"-a",
808         (char*)STRING_ABILITY_NAME.c_str(),
809         (char*)"-b",
810         (char*)STRING_BUNDLE_NAME.c_str(),
811         (char*)"--ps",
812         (char*)STRING_PARAMETER_KEY_STRING.c_str(),
813         (char*)STRING_PARAMETER_VALUE_STRING.c_str(),
814         (char*)"",
815     };
816     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
817 
818     AbilityManagerShellCommand cmd(argc, argv);
819     EXPECT_EQ(cmd.ExecCommand(), STRING_START_ABILITY_OK + "\n");
820 }
821 
822 /**
823  * @tc.number: Aa_Command_Start_3100
824  * @tc.name: ExecCommand
825  * @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b <bundle-name> --psn <key>" command.
826  * @tc.type: FUNC
827  */
828 HWTEST_F(AaCommandStartTest, Aa_Command_Start_3100, Function | MediumTest | Level1)
829 {
830     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_3100");
831 
832     char* argv[] = {
833         (char*)TOOL_NAME.c_str(),
834         (char*)cmd_.c_str(),
835         (char*)"-d",
836         (char*)STRING_DEVICE.c_str(),
837         (char*)"-a",
838         (char*)STRING_ABILITY_NAME.c_str(),
839         (char*)"-b",
840         (char*)STRING_BUNDLE_NAME.c_str(),
841         (char*)"--psn",
842         (char*)STRING_PARAMETER_KEY_NULL_STRING.c_str(),
843         (char*)"",
844     };
845     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
846 
847     AbilityManagerShellCommand cmd(argc, argv);
848     EXPECT_EQ(cmd.ExecCommand(), STRING_START_ABILITY_OK + "\n");
849 }
850 
851 /**
852  * @tc.number: Aa_Command_Start_3200
853  * @tc.name: ExecCommand
854  * @tc.desc: Verify the "aa start -A <action>" command.
855  * @tc.type: FUNC
856  */
857 HWTEST_F(AaCommandStartTest, Aa_Command_Start_3200, Function | MediumTest | Level1)
858 {
859     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_3200");
860 
861     char* argv[] = {
862         (char*)TOOL_NAME.c_str(),
863         (char*)cmd_.c_str(),
864         (char*)"-A",
865         (char*)STRING_ACTION.c_str(),
866         (char*)"",
867     };
868     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
869 
870     AbilityManagerShellCommand cmd(argc, argv);
871     EXPECT_EQ(cmd.ExecCommand(), STRING_START_ABILITY_OK + "\n");
872 }
873 
874 /**
875  * @tc.number: Aa_Command_Start_3300
876  * @tc.name: ExecCommand
877  * @tc.desc: Verify the "aa start -U <URI> -t <type>" command.
878  * @tc.type: FUNC
879  */
880 HWTEST_F(AaCommandStartTest, Aa_Command_Start_3300, Function | MediumTest | Level1)
881 {
882     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_3300");
883 
884     char* argv[] = {
885         (char*)TOOL_NAME.c_str(),
886         (char*)cmd_.c_str(),
887         (char*)"-U",
888         (char*)STRING_URI.c_str(),
889         (char*)"-t",
890         (char*)STRING_TYPE.c_str(),
891         (char*)"",
892     };
893     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
894 
895     AbilityManagerShellCommand cmd(argc, argv);
896     EXPECT_EQ(cmd.ExecCommand(), STRING_START_ABILITY_OK + "\n");
897 }
898 
899 /**
900  * @tc.number: Aa_Command_Start_3500
901  * @tc.name: ExecCommand
902  * @tc.desc: Verify the "aa start -e <entity>" command.
903  * @tc.type: FUNC
904  */
905 HWTEST_F(AaCommandStartTest, Aa_Command_Start_3500, Function | MediumTest | Level1)
906 {
907     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_3500");
908 
909     char* argv[] = {
910         (char*)TOOL_NAME.c_str(),
911         (char*)cmd_.c_str(),
912         (char*)"-e",
913         (char*)STRING_ENTITY.c_str(),
914         (char*)"",
915     };
916     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
917 
918     AbilityManagerShellCommand cmd(argc, argv);
919     EXPECT_EQ(cmd.ExecCommand(), STRING_START_ABILITY_OK + "\n");
920 }
921 
922 /**
923  * @tc.number: Aa_Command_Start_3600
924  * @tc.name: ExecCommand
925  * @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b <bundle-name> --pi <key> <integer-value>" command.
926  * @tc.type: FUNC
927  */
928 HWTEST_F(AaCommandStartTest, Aa_Command_Start_3600, Function | MediumTest | Level1)
929 {
930     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_3600");
931 
932     char* argv[] = {
933         (char*)TOOL_NAME.c_str(),
934         (char*)cmd_.c_str(),
935         (char*)"-d",
936         (char*)STRING_DEVICE.c_str(),
937         (char*)"-a",
938         (char*)STRING_ABILITY_NAME.c_str(),
939         (char*)"-b",
940         (char*)STRING_BUNDLE_NAME.c_str(),
941         (char*)"--pi",
942         (char*)STRING_PARAMETER_KEY_INTEGER.c_str(),
943         (char*)STRING_PARAMETER_VALUE_INTEGER_INVALID.c_str(),
944         (char*)"",
945     };
946     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
947 
948     AbilityManagerShellCommand cmd(argc, argv);
949     EXPECT_EQ(cmd.ExecCommand(), STRING_INVALID_PARAMETER_INTEGER_OPTION + "\n" + HELP_MSG_START);
950 }
951 
952 /**
953  * @tc.number: Aa_Command_Start_3700
954  * @tc.name: ExecCommand
955  * @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b <bundle-name> --pb <key> <bool-value>" command.
956  * @tc.type: FUNC
957  */
958 HWTEST_F(AaCommandStartTest, Aa_Command_Start_3700, Function | MediumTest | Level1)
959 {
960     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_3700");
961 
962     char* argv[] = {
963         (char*)TOOL_NAME.c_str(),
964         (char*)cmd_.c_str(),
965         (char*)"-d",
966         (char*)STRING_DEVICE.c_str(),
967         (char*)"-a",
968         (char*)STRING_ABILITY_NAME.c_str(),
969         (char*)"-b",
970         (char*)STRING_BUNDLE_NAME.c_str(),
971         (char*)"--pb",
972         (char*)STRING_PARAMETER_KEY_BOOL.c_str(),
973         (char*)STRING_PARAMETER_VALUE_BOOL_INVALID.c_str(),
974         (char*)"",
975     };
976     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
977 
978     AbilityManagerShellCommand cmd(argc, argv);
979     EXPECT_EQ(cmd.ExecCommand(), STRING_INVALID_PARAMETER_BOOL_OPTION + "\n" + HELP_MSG_START);
980 }
981 
982 /**
983  * @tc.number: Aa_Command_Start_3800
984  * @tc.name: ExecCommand
985  * @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b <bundle-name> --ps <key> <value>" command.
986  * @tc.type: FUNC
987  */
988 HWTEST_F(AaCommandStartTest, Aa_Command_Start_3800, Function | MediumTest | Level1)
989 {
990     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_3800");
991 
992     char* argv[] = {
993         (char*)TOOL_NAME.c_str(),
994         (char*)cmd_.c_str(),
995         (char*)"-d",
996         (char*)STRING_DEVICE.c_str(),
997         (char*)"-a",
998         (char*)STRING_ABILITY_NAME.c_str(),
999         (char*)"-b",
1000         (char*)STRING_BUNDLE_NAME.c_str(),
1001         (char*)"--ps",
1002         (char*)STRING_PARAMETER_KEY_STRING.c_str(),
1003         (char*)STRING_PARAMETER_VALUE_STRING.c_str(),
1004         (char*)STRING_PARAMETER_VALUE_STRING_INVALID.c_str(),
1005         (char*)"",
1006     };
1007     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1008 
1009     AbilityManagerShellCommand cmd(argc, argv);
1010     EXPECT_EQ(cmd.ExecCommand(), STRING_INVALID_NUMBER_STRING_OPTION + "\n" + HELP_MSG_START);
1011 }
1012 
1013 /**
1014  * @tc.number: Aa_Command_Start_3900
1015  * @tc.name: ExecCommand
1016  * @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b <bundle-name> --pi <key> <integer-value>" command.
1017  * @tc.type: FUNC
1018  */
1019 HWTEST_F(AaCommandStartTest, Aa_Command_Start_3900, Function | MediumTest | Level1)
1020 {
1021     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_3900");
1022 
1023     char* argv[] = {
1024         (char*)TOOL_NAME.c_str(),
1025         (char*)cmd_.c_str(),
1026         (char*)"-d",
1027         (char*)STRING_DEVICE.c_str(),
1028         (char*)"-a",
1029         (char*)STRING_ABILITY_NAME.c_str(),
1030         (char*)"-b",
1031         (char*)STRING_BUNDLE_NAME.c_str(),
1032         (char*)"--pi",
1033         (char*)STRING_PARAMETER_KEY_INTEGER.c_str(),
1034         (char*)STRING_PARAMETER_VALUE_INTEGER.c_str(),
1035         (char*)STRING_PARAMETER_VALUE_INTEGER_INVALID.c_str(),
1036         (char*)"",
1037     };
1038     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1039 
1040     AbilityManagerShellCommand cmd(argc, argv);
1041     EXPECT_EQ(cmd.ExecCommand(), STRING_INVALID_NUMBER_INTEGER_OPTION + "\n" + HELP_MSG_START);
1042 }
1043 
1044 /**
1045  * @tc.number: Aa_Command_Start_4000
1046  * @tc.name: ExecCommand
1047  * @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b <bundle-name> --pb <key> <bool-value>" command.
1048  * @tc.type: FUNC
1049  */
1050 HWTEST_F(AaCommandStartTest, Aa_Command_Start_4000, Function | MediumTest | Level1)
1051 {
1052     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_4000");
1053 
1054     char* argv[] = {
1055         (char*)TOOL_NAME.c_str(),
1056         (char*)cmd_.c_str(),
1057         (char*)"-d",
1058         (char*)STRING_DEVICE.c_str(),
1059         (char*)"-a",
1060         (char*)STRING_ABILITY_NAME.c_str(),
1061         (char*)"-b",
1062         (char*)STRING_BUNDLE_NAME.c_str(),
1063         (char*)"--pb",
1064         (char*)STRING_PARAMETER_KEY_BOOL.c_str(),
1065         (char*)STRING_PARAMETER_VALUE_BOOL.c_str(),
1066         (char*)STRING_PARAMETER_VALUE_BOOL_INVALID.c_str(),
1067         (char*)"",
1068     };
1069     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1070 
1071     AbilityManagerShellCommand cmd(argc, argv);
1072     EXPECT_EQ(cmd.ExecCommand(), STRING_INVALID_NUMBER_BOOL_OPTION + "\n" + HELP_MSG_START);
1073 }
1074 /**
1075  * @tc.number: Aa_Command_Start_4100
1076  * @tc.name: ExecCommand
1077  * @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b <bundle-name> --psn <key>" command.
1078  * @tc.type: FUNC
1079  */
1080 HWTEST_F(AaCommandStartTest, Aa_Command_Start_4100, Function | MediumTest | Level1)
1081 {
1082     TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_4100");
1083 
1084     char* argv[] = {
1085         (char*)TOOL_NAME.c_str(),
1086         (char*)cmd_.c_str(),
1087         (char*)"-d",
1088         (char*)STRING_DEVICE.c_str(),
1089         (char*)"-a",
1090         (char*)STRING_ABILITY_NAME.c_str(),
1091         (char*)"-b",
1092         (char*)STRING_BUNDLE_NAME.c_str(),
1093         (char*)"--psn",
1094         (char*)STRING_PARAMETER_KEY_NULL_STRING.c_str(),
1095         (char*)STRING_PARAMETER_VALUE_STRING_INVALID.c_str(),
1096         (char*)"",
1097     };
1098     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1099 
1100     AbilityManagerShellCommand cmd(argc, argv);
1101     EXPECT_EQ(cmd.ExecCommand(), STRING_INVALID_NUMBER_NULL_STRING_OPTION + "\n" + HELP_MSG_START);
1102 }
1103