1 /*
2 * Copyright (c) 2021 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_constants.h"
22 #include "bundle_installer_interface.h"
23 #include "iremote_broker.h"
24 #include "iremote_object.h"
25 #include "mock_bundle_installer_host.h"
26 #include "mock_bundle_mgr_host.h"
27
28 using namespace testing::ext;
29 using namespace OHOS::AAFwk;
30 using namespace OHOS::AppExecFwk;
31
32 namespace OHOS {
33 class BmCommandDumpTest : public ::testing::Test {
34 public:
35 static void SetUpTestCase();
36 static void TearDownTestCase();
37 void SetUp() override;
38 void TearDown() override;
39
40 void MakeMockObjects();
41 void SetMockObjects(BundleManagerShellCommand &cmd) const;
42
43 std::string cmd_ = "dump";
44 std::string shared_ = "dump-shared";
45 std::string sharedDependencies_ = "dump-shared-dependencies";
46 sptr<IBundleMgr> mgrProxyPtr_;
47 sptr<IBundleInstaller> installerProxyPtr_;
48 };
49
SetUpTestCase()50 void BmCommandDumpTest::SetUpTestCase()
51 {}
52
TearDownTestCase()53 void BmCommandDumpTest::TearDownTestCase()
54 {}
55
SetUp()56 void BmCommandDumpTest::SetUp()
57 {
58 // reset optind to 0
59 optind = 0;
60
61 // make mock objects
62 MakeMockObjects();
63 }
64
TearDown()65 void BmCommandDumpTest::TearDown()
66 {}
67
MakeMockObjects()68 void BmCommandDumpTest::MakeMockObjects()
69 {
70 // mock a mgr host
71 auto mgrHostPtr = sptr<IRemoteObject>(new (std::nothrow) MockBundleMgrHost());
72 // mock a mgr proxy
73 mgrProxyPtr_ = iface_cast<IBundleMgr>(mgrHostPtr);
74
75 // mock a installer host
76 auto installerHostPtr = sptr<IRemoteObject>(new (std::nothrow) MockBundleInstallerHost());
77 // mock a installer proxy
78 installerProxyPtr_ = iface_cast<IBundleInstaller>(installerHostPtr);
79 }
80
SetMockObjects(BundleManagerShellCommand &cmd) const81 void BmCommandDumpTest::SetMockObjects(BundleManagerShellCommand &cmd) const
82 {
83 // set the mock mgr proxy
84 cmd.bundleMgrProxy_ = mgrProxyPtr_;
85
86 // set the mock installer proxy
87 cmd.bundleInstallerProxy_ = installerProxyPtr_;
88 }
89
90 /**
91 * @tc.number: Bm_Command_Dump_0100
92 * @tc.name: ExecCommand
93 * @tc.desc: Verify the "bm dump" command.
94 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0100, Function | MediumTest | Level1)95 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0100, Function | MediumTest | Level1)
96 {
97 char *argv[] = {
98 const_cast<char*>(TOOL_NAME.c_str()),
99 const_cast<char*>(cmd_.c_str()),
100 const_cast<char*>(""),
101 };
102 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
103
104 BundleManagerShellCommand cmd(argc, argv);
105
106 // set the mock objects
107 SetMockObjects(cmd);
108
109 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_DUMP);
110 }
111
112 /**
113 * @tc.number: Bm_Command_Dump_0200
114 * @tc.name: ExecCommand
115 * @tc.desc: Verify the "bm dump xxx" command.
116 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0200, Function | MediumTest | Level1)117 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0200, Function | MediumTest | Level1)
118 {
119 char *argv[] = {
120 const_cast<char*>(TOOL_NAME.c_str()),
121 const_cast<char*>(cmd_.c_str()),
122 const_cast<char*>("xxx"),
123 const_cast<char*>(""),
124 };
125 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
126
127 BundleManagerShellCommand cmd(argc, argv);
128
129 // set the mock objects
130 SetMockObjects(cmd);
131
132 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_DUMP);
133 }
134
135 /**
136 * @tc.number: Bm_Command_Dump_0300
137 * @tc.name: ExecCommand
138 * @tc.desc: Verify the "bm dump -x" command.
139 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0300, Function | MediumTest | Level1)140 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0300, Function | MediumTest | Level1)
141 {
142 char *argv[] = {
143 const_cast<char*>(TOOL_NAME.c_str()),
144 const_cast<char*>(cmd_.c_str()),
145 const_cast<char*>("-x"),
146 const_cast<char*>(""),
147 };
148 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
149
150 BundleManagerShellCommand cmd(argc, argv);
151
152 // set the mock objects
153 SetMockObjects(cmd);
154
155 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DUMP);
156 }
157
158 /**
159 * @tc.number: Bm_Command_Dump_0400
160 * @tc.name: ExecCommand
161 * @tc.desc: Verify the "bm dump -xxx" command.
162 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0400, Function | MediumTest | Level1)163 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0400, Function | MediumTest | Level1)
164 {
165 char *argv[] = {
166 const_cast<char*>(TOOL_NAME.c_str()),
167 const_cast<char*>(cmd_.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 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DUMP);
179 }
180
181 /**
182 * @tc.number: Bm_Command_Dump_0500
183 * @tc.name: ExecCommand
184 * @tc.desc: Verify the "bm dump --x" command.
185 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0500, Function | MediumTest | Level1)186 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0500, Function | MediumTest | Level1)
187 {
188 char *argv[] = {
189 const_cast<char*>(TOOL_NAME.c_str()),
190 const_cast<char*>(cmd_.c_str()),
191 const_cast<char*>("--x"),
192 const_cast<char*>(""),
193 };
194 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
195
196 BundleManagerShellCommand cmd(argc, argv);
197
198 // set the mock objects
199 SetMockObjects(cmd);
200
201 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DUMP);
202 }
203
204 /**
205 * @tc.number: Bm_Command_Dump_0600
206 * @tc.name: ExecCommand
207 * @tc.desc: Verify the "bm dump --xxx" command.
208 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0600, Function | MediumTest | Level1)209 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0600, Function | MediumTest | Level1)
210 {
211 char *argv[] = {
212 const_cast<char*>(TOOL_NAME.c_str()),
213 const_cast<char*>(cmd_.c_str()),
214 const_cast<char*>("--xxx"),
215 const_cast<char*>(""),
216 };
217 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
218
219 BundleManagerShellCommand cmd(argc, argv);
220
221 // set the mock objects
222 SetMockObjects(cmd);
223
224 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DUMP);
225 }
226
227 /**
228 * @tc.number: Bm_Command_Dump_0700
229 * @tc.name: ExecCommand
230 * @tc.desc: Verify the "bm dump -h" command.
231 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0700, Function | MediumTest | Level1)232 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0700, Function | MediumTest | Level1)
233 {
234 char *argv[] = {
235 const_cast<char*>(TOOL_NAME.c_str()),
236 const_cast<char*>(cmd_.c_str()),
237 const_cast<char*>("-h"),
238 const_cast<char*>(""),
239 };
240 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
241
242 BundleManagerShellCommand cmd(argc, argv);
243
244 // set the mock objects
245 SetMockObjects(cmd);
246
247 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_DUMP);
248 }
249
250 /**
251 * @tc.number: Bm_Command_Dump_0800
252 * @tc.name: ExecCommand
253 * @tc.desc: Verify the "bm dump --help" command.
254 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0800, Function | MediumTest | Level1)255 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0800, Function | MediumTest | Level1)
256 {
257 char *argv[] = {
258 const_cast<char*>(TOOL_NAME.c_str()),
259 const_cast<char*>(cmd_.c_str()),
260 const_cast<char*>("--help"),
261 const_cast<char*>(""),
262 };
263 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
264
265 BundleManagerShellCommand cmd(argc, argv);
266
267 // set the mock objects
268 SetMockObjects(cmd);
269
270 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_DUMP);
271 }
272
273 /**
274 * @tc.number: Bm_Command_Dump_0900
275 * @tc.name: ExecCommand
276 * @tc.desc: Verify the "bm dump -a" command.
277 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0900, Function | MediumTest | Level1)278 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_0900, Function | MediumTest | Level1)
279 {
280 char *argv[] = {
281 const_cast<char*>(TOOL_NAME.c_str()),
282 const_cast<char*>(cmd_.c_str()),
283 const_cast<char*>("-a"),
284 const_cast<char*>(""),
285 };
286 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
287
288 BundleManagerShellCommand cmd(argc, argv);
289
290 // set the mock objects
291 SetMockObjects(cmd);
292
293 EXPECT_EQ(cmd.ExecCommand(), "OK");
294 }
295
296 /**
297 * @tc.number: Bm_Command_Dump_1000
298 * @tc.name: ExecCommand
299 * @tc.desc: Verify the "bm dump --all" command.
300 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1000, Function | MediumTest | Level1)301 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1000, Function | MediumTest | Level1)
302 {
303 char *argv[] = {
304 const_cast<char*>(TOOL_NAME.c_str()),
305 const_cast<char*>(cmd_.c_str()),
306 const_cast<char*>("--all"),
307 const_cast<char*>(""),
308 };
309 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
310
311 BundleManagerShellCommand cmd(argc, argv);
312
313 // set the mock objects
314 SetMockObjects(cmd);
315
316 EXPECT_EQ(cmd.ExecCommand(), "OK");
317 }
318
319 /**
320 * @tc.number: Bm_Command_Dump_1100
321 * @tc.name: ExecCommand
322 * @tc.desc: Verify the "bm dump -n" command.
323 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1100, Function | MediumTest | Level1)324 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1100, Function | MediumTest | Level1)
325 {
326 char *argv[] = {
327 const_cast<char*>(TOOL_NAME.c_str()),
328 const_cast<char*>(cmd_.c_str()),
329 const_cast<char*>("-n"),
330 const_cast<char*>(""),
331 };
332 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
333
334 BundleManagerShellCommand cmd(argc, argv);
335
336 // set the mock objects
337 SetMockObjects(cmd);
338
339 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_DUMP);
340 }
341
342 /**
343 * @tc.number: Bm_Command_Dump_1200
344 * @tc.name: ExecCommand
345 * @tc.desc: Verify the "bm dump -n <bundle-name>" command.
346 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1200, Function | MediumTest | Level1)347 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1200, Function | MediumTest | Level1)
348 {
349 char *argv[] = {
350 const_cast<char*>(TOOL_NAME.c_str()),
351 const_cast<char*>(cmd_.c_str()),
352 const_cast<char*>("-n"),
353 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
354 const_cast<char*>(""),
355 };
356 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
357
358 BundleManagerShellCommand cmd(argc, argv);
359
360 // set the mock objects
361 SetMockObjects(cmd);
362
363 EXPECT_EQ(cmd.ExecCommand(), STRING_BUNDLE_NAME + "\n");
364 }
365
366 /**
367 * @tc.number: Bm_Command_Dump_1300
368 * @tc.name: ExecCommand
369 * @tc.desc: Verify the "bm dump -s" command.
370 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1300, Function | MediumTest | Level1)371 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1300, Function | MediumTest | Level1)
372 {
373 char *argv[] = {
374 const_cast<char*>(TOOL_NAME.c_str()),
375 const_cast<char*>(cmd_.c_str()),
376 const_cast<char*>("-s"),
377 const_cast<char*>(""),
378 };
379 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
380 BundleManagerShellCommand cmd(argc, argv);
381 // set the mock objects
382 SetMockObjects(cmd);
383 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_BUNDLE_NAME_OPTION + "\n" + HELP_MSG_DUMP);
384 }
385
386 /**
387 * @tc.number: Bm_Command_Dump_1400
388 * @tc.name: ExecCommand
389 * @tc.desc: Verify the "bm dump -n <bundle-name> -s" command.
390 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1400, Function | MediumTest | Level1)391 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1400, Function | MediumTest | Level1)
392 {
393 char *argv[] = {
394 const_cast<char*>(TOOL_NAME.c_str()),
395 const_cast<char*>(cmd_.c_str()),
396 const_cast<char*>("-n"),
397 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
398 const_cast<char*>("-s"),
399 const_cast<char*>(""),
400 };
401 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
402 BundleManagerShellCommand cmd(argc, argv);
403 // set the mock objects
404 SetMockObjects(cmd);
405 EXPECT_EQ(cmd.ExecCommand(), STRING_BUNDLE_NAME + "\n");
406 }
407
408 /**
409 * @tc.number: Bm_Command_Dump_1500
410 * @tc.name: ExecCommand
411 * @tc.desc: Verify the "bm dump -n <bundle-name> -u" command.
412 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1500, Function | MediumTest | Level1)413 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1500, Function | MediumTest | Level1)
414 {
415 char *argv[] = {
416 const_cast<char*>(TOOL_NAME.c_str()),
417 const_cast<char*>(cmd_.c_str()),
418 const_cast<char*>("-n"),
419 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
420 const_cast<char*>("-u"),
421 const_cast<char*>(""),
422 };
423 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
424 BundleManagerShellCommand cmd(argc, argv);
425 // set the mock objects
426 SetMockObjects(cmd);
427 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_DUMP);
428 }
429
430 /**
431 * @tc.number: Bm_Command_Dump_1600
432 * @tc.name: ExecCommand
433 * @tc.desc: Verify the "bm dump -n <bundle-name> -u <user-id>" command.
434 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1600, Function | MediumTest | Level1)435 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1600, Function | MediumTest | Level1)
436 {
437 char *argv[] = {
438 const_cast<char*>(TOOL_NAME.c_str()),
439 const_cast<char*>(cmd_.c_str()),
440 const_cast<char*>("-n"),
441 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
442 const_cast<char*>("-u"),
443 const_cast<char*>(DEFAULT_USER_ID.c_str()),
444 const_cast<char*>(""),
445 };
446 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
447 BundleManagerShellCommand cmd(argc, argv);
448 // set the mock objects
449 SetMockObjects(cmd);
450 EXPECT_EQ(cmd.ExecCommand(), STRING_BUNDLE_NAME + "\n");
451 }
452
453 /**
454 * @tc.number: Bm_Command_Dump_1700
455 * @tc.name: ExecCommand
456 * @tc.desc: Verify the "bm dump -n <bundle-name> -d" command.
457 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1700, Function | MediumTest | Level1)458 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1700, Function | MediumTest | Level1)
459 {
460 char *argv[] = {
461 const_cast<char*>(TOOL_NAME.c_str()),
462 const_cast<char*>(cmd_.c_str()),
463 const_cast<char*>("-n"),
464 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
465 const_cast<char*>("-d"),
466 const_cast<char*>(""),
467 };
468 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
469 BundleManagerShellCommand cmd(argc, argv);
470 // set the mock objects
471 SetMockObjects(cmd);
472 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_DUMP);
473 }
474
475 /**
476 * @tc.number: Bm_Command_Dump_1800
477 * @tc.name: ExecCommand
478 * @tc.desc: Verify the "bm dump -n <bundle-name> -d <device-id>" command.
479 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1800, Function | MediumTest | Level1)480 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1800, Function | MediumTest | Level1)
481 {
482 char *argv[] = {
483 const_cast<char*>(TOOL_NAME.c_str()),
484 const_cast<char*>(cmd_.c_str()),
485 const_cast<char*>("-n"),
486 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
487 const_cast<char*>("-d"),
488 const_cast<char*>(DEFAULT_DEVICE_TIME.c_str()),
489 const_cast<char*>(""),
490 };
491 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
492 BundleManagerShellCommand cmd(argc, argv);
493 // set the mock objects
494 SetMockObjects(cmd);
495 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_DUMP_FAILED + "\n");
496 }
497
498 /**
499 * @tc.number: Bm_Command_Dump_1900
500 * @tc.name: ExecCommand
501 * @tc.desc: Verify the "bm dump -n <bundle-name> -XXX <user-id>" command.
502 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1900, Function | MediumTest | Level1)503 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_1900, Function | MediumTest | Level1)
504 {
505 char *argv[] = {
506 const_cast<char*>(TOOL_NAME.c_str()),
507 const_cast<char*>(cmd_.c_str()),
508 const_cast<char*>("-n"),
509 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
510 const_cast<char*>("-XXX"),
511 const_cast<char*>(DEFAULT_USER_ID.c_str()),
512 const_cast<char*>(""),
513 };
514 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
515 BundleManagerShellCommand cmd(argc, argv);
516 // set the mock objects
517 SetMockObjects(cmd);
518 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DUMP);
519 }
520
521 /**
522 * @tc.number: Bm_Command_Dump_2000
523 * @tc.name: ExecCommand
524 * @tc.desc: Verify the "bm dump -n <bundle-name> -u <user-id>" command.
525 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_2000, Function | MediumTest | Level1)526 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_2000, Function | MediumTest | Level1)
527 {
528 char *argv[] = {
529 const_cast<char*>(TOOL_NAME.c_str()),
530 const_cast<char*>(cmd_.c_str()),
531 const_cast<char*>("-n"),
532 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
533 const_cast<char*>("-u"),
534 const_cast<char*>(ERR_USER_ID.c_str()),
535 const_cast<char*>(""),
536 };
537 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
538 BundleManagerShellCommand cmd(argc, argv);
539 // set the mock objects
540 SetMockObjects(cmd);
541 EXPECT_EQ(cmd.ExecCommand(), "name\n");
542 }
543
544 /**
545 * @tc.number: Bm_Command_Dump_2100
546 * @tc.name: ExecCommand
547 * @tc.desc: Verify the "bm dump -xx <bundle-name>" command.
548 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_2100, Function | MediumTest | Level1)549 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_2100, Function | MediumTest | Level1)
550 {
551 char *argv[] = {
552 const_cast<char*>(TOOL_NAME.c_str()),
553 const_cast<char*>(cmd_.c_str()),
554 const_cast<char*>("-xx"),
555 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
556 const_cast<char*>(""),
557 };
558 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
559 BundleManagerShellCommand cmd(argc, argv);
560 // set the mock objects
561 SetMockObjects(cmd);
562 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DUMP);
563 }
564
565 /**
566 * @tc.number: Bm_Command_Dump_2200
567 * @tc.name: ExecCommand
568 * @tc.desc: Verify the "bm dump -d <device-id>" command.
569 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_2200, Function | MediumTest | Level1)570 HWTEST_F(BmCommandDumpTest, Bm_Command_Dump_2200, Function | MediumTest | Level1)
571 {
572 char *argv[] = {
573 const_cast<char*>(TOOL_NAME.c_str()),
574 const_cast<char*>(cmd_.c_str()),
575 const_cast<char*>("-d"),
576 const_cast<char*>(DEFAULT_DEVICE_TIME.c_str()),
577 const_cast<char*>(""),
578 };
579 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
580 BundleManagerShellCommand cmd(argc, argv);
581 // set the mock objects
582 SetMockObjects(cmd);
583 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_BUNDLE_NAME_OPTION + "\n" + HELP_MSG_DUMP);
584 }
585
586 /**
587 * @tc.number: Bm_Command_Shared_0001
588 * @tc.name: ExecCommand
589 * @tc.desc: Verify the "bm dump-shared" command.
590 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Shared_0001, Function | MediumTest | Level1)591 HWTEST_F(BmCommandDumpTest, Bm_Command_Shared_0001, Function | MediumTest | Level1)
592 {
593 char *argv[] = {
594 const_cast<char*>(TOOL_NAME.c_str()),
595 const_cast<char*>(shared_.c_str()),
596 const_cast<char*>(""),
597 };
598 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
599
600 BundleManagerShellCommand cmd(argc, argv);
601
602 // set the mock objects
603 SetMockObjects(cmd);
604
605 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_DUMP_SHARED);
606 }
607
608 /**
609 * @tc.number: Bm_Command_Shared_0002
610 * @tc.name: ExecCommand
611 * @tc.desc: Verify the "bm dump-shared -n" command.
612 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Shared_0002, Function | MediumTest | Level1)613 HWTEST_F(BmCommandDumpTest, Bm_Command_Shared_0002, Function | MediumTest | Level1)
614 {
615 char *argv[] = {
616 const_cast<char*>(TOOL_NAME.c_str()),
617 const_cast<char*>(shared_.c_str()),
618 const_cast<char*>("-n"),
619 const_cast<char*>(""),
620 };
621 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
622
623 BundleManagerShellCommand cmd(argc, argv);
624
625 // set the mock objects
626 SetMockObjects(cmd);
627
628 EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_DUMP_SHARED);
629 }
630
631 /**
632 * @tc.number: Bm_Command_Shared_0003
633 * @tc.name: ExecCommand
634 * @tc.desc: Verify the "bm dump-shared -xxx" command.
635 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Shared_0003, Function | MediumTest | Level1)636 HWTEST_F(BmCommandDumpTest, Bm_Command_Shared_0003, Function | MediumTest | Level1)
637 {
638 char *argv[] = {
639 const_cast<char*>(TOOL_NAME.c_str()),
640 const_cast<char*>(shared_.c_str()),
641 const_cast<char*>("-xxx"),
642 const_cast<char*>(""),
643 };
644 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
645
646 BundleManagerShellCommand cmd(argc, argv);
647
648 // set the mock objects
649 SetMockObjects(cmd);
650
651 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DUMP_SHARED);
652 }
653
654 /**
655 * @tc.number: Bm_Command_Shared_0005
656 * @tc.name: ExecCommand
657 * @tc.desc: Verify the "bm dump-shared -h" command.
658 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Shared_0005, Function | MediumTest | Level1)659 HWTEST_F(BmCommandDumpTest, Bm_Command_Shared_0005, Function | MediumTest | Level1)
660 {
661 char *argv[] = {
662 const_cast<char*>(TOOL_NAME.c_str()),
663 const_cast<char*>(shared_.c_str()),
664 const_cast<char*>("-h"),
665 const_cast<char*>(""),
666 };
667 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
668
669 BundleManagerShellCommand cmd(argc, argv);
670
671 // set the mock objects
672 SetMockObjects(cmd);
673
674 EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_DUMP_SHARED);
675 }
676
677 /**
678 * @tc.number: Bm_Command_Shared_0006
679 * @tc.name: ExecCommand
680 * @tc.desc: Verify the "bm dump-shared -n <bundle-name>" command.
681 */
HWTEST_F(BmCommandDumpTest, Bm_Command_Shared_0006, Function | MediumTest | Level1)682 HWTEST_F(BmCommandDumpTest, Bm_Command_Shared_0006, Function | MediumTest | Level1)
683 {
684 char *argv[] = {
685 const_cast<char*>(TOOL_NAME.c_str()),
686 const_cast<char*>(shared_.c_str()),
687 const_cast<char*>("-n"),
688 const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
689 const_cast<char*>("-t"),
690 const_cast<char*>(""),
691 };
692 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
693
694 BundleManagerShellCommand cmd(argc, argv);
695
696 // set the mock objects
697 SetMockObjects(cmd);
698
699 EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_DUMP_SHARED);
700 }
701
702 } // namespace OHOS