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_installer_interface.h"
22 #include "iremote_broker.h"
23 #include "iremote_object.h"
24 #include "mock_bundle_installer_host.h"
25 #include "mock_bundle_mgr_host.h"
26 
27 using namespace testing::ext;
28 using namespace OHOS;
29 using namespace OHOS::AAFwk;
30 using namespace OHOS::AppExecFwk;
31 
32 namespace OHOS {
33 class BmCommandUninstallTest : 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_ = "uninstall";
44     sptr<IBundleMgr> mgrProxyPtr_;
45     sptr<IBundleInstaller> installerProxyPtr_;
46 };
47 
SetUpTestCase()48 void BmCommandUninstallTest::SetUpTestCase()
49 {}
50 
TearDownTestCase()51 void BmCommandUninstallTest::TearDownTestCase()
52 {}
53 
SetUp()54 void BmCommandUninstallTest::SetUp()
55 {
56     // reset optind to 0
57     optind = 0;
58 
59     // make mock objects
60     MakeMockObjects();
61 }
62 
TearDown()63 void BmCommandUninstallTest::TearDown()
64 {}
65 
MakeMockObjects()66 void BmCommandUninstallTest::MakeMockObjects()
67 {
68     // mock a mgr host
69     auto mgrHostPtr = sptr<IRemoteObject>(new (std::nothrow) MockBundleMgrHost());
70     // mock a mgr proxy
71     mgrProxyPtr_ = iface_cast<IBundleMgr>(mgrHostPtr);
72 
73     // mock a installer host
74     auto installerHostPtr = sptr<IRemoteObject>(new (std::nothrow) MockBundleInstallerHost());
75     // mock a installer proxy
76     installerProxyPtr_ = iface_cast<IBundleInstaller>(installerHostPtr);
77 }
78 
SetMockObjects(BundleManagerShellCommand & cmd) const79 void BmCommandUninstallTest::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_Uninstall_0100
90  * @tc.name: ExecCommand
91  * @tc.desc: Verify the "bm uninstall" command.
92  */
93 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_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_UNINSTALL);
108 }
109 
110 /**
111  * @tc.number: Bm_Command_Uninstall_0200
112  * @tc.name: ExecCommand
113  * @tc.desc: Verify the "bm uninstall xxx" command.
114  */
115 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_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_UNINSTALL);
131 }
132 
133 /**
134  * @tc.number: Bm_Command_Uninstall_0300
135  * @tc.name: ExecCommand
136  * @tc.desc: Verify the "bm uninstall -x" command.
137  */
138 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_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_UNINSTALL);
154 }
155 
156 /**
157  * @tc.number: Bm_Command_Uninstall_0400
158  * @tc.name: ExecCommand
159  * @tc.desc: Verify the "bm uninstall -xxx" command.
160  */
161 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_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_UNINSTALL);
177 }
178 
179 /**
180  * @tc.number: Bm_Command_Uninstall_0500
181  * @tc.name: ExecCommand
182  * @tc.desc: Verify the "bm uninstall --x" command.
183  */
184 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_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_UNINSTALL);
200 }
201 
202 /**
203  * @tc.number: Bm_Command_Uninstall_0600
204  * @tc.name: ExecCommand
205  * @tc.desc: Verify the "bm uninstall --xxx" command.
206  */
207 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_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_UNINSTALL);
223 }
224 
225 /**
226  * @tc.number: Bm_Command_Uninstall_0700
227  * @tc.name: ExecCommand
228  * @tc.desc: Verify the "bm uninstall --h" command.
229  */
230 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_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_UNINSTALL);
246 }
247 
248 /**
249  * @tc.number: Bm_Command_Uninstall_0800
250  * @tc.name: ExecCommand
251  * @tc.desc: Verify the "bm uninstall --help" command.
252  */
253 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_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_UNINSTALL);
269 }
270 
271 /**
272  * @tc.number: Bm_Command_Uninstall_0900
273  * @tc.name: ExecCommand
274  * @tc.desc: Verify the "bm uninstall -n" command.
275  */
276 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_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*>("-n"),
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_UNINSTALL);
292 }
293 
294 /**
295  * @tc.number: Bm_Command_Uninstall_1300
296  * @tc.name: ExecCommand
297  * @tc.desc: Verify the "bm uninstall -n <bundle-name>" command.
298  */
299 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_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*>("-n"),
305         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
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(cmd.ExecCommand(), STRING_UNINSTALL_BUNDLE_OK + "\n");
316 }
317 
318 /**
319  * @tc.number: Bm_Command_Uninstall_1100
320  * @tc.name: ExecCommand
321  * @tc.desc: Verify the "bm uninstall -n <bundle-name> -m" command.
322  */
323 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_1100, Function | MediumTest | Level1)
324 {
325     char *argv[] = {
326         const_cast<char*>(TOOL_NAME.c_str()),
327         const_cast<char*>(cmd_.c_str()),
328         const_cast<char*>("-n"),
329         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
330         const_cast<char*>("-m"),
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_REQUIRE_CORRECT_VALUE + HELP_MSG_UNINSTALL);
341 }
342 
343 /**
344  * @tc.number: Bm_Command_Uninstall_1200
345  * @tc.name: ExecCommand
346  * @tc.desc: Verify the "bm uninstall -m <module-name>" command.
347  */
348 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_1200, Function | MediumTest | Level1)
349 {
350     char *argv[] = {
351         const_cast<char*>(TOOL_NAME.c_str()),
352         const_cast<char*>(cmd_.c_str()),
353         const_cast<char*>("-m"),
354         const_cast<char*>(STRING_MODULE_NAME.c_str()),
355         const_cast<char*>(""),
356     };
357     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
358 
359     BundleManagerShellCommand cmd(argc, argv);
360 
361     // set the mock objects
362     SetMockObjects(cmd);
363 
364     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_BUNDLE_NAME_OPTION + "\n" + HELP_MSG_UNINSTALL);
365 }
366 
367 /**
368  * @tc.number: Bm_Command_Uninstall_1300
369  * @tc.name: ExecCommand
370  * @tc.desc: Verify the "bm uninstall -n <bundle-name> -m <module-name>" command.
371  */
372 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_1300, Function | MediumTest | Level1)
373 {
374     char *argv[] = {
375         const_cast<char*>(TOOL_NAME.c_str()),
376         const_cast<char*>(cmd_.c_str()),
377         const_cast<char*>("-n"),
378         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
379         const_cast<char*>("-m"),
380         const_cast<char*>(STRING_MODULE_NAME.c_str()),
381         const_cast<char*>(""),
382     };
383     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
384 
385     BundleManagerShellCommand cmd(argc, argv);
386 
387     // set the mock objects
388     SetMockObjects(cmd);
389 
390     EXPECT_EQ(cmd.ExecCommand(), STRING_UNINSTALL_BUNDLE_OK + "\n");
391 }
392 
393 /**
394  * @tc.number: Bm_Command_Uninstall_1400
395  * @tc.name: ExecCommand
396  * @tc.desc: Verify the "bm uninstall -n <bundle-name> -u" command.
397  */
398 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_1400, Function | MediumTest | Level1)
399 {
400     char *argv[] = {
401         const_cast<char*>(TOOL_NAME.c_str()),
402         const_cast<char*>(cmd_.c_str()),
403         const_cast<char*>("-n"),
404         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
405         const_cast<char*>("-u"),
406         const_cast<char*>(""),
407     };
408     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
409 
410     BundleManagerShellCommand cmd(argc, argv);
411 
412     // set the mock objects
413     SetMockObjects(cmd);
414 
415     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_UNINSTALL);
416 }
417 
418 /**
419  * @tc.number: Bm_Command_Uninstall_1600
420  * @tc.name: ExecCommand
421  * @tc.desc: Verify the "bm uninstall -n <bundle-name> -k" command.
422  */
423 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_1600, Function | MediumTest | Level1)
424 {
425     char *argv[] = {
426         const_cast<char*>(TOOL_NAME.c_str()),
427         const_cast<char*>(cmd_.c_str()),
428         const_cast<char*>("-n"),
429         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
430         const_cast<char*>("-k"),
431         const_cast<char*>(""),
432     };
433     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
434 
435     BundleManagerShellCommand cmd(argc, argv);
436 
437     // set the mock objects
438     SetMockObjects(cmd);
439 
440     EXPECT_EQ(cmd.ExecCommand(), STRING_UNINSTALL_BUNDLE_OK + "\n");
441 }
442 
443 /**
444  * @tc.number: Bm_Command_Uninstall_1700
445  * @tc.name: ExecCommand
446  * @tc.desc: Verify the "bm uninstall -n <bundle-name> -k xxx" command.
447  */
448 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_1700, Function | MediumTest | Level1)
449 {
450     char *argv[] = {
451         const_cast<char*>(TOOL_NAME.c_str()),
452         const_cast<char*>(cmd_.c_str()),
453         const_cast<char*>("-n"),
454         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
455         const_cast<char*>("-k"),
456         const_cast<char*>("XXX"),
457         const_cast<char*>(""),
458     };
459     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
460 
461     BundleManagerShellCommand cmd(argc, argv);
462 
463     // set the mock objects
464     SetMockObjects(cmd);
465 
466     EXPECT_EQ(cmd.ExecCommand(), STRING_UNINSTALL_BUNDLE_OK + "\n");
467 }
468 
469 /**
470  * @tc.number: Bm_Command_Uninstall_1800
471  * @tc.name: ExecCommand
472  * @tc.desc: Verify the "bm uninstall -n xxx" command.
473  */
474 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_1800, Function | MediumTest | Level1)
475 {
476     char *argv[] = {
477         const_cast<char*>(TOOL_NAME.c_str()),
478         const_cast<char*>(cmd_.c_str()),
479         const_cast<char*>("-n"),
480         const_cast<char*>("XXX"),
481         const_cast<char*>(""),
482     };
483     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
484 
485     BundleManagerShellCommand cmd(argc, argv);
486 
487     // set the mock objects
488     SetMockObjects(cmd);
489 
490     EXPECT_EQ(cmd.ExecCommand(), STRING_UNINSTALL_BUNDLE_OK + "\n");
491 }
492 
493 /**
494  * @tc.number: Bm_Command_Uninstall_1900
495  * @tc.name: ExecCommand
496  * @tc.desc: Verify the "bm uninstall -xxx <bundle-name>" command.
497  */
498 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_1900, Function | MediumTest | Level1)
499 {
500     char *argv[] = {
501         const_cast<char*>(TOOL_NAME.c_str()),
502         const_cast<char*>(cmd_.c_str()),
503         const_cast<char*>("-XXX"),
504         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
505         const_cast<char*>(""),
506     };
507     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
508 
509     BundleManagerShellCommand cmd(argc, argv);
510 
511     // set the mock objects
512     SetMockObjects(cmd);
513 
514     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_UNINSTALL);
515 }
516 
517 /**
518  * @tc.number: Bm_Command_Uninstall_2000
519  * @tc.name: ExecCommand
520  * @tc.desc: Verify the "bm uninstall -n <bundle-name> -u <user-id>" command.
521  */
522 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_2000, Function | MediumTest | Level1)
523 {
524     char *argv[] = {
525         const_cast<char*>(TOOL_NAME.c_str()),
526         const_cast<char*>(cmd_.c_str()),
527         const_cast<char*>("-n"),
528         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
529         const_cast<char*>("-u"),
530         const_cast<char*>(ERR_USER_ID.c_str()),
531         const_cast<char*>(""),
532     };
533     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
534 
535     BundleManagerShellCommand cmd(argc, argv);
536 
537     // set the mock objects
538     SetMockObjects(cmd);
539 
540     EXPECT_EQ(cmd.ExecCommand(), "error: option requires a correct value.\n");
541 }
542 
543 /**
544  * @tc.number: Bm_Command_Uninstall_2100
545  * @tc.name: ExecCommand
546  * @tc.desc: Verify the "bm uninstall -n <bundle-name> -k 1" command.
547  */
548 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_2100, Function | MediumTest | Level1)
549 {
550     char *argv[] = {
551         const_cast<char*>(TOOL_NAME.c_str()),
552         const_cast<char*>(cmd_.c_str()),
553         const_cast<char*>("-n"),
554         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
555         const_cast<char*>("-k"),
556         const_cast<char*>("1"),
557         const_cast<char*>(""),
558     };
559     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
560 
561     BundleManagerShellCommand cmd(argc, argv);
562 
563     // set the mock objects
564     SetMockObjects(cmd);
565 
566     EXPECT_EQ(cmd.ExecCommand(), STRING_UNINSTALL_BUNDLE_OK + "\n");
567 }
568 
569 /**
570  * @tc.number: Bm_Command_Uninstall_2200
571  * @tc.name: ExecCommand
572  * @tc.desc: Verify the "bm uninstall -cc <bundle-name>" command.
573  */
574 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_2200, Function | MediumTest | Level1)
575 {
576     char *argv[] = {
577         const_cast<char*>(TOOL_NAME.c_str()),
578         const_cast<char*>(cmd_.c_str()),
579         const_cast<char*>("-ccc"),
580         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
581         const_cast<char*>(""),
582     };
583     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
584 
585     BundleManagerShellCommand cmd(argc, argv);
586 
587     // set the mock objects
588     SetMockObjects(cmd);
589 
590     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_UNINSTALL);
591 }
592 
593 /**
594  * @tc.number: Bm_Command_Uninstall_2300
595  * @tc.name: ExecCommand
596  * @tc.desc: Verify the "bm uninstall -n <bundle-name> -k 1 -v 1 -s" command.
597  */
598 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_2300, Function | MediumTest | Level1)
599 {
600     char *argv[] = {
601         const_cast<char*>(TOOL_NAME.c_str()),
602         const_cast<char*>(cmd_.c_str()),
603         const_cast<char*>("-n"),
604         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
605         const_cast<char*>("-k"),
606         const_cast<char*>("1"),
607         const_cast<char*>("-v"),
608         const_cast<char*>("1"),
609         const_cast<char*>("-s"),
610         const_cast<char*>(""),
611     };
612     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
613 
614     BundleManagerShellCommand cmd(argc, argv);
615 
616     // set the mock objects
617     SetMockObjects(cmd);
618 
619     EXPECT_EQ(cmd.ExecCommand(), STRING_UNINSTALL_BUNDLE_OK + "\n");
620 }
621 
622 /**
623  * @tc.number: Bm_Command_Uninstall_2400
624  * @tc.name: ExecCommand
625  * @tc.desc: Verify the "bm uninstall -k xxxx" command.
626  */
627 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_2400, Function | MediumTest | Level1)
628 {
629     char *argv[] = {
630         const_cast<char*>(TOOL_NAME.c_str()),
631         const_cast<char*>(cmd_.c_str()),
632         const_cast<char*>("-k"),
633         const_cast<char*>("xxxx"),
634     };
635     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
636 
637     BundleManagerShellCommand cmd(argc, argv);
638 
639     // set the mock objects
640     SetMockObjects(cmd);
641 
642     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_BUNDLE_NAME_OPTION + "\n" + HELP_MSG_UNINSTALL);
643 }
644 
645 /**
646  * @tc.number: Bm_Command_Uninstall_2500
647  * @tc.name: ExecCommand
648  * @tc.desc: Verify the "bm uninstall -v 1" command.
649  */
650 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_2500, Function | MediumTest | Level1)
651 {
652     char *argv[] = {
653         const_cast<char*>(TOOL_NAME.c_str()),
654         const_cast<char*>(cmd_.c_str()),
655         const_cast<char*>("-v"),
656         const_cast<char*>("1"),
657     };
658     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
659 
660     BundleManagerShellCommand cmd(argc, argv);
661 
662     // set the mock objects
663     SetMockObjects(cmd);
664 
665     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_UNINSTALL);
666 }
667 
668 /**
669  * @tc.number: Bm_Command_Uninstall_2600
670  * @tc.name: ExecCommand
671  * @tc.desc: Verify the "bm uninstall -s" command.
672  */
673 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_2600, Function | MediumTest | Level1)
674 {
675     char *argv[] = {
676         const_cast<char*>(TOOL_NAME.c_str()),
677         const_cast<char*>(cmd_.c_str()),
678         const_cast<char*>("-s"),
679         const_cast<char*>(""),
680     };
681     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
682 
683     BundleManagerShellCommand cmd(argc, argv);
684 
685     // set the mock objects
686     SetMockObjects(cmd);
687 
688     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_BUNDLE_NAME_OPTION + "\n" + HELP_MSG_UNINSTALL);
689 }
690 
691 /**
692  * @tc.number: Bm_Command_Uninstall_2700
693  * @tc.name: ExecCommand
694  * @tc.desc: Verify the "bm uninstall -n <bundle-name> -k" command.
695  */
696 HWTEST_F(BmCommandUninstallTest, Bm_Command_Uninstall_2700, Function | MediumTest | Level1)
697 {
698     char *argv[] = {
699         const_cast<char*>(TOOL_NAME.c_str()),
700         const_cast<char*>(cmd_.c_str()),
701         const_cast<char*>("-n"),
702         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
703         const_cast<char*>("-k"),
704         const_cast<char*>(""),
705     };
706     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
707 
708     BundleManagerShellCommand cmd(argc, argv);
709 
710     // set the mock objects
711     SetMockObjects(cmd);
712 
713     EXPECT_EQ(cmd.ExecCommand(), STRING_UNINSTALL_BUNDLE_OK + "\n");
714 }
715 } // OHOS