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 <chrono>
17 #include <functional>
18 #include <thread>
19
20 #include "gtest/gtest.h"
21
22 #define private public
23
24 #include "advanced_notification_service.h"
25 #include "ans_const_define.h"
26 #include "ans_inner_errors.h"
27 #include "ans_log_wrapper.h"
28 #include "ans_ut_constant.h"
29 #include "common_event_manager.h"
30 #include "common_event_support.h"
31 #include "mock_ipc_skeleton.h"
32 #include "notification_preferences.h"
33 #include "notification_subscriber.h"
34 #include "system_event_observer.h"
35 #include "notification_constant.h"
36 #include "want_agent_info.h"
37 #include "want_agent_helper.h"
38 #include "want_params.h"
39 #include "bundle_manager_helper.h"
40
41 using namespace testing::ext;
42 using namespace OHOS::Media;
43
44 namespace OHOS {
45 namespace Notification {
46 class AdvancedNotificationServiceTest : public testing::Test {
47 public:
48 static void SetUpTestCase();
49 static void TearDownTestCase();
50 void SetUp();
51 void TearDown();
52
53 private:
54 void TestAddSlot(NotificationConstant::SlotType type);
55
56 private:
57 static sptr<AdvancedNotificationService> advancedNotificationService_;
58 };
59
60 sptr<AdvancedNotificationService> AdvancedNotificationServiceTest::advancedNotificationService_ = nullptr;
61
SetUpTestCase()62 void AdvancedNotificationServiceTest::SetUpTestCase() {}
63
TearDownTestCase()64 void AdvancedNotificationServiceTest::TearDownTestCase() {}
65
SetUp()66 void AdvancedNotificationServiceTest::SetUp()
67 {
68 GTEST_LOG_(INFO) << "SetUp start";
69
70 advancedNotificationService_ = new (std::nothrow) AdvancedNotificationService();
71 IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN);
72 NotificationPreferences::GetInstance().ClearNotificationInRestoreFactorySettings();
73 IPCSkeleton::SetCallingUid(SYSTEM_APP_UID);
74 advancedNotificationService_->CancelAll();
75
76 GTEST_LOG_(INFO) << "SetUp end";
77 }
78
TearDown()79 void AdvancedNotificationServiceTest::TearDown()
80 {
81 IPCSkeleton::SetCallingUid(SYSTEM_APP_UID);
82 IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN);
83 advancedNotificationService_ = nullptr;
84 GTEST_LOG_(INFO) << "TearDown";
85 }
86
SleepForFC()87 inline void SleepForFC()
88 {
89 // For ANS Flow Control
90 std::this_thread::sleep_for(std::chrono::seconds(1));
91 }
92
93 class TestAnsSubscriber : public NotificationSubscriber {
94 public:
OnConnected()95 void OnConnected() override
96 {}
OnDisconnected()97 void OnDisconnected() override
98 {}
OnDied()99 void OnDied() override
100 {}
OnUpdate(const std::shared_ptr<NotificationSortingMap> & sortingMap)101 void OnUpdate(const std::shared_ptr<NotificationSortingMap> &sortingMap) override
102 {}
OnDoNotDisturbDateChange(const std::shared_ptr<NotificationDoNotDisturbDate> & date)103 void OnDoNotDisturbDateChange(const std::shared_ptr<NotificationDoNotDisturbDate> &date) override
104 {}
OnEnabledNotificationChanged(const std::shared_ptr<EnabledNotificationCallbackData> & callbackData)105 void OnEnabledNotificationChanged(
106 const std::shared_ptr<EnabledNotificationCallbackData> &callbackData) override
107 {}
OnCanceled(const std::shared_ptr<Notification> & request,const std::shared_ptr<NotificationSortingMap> & sortingMap,int32_t deleteReason)108 void OnCanceled(const std::shared_ptr<Notification> &request,
109 const std::shared_ptr<NotificationSortingMap> &sortingMap, int32_t deleteReason) override
110 {}
OnConsumed(const std::shared_ptr<Notification> & request)111 void OnConsumed(const std::shared_ptr<Notification> &request) override
112 {}
OnConsumed(const std::shared_ptr<Notification> & request,const std::shared_ptr<NotificationSortingMap> & sortingMap)113 void OnConsumed(const std::shared_ptr<Notification> &request,
114 const std::shared_ptr<NotificationSortingMap> &sortingMap) override
115 {}
116 };
117
TestAddSlot(NotificationConstant::SlotType type)118 void AdvancedNotificationServiceTest::TestAddSlot(NotificationConstant::SlotType type)
119 {
120 std::vector<sptr<NotificationSlot>> slots;
121 sptr<NotificationSlot> slot = new NotificationSlot(type);
122 slots.push_back(slot);
123 EXPECT_EQ(advancedNotificationService_->AddSlots(slots), (int)ERR_OK);
124 }
125
126 /**
127 * @tc.number : ANS_Publish_00100
128 * @tc.name : ANSPublish00100
129 * @tc.desc : Publish a normal text type notification.
130 */
131 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00100, Function | SmallTest | Level1)
132 {
133 TestAddSlot(NotificationConstant::SlotType::OTHER);
134 sptr<NotificationRequest> req = new NotificationRequest(1);
135 EXPECT_NE(req, nullptr);
136 req->SetSlotType(NotificationConstant::SlotType::OTHER);
137 req->SetLabel("req's label");
138 std::string label = "publish's label";
139 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
140 EXPECT_NE(normalContent, nullptr);
141 normalContent->SetText("normalContent's text");
142 normalContent->SetTitle("normalContent's title");
143 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
144 EXPECT_NE(content, nullptr);
145 req->SetContent(content);
146 EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
147 SleepForFC();
148 }
149
150 /**
151 * @tc.number : ANS_Publish_00200
152 * @tc.name : ANSPublish00200
153 * @tc.desc : Publish a normal text type notification twice.
154 */
155 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00200, Function | SmallTest | Level1)
156 {
157 TestAddSlot(NotificationConstant::SlotType::OTHER);
158 sptr<NotificationRequest> req = new NotificationRequest(1);
159 EXPECT_NE(req, nullptr);
160 req->SetSlotType(NotificationConstant::SlotType::OTHER);
161 req->SetLabel("req's label");
162 std::string label = "publish's label";
163 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
164 EXPECT_NE(normalContent, nullptr);
165 normalContent->SetText("normalContent's text");
166 normalContent->SetTitle("normalContent's title");
167 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
168 EXPECT_NE(content, nullptr);
169 req->SetContent(content);
170 EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
171 EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
172 SleepForFC();
173 }
174
175 /**
176 * @tc.number : ANS_Publish_00300
177 * @tc.name : ANSPublish00300
178 * @tc.desc : When slotType is CUSTOM and not systemApp, the notification publish fails,
179 * and the notification publish interface returns ERR_ANS_NON_SYSTEM_APP.
180 */
181 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00300, Function | SmallTest | Level1)
182 {
183 IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID);
184 IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN);
185 sptr<NotificationRequest> req = new NotificationRequest();
186 EXPECT_NE(req, nullptr);
187 req->SetSlotType(NotificationConstant::SlotType::CUSTOM);
188 req->SetLabel("req's label");
189 std::string label = "publish's label";
190 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
191 EXPECT_NE(normalContent, nullptr);
192 normalContent->SetText("normalContent's text");
193 normalContent->SetTitle("normalContent's title");
194 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
195 EXPECT_NE(content, nullptr);
196 req->SetContent(content);
197 EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_ANS_NON_SYSTEM_APP);
198 SleepForFC();
199 }
200
201 /**
202 * @tc.number : ANS_Publish_00400
203 * @tc.name : ANSPublish00400
204 * @tc.desc : When the obtained bundleName is empty, the notification publish interface returns
205 * ERR_ANS_INVALID_BUNDLE.
206 */
207 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00400, Function | SmallTest | Level1)
208 {
209 IPCSkeleton::SetCallingUid(NON_BUNDLE_NAME_UID);
210 sptr<NotificationRequest> req = new NotificationRequest();
211 EXPECT_NE(req, nullptr);
212 req->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION);
213 req->SetLabel("req's label");
214 std::string label = "publish's label";
215 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
216 EXPECT_NE(normalContent, nullptr);
217 normalContent->SetText("normalContent's text");
218 normalContent->SetTitle("normalContent's title");
219 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
220 EXPECT_NE(content, nullptr);
221 req->SetContent(content);
222 EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_ANS_INVALID_BUNDLE);
223 SleepForFC();
224 }
225
226 /**
227 * @tc.number : ANS_Publish_00500
228 * @tc.name : ANSPublish00500
229 * @tc.desc : When the obtained bundleName does not have a corresponding slot in the database,
230 * create the corresponding slot and publish a notification.
231 */
232 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00500, Function | SmallTest | Level1)
233 {
234 TestAddSlot(NotificationConstant::SlotType::SERVICE_REMINDER);
235 sptr<NotificationRequest> req = new NotificationRequest();
236 EXPECT_NE(req, nullptr);
237 req->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION);
238 req->SetLabel("req's label");
239 std::string label = "publish's label";
240 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
241 EXPECT_NE(normalContent, nullptr);
242 normalContent->SetText("normalContent's text");
243 normalContent->SetTitle("normalContent's title");
244 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
245 EXPECT_NE(content, nullptr);
246 req->SetContent(content);
247 EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
248 SleepForFC();
249 }
250
251 /**
252 * @tc.number : ANS_Publish_00600
253 * @tc.name : ANSPublish00600
254 * @tc.desc : When the obtained bundleName have a corresponding slot in the database,
255 * the test publish interface can successfully publish a notification of normal text type.
256 */
257 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00600, Function | SmallTest | Level1)
258 {
259 TestAddSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
260 sptr<NotificationRequest> req = new NotificationRequest();
261 EXPECT_NE(req, nullptr);
262 req->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION);
263 req->SetLabel("req's label");
264 std::string label = "publish's label";
265 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
266 EXPECT_NE(normalContent, nullptr);
267 normalContent->SetText("normalContent's text");
268 normalContent->SetTitle("normalContent's title");
269 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
270 EXPECT_NE(content, nullptr);
271 req->SetContent(content);
272 EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
273 SleepForFC();
274 }
275
276 /**
277 * @tc.number : ANS_Publish_00700
278 * @tc.name : ANSPublish00700
279 * @tc.desc : When the obtained bundleName have a corresponding slot in the database,
280 * create the corresponding slot and publish a notification.
281 */
282 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00700, Function | SmallTest | Level1)
283 {
284 sptr<NotificationRequest> req = new NotificationRequest();
285 EXPECT_NE(req, nullptr);
286 req->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION);
287 req->SetLabel("req's label");
288 std::string label = "publish's label";
289 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
290 EXPECT_NE(normalContent, nullptr);
291 normalContent->SetText("normalContent's text");
292 normalContent->SetTitle("normalContent's title");
293 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
294 EXPECT_NE(content, nullptr);
295 req->SetContent(content);
296 EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
297 SleepForFC();
298 }
299
300 /**
301 * @tc.number : ANS_Publish_00800
302 * @tc.name : ANSPublish00800
303 * @tc.desc : Create a slot of type SOCIAL_COMMUNICATION and successfully publish a notification
304 */
305 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00800, Function | SmallTest | Level1)
306 {
307 TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
308 sptr<NotificationRequest> req = new NotificationRequest();
309 EXPECT_NE(req, nullptr);
310 req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
311 req->SetLabel("req's label");
312 std::string label = "publish's label";
313 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
314 EXPECT_NE(normalContent, nullptr);
315 normalContent->SetText("normalContent's text");
316 normalContent->SetTitle("normalContent's title");
317 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
318 EXPECT_NE(content, nullptr);
319 req->SetContent(content);
320 EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
321 SleepForFC();
322 }
323
324 /**
325 * @tc.number : ANS_Publish_00900
326 * @tc.name : ANSPublish00900
327 * @tc.desc : Create a slot of type SERVICE_REMINDER and successfully publish a notification
328 */
329 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00900, Function | SmallTest | Level1)
330 {
331 TestAddSlot(NotificationConstant::SlotType::SERVICE_REMINDER);
332 sptr<NotificationRequest> req = new NotificationRequest();
333 EXPECT_NE(req, nullptr);
334 req->SetSlotType(NotificationConstant::SlotType::SERVICE_REMINDER);
335 req->SetLabel("req's label");
336 std::string label = "publish's label";
337 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
338 EXPECT_NE(normalContent, nullptr);
339 normalContent->SetText("normalContent's text");
340 normalContent->SetTitle("normalContent's title");
341 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
342 EXPECT_NE(content, nullptr);
343 req->SetContent(content);
344 EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
345 SleepForFC();
346 }
347
348 /**
349 * @tc.number : ANS_Publish_01000
350 * @tc.name : ANSPublish01000
351 * @tc.desc : Create a slot of type CONTENT_INFORMATION and successfully publish a notification
352 */
353 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01000, Function | SmallTest | Level1)
354 {
355 TestAddSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
356 sptr<NotificationRequest> req = new NotificationRequest();
357 EXPECT_NE(req, nullptr);
358 req->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION);
359 req->SetLabel("req's label");
360 std::string label = "publish's label";
361 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
362 EXPECT_NE(normalContent, nullptr);
363 normalContent->SetText("normalContent's text");
364 normalContent->SetTitle("normalContent's title");
365 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
366 EXPECT_NE(content, nullptr);
367 req->SetContent(content);
368 EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
369 SleepForFC();
370 }
371
372 /**
373 * @tc.number : ANS_Publish_01100
374 * @tc.name : ANSPublish01100
375 * @tc.desc : Create a slot of type OTHER and successfully publish a notification
376 */
377 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01100, Function | SmallTest | Level1)
378 {
379 TestAddSlot(NotificationConstant::SlotType::OTHER);
380 sptr<NotificationRequest> req = new NotificationRequest();
381 EXPECT_NE(req, nullptr);
382 req->SetSlotType(NotificationConstant::SlotType::OTHER);
383 req->SetLabel("req's label");
384 std::string label = "publish's label";
385 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
386 EXPECT_NE(normalContent, nullptr);
387 normalContent->SetText("normalContent's text");
388 normalContent->SetTitle("normalContent's title");
389 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
390 EXPECT_NE(content, nullptr);
391 req->SetContent(content);
392 EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
393 SleepForFC();
394 }
395
396 /**
397 * @tc.number : ANS_Publish_01200
398 * @tc.name : ANSPublish01200
399 * @tc.desc : Create a slot of type CUSTOM and successfully publish a notification
400 */
401 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01200, Function | SmallTest | Level1)
402 {
403 TestAddSlot(NotificationConstant::SlotType::CUSTOM);
404 sptr<NotificationRequest> req = new NotificationRequest();
405 EXPECT_NE(req, nullptr);
406 req->SetSlotType(NotificationConstant::SlotType::CUSTOM);
407 req->SetLabel("req's label");
408 std::string label = "publish's label";
409 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
410 EXPECT_NE(normalContent, nullptr);
411 normalContent->SetText("normalContent's text");
412 normalContent->SetTitle("normalContent's title");
413 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
414 EXPECT_NE(content, nullptr);
415 req->SetContent(content);
416 EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
417 SleepForFC();
418 }
419
420 /**
421 * @tc.number : ANS_Publish_01300
422 * @tc.name : ANSPublish01300
423 * @tc.desc : When a bundle is not allowed to publish a notification, the notification publishing interface
424 returns
425 * ERR_ANS_NOT_ALLOWED
426 */
427 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01300, Function | SmallTest | Level1)
428 {
429 TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
430 sptr<NotificationRequest> req = new NotificationRequest();
431 EXPECT_NE(req, nullptr);
432 req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
433 req->SetLabel("req's label");
434 std::string label = "publish's label";
435 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
436 EXPECT_NE(normalContent, nullptr);
437 normalContent->SetText("normalContent's text");
438 normalContent->SetTitle("normalContent's title");
439 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
440 EXPECT_NE(content, nullptr);
441 req->SetContent(content);
442 EXPECT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(
443 std::string(), new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), false),
444 (int)ERR_OK);
445 EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_ANS_NOT_ALLOWED);
446 SleepForFC();
447 }
448
449 /**
450 * @tc.number : AdvancedNotificationServiceTest_01600
451 * @tc.name : ANS_GetSlot_0200
452 * @tc.desc : Test GetSlots function when add two identical data
453 */
454 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01600, Function | SmallTest | Level1)
455 {
456 std::vector<sptr<NotificationSlot>> slots;
457 sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::OTHER);
458 sptr<NotificationSlot> slot1 = new NotificationSlot(NotificationConstant::OTHER);
459 slots.push_back(slot0);
460 slots.push_back(slot1);
461 std::vector<sptr<NotificationSlot>> slotsResult;
462 advancedNotificationService_->AddSlots(slots);
463 advancedNotificationService_->GetSlots(slotsResult);
464 EXPECT_EQ((int)slots.size(), 2);
465 EXPECT_EQ((int)slotsResult.size(), 1);
466 }
467
468 /**
469 * @tc.number : AdvancedNotificationServiceTest_01800
470 * @tc.name : ANS_SetNotificationBadgeNum_0100
471 * @tc.desc : Test SetNotificationBadgeNum function
472 */
473 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01800, Function | SmallTest | Level1)
474 {
475 TestAddSlot(NotificationConstant::SlotType::OTHER);
476 EXPECT_EQ((int)advancedNotificationService_->SetNotificationBadgeNum(2), (int)ERR_OK);
477 }
478
479 /**
480 * @tc.number : AdvancedNotificationServiceTest_01900
481 * @tc.name : ANS_GetBundleImportance_0100
482 * @tc.desc : Test GetBundleImportance function
483 */
484 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01900, Function | SmallTest | Level1)
485 {
486 TestAddSlot(NotificationConstant::SlotType::OTHER);
487 int importance;
488 EXPECT_EQ((int)advancedNotificationService_->GetBundleImportance(importance), (int)ERR_OK);
489 }
490
491 /**
492 * @tc.number : AdvancedNotificationServiceTest_02000
493 * @tc.name : ANS_SetPrivateNotificationsAllowed_0100
494 * @tc.desc : Test SetPrivateNotificationsAllowed function
495 */
496 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02000, Function | SmallTest | Level1)
497 {
498 TestAddSlot(NotificationConstant::SlotType::OTHER);
499 EXPECT_EQ((int)advancedNotificationService_->SetPrivateNotificationsAllowed(true), (int)ERR_OK);
500 }
501
502 /**
503 * @tc.number : AdvancedNotificationServiceTest_02100
504 * @tc.name : ANS_GetPrivateNotificationsAllowed_0100
505 * @tc.desc : Test GetPrivateNotificationsAllowed function
506 */
507 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02100, Function | SmallTest | Level1)
508 {
509 TestAddSlot(NotificationConstant::SlotType::OTHER);
510 EXPECT_EQ((int)advancedNotificationService_->SetPrivateNotificationsAllowed(true), (int)ERR_OK);
511 bool allow = false;
512 EXPECT_EQ((int)advancedNotificationService_->GetPrivateNotificationsAllowed(allow), (int)ERR_OK);
513 EXPECT_TRUE(allow);
514 }
515
516 /**
517 * @tc.number : AdvancedNotificationServiceTest_02200
518 * @tc.name : ANS_UpdateSlots_0100
519 * @tc.desc : Test UpdateSlots function when no slot
520 */
521 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02200, Function | SmallTest | Level1)
522 {
523 TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
524 std::vector<sptr<NotificationSlot>> slots;
525 sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::OTHER);
526 slots.push_back(slot0);
527 EXPECT_EQ((int)advancedNotificationService_->UpdateSlots(
528 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), slots),
529 (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST);
530 }
531
532 /**
533 * @tc.number : AdvancedNotificationServiceTest_02300
534 * @tc.name : ANS_UpdateSlots_0200
535 * @tc.desc : Test UpdateSlots function
536 */
537 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02300, Function | SmallTest | Level1)
538 {
539 TestAddSlot(NotificationConstant::SlotType::OTHER);
540 std::vector<sptr<NotificationSlot>> slots;
541 sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::OTHER);
542 slots.push_back(slot0);
543 EXPECT_EQ((int)advancedNotificationService_->UpdateSlots(
544 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), slots),
545 (int)ERR_OK);
546 }
547
548 /**
549 * @tc.number : AdvancedNotificationServiceTest_02700
550 * @tc.name : ANS_SetShowBadgeEnabledForBundle_0100
551 * @tc.desc : Test the SetShowBadgeEnabledForBundle function when the parameter is wrong
552 */
553 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02700, Function | SmallTest | Level1)
554 {
555 EXPECT_EQ(advancedNotificationService_->SetShowBadgeEnabledForBundle(
556 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID), true),
557 (int)ERR_OK);
558 }
559
560 /**
561 * @tc.number : AdvancedNotificationServiceTest_02800
562 * @tc.name : ANS_GetShowBadgeEnabledForBundle_0100
563 * @tc.desc : Test GetShowBadgeEnabledForBundle function
564 */
565 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02800, Function | SmallTest | Level1)
566 {
567 EXPECT_EQ(advancedNotificationService_->SetShowBadgeEnabledForBundle(
568 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID), true),
569 (int)ERR_OK);
570 bool allow = false;
571 EXPECT_EQ((int)advancedNotificationService_->GetShowBadgeEnabledForBundle(
572 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID), allow),
573 (int)ERR_OK);
574 EXPECT_TRUE(allow);
575 }
576
577 /**
578 * @tc.number : AdvancedNotificationServiceTest_02900
579 * @tc.name : ANS_GetActiveNotifications_0100
580 * @tc.desc : Test GetActiveNotifications function
581 */
582 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02900, Function | SmallTest | Level1)
583 {
584 std::vector<sptr<NotificationRequest>> notifications;
585 EXPECT_EQ((int)advancedNotificationService_->GetActiveNotifications(notifications), (int)ERR_OK);
586 }
587
588 /**
589 * @tc.number : AdvancedNotificationServiceTest_03700
590 * @tc.name : ANS_Delete_0100
591 * @tc.desc : Test Delete function
592 */
593 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_03700, Function | SmallTest | Level1)
594 {
595 const std::string key = "key";
596 EXPECT_EQ((int)advancedNotificationService_->Delete(key, NotificationConstant::CANCEL_REASON_DELETE),
597 (int)ERR_ANS_NOTIFICATION_NOT_EXISTS);
598 }
599
600 /**
601 * @tc.number : AdvancedNotificationServiceTest_03800
602 * @tc.name : ANS_DeleteByBundle_0100
603 * @tc.desc : Test DeleteByBundle function
604 */
605 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_03800, Function | SmallTest | Level1)
606 {
607 EXPECT_EQ(advancedNotificationService_->DeleteByBundle(
608 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID)),
609 ERR_OK);
610 }
611
612 /**
613 * @tc.number : AdvancedNotificationServiceTest_03900
614 * @tc.name : ANS_DeleteAll_0100
615 * @tc.desc : Test DeleteAll function
616 */
617 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_03900, Function | SmallTest | Level1)
618 {
619 EXPECT_EQ(advancedNotificationService_->DeleteAll(), ERR_OK);
620 }
621
622 /**
623 * @tc.number : AdvancedNotificationServiceTest_04000
624 * @tc.name : ANS_GetSlotsByBundle_0100
625 * @tc.desc : Test GetSlotsByBundle function
626 */
627 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04000, Function | SmallTest | Level1)
628 {
629 TestAddSlot(NotificationConstant::SlotType::OTHER);
630 std::vector<sptr<NotificationSlot>> slots;
631 EXPECT_EQ(advancedNotificationService_->GetSlotsByBundle(
632 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), slots),
633 ERR_OK);
634 EXPECT_EQ(slots.size(), (size_t)1);
635 }
636
637 /**
638 * @tc.number : AdvancedNotificationServiceTest_04100
639 * @tc.name : ANS_GetSpecialActiveNotifications_0100
640 * @tc.desc : Test GetSpecialActiveNotifications function
641 */
642 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04100, Function | SmallTest | Level1)
643 {
644 TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
645 sptr<NotificationRequest> req = new NotificationRequest();
646 EXPECT_NE(req, nullptr);
647 req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
648 req->SetLabel("req's label");
649 req->SetAlertOneTime(true);
650 std::string label = "publish's label";
651 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
652 EXPECT_NE(normalContent, nullptr);
653 normalContent->SetText("normalContent's text");
654 normalContent->SetTitle("normalContent's title");
655 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
656 EXPECT_NE(content, nullptr);
657 req->SetContent(content);
658 EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
659 std::vector<sptr<Notification>> allNotifications;
660 EXPECT_EQ(advancedNotificationService_->GetAllActiveNotifications(allNotifications), (int)ERR_OK);
661 EXPECT_EQ(allNotifications.size(), (size_t)1);
662 std::vector<std::string> keys;
663 for (auto notification : allNotifications) {
664 keys.push_back(notification->GetKey());
665 }
666 std::vector<sptr<Notification>> specialActiveNotifications;
667 EXPECT_EQ(
668 advancedNotificationService_->GetSpecialActiveNotifications(keys, specialActiveNotifications), (int)ERR_OK);
669 EXPECT_EQ(specialActiveNotifications.size(), (size_t)1);
670 SleepForFC();
671 }
672
673 /**
674 * @tc.number : AdvancedNotificationServiceTest_04600
675 * @tc.name : ANS_Publish_0500
676 * @tc.desc : publish function when NotificationsEnabled is false
677 */
678 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04600, Function | SmallTest | Level1)
679 {
680 sptr<NotificationRequest> req = new NotificationRequest(1);
681 req->SetSlotType(NotificationConstant::OTHER);
682 TestAddSlot(NotificationConstant::SlotType::OTHER);
683 EXPECT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(
684 std::string(), new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), false),
685 (int)ERR_OK);
686 EXPECT_EQ(advancedNotificationService_->Publish(std::string(), req), (int)ERR_ANS_NOT_ALLOWED);
687 }
688
689 /**
690 * @tc.number : AdvancedNotificationServiceTest_04700
691 * @tc.name : ANS_Cancel_0100
692 * @tc.desc : public two notification to cancel one of them
693 */
694 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04700, Function | SmallTest | Level1)
695 {
696 TestAddSlot(NotificationConstant::SlotType::OTHER);
697 std::string label = "testLabel";
698 {
699 sptr<NotificationRequest> req = new NotificationRequest(1);
700 req->SetSlotType(NotificationConstant::OTHER);
701 req->SetLabel(label);
702 EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
703 }
704 {
705 sptr<NotificationRequest> req = new NotificationRequest(2);
706 req->SetSlotType(NotificationConstant::OTHER);
707 req->SetLabel(label);
708 EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
709 }
710 EXPECT_EQ(advancedNotificationService_->Cancel(1, label), (int)ERR_OK);
711 }
712
713 /**
714 * @tc.number : AdvancedNotificationServiceTest_04800
715 * @tc.name : ANS_Cancel_0200
716 * @tc.desc : Test Cancel function when notification no exists
717 */
718 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04800, Function | SmallTest | Level1)
719 {
720 int32_t notificationId = 0;
721 std::string label = "testLabel";
722 EXPECT_EQ((int)advancedNotificationService_->Cancel(notificationId, label), (int)ERR_ANS_NOTIFICATION_NOT_EXISTS);
723 }
724
725 /**
726 * @tc.number : AdvancedNotificationServiceTest_04900
727 * @tc.name : ANS_CancelAll_0100
728 * @tc.desc : Test CancelAll function
729 */
730 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04900, Function | SmallTest | Level1)
731 {
732 TestAddSlot(NotificationConstant::SlotType::OTHER);
733 sptr<NotificationRequest> req = new NotificationRequest(1);
734 req->SetSlotType(NotificationConstant::OTHER);
735 EXPECT_EQ(advancedNotificationService_->CancelAll(), (int)ERR_OK);
736 }
737
738 /**
739 * @tc.number : AdvancedNotificationServiceTest_05000
740 * @tc.name : ANS_Cancel_0100
741 * @tc.desc : Test Cancel function when unremovable is true
742 */
743 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05000, Function | SmallTest | Level1)
744 {
745 TestAddSlot(NotificationConstant::SlotType::OTHER);
746 int32_t notificationId = 2;
747 std::string label = "testLabel";
748 sptr<NotificationRequest> req = new NotificationRequest(notificationId);
749 req->SetSlotType(NotificationConstant::OTHER);
750 req->SetLabel(label);
751 req->SetUnremovable(true);
752 EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
753 EXPECT_EQ(advancedNotificationService_->Cancel(notificationId, label), (int)ERR_OK);
754 }
755
756 /**
757 * @tc.number : AdvancedNotificationServiceTest_05100
758 * @tc.name : ANS_AddSlots_0100
759 * @tc.desc : Test AddSlots function
760 */
761 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05100, Function | SmallTest | Level1)
762 {
763 std::vector<sptr<NotificationSlot>> slots;
764 sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::OTHER);
765 sptr<NotificationSlot> slot1 = new NotificationSlot(NotificationConstant::OTHER);
766 slots.push_back(slot0);
767 slots.push_back(slot1);
768 EXPECT_EQ(advancedNotificationService_->AddSlots(slots), ERR_OK);
769 }
770
771 /**
772 * @tc.number : AdvancedNotificationServiceTest_05200
773 * @tc.name : ANS_RemoveSlotByType_0100
774 * @tc.desc : Test RemoveSlotByType function
775 */
776 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05200, Function | SmallTest | Level1)
777 {
778 TestAddSlot(NotificationConstant::SlotType::OTHER);
779 EXPECT_EQ(advancedNotificationService_->RemoveSlotByType(NotificationConstant::OTHER), ERR_OK);
780 }
781
782 /**
783 * @tc.number : AdvancedNotificationServiceTest_05300
784 * @tc.name : ANS_RemoveSlotByType_0200
785 * @tc.desc : Test RemoveSlotByType function when no type
786 */
787 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05300, Function | SmallTest | Level1)
788 {
789 TestAddSlot(NotificationConstant::SlotType::OTHER);
790 EXPECT_EQ((int)advancedNotificationService_->RemoveSlotByType(NotificationConstant::CUSTOM), 0);
791 }
792
793 /**
794 * @tc.number : AdvancedNotificationServiceTest_05600
795 * @tc.name : ANS_GetSlot_0100
796 * @tc.desc : Test GetSlot function for data
797 */
798 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05600, Function | SmallTest | Level1)
799 {
800 std::vector<sptr<NotificationSlot>> slots;
801 sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::OTHER);
802 sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::OTHER);
803 slots.push_back(slot0);
804 advancedNotificationService_->AddSlots(slots);
805 EXPECT_EQ((int)advancedNotificationService_->GetSlotByType(NotificationConstant::OTHER, slot), ERR_OK);
806 EXPECT_EQ(slot->GetName(), slot0->GetName());
807 EXPECT_EQ(slot->GetId(), slot0->GetId());
808 EXPECT_EQ(slot->GetLevel(), slot0->GetLevel());
809 }
810
811 /**
812 * @tc.number : AdvancedNotificationServiceTest_05900
813 * @tc.name : ANS_SetNotificationBadgeNum_0100
814 * @tc.desc : Test SetNotificationBadgeNum function
815 */
816 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05900, Function | SmallTest | Level1)
817 {
818 TestAddSlot(NotificationConstant::SlotType::OTHER);
819 EXPECT_EQ((int)advancedNotificationService_->SetNotificationBadgeNum(2), (int)ERR_OK);
820 }
821
822 /**
823 * @tc.number : AdvancedNotificationServiceTest_06000
824 * @tc.name : ANS_GetBundleImportance_0100
825 * @tc.desc : Test GetBundleImportance function
826 */
827 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06000, Function | SmallTest | Level1)
828 {
829 TestAddSlot(NotificationConstant::SlotType::OTHER);
830 int importance = 0;
831 EXPECT_EQ((int)advancedNotificationService_->GetBundleImportance(importance), (int)ERR_OK);
832 }
833
834 /**
835 * @tc.number : AdvancedNotificationServiceTest_06100
836 * @tc.name : ANS_SetPrivateNotificationsAllowed_0100
837 * @tc.desc : Test SetPrivateNotificationsAllowed function
838 */
839 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06100, Function | SmallTest | Level1)
840 {
841 TestAddSlot(NotificationConstant::SlotType::OTHER);
842 EXPECT_EQ((int)advancedNotificationService_->SetPrivateNotificationsAllowed(true), (int)ERR_OK);
843 }
844
845 /**
846 * @tc.number : AdvancedNotificationServiceTest_06200
847 * @tc.name : ANS_GetPrivateNotificationsAllowed_0100
848 * @tc.desc : Test GetPrivateNotificationsAllowed function
849 */
850 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06200, Function | SmallTest | Level1)
851 {
852 TestAddSlot(NotificationConstant::SlotType::OTHER);
853 EXPECT_EQ((int)advancedNotificationService_->SetPrivateNotificationsAllowed(true), (int)ERR_OK);
854 bool allow = false;
855 EXPECT_EQ((int)advancedNotificationService_->GetPrivateNotificationsAllowed(allow), (int)ERR_OK);
856 EXPECT_TRUE(allow);
857 }
858
859 /**
860 * @tc.number : AdvancedNotificationServiceTest_06300
861 * @tc.name : ANS_UpdateSlots_0100
862 * @tc.desc : Test UpdateSlots function when no slot
863 */
864 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06300, Function | SmallTest | Level1)
865 {
866 TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
867 std::vector<sptr<NotificationSlot>> slots;
868 sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::OTHER);
869 slots.push_back(slot0);
870 EXPECT_EQ((int)advancedNotificationService_->UpdateSlots(
871 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), slots),
872 (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST);
873 }
874
875 /**
876 * @tc.number : AdvancedNotificationServiceTest_06400
877 * @tc.name : ANS_UpdateSlots_0200
878 * @tc.desc : Test UpdateSlots function
879 */
880 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06400, Function | SmallTest | Level1)
881 {
882 std::vector<sptr<NotificationSlot>> slots;
883 TestAddSlot(NotificationConstant::SlotType::OTHER);
884 sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::OTHER);
885 slots.push_back(slot0);
886 EXPECT_EQ((int)advancedNotificationService_->UpdateSlots(
887 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), slots),
888 (int)ERR_OK);
889 }
890
891 /**
892 * @tc.number : AdvancedNotificationServiceTest_06800
893 * @tc.name : ANS_SetShowBadgeEnabledForBundle_0100
894 * @tc.desc : Test the SetShowBadgeEnabledForBundle function when the parameter is wrong
895 */
896 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06800, Function | SmallTest | Level1)
897 {
898 EXPECT_EQ(advancedNotificationService_->SetShowBadgeEnabledForBundle(
899 new NotificationBundleOption("", SYSTEM_APP_UID), true),
900 (int)ERR_ANS_INVALID_PARAM);
901 }
902
903 /**
904 * @tc.number : AdvancedNotificationServiceTest_06900
905 * @tc.name : ANS_GetShowBadgeEnabledForBundle_0100
906 * @tc.desc : Test GetShowBadgeEnabledForBundle function when no bundle
907 */
908 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06900, Function | SmallTest | Level1)
909 {
910 bool allow = false;
911 EXPECT_EQ((int)advancedNotificationService_->GetShowBadgeEnabledForBundle(
912 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID), allow),
913 (int)ERR_OK);
914 }
915
916 /**
917 * @tc.number : AdvancedNotificationServiceTest_07000
918 * @tc.name : ANS_GetActiveNotifications_0100
919 * @tc.desc : Test GetActiveNotifications function
920 */
921 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_07000, Function | SmallTest | Level1)
922 {
923 std::vector<sptr<NotificationRequest>> notifications;
924 EXPECT_EQ((int)advancedNotificationService_->GetActiveNotifications(notifications), (int)ERR_OK);
925 }
926
927 /**
928 * @tc.number : AdvancedNotificationServiceTest_07800
929 * @tc.name : ANS_Delete_0100
930 * @tc.desc : Test Delete function
931 */
932 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_07800, Function | SmallTest | Level1)
933 {
934 const std::string key = "key";
935 EXPECT_EQ((int)advancedNotificationService_->Delete(key, NotificationConstant::CANCEL_REASON_DELETE),
936 (int)ERR_ANS_NOTIFICATION_NOT_EXISTS);
937 }
938
939 /**
940 * @tc.number : AdvancedNotificationServiceTest_07900
941 * @tc.name : ANS_DeleteByBundle_0100
942 * @tc.desc : Test DeleteByBundle function
943 */
944 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_07900, Function | SmallTest | Level1)
945 {
946 EXPECT_EQ(advancedNotificationService_->DeleteByBundle(
947 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID)),
948 ERR_OK);
949 }
950
951 /**
952 * @tc.number : AdvancedNotificationServiceTest_08000
953 * @tc.name : ANS_DeleteAll_0100
954 * @tc.desc : Test DeleteAll function
955 */
956 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_08000, Function | SmallTest | Level1)
957 {
958 EXPECT_EQ(advancedNotificationService_->DeleteAll(), ERR_OK);
959 }
960
961 /**
962 * @tc.number : AdvancedNotificationServiceTest_08300
963 * @tc.name : ANS_Subscribe_0100
964 * @tc.desc : Test Subscribe function
965 */
966 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_08300, Function | SmallTest | Level1)
967 {
968 auto subscriber = new TestAnsSubscriber();
969 sptr<NotificationSubscribeInfo> info = new NotificationSubscribeInfo();
970 EXPECT_EQ((int)advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), (int)ERR_OK);
971 EXPECT_EQ((int)advancedNotificationService_->Subscribe(nullptr, info), (int)ERR_ANS_INVALID_PARAM);
972 EXPECT_EQ((int)advancedNotificationService_->Unsubscribe(subscriber->GetImpl(), nullptr), (int)ERR_OK);
973 }
974
975 /**
976 * @tc.number : AdvancedNotificationServiceTest_08600
977 * @tc.name : ANS_GetShowBadgeEnabledForBundle_0200
978 * @tc.desc : Test GetShowBadgeEnabledForBundle function
979 */
980 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_08600, Function | SmallTest | Level1)
981 {
982 TestAddSlot(NotificationConstant::SlotType::OTHER);
983 EXPECT_EQ((int)advancedNotificationService_->SetShowBadgeEnabledForBundle(
984 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID), true),
985 (int)ERR_OK);
986 bool allow = false;
987 EXPECT_EQ((int)advancedNotificationService_->GetShowBadgeEnabledForBundle(
988 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID), allow),
989 (int)ERR_OK);
990 EXPECT_TRUE(allow);
991 }
992
993 /**
994 * @tc.number : AdvancedNotificationServiceTest_08700
995 * @tc.name : ANS_GetSlotByType_0100
996 * @tc.desc : Test GetSlotByType function
997 */
998 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_08700, Function | SmallTest | Level1)
999 {
1000 TestAddSlot(NotificationConstant::SlotType::OTHER);
1001 sptr<NotificationSlot> slot;
1002 EXPECT_EQ((int)advancedNotificationService_->GetSlotByType(NotificationConstant::OTHER, slot), (int)ERR_OK);
1003 EXPECT_EQ(slot->GetType(), NotificationConstant::SlotType::OTHER);
1004 }
1005
1006 /**
1007 * @tc.number : AdvancedNotificationServiceTest_09000
1008 * @tc.name : ANS_GetAllActiveNotifications_0100
1009 * @tc.desc : Test GetAllActiveNotifications function
1010 */
1011 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09000, Function | SmallTest | Level1)
1012 {
1013 std::vector<sptr<Notification>> notifications;
1014 EXPECT_EQ(advancedNotificationService_->GetAllActiveNotifications(notifications), ERR_OK);
1015 }
1016
1017 /**
1018 * @tc.number : AdvancedNotificationServiceTest_09200
1019 * @tc.name : ANS_SetNotificationsEnabledForAllBundles_0200
1020 * @tc.desc : Test SetNotificationsEnabledForAllBundles function
1021 */
1022 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09200, Function | SmallTest | Level1)
1023 {
1024 EXPECT_EQ(
1025 (int)advancedNotificationService_->SetNotificationsEnabledForAllBundles(std::string(), true), (int)ERR_OK);
1026 }
1027
1028 /**
1029 * @tc.number : AdvancedNotificationServiceTest_09300
1030 * @tc.name : ANS_SetNotificationsEnabledForSpecialBundle_0100
1031 * @tc.desc : Test SetNotificationsEnabledForSpecialBundle function
1032 */
1033 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09300, Function | SmallTest | Level1)
1034 {
1035 TestAddSlot(NotificationConstant::SlotType::OTHER);
1036 std::vector<sptr<Notification>> notifications;
1037 EXPECT_EQ((int)advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(
1038 std::string(), new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID), true),
1039 (int)ERR_OK);
1040 }
1041
1042 /**
1043 * @tc.number : AdvancedNotificationServiceTest_09500
1044 * @tc.name : ANS_IsAllowedNotify_0100
1045 * @tc.desc : Test IsAllowedNotify function
1046 */
1047 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09500, Function | SmallTest | Level1)
1048 {
1049 EXPECT_EQ(
1050 (int)advancedNotificationService_->SetNotificationsEnabledForAllBundles(std::string(), true), (int)ERR_OK);
1051 bool allowed = false;
1052 EXPECT_EQ((int)advancedNotificationService_->IsAllowedNotify(allowed), (int)ERR_OK);
1053 EXPECT_TRUE(allowed);
1054 }
1055
1056 /**
1057 * @tc.number : AdvancedNotificationServiceTest_09600
1058 * @tc.name : ANS_IsAllowedNotifySelf_0100
1059 * @tc.desc : Test IsAllowedNotifySelf function
1060 */
1061 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09600, Function | SmallTest | Level1)
1062 {
1063 EXPECT_EQ(
1064 (int)advancedNotificationService_->SetNotificationsEnabledForAllBundles(std::string(), true), (int)ERR_OK);
1065 bool allowed = false;
1066 EXPECT_EQ((int)advancedNotificationService_->IsAllowedNotifySelf(allowed), (int)ERR_OK);
1067 EXPECT_TRUE(allowed);
1068 }
1069
1070 /**
1071 * @tc.number : AdvancedNotificationServiceTest_09700
1072 * @tc.name : ANS_IsSpecialBundleAllowedNotify_0100
1073 * @tc.desc : Test IsSpecialBundleAllowedNotify function
1074 */
1075 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09700, Function | SmallTest | Level1)
1076 {
1077 EXPECT_EQ(
1078 (int)advancedNotificationService_->SetNotificationsEnabledForAllBundles(std::string(), true), (int)ERR_OK);
1079 TestAddSlot(NotificationConstant::SlotType::OTHER);
1080 bool allowed = true;
1081 EXPECT_EQ((int)advancedNotificationService_->IsSpecialBundleAllowedNotify(
1082 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), allowed),
1083 (int)ERR_OK);
1084 }
1085
1086 /**
1087 * @tc.number : AdvancedNotificationServiceTest_09800
1088 * @tc.name : ANS_IsSpecialBundleAllowedNotify_0200
1089 * @tc.desc : Test IsSpecialBundleAllowedNotify function
1090 */
1091 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09800, Function | SmallTest | Level1)
1092 {
1093 EXPECT_EQ(
1094 (int)advancedNotificationService_->SetNotificationsEnabledForAllBundles(std::string(), true), (int)ERR_OK);
1095 std::vector<sptr<Notification>> notifications;
1096 bool allowed = true;
1097 EXPECT_EQ((int)advancedNotificationService_->IsSpecialBundleAllowedNotify(
1098 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), allowed),
1099 (int)ERR_OK);
1100 }
1101
1102 /**
1103 * @tc.number : AdvancedNotificationServiceTest_09900
1104 * @tc.name : ANS_GetSlotsByBundle_0200
1105 * @tc.desc : Test GetSlotsByBundle function when no bundle
1106 */
1107 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09900, Function | SmallTest | Level1)
1108 {
1109 std::vector<sptr<NotificationSlot>> slots;
1110 EXPECT_EQ((int)advancedNotificationService_->GetSlotsByBundle(
1111 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID), slots),
1112 (int)ERR_OK);
1113 }
1114
MakePixelMap(int32_t width,int32_t height)1115 inline std::shared_ptr<PixelMap> MakePixelMap(int32_t width, int32_t height)
1116 {
1117 const int32_t PIXEL_BYTES = 4;
1118 std::shared_ptr<PixelMap> pixelMap = std::make_shared<PixelMap>();
1119 if (pixelMap == nullptr) {
1120 return nullptr;
1121 }
1122 ImageInfo info;
1123 info.size.width = width;
1124 info.size.height = height;
1125 info.pixelFormat = PixelFormat::ARGB_8888;
1126 info.colorSpace = ColorSpace::SRGB;
1127 pixelMap->SetImageInfo(info);
1128 int32_t rowDataSize = width * PIXEL_BYTES;
1129 uint32_t bufferSize = rowDataSize * height;
1130 void *buffer = malloc(bufferSize);
1131 if (buffer != nullptr) {
1132 pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, AllocatorType::HEAP_ALLOC, nullptr);
1133 }
1134 return pixelMap;
1135 }
1136
1137 /**
1138 * @tc.number : AdvancedNotificationServiceTest_10000
1139 * @tc.name : ANS_Publish_With_PixelMap
1140 * @tc.desc : Publish a notification with pixelMap.
1141 */
1142 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10000, Function | SmallTest | Level1)
1143 {
1144 const int BIG_PICTURE_WIDTH = 400;
1145 const int BIG_PICTURE_HEIGHT = 300;
1146 const int ICON_SIZE = 36;
1147
1148 sptr<NotificationRequest> req = new NotificationRequest(1);
1149 EXPECT_NE(req, nullptr);
1150 req->SetSlotType(NotificationConstant::SlotType::OTHER);
1151 req->SetLabel("label");
1152 std::shared_ptr<NotificationPictureContent> pictureContent = std::make_shared<NotificationPictureContent>();
1153 EXPECT_NE(pictureContent, nullptr);
1154 pictureContent->SetText("notification text");
1155 pictureContent->SetTitle("notification title");
1156 std::shared_ptr<PixelMap> bigPicture = MakePixelMap(BIG_PICTURE_WIDTH, BIG_PICTURE_HEIGHT);
1157 EXPECT_NE(bigPicture, nullptr);
1158 pictureContent->SetBigPicture(bigPicture);
1159 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(pictureContent);
1160 EXPECT_NE(content, nullptr);
1161 req->SetContent(content);
1162 std::shared_ptr<PixelMap> littleIcon = MakePixelMap(ICON_SIZE, ICON_SIZE);
1163 req->SetLittleIcon(littleIcon);
1164 std::shared_ptr<PixelMap> bigIcon = MakePixelMap(ICON_SIZE, ICON_SIZE);
1165 req->SetBigIcon(bigIcon);
1166 EXPECT_EQ(advancedNotificationService_->Publish("label", req), (int)ERR_OK);
1167 }
1168
1169 /**
1170 * @tc.number : AdvancedNotificationServiceTest_10100
1171 * @tc.name : ANS_Publish_With_PixelMap_Oversize_00100
1172 * @tc.desc : Publish a notification with oversize pixelMap.
1173 */
1174 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10100, Function | SmallTest | Level1)
1175 {
1176 const int BIG_PICTURE_WIDTH = 1024;
1177 const int BIG_PICTURE_HEIGHT = 1024;
1178 const int ICON_SIZE = 36;
1179
1180 sptr<NotificationRequest> req = new NotificationRequest(1);
1181 EXPECT_NE(req, nullptr);
1182 req->SetSlotType(NotificationConstant::SlotType::OTHER);
1183 req->SetLabel("label");
1184 std::shared_ptr<NotificationPictureContent> pictureContent = std::make_shared<NotificationPictureContent>();
1185 EXPECT_NE(pictureContent, nullptr);
1186 pictureContent->SetText("notification text");
1187 pictureContent->SetTitle("notification title");
1188 std::shared_ptr<PixelMap> bigPicture = MakePixelMap(BIG_PICTURE_WIDTH, BIG_PICTURE_HEIGHT);
1189 EXPECT_NE(bigPicture, nullptr);
1190 pictureContent->SetBigPicture(bigPicture);
1191 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(pictureContent);
1192 EXPECT_NE(content, nullptr);
1193 req->SetContent(content);
1194 std::shared_ptr<PixelMap> littleIcon = MakePixelMap(ICON_SIZE, ICON_SIZE);
1195 req->SetLittleIcon(littleIcon);
1196 std::shared_ptr<PixelMap> bigIcon = MakePixelMap(ICON_SIZE, ICON_SIZE);
1197 req->SetBigIcon(bigIcon);
1198 EXPECT_EQ(advancedNotificationService_->Publish("label", req), (int)ERR_ANS_PICTURE_OVER_SIZE);
1199 }
1200
1201 /**
1202 * @tc.number : AdvancedNotificationServiceTest_10200
1203 * @tc.name : ANS_Publish_With_PixelMap_Oversize_00200
1204 * @tc.desc : Publish a notification with oversize pixelMap.
1205 */
1206 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10200, Function | SmallTest | Level1)
1207 {
1208 const int BIG_PICTURE_WIDTH = 400;
1209 const int BIG_PICTURE_HEIGHT = 300;
1210 const int ICON_SIZE = 256;
1211
1212 sptr<NotificationRequest> req = new NotificationRequest(1);
1213 EXPECT_NE(req, nullptr);
1214 req->SetSlotType(NotificationConstant::SlotType::OTHER);
1215 req->SetLabel("label");
1216 std::shared_ptr<NotificationPictureContent> pictureContent = std::make_shared<NotificationPictureContent>();
1217 EXPECT_NE(pictureContent, nullptr);
1218 pictureContent->SetText("notification text");
1219 pictureContent->SetTitle("notification title");
1220 std::shared_ptr<PixelMap> bigPicture = MakePixelMap(BIG_PICTURE_WIDTH, BIG_PICTURE_HEIGHT);
1221 EXPECT_NE(bigPicture, nullptr);
1222 pictureContent->SetBigPicture(bigPicture);
1223 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(pictureContent);
1224 EXPECT_NE(content, nullptr);
1225 req->SetContent(content);
1226 std::shared_ptr<PixelMap> littleIcon = MakePixelMap(ICON_SIZE, ICON_SIZE);
1227 req->SetLittleIcon(littleIcon);
1228 std::shared_ptr<PixelMap> bigIcon = MakePixelMap(ICON_SIZE, ICON_SIZE);
1229 req->SetBigIcon(bigIcon);
1230 EXPECT_EQ(advancedNotificationService_->Publish("label", req), (int)ERR_ANS_ICON_OVER_SIZE);
1231 }
1232
1233 /**
1234 * @tc.number : AdvancedNotificationServiceTest_10300
1235 * @tc.name : ANS_Cancel_By_Group_10300
1236 * @tc.desc : Cancel notification by group name.
1237 */
1238 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10300, Function | SmallTest | Level1)
1239 {
1240 sptr<NotificationRequest> req = new NotificationRequest(1);
1241 ASSERT_NE(req, nullptr);
1242 req->SetSlotType(NotificationConstant::SlotType::OTHER);
1243 req->SetLabel("label");
1244 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1245 ASSERT_NE(normalContent, nullptr);
1246 normalContent->SetText("text");
1247 normalContent->SetTitle("title");
1248 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1249 ASSERT_NE(content, nullptr);
1250 req->SetContent(content);
1251 std::string groupName = "group";
1252 req->SetGroupName(groupName);
1253 EXPECT_EQ(advancedNotificationService_->Publish("label", req), (int)ERR_OK);
1254 EXPECT_EQ(advancedNotificationService_->CancelGroup(groupName), (int)ERR_OK);
1255 SleepForFC();
1256 }
1257
1258 /**
1259 * @tc.number : AdvancedNotificationServiceTest_10400
1260 * @tc.name : ANS_Remove_By_Group_10400
1261 * @tc.desc : Remove notification by group name.
1262 */
1263 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10400, Function | SmallTest | Level1)
1264 {
1265 sptr<NotificationRequest> req = new NotificationRequest(1);
1266 ASSERT_NE(req, nullptr);
1267 req->SetSlotType(NotificationConstant::SlotType::OTHER);
1268 req->SetLabel("label");
1269 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1270 ASSERT_NE(normalContent, nullptr);
1271 normalContent->SetText("text");
1272 normalContent->SetTitle("title");
1273 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1274 ASSERT_NE(content, nullptr);
1275 req->SetContent(content);
1276 std::string groupName = "group";
1277 req->SetGroupName(groupName);
1278 EXPECT_EQ(advancedNotificationService_->Publish("label", req), (int)ERR_OK);
1279 sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID);
1280 EXPECT_EQ(advancedNotificationService_->RemoveGroupByBundle(bundleOption, groupName), (int)ERR_OK);
1281 SleepForFC();
1282 }
1283
1284 /**
1285 * @tc.number : AdvancedNotificationServiceTest_10500
1286 * @tc.name : ANS_SetDisturbMode_10500
1287 * @tc.desc : Test SetDisturbMode function
1288 */
1289 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10500, Function | SmallTest | Level1)
1290 {
1291 sptr<NotificationDoNotDisturbDate> date =
1292 new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0);
1293 EXPECT_EQ((int)advancedNotificationService_->SetDoNotDisturbDate(date), (int)ERR_OK);
1294
1295 std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now();
1296 auto beginDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
1297 int64_t beginDate = beginDuration.count();
1298 timePoint += std::chrono::hours(1);
1299 auto endDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
1300 int64_t endDate = endDuration.count();
1301 date = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::ONCE, beginDate, endDate);
1302 EXPECT_EQ((int)advancedNotificationService_->SetDoNotDisturbDate(date), (int)ERR_OK);
1303
1304 timePoint = std::chrono::system_clock::now();
1305 beginDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
1306 beginDate = beginDuration.count();
1307 timePoint += std::chrono::hours(1);
1308 endDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
1309 endDate = endDuration.count();
1310 date = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::DAILY, beginDate, endDate);
1311 EXPECT_EQ((int)advancedNotificationService_->SetDoNotDisturbDate(date), (int)ERR_OK);
1312
1313 timePoint = std::chrono::system_clock::now();
1314 beginDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
1315 beginDate = beginDuration.count();
1316 timePoint += std::chrono::hours(1);
1317 endDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
1318 endDate = endDuration.count();
1319 date = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::CLEARLY, beginDate, endDate);
1320 EXPECT_EQ((int)advancedNotificationService_->SetDoNotDisturbDate(date), (int)ERR_OK);
1321 }
1322
1323 /**
1324 * @tc.number : AdvancedNotificationServiceTest_10600
1325 * @tc.name : ANS_GetDisturbMode_10600
1326 * @tc.desc : Test GetDisturbMode function
1327 */
1328 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10600, Function | SmallTest | Level1)
1329 {
1330 sptr<NotificationDoNotDisturbDate> date =
1331 new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0);
1332
1333 EXPECT_EQ((int)advancedNotificationService_->SetDoNotDisturbDate(date), (int)ERR_OK);
1334
1335 sptr<NotificationDoNotDisturbDate> result = nullptr;
1336 EXPECT_EQ((int)advancedNotificationService_->GetDoNotDisturbDate(result), (int)ERR_OK);
1337 ASSERT_NE(result, nullptr);
1338 EXPECT_EQ(result->GetDoNotDisturbType(), NotificationConstant::DoNotDisturbType::NONE);
1339 EXPECT_EQ(result->GetBeginDate(), 0);
1340 EXPECT_EQ(result->GetEndDate(), 0);
1341 }
1342
1343 /**
1344 * @tc.number : AdvancedNotificationServiceTest_10700
1345 * @tc.name : ANS_GetDisturbMode_10700
1346 * @tc.desc : Test GetDisturbMode function
1347 */
1348 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10700, Function | SmallTest | Level1)
1349 {
1350 std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now();
1351 timePoint = std::chrono::time_point_cast<std::chrono::minutes>(timePoint);
1352 timePoint += std::chrono::hours(1);
1353 auto beginDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
1354 int64_t beginDate = beginDuration.count();
1355 timePoint += std::chrono::hours(1);
1356 auto endDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
1357 int64_t endDate = endDuration.count();
1358
1359 sptr<NotificationDoNotDisturbDate> date =
1360 new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::ONCE, beginDate, endDate);
1361 EXPECT_EQ((int)advancedNotificationService_->SetDoNotDisturbDate(date), (int)ERR_OK);
1362
1363 sptr<NotificationDoNotDisturbDate> result = nullptr;
1364 EXPECT_EQ((int)advancedNotificationService_->GetDoNotDisturbDate(result), (int)ERR_OK);
1365 ASSERT_NE(result, nullptr);
1366 EXPECT_EQ(result->GetDoNotDisturbType(), NotificationConstant::DoNotDisturbType::ONCE);
1367 EXPECT_EQ(result->GetBeginDate(), beginDate);
1368 EXPECT_EQ(result->GetEndDate(), endDate);
1369 }
1370
1371 /**
1372 * @tc.number : AdvancedNotificationServiceTest_10800
1373 * @tc.name : ANS_GetDisturbMode_10800
1374 * @tc.desc : Test GetDisturbMode function
1375 */
1376 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10800, Function | SmallTest | Level1)
1377 {
1378 std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now();
1379 timePoint = std::chrono::time_point_cast<std::chrono::minutes>(timePoint);
1380 timePoint += std::chrono::hours(1);
1381 auto beginDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
1382 int64_t beginDate = beginDuration.count();
1383 timePoint += std::chrono::hours(1);
1384 auto endDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
1385 int64_t endDate = endDuration.count();
1386
1387 sptr<NotificationDoNotDisturbDate> date =
1388 new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::DAILY, beginDate, endDate);
1389
1390 EXPECT_EQ((int)advancedNotificationService_->SetDoNotDisturbDate(date), (int)ERR_OK);
1391 sptr<NotificationDoNotDisturbDate> result = nullptr;
1392 EXPECT_EQ((int)advancedNotificationService_->GetDoNotDisturbDate(result), (int)ERR_OK);
1393 ASSERT_NE(result, nullptr);
1394 EXPECT_EQ(result->GetDoNotDisturbType(), NotificationConstant::DoNotDisturbType::DAILY);
1395 EXPECT_EQ(result->GetBeginDate(), beginDate);
1396 EXPECT_EQ(result->GetEndDate(), endDate);
1397 }
1398
1399 /**
1400 * @tc.number : AdvancedNotificationServiceTest_10900
1401 * @tc.name : ANS_GetDisturbMode_10900
1402 * @tc.desc : Test GetDisturbMode function
1403 */
1404 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10900, Function | SmallTest | Level1)
1405 {
1406 std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now();
1407 timePoint = std::chrono::time_point_cast<std::chrono::minutes>(timePoint);
1408 timePoint += std::chrono::hours(1);
1409 auto beginDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
1410 int64_t beginDate = beginDuration.count();
1411 timePoint += std::chrono::hours(1);
1412 auto endDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
1413 int64_t endDate = endDuration.count();
1414
1415 sptr<NotificationDoNotDisturbDate> date =
1416 new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::CLEARLY, beginDate, endDate);
1417 EXPECT_EQ((int)advancedNotificationService_->SetDoNotDisturbDate(date), (int)ERR_OK);
1418
1419 sptr<NotificationDoNotDisturbDate> result = nullptr;
1420 EXPECT_EQ((int)advancedNotificationService_->GetDoNotDisturbDate(result), (int)ERR_OK);
1421 ASSERT_NE(result, nullptr);
1422 EXPECT_EQ(result->GetDoNotDisturbType(), NotificationConstant::DoNotDisturbType::CLEARLY);
1423 EXPECT_EQ(result->GetBeginDate(), beginDate);
1424 EXPECT_EQ(result->GetEndDate(), endDate);
1425 }
1426
1427 /**
1428 * @tc.number : ANS_Publish_01500
1429 * @tc.name : ANSPublish01500
1430 * @tc.desc : publish a continuous task notification
1431 */
1432 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11000, Function | SmallTest | Level1)
1433 {
1434 IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID);
1435 IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
1436 sptr<NotificationRequest> req = new NotificationRequest();
1437 EXPECT_NE(req, nullptr);
1438 req->SetSlotType(NotificationConstant::SlotType::OTHER);
1439 req->SetLabel("req's label");
1440 EXPECT_EQ(advancedNotificationService_->PublishContinuousTaskNotification(req), (int)ERR_OK);
1441 SleepForFC();
1442 }
1443
1444 /**
1445 * @tc.number : ANS_Publish_01600
1446 * @tc.name : ANSPublish01600
1447 * @tc.desc : publish a continuous task notification
1448 */
1449 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11100, Function | SmallTest | Level1)
1450 {
1451 IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN);
1452 sptr<NotificationRequest> req = new NotificationRequest();
1453 EXPECT_NE(req, nullptr);
1454 req->SetSlotType(NotificationConstant::SlotType::OTHER);
1455 req->SetLabel("req's label");
1456 EXPECT_EQ(advancedNotificationService_->PublishContinuousTaskNotification(req), (int)ERR_ANS_NOT_SYSTEM_SERVICE);
1457 SleepForFC();
1458 }
1459
1460 /**
1461 * @tc.number : AdvancedNotificationServiceTest_11200
1462 * @tc.name : ANS_Cancel_0300
1463 * @tc.desc : public two notification to cancel one of them
1464 */
1465 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11200, Function | SmallTest | Level1)
1466 {
1467 IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
1468 IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID);
1469 std::string label = "testLabel";
1470 {
1471 sptr<NotificationRequest> req = new NotificationRequest(1);
1472 req->SetSlotType(NotificationConstant::OTHER);
1473 req->SetLabel(label);
1474 EXPECT_EQ(advancedNotificationService_->PublishContinuousTaskNotification(req), (int)ERR_OK);
1475 }
1476 EXPECT_EQ(advancedNotificationService_->CancelContinuousTaskNotification(label, 1), (int)ERR_OK);
1477 }
1478
1479 /**
1480 * @tc.number : AdvancedNotificationServiceTest_11300
1481 * @tc.name : ANS_Cancel_0400
1482 * @tc.desc : public two notification to cancel one of them
1483 */
1484 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11300, Function | SmallTest | Level1)
1485 {
1486 IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
1487 IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID);
1488 std::string label = "testLabel";
1489 {
1490 sptr<NotificationRequest> req = new NotificationRequest(1);
1491 req->SetSlotType(NotificationConstant::OTHER);
1492 req->SetLabel(label);
1493 EXPECT_EQ(advancedNotificationService_->PublishContinuousTaskNotification(req), (int)ERR_OK);
1494 }
1495 IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN);
1496 EXPECT_EQ(
1497 advancedNotificationService_->CancelContinuousTaskNotification(label, 1), (int)ERR_ANS_NOT_SYSTEM_SERVICE);
1498 }
1499
1500 /**
1501 * @tc.name: AdvancedNotificationServiceTest_12000
1502 * @tc.desc: Send enable notification hisysevent and enable notification error hisysevent.
1503 * @tc.type: FUNC
1504 * @tc.require: I582Y4
1505 */
1506 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12000, Function | SmallTest | Level1)
1507 {
1508 // bundleName is empty
1509 EXPECT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(
1510 std::string(), new NotificationBundleOption(std::string(), -1), true),
1511 (int)ERR_ANS_INVALID_PARAM);
1512
1513 TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1514 sptr<NotificationRequest> req = new NotificationRequest();
1515 EXPECT_NE(req, nullptr);
1516 req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1517 req->SetLabel("req's label");
1518 std::string label = "enable's label";
1519 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1520 EXPECT_NE(normalContent, nullptr);
1521 normalContent->SetText("normalContent's text");
1522 normalContent->SetTitle("normalContent's title");
1523 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1524 EXPECT_NE(content, nullptr);
1525 req->SetContent(content);
1526 EXPECT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(
1527 std::string(), new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), false),
1528 (int)ERR_OK);
1529
1530 EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_ANS_NOT_ALLOWED);
1531 SleepForFC();
1532 }
1533
1534 /**
1535 * @tc.name: AdvancedNotificationServiceTest_12100
1536 * @tc.desc: Send enable notification slot hisysevent.
1537 * @tc.type: FUNC
1538 * @tc.require: I582Y4
1539 */
1540 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12100, Function | SmallTest | Level1)
1541 {
1542 TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1543 sptr<NotificationRequest> req = new NotificationRequest();
1544 EXPECT_NE(req, nullptr);
1545 req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1546 req->SetLabel("req's label");
1547 std::string label = "enable's label";
1548 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1549 EXPECT_NE(normalContent, nullptr);
1550 normalContent->SetText("normalContent's text");
1551 normalContent->SetTitle("normalContent's title");
1552 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1553 EXPECT_NE(content, nullptr);
1554 req->SetContent(content);
1555 auto result = advancedNotificationService_->SetEnabledForBundleSlot(
1556 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID),
1557 NotificationConstant::SlotType::SOCIAL_COMMUNICATION,
1558 false);
1559 EXPECT_EQ(result, (int)ERR_OK);
1560 EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_ENABLED);
1561 SleepForFC();
1562 }
1563
1564 /**
1565 * @tc.name: AdvancedNotificationServiceTest_12200
1566 * @tc.desc: Send remove notification hisysevent.
1567 * @tc.type: FUNC
1568 * @tc.require: I582Y4
1569 */
1570 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12200, Function | SmallTest | Level1)
1571 {
1572 TestAddSlot(NotificationConstant::SlotType::OTHER);
1573 int32_t notificationId = 1;
1574 std::string label = "testRemove";
1575 sptr<NotificationRequest> req = new NotificationRequest(notificationId);
1576 req->SetSlotType(NotificationConstant::OTHER);
1577 req->SetLabel(label);
1578 EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
1579 auto result = advancedNotificationService_->RemoveNotification(
1580 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID),
1581 notificationId, label, NotificationConstant::CANCEL_REASON_DELETE);
1582 EXPECT_EQ(result, (int)ERR_OK);
1583 }
1584
1585 /**
1586 * @tc.name: AdvancedNotificationServiceTest_12300
1587 * @tc.desc: SA publish notification, Failed to publish when creatorUid default.
1588 * @tc.type: FUNC
1589 * @tc.require: I5P1GU
1590 */
1591 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12300, Function | SmallTest | Level1)
1592 {
1593 IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
1594 TestAddSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
1595 sptr<NotificationRequest> req = new NotificationRequest();
1596 EXPECT_NE(req, nullptr);
1597 req->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION);
1598 req->SetLabel("req's label");
1599 std::string label = "publish's label";
1600 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1601 EXPECT_NE(normalContent, nullptr);
1602 normalContent->SetText("normalContent's text");
1603 normalContent->SetTitle("normalContent's title");
1604 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1605 EXPECT_NE(content, nullptr);
1606 req->SetContent(content);
1607 EXPECT_EQ(advancedNotificationService_->Publish(label, req), ERR_ANS_INVALID_UID);
1608 SleepForFC();
1609
1610 req->SetCreatorUid(1);
1611 EXPECT_EQ(advancedNotificationService_->Publish(label, req), 0);
1612 }
1613
1614 /*
1615 * @tc.name: AdvancedNotificationServiceTest_12400
1616 * @tc.desc: DLP App publish notification failed.
1617 * @tc.type: FUNC
1618 * @tc.require: I582TY
1619 */
1620 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12400, Function | SmallTest | Level1)
1621 {
1622 IPCSkeleton::SetCallingTokenID(DLP_NATIVE_TOKEN);
1623 sptr<NotificationRequest> req = new (std::nothrow) NotificationRequest(1);
1624 EXPECT_NE(req, nullptr);
1625 req->SetSlotType(NotificationConstant::SlotType::OTHER);
1626 req->SetLabel("req's label");
1627 std::string label = "publish's label";
1628 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1629 EXPECT_NE(normalContent, nullptr);
1630 normalContent->SetText("normalContent's text");
1631 normalContent->SetTitle("normalContent's title");
1632 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1633 EXPECT_NE(content, nullptr);
1634 req->SetContent(content);
1635 EXPECT_EQ(advancedNotificationService_->Publish(label, req), ERR_ANS_DLP_HAP);
1636 SleepForFC();
1637
1638 IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN);
1639 EXPECT_EQ(advancedNotificationService_->Publish(label, req), ERR_OK);
1640 }
1641
1642 /*
1643 * @tc.name: AdvancedNotificationServiceTest_12500
1644 * @tc.desc: When the user removed event is received and the userid is less than or equal to 100,
1645 * the notification cannot be deleted
1646 * @tc.type: FUNC
1647 */
1648 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12500, Function | SmallTest | Level1)
1649 {
1650 sptr<NotificationRequest> req = new (std::nothrow) NotificationRequest(1);
1651 EXPECT_NE(req, nullptr);
1652 req->SetSlotType(NotificationConstant::SlotType::OTHER);
1653 req->SetLabel("req's label");
1654 std::string label = "publish's label";
1655 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1656 EXPECT_NE(normalContent, nullptr);
1657 normalContent->SetText("normalContent's text");
1658 normalContent->SetTitle("normalContent's title");
1659 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1660 EXPECT_NE(content, nullptr);
1661 req->SetContent(content);
1662 req->SetCreatorUserId(DEFAULT_USER_ID);
1663 EXPECT_EQ(advancedNotificationService_->Publish(label, req), ERR_OK);
1664 SleepForFC();
1665
1666 EventFwk::Want want;
1667 EventFwk::CommonEventData data;
1668 data.SetWant(want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED));
1669 data.SetCode(DEFAULT_USER_ID);
1670 advancedNotificationService_->systemEventObserver_->OnReceiveEvent(data);
1671
1672 std::stringstream key;
1673 key << "_" << req->GetCreatorUserId() << "_" << req->GetCreatorUid() << "_"
1674 << req->GetLabel() << "_" << req->GetNotificationId();
1675
1676 EXPECT_EQ(advancedNotificationService_->IsNotificationExists(key.str()), true);
1677 }
1678
1679 /**
1680 * @tc.number : AdvancedNotificationServiceTest_12600
1681 * @tc.name : ANS_CancelAsBundle_0100
1682 * @tc.desc : Test CancelAsBundle function when the result is ERR_ANS_NOTIFICATION_NOT_EXISTS
1683 * @tc.require : issueI5S4VP
1684 */
1685 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12600, Function | SmallTest | Level1)
1686 {
1687 TestAddSlot(NotificationConstant::SlotType::OTHER);
1688 int32_t notificationId = 1;
1689 std::string representativeBundle = "RepresentativeBundle";
1690 int32_t userId = 1;
1691 int result = ERR_ANS_NOTIFICATION_NOT_EXISTS;
1692 EXPECT_EQ(advancedNotificationService_->CancelAsBundle(notificationId, representativeBundle, userId), result);
1693 }
1694
1695 /**
1696 * @tc.number : AdvancedNotificationServiceTest_12700
1697 * @tc.name : ANS_CanPublishAsBundle_0100
1698 * @tc.desc : Test CanPublishAsBundle function when the result is ERR_INVALID_OPERATION
1699 * @tc.require : issueI5S4VP
1700 */
1701 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12700, Function | SmallTest | Level1)
1702 {
1703 std::string representativeBundle = "RepresentativeBundle";
1704 bool canPublish = true;
1705 int result = ERR_INVALID_OPERATION;
1706 EXPECT_EQ(advancedNotificationService_->CanPublishAsBundle(representativeBundle, canPublish), result);
1707 }
1708
1709 /**
1710 * @tc.number : AdvancedNotificationServiceTest_12800
1711 * @tc.name : ANS_PublishAsBundle_0100
1712 * @tc.desc : Test PublishAsBundle function when the result is ERR_INVALID_OPERATION
1713 * @tc.require : issueI5S4VP
1714 */
1715 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12800, Function | SmallTest | Level1)
1716 {
1717 sptr<NotificationRequest> notification = nullptr;
1718 std::string representativeBundle = "RepresentativeBundle";
1719 int result = ERR_INVALID_OPERATION;
1720 EXPECT_EQ(advancedNotificationService_->PublishAsBundle(notification, representativeBundle), result);
1721 }
1722
1723 /**
1724 * @tc.number : AdvancedNotificationServiceTest_12900
1725 * @tc.name : ANS_HasNotificationPolicyAccessPermission_0100
1726 * @tc.desc : Test HasNotificationPolicyAccessPermission function when the result is ERR_OK
1727 * @tc.require : issueI5S4VP
1728 */
1729 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12900, Function | SmallTest | Level1)
1730 {
1731 bool granted = true;
1732 EXPECT_EQ(advancedNotificationService_->HasNotificationPolicyAccessPermission(granted), (int)ERR_OK);
1733 }
1734
1735 /**
1736 * @tc.number : AdvancedNotificationServiceTest_13000
1737 * @tc.name : ANS_GetShowBadgeEnabled_0100
1738 * @tc.desc : Test GetShowBadgeEnabled function when the result is ERR_OK
1739 * @tc.require : issueI5S4VP
1740 */
1741 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_13000, Function | SmallTest | Level1)
1742 {
1743 TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1744 sptr<NotificationRequest> req = new NotificationRequest();
1745 EXPECT_NE(req, nullptr);
1746 bool enabled = false;
1747 EXPECT_EQ(advancedNotificationService_->GetShowBadgeEnabled(enabled), (int)ERR_OK);
1748 }
1749
1750 /**
1751 * @tc.number : AdvancedNotificationServiceTest_13100
1752 * @tc.name : ANS_RequestEnableNotification_0100
1753 * @tc.desc : Test whether to pop dialog
1754 * @tc.require : issueI5S4VP
1755 */
1756 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_13100, Function | SmallTest | Level1)
1757 {
1758 TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1759 sptr<NotificationRequest> req = new NotificationRequest();
1760 EXPECT_NE(req, nullptr);
1761 std::string deviceId = "DeviceId";
1762 EXPECT_EQ(advancedNotificationService_->RequestEnableNotification(deviceId), (int)ERR_ANS_INVALID_PARAM);
1763 }
1764
1765 /**
1766 * @tc.number : AdvancedNotificationServiceTest_13200
1767 * @tc.name : ANS_PublishReminder_0100
1768 * @tc.desc : Test PublishReminder function
1769 * @tc.require : issueI5S4VP
1770 */
1771 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_13200, Function | SmallTest | Level1)
1772 {
1773 sptr<ReminderRequest> reminder = nullptr;
1774 EXPECT_EQ(advancedNotificationService_->PublishReminder(reminder), ERR_ANS_INVALID_PARAM);
1775 }
1776
1777 /**
1778 * @tc.number : AdvancedNotificationServiceTest_13300
1779 * @tc.name : ANS_CancelReminder_0100
1780 * @tc.desc : Test CancelReminder function when the result is ERR_NO_INIT
1781 * @tc.require : issueI5S4VP
1782 */
1783 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_13300, Function | SmallTest | Level1)
1784 {
1785 TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1786 sptr<NotificationRequest> req = new NotificationRequest();
1787 EXPECT_NE(req, nullptr);
1788 int32_t reminderId = 1;
1789 EXPECT_EQ(advancedNotificationService_->CancelReminder(reminderId), (int)ERR_NO_INIT);
1790 }
1791
1792 /**
1793 * @tc.number : AdvancedNotificationServiceTest_13400
1794 * @tc.name : ANS_CancelAllReminders_0100
1795 * @tc.desc : Test CancelAllReminders function when the result is ERR_NO_INIT
1796 * @tc.require : issueI5S4VP
1797 */
1798 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_13400, Function | SmallTest | Level1)
1799 {
1800 TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1801 sptr<NotificationRequest> req = new NotificationRequest();
1802 EXPECT_NE(req, nullptr);
1803 EXPECT_EQ(advancedNotificationService_->CancelAllReminders(), (int)ERR_NO_INIT);
1804 }
1805
1806 /**
1807 * @tc.number : AdvancedNotificationServiceTest_13500
1808 * @tc.name : ANS_GetValidReminders_0100
1809 * @tc.desc : Test GetValidReminders function when the result is ERR_NO_INIT
1810 * @tc.require : issueI5S4VP
1811 */
1812 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_13500, Function | SmallTest | Level1)
1813 {
1814 std::vector<sptr<ReminderRequest>> reminders;
1815 EXPECT_EQ(advancedNotificationService_->GetValidReminders(reminders), (int)ERR_NO_INIT);
1816 }
1817
1818 /**
1819 * @tc.number : AdvancedNotificationServiceTest_13600
1820 * @tc.name : ANS_ActiveNotificationDump_0100
1821 * @tc.desc : Test ActiveNotificationDump function when the result is ERR_OK
1822 * @tc.require : issueI5S4VP
1823 */
1824 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_13600, Function | SmallTest | Level1)
1825 {
1826 std::string bundle = "Bundle";
1827 int32_t userId = 2;
1828 std::vector<std::string> dumpInfo;
1829 EXPECT_EQ(advancedNotificationService_->ActiveNotificationDump(bundle, userId, dumpInfo), (int)ERR_OK);
1830 }
1831
1832 /**
1833 * @tc.number : AdvancedNotificationServiceTest_13700
1834 * @tc.name : ANS_RecentNotificationDump_0100
1835 * @tc.desc : Test RecentNotificationDump function when the result is ERR_OK
1836 * @tc.require : issueI5S4VP
1837 */
1838 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_13700, Function | SmallTest | Level1)
1839 {
1840 std::string bundle = "Bundle";
1841 int32_t userId = 3;
1842 std::vector<std::string> dumpInfo;
1843 EXPECT_EQ(advancedNotificationService_->RecentNotificationDump(bundle, userId, dumpInfo), (int)ERR_OK);
1844 }
1845
1846 /**
1847 * @tc.number : AdvancedNotificationServiceTest_13800
1848 * @tc.name : ANS_SetRecentNotificationCount_0100
1849 * @tc.desc : Test SetRecentNotificationCount function when the result is ERR_OK
1850 * @tc.require : issueI5S4VP
1851 */
1852 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_13800, Function | SmallTest | Level1)
1853 {
1854 std::string arg = "Arg";
1855 EXPECT_EQ(advancedNotificationService_->SetRecentNotificationCount(arg), (int)ERR_OK);
1856 }
1857
1858 /**
1859 * @tc.number : AdvancedNotificationServiceTest_13900
1860 * @tc.name : ANS_RemoveAllSlots_0100
1861 * @tc.desc : Test RemoveAllSlots function when the result is ERR_OK
1862 * @tc.require : issueI5S4VP
1863 */
1864 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_13900, Function | SmallTest | Level1)
1865 {
1866 TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1867 sptr<NotificationRequest> req = new NotificationRequest();
1868 EXPECT_NE(req, nullptr);
1869 EXPECT_EQ(advancedNotificationService_->RemoveAllSlots(), (int)ERR_OK);
1870 }
1871
1872 /**
1873 * @tc.number : AdvancedNotificationServiceTest_14200
1874 * @tc.name : ANS_DoesSupportDoNotDisturbMode_0100
1875 * @tc.desc : Test DoesSupportDoNotDisturbMode function when the result is ERR_OK
1876 * @tc.require : issueI5S4VP
1877 */
1878 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_14200, Function | SmallTest | Level1)
1879 {
1880 TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1881 sptr<NotificationRequest> req = new NotificationRequest();
1882 EXPECT_NE(req, nullptr);
1883 bool doesSupport = true;
1884 EXPECT_EQ(advancedNotificationService_->DoesSupportDoNotDisturbMode(doesSupport), (int)ERR_OK);
1885 }
1886
1887 /**
1888 * @tc.number : AdvancedNotificationServiceTest_14300
1889 * @tc.name : ANS_IsDistributedEnabled_0100
1890 * @tc.desc : Test IsDistributedEnabled function when the result is ERR_OK
1891 * @tc.require : issueI5S4VP
1892 */
1893 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_14300, Function | SmallTest | Level1)
1894 {
1895 TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1896 sptr<NotificationRequest> req = new NotificationRequest();
1897 EXPECT_NE(req, nullptr);
1898 bool enabled = true;
1899 EXPECT_EQ(advancedNotificationService_->IsDistributedEnabled(enabled), (int)ERR_OK);
1900 }
1901
1902 /**
1903 * @tc.number : AdvancedNotificationServiceTest_14400
1904 * @tc.name : ANS_EnableDistributed_0100
1905 * @tc.desc : Test EnableDistributed function when the result is ERR_OK
1906 * @tc.require : issueI5S4VP
1907 */
1908 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_14400, Function | SmallTest | Level1)
1909 {
1910 TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1911 sptr<NotificationRequest> req = new NotificationRequest();
1912 EXPECT_NE(req, nullptr);
1913 bool enabled = true;
1914 EXPECT_EQ(advancedNotificationService_->EnableDistributed(enabled), (int)ERR_OK);
1915 }
1916
1917 /**
1918 * @tc.number : AdvancedNotificationServiceTest_14600
1919 * @tc.name : ANS_EnableDistributedSelf_0100
1920 * @tc.desc : Test EnableDistributedSelf function when the result is ERR_OK
1921 * @tc.require : issueI5S4VP
1922 */
1923 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_14600, Function | SmallTest | Level1)
1924 {
1925 TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1926 sptr<NotificationRequest> req = new NotificationRequest();
1927 EXPECT_NE(req, nullptr);
1928 bool enabled = true;
1929 EXPECT_EQ(advancedNotificationService_->EnableDistributedSelf(enabled), (int)ERR_OK);
1930 }
1931
1932 /**
1933 * @tc.number : AdvancedNotificationServiceTest_14800
1934 * @tc.name : ANS_IsSpecialUserAllowedNotify_0100
1935 * @tc.desc : Test IsSpecialUserAllowedNotify function when the result is ERR_ANS_INVALID_PARAM
1936 * @tc.require : issueI5S4VP
1937 */
1938 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_14800, Function | SmallTest | Level1)
1939 {
1940 int32_t userId = 3;
1941 bool allowed = true;
1942 EXPECT_EQ(advancedNotificationService_->IsSpecialUserAllowedNotify(userId, allowed), (int)ERR_ANS_INVALID_PARAM);
1943 }
1944
1945 /**
1946 * @tc.number : AdvancedNotificationServiceTest_14900
1947 * @tc.name : ANS_SetNotificationsEnabledByUser_0100
1948 * @tc.desc : Test SetNotificationsEnabledByUser function when the result is ERR_OK
1949 * @tc.require : issueI5S4VP
1950 */
1951 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_14900, Function | SmallTest | Level1)
1952 {
1953 int32_t userId = 3;
1954 bool enabled = true;
1955 EXPECT_EQ(advancedNotificationService_->SetNotificationsEnabledByUser(userId, enabled), (int)ERR_OK);
1956 }
1957
1958 /**
1959 * @tc.number : AdvancedNotificationServiceTest_15000
1960 * @tc.name : ANS_GetDoNotDisturbDate_0100
1961 * @tc.desc : Test GetDoNotDisturbDate function when the result is ERR_OK
1962 * @tc.require : issueI5S4VP
1963 */
1964 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15000, Function | SmallTest | Level1)
1965 {
1966 int32_t userId = 3;
1967 sptr<NotificationDoNotDisturbDate> date = nullptr;
1968 EXPECT_EQ(advancedNotificationService_->GetDoNotDisturbDate(userId, date), (int)ERR_OK);
1969 }
1970
1971 /**
1972 * @tc.number : AdvancedNotificationServiceTest_15100
1973 * @tc.name : ANS_SetHasPoppedDialog_0100
1974 * @tc.desc : Test SetHasPoppedDialog function when the result is ERR_ANS_INVALID_PARAM
1975 * @tc.require : issueI5S4VP
1976 */
1977 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15100, Function | SmallTest | Level1)
1978 {
1979 sptr<NotificationBundleOption> bundleOption = nullptr;
1980 bool hasPopped = true;
1981 EXPECT_EQ(advancedNotificationService_->SetHasPoppedDialog(bundleOption, hasPopped), (int)ERR_ANS_INVALID_PARAM);
1982 }
1983
1984 /**
1985 * @tc.number : AdvancedNotificationServiceTest_15200
1986 * @tc.name : ANS_GetHasPoppedDialog_0100
1987 * @tc.desc : Test GetHasPoppedDialog function when the result is ERR_ANS_INVALID_PARAM
1988 * @tc.require : issueI5S4VP
1989 */
1990 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15200, Function | SmallTest | Level1)
1991 {
1992 sptr<NotificationBundleOption> bundleOption = nullptr;
1993 bool hasPopped = true;
1994 EXPECT_EQ(advancedNotificationService_->GetHasPoppedDialog(bundleOption, hasPopped), (int)ERR_ANS_INVALID_PARAM);
1995 }
1996
1997 /**
1998 * @tc.number : AdvancedNotificationServiceTest_15300
1999 * @tc.name : ANS_ShellDump_0100
2000 * @tc.desc : Test ShellDump function when the result is ERR_ANS_INVALID_PARAM
2001 * @tc.require : issueI5S4VP
2002 */
2003 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15300, Function | SmallTest | Level1)
2004 {
2005 IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
2006 std::string cmd = "CMD";
2007 std::string bundle = "Bundle";
2008 int32_t userId = 4;
2009 std::vector<std::string> dumpInfo;
2010 EXPECT_EQ(advancedNotificationService_->ShellDump(cmd, bundle, userId, dumpInfo), (int)ERR_ANS_INVALID_PARAM);
2011 IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN);
2012 }
2013
2014 /**
2015 * @tc.number : AdvancedNotificationServiceTest_15400
2016 * @tc.name : ANS_Dump_0100
2017 * @tc.desc : Test Dump function when the result is ERR_OK
2018 * @tc.require : issueI5S4VP
2019 */
2020 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15400, Function | SmallTest | Level1)
2021 {
2022 int fd = 1;
2023 std::vector<std::u16string> args;
2024 EXPECT_EQ(advancedNotificationService_->Dump(fd, args), (int)ERR_OK);
2025 }
2026
2027 /**
2028 * @tc.number : AdvancedNotificationServiceTest_15500
2029 * @tc.name : OnReceiveEvent_0100
2030 * @tc.desc : Test OnReceiveEvent function userid<DEFAULT_USER_ID
2031 * @tc.require : I5TIQR
2032 */
2033 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15500, Function | SmallTest | Level1)
2034 {
2035 sptr<NotificationRequest> req = new (std::nothrow) NotificationRequest(1);
2036 EXPECT_NE(req, nullptr);
2037 req->SetSlotType(NotificationConstant::SlotType::OTHER);
2038 req->SetLabel("req's label");
2039 std::string label = "publish's label";
2040 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
2041 EXPECT_NE(normalContent, nullptr);
2042 normalContent->SetText("normalContent's text");
2043 normalContent->SetTitle("normalContent's title");
2044 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
2045 EXPECT_NE(content, nullptr);
2046 req->SetContent(content);
2047 req->SetCreatorUserId(DEFAULT_USER_ID);
2048 EXPECT_EQ(advancedNotificationService_->Publish(label, req), ERR_OK);
2049 SleepForFC();
2050
2051 EventFwk::Want want;
2052 EventFwk::CommonEventData data;
2053 data.SetWant(want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED));
2054 data.SetCode(50);
2055 advancedNotificationService_->systemEventObserver_->OnReceiveEvent(data);
2056
2057 std::stringstream key;
2058 key << "_" << req->GetCreatorUserId() << "_" << req->GetCreatorUid() << "_"
2059 << req->GetLabel() << "_" << req->GetNotificationId();
2060
2061 EXPECT_EQ(advancedNotificationService_->IsNotificationExists(key.str()), true);
2062 }
2063
2064 /**
2065 * @tc.number : AdvancedNotificationServiceTest_15600
2066 * @tc.name : OnReceiveEvent_0200
2067 * @tc.desc : Test OnReceiveEvent function when userid>DEFAULT_USER_ID
2068 * @tc.require : I5TIQR
2069 */
2070 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15600, Function | SmallTest | Level1)
2071 {
2072 sptr<NotificationRequest> req = new (std::nothrow) NotificationRequest(1);
2073 EXPECT_NE(req, nullptr);
2074 req->SetSlotType(NotificationConstant::SlotType::OTHER);
2075 req->SetLabel("req's label");
2076 std::string label = "publish's label";
2077 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
2078 EXPECT_NE(normalContent, nullptr);
2079 normalContent->SetText("normalContent's text");
2080 normalContent->SetTitle("normalContent's title");
2081 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
2082 EXPECT_NE(content, nullptr);
2083 req->SetContent(content);
2084 req->SetCreatorUserId(DEFAULT_USER_ID);
2085 EXPECT_EQ(advancedNotificationService_->Publish(label, req), ERR_OK);
2086 SleepForFC();
2087
2088 EventFwk::Want want;
2089 EventFwk::CommonEventData data;
2090 data.SetWant(want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED));
2091 data.SetCode(200);
2092 advancedNotificationService_->systemEventObserver_->OnReceiveEvent(data);
2093
2094 std::stringstream key;
2095 key << "_" << req->GetCreatorUserId() << "_" << req->GetCreatorUid() << "_"
2096 << req->GetLabel() << "_" << req->GetNotificationId();
2097
2098 EXPECT_EQ(advancedNotificationService_->IsNotificationExists(key.str()), true);
2099 }
2100
2101 /**
2102 * @tc.number : AdvancedNotificationServiceTest_15700
2103 * @tc.name : PrepareNotificationRequest_0100
2104 * @tc.desc : Test PrepareNotificationRequest function when notification is agent.
2105 * @tc.require : #I60KYN
2106 */
2107 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15700, Function | SmallTest | Level1)
2108 {
2109 GTEST_LOG_(INFO) << "PrepareNotificationRequest_0100 test start";
2110 IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID);
2111 IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN);
2112
2113 sptr<NotificationRequest> req = new NotificationRequest();
2114 EXPECT_NE(req, nullptr);
2115
2116 req->SetSlotType(NotificationConstant::SlotType::OTHER);
2117 req->SetLabel("req's label");
2118 std::string label = "publish's label";
2119 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
2120 EXPECT_NE(normalContent, nullptr);
2121
2122 normalContent->SetText("normalContent's text");
2123 normalContent->SetTitle("normalContent's title");
2124 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
2125 EXPECT_NE(content, nullptr);
2126
2127 req->SetContent(content);
2128 req->SetIsAgentNotification(true);
2129 EXPECT_EQ(advancedNotificationService_->PrepareNotificationRequest(req), ERR_ANS_NON_SYSTEM_APP);
2130 GTEST_LOG_(INFO) << "PrepareNotificationRequest_0100 test end";
2131 }
2132
2133 /**
2134 * @tc.number : AdvancedNotificationServiceTest_15800
2135 * @tc.name : GenerateBundleOption_0100
2136 * @tc.desc : Test GenerateBundleOption function when bundle name is null.
2137 * @tc.require : #I60KYN
2138 */
2139 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15800, Function | SmallTest | Level1)
2140 {
2141 GTEST_LOG_(INFO) << "GenerateBundleOption_0100 test start";
2142 IPCSkeleton::SetCallingUid(NON_BUNDLE_NAME_UID);
2143 EXPECT_EQ(advancedNotificationService_->GenerateBundleOption(), nullptr);
2144 GTEST_LOG_(INFO) << "GenerateBundleOption_0100 test end";
2145 }
2146
2147 /**
2148 * @tc.number : AdvancedNotificationServiceTest_16000
2149 * @tc.name : CancelPreparedNotification_1000
2150 * @tc.desc : Test CancelPreparedNotification function.
2151 * @tc.require : #I60KYN
2152 */
2153 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16000, Function | SmallTest | Level1)
2154 {
2155 GTEST_LOG_(INFO) << "CancelPreparedNotification_1000 test start";
2156
2157 int32_t notificationId = 0;
2158 std::string label = "testLabel";
2159 sptr<NotificationBundleOption> bundleOption = nullptr;
2160 EXPECT_EQ(advancedNotificationService_->CancelPreparedNotification(notificationId, label, bundleOption),
2161 ERR_ANS_INVALID_BUNDLE);
2162
2163 GTEST_LOG_(INFO) << "CancelPreparedNotification_1000 test end";
2164 }
2165
2166 /**
2167 * @tc.number : AdvancedNotificationServiceTest_16100
2168 * @tc.name : PrepareNotificationInfo_1000
2169 * @tc.desc : Test PrepareNotificationInfo function.
2170 * @tc.require : #I60KYN
2171 */
2172 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16100, Function | SmallTest | Level1)
2173 {
2174 GTEST_LOG_(INFO) << "CancelPreparedNotification_1000 test start";
2175
2176 sptr<NotificationRequest> req = new (std::nothrow) NotificationRequest(1);
2177 EXPECT_NE(req, nullptr);
2178 req->SetSlotType(NotificationConstant::SlotType::OTHER);
2179 req->SetLabel("req's label");
2180 std::string label = "publish's label";
2181 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
2182 EXPECT_NE(normalContent, nullptr);
2183 normalContent->SetText("normalContent's text");
2184 normalContent->SetTitle("normalContent's title");
2185 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
2186 EXPECT_NE(content, nullptr);
2187 req->SetContent(content);
2188 req->SetCreatorUserId(DEFAULT_USER_ID);
2189 req->SetIsAgentNotification(true);
2190 advancedNotificationService_->Publish(label, req);
2191 SleepForFC();
2192
2193 GTEST_LOG_(INFO) << "CancelPreparedNotification_1000 test end";
2194 }
2195
2196
2197 /**
2198 * @tc.number : AdvancedNotificationServiceTest_16200
2199 * @tc.name : ANS_CancelAsBundle_0200
2200 * @tc.desc : Test CancelAsBundle function
2201 * @tc.require : #I60KYN
2202 */
2203 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16200, Function | SmallTest | Level1)
2204 {
2205 GTEST_LOG_(INFO) << "ANS_CancelAsBundle_0200 test start";
2206
2207 TestAddSlot(NotificationConstant::SlotType::OTHER);
2208 IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID);
2209 IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN);
2210 int32_t notificationId = 1;
2211 std::string representativeBundle = "RepresentativeBundle";
2212 int32_t userId = 1;
2213 int result = ERR_ANS_NON_SYSTEM_APP;
2214 EXPECT_EQ(advancedNotificationService_->CancelAsBundle(notificationId, representativeBundle, userId), result);
2215
2216 GTEST_LOG_(INFO) << "ANS_CancelAsBundle_0200 test end";
2217 }
2218
2219 /**
2220 * @tc.number : AdvancedNotificationServiceTest_16300
2221 * @tc.name : ANS_CancelAsBundle_0300
2222 * @tc.desc : Test CancelAsBundle function when uid is less than 0.
2223 * @tc.require : #I60KYN
2224 */
2225 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16300, Function | SmallTest | Level1)
2226 {
2227 GTEST_LOG_(INFO) << "ANS_CancelAsBundle_0300 test start";
2228
2229 TestAddSlot(NotificationConstant::SlotType::OTHER);
2230 int32_t notificationId = 1;
2231 std::string representativeBundle = "RepresentativeBundle";
2232 int32_t userId = 0;
2233 int result = ERR_ANS_INVALID_UID;
2234 EXPECT_EQ(advancedNotificationService_->CancelAsBundle(notificationId, representativeBundle, userId), result);
2235
2236 GTEST_LOG_(INFO) << "ANS_CancelAsBundle_0300 test end";
2237 }
2238
2239 /**
2240 * @tc.number : AdvancedNotificationServiceTest_16400
2241 * @tc.name : ANS_AddSlots_0100
2242 * @tc.desc : Test AddSlots function whith not system app
2243 * @tc.require : #I60KYN
2244 */
2245 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16400, Function | SmallTest | Level1)
2246 {
2247 GTEST_LOG_(INFO) << "ANS_AddSlots_0100 test start";
2248
2249 IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID);
2250 IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN);
2251 std::vector<sptr<NotificationSlot>> slots;
2252 sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
2253 slots.push_back(slot);
2254 EXPECT_EQ(advancedNotificationService_->AddSlots(slots), ERR_ANS_NON_SYSTEM_APP);
2255
2256 GTEST_LOG_(INFO) << "ANS_AddSlots_0100 test end";
2257 }
2258
2259 /**
2260 * @tc.number : AdvancedNotificationServiceTest_16600
2261 * @tc.name : ANS_AddSlots_0300
2262 * @tc.desc : Test AddSlots function with bundle option is null
2263 * @tc.require : #I60KYN
2264 */
2265 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16600, Function | SmallTest | Level1)
2266 {
2267 GTEST_LOG_(INFO) << "ANS_AddSlots_0300 test start";
2268 IPCSkeleton::SetCallingUid(NON_BUNDLE_NAME_UID);
2269
2270 std::vector<sptr<NotificationSlot>> slots;
2271 sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
2272 slots.push_back(slot);
2273 EXPECT_EQ(advancedNotificationService_->AddSlots(slots), ERR_ANS_INVALID_BUNDLE);
2274
2275 GTEST_LOG_(INFO) << "ANS_AddSlots_0300 test end";
2276 }
2277
2278 /**
2279 * @tc.number : AdvancedNotificationServiceTest_16700
2280 * @tc.name : ANS_AddSlots_0400
2281 * @tc.desc : Test AddSlots function with invalid bundle option
2282 * @tc.require : #I60KYN
2283 */
2284 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16700, Function | SmallTest | Level1)
2285 {
2286 GTEST_LOG_(INFO) << "ANS_AddSlots_0400 test start";
2287
2288 std::vector<sptr<NotificationSlot>> slots;
2289 EXPECT_EQ(advancedNotificationService_->AddSlots(slots), ERR_ANS_INVALID_PARAM);
2290
2291 GTEST_LOG_(INFO) << "ANS_AddSlots_0400 test end";
2292 }
2293
2294 /**
2295 * @tc.number : AdvancedNotificationServiceTest_16800
2296 * @tc.name : ANS_GetSlots_0100
2297 * @tc.desc : Test GetSlots function with bundle option is null
2298 * @tc.require : #I60KYN
2299 */
2300 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16800, Function | SmallTest | Level1)
2301 {
2302 GTEST_LOG_(INFO) << "ANS_GetSlots_0100 test start";
2303 IPCSkeleton::SetCallingUid(NON_BUNDLE_NAME_UID);
2304
2305 std::vector<sptr<NotificationSlot>> slots;
2306 sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
2307 slots.push_back(slot);
2308 EXPECT_EQ(advancedNotificationService_->GetSlots(slots), ERR_ANS_INVALID_BUNDLE);
2309
2310 GTEST_LOG_(INFO) << "ANS_GetSlots_0100 test end";
2311 }
2312
2313 /**
2314 * @tc.number : AdvancedNotificationServiceTest_16900
2315 * @tc.name : ANS_GetActiveNotifications_0100
2316 * @tc.desc : Test function with bundle option is null
2317 * @tc.require : #I60KYN
2318 */
2319 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16900, Function | SmallTest | Level1)
2320 {
2321 GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test start";
2322
2323 IPCSkeleton::SetCallingUid(NON_BUNDLE_NAME_UID);
2324 std::vector<sptr<NotificationRequest>> notifications;
2325 EXPECT_EQ(advancedNotificationService_->GetActiveNotifications(notifications), ERR_ANS_INVALID_BUNDLE);
2326 uint64_t num = 1;
2327 EXPECT_EQ(advancedNotificationService_->GetActiveNotificationNums(num), ERR_ANS_INVALID_BUNDLE);
2328 EXPECT_EQ(advancedNotificationService_->SetNotificationBadgeNum(num), ERR_ANS_INVALID_BUNDLE);
2329 int32_t importance = 2;
2330 EXPECT_EQ(advancedNotificationService_->GetBundleImportance(importance), ERR_ANS_INVALID_BUNDLE);
2331 bool allow = true;
2332 EXPECT_EQ(advancedNotificationService_->SetPrivateNotificationsAllowed(allow), ERR_ANS_INVALID_BUNDLE);
2333 EXPECT_EQ(advancedNotificationService_->GetPrivateNotificationsAllowed(allow), ERR_ANS_INVALID_BUNDLE);
2334 EXPECT_EQ(advancedNotificationService_->GetShowBadgeEnabled(allow), ERR_ANS_INVALID_BUNDLE);
2335
2336 sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::OTHER);
2337 EXPECT_EQ(advancedNotificationService_->GetSlotByType(NotificationConstant::OTHER, slot), ERR_ANS_INVALID_BUNDLE);
2338 EXPECT_EQ(advancedNotificationService_->RemoveSlotByType(NotificationConstant::OTHER), ERR_ANS_INVALID_BUNDLE);
2339
2340 std::string deviceId = "DeviceId";
2341 bool needPop = false;
2342 EXPECT_EQ(advancedNotificationService_->RequestEnableNotification(deviceId), ERR_ANS_INVALID_BUNDLE);
2343 EXPECT_EQ(advancedNotificationService_->IsAllowedNotifySelf(needPop), ERR_ANS_INVALID_BUNDLE);
2344 sptr<NotificationBundleOption> bundleOption;
2345 EXPECT_EQ(advancedNotificationService_->IsAllowedNotifySelf(bundleOption, needPop), ERR_ANS_INVALID_BUNDLE);
2346
2347 EXPECT_EQ(advancedNotificationService_->GetAppTargetBundle(bundleOption, bundleOption), ERR_ANS_INVALID_BUNDLE);
2348
2349 int32_t reminderId = 1;
2350 EXPECT_EQ(advancedNotificationService_->CancelReminder(reminderId), ERR_ANS_INVALID_BUNDLE);
2351
2352 EXPECT_EQ(advancedNotificationService_->CancelAllReminders(), ERR_ANS_INVALID_BUNDLE);
2353
2354 std::vector<sptr<ReminderRequest>> reminders;
2355 EXPECT_EQ(advancedNotificationService_->GetValidReminders(reminders), ERR_ANS_INVALID_BUNDLE);
2356
2357 EXPECT_EQ(advancedNotificationService_->RemoveAllSlots(), ERR_ANS_INVALID_BUNDLE);
2358
2359 EXPECT_EQ(advancedNotificationService_->AddSlotByType(NotificationConstant::SlotType::OTHER),
2360 ERR_ANS_INVALID_BUNDLE);
2361
2362 std::string groupName = "name";
2363 EXPECT_EQ(advancedNotificationService_->CancelGroup(groupName), ERR_ANS_INVALID_BUNDLE);
2364
2365 bool enabled = true;
2366 EXPECT_EQ(advancedNotificationService_->EnableDistributedSelf(enabled), ERR_ANS_INVALID_BUNDLE);
2367
2368 GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test end";
2369 }
2370
2371 /**
2372 * @tc.number : AdvancedNotificationServiceTest_17000
2373 * @tc.name : ANS_GetSetActiveNotifications_0100
2374 * @tc.desc : Test SetNotificationAgent and GetNotificationAgent function with bundle option is null
2375 * @tc.require : #I60KYN
2376 */
2377 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17000, Function | SmallTest | Level1)
2378 {
2379 GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test start";
2380
2381 std::string agent = "agent";
2382 EXPECT_EQ(advancedNotificationService_->SetNotificationAgent(agent), ERR_INVALID_OPERATION);
2383 EXPECT_EQ(advancedNotificationService_->GetNotificationAgent(agent), ERR_INVALID_OPERATION);
2384
2385 GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test end";
2386 }
2387
2388 /**
2389 * @tc.number : AdvancedNotificationServiceTest_17100
2390 * @tc.name : ANS_GetSetActiveNotifications_0100
2391 * @tc.desc : Test function with NON_SYSTEM_APP_UID
2392 * @tc.require : #I60KYN
2393 */
2394 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17100, Function | SmallTest | Level1)
2395 {
2396 GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test start";
2397
2398 IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID);
2399 std::string key = "key";
2400 int32_t removeReason = 0;
2401 sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
2402 EXPECT_EQ(advancedNotificationService_->Delete(key, removeReason), ERR_ANS_NON_SYSTEM_APP);
2403
2404 EXPECT_EQ(advancedNotificationService_->DeleteByBundle(bundleOption), ERR_ANS_NON_SYSTEM_APP);
2405
2406 EXPECT_EQ(advancedNotificationService_->DeleteAll(), ERR_ANS_NON_SYSTEM_APP);
2407
2408 bool enable = true;
2409 EXPECT_EQ(advancedNotificationService_->SetShowBadgeEnabledForBundle(bundleOption, enable), ERR_ANS_NON_SYSTEM_APP);
2410
2411 EXPECT_EQ(advancedNotificationService_->GetShowBadgeEnabledForBundle(bundleOption, enable), ERR_ANS_NON_SYSTEM_APP);
2412
2413 std::vector<sptr<Notification>> notifications;
2414 EXPECT_EQ(advancedNotificationService_->GetAllActiveNotifications(notifications), ERR_ANS_NON_SYSTEM_APP);
2415
2416 std::vector<std::string> keys;
2417 EXPECT_EQ(advancedNotificationService_->GetSpecialActiveNotifications(keys, notifications),
2418 ERR_ANS_NON_SYSTEM_APP);
2419
2420 EXPECT_EQ(advancedNotificationService_->SetNotificationsEnabledForAllBundles(key, enable),
2421 ERR_ANS_NON_SYSTEM_APP);
2422
2423 EXPECT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(
2424 std::string(), bundleOption, enable), ERR_ANS_NON_SYSTEM_APP);
2425
2426 EXPECT_EQ(advancedNotificationService_->IsAllowedNotify(enable), ERR_ANS_NON_SYSTEM_APP);
2427
2428 int32_t notificationId = 1;
2429 EXPECT_EQ(advancedNotificationService_->RemoveNotification(bundleOption, notificationId,
2430 key, removeReason), ERR_ANS_NON_SYSTEM_APP);
2431
2432 EXPECT_EQ(advancedNotificationService_->RemoveAllNotifications(bundleOption), ERR_ANS_NON_SYSTEM_APP);
2433
2434 uint64_t num = 1;
2435 EXPECT_EQ(advancedNotificationService_->GetSlotNumAsBundle(bundleOption, num), ERR_ANS_NON_SYSTEM_APP);
2436
2437 std::string groupName = "group";
2438 EXPECT_EQ(advancedNotificationService_->RemoveGroupByBundle(bundleOption, groupName), ERR_ANS_NON_SYSTEM_APP);
2439
2440 sptr<NotificationDoNotDisturbDate> date = nullptr;
2441 EXPECT_EQ(advancedNotificationService_->SetDoNotDisturbDate(date), ERR_ANS_NON_SYSTEM_APP);
2442 EXPECT_EQ(advancedNotificationService_->GetDoNotDisturbDate(date), ERR_ANS_NON_SYSTEM_APP);
2443
2444 EXPECT_EQ(advancedNotificationService_->DoesSupportDoNotDisturbMode(enable), ERR_ANS_NON_SYSTEM_APP);
2445
2446 EXPECT_EQ(advancedNotificationService_->EnableDistributed(enable), ERR_ANS_NON_SYSTEM_APP);
2447
2448 EXPECT_EQ(advancedNotificationService_->EnableDistributedByBundle(bundleOption, enable), ERR_ANS_NON_SYSTEM_APP);
2449
2450 EXPECT_EQ(advancedNotificationService_->IsDistributedEnableByBundle(bundleOption, enable), ERR_ANS_NON_SYSTEM_APP);
2451
2452 NotificationConstant::RemindType remindType = NotificationConstant::RemindType::DEVICE_ACTIVE_REMIND;
2453 EXPECT_EQ(advancedNotificationService_->GetDeviceRemindType(remindType),
2454 ERR_ANS_NON_SYSTEM_APP);
2455
2456 int32_t userId = 1;
2457 EXPECT_EQ(advancedNotificationService_->IsSpecialUserAllowedNotify(userId, enable),
2458 ERR_ANS_NON_SYSTEM_APP);
2459
2460 EXPECT_EQ(advancedNotificationService_->SetNotificationsEnabledByUser(userId, enable),
2461 ERR_ANS_NON_SYSTEM_APP);
2462
2463 EXPECT_EQ(advancedNotificationService_->DeleteAllByUser(userId), ERR_ANS_NON_SYSTEM_APP);
2464
2465 EXPECT_EQ(advancedNotificationService_->SetDoNotDisturbDate(userId, date), ERR_ANS_NON_SYSTEM_APP);
2466 EXPECT_EQ(advancedNotificationService_->GetDoNotDisturbDate(userId, date), ERR_ANS_NON_SYSTEM_APP);
2467
2468 EXPECT_EQ(advancedNotificationService_->SetEnabledForBundleSlot(bundleOption,
2469 NotificationConstant::SlotType::OTHER, enable), ERR_ANS_NON_SYSTEM_APP);
2470
2471 EXPECT_EQ(advancedNotificationService_->GetEnabledForBundleSlot(bundleOption,
2472 NotificationConstant::SlotType::OTHER, enable), ERR_ANS_NON_SYSTEM_APP);
2473
2474 EXPECT_EQ(advancedNotificationService_->SetSyncNotificationEnabledWithoutApp(userId, enable),
2475 ERR_ANS_NON_SYSTEM_APP);
2476
2477 EXPECT_EQ(advancedNotificationService_->GetSyncNotificationEnabledWithoutApp(userId, enable),
2478 ERR_ANS_NON_SYSTEM_APP);
2479
2480 GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test end";
2481 }
2482
2483 /**
2484 * @tc.number : AdvancedNotificationServiceTest_17200
2485 * @tc.name : ANS_DeleteAll_0100
2486 * @tc.desc : Test DeleteAll function
2487 * @tc.require : #I60KYN
2488 */
2489 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17200, Function | SmallTest | Level1)
2490 {
2491 GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test start";
2492
2493 TestAddSlot(NotificationConstant::SlotType::OTHER);
2494 sptr<NotificationRequest> req = new NotificationRequest(1);
2495 EXPECT_NE(req, nullptr);
2496 req->SetSlotType(NotificationConstant::SlotType::OTHER);
2497 req->SetLabel("req's label");
2498 std::string label = "publish's label";
2499 std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
2500 EXPECT_NE(normalContent, nullptr);
2501 normalContent->SetText("normalContent's text");
2502 normalContent->SetTitle("normalContent's title");
2503 std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
2504 EXPECT_NE(content, nullptr);
2505 req->SetContent(content);
2506 EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK);
2507 SleepForFC();
2508 req->SetCreatorUserId(SUBSCRIBE_USER_INIT);
2509 std::shared_ptr<Notification> notification = std::make_shared<Notification>(req);
2510 EXPECT_EQ(advancedNotificationService_->DeleteAll(), ERR_OK);
2511
2512 GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test end";
2513 }
2514
2515 /**
2516 * @tc.number : AdvancedNotificationServiceTest_17300
2517 * @tc.name : ANS_GetSlotsByBundle_0100
2518 * @tc.desc : Test GetSlotsByBundle function
2519 * @tc.require : #I60KYN
2520 */
2521 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17300, Function | SmallTest | Level1)
2522 {
2523 GTEST_LOG_(INFO) << "ANS_GetSlotsByBundle_0100 test start";
2524 IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID);
2525
2526 std::vector<sptr<NotificationSlot>> slots;
2527 EXPECT_EQ(advancedNotificationService_->GetSlotsByBundle(
2528 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID), slots),
2529 ERR_ANS_NON_SYSTEM_APP);
2530
2531 EXPECT_EQ(advancedNotificationService_->UpdateSlots(
2532 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID), slots),
2533 ERR_ANS_NON_SYSTEM_APP);
2534
2535 GTEST_LOG_(INFO) << "ANS_GetSlotsByBundle_0100 test end";
2536 }
2537
2538 /**
2539 * @tc.number : AdvancedNotificationServiceTest_17400
2540 * @tc.name : Subscribe_1000
2541 * @tc.desc : Test Subscribe function.
2542 * @tc.require : #I60KYN
2543 */
2544 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17400, Function | SmallTest | Level1)
2545 {
2546 GTEST_LOG_(INFO) << "Subscribe_1000 test start";
2547
2548 IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID);
2549 IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN);
2550
2551 auto subscriber = new TestAnsSubscriber();
2552 sptr<NotificationSubscribeInfo> info = new NotificationSubscribeInfo();
2553 EXPECT_EQ(advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), ERR_ANS_NON_SYSTEM_APP);
2554 EXPECT_EQ(advancedNotificationService_->Unsubscribe(subscriber->GetImpl(), info), ERR_ANS_NON_SYSTEM_APP);
2555
2556 GTEST_LOG_(INFO) << "Subscribe_1000 test end";
2557 }
2558
2559 /**
2560 * @tc.number : AdvancedNotificationServiceTest_17500
2561 * @tc.name : Unsubscribe_1000
2562 * @tc.desc : Test Subscribe function.
2563 * @tc.require : #I60KYN
2564 */
2565 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17500, Function | SmallTest | Level1)
2566 {
2567 GTEST_LOG_(INFO) << "Unsubscribe_1000 test start";
2568
2569 auto subscriber = new TestAnsSubscriber();
2570 sptr<NotificationSubscribeInfo> info = new NotificationSubscribeInfo();
2571 EXPECT_EQ(advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), ERR_OK);
2572 EXPECT_EQ(advancedNotificationService_->Unsubscribe(nullptr, info), ERR_ANS_INVALID_PARAM);
2573
2574 GTEST_LOG_(INFO) << "Unsubscribe_1000 test end";
2575 }
2576
2577 /**
2578 * @tc.number : AdvancedNotificationServiceTest_17600
2579 * @tc.name : GetAppTargetBundle_1000
2580 * @tc.desc : Test GetAppTargetBundle function.
2581 * @tc.require : #I60KYN
2582 */
2583 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17600, Function | SmallTest | Level1)
2584 {
2585 GTEST_LOG_(INFO) << "GetAppTargetBundle_1000 test start";
2586
2587 sptr<NotificationBundleOption> bundleOption = nullptr;
2588
2589 EXPECT_EQ(advancedNotificationService_->GetAppTargetBundle(bundleOption, bundleOption), ERR_OK);
2590
2591 GTEST_LOG_(INFO) << "GetAppTargetBundle_1000 test end";
2592 }
2593
2594 /**
2595 * @tc.number : AdvancedNotificationServiceTest_17700
2596 * @tc.name : GetAppTargetBundle_2000
2597 * @tc.desc : Test GetAppTargetBundle function.
2598 * @tc.require : #I60KYN
2599 */
2600 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17700, Function | SmallTest | Level1)
2601 {
2602 GTEST_LOG_(INFO) << "GetAppTargetBundle_2000 test start";
2603
2604 IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID);
2605 sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
2606 sptr<NotificationBundleOption> targetBundle = nullptr;
2607 bundleOption->SetBundleName("test");
2608 EXPECT_EQ(advancedNotificationService_->GetAppTargetBundle(bundleOption, targetBundle), ERR_ANS_NON_SYSTEM_APP);
2609
2610 GTEST_LOG_(INFO) << "GetAppTargetBundle_2000 test end";
2611 }
2612
2613 /**
2614 * @tc.number : AdvancedNotificationServiceTest_17800
2615 * @tc.name : GetAppTargetBundle_3000
2616 * @tc.desc : Test GetAppTargetBundle function.
2617 * @tc.require : #I60KYN
2618 */
2619 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17800, Function | SmallTest | Level1)
2620 {
2621 GTEST_LOG_(INFO) << "GetAppTargetBundle_3000 test start";
2622
2623 sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID);
2624 sptr<NotificationBundleOption> targetBundle = nullptr;
2625 bundleOption->SetBundleName("test");
2626 EXPECT_EQ(advancedNotificationService_->GetAppTargetBundle(bundleOption, targetBundle), ERR_OK);
2627
2628 GTEST_LOG_(INFO) << "GetAppTargetBundle_3000 test end";
2629 }
2630
2631 /**
2632 * @tc.number : AdvancedNotificationServiceTest_17900
2633 * @tc.name : PublishReminder_1000
2634 * @tc.desc : Test PublishReminder function.
2635 * @tc.require : #I61RF2
2636 */
2637 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17900, Function | SmallTest | Level1)
2638 {
2639 GTEST_LOG_(INFO) << "GetAppTargetBundle_1000 test start";
2640
2641 IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
2642 IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID);
2643 int32_t reminderId = 1;
2644 sptr<ReminderRequest> reminder = new ReminderRequest(reminderId);
2645 reminder->InitNotificationRequest();
2646 EXPECT_EQ(advancedNotificationService_->PublishReminder(reminder), ERR_REMINDER_NOTIFICATION_NOT_ENABLE);
2647
2648 GTEST_LOG_(INFO) << "GetAppTargetBundle_1000 test end";
2649 }
2650
2651 /**
2652 * @tc.number : AdvancedNotificationServiceTest_18000
2653 * @tc.name : PublishReminder_2000
2654 * @tc.desc : Test PublishReminder function.
2655 * @tc.require : #I61RF2
2656 */
2657 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18000, Function | SmallTest | Level1)
2658 {
2659 GTEST_LOG_(INFO) << "GetAppTargetBundle_2000 test start";
2660
2661 IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
2662 IPCSkeleton::SetCallingUid(NON_BUNDLE_NAME_UID);
2663 int32_t reminderId = 1;
2664 sptr<ReminderRequest> reminder = new ReminderRequest(reminderId);
2665 reminder->InitNotificationRequest();
2666 EXPECT_EQ(advancedNotificationService_->PublishReminder(reminder), ERR_ANS_INVALID_BUNDLE);
2667
2668 GTEST_LOG_(INFO) << "GetAppTargetBundle_2000 test end";
2669 }
2670
2671 /**
2672 * @tc.number : AdvancedNotificationServiceTest_18100
2673 * @tc.name : ActiveNotificationDump_1000
2674 * @tc.desc : Test ActiveNotificationDump function.
2675 * @tc.require : #I61RF2
2676 */
2677 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18100, Function | SmallTest | Level1)
2678 {
2679 GTEST_LOG_(INFO) << "ActiveNotificationDump_1000 test start";
2680
2681 std::string bundle = "Bundle";
2682 int32_t userId = -1;
2683 std::vector<std::string> dumpInfo;
2684
2685 EXPECT_EQ(advancedNotificationService_->ActiveNotificationDump(bundle, userId, dumpInfo), ERR_OK);
2686
2687 GTEST_LOG_(INFO) << "ActiveNotificationDump_1000 test end";
2688 }
2689
2690 /**
2691 * @tc.number : AdvancedNotificationServiceTest_18200
2692 * @tc.name : RecentNotificationDump_1000
2693 * @tc.desc : Test RecentNotificationDump function.
2694 * @tc.require : #I61RF2
2695 */
2696 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18200, Function | SmallTest | Level1)
2697 {
2698 GTEST_LOG_(INFO) << "RecentNotificationDump_1000 test start";
2699
2700 std::string bundle = "Bundle";
2701 int32_t userId = -1;
2702 std::vector<std::string> dumpInfo;
2703
2704 EXPECT_EQ(advancedNotificationService_->RecentNotificationDump(bundle, userId, dumpInfo), ERR_OK);
2705
2706 GTEST_LOG_(INFO) << "RecentNotificationDump_1000 test end";
2707 }
2708
2709 /**
2710 * @tc.number : AdvancedNotificationServiceTest_18300
2711 * @tc.name : DistributedNotificationDump_1000
2712 * @tc.desc : Test DistributedNotificationDump function.
2713 * @tc.require : #I61RF2
2714 */
2715 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18300, Function | SmallTest | Level1)
2716 {
2717 GTEST_LOG_(INFO) << "DistributedNotificationDump_1000 test start";
2718
2719 std::string bundle = "Bundle";
2720 int32_t userId = -1;
2721 std::vector<std::string> dumpInfo;
2722
2723 EXPECT_EQ(advancedNotificationService_->DistributedNotificationDump(bundle, userId, dumpInfo), ERR_OK);
2724
2725 GTEST_LOG_(INFO) << "DistributedNotificationDump_1000 test end";
2726 }
2727
2728 /**
2729 * @tc.number : AdvancedNotificationServiceTest_18400
2730 * @tc.name : SetRecentNotificationCount_1000
2731 * @tc.desc : Test SetRecentNotificationCount function.
2732 * @tc.require : #I61RF2
2733 */
2734 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18400, Function | SmallTest | Level1)
2735 {
2736 GTEST_LOG_(INFO) << "SetRecentNotificationCount_1000 test start";
2737
2738 std::string arg = "1100";
2739 EXPECT_EQ(advancedNotificationService_->SetRecentNotificationCount(arg), ERR_ANS_INVALID_PARAM);
2740
2741 GTEST_LOG_(INFO) << "SetRecentNotificationCount_1000 test end";
2742 }
2743
2744 /**
2745 * @tc.number : AdvancedNotificationServiceTest_18500
2746 * @tc.name : OnBundleRemoved_1000
2747 * @tc.desc : Test OnBundleRemoved function.
2748 * @tc.require : #I61RF2
2749 */
2750 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18500, Function | SmallTest | Level1)
2751 {
2752 GTEST_LOG_(INFO) << "OnBundleRemoved_1000 test start";
2753
2754 sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID);
2755 advancedNotificationService_->OnBundleRemoved(bundleOption);
2756
2757 GTEST_LOG_(INFO) << "OnBundleRemoved_1000 test end";
2758 }
2759
2760 /**
2761 * @tc.number : AdvancedNotificationServiceTest_18600
2762 * @tc.name : OnScreenOn_1000
2763 * @tc.desc : Test OnScreenOn function.
2764 * @tc.require : #I61RF2
2765 */
2766 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18600, Function | SmallTest | Level1)
2767 {
2768 GTEST_LOG_(INFO) << "OnScreenOn_1000 test start";
2769
2770 advancedNotificationService_->OnScreenOn();
2771 advancedNotificationService_->OnScreenOff();
2772
2773 GTEST_LOG_(INFO) << "OnScreenOn_1000 test end";
2774 }
2775
2776 /**
2777 * @tc.number : AdvancedNotificationServiceTest_18700
2778 * @tc.name : AddSlotByType_1000
2779 * @tc.desc : Test AddSlotByType function.
2780 * @tc.require : #I61RF2
2781 */
2782 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18700, Function | SmallTest | Level1)
2783 {
2784 GTEST_LOG_(INFO) << "AddSlotByType_1000 test start";
2785
2786 EXPECT_EQ(advancedNotificationService_->AddSlotByType(NotificationConstant::SlotType::SERVICE_REMINDER),
2787 ERR_OK);
2788
2789 GTEST_LOG_(INFO) << "AddSlotByType_1000 test end";
2790 }
2791
2792 /**
2793 * @tc.number : AdvancedNotificationServiceTest_18800
2794 * @tc.name : GetSlotNumAsBundle_1000
2795 * @tc.desc : Test GetSlotNumAsBundle function.
2796 * @tc.require : #I61RF2
2797 */
2798 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18800, Function | SmallTest | Level1)
2799 {
2800 GTEST_LOG_(INFO) << "GetSlotNumAsBundle_1000 test start";
2801
2802 sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID);
2803 uint64_t num = 1;
2804 EXPECT_EQ(advancedNotificationService_->GetSlotNumAsBundle(bundleOption, num), ERR_OK);
2805
2806 GTEST_LOG_(INFO) << "GetSlotNumAsBundle_1000 test end";
2807 }
2808
2809 /**
2810 * @tc.number : AdvancedNotificationServiceTest_18900
2811 * @tc.name : CancelGroup_1000
2812 * @tc.desc : Test CancelGroup function.
2813 * @tc.require : #I61RF2
2814 */
2815 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18900, Function | SmallTest | Level1)
2816 {
2817 GTEST_LOG_(INFO) << "CancelGroup_1000 test start";
2818
2819 std::string groupName = "";
2820 EXPECT_EQ(advancedNotificationService_->CancelGroup(groupName), ERR_ANS_INVALID_PARAM);
2821
2822 GTEST_LOG_(INFO) << "CancelGroup_1000 test end";
2823 }
2824
2825 /**
2826 * @tc.number : AdvancedNotificationServiceTest_19000
2827 * @tc.name : RemoveGroupByBundle_1000
2828 * @tc.desc : Test RemoveGroupByBundle function.
2829 * @tc.require : #I61RF2
2830 */
2831 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19000, Function | SmallTest | Level1)
2832 {
2833 GTEST_LOG_(INFO) << "RemoveGroupByBundle_1000 test start";
2834
2835 std::string groupName = "group";
2836 sptr<NotificationBundleOption> bundleOption = nullptr;
2837 EXPECT_EQ(advancedNotificationService_->RemoveGroupByBundle(bundleOption, groupName), ERR_ANS_INVALID_PARAM);
2838
2839 GTEST_LOG_(INFO) << "RemoveGroupByBundle_1000 test end";
2840 }
2841
2842 /**
2843 * @tc.number : AdvancedNotificationServiceTest_19100
2844 * @tc.name : ANS_IsDistributedEnabled_0100
2845 * @tc.desc : Test IsDistributedEnabled function
2846 * @tc.require : #I61RF2
2847 */
2848 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19100, Function | SmallTest | Level1)
2849 {
2850 GTEST_LOG_(INFO) << "ANS_IsDistributedEnabled_0100 test start";
2851
2852 bool enabled = false;
2853 EXPECT_EQ(advancedNotificationService_->IsDistributedEnabled(enabled), ERR_OK);
2854
2855 GTEST_LOG_(INFO) << "ANS_IsDistributedEnabled_0100 test end";
2856 }
2857
2858 /**
2859 * @tc.number : AdvancedNotificationServiceTest_19200
2860 * @tc.name : EnableDistributedByBundle_0100
2861 * @tc.desc : Test EnableDistributedByBundle function
2862 * @tc.require : #I61RF2
2863 */
2864 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19200, Function | SmallTest | Level1)
2865 {
2866 GTEST_LOG_(INFO) << "EnableDistributedByBundle_0100 test start";
2867
2868 sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID);
2869 bool enabled = false;
2870 EXPECT_EQ(advancedNotificationService_->EnableDistributedByBundle(bundleOption, enabled), ERR_OK);
2871
2872 GTEST_LOG_(INFO) << "EnableDistributedByBundle_0100 test end";
2873 }
2874
2875 /**
2876 * @tc.number : AdvancedNotificationServiceTest_19300
2877 * @tc.name : IsDistributedEnableByBundle_0100
2878 * @tc.desc : Test IsDistributedEnableByBundle function
2879 * @tc.require : #I61RF2
2880 */
2881 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19300, Function | SmallTest | Level1)
2882 {
2883 GTEST_LOG_(INFO) << "IsDistributedEnableByBundle_0100 test start";
2884
2885 sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID);
2886 bool enabled = true;
2887 EXPECT_EQ(advancedNotificationService_->IsDistributedEnableByBundle(bundleOption, enabled), ERR_OK);
2888
2889 GTEST_LOG_(INFO) << "IsDistributedEnableByBundle_0100 test end";
2890 }
2891
2892 /**
2893 * @tc.number : AdvancedNotificationServiceTest_19400
2894 * @tc.name : IsDistributedEnableByBundle_0200
2895 * @tc.desc : Test IsDistributedEnableByBundle function
2896 * @tc.require : #I61RF2
2897 */
2898 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19400, Function | SmallTest | Level1)
2899 {
2900 GTEST_LOG_(INFO) << "IsDistributedEnableByBundle_0200 test start";
2901
2902 sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID);
2903 bool enabled = false;
2904 EXPECT_EQ(advancedNotificationService_->IsDistributedEnableByBundle(bundleOption, enabled), ERR_OK);
2905
2906 GTEST_LOG_(INFO) << "IsDistributedEnableByBundle_0200 test end";
2907 }
2908
2909 /**
2910 * @tc.number : AdvancedNotificationServiceTest_19500
2911 * @tc.name : GetDeviceRemindType_0100
2912 * @tc.desc : Test GetDeviceRemindType function
2913 * @tc.require : #I61RF2
2914 */
2915 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19500, Function | SmallTest | Level1)
2916 {
2917 GTEST_LOG_(INFO) << "GetDeviceRemindType_0100 test start";
2918
2919 NotificationConstant::RemindType remindType = NotificationConstant::RemindType::DEVICE_ACTIVE_REMIND;
2920 EXPECT_EQ(advancedNotificationService_->GetDeviceRemindType(remindType), ERR_OK);
2921
2922 GTEST_LOG_(INFO) << "GetDeviceRemindType_0100 test end";
2923 }
2924
2925 /**
2926 * @tc.number : AdvancedNotificationServiceTest_19600
2927 * @tc.name : GetLocalNotificationKeys_0100
2928 * @tc.desc : Test GetLocalNotificationKeys function
2929 * @tc.require : #I61RF2
2930 */
2931 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19600, Function | SmallTest | Level1)
2932 {
2933 GTEST_LOG_(INFO) << "GetLocalNotificationKeys_0100 test start";
2934
2935 sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID);
2936 advancedNotificationService_->GetLocalNotificationKeys(bundleOption);
2937
2938 GTEST_LOG_(INFO) << "GetLocalNotificationKeys_0100 test end";
2939 }
2940
2941 /**
2942 * @tc.number : AdvancedNotificationServiceTest_19700
2943 * @tc.name : CheckDistributedNotificationType_0100
2944 * @tc.desc : Test CheckDistributedNotificationType function
2945 * @tc.require : #I61RF2
2946 */
2947 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19700, Function | SmallTest | Level1)
2948 {
2949 GTEST_LOG_(INFO) << "CheckDistributedNotificationType_0100 test start";
2950
2951 sptr<NotificationRequest> req = new NotificationRequest();
2952 EXPECT_EQ(advancedNotificationService_->CheckDistributedNotificationType(req), true);
2953
2954 GTEST_LOG_(INFO) << "CheckDistributedNotificationType_0100 test end";
2955 }
2956
2957 /**
2958 * @tc.number : AdvancedNotificationServiceTest_19800
2959 * @tc.name : CheckDistributedNotificationType_0200
2960 * @tc.desc : Test CheckDistributedNotificationType function
2961 * @tc.require : #I61RF2
2962 */
2963 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19800, Function | SmallTest | Level1)
2964 {
2965 GTEST_LOG_(INFO) << "CheckDistributedNotificationType_0200 test start";
2966
2967 sptr<NotificationRequest> req = new NotificationRequest();
2968 std::vector<std::string> devices;
2969 devices.push_back("a");
2970 devices.push_back("b");
2971 devices.push_back("c");
2972 req->GetNotificationDistributedOptions().SetDevicesSupportDisplay(devices);
2973 EXPECT_EQ(advancedNotificationService_->CheckDistributedNotificationType(req), true);
2974
2975 GTEST_LOG_(INFO) << "CheckDistributedNotificationType_0200 test end";
2976 }
2977
2978 /**
2979 * @tc.number : AdvancedNotificationServiceTest_19900
2980 * @tc.name : OnDistributedPublish_0100
2981 * @tc.desc : Test OnDistributedPublish function
2982 * @tc.require : #I61RF2
2983 */
2984 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19900, Function | SmallTest | Level1)
2985 {
2986 GTEST_LOG_(INFO) << "CheckDistributedNotificationType_0100 test start";
2987
2988 std::string deviceId = "DeviceId";
2989 std::string bundleName = "BundleName";
2990 sptr<NotificationRequest> request = new NotificationRequest();
2991
2992 advancedNotificationService_->OnDistributedPublish(deviceId, bundleName, request);
2993
2994 GTEST_LOG_(INFO) << "CheckDistributedNotificationType_0100 test end";
2995 }
2996
2997 /**
2998 * @tc.number : AdvancedNotificationServiceTest_20000
2999 * @tc.name : OnDistributedUpdate_0100
3000 * @tc.desc : Test OnDistributedUpdate function
3001 * @tc.require : #I61RF2
3002 */
3003 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20000, Function | SmallTest | Level1)
3004 {
3005 GTEST_LOG_(INFO) << "OnDistributedUpdate_0100 test start";
3006
3007 std::string deviceId = "DeviceId";
3008 std::string bundleName = "BundleName";
3009 sptr<NotificationRequest> request = new NotificationRequest();
3010
3011 advancedNotificationService_->OnDistributedUpdate(deviceId, bundleName, request);
3012
3013 GTEST_LOG_(INFO) << "OnDistributedUpdate_0100 test end";
3014 }
3015
3016 /**
3017 * @tc.number : AdvancedNotificationServiceTest_20100
3018 * @tc.name : OnDistributedDelete_0100
3019 * @tc.desc : Test OnDistributedDelete function
3020 * @tc.require : #I61RF2
3021 */
3022 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20100, Function | SmallTest | Level1)
3023 {
3024 GTEST_LOG_(INFO) << "OnDistributedDelete_0100 test start";
3025
3026 std::string deviceId = "DeviceId";
3027 std::string bundleName = "BundleName";
3028 std::string label = "testLabel";
3029 int32_t id = 1;
3030
3031 advancedNotificationService_->OnDistributedDelete(deviceId, bundleName, label, id);
3032
3033 GTEST_LOG_(INFO) << "OnDistributedDelete_0100 test end";
3034 }
3035
3036 /**
3037 * @tc.number : AdvancedNotificationServiceTest_20200
3038 * @tc.name : CheckPublishWithoutApp_0100
3039 * @tc.desc : Test CheckPublishWithoutApp function
3040 * @tc.require : #I61RF2
3041 */
3042 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20200, Function | SmallTest | Level1)
3043 {
3044 GTEST_LOG_(INFO) << "CheckPublishWithoutApp_0100 test start";
3045
3046 int32_t userId = 1;
3047 sptr<NotificationRequest> request = new NotificationRequest();
3048 EXPECT_EQ(advancedNotificationService_->CheckPublishWithoutApp(userId, request), false);
3049
3050 GTEST_LOG_(INFO) << "CheckPublishWithoutApp_0100 test end";
3051 }
3052
3053 /**
3054 * @tc.number : AdvancedNotificationServiceTest_20300
3055 * @tc.name : CheckPublishWithoutApp_0200
3056 * @tc.desc : Test CheckPublishWithoutApp function
3057 * @tc.require : #I61RF2
3058 */
3059 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20300, Function | SmallTest | Level1)
3060 {
3061 GTEST_LOG_(INFO) << "CheckPublishWithoutApp_0200 test start";
3062
3063 int32_t userId = SYSTEM_APP_UID;
3064 sptr<NotificationRequest> request = new NotificationRequest();
3065 EXPECT_EQ(advancedNotificationService_->CheckPublishWithoutApp(userId, request), false);
3066
3067 GTEST_LOG_(INFO) << "CheckPublishWithoutApp_0200 test end";
3068 }
3069
3070 /**
3071 * @tc.number : AdvancedNotificationServiceTest_20400
3072 * @tc.name : TriggerRemoveWantAgent_0100
3073 * @tc.desc : Test TriggerRemoveWantAgent function
3074 * @tc.require : #I61RF2
3075 */
3076 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20400, Function | SmallTest | Level1)
3077 {
3078 GTEST_LOG_(INFO) << "TriggerRemoveWantAgent_0100 test start";
3079
3080 sptr<NotificationRequest> request = new NotificationRequest();
3081 AbilityRuntime::WantAgent::WantAgentInfo paramsInfo;
3082 std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent =
3083 AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(paramsInfo);
3084
3085 request->SetRemovalWantAgent(wantAgent);
3086 advancedNotificationService_->TriggerRemoveWantAgent(request);
3087
3088 GTEST_LOG_(INFO) << "TriggerRemoveWantAgent_0100 test end";
3089 }
3090
3091 /**
3092 * @tc.number : AdvancedNotificationServiceTest_20500
3093 * @tc.name : DeleteAllByUser_0100
3094 * @tc.desc : Test DeleteAllByUser function
3095 * @tc.require : #I61RF2
3096 */
3097 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20500, Function | SmallTest | Level1)
3098 {
3099 GTEST_LOG_(INFO) << "DeleteAllByUser_0100 test start";
3100
3101 int32_t userId = -2;
3102 EXPECT_EQ(advancedNotificationService_->DeleteAllByUser(userId), ERR_ANS_INVALID_PARAM);
3103
3104 sptr<NotificationDoNotDisturbDate> date = nullptr;
3105 EXPECT_EQ(advancedNotificationService_->SetDoNotDisturbDate(userId, date), ERR_ANS_INVALID_PARAM);
3106 EXPECT_EQ(advancedNotificationService_->GetDoNotDisturbDate(userId, date), ERR_ANS_INVALID_PARAM);
3107 EXPECT_EQ(advancedNotificationService_->SetDoNotDisturbDateByUser(userId, date), ERR_ANS_INVALID_PARAM);
3108 GTEST_LOG_(INFO) << "DeleteAllByUser_0100 test end";
3109 }
3110
3111 /**
3112 * @tc.number : AdvancedNotificationServiceTest_20600
3113 * @tc.name : OnResourceRemove_0100
3114 * @tc.desc : Test OnResourceRemove function
3115 * @tc.require : #I61RF2
3116 */
3117 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20600, Function | SmallTest | Level1)
3118 {
3119 GTEST_LOG_(INFO) << "OnResourceRemove_0100 test start";
3120
3121 int32_t userId = -2;
3122 advancedNotificationService_->OnResourceRemove(userId);
3123
3124 GTEST_LOG_(INFO) << "OnResourceRemove_0100 test end";
3125 }
3126
3127 /**
3128 * @tc.number : AdvancedNotificationServiceTest_20700
3129 * @tc.name : OnBundleDataCleared_0100
3130 * @tc.desc : Test OnBundleDataCleared function
3131 * @tc.require : #I61RF2
3132 */
3133 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20700, Function | SmallTest | Level1)
3134 {
3135 GTEST_LOG_(INFO) << "OnBundleDataCleared_0100 test start";
3136
3137 sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID);
3138 advancedNotificationService_->OnBundleDataCleared(bundleOption);
3139
3140 GTEST_LOG_(INFO) << "OnBundleDataCleared_0100 test end";
3141 }
3142
3143 /**
3144 * @tc.number : AdvancedNotificationServiceTest_20800
3145 * @tc.name : GetDisplayPosition_0100
3146 * @tc.desc : Test GetDisplayPosition function
3147 * @tc.require : #I61RF2
3148 */
3149 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20800, Function | SmallTest | Level1)
3150 {
3151 GTEST_LOG_(INFO) << "GetDisplayPosition_0100 test start";
3152
3153 int offsetX = 1;
3154 int offsetY = 1;
3155 int width = 1;
3156 int height = 1;
3157 bool wideScreen = 1;
3158 advancedNotificationService_->GetDisplayPosition(offsetX, offsetY, width, height, wideScreen);
3159
3160 GTEST_LOG_(INFO) << "GetDisplayPosition_0100 test end";
3161 }
3162
3163 /**
3164 * @tc.number : AdvancedNotificationServiceTest_20900
3165 * @tc.name : GetDumpInfo_0100
3166 * @tc.desc : Test GetDumpInfo function
3167 * @tc.require : #I61RF2
3168 */
3169 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20900, Function | SmallTest | Level1)
3170 {
3171 GTEST_LOG_(INFO) << "GetDumpInfo_0100 test start";
3172
3173 std::vector<std::u16string> args;
3174 args.push_back(Str8ToStr16("args"));
3175 std::string result = "result";
3176 advancedNotificationService_->GetDumpInfo(args, result);
3177
3178 GTEST_LOG_(INFO) << "GetDumpInfo_0100 test end";
3179 }
3180
3181 /**
3182 * @tc.number : AdvancedNotificationServiceTest_21000
3183 * @tc.name : GetDumpInfo_0200
3184 * @tc.desc : Test GetDumpInfo function
3185 * @tc.require : #I61RF2
3186 */
3187 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_21000, Function | SmallTest | Level1)
3188 {
3189 GTEST_LOG_(INFO) << "GetDumpInfo_0200 test start";
3190
3191 std::vector<std::u16string> args;
3192 args.push_back(Str8ToStr16("-h"));
3193 std::string result = "result";
3194 advancedNotificationService_->GetDumpInfo(args, result);
3195
3196 GTEST_LOG_(INFO) << "GetDumpInfo_0200 test end";
3197 }
3198
3199 /**
3200 * @tc.number : AdvancedNotificationServiceTest_21100
3201 * @tc.name : SendFlowControlOccurHiSysEvent_0100
3202 * @tc.desc : Test SendFlowControlOccurHiSysEvent function
3203 * @tc.require : #I61RF2
3204 */
3205 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_21100, Function | SmallTest | Level1)
3206 {
3207 GTEST_LOG_(INFO) << "SendFlowControlOccurHiSysEvent_0100 test start";
3208
3209 std::shared_ptr<NotificationRecord> record = nullptr;
3210 advancedNotificationService_->SendFlowControlOccurHiSysEvent(record);
3211
3212 GTEST_LOG_(INFO) << "SendFlowControlOccurHiSysEvent_0100 test end";
3213 }
3214
3215 /**
3216 * @tc.number : AdvancedNotificationServiceTest_21200
3217 * @tc.name : SendFlowControlOccurHiSysEvent_0200
3218 * @tc.desc : Test SendFlowControlOccurHiSysEvent function
3219 * @tc.require : #I61RF2
3220 */
3221 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_21200, Function | SmallTest | Level1)
3222 {
3223 GTEST_LOG_(INFO) << "SendFlowControlOccurHiSysEvent_0200 test start";
3224
3225 std::shared_ptr<NotificationRecord> record = std::make_shared<NotificationRecord>();
3226 record->request = new NotificationRequest();
3227 record->bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID);
3228 advancedNotificationService_->SendFlowControlOccurHiSysEvent(record);
3229
3230 GTEST_LOG_(INFO) << "SendFlowControlOccurHiSysEvent_0200 test end";
3231 }
3232
3233 /**
3234 * @tc.number : AdvancedNotificationServiceTest_21300
3235 * @tc.name : PrepareNotificationRequest_0200
3236 * @tc.desc : Test PrepareNotificationRequest function when uid < 0.
3237 * @tc.require : issueI62D8C
3238 */
3239 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_21300, Function | SmallTest | Level1)
3240 {
3241 GTEST_LOG_(INFO) << "PrepareNotificationRequest_0200 test start";
3242 IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID);
3243 IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN);
3244
3245 sptr<NotificationRequest> req = new NotificationRequest();
3246 int32_t myNotificationId = 10;
3247 bool isAgentTrue = true;
3248 NotificationRequest notificationRequest(myNotificationId);
3249 notificationRequest.SetIsAgentNotification(isAgentTrue);
3250
3251 std::shared_ptr<BundleManagerHelper> bundleManager = nullptr;
3252
3253 EXPECT_EQ(advancedNotificationService_->PrepareNotificationRequest(req), ERR_OK);
3254 GTEST_LOG_(INFO) << "PrepareNotificationRequest_0200 test end";
3255 }
3256
3257 /**
3258 * @tc.number : AdvancedNotificationServiceTest_21400
3259 * @tc.name : PrepareNotificationInfo_2000
3260 * @tc.desc : Test PrepareNotificationInfo function.
3261 * @tc.require : issueI62D8C
3262 */
3263 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_21400, Function | SmallTest | Level1)
3264 {
3265 GTEST_LOG_(INFO) << "PrepareNotificationInfo_2000 test start";
3266
3267 sptr<NotificationRequest> req = new (std::nothrow) NotificationRequest(1);
3268 EXPECT_NE(req, nullptr);
3269 sptr<NotificationBundleOption> bundleOption = nullptr;
3270
3271 EXPECT_EQ(advancedNotificationService_->PrepareNotificationInfo(req, bundleOption), ERR_OK);
3272
3273 GTEST_LOG_(INFO) << "PrepareNotificationInfo_2000 test end";
3274 }
3275
3276 /**
3277 * @tc.number : AdvancedNotificationServiceTest_21500
3278 * @tc.name : PublishPreparedNotification_1000
3279 * @tc.desc : Test PublishPreparedNotification function.
3280 * @tc.require : issueI62D8C
3281 */
3282 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_21500, Function | SmallTest | Level1)
3283 {
3284 GTEST_LOG_(INFO) << "PublishPreparedNotification_1000 test start";
3285
3286 sptr<NotificationRequest> req = new (std::nothrow) NotificationRequest();
3287 sptr<Notification> notification = new (std::nothrow) Notification(req);
3288 EXPECT_NE(notification, nullptr);
3289 sptr<NotificationBundleOption> bundleOption = nullptr;
3290
3291 EXPECT_EQ(advancedNotificationService_->PublishPreparedNotification(req, bundleOption), ERR_ANS_INVALID_PARAM);
3292
3293 GTEST_LOG_(INFO) << "PublishPreparedNotification_1000 test end";
3294 }
3295
3296 /**
3297 * @tc.number : AdvancedNotificationServiceTest_220000
3298 * @tc.name : TimeToString_1000
3299 * @tc.desc : Test TimeToString function.
3300 * @tc.require : #I61RF2
3301 */
3302 HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_220000, Function | SmallTest | Level1)
3303 {
3304 int64_t time = 60;
3305 std::string ret = "1970-01-01, ";
3306 std::string result = advancedNotificationService_->TimeToString(time);
3307 EXPECT_EQ(result.substr(0, result.size() - 8), ret);
3308 }
3309 } // namespace Notification
3310 } // namespace OHOS