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 #define private public
19 #define protected public
20
21 #include "bundle_command.h"
22 #undef private
23 #include "bundle_installer_interface.h"
24 #include "iremote_broker.h"
25 #include "iremote_object.h"
26 #include "mock_bundle_installer_host.h"
27 #include "mock_bundle_mgr_host.h"
28 #include "parameter.h"
29 #include "parameters.h"
30
31 using namespace testing::ext;
32 using namespace OHOS::AAFwk;
33 using namespace OHOS::AppExecFwk;
34
35 namespace OHOS {
36 namespace {
37 const char* IS_ROOT_MODE_PARAM = "const.debuggable";
38 const std::string IS_DEVELOPER_MODE_PARAM = "const.security.developermode.state";
39 const int32_t ROOT_MODE = 1;
40 }
41
42 class MockCreateCommandMap : public ShellCommand {
43 public:
MockCreateCommandMap(int argc,char * argv[])44 MockCreateCommandMap(int argc, char *argv[]) : ShellCommand(argc, argv, TOOL_NAME)
45 {
46 };
47
CreateCommandMap()48 ErrCode CreateCommandMap() override
49 {
50 return -1;
51 };
CreateMessageMap()52 ErrCode CreateMessageMap() override
53 {
54 return ERR_OK;
55 };
Init()56 ErrCode Init() override
57 {
58 return ERR_OK;
59 };
60
RunAsHelpCommand() const61 ErrCode RunAsHelpCommand() const
62 {
63 return OHOS::ERR_OK;
64 }
65 };
66
67 class MockCreateMessageMap : public ShellCommand {
68 public:
MockCreateMessageMap(int argc,char * argv[])69 MockCreateMessageMap(int argc, char *argv[]) : ShellCommand(argc, argv, TOOL_NAME)
70 {
71 };
72
CreateCommandMap()73 ErrCode CreateCommandMap() override
74 {
75 return ERR_OK;
76 };
CreateMessageMap()77 ErrCode CreateMessageMap() override
78 {
79 return -1;
80 };
Init()81 ErrCode Init() override
82 {
83 return ERR_OK;
84 };
85
RunAsHelpCommand() const86 ErrCode RunAsHelpCommand() const
87 {
88 return OHOS::ERR_OK;
89 }
90 };
91
92 class MockInit : public ShellCommand {
93 public:
MockInit(int argc,char * argv[])94 MockInit(int argc, char *argv[]) : ShellCommand(argc, argv, TOOL_NAME)
95 {
96 };
97
CreateCommandMap()98 ErrCode CreateCommandMap() override
99 {
100 return ERR_OK;
101 };
CreateMessageMap()102 ErrCode CreateMessageMap() override
103 {
104 return ERR_OK;
105 };
Init()106 ErrCode Init() override
107 {
108 return -1;
109 };
110
RunAsHelpCommand() const111 ErrCode RunAsHelpCommand() const
112 {
113 return OHOS::ERR_OK;
114 }
115 };
116
117 class BmCommandTest : public ::testing::Test {
118 public:
119 static void SetUpTestCase();
120 static void TearDownTestCase();
121 void SetUp() override;
122 void TearDown() override;
123
124 void MakeMockObjects();
125 void SetMockObjects(BundleManagerShellCommand &cmd) const;
126
127 sptr<IBundleMgr> mgrProxyPtr_;
128 sptr<IBundleInstaller> installerProxyPtr_;
129 };
130
SetUpTestCase()131 void BmCommandTest::SetUpTestCase()
132 {}
133
TearDownTestCase()134 void BmCommandTest::TearDownTestCase()
135 {}
136
SetUp()137 void BmCommandTest::SetUp()
138 {
139 // reset optind to 0
140 optind = 0;
141
142 // make mock objects
143 MakeMockObjects();
144 }
145
TearDown()146 void BmCommandTest::TearDown()
147 {}
148
MakeMockObjects()149 void BmCommandTest::MakeMockObjects()
150 {
151 // mock a mgr host
152 auto mgrHostPtr = sptr<IRemoteObject>(new (std::nothrow) MockBundleMgrHost());
153 // mock a mgr proxy
154 mgrProxyPtr_ = iface_cast<IBundleMgr>(mgrHostPtr);
155
156 // mock a installer host
157 auto installerHostPtr = sptr<IRemoteObject>(new (std::nothrow) MockBundleInstallerHost());
158 // mock a installer proxy
159 installerProxyPtr_ = iface_cast<IBundleInstaller>(installerHostPtr);
160 }
161
SetMockObjects(BundleManagerShellCommand & cmd) const162 void BmCommandTest::SetMockObjects(BundleManagerShellCommand &cmd) const
163 {
164 // set the mock mgr proxy
165 cmd.bundleMgrProxy_ = mgrProxyPtr_;
166
167 // set the mock installer proxy
168 cmd.bundleInstallerProxy_ = installerProxyPtr_;
169 }
170
171 /**
172 * @tc.number: Bm_Command_0001
173 * @tc.name: ExecCommand
174 * @tc.desc: Verify the "bm" command.
175 */
176 HWTEST_F(BmCommandTest, Bm_Command_0001, Function | MediumTest | TestSize.Level1)
177 {
178 char *argv[] = {
179 const_cast<char*>(TOOL_NAME.c_str()),
180 const_cast<char*>(""),
181 };
182 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
183
184 BundleManagerShellCommand cmd(argc, argv);
185
186 // set the mock objects
187 SetMockObjects(cmd);
188
189 std::string message;
190 message += HELP_MSG;
191 int32_t mode = GetIntParameter(IS_ROOT_MODE_PARAM, ROOT_MODE);
192 if (mode == ROOT_MODE) {
193 message += ENABLE_DISABLE_HELP_MSG;
194 }
195 bool isDeveloperMode = system::GetBoolParameter(IS_DEVELOPER_MODE_PARAM, false);
196 if (mode == ROOT_MODE || isDeveloperMode) {
197 message += CLEAN_HELP_MSG;
198 }
199
200 EXPECT_EQ(cmd.ExecCommand(), message);
201 }
202
203 /**
204 * @tc.number: Bm_Command_0002
205 * @tc.name: ExecCommand
206 * @tc.desc: Verify the "bm xxx" command.
207 */
208 HWTEST_F(BmCommandTest, Bm_Command_0002, Function | MediumTest | TestSize.Level1)
209 {
210 char *argv[] = {
211 const_cast<char*>(TOOL_NAME.c_str()),
212 const_cast<char*>("xxx"),
213 const_cast<char*>(""),
214 };
215 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
216
217 BundleManagerShellCommand cmd(argc, argv);
218
219 // set the mock objects
220 SetMockObjects(cmd);
221
222 std::string message;
223 message += HELP_MSG;
224 int32_t mode = GetIntParameter(IS_ROOT_MODE_PARAM, ROOT_MODE);
225 if (mode == ROOT_MODE) {
226 message += ENABLE_DISABLE_HELP_MSG;
227 }
228 bool isDeveloperMode = system::GetBoolParameter(IS_DEVELOPER_MODE_PARAM, false);
229 if (mode == ROOT_MODE || isDeveloperMode) {
230 message += CLEAN_HELP_MSG;
231 }
232
233 EXPECT_EQ(cmd.ExecCommand(), cmd.GetCommandErrorMsg() + message);
234 }
235
236 /**
237 * @tc.number: Bm_Command_0003
238 * @tc.name: ExecCommand
239 * @tc.desc: Verify the "bm -xxx" command.
240 */
241 HWTEST_F(BmCommandTest, Bm_Command_0003, Function | MediumTest | TestSize.Level1)
242 {
243 char *argv[] = {
244 const_cast<char*>(TOOL_NAME.c_str()),
245 const_cast<char*>("-xxx"),
246 const_cast<char*>(""),
247 };
248 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
249
250 BundleManagerShellCommand cmd(argc, argv);
251
252 // set the mock objects
253 SetMockObjects(cmd);
254
255 std::string message;
256 message += HELP_MSG;
257 int32_t mode = GetIntParameter(IS_ROOT_MODE_PARAM, ROOT_MODE);
258 if (mode == ROOT_MODE) {
259 message += ENABLE_DISABLE_HELP_MSG;
260 }
261 bool isDeveloperMode = system::GetBoolParameter(IS_DEVELOPER_MODE_PARAM, false);
262 if (mode == ROOT_MODE || isDeveloperMode) {
263 message += CLEAN_HELP_MSG;
264 }
265
266 EXPECT_EQ(cmd.ExecCommand(), cmd.GetCommandErrorMsg() + message);
267 }
268
269 /**
270 * @tc.number: Bm_Command_0004
271 * @tc.name: ExecCommand
272 * @tc.desc: Verify the "bm --xxx" command.
273 */
274 HWTEST_F(BmCommandTest, Bm_Command_0004, Function | MediumTest | TestSize.Level1)
275 {
276 char *argv[] = {
277 const_cast<char*>(TOOL_NAME.c_str()),
278 const_cast<char*>("--xxx"),
279 const_cast<char*>(""),
280 };
281 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
282
283 BundleManagerShellCommand cmd(argc, argv);
284
285 // set the mock objects
286 SetMockObjects(cmd);
287
288 std::string message;
289 message += HELP_MSG;
290 int32_t mode = GetIntParameter(IS_ROOT_MODE_PARAM, ROOT_MODE);
291 if (mode == ROOT_MODE) {
292 message += ENABLE_DISABLE_HELP_MSG;
293 }
294 bool isDeveloperMode = system::GetBoolParameter(IS_DEVELOPER_MODE_PARAM, false);
295 if (mode == ROOT_MODE || isDeveloperMode) {
296 message += CLEAN_HELP_MSG;
297 }
298
299 EXPECT_EQ(cmd.ExecCommand(), cmd.GetCommandErrorMsg() + message);
300 }
301
302 /**
303 * @tc.number: Bm_Command_0005
304 * @tc.name: ExecCommand
305 * @tc.desc: Verify the "bm help" command.
306 */
307 HWTEST_F(BmCommandTest, Bm_Command_0005, Function | MediumTest | TestSize.Level1)
308 {
309 char *argv[] = {
310 const_cast<char*>(TOOL_NAME.c_str()),
311 const_cast<char*>("help"),
312 const_cast<char*>(""),
313 };
314 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
315
316 BundleManagerShellCommand cmd(argc, argv);
317
318 // set the mock objects
319 SetMockObjects(cmd);
320
321 std::string message;
322 message += HELP_MSG;
323 int32_t mode = GetIntParameter(IS_ROOT_MODE_PARAM, ROOT_MODE);
324 if (mode == ROOT_MODE) {
325 message += ENABLE_DISABLE_HELP_MSG;
326 }
327 bool isDeveloperMode = system::GetBoolParameter(IS_DEVELOPER_MODE_PARAM, false);
328 if (mode == ROOT_MODE || isDeveloperMode) {
329 message += CLEAN_HELP_MSG;
330 }
331
332 EXPECT_EQ(cmd.ExecCommand(), message);
333 }
334
335 /**
336 * @tc.number: Bm_Command_Clean_0001
337 * @tc.name: ExecCommand
338 * @tc.desc: Verify the "bm clean" command.
339 */
340 HWTEST_F(BmCommandTest, Bm_Command_Clean_0001, Function | MediumTest | TestSize.Level1)
341 {
342 char *argv[] = {
343 const_cast<char*>(TOOL_NAME.c_str()),
344 const_cast<char*>("clean"),
345 const_cast<char*>(""),
346 };
347 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
348 BundleManagerShellCommand cmd(argc, argv);
349 // set the mock objects
350 SetMockObjects(cmd);
351 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_CLEAN);
352 }
353
354 /**
355 * @tc.number: Bm_Command_Clean_0002
356 * @tc.name: ExecCommand
357 * @tc.desc: Verify the "bm clean xx" command.
358 */
359 HWTEST_F(BmCommandTest, Bm_Command_Clean_0002, Function | MediumTest | TestSize.Level1)
360 {
361 char *argv[] = {
362 const_cast<char*>(TOOL_NAME.c_str()),
363 const_cast<char*>("clean"),
364 const_cast<char*>("xxx"),
365 const_cast<char*>(""),
366 };
367 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
368 BundleManagerShellCommand cmd(argc, argv);
369 // set the mock objects
370 SetMockObjects(cmd);
371 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_CLEAN);
372 }
373
374 /**
375 * @tc.number: Bm_Command_Clean_0003
376 * @tc.name: ExecCommand
377 * @tc.desc: Verify the "bm clean -n" command.
378 */
379 HWTEST_F(BmCommandTest, Bm_Command_Clean_0003, Function | MediumTest | TestSize.Level1)
380 {
381 char *argv[] = {
382 const_cast<char*>(TOOL_NAME.c_str()),
383 const_cast<char*>("clean"),
384 const_cast<char*>("-n"),
385 const_cast<char*>(""),
386 };
387 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
388 BundleManagerShellCommand cmd(argc, argv);
389 // set the mock objects
390 SetMockObjects(cmd);
391 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_CLEAN);
392 }
393
394 /**
395 * @tc.number: Bm_Command_Clean_0004
396 * @tc.name: ExecCommand
397 * @tc.desc: Verify the "bm clean -n <bundle-name>" command.
398 */
399 HWTEST_F(BmCommandTest, Bm_Command_Clean_0004, Function | MediumTest | TestSize.Level1)
400 {
401 char *argv[] = {
402 const_cast<char*>(TOOL_NAME.c_str()),
403 const_cast<char*>("clean"),
404 const_cast<char*>("-n"),
405 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
406 const_cast<char*>(""),
407 };
408 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
409 BundleManagerShellCommand cmd(argc, argv);
410 // set the mock objects
411 SetMockObjects(cmd);
412 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_DATA_OR_CACHE_OPTION + "\n" + HELP_MSG_CLEAN);
413 }
414
415 /**
416 * @tc.number: Bm_Command_Clean_0005
417 * @tc.name: ExecCommand
418 * @tc.desc: Verify the "bm clean -n <bundle-name> xxx" command.
419 */
420 HWTEST_F(BmCommandTest, Bm_Command_Clean_0005, Function | MediumTest | TestSize.Level1)
421 {
422 char *argv[] = {
423 const_cast<char*>(TOOL_NAME.c_str()),
424 const_cast<char*>("clean"),
425 const_cast<char*>("-n"),
426 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
427 const_cast<char*>("xxx"),
428 const_cast<char*>(""),
429 };
430 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
431 BundleManagerShellCommand cmd(argc, argv);
432 // set the mock objects
433 SetMockObjects(cmd);
434 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_DATA_OR_CACHE_OPTION + "\n" + HELP_MSG_CLEAN);
435 }
436
437 /**
438 * @tc.number: Bm_Command_Clean_0006
439 * @tc.name: ExecCommand
440 * @tc.desc: Verify the "bm clean -n <bundle-name> -d" command.
441 */
442 HWTEST_F(BmCommandTest, Bm_Command_Clean_0006, Function | MediumTest | TestSize.Level1)
443 {
444 char *argv[] = {
445 const_cast<char*>(TOOL_NAME.c_str()),
446 const_cast<char*>("clean"),
447 const_cast<char*>("-n"),
448 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
449 const_cast<char*>("-d"),
450 const_cast<char*>(""),
451 };
452 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
453 BundleManagerShellCommand cmd(argc, argv);
454 // set the mock objects
455 SetMockObjects(cmd);
456 EXPECT_EQ(cmd.ExecCommand(), STRING_CLEAN_DATA_BUNDLE_NG + "\n");
457 }
458
459 /**
460 * @tc.number: Bm_Command_Clean_0007
461 * @tc.name: ExecCommand
462 * @tc.desc: Verify the "bm clean -n <bundle-name> -c" command.
463 */
464 HWTEST_F(BmCommandTest, Bm_Command_Clean_0007, Function | MediumTest | TestSize.Level1)
465 {
466 char *argv[] = {
467 const_cast<char*>(TOOL_NAME.c_str()),
468 const_cast<char*>("clean"),
469 const_cast<char*>("-n"),
470 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
471 const_cast<char*>("-c"),
472 const_cast<char*>(""),
473 };
474 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
475 BundleManagerShellCommand cmd(argc, argv);
476 // set the mock objects
477 SetMockObjects(cmd);
478 EXPECT_EQ(cmd.ExecCommand(), STRING_CLEAN_CACHE_BUNDLE_OK + "\n");
479 }
480
481 /**
482 * @tc.number: Bm_Command_Clean_0008
483 * @tc.name: ExecCommand
484 * @tc.desc: Verify the "bm clean -c" command.
485 */
486 HWTEST_F(BmCommandTest, Bm_Command_Clean_0008, Function | MediumTest | TestSize.Level1)
487 {
488 char *argv[] = {
489 const_cast<char*>(TOOL_NAME.c_str()),
490 const_cast<char*>("clean"),
491 const_cast<char*>("-c"),
492 const_cast<char*>(""),
493 };
494 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
495 BundleManagerShellCommand cmd(argc, argv);
496 // set the mock objects
497 SetMockObjects(cmd);
498 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_BUNDLE_NAME_OPTION + "\n" + HELP_MSG_CLEAN);
499 }
500
501 /**
502 * @tc.number: Bm_Command_Clean_0009
503 * @tc.name: ExecCommand
504 * @tc.desc: Verify the "bm clean -d" command.
505 */
506 HWTEST_F(BmCommandTest, Bm_Command_Clean_0009, Function | MediumTest | TestSize.Level1)
507 {
508 char *argv[] = {
509 const_cast<char*>(TOOL_NAME.c_str()),
510 const_cast<char*>("clean"),
511 const_cast<char*>("-d"),
512 const_cast<char*>(""),
513 };
514 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
515 BundleManagerShellCommand cmd(argc, argv);
516 // set the mock objects
517 SetMockObjects(cmd);
518 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_BUNDLE_NAME_OPTION + "\n" + HELP_MSG_CLEAN);
519 }
520
521 /**
522 * @tc.number: Bm_Command_Clean_0010
523 * @tc.name: ExecCommand
524 * @tc.desc: Verify the "bm clean -n <bundle-name> -d -u" command.
525 */
526 HWTEST_F(BmCommandTest, Bm_Command_Clean_0010, Function | MediumTest | TestSize.Level1)
527 {
528 char *argv[] = {
529 const_cast<char*>(TOOL_NAME.c_str()),
530 const_cast<char*>("clean"),
531 const_cast<char*>("-n"),
532 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
533 const_cast<char*>("-d"),
534 const_cast<char*>(" "),
535 const_cast<char*>("-u"),
536 const_cast<char*>(""),
537 };
538 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
539 BundleManagerShellCommand cmd(argc, argv);
540 // set the mock objects
541 SetMockObjects(cmd);
542 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_CLEAN);
543 }
544
545 /**
546 * @tc.number: Bm_Command_Clean_0012
547 * @tc.name: ExecCommand
548 * @tc.desc: Verify the "bm clean -n <bundle-name> -d -u <user-id>" command.
549 */
550 HWTEST_F(BmCommandTest, Bm_Command_Clean_0012, Function | MediumTest | TestSize.Level1)
551 {
552 char *argv[] = {
553 const_cast<char*>(TOOL_NAME.c_str()),
554 const_cast<char*>("clean"),
555 const_cast<char*>("-n"),
556 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
557 const_cast<char*>("-d"),
558 const_cast<char*>(" "),
559 const_cast<char*>("-u"),
560 const_cast<char*>(DEFAULT_USER_ID.c_str()),
561 const_cast<char*>(""),
562 };
563 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
564 BundleManagerShellCommand cmd(argc, argv);
565 // set the mock objects
566 SetMockObjects(cmd);
567 EXPECT_EQ(cmd.ExecCommand(), STRING_CLEAN_DATA_BUNDLE_NG + "\n");
568 }
569
570 /**
571 * @tc.number: Bm_Command_Clean_0013
572 * @tc.name: ExecCommand
573 * @tc.desc: Verify the "bm clean -h" command.
574 */
575 HWTEST_F(BmCommandTest, Bm_Command_Clean_0013, Function | MediumTest | TestSize.Level1)
576 {
577 char *argv[] = {
578 const_cast<char*>(TOOL_NAME.c_str()),
579 const_cast<char*>("clean"),
580 const_cast<char*>("-h"),
581 };
582 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
583 BundleManagerShellCommand cmd(argc, argv);
584 // set the mock objects
585 SetMockObjects(cmd);
586 EXPECT_EQ(cmd.ExecCommand(), "error: you must specify an option at least.\n" + HELP_MSG_CLEAN);
587 }
588
589 /**
590 * @tc.number: Bm_Command_Clean_0014
591 * @tc.name: ExecCommand
592 * @tc.desc: Verify the "bm clean -xxx" command.
593 */
594 HWTEST_F(BmCommandTest, Bm_Command_Clean_0014, Function | MediumTest | TestSize.Level1)
595 {
596 char *argv[] = {
597 const_cast<char*>(TOOL_NAME.c_str()),
598 const_cast<char*>("clean"),
599 const_cast<char*>("-XXX"),
600 const_cast<char*>(" "),
601 };
602 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
603 BundleManagerShellCommand cmd(argc, argv);
604 // set the mock objects
605 SetMockObjects(cmd);
606 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_CLEAN);
607 }
608
609 /**
610 * @tc.number: Bm_Command_Clean_0015
611 * @tc.name: ExecCommand
612 * @tc.desc: Verify the "bm clean -n <bundle-name> -d -xxx <user-id>" command.
613 */
614 HWTEST_F(BmCommandTest, Bm_Command_Clean_0015, Function | MediumTest | TestSize.Level1)
615 {
616 char *argv[] = {
617 const_cast<char*>(TOOL_NAME.c_str()),
618 const_cast<char*>("clean"),
619 const_cast<char*>("-n"),
620 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
621 const_cast<char*>("-d"),
622 const_cast<char*>(" "),
623 const_cast<char*>("-XXX"),
624 const_cast<char*>(DEFAULT_USER_ID.c_str()),
625 const_cast<char*>(""),
626 };
627 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
628 BundleManagerShellCommand cmd(argc, argv);
629 // set the mock objects
630 SetMockObjects(cmd);
631 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_CLEAN);
632 }
633
634 /**
635 * @tc.number: Bm_Command_Clean_0016
636 * @tc.name: ExecCommand
637 * @tc.desc: Verify the "bm clean -xxx <bundle-name>" command.
638 */
639 HWTEST_F(BmCommandTest, Bm_Command_Clean_0016, Function | MediumTest | TestSize.Level1)
640 {
641 char *argv[] = {
642 const_cast<char*>(TOOL_NAME.c_str()),
643 const_cast<char*>("clean"),
644 const_cast<char*>("-xxx"),
645 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
646 const_cast<char*>(""),
647 };
648 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
649 BundleManagerShellCommand cmd(argc, argv);
650 // set the mock objects
651 SetMockObjects(cmd);
652 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_CLEAN);
653 }
654
655 /**
656 * @tc.number: Bm_Command_Clean_0017
657 * @tc.name: ExecCommand
658 * @tc.desc: Verify the "bm clean -h" command.
659 */
660 HWTEST_F(BmCommandTest, Bm_Command_Clean_0017, Function | MediumTest | TestSize.Level1)
661 {
662 char *argv[] = {
663 const_cast<char*>(TOOL_NAME.c_str()),
664 const_cast<char*>("clean"),
665 const_cast<char*>("-h"),
666 const_cast<char*>(""),
667 };
668 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
669 BundleManagerShellCommand cmd(argc, argv);
670 // set the mock objects
671 SetMockObjects(cmd);
672 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_CLEAN);
673 }
674
675 /**
676 * @tc.number: Bm_Command_Enable_0001
677 * @tc.name: ExecCommand
678 * @tc.desc: Verify the "bm enable" command.
679 */
680 HWTEST_F(BmCommandTest, Bm_Command_Enable_0001, Function | MediumTest | TestSize.Level1)
681 {
682 char *argv[] = {
683 const_cast<char*>(TOOL_NAME.c_str()),
684 const_cast<char*>("enable"),
685 const_cast<char*>(""),
686 };
687 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
688 BundleManagerShellCommand cmd(argc, argv);
689 // set the mock objects
690 SetMockObjects(cmd);
691 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_ENABLE);
692 }
693
694 /**
695 * @tc.number: Bm_Command_Enable_0002
696 * @tc.name: ExecCommand
697 * @tc.desc: Verify the "bm enable -n <bundle-name>" command.
698 */
699 HWTEST_F(BmCommandTest, Bm_Command_Enable_0002, Function | MediumTest | TestSize.Level1)
700 {
701 char *argv[] = {
702 const_cast<char*>(TOOL_NAME.c_str()),
703 const_cast<char*>("enable"),
704 const_cast<char*>("-n"),
705 const_cast<char*>(""),
706 };
707 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
708 BundleManagerShellCommand cmd(argc, argv);
709 // set the mock objects
710 SetMockObjects(cmd);
711 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_ENABLE);
712 }
713
714 /**
715 * @tc.number: Bm_Command_Enable_0003
716 * @tc.name: ExecCommand
717 * @tc.desc: Verify the "bm enable -n <bundle-name>" command.
718 */
719 HWTEST_F(BmCommandTest, Bm_Command_Enable_0003, Function | MediumTest | TestSize.Level1)
720 {
721 char *argv[] = {
722 const_cast<char*>(TOOL_NAME.c_str()),
723 const_cast<char*>("enable"),
724 const_cast<char*>("-n"),
725 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
726 const_cast<char*>(""),
727 };
728 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
729 BundleManagerShellCommand cmd(argc, argv);
730 // set the mock objects
731 SetMockObjects(cmd);
732 EXPECT_EQ(cmd.ExecCommand(), STRING_ENABLE_BUNDLE_OK + "\n");
733 }
734
735 /**
736 * @tc.number: Bm_Command_Enable_0004
737 * @tc.name: ExecCommand
738 * @tc.desc: Verify the "bm enable -n <bundle-name> -a <ability-name>" command.
739 */
740 HWTEST_F(BmCommandTest, Bm_Command_Enable_0004, Function | MediumTest | TestSize.Level1)
741 {
742 char *argv[] = {
743 const_cast<char*>(TOOL_NAME.c_str()),
744 const_cast<char*>("enable"),
745 const_cast<char*>("-n"),
746 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
747 const_cast<char*>("-a"),
748 const_cast<char*>(""),
749 };
750 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
751 BundleManagerShellCommand cmd(argc, argv);
752 // set the mock objects
753 SetMockObjects(cmd);
754 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_ENABLE);
755 }
756
757 /**
758 * @tc.number: Bm_Command_Enable_0005
759 * @tc.name: ExecCommand
760 * @tc.desc: Verify the "bm enable -n <bundle-name> -a <ability-name>" command.
761 */
762 HWTEST_F(BmCommandTest, Bm_Command_Enable_0005, Function | MediumTest | TestSize.Level1)
763 {
764 char *argv[] = {
765 const_cast<char*>(TOOL_NAME.c_str()),
766 const_cast<char*>("enable"),
767 const_cast<char*>("-n"),
768 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
769 const_cast<char*>("-a"),
770 const_cast<char*>(STRING_ABILITY_NAME.c_str()),
771 const_cast<char*>(""),
772 };
773 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
774 BundleManagerShellCommand cmd(argc, argv);
775 // set the mock objects
776 SetMockObjects(cmd);
777 EXPECT_EQ(cmd.ExecCommand(), STRING_ENABLE_BUNDLE_OK + "\n");
778 }
779
780 /**
781 * @tc.number: Bm_Command_Enable_0006
782 * @tc.name: ExecCommand
783 * @tc.desc: Verify the "bm enable -x" command.
784 */
785 HWTEST_F(BmCommandTest, Bm_Command_Enable_0006, Function | MediumTest | TestSize.Level1)
786 {
787 char *argv[] = {
788 const_cast<char*>(TOOL_NAME.c_str()),
789 const_cast<char*>("enable"),
790 const_cast<char*>("-x"),
791 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
792 const_cast<char*>(""),
793 };
794 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
795 BundleManagerShellCommand cmd(argc, argv);
796 // set the mock objects
797 SetMockObjects(cmd);
798 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_ENABLE);
799 }
800
801 /**
802 * @tc.number: Bm_Command_Enable_0007
803 * @tc.name: ExecCommand
804 * @tc.desc: Verify the "bm enable -n <bundle-name> -u" command.
805 */
806 HWTEST_F(BmCommandTest, Bm_Command_Enable_0007, Function | MediumTest | TestSize.Level1)
807 {
808 char *argv[] = {
809 const_cast<char*>(TOOL_NAME.c_str()),
810 const_cast<char*>("enable"),
811 const_cast<char*>("-n"),
812 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
813 const_cast<char*>("-u"),
814 const_cast<char*>(""),
815 };
816 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
817 BundleManagerShellCommand cmd(argc, argv);
818 // set the mock objects
819 SetMockObjects(cmd);
820 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_ENABLE);
821 }
822
823 /**
824 * @tc.number: Bm_Command_Enable_0009
825 * @tc.name: ExecCommand
826 * @tc.desc: Verify the "bm enable -n <bundle-name> -u <user-id>" command.
827 */
828 HWTEST_F(BmCommandTest, Bm_Command_Enable_0009, Function | MediumTest | TestSize.Level1)
829 {
830 char *argv[] = {
831 const_cast<char*>(TOOL_NAME.c_str()),
832 const_cast<char*>("enable"),
833 const_cast<char*>("-n"),
834 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
835 const_cast<char*>("-u"),
836 const_cast<char*>(DEFAULT_USER_ID.c_str()),
837 const_cast<char*>(""),
838 };
839 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
840 BundleManagerShellCommand cmd(argc, argv);
841 // set the mock objects
842 SetMockObjects(cmd);
843 EXPECT_EQ(cmd.ExecCommand(), STRING_ENABLE_BUNDLE_OK + "\n");
844 }
845
846 /**
847 * @tc.number: Bm_Command_Enable_0010
848 * @tc.name: ExecCommand
849 * @tc.desc: Verify the "bm enable -h" command.
850 */
851 HWTEST_F(BmCommandTest, Bm_Command_Enable_0010, Function | MediumTest | TestSize.Level1)
852 {
853 char *argv[] = {
854 const_cast<char*>(TOOL_NAME.c_str()),
855 const_cast<char*>("enable"),
856 const_cast<char*>("-h"),
857 const_cast<char*>(""),
858 };
859 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
860 BundleManagerShellCommand cmd(argc, argv);
861 // set the mock objects
862 SetMockObjects(cmd);
863 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_ENABLE);
864 }
865
866 /**
867 * @tc.number: Bm_Command_Enable_0011
868 * @tc.name: ExecCommand
869 * @tc.desc: Verify the "bm enable -n <bundle-name> -xxx <user-id>" command.
870 */
871 HWTEST_F(BmCommandTest, Bm_Command_Enable_0011, Function | MediumTest | TestSize.Level1)
872 {
873 char *argv[] = {
874 const_cast<char*>(TOOL_NAME.c_str()),
875 const_cast<char*>("enable"),
876 const_cast<char*>("-n"),
877 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
878 const_cast<char*>("-XXX"),
879 const_cast<char*>(DEFAULT_USER_ID.c_str()),
880 const_cast<char*>(""),
881 };
882 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
883 BundleManagerShellCommand cmd(argc, argv);
884 // set the mock objects
885 SetMockObjects(cmd);
886 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_ENABLE);
887 }
888
889 /**
890 * @tc.number: Bm_Command_Disable_0001
891 * @tc.name: ExecCommand
892 * @tc.desc: Verify the "bm disable" command.
893 */
894 HWTEST_F(BmCommandTest, Bm_Command_Disable_0001, Function | MediumTest | TestSize.Level1)
895 {
896 char *argv[] = {
897 const_cast<char*>(TOOL_NAME.c_str()),
898 const_cast<char*>("disable"),
899 const_cast<char*>(""),
900 };
901 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
902 BundleManagerShellCommand cmd(argc, argv);
903 // set the mock objects
904 SetMockObjects(cmd);
905 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_DISABLE);
906 }
907
908 /**
909 * @tc.number: Bm_Command_Disable_0002
910 * @tc.name: ExecCommand
911 * @tc.desc: Verify the "bm disable -n <bundle-name>" command.
912 */
913 HWTEST_F(BmCommandTest, Bm_Command_Disable_0002, Function | MediumTest | TestSize.Level1)
914 {
915 char *argv[] = {
916 const_cast<char*>(TOOL_NAME.c_str()),
917 const_cast<char*>("disable"),
918 const_cast<char*>("-n"),
919 const_cast<char*>(""),
920 };
921 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
922 BundleManagerShellCommand cmd(argc, argv);
923 // set the mock objects
924 SetMockObjects(cmd);
925 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_DISABLE);
926 }
927
928 /**
929 * @tc.number: Bm_Command_Disable_0003
930 * @tc.name: ExecCommand
931 * @tc.desc: Verify the "bm disable -n <bundle-name>" command.
932 */
933 HWTEST_F(BmCommandTest, Bm_Command_Disable_0003, Function | MediumTest | TestSize.Level1)
934 {
935 char *argv[] = {
936 const_cast<char*>(TOOL_NAME.c_str()),
937 const_cast<char*>("disable"),
938 const_cast<char*>("-n"),
939 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
940 const_cast<char*>(""),
941 };
942 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
943 BundleManagerShellCommand cmd(argc, argv);
944 // set the mock objects
945 SetMockObjects(cmd);
946 EXPECT_EQ(cmd.ExecCommand(), STRING_DISABLE_BUNDLE_OK + "\n");
947 }
948
949 /**
950 * @tc.number: Bm_Command_Disable_0004
951 * @tc.name: ExecCommand
952 * @tc.desc: Verify the "bm disable -n <bundle-name> -a <ability-name>" command.
953 */
954 HWTEST_F(BmCommandTest, Bm_Command_Disable_0004, Function | MediumTest | TestSize.Level1)
955 {
956 char *argv[] = {
957 const_cast<char*>(TOOL_NAME.c_str()),
958 const_cast<char*>("disable"),
959 const_cast<char*>("-n"),
960 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
961 const_cast<char*>("-a"),
962 const_cast<char*>(""),
963 };
964 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
965 BundleManagerShellCommand cmd(argc, argv);
966 // set the mock objects
967 SetMockObjects(cmd);
968 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_DISABLE);
969 }
970
971 /**
972 * @tc.number: Bm_Command_Disable_0005
973 * @tc.name: ExecCommand
974 * @tc.desc: Verify the "bm disable -n <bundle-name> -a <ability-name>" command.
975 */
976 HWTEST_F(BmCommandTest, Bm_Command_Disable_0005, Function | MediumTest | TestSize.Level1)
977 {
978 char *argv[] = {
979 const_cast<char*>(TOOL_NAME.c_str()),
980 const_cast<char*>("disable"),
981 const_cast<char*>("-n"),
982 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
983 const_cast<char*>("-a"),
984 const_cast<char*>(STRING_ABILITY_NAME.c_str()),
985 const_cast<char*>(""),
986 };
987 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
988 BundleManagerShellCommand cmd(argc, argv);
989 // set the mock objects
990 SetMockObjects(cmd);
991 EXPECT_EQ(cmd.ExecCommand(), STRING_DISABLE_BUNDLE_OK + "\n");
992 }
993
994 /**
995 * @tc.number: Bm_Command_Disable_0006
996 * @tc.name: ExecCommand
997 * @tc.desc: Verify the "bm disable -n <bundle-name> -u <user-id>" command.
998 */
999 HWTEST_F(BmCommandTest, Bm_Command_Disable_0006, Function | MediumTest | TestSize.Level1)
1000 {
1001 char *argv[] = {
1002 const_cast<char*>(TOOL_NAME.c_str()),
1003 const_cast<char*>("disable"),
1004 const_cast<char*>("-n"),
1005 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
1006 const_cast<char*>("-u"),
1007 const_cast<char*>(""),
1008 };
1009 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1010 BundleManagerShellCommand cmd(argc, argv);
1011 // set the mock objects
1012 SetMockObjects(cmd);
1013 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_DISABLE);
1014 }
1015
1016 /**
1017 * @tc.number: Bm_Command_Disable_0007
1018 * @tc.name: ExecCommand
1019 * @tc.desc: Verify the "bm disable -n <bundle-name> -u <user-id>" command.
1020 */
1021 HWTEST_F(BmCommandTest, Bm_Command_Disable_0007, Function | MediumTest | TestSize.Level1)
1022 {
1023 char *argv[] = {
1024 const_cast<char*>(TOOL_NAME.c_str()),
1025 const_cast<char*>("disable"),
1026 const_cast<char*>("-n"),
1027 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
1028 const_cast<char*>("-u"),
1029 const_cast<char*>("100"),
1030 const_cast<char*>(""),
1031 };
1032 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1033 BundleManagerShellCommand cmd(argc, argv);
1034 // set the mock objects
1035 SetMockObjects(cmd);
1036 EXPECT_EQ(cmd.ExecCommand(), STRING_DISABLE_BUNDLE_OK + "\n");
1037 }
1038
1039 /**
1040 * @tc.number: Bm_Command_Disable_0008
1041 * @tc.name: ExecCommand
1042 * @tc.desc: Verify the "bm disable -x" command.
1043 */
1044 HWTEST_F(BmCommandTest, Bm_Command_Disable_0008, Function | MediumTest | TestSize.Level1)
1045 {
1046 char *argv[] = {
1047 const_cast<char*>(TOOL_NAME.c_str()),
1048 const_cast<char*>("disable"),
1049 const_cast<char*>("-x"),
1050 const_cast<char*>(""),
1051 };
1052 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1053 BundleManagerShellCommand cmd(argc, argv);
1054 // set the mock objects
1055 SetMockObjects(cmd);
1056 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DISABLE);
1057 }
1058
1059 /**
1060 * @tc.number: Bm_Command_Disable_0009
1061 * @tc.name: ExecCommand
1062 * @tc.desc: Verify the "bm disable -h" command.
1063 */
1064 HWTEST_F(BmCommandTest, Bm_Command_Disable_0009, Function | MediumTest | TestSize.Level1)
1065 {
1066 char *argv[] = {
1067 const_cast<char*>(TOOL_NAME.c_str()),
1068 const_cast<char*>("disable"),
1069 const_cast<char*>("-h"),
1070 const_cast<char*>(""),
1071 };
1072 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1073 BundleManagerShellCommand cmd(argc, argv);
1074 // set the mock objects
1075 SetMockObjects(cmd);
1076 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_DISABLE);
1077 }
1078
1079 /**
1080 * @tc.number: Bm_Command_Disable_0011
1081 * @tc.name: ExecCommand
1082 * @tc.desc: Verify the "bm disable -n <bundle-name> -xxx <ability-name>" command.
1083 */
1084 HWTEST_F(BmCommandTest, Bm_Command_Disable_0011, Function | MediumTest | TestSize.Level1)
1085 {
1086 char *argv[] = {
1087 const_cast<char*>(TOOL_NAME.c_str()),
1088 const_cast<char*>("disable"),
1089 const_cast<char*>("-n"),
1090 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
1091 const_cast<char*>("-XXX"),
1092 const_cast<char*>(STRING_ABILITY_NAME.c_str()),
1093 const_cast<char*>(""),
1094 };
1095 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1096 BundleManagerShellCommand cmd(argc, argv);
1097 // set the mock objects
1098 SetMockObjects(cmd);
1099 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DISABLE);
1100 }
1101
1102 /**
1103 * @tc.number: Bm_Command_Get_0001
1104 * @tc.name: ExecCommand
1105 * @tc.desc: Verify the "bm get" command.
1106 */
1107 HWTEST_F(BmCommandTest, Bm_Command_Get_0001, Function | MediumTest | TestSize.Level1)
1108 {
1109 // install a bundle
1110 char *argv[] = {
1111 const_cast<char*>(TOOL_NAME.c_str()),
1112 const_cast<char*>("get"),
1113 const_cast<char*>(""),
1114 };
1115 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1116
1117 BundleManagerShellCommand cmd(argc, argv);
1118
1119 // set the mock objects
1120 SetMockObjects(cmd);
1121
1122 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_GET);
1123 }
1124
1125 /**
1126 * @tc.number: Bm_Command_Get_0002
1127 * @tc.name: ExecCommand
1128 * @tc.desc: Verify the "bm get -u" command.
1129 */
1130 HWTEST_F(BmCommandTest, Bm_Command_Get_0002, Function | MediumTest | TestSize.Level1)
1131 {
1132 // install a bundle
1133 char *argv[] = {
1134 const_cast<char*>(TOOL_NAME.c_str()),
1135 const_cast<char*>("get"),
1136 const_cast<char*>("-u"),
1137 const_cast<char*>(""),
1138 };
1139 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1140
1141 BundleManagerShellCommand cmd(argc, argv);
1142
1143 // set the mock objects
1144 SetMockObjects(cmd);
1145
1146 std::string result = cmd.ExecCommand();
1147 auto pos = result.find(STRING_GET_UDID_OK);
1148
1149 EXPECT_NE(pos, std::string::npos);
1150 }
1151
1152 /**
1153 * @tc.number: Bm_Command_Get_0003
1154 * @tc.name: ExecCommand
1155 * @tc.desc: Verify the "bm get -x" command.
1156 */
1157 HWTEST_F(BmCommandTest, Bm_Command_Get_0003, Function | MediumTest | TestSize.Level1)
1158 {
1159 // install a bundle
1160 char *argv[] = {
1161 const_cast<char*>(TOOL_NAME.c_str()),
1162 const_cast<char*>("get"),
1163 const_cast<char*>("-x"),
1164 const_cast<char*>(""),
1165 };
1166 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1167
1168 BundleManagerShellCommand cmd(argc, argv);
1169
1170 // set the mock objects
1171 SetMockObjects(cmd);
1172
1173 EXPECT_EQ(cmd.ExecCommand(), STRING_INCORRECT_OPTION + "\n" + HELP_MSG_GET);
1174 }
1175
1176 /**
1177 * @tc.number: Bm_Command_Get_0004
1178 * @tc.name: ExecCommand
1179 * @tc.desc: Verify the "bm get -u -x" command.
1180 */
1181 HWTEST_F(BmCommandTest, Bm_Command_Get_0004, Function | MediumTest | TestSize.Level1)
1182 {
1183 // install a bundle
1184 char *argv[] = {
1185 const_cast<char*>(TOOL_NAME.c_str()),
1186 const_cast<char*>("get"),
1187 const_cast<char*>("-u"),
1188 const_cast<char*>("-x"),
1189 const_cast<char*>(""),
1190 };
1191 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1192
1193 BundleManagerShellCommand cmd(argc, argv);
1194
1195 // set the mock objects
1196 SetMockObjects(cmd);
1197
1198 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
1199 }
1200
1201 /**
1202 * @tc.number: Bm_Command_Get_0005
1203 * @tc.name: ExecCommand
1204 * @tc.desc: Verify the "bm get -u xxx" command.
1205 */
1206 HWTEST_F(BmCommandTest, Bm_Command_Get_0005, Function | MediumTest | TestSize.Level1)
1207 {
1208 // install a bundle
1209 char *argv[] = {
1210 const_cast<char*>(TOOL_NAME.c_str()),
1211 const_cast<char*>("get"),
1212 const_cast<char*>("-u"),
1213 const_cast<char*>("xxx"),
1214 const_cast<char*>(""),
1215 };
1216 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1217
1218 BundleManagerShellCommand cmd(argc, argv);
1219
1220 // set the mock objects
1221 SetMockObjects(cmd);
1222
1223 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
1224 }
1225
1226 /**
1227 * @tc.number: Bm_Command_Get_0006
1228 * @tc.name: ExecCommand
1229 * @tc.desc: Verify the "bm get --udid" command.
1230 */
1231 HWTEST_F(BmCommandTest, Bm_Command_Get_0006, Function | MediumTest | TestSize.Level1)
1232 {
1233 // install a bundle
1234 char *argv[] = {
1235 const_cast<char*>(TOOL_NAME.c_str()),
1236 const_cast<char*>("get"),
1237 const_cast<char*>("--udid"),
1238 const_cast<char*>(""),
1239 };
1240 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1241
1242 BundleManagerShellCommand cmd(argc, argv);
1243
1244 // set the mock objects
1245 SetMockObjects(cmd);
1246
1247 std::string result = cmd.ExecCommand();
1248 auto pos = result.find(STRING_GET_UDID_OK);
1249
1250 EXPECT_NE(pos, std::string::npos);
1251 }
1252
1253 /**
1254 * @tc.number: Bm_Command_Get_0007
1255 * @tc.name: ExecCommand
1256 * @tc.desc: Verify the "bm get --xxx" command.
1257 */
1258 HWTEST_F(BmCommandTest, Bm_Command_Get_0007, Function | MediumTest | TestSize.Level1)
1259 {
1260 // install a bundle
1261 char *argv[] = {
1262 const_cast<char*>(TOOL_NAME.c_str()),
1263 const_cast<char*>("get"),
1264 const_cast<char*>("--xxx"),
1265 const_cast<char*>(""),
1266 };
1267 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1268
1269 BundleManagerShellCommand cmd(argc, argv);
1270
1271 // set the mock objects
1272 SetMockObjects(cmd);
1273
1274 EXPECT_EQ(cmd.ExecCommand(), STRING_INCORRECT_OPTION + "\n" + HELP_MSG_GET);
1275 }
1276
1277 /**
1278 * @tc.number: Bm_Command_Get_0008
1279 * @tc.name: ExecCommand
1280 * @tc.desc: Verify the "bm get --udid -x" command.
1281 */
1282 HWTEST_F(BmCommandTest, Bm_Command_Get_0008, Function | MediumTest | TestSize.Level1)
1283 {
1284 // install a bundle
1285 char *argv[] = {
1286 const_cast<char*>(TOOL_NAME.c_str()),
1287 const_cast<char*>("get"),
1288 const_cast<char*>("--udid"),
1289 const_cast<char*>("-x"),
1290 const_cast<char*>(""),
1291 };
1292 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1293
1294 BundleManagerShellCommand cmd(argc, argv);
1295
1296 // set the mock objects
1297 SetMockObjects(cmd);
1298
1299 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
1300 }
1301
1302 /**
1303 * @tc.number: Bm_Command_Get_0009
1304 * @tc.name: ExecCommand
1305 * @tc.desc: Verify the "bm get -u xxx" command.
1306 */
1307 HWTEST_F(BmCommandTest, Bm_Command_Get_0009, Function | MediumTest | TestSize.Level1)
1308 {
1309 // install a bundle
1310 char *argv[] = {
1311 const_cast<char*>(TOOL_NAME.c_str()),
1312 const_cast<char*>("get"),
1313 const_cast<char*>("--udid"),
1314 const_cast<char*>("xxx"),
1315 const_cast<char*>(""),
1316 };
1317 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1318
1319 BundleManagerShellCommand cmd(argc, argv);
1320
1321 // set the mock objects
1322 SetMockObjects(cmd);
1323
1324 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
1325 }
1326
1327 /**
1328 * @tc.number: Bm_Command_Get_0010
1329 * @tc.name: ExecCommand
1330 * @tc.desc: Verify the "bm get -h" command.
1331 */
1332 HWTEST_F(BmCommandTest, Bm_Command_Get_0010, Function | MediumTest | TestSize.Level1)
1333 {
1334 // install a bundle
1335 char *argv[] = {
1336 const_cast<char*>(TOOL_NAME.c_str()),
1337 const_cast<char*>("get"),
1338 const_cast<char*>("-h"),
1339 const_cast<char*>(""),
1340 };
1341 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1342
1343 BundleManagerShellCommand cmd(argc, argv);
1344
1345 // set the mock objects
1346 SetMockObjects(cmd);
1347
1348 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
1349 }
1350
1351 /**
1352 * @tc.number: GetBundlePath_0001
1353 * @tc.name: test GetBundlePath
1354 * @tc.desc: Verify the "GetBundlePath".
1355 */
1356 HWTEST_F(BmCommandTest, GetBundlePath_0001, Function | MediumTest | TestSize.Level1)
1357 {
1358 // install a bundle
1359 char *argv[] = {
1360 const_cast<char*>(TOOL_NAME.c_str()),
1361 const_cast<char*>("-h"),
1362 };
1363 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1364
1365 BundleManagerShellCommand cmd(argc, argv);
1366 std::string param = "";
1367 std::vector<std::string> bundlePaths;
1368 auto res = cmd.GetBundlePath(param, bundlePaths);
1369 EXPECT_EQ(res, ERR_INVALID_VALUE);
1370
1371 param = "-r";
1372 res = cmd.GetBundlePath(param, bundlePaths);
1373 EXPECT_EQ(res, ERR_INVALID_VALUE);
1374
1375 param = "--replace";
1376 res = cmd.GetBundlePath(param, bundlePaths);
1377 EXPECT_EQ(res, ERR_INVALID_VALUE);
1378
1379 param = "-p";
1380 res = cmd.GetBundlePath(param, bundlePaths);
1381 EXPECT_EQ(res, ERR_INVALID_VALUE);
1382
1383 param = "--bundle-path";
1384 res = cmd.GetBundlePath(param, bundlePaths);
1385 EXPECT_EQ(res, ERR_INVALID_VALUE);
1386
1387 param = "-u";
1388 res = cmd.GetBundlePath(param, bundlePaths);
1389 EXPECT_EQ(res, ERR_INVALID_VALUE);
1390
1391 param = "--user-id";
1392 res = cmd.GetBundlePath(param, bundlePaths);
1393 EXPECT_EQ(res, ERR_INVALID_VALUE);
1394
1395 param = "-w";
1396 res = cmd.GetBundlePath(param, bundlePaths);
1397 EXPECT_EQ(res, ERR_INVALID_VALUE);
1398
1399 param = "--waitting-time";
1400 res = cmd.GetBundlePath(param, bundlePaths);
1401 EXPECT_EQ(res, ERR_INVALID_VALUE);
1402
1403 param = "-x";
1404 res = cmd.GetBundlePath(param, bundlePaths);
1405 EXPECT_EQ(res, ERR_OK);
1406 }
1407
1408 /**
1409 * @tc.number: ShellCommand_0010
1410 * @tc.name: ShellCommand
1411 * @tc.desc: Verify the ShellCommand.
1412 */
1413 HWTEST_F(BmCommandTest, ShellCommand_0010, Function | MediumTest | TestSize.Level1)
1414 {
1415 char *argv[] = {
1416 const_cast<char*>(TOOL_NAME.c_str()),
1417 const_cast<char*>("-h"),
1418 };
1419 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1420
1421 BundleManagerShellCommand cmd(argc, argv);
1422 auto ret = cmd.GetMessageFromCode(-1);
1423
1424 EXPECT_EQ(ret, "");
1425 }
1426
1427 /**
1428 * @tc.number: ShellCommand_0020
1429 * @tc.name: ShellCommand
1430 * @tc.desc: Verify the ShellCommand.
1431 */
1432 HWTEST_F(BmCommandTest, ShellCommand_0020, Function | MediumTest | TestSize.Level1)
1433 {
1434 char *argv[] = {
1435 const_cast<char*>(TOOL_NAME.c_str()),
1436 const_cast<char*>("-h"),
1437 };
1438 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1439
1440 BundleManagerShellCommand cmd(argc, argv);
1441 cmd.ExecCommand();
1442 auto ret = cmd.GetMessageFromCode(IStatusReceiver::ERR_INSTALL_INTERNAL_ERROR);
1443
1444 EXPECT_NE(ret, "");
1445 }
1446
1447 /**
1448 * @tc.number: ShellCommand_0030
1449 * @tc.name: ShellCommand
1450 * @tc.desc: Verify the ShellCommand.
1451 */
1452 HWTEST_F(BmCommandTest, ShellCommand_0030, Function | MediumTest | TestSize.Level1)
1453 {
1454 char *argv[] = {
1455 const_cast<char*>(TOOL_NAME.c_str()),
1456 const_cast<char*>("-h"),
1457 };
1458 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1459
1460 auto originOptind = optind;
1461 optind = 100;
1462
1463 BundleManagerShellCommand cmd(argc, argv);
1464 std::string unknownOption;
1465 auto ret = cmd.GetUnknownOptionMsg(unknownOption);
1466 optind = originOptind;
1467
1468 EXPECT_EQ(ret, "");
1469 }
1470
1471 /**
1472 * @tc.number: ShellCommand_0040
1473 * @tc.name: ShellCommand
1474 * @tc.desc: Verify the ShellCommand.
1475 */
1476 HWTEST_F(BmCommandTest, ShellCommand_0040, Function | MediumTest | TestSize.Level1)
1477 {
1478 char *argv[] = {
1479 const_cast<char*>(TOOL_NAME.c_str()),
1480 const_cast<char*>("-h"),
1481 };
1482 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1483
1484 MockCreateCommandMap mockCreateCommandMap(argc, argv);
1485 mockCreateCommandMap.commandMap_.emplace(
__anon22e11c140202null1486 std::make_pair("help", [mockCreateCommandMap]{ return mockCreateCommandMap.RunAsHelpCommand(); }));
1487 mockCreateCommandMap.cmd_ = "help";
1488 auto ret = mockCreateCommandMap.ExecCommand();
1489 EXPECT_EQ(ret, "");
1490 }
1491
1492 /**
1493 * @tc.number: ShellCommand_0050
1494 * @tc.name: ShellCommand
1495 * @tc.desc: Verify the ShellCommand.
1496 */
1497 HWTEST_F(BmCommandTest, ShellCommand_0050, Function | MediumTest | TestSize.Level1)
1498 {
1499 char *argv[] = {
1500 const_cast<char*>(TOOL_NAME.c_str()),
1501 const_cast<char*>("-h"),
1502 };
1503 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1504
1505 MockCreateMessageMap mockCreateMessageMap(argc, argv);
1506 mockCreateMessageMap.commandMap_.emplace(
__anon22e11c140302null1507 std::make_pair("help", [mockCreateMessageMap]{ return mockCreateMessageMap.RunAsHelpCommand(); }));
1508 mockCreateMessageMap.cmd_ = "help";
1509 auto ret = mockCreateMessageMap.ExecCommand();
1510 EXPECT_EQ(ret, "");
1511 }
1512
1513 /**
1514 * @tc.number: ShellCommand_0060
1515 * @tc.name: ShellCommand
1516 * @tc.desc: Verify the ShellCommand.
1517 */
1518 HWTEST_F(BmCommandTest, ShellCommand_0060, Function | MediumTest | TestSize.Level1)
1519 {
1520 char *argv[] = {
1521 const_cast<char*>(TOOL_NAME.c_str()),
1522 const_cast<char*>("-h"),
1523 };
1524 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1525
1526 MockInit mockInit(argc, argv);
1527 mockInit.commandMap_.emplace(
__anon22e11c140402null1528 std::make_pair("help", [mockInit]{ return mockInit.RunAsHelpCommand(); }));
1529 mockInit.cmd_ = "help";
1530 auto ret = mockInit.OnCommand();
1531 EXPECT_EQ(ret, OHOS::ERR_INVALID_VALUE);
1532 }
1533
1534 /**
1535 * @tc.number: ShellCommand_0070
1536 * @tc.name: ShellCommand
1537 * @tc.desc: Verify the ShellCommand.
1538 */
1539 HWTEST_F(BmCommandTest, ShellCommand_0070, Function | MediumTest | TestSize.Level1)
1540 {
1541 char *argv[] = {
1542 const_cast<char*>(TOOL_NAME.c_str()),
1543 const_cast<char*>("-h"),
1544 };
1545 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1546
1547 MockCreateMessageMap mockCreateMessageMap(argc, argv);
1548 mockCreateMessageMap.commandMap_.emplace(
__anon22e11c140502null1549 std::make_pair("help", [mockCreateMessageMap]{ return mockCreateMessageMap.RunAsHelpCommand(); }));
1550 mockCreateMessageMap.cmd_ = "help";
1551 auto ret = mockCreateMessageMap.OnCommand();
1552 EXPECT_EQ(ret, OHOS::ERR_OK);
1553 }
1554
1555 /**
1556 * @tc.number: ShellCommand_0080
1557 * @tc.name: ShellCommand
1558 * @tc.desc: Verify the ShellCommand.
1559 */
1560 HWTEST_F(BmCommandTest, ShellCommand_0080, Function | MediumTest | TestSize.Level1)
1561 {
1562 char *argv[] = {
1563 const_cast<char*>(TOOL_NAME.c_str()),
1564 const_cast<char*>("-h"),
1565 };
1566 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1567
1568 MockInit mockInit(argc, argv);
1569 mockInit.commandMap_.emplace(
__anon22e11c140602null1570 std::make_pair("help", [mockInit]{ return mockInit.RunAsHelpCommand(); }));
1571 mockInit.cmd_ = "help";
1572 auto ret = mockInit.ExecCommand();
1573 EXPECT_NE(ret, "");
1574 }
1575
1576 /**
1577 * @tc.number: BundleManagerShellCommand_0090
1578 * @tc.name: BundleManagerShellCommand
1579 * @tc.desc: Verify the BundleManagerShellCommand.
1580 */
1581 HWTEST_F(BmCommandTest, BundleManagerShellCommand_0090, Function | MediumTest | TestSize.Level1)
1582 {
1583 char *argv[] = {
1584 const_cast<char*>(TOOL_NAME.c_str()),
1585 const_cast<char*>("copy-ap"),
1586 };
1587 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1588
1589 BundleManagerShellCommand cmd(argc, argv);
1590
1591 auto ret = cmd.ExecCommand();
1592 EXPECT_EQ(ret, HELP_MSG + ENABLE_DISABLE_HELP_MSG + CLEAN_HELP_MSG);
1593 }
1594
1595 /**
1596 * @tc.number: BundleManagerShellCommand_0100
1597 * @tc.name: BundleManagerShellCommand
1598 * @tc.desc: Verify the BundleManagerShellCommand.
1599 */
1600 HWTEST_F(BmCommandTest, BundleManagerShellCommand_0100, Function | MediumTest | TestSize.Level1)
1601 {
1602 char *argv[] = {
1603 const_cast<char*>(TOOL_NAME.c_str()),
1604 const_cast<char*>("-h"),
1605 };
1606 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1607
1608 BundleManagerShellCommand cmd(argc, argv);
1609 auto originOptind = optind;
1610 optind = 100;
1611
1612 auto ret = cmd.RunAsCopyApCommand();
1613 optind = originOptind;
1614 EXPECT_EQ(ret, OHOS::ERR_INVALID_VALUE);
1615 }
1616
1617 /**
1618 * @tc.number: BundleManagerShellCommand_0110
1619 * @tc.name: BundleManagerShellCommand
1620 * @tc.desc: Verify the copy-ap.
1621 */
1622 HWTEST_F(BmCommandTest, BundleManagerShellCommand_0110, Function | MediumTest | TestSize.Level1)
1623 {
1624 char *argv[] = {
1625 const_cast<char*>(TOOL_NAME.c_str()),
1626 const_cast<char*>("copy-ap"),
1627 const_cast<char*>("-n"),
1628 };
1629 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1630
1631 BundleManagerShellCommand cmd(argc, argv);
1632
1633 auto ret = cmd.ExecCommand();
1634 EXPECT_EQ(ret, HELP_MSG_NO_OPTION + "\n" + HELP_MSG_COPY_AP);
1635 }
1636
1637 /**
1638 * @tc.number: BundleManagerShellCommand_0120
1639 * @tc.name: BundleManagerShellCommand
1640 * @tc.desc: Verify the copy-ap.
1641 */
1642 HWTEST_F(BmCommandTest, BundleManagerShellCommand_0120, Function | MediumTest | TestSize.Level1)
1643 {
1644 char *argv[] = {
1645 const_cast<char*>(TOOL_NAME.c_str()),
1646 const_cast<char*>("copy-ap"),
1647 const_cast<char*>("-n"),
1648 const_cast<char*>("test"),
1649 };
1650 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1651
1652 BundleManagerShellCommand cmd(argc, argv);
1653
1654 auto ret = cmd.ExecCommand();
1655 EXPECT_EQ(ret, STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_COPY_AP);
1656 }
1657
1658 /**
1659 * @tc.number: BundleManagerShellCommand_0130
1660 * @tc.name: BundleManagerShellCommand
1661 * @tc.desc: Verify the copy-ap.
1662 */
1663 HWTEST_F(BmCommandTest, BundleManagerShellCommand_0130, Function | MediumTest | TestSize.Level1)
1664 {
1665 char *argv[] = {
1666 const_cast<char*>(TOOL_NAME.c_str()),
1667 const_cast<char*>("copy-ap"),
1668 const_cast<char*>("-n"),
1669 const_cast<char*>("test"),
1670 };
1671 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1672
1673 BundleManagerShellCommand cmd(argc, argv);
1674 auto originOptind = optind;
1675 optind = 100;
1676
1677 auto ret = cmd.ExecCommand();
1678 optind = originOptind;
1679 EXPECT_EQ(ret, "");
1680 }
1681
1682 /**
1683 * @tc.number: BundleManagerShellCommand_0140
1684 * @tc.name: BundleManagerShellCommand
1685 * @tc.desc: Verify the copy-ap.
1686 */
1687 HWTEST_F(BmCommandTest, BundleManagerShellCommand_0140, Function | MediumTest | TestSize.Level1)
1688 {
1689 char *argv[] = {
1690 const_cast<char*>(TOOL_NAME.c_str()),
1691 const_cast<char*>("copy-ap"),
1692 const_cast<char*>("-m"),
1693 const_cast<char*>("test"),
1694 };
1695 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1696
1697 BundleManagerShellCommand cmd(argc, argv);
1698
1699 auto ret = cmd.ExecCommand();
1700 EXPECT_EQ(ret, "error: unknown option.\n" + HELP_MSG_COPY_AP);
1701 }
1702
1703 /**
1704 * @tc.number: BundleManagerShellCommand_0150
1705 * @tc.name: BundleManagerShellCommand
1706 * @tc.desc: Verify the copy-ap.
1707 */
1708 HWTEST_F(BmCommandTest, BundleManagerShellCommand_0150, Function | MediumTest | TestSize.Level1)
1709 {
1710 char *argv[] = {
1711 const_cast<char*>(TOOL_NAME.c_str()),
1712 const_cast<char*>("copy-ap"),
1713 const_cast<char*>("-a"),
1714 const_cast<char*>("test"),
1715 };
1716 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1717
1718 BundleManagerShellCommand cmd(argc, argv);
1719
1720 auto ret = cmd.ExecCommand();
1721 EXPECT_NE(ret, "");
1722 }
1723
1724 /**
1725 * @tc.number: BundleManagerShellCommand_0160
1726 * @tc.name: BundleManagerShellCommand
1727 * @tc.desc: Verify the copy-ap.
1728 */
1729 HWTEST_F(BmCommandTest, BundleManagerShellCommand_0160, Function | MediumTest | TestSize.Level1)
1730 {
1731 char *argv[] = {
1732 const_cast<char*>(TOOL_NAME.c_str()),
1733 const_cast<char*>("copy-ap"),
1734 const_cast<char*>("-h"),
1735 const_cast<char*>("test"),
1736 };
1737 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1738
1739 BundleManagerShellCommand cmd(argc, argv);
1740
1741 auto ret = cmd.ExecCommand();
1742 EXPECT_EQ(ret, HELP_MSG_COPY_AP);
1743 }
1744
1745 /**
1746 * @tc.number: BundleManagerShellCommand_0170
1747 * @tc.name: BundleManagerShellCommand
1748 * @tc.desc: Verify the copy-ap.
1749 */
1750 HWTEST_F(BmCommandTest, BundleManagerShellCommand_0170, Function | MediumTest | TestSize.Level1)
1751 {
1752 char *argv[] = {
1753 const_cast<char*>(TOOL_NAME.c_str()),
1754 const_cast<char*>("copy-ap"),
1755 const_cast<char*>("-n"),
1756 const_cast<char*>("test"),
1757 };
1758 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1759
1760 BundleManagerShellCommand cmd(argc, argv);
1761
1762 auto ret = cmd.ExecCommand();
1763 EXPECT_NE(ret, "");
1764 }
1765
1766 /**
1767 * @tc.number: BundleManagerShellCommand_0180
1768 * @tc.name: BundleManagerShellCommand
1769 * @tc.desc: Verify the copy-ap.
1770 */
1771 HWTEST_F(BmCommandTest, BundleManagerShellCommand_0180, Function | MediumTest | TestSize.Level1)
1772 {
1773 char *argv[] = {
1774 const_cast<char*>(TOOL_NAME.c_str()),
1775 const_cast<char*>("copy-ap"),
1776 const_cast<char*>("-b"),
1777 const_cast<char*>("test"),
1778 };
1779 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1780
1781 BundleManagerShellCommand cmd(argc, argv);
1782
1783 auto ret = cmd.ExecCommand();
1784 EXPECT_NE(ret, "");
1785 }
1786
1787 /**
1788 * @tc.number: BundleManagerShellCommand_0190
1789 * @tc.name: BundleManagerShellCommand
1790 * @tc.desc: Verify the copy-ap.
1791 */
1792 HWTEST_F(BmCommandTest, BundleManagerShellCommand_0190, Function | MediumTest | TestSize.Level1)
1793 {
1794 char *argv[] = {
1795 const_cast<char*>(TOOL_NAME.c_str()),
1796 const_cast<char*>("copy-ap"),
1797 const_cast<char*>("-n"),
1798 const_cast<char*>("test"),
1799 };
1800 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1801
1802 BundleManagerShellCommand cmd(argc, argv);
1803
1804 int32_t option = -1;
1805 std::string bundleName = "111";
1806 bool isAllBundle = false;
1807
1808 auto originOption = option;
1809 auto originOptarg = optarg;
1810 option = 'n';
1811 optarg = const_cast<char*>("test");
1812 auto ret = cmd.ParseCopyApCommand(option, bundleName, isAllBundle);
1813 option = originOption;
1814 optarg = originOptarg;
1815 EXPECT_EQ(ret, OHOS::ERR_OK);
1816 }
1817
1818 /**
1819 * @tc.number: BundleManagerShellCommand_0200
1820 * @tc.name: BundleManagerShellCommand
1821 * @tc.desc: Verify the copy-ap.
1822 */
1823 HWTEST_F(BmCommandTest, BundleManagerShellCommand_0200, Function | MediumTest | TestSize.Level1)
1824 {
1825 char *argv[] = {
1826 const_cast<char*>(TOOL_NAME.c_str()),
1827 const_cast<char*>("copy-ap"),
1828 const_cast<char*>("-b"),
1829 const_cast<char*>("test"),
1830 };
1831 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1832
1833 BundleManagerShellCommand cmd(argc, argv);
1834
1835 int32_t option = -1;
1836 std::string bundleName;
1837 bool isAllBundle = false;
1838
1839 auto originOption = option;
1840 option = 'm';
1841 auto ret = cmd.ParseCopyApCommand(option, bundleName, isAllBundle);
1842 option = originOption;
1843 EXPECT_EQ(ret, OHOS::ERR_INVALID_VALUE);
1844 }
1845 } // namespace OHOS