1 /*
2  * Copyright (c) 2021-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 #include <utility>
18 
19 #define private public
20 #define protected public
21 #include "ans_inner_errors.h"
22 #include "notification_conversational_content.h"
23 #include "notification_live_view_content.h"
24 #include "notification_multiline_content.h"
25 #include "notification_request.h"
26 #include "pixel_map.h"
27 #undef private
28 #undef protected
29 #include "want_agent_helper.h"
30 
31 using namespace testing::ext;
32 namespace OHOS {
33 namespace Notification {
34 class NotificationRequestTest : public testing::Test {
35 public:
SetUpTestCase()36     static void SetUpTestCase() {};
TearDownTestCase()37     static void TearDownTestCase() {};
SetUp()38     void SetUp() {};
TearDown()39     void TearDown() {};
40 };
41 
42 /**
43  * @tc.name: NotificationGetWantAgent_0100
44  * @tc.desc: GetWantAgent
45  * @tc.type: FUNC
46  * @tc.require: issueI5RW70
47  */
HWTEST_F(NotificationRequestTest,NotificationGetWantAgent_0100,Level1)48 HWTEST_F(NotificationRequestTest, NotificationGetWantAgent_0100, Level1)
49 {
50     int32_t myNotificationId = 10;
51     NotificationRequest notificationRequest(myNotificationId);
52     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent = notificationRequest.GetWantAgent();
53     EXPECT_EQ(wantAgent, nullptr);
54 }
55 
56 /**
57  * @tc.name: NotificationSetMaxScreenWantAgent_0100
58  * @tc.desc: SetMaxScreenWantAgent
59  * @tc.type: FUNC
60  * @tc.require: issueI5RW70
61  */
HWTEST_F(NotificationRequestTest,NotificationSetMaxScreenWantAgent_0100,Level1)62 HWTEST_F(NotificationRequestTest, NotificationSetMaxScreenWantAgent_0100, Level1)
63 {
64     int32_t myNotificationId = 10;
65     NotificationRequest notificationRequest(myNotificationId);
66     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent = notificationRequest.GetWantAgent();
67     notificationRequest.SetMaxScreenWantAgent(wantAgent);
68     auto result = notificationRequest.GetMaxScreenWantAgent();
69     EXPECT_EQ(result, nullptr);
70 }
71 
72 /**
73  * @tc.name: NotificationGetAdditionalData_0100
74  * @tc.desc: GetAdditionalData
75  * @tc.type: FUNC
76  * @tc.require: issueI5RW70
77  */
HWTEST_F(NotificationRequestTest,NotificationGetAdditionalData_0100,Level1)78 HWTEST_F(NotificationRequestTest, NotificationGetAdditionalData_0100, Level1)
79 {
80     int32_t myNotificationId = 10;
81     std::shared_ptr<AAFwk::WantParams> additionalPtr;
82     NotificationRequest notificationRequest(myNotificationId);
83     notificationRequest.SetAdditionalData(additionalPtr);
84     auto result = notificationRequest.GetAdditionalData();
85     EXPECT_EQ(result, nullptr);
86 }
87 
88 /**
89  * @tc.name: NotificationSetIsAgentNotification_0100
90  * @tc.desc: SetIsAgentNotification
91  * @tc.type: FUNC
92  * @tc.require: issueI5RW70
93  */
HWTEST_F(NotificationRequestTest,NotificationSetIsAgentNotification_0100,Level1)94 HWTEST_F(NotificationRequestTest, NotificationSetIsAgentNotification_0100, Level1)
95 {
96     int32_t myNotificationId = 10;
97     bool isAgentTrue = true;
98     NotificationRequest notificationRequest(myNotificationId);
99     notificationRequest.SetIsAgentNotification(isAgentTrue);
100     auto result = notificationRequest.IsAgentNotification();
101     EXPECT_EQ(result, true);
102     bool isAgentFalse = false;
103     notificationRequest.SetIsAgentNotification(isAgentFalse);
104     result = notificationRequest.IsAgentNotification();
105     EXPECT_EQ(result, false);
106 }
107 
108 /**
109  * @tc.name: NotificationOwnerUid_0100
110  * @tc.desc: SetOwnerUid and GetOwnerUid
111  * @tc.type: FUNC
112  * @tc.require: issueI5RW70
113  */
HWTEST_F(NotificationRequestTest,NotificationOwnerUid_0100,Level1)114 HWTEST_F(NotificationRequestTest, NotificationOwnerUid_0100, Level1)
115 {
116     int32_t myNotificationId = 10;
117     int32_t uid = 5;
118     NotificationRequest notificationRequest(myNotificationId);
119     notificationRequest.SetOwnerUid(uid);
120     auto result = notificationRequest.GetOwnerUid();
121     EXPECT_EQ(result, uid);
122 }
123 
124 /**
125  * @tc.name: NotificationOwnerUserId_0100
126  * @tc.desc: SetOwnerUserId and GetOwnerUserId
127  * @tc.type: FUNC
128  * @tc.require: issueI5RW70
129  */
HWTEST_F(NotificationRequestTest,NotificationOwnerUserId_0100,Level1)130 HWTEST_F(NotificationRequestTest, NotificationOwnerUserId_0100, Level1)
131 {
132     int32_t myNotificationId = 10;
133     int32_t userid = 5;
134     NotificationRequest notificationRequest(myNotificationId);
135     notificationRequest.SetOwnerUserId(userid);
136     auto result = notificationRequest.GetOwnerUserId();
137     EXPECT_EQ(result, userid);
138 }
139 
140 /**
141  * @tc.name: NotificationMarshalling_0100
142  * @tc.desc: Marshalling
143  * @tc.type: FUNC
144  * @tc.require: issueI5RW70
145  */
HWTEST_F(NotificationRequestTest,NotificationMarshalling_0100,Level1)146 HWTEST_F(NotificationRequestTest, NotificationMarshalling_0100, Level1)
147 {
148     int32_t myNotificationId = 10;
149     Parcel parcel;
150     NotificationRequest notificationRequest(myNotificationId);
151     auto result = notificationRequest.Marshalling(parcel);
152     EXPECT_EQ(result, true);
153 }
154 
155 /**
156  * @tc.name: NotificationReadFromParcel_0100
157  * @tc.desc: ReadFromParcel
158  * @tc.type: FUNC
159  * @tc.require: issueI5RW70
160  */
HWTEST_F(NotificationRequestTest,NotificationReadFromParcel_0100,Level1)161 HWTEST_F(NotificationRequestTest, NotificationReadFromParcel_0100, Level1)
162 {
163     int32_t myNotificationId = 10;
164     Parcel parcel;
165     NotificationRequest notificationRequest(myNotificationId);
166     auto result = notificationRequest.ReadFromParcel(parcel);
167     EXPECT_EQ(result, false);
168 }
169 
170 /**
171  * @tc.name: NotificationSetReceiverUserId_0100
172  * @tc.desc: SetReceiverUserId
173  * @tc.type: FUNC
174  * @tc.require: issueI5RW70
175  */
HWTEST_F(NotificationRequestTest,NotificationSetReceiverUserId_0100,Level1)176 HWTEST_F(NotificationRequestTest, NotificationSetReceiverUserId_0100, Level1)
177 {
178     int32_t myNotificationId = 10;
179     int32_t userid = 5;
180     NotificationRequest notificationRequest(myNotificationId);
181     notificationRequest.SetReceiverUserId(userid);
182     auto result = notificationRequest.GetReceiverUserId();
183     EXPECT_EQ(result, userid);
184 }
185 
186 /**
187  * @tc.name: NotificationSetReceiverUserId_0200
188  * @tc.desc: GetReceiverUserId return creator userId
189  * @tc.type: FUNC
190  * @tc.require: issueI5RW70
191  */
HWTEST_F(NotificationRequestTest,NotificationSetReceiverUserId_0200,Level1)192 HWTEST_F(NotificationRequestTest, NotificationSetReceiverUserId_0200, Level1)
193 {
194     int32_t myNotificationId = 10;
195     int32_t ownerUserId = 5;
196     NotificationRequest notificationRequest(myNotificationId);
197     notificationRequest.SetOwnerUserId(ownerUserId);
198     auto result = notificationRequest.GetReceiverUserId();
199     EXPECT_EQ(result, ownerUserId);
200 }
201 
202 /**
203  * @tc.name: AddActionButton_0100
204  * @tc.desc: AddActionButton
205  * @tc.type: FUNC
206  * @tc.require: issueI65R21
207  */
HWTEST_F(NotificationRequestTest,AddActionButton_0100,Level1)208 HWTEST_F(NotificationRequestTest, AddActionButton_0100, Level1)
209 {
210     int32_t myNotificationId = 10;
211     NotificationRequest notificationRequest(myNotificationId);
212 
213     std::shared_ptr<NotificationActionButton> actionButton = nullptr;
214     notificationRequest.AddActionButton(actionButton);
215     AbilityRuntime::WantAgent::WantAgentInfo paramsInfo;
216     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent =
217         AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(paramsInfo);
218     std::shared_ptr<NotificationActionButton> actionButton1 =
219         NotificationActionButton::Create(nullptr, "title", wantAgent);
220     notificationRequest.AddActionButton(actionButton1);
221     std::shared_ptr<NotificationActionButton> actionButton2 =
222         NotificationActionButton::Create(nullptr, "title2", wantAgent);
223     notificationRequest.AddActionButton(actionButton2);
224     std::shared_ptr<NotificationActionButton> actionButton3 =
225         NotificationActionButton::Create(nullptr, "title3", wantAgent);
226     notificationRequest.AddActionButton(actionButton3);
227     std::vector<std::shared_ptr<NotificationActionButton>> result =
228         notificationRequest.GetActionButtons();
229     std::shared_ptr<NotificationActionButton> actionButton4 =
230         NotificationActionButton::Create(nullptr, "title4", wantAgent);
231     notificationRequest.AddActionButton(actionButton4);
232     notificationRequest.ClearActionButtons();
233     EXPECT_EQ(result.size(), 3);
234 }
235 
236 /**
237  * @tc.name: AddMessageUser_0100
238  * @tc.desc: AddMessageUser
239  * @tc.type: FUNC
240  * @tc.require: issueI65R21
241  */
HWTEST_F(NotificationRequestTest,AddMessageUser_0100,Level1)242 HWTEST_F(NotificationRequestTest, AddMessageUser_0100, Level1)
243 {
244     int32_t myNotificationId = 10;
245     NotificationRequest notificationRequest(myNotificationId);
246 
247     std::shared_ptr<MessageUser> messageUser = nullptr;
248     notificationRequest.AddMessageUser(messageUser);
249     std::vector<std::shared_ptr<MessageUser>> result = notificationRequest.GetMessageUsers();
250     EXPECT_EQ(result.size(), 0);
251 }
252 
253 /**
254  * @tc.name: SetColor_0100
255  * @tc.desc: SetColor
256  * @tc.type: FUNC
257  * @tc.require: issueI65R21
258  */
HWTEST_F(NotificationRequestTest,SetColor_0100,Level1)259 HWTEST_F(NotificationRequestTest, SetColor_0100, Level1)
260 {
261     int32_t myNotificationId = 10;
262     NotificationRequest notificationRequest(myNotificationId);
263 
264     uint32_t color = 1;
265     notificationRequest.SetColor(color);
266     uint32_t result = notificationRequest.GetColor();
267     uint32_t ret = 4278190081;
268     EXPECT_EQ(result, ret);
269 }
270 
271 /**
272  * @tc.name: IsColorEnabled_0100
273  * @tc.desc: IsColorEnabled
274  * @tc.type: FUNC
275  * @tc.require: issueI65R21
276  */
HWTEST_F(NotificationRequestTest,IsColorEnabled_0100,Level1)277 HWTEST_F(NotificationRequestTest, IsColorEnabled_0100, Level1)
278 {
279     int32_t myNotificationId = 10;
280     NotificationRequest notificationRequest(myNotificationId);
281 
282     notificationRequest.SetColorEnabled(true);
283     notificationRequest.SetContent(nullptr);
284     notificationRequest.GetContent();
285     uint32_t result1 = notificationRequest.IsColorEnabled();
286     EXPECT_EQ(result1, false);
287 }
288 
289 /**
290  * @tc.name: IsColorEnabled_0200
291  * @tc.desc: IsColorEnabled
292  * @tc.type: FUNC
293  * @tc.require: issueI65R21
294  */
HWTEST_F(NotificationRequestTest,IsColorEnabled_0200,Level1)295 HWTEST_F(NotificationRequestTest, IsColorEnabled_0200, Level1)
296 {
297     int32_t myNotificationId = 10;
298     NotificationRequest notificationRequest(myNotificationId);
299 
300     notificationRequest.SetColorEnabled(true);
301     std::shared_ptr<NotificationMediaContent> mediaContent = std::make_shared<NotificationMediaContent>();
302     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(mediaContent);
303     notificationRequest.SetContent(content);
304     std::shared_ptr<NotificationContent> result = notificationRequest.GetContent();
305     EXPECT_EQ(result, content);
306     uint32_t result1 = notificationRequest.IsColorEnabled();
307     EXPECT_EQ(result1, false);
308 }
309 
310 /**
311  * @tc.name: IsColorEnabled_0300
312  * @tc.desc: IsColorEnabled
313  * @tc.type: FUNC
314  * @tc.require: issueI65R21
315  */
HWTEST_F(NotificationRequestTest,IsColorEnabled_0300,Level1)316 HWTEST_F(NotificationRequestTest, IsColorEnabled_0300, Level1)
317 {
318     int32_t myNotificationId = 10;
319     NotificationRequest notificationRequest(myNotificationId);
320 
321     notificationRequest.SetColorEnabled(true);
322     std::shared_ptr<NotificationPictureContent> pictureContent = std::make_shared<NotificationPictureContent>();
323     std::shared_ptr<NotificationContent> content1 = std::make_shared<NotificationContent>(pictureContent);
324     notificationRequest.SetContent(content1);
325     std::shared_ptr<NotificationContent> result = notificationRequest.GetContent();
326     EXPECT_EQ(result, content1);
327     uint32_t result1 = notificationRequest.IsColorEnabled();
328     EXPECT_EQ(result1, false);
329 }
330 
331 /**
332  * @tc.name: SetSettingsText_0100
333  * @tc.desc: SetSettingsText
334  * @tc.type: FUNC
335  * @tc.require: issueI65R21
336  */
HWTEST_F(NotificationRequestTest,SetSettingsText_0100,Level1)337 HWTEST_F(NotificationRequestTest, SetSettingsText_0100, Level1)
338 {
339     int32_t myNotificationId = 10;
340     NotificationRequest notificationRequest(myNotificationId);
341 
342     std::shared_ptr<NotificationPictureContent> pictureContent = std::make_shared<NotificationPictureContent>();
343     std::shared_ptr<NotificationContent> content1 = std::make_shared<NotificationContent>(pictureContent);
344     notificationRequest.SetContent(content1);
345     std::shared_ptr<NotificationContent> result = notificationRequest.GetContent();
346     EXPECT_EQ(result, content1);
347     std::string text = "text";
348     notificationRequest.SetSettingsText(text);
349 
350     std::shared_ptr<NotificationLongTextContent> longTextContent =
351         std::make_shared<NotificationLongTextContent>("longtext");
352     std::shared_ptr<NotificationContent> content2 = std::make_shared<NotificationContent>(longTextContent);
353     notificationRequest.SetContent(content2);
354     std::shared_ptr<NotificationContent> result2 = notificationRequest.GetContent();
355     EXPECT_EQ(result2, content2);
356     notificationRequest.SetSettingsText(text);
357 }
358 
359 /**
360  * @tc.name: SetNotificationUserInputHistory_0100
361  * @tc.desc: SetNotificationUserInputHistory
362  * @tc.type: FUNC
363  * @tc.require: issueI65R21
364  */
HWTEST_F(NotificationRequestTest,SetNotificationUserInputHistory_0100,Level1)365 HWTEST_F(NotificationRequestTest, SetNotificationUserInputHistory_0100, Level1)
366 {
367     int32_t myNotificationId = 10;
368     NotificationRequest notificationRequest(myNotificationId);
369 
370     std::vector<std::string> text;
371     notificationRequest.SetNotificationUserInputHistory(text);
372     std::vector<std::string> result = notificationRequest.GetNotificationUserInputHistory();
373     EXPECT_EQ(result.size(), 0);
374 }
375 
376 /**
377  * @tc.name: GetNotificationHashCode_0100
378  * @tc.desc: GetNotificationHashCode
379  * @tc.type: FUNC
380  * @tc.require: issueI65R21
381  */
HWTEST_F(NotificationRequestTest,GetNotificationHashCode_0100,Level1)382 HWTEST_F(NotificationRequestTest, GetNotificationHashCode_0100, Level1)
383 {
384     int32_t myNotificationId = 10;
385     NotificationRequest notificationRequest(myNotificationId);
386 
387     std::string ownerName = "";
388     notificationRequest.SetOwnerBundleName(ownerName);
389     std::string result1 = notificationRequest.GetNotificationHashCode();
390     EXPECT_EQ(result1, ownerName);
391 
392     std::string creatorName = "";
393     notificationRequest.SetCreatorBundleName(creatorName);
394     std::string result2 = notificationRequest.GetNotificationHashCode();
395     EXPECT_EQ(result2, creatorName);
396 
397     int32_t uid = 0;
398     notificationRequest.SetCreatorUid(uid);
399     std::string result3 = notificationRequest.GetNotificationHashCode();
400     EXPECT_EQ(result3, creatorName);
401 
402     notificationRequest.SetOwnerBundleName("ownerName");
403     notificationRequest.SetCreatorBundleName("creatorName");
404     notificationRequest.SetCreatorUid(2);
405     std::string result4 = notificationRequest.GetNotificationHashCode();
406     std::string ret = "10_creatorName_2_ownerName";
407     EXPECT_EQ(result4, ret);
408 }
409 
410 /**
411  * @tc.name: GetNotificationHashCode_0200
412  * @tc.desc: GetNotificationHashCode
413  * @tc.type: FUNC
414  * @tc.require: issueI65R21
415  */
HWTEST_F(NotificationRequestTest,GetNotificationHashCode_0200,Level1)416 HWTEST_F(NotificationRequestTest, GetNotificationHashCode_0200, Level1)
417 {
418     int32_t myNotificationId = 10;
419     NotificationRequest notificationRequest(myNotificationId);
420 
421     notificationRequest.SetCreatorBundleName("creatorName");
422     int32_t uid = 0;
423     notificationRequest.SetCreatorUid(uid);
424     std::string result3 = notificationRequest.GetNotificationHashCode();
425     std::string creatorName = "";
426     EXPECT_EQ(result3, creatorName);
427 }
428 
429 /**
430  * @tc.name: GetNotificationHashCode_0300
431  * @tc.desc: GetNotificationHashCode
432  * @tc.type: FUNC
433  * @tc.require: issueI65R21
434  */
HWTEST_F(NotificationRequestTest,GetNotificationHashCode_0300,Level1)435 HWTEST_F(NotificationRequestTest, GetNotificationHashCode_0300, Level1)
436 {
437     int32_t myNotificationId = 10;
438     NotificationRequest notificationRequest(myNotificationId);
439 
440     notificationRequest.SetCreatorBundleName("creatorName");
441     notificationRequest.SetCreatorUid(2);
442 
443     std::string ownerName = "";
444     notificationRequest.SetOwnerBundleName(ownerName);
445     std::string result1 = notificationRequest.GetNotificationHashCode();
446     EXPECT_EQ(result1, ownerName);
447 }
448 
449 /**
450  * @tc.name: SetDevicesSupportDisplay_0100
451  * @tc.desc: SetDevicesSupportDisplay
452  * @tc.type: FUNC
453  * @tc.require: issueI65R21
454  */
HWTEST_F(NotificationRequestTest,SetDevicesSupportDisplay_0100,Level1)455 HWTEST_F(NotificationRequestTest, SetDevicesSupportDisplay_0100, Level1)
456 {
457     int32_t myNotificationId = 10;
458     NotificationRequest notificationRequest(myNotificationId);
459 
460     std::vector<std::string> devices;
461     notificationRequest.SetDevicesSupportDisplay(devices);
462     notificationRequest.SetDevicesSupportOperate(devices);
463     nlohmann::json jsonObject;
464     notificationRequest.ConvertJsonToNum(nullptr, jsonObject);
465 
466     Notification::NotificationRequest* target = new Notification::NotificationRequest(myNotificationId);
467     notificationRequest.ConvertJsonToNum(target, jsonObject);
468     notificationRequest.ConvertJsonToString(nullptr, jsonObject);
469     notificationRequest.ConvertJsonToEnum(nullptr, jsonObject);
470     notificationRequest.ConvertJsonToBool(nullptr, jsonObject);
471     notificationRequest.ConvertJsonToPixelMap(nullptr, jsonObject);
472     bool result1 = notificationRequest.ConvertJsonToNotificationContent(nullptr, jsonObject);
473     bool result2 = notificationRequest.ConvertJsonToNotificationActionButton(nullptr, jsonObject);
474     bool result3 = notificationRequest.ConvertJsonToNotificationFlags(nullptr, jsonObject);
475     EXPECT_EQ(result1, false);
476     EXPECT_EQ(result2, false);
477     EXPECT_EQ(result3, false);
478 }
479 
480 /**
481  * @tc.name: ConvertJsonToString_0100
482  * @tc.desc: ConvertJsonToString when target not null
483  * @tc.type: FUNC
484  * @tc.require: issueI65R21
485  */
HWTEST_F(NotificationRequestTest,ConvertJsonToString_0100,Level1)486 HWTEST_F(NotificationRequestTest, ConvertJsonToString_0100, Level1)
487 {
488     int32_t myNotificationId = 10;
489     NotificationRequest notificationRequest(myNotificationId);
490 
491     nlohmann::json jsonObject;
492     Notification::NotificationRequest* target = new Notification::NotificationRequest(myNotificationId);
493 
494     notificationRequest.ConvertJsonToString(target, jsonObject);
495     notificationRequest.ConvertJsonToEnum(target, jsonObject);
496     notificationRequest.ConvertJsonToBool(target, jsonObject);
497     notificationRequest.ConvertJsonToPixelMap(target, jsonObject);
498     bool result1 = notificationRequest.ConvertJsonToNotificationContent(target, jsonObject);
499     bool result2 = notificationRequest.ConvertJsonToNotificationActionButton(target, jsonObject);
500     bool result3 = notificationRequest.ConvertJsonToNotificationFlags(target, jsonObject);
501     EXPECT_EQ(result1, true);
502     EXPECT_EQ(result2, true);
503     EXPECT_EQ(result3, true);
504 }
505 
506 /**
507  * @tc.name: ConvertJsonToNotificationDistributedOptions_0100
508  * @tc.desc: ConvertJsonToNotificationDistributedOptions
509  * @tc.type: FUNC
510  * @tc.require: issueI65R21
511  */
HWTEST_F(NotificationRequestTest,ConvertJsonToNotificationDistributedOptions_0100,Level1)512 HWTEST_F(NotificationRequestTest, ConvertJsonToNotificationDistributedOptions_0100, Level1)
513 {
514     int32_t myNotificationId = 10;
515     NotificationRequest notificationRequest(myNotificationId);
516 
517     nlohmann::json jsonObject;
518     bool result1 = notificationRequest.ConvertJsonToNotificationDistributedOptions(nullptr, jsonObject);
519     EXPECT_EQ(result1, false);
520 }
521 
522 /**
523  * @tc.name: ConvertJsonToNotificationDistributedOptions_0200
524  * @tc.desc: ConvertJsonToNotificationDistributedOptions
525  * @tc.type: FUNC
526  * @tc.require: issueI65R21
527  */
HWTEST_F(NotificationRequestTest,ConvertJsonToNotificationDistributedOptions_0200,Level1)528 HWTEST_F(NotificationRequestTest, ConvertJsonToNotificationDistributedOptions_0200, Level1)
529 {
530     int32_t myNotificationId = 10;
531     NotificationRequest notificationRequest(myNotificationId);
532 
533     nlohmann::json jsonObject;
534     Notification::NotificationRequest* target = new Notification::NotificationRequest(myNotificationId);
535     bool result1 = notificationRequest.ConvertJsonToNotificationDistributedOptions(target, jsonObject);
536     EXPECT_EQ(result1, true);
537 }
538 
539 /**
540  * @tc.name: CheckLiveViewRequest_0001
541  * @tc.desc: Check default notification request is not live view request
542  * @tc.type: FUNC
543  * @tc.require: issue
544  */
HWTEST_F(NotificationRequestTest,CheckLiveViewRequest_0001,Level1)545 HWTEST_F(NotificationRequestTest, CheckLiveViewRequest_0001, Level1)
546 {
547     int32_t myNotificationId = 10;
548     NotificationRequest notificationRequest(myNotificationId);
549 
550     EXPECT_EQ(notificationRequest.IsCommonLiveView(), false);
551 }
552 
553 /**
554  * @tc.name: CheckLiveViewRequest_0002
555  * @tc.desc: Check live view request pass
556  * @tc.type: FUNC
557  * @tc.require: issue
558  */
HWTEST_F(NotificationRequestTest,CheckLiveViewRequest_0002,Level1)559 HWTEST_F(NotificationRequestTest, CheckLiveViewRequest_0002, Level1)
560 {
561     int32_t myNotificationId = 10;
562     NotificationRequest notificationRequest(myNotificationId);
563 
564     notificationRequest.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
565     auto liveContent = std::make_shared<NotificationLiveViewContent>();
566     auto content = std::make_shared<NotificationContent>(liveContent);
567     notificationRequest.SetContent(content);
568     EXPECT_EQ(notificationRequest.IsCommonLiveView(), true);
569 }
570 
571 /**
572  * @tc.name: CheckLiveViewRequestParam_0001
573  * @tc.desc: Default notification request no need to check live view paramter
574  * @tc.type: FUNC
575  * @tc.require: issue
576  */
HWTEST_F(NotificationRequestTest,CheckLiveViewRequestParam_0001,Level1)577 HWTEST_F(NotificationRequestTest, CheckLiveViewRequestParam_0001, Level1)
578 {
579     int32_t myNotificationId = 10;
580     NotificationRequest notificationRequest(myNotificationId);
581     EXPECT_EQ(notificationRequest.CheckNotificationRequest(nullptr), ERR_OK);
582 }
583 
584 /**
585  * @tc.name: CheckLiveViewRequestParam_0002
586  * @tc.desc: Check pass when no old notification request
587  * @tc.type: FUNC
588  * @tc.require: issue
589  */
HWTEST_F(NotificationRequestTest,CheckLiveViewRequestParam_0002,Level1)590 HWTEST_F(NotificationRequestTest, CheckLiveViewRequestParam_0002, Level1)
591 {
592     int32_t myNotificationId = 10;
593     NotificationRequest notificationRequest(myNotificationId);
594     notificationRequest.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
595     auto liveContent = std::make_shared<NotificationLiveViewContent>();
596     liveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_CREATE);
597     auto content = std::make_shared<NotificationContent>(liveContent);
598     notificationRequest.SetContent(content);
599     EXPECT_EQ(notificationRequest.CheckNotificationRequest(nullptr), ERR_OK);
600 }
601 
602 /**
603  * @tc.name: CheckLiveViewRequestParam_0003
604  * @tc.desc: Check not pass when update without old notification request
605  * @tc.type: FUNC
606  * @tc.require: issue
607  */
HWTEST_F(NotificationRequestTest,CheckLiveViewRequestParam_0003,Level1)608 HWTEST_F(NotificationRequestTest, CheckLiveViewRequestParam_0003, Level1)
609 {
610     int32_t myNotificationId = 10;
611     NotificationRequest notificationRequest(myNotificationId);
612     notificationRequest.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
613     auto liveContent = std::make_shared<NotificationLiveViewContent>();
614     liveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_INCREMENTAL_UPDATE);
615     auto content = std::make_shared<NotificationContent>(liveContent);
616     notificationRequest.SetContent(content);
617     ErrCode result = notificationRequest.CheckNotificationRequest(nullptr);
618     EXPECT_EQ(result, ERR_ANS_NOTIFICATION_NOT_EXISTS);
619 }
620 
621 /**
622  * @tc.name: CheckLiveViewRequestParam_0004
623  * @tc.desc: Check not pass when old request not live view request
624  * @tc.type: FUNC
625  * @tc.require: issue
626  */
HWTEST_F(NotificationRequestTest,CheckLiveViewRequestParam_0004,Level1)627 HWTEST_F(NotificationRequestTest, CheckLiveViewRequestParam_0004, Level1)
628 {
629     int32_t myNotificationId = 10;
630     NotificationRequest notificationRequest(myNotificationId);
631     notificationRequest.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
632     auto liveContent = std::make_shared<NotificationLiveViewContent>();
633     liveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_INCREMENTAL_UPDATE);
634     auto content = std::make_shared<NotificationContent>(liveContent);
635     notificationRequest.SetContent(content);
636 
637     sptr<NotificationRequest> oldNotificationRequest(new (std::nothrow) NotificationRequest());
638     oldNotificationRequest->SetNotificationId(myNotificationId);
639     oldNotificationRequest->SetSlotType(NotificationConstant::SlotType::OTHER);
640     ErrCode result = notificationRequest.CheckNotificationRequest(oldNotificationRequest);
641     EXPECT_EQ(result, ERR_ANS_INVALID_PARAM);
642 }
643 
644 /**
645  * @tc.name: CheckLiveViewRequestParam_0005
646  * @tc.desc: Check not pass when live view request end
647  * @tc.type: FUNC
648  * @tc.require: issue
649  */
HWTEST_F(NotificationRequestTest,CheckLiveViewRequestParam_0005,Level1)650 HWTEST_F(NotificationRequestTest, CheckLiveViewRequestParam_0005, Level1)
651 {
652     int32_t myNotificationId = 10;
653     NotificationRequest notificationRequest(myNotificationId);
654     notificationRequest.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
655     auto liveContent = std::make_shared<NotificationLiveViewContent>();
656     liveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_INCREMENTAL_UPDATE);
657     auto content = std::make_shared<NotificationContent>(liveContent);
658     notificationRequest.SetContent(content);
659 
660     sptr<NotificationRequest> oldNotificationRequest(new (std::nothrow) NotificationRequest());
661     oldNotificationRequest->SetNotificationId(myNotificationId);
662     oldNotificationRequest->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
663     auto oldLiveContent = std::make_shared<NotificationLiveViewContent>();
664     oldLiveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_END);
665     auto oldContent = std::make_shared<NotificationContent>(oldLiveContent);
666     oldNotificationRequest->SetContent(oldContent);
667     ErrCode result = notificationRequest.CheckNotificationRequest(oldNotificationRequest);
668     EXPECT_EQ(result, ERR_ANS_END_NOTIFICATION);
669 }
670 
671 /**
672  * @tc.name: CheckLiveViewRequestParam_0006
673  * @tc.desc: Check not pass when repeate create
674  * @tc.type: FUNC
675  * @tc.require: issue
676  */
HWTEST_F(NotificationRequestTest,CheckLiveViewRequestParam_0006,Level1)677 HWTEST_F(NotificationRequestTest, CheckLiveViewRequestParam_0006, Level1)
678 {
679     int32_t myNotificationId = 10;
680     NotificationRequest notificationRequest(myNotificationId);
681     notificationRequest.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
682     auto liveContent = std::make_shared<NotificationLiveViewContent>();
683     liveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_CREATE);
684     auto content = std::make_shared<NotificationContent>(liveContent);
685     notificationRequest.SetContent(content);
686 
687     sptr<NotificationRequest> oldNotificationRequest(new (std::nothrow) NotificationRequest());
688     oldNotificationRequest->SetNotificationId(myNotificationId);
689     oldNotificationRequest->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
690     auto oldLiveContent = std::make_shared<NotificationLiveViewContent>();
691     oldLiveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_FULL_UPDATE);
692     auto oldContent = std::make_shared<NotificationContent>(oldLiveContent);
693     oldNotificationRequest->SetContent(oldContent);
694     ErrCode result = notificationRequest.CheckNotificationRequest(oldNotificationRequest);
695     EXPECT_EQ(result, ERR_ANS_REPEAT_CREATE);
696 }
697 
698 /**
699  * @tc.name: CheckLiveViewRequestParam_0007
700  * @tc.desc: Check not pass when live view version invalid
701  * @tc.type: FUNC
702  * @tc.require: issue
703  */
HWTEST_F(NotificationRequestTest,CheckLiveViewRequestParam_0007,Level1)704 HWTEST_F(NotificationRequestTest, CheckLiveViewRequestParam_0007, Level1)
705 {
706     int32_t myNotificationId = 10;
707     NotificationRequest notificationRequest(myNotificationId);
708     notificationRequest.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
709     auto liveContent = std::make_shared<NotificationLiveViewContent>();
710     liveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_INCREMENTAL_UPDATE);
711     liveContent->SetVersion(NotificationLiveViewContent::MAX_VERSION);
712     auto content = std::make_shared<NotificationContent>(liveContent);
713     notificationRequest.SetContent(content);
714 
715     sptr<NotificationRequest> oldNotificationRequest(new (std::nothrow) NotificationRequest());
716     oldNotificationRequest->SetNotificationId(myNotificationId);
717     oldNotificationRequest->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
718     auto oldLiveContent = std::make_shared<NotificationLiveViewContent>();
719     oldLiveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_FULL_UPDATE);
720     oldLiveContent->SetVersion(1);
721     auto oldContent = std::make_shared<NotificationContent>(oldLiveContent);
722     oldNotificationRequest->SetContent(oldContent);
723     ErrCode result = notificationRequest.CheckNotificationRequest(oldNotificationRequest);
724     EXPECT_EQ(result, ERR_ANS_EXPIRED_NOTIFICATION);
725 }
726 
727 /**
728  * @tc.name: CheckLiveViewRequestParam_0008
729  * @tc.desc: Check not pass when version is expired
730  * @tc.type: FUNC
731  * @tc.require: issue
732  */
HWTEST_F(NotificationRequestTest,CheckLiveViewRequestParam_0008,Level1)733 HWTEST_F(NotificationRequestTest, CheckLiveViewRequestParam_0008, Level1)
734 {
735     int32_t myNotificationId = 10;
736     NotificationRequest notificationRequest(myNotificationId);
737     notificationRequest.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
738     auto liveContent = std::make_shared<NotificationLiveViewContent>();
739     liveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_INCREMENTAL_UPDATE);
740     liveContent->SetVersion(1);
741     auto content = std::make_shared<NotificationContent>(liveContent);
742     notificationRequest.SetContent(content);
743 
744     sptr<NotificationRequest> oldNotificationRequest(new (std::nothrow) NotificationRequest());
745     oldNotificationRequest->SetNotificationId(myNotificationId);
746     oldNotificationRequest->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
747     auto oldLiveContent = std::make_shared<NotificationLiveViewContent>();
748     oldLiveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_FULL_UPDATE);
749     oldLiveContent->SetVersion(1);
750     auto oldContent = std::make_shared<NotificationContent>(oldLiveContent);
751     oldNotificationRequest->SetContent(oldContent);
752     ErrCode result = notificationRequest.CheckNotificationRequest(oldNotificationRequest);
753     EXPECT_EQ(result, ERR_ANS_EXPIRED_NOTIFICATION);
754 }
755 
756 /**
757  * @tc.name: CheckLiveViewRequestParam_0009
758  * @tc.desc: Check pass when the version is new
759  * @tc.type: FUNC
760  * @tc.require: issue
761  */
HWTEST_F(NotificationRequestTest,CheckLiveViewRequestParam_0009,Level1)762 HWTEST_F(NotificationRequestTest, CheckLiveViewRequestParam_0009, Level1)
763 {
764     int32_t myNotificationId = 10;
765     NotificationRequest notificationRequest(myNotificationId);
766     notificationRequest.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
767     auto liveContent = std::make_shared<NotificationLiveViewContent>();
768     liveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_INCREMENTAL_UPDATE);
769     liveContent->SetVersion(1);
770     auto content = std::make_shared<NotificationContent>(liveContent);
771     notificationRequest.SetContent(content);
772 
773     sptr<NotificationRequest> oldNotificationRequest(new (std::nothrow) NotificationRequest());
774     oldNotificationRequest->SetNotificationId(myNotificationId);
775     oldNotificationRequest->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
776     auto oldLiveContent = std::make_shared<NotificationLiveViewContent>();
777     oldLiveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_FULL_UPDATE);
778     auto oldContent = std::make_shared<NotificationContent>(oldLiveContent);
779     oldNotificationRequest->SetContent(oldContent);
780     ErrCode result = notificationRequest.CheckNotificationRequest(oldNotificationRequest);
781     EXPECT_EQ(result, ERR_OK);
782 }
783 
784 /**
785  * @tc.name: CheckLiveViewRequestParam_0010
786  * @tc.desc: Check pass when the old version is invalid
787  * @tc.type: FUNC
788  * @tc.require: issue
789  */
HWTEST_F(NotificationRequestTest,CheckLiveViewRequestParam_0010,Level1)790 HWTEST_F(NotificationRequestTest, CheckLiveViewRequestParam_0010, Level1)
791 {
792     int32_t myNotificationId = 10;
793     NotificationRequest notificationRequest(myNotificationId);
794     notificationRequest.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
795     auto liveContent = std::make_shared<NotificationLiveViewContent>();
796     liveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_INCREMENTAL_UPDATE);
797     liveContent->SetVersion(1);
798     auto content = std::make_shared<NotificationContent>(liveContent);
799     notificationRequest.SetContent(content);
800 
801     sptr<NotificationRequest> oldNotificationRequest(new (std::nothrow) NotificationRequest());
802     oldNotificationRequest->SetNotificationId(myNotificationId);
803     oldNotificationRequest->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
804     auto oldLiveContent = std::make_shared<NotificationLiveViewContent>();
805     oldLiveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_FULL_UPDATE);
806     oldLiveContent->SetVersion(NotificationLiveViewContent::MAX_VERSION);
807     auto oldContent = std::make_shared<NotificationContent>(oldLiveContent);
808     oldNotificationRequest->SetContent(oldContent);
809     ErrCode result = notificationRequest.CheckNotificationRequest(oldNotificationRequest);
810     EXPECT_EQ(result, ERR_OK);
811 }
812 
813 /**
814  * @tc.name: FillMissingParameters_0001
815  * @tc.desc: Check no need to fill parameter when not live view request
816  * @tc.type: FUNC
817  * @tc.require: issue
818  */
HWTEST_F(NotificationRequestTest,FillMissingParameters_0001,Level1)819 HWTEST_F(NotificationRequestTest, FillMissingParameters_0001, Level1)
820 {
821     int32_t myNotificationId = 10;
822     NotificationRequest notificationRequest(myNotificationId);
823     notificationRequest.SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION);
824     notificationRequest.FillMissingParameters(nullptr);
825 }
826 
827 /**
828  * @tc.name: FillMissingParameters_0002
829  * @tc.desc: Check no need to fill parameter when not exist old request
830  * @tc.type: FUNC
831  * @tc.require: issue
832  */
HWTEST_F(NotificationRequestTest,FillMissingParameters_0002,Level1)833 HWTEST_F(NotificationRequestTest, FillMissingParameters_0002, Level1)
834 {
835     int32_t myNotificationId = 10;
836     NotificationRequest notificationRequest(myNotificationId);
837     notificationRequest.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
838     auto liveContent = std::make_shared<NotificationLiveViewContent>();
839     liveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_CREATE);
840     auto content = std::make_shared<NotificationContent>(liveContent);
841     notificationRequest.SetContent(content);
842     notificationRequest.FillMissingParameters(nullptr);
843 }
844 
845 /**
846  * @tc.name: FillMissingParameters_0003
847  * @tc.desc: Check no need to fill param when full update
848  * @tc.type: FUNC
849  * @tc.require: issue
850  */
HWTEST_F(NotificationRequestTest,FillMissingParameters_0003,Level1)851 HWTEST_F(NotificationRequestTest, FillMissingParameters_0003, Level1)
852 {
853     int32_t myNotificationId = 10;
854     NotificationRequest notificationRequest(myNotificationId);
855     notificationRequest.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
856     auto liveContent = std::make_shared<NotificationLiveViewContent>();
857     liveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_FULL_UPDATE);
858     auto content = std::make_shared<NotificationContent>(liveContent);
859     notificationRequest.SetContent(content);
860 
861     sptr<NotificationRequest> oldNotificationRequest(new (std::nothrow) NotificationRequest());
862     oldNotificationRequest->SetNotificationId(myNotificationId);
863 
864     notificationRequest.FillMissingParameters(oldNotificationRequest);
865 }
866 
867 /**
868  * @tc.name: FillMissingParameters_0004
869  * @tc.desc: Check update request correctly when batch update
870  * @tc.type: FUNC
871  * @tc.require: issue
872  */
HWTEST_F(NotificationRequestTest,FillMissingParameters_0004,Level1)873 HWTEST_F(NotificationRequestTest, FillMissingParameters_0004, Level1)
874 {
875     int32_t myNotificationId = 10;
876     NotificationRequest notificationRequest(myNotificationId);
877     notificationRequest.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
878     auto liveContent = std::make_shared<NotificationLiveViewContent>();
879     liveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_INCREMENTAL_UPDATE);
880     auto content = std::make_shared<NotificationContent>(liveContent);
881     notificationRequest.SetContent(content);
882 
883     sptr<NotificationRequest> oldNotificationRequest(new (std::nothrow) NotificationRequest());
884     oldNotificationRequest->SetNotificationId(myNotificationId);
885     oldNotificationRequest->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
886     auto oldLiveContent = std::make_shared<NotificationLiveViewContent>();
887     auto oldExtraInfo = std::make_shared<AAFwk::WantParams>();
888     oldExtraInfo->SetParam(string("test"), nullptr);
889     oldLiveContent->SetExtraInfo(oldExtraInfo);
890     PictureMap pictureMap;
891     pictureMap.insert(std::make_pair(string("test"), std::vector<std::shared_ptr<Media::PixelMap>>()));
892     oldLiveContent->SetPicture(pictureMap);
893     auto oldContent = std::make_shared<NotificationContent>(oldLiveContent);
894     oldNotificationRequest->SetContent(oldContent);
895 
896     notificationRequest.FillMissingParameters(oldNotificationRequest);
897     EXPECT_FALSE(liveContent->GetPicture().empty());
898     EXPECT_TRUE(liveContent->GetExtraInfo()->HasParam(string("test")));
899 }
900 
901 /**
902  * @tc.name: FillMissingParameters_0005
903  * @tc.desc: Check update request correctly when old extrainfo is null
904  * @tc.type: FUNC
905  * @tc.require: issue
906  */
HWTEST_F(NotificationRequestTest,FillMissingParameters_0005,Level1)907 HWTEST_F(NotificationRequestTest, FillMissingParameters_0005, Level1)
908 {
909     int32_t myNotificationId = 10;
910     NotificationRequest notificationRequest(myNotificationId);
911     notificationRequest.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
912     auto liveContent = std::make_shared<NotificationLiveViewContent>();
913     liveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_INCREMENTAL_UPDATE);
914     auto content = std::make_shared<NotificationContent>(liveContent);
915     notificationRequest.SetContent(content);
916 
917     sptr<NotificationRequest> oldNotificationRequest(new (std::nothrow) NotificationRequest());
918     oldNotificationRequest->SetNotificationId(myNotificationId);
919     oldNotificationRequest->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
920     auto oldLiveContent = std::make_shared<NotificationLiveViewContent>();
921     PictureMap pictureMap;
922     pictureMap.insert(std::make_pair(string("test"), std::vector<std::shared_ptr<Media::PixelMap>>()));
923     oldLiveContent->SetPicture(pictureMap);
924     auto oldContent = std::make_shared<NotificationContent>(oldLiveContent);
925     oldNotificationRequest->SetContent(oldContent);
926 
927     notificationRequest.FillMissingParameters(oldNotificationRequest);
928     EXPECT_FALSE(liveContent->GetPicture().empty());
929     EXPECT_EQ(oldLiveContent->GetExtraInfo(), nullptr);
930     EXPECT_EQ(liveContent->GetExtraInfo(), nullptr);
931 
932     auto extraInfo = std::make_shared<AAFwk::WantParams>();
933     extraInfo->SetParam(string("test"), nullptr);
934     liveContent->SetExtraInfo(extraInfo);
935     notificationRequest.FillMissingParameters(oldNotificationRequest);
936     EXPECT_FALSE(liveContent->GetPicture().empty());
937     EXPECT_EQ(oldLiveContent->GetExtraInfo(), nullptr);
938     EXPECT_TRUE(liveContent->GetExtraInfo()->HasParam(string("test")));
939 }
940 
941 /**
942  * @tc.name: GetNotificationRequestKey_0001
943  * @tc.desc: Check get key right
944  * @tc.type: FUNC
945  * @tc.require: issue
946  */
HWTEST_F(NotificationRequestTest,GetNotificationRequestKey_0001,Level1)947 HWTEST_F(NotificationRequestTest, GetNotificationRequestKey_0001, Level1)
948 {
949     int32_t myNotificationId = 10;
950     NotificationRequest notificationRequest(myNotificationId);
951     notificationRequest.SetCreatorUid(0);
952     notificationRequest.SetCreatorUserId(1);
953     notificationRequest.SetLabel(string("test"));
954     notificationRequest.SetCreatorBundleName(string("push.com"));
955     auto key = notificationRequest.GetKey();
956     string expectKey {"ans_live_view__1_0_push.com_test_10"};
957     EXPECT_EQ(key, expectKey);
958 }
959 
960 /**
961  * @tc.name: GetNotificationRequestKey_0002
962  * @tc.desc: Check get key right
963  * @tc.type: FUNC
964  * @tc.require: issue
965  */
HWTEST_F(NotificationRequestTest,GetNotificationRequestKey_0002,Level1)966 HWTEST_F(NotificationRequestTest, GetNotificationRequestKey_0002, Level1)
967 {
968     int32_t myNotificationId = 10;
969     NotificationRequest notificationRequest(myNotificationId);
970     notificationRequest.SetOwnerUid(2);
971     notificationRequest.SetOwnerUserId(1);
972     notificationRequest.SetLabel(string("test"));
973     notificationRequest.SetOwnerBundleName(string("test.com"));
974     notificationRequest.SetIsAgentNotification(true);
975     auto key = notificationRequest.GetKey();
976     string expectKey {"ans_live_view__1_2_test.com_test_10"};
977     EXPECT_EQ(key, expectKey);
978 }
979 
TestMakePixelMap(int32_t width,int32_t height)980 inline std::shared_ptr<Media::PixelMap> TestMakePixelMap(int32_t width, int32_t height)
981 {
982     const int32_t PIXEL_BYTES = 4;
983     std::shared_ptr<Media::PixelMap> pixelMap = std::make_shared<Media::PixelMap>();
984     if (pixelMap == nullptr) {
985         return nullptr;
986     }
987     Media::ImageInfo info;
988     info.size.width = width;
989     info.size.height = height;
990     info.pixelFormat = Media::PixelFormat::ARGB_8888;
991     info.colorSpace = Media::ColorSpace::SRGB;
992     pixelMap->SetImageInfo(info);
993     int32_t rowDataSize = width * PIXEL_BYTES;
994     uint32_t bufferSize = rowDataSize * height;
995     void *buffer = malloc(bufferSize);
996     if (buffer != nullptr) {
997         pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, Media::AllocatorType::HEAP_ALLOC, nullptr);
998     }
999     return pixelMap;
1000 }
1001 
1002 /**
1003  * @tc.name: CheckImageSizeForContent_0001
1004  * @tc.desc: Check no need to check image size when request is default
1005  * @tc.type: FUNC
1006  * @tc.require: issue
1007  */
HWTEST_F(NotificationRequestTest,CheckImageSizeForContent_0001,Level1)1008 HWTEST_F(NotificationRequestTest, CheckImageSizeForContent_0001, Level1)
1009 {
1010     int32_t myNotificationId = 10;
1011     NotificationRequest notificationRequest(myNotificationId);
1012 
1013     auto result = notificationRequest.CheckImageSizeForContent();
1014     EXPECT_EQ(result, ERR_OK);
1015 }
1016 
1017 /**
1018  * @tc.name: CheckImageSizeForContent_0002
1019  * @tc.desc: Check pass when conversation request image size is small
1020  * @tc.type: FUNC
1021  * @tc.require: issue
1022  */
HWTEST_F(NotificationRequestTest,CheckImageSizeForContent_0002,Level1)1023 HWTEST_F(NotificationRequestTest, CheckImageSizeForContent_0002, Level1)
1024 {
1025     const int32_t ICON_SIZE = 36;
1026     int32_t myNotificationId = 10;
1027     NotificationRequest notificationRequest(myNotificationId);
1028     MessageUser msgUser;
1029     msgUser.SetPixelMap(TestMakePixelMap(ICON_SIZE, ICON_SIZE));
1030     auto conversationContent = std::make_shared<NotificationConversationalContent>(msgUser);
1031     conversationContent->GetMessageUser();
1032     auto content = std::make_shared<NotificationContent>(conversationContent);
1033     notificationRequest.SetContent(content);
1034 
1035     auto result = notificationRequest.CheckImageSizeForContent();
1036     EXPECT_EQ(result, ERR_OK);
1037 }
1038 
1039 /**
1040  * @tc.name: CheckImageSizeForContent_0003
1041  * @tc.desc: Check not pass when the pixel of picture request exceed limit
1042  * @tc.type: FUNC
1043  * @tc.require: issue
1044  */
HWTEST_F(NotificationRequestTest,CheckImageSizeForContent_0003,Level1)1045 HWTEST_F(NotificationRequestTest, CheckImageSizeForContent_0003, Level1)
1046 {
1047     const int32_t ICON_SIZE = 2 * 1024;
1048     int32_t myNotificationId = 10;
1049     NotificationRequest notificationRequest(myNotificationId);
1050     auto pictureContent = std::make_shared<NotificationPictureContent>();
1051     pictureContent->SetBigPicture(TestMakePixelMap(ICON_SIZE, ICON_SIZE));
1052     auto content = std::make_shared<NotificationContent>(pictureContent);
1053     notificationRequest.SetContent(content);
1054 
1055     auto result = notificationRequest.CheckImageSizeForContent();
1056     EXPECT_EQ(result, ERR_ANS_PICTURE_OVER_SIZE);
1057 }
1058 
1059 /**
1060  * @tc.name: CheckImageSizeForContent_0004
1061  * @tc.desc: Check not pass when live view request icon is empty
1062  * @tc.type: FUNC
1063  * @tc.require: issue
1064  */
HWTEST_F(NotificationRequestTest,CheckImageSizeForContent_0004,Level1)1065 HWTEST_F(NotificationRequestTest, CheckImageSizeForContent_0004, Level1)
1066 {
1067     int32_t myNotificationId = 10;
1068     NotificationRequest notificationRequest(myNotificationId);
1069     auto liveViewContent = std::make_shared<NotificationLiveViewContent>();
1070     PictureMap pictureMap;
1071     pictureMap.insert(std::make_pair(string("test"), PictureMap::mapped_type()));
1072     liveViewContent->SetPicture(pictureMap);
1073     auto content = std::make_shared<NotificationContent>(liveViewContent);
1074     notificationRequest.SetContent(content);
1075 
1076     auto result = notificationRequest.CheckImageSizeForContent();
1077     EXPECT_EQ(result, ERR_ANS_INVALID_PARAM);
1078 }
1079 
1080 /**
1081  * @tc.name: CheckImageSizeForContent_0005
1082  * @tc.desc: Check not pass when the number of live view request exceed limit
1083  * @tc.type: FUNC
1084  * @tc.require: issue
1085  */
HWTEST_F(NotificationRequestTest,CheckImageSizeForContent_0005,Level1)1086 HWTEST_F(NotificationRequestTest, CheckImageSizeForContent_0005, Level1)
1087 {
1088     int32_t myNotificationId = 10;
1089     NotificationRequest notificationRequest(myNotificationId);
1090     auto liveViewContent = std::make_shared<NotificationLiveViewContent>();
1091     PictureMap pictureMap;
1092     pictureMap.insert(std::make_pair(string("test"), PictureMap::mapped_type(MAX_LIVE_VIEW_ICON_NUM + 1)));
1093     liveViewContent->SetPicture(pictureMap);
1094     auto content = std::make_shared<NotificationContent>(liveViewContent);
1095     notificationRequest.SetContent(content);
1096 
1097     auto result = notificationRequest.CheckImageSizeForContent();
1098     EXPECT_EQ(result, ERR_ANS_INVALID_PARAM);
1099 }
1100 
1101 /**
1102  * @tc.name: CheckImageSizeForContent_0006
1103  * @tc.desc: Check not pass when the pixel of live view request exceed limit
1104  * @tc.type: FUNC
1105  * @tc.require: issue
1106  */
HWTEST_F(NotificationRequestTest,CheckImageSizeForContent_0006,Level1)1107 HWTEST_F(NotificationRequestTest, CheckImageSizeForContent_0006, Level1)
1108 {
1109     const int32_t ICON_SIZE = 8 * 32;
1110     auto pixelMap = TestMakePixelMap(ICON_SIZE, ICON_SIZE);
1111     PictureMap pictureMap;
1112     PictureMap::mapped_type vecPixelMap;
1113     vecPixelMap.push_back(pixelMap);
1114     pictureMap.insert(std::make_pair(string("test"), vecPixelMap));
1115     auto liveViewContent = std::make_shared<NotificationLiveViewContent>();
1116     liveViewContent->SetPicture(pictureMap);
1117     auto content = std::make_shared<NotificationContent>(liveViewContent);
1118 
1119     int32_t myNotificationId = 10;
1120     NotificationRequest notificationRequest(myNotificationId);
1121     notificationRequest.SetContent(content);
1122 
1123     auto result = notificationRequest.CheckImageSizeForContent();
1124     EXPECT_EQ(result, ERR_ANS_ICON_OVER_SIZE);
1125 }
1126 
1127 /**
1128  * @tc.name: CheckImageSizeForContent_0007
1129  * @tc.desc: Check live view picture pass when pixel doesn't exceed limit
1130  * @tc.type: FUNC
1131  * @tc.require: issue
1132  */
HWTEST_F(NotificationRequestTest,CheckImageSizeForContent_0007,Level1)1133 HWTEST_F(NotificationRequestTest, CheckImageSizeForContent_0007, Level1)
1134 {
1135     const int32_t ICON_SIZE = 3 * 32;
1136     auto pixelMap = TestMakePixelMap(ICON_SIZE, ICON_SIZE);
1137     PictureMap pictureMap;
1138     PictureMap::mapped_type vecPixelMap;
1139     vecPixelMap.push_back(pixelMap);
1140     pictureMap.insert(std::make_pair(string("test"), vecPixelMap));
1141     auto liveViewContent = std::make_shared<NotificationLiveViewContent>();
1142     liveViewContent->SetPicture(pictureMap);
1143     auto content = std::make_shared<NotificationContent>(liveViewContent);
1144 
1145     int32_t myNotificationId = 10;
1146     NotificationRequest notificationRequest(myNotificationId);
1147     notificationRequest.SetContent(content);
1148 
1149     auto result = notificationRequest.CheckImageSizeForContent();
1150     EXPECT_EQ(result, ERR_OK);
1151 }
1152 
1153 /**
1154  * @tc.name: CheckImageSizeForContent_0008
1155  * @tc.desc: Check pass when notification request is other types
1156  * @tc.type: FUNC
1157  * @tc.require: issue
1158  */
HWTEST_F(NotificationRequestTest,CheckImageSizeForContent_0008,Level1)1159 HWTEST_F(NotificationRequestTest, CheckImageSizeForContent_0008, Level1)
1160 {
1161     auto multiLineContent = std::make_shared<NotificationMultiLineContent>();
1162     auto content = std::make_shared<NotificationContent>(multiLineContent);
1163 
1164     int32_t myNotificationId = 10;
1165     NotificationRequest notificationRequest(myNotificationId);
1166     notificationRequest.SetContent(content);
1167 
1168     auto result = notificationRequest.CheckImageSizeForContent();
1169     EXPECT_EQ(result, ERR_OK);
1170 }
1171 
1172 /**
1173  * @tc.name: SetUpdateDeadLine_0001
1174  * @tc.desc: Check SetUpdateDeadLine operator
1175  * @tc.type: FUNC
1176  * @tc.require: issue
1177  */
HWTEST_F(NotificationRequestTest,SetUpdateDeadLine_0001,Level1)1178 HWTEST_F(NotificationRequestTest, SetUpdateDeadLine_0001, Level1)
1179 {
1180     auto multiLineContent = std::make_shared<NotificationMultiLineContent>();
1181     auto content = std::make_shared<NotificationContent>(multiLineContent);
1182 
1183     int32_t myNotificationId = 10;
1184     NotificationRequest notificationRequest(myNotificationId);
1185     notificationRequest.SetContent(content);
1186 
1187     //override the constructor operator
1188     NotificationRequest newNotificationRequest = notificationRequest;
1189     int updateDeadLine = 1;
1190     newNotificationRequest.SetUpdateDeadLine(updateDeadLine);
1191     EXPECT_EQ(newNotificationRequest.GetUpdateDeadLine(), 1);
1192 }
1193 
1194 /**
1195  * @tc.name: SetArchiveDeadLine_0001
1196  * @tc.desc: Check SetArchiveDeadLine operator
1197  * @tc.type: FUNC
1198  * @tc.require: issue
1199  */
HWTEST_F(NotificationRequestTest,SetArchiveDeadLine_0001,Level1)1200 HWTEST_F(NotificationRequestTest, SetArchiveDeadLine_0001, Level1)
1201 {
1202     int archiveDeadLine = 1;
1203     int32_t myNotificationId = 10;
1204     NotificationRequest notificationRequest(myNotificationId);
1205     notificationRequest.SetArchiveDeadLine(archiveDeadLine);
1206     EXPECT_EQ(notificationRequest.GetArchiveDeadLine(), 1);
1207 }
1208 } // namespace Notification
1209 } // namespace OHOS
1210