• 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_basic_content.h"
21 #include "notification_content.h"
22 #undef private
23 #undef protected
24 
25 using namespace testing::ext;
26 namespace OHOS {
27 namespace Notification {
28 class NotificationContentTest : 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: NotificationContentMarshalling_0100
38  * @tc.desc: Marshalling
39  * @tc.type: FUNC
40  * @tc.require: issueI5S0ZS
41  */
HWTEST_F(NotificationContentTest,NotificationContentMarshalling_0100,Level1)42 HWTEST_F(NotificationContentTest, NotificationContentMarshalling_0100, Level1)
43 {
44     Parcel parcel;
45     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
46     EXPECT_NE(normalContent, nullptr);
47     NotificationContent notificationContent(normalContent);
48     auto result = notificationContent.Marshalling(parcel);
49     EXPECT_EQ(result, true);
50 }
51 
52 /**
53  * @tc.name: NotificationContentReadFromParcel_0100
54  * @tc.desc: ReadFromParcel
55  * @tc.type: FUNC
56  * @tc.require: issueI5S0ZS
57  */
HWTEST_F(NotificationContentTest,NotificationContentReadFromParcel_0100,Level1)58 HWTEST_F(NotificationContentTest, NotificationContentReadFromParcel_0100, Level1)
59 {
60     Parcel parcel;
61     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
62     EXPECT_NE(normalContent, nullptr);
63     NotificationContent notificationContent(normalContent);
64     auto result = notificationContent.ReadFromParcel(parcel);
65     EXPECT_EQ(result, true);
66 }
67 
68 /**
69  * @tc.name: NotificationBasicContentGetAdditionalText_0100
70  * @tc.desc: GetAdditionalText
71  * @tc.type: FUNC
72  * @tc.require: issueI5S0ZS
73  */
HWTEST_F(NotificationContentTest,NotificationBasicContentGetAdditionalText_0100,Level1)74 HWTEST_F(NotificationContentTest, NotificationBasicContentGetAdditionalText_0100, Level1)
75 {
76     std::string additionalText = "test";
77     NotificationBasicContent notificationBasicContent;
78     notificationBasicContent.SetAdditionalText(additionalText);
79     auto result = notificationBasicContent.GetAdditionalText();
80     EXPECT_EQ(result, additionalText);
81 }
82 
83 /**
84  * @tc.name: NotificationBasicContentGetText_0100
85  * @tc.desc: GetText
86  * @tc.type: FUNC
87  * @tc.require: issueI5S0ZS
88  */
HWTEST_F(NotificationContentTest,NotificationBasicContentGetText_0100,Level1)89 HWTEST_F(NotificationContentTest, NotificationBasicContentGetText_0100, Level1)
90 {
91     std::string Text = "test";
92     NotificationBasicContent notificationBasicContent;
93     notificationBasicContent.SetText(Text);
94     auto result = notificationBasicContent.GetText();
95     EXPECT_EQ(result, Text);
96 }
97 
98 /**
99  * @tc.name: NotificationBasicContentGetTitle_0100
100  * @tc.desc: GetTitle
101  * @tc.type: FUNC
102  * @tc.require: issueI5S0ZS
103  */
HWTEST_F(NotificationContentTest,NotificationBasicContentGetTitle_0100,Level1)104 HWTEST_F(NotificationContentTest, NotificationBasicContentGetTitle_0100, Level1)
105 {
106     std::string title = "titleTest";
107     NotificationBasicContent notificationBasicContent;
108     notificationBasicContent.SetTitle(title);
109     auto result = notificationBasicContent.GetTitle();
110     EXPECT_EQ(result, title);
111 }
112 
113 /**
114  * @tc.name: NotificationBasicContentMarshalling_0100
115  * @tc.desc: Marshalling
116  * @tc.type: FUNC
117  * @tc.require: issueI5S0ZS
118  */
HWTEST_F(NotificationContentTest,NotificationBasicContentMarshalling_0100,Level1)119 HWTEST_F(NotificationContentTest, NotificationBasicContentMarshalling_0100, Level1)
120 {
121     Parcel parcel;
122     NotificationBasicContent notificationBasicContent;
123     auto result = notificationBasicContent.Marshalling(parcel);
124     EXPECT_EQ(result, true);
125 }
126 
127 /**
128  * @tc.name: NotificationContentReadFromParcel_0200
129  * @tc.desc: ReadFromParcel
130  * @tc.type: FUNC
131  * @tc.require: issueI665WK
132  */
HWTEST_F(NotificationContentTest,NotificationContentReadFromParcel_0200,Level1)133 HWTEST_F(NotificationContentTest, NotificationContentReadFromParcel_0200, Level1)
134 {
135     std::shared_ptr<NotificationNormalContent> normalContent0 = nullptr;
136     NotificationContent notificationContent0(normalContent0);
137 
138     std::shared_ptr<NotificationLongTextContent> longTextContent = nullptr;
139     NotificationContent notificationContent1(longTextContent);
140 
141     std::shared_ptr<NotificationPictureContent> pictureContent = nullptr;
142     NotificationContent notificationContent2(pictureContent);
143 
144     std::shared_ptr<NotificationConversationalContent> conversationContent = nullptr;
145     NotificationContent notificationContent3(conversationContent);
146 
147     std::shared_ptr<NotificationMultiLineContent> multiLineContent = nullptr;
148     NotificationContent notificationContent4(multiLineContent);
149 
150     std::shared_ptr<NotificationMediaContent> mediaContent = nullptr;
151     NotificationContent notificationContent5(mediaContent);
152 
153     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
154     NotificationContent notificationContent(normalContent);
155     auto result = notificationContent.GetContentType();
156     EXPECT_EQ(result, NotificationContent::Type::BASIC_TEXT);
157 
158     Parcel parcel;
159     auto result1 = notificationContent.ReadFromParcel(parcel);
160     EXPECT_EQ(result1, true);
161 }
162 
163 /**
164  * @tc.name: NotificationContentReadFromParcel_0300
165  * @tc.desc: ReadFromParcel
166  * @tc.type: FUNC
167  * @tc.require: issueI665WK
168  */
HWTEST_F(NotificationContentTest,NotificationContentReadFromParcel_0300,Level1)169 HWTEST_F(NotificationContentTest, NotificationContentReadFromParcel_0300, Level1)
170 {
171     std::shared_ptr<NotificationConversationalContent> conversationContent =
172         std::make_shared<NotificationConversationalContent>();
173     NotificationContent notificationContent(conversationContent);
174     auto result = notificationContent.GetContentType();
175     EXPECT_EQ(result, NotificationContent::Type::CONVERSATION);
176 
177     Parcel parcel;
178     auto result1 = notificationContent.ReadFromParcel(parcel);
179     EXPECT_EQ(result1, true);
180 }
181 
182 /**
183  * @tc.name: NotificationContentReadFromParcel_0400
184  * @tc.desc: ReadFromParcel
185  * @tc.type: FUNC
186  * @tc.require: issueI665WK
187  */
HWTEST_F(NotificationContentTest,NotificationContentReadFromParcel_0400,Level1)188 HWTEST_F(NotificationContentTest, NotificationContentReadFromParcel_0400, Level1)
189 {
190     std::shared_ptr<NotificationPictureContent> pictureContent = std::make_shared<NotificationPictureContent>();
191     NotificationContent notificationContent(pictureContent);
192     auto result = notificationContent.GetContentType();
193     EXPECT_EQ(result, NotificationContent::Type::PICTURE);
194 
195     Parcel parcel;
196     auto result1 = notificationContent.ReadFromParcel(parcel);
197     EXPECT_EQ(result1, true);
198 }
199 
200 /**
201  * @tc.name: NotificationContentReadFromParcel_0500
202  * @tc.desc: ReadFromParcel
203  * @tc.type: FUNC
204  * @tc.require: issueI665WK
205  */
HWTEST_F(NotificationContentTest,NotificationContentReadFromParcel_0500,Level1)206 HWTEST_F(NotificationContentTest, NotificationContentReadFromParcel_0500, Level1)
207 {
208     std::shared_ptr<NotificationMultiLineContent> multiLineContent = std::make_shared<NotificationMultiLineContent>();
209     NotificationContent notificationContent(multiLineContent);
210     auto result = notificationContent.GetContentType();
211     EXPECT_EQ(result, NotificationContent::Type::MULTILINE);
212 
213     Parcel parcel;
214     auto result1 = notificationContent.ReadFromParcel(parcel);
215     EXPECT_EQ(result1, true);
216 }
217 
218 /**
219  * @tc.name: NotificationContentReadFromParcel_0600
220  * @tc.desc: ReadFromParcel
221  * @tc.type: FUNC
222  * @tc.require: issueI665WK
223  */
HWTEST_F(NotificationContentTest,NotificationContentReadFromParcel_0600,Level1)224 HWTEST_F(NotificationContentTest, NotificationContentReadFromParcel_0600, Level1)
225 {
226     std::shared_ptr<NotificationMediaContent> mediaContent = std::make_shared<NotificationMediaContent>();
227     NotificationContent notificationContent(mediaContent);
228     auto result = notificationContent.GetContentType();
229     EXPECT_EQ(result, NotificationContent::Type::MEDIA);
230 
231     Parcel parcel;
232     auto result1 = notificationContent.ReadFromParcel(parcel);
233     EXPECT_EQ(result1, true);
234     notificationContent.Unmarshalling(parcel);
235 }
236 
237 /**
238  * @tc.name: ConvertJsonToContent_0100
239  * @tc.desc: ConvertJsonToContent
240  * @tc.type: FUNC
241  * @tc.require: issueI665WK
242  */
HWTEST_F(NotificationContentTest,ConvertJsonToContent_0100,Level1)243 HWTEST_F(NotificationContentTest, ConvertJsonToContent_0100, Level1)
244 {
245     std::shared_ptr<NotificationMediaContent> mediaContent = std::make_shared<NotificationMediaContent>();
246     NotificationContent notificationContent(mediaContent);
247 
248     nlohmann::json jsonObject;
249     auto result1 = notificationContent.ConvertJsonToContent(nullptr, jsonObject);
250     EXPECT_EQ(result1, false);
251 }
252 
253 /**
254  * @tc.name: FromJson_00002
255  * @tc.desc: Test FromJson parameters.
256  * @tc.type: FUNC
257  * @tc.require: issue
258  */
259 HWTEST_F(NotificationContentTest, FromJson_00002, Function | SmallTest | Level1)
260 {
261     std::shared_ptr<NotificationMediaContent> mediaContent = std::make_shared<NotificationMediaContent>();
262     NotificationContent notificationContent(mediaContent);
263     nlohmann::json jsonObject = nlohmann::json{"processName", "soundEnabled", "name", "arrivedTime1"};
264     notificationContent.FromJson(jsonObject);
265     EXPECT_EQ(jsonObject.is_object(), false);
266     EXPECT_EQ(notificationContent.FromJson(jsonObject), nullptr);
267 }
268 
269 /**
270  * @tc.name: FromJson_00003
271  * @tc.desc: Test FromJson parameters.
272  * @tc.type: FUNC
273  * @tc.require: issue
274  */
275 HWTEST_F(NotificationContentTest, FromJson_00003, Function | SmallTest | Level1)
276 {
277     std::shared_ptr<NotificationMediaContent> mediaContent = std::make_shared<NotificationMediaContent>();
278     NotificationContent notificationContent(mediaContent);
279     nlohmann::json jsonObject = nlohmann::json{
280         {"processName", "process6"}, {"APL", 1},
281         {"version", 2}, {"tokenId", 685266937},
282         {"tokenAttr", 0},
283         {"dcaps", {"AT_CAP", "ST_CAP"}}};
284     notificationContent.FromJson(jsonObject);
285     EXPECT_EQ(jsonObject.is_object(), true);
286 }
287 
288 /**
289  * @tc.name: ToJson_00001
290  * @tc.desc: Test ToJson parameters.
291  * @tc.type: FUNC
292  * @tc.require: issue
293  */
294 HWTEST_F(NotificationContentTest, ToJson_00001, Function | SmallTest | Level1)
295 {
296     std::shared_ptr<NotificationMediaContent> mediaContent = nullptr;
297     NotificationContent notificationContent(mediaContent);
298     std::shared_ptr<NotificationBasicContent> result = notificationContent.GetNotificationContent();
299     EXPECT_EQ(result, nullptr);
300     nlohmann::json jsonObject = nlohmann::json{
301         {"processName", "process6"}, {"APL", 1},
302         {"version", 2}, {"tokenId", 685266937},
303         {"tokenAttr", 0},
304         {"dcaps", {"AT_CAP", "ST_CAP"}}};
305     bool result2 = notificationContent.ToJson(jsonObject);
306     EXPECT_EQ(result2, false);
307 }
308 
309 /**
310  * @tc.name: NotificationContentMarshalling_0200
311  * @tc.desc: Marshalling
312  * @tc.type: FUNC
313  * @tc.require: issueI5S0ZS
314  */
HWTEST_F(NotificationContentTest,NotificationContentMarshalling_0200,Level1)315 HWTEST_F(NotificationContentTest, NotificationContentMarshalling_0200, Level1)
316 {
317     std::shared_ptr<NotificationNormalContent> normalContent = nullptr;
318     auto sptr1 = std::make_shared<NotificationContent>(normalContent);
319     EXPECT_NE(sptr1, nullptr);
320     std::shared_ptr<NotificationLongTextContent> longTextContent = nullptr;
321     auto sptr2 = std::make_shared<NotificationContent>(longTextContent);
322     EXPECT_NE(sptr2, nullptr);
323     std::shared_ptr<NotificationPictureContent> pictureContent = nullptr;
324     auto sptr3 = std::make_shared<NotificationContent>(pictureContent);
325     EXPECT_NE(sptr3, nullptr);
326     std::shared_ptr<NotificationConversationalContent> conversationContent = nullptr;
327     auto sptr4 = std::make_shared<NotificationContent>(conversationContent);
328     EXPECT_NE(sptr4, nullptr);
329     std::shared_ptr<NotificationMultiLineContent> multiLineContent = nullptr;
330     auto sptr5 = std::make_shared<NotificationContent>(multiLineContent);
331     EXPECT_NE(sptr5, nullptr);
332     std::shared_ptr<NotificationMediaContent> mediaContent = nullptr;
333     auto sptr6 = std::make_shared<NotificationContent>(mediaContent);
334     EXPECT_NE(sptr6, nullptr);
335 }
336 
337 /**
338  * @tc.name: ToJson_00002
339  * @tc.desc: Test ToJson parameters.
340  * @tc.type: FUNC
341  * @tc.require: issue
342  */
343 HWTEST_F(NotificationContentTest, ToJson_00002, Function | SmallTest | Level1)
344 {
345     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
346     EXPECT_NE(normalContent, nullptr);
347     NotificationContent notificationContent(normalContent);
348 
349     nlohmann::json jsonObject = nlohmann::json{
350         {"processName", "process6"}, {"APL", 1},
351         {"version", 2}, {"tokenId", 685266937},
352         {"tokenAttr", 0},
353         {"dcaps", {"AT_CAP", "ST_CAP"}}};
354     bool result2 = notificationContent.ToJson(jsonObject);
355     EXPECT_EQ(result2, true);
356 }
357 
358 /**
359  * @tc.name: NotificationBasicContentReadFromJson_00001
360  * @tc.desc: GetAdditionalText
361  * @tc.type: FUNC
362  * @tc.require: issueI5S0ZS
363  */
HWTEST_F(NotificationContentTest,NotificationBasicContentReadFromJson_00001,Level1)364 HWTEST_F(NotificationContentTest, NotificationBasicContentReadFromJson_00001, Level1)
365 {
366     auto notificationBasicContent = std::make_shared<NotificationBasicContent>();
367     nlohmann::json jsonObject = nlohmann::json{
368         {"text", "test"},
369         {"title", "test"},
370         {"additionalText", "test"}};
371     notificationBasicContent->ReadFromJson(jsonObject);
372     EXPECT_NE(notificationBasicContent, nullptr);
373 }
374 }
375 }
376