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 #include "notification_local_live_view_content.h" 18 19 using namespace testing::ext; 20 namespace OHOS { 21 namespace Notification { 22 class NotificationLocalLiveViewContentTest : public testing::Test { 23 public: SetUpTestCase()24 static void SetUpTestCase() {} TearDownTestCase()25 static void TearDownTestCase() {} SetUp()26 void SetUp() {} TearDown()27 void TearDown() {} 28 }; 29 30 /** 31 * @tc.name: SetTypeCode_00001 32 * @tc.desc: Test SetTypeCode parameters. 33 * @tc.type: FUNC 34 * @tc.require: issue 35 */ 36 HWTEST_F(NotificationLocalLiveViewContentTest, SetTypeCode_00001, Function | SmallTest | Level1) 37 { 38 int32_t typeCode = 1; 39 auto rrc = std::make_shared<NotificationLocalLiveViewContent>(); 40 rrc->SetType(typeCode); 41 EXPECT_EQ(rrc->GetType(), typeCode); 42 } 43 44 45 /** 46 * @tc.name: ToJson_00001 47 * @tc.desc: Test ToJson parameters. 48 * @tc.type: FUNC 49 * @tc.require: issueI5WBBH 50 */ 51 HWTEST_F(NotificationLocalLiveViewContentTest, ToJson_00001, Function | SmallTest | Level1) 52 { 53 nlohmann::json jsonObject; 54 auto rrc = std::make_shared<NotificationLocalLiveViewContent>(); 55 rrc->FromJson(jsonObject); 56 EXPECT_EQ(rrc->ToJson(jsonObject), true); 57 } 58 59 /** 60 * @tc.name: ToJson_00002 61 * @tc.desc: Test ToJson parameters. 62 * @tc.type: FUNC 63 * @tc.require: issue 64 */ 65 HWTEST_F(NotificationLocalLiveViewContentTest, ToJson_00002, Function | SmallTest | Level1) 66 { 67 nlohmann::json jsonObject; 68 auto liveViewContent = std::make_shared<NotificationLocalLiveViewContent>(); 69 NotificationCapsule capsule; 70 capsule.SetTitle("testTitle"); 71 liveViewContent->SetCapsule(capsule); 72 73 NotificationLocalLiveViewButton button; 74 button.addSingleButtonName("test"); 75 liveViewContent->SetButton(button); 76 77 NotificationProgress progress; 78 progress.SetMaxValue(1); 79 liveViewContent->SetProgress(progress); 80 81 NotificationTime time; 82 time.SetInitialTime(1); 83 liveViewContent->SetTime(time); 84 85 liveViewContent->addFlag(0); 86 liveViewContent->ToJson(jsonObject); 87 EXPECT_NE(jsonObject.dump(), ""); 88 } 89 90 /** 91 * @tc.name: FromJson_00001 92 * @tc.desc: Test FromJson parameters. 93 * @tc.type: FUNC 94 * @tc.require: issue 95 */ 96 HWTEST_F(NotificationLocalLiveViewContentTest, FromJson_00001, Function | SmallTest | Level1) 97 { 98 auto rrc = std::make_shared<NotificationLocalLiveViewContent>(); 99 nlohmann::json jsonObject = nlohmann::json{"typeCode", "capsule", "button", "progress", "time"}; 100 rrc->FromJson(jsonObject); 101 EXPECT_EQ(jsonObject.is_object(), false); 102 EXPECT_EQ(rrc->FromJson(jsonObject), NULL); 103 } 104 105 /** 106 * @tc.name: FromJson_00003 107 * @tc.desc: Test FromJson parameters. 108 * @tc.type: FUNC 109 * @tc.require: issue 110 */ 111 HWTEST_F(NotificationLocalLiveViewContentTest, FromJson_00003, Function | SmallTest | Level1) 112 { 113 auto liveViewContent = std::make_shared<NotificationLocalLiveViewContent>(); 114 nlohmann::json jsonObject = nlohmann::json{ 115 {"additionalText", ""}, {"button", ""}, {"capsule", ""}, {"flags", ""}, 116 {"progress", ""}, {"text", ""}, {"time", ""}, {"title", ""}, {"typeCode", 1}}; 117 EXPECT_EQ(jsonObject.is_object(), true); 118 auto *liveView = liveViewContent->FromJson(jsonObject); 119 EXPECT_EQ(liveView->GetType(), 1); 120 } 121 122 /** 123 * @tc.name: Marshalling_00001 124 * @tc.desc: Test Marshalling parameters. 125 * @tc.type: FUNC 126 * @tc.require: issueI5WBBH 127 */ 128 HWTEST_F(NotificationLocalLiveViewContentTest, Marshalling_00001, Function | SmallTest | Level1) 129 { 130 Parcel parcel; 131 auto rrc = std::make_shared<NotificationLocalLiveViewContent>(); 132 EXPECT_EQ(rrc->Marshalling(parcel), true); 133 } 134 135 /** 136 * @tc.name: Unmarshalling_00001 137 * @tc.desc: Test Unmarshalling parameters. 138 * @tc.type: FUNC 139 * @tc.require: issueI5WBBH 140 */ 141 HWTEST_F(NotificationLocalLiveViewContentTest, Unmarshalling_00001, Function | SmallTest | Level1) 142 { 143 bool unmarshalling = true; 144 Parcel parcel; 145 auto result = std::make_shared<NotificationLocalLiveViewContent>(); 146 147 if (nullptr != result) { 148 if (nullptr == result->Unmarshalling(parcel)) { 149 unmarshalling = false; 150 } 151 } 152 EXPECT_EQ(unmarshalling, false); 153 } 154 155 /** 156 * @tc.name: FromJson_00002 157 * @tc.desc: Test FromJson parameters. 158 * @tc.type: FUNC 159 * @tc.require: issue 160 */ 161 HWTEST_F(NotificationLocalLiveViewContentTest, FromJson_00002, Function | SmallTest | Level1) 162 { 163 auto rrc = std::make_shared<NotificationLocalLiveViewContent>(); 164 nlohmann::json jsonObject = nlohmann::json{ 165 {"longText", "test"}, 166 {"expandedTitle", "test"}, 167 {"briefText", "test"}}; 168 EXPECT_NE(rrc->FromJson(jsonObject), nullptr); 169 } 170 171 /** 172 * @tc.name: Unmarshalling_00002 173 * @tc.desc: Test Unmarshalling parameters. 174 * @tc.type: FUNC 175 * @tc.require: issueI5WBBH 176 */ 177 HWTEST_F(NotificationLocalLiveViewContentTest, Unmarshalling_00002, Function | SmallTest | Level1) 178 { 179 Parcel parcel; 180 auto liveViewContent = std::make_shared<NotificationLocalLiveViewContent>(); 181 182 NotificationCapsule capsule; 183 capsule.SetTitle("testTitle"); 184 liveViewContent->SetCapsule(capsule); 185 186 NotificationLocalLiveViewButton button; 187 button.addSingleButtonName("test"); 188 liveViewContent->SetButton(button); 189 190 NotificationProgress progress; 191 progress.SetMaxValue(1); 192 liveViewContent->SetProgress(progress); 193 194 NotificationTime time; 195 time.SetInitialTime(1); 196 liveViewContent->SetTime(time); 197 liveViewContent->addFlag(0); 198 199 liveViewContent->Marshalling(parcel); 200 EXPECT_NE(liveViewContent->Unmarshalling(parcel), nullptr); 201 } 202 203 /** 204 * @tc.name: SetLocalLiveViewContent_00001 205 * @tc.desc: Test Set liveViewContent attribute. 206 * @tc.type: FUNC 207 * @tc.require: issue 208 */ 209 HWTEST_F(NotificationLocalLiveViewContentTest, SetLocalLiveViewContent_00001, Function | SmallTest | Level1) 210 { 211 NotificationCapsule capsule; 212 capsule.SetTitle("testTitle"); 213 auto liveViewContent = std::make_shared<NotificationLocalLiveViewContent>(); 214 liveViewContent->SetCapsule(capsule); 215 EXPECT_EQ(liveViewContent->GetCapsule().GetTitle(), "testTitle"); 216 217 NotificationLocalLiveViewButton button; 218 button.addSingleButtonName("test"); 219 liveViewContent->SetButton(button); 220 EXPECT_EQ(liveViewContent->GetButton().GetAllButtonNames()[0], "test"); 221 222 NotificationProgress progress; 223 progress.SetMaxValue(1); 224 liveViewContent->SetProgress(progress); 225 EXPECT_EQ(liveViewContent->GetProgress().GetMaxValue(), 1); 226 227 NotificationTime time; 228 time.SetInitialTime(1); 229 liveViewContent->SetTime(time); 230 EXPECT_EQ(liveViewContent->GetTime().GetInitialTime(), 1); 231 232 liveViewContent->addFlag(0); 233 EXPECT_EQ(liveViewContent->isFlagExist(1), false); 234 EXPECT_EQ(liveViewContent->isFlagExist(0), true); 235 } 236 237 /** 238 * @tc.name: Dump_00001 239 * @tc.desc: Test Dump. 240 * @tc.type: FUNC 241 * @tc.require: issue 242 */ 243 HWTEST_F(NotificationLocalLiveViewContentTest, Dump_00001, Function | SmallTest | Level1) 244 { 245 NotificationCapsule capsule; 246 capsule.SetTitle("testTitle"); 247 auto liveViewContent = std::make_shared<NotificationLocalLiveViewContent>(); 248 liveViewContent->SetCapsule(capsule); 249 250 NotificationLocalLiveViewButton button; 251 button.addSingleButtonName("test"); 252 liveViewContent->SetButton(button); 253 254 NotificationProgress progress; 255 progress.SetMaxValue(1); 256 liveViewContent->SetProgress(progress); 257 258 NotificationTime time; 259 time.SetInitialTime(1); 260 liveViewContent->SetTime(time); 261 liveViewContent->addFlag(0); 262 263 std::string dumpStr = "NotificationLocalLiveViewContent{ title = , text = , additionalText = , " 264 "lockScreenPicture = null, type = 0, " 265 "capsule = Capsule{ title = testTitle, backgroundColor = , content = , icon = null }, button = , " 266 "progress = Progress{ maxValue = 1, currentValue = 0, isPercentage = 1 }, " 267 "time = Time{ initialTime = 1, isCountDown = 0, isPaused = 0, isInTitle = 0 } }"; 268 EXPECT_EQ(liveViewContent->Dump(), dumpStr); 269 } 270 } 271 } 272