1 /*
2 * Copyright (c) 2021 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 #include "bundle_command.h"
20 #undef private
21 #include "bundle_constants.h"
22 #include "bundle_installer_interface.h"
23 #include "iremote_broker.h"
24 #include "iremote_object.h"
25 #include "mock_bundle_mgr_host.h"
26 #include "mock_bundle_installer_host.h"
27
28 using namespace testing::ext;
29 using namespace OHOS;
30 using namespace OHOS::AAFwk;
31 using namespace OHOS::AppExecFwk;
32
33 class BmCommandInstallTest : public ::testing::Test {
34 public:
35 static void SetUpTestCase();
36 static void TearDownTestCase();
37 void SetUp() override;
38 void TearDown() override;
39
40 void MakeMockObjects();
41 void SetMockObjects(BundleManagerShellCommand &cmd) const;
42
43 std::string cmd_ = "install";
44 sptr<IBundleMgr> mgrProxyPtr_;
45 sptr<IBundleInstaller> installerProxyPtr_;
46 };
47
SetUpTestCase()48 void BmCommandInstallTest::SetUpTestCase()
49 {}
50
TearDownTestCase()51 void BmCommandInstallTest::TearDownTestCase()
52 {}
53
SetUp()54 void BmCommandInstallTest::SetUp()
55 {
56 // reset optind to 0
57 optind = 0;
58
59 // make mock objects
60 MakeMockObjects();
61 }
62
TearDown()63 void BmCommandInstallTest::TearDown()
64 {}
65
MakeMockObjects()66 void BmCommandInstallTest::MakeMockObjects()
67 {
68 // mock a mgr host
69 auto mgrHostPtr = sptr<IRemoteObject>(new MockBundleMgrHost());
70 // mock a mgr proxy
71 mgrProxyPtr_ = iface_cast<IBundleMgr>(mgrHostPtr);
72
73 // mock a installer host
74 auto installerHostPtr = sptr<IRemoteObject>(new MockBundleInstallerHost());
75 // mock a installer proxy
76 installerProxyPtr_ = iface_cast<IBundleInstaller>(installerHostPtr);
77 }
78
SetMockObjects(BundleManagerShellCommand & cmd) const79 void BmCommandInstallTest::SetMockObjects(BundleManagerShellCommand &cmd) const
80 {
81 // set the mock mgr proxy
82 cmd.bundleMgrProxy_ = mgrProxyPtr_;
83
84 // set the mock installer proxy
85 cmd.bundleInstallerProxy_ = installerProxyPtr_;
86 }
87
88 /**
89 * @tc.number: Bm_Command_Install_0100
90 * @tc.name: ExecCommand
91 * @tc.desc: Verify the "bm install" command.
92 */
93 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_0100, Function | MediumTest | Level1)
94 {
95 char *argv[] = {
96 const_cast<char*>(TOOL_NAME.c_str()),
97 const_cast<char*>(cmd_.c_str()),
98 const_cast<char*>(""),
99 };
100 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
101
102 BundleManagerShellCommand cmd(argc, argv);
103
104 // set the mock objects
105 SetMockObjects(cmd);
106
107 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_INSTALL);
108 }
109
110 /**
111 * @tc.number: Bm_Command_Install_0200
112 * @tc.name: ExecCommand
113 * @tc.desc: Verify the "bm install xxx" command.
114 */
115 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_0200, Function | MediumTest | Level1)
116 {
117 char *argv[] = {
118 const_cast<char*>(TOOL_NAME.c_str()),
119 const_cast<char*>(cmd_.c_str()),
120 const_cast<char*>("xxx"),
121 const_cast<char*>(""),
122 };
123 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
124
125 BundleManagerShellCommand cmd(argc, argv);
126
127 // set the mock objects
128 SetMockObjects(cmd);
129
130 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_INSTALL);
131 }
132
133 /**
134 * @tc.number: Bm_Command_Install_0300
135 * @tc.name: ExecCommand
136 * @tc.desc: Verify the "bm install -x" command.
137 */
138 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_0300, Function | MediumTest | Level1)
139 {
140 char *argv[] = {
141 const_cast<char*>(TOOL_NAME.c_str()),
142 const_cast<char*>(cmd_.c_str()),
143 const_cast<char*>("-x"),
144 const_cast<char*>(""),
145 };
146 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
147
148 BundleManagerShellCommand cmd(argc, argv);
149
150 // set the mock objects
151 SetMockObjects(cmd);
152
153 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_INSTALL);
154 }
155
156 /**
157 * @tc.number: Bm_Command_Install_0400
158 * @tc.name: ExecCommand
159 * @tc.desc: Verify the "bm install -xxx" command.
160 */
161 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_0400, Function | MediumTest | Level1)
162 {
163 char *argv[] = {
164 const_cast<char*>(TOOL_NAME.c_str()),
165 const_cast<char*>(cmd_.c_str()),
166 const_cast<char*>("-xxx"),
167 const_cast<char*>(""),
168 };
169 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
170
171 BundleManagerShellCommand cmd(argc, argv);
172
173 // set the mock objects
174 SetMockObjects(cmd);
175
176 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_INSTALL);
177 }
178
179 /**
180 * @tc.number: Bm_Command_Install_0500
181 * @tc.name: ExecCommand
182 * @tc.desc: Verify the "bm install --x" command.
183 */
184 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_0500, Function | MediumTest | Level1)
185 {
186 char *argv[] = {
187 const_cast<char*>(TOOL_NAME.c_str()),
188 const_cast<char*>(cmd_.c_str()),
189 const_cast<char*>("--x"),
190 const_cast<char*>(""),
191 };
192 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
193
194 BundleManagerShellCommand cmd(argc, argv);
195
196 // set the mock objects
197 SetMockObjects(cmd);
198
199 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_INSTALL);
200 }
201
202 /**
203 * @tc.number: Bm_Command_Install_0600
204 * @tc.name: ExecCommand
205 * @tc.desc: Verify the "bm install --xxx" command.
206 */
207 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_0600, Function | MediumTest | Level1)
208 {
209 char *argv[] = {
210 const_cast<char*>(TOOL_NAME.c_str()),
211 const_cast<char*>(cmd_.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 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_INSTALL);
223 }
224
225 /**
226 * @tc.number: Bm_Command_Install_0700
227 * @tc.name: ExecCommand
228 * @tc.desc: Verify the "bm install --h" command.
229 */
230 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_0700, Function | MediumTest | Level1)
231 {
232 char *argv[] = {
233 const_cast<char*>(TOOL_NAME.c_str()),
234 const_cast<char*>(cmd_.c_str()),
235 const_cast<char*>("-h"),
236 const_cast<char*>(""),
237 };
238 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
239
240 BundleManagerShellCommand cmd(argc, argv);
241
242 // set the mock objects
243 SetMockObjects(cmd);
244
245 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_INSTALL);
246 }
247
248 /**
249 * @tc.number: Bm_Command_Install_0800
250 * @tc.name: ExecCommand
251 * @tc.desc: Verify the "bm install --help" command.
252 */
253 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_0800, Function | MediumTest | Level1)
254 {
255 char *argv[] = {
256 const_cast<char*>(TOOL_NAME.c_str()),
257 const_cast<char*>(cmd_.c_str()),
258 const_cast<char*>("--help"),
259 const_cast<char*>(""),
260 };
261 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
262
263 BundleManagerShellCommand cmd(argc, argv);
264
265 // set the mock objects
266 SetMockObjects(cmd);
267
268 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_INSTALL);
269 }
270
271 /**
272 * @tc.number: Bm_Command_Install_0900
273 * @tc.name: ExecCommand
274 * @tc.desc: Verify the "bm install -p" command.
275 */
276 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_0900, Function | MediumTest | Level1)
277 {
278 char *argv[] = {
279 const_cast<char*>(TOOL_NAME.c_str()),
280 const_cast<char*>(cmd_.c_str()),
281 const_cast<char*>("-p"),
282 const_cast<char*>(""),
283 };
284 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
285
286 BundleManagerShellCommand cmd(argc, argv);
287
288 // set the mock objects
289 SetMockObjects(cmd);
290
291 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_INSTALL);
292 }
293
294 /**
295 * @tc.number: Bm_Command_Install_1000
296 * @tc.name: ExecCommand
297 * @tc.desc: Verify the "bm install -r" command.
298 */
299 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_1000, Function | MediumTest | Level1)
300 {
301 char *argv[] = {
302 const_cast<char*>(TOOL_NAME.c_str()),
303 const_cast<char*>(cmd_.c_str()),
304 const_cast<char*>("-r"),
305 const_cast<char*>(""),
306 };
307 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
308
309 BundleManagerShellCommand cmd(argc, argv);
310
311 // set the mock objects
312 SetMockObjects(cmd);
313
314 EXPECT_EQ(
315 cmd.ExecCommand(), "error: you must specify a bundle path with '-p' or '--bundle-path'.\n" + HELP_MSG_INSTALL);
316 }
317
318 /**
319 * @tc.number: Bm_Command_Install_1100
320 * @tc.name: ExecCommand
321 * @tc.desc: Verify the "bm install -p <bundle-path>" command.
322 */
323 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_1100, Function | MediumTest | Level1)
324 {
325 // install a bundle
326 char *argv[] = {
327 const_cast<char*>(TOOL_NAME.c_str()),
328 const_cast<char*>(cmd_.c_str()),
329 const_cast<char*>("-p"),
330 const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
331 const_cast<char*>(""),
332 };
333 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
334
335 BundleManagerShellCommand cmd(argc, argv);
336
337 // set the mock objects
338 SetMockObjects(cmd);
339
340 EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
341 }
342
343 /**
344 * @tc.number: Bm_Command_Install_1200
345 * @tc.name: ExecCommand
346 * @tc.desc: Verify the "bm install -p <bundle-path> -r" command.
347 */
348 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_1200, Function | MediumTest | Level1)
349 {
350 // install a bundle
351 char *argv[] = {
352 const_cast<char*>(TOOL_NAME.c_str()),
353 const_cast<char*>(cmd_.c_str()),
354 const_cast<char*>("-p"),
355 const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
356 const_cast<char*>("-r"),
357 const_cast<char*>(""),
358 };
359 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
360
361 BundleManagerShellCommand cmd(argc, argv);
362
363 // set the mock objects
364 SetMockObjects(cmd);
365
366 EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
367 }
368
369 /**
370 * @tc.number: Bm_Command_Install_1300
371 * @tc.name: ExecCommand
372 * @tc.desc: Verify the "bm install -r -p <bundle-path>" command.
373 */
374 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_1300, Function | MediumTest | Level1)
375 {
376 // install a bundle
377 char *argv[] = {
378 const_cast<char*>(TOOL_NAME.c_str()),
379 const_cast<char*>(cmd_.c_str()),
380 const_cast<char*>("-r"),
381 const_cast<char*>("-p"),
382 const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
383 const_cast<char*>(""),
384 };
385 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
386
387 BundleManagerShellCommand cmd(argc, argv);
388
389 // set the mock objects
390 SetMockObjects(cmd);
391
392 EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
393 }
394
395 /**
396 * @tc.number: Bm_Command_Install_1600
397 * @tc.name: ExecCommand
398 * @tc.desc: Verify the "bm install -p <bundle-path> <bundle-path>" command.
399 * @tc.require: AR000GJ4K9
400 */
401 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_1600, Function | MediumTest | Level1)
402 {
403 // install a bundle
404 char *argv[] = {
405 const_cast<char*>(TOOL_NAME.c_str()),
406 const_cast<char*>(cmd_.c_str()),
407 const_cast<char*>("-p"),
408 const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
409 const_cast<char*>(STRING_OTHER_BUNDLE_PATH.c_str()),
410 const_cast<char*>(""),
411 };
412 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
413
414 BundleManagerShellCommand cmd(argc, argv);
415
416 // set the mock objects
417 SetMockObjects(cmd);
418
419 EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
420 }
421
422 /**
423 * @tc.number: Bm_Command_Install_1700
424 * @tc.name: ExecCommand
425 * @tc.desc: Verify the "bm install -p <bundle-path>" command.
426 * @tc.require: AR000GJ4K9
427 */
428 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_1700, Function | MediumTest | Level1)
429 {
430 // install a bundle
431 char *argv[] = {
432 const_cast<char*>(TOOL_NAME.c_str()),
433 const_cast<char*>(cmd_.c_str()),
434 const_cast<char*>("-p"),
435 const_cast<char*>(STRING_BUNDLE_INSTALL_PATH1.c_str()),
436 const_cast<char*>(STRING_BUNDLE_INSTALL_PATH2.c_str()),
437 const_cast<char*>(""),
438 };
439 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
440
441 BundleManagerShellCommand cmd(argc, argv);
442
443 // set the mock objects
444 SetMockObjects(cmd);
445
446 EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
447 }
448
449 /**
450 * @tc.number: Bm_Command_Install_1800
451 * @tc.name: ExecCommand
452 * @tc.desc: Verify the "bm install -p <bundle-path>" command.
453 * @tc.require: AR000GJ4K9
454 */
455 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_1800, Function | MediumTest | Level1)
456 {
457 // install a bundle
458 char *argv[] = {
459 const_cast<char*>(TOOL_NAME.c_str()),
460 const_cast<char*>(cmd_.c_str()),
461 const_cast<char*>("-p"),
462 const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
463 const_cast<char*>(STRING_BUNDLE_INSTALL_PATH2.c_str()),
464 const_cast<char*>(""),
465 };
466 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
467
468 BundleManagerShellCommand cmd(argc, argv);
469
470 // set the mock objects
471 SetMockObjects(cmd);
472
473 EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
474 }
475
476 /**
477 * @tc.number: Bm_Command_Install_1900
478 * @tc.name: ExecCommand
479 * @tc.desc: Verify the "bm install --bundle-path <bundle-path> <bundle-path>" command.
480 * @tc.require: AR000GJ4K9
481 */
482 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_1900, Function | MediumTest | Level1)
483 {
484 // install a bundle
485 char *argv[] = {
486 const_cast<char*>(TOOL_NAME.c_str()),
487 const_cast<char*>(cmd_.c_str()),
488 const_cast<char*>("--bundle-path"),
489 const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
490 const_cast<char*>(STRING_OTHER_BUNDLE_PATH.c_str()),
491 const_cast<char*>(""),
492 };
493 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
494
495 BundleManagerShellCommand cmd(argc, argv);
496
497 // set the mock objects
498 SetMockObjects(cmd);
499
500 EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
501 }
502
503 /**
504 * @tc.number: Bm_Command_Install_2000
505 * @tc.name: ExecCommand
506 * @tc.desc: Verify the "bm install -p <bundle-path>" command.
507 * @tc.require: AR000GJ4K9
508 */
509 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_2000, Function | MediumTest | Level1)
510 {
511 // install a bundle
512 char *argv[] = {
513 const_cast<char*>(TOOL_NAME.c_str()),
514 const_cast<char*>(cmd_.c_str()),
515 const_cast<char*>("--bundle-path"),
516 const_cast<char*>(STRING_BUNDLE_INSTALL_PATH1.c_str()),
517 const_cast<char*>(STRING_BUNDLE_INSTALL_PATH2.c_str()),
518 const_cast<char*>(""),
519 };
520 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
521
522 BundleManagerShellCommand cmd(argc, argv);
523
524 // set the mock objects
525 SetMockObjects(cmd);
526
527 EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
528 }
529
530 /**
531 * @tc.number: Bm_Command_Install_2100
532 * @tc.name: ExecCommand
533 * @tc.desc: Verify the "bm install -p <bundle-path>" command.
534 * @tc.require: AR000GJ4K9
535 */
536 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_2100, Function | MediumTest | Level1)
537 {
538 // install a bundle
539 char *argv[] = {
540 const_cast<char*>(TOOL_NAME.c_str()),
541 const_cast<char*>(cmd_.c_str()),
542 const_cast<char*>("--bundle-path"),
543 const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
544 const_cast<char*>(STRING_BUNDLE_INSTALL_PATH2.c_str()),
545 const_cast<char*>(""),
546 };
547 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
548
549 BundleManagerShellCommand cmd(argc, argv);
550
551 // set the mock objects
552 SetMockObjects(cmd);
553
554 EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
555 }
556
557 /**
558 * @tc.number: Bm_Command_Install_2300
559 * @tc.name: ExecCommand
560 * @tc.desc: Verify the "bm install -p <bundle-path> <bundle-path> -r" command.
561 * @tc.require: AR000GJ4K9
562 */
563 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_2300, Function | MediumTest | Level1)
564 {
565 // install a bundle
566 char *argv[] = {
567 const_cast<char*>(TOOL_NAME.c_str()),
568 const_cast<char*>(cmd_.c_str()),
569 const_cast<char*>("-p"),
570 const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
571 const_cast<char*>(STRING_OTHER_BUNDLE_PATH.c_str()),
572 const_cast<char*>("-r"),
573 const_cast<char*>(""),
574 };
575 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
576
577 BundleManagerShellCommand cmd(argc, argv);
578
579 // set the mock objects
580 SetMockObjects(cmd);
581
582 EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
583 }
584
585 /**
586 * @tc.number: Bm_Command_Install_2400
587 * @tc.name: ExecCommand
588 * @tc.desc: Verify the "bm install -r -p <bundle-path> <bundle-path>" command.
589 * @tc.require: AR000GJ4K9
590 */
591 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_2400, Function | MediumTest | Level1)
592 {
593 // install a bundle
594 char *argv[] = {
595 const_cast<char*>(TOOL_NAME.c_str()),
596 const_cast<char*>(cmd_.c_str()),
597 const_cast<char*>("-r"),
598 const_cast<char*>("-p"),
599 const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
600 const_cast<char*>(STRING_OTHER_BUNDLE_PATH.c_str()),
601 const_cast<char*>(""),
602 };
603 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
604
605 BundleManagerShellCommand cmd(argc, argv);
606
607 // set the mock objects
608 SetMockObjects(cmd);
609
610 EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
611 }
612
613 /**
614 * @tc.number: Bm_Command_Install_2600
615 * @tc.name: ExecCommand
616 * @tc.desc: Verify the "bm install -p -r <bundle-path> <bundle-path>" command.
617 * @tc.require: AR000GJ4K9
618 */
619 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_2600, Function | MediumTest | Level1)
620 {
621 // install a bundle
622 char *argv[] = {
623 const_cast<char*>(TOOL_NAME.c_str()),
624 const_cast<char*>(cmd_.c_str()),
625 const_cast<char*>("-p"),
626 const_cast<char*>("-r"),
627 const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
628 const_cast<char*>(STRING_OTHER_BUNDLE_PATH.c_str()),
629 const_cast<char*>(""),
630 };
631 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
632
633 BundleManagerShellCommand cmd(argc, argv);
634
635 // set the mock objects
636 SetMockObjects(cmd);
637
638 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE);
639 }
640
641 /**
642 * @tc.number: Bm_Command_Install_2700
643 * @tc.name: ExecCommand
644 * @tc.desc: Verify the "bm install -p <bundle-path> <bundle-path> -u xxx" command.
645 * @tc.require: AR000GJ4K9
646 */
647 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_2700, Function | MediumTest | Level1)
648 {
649 // install a bundle
650 char *argv[] = {
651 const_cast<char*>(TOOL_NAME.c_str()),
652 const_cast<char*>(cmd_.c_str()),
653 const_cast<char*>("-p"),
654 const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
655 const_cast<char*>(STRING_OTHER_BUNDLE_PATH.c_str()),
656 const_cast<char*>("-u"),
657 const_cast<char*>("xxx"),
658 const_cast<char*>(""),
659 };
660 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
661
662 BundleManagerShellCommand cmd(argc, argv);
663
664 // set the mock objects
665 SetMockObjects(cmd);
666
667 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE);
668 }
669
670 /**
671 * @tc.number: Bm_Command_Install_2800
672 * @tc.name: ExecCommand
673 * @tc.desc: Verify the "bm install -p <bundle-path> <bundle-path> -u" command.
674 * @tc.require: AR000GJ4K9
675 */
676 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_2800, Function | MediumTest | Level1)
677 {
678 // install a bundle
679 char *argv[] = {
680 const_cast<char*>(TOOL_NAME.c_str()),
681 const_cast<char*>(cmd_.c_str()),
682 const_cast<char*>("-p"),
683 const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
684 const_cast<char*>(STRING_OTHER_BUNDLE_PATH.c_str()),
685 const_cast<char*>("-u"),
686 const_cast<char*>(""),
687 };
688 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
689
690 BundleManagerShellCommand cmd(argc, argv);
691
692 // set the mock objects
693 SetMockObjects(cmd);
694
695 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_INSTALL);
696 }
697
698 /**
699 * @tc.number: Bm_Command_Install_2900
700 * @tc.name: ExecCommand
701 * @tc.desc: Verify the "bm install -p <bundle-path> <bundle-path> -u" command.
702 * @tc.require: AR000GJ4K9
703 */
704 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_2900, Function | MediumTest | Level1)
705 {
706 // install a bundle
707 char *argv[] = {
708 const_cast<char*>(TOOL_NAME.c_str()),
709 const_cast<char*>(cmd_.c_str()),
710 const_cast<char*>("-p"),
711 const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
712 const_cast<char*>(STRING_OTHER_BUNDLE_PATH.c_str()),
713 const_cast<char*>("-u"),
714 const_cast<char*>(DEFAULT_USER_ID.c_str()),
715 const_cast<char*>(""),
716 };
717 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
718
719 BundleManagerShellCommand cmd(argc, argv);
720
721 // set the mock objects
722 SetMockObjects(cmd);
723
724 EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
725 }
726
727 /**
728 * @tc.number: Bm_Command_Install_3000
729 * @tc.name: ExecCommand
730 * @tc.desc: Verify the "bm install -p <bundle-path> -w" command.
731 */
732 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_3000, Function | MediumTest | Level1)
733 {
734 // install a bundle
735 char *argv[] = {
736 const_cast<char*>(TOOL_NAME.c_str()),
737 const_cast<char*>(cmd_.c_str()),
738 const_cast<char*>("-p"),
739 const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
740 const_cast<char*>("-w"),
741 const_cast<char*>(""),
742 };
743 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
744
745 BundleManagerShellCommand cmd(argc, argv);
746
747 // set the mock objects
748 SetMockObjects(cmd);
749
750 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_INSTALL);
751 }
752
753 /**
754 * @tc.number: Bm_Command_Install_3100
755 * @tc.name: ExecCommand
756 * @tc.desc: Verify the "bm install -p <bundle-path> -w <waitting-time>" command.
757 */
758 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_3100, Function | MediumTest | Level1)
759 {
760 // install a bundle
761 char *argv[] = {
762 const_cast<char*>(TOOL_NAME.c_str()),
763 const_cast<char*>(cmd_.c_str()),
764 const_cast<char*>("-p"),
765 const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
766 const_cast<char*>("-w"),
767 const_cast<char*>(DEFAULT_WAIT_TIME.c_str()),
768 const_cast<char*>(""),
769 };
770 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
771
772 BundleManagerShellCommand cmd(argc, argv);
773
774 // set the mock objects
775 SetMockObjects(cmd);
776
777 EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
778 }
779
780 /**
781 * @tc.number: Bm_Command_Install_3200
782 * @tc.name: ExecCommand
783 * @tc.desc: Verify the "bm install -p <bundle-path> -XXX <user-id>" command.
784 */
785 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_3200, Function | MediumTest | Level1)
786 {
787 // install a bundle
788 char *argv[] = {
789 const_cast<char*>(TOOL_NAME.c_str()),
790 const_cast<char*>(cmd_.c_str()),
791 const_cast<char*>("-p"),
792 const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
793 const_cast<char*>(STRING_OTHER_BUNDLE_PATH.c_str()),
794 const_cast<char*>("-XXX"),
795 const_cast<char*>(DEFAULT_USER_ID.c_str()),
796 const_cast<char*>(""),
797 };
798 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
799
800 BundleManagerShellCommand cmd(argc, argv);
801
802 // set the mock objects
803 SetMockObjects(cmd);
804
805 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_INSTALL);
806 }
807
808 /**
809 * @tc.number: Bm_Command_Install_3300
810 * @tc.name: ExecCommand
811 * @tc.desc: Verify the "bm install -p <bundle-path> -w <waitting-time>" command.
812 */
813 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_3300, Function | MediumTest | Level1)
814 {
815 // install a bundle
816 char *argv[] = {
817 const_cast<char*>(TOOL_NAME.c_str()),
818 const_cast<char*>(cmd_.c_str()),
819 const_cast<char*>("-p"),
820 const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
821 const_cast<char*>("-w"),
822 const_cast<char*>(MINIMUMT_WAIT_TIME.c_str()),
823 const_cast<char*>(""),
824 };
825 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
826
827 BundleManagerShellCommand cmd(argc, argv);
828
829 // set the mock objects
830 SetMockObjects(cmd);
831
832 EXPECT_EQ(cmd.ExecCommand(), "error: option requires a correct value.\n");
833 }
834
835 /**
836 * @tc.number: Bm_Command_Install_3400
837 * @tc.name: ExecCommand
838 * @tc.desc: Verify the "bm install -p <bundle-path> -w <waitting-time>" command.
839 */
840 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_3400, Function | MediumTest | Level1)
841 {
842 // install a bundle
843 char *argv[] = {
844 const_cast<char*>(TOOL_NAME.c_str()),
845 const_cast<char*>(cmd_.c_str()),
846 const_cast<char*>("-p"),
847 const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
848 const_cast<char*>("-w"),
849 const_cast<char*>(MAXIMUM_WAIT_TIME.c_str()),
850 const_cast<char*>(""),
851 };
852 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
853
854 BundleManagerShellCommand cmd(argc, argv);
855
856 // set the mock objects
857 SetMockObjects(cmd);
858
859 EXPECT_EQ(cmd.ExecCommand(), "error: option requires a correct value.\n");
860 }
861
862 /**
863 * @tc.number: Bm_Command_Install_3500
864 * @tc.name: ExecCommand
865 * @tc.desc: Verify the "bm install" command.
866 */
867 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_3500, Function | MediumTest | Level1)
868 {
869 char *argv[] = {
870 const_cast<char*>(TOOL_NAME.c_str()),
871 const_cast<char*>(cmd_.c_str()),
872 const_cast<char*>("-cc"),
873 const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
874 const_cast<char*>(""),
875 };
876 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
877
878 BundleManagerShellCommand cmd(argc, argv);
879
880 // set the mock objects
881 SetMockObjects(cmd);
882
883 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_INSTALL);
884 }