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_multiline_content.h" 21 #undef private 22 #undef protected 23 24 using namespace testing::ext; 25 namespace OHOS { 26 namespace Notification { 27 class NotificationMultiLineContentTest : 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: SetExpandedTitle_00001 37 * @tc.desc: Test SetExpandedTitle parameters. 38 * @tc.type: FUNC 39 * @tc.require: issueI5WBBH 40 */ 41 HWTEST_F(NotificationMultiLineContentTest, SetExpandedTitle_00001, Function | SmallTest | Level1) 42 { 43 std::string exTitle = "ExTitle"; 44 auto rrc = std::make_shared<NotificationMultiLineContent>(); 45 rrc->SetExpandedTitle(exTitle); 46 EXPECT_EQ(rrc->GetExpandedTitle(), exTitle); 47 } 48 49 /** 50 * @tc.name: SetBriefText_00001 51 * @tc.desc: Test SetBriefText parameters. 52 * @tc.type: FUNC 53 * @tc.require: issueI5WBBH 54 */ 55 HWTEST_F(NotificationMultiLineContentTest, SetBriefText_00001, Function | SmallTest | Level1) 56 { 57 std::string briefText = "BriefText"; 58 auto rrc = std::make_shared<NotificationMultiLineContent>(); 59 rrc->SetBriefText(briefText); 60 EXPECT_EQ(rrc->GetBriefText(), briefText); 61 } 62 63 /** 64 * @tc.name: AddSingleLine_00001 65 * @tc.desc: Test AddSingleLine parameters. 66 * @tc.type: FUNC 67 * @tc.require: issueI5WBBH 68 */ 69 HWTEST_F(NotificationMultiLineContentTest, AddSingleLine_00001, Function | SmallTest | Level1) 70 { 71 std::string oneLine = "OneLine"; 72 auto rrc = std::make_shared<NotificationMultiLineContent>(); 73 rrc->AddSingleLine(oneLine); 74 std::vector<std::string> result = rrc->GetAllLines(); 75 EXPECT_EQ(result.size(), 1); 76 } 77 78 /** 79 * @tc.name: Dump_00001 80 * @tc.desc: Test Dump parameters. 81 * @tc.type: FUNC 82 * @tc.require: issueI5WBBH 83 */ 84 HWTEST_F(NotificationMultiLineContentTest, Dump_00001, Function | SmallTest | Level1) 85 { 86 auto rrc = std::make_shared<NotificationMultiLineContent>(); 87 std::string ret = "NotificationMultiLineContent{ title = , text = , " 88 "additionalText = , lockScreenPicture = null, briefText = , expandedTitle = , allLines = [] }"; 89 EXPECT_EQ(rrc->Dump(), ret); 90 } 91 92 /** 93 * @tc.name: ToJson_00001 94 * @tc.desc: Test ToJson parameters. 95 * @tc.type: FUNC 96 * @tc.require: issueI5WBBHI 97 */ 98 HWTEST_F(NotificationMultiLineContentTest, ToJson_00001, Function | SmallTest | Level1) 99 { 100 nlohmann::json jsonObject; 101 auto rrc = std::make_shared<NotificationMultiLineContent>(); 102 rrc->FromJson(jsonObject); 103 EXPECT_EQ(rrc->ToJson(jsonObject), true); 104 } 105 106 /** 107 * @tc.name: Marshalling_00001 108 * @tc.desc: Test Marshalling parameters. 109 * @tc.type: FUNC 110 * @tc.require: issueI5WBBHI 111 */ 112 HWTEST_F(NotificationMultiLineContentTest, Marshalling_00001, Function | SmallTest | Level1) 113 { 114 Parcel parcel; 115 auto rrc = std::make_shared<NotificationMultiLineContent>(); 116 EXPECT_EQ(rrc->Marshalling(parcel), true); 117 } 118 119 /** 120 * @tc.name: Unmarshalling_00001 121 * @tc.desc: Test Unmarshalling parameters. 122 * @tc.type: FUNC 123 * @tc.require: issueI5WBBH 124 */ 125 HWTEST_F(NotificationMultiLineContentTest, Unmarshalling_001, Function | SmallTest | Level1) 126 { 127 bool unmarshalling = true; 128 Parcel parcel; 129 std::shared_ptr<NotificationMultiLineContent> result = 130 std::make_shared<NotificationMultiLineContent>(); 131 132 if (nullptr != result) { 133 if (nullptr == result->Unmarshalling(parcel)) { 134 unmarshalling = false; 135 } 136 } 137 EXPECT_EQ(unmarshalling, false); 138 } 139 140 /** 141 * @tc.name: ReadFromParcel_00001 142 * @tc.desc: Test ReadFromParcel parameters. 143 * @tc.type: FUNC 144 * @tc.require: issueI5WBBH 145 */ 146 HWTEST_F(NotificationMultiLineContentTest, ReadFromParcel_00001, Function | SmallTest | Level1) 147 { 148 Parcel parcel; 149 auto rrc = std::make_shared<NotificationMultiLineContent>(); 150 EXPECT_EQ(rrc->ReadFromParcel(parcel), false); 151 } 152 153 /** 154 * @tc.name: AddSingleLine_00002 155 * @tc.desc: Test AddSingleLine parameters. 156 * @tc.type: FUNC 157 * @tc.require: issueI5WBBH 158 */ 159 HWTEST_F(NotificationMultiLineContentTest, AddSingleLine_00002, Function | SmallTest | Level1) 160 { 161 std::string oneLine = "OneLine"; 162 auto rrc = std::make_shared<NotificationMultiLineContent>(); 163 int max = 7; 164 for (int i = 0; i < max; i++) { 165 rrc->AddSingleLine(oneLine); 166 } 167 std::vector<std::string> result = rrc->GetAllLines(); 168 EXPECT_EQ(result.size(), max); 169 } 170 171 /** 172 * @tc.name: FromJson_00001 173 * @tc.desc: Test FromJson parameters. 174 * @tc.type: FUNC 175 * @tc.require: issueI5WBBHI 176 */ 177 HWTEST_F(NotificationMultiLineContentTest, FromJson_00001, Function | SmallTest | Level1) 178 { 179 nlohmann::json jsonObject = nlohmann::json{ 180 {"expandedTitle", "test"}, 181 {"briefText", "test"}, 182 {"allLines", {"a", "b", "c"}}}; 183 auto rrc = std::make_shared<NotificationMultiLineContent>(); 184 auto res = rrc->FromJson(jsonObject); 185 EXPECT_NE(res, nullptr); 186 } 187 188 /** 189 * @tc.name: FromJson_00002 190 * @tc.desc: Test FromJson parameters. 191 * @tc.type: FUNC 192 * @tc.require: issueI5WBBHI 193 */ 194 HWTEST_F(NotificationMultiLineContentTest, FromJson_00002, Function | SmallTest | Level1) 195 { 196 nlohmann::json jsonObject = nlohmann::json{ 197 {"briefText", "test"}, 198 {"allLines", {"a", "b", "c"}}}; 199 auto rrc = std::make_shared<NotificationMultiLineContent>(); 200 auto res = rrc->FromJson(jsonObject); 201 EXPECT_NE(res, nullptr); 202 } 203 204 /** 205 * @tc.name: FromJson_00003 206 * @tc.desc: Test FromJson parameters. 207 * @tc.type: FUNC 208 * @tc.require: issueI5WBBHI 209 */ 210 HWTEST_F(NotificationMultiLineContentTest, FromJson_00003, Function | SmallTest | Level1) 211 { 212 nlohmann::json jsonObject = nlohmann::json{ 213 {"expandedTitle", "test"}, 214 {"allLines", {"a", "b", "c"}}}; 215 auto rrc = std::make_shared<NotificationMultiLineContent>(); 216 auto res = rrc->FromJson(jsonObject); 217 EXPECT_NE(res, nullptr); 218 } 219 220 /** 221 * @tc.name: FromJson_00004 222 * @tc.desc: Test FromJson parameters. 223 * @tc.type: FUNC 224 * @tc.require: issueI5WBBHI 225 */ 226 HWTEST_F(NotificationMultiLineContentTest, FromJson_00004, Function | SmallTest | Level1) 227 { 228 nlohmann::json jsonObject = nlohmann::json{ 229 {"expandedTitle", "test"}, 230 {"briefText", "test"}}; 231 auto rrc = std::make_shared<NotificationMultiLineContent>(); 232 auto res = rrc->FromJson(jsonObject); 233 EXPECT_NE(res, nullptr); 234 } 235 } 236 }