1 /* 2 * Copyright (C) 2024 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 "accessibility_element_info_parcel.h" 18 19 using namespace testing; 20 using namespace testing::ext; 21 22 namespace OHOS { 23 namespace Accessibility { 24 class AccessibilityElementInfoParcelTest : public ::testing::Test { 25 public: AccessibilityElementInfoParcelTest()26 AccessibilityElementInfoParcelTest() 27 {} ~AccessibilityElementInfoParcelTest()28 ~AccessibilityElementInfoParcelTest() 29 {} SetUpTestCase()30 static void SetUpTestCase() 31 { 32 GTEST_LOG_(INFO) << "AccessibilityElementInfoParcelTest Start"; 33 } TearDownTestCase()34 static void TearDownTestCase() 35 { 36 GTEST_LOG_(INFO) << "AccessibilityElementInfoParcelTest End"; 37 } SetUp()38 void SetUp() 39 { 40 GTEST_LOG_(INFO) << "AccessibilityElementInfoParcelTest SetUp() Start"; 41 elementInfo_ = std::make_shared<AccessibilityElementInfo>(); 42 elementInfoParcel_ = std::make_shared<AccessibilityElementInfoParcel>(*elementInfo_); 43 action_ = std::make_shared<AccessibleAction>(); 44 actionParcel_ = std::make_shared<AccessibleActionParcel>(*action_); 45 rangeInfo_ = std::make_shared<RangeInfo>(); 46 rangeInfoParcel_ = std::make_shared<RangeInfoParcel>(*rangeInfo_); 47 gridInfo_ = std::make_shared<GridInfo>(); 48 gridInfoParcel_ = std::make_shared<GridInfoParcel>(*gridInfo_); 49 gridItemInfo_ = std::make_shared<GridItemInfo>(); 50 gridItemInfoParcel_ = std::make_shared<GridItemInfoParcel>(*gridItemInfo_); 51 rect_ = std::make_shared<Rect>(); 52 rectParcel_ = std::make_shared<RectParcel>(*rect_); 53 extraElementInfo_ = std::make_shared<ExtraElementInfo>(); 54 extraElementInfoParcel_ = std::make_shared<ExtraElementInfoParcel>(*extraElementInfo_); 55 GTEST_LOG_(INFO) << "AccessibilityElementInfoParcelTest SetUp() End"; 56 }; TearDown()57 void TearDown() 58 { 59 GTEST_LOG_(INFO) << "AccessibilityElementInfoParcelTest TearDown()"; 60 elementInfo_ = nullptr; 61 elementInfoParcel_ = nullptr; 62 action_ = nullptr; 63 actionParcel_ = nullptr; 64 rangeInfo_ = nullptr; 65 rangeInfoParcel_ = nullptr; 66 gridInfo_ = nullptr; 67 gridInfoParcel_ = nullptr; 68 gridItemInfo_ = nullptr; 69 gridItemInfoParcel_ = nullptr; 70 rect_ = nullptr; 71 rectParcel_ = nullptr; 72 extraElementInfo_ = nullptr; 73 extraElementInfoParcel_ = nullptr; 74 } 75 76 std::shared_ptr<AccessibleAction> action_ = nullptr; 77 std::shared_ptr<AccessibleActionParcel> actionParcel_ = nullptr; 78 std::shared_ptr<RangeInfo> rangeInfo_ = nullptr; 79 std::shared_ptr<RangeInfoParcel> rangeInfoParcel_ = nullptr; 80 std::shared_ptr<GridInfo> gridInfo_ = nullptr; 81 std::shared_ptr<GridInfoParcel> gridInfoParcel_ = nullptr; 82 std::shared_ptr<GridItemInfo> gridItemInfo_ = nullptr; 83 std::shared_ptr<GridItemInfoParcel> gridItemInfoParcel_ = nullptr; 84 std::shared_ptr<Rect> rect_ = nullptr; 85 std::shared_ptr<RectParcel> rectParcel_ = nullptr; 86 std::shared_ptr<AccessibilityElementInfo> elementInfo_ = nullptr; 87 std::shared_ptr<AccessibilityElementInfoParcel> elementInfoParcel_ = nullptr; 88 std::shared_ptr<ExtraElementInfo> extraElementInfo_ = nullptr; 89 std::shared_ptr<ExtraElementInfoParcel> extraElementInfoParcel_ = nullptr; 90 }; 91 92 /** 93 * @tc.number: Element_Info__Marshalling_001 94 * @tc.name: Element_Info_Marshalling 95 * @tc.desc: Test function Marshalling 96 */ 97 HWTEST_F(AccessibilityElementInfoParcelTest, Element_Info_Marshalling_001, TestSize.Level1) 98 { 99 GTEST_LOG_(INFO) << "Element_Info_Marshalling_001 start"; 100 if (!elementInfoParcel_) { 101 GTEST_LOG_(INFO) << "elementInfoParcel_ is null"; 102 return; 103 } 104 105 Parcel parcel; 106 bool ret = elementInfoParcel_->Marshalling(parcel); 107 EXPECT_EQ(ret, true); 108 GTEST_LOG_(INFO) << "Element_Info_Marshalling_001 end"; 109 } 110 111 /** 112 * @tc.number: Element_Info_Unmarshalling_001 113 * @tc.name: Element_Info_Unmarshalling 114 * @tc.desc: Test function Unmarshalling 115 */ 116 HWTEST_F(AccessibilityElementInfoParcelTest, Element_Info_Unmarshalling_001, TestSize.Level1) 117 { 118 GTEST_LOG_(INFO) << "Element_Info_Unmarshalling_001 start"; 119 if (!elementInfoParcel_) { 120 GTEST_LOG_(INFO) << "elementInfoParcel_ is null"; 121 return; 122 } 123 124 Parcel parcel; 125 sptr<AccessibilityElementInfoParcel> elementInfoParcel = elementInfoParcel_->Unmarshalling(parcel); 126 EXPECT_EQ(true, elementInfoParcel == nullptr); 127 GTEST_LOG_(INFO) << "Element_Info_Unmarshalling_001 end"; 128 } 129 130 /** 131 * @tc.number: Rect_Marshalling_001 132 * @tc.name: Rect_Marshalling 133 * @tc.desc: Test function Marshalling 134 */ 135 HWTEST_F(AccessibilityElementInfoParcelTest, Rect_Marshalling_001, TestSize.Level1) 136 { 137 GTEST_LOG_(INFO) << "Rect_Marshalling_001 start"; 138 if (!rectParcel_) { 139 GTEST_LOG_(INFO) << "rectParcel_ is null"; 140 return; 141 } 142 143 Parcel parcel; 144 bool ret = rectParcel_->Marshalling(parcel); 145 EXPECT_EQ(ret, true); 146 GTEST_LOG_(INFO) << "Rect_Marshalling_001 end"; 147 } 148 149 /** 150 * @tc.number: Rect_Unmarshalling_001 151 * @tc.name: Rect__Unmarshalling 152 * @tc.desc: Test function Unmarshalling 153 */ 154 HWTEST_F(AccessibilityElementInfoParcelTest, Rect_Unmarshalling_001, TestSize.Level1) 155 { 156 GTEST_LOG_(INFO) << "Rect_Unmarshalling_001 start"; 157 if (!rectParcel_) { 158 GTEST_LOG_(INFO) << "rectParcel_ is null"; 159 return; 160 } 161 162 Parcel parcel; 163 sptr<RectParcel> rectParcel = rectParcel_->Unmarshalling(parcel); 164 EXPECT_EQ(true, rectParcel == nullptr); 165 GTEST_LOG_(INFO) << "Rect_Unmarshalling_001 end"; 166 } 167 168 /** 169 * @tc.number: Grid_Item_Info_Marshalling_001 170 * @tc.name: Grid_Item_Info_Marshalling 171 * @tc.desc: Test function Marshalling 172 */ 173 HWTEST_F(AccessibilityElementInfoParcelTest, Grid_Item_Info_Marshalling_001, TestSize.Level1) 174 { 175 GTEST_LOG_(INFO) << "Grid_Item_Info_Marshalling_001 start"; 176 if (!gridItemInfoParcel_) { 177 GTEST_LOG_(INFO) << "gridItemInfoParcel_ is null"; 178 return; 179 } 180 181 Parcel parcel; 182 bool ret = gridItemInfoParcel_->Marshalling(parcel); 183 EXPECT_EQ(ret, true); 184 GTEST_LOG_(INFO) << "Grid_Item_Info_Marshalling_001 end"; 185 } 186 187 /** 188 * @tc.number: Grid_Item_Info_Unmarshalling_001 189 * @tc.name: Grid_Item_Info_Unmarshalling 190 * @tc.desc: Test function Unmarshalling 191 */ 192 HWTEST_F(AccessibilityElementInfoParcelTest, Grid_Item_Info_Unmarshalling_001, TestSize.Level1) 193 { 194 GTEST_LOG_(INFO) << "Grid_Item_Info_Unmarshalling_001 start"; 195 if (!gridItemInfoParcel_) { 196 GTEST_LOG_(INFO) << "gridItemInfoParcel_ is null"; 197 return; 198 } 199 200 Parcel parcel; 201 sptr<GridItemInfoParcel> gridItemInfoParcel = gridItemInfoParcel_->Unmarshalling(parcel); 202 EXPECT_EQ(true, gridItemInfoParcel == nullptr); 203 GTEST_LOG_(INFO) << "Grid_Item_Info_Unmarshalling_001 end"; 204 } 205 206 /** 207 * @tc.number: Action_Marshalling_001 208 * @tc.name: Action_Marshalling 209 * @tc.desc: Test function Marshalling 210 */ 211 HWTEST_F(AccessibilityElementInfoParcelTest, Action_Marshalling_001, TestSize.Level1) 212 { 213 GTEST_LOG_(INFO) << "Action_Marshalling_001 start"; 214 if (!actionParcel_) { 215 GTEST_LOG_(INFO) << "actionParcel_ is null"; 216 return; 217 } 218 219 Parcel parcel; 220 bool ret = actionParcel_->Marshalling(parcel); 221 EXPECT_EQ(ret, true); 222 GTEST_LOG_(INFO) << "Action_Marshalling_001 end"; 223 } 224 225 /** 226 * @tc.number: Action_Unmarshalling_001 227 * @tc.name: Action_Unmarshalling 228 * @tc.desc: Test function Unmarshalling 229 */ 230 HWTEST_F(AccessibilityElementInfoParcelTest, Action_Unmarshalling_001, TestSize.Level1) 231 { 232 GTEST_LOG_(INFO) << "Action_Unmarshalling_001 start"; 233 if (!actionParcel_) { 234 GTEST_LOG_(INFO) << "actionParcel_ is null"; 235 return; 236 } 237 238 Parcel parcel; 239 sptr<AccessibleActionParcel> actionParcel = actionParcel_->Unmarshalling(parcel); 240 EXPECT_EQ(true, actionParcel == nullptr); 241 GTEST_LOG_(INFO) << "Action_Unmarshalling_001 end"; 242 } 243 244 /** 245 * @tc.number: Range_Info_Marshalling_001 246 * @tc.name: Range_Info_Marshalling 247 * @tc.desc: Test function Marshalling 248 */ 249 HWTEST_F(AccessibilityElementInfoParcelTest, Range_Info_Marshalling_001, TestSize.Level1) 250 { 251 GTEST_LOG_(INFO) << "Range_Info_Marshalling_001 start"; 252 if (!rangeInfoParcel_) { 253 GTEST_LOG_(INFO) << "rangeInfoParcel_ is null"; 254 return; 255 } 256 257 Parcel parcel; 258 bool ret = rangeInfoParcel_->Marshalling(parcel); 259 EXPECT_EQ(ret, true); 260 GTEST_LOG_(INFO) << "Range_Info_Marshalling_001 end"; 261 } 262 263 /** 264 * @tc.number: Range_Info_Unmarshalling_001 265 * @tc.name: Range_Info_Unmarshalling 266 * @tc.desc: Test function Unmarshalling 267 */ 268 HWTEST_F(AccessibilityElementInfoParcelTest, Range_Info_Unmarshalling_001, TestSize.Level1) 269 { 270 GTEST_LOG_(INFO) << "Range_Info_Unmarshalling_001 start"; 271 if (!rangeInfoParcel_) { 272 GTEST_LOG_(INFO) << "rangeInfoParcel_ is null"; 273 return; 274 } 275 276 Parcel parcel; 277 sptr<RangeInfoParcel> rangeInfoParcel = rangeInfoParcel_->Unmarshalling(parcel); 278 EXPECT_EQ(true, rangeInfoParcel == nullptr); 279 GTEST_LOG_(INFO) << "Range_Info_Unmarshalling_001 end"; 280 } 281 282 /** 283 * @tc.number: Grid_Info_Marshalling_001 284 * @tc.name: Grid_Info_Marshalling 285 * @tc.desc: Test function Marshalling 286 */ 287 HWTEST_F(AccessibilityElementInfoParcelTest, Grid_Info_Marshalling_001, TestSize.Level1) 288 { 289 GTEST_LOG_(INFO) << "Grid_Info_Marshalling_001 start"; 290 if (!gridInfoParcel_) { 291 GTEST_LOG_(INFO) << "gridInfoParcel_ is null"; 292 return; 293 } 294 295 Parcel parcel; 296 bool ret = gridInfoParcel_->Marshalling(parcel); 297 EXPECT_EQ(ret, true); 298 GTEST_LOG_(INFO) << "Grid_Info_Marshalling_001 end"; 299 } 300 301 /** 302 * @tc.number: Grid_Info_Unmarshalling_001 303 * @tc.name: Grid_Info_Unmarshalling 304 * @tc.desc: Test function Unmarshalling 305 */ 306 HWTEST_F(AccessibilityElementInfoParcelTest, Grid_Info_Unmarshalling_001, TestSize.Level1) 307 { 308 GTEST_LOG_(INFO) << "Grid_Info_Unmarshalling_001 start"; 309 if (!gridInfoParcel_) { 310 GTEST_LOG_(INFO) << "gridInfoParcel_ is null"; 311 return; 312 } 313 314 Parcel parcel; 315 sptr<GridInfoParcel> gridInfoParcel = gridInfoParcel_->Unmarshalling(parcel); 316 EXPECT_EQ(true, gridInfoParcel == nullptr); 317 GTEST_LOG_(INFO) << "Grid_Info_Unmarshalling_001 end"; 318 } 319 320 /** 321 * @tc.number: Extra_Element_Info_Parcel__001 322 * @tc.name: Extra_Element_Info_Parcel 323 * @tc.desc: Test function ReadFromParcel 324 */ 325 HWTEST_F(AccessibilityElementInfoParcelTest, Extra_Element_Info_Parcel__001, TestSize.Level1) 326 { 327 GTEST_LOG_(INFO) << "Extra_Element_Info_Parcel__001 start"; 328 if (!extraElementInfoParcel_) { 329 GTEST_LOG_(INFO) << "extraElementInfoParcel_ is null"; 330 return; 331 } 332 333 Parcel parcel; 334 EXPECT_EQ(false, extraElementInfoParcel_->ReadFromParcel(parcel)); 335 GTEST_LOG_(INFO) << "Extra_Element_Info_Parcel__001 end"; 336 } 337 338 /** 339 * @tc.number: Extra_Element_Info_Parcel__002 340 * @tc.name: Extra_Element_Info_Parcel 341 * @tc.desc: Test function Unmarshalling 342 */ 343 HWTEST_F(AccessibilityElementInfoParcelTest, Extra_Element_Info_Parcel__002, TestSize.Level1) 344 { 345 GTEST_LOG_(INFO) << "Extra_Element_Info_Parcel__002 start"; 346 if (!extraElementInfoParcel_) { 347 GTEST_LOG_(INFO) << "extraElementInfoParcel_ is null"; 348 return; 349 } 350 351 Parcel parcel; 352 sptr<ExtraElementInfoParcel> extraElementInfoParcel = extraElementInfoParcel_->Unmarshalling(parcel); 353 EXPECT_EQ(true, extraElementInfoParcel == nullptr); 354 GTEST_LOG_(INFO) << "Extra_Element_Info_Parcel__002 end"; 355 } 356 } // namespace Accessibility 357 } // namespace OHOS