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  */
HWTEST_F(BmCommandTest, Bm_Command_0001, Function | MediumTest | Level1)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  */
HWTEST_F(BmCommandTest, Bm_Command_0002, Function | MediumTest | Level1)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  */
HWTEST_F(BmCommandTest, Bm_Command_0003, Function | MediumTest | Level1)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  */
HWTEST_F(BmCommandTest, Bm_Command_0004, Function | MediumTest | Level1)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  */
HWTEST_F(BmCommandTest, Bm_Command_0005, Function | MediumTest | Level1)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  */
HWTEST_F(BmCommandTest, Bm_Command_Clean_0001, Function | MediumTest | Level1)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  */
HWTEST_F(BmCommandTest, Bm_Command_Clean_0002, Function | MediumTest | Level1)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  */
HWTEST_F(BmCommandTest, Bm_Command_Clean_0003, Function | MediumTest | Level1)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  */
HWTEST_F(BmCommandTest, Bm_Command_Clean_0004, Function | MediumTest | Level1)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  */
HWTEST_F(BmCommandTest, Bm_Command_Clean_0005, Function | MediumTest | Level1)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  */
HWTEST_F(BmCommandTest, Bm_Command_Clean_0006, Function | MediumTest | Level1)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  */
HWTEST_F(BmCommandTest, Bm_Command_Clean_0007, Function | MediumTest | Level1)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  */
HWTEST_F(BmCommandTest, Bm_Command_Clean_0008, Function | MediumTest | Level1)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  */
HWTEST_F(BmCommandTest, Bm_Command_Clean_0009, Function | MediumTest | Level1)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  */
HWTEST_F(BmCommandTest, Bm_Command_Clean_0010, Function | MediumTest | Level1)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_0011
470  * @tc.name: ExecCommand
471  * @tc.desc: Verify the "bm clean -n <bundle-name> -d -u XXX" command.
472  */
HWTEST_F(BmCommandTest, Bm_Command_Clean_0011, Function | MediumTest | Level1)473 HWTEST_F(BmCommandTest, Bm_Command_Clean_0011, 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*>("XXX"),
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_0012
495  * @tc.name: ExecCommand
496  * @tc.desc: Verify the "bm clean -n <bundle-name> -d -u <user-id>" command.
497  */
HWTEST_F(BmCommandTest, Bm_Command_Clean_0012, Function | MediumTest | Level1)498 HWTEST_F(BmCommandTest, Bm_Command_Clean_0012, Function | MediumTest | Level1)
499 {
500     char *argv[] = {
501         const_cast<char*>(TOOL_NAME.c_str()),
502         const_cast<char*>("clean"),
503         const_cast<char*>("-n"),
504         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
505         const_cast<char*>("-d"),
506         const_cast<char*>(" "),
507         const_cast<char*>("-u"),
508         const_cast<char*>(DEFAULT_USER_ID.c_str()),
509         const_cast<char*>(""),
510     };
511     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
512     BundleManagerShellCommand cmd(argc, argv);
513     // set the mock objects
514     SetMockObjects(cmd);
515     EXPECT_EQ(cmd.ExecCommand(), STRING_CLEAN_DATA_BUNDLE_NG + "\n");
516 }
517 
518 /**
519  * @tc.number: Bm_Command_Clean_0013
520  * @tc.name: ExecCommand
521  * @tc.desc: Verify the "bm clean -h" command.
522  */
HWTEST_F(BmCommandTest, Bm_Command_Clean_0013, Function | MediumTest | Level1)523 HWTEST_F(BmCommandTest, Bm_Command_Clean_0013, Function | MediumTest | Level1)
524 {
525     char *argv[] = {
526         const_cast<char*>(TOOL_NAME.c_str()),
527         const_cast<char*>("clean"),
528         const_cast<char*>("-h"),
529     };
530     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
531     BundleManagerShellCommand cmd(argc, argv);
532     // set the mock objects
533     SetMockObjects(cmd);
534     EXPECT_EQ(cmd.ExecCommand(), "error: you must specify an option at least.\n" + HELP_MSG_CLEAN);
535 }
536 
537 /**
538  * @tc.number: Bm_Command_Clean_0014
539  * @tc.name: ExecCommand
540  * @tc.desc: Verify the "bm clean -xxx" command.
541  */
HWTEST_F(BmCommandTest, Bm_Command_Clean_0014, Function | MediumTest | Level1)542 HWTEST_F(BmCommandTest, Bm_Command_Clean_0014, Function | MediumTest | Level1)
543 {
544     char *argv[] = {
545         const_cast<char*>(TOOL_NAME.c_str()),
546         const_cast<char*>("clean"),
547         const_cast<char*>("-XXX"),
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_0015
559  * @tc.name: ExecCommand
560  * @tc.desc: Verify the "bm clean -n <bundle-name> -d -xxx <user-id>" command.
561  */
HWTEST_F(BmCommandTest, Bm_Command_Clean_0015, Function | MediumTest | Level1)562 HWTEST_F(BmCommandTest, Bm_Command_Clean_0015, Function | MediumTest | Level1)
563 {
564     char *argv[] = {
565         const_cast<char*>(TOOL_NAME.c_str()),
566         const_cast<char*>("clean"),
567         const_cast<char*>("-n"),
568         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
569         const_cast<char*>("-d"),
570         const_cast<char*>(" "),
571         const_cast<char*>("-XXX"),
572         const_cast<char*>(DEFAULT_USER_ID.c_str()),
573         const_cast<char*>(""),
574     };
575     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
576     BundleManagerShellCommand cmd(argc, argv);
577     // set the mock objects
578     SetMockObjects(cmd);
579     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_CLEAN);
580 }
581 
582 /**
583  * @tc.number: Bm_Command_Clean_0016
584  * @tc.name: ExecCommand
585  * @tc.desc: Verify the "bm clean -xxx <bundle-name>" command.
586  */
HWTEST_F(BmCommandTest, Bm_Command_Clean_0016, Function | MediumTest | Level1)587 HWTEST_F(BmCommandTest, Bm_Command_Clean_0016, Function | MediumTest | Level1)
588 {
589     char *argv[] = {
590         const_cast<char*>(TOOL_NAME.c_str()),
591         const_cast<char*>("clean"),
592         const_cast<char*>("-xxx"),
593         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
594         const_cast<char*>(""),
595     };
596     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
597     BundleManagerShellCommand cmd(argc, argv);
598     // set the mock objects
599     SetMockObjects(cmd);
600     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_CLEAN);
601 }
602 
603 /**
604  * @tc.number: Bm_Command_Clean_0017
605  * @tc.name: ExecCommand
606  * @tc.desc: Verify the "bm clean -h" command.
607  */
HWTEST_F(BmCommandTest, Bm_Command_Clean_0017, Function | MediumTest | Level1)608 HWTEST_F(BmCommandTest, Bm_Command_Clean_0017, Function | MediumTest | Level1)
609 {
610     char *argv[] = {
611         const_cast<char*>(TOOL_NAME.c_str()),
612         const_cast<char*>("clean"),
613         const_cast<char*>("-h"),
614         const_cast<char*>(""),
615     };
616     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
617     BundleManagerShellCommand cmd(argc, argv);
618     // set the mock objects
619     SetMockObjects(cmd);
620     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_CLEAN);
621 }
622 
623 /**
624  * @tc.number: Bm_Command_Enable_0001
625  * @tc.name: ExecCommand
626  * @tc.desc: Verify the "bm enable" command.
627  */
HWTEST_F(BmCommandTest, Bm_Command_Enable_0001, Function | MediumTest | Level1)628 HWTEST_F(BmCommandTest, Bm_Command_Enable_0001, Function | MediumTest | Level1)
629 {
630     char *argv[] = {
631         const_cast<char*>(TOOL_NAME.c_str()),
632         const_cast<char*>("enable"),
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(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_ENABLE);
640 }
641 
642 /**
643  * @tc.number: Bm_Command_Enable_0002
644  * @tc.name: ExecCommand
645  * @tc.desc: Verify the "bm enable -n <bundle-name>" command.
646  */
HWTEST_F(BmCommandTest, Bm_Command_Enable_0002, Function | MediumTest | Level1)647 HWTEST_F(BmCommandTest, Bm_Command_Enable_0002, 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*>(""),
654     };
655     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
656     BundleManagerShellCommand cmd(argc, argv);
657     // set the mock objects
658     SetMockObjects(cmd);
659     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_ENABLE);
660 }
661 
662 /**
663  * @tc.number: Bm_Command_Enable_0003
664  * @tc.name: ExecCommand
665  * @tc.desc: Verify the "bm enable -n <bundle-name>" command.
666  */
HWTEST_F(BmCommandTest, Bm_Command_Enable_0003, Function | MediumTest | Level1)667 HWTEST_F(BmCommandTest, Bm_Command_Enable_0003, Function | MediumTest | Level1)
668 {
669     char *argv[] = {
670         const_cast<char*>(TOOL_NAME.c_str()),
671         const_cast<char*>("enable"),
672         const_cast<char*>("-n"),
673         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
674         const_cast<char*>(""),
675     };
676     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
677     BundleManagerShellCommand cmd(argc, argv);
678     // set the mock objects
679     SetMockObjects(cmd);
680     EXPECT_EQ(cmd.ExecCommand(), STRING_ENABLE_BUNDLE_OK + "\n");
681 }
682 
683 /**
684  * @tc.number: Bm_Command_Enable_0004
685  * @tc.name: ExecCommand
686  * @tc.desc: Verify the "bm enable -n <bundle-name> -a <ability-name>" command.
687  */
HWTEST_F(BmCommandTest, Bm_Command_Enable_0004, Function | MediumTest | Level1)688 HWTEST_F(BmCommandTest, Bm_Command_Enable_0004, Function | MediumTest | Level1)
689 {
690     char *argv[] = {
691         const_cast<char*>(TOOL_NAME.c_str()),
692         const_cast<char*>("enable"),
693         const_cast<char*>("-n"),
694         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
695         const_cast<char*>("-a"),
696         const_cast<char*>(""),
697     };
698     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
699     BundleManagerShellCommand cmd(argc, argv);
700     // set the mock objects
701     SetMockObjects(cmd);
702     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_ENABLE);
703 }
704 
705 /**
706  * @tc.number: Bm_Command_Enable_0005
707  * @tc.name: ExecCommand
708  * @tc.desc: Verify the "bm enable -n <bundle-name> -a <ability-name>" command.
709  */
HWTEST_F(BmCommandTest, Bm_Command_Enable_0005, Function | MediumTest | Level1)710 HWTEST_F(BmCommandTest, Bm_Command_Enable_0005, Function | MediumTest | Level1)
711 {
712     char *argv[] = {
713         const_cast<char*>(TOOL_NAME.c_str()),
714         const_cast<char*>("enable"),
715         const_cast<char*>("-n"),
716         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
717         const_cast<char*>("-a"),
718         const_cast<char*>(STRING_ABILITY_NAME.c_str()),
719         const_cast<char*>(""),
720     };
721     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
722     BundleManagerShellCommand cmd(argc, argv);
723     // set the mock objects
724     SetMockObjects(cmd);
725     EXPECT_EQ(cmd.ExecCommand(), STRING_ENABLE_BUNDLE_OK + "\n");
726 }
727 
728 /**
729  * @tc.number: Bm_Command_Enable_0006
730  * @tc.name: ExecCommand
731  * @tc.desc: Verify the "bm enable -x" command.
732  */
HWTEST_F(BmCommandTest, Bm_Command_Enable_0006, Function | MediumTest | Level1)733 HWTEST_F(BmCommandTest, Bm_Command_Enable_0006, Function | MediumTest | Level1)
734 {
735     char *argv[] = {
736         const_cast<char*>(TOOL_NAME.c_str()),
737         const_cast<char*>("enable"),
738         const_cast<char*>("-x"),
739         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
740         const_cast<char*>(""),
741     };
742     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
743     BundleManagerShellCommand cmd(argc, argv);
744     // set the mock objects
745     SetMockObjects(cmd);
746     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_ENABLE);
747 }
748 
749 /**
750  * @tc.number: Bm_Command_Enable_0007
751  * @tc.name: ExecCommand
752  * @tc.desc: Verify the "bm enable -n <bundle-name> -u" command.
753  */
HWTEST_F(BmCommandTest, Bm_Command_Enable_0007, Function | MediumTest | Level1)754 HWTEST_F(BmCommandTest, Bm_Command_Enable_0007, Function | MediumTest | Level1)
755 {
756     char *argv[] = {
757         const_cast<char*>(TOOL_NAME.c_str()),
758         const_cast<char*>("enable"),
759         const_cast<char*>("-n"),
760         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
761         const_cast<char*>("-u"),
762         const_cast<char*>(""),
763     };
764     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
765     BundleManagerShellCommand cmd(argc, argv);
766     // set the mock objects
767     SetMockObjects(cmd);
768     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_ENABLE);
769 }
770 
771 /**
772  * @tc.number: Bm_Command_Enable_0008
773  * @tc.name: ExecCommand
774  * @tc.desc: Verify the "bm enable -n <bundle-name> -u XXX" command.
775  */
HWTEST_F(BmCommandTest, Bm_Command_Enable_0008, Function | MediumTest | Level1)776 HWTEST_F(BmCommandTest, Bm_Command_Enable_0008, Function | MediumTest | Level1)
777 {
778     char *argv[] = {
779         const_cast<char*>(TOOL_NAME.c_str()),
780         const_cast<char*>("enable"),
781         const_cast<char*>("-n"),
782         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
783         const_cast<char*>("-u"),
784         const_cast<char*>("XXX"),
785         const_cast<char*>(""),
786     };
787     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
788     BundleManagerShellCommand cmd(argc, argv);
789     // set the mock objects
790     SetMockObjects(cmd);
791     EXPECT_EQ(cmd.ExecCommand(), STRING_ENABLE_BUNDLE_OK + "\n");
792 }
793 
794 /**
795  * @tc.number: Bm_Command_Enable_0009
796  * @tc.name: ExecCommand
797  * @tc.desc: Verify the "bm enable -n <bundle-name> -u <user-id>" command.
798  */
HWTEST_F(BmCommandTest, Bm_Command_Enable_0009, Function | MediumTest | Level1)799 HWTEST_F(BmCommandTest, Bm_Command_Enable_0009, Function | MediumTest | Level1)
800 {
801     char *argv[] = {
802         const_cast<char*>(TOOL_NAME.c_str()),
803         const_cast<char*>("enable"),
804         const_cast<char*>("-n"),
805         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
806         const_cast<char*>("-u"),
807         const_cast<char*>(DEFAULT_USER_ID.c_str()),
808         const_cast<char*>(""),
809     };
810     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
811     BundleManagerShellCommand cmd(argc, argv);
812     // set the mock objects
813     SetMockObjects(cmd);
814     EXPECT_EQ(cmd.ExecCommand(), STRING_ENABLE_BUNDLE_OK + "\n");
815 }
816 
817 /**
818  * @tc.number: Bm_Command_Enable_0010
819  * @tc.name: ExecCommand
820  * @tc.desc: Verify the "bm enable -h" command.
821  */
HWTEST_F(BmCommandTest, Bm_Command_Enable_0010, Function | MediumTest | Level1)822 HWTEST_F(BmCommandTest, Bm_Command_Enable_0010, Function | MediumTest | Level1)
823 {
824     char *argv[] = {
825         const_cast<char*>(TOOL_NAME.c_str()),
826         const_cast<char*>("enable"),
827         const_cast<char*>("-h"),
828         const_cast<char*>(""),
829     };
830     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
831     BundleManagerShellCommand cmd(argc, argv);
832     // set the mock objects
833     SetMockObjects(cmd);
834     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_ENABLE);
835 }
836 
837 /**
838  * @tc.number: Bm_Command_Enable_0011
839  * @tc.name: ExecCommand
840  * @tc.desc: Verify the "bm enable -n <bundle-name> -xxx <user-id>" command.
841  */
HWTEST_F(BmCommandTest, Bm_Command_Enable_0011, Function | MediumTest | Level1)842 HWTEST_F(BmCommandTest, Bm_Command_Enable_0011, Function | MediumTest | Level1)
843 {
844     char *argv[] = {
845         const_cast<char*>(TOOL_NAME.c_str()),
846         const_cast<char*>("enable"),
847         const_cast<char*>("-n"),
848         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
849         const_cast<char*>("-XXX"),
850         const_cast<char*>(DEFAULT_USER_ID.c_str()),
851         const_cast<char*>(""),
852     };
853     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
854     BundleManagerShellCommand cmd(argc, argv);
855     // set the mock objects
856     SetMockObjects(cmd);
857     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_ENABLE);
858 }
859 
860 /**
861  * @tc.number: Bm_Command_Disable_0001
862  * @tc.name: ExecCommand
863  * @tc.desc: Verify the "bm disable" command.
864  */
HWTEST_F(BmCommandTest, Bm_Command_Disable_0001, Function | MediumTest | Level1)865 HWTEST_F(BmCommandTest, Bm_Command_Disable_0001, Function | MediumTest | Level1)
866 {
867     char *argv[] = {
868         const_cast<char*>(TOOL_NAME.c_str()),
869         const_cast<char*>("disable"),
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(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_DISABLE);
877 }
878 
879 /**
880  * @tc.number: Bm_Command_Disable_0002
881  * @tc.name: ExecCommand
882  * @tc.desc: Verify the "bm disable -n <bundle-name>" command.
883  */
HWTEST_F(BmCommandTest, Bm_Command_Disable_0002, Function | MediumTest | Level1)884 HWTEST_F(BmCommandTest, Bm_Command_Disable_0002, 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*>(""),
891     };
892     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
893     BundleManagerShellCommand cmd(argc, argv);
894     // set the mock objects
895     SetMockObjects(cmd);
896     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_DISABLE);
897 }
898 
899 /**
900  * @tc.number: Bm_Command_Disable_0003
901  * @tc.name: ExecCommand
902  * @tc.desc: Verify the "bm disable -n <bundle-name>" command.
903  */
HWTEST_F(BmCommandTest, Bm_Command_Disable_0003, Function | MediumTest | Level1)904 HWTEST_F(BmCommandTest, Bm_Command_Disable_0003, Function | MediumTest | Level1)
905 {
906     char *argv[] = {
907         const_cast<char*>(TOOL_NAME.c_str()),
908         const_cast<char*>("disable"),
909         const_cast<char*>("-n"),
910         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
911         const_cast<char*>(""),
912     };
913     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
914     BundleManagerShellCommand cmd(argc, argv);
915     // set the mock objects
916     SetMockObjects(cmd);
917     EXPECT_EQ(cmd.ExecCommand(), STRING_DISABLE_BUNDLE_OK + "\n");
918 }
919 
920 /**
921  * @tc.number: Bm_Command_Disable_0004
922  * @tc.name: ExecCommand
923  * @tc.desc: Verify the "bm disable -n <bundle-name> -a <ability-name>" command.
924  */
HWTEST_F(BmCommandTest, Bm_Command_Disable_0004, Function | MediumTest | Level1)925 HWTEST_F(BmCommandTest, Bm_Command_Disable_0004, Function | MediumTest | Level1)
926 {
927     char *argv[] = {
928         const_cast<char*>(TOOL_NAME.c_str()),
929         const_cast<char*>("disable"),
930         const_cast<char*>("-n"),
931         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
932         const_cast<char*>("-a"),
933         const_cast<char*>(""),
934     };
935     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
936     BundleManagerShellCommand cmd(argc, argv);
937     // set the mock objects
938     SetMockObjects(cmd);
939     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_DISABLE);
940 }
941 
942 /**
943  * @tc.number: Bm_Command_Disable_0005
944  * @tc.name: ExecCommand
945  * @tc.desc: Verify the "bm disable -n <bundle-name> -a <ability-name>" command.
946  */
HWTEST_F(BmCommandTest, Bm_Command_Disable_0005, Function | MediumTest | Level1)947 HWTEST_F(BmCommandTest, Bm_Command_Disable_0005, Function | MediumTest | Level1)
948 {
949     char *argv[] = {
950         const_cast<char*>(TOOL_NAME.c_str()),
951         const_cast<char*>("disable"),
952         const_cast<char*>("-n"),
953         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
954         const_cast<char*>("-a"),
955         const_cast<char*>(STRING_ABILITY_NAME.c_str()),
956         const_cast<char*>(""),
957     };
958     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
959     BundleManagerShellCommand cmd(argc, argv);
960     // set the mock objects
961     SetMockObjects(cmd);
962     EXPECT_EQ(cmd.ExecCommand(), STRING_DISABLE_BUNDLE_OK + "\n");
963 }
964 
965 /**
966  * @tc.number: Bm_Command_Disable_0006
967  * @tc.name: ExecCommand
968  * @tc.desc: Verify the "bm disable -n <bundle-name> -u <user-id>" command.
969  */
HWTEST_F(BmCommandTest, Bm_Command_Disable_0006, Function | MediumTest | Level1)970 HWTEST_F(BmCommandTest, Bm_Command_Disable_0006, Function | MediumTest | Level1)
971 {
972     char *argv[] = {
973         const_cast<char*>(TOOL_NAME.c_str()),
974         const_cast<char*>("disable"),
975         const_cast<char*>("-n"),
976         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
977         const_cast<char*>("-u"),
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(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_DISABLE);
985 }
986 
987 /**
988  * @tc.number: Bm_Command_Disable_0007
989  * @tc.name: ExecCommand
990  * @tc.desc: Verify the "bm disable -n <bundle-name> -u <user-id>" command.
991  */
HWTEST_F(BmCommandTest, Bm_Command_Disable_0007, Function | MediumTest | Level1)992 HWTEST_F(BmCommandTest, Bm_Command_Disable_0007, Function | MediumTest | Level1)
993 {
994     char *argv[] = {
995         const_cast<char*>(TOOL_NAME.c_str()),
996         const_cast<char*>("disable"),
997         const_cast<char*>("-n"),
998         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
999         const_cast<char*>("-u"),
1000         const_cast<char*>("100"),
1001         const_cast<char*>(""),
1002     };
1003     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1004     BundleManagerShellCommand cmd(argc, argv);
1005     // set the mock objects
1006     SetMockObjects(cmd);
1007     EXPECT_EQ(cmd.ExecCommand(), STRING_DISABLE_BUNDLE_OK + "\n");
1008 }
1009 
1010 /**
1011  * @tc.number: Bm_Command_Disable_0008
1012  * @tc.name: ExecCommand
1013  * @tc.desc: Verify the "bm disable -x" command.
1014  */
HWTEST_F(BmCommandTest, Bm_Command_Disable_0008, Function | MediumTest | Level1)1015 HWTEST_F(BmCommandTest, Bm_Command_Disable_0008, Function | MediumTest | Level1)
1016 {
1017     char *argv[] = {
1018         const_cast<char*>(TOOL_NAME.c_str()),
1019         const_cast<char*>("disable"),
1020         const_cast<char*>("-x"),
1021         const_cast<char*>(""),
1022     };
1023     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1024     BundleManagerShellCommand cmd(argc, argv);
1025     // set the mock objects
1026     SetMockObjects(cmd);
1027     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DISABLE);
1028 }
1029 
1030 /**
1031  * @tc.number: Bm_Command_Disable_0009
1032  * @tc.name: ExecCommand
1033  * @tc.desc: Verify the "bm disable -h" command.
1034  */
HWTEST_F(BmCommandTest, Bm_Command_Disable_0009, Function | MediumTest | Level1)1035 HWTEST_F(BmCommandTest, Bm_Command_Disable_0009, Function | MediumTest | Level1)
1036 {
1037     char *argv[] = {
1038         const_cast<char*>(TOOL_NAME.c_str()),
1039         const_cast<char*>("disable"),
1040         const_cast<char*>("-h"),
1041         const_cast<char*>(""),
1042     };
1043     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1044     BundleManagerShellCommand cmd(argc, argv);
1045     // set the mock objects
1046     SetMockObjects(cmd);
1047     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_DISABLE);
1048 }
1049 
1050 /**
1051  * @tc.number: Bm_Command_Disable_0010
1052  * @tc.name: ExecCommand
1053  * @tc.desc: Verify the "bm disable -n <bundle-name> -u XXX" command.
1054  */
HWTEST_F(BmCommandTest, Bm_Command_Disable_0010, Function | MediumTest | Level1)1055 HWTEST_F(BmCommandTest, Bm_Command_Disable_0010, Function | MediumTest | Level1)
1056 {
1057     char *argv[] = {
1058         const_cast<char*>(TOOL_NAME.c_str()),
1059         const_cast<char*>("disable"),
1060         const_cast<char*>("-u"),
1061         const_cast<char*>("XXX"),
1062         const_cast<char*>(""),
1063     };
1064     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1065     BundleManagerShellCommand cmd(argc, argv);
1066     // set the mock objects
1067     SetMockObjects(cmd);
1068     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_BUNDLE_NAME_OPTION + "\n" + HELP_MSG_DISABLE);
1069 }
1070 
1071 /**
1072  * @tc.number: Bm_Command_Disable_0011
1073  * @tc.name: ExecCommand
1074  * @tc.desc: Verify the "bm disable -n <bundle-name> -xxx <ability-name>" command.
1075  */
HWTEST_F(BmCommandTest, Bm_Command_Disable_0011, Function | MediumTest | Level1)1076 HWTEST_F(BmCommandTest, Bm_Command_Disable_0011, Function | MediumTest | Level1)
1077 {
1078     char *argv[] = {
1079         const_cast<char*>(TOOL_NAME.c_str()),
1080         const_cast<char*>("disable"),
1081         const_cast<char*>("-n"),
1082         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
1083         const_cast<char*>("-XXX"),
1084         const_cast<char*>(STRING_ABILITY_NAME.c_str()),
1085         const_cast<char*>(""),
1086     };
1087     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1088     BundleManagerShellCommand cmd(argc, argv);
1089     // set the mock objects
1090     SetMockObjects(cmd);
1091     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DISABLE);
1092 }
1093 
1094 /**
1095  * @tc.number: Bm_Command_Get_0001
1096  * @tc.name: ExecCommand
1097  * @tc.desc: Verify the "bm get" command.
1098  */
HWTEST_F(BmCommandTest, Bm_Command_Get_0001, Function | MediumTest | Level1)1099 HWTEST_F(BmCommandTest, Bm_Command_Get_0001, Function | MediumTest | Level1)
1100 {
1101     // install a bundle
1102     char *argv[] = {
1103         const_cast<char*>(TOOL_NAME.c_str()),
1104         const_cast<char*>("get"),
1105         const_cast<char*>(""),
1106     };
1107     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1108 
1109     BundleManagerShellCommand cmd(argc, argv);
1110 
1111     // set the mock objects
1112     SetMockObjects(cmd);
1113 
1114     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_GET);
1115 }
1116 
1117 /**
1118  * @tc.number: Bm_Command_Get_0002
1119  * @tc.name: ExecCommand
1120  * @tc.desc: Verify the "bm get -u" command.
1121  */
HWTEST_F(BmCommandTest, Bm_Command_Get_0002, Function | MediumTest | Level1)1122 HWTEST_F(BmCommandTest, Bm_Command_Get_0002, Function | MediumTest | Level1)
1123 {
1124     // install a bundle
1125     char *argv[] = {
1126         const_cast<char*>(TOOL_NAME.c_str()),
1127         const_cast<char*>("get"),
1128         const_cast<char*>("-u"),
1129         const_cast<char*>(""),
1130     };
1131     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1132 
1133     BundleManagerShellCommand cmd(argc, argv);
1134 
1135     // set the mock objects
1136     SetMockObjects(cmd);
1137 
1138     std::string result = cmd.ExecCommand();
1139     auto pos = result.find(STRING_GET_UDID_OK);
1140 
1141     EXPECT_NE(pos, std::string::npos);
1142 }
1143 
1144 /**
1145  * @tc.number: Bm_Command_Get_0003
1146  * @tc.name: ExecCommand
1147  * @tc.desc: Verify the "bm get -x" command.
1148  */
HWTEST_F(BmCommandTest, Bm_Command_Get_0003, Function | MediumTest | Level1)1149 HWTEST_F(BmCommandTest, Bm_Command_Get_0003, Function | MediumTest | Level1)
1150 {
1151     // install a bundle
1152     char *argv[] = {
1153         const_cast<char*>(TOOL_NAME.c_str()),
1154         const_cast<char*>("get"),
1155         const_cast<char*>("-x"),
1156         const_cast<char*>(""),
1157     };
1158     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1159 
1160     BundleManagerShellCommand cmd(argc, argv);
1161 
1162     // set the mock objects
1163     SetMockObjects(cmd);
1164 
1165     EXPECT_EQ(cmd.ExecCommand(), STRING_INCORRECT_OPTION + "\n" + HELP_MSG_GET);
1166 }
1167 
1168 /**
1169  * @tc.number: Bm_Command_Get_0004
1170  * @tc.name: ExecCommand
1171  * @tc.desc: Verify the "bm get -u -x" command.
1172  */
HWTEST_F(BmCommandTest, Bm_Command_Get_0004, Function | MediumTest | Level1)1173 HWTEST_F(BmCommandTest, Bm_Command_Get_0004, Function | MediumTest | Level1)
1174 {
1175     // install a bundle
1176     char *argv[] = {
1177         const_cast<char*>(TOOL_NAME.c_str()),
1178         const_cast<char*>("get"),
1179         const_cast<char*>("-u"),
1180         const_cast<char*>("-x"),
1181         const_cast<char*>(""),
1182     };
1183     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1184 
1185     BundleManagerShellCommand cmd(argc, argv);
1186 
1187     // set the mock objects
1188     SetMockObjects(cmd);
1189 
1190     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
1191 }
1192 
1193 /**
1194  * @tc.number: Bm_Command_Get_0005
1195  * @tc.name: ExecCommand
1196  * @tc.desc: Verify the "bm get -u xxx" command.
1197  */
HWTEST_F(BmCommandTest, Bm_Command_Get_0005, Function | MediumTest | Level1)1198 HWTEST_F(BmCommandTest, Bm_Command_Get_0005, Function | MediumTest | Level1)
1199 {
1200     // install a bundle
1201     char *argv[] = {
1202         const_cast<char*>(TOOL_NAME.c_str()),
1203         const_cast<char*>("get"),
1204         const_cast<char*>("-u"),
1205         const_cast<char*>("xxx"),
1206         const_cast<char*>(""),
1207     };
1208     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1209 
1210     BundleManagerShellCommand cmd(argc, argv);
1211 
1212     // set the mock objects
1213     SetMockObjects(cmd);
1214 
1215     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
1216 }
1217 
1218 /**
1219  * @tc.number: Bm_Command_Get_0006
1220  * @tc.name: ExecCommand
1221  * @tc.desc: Verify the "bm get --udid" command.
1222  */
HWTEST_F(BmCommandTest, Bm_Command_Get_0006, Function | MediumTest | Level1)1223 HWTEST_F(BmCommandTest, Bm_Command_Get_0006, Function | MediumTest | Level1)
1224 {
1225     // install a bundle
1226     char *argv[] = {
1227         const_cast<char*>(TOOL_NAME.c_str()),
1228         const_cast<char*>("get"),
1229         const_cast<char*>("--udid"),
1230         const_cast<char*>(""),
1231     };
1232     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1233 
1234     BundleManagerShellCommand cmd(argc, argv);
1235 
1236     // set the mock objects
1237     SetMockObjects(cmd);
1238 
1239     std::string result = cmd.ExecCommand();
1240     auto pos = result.find(STRING_GET_UDID_OK);
1241 
1242     EXPECT_NE(pos, std::string::npos);
1243 }
1244 
1245 /**
1246  * @tc.number: Bm_Command_Get_0007
1247  * @tc.name: ExecCommand
1248  * @tc.desc: Verify the "bm get --xxx" command.
1249  */
HWTEST_F(BmCommandTest, Bm_Command_Get_0007, Function | MediumTest | Level1)1250 HWTEST_F(BmCommandTest, Bm_Command_Get_0007, Function | MediumTest | Level1)
1251 {
1252     // install a bundle
1253     char *argv[] = {
1254         const_cast<char*>(TOOL_NAME.c_str()),
1255         const_cast<char*>("get"),
1256         const_cast<char*>("--xxx"),
1257         const_cast<char*>(""),
1258     };
1259     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1260 
1261     BundleManagerShellCommand cmd(argc, argv);
1262 
1263     // set the mock objects
1264     SetMockObjects(cmd);
1265 
1266     EXPECT_EQ(cmd.ExecCommand(), STRING_INCORRECT_OPTION + "\n" + HELP_MSG_GET);
1267 }
1268 
1269 /**
1270  * @tc.number: Bm_Command_Get_0008
1271  * @tc.name: ExecCommand
1272  * @tc.desc: Verify the "bm get --udid -x" command.
1273  */
HWTEST_F(BmCommandTest, Bm_Command_Get_0008, Function | MediumTest | Level1)1274 HWTEST_F(BmCommandTest, Bm_Command_Get_0008, Function | MediumTest | Level1)
1275 {
1276     // install a bundle
1277     char *argv[] = {
1278         const_cast<char*>(TOOL_NAME.c_str()),
1279         const_cast<char*>("get"),
1280         const_cast<char*>("--udid"),
1281         const_cast<char*>("-x"),
1282         const_cast<char*>(""),
1283     };
1284     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1285 
1286     BundleManagerShellCommand cmd(argc, argv);
1287 
1288     // set the mock objects
1289     SetMockObjects(cmd);
1290 
1291     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
1292 }
1293 
1294 /**
1295  * @tc.number: Bm_Command_Get_0009
1296  * @tc.name: ExecCommand
1297  * @tc.desc: Verify the "bm get -u xxx" command.
1298  */
HWTEST_F(BmCommandTest, Bm_Command_Get_0009, Function | MediumTest | Level1)1299 HWTEST_F(BmCommandTest, Bm_Command_Get_0009, Function | MediumTest | Level1)
1300 {
1301     // install a bundle
1302     char *argv[] = {
1303         const_cast<char*>(TOOL_NAME.c_str()),
1304         const_cast<char*>("get"),
1305         const_cast<char*>("--udid"),
1306         const_cast<char*>("xxx"),
1307         const_cast<char*>(""),
1308     };
1309     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1310 
1311     BundleManagerShellCommand cmd(argc, argv);
1312 
1313     // set the mock objects
1314     SetMockObjects(cmd);
1315 
1316     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
1317 }
1318 
1319 /**
1320  * @tc.number: Bm_Command_Get_0010
1321  * @tc.name: ExecCommand
1322  * @tc.desc: Verify the "bm get -h" command.
1323  */
HWTEST_F(BmCommandTest, Bm_Command_Get_0010, Function | MediumTest | Level1)1324 HWTEST_F(BmCommandTest, Bm_Command_Get_0010, Function | MediumTest | Level1)
1325 {
1326     // install a bundle
1327     char *argv[] = {
1328         const_cast<char*>(TOOL_NAME.c_str()),
1329         const_cast<char*>("get"),
1330         const_cast<char*>("-h"),
1331         const_cast<char*>(""),
1332     };
1333     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1334 
1335     BundleManagerShellCommand cmd(argc, argv);
1336 
1337     // set the mock objects
1338     SetMockObjects(cmd);
1339 
1340     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
1341 }
1342 
1343 /**
1344  * @tc.number: GetBundlePath_0001
1345  * @tc.name: test GetBundlePath
1346  * @tc.desc: Verify the "GetBundlePath".
1347  */
HWTEST_F(BmCommandTest, GetBundlePath_0001, Function | MediumTest | Level1)1348 HWTEST_F(BmCommandTest, GetBundlePath_0001, Function | MediumTest | Level1)
1349 {
1350     // install a bundle
1351     char *argv[] = {
1352         const_cast<char*>(TOOL_NAME.c_str()),
1353         const_cast<char*>("-h"),
1354     };
1355     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1356 
1357     BundleManagerShellCommand cmd(argc, argv);
1358     std::string param = "";
1359     std::vector<std::string> bundlePaths;
1360     auto res = cmd.GetBundlePath(param, bundlePaths);
1361     EXPECT_EQ(res, ERR_INVALID_VALUE);
1362 
1363     param = "-r";
1364     res = cmd.GetBundlePath(param, bundlePaths);
1365     EXPECT_EQ(res, ERR_INVALID_VALUE);
1366 
1367     param = "--replace";
1368     res = cmd.GetBundlePath(param, bundlePaths);
1369     EXPECT_EQ(res, ERR_INVALID_VALUE);
1370 
1371     param = "-p";
1372     res = cmd.GetBundlePath(param, bundlePaths);
1373     EXPECT_EQ(res, ERR_INVALID_VALUE);
1374 
1375     param = "--bundle-path";
1376     res = cmd.GetBundlePath(param, bundlePaths);
1377     EXPECT_EQ(res, ERR_INVALID_VALUE);
1378 
1379     param = "-u";
1380     res = cmd.GetBundlePath(param, bundlePaths);
1381     EXPECT_EQ(res, ERR_INVALID_VALUE);
1382 
1383     param = "--user-id";
1384     res = cmd.GetBundlePath(param, bundlePaths);
1385     EXPECT_EQ(res, ERR_INVALID_VALUE);
1386 
1387     param = "-w";
1388     res = cmd.GetBundlePath(param, bundlePaths);
1389     EXPECT_EQ(res, ERR_INVALID_VALUE);
1390 
1391     param = "--waitting-time";
1392     res = cmd.GetBundlePath(param, bundlePaths);
1393     EXPECT_EQ(res, ERR_INVALID_VALUE);
1394 
1395     param = "-x";
1396     res = cmd.GetBundlePath(param, bundlePaths);
1397     EXPECT_EQ(res, ERR_OK);
1398 }
1399 } // namespace OHOS