• 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 
18 #define private public
19 #define protected public
20 #include "notification_request.h"
21 #undef private
22 #undef protected
23 #include "want_agent_helper.h"
24 
25 using namespace testing::ext;
26 namespace OHOS {
27 namespace Notification {
28 class NotificationRequestTest : public testing::Test {
29 public:
SetUpTestCase()30     static void SetUpTestCase() {};
TearDownTestCase()31     static void TearDownTestCase() {};
SetUp()32     void SetUp() {};
TearDown()33     void TearDown() {};
34 };
35 
36 /**
37  * @tc.name: NotificationGetWantAgent_0100
38  * @tc.desc: GetWantAgent
39  * @tc.type: FUNC
40  * @tc.require: issueI5RW70
41  */
HWTEST_F(NotificationRequestTest,NotificationGetWantAgent_0100,Level1)42 HWTEST_F(NotificationRequestTest, NotificationGetWantAgent_0100, Level1)
43 {
44     int32_t myNotificationId = 10;
45     NotificationRequest notificationRequest(myNotificationId);
46     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent = notificationRequest.GetWantAgent();
47     EXPECT_EQ(wantAgent, nullptr);
48 }
49 
50 /**
51  * @tc.name: NotificationSetMaxScreenWantAgent_0100
52  * @tc.desc: SetMaxScreenWantAgent
53  * @tc.type: FUNC
54  * @tc.require: issueI5RW70
55  */
HWTEST_F(NotificationRequestTest,NotificationSetMaxScreenWantAgent_0100,Level1)56 HWTEST_F(NotificationRequestTest, NotificationSetMaxScreenWantAgent_0100, Level1)
57 {
58     int32_t myNotificationId = 10;
59     NotificationRequest notificationRequest(myNotificationId);
60     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent = notificationRequest.GetWantAgent();
61     notificationRequest.SetMaxScreenWantAgent(wantAgent);
62     auto result = notificationRequest.GetMaxScreenWantAgent();
63     EXPECT_EQ(result, nullptr);
64 }
65 
66 /**
67  * @tc.name: NotificationGetAdditionalData_0100
68  * @tc.desc: GetAdditionalData
69  * @tc.type: FUNC
70  * @tc.require: issueI5RW70
71  */
HWTEST_F(NotificationRequestTest,NotificationGetAdditionalData_0100,Level1)72 HWTEST_F(NotificationRequestTest, NotificationGetAdditionalData_0100, Level1)
73 {
74     int32_t myNotificationId = 10;
75     std::shared_ptr<AAFwk::WantParams> additionalPtr;
76     NotificationRequest notificationRequest(myNotificationId);
77     notificationRequest.SetAdditionalData(additionalPtr);
78     auto result = notificationRequest.GetAdditionalData();
79     EXPECT_EQ(result, nullptr);
80 }
81 
82 /**
83  * @tc.name: NotificationSetIsAgentNotification_0100
84  * @tc.desc: SetIsAgentNotification
85  * @tc.type: FUNC
86  * @tc.require: issueI5RW70
87  */
HWTEST_F(NotificationRequestTest,NotificationSetIsAgentNotification_0100,Level1)88 HWTEST_F(NotificationRequestTest, NotificationSetIsAgentNotification_0100, Level1)
89 {
90     int32_t myNotificationId = 10;
91     bool isAgentTrue = true;
92     NotificationRequest notificationRequest(myNotificationId);
93     notificationRequest.SetIsAgentNotification(isAgentTrue);
94     auto result = notificationRequest.IsAgentNotification();
95     EXPECT_EQ(result, true);
96     bool isAgentFalse = false;
97     notificationRequest.SetIsAgentNotification(isAgentFalse);
98     result = notificationRequest.IsAgentNotification();
99     EXPECT_EQ(result, false);
100 }
101 
102 /**
103  * @tc.name: NotificationOwnerUid_0100
104  * @tc.desc: SetOwnerUid and GetOwnerUid
105  * @tc.type: FUNC
106  * @tc.require: issueI5RW70
107  */
HWTEST_F(NotificationRequestTest,NotificationOwnerUid_0100,Level1)108 HWTEST_F(NotificationRequestTest, NotificationOwnerUid_0100, Level1)
109 {
110     int32_t myNotificationId = 10;
111     int32_t uid = 5;
112     NotificationRequest notificationRequest(myNotificationId);
113     notificationRequest.SetOwnerUid(uid);
114     auto result = notificationRequest.GetOwnerUid();
115     EXPECT_EQ(result, uid);
116 }
117 
118 /**
119  * @tc.name: NotificationOwnerUserId_0100
120  * @tc.desc: SetOwnerUserId and GetOwnerUserId
121  * @tc.type: FUNC
122  * @tc.require: issueI5RW70
123  */
HWTEST_F(NotificationRequestTest,NotificationOwnerUserId_0100,Level1)124 HWTEST_F(NotificationRequestTest, NotificationOwnerUserId_0100, Level1)
125 {
126     int32_t myNotificationId = 10;
127     int32_t userid = 5;
128     NotificationRequest notificationRequest(myNotificationId);
129     notificationRequest.SetOwnerUserId(userid);
130     auto result = notificationRequest.GetOwnerUserId();
131     EXPECT_EQ(result, userid);
132 }
133 
134 /**
135  * @tc.name: NotificationMarshalling_0100
136  * @tc.desc: Marshalling
137  * @tc.type: FUNC
138  * @tc.require: issueI5RW70
139  */
HWTEST_F(NotificationRequestTest,NotificationMarshalling_0100,Level1)140 HWTEST_F(NotificationRequestTest, NotificationMarshalling_0100, Level1)
141 {
142     int32_t myNotificationId = 10;
143     Parcel parcel;
144     NotificationRequest notificationRequest(myNotificationId);
145     auto result = notificationRequest.Marshalling(parcel);
146     EXPECT_EQ(result, true);
147 }
148 
149 /**
150  * @tc.name: NotificationReadFromParcel_0100
151  * @tc.desc: ReadFromParcel
152  * @tc.type: FUNC
153  * @tc.require: issueI5RW70
154  */
HWTEST_F(NotificationRequestTest,NotificationReadFromParcel_0100,Level1)155 HWTEST_F(NotificationRequestTest, NotificationReadFromParcel_0100, Level1)
156 {
157     int32_t myNotificationId = 10;
158     Parcel parcel;
159     NotificationRequest notificationRequest(myNotificationId);
160     auto result = notificationRequest.ReadFromParcel(parcel);
161     EXPECT_EQ(result, false);
162 }
163 
164 /**
165  * @tc.name: NotificationSetReceiverUserId_0100
166  * @tc.desc: SetReceiverUserId
167  * @tc.type: FUNC
168  * @tc.require: issueI5RW70
169  */
HWTEST_F(NotificationRequestTest,NotificationSetReceiverUserId_0100,Level1)170 HWTEST_F(NotificationRequestTest, NotificationSetReceiverUserId_0100, Level1)
171 {
172     int32_t myNotificationId = 10;
173     int32_t userid = 5;
174     NotificationRequest notificationRequest(myNotificationId);
175     notificationRequest.SetReceiverUserId(userid);
176     auto result = notificationRequest.GetReceiverUserId();
177     EXPECT_EQ(result, userid);
178 }
179 }
180 }
181