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