1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 
18 #define private public
19 #define protected public
20 #include "notification_long_text_content.h"
21 #undef private
22 #undef protected
23 
24 using namespace testing::ext;
25 namespace OHOS {
26 namespace Notification {
27 class NotificationLongTextContentTest : public testing::Test {
28 public:
SetUpTestCase()29     static void SetUpTestCase() {}
TearDownTestCase()30     static void TearDownTestCase() {}
SetUp()31     void SetUp() {}
TearDown()32     void TearDown() {}
33 };
34 
35 /**
36  * @tc.name: SetLongText_00001
37  * @tc.desc: Test SetLongText parameters.
38  * @tc.type: FUNC
39  * @tc.require: issueI5WBBH
40  */
41 HWTEST_F(NotificationLongTextContentTest, SetLongText_00001, Function | SmallTest | Level1)
42 {
43     std::string longText = "";
44     auto rrc = std::make_shared<NotificationLongTextContent>();
45     rrc->SetLongText(longText);
46     EXPECT_EQ(rrc->GetLongText(), longText);
47 }
48 
49 /**
50  * @tc.name: ToJson_00001
51  * @tc.desc: Test ToJson parameters.
52  * @tc.type: FUNC
53  * @tc.require: issueI5WBBH
54  */
55 HWTEST_F(NotificationLongTextContentTest, ToJson_00001, Function | SmallTest | Level1)
56 {
57     nlohmann::json jsonObject;
58     auto rrc = std::make_shared<NotificationLongTextContent>();
59     rrc->FromJson(jsonObject);
60     EXPECT_EQ(rrc->ToJson(jsonObject), true);
61 }
62 
63 /**
64  * @tc.name: FromJson_00002
65  * @tc.desc: Test FromJson parameters.
66  * @tc.type: FUNC
67  * @tc.require: issue
68  */
69 HWTEST_F(NotificationLongTextContentTest, FromJson_00002, Function | SmallTest | Level1)
70 {
71     auto rrc = std::make_shared<NotificationLongTextContent>();
72     nlohmann::json jsonObject = nlohmann::json{"processName", "longText", "name", "arrivedTime1"};
73     rrc->FromJson(jsonObject);
74     EXPECT_EQ(jsonObject.is_object(), false);
75     EXPECT_EQ(rrc->FromJson(jsonObject), nullptr);
76 }
77 
78 /**
79  * @tc.name: FromJson_00003
80  * @tc.desc: Test FromJson parameters.
81  * @tc.type: FUNC
82  * @tc.require: issue
83  */
84 HWTEST_F(NotificationLongTextContentTest, FromJson_00003, Function | SmallTest | Level1)
85 {
86     auto rrc = std::make_shared<NotificationLongTextContent>();
87     nlohmann::json jsonObject = nlohmann::json{
88         {"processName", "process6"}, {"APL", 1},
89         {"version", 2}, {"tokenId", 685266937},
90         {"tokenAttr", 0},
91         {"dcaps", {"AT_CAP", "ST_CAP"}}};
92     rrc->FromJson(jsonObject);
93     EXPECT_EQ(jsonObject.is_object(), true);
94 }
95 
96 /**
97  * @tc.name: Marshalling_00001
98  * @tc.desc: Test Marshalling parameters.
99  * @tc.type: FUNC
100  * @tc.require: issueI5WBBH
101  */
102 HWTEST_F(NotificationLongTextContentTest, Marshalling_00001, Function | SmallTest | Level1)
103 {
104     Parcel parcel;
105     auto rrc = std::make_shared<NotificationLongTextContent>();
106     EXPECT_EQ(rrc->Marshalling(parcel), true);
107 }
108 
109 /**
110  * @tc.name: Unmarshalling_00001
111  * @tc.desc: Test Unmarshalling parameters.
112  * @tc.type: FUNC
113  * @tc.require: issueI5WBBH
114  */
115 HWTEST_F(NotificationLongTextContentTest, Unmarshalling_001, Function | SmallTest | Level1)
116 {
117     bool unmarshalling = true;
118     Parcel parcel;
119     std::shared_ptr<NotificationLongTextContent> result =
120     std::make_shared<NotificationLongTextContent>();
121 
122     if (nullptr != result) {
123         if (nullptr == result->Unmarshalling(parcel)) {
124             unmarshalling = false;
125         }
126     }
127     EXPECT_EQ(unmarshalling, false);
128 }
129 
130 /**
131  * @tc.name: ReadFromParcel_00001
132  * @tc.desc: Test ReadFromParcel parameters.
133  * @tc.type: FUNC
134  * @tc.require: issueI5WBBH
135  */
136 HWTEST_F(NotificationLongTextContentTest, ReadFromParcel_00001, Function | SmallTest | Level1)
137 {
138     Parcel parcel;
139     auto rrc = std::make_shared<NotificationLongTextContent>();
140     EXPECT_EQ(rrc->ReadFromParcel(parcel), false);
141 }
142 
143 /**
144  * @tc.name: FromJson_00004
145  * @tc.desc: Test FromJson parameters.
146  * @tc.type: FUNC
147  * @tc.require: issue
148  */
149 HWTEST_F(NotificationLongTextContentTest, FromJson_00004, Function | SmallTest | Level1)
150 {
151     auto rrc = std::make_shared<NotificationLongTextContent>();
152     nlohmann::json jsonObject = nlohmann::json{
153         {"longText", "test"},
154         {"expandedTitle", "test"},
155         {"briefText", "test"}};
156     EXPECT_NE(rrc->FromJson(jsonObject), nullptr);
157 }
158 
159 /**
160  * @tc.name: ReadFromParcel_00002
161  * @tc.desc: Test Marshalling parameters.
162  * @tc.type: FUNC
163  * @tc.require: issueI5WBBH
164  */
165 HWTEST_F(NotificationLongTextContentTest, ReadFromParcel_00002, Function | SmallTest | Level1)
166 {
167     Parcel parcel;
168     auto rrc = std::make_shared<NotificationLongTextContent>();
169     rrc->SetExpandedTitle("test");
170     rrc->SetBriefText("test");
171     rrc->SetLongText("test");
172     EXPECT_EQ(rrc->Marshalling(parcel), true);
173     EXPECT_EQ(rrc->ReadFromParcel(parcel), true);
174 }
175 }
176 }