• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 private public
19 #include "notification_shell_command.h"
20 #undef private
21 #include "ans_inner_errors.h"
22 #include "ians_manager.h"
23 #include "mock_ans_manager_stub.h"
24 #include "singleton.h"
25 
26 using namespace testing::ext;
27 using namespace OHOS;
28 using namespace OHOS::Notification;
29 
30 namespace {
31 static char g_dumpHelpMsg[] =
32 "request a option 'A' or 'R' or 'D'\n"
33 "usage: anm dump [<options>]\n"
34 "options list:\n"
35 "  --help, -h                   help menu\n"
36 "  --active,  -A                 list all active notifications\n"
37 "  --recent,  -R                 list recent notifications\n"
38 "  --bundle,  -b  <name>         dump the info filter by the specified bundle name\n"
39 "  --user-id, -u  <userId>       dump the info filter by the specified userId\n"
40 "  --receiver, -r  <userId>       dump the info filter by the specified receiver userId\n";
41 
42 static char g_dumpActiveBound[] =
43 "error: option 'b' requires a value.\n"
44 "usage: anm dump [<options>]\noptions list:\n"
45 "  --help, -h                   help menu\n"
46 "  --active,  -A                 list all active notifications\n"
47 "  --recent,  -R                 list recent notifications\n"
48 "  --bundle,  -b  <name>         dump the info filter by the specified bundle name\n"
49 "  --user-id, -u  <userId>       dump the info filter by the specified userId\n"
50 "  --receiver, -r  <userId>       dump the info filter by the specified receiver userId\n";
51 
52 static char g_dumpActiveUser[] =
53 "error: option 'u' requires a value.\n"
54 "usage: anm dump [<options>]\n"
55 "options list:\n"
56 "  --help, -h                   help menu\n"
57 "  --active,  -A                 list all active notifications\n"
58 "  --recent,  -R                 list recent notifications\n"
59 "  --bundle,  -b  <name>         dump the info filter by the specified bundle name\n"
60 "  --user-id, -u  <userId>       dump the info filter by the specified userId\n"
61 "  --receiver, -r  <userId>       dump the info filter by the specified receiver userId\n";
62 
63 constexpr char SETTING_HELP_MSG[] =
64     "usage: anm setting [<options>]\n"
65     "options list:\n"
66     "  --help, -h                   help menu\n"
67     "  --recent-count -c <number>   set the max count of recent notifications keeping in memory\n"
68     "  --enable-notification -e <bundleName:uid:enable> set notification enabled for the bundle,"
69     " eg: -e com.example:10100:1\n"
70     "  --set-device-status -d <device:status> set device status, eg: -d device:1\n"
71     "  --collaboration-switch -k <device:enable> set collaboration status, eg: -k wearable:1\n"
72     "  --collaboration-switch-bundle -b <device:bundleName:bundleUid:status> set bundle collaboration switch status\n"
73     "      eg: -b wearable:example:10100:1\n"
74     "  --collaboration-switch-slot -o <device:slotType:status> set slot collaboration switch status\n"
75     "  --get-device-status -o <device> set device status\n"
76     "      eg: -o wearable:0:1\n";
77 
78 static char g_enableErrorInformation[] =
79 "error: option 'e' requires a value.\n"
80 "usage: anm setting [<options>]\n"
81 "options list:\n"
82 "  --help, -h                   help menu\n"
83 "  --recent-count -c <number>   set the max count of recent notifications keeping in memory\n"
84 "  --enable-notification -e <bundleName:uid:enable> set notification enabled for the bundle, "
85 "eg: -e com.example:10100:1\n"
86 "  --set-device-status -d <device:status> set device status, eg: -d device:1\n"
87 "  --collaboration-switch -k <device:enable> set collaboration status, eg: -k wearable:1\n"
88 "  --collaboration-switch-bundle -b <device:bundleName:bundleUid:status> set bundle collaboration switch status\n"
89 "      eg: -b wearable:example:10100:1\n"
90 "  --collaboration-switch-slot -o <device:slotType:status> set slot collaboration switch status\n"
91 "  --get-device-status -o <device> set device status\n"
92 "      eg: -o wearable:0:1\n";
93 
94 static char g_enableBundleNameNull[] =
95 "error: setting information error\n"
96 "usage: anm setting [<options>]\n"
97 "options list:\n  --help, -h                   help menu\n"
98 "  --recent-count -c <number>   set the max count of recent notifications keeping in memory\n  --enable-notification"
99 " -e <bundleName:uid:enable> set notification enabled for the bundle, eg: -e com.example:10100:1\n  --set-device-status"
100 " -d <device:status> set device status, eg: -d device:1\n"
101 "  --collaboration-switch -k <device:enable> set collaboration status, eg: -k wearable:1\n"
102 "  --collaboration-switch-bundle -b <device:bundleName:bundleUid:status> set bundle collaboration switch status\n"
103 "      eg: -b wearable:example:10100:1\n"
104 "  --collaboration-switch-slot -o <device:slotType:status> set slot collaboration switch status\n"
105 "  --get-device-status -o <device> set device status\n"
106 "      eg: -o wearable:0:1\n";
107 
108 static char g_enableObjectNull[] =
109 "error: object is null\n"
110 "error: object is null\n"
111 "usage: anm setting [<options>]\n"
112 "options list:\n  --help, -h                   help menu\n"
113 "  --recent-count -c <number>   set the max count of recent notifications keeping in memory\n  --enable-notification"
114 " -e <bundleName:uid:enable> set notification enabled for the bundle, eg: -e com.example:10100:1\n  --set-device-status"
115 " -d <device:status> set device status, eg: -d device:1\n"
116 "  --collaboration-switch -k <device:enable> set collaboration status, eg: -k wearable:1\n"
117 "  --collaboration-switch-bundle -b <device:bundleName:bundleUid:status> set bundle collaboration switch status\n"
118 "      eg: -b wearable:example:10100:1\n"
119 "  --collaboration-switch-slot -o <device:slotType:status> set slot collaboration switch status\n"
120 "  --get-device-status -o <device> set device status\n"
121 "      eg: -o wearable:0:1\n";
122 
123 static char g_unknownOption[] =
124 "error: unknown option.\n"
125 "usage: anm dump [<options>]\n"
126 "options list:\n"
127 "  --help, -h                   help menu\n"
128 "  --active,  -A                 list all active notifications\n"
129 "  --recent,  -R                 list recent notifications\n"
130 "  --bundle,  -b  <name>         dump the info filter by the specified bundle name\n"
131 "  --user-id, -u  <userId>       dump the info filter by the specified userId\n"
132 "  --receiver, -r  <userId>       dump the info filter by the specified receiver userId\n";
133 
134 static char g_dumpActiveCount[] =
135 "error: option 'c' requires a value.\n"
136 "usage: anm setting [<options>]\n"
137 "options list:\n"
138 "  --help, -h                   help menu\n"
139 "  --recent-count -c <number>   set the max count of recent notifications keeping in memory\n  --enable-notification"
140 " -e <bundleName:uid:enable> set notification enabled for the bundle, eg: -e com.example:10100:1\n  --set-device-status"
141 " -d <device:status> set device status, eg: -d device:1\n"
142 "  --collaboration-switch -k <device:enable> set collaboration status, eg: -k wearable:1\n"
143 "  --collaboration-switch-bundle -b <device:bundleName:bundleUid:status> set bundle collaboration switch status\n"
144 "      eg: -b wearable:example:10100:1\n"
145 "  --collaboration-switch-slot -o <device:slotType:status> set slot collaboration switch status\n"
146 "  --get-device-status -o <device> set device status\n"
147 "      eg: -o wearable:0:1\n";
148 
149 static char g_helpMsg[] =
150 "error: unknown option.\n"
151 "usage: anm dump [<options>]\n"
152 "options list:\n"
153 "  --help, -h                   help menu\n"
154 "  --active,  -A                 list all active notifications\n"
155 "  --recent,  -R                 list recent notifications\n"
156 "  --bundle,  -b  <name>         dump the info filter by the specified bundle name\n"
157 "  --user-id, -u  <userId>       dump the info filter by the specified userId\n"
158 "  --receiver, -r  <userId>       dump the info filter by the specified receiver userId\n"
159 "usage: anm dump [<options>]\n"
160 "options list:\n"
161 "  --help, -h                   help menu\n"
162 "  --active,  -A                 list all active notifications\n"
163 "  --recent,  -R                 list recent notifications\n"
164 "  --bundle,  -b  <name>         dump the info filter by the specified bundle name\n"
165 "  --user-id, -u  <userId>       dump the info filter by the specified userId\n"
166 "  --receiver, -r  <userId>       dump the info filter by the specified receiver userId\n";
167 
168 class AnmManagerDumpTest : public testing::Test {
169 public:
170     static void SetUpTestCase();
171     static void TearDownTestCase();
172     void SetUp() override;
173     void TearDown() override;
174 
175     void MakeMockObjects();
176 
177     std::string cmd_ = "dump";
178     std::string enable_ = "setting";
179     std::string toolName_ = "anm";
180     sptr<IAnsManager> proxyPtr_;
181     sptr<MockAnsManagerStub> stubPtr_;
182 };
183 
SetUpTestCase()184 void AnmManagerDumpTest::SetUpTestCase()
185 {}
186 
TearDownTestCase()187 void AnmManagerDumpTest::TearDownTestCase()
188 {}
189 
SetUp()190 void AnmManagerDumpTest::SetUp()
191 {
192     // reset optind to 0
193     optind = 0;
194 
195     // make mock objects
196     MakeMockObjects();
197 }
198 
TearDown()199 void AnmManagerDumpTest::TearDown()
200 {}
201 
MakeMockObjects()202 void AnmManagerDumpTest::MakeMockObjects()
203 {
204     // mock a stub
205     stubPtr_ = new (std::nothrow) MockAnsManagerStub();
206 
207     // mock a proxy
208     proxyPtr_ = iface_cast<IAnsManager>(stubPtr_);
209 
210     // set the mock proxy
211     auto ansNotificationPtr = DelayedSingleton<AnsNotification>::GetInstance();
212 }
213 
214 /**
215  * @tc.number: Anm_Command_Dump_0100
216  * @tc.name: ExecCommand
217  * @tc.desc: Verify the "anm dump -h" command.
218  */
219 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_0100, Function | MediumTest | Level1)
220 {
221     char *argv[] = {
222         (char *)toolName_.c_str(),
223         (char *)cmd_.c_str(),
224         (char *)"-h",
225         (char *)"",
226     };
227     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
228 
229     NotificationShellCommand cmd(argc, argv);
230 
231     EXPECT_EQ(cmd.ExecCommand(), g_dumpHelpMsg);
232 }
233 
234 /**
235  * @tc.number: Anm_Command_Dump_0200
236  * @tc.name: ExecCommand
237  * @tc.desc: Verify the "anm dump -A" command.
238  */
239 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_0200, Function | MediumTest | Level1)
240 {
241     char *argv[] = {
242         (char *)toolName_.c_str(),
243         (char *)cmd_.c_str(),
244         (char *)"-A",
245         (char *)"",
246     };
247     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
248 
249     NotificationShellCommand cmd(argc, argv);
250 
251     cmd.ExecCommand();
252 
253     EXPECT_EQ(stubPtr_->GetCmd(), "");
254 }
255 
256 /**
257  * @tc.number: Anm_Command_Dump_0300
258  * @tc.name: ExecCommand
259  * @tc.desc: Verify the "anm dump -R" command.
260  */
261 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_0300, Function | MediumTest | Level1)
262 {
263     char *argv[] = {
264         (char *)toolName_.c_str(),
265         (char *)cmd_.c_str(),
266         (char *)"-R",
267         (char *)"",
268     };
269     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
270 
271     NotificationShellCommand cmd(argc, argv);
272 
273     cmd.ExecCommand();
274 
275     EXPECT_EQ(stubPtr_->GetCmd(), "");
276 }
277 
278 /**
279  * @tc.number: Anm_Command_Dump_0400
280  * @tc.name: ExecCommand
281  * @tc.desc: Verify the "anm dump -R -b" command.
282  */
283 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_0400, Function | MediumTest | Level1)
284 {
285     char *argv[] = {
286         (char *)toolName_.c_str(),
287         (char *)cmd_.c_str(),
288         (char *)"-R",
289         (char *)"-b",
290         (char *)"",
291     };
292     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
293 
294     NotificationShellCommand cmd(argc, argv);
295 
296     EXPECT_EQ(cmd.ExecCommand(), g_dumpActiveBound);
297 }
298 
299 /**
300  * @tc.number: Anm_Command_Dump_0500
301  * @tc.name: ExecCommand
302  * @tc.desc: Verify the "anm dump -A -b example" command.
303  */
304 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_0500, Function | MediumTest | Level1)
305 {
306     char *argv[] = {
307         (char *)toolName_.c_str(),
308         (char *)cmd_.c_str(),
309         (char *)"-A",
310         (char *)"-b",
311         (char *)"example",
312         (char *)"",
313     };
314     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
315 
316     NotificationShellCommand cmd(argc, argv);
317 
318     cmd.ExecCommand();
319 
320     EXPECT_EQ(stubPtr_->GetCmd(), "");
321     EXPECT_EQ(stubPtr_->GetBundle(), "");
322 }
323 
324 /**
325  * @tc.number: Anm_Command_Dump_0600
326  * @tc.name: ExecCommand
327  * @tc.desc: Verify the "anm dump -A -b" command.
328  */
329 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_0600, Function | MediumTest | Level1)
330 {
331     char *argv[] = {
332         (char *)toolName_.c_str(),
333         (char *)cmd_.c_str(),
334         (char *)"-A",
335         (char *)"-b",
336         (char *)"",
337     };
338     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
339 
340     NotificationShellCommand cmd(argc, argv);
341 
342     EXPECT_EQ(cmd.ExecCommand(), g_dumpActiveBound);
343 }
344 
345 /**
346  * @tc.number: Anm_Command_Dump_0700
347  * @tc.name: ExecCommand
348  * @tc.desc: Verify the "anm dump -R -b example" command.
349  */
350 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_0700, Function | MediumTest | Level1)
351 {
352     char *argv[] = {
353         (char *)toolName_.c_str(),
354         (char *)cmd_.c_str(),
355         (char *)"-R",
356         (char *)"-b",
357         (char *)"example",
358         (char *)"",
359     };
360     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
361 
362     NotificationShellCommand cmd(argc, argv);
363 
364     cmd.ExecCommand();
365 
366     EXPECT_EQ(stubPtr_->GetCmd(), "");
367     EXPECT_EQ(stubPtr_->GetBundle(), "");
368 }
369 
370 /**
371  * @tc.number: Anm_Command_Dump_0800
372  * @tc.name: ExecCommand
373  * @tc.desc: Verify the "anm dump -R -u" command.
374  */
375 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_0800, Function | MediumTest | Level1)
376 {
377     char *argv[] = {
378         (char *)toolName_.c_str(),
379         (char *)cmd_.c_str(),
380         (char *)"-R",
381         (char *)"-u",
382         (char *)"",
383     };
384     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
385 
386     NotificationShellCommand cmd(argc, argv);
387 
388     EXPECT_EQ(cmd.ExecCommand(), g_dumpActiveUser);
389 }
390 
391 /**
392  * @tc.number: Anm_Command_Dump_0900
393  * @tc.name: ExecCommand
394  * @tc.desc: Verify the "anm dump -A -u" command.
395  */
396 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_0900, Function | MediumTest | Level1)
397 {
398     char *argv[] = {
399         (char *)toolName_.c_str(),
400         (char *)cmd_.c_str(),
401         (char *)"-A",
402         (char *)"-u",
403         (char *)"",
404     };
405     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
406 
407     NotificationShellCommand cmd(argc, argv);
408 
409     EXPECT_EQ(cmd.ExecCommand(), g_dumpActiveUser);
410 }
411 
412 /**
413  * @tc.number: Anm_Command_Dump_1000
414  * @tc.name: ExecCommand
415  * @tc.desc: Verify the "anm dump -A -u 33" command.
416  */
417 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_1000, Function | MediumTest | Level1)
418 {
419     char *argv[] = {
420         (char *)toolName_.c_str(),
421         (char *)cmd_.c_str(),
422         (char *)"-A",
423         (char *)"-u",
424         (char *)"33",
425         (char *)"",
426     };
427     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
428 
429     NotificationShellCommand cmd(argc, argv);
430 
431     cmd.ExecCommand();
432 
433     EXPECT_EQ(stubPtr_->GetCmd(), "");
434     EXPECT_EQ(stubPtr_->GetUserId(), 0);
435 }
436 
437 /**
438  * @tc.number: Anm_Command_Dump_1100
439  * @tc.name: ExecCommand
440  * @tc.desc: Verify the "anm dump -R -u 33" command.
441  */
442 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_1100, Function | MediumTest | Level1)
443 {
444     char *argv[] = {
445         (char *)toolName_.c_str(),
446         (char *)cmd_.c_str(),
447         (char *)"-R",
448         (char *)"-u",
449         (char *)"33",
450         (char *)"",
451     };
452     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
453 
454     NotificationShellCommand cmd(argc, argv);
455 
456     cmd.ExecCommand();
457 
458     EXPECT_EQ(stubPtr_->GetCmd(), "");
459     EXPECT_EQ(stubPtr_->GetUserId(), 0);
460 }
461 
462 /**
463  * @tc.number: Anm_Command_Dump_1200
464  * @tc.name: RunAsSettingCommand
465  * @tc.desc: test RunAsSettingCommand function
466  */
467 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_1200, Function | MediumTest | Level1)
468 {
469     char *argv[] = {
470         (char *)toolName_.c_str(),
471         (char *)cmd_.c_str(),
472         (char *)"-h",
473         (char *)"",
474     };
475     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
476 
477     NotificationShellCommand cmd(argc, argv);
478 
479     EXPECT_EQ(cmd.RunAsSettingCommand(), ERR_INVALID_VALUE);
480 }
481 
482 /**
483  * @tc.number: Anm_Command_Dump_1300
484  * @tc.name: RunSetEnableCmd
485  * @tc.desc: test RunSetEnableCmd function
486  */
487 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_1300, Function | MediumTest | Level1)
488 {
489     char *argv[] = {
490         (char *)toolName_.c_str(),
491         (char *)cmd_.c_str(),
492         (char *)"-h",
493         (char *)"",
494     };
495     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
496 
497     NotificationShellCommand cmd(argc, argv);
498 
499     EXPECT_EQ(cmd.RunSetEnableCmd(), ERR_ANS_SERVICE_NOT_CONNECTED);
500 }
501 
502 /**
503  * @tc.number: Anm_Command_Dump_1400
504  * @tc.name: GetCommandErrorMsg
505  * @tc.desc: test GetCommandErrorMsg function
506  */
507 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_1400, Function | MediumTest | Level1)
508 {
509     char *argv[] = {
510         (char *)toolName_.c_str(),
511         (char *)cmd_.c_str(),
512         (char *)"-h",
513         (char *)"",
514     };
515     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
516 
517     NotificationShellCommand cmd(argc, argv);
518 
519     EXPECT_EQ(cmd.GetCommandErrorMsg(), "anm_dump: 'dump' is not a valid anm_dump command. See 'anm_dump help'.\n");
520 }
521 
522 /**
523  * @tc.number: Anm_Command_Dump_1500
524  * @tc.name: GetUnknownOptionMsg
525  * @tc.desc: test GetUnknownOptionMsg function
526  */
527 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_1500, Function | MediumTest | Level1)
528 {
529     char *argv[] = {
530         (char *)toolName_.c_str(),
531         (char *)cmd_.c_str(),
532         (char *)"-h",
533         (char *)"",
534     };
535     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
536 
537     NotificationShellCommand cmd(argc, argv);
538 
539     std::string unknownOption = "aa";
540 
541     EXPECT_EQ(cmd.GetUnknownOptionMsg(unknownOption), "error: unknown option.\n");
542 }
543 
544 /**
545  * @tc.number: Anm_Command_Dump_1600
546  * @tc.name: GetMessageFromCode
547  * @tc.desc: test GetMessageFromCode function
548  */
549 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_1600, Function | MediumTest | Level1)
550 {
551     char *argv[] = {
552         (char *)toolName_.c_str(),
553         (char *)cmd_.c_str(),
554         (char *)"-h",
555         (char *)"",
556     };
557     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
558 
559     NotificationShellCommand cmd(argc, argv);
560 
561     int32_t code = 11;
562 
563     EXPECT_EQ(cmd.GetMessageFromCode(code), "");
564 }
565 
566 /**
567  * @tc.number: Anm_Command_Dump_1700
568  * @tc.name: RunAsSettingCommand
569  * @tc.desc: Verify the "anm setting -e bundleName:uid:enable" command.
570  */
571 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_1700, Function | MediumTest | Level1)
572 {
573     char *argv[] = {
574         (char *)toolName_.c_str(),
575         (char *)enable_.c_str(),
576         (char *)"-e",
577         (char *)"dd:ss:aa",
578         (char *)"",
579     };
580     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
581 
582     NotificationShellCommand cmd(argc, argv);
583 
584     EXPECT_EQ(cmd.ExecCommand(),
585         "set notification enabled failed\nfailed reason is Failed to connect to the service\n");
586 }
587 
588 /**
589  * @tc.number: Anm_Command_Dump_1800
590  * @tc.name: RunAsSettingCommand
591  * @tc.desc: Verify the "anm setting -e" command.
592  */
593 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_1800, Function | MediumTest | Level1)
594 {
595     char *argv[] = {
596         (char *)toolName_.c_str(),
597         (char *)enable_.c_str(),
598         (char *)"-e",
599         (char *)"",
600     };
601     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
602 
603     NotificationShellCommand cmd(argc, argv);
604 
605     EXPECT_EQ(cmd.ExecCommand(), g_enableErrorInformation);
606 }
607 
608 /**
609  * @tc.number: Anm_Command_Dump_1900
610  * @tc.name: RunAsSettingCommand
611  * @tc.desc: Verify the "anm setting -e bundleName:uid" command.
612  */
613 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_1900, Function | MediumTest | Level1)
614 {
615     char *argv[] = {
616         (char *)toolName_.c_str(),
617         (char *)enable_.c_str(),
618         (char *)"-e",
619         (char *)"dd:ss",
620         (char *)"",
621     };
622     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
623 
624     NotificationShellCommand cmd(argc, argv);
625 
626     EXPECT_EQ(cmd.ExecCommand(), g_enableBundleNameNull);
627 }
628 
629 /**
630  * @tc.number: Anm_Command_Dump_2000
631  * @tc.name: RunAsSettingCommand
632  * @tc.desc: Verify the "anm setting -e bundleName:uid:enable" command.
633  */
634 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_2000, Function | MediumTest | Level1)
635 {
636     char *argv[] = {
637         (char *)toolName_.c_str(),
638         (char *)enable_.c_str(),
639         (char *)"-e",
640         (char *)"22",
641         (char *)"",
642     };
643     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
644 
645     NotificationShellCommand cmd(argc, argv);
646 
647     EXPECT_EQ(cmd.RunSetEnableCmd(), cmd.RunAsSettingCommand());
648     EXPECT_EQ(cmd.ExecCommand(), g_enableObjectNull);
649 }
650 
651 /**
652  * @tc.number: Anm_Command_Dump_2100
653  * @tc.name: RunAsSettingCommand
654  * @tc.desc: Verify the "anm setting -e bundleName:uid:enable" command.
655  */
656 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_2100, Function | MediumTest | Level1)
657 {
658     char *argv[] = {
659         (char *)toolName_.c_str(),
660         (char *)enable_.c_str(),
661         (char *)"-e",
662         (char *)"gg:ss:aa",
663         (char *)"22",
664         (char *)"",
665     };
666     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
667 
668     NotificationShellCommand cmd(argc, argv);
669 
670     EXPECT_EQ(cmd.ExecCommand(), "set notification enabled success\n");
671 }
672 
673 /**
674  * @tc.number: Anm_Command_Dump_2100
675  * @tc.name: RunAsSettingCommand
676  * @tc.desc: Verify the "anm setting -g phone" command.
677  */
678 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Setting_2100, Function | MediumTest | Level1)
679 {
680     char *argv[] = {
681         (char *)toolName_.c_str(),
682         (char *)enable_.c_str(),
683         (char *)"-g",
684         (char *)"phone",
685         (char *)"",
686     };
687     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
688 
689     NotificationShellCommand cmd(argc, argv);
690 
691     EXPECT_EQ(cmd.ExecCommand(), "Get device status success: 0\n");
692 }
693 
694 /**
695  * @tc.number: Anm_Command_Dump_2100
696  * @tc.name: RunAsSettingCommand
697  * @tc.desc: Verify the "anm setting -g 2in1" command.
698  */
699 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Setting_2101, Function | MediumTest | Level1)
700 {
701     char *argv[] = {
702         (char *)toolName_.c_str(),
703         (char *)enable_.c_str(),
704         (char *)"-g",
705         (char *)"2in1",
706         (char *)"",
707     };
708     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
709 
710     NotificationShellCommand cmd(argc, argv);
711 
712     EXPECT_EQ(cmd.ExecCommand(),
713         "Get device status failed\nfailed reason is Failed to connect to the service\n");
714 }
715 
716 /**
717  * @tc.number: Anm_Command_Dump_2100
718  * @tc.name: RunAsSettingCommand
719  * @tc.desc: Verify the "anm setting -g phone" command.
720  */
721 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Setting_2102, Function | MediumTest | Level1)
722 {
723     char *argv[] = {
724         (char *)toolName_.c_str(),
725         (char *)enable_.c_str(),
726         (char *)"-g",
727         (char *)"",
728     };
729     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
730 
731     NotificationShellCommand cmd(argc, argv);
732 
733     std::string result = "error: option 'g' requires a value.\n";
734     result.append(SETTING_HELP_MSG);
735     EXPECT_EQ(cmd.ExecCommand(), result);
736 }
737 
738 /**
739  * @tc.number: Anm_Command_Dump_2100
740  * @tc.name: RunAsSettingCommand
741  * @tc.desc: Verify the "anm setting -g phone" command.
742  */
743 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Setting_2103, Function | MediumTest | Level1)
744 {
745     char *argv[] = {
746         (char *)toolName_.c_str(),
747         (char *)enable_.c_str(),
748         (char *)"-g",
749         (char *)"",
750         (char *)"",
751     };
752     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
753 
754     NotificationShellCommand cmd(argc, argv);
755 
756     EXPECT_EQ(cmd.ExecCommand(), "error: getting information error\n");
757 }
758 
759 /**
760  * @tc.number: Anm_Command_Dump_2100
761  * @tc.name: RunAsSettingCommand
762  * @tc.desc: Verify the "anm setting -d phone:1" command.
763  */
764 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Setting_2200, Function | MediumTest | Level1)
765 {
766     char *argv[] = {
767         (char *)toolName_.c_str(),
768         (char *)enable_.c_str(),
769         (char *)"-d",
770         (char *)"phone:1",
771         (char *)"",
772     };
773     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
774 
775     NotificationShellCommand cmd(argc, argv);
776 
777     EXPECT_EQ(cmd.ExecCommand(), "set device status success\n");
778 }
779 
780 /**
781  * @tc.number: Anm_Command_Dump_2100
782  * @tc.name: RunAsSettingCommand
783  * @tc.desc: Verify the "anm setting -d 2in1:1" command.
784  */
785 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Setting_2201, Function | MediumTest | Level1)
786 {
787     char *argv[] = {
788         (char *)toolName_.c_str(),
789         (char *)enable_.c_str(),
790         (char *)"-d",
791         (char *)"2in1:1",
792         (char *)"",
793     };
794     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
795 
796     NotificationShellCommand cmd(argc, argv);
797 
798     EXPECT_EQ(cmd.ExecCommand(), "set device status failed\nfailed reason is Failed to connect to the service\n");
799 }
800 
801 /**
802  * @tc.number: Anm_Command_Dump_2100
803  * @tc.name: RunAsSettingCommand
804  * @tc.desc: Verify the "anm setting -d phone:1" command.
805  */
806 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Setting_2202, Function | MediumTest | Level1)
807 {
808     char *argv[] = {
809         (char *)toolName_.c_str(),
810         (char *)enable_.c_str(),
811         (char *)"-d",
812         (char *)"",
813     };
814     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
815 
816     NotificationShellCommand cmd(argc, argv);
817 
818     std::string result = "error: option 'd' requires a value.\n";
819     result.append(SETTING_HELP_MSG);
820     EXPECT_EQ(cmd.ExecCommand(), result);
821 }
822 
823 /**
824  * @tc.number: Anm_Command_Dump_2100
825  * @tc.name: RunAsSettingCommand
826  * @tc.desc: Verify the "anm setting -d 2in1:1" command.
827  */
828 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Setting_2203, Function | MediumTest | Level1)
829 {
830     char *argv[] = {
831         (char *)toolName_.c_str(),
832         (char *)enable_.c_str(),
833         (char *)"-d",
834         (char *)"2in1",
835         (char *)"",
836     };
837     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
838 
839     NotificationShellCommand cmd(argc, argv);
840 
841     std::string result = "error: setting information error\n";
842     result.append(SETTING_HELP_MSG);
843     EXPECT_EQ(cmd.ExecCommand(), result);
844 }
845 
846 /**
847  * @tc.number: Anm_Command_Dump_2100
848  * @tc.name: RunAsSettingCommand
849  * @tc.desc: Verify the "anm setting -k phone:1" command.
850  */
851 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Setting_2300, Function | MediumTest | Level1)
852 {
853     char *argv[] = {
854         (char *)toolName_.c_str(),
855         (char *)enable_.c_str(),
856         (char *)"-k",
857         (char *)"phone:1",
858         (char *)"",
859     };
860     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
861 
862     NotificationShellCommand cmd(argc, argv);
863 
864     EXPECT_EQ(cmd.ExecCommand(), "set collaboration switch success\n");
865 }
866 
867 /**
868  * @tc.number: Anm_Command_Dump_2100
869  * @tc.name: RunAsSettingCommand
870  * @tc.desc: Verify the "anm setting -k phone:1" command.
871  */
872 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Setting_2301, Function | MediumTest | Level1)
873 {
874     char *argv[] = {
875         (char *)toolName_.c_str(),
876         (char *)enable_.c_str(),
877         (char *)"-k",
878         (char *)"2in1:1",
879         (char *)"",
880     };
881     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
882 
883     NotificationShellCommand cmd(argc, argv);
884 
885     EXPECT_EQ(cmd.ExecCommand(),
886         "set collaboration switch failed\nfailed reason is Failed to connect to the service\n");
887 }
888 
889 /**
890  * @tc.number: Anm_Command_Dump_2100
891  * @tc.name: RunAsSettingCommand
892  * @tc.desc: Verify the "anm setting -k phone:1" command.
893  */
894 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Setting_2302, Function | MediumTest | Level1)
895 {
896     char *argv[] = {
897         (char *)toolName_.c_str(),
898         (char *)enable_.c_str(),
899         (char *)"-k",
900         (char *)"",
901     };
902     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
903 
904     NotificationShellCommand cmd(argc, argv);
905 
906     std::string result = "error: option 'k' requires a value.\n";
907     result.append(SETTING_HELP_MSG);
908     EXPECT_EQ(cmd.ExecCommand(), result);
909 }
910 
911 /**
912  * @tc.number: Anm_Command_Dump_2100
913  * @tc.name: RunAsSettingCommand
914  * @tc.desc: Verify the "anm setting -k phone:1" command.
915  */
916 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Setting_2303, Function | MediumTest | Level1)
917 {
918     char *argv[] = {
919         (char *)toolName_.c_str(),
920         (char *)enable_.c_str(),
921         (char *)"-k",
922         (char *)"phone:1:",
923         (char *)"",
924     };
925     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
926 
927     NotificationShellCommand cmd(argc, argv);
928 
929     std::string result = "error: setting information error\n";
930     result.append(SETTING_HELP_MSG);
931     EXPECT_EQ(cmd.ExecCommand(), result);
932 }
933 
934 /**
935  * @tc.number: Anm_Command_Dump_2100
936  * @tc.name: RunAsSettingCommand
937  * @tc.desc: Verify the "anm setting -b phone:1" command.
938  */
939 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Setting_2400, Function | MediumTest | Level1)
940 {
941     char *argv[] = {
942         (char *)toolName_.c_str(),
943         (char *)enable_.c_str(),
944         (char *)"-b",
945         (char *)"phone:bundleName:10001:1",
946         (char *)"",
947     };
948     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
949 
950     NotificationShellCommand cmd(argc, argv);
951 
952     EXPECT_EQ(cmd.ExecCommand(), "set bundle collaboration switch success\n");
953 }
954 
955 /**
956  * @tc.number: Anm_Command_Dump_2100
957  * @tc.name: RunAsSettingCommand
958  * @tc.desc: Verify the "anm setting -b phone:1" command.
959  */
960 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Setting_2401, Function | MediumTest | Level1)
961 {
962     char *argv[] = {
963         (char *)toolName_.c_str(),
964         (char *)enable_.c_str(),
965         (char *)"-b",
966         (char *)"2in1:bundleName:10001:1",
967         (char *)"",
968     };
969     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
970 
971     NotificationShellCommand cmd(argc, argv);
972 
973     EXPECT_EQ(cmd.ExecCommand(),
974         "set bundle collaboration switch failed\nfailed reason is Failed to connect to the service\n");
975 }
976 
977 /**
978  * @tc.number: Anm_Command_Dump_2100
979  * @tc.name: RunAsSettingCommand
980  * @tc.desc: Verify the "anm setting -b phone:1" command.
981  */
982 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Setting_2402, Function | MediumTest | Level1)
983 {
984     char *argv[] = {
985         (char *)toolName_.c_str(),
986         (char *)enable_.c_str(),
987         (char *)"-b",
988         (char *)"",
989     };
990     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
991 
992     NotificationShellCommand cmd(argc, argv);
993 
994     std::string result = "error: option 'b' requires a value.\n";
995     result.append(SETTING_HELP_MSG);
996     EXPECT_EQ(cmd.ExecCommand(), result);
997 }
998 
999 /**
1000  * @tc.number: Anm_Command_Dump_2100
1001  * @tc.name: RunAsSettingCommand
1002  * @tc.desc: Verify the "anm setting -b phone:1" command.
1003  */
1004 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Setting_2403, Function | MediumTest | Level1)
1005 {
1006     char *argv[] = {
1007         (char *)toolName_.c_str(),
1008         (char *)enable_.c_str(),
1009         (char *)"-b",
1010         (char *)"2in1:bundleName:10001:1:",
1011         (char *)"",
1012     };
1013     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1014 
1015     NotificationShellCommand cmd(argc, argv);
1016 
1017     std::string result = "error: setting information error\n";
1018     result.append(SETTING_HELP_MSG);
1019     EXPECT_EQ(cmd.ExecCommand(), result);
1020 }
1021 
1022 /**
1023  * @tc.number: Anm_Command_Dump_2100
1024  * @tc.name: RunAsSettingCommand
1025  * @tc.desc: Verify the "anm setting -b phone:1" command.
1026  */
1027 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Setting_2500, Function | MediumTest | Level1)
1028 {
1029     char *argv[] = {
1030         (char *)toolName_.c_str(),
1031         (char *)enable_.c_str(),
1032         (char *)"-o",
1033         (char *)"phone:2:1",
1034         (char *)"",
1035     };
1036     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1037 
1038     NotificationShellCommand cmd(argc, argv);
1039 
1040     EXPECT_EQ(cmd.ExecCommand(), "set slot collaboration switch success\n");
1041 }
1042 
1043 /**
1044  * @tc.number: Anm_Command_Dump_2100
1045  * @tc.name: RunAsSettingCommand
1046  * @tc.desc: Verify the "anm setting -b phone:1" command.
1047  */
1048 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Setting_2501, Function | MediumTest | Level1)
1049 {
1050     char *argv[] = {
1051         (char *)toolName_.c_str(),
1052         (char *)enable_.c_str(),
1053         (char *)"-o",
1054         (char *)"2in1:2:1",
1055         (char *)"",
1056     };
1057     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1058 
1059     NotificationShellCommand cmd(argc, argv);
1060 
1061     EXPECT_EQ(cmd.ExecCommand(),
1062         "set slot collaboration switch failed\nfailed reason is Failed to connect to the service\n");
1063 }
1064 
1065 /**
1066  * @tc.number: Anm_Command_Dump_2100
1067  * @tc.name: RunAsSettingCommand
1068  * @tc.desc: Verify the "anm setting -b phone:1" command.
1069  */
1070 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Setting_2502, Function | MediumTest | Level1)
1071 {
1072     char *argv[] = {
1073         (char *)toolName_.c_str(),
1074         (char *)enable_.c_str(),
1075         (char *)"-o",
1076         (char *)"",
1077     };
1078     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1079 
1080     NotificationShellCommand cmd(argc, argv);
1081 
1082     std::string result = "error: option 'o' requires a value.\n";
1083     result.append(SETTING_HELP_MSG);
1084     EXPECT_EQ(cmd.ExecCommand(), result);
1085 }
1086 
1087 
1088 /**
1089  * @tc.number: Anm_Command_Dump_2100
1090  * @tc.name: RunAsSettingCommand
1091  * @tc.desc: Verify the "anm setting -b phone:1" command.
1092  */
1093 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Setting_2503, Function | MediumTest | Level1)
1094 {
1095     char *argv[] = {
1096         (char *)toolName_.c_str(),
1097         (char *)enable_.c_str(),
1098         (char *)"-o",
1099         (char *)"2in1:2:1:",
1100         (char *)"",
1101     };
1102     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1103 
1104     NotificationShellCommand cmd(argc, argv);
1105 
1106     std::string result = "error: setting information error\n";
1107     result.append(SETTING_HELP_MSG);
1108     EXPECT_EQ(cmd.ExecCommand(), result);
1109 }
1110 
1111 /**
1112  * @tc.number: Anm_Command_Dump_2200
1113  * @tc.name: ExecCommand
1114  * @tc.desc: Verify the "anm dump -A -s" command.
1115  */
1116 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_2200, Function | MediumTest | Level1)
1117 {
1118     char *argv[] = {
1119         (char *)toolName_.c_str(),
1120         (char *)cmd_.c_str(),
1121         (char *)"-A",
1122         (char *)"-s",
1123         (char *)"",
1124     };
1125     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1126 
1127     NotificationShellCommand cmd(argc, argv);
1128 
1129     EXPECT_EQ(cmd.ExecCommand(), g_unknownOption);
1130 }
1131 
1132 /**
1133  * @tc.number: Anm_Command_Dump_2300
1134  * @tc.name: RunAsSettingCommand
1135  * @tc.desc: Verify the "anm setting -e" command.
1136  */
1137 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_2300, Function | MediumTest | Level1)
1138 {
1139     char *argv[] = {
1140         (char *)toolName_.c_str(),
1141         (char *)enable_.c_str(),
1142         (char *)"-c",
1143         (char *)"",
1144     };
1145     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1146 
1147     NotificationShellCommand cmd(argc, argv);
1148 
1149     EXPECT_EQ(cmd.ExecCommand(), g_dumpActiveCount);
1150 }
1151 
1152 /**
1153  * @tc.number: Anm_Command_Dump_2400
1154  * @tc.name: ExecCommand
1155  * @tc.desc: Verify the "anm dump -D" command.
1156  */
1157 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_0240, Function | MediumTest | Level1)
1158 {
1159     char *argv[] = {
1160         (char *)toolName_.c_str(),
1161         (char *)cmd_.c_str(),
1162         (char *)"-D",
1163         (char *)"",
1164     };
1165     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1166 
1167     NotificationShellCommand cmd(argc, argv);
1168 
1169     cmd.ExecCommand();
1170 
1171     EXPECT_EQ(cmd.ExecCommand(), g_helpMsg);
1172 }
1173 
1174 /**
1175  * @tc.number: Anm_Command_Dump_2500
1176  * @tc.name: ExecCommand
1177  * @tc.desc: Verify the "anm dump -D" command.
1178  */
1179 HWTEST_F(AnmManagerDumpTest, Anm_Notification_Shell_Dump_0250, Function | MediumTest | Level1)
1180 {
1181     char *argv[] = {
1182         (char *)toolName_.c_str(),
1183         (char *)cmd_.c_str(),
1184         (char *)"-p",
1185         (char *)"",
1186     };
1187     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
1188 
1189     NotificationShellCommand cmd(argc, argv);
1190 
1191     cmd.ExecCommand();
1192 
1193     EXPECT_EQ(cmd.ExecCommand(), g_helpMsg);
1194 }
1195 }  // namespace