• 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         (char *)TOOL_NAME.c_str(),
95         (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         (char *)TOOL_NAME.c_str(),
116         (char *)"xxx",
117         (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         (char *)TOOL_NAME.c_str(),
138         (char *)"-xxx",
139         (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         (char *)TOOL_NAME.c_str(),
160         (char *)"--xxx",
161         (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         (char *)TOOL_NAME.c_str(),
182         (char *)"help",
183         (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  * @tc.require: AR000GJUII
200  */
201 HWTEST_F(BmCommandTest, Bm_Command_Clean_0001, Function | MediumTest | Level1)
202 {
203     char *argv[] = {
204         (char *)TOOL_NAME.c_str(),
205         (char *)"clean",
206         (char *)"",
207     };
208     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
209     BundleManagerShellCommand cmd(argc, argv);
210     // set the mock objects
211     SetMockObjects(cmd);
212     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_CLEAN);
213 }
214 
215 /**
216  * @tc.number: Bm_Command_Clean_0002
217  * @tc.name: ExecCommand
218  * @tc.desc: Verify the "bm clean xx" command.
219  * @tc.require: AR000GJUII
220  */
221 HWTEST_F(BmCommandTest, Bm_Command_Clean_0002, Function | MediumTest | Level1)
222 {
223     char *argv[] = {
224         (char *)TOOL_NAME.c_str(),
225         (char *)"clean",
226         (char *)"xxx",
227         (char *)"",
228     };
229     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
230     BundleManagerShellCommand cmd(argc, argv);
231     // set the mock objects
232     SetMockObjects(cmd);
233     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_CLEAN);
234 }
235 
236 /**
237  * @tc.number: Bm_Command_Clean_0003
238  * @tc.name: ExecCommand
239  * @tc.desc: Verify the "bm clean -n" command.
240  * @tc.require: AR000GJUII
241  */
242 HWTEST_F(BmCommandTest, Bm_Command_Clean_0003, Function | MediumTest | Level1)
243 {
244     char *argv[] = {
245         (char *)TOOL_NAME.c_str(),
246         (char *)"clean",
247         (char *)"-n",
248         (char *)"",
249     };
250     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
251     BundleManagerShellCommand cmd(argc, argv);
252     // set the mock objects
253     SetMockObjects(cmd);
254     EXPECT_EQ(cmd.ExecCommand(), "error: option requires a value.\n" + HELP_MSG_CLEAN);
255 }
256 
257 /**
258  * @tc.number: Bm_Command_Clean_0004
259  * @tc.name: ExecCommand
260  * @tc.desc: Verify the "bm clean -n <bundle-name>" command.
261  * @tc.require: AR000GJUII
262  */
263 HWTEST_F(BmCommandTest, Bm_Command_Clean_0004, Function | MediumTest | Level1)
264 {
265     char *argv[] = {
266         (char *)TOOL_NAME.c_str(),
267         (char *)"clean",
268         (char *)"-n",
269         (char *)STRING_BUNDLE_NAME.c_str(),
270         (char *)"",
271     };
272     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
273     BundleManagerShellCommand cmd(argc, argv);
274     // set the mock objects
275     SetMockObjects(cmd);
276     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_DATA_OR_CACHE_OPTION + "\n" + HELP_MSG_CLEAN);
277 }
278 
279 /**
280  * @tc.number: Bm_Command_Clean_0005
281  * @tc.name: ExecCommand
282  * @tc.desc: Verify the "bm clean -n <bundle-name> xxx" command.
283  * @tc.require: AR000GJUII
284  */
285 HWTEST_F(BmCommandTest, Bm_Command_Clean_0005, Function | MediumTest | Level1)
286 {
287     char *argv[] = {
288         (char *)TOOL_NAME.c_str(),
289         (char *)"clean",
290         (char *)"-n",
291         (char *)STRING_BUNDLE_NAME.c_str(),
292         (char *)"xxx",
293         (char *)"",
294     };
295     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
296     BundleManagerShellCommand cmd(argc, argv);
297     // set the mock objects
298     SetMockObjects(cmd);
299     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_DATA_OR_CACHE_OPTION + "\n" + HELP_MSG_CLEAN);
300 }
301 
302 /**
303  * @tc.number: Bm_Command_Clean_0006
304  * @tc.name: ExecCommand
305  * @tc.desc: Verify the "bm clean -n <bundle-name> -d" command.
306  * @tc.require: AR000GJUII
307  */
308 HWTEST_F(BmCommandTest, Bm_Command_Clean_0006, Function | MediumTest | Level1)
309 {
310     char *argv[] = {
311         (char *)TOOL_NAME.c_str(),
312         (char *)"clean",
313         (char *)"-n",
314         (char *)STRING_BUNDLE_NAME.c_str(),
315         (char *)"-d",
316         (char *)"",
317     };
318     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
319     BundleManagerShellCommand cmd(argc, argv);
320     // set the mock objects
321     SetMockObjects(cmd);
322     EXPECT_EQ(cmd.ExecCommand(), STRING_CLEAN_DATA_BUNDLE_OK + "\n");
323 }
324 
325 /**
326  * @tc.number: Bm_Command_Clean_0007
327  * @tc.name: ExecCommand
328  * @tc.desc: Verify the "bm clean -n <bundle-name> -c" command.
329  * @tc.require: AR000GJUII
330  */
331 HWTEST_F(BmCommandTest, Bm_Command_Clean_0007, Function | MediumTest | Level1)
332 {
333     char *argv[] = {
334         (char *)TOOL_NAME.c_str(),
335         (char *)"clean",
336         (char *)"-n",
337         (char *)STRING_BUNDLE_NAME.c_str(),
338         (char *)"-c",
339         (char *)"",
340     };
341     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
342     BundleManagerShellCommand cmd(argc, argv);
343     // set the mock objects
344     SetMockObjects(cmd);
345     EXPECT_EQ(cmd.ExecCommand(), STRING_CLEAN_CACHE_BUNDLE_OK + "\n");
346 }
347 
348 /**
349  * @tc.number: Bm_Command_Clean_0008
350  * @tc.name: ExecCommand
351  * @tc.desc: Verify the "bm clean -c" command.
352  * @tc.require: AR000GJUII
353  */
354 HWTEST_F(BmCommandTest, Bm_Command_Clean_0008, Function | MediumTest | Level1)
355 {
356     char *argv[] = {
357         (char *)TOOL_NAME.c_str(),
358         (char *)"clean",
359         (char *)"-c",
360         (char *)"",
361     };
362     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
363     BundleManagerShellCommand cmd(argc, argv);
364     // set the mock objects
365     SetMockObjects(cmd);
366     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_BUNDLE_NAME_OPTION + "\n" + HELP_MSG_CLEAN);
367 }
368 
369 /**
370  * @tc.number: Bm_Command_Clean_0009
371  * @tc.name: ExecCommand
372  * @tc.desc: Verify the "bm clean -d" command.
373  * @tc.require: AR000GJUII
374  */
375 HWTEST_F(BmCommandTest, Bm_Command_Clean_0009, Function | MediumTest | Level1)
376 {
377     char *argv[] = {
378         (char *)TOOL_NAME.c_str(),
379         (char *)"clean",
380         (char *)"-d",
381         (char *)"",
382     };
383     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
384     BundleManagerShellCommand cmd(argc, argv);
385     // set the mock objects
386     SetMockObjects(cmd);
387     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_BUNDLE_NAME_OPTION + "\n" + HELP_MSG_CLEAN);
388 }
389 
390 /**
391  * @tc.number: Bm_Command_Enable_0001
392  * @tc.name: ExecCommand
393  * @tc.desc: Verify the "bm enable" command.
394  * @tc.require: AR000GJUII
395  */
396 HWTEST_F(BmCommandTest, Bm_Command_Enable_0001, Function | MediumTest | Level1)
397 {
398     char *argv[] = {
399         (char *)TOOL_NAME.c_str(),
400         (char *)"enable",
401         (char *)"",
402     };
403     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
404     BundleManagerShellCommand cmd(argc, argv);
405     // set the mock objects
406     SetMockObjects(cmd);
407     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_ENABLE);
408 }
409 
410 /**
411  * @tc.number: Bm_Command_Enable_0002
412  * @tc.name: ExecCommand
413  * @tc.desc: Verify the "bm enable -n <bundle-name>" command.
414  * @tc.require: AR000GJUII
415  */
416 HWTEST_F(BmCommandTest, Bm_Command_Enable_0002, Function | MediumTest | Level1)
417 {
418     char *argv[] = {
419         (char *)TOOL_NAME.c_str(),
420         (char *)"enable",
421         (char *)"-n",
422         (char *)"",
423     };
424     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
425     BundleManagerShellCommand cmd(argc, argv);
426     // set the mock objects
427     SetMockObjects(cmd);
428     EXPECT_EQ(cmd.ExecCommand(), "error: option requires a value.\n" + HELP_MSG_ENABLE);
429 }
430 
431 /**
432  * @tc.number: Bm_Command_Enable_0003
433  * @tc.name: ExecCommand
434  * @tc.desc: Verify the "bm enable -n <bundle-name>" command.
435  * @tc.require: AR000GJUII
436  */
437 HWTEST_F(BmCommandTest, Bm_Command_Enable_0003, Function | MediumTest | Level1)
438 {
439     char *argv[] = {
440         (char *)TOOL_NAME.c_str(),
441         (char *)"enable",
442         (char *)"-n",
443         (char *)STRING_BUNDLE_NAME.c_str(),
444         (char *)"",
445     };
446     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
447     BundleManagerShellCommand cmd(argc, argv);
448     // set the mock objects
449     SetMockObjects(cmd);
450     EXPECT_EQ(cmd.ExecCommand(), STRING_ENABLE_BUNDLE_OK + "\n");
451 }
452 
453 /**
454  * @tc.number: Bm_Command_Enable_0004
455  * @tc.name: ExecCommand
456  * @tc.desc: Verify the "bm enable -n <bundle-name> -a <ability-name>" command.
457  * @tc.require: AR000GJUII
458  */
459 HWTEST_F(BmCommandTest, Bm_Command_Enable_0004, Function | MediumTest | Level1)
460 {
461     char *argv[] = {
462         (char *)TOOL_NAME.c_str(),
463         (char *)"enable",
464         (char *)"-n",
465         (char *)STRING_BUNDLE_NAME.c_str(),
466         (char *)"-a",
467         (char *)"",
468     };
469     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
470     BundleManagerShellCommand cmd(argc, argv);
471     // set the mock objects
472     SetMockObjects(cmd);
473     EXPECT_EQ(cmd.ExecCommand(), "error: option requires a value.\n" + HELP_MSG_ENABLE);
474 }
475 
476 /**
477  * @tc.number: Bm_Command_Enable_0005
478  * @tc.name: ExecCommand
479  * @tc.desc: Verify the "bm enable -n <bundle-name> -a <ability-name>" command.
480  * @tc.require: AR000GJUII
481  */
482 HWTEST_F(BmCommandTest, Bm_Command_Enable_0005, Function | MediumTest | Level1)
483 {
484     char *argv[] = {
485         (char *)TOOL_NAME.c_str(),
486         (char *)"enable",
487         (char *)"-n",
488         (char *)STRING_BUNDLE_NAME.c_str(),
489         (char *)"-a",
490         (char *)STRING_ABILITY_NAME.c_str(),
491         (char *)"",
492     };
493     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
494     BundleManagerShellCommand cmd(argc, argv);
495     // set the mock objects
496     SetMockObjects(cmd);
497     EXPECT_EQ(cmd.ExecCommand(), STRING_ENABLE_BUNDLE_OK + "\n");
498 }
499 
500 /**
501  * @tc.number: Bm_Command_Disable_0001
502  * @tc.name: ExecCommand
503  * @tc.desc: Verify the "bm disable" command.
504  * @tc.require: AR000GJUII
505  */
506 HWTEST_F(BmCommandTest, Bm_Command_Disable_0001, Function | MediumTest | Level1)
507 {
508     char *argv[] = {
509         (char *)TOOL_NAME.c_str(),
510         (char *)"disable",
511         (char *)"",
512     };
513     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
514     BundleManagerShellCommand cmd(argc, argv);
515     // set the mock objects
516     SetMockObjects(cmd);
517     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_DISABLE);
518 }
519 
520 /**
521  * @tc.number: Bm_Command_Disable_0002
522  * @tc.name: ExecCommand
523  * @tc.desc: Verify the "bm disable -n <bundle-name>" command.
524  * @tc.require: AR000GJUII
525  */
526 HWTEST_F(BmCommandTest, Bm_Command_Disable_0002, Function | MediumTest | Level1)
527 {
528     char *argv[] = {
529         (char *)TOOL_NAME.c_str(),
530         (char *)"disable",
531         (char *)"-n",
532         (char *)"",
533     };
534     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
535     BundleManagerShellCommand cmd(argc, argv);
536     // set the mock objects
537     SetMockObjects(cmd);
538     EXPECT_EQ(cmd.ExecCommand(), "error: option requires a value.\n" + HELP_MSG_DISABLE);
539 }
540 
541 /**
542  * @tc.number: Bm_Command_Disable_0003
543  * @tc.name: ExecCommand
544  * @tc.desc: Verify the "bm disable -n <bundle-name>" command.
545  * @tc.require: AR000GJUII
546  */
547 HWTEST_F(BmCommandTest, Bm_Command_Disable_0003, Function | MediumTest | Level1)
548 {
549     char *argv[] = {
550         (char *)TOOL_NAME.c_str(),
551         (char *)"disable",
552         (char *)"-n",
553         (char *)STRING_BUNDLE_NAME.c_str(),
554         (char *)"",
555     };
556     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
557     BundleManagerShellCommand cmd(argc, argv);
558     // set the mock objects
559     SetMockObjects(cmd);
560     EXPECT_EQ(cmd.ExecCommand(), STRING_DISABLE_BUNDLE_OK + "\n");
561 }
562 
563 /**
564  * @tc.number: Bm_Command_Disable_0004
565  * @tc.name: ExecCommand
566  * @tc.desc: Verify the "bm disable -n <bundle-name> -a <ability-name>" command.
567  * @tc.require: AR000GJUII
568  */
569 HWTEST_F(BmCommandTest, Bm_Command_Disable_0004, Function | MediumTest | Level1)
570 {
571     char *argv[] = {
572         (char *)TOOL_NAME.c_str(),
573         (char *)"disable",
574         (char *)"-n",
575         (char *)STRING_BUNDLE_NAME.c_str(),
576         (char *)"-a",
577         (char *)"",
578     };
579     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
580     BundleManagerShellCommand cmd(argc, argv);
581     // set the mock objects
582     SetMockObjects(cmd);
583     EXPECT_EQ(cmd.ExecCommand(), "error: option requires a value.\n" + HELP_MSG_DISABLE);
584 }
585 
586 /**
587  * @tc.number: Bm_Command_Disable_0005
588  * @tc.name: ExecCommand
589  * @tc.desc: Verify the "bm disable -n <bundle-name> -a <ability-name>" command.
590  * @tc.require: AR000GJUII
591  */
592 HWTEST_F(BmCommandTest, Bm_Command_Disable_0005, Function | MediumTest | Level1)
593 {
594     char *argv[] = {
595         (char *)TOOL_NAME.c_str(),
596         (char *)"disable",
597         (char *)"-n",
598         (char *)STRING_BUNDLE_NAME.c_str(),
599         (char *)"-a",
600         (char *)STRING_ABILITY_NAME.c_str(),
601         (char *)"",
602     };
603     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
604     BundleManagerShellCommand cmd(argc, argv);
605     // set the mock objects
606     SetMockObjects(cmd);
607     EXPECT_EQ(cmd.ExecCommand(), STRING_DISABLE_BUNDLE_OK + "\n");
608 }
609 
610 /**
611  * @tc.number: Bm_Command_Disable_0006
612  * @tc.name: ExecCommand
613  * @tc.desc: Verify the "bm disable -n <bundle-name> -u <user-id>" command.
614  * @tc.require: AR000GJUII
615  */
616 HWTEST_F(BmCommandTest, Bm_Command_Disable_0006, Function | MediumTest | Level1)
617 {
618     char *argv[] = {
619         (char *)TOOL_NAME.c_str(),
620         (char *)"disable",
621         (char *)"-n",
622         (char *)STRING_BUNDLE_NAME.c_str(),
623         (char *)"-u",
624         (char *)"",
625     };
626     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
627     BundleManagerShellCommand cmd(argc, argv);
628     // set the mock objects
629     SetMockObjects(cmd);
630     EXPECT_EQ(cmd.ExecCommand(), "error: option requires a value.\n" + HELP_MSG_DISABLE);
631 }
632 
633 /**
634  * @tc.number: Bm_Command_Disable_0007
635  * @tc.name: ExecCommand
636  * @tc.desc: Verify the "bm disable -n <bundle-name> -u <user-id>" command.
637  * @tc.require: AR000GJUII
638  */
639 HWTEST_F(BmCommandTest, Bm_Command_Disable_0007, Function | MediumTest | Level1)
640 {
641     char *argv[] = {
642         (char *)TOOL_NAME.c_str(),
643         (char *)"disable",
644         (char *)"-n",
645         (char *)STRING_BUNDLE_NAME.c_str(),
646         (char *)"-u",
647         (char *)"100",
648         (char *)"",
649     };
650     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
651     BundleManagerShellCommand cmd(argc, argv);
652     // set the mock objects
653     SetMockObjects(cmd);
654     EXPECT_EQ(cmd.ExecCommand(), STRING_DISABLE_BUNDLE_OK + "\n");
655 }
656 
657 /**
658  * @tc.number: Bm_Command_Get_0001
659  * @tc.name: ExecCommand
660  * @tc.desc: Verify the "bm get" command.
661  * @tc.require: AR000GJ4K9
662  */
663 HWTEST_F(BmCommandTest, Bm_Command_Get_0001, Function | MediumTest | Level1)
664 {
665     // install a bundle
666     char *argv[] = {
667         (char *)TOOL_NAME.c_str(),
668         (char *)"get",
669         (char *)"",
670     };
671     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
672 
673     BundleManagerShellCommand cmd(argc, argv);
674 
675     // set the mock objects
676     SetMockObjects(cmd);
677 
678     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_GET);
679 }
680 
681 /**
682  * @tc.number: Bm_Command_Get_0002
683  * @tc.name: ExecCommand
684  * @tc.desc: Verify the "bm get -u" command.
685  * @tc.require: AR000GJ4K9
686  */
687 HWTEST_F(BmCommandTest, Bm_Command_Get_0002, Function | MediumTest | Level1)
688 {
689     // install a bundle
690     char *argv[] = {
691         (char *)TOOL_NAME.c_str(),
692         (char *)"get",
693         (char *)"-u",
694         (char *)"",
695     };
696     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
697 
698     BundleManagerShellCommand cmd(argc, argv);
699 
700     // set the mock objects
701     SetMockObjects(cmd);
702 
703     std::string result = cmd.ExecCommand();
704     auto pos = result.find(STRING_GET_UDID_OK);
705 
706     EXPECT_NE(pos, std::string::npos);
707 }
708 
709 /**
710  * @tc.number: Bm_Command_Get_0003
711  * @tc.name: ExecCommand
712  * @tc.desc: Verify the "bm get -x" command.
713  * @tc.require: AR000GJ4K9
714  */
715 HWTEST_F(BmCommandTest, Bm_Command_Get_0003, Function | MediumTest | Level1)
716 {
717     // install a bundle
718     char *argv[] = {
719         (char *)TOOL_NAME.c_str(),
720         (char *)"get",
721         (char *)"-x",
722         (char *)"",
723     };
724     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
725 
726     BundleManagerShellCommand cmd(argc, argv);
727 
728     // set the mock objects
729     SetMockObjects(cmd);
730 
731     EXPECT_EQ(cmd.ExecCommand(), STRING_INCORRECT_OPTION + "\n" + HELP_MSG_GET);
732 }
733 
734 /**
735  * @tc.number: Bm_Command_Get_0004
736  * @tc.name: ExecCommand
737  * @tc.desc: Verify the "bm get -u -x" command.
738  * @tc.require: AR000GJ4K9
739  */
740 HWTEST_F(BmCommandTest, Bm_Command_Get_0004, Function | MediumTest | Level1)
741 {
742     // install a bundle
743     char *argv[] = {
744         (char *)TOOL_NAME.c_str(),
745         (char *)"get",
746         (char *)"-u",
747         (char *)"-x",
748         (char *)"",
749     };
750     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
751 
752     BundleManagerShellCommand cmd(argc, argv);
753 
754     // set the mock objects
755     SetMockObjects(cmd);
756 
757     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
758 }
759 
760 /**
761  * @tc.number: Bm_Command_Get_0005
762  * @tc.name: ExecCommand
763  * @tc.desc: Verify the "bm get -u xxx" command.
764  * @tc.require: AR000GJ4K9
765  */
766 HWTEST_F(BmCommandTest, Bm_Command_Get_0005, Function | MediumTest | Level1)
767 {
768     // install a bundle
769     char *argv[] = {
770         (char *)TOOL_NAME.c_str(),
771         (char *)"get",
772         (char *)"-u",
773         (char *)"xxx",
774         (char *)"",
775     };
776     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
777 
778     BundleManagerShellCommand cmd(argc, argv);
779 
780     // set the mock objects
781     SetMockObjects(cmd);
782 
783     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
784 }
785 
786 /**
787  * @tc.number: Bm_Command_Get_0006
788  * @tc.name: ExecCommand
789  * @tc.desc: Verify the "bm get --udid" command.
790  * @tc.require: AR000GJ4K9
791  */
792 HWTEST_F(BmCommandTest, Bm_Command_Get_0006, Function | MediumTest | Level1)
793 {
794     // install a bundle
795     char *argv[] = {
796         (char *)TOOL_NAME.c_str(),
797         (char *)"get",
798         (char *)"--udid",
799         (char *)"",
800     };
801     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
802 
803     BundleManagerShellCommand cmd(argc, argv);
804 
805     // set the mock objects
806     SetMockObjects(cmd);
807 
808     std::string result = cmd.ExecCommand();
809     auto pos = result.find(STRING_GET_UDID_OK);
810 
811     EXPECT_NE(pos, std::string::npos);
812 }
813 
814 /**
815  * @tc.number: Bm_Command_Get_0007
816  * @tc.name: ExecCommand
817  * @tc.desc: Verify the "bm get --xxx" command.
818  * @tc.require: AR000GJ4K9
819  */
820 HWTEST_F(BmCommandTest, Bm_Command_Get_0007, Function | MediumTest | Level1)
821 {
822     // install a bundle
823     char *argv[] = {
824         (char *)TOOL_NAME.c_str(),
825         (char *)"get",
826         (char *)"--xxx",
827         (char *)"",
828     };
829     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
830 
831     BundleManagerShellCommand cmd(argc, argv);
832 
833     // set the mock objects
834     SetMockObjects(cmd);
835 
836     EXPECT_EQ(cmd.ExecCommand(), STRING_INCORRECT_OPTION + "\n" + HELP_MSG_GET);
837 }
838 
839 /**
840  * @tc.number: Bm_Command_Get_0008
841  * @tc.name: ExecCommand
842  * @tc.desc: Verify the "bm get --udid -x" command.
843  * @tc.require: AR000GJ4K9
844  */
845 HWTEST_F(BmCommandTest, Bm_Command_Get_0008, Function | MediumTest | Level1)
846 {
847     // install a bundle
848     char *argv[] = {
849         (char *)TOOL_NAME.c_str(),
850         (char *)"get",
851         (char *)"--udid",
852         (char *)"-x",
853         (char *)"",
854     };
855     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
856 
857     BundleManagerShellCommand cmd(argc, argv);
858 
859     // set the mock objects
860     SetMockObjects(cmd);
861 
862     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
863 }
864 
865 /**
866  * @tc.number: Bm_Command_Get_0009
867  * @tc.name: ExecCommand
868  * @tc.desc: Verify the "bm get -u xxx" command.
869  * @tc.require: AR000GJ4K9
870  */
871 HWTEST_F(BmCommandTest, Bm_Command_Get_0009, Function | MediumTest | Level1)
872 {
873     // install a bundle
874     char *argv[] = {
875         (char *)TOOL_NAME.c_str(),
876         (char *)"get",
877         (char *)"--udid",
878         (char *)"xxx",
879         (char *)"",
880     };
881     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
882 
883     BundleManagerShellCommand cmd(argc, argv);
884 
885     // set the mock objects
886     SetMockObjects(cmd);
887 
888     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
889 }
890 } // namespace OHOS