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 * @tc.require: AR000GJUII
200 */
201 HWTEST_F(BmCommandTest, Bm_Command_Clean_0001, Function | MediumTest | Level1)
202 {
203 char *argv[] = {
204 const_cast<char*>(TOOL_NAME.c_str()),
205 const_cast<char*>("clean"),
206 const_cast<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 const_cast<char*>(TOOL_NAME.c_str()),
225 const_cast<char*>("clean"),
226 const_cast<char*>("xxx"),
227 const_cast<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 const_cast<char*>(TOOL_NAME.c_str()),
246 const_cast<char*>("clean"),
247 const_cast<char*>("-n"),
248 const_cast<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(), STRING_REQUIRE_CORRECT_VALUE + 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 const_cast<char*>(TOOL_NAME.c_str()),
267 const_cast<char*>("clean"),
268 const_cast<char*>("-n"),
269 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
270 const_cast<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 const_cast<char*>(TOOL_NAME.c_str()),
289 const_cast<char*>("clean"),
290 const_cast<char*>("-n"),
291 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
292 const_cast<char*>("xxx"),
293 const_cast<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 const_cast<char*>(TOOL_NAME.c_str()),
312 const_cast<char*>("clean"),
313 const_cast<char*>("-n"),
314 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
315 const_cast<char*>("-d"),
316 const_cast<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 const_cast<char*>(TOOL_NAME.c_str()),
335 const_cast<char*>("clean"),
336 const_cast<char*>("-n"),
337 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
338 const_cast<char*>("-c"),
339 const_cast<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 const_cast<char*>(TOOL_NAME.c_str()),
358 const_cast<char*>("clean"),
359 const_cast<char*>("-c"),
360 const_cast<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 const_cast<char*>(TOOL_NAME.c_str()),
379 const_cast<char*>("clean"),
380 const_cast<char*>("-d"),
381 const_cast<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_Clean_0010
392 * @tc.name: ExecCommand
393 * @tc.desc: Verify the "bm clean -n <bundle-name> -d -u" command.
394 */
395 HWTEST_F(BmCommandTest, Bm_Command_Clean_0010, Function | MediumTest | Level1)
396 {
397 char *argv[] = {
398 const_cast<char*>(TOOL_NAME.c_str()),
399 const_cast<char*>("clean"),
400 const_cast<char*>("-n"),
401 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
402 const_cast<char*>("-d"),
403 const_cast<char*>(" "),
404 const_cast<char*>("-u"),
405 const_cast<char*>(""),
406 };
407 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
408 BundleManagerShellCommand cmd(argc, argv);
409 // set the mock objects
410 SetMockObjects(cmd);
411 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_CLEAN);
412 }
413
414 /**
415 * @tc.number: Bm_Command_Clean_0011
416 * @tc.name: ExecCommand
417 * @tc.desc: Verify the "bm clean -n <bundle-name> -d -u XXX" command.
418 */
419 HWTEST_F(BmCommandTest, Bm_Command_Clean_0011, Function | MediumTest | Level1)
420 {
421 char *argv[] = {
422 const_cast<char*>(TOOL_NAME.c_str()),
423 const_cast<char*>("clean"),
424 const_cast<char*>("-n"),
425 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
426 const_cast<char*>("-d"),
427 const_cast<char*>(" "),
428 const_cast<char*>("-u"),
429 const_cast<char*>("XXX"),
430 const_cast<char*>(""),
431 };
432 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
433 BundleManagerShellCommand cmd(argc, argv);
434 // set the mock objects
435 SetMockObjects(cmd);
436 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE);
437 }
438
439 /**
440 * @tc.number: Bm_Command_Clean_0012
441 * @tc.name: ExecCommand
442 * @tc.desc: Verify the "bm clean -n <bundle-name> -d -u <user-id>" command.
443 */
444 HWTEST_F(BmCommandTest, Bm_Command_Clean_0012, Function | MediumTest | Level1)
445 {
446 char *argv[] = {
447 const_cast<char*>(TOOL_NAME.c_str()),
448 const_cast<char*>("clean"),
449 const_cast<char*>("-n"),
450 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
451 const_cast<char*>("-d"),
452 const_cast<char*>(" "),
453 const_cast<char*>("-u"),
454 const_cast<char*>(DEFAULT_USER_ID.c_str()),
455 const_cast<char*>(""),
456 };
457 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
458 BundleManagerShellCommand cmd(argc, argv);
459 // set the mock objects
460 SetMockObjects(cmd);
461 EXPECT_EQ(cmd.ExecCommand(), STRING_CLEAN_DATA_BUNDLE_OK + "\n");
462 }
463
464 /**
465 * @tc.number: Bm_Command_Clean_0013
466 * @tc.name: ExecCommand
467 * @tc.desc: Verify the "bm clean -h" command.
468 */
469 HWTEST_F(BmCommandTest, Bm_Command_Clean_0013, Function | MediumTest | Level1)
470 {
471 char *argv[] = {
472 const_cast<char*>(TOOL_NAME.c_str()),
473 const_cast<char*>("clean"),
474 const_cast<char*>("-h"),
475 };
476 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
477 BundleManagerShellCommand cmd(argc, argv);
478 // set the mock objects
479 SetMockObjects(cmd);
480 EXPECT_EQ(cmd.ExecCommand(), "error: you must specify an option at least.\n" + HELP_MSG_CLEAN);
481 }
482
483 /**
484 * @tc.number: Bm_Command_Clean_0014
485 * @tc.name: ExecCommand
486 * @tc.desc: Verify the "bm clean -xxx" command.
487 */
488 HWTEST_F(BmCommandTest, Bm_Command_Clean_0014, Function | MediumTest | Level1)
489 {
490 char *argv[] = {
491 const_cast<char*>(TOOL_NAME.c_str()),
492 const_cast<char*>("clean"),
493 const_cast<char*>("-XXX"),
494 const_cast<char*>(" "),
495 };
496 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
497 BundleManagerShellCommand cmd(argc, argv);
498 // set the mock objects
499 SetMockObjects(cmd);
500 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_CLEAN);
501 }
502
503 /**
504 * @tc.number: Bm_Command_Clean_0015
505 * @tc.name: ExecCommand
506 * @tc.desc: Verify the "bm clean -n <bundle-name> -d -xxx <user-id>" command.
507 */
508 HWTEST_F(BmCommandTest, Bm_Command_Clean_0015, Function | MediumTest | Level1)
509 {
510 char *argv[] = {
511 const_cast<char*>(TOOL_NAME.c_str()),
512 const_cast<char*>("clean"),
513 const_cast<char*>("-n"),
514 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
515 const_cast<char*>("-d"),
516 const_cast<char*>(" "),
517 const_cast<char*>("-XXX"),
518 const_cast<char*>(DEFAULT_USER_ID.c_str()),
519 const_cast<char*>(""),
520 };
521 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
522 BundleManagerShellCommand cmd(argc, argv);
523 // set the mock objects
524 SetMockObjects(cmd);
525 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_CLEAN);
526 }
527
528 /**
529 * @tc.number: Bm_Command_Clean_0016
530 * @tc.name: ExecCommand
531 * @tc.desc: Verify the "bm clean -xxx <bundle-name>" command.
532 */
533 HWTEST_F(BmCommandTest, Bm_Command_Clean_0016, Function | MediumTest | Level1)
534 {
535 char *argv[] = {
536 const_cast<char*>(TOOL_NAME.c_str()),
537 const_cast<char*>("clean"),
538 const_cast<char*>("-xxx"),
539 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
540 const_cast<char*>(""),
541 };
542 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
543 BundleManagerShellCommand cmd(argc, argv);
544 // set the mock objects
545 SetMockObjects(cmd);
546 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_CLEAN);
547 }
548
549 /**
550 * @tc.number: Bm_Command_Enable_0001
551 * @tc.name: ExecCommand
552 * @tc.desc: Verify the "bm enable" command.
553 * @tc.require: AR000GJUII
554 */
555 HWTEST_F(BmCommandTest, Bm_Command_Enable_0001, Function | MediumTest | Level1)
556 {
557 char *argv[] = {
558 const_cast<char*>(TOOL_NAME.c_str()),
559 const_cast<char*>("enable"),
560 const_cast<char*>(""),
561 };
562 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
563 BundleManagerShellCommand cmd(argc, argv);
564 // set the mock objects
565 SetMockObjects(cmd);
566 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_ENABLE);
567 }
568
569 /**
570 * @tc.number: Bm_Command_Enable_0002
571 * @tc.name: ExecCommand
572 * @tc.desc: Verify the "bm enable -n <bundle-name>" command.
573 * @tc.require: AR000GJUII
574 */
575 HWTEST_F(BmCommandTest, Bm_Command_Enable_0002, Function | MediumTest | Level1)
576 {
577 char *argv[] = {
578 const_cast<char*>(TOOL_NAME.c_str()),
579 const_cast<char*>("enable"),
580 const_cast<char*>("-n"),
581 const_cast<char*>(""),
582 };
583 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
584 BundleManagerShellCommand cmd(argc, argv);
585 // set the mock objects
586 SetMockObjects(cmd);
587 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_ENABLE);
588 }
589
590 /**
591 * @tc.number: Bm_Command_Enable_0003
592 * @tc.name: ExecCommand
593 * @tc.desc: Verify the "bm enable -n <bundle-name>" command.
594 * @tc.require: AR000GJUII
595 */
596 HWTEST_F(BmCommandTest, Bm_Command_Enable_0003, Function | MediumTest | Level1)
597 {
598 char *argv[] = {
599 const_cast<char*>(TOOL_NAME.c_str()),
600 const_cast<char*>("enable"),
601 const_cast<char*>("-n"),
602 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
603 const_cast<char*>(""),
604 };
605 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
606 BundleManagerShellCommand cmd(argc, argv);
607 // set the mock objects
608 SetMockObjects(cmd);
609 EXPECT_EQ(cmd.ExecCommand(), STRING_ENABLE_BUNDLE_OK + "\n");
610 }
611
612 /**
613 * @tc.number: Bm_Command_Enable_0004
614 * @tc.name: ExecCommand
615 * @tc.desc: Verify the "bm enable -n <bundle-name> -a <ability-name>" command.
616 * @tc.require: AR000GJUII
617 */
618 HWTEST_F(BmCommandTest, Bm_Command_Enable_0004, Function | MediumTest | Level1)
619 {
620 char *argv[] = {
621 const_cast<char*>(TOOL_NAME.c_str()),
622 const_cast<char*>("enable"),
623 const_cast<char*>("-n"),
624 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
625 const_cast<char*>("-a"),
626 const_cast<char*>(""),
627 };
628 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
629 BundleManagerShellCommand cmd(argc, argv);
630 // set the mock objects
631 SetMockObjects(cmd);
632 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_ENABLE);
633 }
634
635 /**
636 * @tc.number: Bm_Command_Enable_0005
637 * @tc.name: ExecCommand
638 * @tc.desc: Verify the "bm enable -n <bundle-name> -a <ability-name>" command.
639 * @tc.require: AR000GJUII
640 */
641 HWTEST_F(BmCommandTest, Bm_Command_Enable_0005, Function | MediumTest | Level1)
642 {
643 char *argv[] = {
644 const_cast<char*>(TOOL_NAME.c_str()),
645 const_cast<char*>("enable"),
646 const_cast<char*>("-n"),
647 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
648 const_cast<char*>("-a"),
649 const_cast<char*>(STRING_ABILITY_NAME.c_str()),
650 const_cast<char*>(""),
651 };
652 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
653 BundleManagerShellCommand cmd(argc, argv);
654 // set the mock objects
655 SetMockObjects(cmd);
656 EXPECT_EQ(cmd.ExecCommand(), STRING_ENABLE_BUNDLE_OK + "\n");
657 }
658
659 /**
660 * @tc.number: Bm_Command_Enable_0006
661 * @tc.name: ExecCommand
662 * @tc.desc: Verify the "bm enable -x" command.
663 */
664 HWTEST_F(BmCommandTest, Bm_Command_Enable_0006, Function | MediumTest | Level1)
665 {
666 char *argv[] = {
667 const_cast<char*>(TOOL_NAME.c_str()),
668 const_cast<char*>("enable"),
669 const_cast<char*>("-x"),
670 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
671 const_cast<char*>(""),
672 };
673 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
674 BundleManagerShellCommand cmd(argc, argv);
675 // set the mock objects
676 SetMockObjects(cmd);
677 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_ENABLE);
678 }
679
680 /**
681 * @tc.number: Bm_Command_Enable_0007
682 * @tc.name: ExecCommand
683 * @tc.desc: Verify the "bm enable -n <bundle-name> -u" command.
684 */
685 HWTEST_F(BmCommandTest, Bm_Command_Enable_0007, Function | MediumTest | Level1)
686 {
687 char *argv[] = {
688 const_cast<char*>(TOOL_NAME.c_str()),
689 const_cast<char*>("enable"),
690 const_cast<char*>("-n"),
691 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
692 const_cast<char*>("-u"),
693 const_cast<char*>(""),
694 };
695 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
696 BundleManagerShellCommand cmd(argc, argv);
697 // set the mock objects
698 SetMockObjects(cmd);
699 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_ENABLE);
700 }
701
702 /**
703 * @tc.number: Bm_Command_Enable_0008
704 * @tc.name: ExecCommand
705 * @tc.desc: Verify the "bm enable -n <bundle-name> -u XXX" command.
706 */
707 HWTEST_F(BmCommandTest, Bm_Command_Enable_0008, Function | MediumTest | Level1)
708 {
709 char *argv[] = {
710 const_cast<char*>(TOOL_NAME.c_str()),
711 const_cast<char*>("enable"),
712 const_cast<char*>("-n"),
713 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
714 const_cast<char*>("-u"),
715 const_cast<char*>("XXX"),
716 const_cast<char*>(""),
717 };
718 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
719 BundleManagerShellCommand cmd(argc, argv);
720 // set the mock objects
721 SetMockObjects(cmd);
722 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE);
723 }
724
725 /**
726 * @tc.number: Bm_Command_Enable_0009
727 * @tc.name: ExecCommand
728 * @tc.desc: Verify the "bm enable -n <bundle-name> -u <user-id>" command.
729 */
730 HWTEST_F(BmCommandTest, Bm_Command_Enable_0009, Function | MediumTest | Level1)
731 {
732 char *argv[] = {
733 const_cast<char*>(TOOL_NAME.c_str()),
734 const_cast<char*>("enable"),
735 const_cast<char*>("-n"),
736 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
737 const_cast<char*>("-u"),
738 const_cast<char*>(DEFAULT_USER_ID.c_str()),
739 const_cast<char*>(""),
740 };
741 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
742 BundleManagerShellCommand cmd(argc, argv);
743 // set the mock objects
744 SetMockObjects(cmd);
745 EXPECT_EQ(cmd.ExecCommand(), STRING_ENABLE_BUNDLE_OK + "\n");
746 }
747
748 /**
749 * @tc.number: Bm_Command_Enable_0010
750 * @tc.name: ExecCommand
751 * @tc.desc: Verify the "bm enable -h" command.
752 */
753 HWTEST_F(BmCommandTest, Bm_Command_Enable_0010, Function | MediumTest | Level1)
754 {
755 char *argv[] = {
756 const_cast<char*>(TOOL_NAME.c_str()),
757 const_cast<char*>("enable"),
758 const_cast<char*>("-h"),
759 const_cast<char*>(""),
760 };
761 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
762 BundleManagerShellCommand cmd(argc, argv);
763 // set the mock objects
764 SetMockObjects(cmd);
765 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_ENABLE);
766 }
767
768 /**
769 * @tc.number: Bm_Command_Enable_0011
770 * @tc.name: ExecCommand
771 * @tc.desc: Verify the "bm enable -n <bundle-name> -xxx <user-id>" command.
772 */
773 HWTEST_F(BmCommandTest, Bm_Command_Enable_0011, Function | MediumTest | Level1)
774 {
775 char *argv[] = {
776 const_cast<char*>(TOOL_NAME.c_str()),
777 const_cast<char*>("enable"),
778 const_cast<char*>("-n"),
779 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
780 const_cast<char*>("-XXX"),
781 const_cast<char*>(DEFAULT_USER_ID.c_str()),
782 const_cast<char*>(""),
783 };
784 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
785 BundleManagerShellCommand cmd(argc, argv);
786 // set the mock objects
787 SetMockObjects(cmd);
788 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_ENABLE);
789 }
790
791 /**
792 * @tc.number: Bm_Command_Disable_0001
793 * @tc.name: ExecCommand
794 * @tc.desc: Verify the "bm disable" command.
795 * @tc.require: AR000GJUII
796 */
797 HWTEST_F(BmCommandTest, Bm_Command_Disable_0001, Function | MediumTest | Level1)
798 {
799 char *argv[] = {
800 const_cast<char*>(TOOL_NAME.c_str()),
801 const_cast<char*>("disable"),
802 const_cast<char*>(""),
803 };
804 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
805 BundleManagerShellCommand cmd(argc, argv);
806 // set the mock objects
807 SetMockObjects(cmd);
808 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_DISABLE);
809 }
810
811 /**
812 * @tc.number: Bm_Command_Disable_0002
813 * @tc.name: ExecCommand
814 * @tc.desc: Verify the "bm disable -n <bundle-name>" command.
815 * @tc.require: AR000GJUII
816 */
817 HWTEST_F(BmCommandTest, Bm_Command_Disable_0002, Function | MediumTest | Level1)
818 {
819 char *argv[] = {
820 const_cast<char*>(TOOL_NAME.c_str()),
821 const_cast<char*>("disable"),
822 const_cast<char*>("-n"),
823 const_cast<char*>(""),
824 };
825 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
826 BundleManagerShellCommand cmd(argc, argv);
827 // set the mock objects
828 SetMockObjects(cmd);
829 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_DISABLE);
830 }
831
832 /**
833 * @tc.number: Bm_Command_Disable_0003
834 * @tc.name: ExecCommand
835 * @tc.desc: Verify the "bm disable -n <bundle-name>" command.
836 * @tc.require: AR000GJUII
837 */
838 HWTEST_F(BmCommandTest, Bm_Command_Disable_0003, Function | MediumTest | Level1)
839 {
840 char *argv[] = {
841 const_cast<char*>(TOOL_NAME.c_str()),
842 const_cast<char*>("disable"),
843 const_cast<char*>("-n"),
844 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
845 const_cast<char*>(""),
846 };
847 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
848 BundleManagerShellCommand cmd(argc, argv);
849 // set the mock objects
850 SetMockObjects(cmd);
851 EXPECT_EQ(cmd.ExecCommand(), STRING_DISABLE_BUNDLE_OK + "\n");
852 }
853
854 /**
855 * @tc.number: Bm_Command_Disable_0004
856 * @tc.name: ExecCommand
857 * @tc.desc: Verify the "bm disable -n <bundle-name> -a <ability-name>" command.
858 * @tc.require: AR000GJUII
859 */
860 HWTEST_F(BmCommandTest, Bm_Command_Disable_0004, Function | MediumTest | Level1)
861 {
862 char *argv[] = {
863 const_cast<char*>(TOOL_NAME.c_str()),
864 const_cast<char*>("disable"),
865 const_cast<char*>("-n"),
866 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
867 const_cast<char*>("-a"),
868 const_cast<char*>(""),
869 };
870 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
871 BundleManagerShellCommand cmd(argc, argv);
872 // set the mock objects
873 SetMockObjects(cmd);
874 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_DISABLE);
875 }
876
877 /**
878 * @tc.number: Bm_Command_Disable_0005
879 * @tc.name: ExecCommand
880 * @tc.desc: Verify the "bm disable -n <bundle-name> -a <ability-name>" command.
881 * @tc.require: AR000GJUII
882 */
883 HWTEST_F(BmCommandTest, Bm_Command_Disable_0005, Function | MediumTest | Level1)
884 {
885 char *argv[] = {
886 const_cast<char*>(TOOL_NAME.c_str()),
887 const_cast<char*>("disable"),
888 const_cast<char*>("-n"),
889 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
890 const_cast<char*>("-a"),
891 const_cast<char*>(STRING_ABILITY_NAME.c_str()),
892 const_cast<char*>(""),
893 };
894 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
895 BundleManagerShellCommand cmd(argc, argv);
896 // set the mock objects
897 SetMockObjects(cmd);
898 EXPECT_EQ(cmd.ExecCommand(), STRING_DISABLE_BUNDLE_OK + "\n");
899 }
900
901 /**
902 * @tc.number: Bm_Command_Disable_0006
903 * @tc.name: ExecCommand
904 * @tc.desc: Verify the "bm disable -n <bundle-name> -u <user-id>" command.
905 * @tc.require: AR000GJUII
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 * @tc.require: AR000GJUII
929 */
930 HWTEST_F(BmCommandTest, Bm_Command_Disable_0007, Function | MediumTest | Level1)
931 {
932 char *argv[] = {
933 const_cast<char*>(TOOL_NAME.c_str()),
934 const_cast<char*>("disable"),
935 const_cast<char*>("-n"),
936 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
937 const_cast<char*>("-u"),
938 const_cast<char*>("100"),
939 const_cast<char*>(""),
940 };
941 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
942 BundleManagerShellCommand cmd(argc, argv);
943 // set the mock objects
944 SetMockObjects(cmd);
945 EXPECT_EQ(cmd.ExecCommand(), STRING_DISABLE_BUNDLE_OK + "\n");
946 }
947
948 /**
949 * @tc.number: Bm_Command_Disable_0008
950 * @tc.name: ExecCommand
951 * @tc.desc: Verify the "bm disable -x" command.
952 */
953 HWTEST_F(BmCommandTest, Bm_Command_Disable_0008, Function | MediumTest | Level1)
954 {
955 char *argv[] = {
956 const_cast<char*>(TOOL_NAME.c_str()),
957 const_cast<char*>("disable"),
958 const_cast<char*>("-x"),
959 const_cast<char*>(""),
960 };
961 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
962 BundleManagerShellCommand cmd(argc, argv);
963 // set the mock objects
964 SetMockObjects(cmd);
965 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DISABLE);
966 }
967
968 /**
969 * @tc.number: Bm_Command_Disable_0009
970 * @tc.name: ExecCommand
971 * @tc.desc: Verify the "bm disable -h" command.
972 */
973 HWTEST_F(BmCommandTest, Bm_Command_Disable_0009, Function | MediumTest | Level1)
974 {
975 char *argv[] = {
976 const_cast<char*>(TOOL_NAME.c_str()),
977 const_cast<char*>("disable"),
978 const_cast<char*>("-h"),
979 const_cast<char*>(""),
980 };
981 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
982 BundleManagerShellCommand cmd(argc, argv);
983 // set the mock objects
984 SetMockObjects(cmd);
985 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_DISABLE);
986 }
987
988 /**
989 * @tc.number: Bm_Command_Disable_0010
990 * @tc.name: ExecCommand
991 * @tc.desc: Verify the "bm disable -n <bundle-name> -u XXX" command.
992 */
993 HWTEST_F(BmCommandTest, Bm_Command_Disable_0010, Function | MediumTest | Level1)
994 {
995 char *argv[] = {
996 const_cast<char*>(TOOL_NAME.c_str()),
997 const_cast<char*>("disable"),
998 const_cast<char*>("-u"),
999 const_cast<char*>("XXX"),
1000 const_cast<char*>(""),
1001 };
1002 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1003 BundleManagerShellCommand cmd(argc, argv);
1004 // set the mock objects
1005 SetMockObjects(cmd);
1006 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE);
1007 }
1008
1009 /**
1010 * @tc.number: Bm_Command_Disable_0011
1011 * @tc.name: ExecCommand
1012 * @tc.desc: Verify the "bm disable -n <bundle-name> -xxx <ability-name>" command.
1013 */
1014 HWTEST_F(BmCommandTest, Bm_Command_Disable_0011, Function | MediumTest | Level1)
1015 {
1016 char *argv[] = {
1017 const_cast<char*>(TOOL_NAME.c_str()),
1018 const_cast<char*>("disable"),
1019 const_cast<char*>("-n"),
1020 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
1021 const_cast<char*>("-XXX"),
1022 const_cast<char*>(STRING_ABILITY_NAME.c_str()),
1023 const_cast<char*>(""),
1024 };
1025 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1026 BundleManagerShellCommand cmd(argc, argv);
1027 // set the mock objects
1028 SetMockObjects(cmd);
1029 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DISABLE);
1030 }
1031
1032 /**
1033 * @tc.number: Bm_Command_Get_0001
1034 * @tc.name: ExecCommand
1035 * @tc.desc: Verify the "bm get" command.
1036 * @tc.require: AR000GJ4K9
1037 */
1038 HWTEST_F(BmCommandTest, Bm_Command_Get_0001, Function | MediumTest | Level1)
1039 {
1040 // install a bundle
1041 char *argv[] = {
1042 const_cast<char*>(TOOL_NAME.c_str()),
1043 const_cast<char*>("get"),
1044 const_cast<char*>(""),
1045 };
1046 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1047
1048 BundleManagerShellCommand cmd(argc, argv);
1049
1050 // set the mock objects
1051 SetMockObjects(cmd);
1052
1053 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_GET);
1054 }
1055
1056 /**
1057 * @tc.number: Bm_Command_Get_0002
1058 * @tc.name: ExecCommand
1059 * @tc.desc: Verify the "bm get -u" command.
1060 * @tc.require: AR000GJ4K9
1061 */
1062 HWTEST_F(BmCommandTest, Bm_Command_Get_0002, Function | MediumTest | Level1)
1063 {
1064 // install a bundle
1065 char *argv[] = {
1066 const_cast<char*>(TOOL_NAME.c_str()),
1067 const_cast<char*>("get"),
1068 const_cast<char*>("-u"),
1069 const_cast<char*>(""),
1070 };
1071 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1072
1073 BundleManagerShellCommand cmd(argc, argv);
1074
1075 // set the mock objects
1076 SetMockObjects(cmd);
1077
1078 std::string result = cmd.ExecCommand();
1079 auto pos = result.find(STRING_GET_UDID_OK);
1080
1081 EXPECT_NE(pos, std::string::npos);
1082 }
1083
1084 /**
1085 * @tc.number: Bm_Command_Get_0003
1086 * @tc.name: ExecCommand
1087 * @tc.desc: Verify the "bm get -x" command.
1088 * @tc.require: AR000GJ4K9
1089 */
1090 HWTEST_F(BmCommandTest, Bm_Command_Get_0003, Function | MediumTest | Level1)
1091 {
1092 // install a bundle
1093 char *argv[] = {
1094 const_cast<char*>(TOOL_NAME.c_str()),
1095 const_cast<char*>("get"),
1096 const_cast<char*>("-x"),
1097 const_cast<char*>(""),
1098 };
1099 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1100
1101 BundleManagerShellCommand cmd(argc, argv);
1102
1103 // set the mock objects
1104 SetMockObjects(cmd);
1105
1106 EXPECT_EQ(cmd.ExecCommand(), STRING_INCORRECT_OPTION + "\n" + HELP_MSG_GET);
1107 }
1108
1109 /**
1110 * @tc.number: Bm_Command_Get_0004
1111 * @tc.name: ExecCommand
1112 * @tc.desc: Verify the "bm get -u -x" command.
1113 * @tc.require: AR000GJ4K9
1114 */
1115 HWTEST_F(BmCommandTest, Bm_Command_Get_0004, Function | MediumTest | Level1)
1116 {
1117 // install a bundle
1118 char *argv[] = {
1119 const_cast<char*>(TOOL_NAME.c_str()),
1120 const_cast<char*>("get"),
1121 const_cast<char*>("-u"),
1122 const_cast<char*>("-x"),
1123 const_cast<char*>(""),
1124 };
1125 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1126
1127 BundleManagerShellCommand cmd(argc, argv);
1128
1129 // set the mock objects
1130 SetMockObjects(cmd);
1131
1132 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
1133 }
1134
1135 /**
1136 * @tc.number: Bm_Command_Get_0005
1137 * @tc.name: ExecCommand
1138 * @tc.desc: Verify the "bm get -u xxx" command.
1139 * @tc.require: AR000GJ4K9
1140 */
1141 HWTEST_F(BmCommandTest, Bm_Command_Get_0005, Function | MediumTest | Level1)
1142 {
1143 // install a bundle
1144 char *argv[] = {
1145 const_cast<char*>(TOOL_NAME.c_str()),
1146 const_cast<char*>("get"),
1147 const_cast<char*>("-u"),
1148 const_cast<char*>("xxx"),
1149 const_cast<char*>(""),
1150 };
1151 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1152
1153 BundleManagerShellCommand cmd(argc, argv);
1154
1155 // set the mock objects
1156 SetMockObjects(cmd);
1157
1158 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
1159 }
1160
1161 /**
1162 * @tc.number: Bm_Command_Get_0006
1163 * @tc.name: ExecCommand
1164 * @tc.desc: Verify the "bm get --udid" command.
1165 * @tc.require: AR000GJ4K9
1166 */
1167 HWTEST_F(BmCommandTest, Bm_Command_Get_0006, Function | MediumTest | Level1)
1168 {
1169 // install a bundle
1170 char *argv[] = {
1171 const_cast<char*>(TOOL_NAME.c_str()),
1172 const_cast<char*>("get"),
1173 const_cast<char*>("--udid"),
1174 const_cast<char*>(""),
1175 };
1176 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1177
1178 BundleManagerShellCommand cmd(argc, argv);
1179
1180 // set the mock objects
1181 SetMockObjects(cmd);
1182
1183 std::string result = cmd.ExecCommand();
1184 auto pos = result.find(STRING_GET_UDID_OK);
1185
1186 EXPECT_NE(pos, std::string::npos);
1187 }
1188
1189 /**
1190 * @tc.number: Bm_Command_Get_0007
1191 * @tc.name: ExecCommand
1192 * @tc.desc: Verify the "bm get --xxx" command.
1193 * @tc.require: AR000GJ4K9
1194 */
1195 HWTEST_F(BmCommandTest, Bm_Command_Get_0007, Function | MediumTest | Level1)
1196 {
1197 // install a bundle
1198 char *argv[] = {
1199 const_cast<char*>(TOOL_NAME.c_str()),
1200 const_cast<char*>("get"),
1201 const_cast<char*>("--xxx"),
1202 const_cast<char*>(""),
1203 };
1204 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1205
1206 BundleManagerShellCommand cmd(argc, argv);
1207
1208 // set the mock objects
1209 SetMockObjects(cmd);
1210
1211 EXPECT_EQ(cmd.ExecCommand(), STRING_INCORRECT_OPTION + "\n" + HELP_MSG_GET);
1212 }
1213
1214 /**
1215 * @tc.number: Bm_Command_Get_0008
1216 * @tc.name: ExecCommand
1217 * @tc.desc: Verify the "bm get --udid -x" command.
1218 * @tc.require: AR000GJ4K9
1219 */
1220 HWTEST_F(BmCommandTest, Bm_Command_Get_0008, Function | MediumTest | Level1)
1221 {
1222 // install a bundle
1223 char *argv[] = {
1224 const_cast<char*>(TOOL_NAME.c_str()),
1225 const_cast<char*>("get"),
1226 const_cast<char*>("--udid"),
1227 const_cast<char*>("-x"),
1228 const_cast<char*>(""),
1229 };
1230 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1231
1232 BundleManagerShellCommand cmd(argc, argv);
1233
1234 // set the mock objects
1235 SetMockObjects(cmd);
1236
1237 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
1238 }
1239
1240 /**
1241 * @tc.number: Bm_Command_Get_0009
1242 * @tc.name: ExecCommand
1243 * @tc.desc: Verify the "bm get -u xxx" command.
1244 * @tc.require: AR000GJ4K9
1245 */
1246 HWTEST_F(BmCommandTest, Bm_Command_Get_0009, Function | MediumTest | Level1)
1247 {
1248 // install a bundle
1249 char *argv[] = {
1250 const_cast<char*>(TOOL_NAME.c_str()),
1251 const_cast<char*>("get"),
1252 const_cast<char*>("--udid"),
1253 const_cast<char*>("xxx"),
1254 const_cast<char*>(""),
1255 };
1256 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1257
1258 BundleManagerShellCommand cmd(argc, argv);
1259
1260 // set the mock objects
1261 SetMockObjects(cmd);
1262
1263 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
1264 }
1265
1266 /**
1267 * @tc.number: Bm_Command_Get_0010
1268 * @tc.name: ExecCommand
1269 * @tc.desc: Verify the "bm get -h" command.
1270 */
1271 HWTEST_F(BmCommandTest, Bm_Command_Get_0010, Function | MediumTest | Level1)
1272 {
1273 // install a bundle
1274 char *argv[] = {
1275 const_cast<char*>(TOOL_NAME.c_str()),
1276 const_cast<char*>("get"),
1277 const_cast<char*>("-h"),
1278 const_cast<char*>(""),
1279 };
1280 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1281
1282 BundleManagerShellCommand cmd(argc, argv);
1283
1284 // set the mock objects
1285 SetMockObjects(cmd);
1286
1287 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_GET);
1288 }
1289
1290 /**
1291 * @tc.number: GetBundlePath_0001
1292 * @tc.name: test GetBundlePath
1293 * @tc.desc: Verify the "GetBundlePath".
1294 */
1295 HWTEST_F(BmCommandTest, GetBundlePath_0001, Function | MediumTest | Level1)
1296 {
1297 // install a bundle
1298 char *argv[] = {
1299 const_cast<char*>(TOOL_NAME.c_str()),
1300 const_cast<char*>("-h"),
1301 };
1302 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1303
1304 BundleManagerShellCommand cmd(argc, argv);
1305 std::string param = "";
1306 std::vector<std::string> bundlePaths;
1307 auto res = cmd.GetBundlePath(param, bundlePaths);
1308 EXPECT_EQ(res, ERR_INVALID_VALUE);
1309
1310 param = "-r";
1311 res = cmd.GetBundlePath(param, bundlePaths);
1312 EXPECT_EQ(res, ERR_INVALID_VALUE);
1313
1314 param = "--replace";
1315 res = cmd.GetBundlePath(param, bundlePaths);
1316 EXPECT_EQ(res, ERR_INVALID_VALUE);
1317
1318 param = "-p";
1319 res = cmd.GetBundlePath(param, bundlePaths);
1320 EXPECT_EQ(res, ERR_INVALID_VALUE);
1321
1322 param = "--bundle-path";
1323 res = cmd.GetBundlePath(param, bundlePaths);
1324 EXPECT_EQ(res, ERR_INVALID_VALUE);
1325
1326 param = "-u";
1327 res = cmd.GetBundlePath(param, bundlePaths);
1328 EXPECT_EQ(res, ERR_INVALID_VALUE);
1329
1330 param = "--user-id";
1331 res = cmd.GetBundlePath(param, bundlePaths);
1332 EXPECT_EQ(res, ERR_INVALID_VALUE);
1333
1334 param = "-w";
1335 res = cmd.GetBundlePath(param, bundlePaths);
1336 EXPECT_EQ(res, ERR_INVALID_VALUE);
1337
1338 param = "--waitting-time";
1339 res = cmd.GetBundlePath(param, bundlePaths);
1340 EXPECT_EQ(res, ERR_INVALID_VALUE);
1341
1342 param = "-x";
1343 res = cmd.GetBundlePath(param, bundlePaths);
1344 EXPECT_EQ(res, ERR_OK);
1345 }
1346 } // namespace OHOS