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_icon_button.h" 20 #include "ans_image_util.h" 21 22 using namespace testing::ext; 23 namespace OHOS { 24 namespace Notification { 25 class NotificationIconButtonTest : 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 HWTEST_F(NotificationIconButtonTest, ToJson_00001, Function | SmallTest | Level1) 34 { 35 nlohmann::json jsonObject; 36 auto rrc = std::make_shared<NotificationIconButton>(); 37 rrc->SetText("text"); 38 rrc->SetName("name"); 39 rrc->SetHidePanel(true); 40 auto resource = std::make_shared<ResourceManager::Resource>(); 41 resource->id = 1; 42 resource->bundleName = "bundleName"; 43 resource->moduleName = "moduleName"; 44 rrc->SetIconResource(resource); 45 std::shared_ptr<Media::PixelMap> iconImage = std::make_shared<Media::PixelMap>(); 46 rrc->SetIconImage(iconImage); 47 EXPECT_EQ(rrc->ToJson(jsonObject), true); 48 } 49 50 HWTEST_F(NotificationIconButtonTest, ToJson_00002_With_PixelMap, Function | SmallTest | Level1) 51 { 52 nlohmann::json jsonObject; 53 auto rrc = std::make_shared<NotificationIconButton>(); 54 rrc->SetText("text"); 55 rrc->SetName("name"); 56 rrc->SetHidePanel(true); 57 std::shared_ptr<Media::PixelMap> iconImage = std::make_shared<Media::PixelMap>(); 58 rrc->SetIconImage(iconImage); 59 EXPECT_EQ(rrc->ToJson(jsonObject), true); 60 } 61 62 HWTEST_F(NotificationIconButtonTest, ToJson_With_Res, Function | SmallTest | Level1) 63 { 64 nlohmann::json jsonObject; 65 auto rrc = std::make_shared<NotificationIconButton>(); 66 rrc->SetText("text"); 67 rrc->SetName("name"); 68 rrc->SetHidePanel(true); 69 auto resource = std::make_shared<ResourceManager::Resource>(); 70 resource->id = 1; 71 resource->bundleName = "bundleName"; 72 resource->moduleName = "moduleName"; 73 rrc->SetIconResource(resource); 74 EXPECT_EQ(rrc->ToJson(jsonObject), true); 75 } 76 77 HWTEST_F(NotificationIconButtonTest, ToJson_Without_All, Function | SmallTest | Level1) 78 { 79 nlohmann::json jsonObject; 80 auto rrc = std::make_shared<NotificationIconButton>(); 81 EXPECT_EQ(rrc->ToJson(jsonObject), true); 82 } 83 84 /** 85 * @tc.name: FromJson_00001 86 * @tc.desc: Test FromJson parameters. 87 * @tc.type: FUNC 88 * @tc.require: issue 89 */ 90 HWTEST_F(NotificationIconButtonTest, FromJson_00001, Function | SmallTest | Level1) 91 { 92 auto rrc = std::make_shared<NotificationIconButton>(); 93 nlohmann::json jsonObject = nlohmann::json{"testjson"}; 94 EXPECT_EQ(jsonObject.is_object(), false); 95 EXPECT_EQ(rrc->FromJson(jsonObject), nullptr); 96 } 97 98 /** 99 * @tc.name: FromJson_00002 100 * @tc.desc: Test FromJson parameters. 101 * @tc.type: FUNC 102 * @tc.require: issue 103 */ 104 HWTEST_F(NotificationIconButtonTest, FromJson_00002, Function | SmallTest | Level1) 105 { 106 auto rrc = std::make_shared<NotificationIconButton>(); 107 nlohmann::json jsonObject = nlohmann::json{{"names", {"test"}}, {"icons", {}}}; 108 EXPECT_EQ(jsonObject.is_object(), true); 109 EXPECT_NE(rrc->FromJson(jsonObject), nullptr); 110 } 111 112 /** 113 * @tc.name: FromJson_00003 114 * @tc.desc: Test FromJson parameters. 115 * @tc.type: FUNC 116 * @tc.require: issue 117 */ 118 HWTEST_F(NotificationIconButtonTest, FromJson_00003, Function | SmallTest | Level1) 119 { 120 auto rrc = std::make_shared<NotificationIconButton>(); 121 nlohmann::json jsonObject = nlohmann::json{{"names", {"test"}}, {"icons", {1, "testIcons"}}}; 122 EXPECT_EQ(jsonObject.is_object(), true); 123 EXPECT_NE(rrc->FromJson(jsonObject), nullptr); 124 } 125 126 /** 127 * @tc.name: Marshalling_00002 128 * @tc.desc: Test Marshalling parameters. 129 * @tc.type: FUNC 130 * @tc.require: issueI5WBBH 131 */ 132 HWTEST_F(NotificationIconButtonTest, Marshalling_00002, Function | SmallTest | Level1) 133 { 134 Parcel parcel; 135 auto button = std::make_shared<NotificationIconButton>(); 136 button->SetText("test"); 137 EXPECT_EQ(button->Marshalling(parcel), true); 138 } 139 140 /** 141 * @tc.name: Marshalling_00001 142 * @tc.desc: Test Marshalling parameters. 143 * @tc.type: FUNC 144 * @tc.require: issueI5WBBH 145 */ 146 HWTEST_F(NotificationIconButtonTest, Marshalling_00001, Function | SmallTest | Level1) 147 { 148 Parcel parcel; 149 auto rrc = std::make_shared<NotificationIconButton>(); 150 EXPECT_EQ(rrc->Marshalling(parcel), true); 151 } 152 153 /** 154 * @tc.name: Unmarshalling_00001 155 * @tc.desc: Test Unmarshalling parameters. 156 * @tc.type: FUNC 157 * @tc.require: issueI5WBBH 158 */ 159 HWTEST_F(NotificationIconButtonTest, Unmarshalling_00001, Function | SmallTest | Level1) 160 { 161 bool unmarshalling = true; 162 Parcel parcel; 163 std::shared_ptr<NotificationIconButton> result = 164 std::make_shared<NotificationIconButton>(); 165 166 if (nullptr != result) { 167 if (nullptr == result->Unmarshalling(parcel)) { 168 unmarshalling = false; 169 } 170 } 171 EXPECT_EQ(unmarshalling, false); 172 } 173 174 /** 175 * @tc.name: Unmarshalling_00002 176 * @tc.desc: Test Unmarshalling parameters. 177 * @tc.type: FUNC 178 * @tc.require: issueI5WBBH 179 */ 180 HWTEST_F(NotificationIconButtonTest, Unmarshalling_00002, Function | SmallTest | Level1) 181 { 182 Parcel parcel; 183 auto button = std::make_shared<NotificationIconButton>(); 184 button->SetText("testText"); 185 button->SetName("testName"); 186 button->Marshalling(parcel); 187 188 auto newButton = button->Unmarshalling(parcel); 189 EXPECT_NE(newButton, nullptr); 190 } 191 192 193 /** 194 * @tc.name: Dump_00001 195 * @tc.desc: Test Dump. 196 * @tc.type: FUNC 197 * @tc.require: issue 198 */ 199 HWTEST_F(NotificationIconButtonTest, Dump_00001, Function | SmallTest | Level1) 200 { 201 auto rrc = std::make_shared<NotificationIconButton>(); 202 rrc->SetName("test"); 203 EXPECT_EQ(rrc->Dump(), "NotificationIconButton {name = test, text = , hidePanel = 0 }"); 204 } 205 } 206 } 207