1 /*
2 * Copyright (c) 2023 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 "define_multimodal.h"
17 #include "event_util_test.h"
18 #include "input_manager_util.h"
19 #include "pixel_map.h"
20
21 #undef MMI_LOG_TAG
22 #define MMI_LOG_TAG "InputManagerPointerTest"
23
24 namespace OHOS {
25 namespace MMI {
26 namespace {
27 constexpr int32_t TIME_WAIT_FOR_OP = 100;
28 constexpr int32_t SIZE_TYPE_CASE = 3;
29 constexpr int32_t POINTER_ITEM_DISPLAY_X_ONE = 222;
30 constexpr int32_t POINTER_ITEM_DISPLAY_X_TWO = 444;
31 constexpr int32_t POINTER_ITEM_DISPLAY_X_THREE = 555;
32 constexpr int32_t POINTER_ITEM_DISPLAY_X_FOUR = 666;
33 constexpr int32_t POINTER_ITEM_DISPLAY_X_FIVE = 923;
34 constexpr int32_t POINTER_ITEM_DISPLAY_Y_ONE = 223;
35 constexpr int32_t POINTER_ITEM_DISPLAY_Y_TWO = 333;
36 constexpr int32_t POINTER_ITEM_DISPLAY_Y_THREE = 555;
37 constexpr int32_t POINTER_ITEM_DISPLAY_Y_FOUR = 777;
38 constexpr int32_t POINTER_ITEM_DISPLAY_Y_FIVE = 793;
39 constexpr int32_t MOVE_MOUSE_OFFSET_ONE = -2000;
40 constexpr int32_t MOVE_MOUSE_OFFSET_TWO = 50;
41 constexpr int32_t MOVE_MOUSE_OFFSET_THREE = 100;
42 constexpr int32_t MOVE_MOUSE_OFFSET_FOUR = 150;
43 constexpr int32_t MOVE_MOUSE_OFFSET_FIVE = 300;
44 constexpr int32_t MOVE_MOUSE_OFFSET_SIX = 350;
45 constexpr int32_t MOVE_MOUSE_OFFSET_SEVEN = 400;
46 constexpr int32_t MOVE_MOUSE_OFFSET_EIGHT = 450;
47 constexpr int32_t MOVE_MOUSE_OFFSET_NINE = 500;
48 constexpr int32_t MOVE_MOUSE_OFFSET_TEN = 550;
49 constexpr int32_t MOVE_MOUSE_OFFSET_ELEVEN = 700;
50 constexpr int32_t MOVE_MOUSE_OFFSET_TWELVE = 1000;
51 constexpr int32_t MOVE_MOUSE_OFFSET_THIRTEEN = -1000;
52 constexpr int32_t POINTER_SPEED_ONE = 4;
53 constexpr int32_t POINTER_SPEED_TWO = 5;
54 constexpr int32_t POINTER_SPEED_THREE = 9;
55 constexpr int32_t POINTER_SPEED_FOUR = 11;
56 constexpr int32_t POINTER_SPEED_FIVE = 20;
57 constexpr int32_t RIGHT_CLICK_TYPE = 2;
58 constexpr int32_t INVAID_VALUE = -1;
59 constexpr int32_t MOUSE_ICON_HOT_SPOT = 20;
60 constexpr int64_t POINTER_ITEM_DOWNTIME_ONE = 9999;
61 constexpr int64_t POINTER_ITEM_DOWNTIME_TWO = 10001;
62 constexpr int64_t POINTER_ITEM_DOWNTIME_THREE = 10003;
63 constexpr int64_t POINTER_ITEM_DOWNTIME_FOUR = 10009;
64 constexpr int64_t POINTER_ITEM_DOWNTIME_FIVE = 10010;
65
66 HapInfoParams infoManagerTestInfoParms = {
67 .userID = 1,
68 .bundleName = "InputManagerPointerTest",
69 .instIndex = 0,
70 .appIDDesc = "test",
71 .isSystemApp = true
72 };
73
74 PermissionDef infoManagerTestPermDef = {
75 .permissionName = "ohos.permission.test",
76 .bundleName = "InputManagerPointerTest",
77 .grantMode = 1,
78 .availableLevel = APL_SYSTEM_CORE,
79 .label = "label",
80 .labelId = 1,
81 .description = "test pointer event",
82 .descriptionId = 1,
83 };
84
85 PermissionStateFull infoManagerTestState = {
86 .permissionName = "ohos.permission.test",
87 .isGeneral = true,
88 .resDeviceID = { "local" },
89 .grantStatus = { PermissionState::PERMISSION_GRANTED },
90 .grantFlags = { 1 },
91 };
92
93 HapPolicyParams infoManagerTestPolicyPrams = {
94 .apl = APL_SYSTEM_CORE,
95 .domain = "test.domain",
96 .permList = { infoManagerTestPermDef },
97 .permStateList = { infoManagerTestState }
98 };
99 } // namespace
100
101 class AccessToken {
102 public:
AccessToken()103 AccessToken()
104 {
105 currentID_ = GetSelfTokenID();
106 AccessTokenIDEx tokenIdEx = AccessTokenKit::AllocHapToken(infoManagerTestInfoParms, infoManagerTestPolicyPrams);
107 accessID_ = tokenIdEx.tokenIDEx;
108 SetSelfTokenID(accessID_);
109 }
~AccessToken()110 ~AccessToken()
111 {
112 AccessTokenKit::DeleteToken(accessID_);
113 SetSelfTokenID(currentID_);
114 }
115 private:
116 uint64_t currentID_ = 0;
117 uint64_t accessID_ = 0;
118 };
119
120 class InputManagerPointerTest : public testing::Test {
121 public:
122 void SetUp();
123 void TearDown();
124 static void SetUpTestCase();
125 static void TearDownTestCase();
126 std::string GetEventDump();
127
128 private:
129 int32_t prePointerSpeed_ { 5 };
130 int32_t prePrimaryButton_ { 0 };
131 int32_t preScrollRows_ { 3 };
132 int32_t preTouchpadPointerSpeed_ { 9 };
133 int32_t preRightClickType_ { 1 };
134 int32_t prePointerSize_ { 1 };
135 int32_t prePointerColor_ { -1 };
136 bool preHoverScrollState_ { true };
137 bool preScrollSwitch_ { true };
138 bool preScrollDirection_ { true };
139 bool preTapSwitch_ { true };
140 bool prePinchSwitch_ { true };
141 bool preSwipeSwitch_ { true };
142 bool preRotateSwitch_ { true };
143 bool preDoubleTapAndDragState_ { true };
144 };
145
SetUpTestCase()146 void InputManagerPointerTest::SetUpTestCase()
147 {
148 ASSERT_TRUE(TestUtil->Init());
149 }
150
TearDownTestCase(void)151 void InputManagerPointerTest::TearDownTestCase(void)
152 {
153 }
154
SetUp()155 void InputManagerPointerTest::SetUp()
156 {
157 TestUtil->SetRecvFlag(RECV_FLAG::RECV_FOCUS);
158 InputManager::GetInstance()->GetPointerSpeed(prePointerSpeed_);
159 InputManager::GetInstance()->GetMousePrimaryButton(prePrimaryButton_);
160 InputManager::GetInstance()->GetHoverScrollState(preHoverScrollState_);
161 InputManager::GetInstance()->GetMouseScrollRows(preScrollRows_);
162 InputManager::GetInstance()->GetTouchpadScrollSwitch(preScrollSwitch_);
163 InputManager::GetInstance()->GetTouchpadScrollDirection(preScrollDirection_);
164 InputManager::GetInstance()->GetTouchpadTapSwitch(preTapSwitch_);
165 InputManager::GetInstance()->GetTouchpadPointerSpeed(preTouchpadPointerSpeed_);
166 InputManager::GetInstance()->GetTouchpadPinchSwitch(prePinchSwitch_);
167 InputManager::GetInstance()->GetTouchpadSwipeSwitch(preSwipeSwitch_);
168 InputManager::GetInstance()->GetTouchpadRightClickType(preRightClickType_);
169 InputManager::GetInstance()->GetTouchpadRotateSwitch(preRotateSwitch_);
170 InputManager::GetInstance()->GetTouchpadDoubleTapAndDragState(preDoubleTapAndDragState_);
171 InputManager::GetInstance()->GetPointerSize(prePointerSize_);
172 InputManager::GetInstance()->GetPointerColor(prePointerColor_);
173 InputManager::GetInstance()->GetTouchpadThreeFingersTapSwitch(threeFingerSwitch_);
174 InputManager::GetInstance()->GetTouchpadScrollRows(preScrollRows_);
175 }
176
TearDown()177 void InputManagerPointerTest::TearDown()
178 {
179 TestUtil->AddEventDump("");
180 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
181 InputManager::GetInstance()->SetPointerSpeed(prePointerSpeed_);
182 InputManager::GetInstance()->SetMousePrimaryButton(prePrimaryButton_);
183 InputManager::GetInstance()->SetHoverScrollState(preHoverScrollState_);
184 InputManager::GetInstance()->SetMouseScrollRows(preScrollRows_);
185 InputManager::GetInstance()->SetTouchpadScrollSwitch(preScrollSwitch_);
186 InputManager::GetInstance()->SetTouchpadScrollDirection(preScrollDirection_);
187 InputManager::GetInstance()->SetTouchpadTapSwitch(preTapSwitch_);
188 InputManager::GetInstance()->SetTouchpadPointerSpeed(preTouchpadPointerSpeed_);
189 InputManager::GetInstance()->SetTouchpadPinchSwitch(prePinchSwitch_);
190 InputManager::GetInstance()->SetTouchpadSwipeSwitch(preSwipeSwitch_);
191 InputManager::GetInstance()->SetTouchpadRotateSwitch(preRotateSwitch_);
192 InputManager::GetInstance()->SetTouchpadDoubleTapAndDragState(preDoubleTapAndDragState_);
193 InputManager::GetInstance()->SetTouchpadRightClickType(preRightClickType_);
194 InputManager::GetInstance()->SetPointerSize(prePointerSize_);
195 InputManager::GetInstance()->SetPointerColor(prePointerColor_);
196 InputManager::GetInstance()->SetTouchpadThreeFingersTapSwitch(threeFingerSwitch_);
197 InputManager::GetInstance()->SetTouchpadScrollRows(preScrollRows_);
198 }
199
GetEventDump()200 std::string InputManagerPointerTest::GetEventDump()
201 {
202 return TestUtil->GetEventDump();
203 }
204
205 /**
206 * @tc.name: InputManagerPointerTest_MouseEventEnterAndLeave_001
207 * @tc.desc: Verify that the mouse moves away from the window
208 * @tc.type: FUNC
209 * @tc.require: I5HMF3 I5HMEF
210 */
211 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_MouseEventEnterAndLeave_001, TestSize.Level1)
212 {
213 CALL_TEST_DEBUG;
214 std::shared_ptr<PointerEvent> pointerEvent{InputManagerUtil::SetupPointerEvent014()};
215 ASSERT_NE(pointerEvent, nullptr);
216 #ifdef OHOS_BUILD_ENABLE_POINTER
217 AccessToken accessToken;
218 SimulateInputEventUtilTest(pointerEvent);
219 #endif // OHOS_BUILD_ENABLE_POINTER
220 }
221
222 /**
223 * @tc.name: InputManagerPointerTest_MouseEventEnterAndLeave_002
224 * @tc.desc: Verify return mouse away from the window
225 * @tc.type: FUNC
226 * @tc.require: I5HMF3 I5HMEF
227 */
228 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_MouseEventEnterAndLeave_002, TestSize.Level1)
229 {
230 CALL_TEST_DEBUG;
231 std::shared_ptr<KeyEvent> keyEvent{InputManagerUtil::SetupKeyEvent002()};
232 ASSERT_NE(keyEvent, nullptr);
233 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
234 AccessToken accessToken;
235 SimulateInputEventUtilTest(keyEvent);
236 #endif // OHOS_BUILD_ENABLE_KEYBOARD
237 }
238
239 /**
240 * @tc.name: InputManagerPointerTest_MouseEventEnterAndLeave_003
241 * @tc.desc: Verify that the home button and mouse leave the window
242 * @tc.type: FUNC
243 * @tc.require: I5HMF3 I5HMEF
244 */
245 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_MouseEventEnterAndLeave_003, TestSize.Level1)
246 {
247 CALL_TEST_DEBUG;
248 std::shared_ptr<KeyEvent> keyEvent{InputManagerUtil::SetupKeyEvent003()};
249 ASSERT_NE(keyEvent, nullptr);
250 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
251 AccessToken accessToken;
252 SimulateInputEventUtilTest(keyEvent);
253 #endif // OHOS_BUILD_ENABLE_KEYBOARD
254 }
255
256 /**
257 * @tc.name: InputManagerPointerTest_MouseEventEnterAndLeave_004
258 * @tc.desc: Verify that the mouse moves to the navigation bar to leave the window
259 * @tc.type: FUNC
260 * @tc.require: I5HMF3 I5HMEF
261 */
262 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_MouseEventEnterAndLeave_004, TestSize.Level1)
263 {
264 CALL_TEST_DEBUG;
265 std::shared_ptr<PointerEvent> pointerEvent{InputManagerUtil::SetupPointerEvent015()};
266 ASSERT_NE(pointerEvent, nullptr);
267 #ifdef OHOS_BUILD_ENABLE_POINTER
268 AccessToken accessToken;
269 SimulateInputEventUtilTest(pointerEvent);
270 #endif // OHOS_BUILD_ENABLE_POINTER
271 }
272
273 /**
274 * @tc.name: InputManagerPointerTest_AddMonitor_001
275 * @tc.desc: Verify pointerevent monitor
276 * @tc.type: FUNC
277 * @tc.require:
278 */
279 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_AddMonitor_001, TestSize.Level1)
280 {
281 CALL_TEST_DEBUG;
__anon3cf8b9530202(std::shared_ptr<PointerEvent> event) 282 auto pointerEventFun = [](std::shared_ptr<PointerEvent> event) { MMI_HILOGD("Add monitor success"); };
283 int32_t monitorId = InputManager::GetInstance()->AddMonitor(pointerEventFun);
284 #if (defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)) && defined(OHOS_BUILD_ENABLE_MONITOR)
285 ASSERT_NE(monitorId, INVALID_HANDLER_ID);
286 #else
287 ASSERT_EQ(monitorId, ERROR_UNSUPPORT);
288 #endif // OHOS_BUILD_ENABLE_MONITOR || OHOS_BUILD_ENABLE_TOUCH && OHOS_BUILD_ENABLE_MONITOR
289 InputManager::GetInstance()->RemoveMonitor(monitorId);
290 }
291
292 /**
293 * @tc.name: InputManagerPointerTest_AddMonitor_002
294 * @tc.desc: Verify keyevent monitor
295 * @tc.type: FUNC
296 * @tc.require:
297 */
298 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_AddMonitor_002, TestSize.Level1)
299 {
300 CALL_TEST_DEBUG;
__anon3cf8b9530302(std::shared_ptr<KeyEvent> event) 301 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) { MMI_HILOGD("Add monitor success"); };
302 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
303 #if defined(OHOS_BUILD_ENABLE_KEYBOARD) && defined(OHOS_BUILD_ENABLE_MONITOR)
304 ASSERT_NE(monitorId, INVALID_HANDLER_ID);
305 #else
306 ASSERT_EQ(monitorId, ERROR_UNSUPPORT);
307 #endif // OHOS_BUILD_ENABLE_KEYBOARD || OHOS_BUILD_ENABLE_MONITOR
308 InputManager::GetInstance()->RemoveMonitor(monitorId);
309 }
310
311 /**
312 * @tc.name: InputManagerPointerTest_OnAddScreenMonitor_001
313 * @tc.desc: Verify touchscreen down event monitor
314 * @tc.type: FUNC
315 * @tc.require:
316 */
317 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_OnAddScreenMonitor_001, TestSize.Level1)
318 {
319 CALL_TEST_DEBUG;
320 auto pointerEvent = InputManagerUtil::SetupPointerEvent001();
321 ASSERT_NE(pointerEvent, nullptr);
322
323 auto callbackPtr = GetPtr<InputEventCallback>();
324 ASSERT_TRUE(callbackPtr != nullptr);
325 int32_t monitorId = InputManagerUtil::TestAddMonitor(callbackPtr);
326 #ifdef OHOS_BUILD_ENABLE_MONITOR
327 EXPECT_TRUE(IsValidHandlerId(monitorId));
328 #else
329 EXPECT_EQ(monitorId, ERROR_UNSUPPORT);
330 #endif // OHOS_BUILD_ENABLE_MONITOR
331 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
332
333 InputManagerUtil::TestMonitor(monitorId, pointerEvent);
334 InputManagerUtil::TestRemoveMonitor(monitorId);
335 }
336
337 /**
338 * @tc.name: InputManagerPointerTest_OnAddScreenMonitor_002
339 * @tc.desc: Verify touchscreen move event multiple monitor
340 * @tc.type: FUNC
341 * @tc.require:
342 */
343 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_OnAddScreenMonitor_002, TestSize.Level1)
344 {
345 CALL_TEST_DEBUG;
346 TestUtil->SetRecvFlag(RECV_FLAG::RECV_MONITOR);
347 const std::vector<int32_t>::size_type N_TEST_CASES{SIZE_TYPE_CASE};
348 std::vector<int32_t> ids(N_TEST_CASES);
349 std::vector<std::shared_ptr<InputEventCallback>> cbs(N_TEST_CASES);
350
351 for (std::vector<int32_t>::size_type i = 0; i < N_TEST_CASES; i++) {
352 cbs[i] = GetPtr<InputEventCallback>();
353 ASSERT_TRUE(cbs[i] != nullptr);
354 ids[i] = InputManagerUtil::TestAddMonitor(cbs[i]);
355 #ifdef OHOS_BUILD_ENABLE_MONITOR
356 EXPECT_TRUE(IsValidHandlerId(ids[i]));
357 #else
358 EXPECT_EQ(ids[i], ERROR_UNSUPPORT);
359 #endif // OHOS_BUILD_ENABLE_MONITOR
360 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
361 }
362
363 auto pointerEvent = InputManagerUtil::SetupPointerEvent002();
364 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
365
366 for (const auto &id : ids) {
367 std::string sPointerEs = GetEventDump();
368 MMI_HILOGD("sPointerEs:%{public}s", sPointerEs.c_str());
369 #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
370 ASSERT_TRUE(!sPointerEs.empty());
371 #else
372 ASSERT_TRUE(sPointerEs.empty());
373 #endif // OHOS_BUILD_ENABLE_TOUCH && OHOS_BUILD_ENABLE_MONITOR
374 if (IsValidHandlerId(id)) {
375 InputManagerUtil::TestRemoveMonitor(id);
376 }
377 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
378 }
379
380 for (std::vector<int32_t>::size_type i = 0; i < N_TEST_CASES; i++) {
381 InputManagerUtil::TestRemoveMonitor(ids[i]);
382 }
383 }
384
385 /**
386 * @tc.name: InputManagerPointerTest_OnAddScreenMonitor_003
387 * @tc.desc: Verify touchscreen up event monitor
388 * @tc.type: FUNC
389 * @tc.require:
390 */
391 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_OnAddScreenMonitor_003, TestSize.Level1)
392 {
393 CALL_TEST_DEBUG;
394 auto pointerEvent = InputManagerUtil::SetupPointerEvent003();
395 ASSERT_NE(pointerEvent, nullptr);
396
397 auto callbackPtr = GetPtr<InputEventCallback>();
398 ASSERT_TRUE(callbackPtr != nullptr);
399 int32_t monitorId = InputManagerUtil::TestAddMonitor(callbackPtr);
400 #ifdef OHOS_BUILD_ENABLE_MONITOR
401 EXPECT_TRUE(IsValidHandlerId(monitorId));
402 #else
403 EXPECT_EQ(monitorId, ERROR_UNSUPPORT);
404 #endif // OHOS_BUILD_ENABLE_MONITOR
405 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
406
407 #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
408 TestSimulateInputEvent(pointerEvent);
409 #endif // OHOS_BUILD_ENABLE_TOUCH && OHOS_BUILD_ENABLE_MONITOR
410
411 if (IsValidHandlerId(monitorId)) {
412 InputManagerUtil::TestRemoveMonitor(monitorId);
413 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
414 }
415 InputManagerUtil::TestRemoveMonitor(monitorId);
416 }
417
418 /**
419 * @tc.name: InputManagerPointerTest_OnAddTouchPadMonitor_001
420 * @tc.desc: Verify touchpad down event monitor
421 * @tc.type: FUNC
422 * @tc.require:
423 */
424 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_OnAddTouchPadMonitor_001, TestSize.Level1)
425 {
426 CALL_TEST_DEBUG;
427 auto pointerEvent = PointerEvent::Create();
428 ASSERT_NE(pointerEvent, nullptr);
429 PointerEvent::PointerItem item;
430 item.SetDownTime(POINTER_ITEM_DOWNTIME_THREE);
431 item.SetPressed(true);
432 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_ONE);
433 item.SetDeviceId(1);
434 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_TWO);
435 item.SetPointerId(0);
436 pointerEvent->AddPointerItem(item);
437 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
438 pointerEvent->SetPointerId(0);
439 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
440
441 auto callbackPtr = GetPtr<InputEventCallback>();
442 ASSERT_TRUE(callbackPtr != nullptr);
443 int32_t monitorId = InputManagerUtil::TestAddMonitor(callbackPtr);
444 #ifdef OHOS_BUILD_ENABLE_MONITOR
445 EXPECT_TRUE(IsValidHandlerId(monitorId));
446 #else
447 EXPECT_EQ(monitorId, ERROR_UNSUPPORT);
448 #endif // OHOS_BUILD_ENABLE_MONITOR
449 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
450
451 InputManagerUtil::TestMonitor(monitorId, pointerEvent);
452 InputManagerUtil::TestRemoveMonitor(monitorId);
453 }
454
455 /**
456 * @tc.name: InputManagerPointerTest_OnAddTouchPadMonitor_002
457 * @tc.desc: Verify touchpad move event monitor
458 * @tc.type: FUNC
459 * @tc.require:
460 */
461 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_OnAddTouchPadMonitor_002, TestSize.Level1)
462 {
463 CALL_TEST_DEBUG;
464 auto pointerEvent = PointerEvent::Create();
465 ASSERT_NE(pointerEvent, nullptr);
466 PointerEvent::PointerItem item;
467 item.SetPointerId(0);
468 item.SetDownTime(POINTER_ITEM_DOWNTIME_TWO);
469 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_TWO);
470 item.SetPressed(true);
471 item.SetDeviceId(1);
472 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_THREE);
473 pointerEvent->AddPointerItem(item);
474 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
475 pointerEvent->SetPointerId(0);
476 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
477
478 auto callbackPtr = GetPtr<InputEventCallback>();
479 ASSERT_TRUE(callbackPtr != nullptr);
480 int32_t monitorId = InputManagerUtil::TestAddMonitor(callbackPtr);
481 #ifdef OHOS_BUILD_ENABLE_MONITOR
482 EXPECT_TRUE(IsValidHandlerId(monitorId));
483 #else
484 EXPECT_EQ(monitorId, ERROR_UNSUPPORT);
485 #endif // OHOS_BUILD_ENABLE_MONITOR
486 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
487
488 InputManagerUtil::TestMonitor(monitorId, pointerEvent);
489 InputManagerUtil::TestRemoveMonitor(monitorId);
490 }
491
492 /**
493 * @tc.name: InputManagerPointerTest_OnAddTouchPadMonitor_003
494 * @tc.desc: Verify touchpad up event monitor
495 * @tc.type: FUNC
496 * @tc.require:
497 */
498 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_OnAddTouchPadMonitor_003, TestSize.Level1)
499 {
500 CALL_TEST_DEBUG;
501 auto pointerEvent = PointerEvent::Create();
502 ASSERT_NE(pointerEvent, nullptr);
503 PointerEvent::PointerItem item;
504 item.SetDownTime(POINTER_ITEM_DOWNTIME_ONE);
505 item.SetPointerId(0);
506 item.SetPressed(true);
507 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_FOUR);
508 item.SetDeviceId(1);
509 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_FOUR);
510 pointerEvent->AddPointerItem(item);
511 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
512 pointerEvent->SetPointerId(0);
513 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
514
515 auto callbackPtr = GetPtr<InputEventCallback>();
516 ASSERT_TRUE(callbackPtr != nullptr);
517 int32_t monitorId = InputManagerUtil::TestAddMonitor(callbackPtr);
518 #ifdef OHOS_BUILD_ENABLE_MONITOR
519 EXPECT_TRUE(IsValidHandlerId(monitorId));
520 #else
521 EXPECT_EQ(monitorId, ERROR_UNSUPPORT);
522 #endif // OHOS_BUILD_ENABLE_MONITOR
523 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
524
525 InputManagerUtil::TestMonitor(monitorId, pointerEvent);
526 InputManagerUtil::TestRemoveMonitor(monitorId);
527 }
528
529 /**
530 * @tc.name: InputManagerPointerTest_OnAddTouchPadMonitor_004
531 * @tc.desc: Verify touchpad multiple monitor
532 * @tc.type: FUNC
533 * @tc.require:
534 */
535 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_OnAddTouchPadMonitor_004, TestSize.Level1)
536 {
537 CALL_TEST_DEBUG;
538 TestUtil->SetRecvFlag(RECV_FLAG::RECV_MONITOR);
539 auto pointerEvent = PointerEvent::Create();
540 ASSERT_NE(pointerEvent, nullptr);
541 PointerEvent::PointerItem item;
542 item.SetDownTime(POINTER_ITEM_DOWNTIME_FOUR);
543 item.SetDeviceId(1);
544 item.SetPointerId(0);
545 item.SetPressed(true);
546 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_THREE);
547 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_FIVE);
548 pointerEvent->AddPointerItem(item);
549 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
550 pointerEvent->SetPointerId(0);
551 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
552
553 const std::vector<int32_t>::size_type N_TEST_CASES{SIZE_TYPE_CASE};
554 std::vector<int32_t> ids(N_TEST_CASES);
555 auto callbackPtr = GetPtr<InputEventCallback>();
556 ASSERT_TRUE(callbackPtr != nullptr);
557 for (std::vector<int32_t>::size_type i = 0; i < N_TEST_CASES; ++i) {
558 ids[i] = InputManagerUtil::TestAddMonitor(callbackPtr);
559 #ifdef OHOS_BUILD_ENABLE_MONITOR
560 EXPECT_TRUE(IsValidHandlerId(ids[i]));
561 #else
562 EXPECT_EQ(ids[i], ERROR_UNSUPPORT);
563 #endif // OHOS_BUILD_ENABLE_MONITOR
564 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
565 }
566
567 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
568
569 for (const auto &id : ids) {
570 std::string sPointerEs = GetEventDump();
571 MMI_HILOGD("sPointerEs:%{public}s", sPointerEs.c_str());
572 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_MONITOR)
573 ASSERT_TRUE(!sPointerEs.empty());
574 #else
575 ASSERT_TRUE(sPointerEs.empty());
576 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_MONITOR
577 if (IsValidHandlerId(id)) {
578 InputManagerUtil::TestRemoveMonitor(id);
579 }
580 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
581 }
582
583 for (std::vector<int32_t>::size_type i = 0; i < N_TEST_CASES; ++i) {
584 InputManagerUtil::TestRemoveMonitor(ids[i]);
585 }
586 }
587
588 /**
589 * @tc.name: InputManagerPointerTest_OnAddTouchPadMonitor_005
590 * @tc.desc: Verify touchpad monitor
591 * @tc.type: FUNC
592 * @tc.require:
593 */
594 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_OnAddTouchPadMonitor_005, TestSize.Level1)
595 {
596 CALL_TEST_DEBUG;
597 auto pointerEvent = PointerEvent::Create();
598 ASSERT_NE(pointerEvent, nullptr);
599 PointerEvent::PointerItem item;
600 item.SetDownTime(POINTER_ITEM_DOWNTIME_FIVE);
601 item.SetPointerId(0);
602 item.SetDeviceId(1);
603 item.SetPressed(true);
604 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_FIVE);
605 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_ONE);
606 pointerEvent->AddPointerItem(item);
607 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
608 pointerEvent->SetPointerId(0);
609 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
610
611 auto callbackPtr = GetPtr<InputEventCallback>();
612 ASSERT_TRUE(callbackPtr != nullptr);
613 int32_t monitorId = InputManagerUtil::TestAddMonitor(callbackPtr);
614 #ifdef OHOS_BUILD_ENABLE_MONITOR
615 EXPECT_TRUE(IsValidHandlerId(monitorId));
616 #else
617 EXPECT_EQ(monitorId, ERROR_UNSUPPORT);
618 #endif // OHOS_BUILD_ENABLE_MONITOR
619 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
620
621 InputManagerUtil::TestMonitor(monitorId, pointerEvent);
622 InputManagerUtil::TestRemoveMonitor(monitorId);
623 }
624
625 /**
626 * @tc.name: InputManagerPointerTest_AddMouseMonitor_001
627 * @tc.desc: Verify mouse down event monitor
628 * @tc.type: FUNC
629 * @tc.require:
630 */
631 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_AddMouseMonitor_001, TestSize.Level1)
632 {
633 CALL_TEST_DEBUG;
634 auto callbackPtr = GetPtr<InputEventCallback>();
635 ASSERT_NE(callbackPtr, nullptr);
636 int32_t monitorId = InputManagerUtil::TestAddMonitor(callbackPtr);
637 #ifdef OHOS_BUILD_ENABLE_MONITOR
638 EXPECT_TRUE(IsValidHandlerId(monitorId));
639 #else
640 EXPECT_EQ(monitorId, ERROR_UNSUPPORT);
641 #endif // OHOS_BUILD_ENABLE_MONITOR
642 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
643
644 auto pointerEvent = InputManagerUtil::SetupPointerEvent005();
645 InputManagerUtil::TestMonitor(monitorId, pointerEvent);
646 InputManagerUtil::TestRemoveMonitor(monitorId);
647 }
648
649 /**
650 * @tc.name: InputManagerPointerTest_AddMouseMonitor_003
651 * @tc.desc: Verify mouse up event monitor
652 * @tc.type: FUNC
653 * @tc.require:
654 */
655 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_AddMouseMonitor_003, TestSize.Level1)
656 {
657 CALL_TEST_DEBUG;
658 auto callbackPtr = GetPtr<InputEventCallback>();
659 ASSERT_TRUE(callbackPtr != nullptr);
660 int32_t monitorId = InputManagerUtil::TestAddMonitor(callbackPtr);
661 #ifdef OHOS_BUILD_ENABLE_MONITOR
662 EXPECT_TRUE(IsValidHandlerId(monitorId));
663 #else
664 EXPECT_EQ(monitorId, ERROR_UNSUPPORT);
665 #endif // OHOS_BUILD_ENABLE_MONITOR
666 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
667
668 auto pointerEvent = InputManagerUtil::SetupPointerEvent007();
669 ASSERT_TRUE(pointerEvent != nullptr);
670 InputManagerUtil::TestMonitor(monitorId, pointerEvent);
671 InputManagerUtil::TestRemoveMonitor(monitorId);
672 }
673
674 /**
675 * @tc.name: InputManagerPointerTest_AddMouseMonitor_004
676 * @tc.desc: Verify monitor upper limit
677 * @tc.type: FUNC
678 * @tc.require:
679 */
680 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_AddMouseMonitor_004, TestSize.Level1)
681 {
682 CALL_TEST_DEBUG;
683 TestUtil->SetRecvFlag(RECV_FLAG::RECV_MONITOR);
684 const std::vector<int32_t>::size_type N_TEST_CASES{MAX_N_INPUT_HANDLERS - 1};
685 std::vector<int32_t> ids;
686 int32_t maxMonitor = 0;
687
688 for (std::vector<int32_t>::size_type i = 0; i < N_TEST_CASES; ++i) {
689 auto callbackPtr = GetPtr<InputEventCallback>();
690 ASSERT_TRUE(callbackPtr != nullptr);
691 maxMonitor = InputManagerUtil::TestAddMonitor(callbackPtr);
692 if (IsValidHandlerId(maxMonitor)) {
693 ids.push_back(maxMonitor);
694 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
695 }
696 }
697
698 auto pointerEvent = InputManagerUtil::SetupPointerEvent007();
699 pointerEvent->AddFlag(PointerEvent::EVENT_FLAG_NO_INTERCEPT);
700 ASSERT_TRUE(pointerEvent != nullptr);
701 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
702 maxMonitor = 0;
703 for (const auto &id : ids) {
704 if (!GetEventDump().empty()) {
705 maxMonitor++;
706 }
707 if (IsValidHandlerId(id)) {
708 InputManagerUtil::TestRemoveMonitor(id);
709 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
710 }
711 }
712 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_MONITOR)
713 ASSERT_EQ(maxMonitor, ids.size());
714 #else
715 ASSERT_EQ(maxMonitor, 0);
716 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_MONITOR
717 }
718
719 /**
720 * @tc.name: InputManagerPointerTest_OnAddKeyboardMonitor_001
721 * @tc.desc: Verify Keyboard multiple monitor
722 * @tc.type: FUNC
723 * @tc.require:
724 */
725 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_OnAddKeyboardMonitor_001, TestSize.Level1)
726 {
727 CALL_TEST_DEBUG;
728 TestUtil->SetRecvFlag(RECV_FLAG::RECV_MONITOR);
729 const std::vector<int32_t>::size_type N_TEST_CASES{SIZE_TYPE_CASE};
730 std::vector<int32_t> ids;
731 auto callbackPtr = GetPtr<InputEventCallback>();
732 ASSERT_TRUE(callbackPtr != nullptr);
733 for (std::vector<int32_t>::size_type i = 0; i < N_TEST_CASES; ++i) {
734 int32_t id = InputManagerUtil::TestAddMonitor(callbackPtr);
735 if (IsValidHandlerId(id)) {
736 ids.push_back(id);
737 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
738 }
739 }
740
741 auto injectEvent = InputManagerUtil::SetupKeyEvent001();
742 ASSERT_TRUE(injectEvent != nullptr);
743 InputManager::GetInstance()->SimulateInputEvent(injectEvent);
744
745 for (const auto &id : ids) {
746 std::string sPointerEs = GetEventDump();
747 MMI_HILOGD("sPointerEs:%{public}s", sPointerEs.c_str());
748 #if defined(OHOS_BUILD_ENABLE_KEYBOARD) && defined(OHOS_BUILD_ENABLE_MONITOR)
749 ASSERT_TRUE(!sPointerEs.empty());
750 #else
751 ASSERT_TRUE(sPointerEs.empty());
752 #endif // OHOS_BUILD_ENABLE_KEYBOARD && OHOS_BUILD_ENABLE_MONITOR
753 if (IsValidHandlerId(id)) {
754 InputManagerUtil::TestRemoveMonitor(id);
755 }
756 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
757 }
758 }
759
760 /**
761 * @tc.name: InputManagerPointerTest_OnAddKeyboardMonitor_002
762 * @tc.desc: Verify Keyboard multiple monitor
763 * @tc.type: FUNC
764 * @tc.require:
765 */
766 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_OnAddKeyboardMonitor_002, TestSize.Level1)
767 {
768 CALL_TEST_DEBUG;
769 const std::vector<int32_t>::size_type N_TEST_CASES{SIZE_TYPE_CASE};
770 std::vector<int32_t> ids;
771 auto callbackPtr = GetPtr<InputEventCallback>();
772 ASSERT_TRUE(callbackPtr != nullptr);
773 for (std::vector<int32_t>::size_type i = 0; i < N_TEST_CASES; ++i) {
774 int32_t id = InputManagerUtil::TestAddMonitor(callbackPtr);
775 if (IsValidHandlerId(id)) {
776 ids.push_back(id);
777 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
778 }
779 }
780
781 auto injectEvent = InputManagerUtil::SetupKeyEvent001();
782 ASSERT_TRUE(injectEvent != nullptr);
783 injectEvent->SetKeyCode(KeyEvent::KEYCODE_UNKNOWN);
784 InputManager::GetInstance()->SimulateInputEvent(injectEvent);
785
786 for (const auto &id : ids) {
787 std::string sPointerEs = GetEventDump();
788 MMI_HILOGD("sPointerEs:%{public}s", sPointerEs.c_str());
789 ASSERT_TRUE(sPointerEs.empty());
790 if (IsValidHandlerId(id)) {
791 InputManagerUtil::TestRemoveMonitor(id);
792 }
793 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
794 }
795 }
796
797 /**
798 * @tc.name: InputManagerPointerTest_SetWindowInputEventConsumer_001
799 * @tc.desc: Verify pointerEvent report eventHandler
800 * @tc.type: FUNC
801 * @tc.require: I5HMDY
802 */
803 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetWindowInputEventConsumer_001, TestSize.Level1)
804 {
805 CALL_TEST_DEBUG;
806 auto runner = AppExecFwk::EventRunner::Create("cooperateHdrTest");
807 ASSERT_TRUE(runner != nullptr);
808 auto eventHandler = std::make_shared<AppExecFwk::EventHandler>(runner);
809 ASSERT_TRUE(eventHandler != nullptr);
810 uint64_t runnerThreadId = 0;
811
__anon3cf8b9530402() 812 auto fun = [&runnerThreadId]() {
813 runnerThreadId = GetThisThreadId();
814 MMI_HILOGD("Create eventHandler is threadId:%{public}" PRIu64, runnerThreadId);
815 ASSERT_TRUE(runnerThreadId != 0);
816 };
817 eventHandler->PostSyncTask(fun, AppExecFwk::EventHandler::Priority::IMMEDIATE);
818 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
819 auto consumer = GetPtr<WindowEventConsumer>();
820 ASSERT_TRUE(consumer != nullptr);
821 MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(consumer, eventHandler);
822 auto pointerEvent = InputManagerUtil::SetupPointerEvent005();
823 pointerEvent->AddFlag(PointerEvent::EVENT_FLAG_NO_INTERCEPT);
824 ASSERT_TRUE(pointerEvent != nullptr);
825 AccessToken accessToken;
826 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
827 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
828 uint64_t consumerThreadId = consumer->GetConsumerThreadId();
829 #ifdef OHOS_BUILD_ENABLE_POINTER
830 EXPECT_EQ(runnerThreadId, consumerThreadId);
831 #else
832 ASSERT_TRUE(runnerThreadId != consumerThreadId);
833 #endif // OHOS_BUILD_ENABLE_POINTER
834 }
835
836 /**
837 * @tc.name: InputManagerPointerTest_SetWindowInputEventConsumer_002
838 * @tc.desc: Verify keyEvent report eventHandler
839 * @tc.type: FUNC
840 * @tc.require: I5HMDY
841 */
842 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetWindowInputEventConsumer_002, TestSize.Level1)
843 {
844 CALL_TEST_DEBUG;
845 const std::string threadTest = "threadNameTest";
846 auto runner = AppExecFwk::EventRunner::Create(threadTest);
847 ASSERT_TRUE(runner != nullptr);
848 auto eventHandler = std::make_shared<AppExecFwk::EventHandler>(runner);
849 ASSERT_TRUE(eventHandler != nullptr);
850 uint64_t runnerThreadId = 0;
851
__anon3cf8b9530502() 852 auto fun = [&runnerThreadId]() {
853 runnerThreadId = GetThisThreadId();
854 MMI_HILOGD("Create eventHandler is threadId:%{public}" PRIu64, runnerThreadId);
855 ASSERT_TRUE(runnerThreadId != 0);
856 };
857 eventHandler->PostSyncTask(fun, AppExecFwk::EventHandler::Priority::IMMEDIATE);
858 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
859 auto consumer = GetPtr<WindowEventConsumer>();
860 ASSERT_TRUE(consumer != nullptr);
861 MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(consumer, eventHandler);
862 auto keyEvent = InputManagerUtil::SetupKeyEvent001();
863 ASSERT_TRUE(keyEvent != nullptr);
864 keyEvent->SetKeyCode(KeyEvent::KEYCODE_A);
865 AccessToken accessToken;
866 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
867 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
868 uint64_t consumerThreadId = consumer->GetConsumerThreadId();
869 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
870 EXPECT_EQ(runnerThreadId, consumerThreadId);
871 #else
872 ASSERT_TRUE(runnerThreadId != consumerThreadId);
873 #endif // OHOS_BUILD_ENABLE_KEYBOARD
874 }
875
876 /**
877 * @tc.name: InputManagerPointerTest_MoveMouse_01
878 * @tc.desc: Verify move mouse
879 * @tc.type: FUNC
880 * @tc.require:
881 */
882 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_MoveMouse_01, TestSize.Level1)
883 {
884 CALL_TEST_DEBUG;
885 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_TWO, MOVE_MOUSE_OFFSET_TWO));
886 }
887
888 /**
889 * @tc.name: InputManagerPointerTest_MoveMouse_02
890 * @tc.desc: Verify move mouse
891 * @tc.type: FUNC
892 * @tc.require:
893 */
894 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_MoveMouse_02, TestSize.Level1)
895 {
896 CALL_TEST_DEBUG;
897 ASSERT_NO_FATAL_FAILURE(
898 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_THIRTEEN, MOVE_MOUSE_OFFSET_THREE));
899 }
900
901 /**
902 * @tc.name: InputManagerPointerTest_MouseHotArea_001
903 * @tc.desc: Mouse event Search window by pointerHotAreas
904 * @tc.type: FUNC
905 * @tc.require: I5HMCB
906 */
907 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_MouseHotArea_001, TestSize.Level1)
908 {
909 CALL_TEST_DEBUG;
910 std::shared_ptr<PointerEvent> pointerEvent{InputManagerUtil::SetupMouseEvent001()};
911 ASSERT_TRUE(pointerEvent != nullptr);
912 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
913 ASSERT_EQ(pointerEvent->GetSourceType(), PointerEvent::SOURCE_TYPE_MOUSE);
914 }
915
916 /**
917 * @tc.name: InputManagerPointerTest_MouseHotArea_002
918 * @tc.desc: Mouse event Search window by pointerHotAreas
919 * @tc.type: FUNC
920 * @tc.require: I5HMCB
921 */
922 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_MouseHotArea_002, TestSize.Level1)
923 {
924 CALL_TEST_DEBUG;
925 std::shared_ptr<PointerEvent> pointerEvent{InputManagerUtil::SetupMouseEvent002()};
926 ASSERT_TRUE(pointerEvent != nullptr);
927 ASSERT_EQ(pointerEvent->GetSourceType(), PointerEvent::SOURCE_TYPE_MOUSE);
928 }
929
930 /**
931 * @tc.name: InputManagerPointerTest_SetPointerLocation_001
932 * @tc.desc: Sets the absolute coordinate of mouse.
933 * @tc.type: FUNC
934 * @tc.require:
935 */
936 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetPointerLocation_001, TestSize.Level1)
937 {
938 CALL_TEST_DEBUG;
939 int32_t x = 0;
940 int32_t y = 0;
941 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->SetPointerLocation(x, y));
942 }
943
944 /**
945 * @tc.name: InputManagerPointerTest_SetPointerLocation_002
946 * @tc.desc: Sets the absolute coordinate of mouse.
947 * @tc.type: FUNC
948 * @tc.require:
949 */
950 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetPointerLocation_002, TestSize.Level1)
951 {
952 CALL_TEST_DEBUG;
953 int32_t x = 300;
954 int32_t y = 300;
955 ASSERT_TRUE(InputManager::GetInstance()->SetPointerLocation(x, y) == RET_OK);
956 }
957
958 /**
959 * @tc.name: InputManagerPointerTest_SetPointerVisible_001
960 * @tc.desc: Sets whether the pointer icon is visible
961 * @tc.type: FUNC
962 * @tc.require: I530VT
963 */
964 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetPointerVisible_001, TestSize.Level1)
965 {
966 bool isVisible{true};
967 if (InputManager::GetInstance()->SetPointerVisible(isVisible) == RET_OK) {
968 ASSERT_TRUE(InputManager::GetInstance()->IsPointerVisible() == isVisible);
969 }
970 }
971
972 /**
973 * @tc.name: InputManagerPointerTest_SetPointerVisible_002
974 * @tc.desc: Sets whether the pointer icon is visible
975 * @tc.type: FUNC
976 * @tc.require: I530VT
977 */
978 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetPointerVisible_002, TestSize.Level1)
979 {
980 bool isVisible{false};
981 if (InputManager::GetInstance()->SetPointerVisible(isVisible) == RET_OK) {
982 ASSERT_TRUE(InputManager::GetInstance()->IsPointerVisible() == isVisible);
983 }
984 }
985
986 /**
987 * @tc.name: InputManagerPointerTest_SetPointSpeed_001
988 * @tc.desc: Abnormal speed value processing
989 * @tc.type: FUNC
990 * @tc.require: I530XP I530UX
991 */
992 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetPointSpeed_001, TestSize.Level1)
993 {
994 CALL_TEST_DEBUG;
995 const int32_t speed = INVAID_VALUE;
996 InputManager::GetInstance()->SetPointerSpeed(speed);
997 int32_t speed1;
998 InputManager::GetInstance()->GetPointerSpeed(speed1);
999 ASSERT_EQ(speed1, 1);
1000 InputManager::GetInstance()->MoveMouse(-MOVE_MOUSE_OFFSET_ONE, MOVE_MOUSE_OFFSET_ONE);
1001 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_TWO, MOVE_MOUSE_OFFSET_TWO);
1002 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1003 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_THREE, MOVE_MOUSE_OFFSET_FOUR);
1004 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1005 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_FIVE, MOVE_MOUSE_OFFSET_SIX);
1006 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1007 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_SEVEN, MOVE_MOUSE_OFFSET_EIGHT);
1008 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1009 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_NINE, MOVE_MOUSE_OFFSET_TEN);
1010 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1011 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_ELEVEN, MOVE_MOUSE_OFFSET_TWELVE);
1012 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1013 }
1014
1015 /**
1016 * @tc.name: InputManagerPointerTest_SetPointSpeed_002
1017 * @tc.desc: Normal speed value processing
1018 * @tc.type: FUNC
1019 * @tc.require: I530XP I530UX
1020 */
1021 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetPointSpeed_002, TestSize.Level1)
1022 {
1023 CALL_TEST_DEBUG;
1024 const int32_t speed = 1;
1025 InputManager::GetInstance()->SetPointerSpeed(speed);
1026 int32_t speed1;
1027 InputManager::GetInstance()->GetPointerSpeed(speed1);
1028 ASSERT_EQ(speed1, speed);
1029 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_ONE, MOVE_MOUSE_OFFSET_ONE);
1030 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_TWO, MOVE_MOUSE_OFFSET_TWO);
1031 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1032 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_THREE, MOVE_MOUSE_OFFSET_FOUR);
1033 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1034 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_FIVE, MOVE_MOUSE_OFFSET_SIX);
1035 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1036 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_SEVEN, MOVE_MOUSE_OFFSET_EIGHT);
1037 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1038 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_NINE, MOVE_MOUSE_OFFSET_TEN);
1039 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1040 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_ELEVEN, MOVE_MOUSE_OFFSET_TWELVE);
1041 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1042 }
1043
1044 /**
1045 * @tc.name: InputManagerPointerTest_SetPointSpeed_003
1046 * @tc.desc: Normal speed value processing
1047 * @tc.type: FUNC
1048 * @tc.require: I530XP I530UX
1049 */
1050 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetPointSpeed_003, TestSize.Level1)
1051 {
1052 CALL_TEST_DEBUG;
1053 const int32_t speed = POINTER_SPEED_ONE;
1054 InputManager::GetInstance()->SetPointerSpeed(speed);
1055 int32_t speed1;
1056 InputManager::GetInstance()->GetPointerSpeed(speed1);
1057 ASSERT_EQ(speed1, speed);
1058 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_ONE, MOVE_MOUSE_OFFSET_ONE);
1059 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_TWO, MOVE_MOUSE_OFFSET_TWO);
1060 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1061 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_THREE, MOVE_MOUSE_OFFSET_FOUR);
1062 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1063 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_FIVE, MOVE_MOUSE_OFFSET_SIX);
1064 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1065 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_SEVEN, MOVE_MOUSE_OFFSET_EIGHT);
1066 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1067 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_NINE, MOVE_MOUSE_OFFSET_TEN);
1068 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1069 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_ELEVEN, MOVE_MOUSE_OFFSET_TWELVE);
1070 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1071 }
1072
1073 /**
1074 * @tc.name: InputManagerPointerTest_SetPointSpeed_004
1075 * @tc.desc: Normal speed value processing
1076 * @tc.type: FUNC
1077 * @tc.require: I530XP I530UX
1078 */
1079 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetPointSpeed_004, TestSize.Level1)
1080 {
1081 CALL_TEST_DEBUG;
1082 const int32_t speed = POINTER_SPEED_FOUR;
1083 InputManager::GetInstance()->SetPointerSpeed(speed);
1084 int32_t speed1;
1085 InputManager::GetInstance()->GetPointerSpeed(speed1);
1086 ASSERT_EQ(speed1, speed);
1087 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_ONE, MOVE_MOUSE_OFFSET_ONE);
1088 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_TWO, MOVE_MOUSE_OFFSET_TWO);
1089 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1090 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_THREE, MOVE_MOUSE_OFFSET_FOUR);
1091 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1092 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_FIVE, MOVE_MOUSE_OFFSET_SIX);
1093 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1094 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_SEVEN, MOVE_MOUSE_OFFSET_EIGHT);
1095 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1096 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_NINE, MOVE_MOUSE_OFFSET_TEN);
1097 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1098 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_ELEVEN, MOVE_MOUSE_OFFSET_TWELVE);
1099 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1100 }
1101
1102 /**
1103 * @tc.name: InputManagerPointerTest_SetPointSpeed_005
1104 * @tc.desc: Abnormal speed value processing
1105 * @tc.type: FUNC
1106 * @tc.require: I530XP I530UX
1107 */
1108 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetPointSpeed_005, TestSize.Level1)
1109 {
1110 CALL_TEST_DEBUG;
1111 const int32_t speed = POINTER_SPEED_FIVE;
1112 InputManager::GetInstance()->SetPointerSpeed(speed);
1113 int32_t speed1;
1114 InputManager::GetInstance()->GetPointerSpeed(speed1);
1115 ASSERT_EQ(speed1, POINTER_SPEED_FOUR);
1116 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_ONE, MOVE_MOUSE_OFFSET_ONE);
1117 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_TWO, MOVE_MOUSE_OFFSET_TWO);
1118 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1119 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_THREE, MOVE_MOUSE_OFFSET_FOUR);
1120 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1121 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_FIVE, MOVE_MOUSE_OFFSET_SIX);
1122 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1123 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_SEVEN, MOVE_MOUSE_OFFSET_EIGHT);
1124 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1125 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_NINE, MOVE_MOUSE_OFFSET_TEN);
1126 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1127 InputManager::GetInstance()->MoveMouse(MOVE_MOUSE_OFFSET_ELEVEN, MOVE_MOUSE_OFFSET_TWELVE);
1128 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1129 }
1130
1131 /**
1132 * @tc.name: InputManagerPointerTest_SetHoverScrollState_001
1133 * @tc.desc: Sets mouse hover scroll state in inactive window
1134 * @tc.type: FUNC
1135 * @tc.require: I530XS
1136 */
1137 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetHoverScrollState_001, TestSize.Level1)
1138 {
1139 CALL_TEST_DEBUG;
1140 ASSERT_TRUE(InputManager::GetInstance()->SetHoverScrollState(false) == RET_OK);
1141 InputManager::GetInstance()->SetHoverScrollState(true);
1142 }
1143
1144 /**
1145 * @tc.name: InputManagerPointerTest_SetHoverScrollState_002
1146 * @tc.desc: Sets mouse hover scroll state in inactive window
1147 * @tc.type: FUNC
1148 * @tc.require: I530XS
1149 */
1150 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetHoverScrollState_002, TestSize.Level1)
1151 {
1152 CALL_TEST_DEBUG;
1153 ASSERT_TRUE(InputManager::GetInstance()->SetHoverScrollState(true) == RET_OK);
1154 }
1155
1156 /**
1157 * @tc.name: InputManagerPointerTest_GetHoverScrollState_001
1158 * @tc.desc: Gets mouse hover scroll state in inactive window
1159 * @tc.type: FUNC
1160 * @tc.require: I530XS
1161 */
1162 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_GetHoverScrollState_001, TestSize.Level1)
1163 {
1164 CALL_TEST_DEBUG;
1165 bool state = true;
1166 if (InputManager::GetInstance()->SetHoverScrollState(state) == RET_OK) {
1167 ASSERT_TRUE(InputManager::GetInstance()->GetHoverScrollState(state) == RET_OK);
1168 ASSERT_TRUE(state);
1169 }
1170 }
1171
1172 /**
1173 * @tc.name: InputManagerPointerTest_SetMousePrimaryButton_001
1174 * @tc.desc: Sets mouse primary button
1175 * @tc.type: FUNC
1176 * @tc.require: I530XS
1177 */
1178 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetMousePrimaryButton_001, TestSize.Level1)
1179 {
1180 CALL_TEST_DEBUG;
1181 int32_t primaryButton = 1;
1182 ASSERT_TRUE(InputManager::GetInstance()->SetMousePrimaryButton(primaryButton) == RET_OK);
1183 primaryButton = 0;
1184 ASSERT_TRUE(InputManager::GetInstance()->SetMousePrimaryButton(primaryButton) == RET_OK);
1185 }
1186
1187 /**
1188 * @tc.name: InputManagerPointerTest_SetMousePrimaryButton_002
1189 * @tc.desc: Sets mouse primary button
1190 * @tc.type: FUNC
1191 * @tc.require: I530XS
1192 */
1193 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetMousePrimaryButton_002, TestSize.Level1)
1194 {
1195 CALL_TEST_DEBUG;
1196 int32_t primaryButton = INVAID_VALUE;
1197 ASSERT_TRUE(InputManager::GetInstance()->SetMousePrimaryButton(primaryButton) == RET_ERR);
1198 }
1199
1200 /**
1201 * @tc.name: InputManagerPointerTest_GetMousePrimaryButton_001
1202 * @tc.desc: Gets mouse primary button
1203 * @tc.type: FUNC
1204 * @tc.require: I530XS
1205 */
1206 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_GetMousePrimaryButton_001, TestSize.Level1)
1207 {
1208 CALL_TEST_DEBUG;
1209 int32_t primaryButton = 1;
1210 if (InputManager::GetInstance()->SetMousePrimaryButton(primaryButton) == RET_OK) {
1211 ASSERT_TRUE(InputManager::GetInstance()->GetMousePrimaryButton(primaryButton) == RET_OK);
1212 ASSERT_EQ(primaryButton, PrimaryButton::RIGHT_BUTTON);
1213 }
1214 }
1215
1216 /**
1217 * @tc.name: InputManagerPointerTest_SetMouseScrollRows_001
1218 * @tc.desc: Sets mouse scroll rows
1219 * @tc.type: FUNC
1220 * @tc.require: I530XS
1221 */
1222 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetMouseScrollRows_001, TestSize.Level1)
1223 {
1224 CALL_TEST_DEBUG;
1225 int32_t rows = 1;
1226 ASSERT_TRUE(InputManager::GetInstance()->SetMouseScrollRows(rows) == RET_OK);
1227 }
1228
1229 /**
1230 * @tc.name: InputManagerPointerTest_GetMouseScrollRows_001
1231 * @tc.desc: Sets mouse scroll rows
1232 * @tc.type: FUNC
1233 * @tc.require: I530XS
1234 */
1235 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_GetMouseScrollRows_001, TestSize.Level1)
1236 {
1237 CALL_TEST_DEBUG;
1238 int32_t rows = 50;
1239 int32_t newRows = 3;
1240 if (InputManager::GetInstance()->SetMouseScrollRows(rows) == RET_OK) {
1241 ASSERT_TRUE(InputManager::GetInstance()->GetMouseScrollRows(newRows) == RET_OK);
1242 ASSERT_EQ(rows, newRows);
1243 }
1244 }
1245
1246 /**
1247 * @tc.name: InputManagerPointerTest_SetMouseIcon_001
1248 * @tc.desc: Set the mouse icon for linux window
1249 * @tc.type: FUNC
1250 * @tc.require: I530XS
1251 */
1252 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetMouseIcon_001, TestSize.Level1)
1253 {
1254 CALL_TEST_DEBUG;
1255 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1256 CHKPV(window);
1257 uint32_t windowId = window->GetWindowId();
1258 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
1259 PointerStyle pointerStyle;
1260 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
1261 ASSERT_NE(pixelMap, nullptr);
1262 pointerStyle.id = MOUSE_ICON::DEVELOPER_DEFINED_ICON;
1263 if (InputManager::GetInstance()->SetMouseIcon(windowId, (void *)pixelMap.get()) == RET_OK) {
1264 ASSERT_TRUE(InputManager::GetInstance()->GetPointerStyle(windowId, pointerStyle) == RET_OK);
1265 ASSERT_EQ(pointerStyle.id, MOUSE_ICON::DEVELOPER_DEFINED_ICON);
1266 } else if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
1267 ASSERT_FALSE(false); // errors occur
1268 } else {
1269 ASSERT_TRUE(false);
1270 }
1271 }
1272
1273 /**
1274 * @tc.name: InputManagerPointerTest_SetMouseIcon_002
1275 * @tc.desc: Set the mouse icon for linux window
1276 * @tc.type: FUNC
1277 * @tc.require: I530XS
1278 */
1279 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetMouseIcon_002, TestSize.Level1)
1280 {
1281 CALL_TEST_DEBUG;
1282 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1283 CHKPV(window);
1284 uint32_t windowId = window->GetWindowId();
1285 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/Zoom_Out.svg";
1286 PointerStyle pointerStyle;
1287 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
1288 ASSERT_NE(pixelMap, nullptr);
1289 pointerStyle.id = MOUSE_ICON::DEVELOPER_DEFINED_ICON;
1290 if (InputManager::GetInstance()->SetMouseIcon(windowId, (void *)pixelMap.get()) == RET_OK) {
1291 ASSERT_TRUE(InputManager::GetInstance()->GetPointerStyle(windowId, pointerStyle) == RET_OK);
1292 ASSERT_EQ(pointerStyle.id, MOUSE_ICON::DEVELOPER_DEFINED_ICON);
1293 } else if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
1294 ASSERT_FALSE(false); // errors occur
1295 } else {
1296 ASSERT_TRUE(false);
1297 }
1298 }
1299
1300 /**
1301 * @tc.name: InputManagerPointerTest_SetMouseIcon_003
1302 * @tc.desc: Set the mouse icon for linux window
1303 * @tc.type: FUNC
1304 * @tc.require: I530XS
1305 */
1306 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetMouseIcon_003, TestSize.Level1)
1307 {
1308 CALL_TEST_DEBUG;
1309 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1310 CHKPV(window);
1311 uint32_t windowId = window->GetWindowId();
1312 PointerStyle pointerStyle;
1313 pointerStyle.id = MOUSE_ICON::DEFAULT;
1314 int32_t ret = InputManager::GetInstance()->SetPointerStyle(windowId, pointerStyle);
1315 ASSERT_TRUE(ret == RET_OK);
1316 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/Zoom_Out.svg";
1317 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
1318 ASSERT_TRUE(pixelMap != nullptr);
1319 pointerStyle.id = MOUSE_ICON::DEVELOPER_DEFINED_ICON;
1320 ret = InputManager::GetInstance()->SetMouseIcon(INVAID_VALUE, (void *)pixelMap.get());
1321 ASSERT_EQ(ret, RET_ERR);
1322 ASSERT_TRUE(InputManager::GetInstance()->GetPointerStyle(windowId, pointerStyle) == RET_OK);
1323 ASSERT_EQ(pointerStyle.id, MOUSE_ICON::DEFAULT);
1324 }
1325
1326 /**
1327 * @tc.name: InputManagerPointerTest_SetMouseHotSpot_001
1328 * @tc.desc: Set the mouse icon hot spot for linux window
1329 * @tc.type: FUNC
1330 * @tc.require: I530XS
1331 */
1332 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetMouseHotSpot_001, TestSize.Level1)
1333 {
1334 CALL_TEST_DEBUG;
1335 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1336 CHKPV(window);
1337 uint32_t windowId = window->GetWindowId();
1338 PointerStyle pointerStyle;
1339 pointerStyle.id = MOUSE_ICON::CROSS;
1340 if (InputManager::GetInstance()->SetPointerStyle(windowId, pointerStyle) == RET_OK) {
1341 ASSERT_TRUE(InputManager::GetInstance()->GetPointerStyle(windowId, pointerStyle) == RET_OK);
1342 ASSERT_EQ(pointerStyle.id, MOUSE_ICON::CROSS);
1343 }
1344 ASSERT_FALSE(
1345 InputManager::GetInstance()->SetMouseHotSpot(windowId, MOUSE_ICON_HOT_SPOT, MOUSE_ICON_HOT_SPOT) == RET_OK);
1346 }
1347
1348 /**
1349 * @tc.name: InputManagerPointerTest_SetMouseHotSpot_002
1350 * @tc.desc: Set the mouse icon hot spot for linux window
1351 * @tc.type: FUNC
1352 * @tc.require: I530XS
1353 */
1354 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetMouseHotSpot_002, TestSize.Level1)
1355 {
1356 CALL_TEST_DEBUG;
1357 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1358 CHKPV(window);
1359 uint32_t windowId = window->GetWindowId();
1360 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/Default.svg";
1361 PointerStyle pointerStyle;
1362 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
1363 ASSERT_NE(pixelMap, nullptr);
1364 pointerStyle.id = MOUSE_ICON::DEVELOPER_DEFINED_ICON;
1365 if (InputManager::GetInstance()->SetMouseIcon(windowId, (void *)pixelMap.get()) == RET_OK) {
1366 ASSERT_TRUE(InputManager::GetInstance()->GetPointerStyle(windowId, pointerStyle) == RET_OK);
1367 ASSERT_EQ(pointerStyle.id, MOUSE_ICON::DEVELOPER_DEFINED_ICON);
1368 ASSERT_TRUE(
1369 InputManager::GetInstance()->SetMouseHotSpot(windowId, MOUSE_ICON_HOT_SPOT, MOUSE_ICON_HOT_SPOT) == RET_OK);
1370 } else {
1371 ASSERT_FALSE(
1372 InputManager::GetInstance()->SetMouseHotSpot(windowId, MOUSE_ICON_HOT_SPOT, MOUSE_ICON_HOT_SPOT) == RET_OK);
1373 }
1374 }
1375
1376 /**
1377 * @tc.name: InputManagerPointerTest_SetPointerStyle_001
1378 * @tc.desc: Sets the pointer style of the window
1379 * @tc.type: FUNC
1380 * @tc.require: I530XS
1381 */
1382 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetPointerStyle_001, TestSize.Level1)
1383 {
1384 CALL_TEST_DEBUG;
1385 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1386 CHKPV(window);
1387 uint32_t windowId = window->GetWindowId();
1388 PointerStyle pointerStyle;
1389 pointerStyle.id = MOUSE_ICON::CROSS;
1390 if (InputManager::GetInstance()->SetPointerStyle(windowId, pointerStyle) == RET_OK) {
1391 ASSERT_TRUE(InputManager::GetInstance()->GetPointerStyle(windowId, pointerStyle) == RET_OK);
1392 ASSERT_EQ(pointerStyle.id, MOUSE_ICON::CROSS);
1393 }
1394 }
1395
1396 /**
1397 * @tc.name: InputManagerPointerTest_SetPointerStyle_002
1398 * @tc.desc: Sets the pointer style of the window
1399 * @tc.type: FUNC
1400 * @tc.require: I530XS
1401 */
1402 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetPointerStyle_002, TestSize.Level1)
1403 {
1404 CALL_TEST_DEBUG;
1405 uint32_t windowId = INVAID_VALUE;
1406 PointerStyle pointerStyle;
1407 pointerStyle.id = MOUSE_ICON::CROSS;
1408 if (InputManager::GetInstance()->SetPointerStyle(windowId, pointerStyle) == RET_OK) {
1409 ASSERT_TRUE(InputManager::GetInstance()->GetPointerStyle(windowId, pointerStyle) == RET_OK);
1410 ASSERT_EQ(pointerStyle.id, MOUSE_ICON::CROSS);
1411 }
1412 }
1413
1414 /**
1415 * @tc.name: InputManagerPointerTest_SetTouchpadScrollSwitch_001
1416 * @tc.desc: Set touchpad scroll switch
1417 * @tc.type: FUNC
1418 * @tc.require:
1419 */
1420 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetTouchpadScrollSwitch_001, TestSize.Level1)
1421 {
1422 CALL_TEST_DEBUG;
1423 bool flag = false;
1424 ASSERT_TRUE(InputManager::GetInstance()->SetTouchpadScrollSwitch(flag) == RET_OK);
1425 }
1426
1427 /**
1428 * @tc.name: InputManagerPointerTest_GetTouchpadScrollSwitch_001
1429 * @tc.desc: Get touchpad scroll switch
1430 * @tc.type: FUNC
1431 * @tc.require:
1432 */
1433 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_GetTouchpadScrollSwitch_001, TestSize.Level1)
1434 {
1435 CALL_TEST_DEBUG;
1436 bool flag = true;
1437 InputManager::GetInstance()->SetTouchpadScrollSwitch(flag);
1438 bool newFlag = true;
1439 ASSERT_TRUE(InputManager::GetInstance()->GetTouchpadScrollSwitch(newFlag) == RET_OK);
1440 ASSERT_TRUE(flag == newFlag);
1441 }
1442
1443 /**
1444 * @tc.name: InputManagerPointerTest_SetTouchpadScrollDirection_001
1445 * @tc.desc: Set touchpad scroll direction switch
1446 * @tc.type: FUNC
1447 * @tc.require:
1448 */
1449 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetTouchpadScrollDirection_001, TestSize.Level1)
1450 {
1451 CALL_TEST_DEBUG;
1452 bool state = false;
1453 ASSERT_TRUE(InputManager::GetInstance()->SetTouchpadScrollDirection(state) == RET_OK);
1454 }
1455
1456 /**
1457 * @tc.name: InputManagerPointerTest_GetTouchpadScrollDirection_001
1458 * @tc.desc: Get touchpad scroll direction switch
1459 * @tc.type: FUNC
1460 * @tc.require:
1461 */
1462 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_GetTouchpadScrollDirection_001, TestSize.Level1)
1463 {
1464 CALL_TEST_DEBUG;
1465 bool state = true;
1466 InputManager::GetInstance()->SetTouchpadScrollDirection(state);
1467 bool newState = true;
1468 ASSERT_TRUE(InputManager::GetInstance()->GetTouchpadScrollDirection(newState) == RET_OK);
1469 ASSERT_TRUE(state == newState);
1470 }
1471
1472 /**
1473 * @tc.name: InputManagerPointerTest_SetTouchpadTapSwitch_001
1474 * @tc.desc: Set touchpad tap switch
1475 * @tc.type: FUNC
1476 * @tc.require:
1477 */
1478 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetTouchpadTapSwitch_001, TestSize.Level1)
1479 {
1480 CALL_TEST_DEBUG;
1481 bool flag = false;
1482 ASSERT_TRUE(InputManager::GetInstance()->SetTouchpadTapSwitch(flag) == RET_OK);
1483 }
1484
1485 /**
1486 * @tc.name: InputManagerPointerTest_GetTouchpadTapSwitch_001
1487 * @tc.desc: Get touchpad tap switch
1488 * @tc.type: FUNC
1489 * @tc.require:
1490 */
1491 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_GetTouchpadTapSwitch_001, TestSize.Level1)
1492 {
1493 CALL_TEST_DEBUG;
1494 bool flag = true;
1495 InputManager::GetInstance()->SetTouchpadTapSwitch(flag);
1496 bool newFlag = true;
1497 ASSERT_TRUE(InputManager::GetInstance()->GetTouchpadTapSwitch(newFlag) == RET_OK);
1498 ASSERT_TRUE(flag == newFlag);
1499 }
1500
1501 /**
1502 * @tc.name: InputManagerPointerTest_SetTouchpadDoubleTapAndDragState_001
1503 * @tc.desc: Set touchpad double tap and drag switch
1504 * @tc.type: FUNC
1505 * @tc.require:
1506 */
1507 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetTouchpadDoubleTapAndDragState_001, TestSize.Level1)
1508 {
1509 CALL_TEST_DEBUG;
1510 bool flag = false;
1511 ASSERT_TRUE(InputManager::GetInstance()->SetTouchpadDoubleTapAndDragState(flag) == RET_OK);
1512 }
1513
1514 /**
1515 * @tc.name: InputManagerPointerTest_GetTouchpadDoubleTapAndDragState_001
1516 * @tc.desc: Get touchpad double tap and drag switch
1517 * @tc.type: FUNC
1518 * @tc.require:
1519 */
1520 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_GetTouchpadDoubleTapAndDragState_001, TestSize.Level1)
1521 {
1522 CALL_TEST_DEBUG;
1523 bool flag = true;
1524 InputManager::GetInstance()->SetTouchpadDoubleTapAndDragState(flag);
1525 bool newFlag = true;
1526 ASSERT_TRUE(InputManager::GetInstance()->GetTouchpadDoubleTapAndDragState(newFlag) == RET_OK);
1527 ASSERT_TRUE(flag == newFlag);
1528 }
1529
1530 /**
1531 * @tc.name: InputManagerPointerTest_SetTouchpadPointerSpeed_001
1532 * @tc.desc: Set touchpad pointer speed
1533 * @tc.type: FUNC
1534 * @tc.require:
1535 */
1536 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetTouchpadPointerSpeed_001, TestSize.Level1)
1537 {
1538 CALL_TEST_DEBUG;
1539 int32_t speed = POINTER_SPEED_ONE;
1540 ASSERT_TRUE(InputManager::GetInstance()->SetTouchpadPointerSpeed(speed) == RET_OK);
1541 }
1542
1543 /**
1544 * @tc.name: InputManagerPointerTest_GetTouchpadPointerSpeed_001
1545 * @tc.desc: Get touchpad pointer speed
1546 * @tc.type: FUNC
1547 * @tc.require:
1548 */
1549 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_GetTouchpadPointerSpeed_001, TestSize.Level1)
1550 {
1551 CALL_TEST_DEBUG;
1552 int32_t speed = POINTER_SPEED_TWO;
1553 InputManager::GetInstance()->SetTouchpadPointerSpeed(speed);
1554 int32_t newSpeed = POINTER_SPEED_THREE;
1555 ASSERT_TRUE(InputManager::GetInstance()->GetTouchpadPointerSpeed(newSpeed) == RET_OK);
1556 ASSERT_TRUE(speed == newSpeed);
1557 }
1558
1559 /**
1560 * @tc.name: InputManagerPointerTest_SetTouchpadPinchSwitch_001
1561 * @tc.desc: Set touchpad pinch switch
1562 * @tc.type: FUNC
1563 * @tc.require:
1564 */
1565 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetTouchpadPinchSwitch_001, TestSize.Level1)
1566 {
1567 CALL_TEST_DEBUG;
1568 bool flag = false;
1569 ASSERT_TRUE(InputManager::GetInstance()->SetTouchpadPinchSwitch(flag) == RET_OK);
1570 }
1571
1572 /**
1573 * @tc.name: InputManagerPointerTest_GetTouchpadPinchSwitch_001
1574 * @tc.desc: Get touchpad pinch switch
1575 * @tc.type: FUNC
1576 * @tc.require:
1577 */
1578 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_GetTouchpadPinchSwitch_001, TestSize.Level1)
1579 {
1580 CALL_TEST_DEBUG;
1581 bool flag = true;
1582 InputManager::GetInstance()->SetTouchpadPinchSwitch(flag);
1583 bool newFlag = true;
1584 ASSERT_TRUE(InputManager::GetInstance()->GetTouchpadPinchSwitch(newFlag) == RET_OK);
1585 ASSERT_TRUE(flag == newFlag);
1586 }
1587
1588 /**
1589 * @tc.name: InputManagerPointerTest_SetTouchpadSwipeSwitch_001
1590 * @tc.desc: Set touchpad swipe switch
1591 * @tc.type: FUNC
1592 * @tc.require:
1593 */
1594 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetTouchpadSwipeSwitch_001, TestSize.Level1)
1595 {
1596 CALL_TEST_DEBUG;
1597 bool flag = false;
1598 ASSERT_TRUE(InputManager::GetInstance()->SetTouchpadSwipeSwitch(flag) == RET_OK);
1599 }
1600
1601 /**
1602 * @tc.name: InputManagerPointerTest_GetTouchpadSwipeSwitch_001
1603 * @tc.desc: Get touchpad swipe switch
1604 * @tc.type: FUNC
1605 * @tc.require:
1606 */
1607 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_GetTouchpadSwipeSwitch_001, TestSize.Level1)
1608 {
1609 CALL_TEST_DEBUG;
1610 bool flag = true;
1611 InputManager::GetInstance()->SetTouchpadSwipeSwitch(flag);
1612 bool newFlag = true;
1613 ASSERT_TRUE(InputManager::GetInstance()->GetTouchpadSwipeSwitch(newFlag) == RET_OK);
1614 ASSERT_TRUE(flag == newFlag);
1615 }
1616
1617 /**
1618 * @tc.name: InputManagerPointerTest_SetTouchpadRightClickType_001
1619 * @tc.desc: Set touchpad right click type
1620 * @tc.type: FUNC
1621 * @tc.require:
1622 */
1623 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetTouchpadRightClickType_001, TestSize.Level1)
1624 {
1625 CALL_TEST_DEBUG;
1626 int32_t type = 1;
1627 ASSERT_TRUE(InputManager::GetInstance()->SetTouchpadRightClickType(type) == RET_OK);
1628 }
1629
1630 /**
1631 * @tc.name: InputManagerPointerTest_GetTouchpadRightClickType_001
1632 * @tc.desc: Get touchpad right click type
1633 * @tc.type: FUNC
1634 * @tc.require:
1635 */
1636 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_GetTouchpadRightClickType_001, TestSize.Level1)
1637 {
1638 CALL_TEST_DEBUG;
1639 int32_t type = RIGHT_CLICK_TYPE;
1640 InputManager::GetInstance()->SetTouchpadRightClickType(type);
1641 int32_t newType = 1;
1642 ASSERT_TRUE(InputManager::GetInstance()->GetTouchpadRightClickType(newType) == RET_OK);
1643 ASSERT_TRUE(type == newType);
1644 }
1645
1646 /**
1647 * @tc.name: InputManagerPointerTest_SetPointerSize_001
1648 * @tc.desc: Sets pointer size
1649 * @tc.type: FUNC
1650 * @tc.require: I530XS
1651 */
1652 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetPointerSize_001, TestSize.Level1)
1653 {
1654 CALL_TEST_DEBUG;
1655 int32_t setSize = 3;
1656 ASSERT_TRUE(InputManager::GetInstance()->SetPointerSize(setSize) == RET_OK);
1657 setSize = 1;
1658 InputManager::GetInstance()->SetPointerSize(setSize);
1659 }
1660
1661 /**
1662 * @tc.name: InputManagerPointerTest_GetPointerSize_001
1663 * @tc.desc: Gets pointer size
1664 * @tc.type: FUNC
1665 * @tc.require: I530XS
1666 */
1667 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_GetPointerSize_001, TestSize.Level1)
1668 {
1669 CALL_TEST_DEBUG;
1670 int32_t setSize = 1;
1671 ASSERT_TRUE(InputManager::GetInstance()->SetPointerSize(setSize) == RET_OK);
1672 int32_t getSize = 3;
1673 ASSERT_TRUE(InputManager::GetInstance()->GetPointerSize(getSize) == RET_OK);
1674 ASSERT_TRUE(setSize == getSize);
1675 }
1676
1677 /**
1678 * @tc.name: InputManagerPointerTest_SetPointerColor_001
1679 * @tc.desc: Sets pointer color
1680 * @tc.type: FUNC
1681 * @tc.require: I530XS
1682 */
1683 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetPointerColor_001, TestSize.Level1)
1684 {
1685 CALL_TEST_DEBUG;
1686 std::vector<int32_t> deviceIds;
__anon3cf8b9530602(std::vector<int32_t> ids) 1687 auto callback = [&deviceIds] (std::vector<int32_t> ids) {
1688 deviceIds = ids;
1689 };
1690 int32_t ret = InputManager::GetInstance()->GetDeviceIds(callback);
1691 ASSERT_EQ(ret, RET_OK);
1692 for (const auto& devicedId : deviceIds) {
1693 std::shared_ptr<InputDevice> device;
__anon3cf8b9530702(std::shared_ptr<InputDevice> inputDevice) 1694 auto tmpcallback = [&device] (std::shared_ptr<InputDevice> inputDevice) {
1695 device = inputDevice;
1696 };
1697 ASSERT_EQ(InputManager::GetInstance()->GetDevice(devicedId, tmpcallback), RET_OK);
1698 ASSERT_TRUE(device != nullptr);
1699 if (device->HasCapability(InputDeviceCapability::INPUT_DEV_CAP_POINTER)) {
1700 int32_t setColor = 0xA946F1;
1701 ASSERT_TRUE(InputManager::GetInstance()->SetPointerColor(setColor) == RET_OK);
1702 setColor = 0x000000;
1703 InputManager::GetInstance()->SetPointerColor(setColor);
1704 break;
1705 }
1706 }
1707 }
1708
1709 /**
1710 * @tc.name: InputManagerPointerTest_GetPointerColor_001
1711 * @tc.desc: Gets pointer color
1712 * @tc.type: FUNC
1713 * @tc.require: I530XS
1714 */
1715 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_GetPointerColor_001, TestSize.Level1)
1716 {
1717 CALL_TEST_DEBUG;
1718 std::vector<int32_t> deviceIds;
__anon3cf8b9530802(std::vector<int32_t> ids) 1719 auto callback = [&deviceIds] (std::vector<int32_t> ids) {
1720 deviceIds = ids;
1721 };
1722 int32_t ret = InputManager::GetInstance()->GetDeviceIds(callback);
1723 ASSERT_EQ(ret, RET_OK);
1724 for (const auto& devicedId : deviceIds) {
1725 std::shared_ptr<InputDevice> device;
__anon3cf8b9530902(std::shared_ptr<InputDevice> inputDevice) 1726 auto tmpcallback = [&device] (std::shared_ptr<InputDevice> inputDevice) {
1727 device = inputDevice;
1728 };
1729 ASSERT_EQ(InputManager::GetInstance()->GetDevice(devicedId, tmpcallback), RET_OK);
1730 ASSERT_TRUE(device != nullptr);
1731 if (device->HasCapability(InputDeviceCapability::INPUT_DEV_CAP_POINTER)) {
1732 int32_t setColor = 0x000000;
1733 ASSERT_TRUE(InputManager::GetInstance()->SetPointerColor(setColor) == RET_OK);
1734 int32_t getColor = 3;
1735 ASSERT_TRUE(InputManager::GetInstance()->GetPointerColor(getColor) == RET_OK);
1736 ASSERT_TRUE(setColor == getColor);
1737 break;
1738 }
1739 }
1740 }
1741
1742 /**
1743 * @tc.name: InputManagerPointerTest_SetCustomCursor_001
1744 * @tc.desc: Set the mouse custom cursor
1745 * @tc.type: FUNC
1746 * @tc.require: I530XS
1747 */
1748 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetCustomCursor_001, TestSize.Level1)
1749 {
1750 CALL_TEST_DEBUG;
1751 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1752 CHKPV(window);
1753 uint32_t windowId = window->GetWindowId();
1754 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
1755 PointerStyle pointerStyle;
1756 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
1757 ASSERT_NE(pixelMap, nullptr);
1758 pointerStyle.id = MOUSE_ICON::DEVELOPER_DEFINED_ICON;
1759 if (InputManager::GetInstance()->SetCustomCursor(windowId, (void *)pixelMap.get(), 32, 32) == RET_OK) {
1760 ASSERT_TRUE(InputManager::GetInstance()->GetPointerStyle(windowId, pointerStyle) == RET_OK);
1761 ASSERT_EQ(pointerStyle.id, MOUSE_ICON::DEVELOPER_DEFINED_ICON);
1762 } else if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
1763 ASSERT_FALSE(false); // errors occur
1764 } else {
1765 ASSERT_TRUE(false);
1766 }
1767 }
1768
1769 /**
1770 * @tc.name: InputManagerPointerTest_SetCustomCursor_002
1771 * @tc.desc: Set the mouse custom cursor
1772 * @tc.type: FUNC
1773 * @tc.require: I530XS
1774 */
1775 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetCustomCursor_002, TestSize.Level1)
1776 {
1777 CALL_TEST_DEBUG;
1778 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1779 CHKPV(window);
1780 uint32_t windowId = window->GetWindowId();
1781 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/Zoom_Out.svg";
1782 PointerStyle pointerStyle;
1783 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
1784 ASSERT_NE(pixelMap, nullptr);
1785 pointerStyle.id = MOUSE_ICON::DEVELOPER_DEFINED_ICON;
1786 if (InputManager::GetInstance()->SetCustomCursor(windowId, (void *)pixelMap.get(), 64, 64) == RET_OK) {
1787 ASSERT_TRUE(InputManager::GetInstance()->GetPointerStyle(windowId, pointerStyle) == RET_OK);
1788 ASSERT_EQ(pointerStyle.id, MOUSE_ICON::DEVELOPER_DEFINED_ICON);
1789 } else if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
1790 ASSERT_FALSE(false); // errors occur
1791 } else {
1792 ASSERT_TRUE(false);
1793 }
1794 }
1795
1796 /**
1797 * @tc.name: InputManagerPointerTest_SetCustomCursor_003
1798 * @tc.desc: Set the mouse custom cursor
1799 * @tc.type: FUNC
1800 * @tc.require: I530XS
1801 */
1802 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetCustomCursor_003, TestSize.Level1)
1803 {
1804 CALL_TEST_DEBUG;
1805 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1806 CHKPV(window);
1807 uint32_t windowId = window->GetWindowId();
1808 PointerStyle pointerStyle;
1809 pointerStyle.id = MOUSE_ICON::DEFAULT;
1810 int32_t ret = InputManager::GetInstance()->SetPointerStyle(windowId, pointerStyle);
1811 ASSERT_TRUE(ret == RET_OK);
1812 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/Zoom_Out.svg";
1813 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
1814 ASSERT_TRUE(pixelMap != nullptr);
1815 pointerStyle.id = MOUSE_ICON::DEVELOPER_DEFINED_ICON;
1816 ret = InputManager::GetInstance()->SetCustomCursor(INVAID_VALUE, (void *)pixelMap.get(), 0, 0);
1817 ASSERT_EQ(ret, RET_ERR);
1818 ASSERT_TRUE(InputManager::GetInstance()->GetPointerStyle(windowId, pointerStyle) == RET_OK);
1819 ASSERT_EQ(pointerStyle.id, MOUSE_ICON::DEFAULT);
1820 }
1821
1822 /**
1823 * @tc.name: InputManagerPointerTest_SetCustomCursor_004
1824 * @tc.desc: Set the mouse custom cursor
1825 * @tc.type: FUNC
1826 * @tc.require: I530XS
1827 */
1828 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetCustomCursor_004, TestSize.Level1)
1829 {
1830 CALL_TEST_DEBUG;
1831 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1832 CHKPV(window);
1833 uint32_t windowId = window->GetWindowId();
1834 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/Zoom_Out.svg";
1835 PointerStyle pointerStyle;
1836 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
1837 ASSERT_NE(pixelMap, nullptr);
1838 pointerStyle.id = MOUSE_ICON::DEVELOPER_DEFINED_ICON;
1839 if (InputManager::GetInstance()->SetCustomCursor(windowId, (void *)pixelMap.get()) == RET_OK) {
1840 ASSERT_TRUE(InputManager::GetInstance()->GetPointerStyle(windowId, pointerStyle) == RET_OK);
1841 ASSERT_EQ(pointerStyle.id, MOUSE_ICON::DEVELOPER_DEFINED_ICON);
1842 } else if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
1843 ASSERT_FALSE(false); // errors occur
1844 } else {
1845 ASSERT_TRUE(false);
1846 }
1847 }
1848
1849 /**
1850 * @tc.name: InputManagerPointerTest_SetCustomCursor_005
1851 * @tc.desc: Set the mouse custom cursor
1852 * @tc.type: FUNC
1853 * @tc.require: I530XS
1854 */
1855 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetCustomCursor_005, TestSize.Level1)
1856 {
1857 CALL_TEST_DEBUG;
1858 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1859 CHKPV(window);
1860 uint32_t windowId = window->GetWindowId();
1861 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/Zoom_Out.svg";
1862 PointerStyle pointerStyle;
1863 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
1864 ASSERT_NE(pixelMap, nullptr);
1865 pointerStyle.id = MOUSE_ICON::DEVELOPER_DEFINED_ICON;
1866 int32_t focusX = 64;
1867 if (InputManager::GetInstance()->SetCustomCursor(windowId, (void *)pixelMap.get(), focusX) == RET_OK) {
1868 ASSERT_TRUE(InputManager::GetInstance()->GetPointerStyle(windowId, pointerStyle) == RET_OK);
1869 ASSERT_EQ(pointerStyle.id, MOUSE_ICON::DEVELOPER_DEFINED_ICON);
1870 } else if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
1871 ASSERT_FALSE(false); // errors occur
1872 } else {
1873 ASSERT_TRUE(false);
1874 }
1875 }
1876
1877 /**
1878 * @tc.name: InputManagerPointerTest_SetTouchpadThreeFingersTapSwitch_001
1879 * @tc.desc: Set touchpad ThreeFingers Tap switch
1880 * @tc.type: FUNC
1881 * @tc.require:
1882 */
1883 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetTouchpadThreeFingersTapSwitch_001, TestSize.Level1)
1884 {
1885 CALL_TEST_DEBUG;
1886 bool flag = false;
1887 ASSERT_TRUE(InputManager::GetInstance()->SetTouchpadThreeFingersTapSwitch(flag) == RET_OK);
1888 }
1889
1890 /**
1891 * @tc.name: InputManagerPointerTest_SetTouchpadScrollRows_001
1892 * @tc.desc: Sets touchpad scroll rows
1893 * @tc.type: FUNC
1894 * @tc.require: I530XS
1895 */
1896 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_SetTouchpadScrollRows_001, TestSize.Level1)
1897 {
1898 CALL_TEST_DEBUG;
1899 int32_t rows = 1;
1900 ASSERT_TRUE(InputManager::GetInstance()->SetTouchpadScrollRows(rows) == RET_OK);
1901 }
1902
1903 /**
1904 * @tc.name: InputManagerPointerTest_GetTouchpadScrollRows_001
1905 * @tc.desc: Sets touchpad scroll rows
1906 * @tc.type: FUNC
1907 * @tc.require: I530XS
1908 */
1909 HWTEST_F(InputManagerPointerTest, InputManagerPointerTest_GetTouchpadScrollRows_001, TestSize.Level1)
1910 {
1911 CALL_TEST_DEBUG;
1912 int32_t rows = 50;
1913 int32_t newRows = 3;
1914 if (InputManager::GetInstance()->SetTouchpadScrollRows(rows) == RET_OK) {
1915 ASSERT_TRUE(InputManager::GetInstance()->GetTouchpadScrollRows(newRows) == RET_OK);
1916 ASSERT_EQ(rows, newRows);
1917 }
1918 }
1919 } // namespace MMI
1920 } // namespace OHOS