• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 
18 #define private public
19 #define protected public
20 #include "notification.h"
21 #undef private
22 #undef protected
23 
24 #include "notification_request.h"
25 #include "parcel.h"
26 
27 using namespace testing::ext;
28 namespace OHOS {
29 namespace Notification {
30 class NotificationTest : public testing::Test {
31 public:
SetUpTestCase()32     static void SetUpTestCase() {}
TearDownTestCase()33     static void TearDownTestCase() {}
SetUp()34     void SetUp() {}
TearDown()35     void TearDown() {}
36 };
37 
38 /**
39  * @tc.name: GetBundleName_00001
40  * @tc.desc: Test when request_ is nullptr get parameters.
41  * @tc.type: FUNC
42  * @tc.require: issueI5WBBH
43  */
44 HWTEST_F(NotificationTest, GetBundleName_00001, Function | SmallTest | Level1)
45 {
46     sptr<NotificationRequest> request = nullptr;
47     auto rrc = std::make_shared<Notification>(request);
48     std::string ret = "";
49     EXPECT_EQ(rrc->GetBundleName(), ret);
50     EXPECT_EQ(rrc->GetCreateBundle(), ret);
51     EXPECT_EQ(rrc->GetLabel(), ret);
52     EXPECT_EQ(rrc->GetId(), -1);
53     EXPECT_EQ(rrc->GetUid(), 0);
54     EXPECT_EQ(rrc->GetPid(), 0);
55     EXPECT_EQ(rrc->IsUnremovable(), false);
56     EXPECT_EQ(rrc->IsGroup(), false);
57     EXPECT_EQ(rrc->IsFloatingIcon(), false);
58     EXPECT_EQ(rrc->GetUserId(), 0);
59 }
60 
61 /**
62  * @tc.name: GetLedLightColor_00001
63  * @tc.desc: Test GetLedLightColor parameters.
64  * @tc.type: FUNC
65  * @tc.require: issueI5WBBH
66  */
67 HWTEST_F(NotificationTest, GetLedLightColor_00001, Function | SmallTest | Level1)
68 {
69     int32_t color = 10;
70     std::string deviceId = "DeviceId";
71     sptr<NotificationRequest> request = nullptr;
72     auto rrc = std::make_shared<Notification>(deviceId, request);
73     rrc->SetLedLightColor(color);
74     EXPECT_EQ(rrc->GetLedLightColor(), color);
75 }
76 
77 /**
78  * @tc.name: GetLockscreenVisibleness_00001
79  * @tc.desc: Test GetLockscreenVisibleness parameters.
80  * @tc.type: FUNC
81  * @tc.require: issueI5WBBH
82  */
83 HWTEST_F(NotificationTest, GetLockscreenVisibleness_00001, Function | SmallTest | Level1)
84 {
85     NotificationConstant::VisiblenessType visbleness = NotificationConstant::VisiblenessType::PUBLIC;
86     sptr<NotificationRequest> request = nullptr;
87     auto rrc = std::make_shared<Notification>(request);
88     rrc->SetLockScreenVisbleness(visbleness);
89     EXPECT_EQ(rrc->GetLockscreenVisibleness(), visbleness);
90 }
91 
92 /**
93  * @tc.name: GetGroup_00001
94  * @tc.desc: Test GetGroup parameters.
95  * @tc.type: FUNC
96  * @tc.require: issue
97  */
98 HWTEST_F(NotificationTest, GetGroup_00001, Function | SmallTest | Level1)
99 {
100     sptr<NotificationRequest> request = nullptr;
101     auto rrc = std::make_shared<Notification>(request);
102     std::string ret = "";
103     EXPECT_EQ(rrc->GetGroup(), ret);
104 }
105 
106 /**
107  * @tc.name: GetGroup_00002
108  * @tc.desc: Test when request_ is not nullptr get parameters.
109  * @tc.type: FUNC
110  * @tc.require: issue
111  */
112 HWTEST_F(NotificationTest, GetGroup_00002, Function | SmallTest | Level1)
113 {
114     sptr<NotificationRequest> request = new NotificationRequest(1);
115     auto rrc = std::make_shared<Notification>(request);
116     std::string ret = "";
117     EXPECT_EQ(rrc->GetGroup(), ret);
118     EXPECT_EQ(rrc->GetPid(), 0);
119     EXPECT_EQ(rrc->IsUnremovable(), false);
120     EXPECT_EQ(rrc->IsGroup(), false);
121     EXPECT_EQ(rrc->IsFloatingIcon(), false);
122 }
123 
124 /**
125  * @tc.name: GetPostTime_00001
126  * @tc.desc: Test GetPostTime parameters.
127  * @tc.type: FUNC
128  * @tc.require: issue
129  */
130 HWTEST_F(NotificationTest, GetPostTime_00001, Function | SmallTest | Level1)
131 {
132     int64_t time = 10;
133     sptr<NotificationRequest> request = nullptr;
134     auto rrc = std::make_shared<Notification>(request);
135     rrc->SetPostTime(time);
136     EXPECT_EQ(rrc->GetPostTime(), time);
137 }
138 
139 /**
140  * @tc.name: GetSound_00001
141  * @tc.desc: Test GetSound parameters.
142  * @tc.type: FUNC
143  * @tc.require: issue
144  */
145 HWTEST_F(NotificationTest, GetSound_00001, Function | SmallTest | Level1)
146 {
147     Uri sound = Uri("sound");
148     bool enable = true;
149     sptr<NotificationRequest> request = nullptr;
150     auto rrc = std::make_shared<Notification>(request);
151     rrc->SetSound(sound);
152     rrc->SetEnableSound(enable);
153     EXPECT_EQ(rrc->GetSound(), sound);
154 }
155 
156 /**
157  * @tc.name: GetVibrationStyle_00001
158  * @tc.desc: Test GetVibrationStyle parameters.
159  * @tc.type: FUNC
160  * @tc.require: issue
161  */
162 HWTEST_F(NotificationTest, GetVibrationStyle_00001, Function | SmallTest | Level1)
163 {
164     std::vector<int64_t> style;
165     sptr<NotificationRequest> request = nullptr;
166     auto rrc = std::make_shared<Notification>(request);
167     rrc->SetVibrationStyle(style);
168     EXPECT_EQ(rrc->GetVibrationStyle(), style);
169 }
170 
171 /**
172  * @tc.name: GetRemindType_00001
173  * @tc.desc: Test GetRemindType parameters.
174  * @tc.type: FUNC
175  * @tc.require: issue
176  */
177 HWTEST_F(NotificationTest, GetRemindType_00001, Function | SmallTest | Level1)
178 {
179     NotificationConstant::RemindType reminType = NotificationConstant::RemindType::NONE;
180     sptr<NotificationRequest> request = nullptr;
181     auto rrc = std::make_shared<Notification>(request);
182     rrc->SetRemindType(reminType);
183     EXPECT_EQ(rrc->GetRemindType(), reminType);
184 }
185 
186 /**
187  * @tc.name: GenerateNotificationKey_00001
188  * @tc.desc: Test GenerateNotificationKey parameters.
189  * @tc.type: FUNC
190  * @tc.require: issue
191  */
192 HWTEST_F(NotificationTest, GenerateNotificationKey_00001, Function | SmallTest | Level1)
193 {
194     int32_t userId = 10;
195     int32_t uid = 20;
196     std::string label = "Lable";
197     int32_t id = 30;
198     sptr<NotificationRequest> request = sptr<NotificationRequest>::MakeSptr();
199     request->SetCreatorUid(uid);
200     request->SetCreatorUserId(userId);
201     request->SetLabel(label);
202     request->SetNotificationId(id);
203     request->SetCreatorBundleName("come.test");
204     auto rrc = std::make_shared<Notification>(request);
205     std::string result = "_10_20_come.test_Lable_30";
206     EXPECT_EQ(rrc->GetKey(), result);
207 }
208 
209 /**
210  * @tc.name: GenerateNotificationKey_00002
211  * @tc.desc: Test GenerateNotificationKey parameters.
212  * @tc.type: FUNC
213  * @tc.require: issue
214  */
215 HWTEST_F(NotificationTest, GenerateNotificationKey_00002, Function | SmallTest | Level1)
216 {
217     std::string deviceId = "DeviceId";
218     int32_t userId = 10;
219     int32_t uid = 20;
220     std::string label = "Lable";
221     int32_t id = 30;
222     sptr<NotificationRequest> request = sptr<NotificationRequest>::MakeSptr();
223     request->SetIsAgentNotification(true);
224     request->SetOwnerUid(uid);
225     request->SetOwnerUserId(userId);
226     request->SetLabel(label);
227     request->SetNotificationId(id);
228     request->SetCreatorBundleName("come.push");
229     request->SetOwnerBundleName("come.test");
230     auto rrc = std::make_shared<Notification>(deviceId, request);
231     std::string result = "DeviceId_10_20_come.test_Lable_30";
232     EXPECT_EQ(rrc->GetKey(), result);
233 }
234 
235 /**
236  * @tc.name: IsRemoveAllowed_00001
237  * @tc.desc: Test IsRemoveAllowed parameters.
238  * @tc.type: FUNC
239  * @tc.require: issue
240  */
241 HWTEST_F(NotificationTest, IsRemoveAllowed_00001, Function | SmallTest | Level1)
242 {
243     bool removeAllowed = true;
244     sptr<NotificationRequest> request = nullptr;
245     auto rrc = std::make_shared<Notification>(request);
246     rrc->SetRemoveAllowed(removeAllowed);
247     EXPECT_EQ(rrc->IsRemoveAllowed(), removeAllowed);
248 }
249 
250 /**
251  * @tc.name: GetSourceType_00001
252  * @tc.desc: Test GetSourceType parameters.
253  * @tc.type: FUNC
254  * @tc.require: issue
255  */
256 HWTEST_F(NotificationTest, GetSourceType_00001, Function | SmallTest | Level1)
257 {
258     NotificationConstant::SourceType sourceType = NotificationConstant::SourceType::TYPE_NORMAL;
259     sptr<NotificationRequest> request = nullptr;
260     auto rrc = std::make_shared<Notification>(request);
261     rrc->SetSourceType(sourceType);
262     EXPECT_EQ(rrc->GetSourceType(), sourceType);
263 }
264 
265 /**
266  * @tc.name: GetDeviceId_00001
267  * @tc.desc: Test GetDeviceId parameters.
268  * @tc.type: FUNC
269  * @tc.require: issue
270  */
271 HWTEST_F(NotificationTest, GetDeviceId_00001, Function | SmallTest | Level1)
272 {
273     std::string deviceId = "DeviceId";
274     sptr<NotificationRequest> request = new NotificationRequest();
275     auto rrc = std::make_shared<Notification>(deviceId, request);
276     EXPECT_EQ(rrc->GetDeviceId(), deviceId);
277 }
278 
279 /**
280  * @tc.name: Dump_00001
281  * @tc.desc: Test Dump parameters.
282  * @tc.type: FUNC
283  * @tc.require: issue
284  */
285 HWTEST_F(NotificationTest, Dump_00001, Function | SmallTest | Level1)
286 {
287     std::string deviceId = "DeviceId";
288     sptr<NotificationRequest> request = new NotificationRequest();
289     auto rrc = std::make_shared<Notification>(deviceId, request);
290     std::string ret = "Notification{ key = DeviceId_-1_0___0, ledLightColor = 0, "
291     "lockscreenVisbleness = 0, remindType = -1, isRemoveAllowed = true, sourceType = 0, "
292     "deviceId = DeviceId, request = NotificationRequest{ notificationId = 0, "
293     "slotType = 3, createTime = 0, deliveryTime = 0, autoDeletedTime = -1, settingsText = , "
294     "creatorBundleName = , creatorPid = 0, creatorUid = 0, ownerBundleName = , "
295     "ownerUid = 0, groupName = , statusBarText = , label = , shortcutId = , "
296     "sortingKey = , groupAlertType = 0, color = 0, badgeNumber = 0, visiblenessType = 0, "
297     "progressValue = 0, progressMax = 0, badgeStyle = 0, classification = , "
298     "notificationContentType = 0, showDeliveryTime = false, tapDismissed = true, "
299     "colorEnabled = false, alertOneTime = false, showStopwatch = false, isCountdown = false, "
300     "inProgress = false, groupOverview = false, isRemoveAllowed = true, progressIndeterminate = false, "
301     "unremovable = false, floatingIcon = false, onlyLocal = false, permitted = true, "
302     "isAgent = false, removalWantAgent = null, maxScreenWantAgent = null, additionalParams = null, "
303     "littleIcon = null, bigIcon = null, overlayIcon = null, notificationContent = null, "
304     "notificationTemplate = null, actionButtons = empty, messageUsers = empty, "
305     "userInputHistory = empty, distributedOptions = NotificationDistributedOptions"
306     "{ isDistributed = true, devicesSupportDisplay = [], devicesSupportOperate = [] }, "
307     "notificationFlags = null, creatorUserId = -1, ownerUserId = -1, receiverUserId = -1, "
308     "updateDeadLine = 0, finishDeadLine = 0 }, postTime = 0, sound = nullptr, vibrationStyle = [], "
309     "updateTimer = 0, finishTimer = 0, archiveTimer = 0 }";
310     EXPECT_EQ(rrc->Dump(), ret);
311 }
312 
313 /**
314  * @tc.name: MarshallingBool_00001
315  * @tc.desc: Test MarshallingBool parameters.
316  * @tc.type: FUNC
317  * @tc.require: issue
318  */
319 HWTEST_F(NotificationTest, MarshallingBool_00001, Function | SmallTest | Level1)
320 {
321     Parcel parcel;
322     std::string deviceId = "DeviceId";
323     sptr<NotificationRequest> request = new NotificationRequest();
324     auto rrc = std::make_shared<Notification>(deviceId, request);
325     EXPECT_EQ(rrc->MarshallingBool(parcel), true);
326 }
327 
328 /**
329  * @tc.name: Marshalling_00001
330  * @tc.desc: Test Marshalling parameters.
331  * @tc.type: FUNC
332  * @tc.require: issueI5WBBHI
333  */
334 HWTEST_F(NotificationTest, Marshalling_00001, Function | SmallTest | Level1)
335 {
336     Parcel parcel;
337     std::string deviceId = "DeviceId";
338     sptr<NotificationRequest> request = new NotificationRequest();
339     auto rrc = std::make_shared<Notification>(deviceId, request);
340     EXPECT_EQ(rrc->Marshalling(parcel), true);
341 }
342 
343 /**
344  * @tc.name: Unmarshalling_00001
345  * @tc.desc: Test Unmarshalling parameters.
346  * @tc.type: FUNC
347  * @tc.require: issueI5WBBH
348  */
349 HWTEST_F(NotificationTest, Unmarshalling_001, Function | SmallTest | Level1)
350 {
351     bool unmarshalling = true;
352     Parcel parcel;
353     std::string deviceId = "DeviceId";
354     sptr<NotificationRequest> request = new NotificationRequest();
355     std::shared_ptr<Notification> result =
356     std::make_shared<Notification>(deviceId, request);
357 
358     if (nullptr != result) {
359         if (nullptr == result->Unmarshalling(parcel)) {
360             unmarshalling = false;
361         }
362     }
363     EXPECT_EQ(unmarshalling, true);
364 }
365 
366 /**
367  * @tc.name: ReadFromParcel_00001
368  * @tc.desc: Test ReadFromParcel parameters.
369  * @tc.type: FUNC
370  * @tc.require: issueI5WBBH
371  */
372 HWTEST_F(NotificationTest, ReadFromParcel_00001, Function | SmallTest | Level1)
373 {
374     Parcel parcel;
375     std::string deviceId = "DeviceId";
376     sptr<NotificationRequest> request = new NotificationRequest();
377     auto rrc = std::make_shared<Notification>(deviceId, request);
378     EXPECT_EQ(rrc->ReadFromParcel(parcel), true);
379 }
380 
381 /**
382  * @tc.name: GetSound_00002
383  * @tc.desc: Test GetSound parameters.
384  * @tc.type: FUNC
385  * @tc.require: issue
386  */
387 HWTEST_F(NotificationTest, GetSound_00002, Function | SmallTest | Level1)
388 {
389     Uri sound = Uri("sound");
390     bool enable = false;
391     sptr<NotificationRequest> request = nullptr;
392     auto rrc = std::make_shared<Notification>(request);
393     rrc->SetSound(sound);
394     rrc->SetEnableSound(enable);
395     EXPECT_EQ(rrc->GetSound(), Uri(""));
396 }
397 
398 /**
399  * @tc.name: GetSound_00003
400  * @tc.desc: Test GetSound parameters.
401  * @tc.type: FUNC
402  * @tc.require: issue
403  */
404 HWTEST_F(NotificationTest, GetSound_00003, Function | SmallTest | Level1)
405 {
406     Uri sound = Uri("");
407     bool enable = true;
408     sptr<NotificationRequest> request = nullptr;
409     auto rrc = std::make_shared<Notification>(request);
410     rrc->SetSound(sound);
411     rrc->SetEnableSound(enable);
412     EXPECT_EQ(rrc->GetSound(), Uri(""));
413 }
414 
415 /**
416  * @tc.name: EnableLight_00001
417  * @tc.desc: Test EnableLight parameters.
418  * @tc.type: FUNC
419  * @tc.require: issue
420  */
421 HWTEST_F(NotificationTest, EnableLight_00001, Function | SmallTest | Level1)
422 {
423     bool enable = true;
424     sptr<NotificationRequest> request = nullptr;
425     auto rrc = std::make_shared<Notification>(request);
426     rrc->SetEnableLight(enable);
427     EXPECT_EQ(rrc->EnableLight(), enable);
428 }
429 
430 /**
431  * @tc.name: EnableSound_00001
432  * @tc.desc: Test EnableSound parameters.
433  * @tc.type: FUNC
434  * @tc.require: issue
435  */
436 HWTEST_F(NotificationTest, EnableSound_00001, Function | SmallTest | Level1)
437 {
438     bool enable = true;
439     sptr<NotificationRequest> request = nullptr;
440     auto rrc = std::make_shared<Notification>(request);
441     rrc->SetEnableSound(enable);
442     EXPECT_EQ(rrc->EnableSound(), enable);
443     Parcel parcel;
444     rrc->ReadFromParcelString(parcel);
445 }
446 
447 /**
448  * @tc.name: EnableVibrate_00001
449  * @tc.desc: Test EnableVibrate parameters.
450  * @tc.type: FUNC
451  * @tc.require: issue
452  */
453 HWTEST_F(NotificationTest, EnableVibrate_00001, Function | SmallTest | Level1)
454 {
455     bool enable = true;
456     sptr<NotificationRequest> request = nullptr;
457     auto rrc = std::make_shared<Notification>(request);
458     rrc->SetEnableVibration(enable);
459     EXPECT_EQ(rrc->EnableVibrate(), enable);
460 }
461 
462 /**
463  * @tc.name: GetBundleName_00002
464  * @tc.desc: Test when request_ is nullptr get parameters.
465  * @tc.type: FUNC
466  * @tc.require: issueI5WBBH
467  */
468 HWTEST_F(NotificationTest, GetBundleName_00002, Function | SmallTest | Level1)
469 {
470     sptr<NotificationRequest> request = new NotificationRequest(1);
471     auto rrc = std::make_shared<Notification>(request);
472     std::string ret = "";
473     EXPECT_EQ(rrc->GetBundleName(), ret);
474     EXPECT_EQ(rrc->GetCreateBundle(), ret);
475 }
476 
477 /**
478  * @tc.name: GetSound_00004
479  * @tc.desc: Test GetSound parameters.
480  * @tc.type: FUNC
481  * @tc.require: issue
482  */
483 HWTEST_F(NotificationTest, GetSound_00004, Function | SmallTest | Level1)
484 {
485     Uri sound = Uri("sound");
486     bool enable = false;
487     sptr<NotificationRequest> request = new NotificationRequest(1);
488     auto rrc = std::make_shared<Notification>(request);
489     rrc->SetSound(sound);
490     rrc->SetEnableSound(enable);
491     EXPECT_EQ(rrc->GetSound(), Uri(""));
492 }
493 
494 /**
495  * @tc.name: GetSound_00005
496  * @tc.desc: Test GetSound parameters.
497  * @tc.type: FUNC
498  * @tc.require: issue
499  */
500 HWTEST_F(NotificationTest, GetSound_00005, Function | SmallTest | Level1)
501 {
502     Uri sound = Uri("sound");
503     bool enable = true;
504     sptr<NotificationRequest> request = new NotificationRequest(1);
505     auto rrc = std::make_shared<Notification>(request);
506     rrc->SetSound(sound);
507     rrc->SetEnableSound(enable);
508     EXPECT_EQ(rrc->GetSound(), Uri("sound"));
509 }
510 
511 /**
512  * @tc.name: Marshalling_00002
513  * @tc.desc: Test Marshalling parameters.
514  * @tc.type: FUNC
515  * @tc.require: issueI5WBBHI
516  */
517 HWTEST_F(NotificationTest, Marshalling_00002, Function | SmallTest | Level1)
518 {
519     Parcel parcel;
520     std::string deviceId = "DeviceId";
521     sptr<NotificationRequest> request = new NotificationRequest();
522     auto rrc = std::make_shared<Notification>(deviceId, request);
523 
524     bool enable = true;
525     auto sound = std::make_shared<Uri>("sound");
526     rrc->SetSound(*sound);
527     rrc->SetEnableSound(enable);
528 
529     EXPECT_EQ(rrc->Marshalling(parcel), true);
530 }
531 
532 /**
533  * @tc.name: Marshalling_00003
534  * @tc.desc: Test Marshalling parameters.
535  * @tc.type: FUNC
536  * @tc.require: issueI5WBBHI
537  */
538 HWTEST_F(NotificationTest, Marshalling_00003, Function | SmallTest | Level1)
539 {
540     Parcel parcel;
541     std::string deviceId = "DeviceId";
542     sptr<NotificationRequest> request = new NotificationRequest();
543     auto rrc = std::make_shared<Notification>(deviceId, request);
544 
545     bool enable = false;
546     auto sound = std::make_shared<Uri>("sound");
547     rrc->SetSound(*sound);
548     rrc->SetEnableSound(enable);
549 
550     EXPECT_EQ(rrc->Marshalling(parcel), true);
551 }
552 
553 /**
554  * @tc.name: GetUpdateTimer_00001
555  * @tc.desc: Test get update timer.
556  * @tc.type: FUNC
557  * @tc.require: issue
558  */
559 HWTEST_F(NotificationTest, GetUpdateTimer_00001, Function | SmallTest | Level1)
560 {
561     sptr<NotificationRequest> request = new NotificationRequest(1);
562     auto rrc = std::make_shared<Notification>(request);
563     rrc->SetUpdateTimer(1);
564     EXPECT_EQ(rrc->GetUpdateTimer(), 1);
565 }
566 
567 /**
568  * @tc.name: GetFinishTimer_00001
569  * @tc.desc: Test get finish timer.
570  * @tc.type: FUNC
571  * @tc.require: issue
572  */
573 HWTEST_F(NotificationTest, GetFinishTimer_00001, Function | SmallTest | Level1)
574 {
575     sptr<NotificationRequest> request = new NotificationRequest(1);
576     auto rrc = std::make_shared<Notification>(request);
577     rrc->SetFinishTimer(1);
578     EXPECT_EQ(rrc->GetFinishTimer(), 1);
579 }
580 } // namespace Notification
581 } // namespace OHOS
582