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 <memory> 18 #include "accessibility_event_info.h" 19 20 using namespace testing; 21 using namespace testing::ext; 22 23 namespace OHOS { 24 namespace Accessibility { 25 constexpr int64_t TIMESTAMP = 6000; 26 constexpr uint32_t RESOURCE_ID = 12345; 27 constexpr int64_t SOURCE_ID = 1001; 28 constexpr int32_t WINDOW_ID = 1002; 29 constexpr int32_t CURRENT_INDEX = 1; 30 constexpr int32_t BEGIN_INDEX = 1; 31 constexpr int32_t END_INDEX = 1; 32 constexpr int32_t ITEM_COUNTS = 1; 33 constexpr int32_t REQUEST_FOCUS_ELEMENT_ID = 1; 34 const std::string RESOURCE_MODULE_NAME = "accessibilityResourceModuleNameTest"; 35 const std::string RESOURCE_BUNDLE_NAME = "accessibilityResourceBundleNameTest"; 36 const std::string BUNDLE_NAME = "accessibilityBundleNameTest"; 37 const std::string NOTIFICATION_CONTENT = "notificationContent"; 38 const std::string COMPONENT_TYPE = "text"; 39 const std::string BEFORE_TEXT = "accessibility"; 40 const std::string LATEST_CONTENT = "lastContext"; 41 const std::string DESCRIPTION = "descripion"; 42 const std::string TEXT_ANNOUNCED_FOR_ACCESSIBILITY = "textAnnouncedForAccessibility"; 43 const std::string INSPECTOR_KEY = "inspectorKey"; 44 const std::vector<std::string> CONTENT_LIST = {"content1", "content2"}; 45 46 class AccessibilityEventInfoUnitTest : public ::testing::Test { 47 public: AccessibilityEventInfoUnitTest()48 AccessibilityEventInfoUnitTest() 49 {} ~AccessibilityEventInfoUnitTest()50 ~AccessibilityEventInfoUnitTest() 51 {} SetUpTestCase()52 static void SetUpTestCase() 53 { 54 GTEST_LOG_(INFO) << "AccessibilityEventInfoUnitTest Start"; 55 } TearDownTestCase()56 static void TearDownTestCase() 57 { 58 GTEST_LOG_(INFO) << "AccessibilityEventInfoUnitTest End"; 59 } SetUp()60 void SetUp() 61 { 62 GTEST_LOG_(INFO) << "AccessibilityEventInfoUnitTest SetUp() Start"; 63 eventInfo_ = std::make_shared<AccessibilityEventInfo>(); 64 GTEST_LOG_(INFO) << "AccessibilityEventInfoUnitTest SetUp() End"; 65 }; TearDown()66 void TearDown() 67 { 68 GTEST_LOG_(INFO) << "AccessibilityEventInfoUnitTest TearDown()"; 69 eventInfo_ = nullptr; 70 } 71 72 std::shared_ptr<AccessibilityEventInfo> eventInfo_ = nullptr; 73 }; 74 75 /** 76 * @tc.number: SetWindowChangeTypes_001 77 * @tc.name: SetWindowChangeTypes 78 * @tc.desc: Test function SetWindowChangeTypes 79 */ 80 HWTEST_F(AccessibilityEventInfoUnitTest, SetWindowChangeTypes_001, TestSize.Level1) 81 { 82 GTEST_LOG_(INFO) << "SetWindowChangeTypes_001 start"; 83 if (!eventInfo_) { 84 GTEST_LOG_(INFO) << "eventInfo_ is null"; 85 } else { 86 eventInfo_->SetWindowChangeTypes(WindowUpdateType::WINDOW_UPDATE_ACTIVE); 87 EXPECT_EQ(eventInfo_->GetWindowChangeTypes(), WindowUpdateType::WINDOW_UPDATE_ACTIVE); 88 } 89 GTEST_LOG_(INFO) << "SetWindowChangeTypes_001 end"; 90 } 91 92 /** 93 * @tc.number: SetEventType_001 94 * @tc.name: SetEventType 95 * @tc.desc: Test function SetEventType 96 */ 97 HWTEST_F(AccessibilityEventInfoUnitTest, SetEventType_001, TestSize.Level1) 98 { 99 GTEST_LOG_(INFO) << "SetEventType_001 start"; 100 if (!eventInfo_) { 101 GTEST_LOG_(INFO) << "eventInfo_ is null"; 102 } else { 103 eventInfo_->SetEventType(EventType::TYPE_PAGE_CONTENT_UPDATE); 104 EXPECT_EQ(eventInfo_->GetEventType(), EventType::TYPE_PAGE_CONTENT_UPDATE); 105 } 106 GTEST_LOG_(INFO) << "SetEventType_001 end"; 107 } 108 109 /** 110 * @tc.number: SetWindowContentChangeTypes_001 111 * @tc.name: SetWindowContentChangeTypes 112 * @tc.desc: Test function SetWindowContentChangeTypes 113 */ 114 HWTEST_F(AccessibilityEventInfoUnitTest, SetWindowContentChangeTypes_001, TestSize.Level1) 115 { 116 GTEST_LOG_(INFO) << "SetWindowContentChangeTypes_001 start"; 117 if (!eventInfo_) { 118 GTEST_LOG_(INFO) << "eventInfo_ is null"; 119 } else { 120 eventInfo_->SetWindowContentChangeTypes(WindowsContentChangeTypes::CONTENT_CHANGE_TYPE_TEXT); 121 EXPECT_EQ(eventInfo_->GetWindowContentChangeTypes(), WindowsContentChangeTypes::CONTENT_CHANGE_TYPE_TEXT); 122 } 123 GTEST_LOG_(INFO) << "SetWindowContentChangeTypes_001 end"; 124 } 125 126 /** 127 * @tc.number: SetTimeStamp_001 128 * @tc.name: SetTimeStamp 129 * @tc.desc: Test function SetTimeStamp 130 */ 131 HWTEST_F(AccessibilityEventInfoUnitTest, SetTimeStamp_001, TestSize.Level1) 132 { 133 GTEST_LOG_(INFO) << "SetTimeStamp_001 start"; 134 if (!eventInfo_) { 135 GTEST_LOG_(INFO) << "eventInfo_ is null"; 136 } else { 137 eventInfo_->SetTimeStamp(TIMESTAMP); 138 EXPECT_EQ(eventInfo_->GetTimeStamp(), TIMESTAMP); 139 } 140 GTEST_LOG_(INFO) << "SetTimeStamp_001 end"; 141 } 142 143 /** 144 * @tc.number: SetResourceId_001 145 * @tc.name: SetResourceId 146 * @tc.desc: Test function SetResourceId 147 */ 148 HWTEST_F(AccessibilityEventInfoUnitTest, SetResourceId_001, TestSize.Level1) 149 { 150 GTEST_LOG_(INFO) << "SetResourceId_001 start"; 151 if (!eventInfo_) { 152 GTEST_LOG_(INFO) << "eventInfo_ is null"; 153 } else { 154 eventInfo_->SetResourceId(RESOURCE_ID); 155 EXPECT_EQ(eventInfo_->GetResourceId(), RESOURCE_ID); 156 } 157 GTEST_LOG_(INFO) << "SetResourceId_001 end"; 158 } 159 160 /** 161 * @tc.number: SetResourceModuleName_001 162 * @tc.name: SetResourceModuleName 163 * @tc.desc: Test function SetResourceModuleName 164 */ 165 HWTEST_F(AccessibilityEventInfoUnitTest, SetResourceModuleName_001, TestSize.Level1) 166 { 167 GTEST_LOG_(INFO) << "SetResourceModuleName_001 start"; 168 if (!eventInfo_) { 169 GTEST_LOG_(INFO) << "eventInfo_ is null"; 170 } else { 171 eventInfo_->SetResourceModuleName(RESOURCE_MODULE_NAME); 172 EXPECT_EQ(eventInfo_->GetResourceModuleName(), RESOURCE_MODULE_NAME); 173 } 174 GTEST_LOG_(INFO) << "SetResourceModuleName_001 end"; 175 } 176 177 /** 178 * @tc.number: SetResourceBundleName_001 179 * @tc.name: SetResourceBundleName 180 * @tc.desc: Test function SetResourceBundleName 181 */ 182 HWTEST_F(AccessibilityEventInfoUnitTest, SetResourceBundleName_001, TestSize.Level1) 183 { 184 GTEST_LOG_(INFO) << "SetResourceBundleName_001 start"; 185 if (!eventInfo_) { 186 GTEST_LOG_(INFO) << "eventInfo_ is null"; 187 } else { 188 eventInfo_->SetResourceBundleName(RESOURCE_BUNDLE_NAME); 189 EXPECT_EQ(eventInfo_->GetResourceBundleName(), RESOURCE_BUNDLE_NAME); 190 } 191 GTEST_LOG_(INFO) << "SetResourceBundleName_001 end"; 192 } 193 194 /** 195 * @tc.number: SetBundleName_001 196 * @tc.name: SetBundleName 197 * @tc.desc: Test function SetBundleName 198 */ 199 HWTEST_F(AccessibilityEventInfoUnitTest, SetBundleName_001, TestSize.Level1) 200 { 201 GTEST_LOG_(INFO) << "SetBundleName_001 start"; 202 if (!eventInfo_) { 203 GTEST_LOG_(INFO) << "eventInfo_ is null"; 204 } else { 205 eventInfo_->SetBundleName(BUNDLE_NAME); 206 EXPECT_EQ(eventInfo_->GetBundleName(), BUNDLE_NAME); 207 } 208 GTEST_LOG_(INFO) << "SetBundleName_001 end"; 209 } 210 211 /** 212 * @tc.number: SetNotificationContent_001 213 * @tc.name: SetNotificationContent 214 * @tc.desc: Test function SetNotificationContent 215 */ 216 HWTEST_F(AccessibilityEventInfoUnitTest, SetNotificationContent_001, TestSize.Level1) 217 { 218 GTEST_LOG_(INFO) << "SetNotificationContent_001 start"; 219 if (!eventInfo_) { 220 GTEST_LOG_(INFO) << "eventInfo_ is null"; 221 } else { 222 eventInfo_->SetNotificationContent(NOTIFICATION_CONTENT); 223 EXPECT_EQ(eventInfo_->GetNotificationContent(), NOTIFICATION_CONTENT); 224 } 225 GTEST_LOG_(INFO) << "SetNotificationContent_001 end"; 226 } 227 228 /** 229 * @tc.number: SetTextMovementStep_001 230 * @tc.name: SetTextMovementStep 231 * @tc.desc: Test function SetTextMovementStep 232 */ 233 HWTEST_F(AccessibilityEventInfoUnitTest, SetTextMovementStep_001, TestSize.Level1) 234 { 235 GTEST_LOG_(INFO) << "SetTextMovementStep_001 start"; 236 if (!eventInfo_) { 237 GTEST_LOG_(INFO) << "eventInfo_ is null"; 238 } else { 239 eventInfo_->SetTextMovementStep(TextMoveUnit::STEP_LINE); 240 EXPECT_EQ(eventInfo_->GetTextMovementStep(), TextMoveUnit::STEP_LINE); 241 } 242 GTEST_LOG_(INFO) << "SetTextMovementStep_001 end"; 243 } 244 245 /** 246 * @tc.number: SetTriggerAction_001 247 * @tc.name: SetTriggerAction 248 * @tc.desc: Test function SetTriggerAction 249 */ 250 HWTEST_F(AccessibilityEventInfoUnitTest, SetTriggerAction_001, TestSize.Level1) 251 { 252 GTEST_LOG_(INFO) << "SetTriggerAction_001 start"; 253 if (!eventInfo_) { 254 GTEST_LOG_(INFO) << "eventInfo_ is null"; 255 } else { 256 eventInfo_->SetTriggerAction(ActionType::ACCESSIBILITY_ACTION_CLICK); 257 EXPECT_EQ(eventInfo_->GetTriggerAction(), ActionType::ACCESSIBILITY_ACTION_CLICK); 258 } 259 GTEST_LOG_(INFO) << "SetTriggerAction_001 end"; 260 } 261 262 /** 263 * @tc.number: SetNotificationInfo_001 264 * @tc.name: SetNotificationInfo 265 * @tc.desc: Test function SetNotificationInfo 266 */ 267 HWTEST_F(AccessibilityEventInfoUnitTest, SetNotificationInfo_001, TestSize.Level1) 268 { 269 GTEST_LOG_(INFO) << "SetNotificationInfo_001 start"; 270 if (!eventInfo_) { 271 GTEST_LOG_(INFO) << "eventInfo_ is null"; 272 } else { 273 eventInfo_->SetNotificationInfo(NotificationCategory::CATEGORY_CALL); 274 EXPECT_EQ(eventInfo_->GetNotificationInfo(), NotificationCategory::CATEGORY_CALL); 275 } 276 GTEST_LOG_(INFO) << "SetNotificationInfo_001 end"; 277 } 278 279 /** 280 * @tc.number: SetGestureType_001 281 * @tc.name: SetGestureType 282 * @tc.desc: Test function SetGestureType 283 */ 284 HWTEST_F(AccessibilityEventInfoUnitTest, SetGestureType_001, TestSize.Level1) 285 { 286 GTEST_LOG_(INFO) << "SetGestureType_001 start"; 287 if (!eventInfo_) { 288 GTEST_LOG_(INFO) << "eventInfo_ is null"; 289 } else { 290 eventInfo_->SetGestureType(GestureType::GESTURE_SWIPE_UP); 291 EXPECT_EQ(eventInfo_->GetGestureType(), GestureType::GESTURE_SWIPE_UP); 292 } 293 GTEST_LOG_(INFO) << "SetGestureType_001 end"; 294 } 295 296 /** 297 * @tc.number: SetPageId_001 298 * @tc.name: SetPageId 299 * @tc.desc: Test function SetPageId 300 */ 301 HWTEST_F(AccessibilityEventInfoUnitTest, SetPageId_001, TestSize.Level1) 302 { 303 GTEST_LOG_(INFO) << "SetPageId_001 start"; 304 if (!eventInfo_) { 305 GTEST_LOG_(INFO) << "eventInfo_ is null"; 306 } else { 307 eventInfo_->SetPageId(1); 308 EXPECT_EQ(eventInfo_->GetPageId(), 1); 309 } 310 GTEST_LOG_(INFO) << "SetPageId_001 end"; 311 } 312 313 /** 314 * @tc.number: SetSource_001 315 * @tc.name: SetSource 316 * @tc.desc: Test function SetSource 317 */ 318 HWTEST_F(AccessibilityEventInfoUnitTest, SetSource_001, TestSize.Level1) 319 { 320 GTEST_LOG_(INFO) << "SetSource_001 start"; 321 if (!eventInfo_) { 322 GTEST_LOG_(INFO) << "eventInfo_ is null"; 323 } else { 324 eventInfo_->SetSource(SOURCE_ID); 325 EXPECT_EQ(eventInfo_->GetViewId(), SOURCE_ID); 326 EXPECT_EQ(eventInfo_->GetAccessibilityId(), SOURCE_ID); 327 } 328 GTEST_LOG_(INFO) << "SetSource_001 end"; 329 } 330 331 /** 332 * @tc.number: SetWindowId_001 333 * @tc.name: SetWindowId 334 * @tc.desc: Test function SetWindowId 335 */ 336 HWTEST_F(AccessibilityEventInfoUnitTest, SetWindowId_001, TestSize.Level1) 337 { 338 GTEST_LOG_(INFO) << "SetWindowId_001 start"; 339 if (!eventInfo_) { 340 GTEST_LOG_(INFO) << "eventInfo_ is null"; 341 } else { 342 eventInfo_->SetWindowId(WINDOW_ID); 343 EXPECT_EQ(eventInfo_->GetWindowId(), WINDOW_ID); 344 } 345 GTEST_LOG_(INFO) << "SetWindowId_001 end"; 346 } 347 348 /** 349 * @tc.number: SetCurrentIndex_001 350 * @tc.name: SetCurrentIndex 351 * @tc.desc: Test function SetCurrentIndex 352 */ 353 HWTEST_F(AccessibilityEventInfoUnitTest, SetCurrentIndex_001, TestSize.Level1) 354 { 355 GTEST_LOG_(INFO) << "SetCurrentIndex_001 start"; 356 if (!eventInfo_) { 357 GTEST_LOG_(INFO) << "eventInfo_ is null"; 358 } else { 359 eventInfo_->SetCurrentIndex(CURRENT_INDEX); 360 EXPECT_EQ(eventInfo_->GetCurrentIndex(), CURRENT_INDEX); 361 } 362 GTEST_LOG_(INFO) << "SetCurrentIndex_001 end"; 363 } 364 365 /** 366 * @tc.number: SetBeginIndex_001 367 * @tc.name: SetBeginIndex 368 * @tc.desc: Test function SetBeginIndex 369 */ 370 HWTEST_F(AccessibilityEventInfoUnitTest, SetBeginIndex_001, TestSize.Level1) 371 { 372 GTEST_LOG_(INFO) << "SetBeginIndex_001 start"; 373 if (!eventInfo_) { 374 GTEST_LOG_(INFO) << "eventInfo_ is null"; 375 } else { 376 eventInfo_->SetBeginIndex(BEGIN_INDEX); 377 EXPECT_EQ(eventInfo_->GetBeginIndex(), BEGIN_INDEX); 378 } 379 GTEST_LOG_(INFO) << "SetBeginIndex_001 end"; 380 } 381 382 /** 383 * @tc.number: SetEndIndex_001 384 * @tc.name: SetEndIndex 385 * @tc.desc: Test function SetEndIndex 386 */ 387 HWTEST_F(AccessibilityEventInfoUnitTest, SetEndIndex_001, TestSize.Level1) 388 { 389 GTEST_LOG_(INFO) << "SetEndIndex_001 start"; 390 if (!eventInfo_) { 391 GTEST_LOG_(INFO) << "eventInfo_ is null"; 392 } else { 393 eventInfo_->SetEndIndex(END_INDEX); 394 EXPECT_EQ(eventInfo_->GetEndIndex(), END_INDEX); 395 } 396 GTEST_LOG_(INFO) << "SetEndIndex_001 end"; 397 } 398 399 /** 400 * @tc.number: SetItemCounts_001 401 * @tc.name: SetItemCounts 402 * @tc.desc: Test function SetItemCounts 403 */ 404 HWTEST_F(AccessibilityEventInfoUnitTest, SetItemCounts_001, TestSize.Level1) 405 { 406 GTEST_LOG_(INFO) << "SetItemCounts_001 start"; 407 if (!eventInfo_) { 408 GTEST_LOG_(INFO) << "eventInfo_ is null"; 409 } else { 410 eventInfo_->SetItemCounts(ITEM_COUNTS); 411 EXPECT_EQ(eventInfo_->GetItemCounts(), ITEM_COUNTS); 412 } 413 GTEST_LOG_(INFO) << "SetItemCounts_001 end"; 414 } 415 416 /** 417 * @tc.number: SetComponentType_001 418 * @tc.name: SetComponentType 419 * @tc.desc: Test function SetComponentType 420 */ 421 HWTEST_F(AccessibilityEventInfoUnitTest, SetComponentType_001, TestSize.Level1) 422 { 423 GTEST_LOG_(INFO) << "SetComponentType_001 start"; 424 if (!eventInfo_) { 425 GTEST_LOG_(INFO) << "eventInfo_ is null"; 426 } else { 427 eventInfo_->SetComponentType(COMPONENT_TYPE); 428 EXPECT_EQ(eventInfo_->GetComponentType(), COMPONENT_TYPE); 429 } 430 GTEST_LOG_(INFO) << "SetComponentType_001 end"; 431 } 432 433 /** 434 * @tc.number: SetBeforeText_001 435 * @tc.name: SetBeforeText 436 * @tc.desc: Test function SetBeforeText 437 */ 438 HWTEST_F(AccessibilityEventInfoUnitTest, SetBeforeText_001, TestSize.Level1) 439 { 440 GTEST_LOG_(INFO) << "SetBeforeText_001 start"; 441 if (!eventInfo_) { 442 GTEST_LOG_(INFO) << "eventInfo_ is null"; 443 } else { 444 eventInfo_->SetBeforeText(BEFORE_TEXT); 445 EXPECT_EQ(eventInfo_->GetBeforeText(), BEFORE_TEXT); 446 } 447 GTEST_LOG_(INFO) << "SetBeforeText_001 end"; 448 } 449 450 /** 451 * @tc.number: SetLatestContent_001 452 * @tc.name: SetLatestContent 453 * @tc.desc: Test function SetLatestContent 454 */ 455 HWTEST_F(AccessibilityEventInfoUnitTest, SetLatestContent_001, TestSize.Level1) 456 { 457 GTEST_LOG_(INFO) << "SetLatestContent_001 start"; 458 if (!eventInfo_) { 459 GTEST_LOG_(INFO) << "eventInfo_ is null"; 460 } else { 461 eventInfo_->SetLatestContent(LATEST_CONTENT); 462 EXPECT_EQ(eventInfo_->GetLatestContent(), LATEST_CONTENT); 463 } 464 GTEST_LOG_(INFO) << "SetLatestContent_001 end"; 465 } 466 467 /** 468 * @tc.number: SetDescription_001 469 * @tc.name: SetDescription 470 * @tc.desc: Test function SetDescription 471 */ 472 HWTEST_F(AccessibilityEventInfoUnitTest, SetDescription_001, TestSize.Level1) 473 { 474 GTEST_LOG_(INFO) << "SetDescription_001 start"; 475 if (!eventInfo_) { 476 GTEST_LOG_(INFO) << "eventInfo_ is null"; 477 } else { 478 eventInfo_->SetDescription(DESCRIPTION); 479 EXPECT_EQ(eventInfo_->GetDescription(), DESCRIPTION); 480 } 481 GTEST_LOG_(INFO) << "SetDescription_001 end"; 482 } 483 484 /** 485 * @tc.number: SetTextAnnouncedForAccessibility_001 486 * @tc.name: SetTextAnnouncedForAccessibility 487 * @tc.desc: Test function SetTextAnnouncedForAccessibility 488 */ 489 HWTEST_F(AccessibilityEventInfoUnitTest, SetTextAnnouncedForAccessibility_001, TestSize.Level1) 490 { 491 GTEST_LOG_(INFO) << "SetTextAnnouncedForAccessibility_001 start"; 492 if (!eventInfo_) { 493 GTEST_LOG_(INFO) << "eventInfo_ is null"; 494 } else { 495 eventInfo_->SetTextAnnouncedForAccessibility(TEXT_ANNOUNCED_FOR_ACCESSIBILITY); 496 EXPECT_EQ(eventInfo_->GetTextAnnouncedForAccessibility(), TEXT_ANNOUNCED_FOR_ACCESSIBILITY); 497 } 498 GTEST_LOG_(INFO) << "SetTextAnnouncedForAccessibility_001 end"; 499 } 500 501 /** 502 * @tc.number: SetInspectorKey_001 503 * @tc.name: SetInspectorKey 504 * @tc.desc: Test function SetInspectorKey 505 */ 506 HWTEST_F(AccessibilityEventInfoUnitTest, SetInspectorKey_001, TestSize.Level1) 507 { 508 GTEST_LOG_(INFO) << "SetInspectorKey_001 start"; 509 if (!eventInfo_) { 510 GTEST_LOG_(INFO) << "eventInfo_ is null"; 511 } else { 512 eventInfo_->SetInspectorKey(INSPECTOR_KEY); 513 EXPECT_EQ(eventInfo_->GetInspectorKey(), INSPECTOR_KEY); 514 } 515 GTEST_LOG_(INFO) << "SetInspectorKey_001 end"; 516 } 517 518 /** 519 * @tc.number: SetRequestFocusElementId_001 520 * @tc.name: SetRequestFocusElementId 521 * @tc.desc: Test function SetRequestFocusElementId 522 */ 523 HWTEST_F(AccessibilityEventInfoUnitTest, SetRequestFocusElementId_001, TestSize.Level1) 524 { 525 GTEST_LOG_(INFO) << "SetRequestFocusElementId_001 start"; 526 if (!eventInfo_) { 527 GTEST_LOG_(INFO) << "eventInfo_ is null"; 528 } else { 529 eventInfo_->SetRequestFocusElementId(REQUEST_FOCUS_ELEMENT_ID); 530 EXPECT_EQ(eventInfo_->GetRequestFocusElementId(), REQUEST_FOCUS_ELEMENT_ID); 531 } 532 GTEST_LOG_(INFO) << "SetRequestFocusElementId_001 end"; 533 } 534 535 /** 536 * @tc.number: AddContent_001 537 * @tc.name: AddContent 538 * @tc.desc: Test function AddContent 539 */ 540 HWTEST_F(AccessibilityEventInfoUnitTest, AddContent_001, TestSize.Level1) 541 { 542 GTEST_LOG_(INFO) << "AddContent_001 start"; 543 if (!eventInfo_) { 544 GTEST_LOG_(INFO) << "eventInfo_ is null"; 545 } else { 546 for (auto &content : CONTENT_LIST) { 547 eventInfo_->AddContent(content); 548 } 549 std::vector<std::string> contentList = eventInfo_->GetContentList(); 550 EXPECT_FALSE(contentList.empty()); 551 EXPECT_EQ(contentList.size(), CONTENT_LIST.size()); 552 int32_t index = 0; 553 for (auto &content : contentList) { 554 EXPECT_EQ(content, CONTENT_LIST[index++]); 555 } 556 } 557 GTEST_LOG_(INFO) << "AddContent_001 end"; 558 } 559 560 /** 561 * @tc.number: SetElementInfo_001 562 * @tc.name: SetElementInfo 563 * @tc.desc: Test function SetElement&GetElement 564 */ 565 HWTEST_F(AccessibilityEventInfoUnitTest, SetElementInfo_001, TestSize.Level1) 566 { 567 GTEST_LOG_(INFO) << "SetElementInfo_001 start"; 568 int accessibilityId = 1; 569 AccessibilityElementInfo elementInfo; 570 std::shared_ptr<AccessibilityEventInfo> eventInfo = 571 std::make_shared<AccessibilityEventInfo>(1, WINDOW_UPDATE_FOCUSED); 572 elementInfo.SetAccessibilityId(accessibilityId); 573 ASSERT_TRUE(eventInfo); 574 eventInfo->SetElementInfo(elementInfo); 575 EXPECT_EQ(eventInfo->GetElementInfo().GetAccessibilityId(), accessibilityId); 576 GTEST_LOG_(INFO) << "SetElementInfo_001 end"; 577 } 578 579 /** 580 * @tc.number: AccessibilityEventInfo_001 581 * @tc.name: AccessibilityEventInfo 582 * @tc.desc: Test function AccessibilityEventInfo 583 */ 584 HWTEST_F(AccessibilityEventInfoUnitTest, AccessibilityEventInfo_001, TestSize.Level1) 585 { 586 GTEST_LOG_(INFO) << "AccessibilityEventInfo_001 start"; 587 std::shared_ptr<AccessibilityEventInfo> eventInfo = 588 std::make_shared<AccessibilityEventInfo>(1, WINDOW_UPDATE_FOCUSED); 589 ASSERT_TRUE(eventInfo); 590 EXPECT_EQ(eventInfo->GetWindowId(), 1); 591 EXPECT_EQ(eventInfo->GetWindowChangeTypes(), WINDOW_UPDATE_FOCUSED); 592 GTEST_LOG_(INFO) << "AccessibilityEventInfo_001 end"; 593 } 594 595 /** 596 * @tc.number: SetExtraEvent_001 597 * @tc.name: SetExtraEvent 598 * @tc.desc: Test function SetExtraEvent, GetExtraEvent 599 */ 600 HWTEST_F(AccessibilityEventInfoUnitTest, SetExtraEvent_001, TestSize.Level1) 601 { 602 GTEST_LOG_(INFO) << "SetExtraEvent_001 start"; 603 ExtraEventInfo extraEventInfo {}; 604 extraEventInfo.SetExtraEventInfo("addText", "1"); 605 eventInfo_->SetExtraEvent(extraEventInfo); 606 EXPECT_TRUE(eventInfo_->GetExtraEvent().GetExtraEventInfoValueStr().size() == 1); 607 GTEST_LOG_(INFO) << "SetExtraEvent_001 end"; 608 } 609 } // namespace Accessibility 610 } // namespace OHOS 611