1 /*
2  * Copyright (c) 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 protected public
19 #include "bundle_command.h"
20 #include "quick_fix_command.h"
21 #undef protected
22 
23 using namespace testing::ext;
24 using namespace OHOS;
25 using namespace OHOS::AppExecFwk;
26 const int QUICK_FIX_COPY_FILES_FAILED = 4;
27 const int QUICK_FIX_GET_BUNDLE_INFO_FAILED = 8;
28 const int QUICK_FIX_INVALID_VALUE = 22;
29 const int QUICK_FIX_OK = 0;
30 
31 namespace OHOS {
32 namespace AppExecFwk {
33 class BmCommandQuickFixTest : public testing::Test {
34 public:
35     static void SetUpTestCase();
36     static void TearDownTestCase();
37     void SetUp();
38     void TearDown();
39 
40     std::string cmd_ = "quickfix";
41 };
42 
SetUpTestCase()43 void BmCommandQuickFixTest::SetUpTestCase()
44 {}
45 
TearDownTestCase()46 void BmCommandQuickFixTest::TearDownTestCase()
47 {}
48 
SetUp()49 void BmCommandQuickFixTest::SetUp()
50 {
51     // reset optind to 0
52     optind = 0;
53 }
54 
TearDown()55 void BmCommandQuickFixTest::TearDown()
56 {}
57 
58 /**
59  * @tc.name: Bm_Command_QuickFix_0100
60  * @tc.desc: "bm quickfix" test.
61  * @tc.type: FUNC
62  * @tc.require: issueI5OCZV
63  */
64 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_0100, TestSize.Level1)
65 {
66     char *argv[] = {
67         const_cast<char*>(TOOL_NAME.c_str()),
68         const_cast<char*>(cmd_.c_str()),
69         const_cast<char*>(""),
70     };
71     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
72 
73     BundleManagerShellCommand cmd(argc, argv);
74 
75     EXPECT_EQ(cmd.ExecCommand(), "error: parameter is not enough.\n" + HELP_MSG_QUICK_FIX);
76 }
77 
78 /**
79  * @tc.name: Bm_Command_QuickFix_0200
80  * @tc.desc: "bm quickfix --invalid" test.
81  * @tc.type: FUNC
82  * @tc.require: issueI5OCZV
83  */
84 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_0200, TestSize.Level1)
85 {
86     char *argv[] = {
87         const_cast<char*>(TOOL_NAME.c_str()),
88         const_cast<char*>(cmd_.c_str()),
89         const_cast<char*>("--invalid"),
90         const_cast<char*>(""),
91     };
92     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
93 
94     BundleManagerShellCommand cmd(argc, argv);
95 
96     EXPECT_EQ(cmd.ExecCommand(), "error: unknown option.\n" + HELP_MSG_QUICK_FIX);
97 }
98 
99 /**
100  * @tc.name: Bm_Command_QuickFix_Help_0100
101  * @tc.desc: "bm quickfix -h" test.
102  * @tc.type: FUNC
103  * @tc.require: issueI5OCZV
104  */
105 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Help_0100, TestSize.Level1)
106 {
107     char *argv[] = {
108         const_cast<char*>(TOOL_NAME.c_str()),
109         const_cast<char*>(cmd_.c_str()),
110         const_cast<char*>("-h"),
111         const_cast<char*>(""),
112     };
113     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
114 
115     BundleManagerShellCommand cmd(argc, argv);
116 
117     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_QUICK_FIX);
118 }
119 
120 /**
121  * @tc.name: Bm_Command_QuickFix_Help_0200
122  * @tc.desc: "bm quickfix --help" test.
123  * @tc.type: FUNC
124  * @tc.require: issueI5OCZV
125  */
126 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Help_0200, TestSize.Level1)
127 {
128     char *argv[] = {
129         const_cast<char*>(TOOL_NAME.c_str()),
130         const_cast<char*>(cmd_.c_str()),
131         const_cast<char*>("--help"),
132         const_cast<char*>(""),
133     };
134     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
135 
136     BundleManagerShellCommand cmd(argc, argv);
137 
138     EXPECT_EQ(cmd.ExecCommand(), HELP_MSG_QUICK_FIX);
139 }
140 
141 /**
142  * @tc.name: Bm_Command_QuickFix_Apply_0100
143  * @tc.desc: "bm quickfix -a" test.
144  * @tc.type: FUNC
145  * @tc.require: issueI5OCZV
146  */
147 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Apply_0100, TestSize.Level1)
148 {
149     char *argv[] = {
150         const_cast<char*>(TOOL_NAME.c_str()),
151         const_cast<char*>(cmd_.c_str()),
152         const_cast<char*>("-a"),
153         const_cast<char*>(""),
154     };
155     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
156 
157     BundleManagerShellCommand cmd(argc, argv);
158 
159     EXPECT_EQ(cmd.ExecCommand(), "error: option [--apply] is incorrect.\n" + HELP_MSG_QUICK_FIX);
160 }
161 
162 /**
163  * @tc.name: Bm_Command_QuickFix_Apply_0200
164  * @tc.desc: "bm quickfix --apply" test.
165  * @tc.type: FUNC
166  * @tc.require: issueI5OCZV
167  */
168 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Apply_0200, TestSize.Level1)
169 {
170     char *argv[] = {
171         const_cast<char*>(TOOL_NAME.c_str()),
172         const_cast<char*>(cmd_.c_str()),
173         const_cast<char*>("--apply"),
174         const_cast<char*>(""),
175     };
176     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
177 
178     BundleManagerShellCommand cmd(argc, argv);
179 
180     EXPECT_EQ(cmd.ExecCommand(), "error: option [--apply] is incorrect.\n" + HELP_MSG_QUICK_FIX);
181 }
182 
183 /**
184  * @tc.name: Bm_Command_QuickFix_Apply_0300
185  * @tc.desc: "bm quickfix --apply --invalidKey" test.
186  * @tc.type: FUNC
187  * @tc.require: issueI5OCZV
188  */
189 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Apply_0300, TestSize.Level1)
190 {
191     char *argv[] = {
192         const_cast<char*>(TOOL_NAME.c_str()),
193         const_cast<char*>(cmd_.c_str()),
194         const_cast<char*>("--apply"),
195         const_cast<char*>("--invalidKey"),
196         const_cast<char*>(""),
197     };
198     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
199 
200     BundleManagerShellCommand cmd(argc, argv);
201 
202     EXPECT_EQ(cmd.ExecCommand(), "error: option [--apply] is incorrect.\n" + HELP_MSG_QUICK_FIX);
203 }
204 
205 /**
206  * @tc.name: Bm_Command_QuickFix_Apply_0400
207  * @tc.desc: "bm quickfix --apply --invalidKey invalidValue" test.
208  * @tc.type: FUNC
209  * @tc.require: issueI5OCZV
210  */
211 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Apply_0400, TestSize.Level1)
212 {
213     char *argv[] = {
214         const_cast<char*>(TOOL_NAME.c_str()),
215         const_cast<char*>(cmd_.c_str()),
216         const_cast<char*>("--apply"),
217         const_cast<char*>("--invalidKey"),
218         const_cast<char*>("invalidValue"),
219         const_cast<char*>(""),
220     };
221     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
222 
223     BundleManagerShellCommand cmd(argc, argv);
224 
225     EXPECT_EQ(cmd.ExecCommand(), "error: parameter is not enough.\n" + HELP_MSG_QUICK_FIX);
226 }
227 
228 /**
229  * @tc.name: Bm_Command_QuickFix_Apply_0500
230  * @tc.desc: "bm quickfix --apply -f <file-path>" test.
231  * @tc.type: FUNC
232  * @tc.require: issueI5OCZV
233  */
234 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Apply_0500, TestSize.Level1)
235 {
236     char *argv[] = {
237         const_cast<char*>(TOOL_NAME.c_str()),
238         const_cast<char*>(cmd_.c_str()),
239         const_cast<char*>("--apply"),
240         const_cast<char*>("-f"),
241         const_cast<char*>("/data/storage/el1/aa.hqf"),
242         const_cast<char*>(""),
243     };
244     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
245 
246     BundleManagerShellCommand cmd(argc, argv);
247 
248     EXPECT_EQ(cmd.ExecCommand(), "apply quickfix failed with errno: 4.\n");
249 }
250 
251 /**
252  * @tc.name: Bm_Command_QuickFix_Apply_0600
253  * @tc.desc: "bm quickfix --apply --file-path <file-path> <file-path>" test.
254  * @tc.type: FUNC
255  * @tc.require: issueI5OCZV
256  */
257 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Apply_0600, TestSize.Level1)
258 {
259     char *argv[] = {
260         const_cast<char*>(TOOL_NAME.c_str()),
261         const_cast<char*>(cmd_.c_str()),
262         const_cast<char*>("--apply"),
263         const_cast<char*>("--file-path"),
264         const_cast<char*>("/data/storage/el1/aa.hqf"),
265         const_cast<char*>("/data/storage/el2/bb.hqf"),
266         const_cast<char*>(""),
267     };
268     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
269 
270     BundleManagerShellCommand cmd(argc, argv);
271 
272     EXPECT_EQ(cmd.ExecCommand(), "apply quickfix failed with errno: 4.\n");
273 }
274 
275 /**
276  * @tc.name: Bm_Command_QuickFix_Apply_0700
277  * @tc.desc: "bm quickfix --apply --file-path <bundle-direction>" test.
278  * @tc.type: FUNC
279  * @tc.require: issueI5OCZV
280  */
281 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Apply_0700, TestSize.Level1)
282 {
283     char *argv[] = {
284         const_cast<char*>(TOOL_NAME.c_str()),
285         const_cast<char*>(cmd_.c_str()),
286         const_cast<char*>("--apply"),
287         const_cast<char*>("--file-path"),
288         const_cast<char*>("/data/storage/el1"),
289         const_cast<char*>(""),
290     };
291     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
292 
293     BundleManagerShellCommand cmd(argc, argv);
294 
295     EXPECT_EQ(cmd.ExecCommand(), "apply quickfix failed with errno: 4.\n");
296 }
297 
298 /**
299  * @tc.name: Bm_Command_QuickFix_Apply_0800
300  * @tc.desc: "bm quickfix --apply --file-path <bundle-direction> --target" test.
301  * @tc.type: FUNC
302  * @tc.require: issueI9R2WQ
303  */
304 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Apply_0800, TestSize.Level1)
305 {
306     char *argv[] = {
307         const_cast<char*>(TOOL_NAME.c_str()),
308         const_cast<char*>(cmd_.c_str()),
309         const_cast<char*>("--apply"),
310         const_cast<char*>("--file-path"),
311         const_cast<char*>("/data/storage/el1/aa.hqf"),
312         const_cast<char*>("--target"),
313         const_cast<char*>("../mydir"),
314         const_cast<char*>(""),
315     };
316     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
317 
318     BundleManagerShellCommand cmd(argc, argv);
319 
320     EXPECT_EQ(cmd.ExecCommand(), "apply quickfix failed with errno: 8520706.\n");
321 }
322 
323 /**
324  * @tc.name: Bm_Command_QuickFix_Apply_0900
325  * @tc.desc: "bm quickfix --apply --file-path <bundle-direction>  --target" test.
326  * @tc.type: FUNC
327  * @tc.require: issueI9R2WQ
328  */
329 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Apply_0900, TestSize.Level1)
330 {
331     char *argv[] = {
332         const_cast<char*>(TOOL_NAME.c_str()),
333         const_cast<char*>(cmd_.c_str()),
334         const_cast<char*>("--apply"),
335         const_cast<char*>("--file-path"),
336         const_cast<char*>("/data/storage/el1/aa.hqf"),
337         const_cast<char*>("--target"),
338         const_cast<char*>("mydir/subdir"),
339         const_cast<char*>(""),
340     };
341     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
342 
343     BundleManagerShellCommand cmd(argc, argv);
344 
345     EXPECT_EQ(cmd.ExecCommand(), "apply quickfix failed with errno: 8520706.\n");
346 }
347 
348 /**
349  * @tc.name: Bm_Command_QuickFix_Query_0100
350  * @tc.desc: "bm quickfix -q" test.
351  * @tc.type: FUNC
352  * @tc.require: issueI5OCZV
353  */
354 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Query_0100, TestSize.Level1)
355 {
356     char *argv[] = {
357         const_cast<char*>(TOOL_NAME.c_str()),
358         const_cast<char*>(cmd_.c_str()),
359         const_cast<char*>("-q"),
360         const_cast<char*>(""),
361     };
362     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
363 
364     BundleManagerShellCommand cmd(argc, argv);
365 
366     EXPECT_EQ(cmd.ExecCommand(), "error: option [--query] is incorrect.\n" + HELP_MSG_QUICK_FIX);
367 }
368 
369 /**
370  * @tc.name: Bm_Command_QuickFix_Query_0200
371  * @tc.desc: "bm quickfix --query" test.
372  * @tc.type: FUNC
373  * @tc.require: issueI5OCZV
374  */
375 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Query_0200, TestSize.Level1)
376 {
377     char *argv[] = {
378         const_cast<char*>(TOOL_NAME.c_str()),
379         const_cast<char*>(cmd_.c_str()),
380         const_cast<char*>("--query"),
381         const_cast<char*>(""),
382     };
383     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
384 
385     BundleManagerShellCommand cmd(argc, argv);
386 
387     EXPECT_EQ(cmd.ExecCommand(), "error: option [--query] is incorrect.\n" + HELP_MSG_QUICK_FIX);
388 }
389 
390 /**
391  * @tc.name: Bm_Command_QuickFix_Query_0300
392  * @tc.desc: "bm quickfix -q --invalidKey" test.
393  * @tc.type: FUNC
394  * @tc.require: issueI5OCZV
395  */
396 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Query_0300, TestSize.Level1)
397 {
398     char *argv[] = {
399         const_cast<char*>(TOOL_NAME.c_str()),
400         const_cast<char*>(cmd_.c_str()),
401         const_cast<char*>("-q"),
402         const_cast<char*>("--invalidKey"),
403         const_cast<char*>(""),
404     };
405     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
406 
407     BundleManagerShellCommand cmd(argc, argv);
408 
409     EXPECT_EQ(cmd.ExecCommand(), "error: option [--query] is incorrect.\n" + HELP_MSG_QUICK_FIX);
410 }
411 
412 /**
413  * @tc.name: Bm_Command_QuickFix_Query_0400
414  * @tc.desc: "bm quickfix --query --invalidKey invalidValue" test.
415  * @tc.type: FUNC
416  * @tc.require: issueI5OCZV
417  */
418 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Query_0400, TestSize.Level1)
419 {
420     char *argv[] = {
421         const_cast<char*>(TOOL_NAME.c_str()),
422         const_cast<char*>(cmd_.c_str()),
423         const_cast<char*>("--query"),
424         const_cast<char*>("--invalidKey"),
425         const_cast<char*>("invalidValue"),
426         const_cast<char*>(""),
427     };
428     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
429 
430     BundleManagerShellCommand cmd(argc, argv);
431 
432     EXPECT_EQ(cmd.ExecCommand(), "bundle name is empty.\n");
433 }
434 
435 /**
436  * @tc.name: Bm_Command_QuickFix_Query_0500
437  * @tc.desc: "bm quickfix --query -b <bundle-name>" test.
438  * @tc.type: FUNC
439  * @tc.require: issueI5OCZV
440  */
441 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Query_0500, TestSize.Level1)
442 {
443     char *argv[] = {
444         const_cast<char*>(TOOL_NAME.c_str()),
445         const_cast<char*>(cmd_.c_str()),
446         const_cast<char*>("--query"),
447         const_cast<char*>("-b"),
448         const_cast<char*>("bundleName1"),
449         const_cast<char*>(""),
450     };
451     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
452 
453     BundleManagerShellCommand cmd(argc, argv);
454 
455     EXPECT_EQ(cmd.ExecCommand(), "Get quick fix info failed with errno 8.\n");
456 }
457 
458 /**
459  * @tc.name: Bm_Command_QuickFix_Query_0600
460  * @tc.desc: "bm quickfix --query --bundle-name <bundle-name>" test.
461  * @tc.type: FUNC
462  * @tc.require: issueI5OCZV
463  */
464 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Query_0600, TestSize.Level1)
465 {
466     char *argv[] = {
467         const_cast<char*>(TOOL_NAME.c_str()),
468         const_cast<char*>(cmd_.c_str()),
469         const_cast<char*>("--query"),
470         const_cast<char*>("--bundle-name"),
471         const_cast<char*>("bundleName1"),
472         const_cast<char*>(""),
473     };
474     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
475 
476     BundleManagerShellCommand cmd(argc, argv);
477 
478     EXPECT_EQ(cmd.ExecCommand(), "Get quick fix info failed with errno 8.\n");
479 }
480 
481 /**
482  * @tc.name: Bm_Command_QuickFix_Query_0700
483  * @tc.desc: Test quickFixFiles is empty
484  * @tc.type: FUNC
485  * @tc.require: issueI5OCZV
486  */
487 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Query_0700, TestSize.Level1)
488 {
489     QuickFixCommand command;
490     std::vector<std::string> quickFixFiles;
491     std::string resultInfo;
492     auto ret = command.ApplyQuickFix(quickFixFiles, resultInfo);
493     EXPECT_EQ(resultInfo, "quick fix file is empty.\n");
494     EXPECT_EQ(ret, QUICK_FIX_INVALID_VALUE);
495 }
496 
497 /**
498  * @tc.name: Bm_Command_QuickFix_Query_0800
499  * @tc.desc: Test dir not have hqf file
500  * @tc.type: FUNC
501  * @tc.require: issueI5OCZV
502  */
503 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Query_0800, TestSize.Level1)
504 {
505     QuickFixCommand command;
506     std::vector<std::string> quickFixFiles = { "/data/null" };
507     std::string resultInfo;
508     auto ret = command.ApplyQuickFix(quickFixFiles, resultInfo);
509     EXPECT_EQ(resultInfo, "apply quickfix failed with errno: 4.\n");
510     EXPECT_EQ(ret, QUICK_FIX_COPY_FILES_FAILED);
511 }
512 
513 /**
514  * @tc.name: Bm_Command_QuickFix_Query_0900
515  * @tc.desc: Test empty bundleName
516  * @tc.type: FUNC
517  * @tc.require: issueI5OCZV
518  */
519 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Query_0900, TestSize.Level1)
520 {
521     QuickFixCommand command;
522     std::string bundleName;
523     std::string resultInfo;
524     auto ret = command.GetApplyedQuickFixInfo(bundleName, resultInfo);
525     EXPECT_EQ(resultInfo, "bundle name is empty.\n");
526     EXPECT_EQ(ret, QUICK_FIX_INVALID_VALUE);
527 }
528 
529 /**
530  * @tc.name: Bm_Command_QuickFix_Query_1000
531  * @tc.desc: Test right bundleName
532  * @tc.type: FUNC
533  * @tc.require: issueI5OCZV
534  */
535 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Query_1000, TestSize.Level1)
536 {
537     QuickFixCommand command;
538     std::string bundleName = "ohos.global.systemres";
539     std::string resultInfo;
540     auto ret = command.GetApplyedQuickFixInfo(bundleName, resultInfo);
541     EXPECT_EQ(ret, QUICK_FIX_OK);
542 }
543 
544 /**
545  * @tc.name: Bm_Command_QuickFix_Query_1100
546  * @tc.desc: Test wrong bundleName
547  * @tc.type: FUNC
548  * @tc.require: issueI5OCZV
549  */
550 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Query_1100, TestSize.Level1)
551 {
552     QuickFixCommand command;
553     std::string bundleName = "wrong";
554     std::string resultInfo;
555     auto ret = command.GetApplyedQuickFixInfo(bundleName, resultInfo);
556     EXPECT_EQ(ret, QUICK_FIX_GET_BUNDLE_INFO_FAILED);
557 }
558 
559 /**
560  * @tc.name: Bm_Command_QuickFix_Query_1200
561  * @tc.desc: Test GetQuickFixInfoString with different type
562  * @tc.type: FUNC
563  * @tc.require: issueI5OCZV
564  */
565 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Query_1200, TestSize.Level1)
566 {
567     QuickFixCommand command;
568     AAFwk::ApplicationQuickFixInfo quickFixInfo;
569     std::vector<HqfInfo> hqfInfos;
570     HqfInfo hq1;
571     hq1.moduleName = "step1";
572     hq1.hapSha256 = "step2";
573     hq1.hqfFilePath = "step3";
574     hqfInfos.emplace_back(hq1);
575     quickFixInfo.appqfInfo.hqfInfos = hqfInfos;
576     quickFixInfo.appqfInfo.type = AppExecFwk::QuickFixType::PATCH;
577     auto ret = command.GetQuickFixInfoString(quickFixInfo);
578     EXPECT_EQ(ret, "ApplicationQuickFixInfo:\n  bundle name: \n  bundle version code: 0\n  "
579         "bundle version name: \n  patch version code: 0\n  patch version name: \n  "
580         "cpu abi: \n  native library path: \n  type: patch\n  ModuelQuickFixInfo:\n    "
581         "module name: step1\n    module sha256: step2\n    "
582         "file path: step3\n");
583     quickFixInfo.appqfInfo.type = AppExecFwk::QuickFixType::HOT_RELOAD;
584     ret = command.GetQuickFixInfoString(quickFixInfo);
585     EXPECT_EQ(ret, "ApplicationQuickFixInfo:\n  bundle name: \n  bundle version code: 0\n  "
586         "bundle version name: \n  patch version code: 0\n  patch version name: \n  "
587         "cpu abi: \n  native library path: \n  type: hotreload\n  ModuelQuickFixInfo:\n    "
588         "module name: step1\n    module sha256: step2\n    "
589         "file path: step3\n");
590 }
591 
592 /**
593  * @tc.name: Bm_Command_QuickFix_Remove_0001
594  * @tc.desc: "bm quickfix -r" test.
595  * @tc.type: FUNC
596  * @tc.require: issueI9R2WQ
597  */
598 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Remove_0001, TestSize.Level1)
599 {
600     char *argv[] = {
601         const_cast<char*>(TOOL_NAME.c_str()),
602         const_cast<char*>(cmd_.c_str()),
603         const_cast<char*>("-r"),
604         const_cast<char*>(""),
605     };
606     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
607 
608     BundleManagerShellCommand cmd(argc, argv);
609 
610     EXPECT_EQ(cmd.ExecCommand(), "error: option [--remove] is incorrect.\n" + HELP_MSG_QUICK_FIX);
611 }
612 
613 /**
614  * @tc.name: Bm_Command_QuickFix_Remove_0002
615  * @tc.desc: "bm quickfix -r" test.
616  * @tc.type: FUNC
617  * @tc.require: issueI9R2WQ
618  */
619 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Remove_0002, TestSize.Level1)
620 {
621     char *argv[] = {
622         const_cast<char*>(TOOL_NAME.c_str()),
623         const_cast<char*>(cmd_.c_str()),
624         const_cast<char*>("-r"),
625         const_cast<char*>("-b"),
626         const_cast<char*>(""),
627     };
628     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
629 
630     BundleManagerShellCommand cmd(argc, argv);
631 
632     EXPECT_EQ(cmd.ExecCommand(), "error: option [--remove] is incorrect.\n" + HELP_MSG_QUICK_FIX);
633 }
634 
635 /**
636  * @tc.name: Bm_Command_QuickFix_Remove_0003
637  * @tc.desc: "bm quickfix -r" test.
638  * @tc.type: FUNC
639  * @tc.require: issueI9R2WQ
640  */
641 HWTEST_F(BmCommandQuickFixTest, Bm_Command_QuickFix_Remove_0003, TestSize.Level1)
642 {
643     char *argv[] = {
644         const_cast<char*>(TOOL_NAME.c_str()),
645         const_cast<char*>(cmd_.c_str()),
646         const_cast<char*>("-r"),
647         const_cast<char*>("-b"),
648         const_cast<char*>("com.test.bundle"),
649         const_cast<char*>(""),
650     };
651     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
652 
653     BundleManagerShellCommand cmd(argc, argv);
654 
655     EXPECT_EQ(cmd.ExecCommand(), "delete quick fix successfully\n");
656 }
657 } // namespace AAFwk
658 } // namespace OHOS
659