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 <cstdio> 17 #include <fstream> 18 #include <gtest/gtest.h> 19 20 #include "mmi_log.h" 21 #include "pointer_event.h" 22 #ifndef USE_ROSEN_DRAWING 23 #define USE_ROSEN_DRAWING 24 #endif 25 #include "touch_drawing_manager.h" 26 #include "old_display_info.h" 27 28 #undef MMI_LOG_TAG 29 #define MMI_LOG_TAG "TouchDrawingManagerTest" 30 31 namespace OHOS { 32 namespace MMI { 33 namespace { 34 using namespace testing::ext; 35 } // namespace 36 class TouchDrawingManagerTest : public testing::Test { 37 public: SetUpTestCase(void)38 static void SetUpTestCase(void) {}; TearDownTestCase(void)39 static void TearDownTestCase(void) {}; SetUp(void)40 void SetUp(void) {}; 41 }; 42 43 /** 44 * @tc.name: TouchDrawingManagerTest_RecordLabelsInfo 45 * @tc.desc: Test RecordLabelsInfo 46 * @tc.type: Function 47 * @tc.require: 48 */ 49 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_RecordLabelsInfo, TestSize.Level1) 50 { 51 CALL_TEST_DEBUG; 52 TouchDrawingManager touchDrawMgr; 53 touchDrawMgr.pointerEvent_ = PointerEvent::Create(); 54 ASSERT_NE(touchDrawMgr.pointerEvent_, nullptr); 55 PointerEvent::PointerItem item; 56 item.SetPointerId(0); 57 item.SetPressed(true); 58 item.SetDisplayX(100); 59 item.SetDisplayY(100); 60 touchDrawMgr.pointerEvent_->AddPointerItem(item); 61 touchDrawMgr.pointerEvent_->SetPointerId(0); 62 touchDrawMgr.currentPointerId_ = 1; 63 EXPECT_NO_FATAL_FAILURE(touchDrawMgr.RecordLabelsInfo()); 64 65 touchDrawMgr.currentPointerId_ = 0; 66 touchDrawMgr.isFirstDownAction_ = true; 67 touchDrawMgr.lastPointerItem_.push_back(item); 68 touchDrawMgr.pointerEvent_->SetActionTime(150); 69 touchDrawMgr.lastActionTime_ = 300; 70 EXPECT_NO_FATAL_FAILURE(touchDrawMgr.RecordLabelsInfo()); 71 72 touchDrawMgr.pointerEvent_->SetActionTime(50); 73 touchDrawMgr.lastActionTime_ = 50; 74 EXPECT_NO_FATAL_FAILURE(touchDrawMgr.RecordLabelsInfo()); 75 76 item.SetPressed(false); 77 touchDrawMgr.isFirstDownAction_ = false; 78 touchDrawMgr.pointerEvent_->SetPointerId(10); 79 touchDrawMgr.pointerEvent_->UpdatePointerItem(0, item); 80 EXPECT_NO_FATAL_FAILURE(touchDrawMgr.RecordLabelsInfo()); 81 } 82 83 /** 84 * @tc.name: TouchDrawingManagerTest_TouchDrawHandler 85 * @tc.desc: Test TouchDrawHandler 86 * @tc.type: Function 87 * @tc.require: 88 */ 89 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_TouchDrawHandler, TestSize.Level1) 90 { 91 CALL_TEST_DEBUG; 92 TouchDrawingManager touchDrawMgr; 93 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 94 ASSERT_NE(pointerEvent, nullptr); 95 PointerEvent::PointerItem item; 96 touchDrawMgr.bubbleMode_.isShow = true; 97 touchDrawMgr.stopRecord_ = false; 98 touchDrawMgr.pointerMode_.isShow = true; 99 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP); 100 pointerEvent->AddPointerItem(item); 101 EXPECT_NO_FATAL_FAILURE(touchDrawMgr.TouchDrawHandler(pointerEvent)); 102 103 touchDrawMgr.bubbleMode_.isShow = false; 104 touchDrawMgr.pointerMode_.isShow = false; 105 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); 106 EXPECT_NO_FATAL_FAILURE(touchDrawMgr.TouchDrawHandler(pointerEvent)); 107 } 108 109 /** 110 * @tc.name: TouchDrawingManagerTest_UpdateDisplayInfo 111 * @tc.desc: Test UpdateDisplayInfo 112 * @tc.type: Function 113 * @tc.require: 114 */ 115 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_UpdateDisplayInfo, TestSize.Level1) 116 { 117 CALL_TEST_DEBUG; 118 TouchDrawingManager touchDrawMgr; 119 OLD::DisplayInfo displayInfo; 120 displayInfo.direction = Direction::DIRECTION0; 121 touchDrawMgr.displayInfo_.direction = Direction::DIRECTION0; 122 displayInfo.width = 700; 123 displayInfo.height = 500; 124 EXPECT_NO_FATAL_FAILURE(touchDrawMgr.UpdateDisplayInfo(displayInfo)); 125 126 displayInfo.direction = Direction::DIRECTION180; 127 touchDrawMgr.displayInfo_.direction = Direction::DIRECTION180; 128 EXPECT_NO_FATAL_FAILURE(touchDrawMgr.UpdateDisplayInfo(displayInfo)); 129 130 displayInfo.direction = Direction::DIRECTION270; 131 touchDrawMgr.displayInfo_.direction = Direction::DIRECTION270; 132 EXPECT_NO_FATAL_FAILURE(touchDrawMgr.UpdateDisplayInfo(displayInfo)); 133 } 134 135 /** 136 * @tc.name: TouchDrawingManagerTest_GetOriginalTouchScreenCoordinates 137 * @tc.desc: Test GetOriginalTouchScreenCoordinates 138 * @tc.type: Function 139 * @tc.require: 140 */ 141 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_GetOriginalTouchScreenCoordinates, TestSize.Level1) 142 { 143 CALL_TEST_DEBUG; 144 TouchDrawingManager touchDrawingMgr; 145 int32_t width = 720; 146 int32_t height = 1800; 147 int32_t physicalX = 300; 148 int32_t physicalY = 600; 149 Direction direction = DIRECTION0; 150 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.GetOriginalTouchScreenCoordinates(direction, width, height, 151 physicalX, physicalY)); 152 direction = DIRECTION90; 153 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.GetOriginalTouchScreenCoordinates(direction, width, height, 154 physicalX, physicalY)); 155 direction = DIRECTION180; 156 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.GetOriginalTouchScreenCoordinates(direction, width, height, 157 physicalX, physicalY)); 158 direction = DIRECTION270; 159 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.GetOriginalTouchScreenCoordinates(direction, width, height, 160 physicalX, physicalY)); 161 direction = static_cast<Direction>(10); 162 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.GetOriginalTouchScreenCoordinates(direction, width, height, 163 physicalX, physicalY)); 164 } 165 166 /** 167 * @tc.name: TouchDrawingManagerTest_UpdateBubbleData 168 * @tc.desc: Test UpdateBubbleData 169 * @tc.type: Function 170 * @tc.require: 171 */ 172 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_UpdateBubbleData, TestSize.Level1) 173 { 174 CALL_TEST_DEBUG; 175 TouchDrawingManager touchDrawingMgr; 176 Rosen::RSSurfaceNodeConfig surfaceNodeConfig; 177 surfaceNodeConfig.SurfaceNodeName = "touch window"; 178 Rosen::RSSurfaceNodeType surfaceNodeType = Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE; 179 touchDrawingMgr.surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, surfaceNodeType); 180 ASSERT_NE(touchDrawingMgr.surfaceNode_, nullptr); 181 touchDrawingMgr.bubbleCanvasNode_ = Rosen::RSCanvasNode::Create(); 182 ASSERT_NE(touchDrawingMgr.bubbleCanvasNode_, nullptr); 183 touchDrawingMgr.bubbleMode_.isShow = false; 184 EXPECT_EQ(touchDrawingMgr.UpdateBubbleData(), RET_OK); 185 186 touchDrawingMgr.bubbleMode_.isShow = true; 187 EXPECT_EQ(touchDrawingMgr.UpdateBubbleData(), RET_OK); 188 } 189 190 /** 191 * @tc.name: TouchDrawingManagerTest_RotationScreen 192 * @tc.desc: Test RotationScreen 193 * @tc.type: Function 194 * @tc.require: 195 */ 196 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_RotationScreen, TestSize.Level1) 197 { 198 CALL_TEST_DEBUG; 199 TouchDrawingManager touchDrawingMgr; 200 touchDrawingMgr.isChangedRotation_ = false; 201 touchDrawingMgr.isChangedMode_ = false; 202 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.RotationScreen()); 203 204 touchDrawingMgr.trackerCanvasNode_ = Rosen::RSCanvasNode::Create(); 205 ASSERT_NE(touchDrawingMgr.trackerCanvasNode_, nullptr); 206 touchDrawingMgr.crosshairCanvasNode_ = Rosen::RSCanvasNode::Create(); 207 ASSERT_NE(touchDrawingMgr.crosshairCanvasNode_, nullptr); 208 touchDrawingMgr.bubbleCanvasNode_ = Rosen::RSCanvasNode::Create(); 209 ASSERT_NE(touchDrawingMgr.bubbleCanvasNode_, nullptr); 210 touchDrawingMgr.labelsCanvasNode_ = Rosen::RSCanvasNode::Create(); 211 ASSERT_NE(touchDrawingMgr.labelsCanvasNode_, nullptr); 212 touchDrawingMgr.isChangedRotation_ = true; 213 touchDrawingMgr.isChangedMode_ = true; 214 touchDrawingMgr.pointerMode_.isShow = true; 215 touchDrawingMgr.bubbleMode_.isShow = true; 216 PointerEvent::PointerItem item; 217 touchDrawingMgr.lastPointerItem_.push_back(item); 218 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.RotationScreen()); 219 220 touchDrawingMgr.lastPointerItem_.clear(); 221 touchDrawingMgr.stopRecord_ = true; 222 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.RotationScreen()); 223 224 touchDrawingMgr.bubbleMode_.isShow = false; 225 touchDrawingMgr.stopRecord_ = false; 226 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.RotationScreen()); 227 228 touchDrawingMgr.pointerMode_.isShow = false; 229 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.RotationScreen()); 230 } 231 232 /** 233 * @tc.name: TouchDrawingManagerTest_CreateObserver 234 * @tc.desc: Test CreateObserver 235 * @tc.type: Function 236 * @tc.require: 237 */ 238 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_CreateObserver, TestSize.Level1) 239 { 240 CALL_TEST_DEBUG; 241 TouchDrawingManager touchDrawingMgr; 242 touchDrawingMgr.hasBubbleObserver_ = false; 243 touchDrawingMgr.hasPointerObserver_ = false; 244 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.CreateObserver()); 245 } 246 247 /** 248 * @tc.name: TouchDrawingManagerTest_CreateObserver_001 249 * @tc.desc: Test CreateObserver 250 * @tc.type: Function 251 * @tc.require: 252 */ 253 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_CreateObserver_001, TestSize.Level1) 254 { 255 CALL_TEST_DEBUG; 256 TouchDrawingManager touchDrawingMgr; 257 touchDrawingMgr.hasBubbleObserver_ = true; 258 touchDrawingMgr.hasPointerObserver_ = true; 259 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.CreateObserver()); 260 } 261 262 /** 263 * @tc.name: TouchDrawingManagerTest_AddCanvasNode 264 * @tc.desc: Test AddCanvasNode 265 * @tc.type: Function 266 * @tc.require: 267 */ 268 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_AddCanvasNode, TestSize.Level1) 269 { 270 CALL_TEST_DEBUG; 271 TouchDrawingManager touchDrawingMgr; 272 Rosen::RSSurfaceNodeConfig surfaceNodeConfig; 273 surfaceNodeConfig.SurfaceNodeName = "touch window"; 274 Rosen::RSSurfaceNodeType surfaceNodeType = Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE; 275 touchDrawingMgr.surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, surfaceNodeType); 276 std::shared_ptr<Rosen::RSCanvasNode> canvasNode = Rosen::RSCanvasNode::Create(); 277 ASSERT_NE(canvasNode, nullptr); 278 bool isTrackerNode = true; 279 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.AddCanvasNode(canvasNode, isTrackerNode)); 280 281 canvasNode = nullptr; 282 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.AddCanvasNode(canvasNode, isTrackerNode)); 283 } 284 285 /** 286 * @tc.name: TouchDrawingManagerTest_RotationCanvasNode 287 * @tc.desc: Test RotationCanvasNode 288 * @tc.type: Function 289 * @tc.require: 290 */ 291 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_RotationCanvasNode, TestSize.Level1) 292 { 293 CALL_TEST_DEBUG; 294 TouchDrawingManager touchDrawingMgr; 295 std::shared_ptr<Rosen::RSCanvasNode> canvasNode = Rosen::RSCanvasNode::Create(); 296 ASSERT_NE(canvasNode, nullptr); 297 touchDrawingMgr.displayInfo_.width = 720; 298 touchDrawingMgr.displayInfo_.height = 1800; 299 touchDrawingMgr.displayInfo_.direction = Direction::DIRECTION90; 300 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.RotationCanvasNode(canvasNode)); 301 touchDrawingMgr.displayInfo_.direction = Direction::DIRECTION270; 302 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.RotationCanvasNode(canvasNode)); 303 touchDrawingMgr.displayInfo_.direction = Direction::DIRECTION180; 304 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.RotationCanvasNode(canvasNode)); 305 touchDrawingMgr.displayInfo_.direction = Direction::DIRECTION0; 306 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.RotationCanvasNode(canvasNode)); 307 } 308 309 /** 310 * @tc.name: TouchDrawingManagerTest_RotationCanvas 311 * @tc.desc: Test RotationCanvas 312 * @tc.type: Function 313 * @tc.require: 314 */ 315 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_RotationCanvas, TestSize.Level1) 316 { 317 CALL_TEST_DEBUG; 318 TouchDrawingManager touchDrawingMgr; 319 int32_t width = 720; 320 int32_t height = 1800; 321 touchDrawingMgr.displayInfo_.width = 300; 322 touchDrawingMgr.displayInfo_.height = 100; 323 Direction direction = Direction::DIRECTION90; 324 touchDrawingMgr.labelsCanvasNode_ = Rosen::RSCanvasDrawingNode::Create(); 325 auto canvas = static_cast<TouchDrawingManager::RosenCanvas *> 326 (touchDrawingMgr.labelsCanvasNode_->BeginRecording(width, height)); 327 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.RotationCanvas(canvas, direction)); 328 direction = Direction::DIRECTION180; 329 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.RotationCanvas(canvas, direction)); 330 direction = Direction::DIRECTION270; 331 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.RotationCanvas(canvas, direction)); 332 direction = Direction::DIRECTION0; 333 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.RotationCanvas(canvas, direction)); 334 } 335 336 /** 337 * @tc.name: TouchDrawingManagerTest_CreateTouchWindow 338 * @tc.desc: Test CreateTouchWindow 339 * @tc.type: Function 340 * @tc.require: 341 */ 342 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_CreateTouchWindow, TestSize.Level1) 343 { 344 CALL_TEST_DEBUG; 345 TouchDrawingManager touchDrawingMgr; 346 Rosen::RSSurfaceNodeConfig surfaceNodeConfig; 347 surfaceNodeConfig.SurfaceNodeName = "touch window"; 348 Rosen::RSSurfaceNodeType surfaceNodeType = Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE; 349 touchDrawingMgr.surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, surfaceNodeType); 350 ASSERT_NE(touchDrawingMgr.surfaceNode_, nullptr); 351 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.CreateTouchWindow()); 352 touchDrawingMgr.surfaceNode_ = nullptr; 353 touchDrawingMgr.scaleW_ = 0; 354 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.CreateTouchWindow()); 355 touchDrawingMgr.scaleW_ = 100; 356 touchDrawingMgr.scaleH_ = 0; 357 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.CreateTouchWindow()); 358 touchDrawingMgr.scaleH_ = 500; 359 touchDrawingMgr.displayInfo_.id = 1000; 360 touchDrawingMgr.displayInfo_.displayMode = DisplayMode::MAIN; 361 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.CreateTouchWindow()); 362 } 363 364 /** 365 * @tc.name: TouchDrawingManagerTest_CreateTouchWindow_001 366 * @tc.desc: Test CreateTouchWindow 367 * @tc.type: Function 368 * @tc.require: 369 */ 370 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_CreateTouchWindow_001, TestSize.Level1) 371 { 372 CALL_TEST_DEBUG; 373 TouchDrawingManager touchDrawingMgr; 374 touchDrawingMgr.surfaceNode_ = nullptr; 375 touchDrawingMgr.scaleW_ = 100; 376 touchDrawingMgr.scaleH_ = 500; 377 touchDrawingMgr.displayInfo_.id = 1000; 378 touchDrawingMgr.displayInfo_.displayMode = DisplayMode::FULL; 379 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.CreateTouchWindow()); 380 } 381 382 /** 383 * @tc.name: TouchDrawingManagerTest_CreateTouchWindow_002 384 * @tc.desc: Test CreateTouchWindow 385 * @tc.type: Function 386 * @tc.require: 387 */ 388 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_CreateTouchWindow_002, TestSize.Level1) 389 { 390 CALL_TEST_DEBUG; 391 TouchDrawingManager touchDrawingMgr; 392 touchDrawingMgr.surfaceNode_ = nullptr; 393 touchDrawingMgr.scaleW_ = 100; 394 touchDrawingMgr.scaleH_ = 500; 395 touchDrawingMgr.displayInfo_.id = 1000; 396 touchDrawingMgr.displayInfo_.displayMode = DisplayMode::UNKNOWN; 397 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.CreateTouchWindow()); 398 } 399 400 /** 401 * @tc.name: TouchDrawingManagerTest_DrawBubbleHandler 402 * @tc.desc: Test DrawBubbleHandler 403 * @tc.type: Function 404 * @tc.require: 405 */ 406 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_DrawBubbleHandler, TestSize.Level1) 407 { 408 CALL_TEST_DEBUG; 409 TouchDrawingManager touchDrawingMgr; 410 touchDrawingMgr.pointerEvent_ = PointerEvent::Create(); 411 ASSERT_NE(touchDrawingMgr.pointerEvent_, nullptr); 412 touchDrawingMgr.bubbleCanvasNode_ = Rosen::RSCanvasNode::Create(); 413 ASSERT_NE(touchDrawingMgr.bubbleCanvasNode_, nullptr); 414 touchDrawingMgr.pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); 415 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.DrawBubbleHandler()); 416 417 touchDrawingMgr.pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN); 418 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.DrawBubbleHandler()); 419 } 420 421 /** 422 * @tc.name: TouchDrawingManagerTest_DrawBubble 423 * @tc.desc: Test DrawBubble 424 * @tc.type: Function 425 * @tc.require: 426 */ 427 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_DrawBubble, TestSize.Level1) 428 { 429 CALL_TEST_DEBUG; 430 TouchDrawingManager touchDrawingMgr; 431 touchDrawingMgr.bubbleCanvasNode_ = Rosen::RSCanvasNode::Create(); 432 touchDrawingMgr.pointerEvent_ = PointerEvent::Create(); 433 ASSERT_NE(touchDrawingMgr.pointerEvent_, nullptr); 434 PointerEvent::PointerItem item; 435 item.SetPointerId(1); 436 touchDrawingMgr.pointerEvent_->SetPointerId(1); 437 touchDrawingMgr.pointerEvent_->AddPointerItem(item); 438 touchDrawingMgr.pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_UP); 439 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.DrawBubble()); 440 touchDrawingMgr.pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_PULL_UP); 441 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.DrawBubble()); 442 touchDrawingMgr.pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_CANCEL); 443 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.DrawBubble()); 444 } 445 446 /** 447 * @tc.name: TouchDrawingManagerTest_DrawBubble_001 448 * @tc.desc: Test DrawBubble 449 * @tc.type: Function 450 * @tc.require: 451 */ 452 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_DrawBubble_001, TestSize.Level1) 453 { 454 CALL_TEST_DEBUG; 455 TouchDrawingManager touchDrawingMgr; 456 touchDrawingMgr.bubbleCanvasNode_ = Rosen::RSCanvasNode::Create(); 457 touchDrawingMgr.pointerEvent_ = PointerEvent::Create(); 458 ASSERT_NE(touchDrawingMgr.pointerEvent_, nullptr); 459 PointerEvent::PointerItem item; 460 item.SetPointerId(1); 461 touchDrawingMgr.pointerEvent_->AddPointerItem(item); 462 touchDrawingMgr.pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); 463 item.SetPointerId(2); 464 touchDrawingMgr.pointerEvent_->SetPointerId(2); 465 touchDrawingMgr.pointerEvent_->AddPointerItem(item); 466 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.DrawBubble()); 467 } 468 469 /** 470 * @tc.name: TouchDrawingManagerTest_DrawPointerPositionHandler 471 * @tc.desc: Test DrawPointerPositionHandler 472 * @tc.type: Function 473 * @tc.require: 474 */ 475 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_DrawPointerPositionHandler, TestSize.Level1) 476 { 477 CALL_TEST_DEBUG; 478 TouchDrawingManager touchDrawingMgr; 479 touchDrawingMgr.bubbleCanvasNode_ = Rosen::RSCanvasNode::Create(); 480 touchDrawingMgr.pointerEvent_ = PointerEvent::Create(); 481 ASSERT_NE(touchDrawingMgr.pointerEvent_, nullptr); 482 touchDrawingMgr.trackerCanvasNode_ = Rosen::RSCanvasNode::Create(); 483 ASSERT_NE(touchDrawingMgr.trackerCanvasNode_, nullptr); 484 touchDrawingMgr.crosshairCanvasNode_ = Rosen::RSCanvasNode::Create(); 485 ASSERT_NE(touchDrawingMgr.crosshairCanvasNode_, nullptr); 486 touchDrawingMgr.labelsCanvasNode_ = Rosen::RSCanvasNode::Create(); 487 ASSERT_NE(touchDrawingMgr.labelsCanvasNode_, nullptr); 488 PointerEvent::PointerItem item; 489 item.SetDisplayX(300); 490 item.SetDisplayY(500); 491 item.SetPointerId(100); 492 touchDrawingMgr.scaleW_ = 720; 493 touchDrawingMgr.scaleH_ = 1800; 494 touchDrawingMgr.pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_UP); 495 touchDrawingMgr.pointerEvent_->SetPointerId(100); 496 touchDrawingMgr.pointerEvent_->AddPointerItem(item); 497 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.DrawPointerPositionHandler()); 498 499 touchDrawingMgr.pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); 500 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.DrawPointerPositionHandler()); 501 } 502 503 /** 504 * @tc.name: TouchDrawingManagerTest_DrawTracker 505 * @tc.desc: Test DrawTracker 506 * @tc.type: Function 507 * @tc.require: 508 */ 509 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_DrawTracker, TestSize.Level1) 510 { 511 CALL_TEST_DEBUG; 512 TouchDrawingManager touchDrawingMgr; 513 int32_t x = 100; 514 int32_t y = 300; 515 int32_t pointerId = 10; 516 PointerEvent::PointerItem item; 517 item.SetPointerId(10); 518 item.SetDisplayX(100); 519 item.SetDisplayY(300); 520 touchDrawingMgr.isDownAction_ = true; 521 touchDrawingMgr.xVelocity_ = 200; 522 touchDrawingMgr.yVelocity_ = 400; 523 touchDrawingMgr.lastPointerItem_.push_back(item); 524 touchDrawingMgr.trackerCanvasNode_ = Rosen::RSCanvasNode::Create(); 525 ASSERT_NE(touchDrawingMgr.trackerCanvasNode_, nullptr); 526 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.DrawTracker(x, y, pointerId)); 527 528 pointerId = 20; 529 touchDrawingMgr.isDownAction_ = false; 530 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.DrawTracker(x, y, pointerId)); 531 } 532 533 /** 534 * @tc.name: TouchDrawingManagerTest_DrawLabels 535 * @tc.desc: Test DrawLabels 536 * @tc.type: Function 537 * @tc.require: 538 */ 539 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_DrawLabels, TestSize.Level1) 540 { 541 CALL_TEST_DEBUG; 542 TouchDrawingManager touchDrawingMgr; 543 touchDrawingMgr.labelsCanvasNode_ = Rosen::RSCanvasNode::Create(); 544 ASSERT_NE(touchDrawingMgr.labelsCanvasNode_, nullptr); 545 PointerEvent::PointerItem item; 546 touchDrawingMgr.currentPointerCount_ = 10; 547 touchDrawingMgr.maxPointerCount_ = 20; 548 touchDrawingMgr.scaleW_ = 30; 549 touchDrawingMgr.scaleH_ = 50; 550 touchDrawingMgr.xVelocity_ = 30; 551 touchDrawingMgr.yVelocity_ = 50; 552 touchDrawingMgr.pressure_ = 10; 553 touchDrawingMgr.rectTopPosition_ = 100; 554 touchDrawingMgr.itemRectW_ = 100.0; 555 touchDrawingMgr.isDownAction_ = true; 556 touchDrawingMgr.lastPointerItem_.push_back(item); 557 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.DrawLabels()); 558 touchDrawingMgr.isDownAction_ = false; 559 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.DrawLabels()); 560 touchDrawingMgr.lastPointerItem_.clear(); 561 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.DrawLabels()); 562 } 563 564 /** 565 * @tc.name: TouchDrawingManagerTest_UpdatePointerPosition 566 * @tc.desc: Test UpdatePointerPosition 567 * @tc.type: Function 568 * @tc.require: 569 */ 570 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_UpdatePointerPosition, TestSize.Level1) 571 { 572 CALL_TEST_DEBUG; 573 TouchDrawingManager touchDrawingMgr; 574 touchDrawingMgr.pointerEvent_ = PointerEvent::Create(); 575 ASSERT_NE(touchDrawingMgr.pointerEvent_, nullptr); 576 PointerEvent::PointerItem item; 577 touchDrawingMgr.pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); 578 touchDrawingMgr.pointerEvent_->SetPointerId(10); 579 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.UpdatePointerPosition()); 580 touchDrawingMgr.lastPointerItem_.push_back(item); 581 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.UpdatePointerPosition()); 582 } 583 584 /** 585 * @tc.name: TouchDrawingManagerTest_UpdatePointerPosition_001 586 * @tc.desc: Test UpdatePointerPosition 587 * @tc.type: Function 588 * @tc.require: 589 */ 590 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_UpdatePointerPosition_001, TestSize.Level1) 591 { 592 CALL_TEST_DEBUG; 593 TouchDrawingManager touchDrawingMgr; 594 touchDrawingMgr.pointerEvent_ = PointerEvent::Create(); 595 ASSERT_NE(touchDrawingMgr.pointerEvent_, nullptr); 596 PointerEvent::PointerItem item; 597 touchDrawingMgr.pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_UP); 598 touchDrawingMgr.pointerEvent_->SetPointerId(10); 599 item.SetPointerId(20); 600 touchDrawingMgr.lastPointerItem_.push_back(item); 601 item.SetPointerId(10); 602 touchDrawingMgr.lastPointerItem_.push_back(item); 603 touchDrawingMgr.currentPointerId_ = 10; 604 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.UpdatePointerPosition()); 605 touchDrawingMgr.lastPointerItem_.clear(); 606 touchDrawingMgr.currentPointerId_ = 50; 607 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.UpdatePointerPosition()); 608 touchDrawingMgr.pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN); 609 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.UpdatePointerPosition()); 610 } 611 612 /** 613 * @tc.name: TouchDrawingManagerTest_UpdateLastPointerItem 614 * @tc.desc: Test UpdateLastPointerItem 615 * @tc.type: Function 616 * @tc.require: 617 */ 618 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_UpdateLastPointerItem, TestSize.Level1) 619 { 620 CALL_TEST_DEBUG; 621 TouchDrawingManager touchDrawingMgr; 622 PointerEvent::PointerItem item; 623 item.SetPressed(false); 624 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.UpdateLastPointerItem(item)); 625 item.SetPressed(true); 626 item.SetPointerId(10); 627 touchDrawingMgr.lastPointerItem_.push_back(item); 628 item.SetPointerId(20); 629 touchDrawingMgr.lastPointerItem_.push_back(item); 630 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.UpdateLastPointerItem(item)); 631 } 632 633 /** 634 * @tc.name: TouchDrawingManagerTest_DestoryTouchWindow 635 * @tc.desc: Test DestoryTouchWindow 636 * @tc.type: Function 637 * @tc.require: 638 */ 639 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_DestoryTouchWindow, TestSize.Level1) 640 { 641 CALL_TEST_DEBUG; 642 TouchDrawingManager touchDrawingMgr; 643 Rosen::RSSurfaceNodeConfig surfaceNodeConfig; 644 surfaceNodeConfig.SurfaceNodeName = "touch window"; 645 Rosen::RSSurfaceNodeType surfaceNodeType = Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE; 646 touchDrawingMgr.surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, surfaceNodeType); 647 ASSERT_NE(touchDrawingMgr.surfaceNode_, nullptr); 648 touchDrawingMgr.bubbleMode_.isShow = true; 649 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.DestoryTouchWindow()); 650 touchDrawingMgr.bubbleMode_.isShow = false; 651 touchDrawingMgr.pointerMode_.isShow = true; 652 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.DestoryTouchWindow()); 653 touchDrawingMgr.pointerMode_.isShow = false; 654 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.DestoryTouchWindow()); 655 } 656 657 /** 658 * @tc.name: TouchDrawingManagerTest_ClearTracker 659 * @tc.desc: Test ClearTracker 660 * @tc.type: Function 661 * @tc.require: 662 */ 663 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_ClearTracker, TestSize.Level1) 664 { 665 CALL_TEST_DEBUG; 666 TouchDrawingManager touchDrawingMgr; 667 touchDrawingMgr.trackerCanvasNode_ = Rosen::RSCanvasNode::Create(); 668 ASSERT_NE(touchDrawingMgr.trackerCanvasNode_, nullptr); 669 touchDrawingMgr.scaleW_ = 300; 670 touchDrawingMgr.scaleH_ = 500; 671 touchDrawingMgr.isDownAction_ = true; 672 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.ClearTracker()); 673 touchDrawingMgr.isDownAction_ = false; 674 EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.ClearTracker()); 675 } 676 677 /** 678 * @tc.name: TouchDrawingManagerTest_IsValidAction 679 * @tc.desc: Test IsValidAction 680 * @tc.type: Function 681 * @tc.require: 682 */ 683 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_IsValidAction, TestSize.Level1) 684 { 685 CALL_TEST_DEBUG; 686 TouchDrawingManager touchDrawingMgr; 687 int32_t action = PointerEvent::POINTER_ACTION_DOWN; 688 EXPECT_TRUE(touchDrawingMgr.IsValidAction(action)); 689 action = PointerEvent::POINTER_ACTION_PULL_DOWN; 690 EXPECT_TRUE(touchDrawingMgr.IsValidAction(action)); 691 action = PointerEvent::POINTER_ACTION_MOVE; 692 EXPECT_TRUE(touchDrawingMgr.IsValidAction(action)); 693 action = PointerEvent::POINTER_ACTION_PULL_MOVE; 694 EXPECT_TRUE(touchDrawingMgr.IsValidAction(action)); 695 action = PointerEvent::POINTER_ACTION_UP; 696 EXPECT_TRUE(touchDrawingMgr.IsValidAction(action)); 697 action = PointerEvent::POINTER_ACTION_PULL_UP; 698 EXPECT_TRUE(touchDrawingMgr.IsValidAction(action)); 699 action = PointerEvent::POINTER_ACTION_CANCEL; 700 EXPECT_TRUE(touchDrawingMgr.IsValidAction(action)); 701 action = PointerEvent::POINTER_ACTION_UNKNOWN; 702 EXPECT_FALSE(touchDrawingMgr.IsValidAction(action)); 703 } 704 } // namespace MMI 705 } // namespace OHOS