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_picture_content.h" 21 #undef private 22 #undef protected 23 24 using namespace testing::ext; 25 namespace OHOS { 26 namespace Notification { 27 class NotificationPictureContentTest : 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(NotificationPictureContentTest, SetExpandedTitle_00001, Function | SmallTest | Level1) 42 { 43 std::string exTitle = "ExTitle"; 44 auto rrc = std::make_shared<NotificationPictureContent>(); 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(NotificationPictureContentTest, SetBriefText_00001, Function | SmallTest | Level1) 56 { 57 std::string briefText = "BriefText"; 58 auto rrc = std::make_shared<NotificationPictureContent>(); 59 rrc->SetBriefText(briefText); 60 EXPECT_EQ(rrc->GetBriefText(), briefText); 61 } 62 63 /** 64 * @tc.name: SetBigPicture_00001 65 * @tc.desc: Test SetBigPicture parameters. 66 * @tc.type: FUNC 67 * @tc.require: issueI5WBBH 68 */ 69 HWTEST_F(NotificationPictureContentTest, SetBigPicture_00001, Function | SmallTest | Level1) 70 { 71 std::shared_ptr<Media::PixelMap> bigPicture = std::make_shared<Media::PixelMap>(); 72 auto rrc = std::make_shared<NotificationPictureContent>(); 73 rrc->SetBigPicture(bigPicture); 74 EXPECT_EQ(rrc->GetBigPicture(), bigPicture); 75 } 76 77 /** 78 * @tc.name: Dump_00001 79 * @tc.desc: Test Dump parameters. 80 * @tc.type: FUNC 81 * @tc.require: issueI5WBBH 82 */ 83 HWTEST_F(NotificationPictureContentTest, Dump_00001, Function | SmallTest | Level1) 84 { 85 auto rrc = std::make_shared<NotificationPictureContent>(); 86 std::string ret = "NotificationPictureContent{ title = , text = , " 87 "additionalText = , lockScreenPicture = null, briefText = , expandedTitle = , bigPicture = null }"; 88 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(NotificationPictureContentTest, ToJson_00001, Function | SmallTest | Level1) 99 { 100 nlohmann::json jsonObject; 101 auto rrc = std::make_shared<NotificationPictureContent>(); 102 rrc->FromJson(jsonObject); 103 EXPECT_EQ(rrc->ToJson(jsonObject), true); 104 } 105 106 /** 107 * @tc.name: FromJson_00001 108 * @tc.desc: Test FromJson parameters. 109 * @tc.type: FUNC 110 * @tc.require: issueI5WBBHI 111 */ 112 HWTEST_F(NotificationPictureContentTest, FromJson_00001, Function | SmallTest | Level1) 113 { 114 auto rrc = std::make_shared<NotificationPictureContent>(); 115 116 nlohmann::json jsonObject = nlohmann::json{"processName", "process6", "expandedTitle", "arrivedTime1"}; 117 rrc->FromJson(jsonObject); 118 EXPECT_EQ(jsonObject.is_object(), false); 119 EXPECT_EQ(rrc->FromJson(jsonObject), nullptr); 120 } 121 122 /** 123 * @tc.name: FromJson_00002 124 * @tc.desc: Test FromJson parameters. 125 * @tc.type: FUNC 126 * @tc.require: issueI5WBBHI 127 */ 128 HWTEST_F(NotificationPictureContentTest, FromJson_00002, Function | SmallTest | Level1) 129 { 130 auto rrc = std::make_shared<NotificationPictureContent>(); 131 132 nlohmann::json jsonObject = nlohmann::json{ 133 {"processName", "process6"}, {"APL", 1}, 134 {"version", 2}, {"tokenId", 685266937}, 135 {"tokenAttr", 0}, 136 {"dcaps", {"AT_CAP", "ST_CAP"}}}; 137 rrc->FromJson(jsonObject); 138 EXPECT_EQ(jsonObject.is_object(), true); 139 } 140 141 /** 142 * @tc.name: Marshalling_00001 143 * @tc.desc: Test Marshalling parameters. 144 * @tc.type: FUNC 145 * @tc.require: issueI5WBBHI 146 */ 147 HWTEST_F(NotificationPictureContentTest, Marshalling_00001, Function | SmallTest | Level1) 148 { 149 Parcel parcel; 150 auto rrc = std::make_shared<NotificationPictureContent>(); 151 EXPECT_EQ(rrc->Marshalling(parcel), true); 152 } 153 154 /** 155 * @tc.name: Unmarshalling_00001 156 * @tc.desc: Test Unmarshalling parameters. 157 * @tc.type: FUNC 158 * @tc.require: issueI5WBBH 159 */ 160 HWTEST_F(NotificationPictureContentTest, Unmarshalling_001, Function | SmallTest | Level1) 161 { 162 bool unmarshalling = true; 163 Parcel parcel; 164 std::shared_ptr<NotificationPictureContent> result = 165 std::make_shared<NotificationPictureContent>(); 166 167 if (nullptr != result) { 168 if (nullptr == result->Unmarshalling(parcel)) { 169 unmarshalling = false; 170 } 171 } 172 EXPECT_EQ(unmarshalling, false); 173 } 174 175 /** 176 * @tc.name: ReadFromParcel_00001 177 * @tc.desc: Test ReadFromParcel parameters. 178 * @tc.type: FUNC 179 * @tc.require: issueI5WBBHI 180 */ 181 HWTEST_F(NotificationPictureContentTest, ReadFromParcel_00001, Function | SmallTest | Level1) 182 { 183 Parcel parcel; 184 auto rrc = std::make_shared<NotificationPictureContent>(); 185 EXPECT_EQ(rrc->ReadFromParcel(parcel), false); 186 } 187 188 /** 189 * @tc.name: FromJson_00003 190 * @tc.desc: Test FromJson parameters. 191 * @tc.type: FUNC 192 * @tc.require: issueI5WBBHI 193 */ 194 HWTEST_F(NotificationPictureContentTest, FromJson_00003, Function | SmallTest | Level1) 195 { 196 auto rrc = std::make_shared<NotificationPictureContent>(); 197 198 nlohmann::json jsonObject = nlohmann::json{ 199 {"expandedTitle", "title"}, 200 {"briefText", "test"}, 201 {"bigPicture", "/data/image/1.jpeg"}}; 202 auto res = rrc->FromJson(jsonObject); 203 EXPECT_NE(res, nullptr); 204 } 205 206 /** 207 * @tc.name: Marshalling_00002 208 * @tc.desc: Test Marshalling parameters. 209 * @tc.type: FUNC 210 * @tc.require: issueI5WBBHI 211 */ 212 HWTEST_F(NotificationPictureContentTest, Marshalling_00002, Function | SmallTest | Level1) 213 { 214 Parcel parcel; 215 auto rrc = std::make_shared<NotificationPictureContent>(); 216 auto data = std::make_shared<Media::PixelMap>(); 217 rrc->SetBigPicture(data); 218 rrc->SetExpandedTitle("title"); 219 rrc->SetBriefText("test"); 220 EXPECT_EQ(rrc->Marshalling(parcel), false); 221 EXPECT_EQ(rrc->ReadFromParcel(parcel), false); 222 } 223 } 224 }