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