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 <string> 18 #include <unistd.h> 19 #include "notification_local_live_view_button.h" 20 #include "ans_image_util.h" 21 22 using namespace testing::ext; 23 namespace OHOS { 24 namespace Notification { 25 class NotificationLocalLiveViewButtonTest : public testing::Test { 26 public: SetUpTestCase()27 static void SetUpTestCase() {} TearDownTestCase()28 static void TearDownTestCase() {} SetUp()29 void SetUp() {} TearDown()30 void TearDown() {} 31 }; 32 33 /** 34 * @tc.name: AddSingleButtonName_00001 35 * @tc.desc: Test buttonNames_ parameters. 36 * @tc.type: FUNC 37 * @tc.require: issue 38 */ 39 HWTEST_F(NotificationLocalLiveViewButtonTest, AddSingleButtonName_00001, Function | SmallTest | Level1) 40 { 41 std::string buttonName = "testOneButton"; 42 auto rrc = std::make_shared<NotificationLocalLiveViewButton>(); 43 rrc->addSingleButtonName(buttonName); 44 EXPECT_EQ(rrc->GetAllButtonNames()[0], buttonName); 45 } 46 47 /** 48 * @tc.name: AddSingleButtonName_00002 49 * @tc.desc: Test buttonNames_ parameters. 50 * @tc.type: FUNC 51 * @tc.require: issue 52 */ 53 HWTEST_F(NotificationLocalLiveViewButtonTest, AddSingleButtonName_00002, Function | SmallTest | Level1) 54 { 55 std::string buttonName = "testOneButton"; 56 auto rrc = std::make_shared<NotificationLocalLiveViewButton>(); 57 rrc->addSingleButtonName(buttonName); 58 EXPECT_EQ(rrc->GetAllButtonNames().size(), 1); 59 } 60 61 /** 62 * @tc.name: AddSingleButtonName_00003 63 * @tc.desc: Test buttonNames_ parameters. 64 * @tc.type: FUNC 65 * @tc.require: issue 66 */ 67 HWTEST_F(NotificationLocalLiveViewButtonTest, AddSingleButtonName_00003, Function | SmallTest | Level1) 68 { 69 std::string buttonNameOne = "testOneButton"; 70 std::string buttonNameTwo = "testTwoButton"; 71 std::string buttonNameThree = "testThreeButton"; 72 std::string buttonNameFour = "testFourButton"; 73 auto rrc = std::make_shared<NotificationLocalLiveViewButton>(); 74 rrc->addSingleButtonName(buttonNameOne); 75 rrc->addSingleButtonName(buttonNameTwo); 76 rrc->addSingleButtonName(buttonNameThree); 77 rrc->addSingleButtonName(buttonNameFour); 78 EXPECT_EQ(rrc->GetAllButtonNames().size(), 3); 79 } 80 81 /** 82 * @tc.name: addSingleButtonIcon_00001 83 * @tc.desc: Test buttonNames_ parameters. 84 * @tc.type: FUNC 85 * @tc.require: issue 86 */ 87 HWTEST_F(NotificationLocalLiveViewButtonTest, addSingleButtonIcon_00001, Function | SmallTest | Level1) 88 { 89 auto pixelMapOne = std::make_shared<Media::PixelMap>(); 90 auto pixelMapTwo = std::make_shared<Media::PixelMap>(); 91 auto pixelMapThree = std::make_shared<Media::PixelMap>(); 92 auto pixelMapFour = std::make_shared<Media::PixelMap>(); 93 auto rrc = std::make_shared<NotificationLocalLiveViewButton>(); 94 rrc->addSingleButtonIcon(pixelMapOne); 95 rrc->addSingleButtonIcon(pixelMapTwo); 96 rrc->addSingleButtonIcon(pixelMapThree); 97 rrc->addSingleButtonIcon(pixelMapFour); 98 99 EXPECT_EQ(rrc->GetAllButtonIcons().size(), 3); 100 } 101 102 /** 103 * @tc.name: ToJson_00001 104 * @tc.desc: Test ToJson parameters. 105 * @tc.type: FUNC 106 * @tc.require: issueI5WBBH 107 */ 108 HWTEST_F(NotificationLocalLiveViewButtonTest, ToJson_00001, Function | SmallTest | Level1) 109 { 110 nlohmann::json jsonObject; 111 auto rrc = std::make_shared<NotificationLocalLiveViewButton>(); 112 rrc->FromJson(jsonObject); 113 EXPECT_EQ(rrc->ToJson(jsonObject), true); 114 } 115 116 /** 117 * @tc.name: ToJson_00002 118 * @tc.desc: Test ToJson parameters. 119 * @tc.type: FUNC 120 * @tc.require: issueI5WBBH 121 */ 122 HWTEST_F(NotificationLocalLiveViewButtonTest, ToJson_00002, Function | SmallTest | Level1) 123 { 124 nlohmann::json jsonObject; 125 auto button = std::make_shared<NotificationLocalLiveViewButton>(); 126 auto pixelMap = std::make_shared<Media::PixelMap>(); 127 button->addSingleButtonIcon(pixelMap); 128 129 EXPECT_EQ(button->ToJson(jsonObject), true); 130 } 131 132 /** 133 * @tc.name: FromJson_00001 134 * @tc.desc: Test FromJson parameters. 135 * @tc.type: FUNC 136 * @tc.require: issue 137 */ 138 HWTEST_F(NotificationLocalLiveViewButtonTest, FromJson_00001, Function | SmallTest | Level1) 139 { 140 auto rrc = std::make_shared<NotificationLocalLiveViewButton>(); 141 nlohmann::json jsonObject = nlohmann::json{"test"}; 142 EXPECT_EQ(jsonObject.is_object(), false); 143 EXPECT_EQ(rrc->FromJson(jsonObject), nullptr); 144 } 145 146 /** 147 * @tc.name: FromJson_00002 148 * @tc.desc: Test FromJson parameters. 149 * @tc.type: FUNC 150 * @tc.require: issue 151 */ 152 HWTEST_F(NotificationLocalLiveViewButtonTest, FromJson_00002, Function | SmallTest | Level1) 153 { 154 auto rrc = std::make_shared<NotificationLocalLiveViewButton>(); 155 nlohmann::json jsonObject = nlohmann::json{{"names", {"test"}}, {"icons", {}}}; 156 EXPECT_EQ(jsonObject.is_object(), true); 157 EXPECT_NE(rrc->FromJson(jsonObject), nullptr); 158 } 159 160 /** 161 * @tc.name: FromJson_00003 162 * @tc.desc: Test FromJson parameters. 163 * @tc.type: FUNC 164 * @tc.require: issue 165 */ 166 HWTEST_F(NotificationLocalLiveViewButtonTest, FromJson_00003, Function | SmallTest | Level1) 167 { 168 auto rrc = std::make_shared<NotificationLocalLiveViewButton>(); 169 nlohmann::json jsonObject = nlohmann::json{{"names", {"test"}}, {"icons", {1, "testIcons"}}}; 170 EXPECT_EQ(jsonObject.is_object(), true); 171 EXPECT_EQ(rrc->FromJson(jsonObject), nullptr); 172 } 173 174 /** 175 * @tc.name: Marshalling_00002 176 * @tc.desc: Test Marshalling parameters. 177 * @tc.type: FUNC 178 * @tc.require: issueI5WBBH 179 */ 180 HWTEST_F(NotificationLocalLiveViewButtonTest, Marshalling_00002, Function | SmallTest | Level1) 181 { 182 Parcel parcel; 183 auto button = std::make_shared<NotificationLocalLiveViewButton>(); 184 button->addSingleButtonName("test"); 185 auto pixelMap = std::make_shared<Media::PixelMap>(); 186 button->addSingleButtonIcon(pixelMap); 187 188 EXPECT_EQ(button->Marshalling(parcel), false); 189 } 190 191 /** 192 * @tc.name: Marshalling_00001 193 * @tc.desc: Test Marshalling parameters. 194 * @tc.type: FUNC 195 * @tc.require: issueI5WBBH 196 */ 197 HWTEST_F(NotificationLocalLiveViewButtonTest, Marshalling_00001, Function | SmallTest | Level1) 198 { 199 Parcel parcel; 200 auto rrc = std::make_shared<NotificationLocalLiveViewButton>(); 201 EXPECT_EQ(rrc->Marshalling(parcel), true); 202 } 203 204 /** 205 * @tc.name: Unmarshalling_00001 206 * @tc.desc: Test Unmarshalling parameters. 207 * @tc.type: FUNC 208 * @tc.require: issueI5WBBH 209 */ 210 HWTEST_F(NotificationLocalLiveViewButtonTest, Unmarshalling_00001, Function | SmallTest | Level1) 211 { 212 bool unmarshalling = true; 213 Parcel parcel; 214 std::shared_ptr<NotificationLocalLiveViewButton> result = 215 std::make_shared<NotificationLocalLiveViewButton>(); 216 217 if (nullptr != result) { 218 if (nullptr == result->Unmarshalling(parcel)) { 219 unmarshalling = false; 220 } 221 } 222 EXPECT_EQ(unmarshalling, true); 223 } 224 225 /** 226 * @tc.name: Unmarshalling_00002 227 * @tc.desc: Test Unmarshalling parameters. 228 * @tc.type: FUNC 229 * @tc.require: issueI5WBBH 230 */ 231 HWTEST_F(NotificationLocalLiveViewButtonTest, Unmarshalling_00002, Function | SmallTest | Level1) 232 { 233 Parcel parcel; 234 auto button = std::make_shared<NotificationLocalLiveViewButton>(); 235 button->addSingleButtonName("test"); 236 button->Marshalling(parcel); 237 238 auto newButton = button->Unmarshalling(parcel); 239 EXPECT_NE(newButton, nullptr); 240 } 241 242 /** 243 * @tc.name: Unmarshalling_00003 244 * @tc.desc: Test Unmarshalling parameters. 245 * @tc.type: FUNC 246 * @tc.require: issueI5WBBH 247 */ 248 HWTEST_F(NotificationLocalLiveViewButtonTest, Unmarshalling_00003, Function | SmallTest | Level1) 249 { 250 Parcel parcel; 251 auto button = std::make_shared<NotificationLocalLiveViewButton>(); 252 std::shared_ptr<Media::PixelMap> icon = std::make_shared<Media::PixelMap>(); 253 button->addSingleButtonName("test"); 254 button->addSingleButtonIcon(icon); 255 button->Marshalling(parcel); 256 257 auto newButton = button->Unmarshalling(parcel); 258 EXPECT_EQ(newButton, nullptr); 259 } 260 261 /** 262 * @tc.name: Dump_00001 263 * @tc.desc: Test Dump. 264 * @tc.type: FUNC 265 * @tc.require: issue 266 */ 267 HWTEST_F(NotificationLocalLiveViewButtonTest, Dump_00001, Function | SmallTest | Level1) 268 { 269 auto rrc = std::make_shared<NotificationLocalLiveViewButton>(); 270 271 EXPECT_EQ(rrc->Dump(), ""); 272 } 273 } 274 } 275