1 /*
2 * Copyright (c) 2021-2025 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 <cinttypes>
17 #include <semaphore.h>
18
19 #include <cJSON.h>
20 #include <config_policy_utils.h>
21
22 #include "event_log_helper.h"
23 #include "event_util_test.h"
24 #include "input_manager.h"
25 #include "input_manager_util.h"
26 #include "multimodal_event_handler.h"
27 #include "system_info.h"
28 #include "error_multimodal.h"
29
30 #undef MMI_LOG_TAG
31 #define MMI_LOG_TAG "InputManagerTest"
32
33 namespace OHOS {
34 namespace MMI {
35 namespace {
36 constexpr int32_t TUPLE_PID = 0;
37 constexpr int32_t TUPLE_UID = 1;
38 constexpr int32_t TUPLE_NAME = 2;
39 constexpr int32_t ITEM_WIDTH = 20;
40 constexpr int32_t ITEM_HEIGHT = 60;
41 constexpr int32_t TIME_WAIT_FOR_OP = 100;
42 constexpr int32_t NANOSECOND_TO_MILLISECOND = 1000000;
43 constexpr int32_t SLEEP_MILLISECONDS = 1000;
44 constexpr int32_t DEFAULT_DEVICE_ID = 0;
45 constexpr int32_t KEY_REPEAT_DELAY = 350;
46 constexpr int32_t KEY_REPEAT_RATE = 60;
47 constexpr int32_t POINTER_ITEM_DISPLAY_X_ONE = 147;
48 constexpr int32_t POINTER_ITEM_DISPLAY_X_TWO = 456;
49 constexpr int32_t POINTER_ITEM_DISPLAY_Y_ONE = 123;
50 constexpr int32_t POINTER_ITEM_DISPLAY_Y_TWO = 258;
51 constexpr int32_t POINTER_ITEM_WINDOW_X = 701;
52 constexpr int32_t POINTER_ITEM_WINDOW_Y = 702;
53 constexpr int32_t KEY_DOWN_DURATION = 300;
54 constexpr int32_t KEY_DOWN_DURATION_TWO = 500;
55 constexpr int32_t FINAL_KEY_DOWN_DURATION_ONE = 10;
56 constexpr int32_t FINAL_KEY_DOWN_DURATION_TWO = 2000;
57 constexpr int32_t POINTER_SENSOR_INPUT_TIME = 2000;
58 constexpr int32_t KEYBOARD_TYPE_SIZE = 20;
59 constexpr int32_t PARAMETER_ERROR = 401;
60 constexpr int32_t INVAID_VALUE = -1;
61 constexpr uint32_t MAX_WINDOW_NUMS = 15;
62 constexpr int32_t MOUSE_ICON_SIZE = 64;
63 constexpr int32_t SYNERGY_UID = 5521;
64 constexpr int32_t DEFAULT_SAMPLING_PERIOD { 8 }; // 8ms
65 constexpr int32_t MIN_MULTI_TOUCH_POINT_NUM { 0 };
66 constexpr int32_t MAX_MULTI_TOUCH_POINT_NUM { 10 };
67 constexpr int32_t UNKNOWN_MULTI_TOUCH_POINT_NUM { -1 };
68 #ifdef OHOS_BUILD_ENABLE_ANCO
69 constexpr uint32_t SHELL_FLAGS_VALUE = 2;
70 #endif // OHOS_BUILD_ENABLE_ANCO
71
72 constexpr double POINTER_ITEM_PRESSURE = 5.0;
73 } // namespace
74
75 class InputManagerTest : public testing::Test {
76 public:
77 void SetUp();
78 void TearDown();
79 static void SetUpTestCase();
80 std::string GetEventDump();
81 std::unique_ptr<OHOS::Media::PixelMap> SetMouseIconTest(const std::string iconPath);
82
83 protected:
84 void InjectAltTabs(size_t nTriggers);
85 void InjectAltL(size_t nTriggers);
86 void ReadMaxMultiTouchPointNum(int32_t &maxMultiTouchPointNum);
87 void ReadMaxMultiTouchPointNum(const std::string &cfgPath, int32_t &maxMultiTouchPointNum);
88 void ReadMaxMultiTouchPointNum(cJSON *productCfg, int32_t &maxMultiTouchPointNum);
89
90 private:
91 int32_t keyboardRepeatRate_ { 50 };
92 int32_t keyboardRepeatDelay_ { 500 };
93 };
94
95 class MMIWindowChecker : public MMI::IWindowChecker {
96 public:
97 int32_t CheckWindowId(int32_t windowId) const override;
98 };
99
100 class IEventObserver : public MMI::MMIEventObserver {
101 public:
102 void SyncBundleName(int32_t pid, int32_t uid, std::string bundleName, int32_t syncStatus) override;
103 };
104
SyncBundleName(int32_t pid,int32_t uid,std::string bundleName,int32_t syncStatus)105 void IEventObserver::SyncBundleName(int32_t pid, int32_t uid, std::string bundleName, int32_t syncStatus)
106 {
107 int32_t getPid = pid;
108 int32_t getUid = uid;
109 std::string getName = bundleName;
110 int32_t getStatus = syncStatus;
111 MMI_HILOGD("SyncBundleName info is :%{public}d, %{public}d, %{public}s, %{public}d",
112 getPid, getUid, getName.c_str(), getStatus);
113 }
114
CheckWindowId(int32_t windowId) const115 int32_t MMIWindowChecker::CheckWindowId(int32_t windowId) const
116 {
117 return getpid();
118 }
119
SetUpTestCase()120 void InputManagerTest::SetUpTestCase()
121 {
122 ASSERT_TRUE(TestUtil->Init());
123 }
124
SetUp()125 void InputManagerTest::SetUp()
126 {
127 TestUtil->SetRecvFlag(RECV_FLAG::RECV_FOCUS);
128 }
129
TearDown()130 void InputManagerTest::TearDown()
131 {
132 TestUtil->AddEventDump("");
133 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
134 InputManager::GetInstance()->SetKeyboardRepeatDelay(keyboardRepeatDelay_);
135 InputManager::GetInstance()->SetKeyboardRepeatRate(keyboardRepeatRate_);
136 }
137
GetEventDump()138 std::string InputManagerTest::GetEventDump()
139 {
140 return TestUtil->GetEventDump();
141 }
142
SetMouseIconTest(const std::string iconPath)143 std::unique_ptr<OHOS::Media::PixelMap> InputManagerTest::SetMouseIconTest(const std::string iconPath)
144 {
145 CALL_DEBUG_ENTER;
146 OHOS::Media::SourceOptions opts;
147 opts.formatHint = "image/svg+xml";
148 uint32_t ret = 0;
149 auto imageSource = OHOS::Media::ImageSource::CreateImageSource(iconPath, opts, ret);
150 CHKPP(imageSource);
151 std::set<std::string> formats;
152 ret = imageSource->GetSupportedFormats(formats);
153 MMI_HILOGD("Get supported format ret:%{public}u", ret);
154
155 OHOS::Media::DecodeOptions decodeOpts;
156 decodeOpts.desiredSize = {.width = MOUSE_ICON_SIZE, .height = MOUSE_ICON_SIZE};
157
158 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, ret);
159 CHKPL(pixelMap);
160 return pixelMap;
161 }
162
163 /**
164 * @tc.name: InputManagerTest_SetTouchpadThreeFingersTapSwitch_001
165 * @tc.desc: Test the funcation SetTouchpadThreeFingersTapSwitch
166 * @tc.type: FUNC
167 * @tc.require:
168 */
169 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadThreeFingersTapSwitch_001, TestSize.Level1)
170 {
171 CALL_TEST_DEBUG;
172 bool switchFlag = true;
173 int32_t ret = InputManager::GetInstance()->SetTouchpadThreeFingersTapSwitch(switchFlag);
174 EXPECT_EQ(ret, RET_OK);
175 }
176
177 /**
178 * @tc.name: InputManagerTest_GetTouchpadThreeFingersTapSwitch_001
179 * @tc.desc: Test the funcation GetTouchpadThreeFingersTapSwitch
180 * @tc.type: FUNC
181 * @tc.require:
182 */
183 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadThreeFingersTapSwitch_001, TestSize.Level1)
184 {
185 CALL_TEST_DEBUG;
186 bool switchFlag = true;
187 int32_t ret = InputManager::GetInstance()->GetTouchpadThreeFingersTapSwitch(switchFlag);
188 EXPECT_EQ(ret, RET_OK);
189 }
190
191 /**
192 * @tc.name: InputManagerTest_SetKeyDownDuration_01
193 * @tc.desc: Test SetKeyDownDuration
194 * @tc.type: FUNC
195 * @tc.require:
196 */
197 HWTEST_F(InputManagerTest, InputManagerTest_SetKeyDownDuration_01, TestSize.Level1)
198 {
199 CALL_TEST_DEBUG;
200 std::string businessId = "";
201 int32_t delay = 4500;
202 int32_t ret = InputManager::GetInstance()->SetKeyDownDuration(businessId, delay);
203 EXPECT_EQ(ret, RET_ERR);
204 }
205
206 /**
207 * @tc.name: InputManagerTest_SetKeyDownDuration_02
208 * @tc.desc: Test SetKeyDownDuration
209 * @tc.type: FUNC
210 * @tc.require:
211 */
212 HWTEST_F(InputManagerTest, InputManagerTest_SetKeyDownDuration_02, TestSize.Level1)
213 {
214 CALL_TEST_DEBUG;
215 std::string businessId = "";
216 int32_t delay = 0;
217 int32_t ret = InputManager::GetInstance()->SetKeyDownDuration(businessId, delay);
218 EXPECT_EQ(ret, PARAMETER_ERROR);
219 }
220
221 /**
222 * @tc.name: InputManagerTest_SetMouseIcon_01
223 * @tc.desc: Test SetMouseIcon
224 * @tc.type: FUNC
225 * @tc.require:
226 */
227 HWTEST_F(InputManagerTest, InputManagerTest_SetMouseIcon_01, TestSize.Level1)
228 {
229 CALL_TEST_DEBUG;
230 int32_t windowId = 2;
231 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
232 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerTest::SetMouseIconTest(iconPath);
233 ASSERT_NE(pixelMap, nullptr);
234
235 int32_t ret = InputManager::GetInstance()->SetMouseIcon(windowId, (void *)pixelMap.get());
236 EXPECT_EQ(ret, INVAID_VALUE);
237 pixelMap = nullptr;
238 }
239
240 /**
241 * @tc.name: InputManagerTest_EnableHardwareCursorStats_01
242 * @tc.desc: Test EnableHardwareCursorStats
243 * @tc.type: FUNC
244 * @tc.require:
245 */
246 HWTEST_F(InputManagerTest, InputManagerTest_EnableHardwareCursorStats_01, TestSize.Level1)
247 {
248 CALL_TEST_DEBUG;
249 bool enable = true;
250 int32_t ret = InputManager::GetInstance()->EnableHardwareCursorStats(enable);
251 EXPECT_EQ(ret, RET_OK);
252 }
253
254 /**
255 * @tc.name: InputManagerTest_EnableHardwareCursorStats_02
256 * @tc.desc: Test EnableHardwareCursorStats
257 * @tc.type: FUNC
258 * @tc.require:
259 */
260 HWTEST_F(InputManagerTest, InputManagerTest_EnableHardwareCursorStats_02, TestSize.Level1)
261 {
262 CALL_TEST_DEBUG;
263 bool enable = false;
264 int32_t ret = InputManager::GetInstance()->EnableHardwareCursorStats(enable);
265 EXPECT_EQ(ret, RET_OK);
266 }
267
268 /**
269 * @tc.name: InputManagerTest_SetMouseHotSpot_01
270 * @tc.desc: Test SetMouseHotSpot
271 * @tc.type: FUNC
272 * @tc.require:
273 */
274 HWTEST_F(InputManagerTest, InputManagerTest_SetMouseHotSpot_01, TestSize.Level1)
275 {
276 CALL_TEST_DEBUG;
277 int32_t windowId = 8;
278 int32_t hotSpotX = 3;
279 int32_t hotSpotY = 5;
280
281 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->GetWindowPid(windowId));
282 int32_t ret = InputManager::GetInstance()->SetMouseHotSpot(windowId, hotSpotX, hotSpotY);
283 EXPECT_EQ(ret, RET_ERR);
284 }
285
286 /**
287 * @tc.name: InputManagerTest_GetWinSyncBatchSize
288 * @tc.desc: Test GetWinSyncBatchSize
289 * @tc.type: FUNC
290 * @tc.require:
291 */
292 HWTEST_F(InputManagerTest, InputManagerTest_GetWinSyncBatchSize, TestSize.Level1)
293 {
294 int32_t maxAreasCount = 1;
295 int32_t displayCount = 2;
296 int32_t ret = InputManager::GetInstance()->GetWinSyncBatchSize(maxAreasCount, displayCount);
297 EXPECT_NE(ret, 0);
298 }
299
300 /**
301 * @tc.name: InputManager_NotResponse_001
302 * @tc.desc: detection of not response
303 * @tc.type: FUNC
304 * @tc.require:AR000GJG6G
305 */
306 HWTEST_F(InputManagerTest, InputManager_NotResponse_001, TestSize.Level1)
307 {
308 CALL_TEST_DEBUG;
309 auto pointerEvent = PointerEvent::Create();
310 ASSERT_NE(pointerEvent, nullptr);
311
312 PointerEvent::PointerItem item;
313 item.SetPressure(POINTER_ITEM_PRESSURE);
314 item.SetPointerId(0);
315 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_TWO);
316 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_ONE);
317 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
318 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
319 pointerEvent->SetPointerId(0);
320 pointerEvent->AddPointerItem(item);
321 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
322 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
323 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
324 }
325
326 /**
327 * @tc.name: InputManager_NotResponse_002
328 * @tc.desc: detection of not response
329 * @tc.type: FUNC
330 * @tc.require:SR000GGN6G
331 */
332 HWTEST_F(InputManagerTest, InputManager_NotResponse_002, TestSize.Level1)
333 {
334 CALL_TEST_DEBUG;
335 auto pointerEvent = PointerEvent::Create();
336 ASSERT_NE(pointerEvent, nullptr);
337
338 PointerEvent::PointerItem item;
339 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_TWO);
340 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_ONE);
341 item.SetPressure(POINTER_ITEM_PRESSURE);
342 item.SetPointerId(0);
343 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
344 pointerEvent->SetPointerId(0);
345 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
346 pointerEvent->AddPointerItem(item);
347 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
348 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
349 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
350 }
351
352 /**
353 * @tc.name: InputManagerTest_SubscribeKeyEvent_001
354 * @tc.desc: Verify invalid parameter.
355 * @tc.type: FUNC
356 * @tc.require:SR000GGQL4 AR000GJNGN
357 * @tc.author: yangguang
358 */
359 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_001, TestSize.Level1)
360 {
361 CALL_TEST_DEBUG;
362 std::set<int32_t> preKeys;
363 std::shared_ptr<KeyOption> keyOption =
364 InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_MUTE, true, 0);
365 int32_t response = INVAID_VALUE;
366 response = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, nullptr);
367 EXPECT_TRUE(response < 0);
368 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
369 InputManager::GetInstance()->UnsubscribeKeyEvent(response);
370 }
371
372 /**
373 * @tc.name: InputManagerTest_SubscribeKeyEvent_02
374 * @tc.desc: Verify subscribe power key event.
375 * @tc.type: FUNC
376 * @tc.require:SR000GGQL4 AR000GJNGN
377 * @tc.author: zhaoxueyuan
378 */
379 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_02, TestSize.Level1)
380 {
381 CALL_TEST_DEBUG;
382 ASSERT_TRUE(MMIEventHdl.InitClient());
383 // 电源键长按按下订阅
384 std::set<int32_t> preKeys;
385 std::shared_ptr<KeyOption> keyOption =
386 InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_POWER, true, FINAL_KEY_DOWN_DURATION_TWO);
387 int32_t subscribeId1 = INVAID_VALUE;
__anonaec9e8f50202(std::shared_ptr<KeyEvent> keyEvent) 388 subscribeId1 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
389 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
390 MMI_HILOGD("Subscribe key event KEYCODE_POWER down trigger callback");
391 });
392 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
393 EXPECT_FALSE(subscribeId1 >= 0);
394 #else
395 EXPECT_TRUE(subscribeId1 < 0);
396 #endif // OHOS_BUILD_ENABLE_KEYBOARD
397
398 // 电源键抬起订阅
399 std::shared_ptr<KeyOption> keyOption2 = InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_POWER, false, 0);
400 int32_t subscribeId2 = INVAID_VALUE;
__anonaec9e8f50302(std::shared_ptr<KeyEvent> keyEvent) 401 subscribeId2 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption2, [](std::shared_ptr<KeyEvent> keyEvent) {
402 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
403 MMI_HILOGD("Subscribe key event KEYCODE_POWER up trigger callback");
404 });
405 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
406 EXPECT_TRUE(subscribeId2 >= 0);
407 #else
408 EXPECT_TRUE(subscribeId2 < 0);
409 #endif // OHOS_BUILD_ENABLE_KEYBOARD
410
411 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
412 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId1);
413 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId2);
414 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
415 }
416
417 /**
418 * @tc.name: InputManagerTest_SubscribeKeyEvent_03
419 * @tc.desc: Verify subscribe volume up key event.
420 * @tc.type: FUNC
421 * @tc.require:
422 */
423 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_03, TestSize.Level1)
424 {
425 CALL_TEST_DEBUG;
426 ASSERT_TRUE(MMIEventHdl.InitClient());
427 std::set<int32_t> preKeys;
428 std::shared_ptr<KeyOption> keyOption1 =
429 InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_UP, true, FINAL_KEY_DOWN_DURATION_ONE);
430 int32_t subscribeId1 = INVAID_VALUE;
__anonaec9e8f50402(std::shared_ptr<KeyEvent> keyEvent) 431 subscribeId1 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption1, [](std::shared_ptr<KeyEvent> keyEvent) {
432 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
433 MMI_HILOGD("Subscribe key event KEYCODE_VOLUME_UP down trigger callback");
434 });
435 std::shared_ptr<KeyOption> keyOption2 =
436 InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_UP, false, 0);
437 int32_t subscribeId2 = INVAID_VALUE;
__anonaec9e8f50502(std::shared_ptr<KeyEvent> keyEvent) 438 subscribeId2 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption2, [](std::shared_ptr<KeyEvent> keyEvent) {
439 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
440 MMI_HILOGD("Subscribe key event KEYCODE_VOLUME_UP up trigger callback");
441 });
442 std::shared_ptr<KeyOption> keyOption3 = InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_UP, true, 0);
443 int32_t subscribeId3 = INVAID_VALUE;
__anonaec9e8f50602(std::shared_ptr<KeyEvent> keyEvent) 444 subscribeId3 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption3, [](std::shared_ptr<KeyEvent> keyEvent) {
445 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
446 MMI_HILOGD("Subscribe key event KEYCODE_VOLUME_UP down trigger callback");
447 });
448 std::shared_ptr<KeyOption> keyOption4 =
449 InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_UP, false, 0);
450 int32_t subscribeId4 = INVAID_VALUE;
__anonaec9e8f50702(std::shared_ptr<KeyEvent> keyEvent) 451 subscribeId4 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption4, [](std::shared_ptr<KeyEvent> keyEvent) {
452 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
453 MMI_HILOGD("Subscribe key event KEYCODE_VOLUME_UP up trigger callback");
454 });
455
456 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
457 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId1);
458 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId2);
459 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId3);
460 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId4);
461 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
462 }
463
464 /**
465 * @tc.name: InputManagerTest_SubscribeKeyEvent_04
466 * @tc.desc: Verify subscribe key event.
467 * @tc.type: FUNC
468 * @tc.require:
469 * @tc.author:
470 */
471 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_04, TestSize.Level1)
472 {
473 CALL_TEST_DEBUG;
474 std::set<int32_t> preKeys;
475 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
476 keyOption->SetPreKeys(preKeys);
477 keyOption->SetFinalKey(KeyEvent::KEYCODE_VOLUME_DOWN);
478 keyOption->SetFinalKeyDown(true);
479 keyOption->SetFinalKeyDownDuration(INVAID_VALUE);
480 int32_t subscribeId = INVAID_VALUE;
__anonaec9e8f50802(std::shared_ptr<KeyEvent> keyEvent) 481 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
482 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
483 MMI_HILOGD("Subscribe key event KEYCODE_POWER down trigger callback");
484 });
485 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
486 EXPECT_TRUE(subscribeId >= 0);
487 #else
488 EXPECT_TRUE(subscribeId < 0);
489 #endif // OHOS_BUILD_ENABLE_KEYBOARD
490 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
491 ASSERT_TRUE(injectDownEvent != nullptr);
492 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
493 KeyEvent::KeyItem kitDown;
494 kitDown.SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
495 kitDown.SetPressed(true);
496 kitDown.SetDownTime(downTime);
497 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
498 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
499 injectDownEvent->AddPressedKeyItems(kitDown);
500 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
501 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
502 }
503
504 /**
505 * @tc.name: InputManagerTest_SubscribeKeyEvent_08
506 * @tc.desc: Verify subscribe key event.
507 * @tc.type: FUNC
508 * @tc.require:
509 * @tc.author:
510 */
511 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_08, TestSize.Level1)
512 {
513 CALL_TEST_DEBUG;
514 std::set<int32_t> preKeys;
515 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
516 keyOption->SetPreKeys(preKeys);
517 keyOption->SetFinalKey(KeyEvent::KEYCODE_DAGGER_CLICK);
518 keyOption->SetFinalKeyDown(true);
519 keyOption->SetFinalKeyDownDuration(0);
520 int32_t subscribeId = INVAID_VALUE;
__anonaec9e8f50902(std::shared_ptr<KeyEvent> keyEvent) 521 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
522 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
523 MMI_HILOGD("Subscribe key event KEYCODE_DAGGER_CLICK down trigger callback");
524 });
525 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
526 EXPECT_TRUE(subscribeId >= 0);
527 #else
528 EXPECT_TRUE(subscribeId < 0);
529 #endif // OHOS_BUILD_ENABLE_KEYBOARD
530 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
531 ASSERT_TRUE(injectDownEvent != nullptr);
532 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
533 KeyEvent::KeyItem kitDown;
534 kitDown.SetKeyCode(KeyEvent::KEYCODE_DAGGER_CLICK);
535 kitDown.SetPressed(true);
536 kitDown.SetDownTime(downTime);
537 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_DAGGER_CLICK);
538 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
539 injectDownEvent->AddPressedKeyItems(kitDown);
540 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
541 }
542
543 /**
544 * @tc.name: InputManagerTest_SubscribeKeyEvent_06
545 * @tc.desc: Verify subscribe key event.
546 * @tc.type: FUNC
547 * @tc.require:
548 * @tc.author:
549 */
550 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_06, TestSize.Level1)
551 {
552 CALL_TEST_DEBUG;
553 std::set<int32_t> preKeys;
554 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
555 keyOption->SetPreKeys(preKeys);
556 keyOption->SetFinalKey(KeyEvent::KEYCODE_DAGGER_DOUBLE_CLICK);
557 keyOption->SetFinalKeyDown(true);
558 keyOption->SetFinalKeyDownDuration(0);
559 int32_t subscribeId = INVAID_VALUE;
__anonaec9e8f50a02(std::shared_ptr<KeyEvent> keyEvent) 560 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
561 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
562 MMI_HILOGD("Subscribe key event KEYCODE_DAGGER_DOUBLE_CLICK down trigger callback");
563 });
564 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
565 EXPECT_TRUE(subscribeId >= 0);
566 #else
567 EXPECT_TRUE(subscribeId < 0);
568 #endif // OHOS_BUILD_ENABLE_KEYBOARD
569 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
570 ASSERT_TRUE(injectDownEvent != nullptr);
571 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
572 KeyEvent::KeyItem kitDown;
573 kitDown.SetKeyCode(KeyEvent::KEYCODE_DAGGER_DOUBLE_CLICK);
574 kitDown.SetPressed(true);
575 kitDown.SetDownTime(downTime);
576 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_DAGGER_DOUBLE_CLICK);
577 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
578 injectDownEvent->AddPressedKeyItems(kitDown);
579 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
580 }
581
582 /**
583 * @tc.name: InputManagerTest_SubscribeKeyEvent_07
584 * @tc.desc: Verify subscribe key event.
585 * @tc.type: FUNC
586 * @tc.require:
587 * @tc.author:
588 */
589 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_07, TestSize.Level1)
590 {
591 CALL_TEST_DEBUG;
592 std::set<int32_t> preKeys;
593 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
594 keyOption->SetPreKeys(preKeys);
595 keyOption->SetFinalKey(KeyEvent::KEYCODE_DAGGER_LONG_PRESS);
596 keyOption->SetFinalKeyDown(true);
597 keyOption->SetFinalKeyDownDuration(0);
598 int32_t subscribeId = INVAID_VALUE;
__anonaec9e8f50b02(std::shared_ptr<KeyEvent> keyEvent) 599 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
600 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
601 MMI_HILOGD("Subscribe key event KEYCODE_DAGGER_LONG_PRESS down trigger callback");
602 });
603 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
604 EXPECT_TRUE(subscribeId >= 0);
605 #else
606 EXPECT_TRUE(subscribeId < 0);
607 #endif // OHOS_BUILD_ENABLE_KEYBOARD
608 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
609 ASSERT_TRUE(injectDownEvent != nullptr);
610 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
611 KeyEvent::KeyItem kitDown;
612 kitDown.SetKeyCode(KeyEvent::KEYCODE_DAGGER_LONG_PRESS);
613 kitDown.SetPressed(true);
614 kitDown.SetDownTime(downTime);
615 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_DAGGER_LONG_PRESS);
616 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
617 injectDownEvent->AddPressedKeyItems(kitDown);
618 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
619 }
620
InjectAltTabs(size_t nTriggers)621 void InputManagerTest::InjectAltTabs(size_t nTriggers)
622 {
623 auto keyEvent = KeyEvent::Create();
624 ASSERT_NE(keyEvent, nullptr);
625 keyEvent->SetKeyCode(KeyEvent::KEYCODE_TAB);
626
627 KeyEvent::KeyItem keyItem {};
628 keyItem.SetKeyCode(KeyEvent::KEYCODE_ALT_LEFT);
629 keyItem.SetPressed(true);
630 keyItem.SetDownTime(GetSysClockTime() - MS2US(DEFAULT_SAMPLING_PERIOD));
631 keyEvent->AddKeyItem(keyItem);
632 keyItem.SetKeyCode(KeyEvent::KEYCODE_TAB);
633
634 while (nTriggers-- > 0) {
635 auto now = GetSysClockTime();
636 keyItem.SetPressed(true);
637 keyItem.SetDownTime(now);
638 keyEvent->AddKeyItem(keyItem);
639 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
640 keyEvent->SetActionTime(now);
641 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
642 std::this_thread::sleep_for(std::chrono::milliseconds(DEFAULT_SAMPLING_PERIOD));
643
644 keyItem.SetPressed(false);
645 keyEvent->RemoveReleasedKeyItems(keyItem);
646
647 now = GetSysClockTime();
648 keyEvent->AddKeyItem(keyItem);
649 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
650 keyEvent->SetActionTime(now);
651 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
652 keyEvent->RemoveReleasedKeyItems(keyItem);
653 std::this_thread::sleep_for(std::chrono::milliseconds(DEFAULT_SAMPLING_PERIOD));
654 }
655 }
656
657 /**
658 * @tc.name: InputManagerTest_SubscribeKeyEvent_05
659 * @tc.desc: Verify subscription and unsubscription of ALT+TAB.
660 * @tc.type: FUNC
661 * @tc.require:
662 * @tc.author:
663 */
664 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_05, TestSize.Level1)
665 {
666 CALL_TEST_DEBUG;
667 size_t nCalls { 0 };
668 std::set<int32_t> preKeys { KeyEvent::KEYCODE_ALT_LEFT };
669 std::shared_ptr<KeyOption> keyOption = InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_TAB, true, 0);
670 auto subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption,
__anonaec9e8f50c02(std::shared_ptr<KeyEvent> keyEvent) 671 [&nCalls](std::shared_ptr<KeyEvent> keyEvent) {
672 if ((keyEvent->GetKeyCode() == KeyEvent::KEYCODE_TAB) &&
673 (keyEvent->GetKeyAction() == KeyEvent::KEY_ACTION_DOWN)) {
674 auto pressedKeys = keyEvent->GetPressedKeys();
675 if (std::any_of(pressedKeys.cbegin(), pressedKeys.cend(),
676 [](const auto keyCode) {
677 return (keyCode == KeyEvent::KEYCODE_ALT_LEFT);
678 })) {
679 ++nCalls;
680 }
681 }
682 });
683 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
684 ASSERT_TRUE(subscribeId >= 0);
685 size_t nTriggers { 30 };
686 InjectAltTabs(nTriggers);
687 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId));
688 InjectAltTabs(nTriggers);
689 #else
690 EXPECT_TRUE(subscribeId < 0);
691 #endif // OHOS_BUILD_ENABLE_KEYBOARD
692 }
693
694 /**
695 * @tc.name: InputManagerTest_SubscribeKeyEvent_09
696 * @tc.desc: Verify subscribe key event.
697 * @tc.type: FUNC
698 * @tc.require:
699 * @tc.author:
700 */
701 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_09, TestSize.Level1)
702 {
703 CALL_TEST_DEBUG;
704 std::set<int32_t> preKeys;
705 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
706 keyOption->SetPreKeys(preKeys);
707 keyOption->SetFinalKey(KeyEvent::KEYCODE_KEY_PEN_AIR_MOUSE);
708 keyOption->SetFinalKeyDown(true);
709 keyOption->SetFinalKeyDownDuration(0);
710 int32_t subscribeId = INVAID_VALUE;
__anonaec9e8f50e02(std::shared_ptr<KeyEvent> keyEvent) 711 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
712 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
713 MMI_HILOGD("[YKP] Subscribe key event KEYCODE_KEY_PEN_AIR_MOUSE down trigger callback");
714 });
715 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
716 EXPECT_TRUE(subscribeId >= 0);
717 #else
718 EXPECT_TRUE(subscribeId < 0);
719 #endif // OHOS_BUILD_ENABLE_KEYBOARD
720 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
721 ASSERT_TRUE(injectDownEvent != nullptr);
722 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
723 KeyEvent::KeyItem kitDown;
724 kitDown.SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_AIR_MOUSE);
725 kitDown.SetPressed(true);
726 kitDown.SetDownTime(downTime);
727 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_AIR_MOUSE);
728 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
729 injectDownEvent->AddPressedKeyItems(kitDown);
730 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
731 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
732
733 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
734 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
735 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
736 }
737
738 /**
739 * @tc.name: InputManagerTest_SubscribeKeyEvent_10
740 * @tc.desc: Verify subscribe key event.
741 * @tc.type: FUNC
742 * @tc.require:
743 * @tc.author:
744 */
745 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_10, TestSize.Level1)
746 {
747 CALL_TEST_DEBUG;
748 std::set<int32_t> preKeys;
749 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
750 keyOption->SetPreKeys(preKeys);
751 keyOption->SetFinalKey(KeyEvent::KEYCODE_KEY_PEN_LIGHT_PINCH);
752 keyOption->SetFinalKeyDown(true);
753 keyOption->SetFinalKeyDownDuration(0);
754 int32_t subscribeId = INVAID_VALUE;
__anonaec9e8f50f02(std::shared_ptr<KeyEvent> keyEvent) 755 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
756 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
757 MMI_HILOGD("[YKP] Subscribe key event KEYCODE_KEY_PEN_LIGHT_PINCH down trigger callback");
758 });
759 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
760 EXPECT_TRUE(subscribeId >= 0);
761 #else
762 EXPECT_TRUE(subscribeId < 0);
763 #endif // OHOS_BUILD_ENABLE_KEYBOARD
764 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
765 ASSERT_TRUE(injectDownEvent != nullptr);
766 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
767 KeyEvent::KeyItem kitDown;
768 kitDown.SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_LIGHT_PINCH);
769 kitDown.SetPressed(true);
770 kitDown.SetDownTime(downTime);
771 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_LIGHT_PINCH);
772 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
773 injectDownEvent->AddPressedKeyItems(kitDown);
774 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
775 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
776
777 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
778 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
779 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
780 }
781
782 /**
783 * @tc.name: InputManagerTest_SubscribeKeyEvent_13
784 * @tc.desc: Verify subscribe key event.
785 * @tc.type: FUNC
786 * @tc.require:
787 * @tc.author:
788 */
789 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_13, TestSize.Level1)
790 {
791 CALL_TEST_DEBUG;
792 std::set<int32_t> preKeys;
793 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
794 keyOption->SetPreKeys(preKeys);
795 keyOption->SetFinalKey(KeyEvent::KEYCODE_KEY_PEN_AI);
796 keyOption->SetFinalKeyDown(true);
797 keyOption->SetFinalKeyDownDuration(0);
798 int32_t subscribeId = INVAID_VALUE;
__anonaec9e8f51002(std::shared_ptr<KeyEvent> keyEvent) 799 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
800 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
801 MMI_HILOGD("[YKP] Subscribe key event KEYCODE_KEY_PEN_AI down trigger callback");
802 });
803 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
804 EXPECT_TRUE(subscribeId >= 0);
805 #else
806 EXPECT_TRUE(subscribeId < 0);
807 #endif // OHOS_BUILD_ENABLE_KEYBOARD
808 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
809 ASSERT_TRUE(injectDownEvent != nullptr);
810 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
811 KeyEvent::KeyItem kitDown;
812 kitDown.SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_AI);
813 kitDown.SetPressed(true);
814 kitDown.SetDownTime(downTime);
815 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_AI);
816 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
817 injectDownEvent->AddPressedKeyItems(kitDown);
818 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
819 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
820
821 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
822 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
823 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
824 }
825
826 /**
827 * @tc.name: InputManagerTest_SubscribeKeyEvent_11
828 * @tc.desc: Verify subscribe key event.
829 * @tc.type: FUNC
830 * @tc.require:
831 * @tc.author:
832 */
833 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_11, TestSize.Level1)
834 {
835 CALL_TEST_DEBUG;
836 std::set<int32_t> preKeys;
837 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
838 keyOption->SetPreKeys(preKeys);
839 keyOption->SetFinalKey(KeyEvent::KEYCODE_KEY_PEN_END_CLICK);
840 keyOption->SetFinalKeyDown(true);
841 keyOption->SetFinalKeyDownDuration(0);
842 int32_t subscribeId = INVAID_VALUE;
__anonaec9e8f51102(std::shared_ptr<KeyEvent> keyEvent) 843 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
844 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
845 MMI_HILOGD("Subscribe key event KEYCODE_KEY_PEN_END_CLICK down trigger callback");
846 });
847 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
848 EXPECT_TRUE(subscribeId >= 0);
849 #else
850 EXPECT_TRUE(subscribeId < 0);
851 #endif // OHOS_BUILD_ENABLE_KEYBOARD
852 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
853 ASSERT_TRUE(injectDownEvent != nullptr);
854 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
855 KeyEvent::KeyItem kitDown;
856 kitDown.SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_END_CLICK);
857 kitDown.SetPressed(true);
858 kitDown.SetDownTime(downTime);
859 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_END_CLICK);
860 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
861 injectDownEvent->AddPressedKeyItems(kitDown);
862 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
863 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
864
865 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
866 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
867 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
868 }
869
870 /**
871 * @tc.name: InputManagerTest_SubscribeKeyEvent_12
872 * @tc.desc: Verify subscribe key event.
873 * @tc.type: FUNC
874 * @tc.require:
875 * @tc.author:
876 */
877 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_12, TestSize.Level1)
878 {
879 CALL_TEST_DEBUG;
880 std::set<int32_t> preKeys;
881 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
882 keyOption->SetPreKeys(preKeys);
883 keyOption->SetFinalKey(KeyEvent::KEYCODE_KEY_PEN_END_DOUBLE_CLICK);
884 keyOption->SetFinalKeyDown(true);
885 keyOption->SetFinalKeyDownDuration(0);
886 int32_t subscribeId = INVAID_VALUE;
__anonaec9e8f51202(std::shared_ptr<KeyEvent> keyEvent) 887 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
888 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
889 MMI_HILOGD("[YKP] Subscribe key event KEYCODE_KEY_PEN_END_DOUBLE_CLICK down trigger callback");
890 });
891 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
892 EXPECT_TRUE(subscribeId >= 0);
893 #else
894 EXPECT_TRUE(subscribeId < 0);
895 #endif // OHOS_BUILD_ENABLE_KEYBOARD
896 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
897 ASSERT_TRUE(injectDownEvent != nullptr);
898 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
899 KeyEvent::KeyItem kitDown;
900 kitDown.SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_END_DOUBLE_CLICK);
901 kitDown.SetPressed(true);
902 kitDown.SetDownTime(downTime);
903 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_END_DOUBLE_CLICK);
904 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
905 injectDownEvent->AddPressedKeyItems(kitDown);
906 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
907 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
908
909 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
910 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
911 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
912 }
913
914
915 /**
916 * @tc.name: InputManagerTest_SubscribeKeyEvent_17
917 * @tc.desc: Verify subscribe key event.
918 * @tc.type: FUNC
919 * @tc.require:
920 * @tc.author:
921 */
922 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_17, TestSize.Level1)
923 {
924 CALL_TEST_DEBUG;
925 std::set<int32_t> preKeys;
926 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
927 keyOption->SetPreKeys(preKeys);
928 keyOption->SetFinalKey(KeyEvent::KEYCODE_KEY_PEN_MODE_SWITCH);
929 keyOption->SetFinalKeyDown(true);
930 keyOption->SetFinalKeyDownDuration(0);
931 int32_t subscribeId = INVAID_VALUE;
__anonaec9e8f51302(std::shared_ptr<KeyEvent> keyEvent) 932 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
933 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
934 MMI_HILOGD("[YKP] Subscribe key event KEYCODE_KEY_PEN_MODE_SWITCH down trigger callback");
935 });
936 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
937 EXPECT_TRUE(subscribeId >= 0);
938 #else
939 EXPECT_TRUE(subscribeId < 0);
940 #endif // OHOS_BUILD_ENABLE_KEYBOARD
941 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
942 ASSERT_TRUE(injectDownEvent != nullptr);
943 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
944 KeyEvent::KeyItem kitDown;
945 kitDown.SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_MODE_SWITCH);
946 kitDown.SetPressed(true);
947 kitDown.SetDownTime(downTime);
948 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_MODE_SWITCH);
949 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
950 injectDownEvent->AddPressedKeyItems(kitDown);
951 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
952 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
953
954 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
955 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
956 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
957 }
958
959 /**
960 * @tc.name: InputManagerTest_SubscribeKeyEvent_14
961 * @tc.desc: Verify subscribe key event.
962 * @tc.type: FUNC
963 * @tc.require:
964 * @tc.author:
965 */
966 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_14, TestSize.Level1)
967 {
968 CALL_TEST_DEBUG;
969 std::set<int32_t> preKeys;
970 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
971 keyOption->SetPreKeys(preKeys);
972 keyOption->SetFinalKey(KeyEvent::KEYCODE_REMOTE_POWER);
973 keyOption->SetFinalKeyDown(true);
974 keyOption->SetFinalKeyDownDuration(0);
975 int32_t subscribeId = INVAID_VALUE;
__anonaec9e8f51402(std::shared_ptr<KeyEvent> keyEvent) 976 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
977 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
978 MMI_HILOGD("Subscribe key event %{private}d down trigger callback", keyEvent->GetKeyCode());
979 });
980 EXPECT_TRUE(subscribeId >= 0);
981 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
982 ASSERT_TRUE(injectDownEvent != nullptr);
983 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
984 KeyEvent::KeyItem kitDown;
985 kitDown.SetKeyCode(KeyEvent::KEYCODE_REMOTE_POWER);
986 kitDown.SetPressed(true);
987 kitDown.SetDownTime(downTime);
988 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_REMOTE_POWER);
989 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
990 injectDownEvent->AddPressedKeyItems(kitDown);
991 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
992 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
993 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
994 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
995 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
996 }
997
998 /**
999 * @tc.name: InputManagerTest_SubscribeKeyEvent_15
1000 * @tc.desc: Verify subscribe key event.
1001 * @tc.type: FUNC
1002 * @tc.require:
1003 * @tc.author:
1004 */
1005 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_15, TestSize.Level1)
1006 {
1007 CALL_TEST_DEBUG;
1008 std::set<int32_t> preKeys;
1009 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
1010 keyOption->SetPreKeys(preKeys);
1011 keyOption->SetFinalKey(KeyEvent::KEYCODE_REMOTE_POWER);
1012 keyOption->SetFinalKeyDown(true);
1013 keyOption->SetFinalKeyDownDuration(0);
1014 int32_t subscribeId = INVAID_VALUE;
__anonaec9e8f51502(std::shared_ptr<KeyEvent> keyEvent) 1015 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
1016 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
1017 MMI_HILOGD("Subscribe key event %{private}d down trigger callback", keyEvent->GetKeyCode());
1018 });
1019 EXPECT_TRUE(subscribeId >= 0);
1020 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
1021 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
1022 }
1023
1024 /**
1025 * @tc.name: InputManagerTest_SubscribeKeyEvent_020
1026 * @tc.desc: Verify subscribe key event.
1027 * @tc.type: FUNC
1028 * @tc.require:
1029 * @tc.author:
1030 */
1031 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_020, TestSize.Level1)
1032 {
1033 CALL_TEST_DEBUG;
1034 std::set<int32_t> preKeys;
1035 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
1036 keyOption->SetPreKeys(preKeys);
1037 keyOption->SetFinalKey(KeyEvent::KEYCODE_REMOTE_POWER);
1038 keyOption->SetFinalKeyDown(true);
1039 keyOption->SetFinalKeyDownDuration(KEY_DOWN_DURATION_TWO);
1040 int32_t subscribeId = INVAID_VALUE;
__anonaec9e8f51602(std::shared_ptr<KeyEvent> keyEvent) 1041 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
1042 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
1043 MMI_HILOGD("Subscribe key event %{private}d down trigger callback", keyEvent->GetKeyCode());
1044 });
1045 EXPECT_TRUE(subscribeId >= 0);
1046 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
1047 ASSERT_TRUE(injectDownEvent != nullptr);
1048 int64_t downTime = KEY_DOWN_DURATION_TWO + 1;
1049 KeyEvent::KeyItem kitDown;
1050 kitDown.SetKeyCode(KeyEvent::KEYCODE_REMOTE_POWER);
1051 kitDown.SetPressed(true);
1052 kitDown.SetDownTime(downTime);
1053 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_REMOTE_POWER);
1054 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1055 injectDownEvent->AddPressedKeyItems(kitDown);
1056 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
1057 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
1058 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
1059 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
1060 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
1061 }
1062
1063 /**
1064 * @tc.name: InputManagerTest_SubscribeKeyEvent_020
1065 * @tc.desc: Verify subscribe key event.
1066 * @tc.type: FUNC
1067 * @tc.require:
1068 * @tc.author:
1069 */
1070 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_021, TestSize.Level1)
1071 {
1072 CALL_TEST_DEBUG;
1073 std::set<int32_t> preKeys;
1074 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
1075 keyOption->SetPreKeys(preKeys);
1076 keyOption->SetFinalKey(KeyEvent::KEYCODE_REMOTE_POWER);
1077 keyOption->SetFinalKeyDown(false);
1078 keyOption->SetFinalKeyDownDuration(0);
1079 int32_t subscribeId = INVAID_VALUE;
__anonaec9e8f51702(std::shared_ptr<KeyEvent> keyEvent) 1080 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
1081 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
1082 MMI_HILOGD("Subscribe key event %{private}d down trigger callback", keyEvent->GetKeyCode());
1083 });
1084 EXPECT_TRUE(subscribeId >= 0);
1085 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
1086 ASSERT_TRUE(injectDownEvent != nullptr);
1087 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
1088 KeyEvent::KeyItem kitDown;
1089 kitDown.SetKeyCode(KeyEvent::KEYCODE_REMOTE_POWER);
1090 kitDown.SetPressed(false);
1091 kitDown.SetDownTime(downTime);
1092 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_REMOTE_POWER);
1093 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
1094 injectDownEvent->AddPressedKeyItems(kitDown);
1095 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
1096 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_UP);
1097 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
1098 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
1099 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
1100 }
1101 /**
1102 * @tc.name: TestGetKeystrokeAbility_001
1103 * @tc.desc: Verify SupportKeys
1104 * @tc.type: FUNC
1105 * @tc.require:
1106 */
1107 HWTEST_F(InputManagerTest, TestGetKeystrokeAbility_001, TestSize.Level1)
1108 {
1109 CALL_TEST_DEBUG;
1110 std::vector<int32_t> keyCodes = {
1111 KeyEvent::KEYCODE_VOLUME_DOWN, KeyEvent::KEYCODE_VOLUME_MUTE, KeyEvent::KEYCODE_DEL};
1112 int32_t result = InputManager::GetInstance()->SupportKeys(
__anonaec9e8f51802(std::vector<bool> keystrokeAbility) 1113 0, keyCodes, [](std::vector<bool> keystrokeAbility) { MMI_HILOGD("TestGetKeystrokeAbility_001 callback ok"); });
1114 ASSERT_EQ(result, 0);
1115 MMI_HILOGD("Stop TestGetKeystrokeAbility_001");
1116 }
1117
1118 static int32_t g_deviceIDtest = 0;
GetKeyboardTypeCallback(int32_t keyboardType)1119 static void GetKeyboardTypeCallback(int32_t keyboardType)
1120 {
1121 switch (keyboardType) {
1122 case KEYBOARD_TYPE_NONE: {
1123 MMI_HILOGD("The g_deviceIDtest:%{public}d, KeyboardType:%{public}s", g_deviceIDtest, "None");
1124 break;
1125 }
1126 case KEYBOARD_TYPE_UNKNOWN: {
1127 MMI_HILOGD("The g_deviceIDtest:%{public}d, KeyboardType:%{public}s", g_deviceIDtest, "unknown");
1128 break;
1129 }
1130 case KEYBOARD_TYPE_ALPHABETICKEYBOARD: {
1131 MMI_HILOGD("The g_deviceIDtest:%{public}d, KeyboardType:%{public}s", g_deviceIDtest, "alphabetickeyboard");
1132 break;
1133 }
1134 case KEYBOARD_TYPE_DIGITALKEYBOARD: {
1135 MMI_HILOGD("The g_deviceIDtest:%{public}d, KeyboardType:%{public}s", g_deviceIDtest, "digitalkeyboard");
1136 break;
1137 }
1138 case KEYBOARD_TYPE_HANDWRITINGPEN: {
1139 MMI_HILOGD("The g_deviceIDtest:%{public}d, KeyboardType:%{public}s", g_deviceIDtest, "handwritingpen");
1140 break;
1141 }
1142 case KEYBOARD_TYPE_REMOTECONTROL: {
1143 MMI_HILOGD("The g_deviceIDtest:%{public}d, KeyboardType:%{public}s", g_deviceIDtest, "remotecontrol");
1144 break;
1145 }
1146 default: {
1147 MMI_HILOGW("Error obtaining keyboard type");
1148 break;
1149 }
1150 }
1151 }
1152
1153 /**
1154 * @tc.name: InputManagerTest_GetKeyboardType
1155 * @tc.desc: Verify Get Keyboard Type
1156 * @tc.type: FUNC
1157 * @tc.require:
1158 */
1159 HWTEST_F(InputManagerTest, InputManagerTest_GetKeyboardType, TestSize.Level1)
1160 {
1161 MMI_HILOGD("Start InputManagerTest_GetKeyboardType");
1162 for (int32_t i = 0; i < KEYBOARD_TYPE_SIZE; ++i) {
1163 g_deviceIDtest = i;
1164 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->GetKeyboardType(i, GetKeyboardTypeCallback));
1165 MMI_HILOGD("The i:%{public}d", i);
1166 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1167 }
1168 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1169 MMI_HILOGD("Stop InputManagerTest_GetKeyboardType");
1170 }
1171
1172 /**
1173 * @tc.name: InputManagerTest_SetKeyboardRepeatDelay
1174 * @tc.desc: Verify Set Keyboard Repeat Delay
1175 * @tc.type: FUNC
1176 * @tc.require:
1177 */
1178 HWTEST_F(InputManagerTest, InputManagerTest_SetKeyboardRepeatDelay, TestSize.Level1)
1179 {
1180 MMI_HILOGD("Start InputManagerTest_SetKeyboardRepeatDelay");
1181 int32_t ret = InputManager::GetInstance()->SetKeyboardRepeatDelay(KEY_REPEAT_DELAY);
1182 ASSERT_EQ(ret, RET_OK);
1183 MMI_HILOGD("Stop InputManagerTest_SetKeyboardRepeatDelay");
1184 }
1185
1186 /**
1187 * @tc.name: InputManagerTest_SetKeyboardRepeatRate
1188 * @tc.desc: Verify Set Keyboard Repeat Rate
1189 * @tc.type: FUNC
1190 * @tc.require:
1191 */
1192 HWTEST_F(InputManagerTest, InputManagerTest_SetKeyboardRepeatRate, TestSize.Level1)
1193 {
1194 MMI_HILOGD("Start InputManagerTest_SetKeyboardRepeatRate");
1195 int32_t ret = InputManager::GetInstance()->SetKeyboardRepeatRate(KEY_REPEAT_RATE);
1196 ASSERT_EQ(ret, RET_OK);
1197 MMI_HILOGD("Stop InputManagerTest_SetKeyboardRepeatRate");
1198 }
1199
1200 /**
1201 * @tc.name: InputManagerTest_GetKeyboardRepeatDelay
1202 * @tc.desc: Verify Get Keyboard Repeat Delay
1203 * @tc.type: FUNC
1204 * @tc.require:
1205 */
1206 HWTEST_F(InputManagerTest, InputManagerTest_GetKeyboardRepeatDelay, TestSize.Level1)
1207 {
1208 MMI_HILOGD("Start InputManagerTest_GetKeyboardRepeatDelay");
__anonaec9e8f51902(int32_t delay) 1209 auto callback = [](int32_t delay) {
1210 ASSERT_TRUE(delay == KEY_REPEAT_DELAY);
1211 MMI_HILOGD("Get keyboard repeat delay success");
1212 };
1213 if (InputManager::GetInstance()->SetKeyboardRepeatDelay(KEY_REPEAT_DELAY) == RET_OK) {
1214 ASSERT_TRUE(InputManager::GetInstance()->GetKeyboardRepeatDelay(callback) == RET_OK);
1215 }
1216 MMI_HILOGD("Stop InputManagerTest_GetKeyboardRepeatDelay");
1217 }
1218
1219 /**
1220 * @tc.name: InputManagerTest_GetKeyboardRepeatRate
1221 * @tc.desc: Verify Get Keyboard Repeat Rate
1222 * @tc.type: FUNC
1223 * @tc.require:
1224 */
1225 HWTEST_F(InputManagerTest, InputManagerTest_GetKeyboardRepeatRate, TestSize.Level1)
1226 {
1227 MMI_HILOGD("Start InputManagerTest_GetKeyboardRepeatRate");
__anonaec9e8f51a02(int32_t rate) 1228 auto callback = [](int32_t rate) {
1229 ASSERT_TRUE(rate == KEY_REPEAT_RATE);
1230 MMI_HILOGD("Get keyboard repeat rate success");
1231 };
1232 if (InputManager::GetInstance()->SetKeyboardRepeatRate(KEY_REPEAT_RATE) == RET_OK) {
1233 ASSERT_TRUE(InputManager::GetInstance()->GetKeyboardRepeatRate(callback) == RET_OK);
1234 }
1235 MMI_HILOGD("Stop InputManagerTest_GetKeyboardRepeatRate");
1236 }
1237
1238 HWTEST_F(InputManagerTest, InputManagerTest_GetProcCpuUsage, TestSize.Level1)
1239 {
1240 CALL_TEST_DEBUG;
1241 SYSTEM_INFO::CpuInfo cpuInfo;
1242 const std::string process_name = "multimodalinput";
1243 auto usage = cpuInfo.GetProcCpuUsage(process_name);
1244 MMI_HILOGD("The CPU usage of the %{public}s process is %{public}.2f", process_name.c_str(), usage);
1245 ASSERT_TRUE(usage < SYSTEM_INFO::CPU_USAGE_LOAD && usage != SYSTEM_INFO::CPU_USAGE_UNKNOWN);
1246 }
1247
1248 /**
1249 * @tc.name: InputManagerTest_FunctionKeyState_001
1250 * @tc.desc: Set NumLock for the keyboard enablement state to true
1251 * @tc.type: FUNC
1252 * @tc.require: I5HMCX
1253 */
1254 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_001, TestSize.Level1)
1255 {
1256 CALL_TEST_DEBUG;
1257 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY, true);
1258 bool state = false;
1259 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY, state);
1260 ASSERT_FALSE(state);
1261 }
1262
1263 /**
1264 * @tc.name: InputManagerTest_FunctionKeyState_002
1265 * @tc.desc: Set NumLock for the keyboard enablement state to false
1266 * @tc.type: FUNC
1267 * @tc.require: I5HMCX
1268 */
1269 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_002, TestSize.Level1)
1270 {
1271 CALL_TEST_DEBUG;
1272 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY, false);
1273 bool state = true;
1274 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY, state);
1275 ASSERT_FALSE(state);
1276 }
1277
1278 /**
1279 * @tc.name: InputManagerTest_FunctionKeyState_003
1280 * @tc.desc: Set ScrollLock for the keyboard enablement state to true
1281 * @tc.type: FUNC
1282 * @tc.require: I5HMCX
1283 */
1284 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_003, TestSize.Level1)
1285 {
1286 CALL_TEST_DEBUG;
1287 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY, true);
1288 bool state = false;
1289 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY, state);
1290 ASSERT_FALSE(state);
1291 }
1292
1293 /**
1294 * @tc.name: InputManagerTest_FunctionKeyState_004
1295 * @tc.desc: Set ScrollLock for the keyboard enablement state to false
1296 * @tc.type: FUNC
1297 * @tc.require: I5HMCX
1298 */
1299 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_004, TestSize.Level1)
1300 {
1301 CALL_TEST_DEBUG;
1302 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY, false);
1303 bool state = true;
1304 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY, state);
1305 ASSERT_FALSE(state);
1306 }
1307
1308 /**
1309 * @tc.name: InputManagerTest_FunctionKeyState_005
1310 * @tc.desc: Set CapsLock for the keyboard enablement state to true
1311 * @tc.type: FUNC
1312 * @tc.require: I5HMCX
1313 */
1314 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_005, TestSize.Level1)
1315 {
1316 CALL_TEST_DEBUG;
1317 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY, true);
1318 bool state = false;
1319 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY, state);
1320 ASSERT_FALSE(state);
1321 }
1322
1323 /**
1324 * @tc.name: InputManagerTest_FunctionKeyState_006
1325 * @tc.desc: Set CapsLock for the keyboard enablement state to false
1326 * @tc.type: FUNC
1327 * @tc.require: I5HMCX
1328 */
1329 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_006, TestSize.Level1)
1330 {
1331 CALL_TEST_DEBUG;
1332 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY, false);
1333 bool state = true;
1334 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY, state);
1335 ASSERT_FALSE(state);
1336 }
1337
1338 /**
1339 * @tc.name: InputManagerTest_FunctionKeyState_007
1340 * @tc.desc: Set other function keys
1341 * @tc.type: FUNC
1342 * @tc.require: I5HMCX
1343 */
1344 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_007, TestSize.Level1)
1345 {
1346 CALL_TEST_DEBUG;
1347 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY, true);
1348 bool state = true;
1349 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY, state);
1350 ASSERT_FALSE(state);
1351
1352 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY, false);
1353 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY, state);
1354 ASSERT_FALSE(state);
1355 }
1356
1357 /**
1358 * @tc.name: InputManagerTest_EnableCombineKey_001
1359 * @tc.desc: Enable combine key
1360 * @tc.type: FUNC
1361 * @tc.require: I5HMCX
1362 */
1363 HWTEST_F(InputManagerTest, InputManagerTest_EnableCombineKey_001, TestSize.Level1)
1364 {
1365 CALL_TEST_DEBUG;
1366 ASSERT_EQ(InputManager::GetInstance()->EnableCombineKey(false), RET_OK);
1367 }
1368
1369 /**
1370 * @tc.name: InputManagerTest_EnableCombineKey_002
1371 * @tc.desc: Enable combine key
1372 * @tc.type: FUNC
1373 * @tc.require: I5HMCX
1374 */
1375 HWTEST_F(InputManagerTest, InputManagerTest_EnableCombineKey_002, TestSize.Level1)
1376 {
1377 CALL_TEST_DEBUG;
1378 ASSERT_EQ(InputManager::GetInstance()->EnableCombineKey(true), RET_OK);
1379 }
1380
1381 /**
1382 * @tc.name: InputManagerTest_TouchScreenHotArea_001
1383 * @tc.desc: Touch event Search window by defaultHotAreas
1384 * @tc.type: FUNC
1385 * @tc.require: I5HMCB
1386 */
1387 HWTEST_F(InputManagerTest, InputManagerTest_TouchScreenHotArea_001, TestSize.Level1)
1388 {
1389 CALL_TEST_DEBUG;
1390 std::shared_ptr<PointerEvent> pointerEvent{InputManagerUtil::SetupTouchScreenEvent001()};
1391 ASSERT_TRUE(pointerEvent != nullptr);
1392 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
1393 ASSERT_EQ(pointerEvent->GetSourceType(), PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
1394 }
1395
1396 /**
1397 * @tc.name: InputManagerTest_TouchScreenHotArea_002
1398 * @tc.desc: Touch event Search window by pointerHotAreas
1399 * @tc.type: FUNC
1400 * @tc.require: I5HMCB
1401 */
1402 HWTEST_F(InputManagerTest, InputManagerTest_TouchScreenHotArea_002, TestSize.Level1)
1403 {
1404 CALL_TEST_DEBUG;
1405 std::shared_ptr<PointerEvent> pointerEvent{InputManagerUtil::SetupTouchScreenEvent002()};
1406 ASSERT_TRUE(pointerEvent != nullptr);
1407 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
1408 ASSERT_EQ(pointerEvent->GetSourceType(), PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
1409 }
1410
1411 /**
1412 * @tc.name: InputManagerTest_UpdateDisplayInfo
1413 * @tc.desc: Update window information
1414 * @tc.type: FUNC
1415 * @tc.require:
1416 */
1417 HWTEST_F(InputManagerTest, InputManagerTest_UpdateDisplayInfo, TestSize.Level1)
1418 {
1419 CALL_TEST_DEBUG;
1420 DisplayGroupInfo displayGroupInfo;
1421 displayGroupInfo.focusWindowId = 0;
1422 UserScreenInfo userScreenInfo;
1423 userScreenInfo.displayGroups.push_back(displayGroupInfo);
1424 InputManager::GetInstance()->UpdateDisplayInfo(userScreenInfo);
1425 if (!userScreenInfo.displayGroups.empty()) {
1426 ASSERT_TRUE(userScreenInfo.displayGroups[0].displaysInfo.empty());
1427 }
1428 }
1429
1430 /**
1431 * @tc.name: InputManagerTest_UpdateDisplayInfo for 1 display and 1 window
1432 * @tc.desc: Update window information
1433 * @tc.type: FUNC
1434 * @tc.require:
1435 */
1436 HWTEST_F(InputManagerTest, InputManagerTest_UpdateDisplayInfo001, TestSize.Level1)
1437 {
1438 CALL_TEST_DEBUG;
1439 DisplayGroupInfo displayGroupInfo;
1440 displayGroupInfo.focusWindowId = 1;
1441 int32_t dgw = 1000;
1442 int32_t dgh = 2000;
1443 DisplayInfo displayInfo;
1444 displayInfo.id = 0;
1445 displayInfo.x =1;
1446 displayInfo.y = 1;
1447 displayInfo.width = 2;
1448 displayInfo.height = 2;
1449 displayInfo.dpi = 240;
1450 displayInfo.name = "pp";
1451 displayInfo.direction = DIRECTION0;
1452 displayGroupInfo.displaysInfo.push_back(displayInfo);
1453 WindowInfo info;
1454 info.id = 1;
1455 info.pid = 1;
1456 info.uid = 1;
1457 info.area = {1, 1, 1, 1};
1458 info.defaultHotAreas = { info.area };
1459 info.pointerHotAreas = { info.area };
1460 info.pointerChangeAreas = {16, 5, 16, 5, 16, 5, 16, 5};
1461 info.transform = {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f};
1462 info.agentWindowId = 1;
1463 info.flags = 0;
1464 info.displayId = 0;
1465 displayGroupInfo.windowsInfo.push_back(info);
1466
1467 std::vector<ScreenInfo> screenInfos;
1468 ScreenInfo screenInfo;
1469 screenInfo.screenType =(ScreenType)info.windowType;
1470 screenInfo.dpi = displayInfo.dpi;
1471 screenInfo.height = displayInfo.height;
1472 screenInfo.width = displayInfo.width;
1473 screenInfo.physicalWidth = dgw;
1474 screenInfo.physicalHeight = dgh;
1475 screenInfo.id =info.id;
1476 screenInfo.rotation = Rotation::ROTATION_0;
1477 screenInfo.tpDirection = Direction::DIRECTION0;
1478 screenInfo.uniqueId = displayInfo.name;
1479 screenInfos.push_back(screenInfo);
1480
1481 UserScreenInfo userScreenInfo;
1482 userScreenInfo.displayGroups.push_back(displayGroupInfo);
1483 userScreenInfo.screens = screenInfos;
1484 InputManager::GetInstance()->UpdateDisplayInfo(userScreenInfo);
1485 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateDisplayInfo(userScreenInfo));
1486 }
1487
1488 /**
1489 * @tc.name: InputManagerTest_UpdateDisplayInfo for 1 display and max-windows
1490 * @tc.desc: Update window information
1491 * @tc.type: FUNC
1492 * @tc.require:
1493 */
1494 HWTEST_F(InputManagerTest, InputManagerTest_UpdateDisplayInfo002, TestSize.Level1)
1495 {
1496 CALL_TEST_DEBUG;
1497 DisplayGroupInfo displayGroupInfo;
1498 displayGroupInfo.focusWindowId = 0;
1499 int32_t dgw = 1000;
1500 int32_t dgh = 2000;
1501 DisplayInfo displayInfo;
1502 displayInfo.id = 0;
1503 displayInfo.x =1;
1504 displayInfo.y = 1;
1505 displayInfo.width = 2;
1506 displayInfo.height = 2;
1507 displayInfo.dpi = 240;
1508 displayInfo.name = "pp";
1509 displayInfo.direction = DIRECTION0;
1510 displayInfo.displayMode = DisplayMode::FULL;
1511 displayGroupInfo.displaysInfo.push_back(displayInfo);
1512 std::vector<ScreenInfo> screenInfos;
1513 for (uint32_t i = 0; i < MAX_WINDOW_NUMS; i++) {
1514 WindowInfo info;
1515 info.id = i + 1;
1516 info.pid = 1;
1517 info.uid = 1;
1518 info.area = {1, 1, 1, 1};
1519 info.defaultHotAreas = { info.area };
1520 info.pointerHotAreas = { info.area };
1521 info.pointerChangeAreas = {16, 5, 16, 5, 16, 5, 16, 5};
1522 info.transform = {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f};
1523 info.agentWindowId = 1;
1524 info.flags = 0;
1525 info.displayId = 0;
1526 info.zOrder = static_cast<float>(MAX_WINDOW_NUMS - i);
1527 displayGroupInfo.windowsInfo.push_back(info);
1528 ScreenInfo screenInfo;
1529 screenInfo.screenType =(ScreenType)info.windowType;
1530 screenInfo.dpi = displayInfo.dpi;
1531 screenInfo.height = displayInfo.height;
1532 screenInfo.width = displayInfo.width;
1533 screenInfo.physicalWidth = dgw;
1534 screenInfo.physicalHeight = dgh;
1535 screenInfo.id =info.id;
1536 screenInfo.rotation = Rotation::ROTATION_0;
1537 screenInfo.tpDirection = Direction::DIRECTION0;
1538 screenInfo.uniqueId = displayInfo.name;
1539 screenInfos.push_back(screenInfo);
1540 }
1541 UserScreenInfo userScreenInfo;
1542 userScreenInfo.displayGroups.push_back(displayGroupInfo);
1543 userScreenInfo.screens = screenInfos;
1544 InputManager::GetInstance()->UpdateDisplayInfo(userScreenInfo);
1545 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateDisplayInfo(userScreenInfo));
1546 }
1547
1548 /**
1549 * @tc.name: InputManagerTest_UpdateDisplayInfo for 1 display and 1 window
1550 * @tc.desc: Update window information
1551 * @tc.type: FUNC
1552 * @tc.require:
1553 */
1554 HWTEST_F(InputManagerTest, InputManagerTest_UpdateDisplayInfo003, TestSize.Level1)
1555 {
1556 CALL_TEST_DEBUG;
1557 DisplayGroupInfo displayGroupInfo;
1558 displayGroupInfo.focusWindowId = 1;
1559 int32_t dgw = 1000;
1560 int32_t dgh = 2000;
1561 DisplayInfo displayInfo;
1562 std::vector<ScreenInfo> screenInfos;
1563 for (uint32_t i = 0; i < 2; i++) { // one is default-display and another is simulate display
1564 displayInfo.id = i;
1565 displayInfo.x =1;
1566 displayInfo.y = 1;
1567 displayInfo.width = 2;
1568 displayInfo.height = 2;
1569 displayInfo.dpi = 240;
1570 displayInfo.name = "pp";
1571 displayInfo.direction = DIRECTION0;
1572 displayGroupInfo.displaysInfo.push_back(displayInfo);
1573 }
1574 WindowInfo info;
1575 for (uint32_t i = 0; i < 2; i++) { // 2 widnows for 2 display
1576 info.id = 1;
1577 info.pid = 1;
1578 info.uid = 1;
1579 info.defaultHotAreas = { {1, 1, 1, 1} };
1580 info.agentWindowId = 1;
1581 info.flags = 0;
1582 info.displayId = i;
1583 displayGroupInfo.windowsInfo.push_back(info);
1584
1585 displayInfo = displayGroupInfo.displaysInfo[i];
1586 ScreenInfo screenInfo;
1587 screenInfo.screenType =(ScreenType)info.windowType;
1588 screenInfo.dpi = displayInfo.dpi;
1589 screenInfo.height = displayInfo.height;
1590 screenInfo.width = displayInfo.width;
1591 screenInfo.physicalWidth = dgw;
1592 screenInfo.physicalHeight = dgh;
1593 screenInfo.id =info.id;
1594 screenInfo.rotation = Rotation::ROTATION_0;
1595 screenInfo.tpDirection = Direction::DIRECTION0;
1596 screenInfo.uniqueId = displayInfo.name;
1597 screenInfos.push_back(screenInfo);
1598 }
1599 UserScreenInfo userScreenInfo;
1600 userScreenInfo.displayGroups.push_back(displayGroupInfo);
1601 userScreenInfo.screens = screenInfos;
1602 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateDisplayInfo(userScreenInfo));
1603 }
1604
1605 /**
1606 * @tc.name: InputManagerTest_UpdateWindowGroupInfo_001
1607 * @tc.desc: Update window information
1608 * @tc.type: FUNC
1609 * @tc.require:
1610 */
1611 HWTEST_F(InputManagerTest, InputManagerTest_UpdateWindowGroupInfo_001, TestSize.Level1)
1612 {
1613 CALL_TEST_DEBUG;
1614 WindowInfo window;
1615 window.id = 1;
1616 window.action = WINDOW_UPDATE_ACTION::ADD;
1617 WindowGroupInfo windowGroupInfo;
1618 windowGroupInfo.displayId = 0;
1619 windowGroupInfo.focusWindowId = 1;
1620 windowGroupInfo.windowsInfo = {window};
1621 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateWindowInfo(windowGroupInfo));
1622 }
1623
1624 /**
1625 * @tc.name: InputManagerTest_UpdateWindowGroupInfo_002
1626 * @tc.desc: Update window information
1627 * @tc.type: FUNC
1628 * @tc.require:
1629 */
1630 HWTEST_F(InputManagerTest, InputManagerTest_UpdateWindowGroupInfo_002, TestSize.Level1)
1631 {
1632 CALL_TEST_DEBUG;
1633 WindowInfo window;
1634 window.id = 1;
1635 window.action = WINDOW_UPDATE_ACTION::CHANGE;
1636 WindowGroupInfo windowGroupInfo;
1637 windowGroupInfo.windowsInfo = {window};
1638 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateWindowInfo(windowGroupInfo));
1639 }
1640
1641 /**
1642 * @tc.name: InputManagerTest_UpdateWindowGroupInfo_003
1643 * @tc.desc: Update window information
1644 * @tc.type: FUNC
1645 * @tc.require:
1646 */
1647 HWTEST_F(InputManagerTest, InputManagerTest_UpdateWindowGroupInfo_003, TestSize.Level1)
1648 {
1649 CALL_TEST_DEBUG;
1650 WindowInfo window;
1651 window.id = 1;
1652 window.action = WINDOW_UPDATE_ACTION::DEL;
1653 WindowGroupInfo windowGroupInfo;
1654 windowGroupInfo.windowsInfo = {window};
1655 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateWindowInfo(windowGroupInfo));
1656 }
1657
1658 /**
1659 * @tc.name: InputManagerTest_UpdateWindowGroupInfo_004
1660 * @tc.desc: Update window information
1661 * @tc.type: FUNC
1662 * @tc.require:
1663 */
1664 HWTEST_F(InputManagerTest, InputManagerTest_UpdateWindowGroupInfo_004, TestSize.Level1)
1665 {
1666 CALL_TEST_DEBUG;
1667 WindowInfo window;
1668 window.id = 1;
1669 window.action = WINDOW_UPDATE_ACTION::UNKNOWN;
1670
1671 WindowGroupInfo windowGroupInfo;
1672 windowGroupInfo.windowsInfo = {window};
1673 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateWindowInfo(windowGroupInfo));
1674 }
1675
1676 /**
1677 * @tc.name: InputManagerTest_UpdateWindowGroupInfo_005
1678 * @tc.desc: Update window information
1679 * @tc.type: FUNC
1680 * @tc.require:
1681 */
1682 HWTEST_F(InputManagerTest, InputManagerTest_UpdateWindowGroupInfo_005, TestSize.Level1)
1683 {
1684 CALL_TEST_DEBUG;
1685 WindowInfo window;
1686 window.id = 1;
1687 window.action = WINDOW_UPDATE_ACTION::CHANGE;
1688 #ifdef OHOS_BUILD_ENABLE_ANCO
1689 window.flags |= SHELL_FLAGS_VALUE;
1690 #endif // OHOS_BUILD_ENABLE_ANCO
1691 WindowGroupInfo windowGroupInfo;
1692 windowGroupInfo.windowsInfo = {window};
1693 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateWindowInfo(windowGroupInfo));
1694 }
1695
1696 #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT
1697 /**
1698 * @tc.name: InputManagerTest_SetEnhanceConfig_001
1699 * @tc.desc: Set Secutity component enhance config
1700 * @tc.type: FUNC
1701 * @tc.require:
1702 */
1703 HWTEST_F(InputManagerTest, InputManagerTest_SetEnhanceConfig_001, TestSize.Level1)
1704 {
1705 CALL_TEST_DEBUG;
1706 uint8_t cfgData[16] = {0};
1707 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->SetEnhanceConfig(cfgData, 16));
1708 }
1709 #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT
1710
1711 /**
1712 * @tc.name: InputManagerTest_GetDevice_001
1713 * @tc.desc: Verify the fetch device info
1714 * @tc.type: FUNC
1715 * @tc.require:
1716 */
1717 HWTEST_F(InputManagerTest, InputManagerTest_GetDevice_001, TestSize.Level1)
1718 {
1719 CALL_TEST_DEBUG;
1720 int32_t deviceId = 0;
__anonaec9e8f51b02(std::shared_ptr<InputDevice> inputDevice) 1721 auto callback = [](std::shared_ptr<InputDevice> inputDevice) {
1722 MMI_HILOGD("Get device success");
1723 ASSERT_TRUE(inputDevice != nullptr);
1724 };
1725 InputManager::GetInstance()->GetDevice(deviceId, callback);
1726 }
1727
1728 /**
1729 * @tc.name: InputManagerTest_GetDevice_002
1730 * @tc.desc: Verify the fetch device info
1731 * @tc.type: FUNC
1732 * @tc.require:
1733 */
1734 HWTEST_F(InputManagerTest, InputManagerTest_GetDevice_002, TestSize.Level1)
1735 {
1736 CALL_TEST_DEBUG;
1737 int32_t deviceId = INVAID_VALUE;
__anonaec9e8f51c02(std::shared_ptr<InputDevice> inputDevice) 1738 auto callback = [](std::shared_ptr<InputDevice> inputDevice) {
1739 MMI_HILOGD("Get device success");
1740 ASSERT_TRUE(inputDevice != nullptr);
1741 };
1742 int32_t ret = InputManager::GetInstance()->GetDevice(deviceId, callback);
1743 ASSERT_NE(ret, RET_OK);
1744 }
1745
1746 /**
1747 * @tc.name: InputManagerTest_GetDeviceIds
1748 * @tc.desc: Verify the fetch device list
1749 * @tc.type: FUNC
1750 * @tc.require:
1751 */
1752 HWTEST_F(InputManagerTest, InputManagerTest_GetDeviceIds, TestSize.Level1)
1753 {
1754 CALL_TEST_DEBUG;
__anonaec9e8f51d02(std::vector<int32_t> ids) 1755 auto callback = [](std::vector<int32_t> ids) { MMI_HILOGD("Get device success"); };
1756 int32_t ret = InputManager::GetInstance()->GetDeviceIds(callback);
1757 ASSERT_EQ(ret, RET_OK);
1758 }
1759
1760 /**
1761 * @tc.name: InputManagerTest_EventTypeToString
1762 * @tc.desc: Verify inputevent interface
1763 * @tc.type: FUNC
1764 * @tc.require:
1765 */
1766 HWTEST_F(InputManagerTest, InputManagerTest_EventTypeToString, TestSize.Level1)
1767 {
1768 CALL_TEST_DEBUG;
1769 auto inputEvent = InputEvent::Create();
1770 ASSERT_NE(inputEvent, nullptr);
1771 auto ret = inputEvent->EventTypeToString(InputEvent::EVENT_TYPE_BASE);
1772 ASSERT_STREQ(ret, "base");
1773 ret = inputEvent->EventTypeToString(InputEvent::EVENT_TYPE_KEY);
1774 ASSERT_STREQ(ret, "key");
1775 ret = inputEvent->EventTypeToString(InputEvent::EVENT_TYPE_AXIS);
1776 ASSERT_STREQ(ret, "axis");
1777 ret = inputEvent->EventTypeToString(INVAID_VALUE);
1778 ASSERT_STREQ(ret, "unknown");
1779 }
1780
1781 /**
1782 * @tc.name: InputManagerTest_InputDeviceInterface_001
1783 * @tc.desc: Verify inputdevice interface
1784 * @tc.type: FUNC
1785 * @tc.require:
1786 */
1787 HWTEST_F(InputManagerTest, InputManagerTest_InputDeviceInterface_001, TestSize.Level1)
1788 {
1789 CALL_TEST_DEBUG;
1790 std::shared_ptr<InputDevice> inputDevice = std::make_shared<InputDevice>();
1791 ASSERT_NE(inputDevice, nullptr);
1792 inputDevice->SetId(0);
1793 ASSERT_EQ(inputDevice->GetId(), 0);
1794 inputDevice->SetName("name");
1795 ASSERT_STREQ(inputDevice->GetName().c_str(), "name");
1796 inputDevice->SetType(0);
1797 ASSERT_EQ(inputDevice->GetType(), 0);
1798 inputDevice->SetBus(0);
1799 ASSERT_EQ(inputDevice->GetBus(), 0);
1800 inputDevice->SetVersion(0);
1801 ASSERT_EQ(inputDevice->GetVersion(), 0);
1802 inputDevice->SetProduct(0);
1803 ASSERT_EQ(inputDevice->GetProduct(), 0);
1804 inputDevice->SetVendor(0);
1805 ASSERT_EQ(inputDevice->GetVendor(), 0);
1806 inputDevice->SetPhys("phys");
1807 ASSERT_STREQ(inputDevice->GetPhys().c_str(), "phys");
1808 inputDevice->SetUniq("uniq");
1809 ASSERT_STREQ(inputDevice->GetUniq().c_str(), "uniq");
1810 }
1811
1812 /**
1813 * @tc.name: InputManagerTest_InputDeviceInterface_002
1814 * @tc.desc: Verify inputdevice interface
1815 * @tc.type: FUNC
1816 * @tc.require:
1817 */
1818 HWTEST_F(InputManagerTest, InputManagerTest_InputDeviceInterface_002, TestSize.Level1)
1819 {
1820 CALL_TEST_DEBUG;
1821 std::shared_ptr<InputDevice> inputDevice = std::make_shared<InputDevice>();
1822 ASSERT_NE(inputDevice, nullptr);
1823 InputDevice::AxisInfo axis;
1824 axis.SetAxisType(0);
1825 axis.SetMinimum(0);
1826 axis.SetMaximum(1);
1827 axis.SetFuzz(0);
1828 axis.SetFlat(1);
1829 axis.SetResolution(0);
1830 inputDevice->AddAxisInfo(axis);
1831 auto iter = inputDevice->GetAxisInfo();
1832 ASSERT_EQ(iter[0].GetAxisType(), 0);
1833 ASSERT_EQ(iter[0].GetMinimum(), 0);
1834 ASSERT_EQ(iter[0].GetMaximum(), 1);
1835 ASSERT_EQ(iter[0].GetFuzz(), 0);
1836 ASSERT_EQ(iter[0].GetFlat(), 1);
1837 ASSERT_EQ(iter[0].GetResolution(), 0);
1838 }
1839
1840 /**
1841 * @tc.name: InputManagerTest_SetAnrObserver
1842 * @tc.desc: Verify the observer for events
1843 * @tc.type: FUNC
1844 * @tc.require:
1845 */
1846 HWTEST_F(InputManagerTest, InputManagerTest_SetAnrObserver, TestSize.Level1)
1847 {
1848 CALL_TEST_DEBUG;
1849 class IAnrObserverTest : public IAnrObserver {
1850 public:
IAnrObserverTest()1851 IAnrObserverTest() : IAnrObserver()
1852 {}
~IAnrObserverTest()1853 virtual ~IAnrObserverTest()
1854 {}
OnAnr(int32_t pid,int32_t eventId) const1855 void OnAnr(int32_t pid, int32_t eventId) const override
1856 {
1857 MMI_HILOGD("Set anr success");
1858 };
1859 };
1860
1861 std::shared_ptr<IAnrObserverTest> observer = std::make_shared<IAnrObserverTest>();
1862 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->SetAnrObserver(observer));
1863 }
1864
1865 /**
1866 * @tc.name: InputManagerTest_EnableInputDevice_001
1867 * @tc.desc: Enable input device
1868 * @tc.type: FUNC
1869 * @tc.require:
1870 */
1871 HWTEST_F(InputManagerTest, InputManagerTest_EnableInputDevice_001, TestSize.Level1)
1872 {
1873 CALL_TEST_DEBUG;
1874 auto ret = InputManager::GetInstance()->EnableInputDevice(false);
1875 ASSERT_EQ(ret, RET_OK);
1876 ret = InputManager::GetInstance()->EnableInputDevice(true);
1877 ASSERT_EQ(ret, RET_OK);
1878 }
1879
1880 /**
1881 * @tc.name: InputManagerTest_SensorInputTime_001
1882 * @tc.desc: Test SensorTime
1883 * @tc.type: FUNC
1884 * @tc.require:
1885 */
1886 HWTEST_F(InputManagerTest, InputManagerTest_SensorInputTime_001, TestSize.Level1)
1887 {
1888 CALL_TEST_DEBUG;
1889 auto pointerEvent = PointerEvent::Create();
1890 ASSERT_TRUE(pointerEvent != nullptr);
1891 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1892 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1893 pointerEvent->SetPointerId(0);
1894 pointerEvent->SetSensorInputTime(POINTER_SENSOR_INPUT_TIME);
1895 ASSERT_TRUE(pointerEvent->GetSensorInputTime() == POINTER_SENSOR_INPUT_TIME);
1896 }
1897
1898 /**
1899 * @tc.name: InputManagerTest_GetDisplayBindInfo_001
1900 * @tc.desc: Get diaplay bind information
1901 * @tc.type: FUNC
1902 * @tc.require:
1903 */
1904 HWTEST_F(InputManagerTest, InputManagerTest_GetDisplayBindInfo_001, TestSize.Level1)
1905 {
1906 CALL_TEST_DEBUG;
1907 OHOS::MMI::DisplayBindInfos infos;
1908 int32_t ret = InputManager::GetInstance()->GetDisplayBindInfo(infos);
1909 ASSERT_TRUE(ret == RET_OK);
1910 if (ret != RET_OK) {
1911 MMI_HILOGE("Call GetDisplayBindInfo failed, ret:%{public}d", ret);
1912 }
1913 }
1914
1915 /**
1916 * @tc.name: InputManagerTest_SetDisplayBind_001
1917 * @tc.desc: Set diaplay bind information
1918 * @tc.type: FUNC
1919 * @tc.require:
1920 */
1921 HWTEST_F(InputManagerTest, InputManagerTest_SetDisplayBind_001, TestSize.Level1)
1922 {
1923 CALL_TEST_DEBUG;
1924 int32_t deviceId = DEFAULT_DEVICE_ID;
1925 int32_t displayId = INVAID_VALUE;
1926 std::string msg;
1927 int32_t ret = InputManager::GetInstance()->SetDisplayBind(deviceId, displayId, msg);
1928 ASSERT_TRUE(ret != RET_OK);
1929 if (ret != RET_OK) {
1930 MMI_HILOGE("Call SetDisplayBind failed, ret:%{public}d", ret);
1931 }
1932 }
1933
1934 /**
1935 * @tc.name: InputManagerTest_MarkConsumed_001
1936 * @tc.desc: Mark Cosumer
1937 * @tc.type: FUNC
1938 * @tc.require:
1939 */
1940 HWTEST_F(InputManagerTest, InputManagerTest_MarkConsumed_001, TestSize.Level1)
1941 {
1942 CALL_TEST_DEBUG;
1943 auto consumer = GetPtr<InputEventConsumer>();
1944 ASSERT_TRUE(consumer != nullptr);
1945 int32_t monitorId = InputManager::GetInstance()->AddMonitor(consumer);
1946 auto pointerEvent = PointerEvent::Create();
1947 ASSERT_TRUE(pointerEvent != nullptr);
1948 auto eventId = pointerEvent->GetId();
1949 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->MarkConsumed(monitorId, eventId));
1950 }
1951
1952 /**
1953 * @tc.name: InputManagerTest_EnterCaptureMode_001
1954 * @tc.desc: Entering capture mode.
1955 * @tc.type: FUNC
1956 * @tc.require:
1957 */
1958 HWTEST_F(InputManagerTest, InputManagerTest_EnterCaptureMode_001, TestSize.Level1)
1959 {
1960 CALL_TEST_DEBUG;
1961 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1962 CHKPV(window);
1963 uint32_t windowId = window->GetWindowId();
1964 int32_t ret = InputManager::GetInstance()->EnterCaptureMode(windowId);
1965 ASSERT_TRUE(ret == RET_OK);
1966 if (ret != RET_OK) {
1967 MMI_HILOGE("Call EnterCaptureMode failed, ret:%{public}d", ret);
1968 }
1969 }
1970
1971 /**
1972 * @tc.name: InputManagerTest_LeaveCaptureMode_001
1973 * @tc.desc: Leaving capture mode.
1974 * @tc.type: FUNC
1975 * @tc.require:
1976 */
1977 HWTEST_F(InputManagerTest, InputManagerTest_LeaveCaptureMode_001, TestSize.Level1)
1978 {
1979 CALL_TEST_DEBUG;
1980 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1981 CHKPV(window);
1982 uint32_t windowId = window->GetWindowId();
1983 int32_t ret = InputManager::GetInstance()->LeaveCaptureMode(windowId);
1984 ASSERT_TRUE(ret == RET_OK);
1985 if (ret != RET_OK) {
1986 MMI_HILOGE("Call LeaveCaptureMode failed, ret:%{public}d", ret);
1987 }
1988 }
1989
1990 /**
1991 * @tc.name: InputManagerTest_GetWindowPid_001
1992 * @tc.desc: Get window pid.
1993 * @tc.type: FUNC
1994 * @tc.require:
1995 */
1996 HWTEST_F(InputManagerTest, InputManagerTest_GetWindowPid_001, TestSize.Level1)
1997 {
1998 CALL_TEST_DEBUG;
1999 auto window = WindowUtilsTest::GetInstance()->GetWindow();
2000 CHKPV(window);
2001 uint32_t windowId = window->GetWindowId();
2002 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->GetWindowPid(windowId));
2003 int32_t ret = InputManager::GetInstance()->GetWindowPid(windowId);
2004 if (ret == RET_ERR) {
2005 MMI_HILOGE("Call GetWindowPid failed, ret:%{public}d", ret);
2006 }
2007 }
2008
2009 /**
2010 * @tc.name: InputManagerTest_SetHoverScrollState_001
2011 * @tc.desc: Set hover scroll state
2012 * @tc.type: FUNC
2013 * @tc.require:
2014 */
2015 HWTEST_F(InputManagerTest, InputManagerTest_SetHoverScrollState_001, TestSize.Level1)
2016 {
2017 CALL_TEST_DEBUG;
2018 auto ret = InputManager::GetInstance()->SetHoverScrollState(false);
2019 ASSERT_EQ(ret, RET_OK);
2020 ret = InputManager::GetInstance()->SetHoverScrollState(true);
2021 ASSERT_EQ(ret, RET_OK);
2022 }
2023
2024 /**
2025 * @tc.name: InputManagerTest_GetHoverScrollState_001
2026 * @tc.desc: Get hover scroll state
2027 * @tc.type: FUNC
2028 * @tc.require:
2029 */
2030 HWTEST_F(InputManagerTest, InputManagerTest_GetHoverScrollState_001, TestSize.Level1)
2031 {
2032 CALL_TEST_DEBUG;
2033 bool statefalse = false;
2034 auto ret = InputManager::GetInstance()->GetHoverScrollState(statefalse);
2035 ASSERT_EQ(ret, RET_OK);
2036 bool statetrue = true;
2037 ret = InputManager::GetInstance()->GetHoverScrollState(statetrue);
2038 ASSERT_EQ(ret, RET_OK);
2039 }
2040
2041 /**
2042 * @tc.name: InputManagerTest_SetPointerVisible_001
2043 * @tc.desc: Set pointer visible
2044 * @tc.type: FUNC
2045 * @tc.require:
2046 */
2047 HWTEST_F(InputManagerTest, InputManagerTest_SetPointerVisible_001, TestSize.Level1)
2048 {
2049 CALL_TEST_DEBUG;
2050 auto ret = InputManager::GetInstance()->SetPointerVisible(false);
2051 ASSERT_EQ(ret, RET_OK);
2052 bool isVisible{true};
2053 if (InputManager::GetInstance()->SetPointerVisible(isVisible) == RET_OK) {
2054 ASSERT_TRUE(InputManager::GetInstance()->IsPointerVisible() == isVisible);
2055 }
2056 }
2057
2058 /**
2059 * @tc.name: InputManagerTest_IsPointerVisible_001
2060 * @tc.desc: Test flag `InputEvent::EVENT_FLAG_HIDE_POINTER` on controlling pointer visibility
2061 * @tc.type: FUNC
2062 * @tc.require:
2063 */
2064 HWTEST_F(InputManagerTest, InputManagerTest_IsPointerVisible_001, TestSize.Level1)
2065 {
2066 CALL_TEST_DEBUG;
2067 PointerEvent::PointerItem item;
2068 item.SetPointerId(0);
2069 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_ONE);
2070 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_ONE);
2071
2072 auto pointerEvent = PointerEvent::Create();
2073 ASSERT_NE(pointerEvent, nullptr);
2074 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
2075 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
2076 pointerEvent->AddFlag(InputEvent::EVENT_FLAG_HIDE_POINTER);
2077 pointerEvent->SetPointerId(0);
2078 pointerEvent->AddPointerItem(item);
2079
2080 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2081 ASSERT_TRUE(InputManager::GetInstance()->IsPointerVisible());
2082 }
2083
2084 /**
2085 * @tc.name: InputManagerTest_IsPointerVisible_002
2086 * @tc.desc: Test flag `InputEvent::EVENT_FLAG_HIDE_POINTER` on controlling pointer visibility
2087 * @tc.type: FUNC
2088 * @tc.require:
2089 */
2090 HWTEST_F(InputManagerTest, InputManagerTest_IsPointerVisible_002, TestSize.Level1)
2091 {
2092 CALL_TEST_DEBUG;
2093 PointerEvent::PointerItem item;
2094 item.SetPointerId(0);
2095 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_TWO);
2096 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_TWO);
2097
2098 auto pointerEvent = PointerEvent::Create();
2099 ASSERT_NE(pointerEvent, nullptr);
2100 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
2101 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
2102 pointerEvent->SetPointerId(0);
2103 pointerEvent->AddPointerItem(item);
2104
2105 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2106 ASSERT_TRUE(InputManager::GetInstance()->IsPointerVisible());
2107 }
2108
2109 /**
2110 * @tc.name: InputManagerTest_SetTouchpadScrollSwitch_001
2111 * @tc.desc: Set touchpad scroll switch
2112 * @tc.type: FUNC
2113 * @tc.require:
2114 */
2115 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadScrollSwitch_001, TestSize.Level1)
2116 {
2117 CALL_TEST_DEBUG;
2118 auto ret = InputManager::GetInstance()->SetTouchpadScrollSwitch(false);
2119 ASSERT_EQ(ret, RET_OK);
2120 ret = InputManager::GetInstance()->SetTouchpadScrollSwitch(true);
2121 ASSERT_EQ(ret, RET_OK);
2122 }
2123
2124 /**
2125 * @tc.name: InputManagerTest_GetTouchpadScrollSwitch_001
2126 * @tc.desc: Get touchpad scroll switch
2127 * @tc.type: FUNC
2128 * @tc.require:
2129 */
2130 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadScrollSwitch_001, TestSize.Level1)
2131 {
2132 CALL_TEST_DEBUG;
2133 bool flagfalse = false;
2134 auto ret = InputManager::GetInstance()->GetTouchpadScrollSwitch(flagfalse);
2135 ASSERT_EQ(ret, RET_OK);
2136 bool flagtrue = true;
2137 ret = InputManager::GetInstance()->GetTouchpadScrollSwitch(flagtrue);
2138 ASSERT_EQ(ret, RET_OK);
2139 }
2140
2141 /**
2142 * @tc.name: InputManagerTest_SetTouchpadScrollDirection_001
2143 * @tc.desc: Set touchpad scroll direction
2144 * @tc.type: FUNC
2145 * @tc.require:
2146 */
2147 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadScrollDirection_001, TestSize.Level1)
2148 {
2149 CALL_TEST_DEBUG;
2150 auto ret = InputManager::GetInstance()->SetTouchpadScrollDirection(false);
2151 ASSERT_EQ(ret, RET_OK);
2152 ret = InputManager::GetInstance()->SetTouchpadScrollDirection(true);
2153 ASSERT_EQ(ret, RET_OK);
2154 }
2155
2156 /**
2157 * @tc.name: InputManagerTest_GetTouchpadScrollDirection_001
2158 * @tc.desc: Get touchpad scroll direction
2159 * @tc.type: FUNC
2160 * @tc.require:
2161 */
2162 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadScrollDirection_001, TestSize.Level1)
2163 {
2164 CALL_TEST_DEBUG;
2165 bool statefalse = false;
2166 auto ret = InputManager::GetInstance()->GetTouchpadScrollDirection(statefalse);
2167 ASSERT_EQ(ret, RET_OK);
2168 bool statetrue = true;
2169 ret = InputManager::GetInstance()->GetTouchpadScrollDirection(statetrue);
2170 ASSERT_EQ(ret, RET_OK);
2171 }
2172
2173 /**
2174 * @tc.name: InputManagerTest_SetPointerSpeed_001
2175 * @tc.desc: Set pointer speed
2176 * @tc.type: FUNC
2177 * @tc.require:
2178 */
2179 HWTEST_F(InputManagerTest, InputManagerTest_SetPointerSpeed_001, TestSize.Level1)
2180 {
2181 CALL_TEST_DEBUG;
2182 const int32_t speed = INVAID_VALUE;
2183 InputManager::GetInstance()->SetPointerSpeed(speed);
2184 int32_t speed1;
2185 InputManager::GetInstance()->GetPointerSpeed(speed1);
2186 ASSERT_EQ(speed1, 1);
2187 }
2188
2189 /**
2190 * @tc.name: InputManagerTest_SetPointerLocation_001
2191 * @tc.desc: Set pointer location
2192 * @tc.type: FUNC
2193 * @tc.require:
2194 */
2195 HWTEST_F(InputManagerTest, InputManagerTest_SetPointerLocation_001, TestSize.Level1)
2196 {
2197 CALL_TEST_DEBUG;
2198 int32_t x = 0;
2199 int32_t y = 0;
2200 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->SetPointerLocation(x, y));
2201 }
2202
2203 /**
2204 * @tc.name: InputManagerTest_SetPointerLocation_002
2205 * @tc.desc: Set pointer location
2206 * @tc.type: FUNC
2207 * @tc.require:
2208 */
2209 HWTEST_F(InputManagerTest, InputManagerTest_SetPointerLocation_002, TestSize.Level1)
2210 {
2211 CALL_TEST_DEBUG;
2212 int32_t x = 10;
2213 int32_t y = 20;
2214 int32_t displayId = 32;
2215 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->SetPointerLocation(x, y, displayId));
2216 }
2217
2218 /**
2219 * @tc.name: InputManagerTest_GetPointerLocation_001
2220 * @tc.desc: Get pointer location
2221 * @tc.type: FUNC
2222 * @tc.require:
2223 */
2224 HWTEST_F(InputManagerTest, InputManagerTest_GetPointerLocation_001, TestSize.Level1)
2225 {
2226 CALL_TEST_DEBUG;
2227 int32_t displayId = -1;
2228 double displayX = 0.0;
2229 double displayY = 0.0;
2230 int32_t ret = InputManager::GetInstance()->GetPointerLocation(displayId, displayX, displayY);
2231 EXPECT_EQ(ret, ERROR_APP_NOT_FOCUSED);
2232 }
2233
2234 /**
2235 * @tc.name: InputManagerTest_GetTouchpadRightClickType_001
2236 * @tc.desc: Get touchpad right click type
2237 * @tc.type: FUNC
2238 * @tc.require:
2239 */
2240 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadRightClickType_001, TestSize.Level1)
2241 {
2242 CALL_TEST_DEBUG;
2243 int32_t newType = 1;
2244 int32_t ret = InputManager::GetInstance()->GetTouchpadRightClickType(newType);
2245 ASSERT_EQ(ret, RET_OK);
2246 }
2247
2248 /**
2249 * @tc.name: InputManagerTest_GetKeyState_001
2250 * @tc.desc: Get key state
2251 * @tc.type: FUNC
2252 * @tc.require:
2253 */
2254 HWTEST_F(InputManagerTest, InputManagerTest_GetKeyState_001, TestSize.Level1)
2255 {
2256 CALL_TEST_DEBUG;
2257 std::vector<int32_t> pressedKeys;
2258 std::map<int32_t, int32_t> specialKeysState;
2259 int32_t ret = InputManager::GetInstance()->GetKeyState(pressedKeys, specialKeysState);
2260 ASSERT_EQ(ret, RET_OK);
2261 }
2262
2263 /**
2264 * @tc.name: InputManagerTest_MarkProcessed_001
2265 * @tc.desc: Mark processed
2266 * @tc.type: FUNC
2267 * @tc.require:
2268 */
2269 HWTEST_F(InputManagerTest, InputManagerTest_MarkProcessed_001, TestSize.Level1)
2270 {
2271 CALL_TEST_DEBUG;
2272 int32_t x = 0;
2273 int64_t y = 0;
2274 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->MarkProcessed(x, y));
2275 }
2276
2277 /**
2278 * @tc.name: InputManagerTest_SetCustomCursor
2279 * @tc.desc: Test set the wrong windowId for SetCustomCursor
2280 * @tc.type: FUNC
2281 * @tc.require:
2282 */
2283 HWTEST_F(InputManagerTest, InputManagerTest_SetCustomCursor, TestSize.Level1)
2284 {
2285 CALL_TEST_DEBUG;
2286 int32_t fakeWindowId = 100;
2287 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
2288 PointerStyle pointerStyle;
2289 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
2290 ASSERT_NE(pixelMap, nullptr);
2291 pointerStyle.id = MOUSE_ICON::DEVELOPER_DEFINED_ICON;
2292 ASSERT_FALSE(InputManager::GetInstance()->SetCustomCursor(fakeWindowId, (void *)pixelMap.get(), 32, 32) == RET_ERR);
2293 pixelMap = nullptr;
2294 }
2295
2296 /**
2297 * @tc.name: InputManagerTest_SetMouseIcon
2298 * @tc.desc: Test set the wrong windowId for SetMouseIcon
2299 * @tc.type: FUNC
2300 * @tc.require:
2301 */
2302 HWTEST_F(InputManagerTest, InputManagerTest_SetMouseIcon, TestSize.Level1)
2303 {
2304 CALL_TEST_DEBUG;
2305 int32_t fakeWindoId = 100;
2306 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
2307 PointerStyle pointerStyle;
2308 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
2309 ASSERT_NE(pixelMap, nullptr);
2310 pointerStyle.id = MOUSE_ICON::DEVELOPER_DEFINED_ICON;
2311 ASSERT_TRUE(InputManager::GetInstance()->SetMouseIcon(fakeWindoId, (void *)pixelMap.get()) == RET_ERR);
2312 pixelMap = nullptr;
2313 }
2314
2315 /**
2316 * @tc.name: InputManagerTest_SetMouseHotSpot
2317 * @tc.desc: Test set the wrong windowId for SetMouseHotSpot
2318 * @tc.type: FUNC
2319 * @tc.require:
2320 */
2321 HWTEST_F(InputManagerTest, InputManagerTest_SetMouseHotSpot, TestSize.Level1)
2322 {
2323 CALL_TEST_DEBUG;
2324 PointerStyle pointerStyle;
2325 pointerStyle.id = MOUSE_ICON::CROSS;
2326 int32_t fakeWindoId = 100;
2327 int32_t mouseIcon = 20;
2328 ASSERT_TRUE(
2329 InputManager::GetInstance()->SetMouseHotSpot(fakeWindoId, mouseIcon, mouseIcon) == RET_ERR);
2330 }
2331
2332
2333 /**
2334 * @tc.name: InputManagerTest_SetKeyDownDuration_001
2335 * @tc.desc: Customize the delay time for starting the ability by using the shortcut key.
2336 * @tc.type: FUNC
2337 * @tc.require:
2338 */
2339 HWTEST_F(InputManagerTest, InputManagerTest_SetKeyDownDuration_001, TestSize.Level1)
2340 {
2341 CALL_TEST_DEBUG;
2342 std::string businessId = "";
2343 int32_t delay = KEY_DOWN_DURATION;
2344 ASSERT_EQ(PARAMETER_ERROR, InputManager::GetInstance()->SetKeyDownDuration(businessId, delay));
2345 }
2346
2347 /**
2348 * @tc.name: InputManagerTest_SubscribeSwitchEvent_001
2349 * @tc.desc: Subscribes from a switch input event.
2350 * @tc.type: FUNC
2351 * @tc.require:
2352 */
2353 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeSwitchEvent_001, TestSize.Level1)
2354 {
__anonaec9e8f51e02(std::shared_ptr<SwitchEvent> event) 2355 auto fun = [](std::shared_ptr<SwitchEvent> event) {
2356 MMI_HILOGD("Subscribe switch event success, type:%{public}d, value:%{public}d",
2357 event->GetSwitchType(), event->GetSwitchValue());
2358 };
2359 int32_t subscribeId = InputManager::GetInstance()->SubscribeSwitchEvent(fun, SwitchEvent::SwitchType::SWITCH_LID);
2360 ASSERT_NE(subscribeId, INVAID_VALUE);
2361 InputManager::GetInstance()->UnsubscribeSwitchEvent(subscribeId);
2362 }
2363
2364 /**
2365 * @tc.name: InputManagerTest_SubscribeSwitchEvent_002
2366 * @tc.desc: Subscribes from a switch input event.
2367 * @tc.type: FUNC
2368 * @tc.require:
2369 */
2370 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeSwitchEvent_002, TestSize.Level1)
2371 {
2372 ASSERT_EQ(InputManager::GetInstance()->SubscribeSwitchEvent(nullptr), -1);
2373 }
2374
2375 /**
2376 * @tc.name: InputManagerTest_SubscribeSwitchEvent_003
2377 * @tc.desc: Subscribes from a switch input event.
2378 * @tc.type: FUNC
2379 * @tc.require:
2380 */
2381 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeSwitchEvent_003, TestSize.Level1)
2382 {
__anonaec9e8f51f02(std::shared_ptr<SwitchEvent> event) 2383 auto fun = [](std::shared_ptr<SwitchEvent> event) {
2384 MMI_HILOGD("Subscribe switch event success, type:%{public}d, value:%{public}d",
2385 event->GetSwitchType(), event->GetSwitchValue());
2386 };
2387 ASSERT_EQ(InputManager::GetInstance()->SubscribeSwitchEvent(
2388 fun, SwitchEvent::SwitchType(INVAID_VALUE)), -1);
2389 }
2390
2391 /**
2392 * @tc.name: InputManagerTest_UnsubscribeSwitchEvent_001
2393 * @tc.desc: Unsubscribes from a switch input event.
2394 * @tc.type: FUNC
2395 * @tc.require:
2396 */
2397 HWTEST_F(InputManagerTest, InputManagerTest_UnsubscribeSwitchEvent_001, TestSize.Level1)
2398 {
2399 CALL_TEST_DEBUG;
2400 int32_t subscriberId = INVAID_VALUE;
2401 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UnsubscribeSwitchEvent(subscriberId));
2402 }
2403
2404 /**
2405 * @tc.name: InputManagerTest_QuerySwitchStatus_001
2406 * @tc.desc: Unsubscribes from a switch input event.
2407 * @tc.type: FUNC
2408 * @tc.require:
2409 */
2410 HWTEST_F(InputManagerTest, InputManagerTest_QuerySwitchStatus_001, TestSize.Level1)
2411 {
2412 CALL_TEST_DEBUG;
2413 SwitchEvent::SwitchState state = SwitchEvent::SwitchState::STATE_OFF;
2414 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->QuerySwitchStatus(SwitchEvent::SwitchType::SWITCH_TABLET,
2415 state));
2416 }
2417
2418 /**
2419 * @tc.name: InputManagerTest_SubscribeLongPressEvent_01
2420 * @tc.desc: Verify invalid parameter : finger count less than 0.
2421 * @tc.type: FUNC
2422 * @tc.require: AR2024112192028
2423 * @tc.author:
2424 */
2425 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_01, TestSize.Level1)
2426 {
2427 CALL_TEST_DEBUG;
2428 LongPressRequest longPressRequest;
2429 longPressRequest.fingerCount = -1;
2430 longPressRequest.duration = 300;
2431 int32_t subscribeId = INVAID_VALUE;
2432 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(longPressRequest,
__anonaec9e8f52002(const LongPressEvent &longPressEvent) 2433 [](const LongPressEvent &longPressEvent) {
2434 MMI_HILOGD("Subscribe long press event trigger callback");
2435 });
2436 EXPECT_TRUE(subscribeId < 0);
2437 }
2438
2439 /**
2440 * @tc.name: InputManagerTest_SubscribeLongPressEvent_02
2441 * @tc.desc: Verify invalid parameter : finger count equals 0.
2442 * @tc.type: FUNC
2443 * @tc.require: AR2024112192028
2444 * @tc.author:
2445 */
2446 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_02, TestSize.Level1)
2447 {
2448 CALL_TEST_DEBUG;
2449 LongPressRequest longPressRequest;
2450 longPressRequest.fingerCount = 0;
2451 longPressRequest.duration = 300;
2452 int32_t subscribeId = INVAID_VALUE;
2453 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(longPressRequest,
__anonaec9e8f52102(const LongPressEvent &longPressEvent) 2454 [](const LongPressEvent &longPressEvent) {
2455 MMI_HILOGD("Subscribe long press event trigger callback");
2456 });
2457 EXPECT_TRUE(subscribeId < 0);
2458 }
2459
2460 /**
2461 * @tc.name: InputManagerTest_SubscribeLongPressEvent_03
2462 * @tc.desc: Verify valid parameter : finger count equals 2.
2463 * @tc.type: FUNC
2464 * @tc.require: AR2024112192028
2465 * @tc.author:
2466 */
2467 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_03, TestSize.Level1)
2468 {
2469 CALL_TEST_DEBUG;
2470 LongPressRequest longPressRequest;
2471 longPressRequest.fingerCount = 2;
2472 longPressRequest.duration = 300;
2473 int32_t subscribeId = INVAID_VALUE;
2474 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(longPressRequest,
__anonaec9e8f52202(const LongPressEvent &longPressEvent) 2475 [](const LongPressEvent &longPressEvent) {
2476 MMI_HILOGD("Subscribe long press event trigger callback");
2477 });
2478 EXPECT_TRUE(subscribeId >= 0);
2479 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2480 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId);
2481 }
2482
2483 /**
2484 * @tc.name: InputManagerTest_SubscribeLongPressEvent_04
2485 * @tc.desc: Verify invalid parameter : finger count greater than 2.
2486 * @tc.type: FUNC
2487 * @tc.require: AR2024112192028
2488 * @tc.author:
2489 */
2490 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_04, TestSize.Level1)
2491 {
2492 CALL_TEST_DEBUG;
2493 LongPressRequest longPressRequest;
2494 longPressRequest.fingerCount = 4;
2495 longPressRequest.duration = 300;
2496 int32_t subscribeId = INVAID_VALUE;
2497 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(longPressRequest,
__anonaec9e8f52302(const LongPressEvent &longPressEvent) 2498 [](const LongPressEvent &longPressEvent) {
2499 MMI_HILOGD("Subscribe long press event trigger callback");
2500 });
2501 EXPECT_TRUE(subscribeId < 0);
2502 }
2503
2504 /**
2505 * @tc.name: InputManagerTest_SubscribeLongPressEvent_05
2506 * @tc.desc: Verify invalid parameter : duration less than 0ms.
2507 * @tc.type: FUNC
2508 * @tc.require: AR2024112192028
2509 * @tc.author:
2510 */
2511 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_05, TestSize.Level1)
2512 {
2513 CALL_TEST_DEBUG;
2514 LongPressRequest longPressRequest;
2515 longPressRequest.fingerCount = 1;
2516 longPressRequest.duration = -1;
2517 int32_t subscribeId = INVAID_VALUE;
2518 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(longPressRequest,
__anonaec9e8f52402(const LongPressEvent &longPressEvent) 2519 [](const LongPressEvent &longPressEvent) {
2520 MMI_HILOGD("Subscribe long press event trigger callback");
2521 });
2522 EXPECT_TRUE(subscribeId < 0);
2523 }
2524
2525 /**
2526 * @tc.name: InputManagerTest_SubscribeLongPressEvent_06
2527 * @tc.desc: Verify invalid parameter : duration equals 0ms.
2528 * @tc.type: FUNC
2529 * @tc.require: AR2024112192028
2530 * @tc.author:
2531 */
2532 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_06, TestSize.Level1)
2533 {
2534 CALL_TEST_DEBUG;
2535 LongPressRequest longPressRequest;
2536 longPressRequest.fingerCount = 1;
2537 longPressRequest.duration = 0;
2538 int32_t subscribeId = INVAID_VALUE;
2539 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(longPressRequest,
__anonaec9e8f52502(const LongPressEvent &longPressEvent) 2540 [](const LongPressEvent &longPressEvent) {
2541 MMI_HILOGD("Subscribe long press event trigger callback");
2542 });
2543 EXPECT_TRUE(subscribeId < 0);
2544 }
2545
2546 /**
2547 * @tc.name: InputManagerTest_SubscribeLongPressEvent_07
2548 * @tc.desc: Verify valid parameter : duration equals 3000ms.
2549 * @tc.type: FUNC
2550 * @tc.require: AR2024112192028
2551 * @tc.author:
2552 */
2553 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_07, TestSize.Level1)
2554 {
2555 CALL_TEST_DEBUG;
2556 LongPressRequest longPressRequest;
2557 longPressRequest.fingerCount = 1;
2558 longPressRequest.duration = 3000;
2559 int32_t subscribeId = INVAID_VALUE;
2560 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(longPressRequest,
__anonaec9e8f52602(const LongPressEvent &longPressEvent) 2561 [](const LongPressEvent &longPressEvent) {
2562 MMI_HILOGD("Subscribe long press event trigger callback");
2563 });
2564 EXPECT_TRUE(subscribeId >= 0);
2565 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2566 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId);
2567 }
2568
2569 /**
2570 * @tc.name: InputManagerTest_SubscribeLongPressEvent_08
2571 * @tc.desc: Verify invalid parameter : duration greater than 3000ms.
2572 * @tc.type: FUNC
2573 * @tc.require: AR2024112192028
2574 * @tc.author:
2575 */
2576 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_08, TestSize.Level1)
2577 {
2578 CALL_TEST_DEBUG;
2579 LongPressRequest longPressRequest;
2580 longPressRequest.fingerCount = 4;
2581 longPressRequest.duration = 3001;
2582 int32_t subscribeId = INVAID_VALUE;
2583 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(longPressRequest,
__anonaec9e8f52702(const LongPressEvent &longPressEvent) 2584 [](const LongPressEvent &longPressEvent) {
2585 MMI_HILOGD("Subscribe long press event trigger callback");
2586 });
2587 EXPECT_TRUE(subscribeId < 0);
2588 }
2589
2590 /**
2591 * @tc.name: InputManagerTest_SubscribeLongPressEvent_09
2592 * @tc.desc: Verify invalid parameter : null callback.
2593 * @tc.type: FUNC
2594 * @tc.require: AR2024112192028
2595 * @tc.author:
2596 */
2597 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_09, TestSize.Level1)
2598 {
2599 CALL_TEST_DEBUG;
2600 LongPressRequest longPressRequest;
2601 longPressRequest.fingerCount = 1;
2602 longPressRequest.duration = 300;
2603 int32_t subscribeId = INVAID_VALUE;
2604 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(longPressRequest, nullptr);
2605 EXPECT_TRUE(subscribeId < 0);
2606 }
2607
2608 /**
2609 * @tc.name: InputManagerTest_SubscribeLongPressEvent_10
2610 * @tc.desc: Verify subscribe repeat long press event.
2611 * @tc.type: FUNC
2612 * @tc.require: AR2024112192028
2613 * @tc.author:
2614 */
2615 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_10, TestSize.Level1)
2616 {
2617 CALL_TEST_DEBUG;
2618 ASSERT_TRUE(MMIEventHdl.InitClient());
2619 int32_t subscribeId1 = INVAID_VALUE;
2620 LongPressRequest pressEvent;
2621 pressEvent.fingerCount = 1;
2622 pressEvent.duration = 300;
2623 subscribeId1 = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent,
__anonaec9e8f52802(const LongPressEvent &longPressEvent) 2624 [](const LongPressEvent &longPressEvent) {
2625 MMI_HILOGD("Subscribe long press event trigger callback");
2626 });
2627 EXPECT_TRUE(subscribeId1 >= 0);
2628
2629 int32_t subscribeId2 = INVAID_VALUE;
2630 subscribeId2 = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent,
__anonaec9e8f52902(const LongPressEvent &longPressEvent) 2631 [](const LongPressEvent &longPressEvent) {
2632 MMI_HILOGD("Subscribe long press event trigger callback");
2633 });
2634 EXPECT_TRUE(subscribeId2 >= 0);
2635
2636 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2637 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId1);
2638 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId2);
2639 }
2640
2641
2642 /**
2643 * @tc.name: InputManagerTest_SubscribeLongPressEvent_11
2644 * @tc.desc: Verify subscribe ten long press event.
2645 * @tc.type: FUNC
2646 * @tc.require: AR2024112192028
2647 * @tc.author:
2648 */
2649 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_11, TestSize.Level1)
2650 {
2651 CALL_TEST_DEBUG;
2652 ASSERT_TRUE(MMIEventHdl.InitClient());
2653 int32_t subscribeId = INVAID_VALUE;
2654 LongPressRequest pressEvent;
2655 pressEvent.fingerCount = 1;
2656 pressEvent.duration = 300;
2657 std::vector<int32_t> ids;
2658 for (size_t i = 0; i < 10; ++i) {
2659 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent,
__anonaec9e8f52a02(const LongPressEvent &longPressEvent) 2660 [](const LongPressEvent &longPressEvent) {
2661 MMI_HILOGD("Subscribe long press event trigger callback");
2662 });
2663 EXPECT_TRUE(subscribeId >= 0);
2664 ids.push_back(subscribeId);
2665 pressEvent.duration += 100;
2666 }
2667 EXPECT_TRUE(ids.size() == 10);
2668 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2669 for (size_t i = 0; i < ids.size(); ++i) {
2670 InputManager::GetInstance()->UnsubscribeLongPressEvent(ids[i]);
2671 }
2672 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2673 }
2674
2675 /**
2676 * @tc.name: InputManagerTest_SubscribeLongPressEvent_12
2677 * @tc.desc: Verify subscribe two long press event.
2678 * @tc.type: FUNC
2679 * @tc.require: AR2024112192028
2680 * @tc.author:
2681 */
2682 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_12, TestSize.Level1)
2683 {
2684 CALL_TEST_DEBUG;
2685 ASSERT_TRUE(MMIEventHdl.InitClient());
2686 int32_t subscribeId1 = INVAID_VALUE;
2687 LongPressRequest pressEvent1;
2688 pressEvent1.fingerCount = 1;
2689 pressEvent1.duration = 300;
2690 subscribeId1 = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent1,
__anonaec9e8f52b02(const LongPressEvent &longPressEvent) 2691 [](const LongPressEvent &longPressEvent) {
2692 MMI_HILOGD("Subscribe long press event trigger callback");
2693 });
2694 EXPECT_TRUE(subscribeId1 >= 0);
2695
2696 int32_t subscribeId2 = INVAID_VALUE;
2697 LongPressRequest pressEvent2;
2698 pressEvent2.fingerCount = 2;
2699 pressEvent2.duration = 300;
2700 subscribeId2 = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent2,
__anonaec9e8f52c02(const LongPressEvent &longPressEvent) 2701 [](const LongPressEvent &longPressEvent) {
2702 MMI_HILOGD("Subscribe long press event trigger callback");
2703 });
2704 EXPECT_TRUE(subscribeId2 >= 0);
2705
2706 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2707 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId1);
2708 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId2);
2709 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2710 }
2711
2712 /**
2713 * @tc.name: InputManagerTest_SubscribeLongPressEvent_13
2714 * @tc.desc: Verify recognition algorithm of long press event, only subscribe two finger.
2715 * @tc.type: FUNC
2716 * @tc.require: AR2024112192028
2717 * @tc.author:
2718 */
2719 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_13, TestSize.Level1)
2720 {
2721 CALL_TEST_DEBUG;
2722 ASSERT_TRUE(MMIEventHdl.InitClient());
2723 int32_t subscribeId1 = INVAID_VALUE;
2724 LongPressRequest pressEvent1;
2725 pressEvent1.fingerCount = 2;
2726 pressEvent1.duration = 300;
2727 subscribeId1 = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent1,
__anonaec9e8f52d02(const LongPressEvent &longPressEvent) 2728 [](const LongPressEvent &longPressEvent) {
2729 MMI_HILOGD("Subscribe long press event trigger callback");
2730 });
2731 EXPECT_TRUE(subscribeId1 >= 0);
2732
2733 int32_t subscribeId2 = INVAID_VALUE;
2734 LongPressRequest pressEvent2;
2735 pressEvent2.fingerCount = 2;
2736 pressEvent2.duration = 900;
2737 subscribeId2 = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent2,
__anonaec9e8f52e02(const LongPressEvent &longPressEvent) 2738 [](const LongPressEvent &longPressEvent) {
2739 MMI_HILOGD("Subscribe long press event trigger callback");
2740 });
2741 EXPECT_TRUE(subscribeId2 >= 0);
2742
2743 int32_t subscribeId3 = INVAID_VALUE;
2744 LongPressRequest pressEvent3;
2745 pressEvent3.fingerCount = 2;
2746 pressEvent3.duration = 1500;
2747 subscribeId3 = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent3,
__anonaec9e8f52f02(const LongPressEvent &longPressEvent) 2748 [](const LongPressEvent &longPressEvent) {
2749 MMI_HILOGD("Subscribe long press event trigger callback");
2750 });
2751 EXPECT_TRUE(subscribeId3 >= 0);
2752
2753 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2754 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId1);
2755 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId2);
2756 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId3);
2757 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2758 }
2759
2760 /**
2761 * @tc.name: InputManagerTest_SubscribeLongPressEvent_14
2762 * @tc.desc: Verify recognition algorithm of long press event, subscribe one finger and two finger.
2763 * @tc.type: FUNC
2764 * @tc.require: AR2024112192028
2765 * @tc.author:
2766 */
2767 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_14, TestSize.Level1)
2768 {
2769 CALL_TEST_DEBUG;
2770 ASSERT_TRUE(MMIEventHdl.InitClient());
2771 int32_t subscribeId1 = INVAID_VALUE;
2772 LongPressRequest pressEvent1;
2773 pressEvent1.fingerCount = 1;
2774 pressEvent1.duration = 300;
2775 subscribeId1 = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent1,
__anonaec9e8f53002(const LongPressEvent &longPressEvent) 2776 [](const LongPressEvent &longPressEvent) {
2777 MMI_HILOGD("Subscribe long press event trigger callback");
2778 });
2779 EXPECT_TRUE(subscribeId1 >= 0);
2780
2781 int32_t subscribeId2 = INVAID_VALUE;
2782 LongPressRequest pressEvent2;
2783 pressEvent2.fingerCount = 2;
2784 pressEvent2.duration = 300;
2785 subscribeId2 = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent2,
__anonaec9e8f53102(const LongPressEvent &longPressEvent) 2786 [](const LongPressEvent &longPressEvent) {
2787 MMI_HILOGD("Subscribe long press event trigger callback");
2788 });
2789 EXPECT_TRUE(subscribeId2 >= 0);
2790
2791 int32_t subscribeId3 = INVAID_VALUE;
2792 LongPressRequest pressEvent3;
2793 pressEvent3.fingerCount = 1;
2794 pressEvent3.duration = 900;
2795 subscribeId3 = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent3,
__anonaec9e8f53202(const LongPressEvent &longPressEvent) 2796 [](const LongPressEvent &longPressEvent) {
2797 MMI_HILOGD("Subscribe long press event trigger callback");
2798 });
2799 EXPECT_TRUE(subscribeId3 >= 0);
2800
2801 int32_t subscribeId4 = INVAID_VALUE;
2802 LongPressRequest pressEvent4;
2803 pressEvent4.fingerCount = 2;
2804 pressEvent4.duration = 900;
2805 subscribeId4 = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent4,
__anonaec9e8f53302(const LongPressEvent &longPressEvent) 2806 [](const LongPressEvent &longPressEvent) {
2807 MMI_HILOGD("Subscribe long press event trigger callback");
2808 });
2809 EXPECT_TRUE(subscribeId4 >= 0);
2810
2811 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2812 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId1);
2813 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId2);
2814 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId3);
2815 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId4);
2816 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2817 }
2818
2819 /**
2820 * @tc.name: InputManagerTest_UnsubscribeLongPressEvent_01
2821 * @tc.desc: Verify invalid parameter : subscribe id less than 0.
2822 * @tc.type: FUNC
2823 * @tc.require: AR2024112192028
2824 * @tc.author:
2825 */
2826 HWTEST_F(InputManagerTest, InputManagerTest_UnsubscribeLongPressEvent_01, TestSize.Level1)
2827 {
2828 CALL_TEST_DEBUG;
2829 LongPressRequest longPressRequest;
2830 longPressRequest.fingerCount = 1;
2831 longPressRequest.duration = 300;
2832 int32_t subscribeId = INVAID_VALUE;
2833 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(longPressRequest,
__anonaec9e8f53402(const LongPressEvent &longPressEvent) 2834 [](const LongPressEvent &longPressEvent) {
2835 MMI_HILOGD("Subscribe long press event trigger callback");
2836 });
2837 EXPECT_TRUE(subscribeId >= 0);
2838 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2839 subscribeId = -1;
2840 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId));
2841 }
2842
2843 /**
2844 * @tc.name: InputManagerTest_UnsubscribeLongPressEvent_02
2845 * @tc.desc: Verify invalid parameter : subscribe id less than 0.
2846 * @tc.type: FUNC
2847 * @tc.require: AR2024112192028
2848 * @tc.author:
2849 */
2850 HWTEST_F(InputManagerTest, InputManagerTest_UnsubscribeLongPressEvent_02, TestSize.Level1)
2851 {
2852 CALL_TEST_DEBUG;
2853 int32_t subscribeId = INVAID_VALUE;
2854 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId));
2855 }
2856
2857 /**
2858 * @tc.name: InputManagerTest_UnsubscribeLongPressEvent_03
2859 * @tc.desc: Verify invalid parameter : subscribe id is not a subscribed value.
2860 * @tc.type: FUNC
2861 * @tc.require: AR2024112192028
2862 * @tc.author:
2863 */
2864 HWTEST_F(InputManagerTest, InputManagerTest_UnsubscribeLongPressEvent_03, TestSize.Level1)
2865 {
2866 CALL_TEST_DEBUG;
2867 LongPressRequest longPressRequest;
2868 longPressRequest.fingerCount = 1;
2869 longPressRequest.duration = 300;
2870 int32_t subscribeId = INVAID_VALUE;
2871 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(longPressRequest,
__anonaec9e8f53502(const LongPressEvent &longPressEvent) 2872 [](const LongPressEvent &longPressEvent) {
2873 MMI_HILOGD("Subscribe long press event trigger callback");
2874 });
2875 EXPECT_TRUE(subscribeId >= 0);
2876 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2877 subscribeId += 10;
2878 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId));
2879 }
2880
2881 /**
2882 * @tc.name: InputManagerTest_UnsubscribeLongPressEvent_04
2883 * @tc.desc: Verify cancel ten subscription.
2884 * @tc.type: FUNC
2885 * @tc.require: AR2024112192028
2886 * @tc.author:
2887 */
2888 HWTEST_F(InputManagerTest, InputManagerTest_UnsubscribeLongPressEvent_04, TestSize.Level1)
2889 {
2890 CALL_TEST_DEBUG;
2891 int32_t subscribeId = INVAID_VALUE;
2892 LongPressRequest pressEvent;
2893 pressEvent.fingerCount = 1;
2894 pressEvent.duration = 300;
2895 std::vector<int32_t> ids;
2896 for (size_t i = 0; i < 10; ++i) {
2897 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent,
__anonaec9e8f53602(const LongPressEvent &longPressEvent) 2898 [](const LongPressEvent &longPressEvent) {
2899 MMI_HILOGD("Subscribe long press event trigger callback");
2900 });
2901 EXPECT_TRUE(subscribeId >= 0);
2902 ids.push_back(subscribeId);
2903 pressEvent.duration += 100;
2904 }
2905 EXPECT_TRUE(ids.size() == 10);
2906 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2907 for (size_t i = 0; i < ids.size(); ++i) {
2908 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId));
2909 }
2910 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2911 }
2912
2913 /**
2914 * @tc.name: InputManagerTest_ClearWindowPointerStyle_001
2915 * @tc.desc: Verify invalid parameter.
2916 * @tc.type: FUNC
2917 * @tc.require:SR000GGQL4 AR000GJNGN
2918 * @tc.author: yangguang
2919 */
2920 HWTEST_F(InputManagerTest, InputManagerTest_ClearWindowPointerStyle_001, TestSize.Level1)
2921 {
2922 CALL_TEST_DEBUG;
2923 auto window = WindowUtilsTest::GetInstance()->GetWindow();
2924 CHKPV(window);
2925 uint32_t windowId = window->GetWindowId();
2926 PointerStyle pointerStyle;
2927 pointerStyle.id = MOUSE_ICON::CROSS;
2928 int32_t ret = InputManager::GetInstance()->SetPointerStyle(windowId, pointerStyle);
2929 InputManager::GetInstance()->ClearWindowPointerStyle(getpid(), windowId);
2930 PointerStyle style;
2931 ret = InputManager::GetInstance()->GetPointerStyle(windowId, style);
2932 EXPECT_TRUE(ret == RET_OK);
2933 }
2934
2935 HWTEST_F(InputManagerTest, InputManagerTest_SyncBundleName_001, TestSize.Level1)
2936 {
2937 CALL_TEST_DEBUG;
2938 auto mmiObserver = std::make_shared<IEventObserver>();
2939 InputManager::GetInstance()->AddInputEventObserver(mmiObserver);
2940 auto callbackPtr = GetPtr<InputEventCallback>();
2941 ASSERT_TRUE(callbackPtr != nullptr);
2942 int32_t monitorId = InputManagerUtil::TestAddMonitor(callbackPtr);
2943 InputManager::GetInstance()->SetNapStatus(10, 20, "bundleName_test", 0);
2944 std::map<std::tuple<int32_t, int32_t, std::string>, int32_t> mapBefore;
2945 InputManager::GetInstance()->GetAllMmiSubscribedEvents(mapBefore);
2946 for (auto map = mapBefore.begin(); map != mapBefore.end(); ++map) {
2947 if (std::get<TUPLE_PID>(map->first) == 10) {
2948 EXPECT_TRUE(std::get<TUPLE_UID>(map->first) == 20);
2949 EXPECT_TRUE(std::get<TUPLE_NAME>(map->first) == "bundleName_test");
2950 EXPECT_TRUE(map->second == 0);
2951 }
2952 }
2953 for (const auto& map : mapBefore) {
2954 MMI_HILOGD("All NapStatus in mapBefore pid:%{public}d, uid:%{public}d, name:%{public}s, status:%{public}d",
2955 std::get<TUPLE_PID>(map.first), std::get<TUPLE_UID>(map.first), std::get<TUPLE_NAME>(map.first).c_str(),
2956 map.second);
2957 }
2958 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2959 InputManagerUtil::TestRemoveMonitor(monitorId);
2960 InputManager::GetInstance()->SetNapStatus(10, 20, "bundleName_test", 2);
2961 std::map<std::tuple<int32_t, int32_t, std::string>, int32_t> mapAfter;
2962 InputManager::GetInstance()->GetAllMmiSubscribedEvents(mapAfter);
2963 for (const auto& map : mapAfter) {
2964 EXPECT_FALSE(std::get<TUPLE_PID>(map.first) == 10);
2965 EXPECT_FALSE(std::get<TUPLE_UID>(map.first) == 20);
2966 EXPECT_FALSE(std::get<TUPLE_NAME>(map.first) == "bundleName_test");
2967 }
2968 for (const auto& map : mapAfter) {
2969 MMI_HILOGD("All NapStatus in mapAfter pid:%{public}d, uid:%{public}d, name:%{public}s, status:%{public}d",
2970 std::get<TUPLE_PID>(map.first), std::get<TUPLE_UID>(map.first), std::get<TUPLE_NAME>(map.first).c_str(),
2971 map.second);
2972 }
2973 InputManager::GetInstance()->RemoveInputEventObserver(mmiObserver);
2974 }
2975
2976 /**
2977 * @tc.name: InputManager_InjectMouseEvent_001
2978 * @tc.desc: Injection interface detection
2979 * @tc.type: FUNC
2980 * @tc.require:AR000GJG6G
2981 */
2982 HWTEST_F(InputManagerTest, InputManager_InjectMouseEvent_001, TestSize.Level1)
2983 {
2984 CALL_TEST_DEBUG;
2985 auto pointerEvent = PointerEvent::Create();
2986 pointerEvent->SetButtonId(PointerEvent::MOUSE_BUTTON_LEFT);
2987 pointerEvent->SetButtonPressed(PointerEvent::MOUSE_BUTTON_LEFT);
2988 ASSERT_NE(pointerEvent, nullptr);
2989
2990 PointerEvent::PointerItem item;
2991 item.SetPointerId(0);
2992 item.SetDisplayX(200);
2993 item.SetDisplayY(200);
2994 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN);
2995 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
2996 pointerEvent->SetPointerId(0);
2997 pointerEvent->AddPointerItem(item);
2998 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2999 }
3000
3001 /**
3002 * @tc.name: InputManager_InjectMouseEvent_002
3003 * @tc.desc: Injection interface detection
3004 * @tc.type: FUNC
3005 * @tc.require:AR000GJG6G
3006 */
3007 HWTEST_F(InputManagerTest, InputManager_InjectMouseEvent_002, TestSize.Level1)
3008 {
3009 CALL_TEST_DEBUG;
3010 auto pointerEvent = PointerEvent::Create();
3011 pointerEvent->SetButtonId(PointerEvent::MOUSE_BUTTON_LEFT);
3012 pointerEvent->SetButtonPressed(PointerEvent::MOUSE_BUTTON_LEFT);
3013 ASSERT_NE(pointerEvent, nullptr);
3014
3015 PointerEvent::PointerItem item;
3016 item.SetPointerId(0);
3017 item.SetDisplayX(200);
3018 item.SetDisplayY(200);
3019 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_UP);
3020 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
3021 pointerEvent->SetPointerId(0);
3022 pointerEvent->AddPointerItem(item);
3023 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3024 }
3025
3026 /**
3027 * @tc.name: InputManager_InjectMouseEvent_003
3028 * @tc.desc: Injection interface detection
3029 * @tc.type: FUNC
3030 * @tc.require:AR000GJG6G
3031 */
3032 HWTEST_F(InputManagerTest, InputManager_InjectMouseEvent_003, TestSize.Level1)
3033 {
3034 CALL_TEST_DEBUG;
3035 auto pointerEvent = PointerEvent::Create();
3036 ASSERT_NE(pointerEvent, nullptr);
3037
3038 PointerEvent::PointerItem item;
3039 item.SetPointerId(0);
3040 item.SetDisplayX(200);
3041 item.SetDisplayY(200);
3042 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
3043 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
3044 pointerEvent->SetPointerId(0);
3045 pointerEvent->AddPointerItem(item);
3046 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3047 }
3048
SimulateInputEventInjectKeyTest(int32_t keyAction,int32_t keyCode,bool isPressed,int32_t downTime)3049 static bool SimulateInputEventInjectKeyTest(int32_t keyAction, int32_t keyCode, bool isPressed, int32_t downTime)
3050 {
3051 auto keyEvent = KeyEvent::Create();
3052 if (keyEvent == nullptr) {
3053 return false;
3054 }
3055 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3056 keyEvent->SetKeyCode(keyCode);
3057
3058 KeyEvent::KeyItem item;
3059 keyEvent->SetKeyAction(keyAction);
3060 item.SetKeyCode(keyCode);
3061 item.SetPressed(isPressed);
3062 item.SetDownTime(downTime);
3063 keyEvent->AddKeyItem(item);
3064 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3065 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
3066 return true;
3067 }
3068
3069 /**
3070 * @tc.name: InputManager_InjectKeyEvent_001
3071 * @tc.desc: Injection interface detection
3072 * @tc.type: FUNC
3073 * @tc.require:
3074 */
3075 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_001, TestSize.Level1)
3076 {
3077 CALL_TEST_DEBUG;
__anonaec9e8f53702(std::shared_ptr<KeyEvent> event) 3078 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3079 MMI_HILOGD("Add monitor success");
3080 };
3081 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3082 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3083 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
3084 KeyEvent::KEYCODE_CALL_NOTIFICATION_CENTER, true, 500));
3085 InputManager::GetInstance()->RemoveMonitor(monitorId);
3086 }
3087
3088 /**
3089 * @tc.name: InputManager_InjectKeyEvent_002
3090 * @tc.desc: Injection interface detection
3091 * @tc.type: FUNC
3092 * @tc.require:
3093 */
3094 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_002, TestSize.Level1)
3095 {
3096 CALL_TEST_DEBUG;
__anonaec9e8f53802(std::shared_ptr<KeyEvent> event) 3097 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3098 MMI_HILOGD("Add monitor success");
3099 };
3100 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3101 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3102 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
3103 KeyEvent::KEYCODE_CALL_CONTROL_CENTER, true, 500));
3104 InputManager::GetInstance()->RemoveMonitor(monitorId);
3105 }
3106
3107 /**
3108 * @tc.name: InputManager_InjectKeyEvent_003
3109 * @tc.desc: Injection interface detection
3110 * @tc.type: FUNC
3111 * @tc.require:
3112 */
3113 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_003, TestSize.Level1)
3114 {
3115 CALL_TEST_DEBUG;
__anonaec9e8f53902(std::shared_ptr<KeyEvent> event) 3116 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3117 MMI_HILOGD("Add monitor success");
3118 };
3119 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3120 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3121 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
3122 KeyEvent::KEYCODE_CALL_NOTIFICATION_CENTER, false, 500));
3123 InputManager::GetInstance()->RemoveMonitor(monitorId);
3124 }
3125
3126 /**
3127 * @tc.name: InputManager_InjectKeyEvent_004
3128 * @tc.desc: Injection interface detection
3129 * @tc.type: FUNC
3130 * @tc.require:
3131 */
3132 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_004, TestSize.Level1)
3133 {
3134 CALL_TEST_DEBUG;
__anonaec9e8f53a02(std::shared_ptr<KeyEvent> event) 3135 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3136 MMI_HILOGD("Add monitor success");
3137 };
3138 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3139 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3140 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
3141 KeyEvent::KEYCODE_CALL_CONTROL_CENTER, false, 500));
3142 InputManager::GetInstance()->RemoveMonitor(monitorId);
3143 }
3144
3145 /**
3146 * @tc.name: InputManager_InjectKeyEvent_005
3147 * @tc.desc: Injection interface detection
3148 * @tc.type: FUNC
3149 * @tc.require:
3150 */
3151 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_005, TestSize.Level1)
3152 {
3153 CALL_TEST_DEBUG;
__anonaec9e8f53b02(std::shared_ptr<KeyEvent> event) 3154 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3155 MMI_HILOGD("Add monitor success");
3156 };
3157 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3158 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3159 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
3160 KeyEvent::KEYCODE_CALL_NOTIFICATION_CENTER, true, 1000));
3161 InputManager::GetInstance()->RemoveMonitor(monitorId);
3162 }
3163
3164 /**
3165 * @tc.name: InputManager_InjectKeyEvent_006
3166 * @tc.desc: Injection interface detection
3167 * @tc.type: FUNC
3168 * @tc.require:
3169 */
3170 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_006, TestSize.Level1)
3171 {
3172 CALL_TEST_DEBUG;
__anonaec9e8f53c02(std::shared_ptr<KeyEvent> event) 3173 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3174 MMI_HILOGD("Add monitor success");
3175 };
3176 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3177 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3178 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
3179 KeyEvent::KEYCODE_CALL_CONTROL_CENTER, true, 1000));
3180 InputManager::GetInstance()->RemoveMonitor(monitorId);
3181 }
3182
3183 /**
3184 * @tc.name: InputManager_InjectKeyEvent_007
3185 * @tc.desc: Injection interface detection
3186 * @tc.type: FUNC
3187 * @tc.require:
3188 */
3189 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_007, TestSize.Level1)
3190 {
3191 CALL_TEST_DEBUG;
__anonaec9e8f53d02(std::shared_ptr<KeyEvent> event) 3192 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3193 MMI_HILOGD("Add monitor success");
3194 };
3195 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3196 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3197 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
3198 KeyEvent::KEYCODE_CALL_NOTIFICATION_CENTER, false, 1000));
3199 InputManager::GetInstance()->RemoveMonitor(monitorId);
3200 }
3201
3202 /**
3203 * @tc.name: InputManager_InjectKeyEvent_008
3204 * @tc.desc: Injection interface detection
3205 * @tc.type: FUNC
3206 * @tc.require:
3207 */
3208 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_008, TestSize.Level1)
3209 {
3210 CALL_TEST_DEBUG;
__anonaec9e8f53e02(std::shared_ptr<KeyEvent> event) 3211 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3212 MMI_HILOGD("Add monitor success");
3213 };
3214 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3215 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3216 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
3217 KeyEvent::KEYCODE_CALL_CONTROL_CENTER, false, 1000));
3218 InputManager::GetInstance()->RemoveMonitor(monitorId);
3219 }
3220
3221 /**
3222 * @tc.name: InputManager_InjectKeyEvent_009
3223 * @tc.desc: Injection interface detection
3224 * @tc.type: FUNC
3225 * @tc.require:
3226 */
3227 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_009, TestSize.Level1)
3228 {
3229 CALL_TEST_DEBUG;
__anonaec9e8f53f02(std::shared_ptr<KeyEvent> event) 3230 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3231 MMI_HILOGD("Add monitor success");
3232 };
3233 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3234 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3235 auto keyEvent = KeyEvent::Create();
3236 ASSERT_NE(keyEvent, nullptr);
3237 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3238
3239 KeyEvent::KeyItem itemFirst;
3240 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3241 keyEvent->SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
3242
3243 itemFirst.SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
3244 itemFirst.SetPressed(false);
3245 itemFirst.SetDownTime(1000);
3246 keyEvent->AddKeyItem(itemFirst);
3247
3248 KeyEvent::KeyItem itemSecond;
3249 itemSecond.SetKeyCode(KeyEvent::KEYCODE_R);
3250 itemSecond.SetPressed(true);
3251 itemSecond.SetDownTime(1000);
3252 keyEvent->AddKeyItem(itemSecond);
3253 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3254 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
3255 InputManager::GetInstance()->RemoveMonitor(monitorId);
3256 }
3257
3258 /**
3259 * @tc.name: InputManager_InjectKeyEvent_010
3260 * @tc.desc: Injection interface detection
3261 * @tc.type: FUNC
3262 * @tc.require:
3263 */
3264 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_010, TestSize.Level1)
3265 {
3266 CALL_TEST_DEBUG;
__anonaec9e8f54002(std::shared_ptr<KeyEvent> event) 3267 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3268 MMI_HILOGD("Add monitor success");
3269 };
3270 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3271 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3272 auto keyEvent = KeyEvent::Create();
3273 ASSERT_NE(keyEvent, nullptr);
3274 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3275
3276 KeyEvent::KeyItem itemFirst;
3277 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3278 keyEvent->SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
3279
3280 itemFirst.SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
3281 itemFirst.SetPressed(false);
3282 itemFirst.SetDownTime(1000);
3283 keyEvent->AddKeyItem(itemFirst);
3284
3285 KeyEvent::KeyItem itemSecond;
3286 itemSecond.SetKeyCode(KeyEvent::KEYCODE_R);
3287 itemSecond.SetPressed(false);
3288 itemSecond.SetDownTime(1000);
3289 keyEvent->AddKeyItem(itemSecond);
3290 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3291 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
3292 InputManager::GetInstance()->RemoveMonitor(monitorId);
3293 }
3294
3295 /**
3296 * @tc.name: InputManager_InjectKeyEvent_011
3297 * @tc.desc: Injection interface detection
3298 * @tc.type: FUNC
3299 * @tc.require:AR000GJG6G mymy
3300 */
3301 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_011, TestSize.Level1)
3302 {
3303 CALL_TEST_DEBUG;
__anonaec9e8f54102(std::shared_ptr<KeyEvent> event) 3304 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3305 MMI_HILOGD("Add monitor success");
3306 };
3307 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3308 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3309 auto keyEvent = KeyEvent::Create();
3310 ASSERT_NE(keyEvent, nullptr);
3311 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3312
3313 KeyEvent::KeyItem itemFirst;
3314 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3315 keyEvent->SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
3316
3317 itemFirst.SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
3318 itemFirst.SetPressed(false);
3319 itemFirst.SetDownTime(500);
3320 keyEvent->AddKeyItem(itemFirst);
3321
3322 KeyEvent::KeyItem itemSecond;
3323 itemSecond.SetKeyCode(KeyEvent::KEYCODE_R);
3324 itemSecond.SetPressed(false);
3325 itemSecond.SetDownTime(500);
3326 keyEvent->AddKeyItem(itemSecond);
3327 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3328 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
3329 InputManager::GetInstance()->RemoveMonitor(monitorId);
3330 }
3331
3332 /**
3333 * @tc.name: InputManager_InjectKeyEvent_012
3334 * @tc.desc: Injection interface detection
3335 * @tc.type: FUNC
3336 * @tc.require:AR000GJG6G mymy
3337 */
3338 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_012, TestSize.Level1)
3339 {
3340 CALL_TEST_DEBUG;
__anonaec9e8f54202(std::shared_ptr<KeyEvent> event) 3341 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3342 MMI_HILOGD("Add monitor success");
3343 };
3344 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3345 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3346 auto keyEvent = KeyEvent::Create();
3347 ASSERT_NE(keyEvent, nullptr);
3348 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3349
3350 KeyEvent::KeyItem itemFirst;
3351 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3352 keyEvent->SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
3353
3354 itemFirst.SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
3355 itemFirst.SetPressed(false);
3356 itemFirst.SetDownTime(500);
3357 keyEvent->AddKeyItem(itemFirst);
3358
3359 KeyEvent::KeyItem itemSecond;
3360 itemSecond.SetKeyCode(KeyEvent::KEYCODE_R);
3361 itemSecond.SetPressed(true);
3362 itemSecond.SetDownTime(500);
3363 keyEvent->AddKeyItem(itemSecond);
3364 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3365 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
3366 InputManager::GetInstance()->RemoveMonitor(monitorId);
3367 }
3368
3369 /**
3370 * @tc.name: InputManager_InjectKeyEvent_013
3371 * @tc.desc: Injection interface detection
3372 * @tc.type: FUNC
3373 * @tc.require:
3374 */
3375 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_013, TestSize.Level1)
3376 {
3377 CALL_TEST_DEBUG;
__anonaec9e8f54302(std::shared_ptr<KeyEvent> event) 3378 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3379 MMI_HILOGD("Add monitor success");
3380 };
3381 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3382 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3383 auto keyEvent = KeyEvent::Create();
3384 ASSERT_NE(keyEvent, nullptr);
3385 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3386
3387 KeyEvent::KeyItem itemFirst;
3388 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3389 keyEvent->SetKeyCode(KeyEvent::KEYCODE_DAGGER_CLICK);
3390
3391 itemFirst.SetKeyCode(KeyEvent::KEYCODE_DAGGER_CLICK);
3392 itemFirst.SetPressed(true);
3393 itemFirst.SetDownTime(500);
3394 keyEvent->AddKeyItem(itemFirst);
3395
3396 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3397 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
3398 InputManager::GetInstance()->RemoveMonitor(monitorId);
3399 }
3400
3401 /**
3402 * @tc.name: InputManager_InjectKeyEvent_014
3403 * @tc.desc: Injection interface detection
3404 * @tc.type: FUNC
3405 * @tc.require:
3406 */
3407 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_014, TestSize.Level1)
3408 {
3409 CALL_TEST_DEBUG;
__anonaec9e8f54402(std::shared_ptr<KeyEvent> event) 3410 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3411 MMI_HILOGD("Add monitor success");
3412 };
3413 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3414 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3415 auto keyEvent = KeyEvent::Create();
3416 ASSERT_NE(keyEvent, nullptr);
3417 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3418
3419 KeyEvent::KeyItem itemFirst;
3420 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3421 keyEvent->SetKeyCode(KeyEvent::KEYCODE_DAGGER_DOUBLE_CLICK);
3422
3423 itemFirst.SetKeyCode(KeyEvent::KEYCODE_DAGGER_DOUBLE_CLICK);
3424 itemFirst.SetPressed(true);
3425 itemFirst.SetDownTime(500);
3426 keyEvent->AddKeyItem(itemFirst);
3427
3428 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3429 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
3430 InputManager::GetInstance()->RemoveMonitor(monitorId);
3431 }
3432
3433 /**
3434 * @tc.name: InputManager_InjectKeyEvent_015
3435 * @tc.desc: Injection interface detection
3436 * @tc.type: FUNC
3437 * @tc.require:
3438 */
3439 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_015, TestSize.Level1)
3440 {
3441 CALL_TEST_DEBUG;
__anonaec9e8f54502(std::shared_ptr<KeyEvent> event) 3442 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3443 MMI_HILOGD("Add monitor success");
3444 };
3445 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3446 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3447 auto keyEvent = KeyEvent::Create();
3448 ASSERT_NE(keyEvent, nullptr);
3449 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3450
3451 KeyEvent::KeyItem itemFirst;
3452 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3453 keyEvent->SetKeyCode(KeyEvent::KEYCODE_DAGGER_LONG_PRESS);
3454
3455 itemFirst.SetKeyCode(KeyEvent::KEYCODE_DAGGER_LONG_PRESS);
3456 itemFirst.SetPressed(true);
3457 itemFirst.SetDownTime(500);
3458 keyEvent->AddKeyItem(itemFirst);
3459
3460 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3461 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
3462 InputManager::GetInstance()->RemoveMonitor(monitorId);
3463 }
3464
3465 /**
3466 * @tc.name: InputManager_InjectKeyEvent_016
3467 * @tc.desc: Injection interface detection
3468 * @tc.type: FUNC
3469 * @tc.require:
3470 */
3471 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_016, TestSize.Level1)
3472 {
3473 CALL_TEST_DEBUG;
__anonaec9e8f54602(std::shared_ptr<KeyEvent> event) 3474 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3475 MMI_HILOGD("Add monitor success");
3476 };
3477 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3478 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3479 auto keyEvent = KeyEvent::Create();
3480 ASSERT_NE(keyEvent, nullptr);
3481 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3482
3483 KeyEvent::KeyItem itemFirst;
3484 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3485 keyEvent->SetKeyCode(KeyEvent::KEYCODE_DAGGER_CLICK);
3486
3487 itemFirst.SetKeyCode(KeyEvent::KEYCODE_DAGGER_CLICK);
3488 itemFirst.SetPressed(false);
3489 itemFirst.SetDownTime(500);
3490 keyEvent->AddKeyItem(itemFirst);
3491
3492 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3493 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
3494 InputManager::GetInstance()->RemoveMonitor(monitorId);
3495 }
3496
3497 /**
3498 * @tc.name: InputManager_InjectKeyEvent_017
3499 * @tc.desc: Injection interface detection
3500 * @tc.type: FUNC
3501 * @tc.require:
3502 */
3503 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_017, TestSize.Level1)
3504 {
3505 CALL_TEST_DEBUG;
__anonaec9e8f54702(std::shared_ptr<KeyEvent> event) 3506 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3507 MMI_HILOGD("Add monitor success");
3508 };
3509 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3510 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3511 auto keyEvent = KeyEvent::Create();
3512 ASSERT_NE(keyEvent, nullptr);
3513 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3514
3515 KeyEvent::KeyItem itemFirst;
3516 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3517 keyEvent->SetKeyCode(KeyEvent::KEYCODE_DAGGER_DOUBLE_CLICK);
3518
3519 itemFirst.SetKeyCode(KeyEvent::KEYCODE_DAGGER_DOUBLE_CLICK);
3520 itemFirst.SetPressed(false);
3521 itemFirst.SetDownTime(500);
3522 keyEvent->AddKeyItem(itemFirst);
3523
3524 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3525 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
3526 InputManager::GetInstance()->RemoveMonitor(monitorId);
3527 }
3528
3529 /**
3530 * @tc.name: InputManager_InjectKeyEvent_018
3531 * @tc.desc: Injection interface detection
3532 * @tc.type: FUNC
3533 * @tc.require:
3534 */
3535 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_018, TestSize.Level1)
3536 {
3537 CALL_TEST_DEBUG;
__anonaec9e8f54802(std::shared_ptr<KeyEvent> event) 3538 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3539 MMI_HILOGD("Add monitor success");
3540 };
3541 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3542 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3543 auto keyEvent = KeyEvent::Create();
3544 ASSERT_NE(keyEvent, nullptr);
3545 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3546
3547 KeyEvent::KeyItem itemFirst;
3548 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3549 keyEvent->SetKeyCode(KeyEvent::KEYCODE_DAGGER_LONG_PRESS);
3550
3551 itemFirst.SetKeyCode(KeyEvent::KEYCODE_DAGGER_LONG_PRESS);
3552 itemFirst.SetPressed(false);
3553 itemFirst.SetDownTime(500);
3554 keyEvent->AddKeyItem(itemFirst);
3555
3556 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3557 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
3558 InputManager::GetInstance()->RemoveMonitor(monitorId);
3559 }
3560
3561 /**
3562 * @tc.name: InputManager_InjectTouchEvent_001
3563 * @tc.desc: Injection interface detection
3564 * @tc.type: FUNC
3565 * @tc.require:AR000GJG6G
3566 */
3567 HWTEST_F(InputManagerTest, InputManager_InjectTouchEvent_001, TestSize.Level1)
3568 {
3569 CALL_TEST_DEBUG;
3570 auto pointerEvent = PointerEvent::Create();
3571 ASSERT_NE(pointerEvent, nullptr);
3572
3573 PointerEvent::PointerItem item;
3574 item.SetPointerId(0);
3575 item.SetDisplayX(200);
3576 item.SetDisplayY(200);
3577 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
3578 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
3579 pointerEvent->SetPointerId(0);
3580 pointerEvent->AddPointerItem(item);
3581 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3582 }
3583
3584 /**
3585 * @tc.name: InputManager_InjectTouchEvent_002
3586 * @tc.desc: Injection interface detection
3587 * @tc.type: FUNC
3588 * @tc.require:AR000GJG6G
3589 */
3590 HWTEST_F(InputManagerTest, InputManager_InjectTouchEvent_002, TestSize.Level1)
3591 {
3592 CALL_TEST_DEBUG;
3593 auto pointerEvent = PointerEvent::Create();
3594 ASSERT_NE(pointerEvent, nullptr);
3595
3596 PointerEvent::PointerItem item;
3597 item.SetPointerId(0);
3598 item.SetDisplayX(200);
3599 item.SetDisplayY(200);
3600 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
3601 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
3602 pointerEvent->SetPointerId(0);
3603 pointerEvent->AddPointerItem(item);
3604 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3605 }
3606
3607 /**
3608 * @tc.name: InputManager_InjectEvent_003
3609 * @tc.desc: Injection interface detection
3610 * @tc.type: FUNC
3611 * @tc.require:AR000GJG6G
3612 */
3613 HWTEST_F(InputManagerTest, InputManager_InjectEvent_003, TestSize.Level1)
3614 {
3615 CALL_TEST_DEBUG;
3616 auto keyEvent = KeyEvent::Create();
3617 ASSERT_NE(keyEvent, nullptr);
3618 ASSERT_NO_FATAL_FAILURE(keyEvent->SetRepeat(true));
3619 }
3620
3621 /**
3622 * @tc.name: InputManager_InjectEvent_001
3623 * @tc.desc: Injection interface detection
3624 * @tc.type: FUNC
3625 * @tc.require:AR000GJG6G
3626 */
3627 HWTEST_F(InputManagerTest, InputManager_InjectEvent_001, TestSize.Level1)
3628 {
3629 CALL_TEST_DEBUG;
3630 auto keyEvent = KeyEvent::Create();
3631 ASSERT_NE(keyEvent, nullptr);
3632 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3633
3634 KeyEvent::KeyItem item;
3635 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3636 item.SetKeyCode(2017);
3637 item.SetPressed(true);
3638 item.SetDownTime(500);
3639 keyEvent->AddKeyItem(item);
3640 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3641 }
3642
3643 /**
3644 * @tc.name: InputManager_InjectEvent_002
3645 * @tc.desc: Injection interface detection
3646 * @tc.type: FUNC
3647 * @tc.require:AR000GJG6G
3648 */
3649 HWTEST_F(InputManagerTest, InputManager_InjectEvent_002, TestSize.Level1)
3650 {
3651 CALL_TEST_DEBUG;
3652 auto keyEvent = KeyEvent::Create();
3653 ASSERT_NE(keyEvent, nullptr);
3654 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3655 std::vector<int32_t> downKey;
3656 downKey.push_back(2072);
3657 downKey.push_back(2017);
3658
3659 KeyEvent::KeyItem item[downKey.size()];
3660 for (size_t i = 0; i < downKey.size(); i++) {
3661 keyEvent->SetKeyCode(2072);
3662 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3663 item[i].SetKeyCode(downKey[i]);
3664 item[i].SetPressed(true);
3665 item[i].SetDownTime(0);
3666 keyEvent->AddKeyItem(item[i]);
3667 }
3668 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3669 }
3670
3671 /**
3672 * @tc.name: InputManagerTest_GetPointerColor_001
3673 * @tc.desc: Obtains the mouse color.
3674 * @tc.type: FUNC
3675 * @tc.require:
3676 */
3677 HWTEST_F(InputManagerTest, InputManagerTest_GetPointerColor_001, TestSize.Level1)
3678 {
3679 CALL_TEST_DEBUG;
3680 int32_t setColor = 0x000000;
3681 InputManager::GetInstance()->SetPointerColor(setColor);
3682 int32_t getColor = 3;
3683 ASSERT_TRUE(InputManager::GetInstance()->GetPointerColor(getColor) == RET_OK);
3684 }
3685
3686 /**
3687 * @tc.name: InputManagerTest_SimulateInputEventExt_001
3688 * @tc.desc: Obtains the mouse color.
3689 * @tc.type: FUNC
3690 * @tc.require:
3691 */
3692 HWTEST_F(InputManagerTest, InputManagerTest_SimulateInputEventExt_001, TestSize.Level1)
3693 {
3694 CALL_TEST_DEBUG;
3695 auto pointerEvent = PointerEvent::Create();
3696 ASSERT_NE(pointerEvent, nullptr);
3697
3698 PointerEvent::PointerItem item;
3699 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_TWO);
3700 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_ONE);
3701 item.SetPressure(POINTER_ITEM_PRESSURE);
3702 item.SetPointerId(0);
3703 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
3704 pointerEvent->SetPointerId(0);
3705 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
3706 pointerEvent->AddPointerItem(item);
3707
3708 #ifdef OHOS_BUILD_ENABLE_ANCO
3709 InputManager::GetInstance()->SimulateInputEventExt(pointerEvent);
3710 InputManager::GetInstance()->SimulateInputEventExt(pointerEvent);
3711 InputManager::GetInstance()->SimulateInputEventExt(pointerEvent);
3712 #endif // OHOS_BUILD_ENABLE_ANCO
3713 }
3714
3715 /**
3716 * @tc.name: InputManagerTest_SimulateInputEventExt_002
3717 * @tc.desc: Obtains the mouse color.
3718 * @tc.type: FUNC
3719 * @tc.require:
3720 */
3721 HWTEST_F(InputManagerTest, InputManagerTest_SimulateInputEventExt_002, TestSize.Level1)
3722 {
3723 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
3724 ASSERT_TRUE(injectDownEvent != nullptr);
3725 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
3726 KeyEvent::KeyItem kitDown;
3727 kitDown.SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
3728 kitDown.SetPressed(true);
3729 kitDown.SetDownTime(downTime);
3730 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
3731 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3732 injectDownEvent->AddPressedKeyItems(kitDown);
3733
3734 #ifdef OHOS_BUILD_ENABLE_ANCO
3735 InputManager::GetInstance()->SimulateInputEventExt(injectDownEvent);
3736 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
3737 #endif // OHOS_BUILD_ENABLE_ANCO
3738 }
3739
3740 /**
3741 * @tc.name: InputManagerTest_SimulateInputEventZorder_001
3742 * @tc.desc: Simulate input evnet with zOrder.
3743 * @tc.type: FUNC
3744 * @tc.require:
3745 */
3746 HWTEST_F(InputManagerTest, InputManagerTest_SimulateInputEventZorder_001, TestSize.Level1)
3747 {
3748 CALL_TEST_DEBUG;
3749 auto pointerEvent = PointerEvent::Create();
3750 ASSERT_NE(pointerEvent, nullptr);
3751
3752 PointerEvent::PointerItem item;
3753 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_TWO);
3754 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_ONE);
3755 item.SetPressure(POINTER_ITEM_PRESSURE);
3756 item.SetPointerId(0);
3757 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
3758 pointerEvent->SetPointerId(0);
3759 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
3760 pointerEvent->AddPointerItem(item);
3761 pointerEvent->SetZOrder(10.0);
3762 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->SimulateInputEvent(pointerEvent, 10.0, false));
3763 }
3764
3765 /**
3766 * @tc.name: InputManagerTest_SetShieldStatus_001
3767 * @tc.desc: Test set shield status
3768 * @tc.type: FUNC
3769 * @tc.require:
3770 */
3771 HWTEST_F(InputManagerTest, InputManagerTest_SetShieldStatus_001, TestSize.Level1)
3772 {
3773 bool factoryModeStatus = false;
3774 bool oobeModeStatus = false;
3775 int32_t ret = InputManager::GetInstance()->SetShieldStatus(SHIELD_MODE::FACTORY_MODE, true);
3776 ASSERT_EQ(ret, RET_OK);
3777 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::FACTORY_MODE, factoryModeStatus);
3778 ASSERT_EQ(ret, RET_OK);
3779 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::OOBE_MODE, oobeModeStatus);
3780 ASSERT_EQ(ret, RET_OK);
3781 ASSERT_TRUE(factoryModeStatus);
3782 ASSERT_FALSE(oobeModeStatus);
3783 ret = InputManager::GetInstance()->SetShieldStatus(SHIELD_MODE::OOBE_MODE, true);
3784 ASSERT_EQ(ret, RET_OK);
3785 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::FACTORY_MODE, factoryModeStatus);
3786 ASSERT_EQ(ret, RET_OK);
3787 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::OOBE_MODE, oobeModeStatus);
3788 ASSERT_EQ(ret, RET_OK);
3789 ASSERT_FALSE(factoryModeStatus);
3790 ASSERT_TRUE(oobeModeStatus);
3791 ret = InputManager::GetInstance()->SetShieldStatus(SHIELD_MODE::OOBE_MODE, false);
3792 ASSERT_EQ(ret, RET_OK);
3793 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::FACTORY_MODE, factoryModeStatus);
3794 ASSERT_EQ(ret, RET_OK);
3795 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::OOBE_MODE, oobeModeStatus);
3796 ASSERT_EQ(ret, RET_OK);
3797 ASSERT_FALSE(factoryModeStatus);
3798 ASSERT_FALSE(oobeModeStatus);
3799 }
3800
3801 /**
3802 * @tc.name: InputManager_SimulateInputEvent_001
3803 * @tc.desc: Set SourceType to SOURCE_TYPE_MOUSE
3804 * @tc.type: FUNC
3805 * @tc.require:SR000GGN6G
3806 */
3807 HWTEST_F(InputManagerTest, InputManager_SimulateInputEvent_001, TestSize.Level1)
3808 {
3809 CALL_TEST_DEBUG;
3810 auto pointerEvent = PointerEvent::Create();
3811 ASSERT_NE(pointerEvent, nullptr);
3812 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
3813 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3814 }
3815
3816 /**
3817 * @tc.name: InputManager_SimulateInputEvent_002
3818 * @tc.desc: Set SourceType to SOURCE_TYPE_TOUCHPAD
3819 * @tc.type: FUNC
3820 * @tc.require:SR000GGN6G
3821 */
3822 HWTEST_F(InputManagerTest, InputManager_SimulateInputEvent_002, TestSize.Level1)
3823 {
3824 CALL_TEST_DEBUG;
3825 auto pointerEvent = PointerEvent::Create();
3826 ASSERT_NE(pointerEvent, nullptr);
3827 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD);
3828 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3829 }
3830
3831 /**
3832 * @tc.name: InputManager_SimulateInputEvent_003
3833 * @tc.desc: Set SourceType to SOURCE_TYPE_TOUCHSCREEN
3834 * @tc.type: FUNC
3835 * @tc.require:SR000GGN6G
3836 */
3837 HWTEST_F(InputManagerTest, InputManager_SimulateInputEvent_003, TestSize.Level1)
3838 {
3839 CALL_TEST_DEBUG;
3840 auto pointerEvent = PointerEvent::Create();
3841 ASSERT_NE(pointerEvent, nullptr);
3842 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
3843 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3844 }
3845
3846 /**
3847 * @tc.name: InputManager_SimulateInputEvent_004
3848 * @tc.desc: Set SourceType to SOURCE_TYPE_JOYSTICK
3849 * @tc.type: FUNC
3850 * @tc.require:SR000GGN6G
3851 */
3852 HWTEST_F(InputManagerTest, InputManager_SimulateInputEvent_004, TestSize.Level1)
3853 {
3854 CALL_TEST_DEBUG;
3855 auto pointerEvent = PointerEvent::Create();
3856 ASSERT_NE(pointerEvent, nullptr);
3857 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_JOYSTICK);
3858 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3859 }
3860
3861 /**
3862 * @tc.name: InputManager_SimulateInputEvent_005
3863 * @tc.desc: Set SourceType to invalid
3864 * @tc.type: FUNC
3865 * @tc.require:SR000GGN6G
3866 */
3867 HWTEST_F(InputManagerTest, InputManager_SimulateInputEvent_005, TestSize.Level1)
3868 {
3869 CALL_TEST_DEBUG;
3870 auto pointerEvent = PointerEvent::Create();
3871 ASSERT_NE(pointerEvent, nullptr);
3872 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_UNKNOWN);
3873 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3874 }
3875
3876 /**
3877 * @tc.name: InputManager_SimulateInputEvent_001
3878 * @tc.desc: SimulateInputEvent interface detection
3879 * @tc.type: FUNC
3880 * @tc.require:SR000GGN6G
3881 */
3882 HWTEST_F(InputManagerTest, InputManager_SimulateInputKeyEvent_001, TestSize.Level1)
3883 {
3884 CALL_TEST_DEBUG;
3885 auto keyEvent = KeyEvent::Create();
3886 ASSERT_NE(keyEvent, nullptr);
3887 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3888 }
3889
3890 /**
3891 * @tc.name: InputManagerTest_RemoveInputEventFilter_001
3892 * @tc.desc: When eventFilterService is empty
3893 * @tc.type: FUNC
3894 * @tc.require:
3895 */
3896 HWTEST_F(InputManagerTest, InputManagerTest_RemoveInputEventFilter_001, TestSize.Level1)
3897 {
3898 CALL_TEST_DEBUG;
3899 int32_t ret = InputManager::GetInstance()->RemoveInputEventFilter(-1);
3900 ASSERT_EQ(ret, RET_OK);
3901 ret = InputManager::GetInstance()->RemoveInputEventFilter(0);
3902 ASSERT_EQ(ret, RET_OK);
3903 ret = InputManager::GetInstance()->RemoveInputEventFilter(1);
3904 ASSERT_EQ(ret, RET_OK);
3905 }
3906
3907 /**
3908 * @tc.name: InputManagerTest_RemoveInputEventFilter_002
3909 * @tc.desc: When the eventFilterService is full
3910 * @tc.type: FUNC
3911 * @tc.require:
3912 */
3913 HWTEST_F(InputManagerTest, InputManagerTest_RemoveInputEventFilter_002, TestSize.Level1)
3914 {
3915 CALL_DEBUG_ENTER;
3916 struct KeyFilter : public IInputEventFilter {
OnInputEventOHOS::MMI::KeyFilter3917 bool OnInputEvent(std::shared_ptr<KeyEvent> keyEvent) const override
3918 {
3919 MMI_HILOGI("KeyFilter::OnInputEvent enter,pid:%{public}d", getpid());
3920 return false;
3921 }
OnInputEventOHOS::MMI::KeyFilter3922 bool OnInputEvent(std::shared_ptr<PointerEvent> pointerEvent) const override
3923 {
3924 return false;
3925 }
3926 };
__anonaec9e8f54902() 3927 auto addFilter = []() -> int32_t {
3928 auto filter = std::make_shared<KeyFilter>();
3929 uint32_t touchTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX);
3930 const int32_t filterId = InputManager::GetInstance()->AddInputEventFilter(filter, 220, touchTags);
3931 return filterId;
3932 };
3933 const size_t singleClientSuportMaxNum = 4;
3934 for (size_t i = 0; i < singleClientSuportMaxNum; ++i) {
3935 int32_t filterId = addFilter();
3936 ASSERT_NE(filterId, RET_ERR);
3937 }
3938 int32_t filterId = addFilter();
3939 ASSERT_EQ(filterId, RET_ERR);
3940 auto ret = InputManager::GetInstance()->RemoveInputEventFilter(RET_ERR);
3941 ASSERT_EQ(ret, RET_OK);
3942 }
3943
3944 /**
3945 * @tc.name: InputManagerTest_RemoveInputEventFilter_003
3946 * @tc.desc: Verify valid parameter.
3947 * @tc.type: FUNC
3948 * @tc.require:
3949 */
3950 HWTEST_F(InputManagerTest, InputManagerTest_RemoveInputEventFilter_003, TestSize.Level1)
3951 {
3952 CALL_DEBUG_ENTER;
3953 struct KeyFilter : public IInputEventFilter {
OnInputEventOHOS::MMI::KeyFilter3954 bool OnInputEvent(std::shared_ptr<KeyEvent> keyEvent) const override
3955 {
3956 MMI_HILOGI("KeyFilter::OnInputEvent enter,pid:%{public}d", getpid());
3957 return false;
3958 }
OnInputEventOHOS::MMI::KeyFilter3959 bool OnInputEvent(std::shared_ptr<PointerEvent> pointerEvent) const override
3960 {
3961 return false;
3962 }
3963 };
__anonaec9e8f54a02() 3964 auto addFilter = []() -> int32_t {
3965 auto filter = std::make_shared<KeyFilter>();
3966 uint32_t touchTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX);
3967 int32_t filterId = InputManager::GetInstance()->AddInputEventFilter(filter, 220, touchTags);
3968 return filterId;
3969 };
3970 int32_t filterId = addFilter();
3971 ASSERT_NE(filterId, RET_ERR);
3972 auto ret = InputManager::GetInstance()->RemoveInputEventFilter(filterId);
3973 ASSERT_EQ(ret, RET_OK);
3974 filterId = addFilter();
3975 ASSERT_NE(filterId, RET_ERR);
3976 ret = InputManager::GetInstance()->RemoveInputEventFilter(filterId);
3977 ASSERT_EQ(ret, RET_OK);
3978 }
3979
3980 /**
3981 * @tc.name: InputManager_SlideUpBrightScreenUnlockEvent_001
3982 * @tc.desc: Injection interface detection
3983 * @tc.type: FUNC
3984 * @tc.require:AR000GJG6G
3985 */
3986 HWTEST_F(InputManagerTest, InputManager_SlideUpBrightScreenUnlockEvent_001, TestSize.Level1)
3987 {
3988 CALL_TEST_DEBUG;
3989 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
3990 ASSERT_NE(injectDownEvent, nullptr);
3991 injectDownEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3992
3993 KeyEvent::KeyItem kitDown;
3994 kitDown.SetKeyCode(KeyEvent::KEYCODE_F5);
3995 kitDown.SetPressed(true);
3996 kitDown.SetDownTime(500);
3997 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_F5);
3998 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3999 injectDownEvent->AddPressedKeyItems(kitDown);
4000 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
4001
4002 std::shared_ptr<KeyEvent> injectUpEvent = KeyEvent::Create();
4003 ASSERT_NE(injectUpEvent, nullptr);
4004 injectDownEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
4005
4006 KeyEvent::KeyItem kitUp;
4007 kitUp.SetKeyCode(KeyEvent::KEYCODE_F5);
4008 kitUp.SetPressed(false);
4009 kitUp.SetDownTime(500);
4010 injectUpEvent->SetKeyCode(KeyEvent::KEYCODE_F5);
4011 injectUpEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
4012 injectUpEvent->RemoveReleasedKeyItems(kitUp);
4013 InputManager::GetInstance()->SimulateInputEvent(injectUpEvent);
4014 }
4015
4016 /**
4017 * @tc.name: InputManager_SimulateEvent_001
4018 * @tc.desc: Injection interface detection
4019 * @tc.type: FUNC
4020 * @tc.require:AR20240223308600
4021 */
4022 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_001, TestSize.Level1)
4023 {
4024 CALL_TEST_DEBUG;
4025 auto pointerEvent = InputManagerUtil::SetupSimulateEvent001();
4026 MMI_HILOGI("Before handle SimulateInputEvent");
4027 InputManagerUtil::PrintPointerEventId(pointerEvent);
4028 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
4029 MMI_HILOGI("After handle SimulateInputEvent");
4030 InputManagerUtil::PrintPointerEventId(pointerEvent);
4031 }
4032
4033 /**
4034 * @tc.name: InputManager_SimulateEvent_002
4035 * @tc.desc: Injection interface detection
4036 * @tc.type: FUNC
4037 * @tc.require:AR20240223308600
4038 */
4039 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_002, TestSize.Level1)
4040 {
4041 CALL_TEST_DEBUG;
4042 auto pointerEvent = InputManagerUtil::SetupSimulateEvent002();
4043 MMI_HILOGI("Before handle SimulateInputEvent");
4044 InputManagerUtil::PrintPointerEventId(pointerEvent);
4045 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
4046 MMI_HILOGI("After handle SimulateInputEvent");
4047 InputManagerUtil::PrintPointerEventId(pointerEvent);
4048 }
4049
4050 /**
4051 * @tc.name: InputManager_SimulateEvent_003
4052 * @tc.desc: Injection interface detection
4053 * @tc.type: FUNC
4054 * @tc.require:AR20240223308600
4055 */
4056 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_003, TestSize.Level1)
4057 {
4058 CALL_TEST_DEBUG;
4059 auto pointerEvent = InputManagerUtil::SetupSimulateEvent003();
4060 MMI_HILOGI("Before handle SimulateInputEvent");
4061 InputManagerUtil::PrintPointerEventId(pointerEvent);
4062 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
4063 MMI_HILOGI("After handle SimulateInputEvent");
4064 InputManagerUtil::PrintPointerEventId(pointerEvent);
4065 }
4066
4067 /**
4068 * @tc.name: InputManager_SimulateEvent_004
4069 * @tc.desc: Injection interface detection
4070 * @tc.type: FUNC
4071 * @tc.require:AR20240223308600
4072 */
4073 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_004, TestSize.Level1)
4074 {
4075 CALL_TEST_DEBUG;
4076 auto pointerEvent = InputManagerUtil::SetupSimulateEvent004();
4077 MMI_HILOGI("Before handle SimulateInputEvent");
4078 InputManagerUtil::PrintPointerEventId(pointerEvent);
4079 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
4080 MMI_HILOGI("After handle SimulateInputEvent");
4081 InputManagerUtil::PrintPointerEventId(pointerEvent);
4082 }
4083
4084 /**
4085 * @tc.name: InputManager_SimulateEvent_005
4086 * @tc.desc: Injection interface detection
4087 * @tc.type: FUNC
4088 * @tc.require:AR20240223308600
4089 */
4090 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_005, TestSize.Level1)
4091 {
4092 CALL_TEST_DEBUG;
4093 auto pointerEvent = InputManagerUtil::SetupSimulateEvent005();
4094 MMI_HILOGI("Before handle SimulateInputEvent");
4095 InputManagerUtil::PrintPointerEventId(pointerEvent);
4096 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
4097 MMI_HILOGI("After handle SimulateInputEvent");
4098 InputManagerUtil::PrintPointerEventId(pointerEvent);
4099 }
4100
4101 /**
4102 * @tc.name: InputManager_SimulateEvent_006
4103 * @tc.desc: Injection interface detection
4104 * @tc.type: FUNC
4105 * @tc.require:AR20240223308600
4106 */
4107 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_006, TestSize.Level1)
4108 {
4109 CALL_TEST_DEBUG;
4110 auto pointerEvent = InputManagerUtil::SetupSimulateEvent006();
4111 MMI_HILOGI("Before handle SimulateInputEvent");
4112 InputManagerUtil::PrintPointerEventId(pointerEvent);
4113 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
4114 MMI_HILOGI("After handle SimulateInputEvent");
4115 InputManagerUtil::PrintPointerEventId(pointerEvent);
4116 }
4117
4118 /**
4119 * @tc.name: InputManager_SimulateEvent_007
4120 * @tc.desc: Injection interface detection
4121 * @tc.type: FUNC
4122 * @tc.require:AR20240223308600
4123 */
4124 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_007, TestSize.Level1)
4125 {
4126 CALL_TEST_DEBUG;
4127 auto pointerEvent = InputManagerUtil::SetupSimulateEvent007();
4128 MMI_HILOGI("Before handle SimulateInputEvent");
4129 InputManagerUtil::PrintPointerEventId(pointerEvent);
4130 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
4131 MMI_HILOGI("After handle SimulateInputEvent");
4132 InputManagerUtil::PrintPointerEventId(pointerEvent);
4133 }
4134
4135 /**
4136 * @tc.name: InputManager_SimulateEvent_008
4137 * @tc.desc: Injection interface detection
4138 * @tc.type: FUNC
4139 * @tc.require:AR20240223308600
4140 */
4141 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_008, TestSize.Level1)
4142 {
4143 CALL_TEST_DEBUG;
4144 auto pointerEvent = InputManagerUtil::SetupSimulateEvent008();
4145 MMI_HILOGI("Before handle SimulateInputEvent");
4146 InputManagerUtil::PrintPointerEventId(pointerEvent);
4147 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
4148 MMI_HILOGI("After handle SimulateInputEvent");
4149 InputManagerUtil::PrintPointerEventId(pointerEvent);
4150 }
4151
4152 class ServiceWatcher final : public IInputServiceWatcher {
4153 public:
4154 ServiceWatcher() = default;
4155 ~ServiceWatcher() = default;
4156
OnServiceDied()4157 void OnServiceDied() override
4158 {}
4159 };
4160
4161 /**
4162 * @tc.name: InputManagerTest_InputServiceWatcher
4163 * @tc.desc: Verify service watcher.
4164 * @tc.type: FUNC
4165 * @tc.require:
4166 */
4167 HWTEST_F(InputManagerTest, InputManagerTest_InputServiceWatcher, TestSize.Level1)
4168 {
4169 auto watcher = std::make_shared<ServiceWatcher>();
4170 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->AddServiceWatcher(watcher));
4171 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->RemoveServiceWatcher(watcher));
4172 }
4173
4174 /**
4175 * @tc.name: InputManagerTest_MoveMouse_001
4176 * @tc.desc: MoveMouse interface detection
4177 * @tc.type: FUNC
4178 * @tc.require:
4179 */
4180 HWTEST_F(InputManagerTest, InputManagerTest_MoveMouse_001, TestSize.Level1)
4181 {
4182 CALL_TEST_DEBUG;
4183 int32_t offsetX = 20;
4184 int32_t offsetY = 20;
4185 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->MoveMouse(offsetX, offsetY));
4186 }
4187
4188 /**
4189 * @tc.name: InputManagerTest_MouseScrollRows_001
4190 * @tc.desc: SetMouseScrollRows and GetMouseScrollRows interface detection
4191 * @tc.type: FUNC
4192 * @tc.require:
4193 */
4194 HWTEST_F(InputManagerTest, InputManagerTest_MouseScrollRows_001, TestSize.Level1)
4195 {
4196 CALL_TEST_DEBUG;
4197 int32_t rows = 1;
4198 int32_t result = InputManager::GetInstance()->SetMouseScrollRows(rows);
4199 ASSERT_EQ(result, RET_OK);
4200 result = InputManager::GetInstance()->GetMouseScrollRows(rows);
4201 ASSERT_EQ(rows, 1);
4202 ASSERT_EQ(result, RET_OK);
4203 }
4204
4205 /**
4206 * @tc.name: InputManagerTest_SetCustomCursor_001
4207 * @tc.desc: SetCustomCursor interface detection
4208 * @tc.type: FUNC
4209 * @tc.require:
4210 */
4211 HWTEST_F(InputManagerTest, InputManagerTest_SetCustomCursor_001, TestSize.Level1)
4212 {
4213 CALL_TEST_DEBUG;
4214 int32_t windowId = 500;
4215 void* pixelMap = nullptr;
4216 int32_t result = InputManager::GetInstance()->SetCustomCursor(windowId, pixelMap);
4217 ASSERT_NE(result, RET_ERR);
4218 }
4219
4220 /**
4221 * @tc.name: InputManagerTest_SetMouseIcon_001
4222 * @tc.desc: SetMouseIcon interface detection
4223 * @tc.type: FUNC
4224 * @tc.require:
4225 */
4226 HWTEST_F(InputManagerTest, InputManagerTest_SetMouseIcon_001, TestSize.Level1)
4227 {
4228 CALL_TEST_DEBUG;
4229 int32_t windowId = 500;
4230 void* pixelMap = nullptr;
4231 int32_t result = InputManager::GetInstance()->SetMouseIcon(windowId, pixelMap);
4232 ASSERT_NE(result, RET_OK);
4233 }
4234
4235 /**
4236 * @tc.name: InputManagerTest_SetMouseHotSpot_001
4237 * @tc.desc: SetMouseHotSpot interface detection
4238 * @tc.type: FUNC
4239 * @tc.require:
4240 */
4241 HWTEST_F(InputManagerTest, InputManagerTest_SetMouseHotSpot_001, TestSize.Level1)
4242 {
4243 CALL_TEST_DEBUG;
4244 int32_t windowId = 500;
4245 int32_t hotSpotX = 20;
4246 int32_t hotSpotY = 20;
4247 int32_t result = InputManager::GetInstance()->SetMouseHotSpot(windowId, hotSpotX, hotSpotY);
4248 ASSERT_EQ(result, RET_ERR);
4249 }
4250
4251 /**
4252 * @tc.name: InputManagerTest_PointerSize_001
4253 * @tc.desc: SetPointerSize and GetPointerSize interface detection
4254 * @tc.type: FUNC
4255 * @tc.require:
4256 */
4257 HWTEST_F(InputManagerTest, InputManagerTest_PointerSize_001, TestSize.Level1)
4258 {
4259 CALL_TEST_DEBUG;
4260 int32_t size = 5;
4261 int32_t result = InputManager::GetInstance()->SetPointerSize(size);
4262 ASSERT_EQ(result, RET_OK);
4263 result = InputManager::GetInstance()->GetPointerSize(size);
4264 ASSERT_EQ(size, 5);
4265 ASSERT_EQ(result, RET_OK);
4266 }
4267
4268 /**
4269 * @tc.name: InputManagerTest_GetCursorSurfaceId_001
4270 * @tc.desc: SetPointerSize and GetPointerSize interface detection
4271 * @tc.type: FUNC
4272 * @tc.require:
4273 */
4274 HWTEST_F(InputManagerTest, InputManagerTest_GetCursorSurfaceId_001, TestSize.Level1)
4275 {
4276 CALL_TEST_DEBUG;
4277 uint64_t surfaceId {};
4278 auto result = InputManager::GetInstance()->GetCursorSurfaceId(surfaceId);
4279 ASSERT_EQ(result, RET_OK);
4280 std::cout << "CursorSurfaceId:" << surfaceId << std::endl;
4281 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->GetCursorSurfaceId(surfaceId));
4282 }
4283
4284 /**
4285 * @tc.name: InputManagerTest_MousePrimaryButton_001
4286 * @tc.desc: SetMousePrimaryButton and GetMousePrimaryButton interface detection
4287 * @tc.type: FUNC
4288 * @tc.require:
4289 */
4290 HWTEST_F(InputManagerTest, InputManagerTest_MousePrimaryButton_001, TestSize.Level1)
4291 {
4292 CALL_TEST_DEBUG;
4293 int32_t primaryButton = 2;
4294 int32_t result = InputManager::GetInstance()->SetMousePrimaryButton(primaryButton);
4295 ASSERT_EQ(result, RET_ERR);
4296 primaryButton = 1;
4297 result = InputManager::GetInstance()->SetMousePrimaryButton(primaryButton);
4298 ASSERT_EQ(result, RET_OK);
4299 result = InputManager::GetInstance()->GetMousePrimaryButton(primaryButton);
4300 ASSERT_EQ(primaryButton, 1);
4301 ASSERT_EQ(result, RET_OK);
4302 }
4303
4304 /**
4305 * @tc.name: InputManagerTest_TouchpadScrollDirection_001
4306 * @tc.desc: SetTouchpadScrollDirection and GetTouchpadScrollDirection interface detection
4307 * @tc.type: FUNC
4308 * @tc.require:
4309 */
4310 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadScrollDirection_001, TestSize.Level1)
4311 {
4312 CALL_TEST_DEBUG;
4313 bool state = true;
4314 int32_t result = InputManager::GetInstance()->SetTouchpadScrollDirection(state);
4315 ASSERT_EQ(result, RET_OK);
4316 result = InputManager::GetInstance()->GetTouchpadScrollDirection(state);
4317 ASSERT_EQ(state, true);
4318 ASSERT_EQ(result, RET_OK);
4319 }
4320
4321 /**
4322 * @tc.name: InputManagerTest_TouchpadScrollDirection_001
4323 * @tc.desc: SetTouchpadScrollDirection and GetTouchpadScrollDirection interface detection
4324 * @tc.type: FUNC
4325 * @tc.require:
4326 */
4327 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadScrollSwitch_001, TestSize.Level1)
4328 {
4329 CALL_TEST_DEBUG;
4330 bool switchFlag = true;
4331 int32_t result = InputManager::GetInstance()->SetTouchpadScrollSwitch(switchFlag);
4332 ASSERT_EQ(result, RET_OK);
4333 result = InputManager::GetInstance()->GetTouchpadScrollSwitch(switchFlag);
4334 ASSERT_EQ(switchFlag, true);
4335 ASSERT_EQ(result, RET_OK);
4336 }
4337
4338 /**
4339 * @tc.name: InputManagerTest_TouchpadPointerSpeed_001
4340 * @tc.desc: SetTouchpadPointerSpeed and GetTouchpadPointerSpeed interface detection
4341 * @tc.type: FUNC
4342 * @tc.require:
4343 */
4344 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadPointerSpeed_001, TestSize.Level1)
4345 {
4346 CALL_TEST_DEBUG;
4347 int32_t speed = 1;
4348 int32_t result = InputManager::GetInstance()->SetTouchpadPointerSpeed(speed);
4349 ASSERT_EQ(result, RET_OK);
4350 result = InputManager::GetInstance()->GetTouchpadPointerSpeed(speed);
4351 ASSERT_EQ(speed, 1);
4352 ASSERT_EQ(result, RET_OK);
4353 }
4354
4355 /**
4356 * @tc.name: InputManagerTest_TouchpadPinchSwitch_001
4357 * @tc.desc: SetTouchpadPinchSwitch and GetTouchpadPinchSwitch interface detection
4358 * @tc.type: FUNC
4359 * @tc.require:
4360 */
4361 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadPinchSwitch_001, TestSize.Level1)
4362 {
4363 CALL_TEST_DEBUG;
4364 bool switchFlag = true;
4365 int32_t result = InputManager::GetInstance()->SetTouchpadPinchSwitch(switchFlag);
4366 ASSERT_EQ(result, RET_OK);
4367 result = InputManager::GetInstance()->GetTouchpadPinchSwitch(switchFlag);
4368 ASSERT_EQ(switchFlag, true);
4369 ASSERT_EQ(result, RET_OK);
4370 }
4371
4372 /**
4373 * @tc.name: InputManagerTest_TouchpadPinchSwitch_002
4374 * @tc.desc: GetTouchpadPinchSwitch interface detection without SetTouchpadPinchSwitch
4375 * @tc.type: FUNC
4376 * @tc.require:
4377 */
4378 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadPinchSwitch_002, TestSize.Level1)
4379 {
4380 CALL_TEST_DEBUG;
4381 bool switchFlag = false;
4382 EXPECT_NO_FATAL_FAILURE(InputManager::GetInstance()->GetTouchpadPinchSwitch(switchFlag));
4383 EXPECT_EQ(switchFlag, true);
4384 }
4385
4386 /**
4387 * @tc.name: InputManagerTest_TouchpadSwipeSwitch_001
4388 * @tc.desc: SetTouchpadSwipeSwitch and GetTouchpadSwipeSwitch interface detection
4389 * @tc.type: FUNC
4390 * @tc.require:
4391 */
4392 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadSwipeSwitch_001, TestSize.Level1)
4393 {
4394 CALL_TEST_DEBUG;
4395 bool switchFlag = true;
4396 int32_t result = InputManager::GetInstance()->SetTouchpadSwipeSwitch(switchFlag);
4397 ASSERT_EQ(result, RET_OK);
4398 result = InputManager::GetInstance()->GetTouchpadSwipeSwitch(switchFlag);
4399 ASSERT_EQ(switchFlag, true);
4400 ASSERT_EQ(result, RET_OK);
4401 }
4402
4403 /**
4404 * @tc.name: InputManagerTest_TouchpadSwipeSwitch_002
4405 * @tc.desc: GetTouchpadSwipeSwitch interface detection witchout SetTouchpadSwipeSwitch
4406 * @tc.type: FUNC
4407 * @tc.require:
4408 */
4409 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadSwipeSwitch_002, TestSize.Level1)
4410 {
4411 CALL_TEST_DEBUG;
4412 bool switchFlag = false;
4413 EXPECT_NO_FATAL_FAILURE(InputManager::GetInstance()->GetTouchpadSwipeSwitch(switchFlag));
4414 EXPECT_EQ(switchFlag, true);
4415 }
4416
4417 /**
4418 * @tc.name: InputManagerTest_TouchpadRightClickType_001
4419 * @tc.desc: SetTouchpadRightClickType and GetTouchpadRightClickType interface detection
4420 * @tc.type: FUNC
4421 * @tc.require:
4422 */
4423 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadRightClickType_001, TestSize.Level1)
4424 {
4425 CALL_TEST_DEBUG;
4426 int32_t type = 1;
4427 int32_t result = InputManager::GetInstance()->SetTouchpadRightClickType(type);
4428 ASSERT_EQ(result, RET_OK);
4429 result = InputManager::GetInstance()->GetTouchpadRightClickType(type);
4430 ASSERT_EQ(type, 1);
4431 ASSERT_EQ(result, RET_OK);
4432 }
4433
4434 /**
4435 * @tc.name: InputManagerTest_SetTouchpadTapSwitch_001
4436 * @tc.desc: Set touchpad tap switch
4437 * @tc.type: FUNC
4438 * @tc.require:
4439 */
4440 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadTapSwitch_001, TestSize.Level1)
4441 {
4442 CALL_TEST_DEBUG;
4443 bool flag = false;
4444 InputManager::GetInstance()->Authorize(true);
4445 ASSERT_TRUE(InputManager::GetInstance()->SetTouchpadTapSwitch(flag) == RET_OK);
4446 }
4447
4448 /**
4449 * @tc.name: InputManagerTest_GetTouchpadTapSwitch_001
4450 * @tc.desc: Get touchpad tap switch
4451 * @tc.type: FUNC
4452 * @tc.require:
4453 */
4454 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadTapSwitch_001, TestSize.Level1)
4455 {
4456 CALL_TEST_DEBUG;
4457 bool flag = true;
4458 InputManager::GetInstance()->SetTouchpadTapSwitch(flag);
4459 bool newFlag = true;
4460 InputManager::GetInstance()->Authorize(true);
4461 ASSERT_TRUE(InputManager::GetInstance()->GetTouchpadTapSwitch(newFlag) == RET_OK);
4462 ASSERT_TRUE(flag == newFlag);
4463 }
4464
4465 /**
4466 * @tc.name: InputManagerTest_SetTouchpadDoubleTapAndDragState_001
4467 * @tc.desc: Set Touchpad Double Tap And Drag State
4468 * @tc.type: FUNC
4469 * @tc.require:
4470 */
4471 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadDoubleTapAndDragState_001, TestSize.Level1)
4472 {
4473 CALL_TEST_DEBUG;
4474 bool switchFlag = true;
4475 int32_t ret = InputManager::GetInstance()->SetTouchpadDoubleTapAndDragState(switchFlag);
4476 EXPECT_EQ(ret, RET_OK);
4477 }
4478
4479 /**
4480 * @tc.name: InputManagerTest_GetTouchpadDoubleTapAndDragState_001
4481 * @tc.desc: Get touchpad tap switch
4482 * @tc.type: FUNC
4483 * @tc.require:
4484 */
4485 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadDoubleTapAndDragState_001, TestSize.Level1)
4486 {
4487 CALL_TEST_DEBUG;
4488 bool flag = true;
4489 InputManager::GetInstance()->SetTouchpadDoubleTapAndDragState(flag);
4490 bool newFlag = true;
4491 ASSERT_TRUE(InputManager::GetInstance()->GetTouchpadDoubleTapAndDragState(newFlag) == RET_OK);
4492 ASSERT_TRUE(flag == newFlag);
4493 }
4494
4495 /**
4496 * @tc.name: InputManagerTest_SetTouchpadRotateSwitch_001
4497 * @tc.desc: Set touchpad rotate switch
4498 * @tc.type: FUNC
4499 * @tc.require:
4500 */
4501 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadRotateSwitch_001, TestSize.Level1)
4502 {
4503 CALL_TEST_DEBUG;
4504 bool rotateSwitch = false;
4505 ASSERT_TRUE(InputManager::GetInstance()->SetTouchpadRotateSwitch(rotateSwitch) == RET_OK);
4506 }
4507
4508 /**
4509 * @tc.name: InputManagerTest_GetTouchpadRotateSwitch_001
4510 * @tc.desc: Get touchpad rotate switch
4511 * @tc.type: FUNC
4512 * @tc.require:
4513 */
4514 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadRotateSwitch_001, TestSize.Level1)
4515 {
4516 CALL_TEST_DEBUG;
4517 bool rotateSwitch = true;
4518 InputManager::GetInstance()->SetTouchpadRotateSwitch(rotateSwitch);
4519 bool newRotateSwitch = true;
4520 ASSERT_TRUE(InputManager::GetInstance()->GetTouchpadRotateSwitch(newRotateSwitch) == RET_OK);
4521 ASSERT_TRUE(rotateSwitch == newRotateSwitch);
4522 }
4523
4524 /**
4525 * @tc.name: InputManagerTest_SetCurrentUser_001
4526 * @tc.desc: set current user id
4527 * @tc.type: FUNC
4528 * @tc.require:
4529 */
4530 HWTEST_F(InputManagerTest, InputManagerTest_SetCurrentUser_001, TestSize.Level1)
4531 {
4532 int32_t userId = 10;
4533 int32_t ret = InputManager::GetInstance()->SetCurrentUser(userId);
4534 EXPECT_FALSE(ret == RET_OK);
4535 }
4536
4537 /**
4538 * @tc.name: InputManagerTest_HasIrEmitter
4539 * @tc.desc: Test HasIrEmitter
4540 * @tc.type: FUNC
4541 * @tc.require:
4542 */
4543 HWTEST_F(InputManagerTest, InputManagerTest_HasIrEmitter, TestSize.Level1)
4544 {
4545 bool hasIrEmitter = false;
4546 int32_t ret = InputManager::GetInstance()->HasIrEmitter(hasIrEmitter);
4547 EXPECT_EQ(ret, RET_OK);
4548 }
4549
4550 /**
4551 * @tc.name: InputManagerTest_GetInfraredFrequencies
4552 * @tc.desc: Test GetInfraredFrequencies
4553 * @tc.type: FUNC
4554 * @tc.require:
4555 */
4556 HWTEST_F(InputManagerTest, InputManagerTest_GetInfraredFrequencies, TestSize.Level1)
4557 {
4558 InfraredFrequency infraredFrequency;
4559 infraredFrequency.max_ = 30;
4560 infraredFrequency.min_ = 10;
4561 std::vector<InfraredFrequency> requencys;
4562 requencys.push_back(infraredFrequency);
4563 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->GetInfraredFrequencies(requencys));
4564 }
4565
4566 /**
4567 * @tc.name: InputManagerTest_TransmitInfrared
4568 * @tc.desc: Test TransmitInfrared
4569 * @tc.type: FUNC
4570 * @tc.require:
4571 */
4572 HWTEST_F(InputManagerTest, InputManagerTest_TransmitInfrared, TestSize.Level1)
4573 {
4574 int64_t number = 10;
4575 std::vector<int64_t> pattern = { 10, 20, 30 };
4576 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->TransmitInfrared(number, pattern));
4577 }
4578
4579 /**
4580 * @tc.name: InputManagerTest_EnableHardwareCursorStats_001
4581 * @tc.desc: Enable hardware cursor stats
4582 * @tc.type: FUNC
4583 * @tc.require:
4584 */
4585 HWTEST_F(InputManagerTest, InputManagerTest_EnableHardwareCursorStats_001, TestSize.Level1)
4586 {
4587 CALL_TEST_DEBUG;
4588 #ifdef OHOS_BUILD_ENABLE_POINTER
4589 auto ret = InputManager::GetInstance()->EnableHardwareCursorStats(false);
4590 ASSERT_EQ(ret, RET_OK);
4591 ret = InputManager::GetInstance()->EnableHardwareCursorStats(true);
4592 ASSERT_EQ(ret, RET_OK);
4593 #else
4594 auto ret = InputManager::GetInstance()->EnableHardwareCursorStats(false);
4595 ASSERT_EQ(ret, ERROR_UNSUPPORT);
4596 ret = InputManager::GetInstance()->EnableHardwareCursorStats(true);
4597 ASSERT_EQ(ret, ERROR_UNSUPPORT);
4598 #endif // OHOS_BUILD_ENABLE_POINTER
4599 }
4600
4601 /**
4602 * @tc.name: InputManagerTest_GetHardwareCursorStats_001
4603 * @tc.desc: get hardware cursor stats
4604 * @tc.type: FUNC
4605 * @tc.require:
4606 */
4607 HWTEST_F(InputManagerTest, InputManagerTest_GetHardwareCursorStats_001, TestSize.Level1)
4608 {
4609 CALL_TEST_DEBUG;
4610 uint32_t frameCount = 1;
4611 uint32_t vsyncCount = 1;
4612 #ifdef OHOS_BUILD_ENABLE_POINTER
4613 auto ret = InputManager::GetInstance()->EnableHardwareCursorStats(true);
4614 ASSERT_EQ(ret, RET_OK);
4615 ret = InputManager::GetInstance()->EnableHardwareCursorStats(false);
4616 ASSERT_EQ(ret, RET_OK);
4617 ret = InputManager::GetInstance()->GetHardwareCursorStats(frameCount, vsyncCount);
4618 ASSERT_EQ(ret, RET_OK);
4619 ASSERT_EQ(frameCount, 0);
4620 ASSERT_EQ(vsyncCount, 0);
4621 #else
4622 auto ret = InputManager::GetInstance()->GetHardwareCursorStats(frameCount, vsyncCount);
4623 ASSERT_EQ(ret, ERROR_UNSUPPORT);
4624 #endif // OHOS_BUILD_ENABLE_POINTER
4625 }
4626
4627 /**
4628 * @tc.name: InputManagerTest_AppendExtraData_001
4629 * @tc.desc: Append Extra Data
4630 * @tc.type: FUNC
4631 * @tc.require:
4632 */
4633 HWTEST_F(InputManagerTest, InputManagerTest_AppendExtraData_001, TestSize.Level1)
4634 {
4635 CALL_TEST_DEBUG;
4636 ExtraData data;
4637 data.buffer.resize(1025);
4638 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->AppendExtraData(data));
4639 data.buffer.resize(512);
4640 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->AppendExtraData(data));
4641 }
4642
4643 /**
4644 * @tc.name: InputManagerTest_TouchpadScrollRows_001
4645 * @tc.desc: SetTouchpadScrollRows and GetTouchpadScrollRows interface detection
4646 * @tc.type: FUNC
4647 * @tc.require:
4648 */
4649 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadScrollRows_001, TestSize.Level1)
4650 {
4651 CALL_TEST_DEBUG;
4652 int32_t rows = 1;
4653 int32_t result = InputManager::GetInstance()->SetTouchpadScrollRows(rows);
4654 ASSERT_EQ(result, RET_OK);
4655 result = InputManager::GetInstance()->GetTouchpadScrollRows(rows);
4656 ASSERT_EQ(rows, 1);
4657 ASSERT_EQ(result, RET_OK);
4658 }
4659
4660 /**
4661 * @tc.name: InputManagerTest_TouchpadScrollRows_002
4662 * @tc.desc: SetTouchpadScrollRows and GetTouchpadScrollRows interface detection
4663 * @tc.type: FUNC
4664 * @tc.require:
4665 */
4666 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadScrollRows_002, TestSize.Level1)
4667 {
4668 CALL_TEST_DEBUG;
4669 int32_t rows = -1;
4670 InputManager::GetInstance()->SetTouchpadScrollRows(rows);
4671 int32_t result = InputManager::GetInstance()->GetTouchpadScrollRows(rows);
4672 ASSERT_EQ(rows, 1);
4673 ASSERT_EQ(result, RET_OK);
4674 rows = 101;
4675 InputManager::GetInstance()->SetTouchpadScrollRows(rows);
4676 result = InputManager::GetInstance()->GetTouchpadScrollRows(rows);
4677 ASSERT_EQ(rows, 100);
4678 ASSERT_EQ(result, RET_OK);
4679 }
4680
4681 /**
4682 * @tc.name: InputManagerTest_GetPointerSnapshot
4683 * @tc.desc: Test GetPointerSnapshot
4684 * @tc.require:
4685 */
4686 HWTEST_F(InputManagerTest, InputManagerTest_GetPointerSnapshot, TestSize.Level1)
4687 {
4688 CALL_TEST_DEBUG;
4689 void *pixelMap = nullptr;
4690 EXPECT_NE(InputManager::GetInstance()->GetPointerSnapshot(pixelMap), RET_OK);
4691 }
4692
4693 /**
4694 * @tc.name: InputManagerTest_GetIntervalSinceLastInput001
4695 * @tc.desc: GetIntervalSinceLastInput interface detection
4696 * @tc.type: FUNC
4697 * @tc.require:
4698 */
4699 HWTEST_F(InputManagerTest, InputManagerTest_GetIntervalSinceLastInput001, TestSize.Level1)
4700 {
4701 CALL_TEST_DEBUG;
4702 int64_t timeInterval = -1;
4703 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->GetIntervalSinceLastInput(timeInterval));
4704 }
4705
4706 /**
4707 * @tc.name: InputManagerTest_GetIntervalSinceLastInput002
4708 * @tc.desc: GetIntervalSinceLastInput interface detection
4709 * @tc.type: FUNC
4710 * @tc.require:
4711 */
4712 HWTEST_F(InputManagerTest, InputManagerTest_GetIntervalSinceLastInput002, TestSize.Level1)
4713 {
4714 CALL_TEST_DEBUG;
4715 auto pointerEvent = PointerEvent::Create();
4716 ASSERT_NE(pointerEvent, nullptr);
4717 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD);
4718 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
4719 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
4720 int64_t timeInterval = 0;
4721 int32_t result =InputManager::GetInstance()->GetIntervalSinceLastInput(timeInterval);
4722 ASSERT_EQ(result, RET_OK);
4723 EXPECT_GE(timeInterval, (TIME_WAIT_FOR_OP * SLEEP_MILLISECONDS));
4724 }
4725
4726 /**
4727 * @tc.name: InputManagerTest_GetIntervalSinceLastInput003
4728 * @tc.desc: GetIntervalSinceLastInput interface detection
4729 * @tc.type: FUNC
4730 * @tc.require:
4731 */
4732 HWTEST_F(InputManagerTest, InputManagerTest_GetIntervalSinceLastInput003, TestSize.Level1)
4733 {
4734 CALL_TEST_DEBUG;
4735 auto pointerEvent = PointerEvent::Create();
4736 ASSERT_NE(pointerEvent, nullptr);
4737 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD);
4738 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
4739 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
4740 auto keyEvent = KeyEvent::Create();
4741 ASSERT_NE(keyEvent, nullptr);
4742 KeyEvent::KeyItem itemSecond;
4743 itemSecond.SetKeyCode(KeyEvent::KEYCODE_R);
4744 itemSecond.SetPressed(true);
4745 itemSecond.SetDownTime(500);
4746 keyEvent->AddKeyItem(itemSecond);
4747 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
4748 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
4749 int64_t timeInterval = 0;
4750 int32_t result =InputManager::GetInstance()->GetIntervalSinceLastInput(timeInterval);
4751 ASSERT_EQ(result, RET_OK);
4752 EXPECT_GE(timeInterval, (TIME_WAIT_FOR_OP * SLEEP_MILLISECONDS));
4753 }
4754
4755 /**
4756 * @tc.name: InputManagerTest_GetAllSystemHotkey
4757 * @tc.desc: Obtains all hot keys supported by the system.
4758 * @tc.type: FUNC
4759 * @tc.require:
4760 */
4761 HWTEST_F(InputManagerTest, InputManagerTest_GetAllSystemHotkey_001, TestSize.Level1)
4762 {
4763 CALL_TEST_DEBUG;
4764 int32_t count = 0;
4765 std::vector<std::unique_ptr<KeyOption>> keyOptions;
4766 int32_t ret = InputManager::GetInstance()->GetAllSystemHotkeys(keyOptions, count);
4767 ASSERT_EQ(ret, RET_OK);
4768 }
4769
4770 /**
4771 * @tc.name: InputManagerTest_SkipPointerLayer_001
4772 * @tc.desc: Test SkipPointerLayer
4773 * @tc.require:
4774 */
4775 HWTEST_F(InputManagerTest, InputManagerTest_SkipPointerLayer_001, TestSize.Level1)
4776 {
4777 CALL_TEST_DEBUG;
4778 bool isSkip = true;
4779 int32_t ret = InputManager::GetInstance()->SkipPointerLayer(isSkip);
4780 EXPECT_EQ(ret, RET_OK);
4781 isSkip = false;
4782 ret = InputManager::GetInstance()->SkipPointerLayer(isSkip);
4783 EXPECT_EQ(ret, RET_OK);
4784 }
4785
4786 /**
4787 * @tc.name: InputManagerTest_ConvertToCapiKeyAction_001
4788 * @tc.desc: Test the funcation ConvertToCapiKeyAction
4789 * @tc.require:
4790 */
4791 HWTEST_F(InputManagerTest, InputManagerTest_ConvertToCapiKeyAction_001, TestSize.Level1)
4792 {
4793 CALL_TEST_DEBUG;
4794 int32_t keyAction = 0X00000002;
4795 int32_t ret = InputManager::GetInstance()->ConvertToCapiKeyAction(keyAction);
4796 EXPECT_NE(ret, -1);
4797 }
4798
4799 /**
4800 * @tc.name: InputManagerTest_GestureMonitor_001
4801 * @tc.desc: Gesture Monitor
4802 * @tc.type: FUNC
4803 * @tc.require:
4804 */
4805 HWTEST_F(InputManagerTest, InputManagerTest_GestureMonitor_001, TestSize.Level1)
4806 {
4807 CALL_TEST_DEBUG;
4808 auto consumer = GetPtr<InputEventConsumer>();
4809 ASSERT_TRUE(consumer != nullptr);
4810 int32_t monitorId = InputManager::GetInstance()->AddGestureMonitor(consumer, TOUCH_GESTURE_TYPE_ALL, 1);
4811 #ifdef OHOS_BUILD_ENABLE_MONITOR
4812 ASSERT_TRUE(monitorId == INVALID_HANDLER_ID);
4813 #else
4814 ASSERT_TRUE(monitorId == ERROR_UNSUPPORT);
4815 #endif // OHOS_BUILD_ENABLE_MONITOR
4816 }
4817
4818 /**
4819 * @tc.name: InputManagerTest_GestureMonitor_002
4820 * @tc.desc: Gesture Monitor
4821 * @tc.type: FUNC
4822 * @tc.require:
4823 */
4824 HWTEST_F(InputManagerTest, InputManagerTest_GestureMonitor_002, TestSize.Level1)
4825 {
4826 CALL_TEST_DEBUG;
4827 auto consumer = GetPtr<InputEventConsumer>();
4828 ASSERT_TRUE(consumer != nullptr);
4829 int32_t monitorId = InputManager::GetInstance()->AddGestureMonitor(consumer, TOUCH_GESTURE_TYPE_PINCH, 3);
4830 #ifdef OHOS_BUILD_ENABLE_MONITOR
4831 ASSERT_TRUE(monitorId == INVALID_HANDLER_ID);
4832 #else
4833 ASSERT_TRUE(monitorId == ERROR_UNSUPPORT);
4834 #endif // OHOS_BUILD_ENABLE_MONITOR
4835 }
4836
4837 /**
4838 * @tc.name: InputManagerTest_GestureMonitor_003
4839 * @tc.desc: Gesture Monitor
4840 * @tc.type: FUNC
4841 * @tc.require:
4842 */
4843 HWTEST_F(InputManagerTest, InputManagerTest_GestureMonitor_003, TestSize.Level1)
4844 {
4845 CALL_TEST_DEBUG;
4846 auto consumer = GetPtr<InputEventConsumer>();
4847 ASSERT_TRUE(consumer != nullptr);
4848 int32_t monitorId = InputManager::GetInstance()->AddGestureMonitor(consumer, TOUCH_GESTURE_TYPE_ALL, 0);
4849 #ifdef OHOS_BUILD_ENABLE_MONITOR
4850 ASSERT_TRUE(monitorId != INVALID_HANDLER_ID);
4851 #else
4852 ASSERT_TRUE(monitorId == ERROR_UNSUPPORT);
4853 #endif // OHOS_BUILD_ENABLE_MONITOR
4854
4855 int32_t ret = InputManager::GetInstance()->RemoveGestureMonitor(monitorId);
4856 #ifdef OHOS_BUILD_ENABLE_MONITOR
4857 ASSERT_TRUE(ret == RET_OK);
4858 #else
4859 ASSERT_TRUE(ret == ERROR_UNSUPPORT);
4860 #endif // OHOS_BUILD_ENABLE_MONITOR
4861 }
4862
4863 /**
4864 @tc.name: InputManagerTest_SubscribeHotkey_001
4865 @tc.desc: Test the funcation SubscribeHotkey
4866 @tc.type: FUNC
4867 @tc.require:
4868 */
4869 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeHotkey_001, TestSize.Level1)
4870 {
4871 CALL_TEST_DEBUG;
4872 std::set<int32_t> preKeys;
4873 std::shared_ptr keyOption =
4874 InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_POWER, true, 0);
4875 int32_t response = INVAID_VALUE;
4876 response = InputManager::GetInstance()->SubscribeHotkey(keyOption, nullptr);
4877 EXPECT_TRUE(response < 0);
4878 }
4879
4880 /**
4881 @tc.name: InputManagerTest_UnsubscribeHotkey_001
4882 @tc.desc: Test the funcation UnsubscribeHotkey
4883 @tc.type: FUNC
4884 @tc.require:
4885 */
4886 HWTEST_F(InputManagerTest, InputManagerTest_UnsubscribeHotkey_001, TestSize.Level1)
4887 {
4888 CALL_TEST_DEBUG;
4889 int32_t subscriberId = 1;
4890 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UnsubscribeHotkey(subscriberId));
4891 }
4892
InjectAltL(size_t nTriggers)4893 void InputManagerTest::InjectAltL(size_t nTriggers)
4894 {
4895 auto keyEvent = KeyEvent::Create();
4896 ASSERT_NE(keyEvent, nullptr);
4897 keyEvent->SetKeyCode(KeyEvent::KEYCODE_L);
4898
4899 KeyEvent::KeyItem keyItem {};
4900 keyItem.SetKeyCode(KeyEvent::KEYCODE_ALT_LEFT);
4901 keyItem.SetPressed(true);
4902 keyItem.SetDownTime(GetSysClockTime() - MS2US(DEFAULT_SAMPLING_PERIOD));
4903 keyEvent->AddKeyItem(keyItem);
4904 keyItem.SetKeyCode(KeyEvent::KEYCODE_L);
4905
4906 while (nTriggers-- > 0) {
4907 auto now = GetSysClockTime();
4908 keyItem.SetPressed(true);
4909 keyItem.SetDownTime(now);
4910 keyEvent->AddKeyItem(keyItem);
4911 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
4912 keyEvent->SetActionTime(now);
4913 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
4914 std::this_thread::sleep_for(std::chrono::milliseconds(DEFAULT_SAMPLING_PERIOD));
4915
4916 keyItem.SetPressed(false);
4917 keyEvent->RemoveReleasedKeyItems(keyItem);
4918
4919 now = GetSysClockTime();
4920 keyEvent->AddKeyItem(keyItem);
4921 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
4922 keyEvent->SetActionTime(now);
4923 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
4924 keyEvent->RemoveReleasedKeyItems(keyItem);
4925 std::this_thread::sleep_for(std::chrono::milliseconds(DEFAULT_SAMPLING_PERIOD));
4926 }
4927 }
4928
4929 /**
4930 * @tc.name: InputManagerTest_SubscribeHotkey_002
4931 * @tc.desc: Verify subscription and unsubscription of hot key.
4932 * @tc.type: FUNC
4933 * @tc.require:
4934 * @tc.author:
4935 */
4936 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeHotkey_002, TestSize.Level1)
4937 {
4938 CALL_TEST_DEBUG;
4939 size_t nCalls { 0 };
4940 std::set<int32_t> preKeys { KeyEvent::KEYCODE_ALT_LEFT };
4941 std::shared_ptr<KeyOption> keyOption = InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_L, true, 0);
4942 auto subscribeId = InputManager::GetInstance()->SubscribeHotkey(keyOption,
__anonaec9e8f54b02(std::shared_ptr<KeyEvent> keyEvent) 4943 [&nCalls](std::shared_ptr<KeyEvent> keyEvent) {
4944 if ((keyEvent->GetKeyCode() == KeyEvent::KEYCODE_L) &&
4945 (keyEvent->GetKeyAction() == KeyEvent::KEY_ACTION_DOWN)) {
4946 auto pressedKeys = keyEvent->GetPressedKeys();
4947 if (std::any_of(pressedKeys.cbegin(), pressedKeys.cend(),
4948 [](const auto keyCode) {
4949 return (keyCode == KeyEvent::KEYCODE_ALT_LEFT);
4950 })) {
4951 ++nCalls;
4952 }
4953 }
4954 });
4955 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
4956 ASSERT_TRUE(subscribeId >= 0);
4957 size_t nTriggers { 30 };
4958 InjectAltL(nTriggers);
4959 InputManager::GetInstance()->UnsubscribeHotkey(subscribeId);
4960 EXPECT_EQ(nTriggers, nCalls);
4961 InjectAltL(nTriggers);
4962 EXPECT_EQ(nTriggers, nCalls);
4963 #else
4964 ASSERT_TRUE(subscribeId < 0);
4965 #endif // OHOS_BUILD_ENABLE_KEYBOARD
4966 }
4967
4968 /*
4969 * @tc.name: InputManagerTest_SetTouchpadScrollRows_001
4970 * @tc.desc: Test the funcation SetTouchpadScrollRows
4971 * @tc.type: FUNC
4972 * @tc.require:
4973 */
4974 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadScrollRows_001, TestSize.Level1)
4975 {
4976 CALL_TEST_DEBUG;
4977 int32_t rows = 1;
4978 int32_t ret = InputManager::GetInstance()->SetTouchpadScrollRows(rows);
4979 ASSERT_EQ(ret, RET_OK);
4980 }
4981
4982 /*
4983 * @tc.name: InputManagerTest_GetTouchpadScrollRows_001
4984 * @tc.desc: Test the funcation GetTouchpadScrollRows
4985 * @tc.type: FUNC
4986 * @tc.require:
4987 */
4988 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadScrollRows_001, TestSize.Level1)
4989 {
4990 CALL_TEST_DEBUG;
4991 int32_t rows = 2;
4992 int32_t ret = InputManager::GetInstance()->GetTouchpadScrollRows(rows);
4993 ASSERT_EQ(ret, RET_OK);
4994 }
4995
4996 /**
4997 * @tc.name: InputManagerTest_SetInputDeviceEnable_001
4998 * @tc.desc: Set input device enable
4999 * @tc.type: FUNC
5000 * @tc.require:
5001 */
5002 HWTEST_F(InputManagerTest, InputManagerTest_SetInputDeviceEnable_001, TestSize.Level1)
5003 {
5004 CALL_TEST_DEBUG;
5005 std::vector<int32_t> aucids;
__anonaec9e8f54d02(std::vector<int32_t> ids) 5006 auto callback = [&aucids](std::vector<int32_t> ids) { aucids = std::move(ids); };
5007 InputManager::GetInstance()->GetDeviceIds(callback);
5008 for (const auto &iter : aucids) {
5009 MMI_HILOGI("Set inputdevice %{public}d disable", iter);
__anonaec9e8f54e02(int32_t result) 5010 auto cb = [](int32_t result) {
5011 MMI_HILOGI("Set input device result:%{public}d ", result);
5012 ASSERT_EQ(result, RET_OK);
5013 };
5014 InputManager::GetInstance()->SetInputDeviceEnabled(iter, false, cb);
5015 }
5016 }
5017
5018 /**
5019 * @tc.name: InputManagerTest_SetInputDeviceEnable_002
5020 * @tc.desc: Set input device enable
5021 * @tc.type: FUNC
5022 * @tc.require:
5023 */
5024 HWTEST_F(InputManagerTest, InputManagerTest_SetInputDeviceEnable_002, TestSize.Level1)
5025 {
5026 CALL_TEST_DEBUG;
5027 std::vector<int32_t> aucids;
__anonaec9e8f54f02(std::vector<int32_t> ids) 5028 auto callback = [&aucids](std::vector<int32_t> ids) { aucids = std::move(ids); };
5029 InputManager::GetInstance()->GetDeviceIds(callback);
5030 for (const auto &iter : aucids) {
5031 MMI_HILOGI("Set inputdevice %{public}d enable", iter);
__anonaec9e8f55002(int32_t result) 5032 auto cb = [](int32_t result) {
5033 MMI_HILOGI("Set input device result:%{public}d ", result);
5034 ASSERT_EQ(result, RET_OK);
5035 };
5036 InputManager::GetInstance()->SetInputDeviceEnabled(iter, true, cb);
5037 }
5038 }
5039
5040 /**
5041 * @tc.name: InputManagerTest_SetInputDeviceEnable_003
5042 * @tc.desc: Set input device enable
5043 * @tc.type: FUNC
5044 * @tc.require:
5045 */
5046 HWTEST_F(InputManagerTest, InputManagerTest_SetInputDeviceEnable_003, TestSize.Level1)
5047 {
5048 CALL_TEST_DEBUG;
__anonaec9e8f55102(int32_t result) 5049 auto cb = [](int32_t result) {
5050 MMI_HILOGI("Set input device result:%{public}d ", result);
5051 ASSERT_EQ(result, ERROR_DEVICE_NOT_EXIST);
5052 };
5053 InputManager::GetInstance()->SetInputDeviceEnabled(10000, true, cb);
5054 }
5055
5056 /*
5057 * @tc.name: InputManagerTest_ShiftAppPointerEvent_001
5058 * @tc.desc: Test the funcation ShiftAppPointerEvent
5059 * @tc.type: FUNC
5060 * @tc.require:
5061 */
5062 HWTEST_F(InputManagerTest, InputManagerTest_ShiftAppPointerEvent_001, TestSize.Level1)
5063 {
5064 CALL_TEST_DEBUG;
5065 int32_t sourceWindowId = 99;
5066 int32_t targetWindowId = 99;
5067 ShiftWindowParam param;
5068 param.sourceWindowId = sourceWindowId;
5069 param.targetWindowId = targetWindowId;
5070 bool autoGenDown = true;
5071 int32_t ret = InputManager::GetInstance()->ShiftAppPointerEvent(param, autoGenDown);
5072 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
5073 ASSERT_EQ(ret, ARGV_VALID);
5074 #else
5075 ASSERT_EQ(ret, ERROR_UNSUPPORT);
5076 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
5077 }
5078
5079 /*
5080 * @tc.name: InputManagerTest_ShiftAppPointerEvent_002
5081 * @tc.desc: Test the funcation ShiftAppPointerEvent
5082 * @tc.type: FUNC
5083 * @tc.require:
5084 */
5085 HWTEST_F(InputManagerTest, InputManagerTest_ShiftAppPointerEvent_002, TestSize.Level1)
5086 {
5087 CALL_TEST_DEBUG;
5088 int32_t sourceWindowId = -150;
5089 int32_t targetWindowId = -99;
5090 ShiftWindowParam param;
5091 param.sourceWindowId = sourceWindowId;
5092 param.targetWindowId = targetWindowId;
5093 bool autoGenDown = true;
5094 int32_t ret = InputManager::GetInstance()->ShiftAppPointerEvent(param, autoGenDown);
5095 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
5096 ASSERT_EQ(ret, RET_ERR);
5097 #else
5098 ASSERT_EQ(ret, ERROR_UNSUPPORT);
5099 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
5100 }
5101
5102 /**
5103 * @tc.name: InputManagerTest_SetCustomCursorEx_001
5104 * @tc.desc: Test SetCustomCursorEx_001
5105 * @tc.type: FUNC
5106 * @tc.require:
5107 */
5108 HWTEST_F(InputManagerTest, InputManagerTest_SetCustomCursorEx_001, TestSize.Level1)
5109 {
5110 CALL_TEST_DEBUG;
5111 int32_t fakeWindowId = 100;
5112 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
5113 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
5114 ASSERT_NE(pixelMap, nullptr);
5115 CustomCursor cursor;
5116 cursor.pixelMap = (void *)pixelMap.get();
5117 cursor.focusX = 32;
5118 cursor.focusY = 32;
5119 CursorOptions options;
5120 options.followSystem = true;
5121 ASSERT_TRUE(InputManager::GetInstance()->SetCustomCursor(fakeWindowId, cursor, options) != RET_ERR);
5122 pixelMap = nullptr;
5123 }
5124
5125 /**
5126 * @tc.name: InputManagerTest_SetCustomCursorEx_002
5127 * @tc.desc: Test SetCustomCursorEx_002
5128 * @tc.type: FUNC
5129 * @tc.require:
5130 */
5131 HWTEST_F(InputManagerTest, InputManagerTest_SetCustomCursorEx_002, TestSize.Level1)
5132 {
5133 CALL_TEST_DEBUG;
5134 int32_t fakeWindowId = 100;
5135 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
5136 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
5137 ASSERT_NE(pixelMap, nullptr);
5138 CustomCursor cursor;
5139 cursor.pixelMap = (void *)pixelMap.get();
5140 cursor.focusX = 32;
5141 cursor.focusY = 32;
5142 CursorOptions options;
5143 options.followSystem = false;
5144 ASSERT_TRUE(InputManager::GetInstance()->SetCustomCursor(fakeWindowId, cursor, options) != RET_ERR);
5145 pixelMap = nullptr;
5146 }
5147
5148 /**
5149 * @tc.name: InputManagerTest_SetCustomCursorEx_003
5150 * @tc.desc: Test SetCustomCursorEx_003
5151 * @tc.type: FUNC
5152 * @tc.require:
5153 */
5154 HWTEST_F(InputManagerTest, InputManagerTest_SetCustomCursorEx_003, TestSize.Level1)
5155 {
5156 CALL_TEST_DEBUG;
5157 int32_t fakeWindowId = 100;
5158 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
5159 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
5160 ASSERT_NE(pixelMap, nullptr);
5161 CustomCursor cursor;
5162 cursor.pixelMap = (void *)pixelMap.get();
5163 cursor.focusX = 512;
5164 cursor.focusY = 512;
5165 CursorOptions options;
5166 options.followSystem = false;
5167 ASSERT_TRUE(InputManager::GetInstance()->SetCustomCursor(fakeWindowId, cursor, options) != RET_ERR);
5168 pixelMap = nullptr;
5169 }
5170
5171 /**
5172 * @tc.name: InputManagerTest_SetCustomCursorEx_004
5173 * @tc.desc: Test SetCustomCursorEx_004
5174 * @tc.type: FUNC
5175 * @tc.require:
5176 */
5177 HWTEST_F(InputManagerTest, InputManagerTest_SetCustomCursorEx_004, TestSize.Level1)
5178 {
5179 CALL_TEST_DEBUG;
5180 int32_t fakeWindowId = 100;
5181 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
5182 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
5183 ASSERT_NE(pixelMap, nullptr);
5184 Media::ImageInfo imageInfo;
5185 imageInfo.size.width = 280;
5186 imageInfo.size.height = 280;
5187 pixelMap->SetImageInfo(imageInfo);
5188 CustomCursor cursor;
5189 cursor.pixelMap = (void *)pixelMap.get();
5190 cursor.focusX = 32;
5191 cursor.focusY = 32;
5192 CursorOptions options;
5193 options.followSystem = false;
5194 ASSERT_TRUE(InputManager::GetInstance()->SetCustomCursor(fakeWindowId, cursor, options) != RET_ERR);
5195 pixelMap = nullptr;
5196 }
5197
CreatePointerEventTest()5198 std::shared_ptr<PointerEvent> CreatePointerEventTest()
5199 {
5200 auto pointerEvent = PointerEvent::Create();
5201 CHKPP(pointerEvent);
5202 pointerEvent->SetPointerId(1);
5203 PointerEvent::PointerItem item;
5204 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_TWO);
5205 item.SetPressed(true);
5206 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_ONE);
5207 item.SetWindowX(POINTER_ITEM_WINDOW_X);
5208 item.SetPointerId(1);
5209 item.SetWindowY(POINTER_ITEM_WINDOW_Y);
5210 item.SetDeviceId(0);
5211 item.SetWidth(ITEM_WIDTH);
5212 item.SetHeight(ITEM_HEIGHT);
5213 item.SetPressure(POINTER_ITEM_PRESSURE);
5214 pointerEvent->AddPointerItem(item);
5215 return pointerEvent;
5216 }
5217
5218 /*
5219 * @tc.name: InputManagerTest_TransformMouseEventToTouchEvent_001
5220 * @tc.desc: Test the funcation PointerEventMouseToTouch, convert mouse events to touch events
5221 * @tc.type: FUNC
5222 * @tc.require:
5223 */
5224 HWTEST_F(InputManagerTest, InputManagerTest_TransformMouseEventToTouchEvent_001, TestSize.Level1)
5225 {
5226 CALL_TEST_DEBUG;
5227 auto pointerEvent = CreatePointerEventTest();
5228 bool ret = false;
5229 int32_t pointerId = pointerEvent->GetPointerId();
5230 PointerEvent::PointerItem pointerItem;
5231 ret = pointerEvent->GetPointerItem(pointerId, pointerItem);
5232 ASSERT_EQ(ret, true);
5233 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
5234 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN);
5235 ret = MMI::InputManager::GetInstance()->TransformMouseEventToTouchEvent(pointerEvent);
5236 ASSERT_EQ(ret, true);
5237 }
5238
5239 /*
5240 * @tc.name: InputManagerTest_TransformMouseEventToTouchEvent_002
5241 * @tc.desc: Test the funcation PointerEventMouseToTouch, convert mouse events to touch events
5242 * @tc.type: FUNC
5243 * @tc.require:
5244 */
5245 HWTEST_F(InputManagerTest, InputManagerTest_TransformMouseEventToTouchEvent_002, TestSize.Level1)
5246 {
5247 CALL_TEST_DEBUG;
5248 auto pointerEvent = CreatePointerEventTest();
5249 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
5250 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN);
5251 bool ret = false;
5252 int32_t pointerId = pointerEvent->GetPointerId();
5253 PointerEvent::PointerItem pointerItem;
5254 ret = pointerEvent->GetPointerItem(pointerId, pointerItem);
5255 ASSERT_EQ(ret, true);
5256 pointerItem.SetToolType(PointerEvent::TOOL_TYPE_FINGER);
5257 ret = MMI::InputManager::GetInstance()->TransformMouseEventToTouchEvent(pointerEvent);
5258 ASSERT_EQ(ret, true);
5259 }
5260
5261 /*
5262 * @tc.name: InputManagerTest_TransformMouseEventToTouchEvent_003
5263 * @tc.desc: Test the funcation PointerEventMouseToTouch, convert mouse events to touch events
5264 * @tc.type: FUNC
5265 * @tc.require:
5266 */
5267 HWTEST_F(InputManagerTest, InputManagerTest_TransformMouseEventToTouchEvent_003, TestSize.Level1)
5268 {
5269 CALL_TEST_DEBUG;
5270 auto pointerEvent = CreatePointerEventTest();
5271 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
5272 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN);
5273 bool ret = false;
5274 int32_t pointerId = pointerEvent->GetPointerId();
5275 PointerEvent::PointerItem pointerItem;
5276 ret = pointerEvent->GetPointerItem(pointerId, pointerItem);
5277 ASSERT_EQ(ret, true);
5278 pointerItem.SetToolType(PointerEvent::TOOL_TYPE_FINGER);
5279 ret = MMI::InputManager::GetInstance()->TransformMouseEventToTouchEvent(pointerEvent);
5280 ASSERT_EQ(ret, true);
5281 }
5282
5283 /*
5284 * @tc.name: InputManagerTest_TransformMouseEventToTouchEvent_004
5285 * @tc.desc: Test the funcation PointerEventMouseToTouch, convert mouse events to touch events
5286 * @tc.type: FUNC
5287 * @tc.require:
5288 */
5289 HWTEST_F(InputManagerTest, InputManagerTest_TransformMouseEventToTouchEvent_004, TestSize.Level1)
5290 {
5291 CALL_TEST_DEBUG;
5292 auto pointerEvent = PointerEvent::Create();
5293 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
5294 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN);
5295 pointerEvent->SetPointerId(1);
5296 bool ret = false;
5297 int32_t pointerId = pointerEvent->GetPointerId();
5298 PointerEvent::PointerItem pointerItem;
5299 ret = pointerEvent->GetPointerItem(pointerId, pointerItem);
5300 ASSERT_EQ(ret, false);
5301 }
5302
5303 /*
5304 * @tc.name: InputManagerTest_TransformTouchEventToMouseEvent_001
5305 * @tc.desc: Test the funcation PointerEventTouchToMouse, convert touch events to mouse events
5306 * @tc.type: FUNC
5307 * @tc.require:
5308 */
5309 HWTEST_F(InputManagerTest, InputManagerTest_TransformTouchEventToMouseEvent_001, TestSize.Level1)
5310 {
5311 CALL_TEST_DEBUG;
5312 auto pointerEvent = CreatePointerEventTest();
5313 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
5314 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
5315 bool ret = false;
5316 int32_t pointerId = pointerEvent->GetPointerId();
5317 PointerEvent::PointerItem pointerItem;
5318 ret = pointerEvent->GetPointerItem(pointerId, pointerItem);
5319 ASSERT_EQ(ret, true);
5320 ret = MMI::InputManager::GetInstance()->TransformTouchEventToMouseEvent(pointerEvent);
5321 ASSERT_EQ(ret, true);
5322 }
5323
5324 /*
5325 * @tc.name: InputManagerTest_TransformTouchEventToMouseEvent_002
5326 * @tc.desc: Test the funcation PointerEventTouchToMouse, convert touch events to mouse events
5327 * @tc.type: FUNC
5328 * @tc.require:
5329 */
5330 HWTEST_F(InputManagerTest, InputManagerTest_TransformTouchEventToMouseEvent_002, TestSize.Level1)
5331 {
5332 CALL_TEST_DEBUG;
5333 auto pointerEvent = CreatePointerEventTest();
5334 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
5335 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
5336 bool ret = false;
5337 int32_t pointerId = pointerEvent->GetPointerId();
5338 PointerEvent::PointerItem pointerItem;
5339 ret = pointerEvent->GetPointerItem(pointerId, pointerItem);
5340 ASSERT_EQ(ret, true);
5341 pointerItem.SetToolType(PointerEvent::TOOL_TYPE_MOUSE);
5342 ret = MMI::InputManager::GetInstance()->TransformTouchEventToMouseEvent(pointerEvent);
5343 ASSERT_EQ(ret, true);
5344 }
5345
5346 /*
5347 * @tc.name: InputManagerTest_TransformTouchEventToMouseEvent_003
5348 * @tc.desc: Test the funcation PointerEventTouchToMouse, convert touch events to mouse events
5349 * @tc.type: FUNC
5350 * @tc.require:
5351 */
5352 HWTEST_F(InputManagerTest, InputManagerTest_TransformTouchEventToMouseEvent_003, TestSize.Level1)
5353 {
5354 CALL_TEST_DEBUG;
5355 auto pointerEvent = CreatePointerEventTest();
5356 bool ret = false;
5357 int32_t pointerId = pointerEvent->GetPointerId();
5358 PointerEvent::PointerItem pointerItem;
5359 ret = pointerEvent->GetPointerItem(pointerId, pointerItem);
5360 ASSERT_EQ(ret, true);
5361 pointerItem.SetToolType(PointerEvent::TOOL_TYPE_FINGER);
5362 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
5363 ret = MMI::InputManager::GetInstance()->TransformTouchEventToMouseEvent(pointerEvent);
5364 ASSERT_EQ(ret, true);
5365 }
5366
5367 /*
5368 * @tc.name: InputManagerTest_TransformTouchEventToMouseEvent_004
5369 * @tc.desc: Test the funcation PointerEventTouchToMouse, convert touch events to mouse events
5370 * @tc.type: FUNC
5371 * @tc.require:
5372 */
5373 HWTEST_F(InputManagerTest, InputManagerTest_TransformTouchEventToMouseEvent_004, TestSize.Level1)
5374 {
5375 CALL_TEST_DEBUG;
5376 auto pointerEvent = PointerEvent::Create();
5377 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
5378 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
5379 pointerEvent->SetPointerId(1);
5380 bool ret = false;
5381 int32_t pointerId = pointerEvent->GetPointerId();
5382 PointerEvent::PointerItem pointerItem;
5383 ret = pointerEvent->GetPointerItem(pointerId, pointerItem);
5384 ASSERT_EQ(ret, false);
5385 }
5386
5387 /*
5388 * @tc.name: InputManagerTest_SubscribeKeyEvent_016
5389 * @tc.desc: Verify subscribe KEYCODE_HOME key up event.
5390 * @tc.type: FUNC
5391 * @tc.require:
5392 */
5393 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_016, TestSize.Level1)
5394 {
5395 CALL_TEST_DEBUG;
5396 std::set<int32_t> preKeys;
5397 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
5398 keyOption->SetPreKeys(preKeys);
5399 keyOption->SetFinalKey(KeyEvent::KEYCODE_HOME);
5400 keyOption->SetFinalKeyDown(false);
5401 keyOption->SetFinalKeyDownDuration(0);
5402 int32_t subscribeId = INVAID_VALUE;
__anonaec9e8f55202(std::shared_ptr<KeyEvent> keyEvent) 5403 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
5404 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
5405 MMI_HILOGD("Subscribe key event KEYCODE_HOME up trigger callback");
5406 });
5407 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5408 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
5409 EXPECT_TRUE(subscribeId >= 0);
5410 #else
5411 EXPECT_TRUE(subscribeId < 0);
5412 #endif // OHOS_BUILD_ENABLE_KEYBOARD
5413 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
5414 ASSERT_TRUE(injectDownEvent != nullptr);
5415 KeyEvent::KeyItem kitDown;
5416 kitDown.SetKeyCode(KeyEvent::KEYCODE_HOME);
5417 kitDown.SetPressed(false);
5418 kitDown.SetDownTime(0);
5419 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_HOME);
5420 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
5421 injectDownEvent->AddPressedKeyItems(kitDown);
5422 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
5423 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_UP);
5424
5425 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5426 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
5427 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5428 }
5429
5430 /*
5431 * @tc.name: InputManagerTest_SubscribeKeyEvent_017
5432 * @tc.desc: Verify subscribe KEYCODE_HOME key down event.
5433 * @tc.type: FUNC
5434 * @tc.require:
5435 */
5436 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_017, TestSize.Level1)
5437 {
5438 CALL_TEST_DEBUG;
5439 std::set<int32_t> preKeys;
5440 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
5441 keyOption->SetPreKeys(preKeys);
5442 keyOption->SetFinalKey(KeyEvent::KEYCODE_HOME);
5443 keyOption->SetFinalKeyDown(true);
5444 keyOption->SetFinalKeyDownDuration(0);
5445 int32_t subscribeId = INVAID_VALUE;
__anonaec9e8f55302(std::shared_ptr<KeyEvent> keyEvent) 5446 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
5447 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
5448 MMI_HILOGD("Subscribe key event KEYCODE_HOME down trigger callback");
5449 });
5450 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5451 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
5452 EXPECT_TRUE(subscribeId >= 0);
5453 #else
5454 EXPECT_TRUE(subscribeId < 0);
5455 #endif // OHOS_BUILD_ENABLE_KEYBOARD
5456 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
5457 ASSERT_TRUE(injectDownEvent != nullptr);
5458 KeyEvent::KeyItem kitDown;
5459 kitDown.SetKeyCode(KeyEvent::KEYCODE_HOME);
5460 kitDown.SetPressed(true);
5461 kitDown.SetDownTime(0);
5462 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_HOME);
5463 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
5464 injectDownEvent->AddPressedKeyItems(kitDown);
5465 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
5466 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
5467
5468 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5469 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
5470 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5471 }
5472
5473 /*
5474 * @tc.name: InputManagerTest_SubscribeKeyEvent_018
5475 * @tc.desc: Verify subscribe KEYCODE_MENU key up event.
5476 * @tc.type: FUNC
5477 * @tc.require:
5478 */
5479 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_018, TestSize.Level1)
5480 {
5481 CALL_TEST_DEBUG;
5482 std::set<int32_t> preKeys;
5483 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
5484 keyOption->SetPreKeys(preKeys);
5485 keyOption->SetFinalKey(KeyEvent::KEYCODE_MENU);
5486 keyOption->SetFinalKeyDown(false);
5487 keyOption->SetFinalKeyDownDuration(0);
5488 int32_t subscribeId = INVAID_VALUE;
__anonaec9e8f55402(std::shared_ptr<KeyEvent> keyEvent) 5489 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
5490 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
5491 MMI_HILOGD("Subscribe key event KEYCODE_MENU up trigger callback");
5492 });
5493 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5494 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
5495 EXPECT_TRUE(subscribeId >= 0);
5496 #else
5497 EXPECT_TRUE(subscribeId < 0);
5498 #endif // OHOS_BUILD_ENABLE_KEYBOARD
5499 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
5500 ASSERT_TRUE(injectDownEvent != nullptr);
5501 KeyEvent::KeyItem kitDown;
5502 kitDown.SetKeyCode(KeyEvent::KEYCODE_MENU);
5503 kitDown.SetPressed(false);
5504 kitDown.SetDownTime(0);
5505 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_MENU);
5506 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
5507 injectDownEvent->AddPressedKeyItems(kitDown);
5508 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
5509 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_UP);
5510
5511 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5512 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
5513 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5514 }
5515
5516 /*
5517 * @tc.name: InputManagerTest_SubscribeKeyEvent_019
5518 * @tc.desc: Verify subscribe KEYCODE_MENU key down event.
5519 * @tc.type: FUNC
5520 * @tc.require:
5521 */
5522 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_019, TestSize.Level1)
5523 {
5524 CALL_TEST_DEBUG;
5525 std::set<int32_t> preKeys;
5526 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
5527 keyOption->SetPreKeys(preKeys);
5528 keyOption->SetFinalKey(KeyEvent::KEYCODE_MENU);
5529 keyOption->SetFinalKeyDown(true);
5530 keyOption->SetFinalKeyDownDuration(0);
5531 int32_t subscribeId = INVAID_VALUE;
__anonaec9e8f55502(std::shared_ptr<KeyEvent> keyEvent) 5532 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
5533 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
5534 MMI_HILOGD("Subscribe key event KEYCODE_MENU down trigger callback");
5535 });
5536 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5537 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
5538 EXPECT_TRUE(subscribeId >= 0);
5539 #else
5540 EXPECT_TRUE(subscribeId < 0);
5541 #endif // OHOS_BUILD_ENABLE_KEYBOARD
5542 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
5543 ASSERT_TRUE(injectDownEvent != nullptr);
5544 KeyEvent::KeyItem kitDown;
5545 kitDown.SetKeyCode(KeyEvent::KEYCODE_MENU);
5546 kitDown.SetPressed(true);
5547 kitDown.SetDownTime(0);
5548 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_MENU);
5549 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
5550 injectDownEvent->AddPressedKeyItems(kitDown);
5551 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
5552 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
5553
5554 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5555 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
5556 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5557 }
5558
5559 /*
5560 * @tc.name: InputManagerTest_SubscribeKeyEvent_022
5561 * @tc.desc: Verify subscribe KEYCODE_HEADSETHOOK and high priority and uid is not within the range event.
5562 * @tc.type: FUNC
5563 * @tc.require:
5564 */
5565 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_022, TestSize.Level1)
5566 {
5567 CALL_TEST_DEBUG;
5568 std::set<int32_t> preKeys;
5569 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
5570 keyOption->SetPreKeys(preKeys);
5571 keyOption->SetFinalKey(KeyEvent::KEYCODE_HEADSETHOOK);
5572 keyOption->SetFinalKeyDown(true);
5573 keyOption->SetFinalKeyDownDuration(0);
5574 keyOption->SetPriority(SubscribePriority::PRIORITY_100);
5575 int32_t subscribeId = INVAID_VALUE;
__anonaec9e8f55602(std::shared_ptr<KeyEvent> keyEvent) 5576 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
5577 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
5578 MMI_HILOGD("Subscribe key event KEYCODE_HOME down trigger callback");
5579 });
5580 EXPECT_FALSE(subscribeId < 0);
5581 }
5582
5583 /*
5584 * @tc.name: InputManagerTest_SubscribeKeyEvent_023
5585 * @tc.desc: Verify subscribe KEYCODE_HOME and high priority event.
5586 * @tc.type: FUNC
5587 * @tc.require:
5588 */
5589 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_023, TestSize.Level1)
5590 {
5591 CALL_TEST_DEBUG;
5592 std::set<int32_t> preKeys;
5593 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
5594 keyOption->SetPreKeys(preKeys);
5595 keyOption->SetFinalKey(KeyEvent::KEYCODE_HOME);
5596 keyOption->SetFinalKeyDown(true);
5597 keyOption->SetFinalKeyDownDuration(0);
5598 keyOption->SetPriority(SubscribePriority::PRIORITY_100);
5599 int32_t subscribeId = INVAID_VALUE;
__anonaec9e8f55702(std::shared_ptr<KeyEvent> keyEvent) 5600 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
5601 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
5602 MMI_HILOGD("Subscribe key event KEYCODE_HOME down trigger callback");
5603 });
5604 EXPECT_TRUE(subscribeId < 0);
5605 }
5606
5607 /*
5608 * @tc.name: InputManagerTest_SubscribeKeyEvent_024
5609 * @tc.desc: Verify subscribe KEYCODE_HEADSETHOOK and low priority event.
5610 * @tc.type: FUNC
5611 * @tc.require:
5612 */
5613 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_024, TestSize.Level1)
5614 {
5615 CALL_TEST_DEBUG;
5616 std::set<int32_t> preKeys;
5617 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
5618 keyOption->SetPreKeys(preKeys);
5619 keyOption->SetFinalKey(KeyEvent::KEYCODE_HEADSETHOOK);
5620 keyOption->SetFinalKeyDown(true);
5621 keyOption->SetFinalKeyDownDuration(0);
5622 keyOption->SetPriority(SubscribePriority::PRIORITY_0);
5623 int32_t subscribeId = INVAID_VALUE;
__anonaec9e8f55802(std::shared_ptr<KeyEvent> keyEvent) 5624 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
5625 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
5626 MMI_HILOGD("Subscribe key event KEYCODE_HOME down trigger callback");
5627 });
5628 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
5629 EXPECT_TRUE(subscribeId >= 0);
5630 #else
5631 EXPECT_TRUE(subscribeId < 0);
5632 #endif // OHOS_BUILD_ENABLE_KEYBOARD
5633 }
5634
5635 /*
5636 * @tc.name: InputManagerTest_SetMouseAccelerateMotionSwitch
5637 * @tc.desc: SetMouseAccelerateMotionSwitch
5638 * @tc.type: FUNC
5639 * @tc.require:
5640 */
5641 HWTEST_F(InputManagerTest, InputManagerTest_SetMouseAccelerateMotionSwitch, TestSize.Level1)
5642 {
5643 CALL_TEST_DEBUG;
5644 int32_t deviceId = 0;
5645 std::shared_ptr<InputManager> inputManager = std::make_shared<InputManager>();
5646 ASSERT_NO_FATAL_FAILURE(inputManager->SetMouseAccelerateMotionSwitch(deviceId, true));
5647 }
5648
5649 /*
5650 * @tc.name: InputManagerTest_ClearMouseHideFlag
5651 * @tc.desc: ClearMouseHideFlag
5652 * @tc.type: FUNC
5653 * @tc.require:
5654 */
5655 HWTEST_F(InputManagerTest, InputManagerTest_ClearMouseHideFlag, TestSize.Level1)
5656 {
5657 CALL_TEST_DEBUG;
5658 int32_t eventId = SYNERGY_UID;
5659 std::shared_ptr<InputManager> inputManager = std::make_shared<InputManager>();
5660 ASSERT_NO_FATAL_FAILURE(inputManager->ClearMouseHideFlag(eventId));
5661 }
5662
5663 /*
5664 * @tc.name: InputManagerTest_SwitchScreenCapturePermission
5665 * @tc.desc: SwitchScreenCapturePermission DEFAULT_PERMISSIONS
5666 * @tc.type: FUNC
5667 * @tc.require:
5668 */
5669 HWTEST_F(InputManagerTest, SwitchScreenCapturePermission, TestSize.Level1)
5670 {
5671 CALL_TEST_DEBUG;
5672 std::uint32_t permissions = DEFAULT_PERMISSIONS;
5673 bool enable = true;
5674 EXPECT_NE(InputManager::GetInstance()->SwitchScreenCapturePermission(permissions, enable), RET_OK);
5675
5676 auto uid = getuid();
5677 int32_t panglaiUid = 7655;
5678 setuid(panglaiUid);
5679 EXPECT_EQ(InputManager::GetInstance()->SwitchScreenCapturePermission(permissions, enable), RET_OK);
5680 setuid(uid);
5681 }
5682
5683 /*
5684 * @tc.name: InputManagerTest_AddPreMonitor_001
5685 * @tc.desc: AddPreMonitor.
5686 * @tc.type: FUNC
5687 * @tc.require:
5688 */
5689 HWTEST_F(InputManagerTest, InputManagerTest_AddPreMonitor_001, TestSize.Level1)
5690 {
5691 CALL_TEST_DEBUG;
5692 std::vector<int32_t> keys;
5693 keys.push_back(3);
5694 uint32_t handleEventType = 0;
5695 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->AddPreMonitor(nullptr, handleEventType, keys));
5696 }
5697
5698 /*
5699 * @tc.name: InputManagerTest_RemovePreMonitor_001
5700 * @tc.desc: RemovePreMonitor.
5701 * @tc.type: FUNC
5702 * @tc.require:
5703 */
5704 HWTEST_F(InputManagerTest, InputManagerTest_RemovePreMonitor_001, TestSize.Level1)
5705 {
5706 CALL_TEST_DEBUG;
5707 int32_t monitorId = 0;
5708 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->RemovePreMonitor(monitorId));
5709 }
5710
5711 /*
5712 * @tc.name: InputManagerTest_SetMultiWindowScreenId_001
5713 * @tc.desc: SetMultiWindowScreenId.
5714 * @tc.type: FUNC
5715 * @tc.require:
5716 */
5717 HWTEST_F(InputManagerTest, InputManagerTest_SetMultiWindowScreenId_001, TestSize.Level1)
5718 {
5719 CALL_TEST_DEBUG;
5720 uint64_t screenId = 1;
5721 uint64_t displayNodeScreenId = 2;
5722 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->SetMultiWindowScreenId(screenId, displayNodeScreenId));
5723 }
5724
5725 /**
5726 * @tc.name: InputManagerTest_SimulateEvent_009
5727 * @tc.desc: Injection interface detection test KeyCommandHandler::MenuClickHandle
5728 * @tc.type: FUNC
5729 * @tc.require:
5730 */
5731 HWTEST_F(InputManagerTest, InputManagerTest_SimulateEvent_009, TestSize.Level1)
5732 {
5733 CALL_TEST_DEBUG;
5734 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
5735 ASSERT_TRUE(injectDownEvent != nullptr);
5736 KeyEvent::KeyItem kitDown;
5737 kitDown.SetKeyCode(KeyEvent::KEYCODE_MENU);
5738 kitDown.SetPressed(true);
5739 kitDown.SetDownTime(0);
5740 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_MENU);
5741 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
5742 injectDownEvent->AddPressedKeyItems(kitDown);
5743 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
5744 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
5745
5746 kitDown.SetKeyCode(KeyEvent::KEYCODE_MENU);
5747 kitDown.SetPressed(false);
5748 kitDown.SetDownTime(0);
5749 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_MENU);
5750 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
5751 injectDownEvent->AddPressedKeyItems(kitDown);
5752 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
5753 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_UP);
5754 }
5755
5756 /**
5757 * @tc.name: InputManagerTest_SimulateEvent_010
5758 * @tc.desc: Injection interface detection test KeyCommandHandler::MenuClickHandle
5759 * @tc.type: FUNC
5760 * @tc.require:
5761 */
5762 HWTEST_F(InputManagerTest, InputManagerTest_SimulateEvent_010, TestSize.Level1)
5763 {
5764 CALL_TEST_DEBUG;
5765 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
5766 ASSERT_TRUE(injectDownEvent != nullptr);
5767 KeyEvent::KeyItem kitDown;
5768 kitDown.SetKeyCode(KeyEvent::KEYCODE_MENU);
5769 kitDown.SetPressed(true);
5770 kitDown.SetDownTime(0);
5771 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_MENU);
5772 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
5773 injectDownEvent->AddPressedKeyItems(kitDown);
5774 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
5775 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
5776
5777 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5778
5779 kitDown.SetKeyCode(KeyEvent::KEYCODE_MENU);
5780 kitDown.SetPressed(false);
5781 kitDown.SetDownTime(0);
5782 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_MENU);
5783 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
5784 injectDownEvent->AddPressedKeyItems(kitDown);
5785 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
5786 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_UP);
5787 }
5788
5789 /**
5790 * @tc.name: InputManagerTest_SimulateEvent_011
5791 * @tc.desc: Injection interface detection test KeyCommandHandler::MenuClickHandle
5792 * @tc.type: FUNC
5793 * @tc.require:
5794 */
5795 HWTEST_F(InputManagerTest, InputManagerTest_SimulateEvent_011, TestSize.Level1)
5796 {
5797 CALL_TEST_DEBUG;
5798 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
5799 ASSERT_TRUE(injectDownEvent != nullptr);
5800 KeyEvent::KeyItem kitDown;
5801 kitDown.SetKeyCode(KeyEvent::KEYCODE_HOME);
5802 kitDown.SetPressed(true);
5803 kitDown.SetDownTime(0);
5804 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_HOME);
5805 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
5806 injectDownEvent->AddPressedKeyItems(kitDown);
5807 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
5808 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
5809 }
5810
5811 /*
5812 * @tc.name: InputManagerTest_SubscribeKeyMonitor_001
5813 * @tc.desc: SubscribeKeyMonitor.
5814 * @tc.type: FUNC
5815 * @tc.require:
5816 */
5817 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyMonitor_001, TestSize.Level1)
5818 {
5819 CALL_TEST_DEBUG;
5820 KeyMonitorOption keyOption;
5821 std::function<void(std::shared_ptr<KeyEvent>)> callback;
5822 int32_t ret = InputManager::GetInstance()->SubscribeKeyMonitor(keyOption, callback);
5823 EXPECT_NE(ret, INVAID_VALUE);
5824 }
5825
5826 /*
5827 * @tc.name: InputManagerTest_UnsubscribeKeyMonitor_001
5828 * @tc.desc: UnsubscribeKeyMonitor.
5829 * @tc.type: FUNC
5830 * @tc.require:
5831 */
5832 HWTEST_F(InputManagerTest, InputManagerTest_UnsubscribeKeyMonitor_001, TestSize.Level1)
5833 {
5834 CALL_TEST_DEBUG;
5835 int32_t subscriberId = 1;
5836 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UnsubscribeKeyMonitor(subscriberId));
5837 }
5838
5839 #ifdef OHOS_BUILD_ENABLE_VKEYBOARD
5840 /*
5841 * @tc.name: InputManagerTest_CreateVKeyboardDevice_001
5842 * @tc.desc: CreateVKeyboardDevice.
5843 * @tc.type: FUNC
5844 * @tc.require:
5845 */
5846 HWTEST_F(InputManagerTest, InputManagerTest_CreateVKeyboardDevice_001, TestSize.Level1)
5847 {
5848 CALL_TEST_DEBUG;
5849 sptr<IRemoteObject> vkeyboardDevice;
5850 int32_t ret = InputManager::GetInstance()->CreateVKeyboardDevice(vkeyboardDevice);
5851 EXPECT_EQ(ret, INVALID_HANDLER_ID);
5852 }
5853 #endif // OHOS_BUILD_ENABLE_VKEYBOARD
5854
5855 /*
5856 * @tc.name: InputManagerTest_CheckKnuckleEvent_001
5857 * @tc.desc: CheckKnuckleEvent.
5858 * @tc.type: FUNC
5859 * @tc.require:
5860 */
5861 HWTEST_F(InputManagerTest, InputManagerTest_CheckKnuckleEvent_001, TestSize.Level1)
5862 {
5863 CALL_TEST_DEBUG;
5864 float pointX = 1.0;
5865 float pointY = 1.0;
5866 bool isKnuckleType = true;
5867 int32_t ret = InputManager::GetInstance()->CheckKnuckleEvent(pointX, pointY, isKnuckleType);
5868 EXPECT_EQ(ret, -2);
5869 }
5870
5871 /**
5872 * @tc.name: InputManagerTest_SubscribeTabletProximity_001
5873 * @tc.desc: Test SubscribeTabletProximity
5874 * @tc.type: FUNC
5875 * @tc.require:
5876 */
5877 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeTabletProximity_001, TestSize.Level1)
5878 {
5879 CALL_TEST_DEBUG;
5880 std::function<void(std::shared_ptr<PointerEvent>)> callback;
5881 std::shared_ptr<InputManager> inputManager = std::make_shared<InputManager>();
5882 EXPECT_EQ(inputManager->SubscribeTabletProximity(callback), RET_ERR);
5883 }
5884
5885 /**
5886 * @tc.name: InputManagerTest_UnsubscribetabletProximity_001
5887 * @tc.desc: Test UnsubscribetabletProximity
5888 * @tc.type: FUNC
5889 * @tc.require:
5890 */
5891 HWTEST_F(InputManagerTest, InputManagerTest_UnsubscribetabletProximity_001, TestSize.Level1)
5892 {
5893 CALL_TEST_DEBUG;
5894 int32_t subscriberId = INVAID_VALUE;
5895 std::shared_ptr<InputManager> inputManager = std::make_shared<InputManager>();
5896 ASSERT_NO_FATAL_FAILURE(inputManager->UnsubscribetabletProximity(subscriberId));
5897 }
5898
5899 /**
5900 * @tc.name: InputManagerTest_AddPreMonitor_002
5901 * @tc.desc: Test AddPreMonitor
5902 * @tc.type: FUNC
5903 * @tc.require:
5904 */
5905 HWTEST_F(InputManagerTest, InputManagerTest_AddPreMonitor_002, TestSize.Level1)
5906 {
5907 CALL_TEST_DEBUG;
5908 std::shared_ptr<IInputEventConsumer> monitor = nullptr;
5909 HandleEventType eventType = 0;
5910 std::vector<int32_t> keys;
5911 std::shared_ptr<InputManager> inputManager = std::make_shared<InputManager>();
5912 EXPECT_EQ(inputManager->AddPreMonitor(monitor, eventType, keys), INVALID_HANDLER_ID);
5913 }
5914
5915 /**
5916 * @tc.name: InputManagerTest_RemovePreMonitor_002
5917 * @tc.desc: Test RemovePreMonitor
5918 * @tc.type: FUNC
5919 * @tc.require:
5920 */
5921 HWTEST_F(InputManagerTest, InputManagerTest_RemovePreMonitor_002, TestSize.Level1)
5922 {
5923 CALL_TEST_DEBUG;
5924 int32_t monitorId = INVAID_VALUE;
5925 std::shared_ptr<InputManager> inputManager = std::make_shared<InputManager>();
5926 ASSERT_NO_FATAL_FAILURE(inputManager->RemovePreMonitor(monitorId));
5927 }
5928
5929 /*
5930 * @tc.name: InputManagerTest_SetMultiWindowScreenId_002
5931 * @tc.desc: SetMultiWindowScreenId
5932 * @tc.type: FUNC
5933 * @tc.require:
5934 */
5935 HWTEST_F(InputManagerTest, InputManagerTest_SetMultiWindowScreenId_002, TestSize.Level1)
5936 {
5937 CALL_TEST_DEBUG;
5938 uint64_t screenId = 0;
5939 uint64_t displayNodeScreenId = 0;
5940 std::shared_ptr<InputManager> inputManager = std::make_shared<InputManager>();
5941 ASSERT_NO_FATAL_FAILURE(inputManager->SetMultiWindowScreenId(screenId, displayNodeScreenId));
5942 }
5943
5944 /*
5945 * @tc.name: InputManagerTest_SetKnuckleSwitch_001
5946 * @tc.desc: SetKnuckleSwitch
5947 * @tc.type: FUNC
5948 * @tc.require:
5949 */
5950 HWTEST_F(InputManagerTest, InputManagerTest_SetKnuckleSwitch_001, TestSize.Level1)
5951 {
5952 CALL_TEST_DEBUG;
5953 bool knuckleSwitch = false;
5954 std::shared_ptr<InputManager> inputManager = std::make_shared<InputManager>();
5955 ASSERT_NO_FATAL_FAILURE(inputManager->SetKnuckleSwitch(knuckleSwitch));
5956 }
5957
ReadMaxMultiTouchPointNum(int32_t & maxMultiTouchPointNum)5958 void InputManagerTest::ReadMaxMultiTouchPointNum(int32_t &maxMultiTouchPointNum)
5959 {
5960 maxMultiTouchPointNum = -1;
5961 char cfgName[] { "etc/input/input_product_config.json" };
5962 char buf[MAX_PATH_LEN] {};
5963 char *cfgPath = ::GetOneCfgFile(cfgName, buf, sizeof(buf));
5964 if (cfgPath == nullptr) {
5965 MMI_HILOGE("No '%{private}s' was found", cfgName);
5966 return;
5967 }
5968 std::cout << "Input product config: " << cfgPath << std::endl;
5969 ReadMaxMultiTouchPointNum(std::string(cfgPath), maxMultiTouchPointNum);
5970 }
5971
ReadMaxMultiTouchPointNum(const std::string & cfgPath,int32_t & maxMultiTouchPointNum)5972 void InputManagerTest::ReadMaxMultiTouchPointNum(const std::string &cfgPath, int32_t &maxMultiTouchPointNum)
5973 {
5974 std::string cfg = ReadJsonFile(cfgPath);
5975 cJSON *jsonProductCfg = cJSON_Parse(cfg.c_str());
5976 CHKPV(jsonProductCfg);
5977 ReadMaxMultiTouchPointNum(jsonProductCfg, maxMultiTouchPointNum);
5978 cJSON_Delete(jsonProductCfg);
5979 }
5980
ReadMaxMultiTouchPointNum(cJSON * productCfg,int32_t & maxMultiTouchPointNum)5981 void InputManagerTest::ReadMaxMultiTouchPointNum(cJSON *productCfg, int32_t &maxMultiTouchPointNum)
5982 {
5983 if (!cJSON_IsObject(productCfg)) {
5984 MMI_HILOGE("Not json format");
5985 return;
5986 }
5987 cJSON *jsonTouchscreen = cJSON_GetObjectItemCaseSensitive(productCfg, "touchscreen");
5988 if (!cJSON_IsObject(jsonTouchscreen)) {
5989 MMI_HILOGE("The jsonTouchscreen is not object");
5990 return;
5991 }
5992 cJSON *jsonMaxNumOfTouches = cJSON_GetObjectItemCaseSensitive(jsonTouchscreen, "MaxTouchPoints");
5993 if (!cJSON_IsNumber(jsonMaxNumOfTouches)) {
5994 MMI_HILOGE("The jsonMaxNumOfTouches is not number");
5995 return;
5996 }
5997 auto num = static_cast<int32_t>(cJSON_GetNumberValue(jsonMaxNumOfTouches));
5998 if ((num < MIN_MULTI_TOUCH_POINT_NUM) || (num > MAX_MULTI_TOUCH_POINT_NUM)) {
5999 MMI_HILOGW("Invalid config: MaxTouchPoints(%{public}d) is out of range[%{public}d, %{public}d]",
6000 num, MIN_MULTI_TOUCH_POINT_NUM, MAX_MULTI_TOUCH_POINT_NUM);
6001 return;
6002 }
6003 maxMultiTouchPointNum = num;
6004 MMI_HILOGI("touchscreen.MaxTouchPoints:%{public}d", maxMultiTouchPointNum);
6005 }
6006
6007 /*
6008 * @tc.name: InputManagerTest_GetMaxMultiTouchPointNum_001
6009 * @tc.desc: GetMaxMultiTouchPointNum
6010 * @tc.type: FUNC
6011 * @tc.require:
6012 */
6013 HWTEST_F(InputManagerTest, InputManagerTest_GetMaxMultiTouchPointNum_001, TestSize.Level1)
6014 {
6015 CALL_TEST_DEBUG;
6016 int32_t pointNum { UNKNOWN_MULTI_TOUCH_POINT_NUM };
6017 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->GetMaxMultiTouchPointNum(pointNum));
6018
6019 int32_t multiTouchPointNum { UNKNOWN_MULTI_TOUCH_POINT_NUM };
6020 ReadMaxMultiTouchPointNum(multiTouchPointNum);
6021 std::cout << "MaxTouchPoints:" << multiTouchPointNum << std::endl;
6022
6023 auto ret = InputManager::GetInstance()->GetMaxMultiTouchPointNum(pointNum);
6024 if ((multiTouchPointNum >= MIN_MULTI_TOUCH_POINT_NUM) && (multiTouchPointNum <= MAX_MULTI_TOUCH_POINT_NUM)) {
6025 EXPECT_EQ(ret, RET_OK);
6026 EXPECT_EQ(pointNum, multiTouchPointNum);
6027 } else {
6028 EXPECT_EQ(ret, MMI_ERR_NO_PRODUCT_CONFIG);
6029 EXPECT_EQ(pointNum, UNKNOWN_MULTI_TOUCH_POINT_NUM);
6030 }
6031 }
6032
6033 /*
6034 * @tc.name: InputManagerTest_SubscribeTabletProximity
6035 * @tc.desc: Test SubscribeTabletProximity and UnsubscribetabletProximity
6036 * @tc.type: FUNC
6037 * @tc.require:
6038 */
6039 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeTabletProximity, TestSize.Level1)
6040 {
6041 CALL_TEST_DEBUG;
6042 std::function<void(std::shared_ptr<PointerEvent>)> callback;
6043 int32_t ret = InputManager::GetInstance()->SubscribeTabletProximity(callback);
6044 EXPECT_EQ(ret, INVAID_VALUE);
6045 int32_t subscriberId = INVAID_VALUE;
6046 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UnsubscribetabletProximity(subscriberId));
6047 }
6048
6049 /*
6050 * @tc.name: InputManagerTest_SubscribeInputActive
6051 * @tc.desc: Test SubscribeInputActive and UnsubscribeInputActive
6052 * @tc.type: FUNC
6053 * @tc.require:
6054 */
6055 HWTEST_F(InputManagerTest, InputManagerTest_subscribeInputActive, TestSize.Level1)
6056 {
6057 CALL_TEST_DEBUG;
6058 std::shared_ptr<IInputEventConsumer> consumer;
6059 int64_t interval = 1;
6060 int32_t ret = InputManager::GetInstance()->SubscribeInputActive(consumer, interval);
6061 ASSERT_EQ(ret, INVALID_HANDLER_ID);
6062 int32_t subscriberId = INVAID_VALUE;
6063 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UnsubscribeInputActive(subscriberId));
6064 }
6065
6066 /*
6067 * @tc.name: InputManagerTest_QueryPointerRecord_001
6068 * @tc.desc: QueryPointerRecord
6069 * @tc.type: FUNC
6070 * @tc.require:
6071 */
6072 HWTEST_F(InputManagerTest, InputManagerTest_QueryPointerRecord_001, TestSize.Level1)
6073 {
6074 CALL_TEST_DEBUG;
6075 int32_t count = -1;
6076 std::vector<std::shared_ptr<PointerEvent>> pointerList;
6077 EXPECT_EQ(InputManager::GetInstance()->QueryPointerRecord(count, pointerList), RET_OK);
6078 }
6079
6080 /*
6081 * @tc.name: InputManagerTest_QueryPointerRecord_002
6082 * @tc.desc: QueryPointerRecord
6083 * @tc.type: FUNC
6084 * @tc.require:
6085 */
6086 HWTEST_F(InputManagerTest, InputManagerTest_QueryPointerRecord_002, TestSize.Level1)
6087 {
6088 CALL_TEST_DEBUG;
6089 int32_t count = 0;
6090 std::vector<std::shared_ptr<PointerEvent>> pointerList;
6091 EXPECT_EQ(InputManager::GetInstance()->QueryPointerRecord(count, pointerList), RET_OK);
6092 }
6093
6094 /*
6095 * @tc.name: InputManagerTest_QueryPointerRecord_003
6096 * @tc.desc: QueryPointerRecord
6097 * @tc.type: FUNC
6098 * @tc.require:
6099 */
6100 HWTEST_F(InputManagerTest, InputManagerTest_QueryPointerRecord_003, TestSize.Level1)
6101 {
6102 CALL_TEST_DEBUG;
6103 int32_t count = 30;
6104 std::vector<std::shared_ptr<PointerEvent>> pointerList;
6105 EXPECT_EQ(InputManager::GetInstance()->QueryPointerRecord(count, pointerList), RET_OK);
6106 }
6107
6108 /*
6109 * @tc.name: InputManagerTest_QueryPointerRecord_004
6110 * @tc.desc: QueryPointerRecord
6111 * @tc.type: FUNC
6112 * @tc.require:
6113 */
6114 HWTEST_F(InputManagerTest, InputManagerTest_QueryPointerRecord_004, TestSize.Level1)
6115 {
6116 CALL_TEST_DEBUG;
6117 int32_t count = 100;
6118 std::vector<std::shared_ptr<PointerEvent>> pointerList;
6119 EXPECT_EQ(InputManager::GetInstance()->QueryPointerRecord(count, pointerList), RET_OK);
6120 }
6121
6122 /*
6123 * @tc.name: InputManagerTest_QueryPointerRecord_005
6124 * @tc.desc: QueryPointerRecord
6125 * @tc.type: FUNC
6126 * @tc.require:
6127 */
6128 HWTEST_F(InputManagerTest, InputManagerTest_QueryPointerRecord_005, TestSize.Level1)
6129 {
6130 CALL_TEST_DEBUG;
6131 int32_t count = 101;
6132 std::vector<std::shared_ptr<PointerEvent>> pointerList;
6133 EXPECT_EQ(InputManager::GetInstance()->QueryPointerRecord(count, pointerList), RET_OK);
6134 }
6135
6136 /*
6137 * @tc.name: InputManagerTest_InsertRequestInjectionCallback_001
6138 * @tc.desc: InsertRequestInjectionCallback
6139 * @tc.type: FUNC
6140 * @tc.require:
6141 */
6142 HWTEST_F(InputManagerTest, InputManagerTest_InsertRequestInjectionCallback_001, TestSize.Level1)
6143 {
6144 CALL_TEST_DEBUG;
6145 int32_t reqId = 1;
6146 std::function<void(int32_t)> callback;
6147 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->InsertRequestInjectionCallback(reqId, callback));
6148 }
6149
6150 /*
6151 * @tc.name: InputManagerTest_RequestInjectionCallback_001
6152 * @tc.desc: RequestInjectionCallback
6153 * @tc.type: FUNC
6154 * @tc.require:
6155 */
6156 HWTEST_F(InputManagerTest, InputManagerTest_RequestInjectionCallback_001, TestSize.Level1)
6157 {
6158 CALL_TEST_DEBUG;
6159 int32_t reqId = -1;
6160 int32_t status = 0;
6161 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->RequestInjectionCallback(reqId, status));
6162 }
6163
6164 /*
6165 * @tc.name: InputManagerTest_SetInputDeviceConsumer
6166 * @tc.desc: SetInputDeviceConsumer
6167 * @tc.type: FUNC
6168 * @tc.require:
6169 */
6170 HWTEST_F(InputManagerTest, InputManagerTest_SetInputDeviceConsumer, TestSize.Level1)
6171 {
6172 CALL_TEST_DEBUG;
6173 std::vector<std::string> deviceNames;
6174 deviceNames.push_back("test1");
6175 deviceNames.push_back("test2");
6176 std::shared_ptr<IInputEventConsumer> consumer = nullptr;
6177 std::shared_ptr<InputManager> inputManager = std::make_shared<InputManager>();
6178 EXPECT_NE(inputManager->SetInputDeviceConsumer(deviceNames, consumer), RET_OK);
6179 }
6180 } // namespace MMI
6181 } // namespace OHOS
6182