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_installer_host.h"
26 #include "mock_bundle_mgr_host.h"
27 
28 using namespace testing::ext;
29 using namespace OHOS::AAFwk;
30 using namespace OHOS::AppExecFwk;
31 
32 namespace OHOS {
33 class BmCommandDumpTest : 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_ = "dump";
44     std::string shared_ = "dump-shared";
45     std::string sharedDependencies_ = "dump-shared-dependencies";
46     sptr<IBundleMgr> mgrProxyPtr_;
47     sptr<IBundleInstaller> installerProxyPtr_;
48 };
49 
SetUpTestCase()50 void BmCommandDumpTest::SetUpTestCase()
51 {}
52 
TearDownTestCase()53 void BmCommandDumpTest::TearDownTestCase()
54 {}
55 
SetUp()56 void BmCommandDumpTest::SetUp()
57 {
58     // reset optind to 0
59     optind = 0;
60 
61     // make mock objects
62     MakeMockObjects();
63 }
64 
TearDown()65 void BmCommandDumpTest::TearDown()
66 {}
67 
MakeMockObjects()68 void BmCommandDumpTest::MakeMockObjects()
69 {
70     // mock a mgr host
71     auto mgrHostPtr = sptr<IRemoteObject>(new (std::nothrow) MockBundleMgrHost());
72     // mock a mgr proxy
73     mgrProxyPtr_ = iface_cast<IBundleMgr>(mgrHostPtr);
74 
75     // mock a installer host
76     auto installerHostPtr = sptr<IRemoteObject>(new (std::nothrow) MockBundleInstallerHost());
77     // mock a installer proxy
78     installerProxyPtr_ = iface_cast<IBundleInstaller>(installerHostPtr);
79 }
80 
SetMockObjects(BundleManagerShellCommand & cmd) const81 void BmCommandDumpTest::SetMockObjects(BundleManagerShellCommand &cmd) const
82 {
83     // set the mock mgr proxy
84     cmd.bundleMgrProxy_ = mgrProxyPtr_;
85 
86     // set the mock installer proxy
87     cmd.bundleInstallerProxy_ = installerProxyPtr_;
88 }
89 
90 /**
91  * @tc.number: Bm_Command_Dump_0100
92  * @tc.name: ExecCommand
93  * @tc.desc: Verify the "bm dump" command.
94  */
95 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0100, Function | MediumTest | Level1)
96 {
97     char *argv[] = {
98         const_cast<char*>(TOOL_NAME.c_str()),
99         const_cast<char*>(cmd_.c_str()),
100         const_cast<char*>(""),
101     };
102     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
103 
104     BundleManagerShellCommand cmd(argc, argv);
105 
106     // set the mock objects
107     SetMockObjects(cmd);
108 
109     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_DUMP);
110 }
111 
112 /**
113  * @tc.number: Bm_Command_Dump_0200
114  * @tc.name: ExecCommand
115  * @tc.desc: Verify the "bm dump xxx" command.
116  */
117 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0200, Function | MediumTest | Level1)
118 {
119     char *argv[] = {
120         const_cast<char*>(TOOL_NAME.c_str()),
121         const_cast<char*>(cmd_.c_str()),
122         const_cast<char*>("xxx"),
123         const_cast<char*>(""),
124     };
125     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
126 
127     BundleManagerShellCommand cmd(argc, argv);
128 
129     // set the mock objects
130     SetMockObjects(cmd);
131 
132     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_DUMP);
133 }
134 
135 /**
136  * @tc.number: Bm_Command_Dump_0300
137  * @tc.name: ExecCommand
138  * @tc.desc: Verify the "bm dump -x" command.
139  */
140 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0300, Function | MediumTest | Level1)
141 {
142     char *argv[] = {
143         const_cast<char*>(TOOL_NAME.c_str()),
144         const_cast<char*>(cmd_.c_str()),
145         const_cast<char*>("-x"),
146         const_cast<char*>(""),
147     };
148     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
149 
150     BundleManagerShellCommand cmd(argc, argv);
151 
152     // set the mock objects
153     SetMockObjects(cmd);
154 
155     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DUMP);
156 }
157 
158 /**
159  * @tc.number: Bm_Command_Dump_0400
160  * @tc.name: ExecCommand
161  * @tc.desc: Verify the "bm dump -xxx" command.
162  */
163 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0400, Function | MediumTest | Level1)
164 {
165     char *argv[] = {
166         const_cast<char*>(TOOL_NAME.c_str()),
167         const_cast<char*>(cmd_.c_str()),
168         const_cast<char*>("-xxx"),
169         const_cast<char*>(""),
170     };
171     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
172 
173     BundleManagerShellCommand cmd(argc, argv);
174 
175     // set the mock objects
176     SetMockObjects(cmd);
177 
178     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DUMP);
179 }
180 
181 /**
182  * @tc.number: Bm_Command_Dump_0500
183  * @tc.name: ExecCommand
184  * @tc.desc: Verify the "bm dump --x" command.
185  */
186 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0500, Function | MediumTest | Level1)
187 {
188     char *argv[] = {
189         const_cast<char*>(TOOL_NAME.c_str()),
190         const_cast<char*>(cmd_.c_str()),
191         const_cast<char*>("--x"),
192         const_cast<char*>(""),
193     };
194     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
195 
196     BundleManagerShellCommand cmd(argc, argv);
197 
198     // set the mock objects
199     SetMockObjects(cmd);
200 
201     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DUMP);
202 }
203 
204 /**
205  * @tc.number: Bm_Command_Dump_0600
206  * @tc.name: ExecCommand
207  * @tc.desc: Verify the "bm dump --xxx" command.
208  */
209 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0600, Function | MediumTest | Level1)
210 {
211     char *argv[] = {
212         const_cast<char*>(TOOL_NAME.c_str()),
213         const_cast<char*>(cmd_.c_str()),
214         const_cast<char*>("--xxx"),
215         const_cast<char*>(""),
216     };
217     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
218 
219     BundleManagerShellCommand cmd(argc, argv);
220 
221     // set the mock objects
222     SetMockObjects(cmd);
223 
224     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DUMP);
225 }
226 
227 /**
228  * @tc.number: Bm_Command_Dump_0700
229  * @tc.name: ExecCommand
230  * @tc.desc: Verify the "bm dump -h" command.
231  */
232 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0700, Function | MediumTest | Level1)
233 {
234     char *argv[] = {
235         const_cast<char*>(TOOL_NAME.c_str()),
236         const_cast<char*>(cmd_.c_str()),
237         const_cast<char*>("-h"),
238         const_cast<char*>(""),
239     };
240     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
241 
242     BundleManagerShellCommand cmd(argc, argv);
243 
244     // set the mock objects
245     SetMockObjects(cmd);
246 
247     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_DUMP);
248 }
249 
250 /**
251  * @tc.number: Bm_Command_Dump_0800
252  * @tc.name: ExecCommand
253  * @tc.desc: Verify the "bm dump --help" command.
254  */
255 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0800, Function | MediumTest | Level1)
256 {
257     char *argv[] = {
258         const_cast<char*>(TOOL_NAME.c_str()),
259         const_cast<char*>(cmd_.c_str()),
260         const_cast<char*>("--help"),
261         const_cast<char*>(""),
262     };
263     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
264 
265     BundleManagerShellCommand cmd(argc, argv);
266 
267     // set the mock objects
268     SetMockObjects(cmd);
269 
270     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_DUMP);
271 }
272 
273 /**
274  * @tc.number: Bm_Command_Dump_0900
275  * @tc.name: ExecCommand
276  * @tc.desc: Verify the "bm dump -a" command.
277  */
278 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0900, Function | MediumTest | Level1)
279 {
280     char *argv[] = {
281         const_cast<char*>(TOOL_NAME.c_str()),
282         const_cast<char*>(cmd_.c_str()),
283         const_cast<char*>("-a"),
284         const_cast<char*>(""),
285     };
286     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
287 
288     BundleManagerShellCommand cmd(argc, argv);
289 
290     // set the mock objects
291     SetMockObjects(cmd);
292 
293     EXPECT_EQ(cmd.ExecCommand(), "OK");
294 }
295 
296 /**
297  * @tc.number: Bm_Command_Dump_1000
298  * @tc.name: ExecCommand
299  * @tc.desc: Verify the "bm dump --all" command.
300  */
301 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1000, Function | MediumTest | Level1)
302 {
303     char *argv[] = {
304         const_cast<char*>(TOOL_NAME.c_str()),
305         const_cast<char*>(cmd_.c_str()),
306         const_cast<char*>("--all"),
307         const_cast<char*>(""),
308     };
309     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
310 
311     BundleManagerShellCommand cmd(argc, argv);
312 
313     // set the mock objects
314     SetMockObjects(cmd);
315 
316     EXPECT_EQ(cmd.ExecCommand(), "OK");
317 }
318 
319 /**
320  * @tc.number: Bm_Command_Dump_1100
321  * @tc.name: ExecCommand
322  * @tc.desc: Verify the "bm dump -n" command.
323  */
324 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1100, Function | MediumTest | Level1)
325 {
326     char *argv[] = {
327         const_cast<char*>(TOOL_NAME.c_str()),
328         const_cast<char*>(cmd_.c_str()),
329         const_cast<char*>("-n"),
330         const_cast<char*>(""),
331     };
332     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
333 
334     BundleManagerShellCommand cmd(argc, argv);
335 
336     // set the mock objects
337     SetMockObjects(cmd);
338 
339     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_DUMP);
340 }
341 
342 /**
343  * @tc.number: Bm_Command_Dump_1200
344  * @tc.name: ExecCommand
345  * @tc.desc: Verify the "bm dump -n <bundle-name>" command.
346  */
347 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1200, Function | MediumTest | Level1)
348 {
349     char *argv[] = {
350         const_cast<char*>(TOOL_NAME.c_str()),
351         const_cast<char*>(cmd_.c_str()),
352         const_cast<char*>("-n"),
353         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
354         const_cast<char*>(""),
355     };
356     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
357 
358     BundleManagerShellCommand cmd(argc, argv);
359 
360     // set the mock objects
361     SetMockObjects(cmd);
362 
363     EXPECT_EQ(cmd.ExecCommand(), STRING_BUNDLE_NAME + "\n");
364 }
365 
366 /**
367  * @tc.number: Bm_Command_Dump_1300
368  * @tc.name: ExecCommand
369  * @tc.desc: Verify the "bm dump -s" command.
370  */
371 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1300, Function | MediumTest | Level1)
372 {
373     char *argv[] = {
374         const_cast<char*>(TOOL_NAME.c_str()),
375         const_cast<char*>(cmd_.c_str()),
376         const_cast<char*>("-s"),
377         const_cast<char*>(""),
378     };
379     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
380     BundleManagerShellCommand cmd(argc, argv);
381     // set the mock objects
382     SetMockObjects(cmd);
383     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_BUNDLE_NAME_OPTION + "\n" + HELP_MSG_DUMP);
384 }
385 
386 /**
387  * @tc.number: Bm_Command_Dump_1400
388  * @tc.name: ExecCommand
389  * @tc.desc: Verify the "bm dump -n <bundle-name> -s" command.
390  */
391 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1400, Function | MediumTest | Level1)
392 {
393     char *argv[] = {
394         const_cast<char*>(TOOL_NAME.c_str()),
395         const_cast<char*>(cmd_.c_str()),
396         const_cast<char*>("-n"),
397         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
398         const_cast<char*>("-s"),
399         const_cast<char*>(""),
400     };
401     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
402     BundleManagerShellCommand cmd(argc, argv);
403     // set the mock objects
404     SetMockObjects(cmd);
405     EXPECT_EQ(cmd.ExecCommand(), STRING_BUNDLE_NAME + "\n");
406 }
407 
408 /**
409  * @tc.number: Bm_Command_Dump_1500
410  * @tc.name: ExecCommand
411  * @tc.desc: Verify the "bm dump -n <bundle-name> -u" command.
412  */
413 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1500, Function | MediumTest | Level1)
414 {
415     char *argv[] = {
416         const_cast<char*>(TOOL_NAME.c_str()),
417         const_cast<char*>(cmd_.c_str()),
418         const_cast<char*>("-n"),
419         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
420         const_cast<char*>("-u"),
421         const_cast<char*>(""),
422     };
423     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
424     BundleManagerShellCommand cmd(argc, argv);
425     // set the mock objects
426     SetMockObjects(cmd);
427     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_DUMP);
428 }
429 
430 /**
431  * @tc.number: Bm_Command_Dump_1700
432  * @tc.name: ExecCommand
433  * @tc.desc: Verify the "bm dump -n <bundle-name> -d" command.
434  */
435 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1700, Function | MediumTest | Level1)
436 {
437     char *argv[] = {
438         const_cast<char*>(TOOL_NAME.c_str()),
439         const_cast<char*>(cmd_.c_str()),
440         const_cast<char*>("-n"),
441         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
442         const_cast<char*>("-d"),
443         const_cast<char*>(""),
444     };
445     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
446     BundleManagerShellCommand cmd(argc, argv);
447     // set the mock objects
448     SetMockObjects(cmd);
449     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_DUMP);
450 }
451 
452 /**
453  * @tc.number: Bm_Command_Dump_1800
454  * @tc.name: ExecCommand
455  * @tc.desc: Verify the "bm dump -n <bundle-name> -d <device-id>" command.
456  */
457 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1800, Function | MediumTest | Level1)
458 {
459     char *argv[] = {
460         const_cast<char*>(TOOL_NAME.c_str()),
461         const_cast<char*>(cmd_.c_str()),
462         const_cast<char*>("-n"),
463         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
464         const_cast<char*>("-d"),
465         const_cast<char*>(DEFAULT_DEVICE_TIME.c_str()),
466         const_cast<char*>(""),
467     };
468     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
469     BundleManagerShellCommand cmd(argc, argv);
470     // set the mock objects
471     SetMockObjects(cmd);
472     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_DUMP_FAILED + "\n");
473 }
474 
475 /**
476  * @tc.number: Bm_Command_Dump_1900
477  * @tc.name: ExecCommand
478  * @tc.desc: Verify the "bm dump -n <bundle-name> -XXX <user-id>" command.
479  */
480 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1900, Function | MediumTest | Level1)
481 {
482     char *argv[] = {
483         const_cast<char*>(TOOL_NAME.c_str()),
484         const_cast<char*>(cmd_.c_str()),
485         const_cast<char*>("-n"),
486         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
487         const_cast<char*>("-XXX"),
488         const_cast<char*>(DEFAULT_USER_ID.c_str()),
489         const_cast<char*>(""),
490     };
491     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
492     BundleManagerShellCommand cmd(argc, argv);
493     // set the mock objects
494     SetMockObjects(cmd);
495     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DUMP);
496 }
497 
498 /**
499  * @tc.number: Bm_Command_Dump_2100
500  * @tc.name: ExecCommand
501  * @tc.desc: Verify the "bm dump -xx <bundle-name>" command.
502  */
503 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_2100, Function | MediumTest | Level1)
504 {
505     char *argv[] = {
506         const_cast<char*>(TOOL_NAME.c_str()),
507         const_cast<char*>(cmd_.c_str()),
508         const_cast<char*>("-xx"),
509         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
510         const_cast<char*>(""),
511     };
512     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
513     BundleManagerShellCommand cmd(argc, argv);
514     // set the mock objects
515     SetMockObjects(cmd);
516     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DUMP);
517 }
518 
519 /**
520  * @tc.number: Bm_Command_Dump_2200
521  * @tc.name: ExecCommand
522  * @tc.desc: Verify the "bm dump -d <device-id>" command.
523  */
524 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_2200, Function | MediumTest | Level1)
525 {
526     char *argv[] = {
527         const_cast<char*>(TOOL_NAME.c_str()),
528         const_cast<char*>(cmd_.c_str()),
529         const_cast<char*>("-d"),
530         const_cast<char*>(DEFAULT_DEVICE_TIME.c_str()),
531         const_cast<char*>(""),
532     };
533     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
534     BundleManagerShellCommand cmd(argc, argv);
535     // set the mock objects
536     SetMockObjects(cmd);
537     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_BUNDLE_NAME_OPTION + "\n" + HELP_MSG_DUMP);
538 }
539 
540 /**
541  * @tc.number: Bm_Command_Shared_0001
542  * @tc.name: ExecCommand
543  * @tc.desc: Verify the "bm dump-shared" command.
544  */
545 HWTEST_F(BmCommandDumpTest, Bm_Command_Shared_0001, Function | MediumTest | Level1)
546 {
547     char *argv[] = {
548         const_cast<char*>(TOOL_NAME.c_str()),
549         const_cast<char*>(shared_.c_str()),
550         const_cast<char*>(""),
551     };
552     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
553 
554     BundleManagerShellCommand cmd(argc, argv);
555 
556     // set the mock objects
557     SetMockObjects(cmd);
558 
559     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_DUMP_SHARED);
560 }
561 
562 /**
563  * @tc.number: Bm_Command_Shared_0002
564  * @tc.name: ExecCommand
565  * @tc.desc: Verify the "bm dump-shared -n" command.
566  */
567 HWTEST_F(BmCommandDumpTest, Bm_Command_Shared_0002, Function | MediumTest | Level1)
568 {
569     char *argv[] = {
570         const_cast<char*>(TOOL_NAME.c_str()),
571         const_cast<char*>(shared_.c_str()),
572         const_cast<char*>("-n"),
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_REQUIRE_CORRECT_VALUE + HELP_MSG_DUMP_SHARED);
583 }
584 
585 /**
586  * @tc.number: Bm_Command_Shared_0003
587  * @tc.name: ExecCommand
588  * @tc.desc: Verify the "bm dump-shared -xxx" command.
589  */
590 HWTEST_F(BmCommandDumpTest, Bm_Command_Shared_0003, Function | MediumTest | Level1)
591 {
592     char *argv[] = {
593         const_cast<char*>(TOOL_NAME.c_str()),
594         const_cast<char*>(shared_.c_str()),
595         const_cast<char*>("-xxx"),
596         const_cast<char*>(""),
597     };
598     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
599 
600     BundleManagerShellCommand cmd(argc, argv);
601 
602     // set the mock objects
603     SetMockObjects(cmd);
604 
605     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DUMP_SHARED);
606 }
607 
608 /**
609  * @tc.number: Bm_Command_Shared_0005
610  * @tc.name: ExecCommand
611  * @tc.desc: Verify the "bm dump-shared -h" command.
612  */
613 HWTEST_F(BmCommandDumpTest, Bm_Command_Shared_0005, Function | MediumTest | Level1)
614 {
615     char *argv[] = {
616         const_cast<char*>(TOOL_NAME.c_str()),
617         const_cast<char*>(shared_.c_str()),
618         const_cast<char*>("-h"),
619         const_cast<char*>(""),
620     };
621     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
622 
623     BundleManagerShellCommand cmd(argc, argv);
624 
625     // set the mock objects
626     SetMockObjects(cmd);
627 
628     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_DUMP_SHARED);
629 }
630 
631 /**
632  * @tc.number: Bm_Command_Shared_0006
633  * @tc.name: ExecCommand
634  * @tc.desc: Verify the "bm dump-shared -n <bundle-name>" command.
635  */
636 HWTEST_F(BmCommandDumpTest, Bm_Command_Shared_0006, Function | MediumTest | Level1)
637 {
638     char *argv[] = {
639         const_cast<char*>(TOOL_NAME.c_str()),
640         const_cast<char*>(shared_.c_str()),
641         const_cast<char*>("-n"),
642         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
643         const_cast<char*>("-t"),
644         const_cast<char*>(""),
645     };
646     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
647 
648     BundleManagerShellCommand cmd(argc, argv);
649 
650     // set the mock objects
651     SetMockObjects(cmd);
652 
653     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DUMP_SHARED);
654 }
655 
656 } // namespace OHOS