• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     EXPECT_EQ(notificationRequest.GetNotificationId(), myNotificationId);
826 }
827 
828 /**
829  * @tc.name: FillMissingParameters_0002
830  * @tc.desc: Check no need to fill parameter when not exist old request
831  * @tc.type: FUNC
832  * @tc.require: issue
833  */
HWTEST_F(NotificationRequestTest,FillMissingParameters_0002,Level1)834 HWTEST_F(NotificationRequestTest, FillMissingParameters_0002, Level1)
835 {
836     int32_t myNotificationId = 10;
837     NotificationRequest notificationRequest(myNotificationId);
838     notificationRequest.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
839     auto liveContent = std::make_shared<NotificationLiveViewContent>();
840     liveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_CREATE);
841     auto content = std::make_shared<NotificationContent>(liveContent);
842     notificationRequest.SetContent(content);
843     notificationRequest.FillMissingParameters(nullptr);
844     EXPECT_EQ(notificationRequest.GetNotificationId(), myNotificationId);
845 }
846 
847 /**
848  * @tc.name: FillMissingParameters_0003
849  * @tc.desc: Check no need to fill param when full update
850  * @tc.type: FUNC
851  * @tc.require: issue
852  */
HWTEST_F(NotificationRequestTest,FillMissingParameters_0003,Level1)853 HWTEST_F(NotificationRequestTest, FillMissingParameters_0003, Level1)
854 {
855     int32_t myNotificationId = 10;
856     NotificationRequest notificationRequest(myNotificationId);
857     notificationRequest.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
858     auto liveContent = std::make_shared<NotificationLiveViewContent>();
859     liveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_FULL_UPDATE);
860     auto content = std::make_shared<NotificationContent>(liveContent);
861     notificationRequest.SetContent(content);
862 
863     sptr<NotificationRequest> oldNotificationRequest(new (std::nothrow) NotificationRequest());
864     oldNotificationRequest->SetNotificationId(myNotificationId);
865 
866     notificationRequest.FillMissingParameters(oldNotificationRequest);
867     EXPECT_EQ(notificationRequest.GetNotificationId(), myNotificationId);
868 }
869 
870 /**
871  * @tc.name: FillMissingParameters_0004
872  * @tc.desc: Check update request correctly when batch update
873  * @tc.type: FUNC
874  * @tc.require: issue
875  */
HWTEST_F(NotificationRequestTest,FillMissingParameters_0004,Level1)876 HWTEST_F(NotificationRequestTest, FillMissingParameters_0004, Level1)
877 {
878     int32_t myNotificationId = 10;
879     NotificationRequest notificationRequest(myNotificationId);
880     notificationRequest.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
881     auto liveContent = std::make_shared<NotificationLiveViewContent>();
882     liveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_INCREMENTAL_UPDATE);
883     auto content = std::make_shared<NotificationContent>(liveContent);
884     notificationRequest.SetContent(content);
885 
886     sptr<NotificationRequest> oldNotificationRequest(new (std::nothrow) NotificationRequest());
887     oldNotificationRequest->SetNotificationId(myNotificationId);
888     oldNotificationRequest->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
889     auto oldLiveContent = std::make_shared<NotificationLiveViewContent>();
890     auto oldExtraInfo = std::make_shared<AAFwk::WantParams>();
891     oldExtraInfo->SetParam(string("test"), nullptr);
892     oldLiveContent->SetExtraInfo(oldExtraInfo);
893     PictureMap pictureMap;
894     pictureMap.insert(std::make_pair(string("test"), std::vector<std::shared_ptr<Media::PixelMap>>()));
895     oldLiveContent->SetPicture(pictureMap);
896     auto oldContent = std::make_shared<NotificationContent>(oldLiveContent);
897     oldNotificationRequest->SetContent(oldContent);
898 
899     notificationRequest.FillMissingParameters(oldNotificationRequest);
900     EXPECT_FALSE(liveContent->GetPicture().empty());
901     EXPECT_TRUE(liveContent->GetExtraInfo()->HasParam(string("test")));
902 }
903 
904 /**
905  * @tc.name: FillMissingParameters_0005
906  * @tc.desc: Check update request correctly when old extrainfo is null
907  * @tc.type: FUNC
908  * @tc.require: issue
909  */
HWTEST_F(NotificationRequestTest,FillMissingParameters_0005,Level1)910 HWTEST_F(NotificationRequestTest, FillMissingParameters_0005, Level1)
911 {
912     int32_t myNotificationId = 10;
913     NotificationRequest notificationRequest(myNotificationId);
914     notificationRequest.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
915     auto liveContent = std::make_shared<NotificationLiveViewContent>();
916     liveContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_INCREMENTAL_UPDATE);
917     auto content = std::make_shared<NotificationContent>(liveContent);
918     notificationRequest.SetContent(content);
919 
920     sptr<NotificationRequest> oldNotificationRequest(new (std::nothrow) NotificationRequest());
921     oldNotificationRequest->SetNotificationId(myNotificationId);
922     oldNotificationRequest->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
923     auto oldLiveContent = std::make_shared<NotificationLiveViewContent>();
924     PictureMap pictureMap;
925     pictureMap.insert(std::make_pair(string("test"), std::vector<std::shared_ptr<Media::PixelMap>>()));
926     oldLiveContent->SetPicture(pictureMap);
927     auto oldContent = std::make_shared<NotificationContent>(oldLiveContent);
928     oldNotificationRequest->SetContent(oldContent);
929 
930     notificationRequest.FillMissingParameters(oldNotificationRequest);
931     EXPECT_FALSE(liveContent->GetPicture().empty());
932     EXPECT_EQ(oldLiveContent->GetExtraInfo(), nullptr);
933     EXPECT_EQ(liveContent->GetExtraInfo(), nullptr);
934 
935     auto extraInfo = std::make_shared<AAFwk::WantParams>();
936     extraInfo->SetParam(string("test"), nullptr);
937     liveContent->SetExtraInfo(extraInfo);
938     notificationRequest.FillMissingParameters(oldNotificationRequest);
939     EXPECT_FALSE(liveContent->GetPicture().empty());
940     EXPECT_EQ(oldLiveContent->GetExtraInfo(), nullptr);
941     EXPECT_TRUE(liveContent->GetExtraInfo()->HasParam(string("test")));
942 }
943 
944 /**
945  * @tc.name: GetNotificationRequestKey_0001
946  * @tc.desc: Check get key right
947  * @tc.type: FUNC
948  * @tc.require: issue
949  */
HWTEST_F(NotificationRequestTest,GetNotificationRequestKey_0001,Level1)950 HWTEST_F(NotificationRequestTest, GetNotificationRequestKey_0001, Level1)
951 {
952     int32_t myNotificationId = 10;
953     NotificationRequest notificationRequest(myNotificationId);
954     notificationRequest.SetCreatorUid(0);
955     notificationRequest.SetCreatorUserId(1);
956     notificationRequest.SetLabel(string("test"));
957     notificationRequest.SetCreatorBundleName(string("push.com"));
958     auto key = notificationRequest.GetKey();
959     string expectKey {"ans_live_view___1_0_push.com_test_10"};
960     EXPECT_EQ(key, expectKey);
961 }
962 
963 /**
964  * @tc.name: GetNotificationRequestKey_0002
965  * @tc.desc: Check get key right
966  * @tc.type: FUNC
967  * @tc.require: issue
968  */
HWTEST_F(NotificationRequestTest,GetNotificationRequestKey_0002,Level1)969 HWTEST_F(NotificationRequestTest, GetNotificationRequestKey_0002, Level1)
970 {
971     int32_t myNotificationId = 10;
972     NotificationRequest notificationRequest(myNotificationId);
973     notificationRequest.SetOwnerUid(2);
974     notificationRequest.SetOwnerUserId(1);
975     notificationRequest.SetLabel(string("test"));
976     notificationRequest.SetOwnerBundleName(string("test.com"));
977     notificationRequest.SetIsAgentNotification(true);
978     auto key = notificationRequest.GetKey();
979     string expectKey {"ans_live_view___1_2_test.com_test_10"};
980     EXPECT_EQ(key, expectKey);
981 }
982 
TestMakePixelMap(int32_t width,int32_t height)983 inline std::shared_ptr<Media::PixelMap> TestMakePixelMap(int32_t width, int32_t height)
984 {
985     const int32_t PIXEL_BYTES = 4;
986     std::shared_ptr<Media::PixelMap> pixelMap = std::make_shared<Media::PixelMap>();
987     if (pixelMap == nullptr) {
988         return nullptr;
989     }
990     Media::ImageInfo info;
991     info.size.width = width;
992     info.size.height = height;
993     info.pixelFormat = Media::PixelFormat::ARGB_8888;
994     info.colorSpace = Media::ColorSpace::SRGB;
995     pixelMap->SetImageInfo(info);
996     int32_t rowDataSize = width * PIXEL_BYTES;
997     uint32_t bufferSize = rowDataSize * height;
998     void *buffer = malloc(bufferSize);
999     if (buffer != nullptr) {
1000         pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, Media::AllocatorType::HEAP_ALLOC, nullptr);
1001     }
1002     return pixelMap;
1003 }
1004 
1005 /**
1006  * @tc.name: CheckImageSizeForContent_0001
1007  * @tc.desc: Check no need to check image size when request is default
1008  * @tc.type: FUNC
1009  * @tc.require: issue
1010  */
HWTEST_F(NotificationRequestTest,CheckImageSizeForContent_0001,Level1)1011 HWTEST_F(NotificationRequestTest, CheckImageSizeForContent_0001, Level1)
1012 {
1013     int32_t myNotificationId = 10;
1014     NotificationRequest notificationRequest(myNotificationId);
1015 
1016     auto result = notificationRequest.CheckImageSizeForContent();
1017     EXPECT_EQ(result, ERR_OK);
1018 }
1019 
1020 /**
1021  * @tc.name: CheckImageSizeForContent_0002
1022  * @tc.desc: Check pass when conversation request image size is small
1023  * @tc.type: FUNC
1024  * @tc.require: issue
1025  */
HWTEST_F(NotificationRequestTest,CheckImageSizeForContent_0002,Level1)1026 HWTEST_F(NotificationRequestTest, CheckImageSizeForContent_0002, Level1)
1027 {
1028     const int32_t ICON_SIZE = 36;
1029     int32_t myNotificationId = 10;
1030     NotificationRequest notificationRequest(myNotificationId);
1031     MessageUser msgUser;
1032     msgUser.SetPixelMap(TestMakePixelMap(ICON_SIZE, ICON_SIZE));
1033     auto conversationContent = std::make_shared<NotificationConversationalContent>(msgUser);
1034     conversationContent->GetMessageUser();
1035     auto content = std::make_shared<NotificationContent>(conversationContent);
1036     notificationRequest.SetContent(content);
1037 
1038     auto result = notificationRequest.CheckImageSizeForContent();
1039     EXPECT_EQ(result, ERR_OK);
1040 }
1041 
1042 /**
1043  * @tc.name: CheckImageSizeForContent_0003
1044  * @tc.desc: Check not pass when the pixel of picture request exceed limit
1045  * @tc.type: FUNC
1046  * @tc.require: issue
1047  */
HWTEST_F(NotificationRequestTest,CheckImageSizeForContent_0003,Level1)1048 HWTEST_F(NotificationRequestTest, CheckImageSizeForContent_0003, Level1)
1049 {
1050     const int32_t ICON_SIZE = 2 * 1024;
1051     int32_t myNotificationId = 10;
1052     NotificationRequest notificationRequest(myNotificationId);
1053     auto pictureContent = std::make_shared<NotificationPictureContent>();
1054     pictureContent->SetBigPicture(TestMakePixelMap(ICON_SIZE, ICON_SIZE));
1055     auto content = std::make_shared<NotificationContent>(pictureContent);
1056     notificationRequest.SetContent(content);
1057 
1058     auto result = notificationRequest.CheckImageSizeForContent();
1059     EXPECT_EQ(result, ERR_ANS_PICTURE_OVER_SIZE);
1060 }
1061 
1062 /**
1063  * @tc.name: CheckImageSizeForContent_0004
1064  * @tc.desc: Check not pass when live view request icon is empty
1065  * @tc.type: FUNC
1066  * @tc.require: issue
1067  */
HWTEST_F(NotificationRequestTest,CheckImageSizeForContent_0004,Level1)1068 HWTEST_F(NotificationRequestTest, CheckImageSizeForContent_0004, Level1)
1069 {
1070     int32_t myNotificationId = 10;
1071     NotificationRequest notificationRequest(myNotificationId);
1072     auto liveViewContent = std::make_shared<NotificationLiveViewContent>();
1073     PictureMap pictureMap;
1074     pictureMap.insert(std::make_pair(string("test"), PictureMap::mapped_type()));
1075     liveViewContent->SetPicture(pictureMap);
1076     auto content = std::make_shared<NotificationContent>(liveViewContent);
1077     notificationRequest.SetContent(content);
1078 
1079     auto result = notificationRequest.CheckImageSizeForContent();
1080     EXPECT_EQ(result, ERR_ANS_INVALID_PARAM);
1081 }
1082 
1083 /**
1084  * @tc.name: CheckImageSizeForContent_0005
1085  * @tc.desc: Check not pass when the number of live view request exceed limit
1086  * @tc.type: FUNC
1087  * @tc.require: issue
1088  */
HWTEST_F(NotificationRequestTest,CheckImageSizeForContent_0005,Level1)1089 HWTEST_F(NotificationRequestTest, CheckImageSizeForContent_0005, Level1)
1090 {
1091     int32_t myNotificationId = 10;
1092     NotificationRequest notificationRequest(myNotificationId);
1093     auto liveViewContent = std::make_shared<NotificationLiveViewContent>();
1094     PictureMap pictureMap;
1095     pictureMap.insert(std::make_pair(string("test"), PictureMap::mapped_type(MAX_LIVE_VIEW_ICON_NUM + 1)));
1096     liveViewContent->SetPicture(pictureMap);
1097     auto content = std::make_shared<NotificationContent>(liveViewContent);
1098     notificationRequest.SetContent(content);
1099 
1100     auto result = notificationRequest.CheckImageSizeForContent();
1101     EXPECT_EQ(result, ERR_ANS_INVALID_PARAM);
1102 }
1103 
1104 /**
1105  * @tc.name: CheckImageSizeForContent_0006
1106  * @tc.desc: Check not pass when the pixel of live view request exceed limit
1107  * @tc.type: FUNC
1108  * @tc.require: issue
1109  */
HWTEST_F(NotificationRequestTest,CheckImageSizeForContent_0006,Level1)1110 HWTEST_F(NotificationRequestTest, CheckImageSizeForContent_0006, Level1)
1111 {
1112     const int32_t ICON_SIZE = 8 * 32;
1113     auto pixelMap = TestMakePixelMap(ICON_SIZE, ICON_SIZE);
1114     PictureMap pictureMap;
1115     PictureMap::mapped_type vecPixelMap;
1116     vecPixelMap.push_back(pixelMap);
1117     pictureMap.insert(std::make_pair(string("test"), vecPixelMap));
1118     auto liveViewContent = std::make_shared<NotificationLiveViewContent>();
1119     liveViewContent->SetPicture(pictureMap);
1120     auto content = std::make_shared<NotificationContent>(liveViewContent);
1121 
1122     int32_t myNotificationId = 10;
1123     NotificationRequest notificationRequest(myNotificationId);
1124     notificationRequest.SetContent(content);
1125 
1126     auto result = notificationRequest.CheckImageSizeForContent();
1127     EXPECT_EQ(result, ERR_ANS_ICON_OVER_SIZE);
1128 }
1129 
1130 /**
1131  * @tc.name: CheckImageSizeForContent_0007
1132  * @tc.desc: Check live view picture pass when pixel doesn't exceed limit
1133  * @tc.type: FUNC
1134  * @tc.require: issue
1135  */
HWTEST_F(NotificationRequestTest,CheckImageSizeForContent_0007,Level1)1136 HWTEST_F(NotificationRequestTest, CheckImageSizeForContent_0007, Level1)
1137 {
1138     const int32_t ICON_SIZE = 3 * 32;
1139     auto pixelMap = TestMakePixelMap(ICON_SIZE, ICON_SIZE);
1140     PictureMap pictureMap;
1141     PictureMap::mapped_type vecPixelMap;
1142     vecPixelMap.push_back(pixelMap);
1143     pictureMap.insert(std::make_pair(string("test"), vecPixelMap));
1144     auto liveViewContent = std::make_shared<NotificationLiveViewContent>();
1145     liveViewContent->SetPicture(pictureMap);
1146     auto content = std::make_shared<NotificationContent>(liveViewContent);
1147 
1148     int32_t myNotificationId = 10;
1149     NotificationRequest notificationRequest(myNotificationId);
1150     notificationRequest.SetContent(content);
1151 
1152     auto result = notificationRequest.CheckImageSizeForContent();
1153     EXPECT_EQ(result, ERR_OK);
1154 }
1155 
1156 /**
1157  * @tc.name: CheckImageSizeForContent_0008
1158  * @tc.desc: Check pass when notification request is other types
1159  * @tc.type: FUNC
1160  * @tc.require: issue
1161  */
HWTEST_F(NotificationRequestTest,CheckImageSizeForContent_0008,Level1)1162 HWTEST_F(NotificationRequestTest, CheckImageSizeForContent_0008, Level1)
1163 {
1164     auto multiLineContent = std::make_shared<NotificationMultiLineContent>();
1165     auto content = std::make_shared<NotificationContent>(multiLineContent);
1166 
1167     int32_t myNotificationId = 10;
1168     NotificationRequest notificationRequest(myNotificationId);
1169     notificationRequest.SetContent(content);
1170 
1171     auto result = notificationRequest.CheckImageSizeForContent();
1172     EXPECT_EQ(result, ERR_OK);
1173 }
1174 
1175 /**
1176  * @tc.name: SetUpdateDeadLine_0001
1177  * @tc.desc: Check SetUpdateDeadLine operator
1178  * @tc.type: FUNC
1179  * @tc.require: issue
1180  */
HWTEST_F(NotificationRequestTest,SetUpdateDeadLine_0001,Level1)1181 HWTEST_F(NotificationRequestTest, SetUpdateDeadLine_0001, Level1)
1182 {
1183     auto multiLineContent = std::make_shared<NotificationMultiLineContent>();
1184     auto content = std::make_shared<NotificationContent>(multiLineContent);
1185 
1186     int32_t myNotificationId = 10;
1187     NotificationRequest notificationRequest(myNotificationId);
1188     notificationRequest.SetContent(content);
1189 
1190     //override the constructor operator
1191     NotificationRequest newNotificationRequest = notificationRequest;
1192     int updateDeadLine = 1;
1193     newNotificationRequest.SetUpdateDeadLine(updateDeadLine);
1194     EXPECT_EQ(newNotificationRequest.GetUpdateDeadLine(), 1);
1195 }
1196 
1197 /**
1198  * @tc.name: SetArchiveDeadLine_0001
1199  * @tc.desc: Check SetArchiveDeadLine operator
1200  * @tc.type: FUNC
1201  * @tc.require: issue
1202  */
HWTEST_F(NotificationRequestTest,SetArchiveDeadLine_0001,Level1)1203 HWTEST_F(NotificationRequestTest, SetArchiveDeadLine_0001, Level1)
1204 {
1205     int archiveDeadLine = 1;
1206     int32_t myNotificationId = 10;
1207     NotificationRequest notificationRequest(myNotificationId);
1208     notificationRequest.SetArchiveDeadLine(archiveDeadLine);
1209     EXPECT_EQ(notificationRequest.GetArchiveDeadLine(), 1);
1210 }
1211 } // namespace Notification
1212 } // namespace OHOS
1213