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 namespace OHOS {
34 class BmCommandInstallTest : public ::testing::Test {
35 public:
36     static void SetUpTestCase();
37     static void TearDownTestCase();
38     void SetUp() override;
39     void TearDown() override;
40 
41     void MakeMockObjects();
42     void SetMockObjects(BundleManagerShellCommand &cmd) const;
43 
44     std::string cmd_ = "install";
45     sptr<IBundleMgr> mgrProxyPtr_;
46     sptr<IBundleInstaller> installerProxyPtr_;
47 };
48 
SetUpTestCase()49 void BmCommandInstallTest::SetUpTestCase()
50 {}
51 
TearDownTestCase()52 void BmCommandInstallTest::TearDownTestCase()
53 {}
54 
SetUp()55 void BmCommandInstallTest::SetUp()
56 {
57     // reset optind to 0
58     optind = 0;
59 
60     // make mock objects
61     MakeMockObjects();
62 }
63 
TearDown()64 void BmCommandInstallTest::TearDown()
65 {}
66 
MakeMockObjects()67 void BmCommandInstallTest::MakeMockObjects()
68 {
69     // mock a mgr host
70     auto mgrHostPtr = sptr<IRemoteObject>(new (std::nothrow) MockBundleMgrHost());
71     // mock a mgr proxy
72     mgrProxyPtr_ = iface_cast<IBundleMgr>(mgrHostPtr);
73 
74     // mock a installer host
75     auto installerHostPtr = sptr<IRemoteObject>(new (std::nothrow) MockBundleInstallerHost());
76     // mock a installer proxy
77     installerProxyPtr_ = iface_cast<IBundleInstaller>(installerHostPtr);
78 }
79 
SetMockObjects(BundleManagerShellCommand & cmd) const80 void BmCommandInstallTest::SetMockObjects(BundleManagerShellCommand &cmd) const
81 {
82     // set the mock mgr proxy
83     cmd.bundleMgrProxy_ = mgrProxyPtr_;
84 
85     // set the mock installer proxy
86     cmd.bundleInstallerProxy_ = installerProxyPtr_;
87 }
88 
89 /**
90  * @tc.number: Bm_Command_Install_0100
91  * @tc.name: ExecCommand
92  * @tc.desc: Verify the "bm install" command.
93  */
94 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_0100, Function | MediumTest | Level1)
95 {
96     char *argv[] = {
97         const_cast<char*>(TOOL_NAME.c_str()),
98         const_cast<char*>(cmd_.c_str()),
99         const_cast<char*>(""),
100     };
101     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
102 
103     BundleManagerShellCommand cmd(argc, argv);
104 
105     // set the mock objects
106     SetMockObjects(cmd);
107 
108     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_INSTALL);
109 }
110 
111 /**
112  * @tc.number: Bm_Command_Install_0200
113  * @tc.name: ExecCommand
114  * @tc.desc: Verify the "bm install xxx" command.
115  */
116 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_0200, Function | MediumTest | Level1)
117 {
118     char *argv[] = {
119         const_cast<char*>(TOOL_NAME.c_str()),
120         const_cast<char*>(cmd_.c_str()),
121         const_cast<char*>("xxx"),
122         const_cast<char*>(""),
123     };
124     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
125 
126     BundleManagerShellCommand cmd(argc, argv);
127 
128     // set the mock objects
129     SetMockObjects(cmd);
130 
131     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_INSTALL);
132 }
133 
134 /**
135  * @tc.number: Bm_Command_Install_0300
136  * @tc.name: ExecCommand
137  * @tc.desc: Verify the "bm install -x" command.
138  */
139 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_0300, Function | MediumTest | Level1)
140 {
141     char *argv[] = {
142         const_cast<char*>(TOOL_NAME.c_str()),
143         const_cast<char*>(cmd_.c_str()),
144         const_cast<char*>("-x"),
145         const_cast<char*>(""),
146     };
147     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
148 
149     BundleManagerShellCommand cmd(argc, argv);
150 
151     // set the mock objects
152     SetMockObjects(cmd);
153 
154     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_INSTALL);
155 }
156 
157 /**
158  * @tc.number: Bm_Command_Install_0400
159  * @tc.name: ExecCommand
160  * @tc.desc: Verify the "bm install -xxx" command.
161  */
162 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_0400, Function | MediumTest | Level1)
163 {
164     char *argv[] = {
165         const_cast<char*>(TOOL_NAME.c_str()),
166         const_cast<char*>(cmd_.c_str()),
167         const_cast<char*>("-xxx"),
168         const_cast<char*>(""),
169     };
170     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
171 
172     BundleManagerShellCommand cmd(argc, argv);
173 
174     // set the mock objects
175     SetMockObjects(cmd);
176 
177     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_INSTALL);
178 }
179 
180 /**
181  * @tc.number: Bm_Command_Install_0500
182  * @tc.name: ExecCommand
183  * @tc.desc: Verify the "bm install --x" command.
184  */
185 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_0500, Function | MediumTest | Level1)
186 {
187     char *argv[] = {
188         const_cast<char*>(TOOL_NAME.c_str()),
189         const_cast<char*>(cmd_.c_str()),
190         const_cast<char*>("--x"),
191         const_cast<char*>(""),
192     };
193     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
194 
195     BundleManagerShellCommand cmd(argc, argv);
196 
197     // set the mock objects
198     SetMockObjects(cmd);
199 
200     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_INSTALL);
201 }
202 
203 /**
204  * @tc.number: Bm_Command_Install_0600
205  * @tc.name: ExecCommand
206  * @tc.desc: Verify the "bm install --xxx" command.
207  */
208 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_0600, Function | MediumTest | Level1)
209 {
210     char *argv[] = {
211         const_cast<char*>(TOOL_NAME.c_str()),
212         const_cast<char*>(cmd_.c_str()),
213         const_cast<char*>("--xxx"),
214         const_cast<char*>(""),
215     };
216     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
217 
218     BundleManagerShellCommand cmd(argc, argv);
219 
220     // set the mock objects
221     SetMockObjects(cmd);
222 
223     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_INSTALL);
224 }
225 
226 /**
227  * @tc.number: Bm_Command_Install_0700
228  * @tc.name: ExecCommand
229  * @tc.desc: Verify the "bm install --h" command.
230  */
231 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_0700, Function | MediumTest | Level1)
232 {
233     char *argv[] = {
234         const_cast<char*>(TOOL_NAME.c_str()),
235         const_cast<char*>(cmd_.c_str()),
236         const_cast<char*>("-h"),
237         const_cast<char*>(""),
238     };
239     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
240 
241     BundleManagerShellCommand cmd(argc, argv);
242 
243     // set the mock objects
244     SetMockObjects(cmd);
245 
246     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_INSTALL);
247 }
248 
249 /**
250  * @tc.number: Bm_Command_Install_0800
251  * @tc.name: ExecCommand
252  * @tc.desc: Verify the "bm install --help" command.
253  */
254 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_0800, Function | MediumTest | Level1)
255 {
256     char *argv[] = {
257         const_cast<char*>(TOOL_NAME.c_str()),
258         const_cast<char*>(cmd_.c_str()),
259         const_cast<char*>("--help"),
260         const_cast<char*>(""),
261     };
262     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
263 
264     BundleManagerShellCommand cmd(argc, argv);
265 
266     // set the mock objects
267     SetMockObjects(cmd);
268 
269     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_INSTALL);
270 }
271 
272 /**
273  * @tc.number: Bm_Command_Install_0900
274  * @tc.name: ExecCommand
275  * @tc.desc: Verify the "bm install -p" command.
276  */
277 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_0900, Function | MediumTest | Level1)
278 {
279     char *argv[] = {
280         const_cast<char*>(TOOL_NAME.c_str()),
281         const_cast<char*>(cmd_.c_str()),
282         const_cast<char*>("-p"),
283         const_cast<char*>(""),
284     };
285     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
286 
287     BundleManagerShellCommand cmd(argc, argv);
288 
289     // set the mock objects
290     SetMockObjects(cmd);
291 
292     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_INSTALL);
293 }
294 
295 /**
296  * @tc.number: Bm_Command_Install_1000
297  * @tc.name: ExecCommand
298  * @tc.desc: Verify the "bm install -r" command.
299  */
300 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_1000, Function | MediumTest | Level1)
301 {
302     char *argv[] = {
303         const_cast<char*>(TOOL_NAME.c_str()),
304         const_cast<char*>(cmd_.c_str()),
305         const_cast<char*>("-r"),
306         const_cast<char*>(""),
307     };
308     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
309 
310     BundleManagerShellCommand cmd(argc, argv);
311 
312     // set the mock objects
313     SetMockObjects(cmd);
314 
315     EXPECT_EQ(
316         cmd.ExecCommand(), "error: you must specify a bundle path with '-p' or '--bundle-path'.\n" + HELP_MSG_INSTALL);
317 }
318 
319 /**
320  * @tc.number: Bm_Command_Install_1100
321  * @tc.name: ExecCommand
322  * @tc.desc: Verify the "bm install -p <bundle-path>" command.
323  */
324 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_1100, Function | MediumTest | Level1)
325 {
326     // install a bundle
327     char *argv[] = {
328         const_cast<char*>(TOOL_NAME.c_str()),
329         const_cast<char*>(cmd_.c_str()),
330         const_cast<char*>("-p"),
331         const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
332         const_cast<char*>(""),
333     };
334     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
335 
336     BundleManagerShellCommand cmd(argc, argv);
337 
338     // set the mock objects
339     SetMockObjects(cmd);
340 
341     EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
342 }
343 
344 /**
345  * @tc.number: Bm_Command_Install_1200
346  * @tc.name: ExecCommand
347  * @tc.desc: Verify the "bm install -p <bundle-path> -r" command.
348  */
349 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_1200, Function | MediumTest | Level1)
350 {
351     // install a bundle
352     char *argv[] = {
353         const_cast<char*>(TOOL_NAME.c_str()),
354         const_cast<char*>(cmd_.c_str()),
355         const_cast<char*>("-p"),
356         const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
357         const_cast<char*>("-r"),
358         const_cast<char*>(""),
359     };
360     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
361 
362     BundleManagerShellCommand cmd(argc, argv);
363 
364     // set the mock objects
365     SetMockObjects(cmd);
366 
367     EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
368 }
369 
370 /**
371  * @tc.number: Bm_Command_Install_1300
372  * @tc.name: ExecCommand
373  * @tc.desc: Verify the "bm install -r -p <bundle-path>" command.
374  */
375 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_1300, Function | MediumTest | Level1)
376 {
377     // install a bundle
378     char *argv[] = {
379         const_cast<char*>(TOOL_NAME.c_str()),
380         const_cast<char*>(cmd_.c_str()),
381         const_cast<char*>("-r"),
382         const_cast<char*>("-p"),
383         const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
384         const_cast<char*>(""),
385     };
386     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
387 
388     BundleManagerShellCommand cmd(argc, argv);
389 
390     // set the mock objects
391     SetMockObjects(cmd);
392 
393     EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
394 }
395 
396 /**
397  * @tc.number: Bm_Command_Install_1600
398  * @tc.name: ExecCommand
399  * @tc.desc: Verify the "bm install -p <bundle-path> <bundle-path>" command.
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  */
427 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_1700, Function | MediumTest | Level1)
428 {
429     // install a bundle
430     char *argv[] = {
431         const_cast<char*>(TOOL_NAME.c_str()),
432         const_cast<char*>(cmd_.c_str()),
433         const_cast<char*>("-p"),
434         const_cast<char*>(STRING_BUNDLE_INSTALL_PATH1.c_str()),
435         const_cast<char*>(STRING_BUNDLE_INSTALL_PATH2.c_str()),
436         const_cast<char*>(""),
437     };
438     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
439 
440     BundleManagerShellCommand cmd(argc, argv);
441 
442     // set the mock objects
443     SetMockObjects(cmd);
444 
445     EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
446 }
447 
448 /**
449  * @tc.number: Bm_Command_Install_1800
450  * @tc.name: ExecCommand
451  * @tc.desc: Verify the "bm install -p <bundle-path>" command.
452  */
453 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_1800, Function | MediumTest | Level1)
454 {
455     // install a bundle
456     char *argv[] = {
457         const_cast<char*>(TOOL_NAME.c_str()),
458         const_cast<char*>(cmd_.c_str()),
459         const_cast<char*>("-p"),
460         const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
461         const_cast<char*>(STRING_BUNDLE_INSTALL_PATH2.c_str()),
462         const_cast<char*>(""),
463     };
464     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
465 
466     BundleManagerShellCommand cmd(argc, argv);
467 
468     // set the mock objects
469     SetMockObjects(cmd);
470 
471     EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
472 }
473 
474 /**
475  * @tc.number: Bm_Command_Install_1900
476  * @tc.name: ExecCommand
477  * @tc.desc: Verify the "bm install --bundle-path <bundle-path> <bundle-path>" command.
478  */
479 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_1900, Function | MediumTest | Level1)
480 {
481     // install a bundle
482     char *argv[] = {
483         const_cast<char*>(TOOL_NAME.c_str()),
484         const_cast<char*>(cmd_.c_str()),
485         const_cast<char*>("--bundle-path"),
486         const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
487         const_cast<char*>(STRING_OTHER_BUNDLE_PATH.c_str()),
488         const_cast<char*>(""),
489     };
490     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
491 
492     BundleManagerShellCommand cmd(argc, argv);
493 
494     // set the mock objects
495     SetMockObjects(cmd);
496 
497     EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
498 }
499 
500 /**
501  * @tc.number: Bm_Command_Install_2000
502  * @tc.name: ExecCommand
503  * @tc.desc: Verify the "bm install -p <bundle-path>" command.
504  */
505 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_2000, Function | MediumTest | Level1)
506 {
507     // install a bundle
508     char *argv[] = {
509         const_cast<char*>(TOOL_NAME.c_str()),
510         const_cast<char*>(cmd_.c_str()),
511         const_cast<char*>("--bundle-path"),
512         const_cast<char*>(STRING_BUNDLE_INSTALL_PATH1.c_str()),
513         const_cast<char*>(STRING_BUNDLE_INSTALL_PATH2.c_str()),
514         const_cast<char*>(""),
515     };
516     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
517 
518     BundleManagerShellCommand cmd(argc, argv);
519 
520     // set the mock objects
521     SetMockObjects(cmd);
522 
523     EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
524 }
525 
526 /**
527  * @tc.number: Bm_Command_Install_2100
528  * @tc.name: ExecCommand
529  * @tc.desc: Verify the "bm install -p <bundle-path>" command.
530  */
531 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_2100, Function | MediumTest | Level1)
532 {
533     // install a bundle
534     char *argv[] = {
535         const_cast<char*>(TOOL_NAME.c_str()),
536         const_cast<char*>(cmd_.c_str()),
537         const_cast<char*>("--bundle-path"),
538         const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
539         const_cast<char*>(STRING_BUNDLE_INSTALL_PATH2.c_str()),
540         const_cast<char*>(""),
541     };
542     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
543 
544     BundleManagerShellCommand cmd(argc, argv);
545 
546     // set the mock objects
547     SetMockObjects(cmd);
548 
549     EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
550 }
551 
552 /**
553  * @tc.number: Bm_Command_Install_2300
554  * @tc.name: ExecCommand
555  * @tc.desc: Verify the "bm install -p <bundle-path> <bundle-path> -r" command.
556  */
557 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_2300, Function | MediumTest | Level1)
558 {
559     // install a bundle
560     char *argv[] = {
561         const_cast<char*>(TOOL_NAME.c_str()),
562         const_cast<char*>(cmd_.c_str()),
563         const_cast<char*>("-p"),
564         const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
565         const_cast<char*>(STRING_OTHER_BUNDLE_PATH.c_str()),
566         const_cast<char*>("-r"),
567         const_cast<char*>(""),
568     };
569     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
570 
571     BundleManagerShellCommand cmd(argc, argv);
572 
573     // set the mock objects
574     SetMockObjects(cmd);
575 
576     EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
577 }
578 
579 /**
580  * @tc.number: Bm_Command_Install_2400
581  * @tc.name: ExecCommand
582  * @tc.desc: Verify the "bm install -r -p <bundle-path> <bundle-path>" command.
583  */
584 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_2400, Function | MediumTest | Level1)
585 {
586     // install a bundle
587     char *argv[] = {
588         const_cast<char*>(TOOL_NAME.c_str()),
589         const_cast<char*>(cmd_.c_str()),
590         const_cast<char*>("-r"),
591         const_cast<char*>("-p"),
592         const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
593         const_cast<char*>(STRING_OTHER_BUNDLE_PATH.c_str()),
594         const_cast<char*>(""),
595     };
596     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
597 
598     BundleManagerShellCommand cmd(argc, argv);
599 
600     // set the mock objects
601     SetMockObjects(cmd);
602 
603     EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
604 }
605 
606 /**
607  * @tc.number: Bm_Command_Install_2600
608  * @tc.name: ExecCommand
609  * @tc.desc: Verify the "bm install -p -r <bundle-path> <bundle-path>" command.
610  */
611 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_2600, Function | MediumTest | Level1)
612 {
613     // install a bundle
614     char *argv[] = {
615         const_cast<char*>(TOOL_NAME.c_str()),
616         const_cast<char*>(cmd_.c_str()),
617         const_cast<char*>("-p"),
618         const_cast<char*>("-r"),
619         const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
620         const_cast<char*>(STRING_OTHER_BUNDLE_PATH.c_str()),
621         const_cast<char*>(""),
622     };
623     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
624 
625     BundleManagerShellCommand cmd(argc, argv);
626 
627     // set the mock objects
628     SetMockObjects(cmd);
629 
630     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE);
631 }
632 
633 /**
634  * @tc.number: Bm_Command_Install_2700
635  * @tc.name: ExecCommand
636  * @tc.desc: Verify the "bm install -p <bundle-path> <bundle-path> -u xxx" command.
637  */
638 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_2700, Function | MediumTest | Level1)
639 {
640     // install a bundle
641     char *argv[] = {
642         const_cast<char*>(TOOL_NAME.c_str()),
643         const_cast<char*>(cmd_.c_str()),
644         const_cast<char*>("-p"),
645         const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
646         const_cast<char*>(STRING_OTHER_BUNDLE_PATH.c_str()),
647         const_cast<char*>("-u"),
648         const_cast<char*>("xxx"),
649         const_cast<char*>(""),
650     };
651     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
652 
653     BundleManagerShellCommand cmd(argc, argv);
654 
655     // set the mock objects
656     SetMockObjects(cmd);
657 
658     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE);
659 }
660 
661 /**
662  * @tc.number: Bm_Command_Install_2800
663  * @tc.name: ExecCommand
664  * @tc.desc: Verify the "bm install -p <bundle-path> <bundle-path> -u" command.
665  */
666 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_2800, Function | MediumTest | Level1)
667 {
668     // install a bundle
669     char *argv[] = {
670         const_cast<char*>(TOOL_NAME.c_str()),
671         const_cast<char*>(cmd_.c_str()),
672         const_cast<char*>("-p"),
673         const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
674         const_cast<char*>(STRING_OTHER_BUNDLE_PATH.c_str()),
675         const_cast<char*>("-u"),
676         const_cast<char*>(""),
677     };
678     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
679 
680     BundleManagerShellCommand cmd(argc, argv);
681 
682     // set the mock objects
683     SetMockObjects(cmd);
684 
685     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_INSTALL);
686 }
687 
688 /**
689  * @tc.number: Bm_Command_Install_3000
690  * @tc.name: ExecCommand
691  * @tc.desc: Verify the "bm install -p <bundle-path> -w" command.
692  */
693 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_3000, Function | MediumTest | Level1)
694 {
695     // install a bundle
696     char *argv[] = {
697         const_cast<char*>(TOOL_NAME.c_str()),
698         const_cast<char*>(cmd_.c_str()),
699         const_cast<char*>("-p"),
700         const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
701         const_cast<char*>("-w"),
702         const_cast<char*>(""),
703     };
704     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
705 
706     BundleManagerShellCommand cmd(argc, argv);
707 
708     // set the mock objects
709     SetMockObjects(cmd);
710 
711     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_INSTALL);
712 }
713 
714 /**
715  * @tc.number: Bm_Command_Install_3100
716  * @tc.name: ExecCommand
717  * @tc.desc: Verify the "bm install -p <bundle-path> -w <waitting-time>" command.
718  */
719 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_3100, Function | MediumTest | Level1)
720 {
721     // install a bundle
722     char *argv[] = {
723         const_cast<char*>(TOOL_NAME.c_str()),
724         const_cast<char*>(cmd_.c_str()),
725         const_cast<char*>("-p"),
726         const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
727         const_cast<char*>("-w"),
728         const_cast<char*>(DEFAULT_WAIT_TIME.c_str()),
729         const_cast<char*>(""),
730     };
731     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
732 
733     BundleManagerShellCommand cmd(argc, argv);
734 
735     // set the mock objects
736     SetMockObjects(cmd);
737 
738     EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
739 }
740 
741 /**
742  * @tc.number: Bm_Command_Install_3200
743  * @tc.name: ExecCommand
744  * @tc.desc: Verify the "bm install -p <bundle-path> -XXX <user-id>" command.
745  */
746 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_3200, Function | MediumTest | Level1)
747 {
748     // install a bundle
749     char *argv[] = {
750         const_cast<char*>(TOOL_NAME.c_str()),
751         const_cast<char*>(cmd_.c_str()),
752         const_cast<char*>("-p"),
753         const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
754         const_cast<char*>(STRING_OTHER_BUNDLE_PATH.c_str()),
755         const_cast<char*>("-XXX"),
756         const_cast<char*>(DEFAULT_USER_ID.c_str()),
757         const_cast<char*>(""),
758     };
759     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
760 
761     BundleManagerShellCommand cmd(argc, argv);
762 
763     // set the mock objects
764     SetMockObjects(cmd);
765 
766     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_INSTALL);
767 }
768 
769 /**
770  * @tc.number: Bm_Command_Install_3300
771  * @tc.name: ExecCommand
772  * @tc.desc: Verify the "bm install -p <bundle-path> -w <waitting-time>" command.
773  */
774 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_3300, Function | MediumTest | Level1)
775 {
776     // install a bundle
777     char *argv[] = {
778         const_cast<char*>(TOOL_NAME.c_str()),
779         const_cast<char*>(cmd_.c_str()),
780         const_cast<char*>("-p"),
781         const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
782         const_cast<char*>("-w"),
783         const_cast<char*>(MINIMUMT_WAIT_TIME.c_str()),
784         const_cast<char*>(""),
785     };
786     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
787 
788     BundleManagerShellCommand cmd(argc, argv);
789 
790     // set the mock objects
791     SetMockObjects(cmd);
792 
793     EXPECT_EQ(cmd.ExecCommand(), "error: option requires a correct value.\n");
794 }
795 
796 /**
797  * @tc.number: Bm_Command_Install_3400
798  * @tc.name: ExecCommand
799  * @tc.desc: Verify the "bm install -p <bundle-path> -w <waitting-time>" command.
800  */
801 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_3400, Function | MediumTest | Level1)
802 {
803     // install a bundle
804     char *argv[] = {
805         const_cast<char*>(TOOL_NAME.c_str()),
806         const_cast<char*>(cmd_.c_str()),
807         const_cast<char*>("-p"),
808         const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
809         const_cast<char*>("-w"),
810         const_cast<char*>(MAXIMUM_WAIT_TIME.c_str()),
811         const_cast<char*>(""),
812     };
813     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
814 
815     BundleManagerShellCommand cmd(argc, argv);
816 
817     // set the mock objects
818     SetMockObjects(cmd);
819 
820     EXPECT_EQ(cmd.ExecCommand(), "error: option requires a correct value.\n");
821 }
822 
823 /**
824  * @tc.number: Bm_Command_Install_3500
825  * @tc.name: ExecCommand
826  * @tc.desc: Verify the "bm install" command.
827  */
828 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_3500, Function | MediumTest | Level1)
829 {
830     char *argv[] = {
831         const_cast<char*>(TOOL_NAME.c_str()),
832         const_cast<char*>(cmd_.c_str()),
833         const_cast<char*>("-cc"),
834         const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
835         const_cast<char*>(""),
836     };
837     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
838 
839     BundleManagerShellCommand cmd(argc, argv);
840 
841     // set the mock objects
842     SetMockObjects(cmd);
843 
844     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_INSTALL);
845 }
846 
847 /**
848  * @tc.number: Bm_Command_Install_3600
849  * @tc.name: ExecCommand
850  * @tc.desc: Verify the "bm install -s <bundle-path>" command.
851  */
852 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_3600, Function | MediumTest | Level1)
853 {
854     // install a bundle
855     char *argv[] = {
856         const_cast<char*>(TOOL_NAME.c_str()),
857         const_cast<char*>(cmd_.c_str()),
858         const_cast<char*>("-s"),
859         const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
860         const_cast<char*>(""),
861     };
862     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
863 
864     BundleManagerShellCommand cmd(argc, argv);
865 
866     // set the mock objects
867     SetMockObjects(cmd);
868 
869     EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
870 }
871 
872 /**
873  * @tc.number: Bm_Command_Install_3700
874  * @tc.name: ExecCommand
875  * @tc.desc: Verify the "bm install -s <bundle-path>" command.
876  */
877 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_3700, Function | MediumTest | Level1)
878 {
879     // install a bundle
880     char *argv[] = {
881         const_cast<char*>(TOOL_NAME.c_str()),
882         const_cast<char*>(cmd_.c_str()),
883         const_cast<char*>("--shared-bundle-dir-path"),
884         const_cast<char*>(STRING_BUNDLE_PATH.c_str()),
885         const_cast<char*>(""),
886     };
887     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
888 
889     BundleManagerShellCommand cmd(argc, argv);
890 
891     // set the mock objects
892     SetMockObjects(cmd);
893 
894     EXPECT_EQ(cmd.ExecCommand(), STRING_INSTALL_BUNDLE_OK + "\n");
895 }
896 
897 /**
898  * @tc.number: Bm_Command_Install_3800
899  * @tc.name: ExecCommand
900  * @tc.desc: Verify the "bm install -s <bundle-path>" command.
901  */
902 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_3800, Function | MediumTest | Level1)
903 {
904     // install a bundle
905     char *argv[] = {
906         const_cast<char*>(TOOL_NAME.c_str()),
907         const_cast<char*>(cmd_.c_str()),
908         const_cast<char*>("-s"),
909         const_cast<char*>("-r"),
910         const_cast<char*>("xxx"),
911         const_cast<char*>(""),
912     };
913     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
914 
915     BundleManagerShellCommand cmd(argc, argv);
916 
917     // set the mock objects
918     SetMockObjects(cmd);
919 
920     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE);
921 }
922 
923 /**
924  * @tc.number: Bm_Command_Install_3900
925  * @tc.name: ExecCommand
926  * @tc.desc: Verify the "bm install -s <bundle-path>" command.
927  */
928 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_3900, Function | MediumTest | Level1)
929 {
930     // install a bundle
931     char *argv[] = {
932         const_cast<char*>(TOOL_NAME.c_str()),
933         const_cast<char*>(cmd_.c_str()),
934         const_cast<char*>("-s"),
935         const_cast<char*>("--replace"),
936         const_cast<char*>("xxx"),
937         const_cast<char*>(""),
938     };
939     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
940 
941     BundleManagerShellCommand cmd(argc, argv);
942 
943     // set the mock objects
944     SetMockObjects(cmd);
945 
946     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE);
947 }
948 
949 /**
950  * @tc.number: Bm_Command_Install_4000
951  * @tc.name: ExecCommand
952  * @tc.desc: Verify the "bm install -s <bundle-path>" command.
953  */
954 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_4000, Function | MediumTest | Level1)
955 {
956     // install a bundle
957     char *argv[] = {
958         const_cast<char*>(TOOL_NAME.c_str()),
959         const_cast<char*>(cmd_.c_str()),
960         const_cast<char*>("-s"),
961         const_cast<char*>("-p"),
962         const_cast<char*>("xxx"),
963         const_cast<char*>(""),
964     };
965     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
966 
967     BundleManagerShellCommand cmd(argc, argv);
968 
969     // set the mock objects
970     SetMockObjects(cmd);
971 
972     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE);
973 }
974 
975 /**
976  * @tc.number: Bm_Command_Install_4100
977  * @tc.name: ExecCommand
978  * @tc.desc: Verify the "bm install -s <bundle-path>" command.
979  */
980 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_4100, Function | MediumTest | Level1)
981 {
982     // install a bundle
983     char *argv[] = {
984         const_cast<char*>(TOOL_NAME.c_str()),
985         const_cast<char*>(cmd_.c_str()),
986         const_cast<char*>("-s"),
987         const_cast<char*>("--bundle-path"),
988         const_cast<char*>("xxx"),
989         const_cast<char*>(""),
990     };
991     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
992 
993     BundleManagerShellCommand cmd(argc, argv);
994 
995     // set the mock objects
996     SetMockObjects(cmd);
997 
998     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE);
999 }
1000 
1001 /**
1002  * @tc.number: Bm_Command_Install_4200
1003  * @tc.name: ExecCommand
1004  * @tc.desc: Verify the "bm install -s <bundle-path>" command.
1005  */
1006 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_4200, Function | MediumTest | Level1)
1007 {
1008     // install a bundle
1009     char *argv[] = {
1010         const_cast<char*>(TOOL_NAME.c_str()),
1011         const_cast<char*>(cmd_.c_str()),
1012         const_cast<char*>("-s"),
1013         const_cast<char*>("-u"),
1014         const_cast<char*>("xxx"),
1015         const_cast<char*>(""),
1016     };
1017     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1018 
1019     BundleManagerShellCommand cmd(argc, argv);
1020 
1021     // set the mock objects
1022     SetMockObjects(cmd);
1023 
1024     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE);
1025 }
1026 
1027 /**
1028  * @tc.number: Bm_Command_Install_4300
1029  * @tc.name: ExecCommand
1030  * @tc.desc: Verify the "bm install -s <bundle-path>" command.
1031  */
1032 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_4300, Function | MediumTest | Level1)
1033 {
1034     // install a bundle
1035     char *argv[] = {
1036         const_cast<char*>(TOOL_NAME.c_str()),
1037         const_cast<char*>(cmd_.c_str()),
1038         const_cast<char*>("-s"),
1039         const_cast<char*>("--user-id"),
1040         const_cast<char*>("xxx"),
1041         const_cast<char*>(""),
1042     };
1043     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1044 
1045     BundleManagerShellCommand cmd(argc, argv);
1046 
1047     // set the mock objects
1048     SetMockObjects(cmd);
1049 
1050     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE);
1051 }
1052 
1053 /**
1054  * @tc.number: Bm_Command_Install_4400
1055  * @tc.name: ExecCommand
1056  * @tc.desc: Verify the "bm install -s <bundle-path>" command.
1057  */
1058 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_4400, Function | MediumTest | Level1)
1059 {
1060     // install a bundle
1061     char *argv[] = {
1062         const_cast<char*>(TOOL_NAME.c_str()),
1063         const_cast<char*>(cmd_.c_str()),
1064         const_cast<char*>("-s"),
1065         const_cast<char*>("-w"),
1066         const_cast<char*>("xxx"),
1067         const_cast<char*>(""),
1068     };
1069     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1070 
1071     BundleManagerShellCommand cmd(argc, argv);
1072 
1073     // set the mock objects
1074     SetMockObjects(cmd);
1075 
1076     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE);
1077 }
1078 
1079 /**
1080  * @tc.number: Bm_Command_Install_4500
1081  * @tc.name: ExecCommand
1082  * @tc.desc: Verify the "bm install -s <bundle-path>" command.
1083  */
1084 HWTEST_F(BmCommandInstallTest, Bm_Command_Install_4500, Function | MediumTest | Level1)
1085 {
1086     // install a bundle
1087     char *argv[] = {
1088         const_cast<char*>(TOOL_NAME.c_str()),
1089         const_cast<char*>(cmd_.c_str()),
1090         const_cast<char*>("-s"),
1091         const_cast<char*>("--waitting-time"),
1092         const_cast<char*>("xxx"),
1093         const_cast<char*>(""),
1094     };
1095     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1096 
1097     BundleManagerShellCommand cmd(argc, argv);
1098 
1099     // set the mock objects
1100     SetMockObjects(cmd);
1101 
1102     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE);
1103 }
1104 } // OHOS