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