1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 
18 #define private public
19 #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 #include "parameter.h"
27 #include "parameters.h"
28 
29 using namespace testing::ext;
30 using namespace OHOS::AAFwk;
31 using namespace OHOS::AppExecFwk;
32 
33 namespace OHOS {
34 namespace {
35     const char* IS_ROOT_MODE_PARAM = "const.debuggable";
36     const std::string IS_DEVELOPER_MODE_PARAM = "const.security.developermode.state";
37     const int32_t ROOT_MODE = 1;
38 }
39 
40 class BmCommandTest : public ::testing::Test {
41 public:
42     static void SetUpTestCase();
43     static void TearDownTestCase();
44     void SetUp() override;
45     void TearDown() override;
46 
47     void MakeMockObjects();
48     void SetMockObjects(BundleManagerShellCommand &cmd) const;
49 
50     sptr<IBundleMgr> mgrProxyPtr_;
51     sptr<IBundleInstaller> installerProxyPtr_;
52 };
53 
SetUpTestCase()54 void BmCommandTest::SetUpTestCase()
55 {}
56 
TearDownTestCase()57 void BmCommandTest::TearDownTestCase()
58 {}
59 
SetUp()60 void BmCommandTest::SetUp()
61 {
62     // reset optind to 0
63     optind = 0;
64 
65     // make mock objects
66     MakeMockObjects();
67 }
68 
TearDown()69 void BmCommandTest::TearDown()
70 {}
71 
MakeMockObjects()72 void BmCommandTest::MakeMockObjects()
73 {
74     // mock a mgr host
75     auto mgrHostPtr = sptr<IRemoteObject>(new (std::nothrow) MockBundleMgrHost());
76     // mock a mgr proxy
77     mgrProxyPtr_ = iface_cast<IBundleMgr>(mgrHostPtr);
78 
79     // mock a installer host
80     auto installerHostPtr = sptr<IRemoteObject>(new (std::nothrow) MockBundleInstallerHost());
81     // mock a installer proxy
82     installerProxyPtr_ = iface_cast<IBundleInstaller>(installerHostPtr);
83 }
84 
SetMockObjects(BundleManagerShellCommand & cmd) const85 void BmCommandTest::SetMockObjects(BundleManagerShellCommand &cmd) const
86 {
87     // set the mock mgr proxy
88     cmd.bundleMgrProxy_ = mgrProxyPtr_;
89 
90     // set the mock installer proxy
91     cmd.bundleInstallerProxy_ = installerProxyPtr_;
92 }
93 
94 /**
95  * @tc.number: Bm_Command_0001
96  * @tc.name: ExecCommand
97  * @tc.desc: Verify the "bm" command.
98  */
99 HWTEST_F(BmCommandTest, Bm_Command_0001, Function | MediumTest | Level1)
100 {
101     char *argv[] = {
102         const_cast<char*>(TOOL_NAME.c_str()),
103         const_cast<char*>(""),
104     };
105     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
106 
107     BundleManagerShellCommand cmd(argc, argv);
108 
109     // set the mock objects
110     SetMockObjects(cmd);
111 
112     std::string message;
113     message += HELP_MSG;
114     int32_t mode = GetIntParameter(IS_ROOT_MODE_PARAM, ROOT_MODE);
115     if (mode == ROOT_MODE) {
116         message += ENABLE_DISABLE_HELP_MSG;
117     }
118     bool isDeveloperMode = system::GetBoolParameter(IS_DEVELOPER_MODE_PARAM, false);
119     if (mode == ROOT_MODE || isDeveloperMode) {
120         message += CLEAN_HELP_MSG;
121     }
122 
123     EXPECT_EQ(cmd.ExecCommand(), message);
124 }
125 
126 /**
127  * @tc.number: Bm_Command_0002
128  * @tc.name: ExecCommand
129  * @tc.desc: Verify the "bm xxx" command.
130  */
131 HWTEST_F(BmCommandTest, Bm_Command_0002, Function | MediumTest | Level1)
132 {
133     char *argv[] = {
134         const_cast<char*>(TOOL_NAME.c_str()),
135         const_cast<char*>("xxx"),
136         const_cast<char*>(""),
137     };
138     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
139 
140     BundleManagerShellCommand cmd(argc, argv);
141 
142     // set the mock objects
143     SetMockObjects(cmd);
144 
145     std::string message;
146     message += HELP_MSG;
147     int32_t mode = GetIntParameter(IS_ROOT_MODE_PARAM, ROOT_MODE);
148     if (mode == ROOT_MODE) {
149         message += ENABLE_DISABLE_HELP_MSG;
150     }
151     bool isDeveloperMode = system::GetBoolParameter(IS_DEVELOPER_MODE_PARAM, false);
152     if (mode == ROOT_MODE || isDeveloperMode) {
153         message += CLEAN_HELP_MSG;
154     }
155 
156     EXPECT_EQ(cmd.ExecCommand(), cmd.GetCommandErrorMsg() + message);
157 }
158 
159 /**
160  * @tc.number: Bm_Command_0003
161  * @tc.name: ExecCommand
162  * @tc.desc: Verify the "bm -xxx" command.
163  */
164 HWTEST_F(BmCommandTest, Bm_Command_0003, Function | MediumTest | Level1)
165 {
166     char *argv[] = {
167         const_cast<char*>(TOOL_NAME.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     std::string message;
179     message += HELP_MSG;
180     int32_t mode = GetIntParameter(IS_ROOT_MODE_PARAM, ROOT_MODE);
181     if (mode == ROOT_MODE) {
182         message += ENABLE_DISABLE_HELP_MSG;
183     }
184     bool isDeveloperMode = system::GetBoolParameter(IS_DEVELOPER_MODE_PARAM, false);
185     if (mode == ROOT_MODE || isDeveloperMode) {
186         message += CLEAN_HELP_MSG;
187     }
188 
189     EXPECT_EQ(cmd.ExecCommand(), cmd.GetCommandErrorMsg() + message);
190 }
191 
192 /**
193  * @tc.number: Bm_Command_0004
194  * @tc.name: ExecCommand
195  * @tc.desc: Verify the "bm --xxx" command.
196  */
197 HWTEST_F(BmCommandTest, Bm_Command_0004, Function | MediumTest | Level1)
198 {
199     char *argv[] = {
200         const_cast<char*>(TOOL_NAME.c_str()),
201         const_cast<char*>("--xxx"),
202         const_cast<char*>(""),
203     };
204     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
205 
206     BundleManagerShellCommand cmd(argc, argv);
207 
208     // set the mock objects
209     SetMockObjects(cmd);
210 
211     std::string message;
212     message += HELP_MSG;
213     int32_t mode = GetIntParameter(IS_ROOT_MODE_PARAM, ROOT_MODE);
214     if (mode == ROOT_MODE) {
215         message += ENABLE_DISABLE_HELP_MSG;
216     }
217     bool isDeveloperMode = system::GetBoolParameter(IS_DEVELOPER_MODE_PARAM, false);
218     if (mode == ROOT_MODE || isDeveloperMode) {
219         message += CLEAN_HELP_MSG;
220     }
221 
222     EXPECT_EQ(cmd.ExecCommand(), cmd.GetCommandErrorMsg() + message);
223 }
224 
225 /**
226  * @tc.number: Bm_Command_0005
227  * @tc.name: ExecCommand
228  * @tc.desc: Verify the "bm help" command.
229  */
230 HWTEST_F(BmCommandTest, Bm_Command_0005, Function | MediumTest | Level1)
231 {
232     char *argv[] = {
233         const_cast<char*>(TOOL_NAME.c_str()),
234         const_cast<char*>("help"),
235         const_cast<char*>(""),
236     };
237     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
238 
239     BundleManagerShellCommand cmd(argc, argv);
240 
241     // set the mock objects
242     SetMockObjects(cmd);
243 
244     std::string message;
245     message += HELP_MSG;
246     int32_t mode = GetIntParameter(IS_ROOT_MODE_PARAM, ROOT_MODE);
247     if (mode == ROOT_MODE) {
248         message += ENABLE_DISABLE_HELP_MSG;
249     }
250     bool isDeveloperMode = system::GetBoolParameter(IS_DEVELOPER_MODE_PARAM, false);
251     if (mode == ROOT_MODE || isDeveloperMode) {
252         message += CLEAN_HELP_MSG;
253     }
254 
255     EXPECT_EQ(cmd.ExecCommand(), message);
256 }
257 
258 /**
259  * @tc.number: Bm_Command_Clean_0001
260  * @tc.name: ExecCommand
261  * @tc.desc: Verify the "bm clean" command.
262  */
263 HWTEST_F(BmCommandTest, Bm_Command_Clean_0001, Function | MediumTest | Level1)
264 {
265     char *argv[] = {
266         const_cast<char*>(TOOL_NAME.c_str()),
267         const_cast<char*>("clean"),
268         const_cast<char*>(""),
269     };
270     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
271     BundleManagerShellCommand cmd(argc, argv);
272     // set the mock objects
273     SetMockObjects(cmd);
274     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_CLEAN);
275 }
276 
277 /**
278  * @tc.number: Bm_Command_Clean_0002
279  * @tc.name: ExecCommand
280  * @tc.desc: Verify the "bm clean xx" command.
281  */
282 HWTEST_F(BmCommandTest, Bm_Command_Clean_0002, Function | MediumTest | Level1)
283 {
284     char *argv[] = {
285         const_cast<char*>(TOOL_NAME.c_str()),
286         const_cast<char*>("clean"),
287         const_cast<char*>("xxx"),
288         const_cast<char*>(""),
289     };
290     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
291     BundleManagerShellCommand cmd(argc, argv);
292     // set the mock objects
293     SetMockObjects(cmd);
294     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_CLEAN);
295 }
296 
297 /**
298  * @tc.number: Bm_Command_Clean_0003
299  * @tc.name: ExecCommand
300  * @tc.desc: Verify the "bm clean -n" command.
301  */
302 HWTEST_F(BmCommandTest, Bm_Command_Clean_0003, Function | MediumTest | Level1)
303 {
304     char *argv[] = {
305         const_cast<char*>(TOOL_NAME.c_str()),
306         const_cast<char*>("clean"),
307         const_cast<char*>("-n"),
308         const_cast<char*>(""),
309     };
310     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
311     BundleManagerShellCommand cmd(argc, argv);
312     // set the mock objects
313     SetMockObjects(cmd);
314     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_CLEAN);
315 }
316 
317 /**
318  * @tc.number: Bm_Command_Clean_0004
319  * @tc.name: ExecCommand
320  * @tc.desc: Verify the "bm clean -n <bundle-name>" command.
321  */
322 HWTEST_F(BmCommandTest, Bm_Command_Clean_0004, Function | MediumTest | Level1)
323 {
324     char *argv[] = {
325         const_cast<char*>(TOOL_NAME.c_str()),
326         const_cast<char*>("clean"),
327         const_cast<char*>("-n"),
328         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
329         const_cast<char*>(""),
330     };
331     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
332     BundleManagerShellCommand cmd(argc, argv);
333     // set the mock objects
334     SetMockObjects(cmd);
335     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_DATA_OR_CACHE_OPTION + "\n" + HELP_MSG_CLEAN);
336 }
337 
338 /**
339  * @tc.number: Bm_Command_Clean_0005
340  * @tc.name: ExecCommand
341  * @tc.desc: Verify the "bm clean -n <bundle-name> xxx" command.
342  */
343 HWTEST_F(BmCommandTest, Bm_Command_Clean_0005, Function | MediumTest | Level1)
344 {
345     char *argv[] = {
346         const_cast<char*>(TOOL_NAME.c_str()),
347         const_cast<char*>("clean"),
348         const_cast<char*>("-n"),
349         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
350         const_cast<char*>("xxx"),
351         const_cast<char*>(""),
352     };
353     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
354     BundleManagerShellCommand cmd(argc, argv);
355     // set the mock objects
356     SetMockObjects(cmd);
357     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_DATA_OR_CACHE_OPTION + "\n" + HELP_MSG_CLEAN);
358 }
359 
360 /**
361  * @tc.number: Bm_Command_Clean_0006
362  * @tc.name: ExecCommand
363  * @tc.desc: Verify the "bm clean -n <bundle-name> -d" command.
364  */
365 HWTEST_F(BmCommandTest, Bm_Command_Clean_0006, Function | MediumTest | Level1)
366 {
367     char *argv[] = {
368         const_cast<char*>(TOOL_NAME.c_str()),
369         const_cast<char*>("clean"),
370         const_cast<char*>("-n"),
371         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
372         const_cast<char*>("-d"),
373         const_cast<char*>(""),
374     };
375     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
376     BundleManagerShellCommand cmd(argc, argv);
377     // set the mock objects
378     SetMockObjects(cmd);
379     EXPECT_EQ(cmd.ExecCommand(), STRING_CLEAN_DATA_BUNDLE_NG + "\n");
380 }
381 
382 /**
383  * @tc.number: Bm_Command_Clean_0007
384  * @tc.name: ExecCommand
385  * @tc.desc: Verify the "bm clean -n <bundle-name> -c" command.
386  */
387 HWTEST_F(BmCommandTest, Bm_Command_Clean_0007, Function | MediumTest | Level1)
388 {
389     char *argv[] = {
390         const_cast<char*>(TOOL_NAME.c_str()),
391         const_cast<char*>("clean"),
392         const_cast<char*>("-n"),
393         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
394         const_cast<char*>("-c"),
395         const_cast<char*>(""),
396     };
397     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
398     BundleManagerShellCommand cmd(argc, argv);
399     // set the mock objects
400     SetMockObjects(cmd);
401     EXPECT_EQ(cmd.ExecCommand(), STRING_CLEAN_CACHE_BUNDLE_OK + "\n");
402 }
403 
404 /**
405  * @tc.number: Bm_Command_Clean_0008
406  * @tc.name: ExecCommand
407  * @tc.desc: Verify the "bm clean -c" command.
408  */
409 HWTEST_F(BmCommandTest, Bm_Command_Clean_0008, Function | MediumTest | Level1)
410 {
411     char *argv[] = {
412         const_cast<char*>(TOOL_NAME.c_str()),
413         const_cast<char*>("clean"),
414         const_cast<char*>("-c"),
415         const_cast<char*>(""),
416     };
417     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
418     BundleManagerShellCommand cmd(argc, argv);
419     // set the mock objects
420     SetMockObjects(cmd);
421     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_BUNDLE_NAME_OPTION + "\n" + HELP_MSG_CLEAN);
422 }
423 
424 /**
425  * @tc.number: Bm_Command_Clean_0009
426  * @tc.name: ExecCommand
427  * @tc.desc: Verify the "bm clean -d" command.
428  */
429 HWTEST_F(BmCommandTest, Bm_Command_Clean_0009, Function | MediumTest | Level1)
430 {
431     char *argv[] = {
432         const_cast<char*>(TOOL_NAME.c_str()),
433         const_cast<char*>("clean"),
434         const_cast<char*>("-d"),
435         const_cast<char*>(""),
436     };
437     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
438     BundleManagerShellCommand cmd(argc, argv);
439     // set the mock objects
440     SetMockObjects(cmd);
441     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_BUNDLE_NAME_OPTION + "\n" + HELP_MSG_CLEAN);
442 }
443 
444 /**
445  * @tc.number: Bm_Command_Clean_0010
446  * @tc.name: ExecCommand
447  * @tc.desc: Verify the "bm clean -n <bundle-name> -d -u" command.
448  */
449 HWTEST_F(BmCommandTest, Bm_Command_Clean_0010, Function | MediumTest | Level1)
450 {
451     char *argv[] = {
452         const_cast<char*>(TOOL_NAME.c_str()),
453         const_cast<char*>("clean"),
454         const_cast<char*>("-n"),
455         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
456         const_cast<char*>("-d"),
457         const_cast<char*>(" "),
458         const_cast<char*>("-u"),
459         const_cast<char*>(""),
460     };
461     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
462     BundleManagerShellCommand cmd(argc, argv);
463     // set the mock objects
464     SetMockObjects(cmd);
465     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_CLEAN);
466 }
467 
468 /**
469  * @tc.number: Bm_Command_Clean_0012
470  * @tc.name: ExecCommand
471  * @tc.desc: Verify the "bm clean -n <bundle-name> -d -u <user-id>" command.
472  */
473 HWTEST_F(BmCommandTest, Bm_Command_Clean_0012, Function | MediumTest | Level1)
474 {
475     char *argv[] = {
476         const_cast<char*>(TOOL_NAME.c_str()),
477         const_cast<char*>("clean"),
478         const_cast<char*>("-n"),
479         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
480         const_cast<char*>("-d"),
481         const_cast<char*>(" "),
482         const_cast<char*>("-u"),
483         const_cast<char*>(DEFAULT_USER_ID.c_str()),
484         const_cast<char*>(""),
485     };
486     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
487     BundleManagerShellCommand cmd(argc, argv);
488     // set the mock objects
489     SetMockObjects(cmd);
490     EXPECT_EQ(cmd.ExecCommand(), STRING_CLEAN_DATA_BUNDLE_NG + "\n");
491 }
492 
493 /**
494  * @tc.number: Bm_Command_Clean_0013
495  * @tc.name: ExecCommand
496  * @tc.desc: Verify the "bm clean -h" command.
497  */
498 HWTEST_F(BmCommandTest, Bm_Command_Clean_0013, Function | MediumTest | Level1)
499 {
500     char *argv[] = {
501         const_cast<char*>(TOOL_NAME.c_str()),
502         const_cast<char*>("clean"),
503         const_cast<char*>("-h"),
504     };
505     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
506     BundleManagerShellCommand cmd(argc, argv);
507     // set the mock objects
508     SetMockObjects(cmd);
509     EXPECT_EQ(cmd.ExecCommand(), "error: you must specify an option at least.\n" + HELP_MSG_CLEAN);
510 }
511 
512 /**
513  * @tc.number: Bm_Command_Clean_0014
514  * @tc.name: ExecCommand
515  * @tc.desc: Verify the "bm clean -xxx" command.
516  */
517 HWTEST_F(BmCommandTest, Bm_Command_Clean_0014, Function | MediumTest | Level1)
518 {
519     char *argv[] = {
520         const_cast<char*>(TOOL_NAME.c_str()),
521         const_cast<char*>("clean"),
522         const_cast<char*>("-XXX"),
523         const_cast<char*>(" "),
524     };
525     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
526     BundleManagerShellCommand cmd(argc, argv);
527     // set the mock objects
528     SetMockObjects(cmd);
529     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_CLEAN);
530 }
531 
532 /**
533  * @tc.number: Bm_Command_Clean_0015
534  * @tc.name: ExecCommand
535  * @tc.desc: Verify the "bm clean -n <bundle-name> -d -xxx <user-id>" command.
536  */
537 HWTEST_F(BmCommandTest, Bm_Command_Clean_0015, Function | MediumTest | Level1)
538 {
539     char *argv[] = {
540         const_cast<char*>(TOOL_NAME.c_str()),
541         const_cast<char*>("clean"),
542         const_cast<char*>("-n"),
543         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
544         const_cast<char*>("-d"),
545         const_cast<char*>(" "),
546         const_cast<char*>("-XXX"),
547         const_cast<char*>(DEFAULT_USER_ID.c_str()),
548         const_cast<char*>(""),
549     };
550     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
551     BundleManagerShellCommand cmd(argc, argv);
552     // set the mock objects
553     SetMockObjects(cmd);
554     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_CLEAN);
555 }
556 
557 /**
558  * @tc.number: Bm_Command_Clean_0016
559  * @tc.name: ExecCommand
560  * @tc.desc: Verify the "bm clean -xxx <bundle-name>" command.
561  */
562 HWTEST_F(BmCommandTest, Bm_Command_Clean_0016, Function | MediumTest | Level1)
563 {
564     char *argv[] = {
565         const_cast<char*>(TOOL_NAME.c_str()),
566         const_cast<char*>("clean"),
567         const_cast<char*>("-xxx"),
568         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
569         const_cast<char*>(""),
570     };
571     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
572     BundleManagerShellCommand cmd(argc, argv);
573     // set the mock objects
574     SetMockObjects(cmd);
575     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_CLEAN);
576 }
577 
578 /**
579  * @tc.number: Bm_Command_Clean_0017
580  * @tc.name: ExecCommand
581  * @tc.desc: Verify the "bm clean -h" command.
582  */
583 HWTEST_F(BmCommandTest, Bm_Command_Clean_0017, Function | MediumTest | Level1)
584 {
585     char *argv[] = {
586         const_cast<char*>(TOOL_NAME.c_str()),
587         const_cast<char*>("clean"),
588         const_cast<char*>("-h"),
589         const_cast<char*>(""),
590     };
591     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
592     BundleManagerShellCommand cmd(argc, argv);
593     // set the mock objects
594     SetMockObjects(cmd);
595     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_CLEAN);
596 }
597 
598 /**
599  * @tc.number: Bm_Command_Enable_0001
600  * @tc.name: ExecCommand
601  * @tc.desc: Verify the "bm enable" command.
602  */
603 HWTEST_F(BmCommandTest, Bm_Command_Enable_0001, Function | MediumTest | Level1)
604 {
605     char *argv[] = {
606         const_cast<char*>(TOOL_NAME.c_str()),
607         const_cast<char*>("enable"),
608         const_cast<char*>(""),
609     };
610     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
611     BundleManagerShellCommand cmd(argc, argv);
612     // set the mock objects
613     SetMockObjects(cmd);
614     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_ENABLE);
615 }
616 
617 /**
618  * @tc.number: Bm_Command_Enable_0002
619  * @tc.name: ExecCommand
620  * @tc.desc: Verify the "bm enable -n <bundle-name>" command.
621  */
622 HWTEST_F(BmCommandTest, Bm_Command_Enable_0002, Function | MediumTest | Level1)
623 {
624     char *argv[] = {
625         const_cast<char*>(TOOL_NAME.c_str()),
626         const_cast<char*>("enable"),
627         const_cast<char*>("-n"),
628         const_cast<char*>(""),
629     };
630     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
631     BundleManagerShellCommand cmd(argc, argv);
632     // set the mock objects
633     SetMockObjects(cmd);
634     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_ENABLE);
635 }
636 
637 /**
638  * @tc.number: Bm_Command_Enable_0003
639  * @tc.name: ExecCommand
640  * @tc.desc: Verify the "bm enable -n <bundle-name>" command.
641  */
642 HWTEST_F(BmCommandTest, Bm_Command_Enable_0003, Function | MediumTest | Level1)
643 {
644     char *argv[] = {
645         const_cast<char*>(TOOL_NAME.c_str()),
646         const_cast<char*>("enable"),
647         const_cast<char*>("-n"),
648         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
649         const_cast<char*>(""),
650     };
651     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
652     BundleManagerShellCommand cmd(argc, argv);
653     // set the mock objects
654     SetMockObjects(cmd);
655     EXPECT_EQ(cmd.ExecCommand(), STRING_ENABLE_BUNDLE_OK + "\n");
656 }
657 
658 /**
659  * @tc.number: Bm_Command_Enable_0004
660  * @tc.name: ExecCommand
661  * @tc.desc: Verify the "bm enable -n <bundle-name> -a <ability-name>" command.
662  */
663 HWTEST_F(BmCommandTest, Bm_Command_Enable_0004, Function | MediumTest | Level1)
664 {
665     char *argv[] = {
666         const_cast<char*>(TOOL_NAME.c_str()),
667         const_cast<char*>("enable"),
668         const_cast<char*>("-n"),
669         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
670         const_cast<char*>("-a"),
671         const_cast<char*>(""),
672     };
673     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
674     BundleManagerShellCommand cmd(argc, argv);
675     // set the mock objects
676     SetMockObjects(cmd);
677     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_ENABLE);
678 }
679 
680 /**
681  * @tc.number: Bm_Command_Enable_0005
682  * @tc.name: ExecCommand
683  * @tc.desc: Verify the "bm enable -n <bundle-name> -a <ability-name>" command.
684  */
685 HWTEST_F(BmCommandTest, Bm_Command_Enable_0005, Function | MediumTest | Level1)
686 {
687     char *argv[] = {
688         const_cast<char*>(TOOL_NAME.c_str()),
689         const_cast<char*>("enable"),
690         const_cast<char*>("-n"),
691         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
692         const_cast<char*>("-a"),
693         const_cast<char*>(STRING_ABILITY_NAME.c_str()),
694         const_cast<char*>(""),
695     };
696     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
697     BundleManagerShellCommand cmd(argc, argv);
698     // set the mock objects
699     SetMockObjects(cmd);
700     EXPECT_EQ(cmd.ExecCommand(), STRING_ENABLE_BUNDLE_OK + "\n");
701 }
702 
703 /**
704  * @tc.number: Bm_Command_Enable_0006
705  * @tc.name: ExecCommand
706  * @tc.desc: Verify the "bm enable -x" command.
707  */
708 HWTEST_F(BmCommandTest, Bm_Command_Enable_0006, Function | MediumTest | Level1)
709 {
710     char *argv[] = {
711         const_cast<char*>(TOOL_NAME.c_str()),
712         const_cast<char*>("enable"),
713         const_cast<char*>("-x"),
714         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
715         const_cast<char*>(""),
716     };
717     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
718     BundleManagerShellCommand cmd(argc, argv);
719     // set the mock objects
720     SetMockObjects(cmd);
721     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_ENABLE);
722 }
723 
724 /**
725  * @tc.number: Bm_Command_Enable_0007
726  * @tc.name: ExecCommand
727  * @tc.desc: Verify the "bm enable -n <bundle-name> -u" command.
728  */
729 HWTEST_F(BmCommandTest, Bm_Command_Enable_0007, Function | MediumTest | Level1)
730 {
731     char *argv[] = {
732         const_cast<char*>(TOOL_NAME.c_str()),
733         const_cast<char*>("enable"),
734         const_cast<char*>("-n"),
735         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
736         const_cast<char*>("-u"),
737         const_cast<char*>(""),
738     };
739     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
740     BundleManagerShellCommand cmd(argc, argv);
741     // set the mock objects
742     SetMockObjects(cmd);
743     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_ENABLE);
744 }
745 
746 /**
747  * @tc.number: Bm_Command_Enable_0009
748  * @tc.name: ExecCommand
749  * @tc.desc: Verify the "bm enable -n <bundle-name> -u <user-id>" command.
750  */
751 HWTEST_F(BmCommandTest, Bm_Command_Enable_0009, Function | MediumTest | Level1)
752 {
753     char *argv[] = {
754         const_cast<char*>(TOOL_NAME.c_str()),
755         const_cast<char*>("enable"),
756         const_cast<char*>("-n"),
757         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
758         const_cast<char*>("-u"),
759         const_cast<char*>(DEFAULT_USER_ID.c_str()),
760         const_cast<char*>(""),
761     };
762     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
763     BundleManagerShellCommand cmd(argc, argv);
764     // set the mock objects
765     SetMockObjects(cmd);
766     EXPECT_EQ(cmd.ExecCommand(), STRING_ENABLE_BUNDLE_OK + "\n");
767 }
768 
769 /**
770  * @tc.number: Bm_Command_Enable_0010
771  * @tc.name: ExecCommand
772  * @tc.desc: Verify the "bm enable -h" command.
773  */
774 HWTEST_F(BmCommandTest, Bm_Command_Enable_0010, Function | MediumTest | Level1)
775 {
776     char *argv[] = {
777         const_cast<char*>(TOOL_NAME.c_str()),
778         const_cast<char*>("enable"),
779         const_cast<char*>("-h"),
780         const_cast<char*>(""),
781     };
782     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
783     BundleManagerShellCommand cmd(argc, argv);
784     // set the mock objects
785     SetMockObjects(cmd);
786     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_ENABLE);
787 }
788 
789 /**
790  * @tc.number: Bm_Command_Enable_0011
791  * @tc.name: ExecCommand
792  * @tc.desc: Verify the "bm enable -n <bundle-name> -xxx <user-id>" command.
793  */
794 HWTEST_F(BmCommandTest, Bm_Command_Enable_0011, Function | MediumTest | Level1)
795 {
796     char *argv[] = {
797         const_cast<char*>(TOOL_NAME.c_str()),
798         const_cast<char*>("enable"),
799         const_cast<char*>("-n"),
800         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
801         const_cast<char*>("-XXX"),
802         const_cast<char*>(DEFAULT_USER_ID.c_str()),
803         const_cast<char*>(""),
804     };
805     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
806     BundleManagerShellCommand cmd(argc, argv);
807     // set the mock objects
808     SetMockObjects(cmd);
809     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_ENABLE);
810 }
811 
812 /**
813  * @tc.number: Bm_Command_Disable_0001
814  * @tc.name: ExecCommand
815  * @tc.desc: Verify the "bm disable" command.
816  */
817 HWTEST_F(BmCommandTest, Bm_Command_Disable_0001, Function | MediumTest | Level1)
818 {
819     char *argv[] = {
820         const_cast<char*>(TOOL_NAME.c_str()),
821         const_cast<char*>("disable"),
822         const_cast<char*>(""),
823     };
824     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
825     BundleManagerShellCommand cmd(argc, argv);
826     // set the mock objects
827     SetMockObjects(cmd);
828     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_DISABLE);
829 }
830 
831 /**
832  * @tc.number: Bm_Command_Disable_0002
833  * @tc.name: ExecCommand
834  * @tc.desc: Verify the "bm disable -n <bundle-name>" command.
835  */
836 HWTEST_F(BmCommandTest, Bm_Command_Disable_0002, Function | MediumTest | Level1)
837 {
838     char *argv[] = {
839         const_cast<char*>(TOOL_NAME.c_str()),
840         const_cast<char*>("disable"),
841         const_cast<char*>("-n"),
842         const_cast<char*>(""),
843     };
844     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
845     BundleManagerShellCommand cmd(argc, argv);
846     // set the mock objects
847     SetMockObjects(cmd);
848     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_DISABLE);
849 }
850 
851 /**
852  * @tc.number: Bm_Command_Disable_0003
853  * @tc.name: ExecCommand
854  * @tc.desc: Verify the "bm disable -n <bundle-name>" command.
855  */
856 HWTEST_F(BmCommandTest, Bm_Command_Disable_0003, Function | MediumTest | Level1)
857 {
858     char *argv[] = {
859         const_cast<char*>(TOOL_NAME.c_str()),
860         const_cast<char*>("disable"),
861         const_cast<char*>("-n"),
862         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
863         const_cast<char*>(""),
864     };
865     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
866     BundleManagerShellCommand cmd(argc, argv);
867     // set the mock objects
868     SetMockObjects(cmd);
869     EXPECT_EQ(cmd.ExecCommand(), STRING_DISABLE_BUNDLE_OK + "\n");
870 }
871 
872 /**
873  * @tc.number: Bm_Command_Disable_0004
874  * @tc.name: ExecCommand
875  * @tc.desc: Verify the "bm disable -n <bundle-name> -a <ability-name>" command.
876  */
877 HWTEST_F(BmCommandTest, Bm_Command_Disable_0004, Function | MediumTest | Level1)
878 {
879     char *argv[] = {
880         const_cast<char*>(TOOL_NAME.c_str()),
881         const_cast<char*>("disable"),
882         const_cast<char*>("-n"),
883         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
884         const_cast<char*>("-a"),
885         const_cast<char*>(""),
886     };
887     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
888     BundleManagerShellCommand cmd(argc, argv);
889     // set the mock objects
890     SetMockObjects(cmd);
891     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_DISABLE);
892 }
893 
894 /**
895  * @tc.number: Bm_Command_Disable_0005
896  * @tc.name: ExecCommand
897  * @tc.desc: Verify the "bm disable -n <bundle-name> -a <ability-name>" command.
898  */
899 HWTEST_F(BmCommandTest, Bm_Command_Disable_0005, Function | MediumTest | Level1)
900 {
901     char *argv[] = {
902         const_cast<char*>(TOOL_NAME.c_str()),
903         const_cast<char*>("disable"),
904         const_cast<char*>("-n"),
905         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
906         const_cast<char*>("-a"),
907         const_cast<char*>(STRING_ABILITY_NAME.c_str()),
908         const_cast<char*>(""),
909     };
910     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
911     BundleManagerShellCommand cmd(argc, argv);
912     // set the mock objects
913     SetMockObjects(cmd);
914     EXPECT_EQ(cmd.ExecCommand(), STRING_DISABLE_BUNDLE_OK + "\n");
915 }
916 
917 /**
918  * @tc.number: Bm_Command_Disable_0006
919  * @tc.name: ExecCommand
920  * @tc.desc: Verify the "bm disable -n <bundle-name> -u <user-id>" command.
921  */
922 HWTEST_F(BmCommandTest, Bm_Command_Disable_0006, Function | MediumTest | Level1)
923 {
924     char *argv[] = {
925         const_cast<char*>(TOOL_NAME.c_str()),
926         const_cast<char*>("disable"),
927         const_cast<char*>("-n"),
928         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
929         const_cast<char*>("-u"),
930         const_cast<char*>(""),
931     };
932     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
933     BundleManagerShellCommand cmd(argc, argv);
934     // set the mock objects
935     SetMockObjects(cmd);
936     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_DISABLE);
937 }
938 
939 /**
940  * @tc.number: Bm_Command_Disable_0007
941  * @tc.name: ExecCommand
942  * @tc.desc: Verify the "bm disable -n <bundle-name> -u <user-id>" command.
943  */
944 HWTEST_F(BmCommandTest, Bm_Command_Disable_0007, Function | MediumTest | Level1)
945 {
946     char *argv[] = {
947         const_cast<char*>(TOOL_NAME.c_str()),
948         const_cast<char*>("disable"),
949         const_cast<char*>("-n"),
950         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
951         const_cast<char*>("-u"),
952         const_cast<char*>("100"),
953         const_cast<char*>(""),
954     };
955     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
956     BundleManagerShellCommand cmd(argc, argv);
957     // set the mock objects
958     SetMockObjects(cmd);
959     EXPECT_EQ(cmd.ExecCommand(), STRING_DISABLE_BUNDLE_OK + "\n");
960 }
961 
962 /**
963  * @tc.number: Bm_Command_Disable_0008
964  * @tc.name: ExecCommand
965  * @tc.desc: Verify the "bm disable -x" command.
966  */
967 HWTEST_F(BmCommandTest, Bm_Command_Disable_0008, Function | MediumTest | Level1)
968 {
969     char *argv[] = {
970         const_cast<char*>(TOOL_NAME.c_str()),
971         const_cast<char*>("disable"),
972         const_cast<char*>("-x"),
973         const_cast<char*>(""),
974     };
975     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
976     BundleManagerShellCommand cmd(argc, argv);
977     // set the mock objects
978     SetMockObjects(cmd);
979     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DISABLE);
980 }
981 
982 /**
983  * @tc.number: Bm_Command_Disable_0009
984  * @tc.name: ExecCommand
985  * @tc.desc: Verify the "bm disable -h" command.
986  */
987 HWTEST_F(BmCommandTest, Bm_Command_Disable_0009, Function | MediumTest | Level1)
988 {
989     char *argv[] = {
990         const_cast<char*>(TOOL_NAME.c_str()),
991         const_cast<char*>("disable"),
992         const_cast<char*>("-h"),
993         const_cast<char*>(""),
994     };
995     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
996     BundleManagerShellCommand cmd(argc, argv);
997     // set the mock objects
998     SetMockObjects(cmd);
999     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_DISABLE);
1000 }
1001 
1002 /**
1003  * @tc.number: Bm_Command_Disable_0011
1004  * @tc.name: ExecCommand
1005  * @tc.desc: Verify the "bm disable -n <bundle-name> -xxx <ability-name>" command.
1006  */
1007 HWTEST_F(BmCommandTest, Bm_Command_Disable_0011, Function | MediumTest | Level1)
1008 {
1009     char *argv[] = {
1010         const_cast<char*>(TOOL_NAME.c_str()),
1011         const_cast<char*>("disable"),
1012         const_cast<char*>("-n"),
1013         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
1014         const_cast<char*>("-XXX"),
1015         const_cast<char*>(STRING_ABILITY_NAME.c_str()),
1016         const_cast<char*>(""),
1017     };
1018     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1019     BundleManagerShellCommand cmd(argc, argv);
1020     // set the mock objects
1021     SetMockObjects(cmd);
1022     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DISABLE);
1023 }
1024 
1025 /**
1026  * @tc.number: Bm_Command_Get_0001
1027  * @tc.name: ExecCommand
1028  * @tc.desc: Verify the "bm get" command.
1029  */
1030 HWTEST_F(BmCommandTest, Bm_Command_Get_0001, Function | MediumTest | Level1)
1031 {
1032     // install a bundle
1033     char *argv[] = {
1034         const_cast<char*>(TOOL_NAME.c_str()),
1035         const_cast<char*>("get"),
1036         const_cast<char*>(""),
1037     };
1038     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1039 
1040     BundleManagerShellCommand cmd(argc, argv);
1041 
1042     // set the mock objects
1043     SetMockObjects(cmd);
1044 
1045     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_GET);
1046 }
1047 
1048 /**
1049  * @tc.number: Bm_Command_Get_0002
1050  * @tc.name: ExecCommand
1051  * @tc.desc: Verify the "bm get -u" command.
1052  */
1053 HWTEST_F(BmCommandTest, Bm_Command_Get_0002, Function | MediumTest | Level1)
1054 {
1055     // install a bundle
1056     char *argv[] = {
1057         const_cast<char*>(TOOL_NAME.c_str()),
1058         const_cast<char*>("get"),
1059         const_cast<char*>("-u"),
1060         const_cast<char*>(""),
1061     };
1062     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1063 
1064     BundleManagerShellCommand cmd(argc, argv);
1065 
1066     // set the mock objects
1067     SetMockObjects(cmd);
1068 
1069     std::string result = cmd.ExecCommand();
1070     auto pos = result.find(STRING_GET_UDID_OK);
1071 
1072     EXPECT_NE(pos, std::string::npos);
1073 }
1074 
1075 /**
1076  * @tc.number: Bm_Command_Get_0003
1077  * @tc.name: ExecCommand
1078  * @tc.desc: Verify the "bm get -x" command.
1079  */
1080 HWTEST_F(BmCommandTest, Bm_Command_Get_0003, Function | MediumTest | Level1)
1081 {
1082     // install a bundle
1083     char *argv[] = {
1084         const_cast<char*>(TOOL_NAME.c_str()),
1085         const_cast<char*>("get"),
1086         const_cast<char*>("-x"),
1087         const_cast<char*>(""),
1088     };
1089     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1090 
1091     BundleManagerShellCommand cmd(argc, argv);
1092 
1093     // set the mock objects
1094     SetMockObjects(cmd);
1095 
1096     EXPECT_EQ(cmd.ExecCommand(), STRING_INCORRECT_OPTION + "\n" + HELP_MSG_GET);
1097 }
1098 
1099 /**
1100  * @tc.number: Bm_Command_Get_0004
1101  * @tc.name: ExecCommand
1102  * @tc.desc: Verify the "bm get -u -x" command.
1103  */
1104 HWTEST_F(BmCommandTest, Bm_Command_Get_0004, Function | MediumTest | Level1)
1105 {
1106     // install a bundle
1107     char *argv[] = {
1108         const_cast<char*>(TOOL_NAME.c_str()),
1109         const_cast<char*>("get"),
1110         const_cast<char*>("-u"),
1111         const_cast<char*>("-x"),
1112         const_cast<char*>(""),
1113     };
1114     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1115 
1116     BundleManagerShellCommand cmd(argc, argv);
1117 
1118     // set the mock objects
1119     SetMockObjects(cmd);
1120 
1121     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
1122 }
1123 
1124 /**
1125  * @tc.number: Bm_Command_Get_0005
1126  * @tc.name: ExecCommand
1127  * @tc.desc: Verify the "bm get -u xxx" command.
1128  */
1129 HWTEST_F(BmCommandTest, Bm_Command_Get_0005, Function | MediumTest | Level1)
1130 {
1131     // install a bundle
1132     char *argv[] = {
1133         const_cast<char*>(TOOL_NAME.c_str()),
1134         const_cast<char*>("get"),
1135         const_cast<char*>("-u"),
1136         const_cast<char*>("xxx"),
1137         const_cast<char*>(""),
1138     };
1139     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1140 
1141     BundleManagerShellCommand cmd(argc, argv);
1142 
1143     // set the mock objects
1144     SetMockObjects(cmd);
1145 
1146     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
1147 }
1148 
1149 /**
1150  * @tc.number: Bm_Command_Get_0006
1151  * @tc.name: ExecCommand
1152  * @tc.desc: Verify the "bm get --udid" command.
1153  */
1154 HWTEST_F(BmCommandTest, Bm_Command_Get_0006, Function | MediumTest | Level1)
1155 {
1156     // install a bundle
1157     char *argv[] = {
1158         const_cast<char*>(TOOL_NAME.c_str()),
1159         const_cast<char*>("get"),
1160         const_cast<char*>("--udid"),
1161         const_cast<char*>(""),
1162     };
1163     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1164 
1165     BundleManagerShellCommand cmd(argc, argv);
1166 
1167     // set the mock objects
1168     SetMockObjects(cmd);
1169 
1170     std::string result = cmd.ExecCommand();
1171     auto pos = result.find(STRING_GET_UDID_OK);
1172 
1173     EXPECT_NE(pos, std::string::npos);
1174 }
1175 
1176 /**
1177  * @tc.number: Bm_Command_Get_0007
1178  * @tc.name: ExecCommand
1179  * @tc.desc: Verify the "bm get --xxx" command.
1180  */
1181 HWTEST_F(BmCommandTest, Bm_Command_Get_0007, Function | MediumTest | Level1)
1182 {
1183     // install a bundle
1184     char *argv[] = {
1185         const_cast<char*>(TOOL_NAME.c_str()),
1186         const_cast<char*>("get"),
1187         const_cast<char*>("--xxx"),
1188         const_cast<char*>(""),
1189     };
1190     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1191 
1192     BundleManagerShellCommand cmd(argc, argv);
1193 
1194     // set the mock objects
1195     SetMockObjects(cmd);
1196 
1197     EXPECT_EQ(cmd.ExecCommand(), STRING_INCORRECT_OPTION + "\n" + HELP_MSG_GET);
1198 }
1199 
1200 /**
1201  * @tc.number: Bm_Command_Get_0008
1202  * @tc.name: ExecCommand
1203  * @tc.desc: Verify the "bm get --udid -x" command.
1204  */
1205 HWTEST_F(BmCommandTest, Bm_Command_Get_0008, Function | MediumTest | Level1)
1206 {
1207     // install a bundle
1208     char *argv[] = {
1209         const_cast<char*>(TOOL_NAME.c_str()),
1210         const_cast<char*>("get"),
1211         const_cast<char*>("--udid"),
1212         const_cast<char*>("-x"),
1213         const_cast<char*>(""),
1214     };
1215     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1216 
1217     BundleManagerShellCommand cmd(argc, argv);
1218 
1219     // set the mock objects
1220     SetMockObjects(cmd);
1221 
1222     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
1223 }
1224 
1225 /**
1226  * @tc.number: Bm_Command_Get_0009
1227  * @tc.name: ExecCommand
1228  * @tc.desc: Verify the "bm get -u xxx" command.
1229  */
1230 HWTEST_F(BmCommandTest, Bm_Command_Get_0009, Function | MediumTest | Level1)
1231 {
1232     // install a bundle
1233     char *argv[] = {
1234         const_cast<char*>(TOOL_NAME.c_str()),
1235         const_cast<char*>("get"),
1236         const_cast<char*>("--udid"),
1237         const_cast<char*>("xxx"),
1238         const_cast<char*>(""),
1239     };
1240     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1241 
1242     BundleManagerShellCommand cmd(argc, argv);
1243 
1244     // set the mock objects
1245     SetMockObjects(cmd);
1246 
1247     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
1248 }
1249 
1250 /**
1251  * @tc.number: Bm_Command_Get_0010
1252  * @tc.name: ExecCommand
1253  * @tc.desc: Verify the "bm get -h" command.
1254  */
1255 HWTEST_F(BmCommandTest, Bm_Command_Get_0010, Function | MediumTest | Level1)
1256 {
1257     // install a bundle
1258     char *argv[] = {
1259         const_cast<char*>(TOOL_NAME.c_str()),
1260         const_cast<char*>("get"),
1261         const_cast<char*>("-h"),
1262         const_cast<char*>(""),
1263     };
1264     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1265 
1266     BundleManagerShellCommand cmd(argc, argv);
1267 
1268     // set the mock objects
1269     SetMockObjects(cmd);
1270 
1271     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
1272 }
1273 
1274 /**
1275  * @tc.number: GetBundlePath_0001
1276  * @tc.name: test GetBundlePath
1277  * @tc.desc: Verify the "GetBundlePath".
1278  */
1279 HWTEST_F(BmCommandTest, GetBundlePath_0001, Function | MediumTest | Level1)
1280 {
1281     // install a bundle
1282     char *argv[] = {
1283         const_cast<char*>(TOOL_NAME.c_str()),
1284         const_cast<char*>("-h"),
1285     };
1286     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1287 
1288     BundleManagerShellCommand cmd(argc, argv);
1289     std::string param = "";
1290     std::vector<std::string> bundlePaths;
1291     auto res = cmd.GetBundlePath(param, bundlePaths);
1292     EXPECT_EQ(res, ERR_INVALID_VALUE);
1293 
1294     param = "-r";
1295     res = cmd.GetBundlePath(param, bundlePaths);
1296     EXPECT_EQ(res, ERR_INVALID_VALUE);
1297 
1298     param = "--replace";
1299     res = cmd.GetBundlePath(param, bundlePaths);
1300     EXPECT_EQ(res, ERR_INVALID_VALUE);
1301 
1302     param = "-p";
1303     res = cmd.GetBundlePath(param, bundlePaths);
1304     EXPECT_EQ(res, ERR_INVALID_VALUE);
1305 
1306     param = "--bundle-path";
1307     res = cmd.GetBundlePath(param, bundlePaths);
1308     EXPECT_EQ(res, ERR_INVALID_VALUE);
1309 
1310     param = "-u";
1311     res = cmd.GetBundlePath(param, bundlePaths);
1312     EXPECT_EQ(res, ERR_INVALID_VALUE);
1313 
1314     param = "--user-id";
1315     res = cmd.GetBundlePath(param, bundlePaths);
1316     EXPECT_EQ(res, ERR_INVALID_VALUE);
1317 
1318     param = "-w";
1319     res = cmd.GetBundlePath(param, bundlePaths);
1320     EXPECT_EQ(res, ERR_INVALID_VALUE);
1321 
1322     param = "--waitting-time";
1323     res = cmd.GetBundlePath(param, bundlePaths);
1324     EXPECT_EQ(res, ERR_INVALID_VALUE);
1325 
1326     param = "-x";
1327     res = cmd.GetBundlePath(param, bundlePaths);
1328     EXPECT_EQ(res, ERR_OK);
1329 }
1330 } // namespace OHOS