1 /*
2  * Copyright (c) 2023 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 BmCommandOverlayTest : 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     std::string overlay_ = "dump-overlay";
43     std::string tOverlay_ = "dump-target-overlay";
44     sptr<IBundleMgr> mgrProxyPtr_;
45     sptr<IBundleInstaller> installerProxyPtr_;
46 };
47 
SetUpTestCase()48 void BmCommandOverlayTest::SetUpTestCase()
49 {}
50 
TearDownTestCase()51 void BmCommandOverlayTest::TearDownTestCase()
52 {}
53 
SetUp()54 void BmCommandOverlayTest::SetUp()
55 {
56     // reset optind to 0
57     optind = 0;
58 
59     // make mock objects
60     MakeMockObjects();
61 }
62 
TearDown()63 void BmCommandOverlayTest::TearDown()
64 {}
65 
MakeMockObjects()66 void BmCommandOverlayTest::MakeMockObjects()
67 {
68     // mock a mgr host
69     auto mgrHostPtr = sptr<IRemoteObject>(new (std::nothrow) MockBundleMgrHost());
70     // mock a mgr proxy
71     mgrProxyPtr_ = iface_cast<IBundleMgr>(mgrHostPtr);
72 
73     // mock a installer host
74     auto installerHostPtr = sptr<IRemoteObject>(new (std::nothrow) MockBundleInstallerHost());
75     // mock a installer proxy
76     installerProxyPtr_ = iface_cast<IBundleInstaller>(installerHostPtr);
77 }
78 
SetMockObjects(BundleManagerShellCommand &cmd) const79 void BmCommandOverlayTest::SetMockObjects(BundleManagerShellCommand &cmd) const
80 {
81     // set the mock mgr proxy
82     cmd.bundleMgrProxy_ = mgrProxyPtr_;
83 
84     // set the mock installer proxy
85     cmd.bundleInstallerProxy_ = installerProxyPtr_;
86 }
87 
88 /**
89  * @tc.number: Bm_Command_Overlay_0001
90  * @tc.name: ExecCommand
91  * @tc.desc: Verify the "bm dump-overlay" command.
92  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0001, Function | MediumTest | Level1)93 HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0001, Function | MediumTest | Level1)
94 {
95     char *argv[] = {
96         const_cast<char*>(TOOL_NAME.c_str()),
97         const_cast<char*>(overlay_.c_str()),
98         const_cast<char*>(""),
99     };
100     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
101 
102     BundleManagerShellCommand cmd(argc, argv);
103 
104     // set the mock objects
105     SetMockObjects(cmd);
106 
107     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_OVERLAY);
108 }
109 
110 /**
111  * @tc.number: Bm_Command_Overlay_0002
112  * @tc.name: ExecCommand
113  * @tc.desc: Verify the "bm dump-overlay -xxx" command.
114  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0002, Function | MediumTest | Level1)115 HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0002, Function | MediumTest | Level1)
116 {
117     char *argv[] = {
118         const_cast<char*>(TOOL_NAME.c_str()),
119         const_cast<char*>(overlay_.c_str()),
120         const_cast<char*>("-xxx"),
121         const_cast<char*>(""),
122     };
123     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
124 
125     BundleManagerShellCommand cmd(argc, argv);
126 
127     // set the mock objects
128     SetMockObjects(cmd);
129 
130     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_OVERLAY);
131 }
132 
133 /**
134  * @tc.number: Bm_Command_Overlay_0003
135  * @tc.name: ExecCommand
136  * @tc.desc: Verify the "bm dump-overlay -b" command.
137  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0003, Function | MediumTest | Level1)138 HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0003, Function | MediumTest | Level1)
139 {
140     char *argv[] = {
141         const_cast<char*>(TOOL_NAME.c_str()),
142         const_cast<char*>(overlay_.c_str()),
143         const_cast<char*>("-b"),
144         const_cast<char*>(""),
145     };
146     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
147 
148     BundleManagerShellCommand cmd(argc, argv);
149 
150     // set the mock objects
151     SetMockObjects(cmd);
152 
153     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_OVERLAY);
154 }
155 
156 /**
157  * @tc.number: Bm_Command_Overlay_0004
158  * @tc.name: ExecCommand
159  * @tc.desc: Verify the "bm dump-overlay -m" command.
160  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0004, Function | MediumTest | Level1)161 HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0004, Function | MediumTest | Level1)
162 {
163     char *argv[] = {
164         const_cast<char*>(TOOL_NAME.c_str()),
165         const_cast<char*>(overlay_.c_str()),
166         const_cast<char*>("-m"),
167         const_cast<char*>(""),
168     };
169     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
170 
171     BundleManagerShellCommand cmd(argc, argv);
172 
173     // set the mock objects
174     SetMockObjects(cmd);
175 
176     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_OVERLAY);
177 }
178 
179 /**
180  * @tc.number: Bm_Command_Overlay_0005
181  * @tc.name: ExecCommand
182  * @tc.desc: Verify the "bm dump-overlay -t" command.
183  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0005, Function | MediumTest | Level1)184 HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0005, Function | MediumTest | Level1)
185 {
186     char *argv[] = {
187         const_cast<char*>(TOOL_NAME.c_str()),
188         const_cast<char*>(overlay_.c_str()),
189         const_cast<char*>("-t"),
190         const_cast<char*>(""),
191     };
192     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
193 
194     BundleManagerShellCommand cmd(argc, argv);
195 
196     // set the mock objects
197     SetMockObjects(cmd);
198 
199     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_OVERLAY);
200 }
201 
202 /**
203  * @tc.number: Bm_Command_Overlay_0006
204  * @tc.name: ExecCommand
205  * @tc.desc: Verify the "bm dump-overlay -u" command.
206  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0006, Function | MediumTest | Level1)207 HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0006, Function | MediumTest | Level1)
208 {
209     char *argv[] = {
210         const_cast<char*>(TOOL_NAME.c_str()),
211         const_cast<char*>(overlay_.c_str()),
212         const_cast<char*>("-u"),
213         const_cast<char*>(""),
214     };
215     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
216 
217     BundleManagerShellCommand cmd(argc, argv);
218 
219     // set the mock objects
220     SetMockObjects(cmd);
221 
222     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_OVERLAY);
223 }
224 
225 /**
226  * @tc.number: Bm_Command_Overlay_0007
227  * @tc.name: ExecCommand
228  * @tc.desc: Verify the "bm dump-overlay -h" command.
229  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0007, Function | MediumTest | Level1)230 HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0007, Function | MediumTest | Level1)
231 {
232     char *argv[] = {
233         const_cast<char*>(TOOL_NAME.c_str()),
234         const_cast<char*>(overlay_.c_str()),
235         const_cast<char*>("-h"),
236         const_cast<char*>(""),
237     };
238     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
239 
240     BundleManagerShellCommand cmd(argc, argv);
241 
242     // set the mock objects
243     SetMockObjects(cmd);
244 
245     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_OVERLAY);
246 }
247 
248 /**
249  * @tc.number: Bm_Command_Overlay_0008
250  * @tc.name: ExecCommand
251  * @tc.desc: Verify the "bm dump-overlay -b <bundle-name>" command.
252  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0008, Function | MediumTest | Level1)253 HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0008, Function | MediumTest | Level1)
254 {
255     char *argv[] = {
256         const_cast<char*>(TOOL_NAME.c_str()),
257         const_cast<char*>(overlay_.c_str()),
258         const_cast<char*>("-b"),
259         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
260         const_cast<char*>(""),
261     };
262     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
263 
264     BundleManagerShellCommand cmd(argc, argv);
265 
266     // set the mock objects
267     SetMockObjects(cmd);
268 
269     EXPECT_EQ(cmd.ExecCommand(), STRING_DUMP_OVERLAY_NG + "\n");
270 }
271 
272 /**
273  * @tc.number: Bm_Command_Overlay_0009
274  * @tc.name: ExecCommand
275  * @tc.desc: Verify the "bm dump-overlay -m <module-name>" command.
276  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0009, Function | MediumTest | Level1)277 HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0009, Function | MediumTest | Level1)
278 {
279     char *argv[] = {
280         const_cast<char*>(TOOL_NAME.c_str()),
281         const_cast<char*>(overlay_.c_str()),
282         const_cast<char*>("-m"),
283         const_cast<char*>(STRING_MODULE_NAME.c_str()),
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(), STRING_DUMP_OVERLAY_NG + "\n");
294 }
295 
296 /**
297  * @tc.number: Bm_Command_Overlay_0010
298  * @tc.name: ExecCommand
299  * @tc.desc: Verify the "bm dump-overlay -t <target-module-name>" command.
300  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0010, Function | MediumTest | Level1)301 HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0010, Function | MediumTest | Level1)
302 {
303     char *argv[] = {
304         const_cast<char*>(TOOL_NAME.c_str()),
305         const_cast<char*>(overlay_.c_str()),
306         const_cast<char*>("-t"),
307         const_cast<char*>(STRING_MODULE_NAME.c_str()),
308         const_cast<char*>(""),
309     };
310     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
311 
312     BundleManagerShellCommand cmd(argc, argv);
313 
314     // set the mock objects
315     SetMockObjects(cmd);
316 
317     EXPECT_EQ(cmd.ExecCommand(), STRING_DUMP_OVERLAY_NG + "\n");
318 }
319 
320 /**
321  * @tc.number: Bm_Command_Overlay_0011
322  * @tc.name: ExecCommand
323  * @tc.desc: Verify the "bm dump-overlay -u <user-id>" command.
324  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0011, Function | MediumTest | Level1)325 HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0011, Function | MediumTest | Level1)
326 {
327     char *argv[] = {
328         const_cast<char*>(TOOL_NAME.c_str()),
329         const_cast<char*>(overlay_.c_str()),
330         const_cast<char*>("-u"),
331         const_cast<char*>("N"),
332         const_cast<char*>(""),
333     };
334     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
335 
336     BundleManagerShellCommand cmd(argc, argv);
337 
338     // set the mock objects
339     SetMockObjects(cmd);
340 
341     EXPECT_EQ(cmd.ExecCommand(), STRING_DUMP_OVERLAY_NG + "\n");
342 }
343 
344 /**
345  * @tc.number: Bm_Command_Overlay_0012
346  * @tc.name: ExecCommand
347  * @tc.desc: Verify the "bm dump-overlay -u <user-id>" command.
348  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0012, Function | MediumTest | Level1)349 HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0012, Function | MediumTest | Level1)
350 {
351     char *argv[] = {
352         const_cast<char*>(TOOL_NAME.c_str()),
353         const_cast<char*>(overlay_.c_str()),
354         const_cast<char*>("-u"),
355         const_cast<char*>(DEFAULT_USER_ID.c_str()),
356         const_cast<char*>(""),
357     };
358     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
359 
360     BundleManagerShellCommand cmd(argc, argv);
361 
362     // set the mock objects
363     SetMockObjects(cmd);
364 
365     EXPECT_EQ(cmd.ExecCommand(), STRING_DUMP_OVERLAY_NG + "\n");
366 }
367 
368 /**
369  * @tc.number: Bm_Command_Overlay_0013
370  * @tc.name: ExecCommand
371  * @tc.desc: Verify the "bm dump-overlay -u <user-id>" command.
372  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0013, Function | MediumTest | Level1)373 HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0013, Function | MediumTest | Level1)
374 {
375     char *argv[] = {
376         const_cast<char*>(TOOL_NAME.c_str()),
377         const_cast<char*>(overlay_.c_str()),
378         const_cast<char*>("-u"),
379         const_cast<char*>(ERR_USER_ID.c_str()),
380         const_cast<char*>(""),
381     };
382     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
383 
384     BundleManagerShellCommand cmd(argc, argv);
385 
386     // set the mock objects
387     SetMockObjects(cmd);
388 
389     EXPECT_EQ(cmd.ExecCommand(), STRING_DUMP_OVERLAY_NG + "\n");
390 }
391 
392 /**
393  * @tc.number: Bm_Command_Overlay_0014
394  * @tc.name: ExecCommand
395  * @tc.desc: Verify the "bm dump-overlay -b <bundle-name> -m -t" command.
396  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0014, Function | MediumTest | Level1)397 HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0014, Function | MediumTest | Level1)
398 {
399     char *argv[] = {
400         const_cast<char*>(TOOL_NAME.c_str()),
401         const_cast<char*>(overlay_.c_str()),
402         const_cast<char*>("-b"),
403         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
404         const_cast<char*>("-u"),
405         const_cast<char*>(DEFAULT_USER_ID.c_str()),
406         const_cast<char*>(""),
407     };
408     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
409 
410     BundleManagerShellCommand cmd(argc, argv);
411 
412     // set the mock objects
413     SetMockObjects(cmd);
414 
415     EXPECT_EQ(cmd.ExecCommand(), STRING_DUMP_OVERLAY_NG + "\n");
416 }
417 
418 /**
419  * @tc.number: Bm_Command_Overlay_0015
420  * @tc.name: ExecCommand
421  * @tc.desc: Verify the "bm dump-overlay -b <bundle-name> -m <module-name> -t" command.
422  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0015, Function | MediumTest | Level1)423 HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0015, Function | MediumTest | Level1)
424 {
425     char *argv[] = {
426         const_cast<char*>(TOOL_NAME.c_str()),
427         const_cast<char*>(overlay_.c_str()),
428         const_cast<char*>("-b"),
429         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
430         const_cast<char*>("-m"),
431         const_cast<char*>(STRING_MODULE_NAME.c_str()),
432         const_cast<char*>("-u"),
433         const_cast<char*>(DEFAULT_USER_ID.c_str()),
434         const_cast<char*>(""),
435     };
436     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
437 
438     BundleManagerShellCommand cmd(argc, argv);
439 
440     // set the mock objects
441     SetMockObjects(cmd);
442 
443     EXPECT_EQ(cmd.ExecCommand(), STRING_DUMP_OVERLAY_NG + "\n");
444 }
445 
446 /**
447  * @tc.number: Bm_Command_Overlay_0016
448  * @tc.name: ExecCommand
449  * @tc.desc: Verify the "bm dump-overlay -b <bundle-name> -m -t <target-module-name>" command.
450  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0016, Function | MediumTest | Level1)451 HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0016, Function | MediumTest | Level1)
452 {
453     char *argv[] = {
454         const_cast<char*>(TOOL_NAME.c_str()),
455         const_cast<char*>(overlay_.c_str()),
456         const_cast<char*>("-b"),
457         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
458         const_cast<char*>("-t"),
459         const_cast<char*>(STRING_MODULE_NAME.c_str()),
460         const_cast<char*>("-u"),
461         const_cast<char*>(DEFAULT_USER_ID.c_str()),
462         const_cast<char*>(""),
463     };
464     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
465 
466     BundleManagerShellCommand cmd(argc, argv);
467 
468     // set the mock objects
469     SetMockObjects(cmd);
470 
471     EXPECT_EQ(cmd.ExecCommand(), STRING_DUMP_OVERLAY_NG + "\n");
472 }
473 
474 /**
475  * @tc.number: Bm_Command_Overlay_0017
476  * @tc.name: ExecCommand
477  * @tc.desc: Verify the "bm dump-overlay -b <bundle-name>
478  *     -m <module-name> -t <target-module-name>" command.
479  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0017, Function | MediumTest | Level1)480 HWTEST_F(BmCommandOverlayTest, Bm_Command_Overlay_0017, Function | MediumTest | Level1)
481 {
482     char *argv[] = {
483         const_cast<char*>(TOOL_NAME.c_str()),
484         const_cast<char*>(overlay_.c_str()),
485         const_cast<char*>("-b"),
486         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
487         const_cast<char*>("-m"),
488         const_cast<char*>(STRING_MODULE_NAME.c_str()),
489         const_cast<char*>("-t"),
490         const_cast<char*>(STRING_MODULE_NAME.c_str()),
491         const_cast<char*>("-u"),
492         const_cast<char*>(DEFAULT_USER_ID.c_str()),
493         const_cast<char*>(""),
494     };
495     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
496 
497     BundleManagerShellCommand cmd(argc, argv);
498 
499     // set the mock objects
500     SetMockObjects(cmd);
501 
502     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_OVERLAY);
503 }
504 
505 /**
506  * @tc.number: Bm_Command_Target_Overlay_0001
507  * @tc.name: ExecCommand
508  * @tc.desc: Verify the "bm dump-target-overlay" command.
509  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0001, Function | MediumTest | Level1)510 HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0001, Function | MediumTest | Level1)
511 {
512     char *argv[] = {
513         const_cast<char*>(TOOL_NAME.c_str()),
514         const_cast<char*>(tOverlay_.c_str()),
515         const_cast<char*>(""),
516     };
517     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
518 
519     BundleManagerShellCommand cmd(argc, argv);
520 
521     // set the mock objects
522     SetMockObjects(cmd);
523 
524     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_NO_OPTION + "\n" + HELP_MSG_OVERLAY_TARGET);
525 }
526 
527 /**
528  * @tc.number: Bm_Command_Target_Overlay_0002
529  * @tc.name: ExecCommand
530  * @tc.desc: Verify the "bm dump-target-overlay -b" command.
531  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0002, Function | MediumTest | Level1)532 HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0002, Function | MediumTest | Level1)
533 {
534     char *argv[] = {
535         const_cast<char*>(TOOL_NAME.c_str()),
536         const_cast<char*>(tOverlay_.c_str()),
537         const_cast<char*>("-b"),
538         const_cast<char*>(""),
539     };
540     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
541 
542     BundleManagerShellCommand cmd(argc, argv);
543 
544     // set the mock objects
545     SetMockObjects(cmd);
546 
547     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_OVERLAY_TARGET);
548 }
549 
550 /**
551  * @tc.number: Bm_Command_Target_Overlay_0003
552  * @tc.name: ExecCommand
553  * @tc.desc: Verify the "bm dump-target-overlay -xxx" command.
554  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0003, Function | MediumTest | Level1)555 HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0003, Function | MediumTest | Level1)
556 {
557     char *argv[] = {
558         const_cast<char*>(TOOL_NAME.c_str()),
559         const_cast<char*>(tOverlay_.c_str()),
560         const_cast<char*>("-xxx"),
561         const_cast<char*>(""),
562     };
563     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
564 
565     BundleManagerShellCommand cmd(argc, argv);
566 
567     // set the mock objects
568     SetMockObjects(cmd);
569 
570     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_OVERLAY_TARGET);
571 }
572 
573 /**
574  * @tc.number: Bm_Command_Target_Overlay_0004
575  * @tc.name: ExecCommand
576  * @tc.desc: Verify the "bm dump-target-overlay -m" command.
577  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0004, Function | MediumTest | Level1)578 HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0004, Function | MediumTest | Level1)
579 {
580     char *argv[] = {
581         const_cast<char*>(TOOL_NAME.c_str()),
582         const_cast<char*>(tOverlay_.c_str()),
583         const_cast<char*>("-m"),
584         const_cast<char*>(""),
585     };
586     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
587 
588     BundleManagerShellCommand cmd(argc, argv);
589 
590     // set the mock objects
591     SetMockObjects(cmd);
592 
593     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_OVERLAY_TARGET);
594 }
595 
596 /**
597  * @tc.number: Bm_Command_Target_Overlay_0005
598  * @tc.name: ExecCommand
599  * @tc.desc: Verify the "bm dump-target-overlay -u" command.
600  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0005, Function | MediumTest | Level1)601 HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0005, Function | MediumTest | Level1)
602 {
603     char *argv[] = {
604         const_cast<char*>(TOOL_NAME.c_str()),
605         const_cast<char*>(tOverlay_.c_str()),
606         const_cast<char*>("-u"),
607         const_cast<char*>(""),
608     };
609     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
610 
611     BundleManagerShellCommand cmd(argc, argv);
612 
613     // set the mock objects
614     SetMockObjects(cmd);
615 
616     EXPECT_EQ(cmd.ExecCommand(), STRING_REQUIRE_CORRECT_VALUE + HELP_MSG_OVERLAY_TARGET);
617 }
618 
619 /**
620  * @tc.number: Bm_Command_Target_Overlay_0006
621  * @tc.name: ExecCommand
622  * @tc.desc: Verify the "bm dump-target-overlay -h" command.
623  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0006, Function | MediumTest | Level1)624 HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0006, Function | MediumTest | Level1)
625 {
626     char *argv[] = {
627         const_cast<char*>(TOOL_NAME.c_str()),
628         const_cast<char*>(tOverlay_.c_str()),
629         const_cast<char*>("-h"),
630         const_cast<char*>(""),
631     };
632     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
633 
634     BundleManagerShellCommand cmd(argc, argv);
635 
636     // set the mock objects
637     SetMockObjects(cmd);
638 
639     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_OVERLAY_TARGET);
640 }
641 
642 /**
643  * @tc.number: Bm_Command_Target_Overlay_0007
644  * @tc.name: ExecCommand
645  * @tc.desc: Verify the "bm dump-target-overlay -b <bundle-name>" command.
646  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0007, Function | MediumTest | Level1)647 HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0007, Function | MediumTest | Level1)
648 {
649     char *argv[] = {
650         const_cast<char*>(TOOL_NAME.c_str()),
651         const_cast<char*>(tOverlay_.c_str()),
652         const_cast<char*>("-b"),
653         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
654         const_cast<char*>("-u"),
655         const_cast<char*>(DEFAULT_USER_ID.c_str()),
656         const_cast<char*>(""),
657     };
658     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
659 
660     BundleManagerShellCommand cmd(argc, argv);
661 
662     // set the mock objects
663     SetMockObjects(cmd);
664 
665     EXPECT_EQ(cmd.ExecCommand(), STRING_DUMP_TARGET_OVERLAY_NG + "\n");
666 }
667 
668 /**
669  * @tc.number: Bm_Command_Target_Overlay_0008
670  * @tc.name: ExecCommand
671  * @tc.desc: Verify the "bm dump-overlay -m <module-name>" command.
672  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0008, Function | MediumTest | Level1)673 HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0008, Function | MediumTest | Level1)
674 {
675     char *argv[] = {
676         const_cast<char*>(TOOL_NAME.c_str()),
677         const_cast<char*>(tOverlay_.c_str()),
678         const_cast<char*>("-m"),
679         const_cast<char*>(STRING_MODULE_NAME.c_str()),
680         const_cast<char*>("-u"),
681         const_cast<char*>(DEFAULT_USER_ID.c_str()),
682         const_cast<char*>(""),
683     };
684     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
685 
686     BundleManagerShellCommand cmd(argc, argv);
687 
688     // set the mock objects
689     SetMockObjects(cmd);
690 
691     EXPECT_EQ(cmd.ExecCommand(), STRING_DUMP_TARGET_OVERLAY_NG + "\n");
692 }
693 
694 /**
695  * @tc.number: Bm_Command_Target_Overlay_0009
696  * @tc.name: ExecCommand
697  * @tc.desc: Verify the "bm dump-overlay -u <user-id>" command.
698  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0009, Function | MediumTest | Level1)699 HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0009, Function | MediumTest | Level1)
700 {
701     char *argv[] = {
702         const_cast<char*>(TOOL_NAME.c_str()),
703         const_cast<char*>(tOverlay_.c_str()),
704         const_cast<char*>("-u"),
705         const_cast<char*>("N"),
706         const_cast<char*>(""),
707     };
708     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
709 
710     BundleManagerShellCommand cmd(argc, argv);
711 
712     // set the mock objects
713     SetMockObjects(cmd);
714 
715     EXPECT_EQ(cmd.ExecCommand(), STRING_DUMP_TARGET_OVERLAY_NG + "\n");
716 }
717 
718 /**
719  * @tc.number: Bm_Command_Target_Overlay_0010
720  * @tc.name: ExecCommand
721  * @tc.desc: Verify the "bm dump-overlay -u <user-id>" command.
722  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0010, Function | MediumTest | Level1)723 HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0010, Function | MediumTest | Level1)
724 {
725     char *argv[] = {
726         const_cast<char*>(TOOL_NAME.c_str()),
727         const_cast<char*>(tOverlay_.c_str()),
728         const_cast<char*>("-u"),
729         const_cast<char*>(DEFAULT_USER_ID.c_str()),
730         const_cast<char*>(""),
731     };
732     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
733 
734     BundleManagerShellCommand cmd(argc, argv);
735 
736     // set the mock objects
737     SetMockObjects(cmd);
738 
739     EXPECT_EQ(cmd.ExecCommand(), STRING_DUMP_TARGET_OVERLAY_NG + "\n");
740 }
741 
742 /**
743  * @tc.number: Bm_Command_Target_Overlay_0012
744  * @tc.name: ExecCommand
745  * @tc.desc: Verify the "bm dump-overlay -b <bundle-name> -m <module-name> -t" command.
746  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0012, Function | MediumTest | Level1)747 HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0012, Function | MediumTest | Level1)
748 {
749     char *argv[] = {
750         const_cast<char*>(TOOL_NAME.c_str()),
751         const_cast<char*>(tOverlay_.c_str()),
752         const_cast<char*>("-b"),
753         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
754         const_cast<char*>("-m"),
755         const_cast<char*>(STRING_MODULE_NAME.c_str()),
756         const_cast<char*>("-u"),
757         const_cast<char*>(DEFAULT_USER_ID.c_str()),
758         const_cast<char*>(""),
759     };
760     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
761 
762     BundleManagerShellCommand cmd(argc, argv);
763 
764     // set the mock objects
765     SetMockObjects(cmd);
766 
767     EXPECT_EQ(cmd.ExecCommand(), STRING_DUMP_TARGET_OVERLAY_NG + "\n");
768 }
769 
770 /**
771  * @tc.number: Bm_Command_Target_Overlay_0013
772  * @tc.name: ExecCommand
773  * @tc.desc: Verify the "bm dump-overlay -b <bundle-name> -m" command.
774  */
HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0013, Function | MediumTest | Level1)775 HWTEST_F(BmCommandOverlayTest, Bm_Command_Target_Overlay_0013, Function | MediumTest | Level1)
776 {
777     char *argv[] = {
778         const_cast<char*>(TOOL_NAME.c_str()),
779         const_cast<char*>(tOverlay_.c_str()),
780         const_cast<char*>("-b"),
781         const_cast<char*>(STRING_BUNDLE_NAME.c_str()),
782         const_cast<char*>("-u"),
783         const_cast<char*>(DEFAULT_USER_ID.c_str()),
784         const_cast<char*>(""),
785     };
786     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
787 
788     BundleManagerShellCommand cmd(argc, argv);
789 
790     // set the mock objects
791     SetMockObjects(cmd);
792 
793     EXPECT_EQ(cmd.ExecCommand(), STRING_DUMP_TARGET_OVERLAY_NG + "\n");
794 }
795 } // namespace OHOS