1 /*
2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <cinttypes>
17 #include <semaphore.h>
18
19 #include "event_log_helper.h"
20 #include "event_util_test.h"
21 #include "input_manager.h"
22 #include "input_manager_util.h"
23 #include "multimodal_event_handler.h"
24 #include "system_info.h"
25
26 #undef MMI_LOG_TAG
27 #define MMI_LOG_TAG "InputManagerTest"
28
29 namespace OHOS {
30 namespace MMI {
31 namespace {
32 constexpr int32_t TUPLE_PID = 0;
33 constexpr int32_t TUPLE_UID = 1;
34 constexpr int32_t TUPLE_NAME = 2;
35 constexpr int32_t TIME_WAIT_FOR_OP = 100;
36 constexpr int32_t NANOSECOND_TO_MILLISECOND = 1000000;
37 constexpr int32_t SLEEP_MILLISECONDS = 1000;
38 constexpr int32_t DEFAULT_DEVICE_ID = 0;
39 constexpr int32_t KEY_REPEAT_DELAY = 350;
40 constexpr int32_t KEY_REPEAT_RATE = 60;
41 constexpr int32_t POINTER_ITEM_DISPLAY_X_ONE = 147;
42 constexpr int32_t POINTER_ITEM_DISPLAY_X_TWO = 456;
43 constexpr int32_t POINTER_ITEM_DISPLAY_Y_ONE = 123;
44 constexpr int32_t POINTER_ITEM_DISPLAY_Y_TWO = 258;
45 constexpr int32_t KEY_DOWN_DURATION = 300;
46 constexpr int32_t FINAL_KEY_DOWN_DURATION_ONE = 10;
47 constexpr int32_t FINAL_KEY_DOWN_DURATION_TWO = 2000;
48 constexpr int32_t POINTER_SENSOR_INPUT_TIME = 2000;
49 constexpr int32_t KEYBOARD_TYPE_SIZE = 20;
50 constexpr int32_t PARAMETER_ERROR = 401;
51 constexpr int32_t INVAID_VALUE = -1;
52 constexpr uint32_t MAX_WINDOW_NUMS = 15;
53 constexpr int32_t MOUSE_ICON_SIZE = 64;
54 #ifdef OHOS_BUILD_ENABLE_ANCO
55 constexpr uint32_t SHELL_FLAGS_VALUE = 2;
56 #endif // OHOS_BUILD_ENABLE_ANCO
57
58 constexpr double POINTER_ITEM_PRESSURE = 5.0;
59 } // namespace
60
61 class InputManagerTest : public testing::Test {
62 public:
63 void SetUp();
64 void TearDown();
65 static void SetUpTestCase();
66 std::string GetEventDump();
67 std::unique_ptr<OHOS::Media::PixelMap> SetMouseIconTest(const std::string iconPath);
68
69 private:
70 int32_t keyboardRepeatRate_ { 50 };
71 int32_t keyboardRepeatDelay_ { 500 };
72 };
73
74 class MMIWindowChecker : public MMI::IWindowChecker {
75 public:
76 int32_t CheckWindowId(int32_t windowId) const override;
77 };
78
79 class IEventObserver : public MMI::MMIEventObserver {
80 public:
81 void SyncBundleName(int32_t pid, int32_t uid, std::string bundleName, int32_t syncStatus) override;
82 };
83
SyncBundleName(int32_t pid,int32_t uid,std::string bundleName,int32_t syncStatus)84 void IEventObserver::SyncBundleName(int32_t pid, int32_t uid, std::string bundleName, int32_t syncStatus)
85 {
86 int32_t getPid = pid;
87 int32_t getUid = uid;
88 std::string getName = bundleName;
89 int32_t getStatus = syncStatus;
90 MMI_HILOGD("SyncBundleName info is : %{public}d, %{public}d, %{public}s, %{public}d",
91 getPid, getUid, getName.c_str(), getStatus);
92 }
93
CheckWindowId(int32_t windowId) const94 int32_t MMIWindowChecker::CheckWindowId(int32_t windowId) const
95 {
96 return getpid();
97 }
98
SetUpTestCase()99 void InputManagerTest::SetUpTestCase()
100 {
101 ASSERT_TRUE(TestUtil->Init());
102 }
103
SetUp()104 void InputManagerTest::SetUp()
105 {
106 TestUtil->SetRecvFlag(RECV_FLAG::RECV_FOCUS);
107 }
108
TearDown()109 void InputManagerTest::TearDown()
110 {
111 TestUtil->AddEventDump("");
112 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
113 InputManager::GetInstance()->SetKeyboardRepeatDelay(keyboardRepeatDelay_);
114 InputManager::GetInstance()->SetKeyboardRepeatRate(keyboardRepeatRate_);
115 }
116
GetEventDump()117 std::string InputManagerTest::GetEventDump()
118 {
119 return TestUtil->GetEventDump();
120 }
121
SetMouseIconTest(const std::string iconPath)122 std::unique_ptr<OHOS::Media::PixelMap> InputManagerTest::SetMouseIconTest(const std::string iconPath)
123 {
124 CALL_DEBUG_ENTER;
125 OHOS::Media::SourceOptions opts;
126 opts.formatHint = "image/svg+xml";
127 uint32_t ret = 0;
128 auto imageSource = OHOS::Media::ImageSource::CreateImageSource(iconPath, opts, ret);
129 CHKPP(imageSource);
130 std::set<std::string> formats;
131 ret = imageSource->GetSupportedFormats(formats);
132 MMI_HILOGD("Get supported format ret:%{public}u", ret);
133
134 OHOS::Media::DecodeOptions decodeOpts;
135 decodeOpts.desiredSize = {.width = MOUSE_ICON_SIZE, .height = MOUSE_ICON_SIZE};
136
137 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, ret);
138 CHKPL(pixelMap);
139 return pixelMap;
140 }
141
142 /**
143 * @tc.name: InputManagerTest_SetKeyDownDuration_01
144 * @tc.desc: Test SetKeyDownDuration
145 * @tc.type: FUNC
146 * @tc.require:
147 */
148 HWTEST_F(InputManagerTest, InputManagerTest_SetKeyDownDuration_01, TestSize.Level1)
149 {
150 CALL_TEST_DEBUG;
151 std::string businessId = "";
152 int32_t delay = 4500;
153 int32_t ret = InputManager::GetInstance()->SetKeyDownDuration(businessId, delay);
154 EXPECT_EQ(ret, RET_ERR);
155 }
156
157 /**
158 * @tc.name: InputManagerTest_SetKeyDownDuration_02
159 * @tc.desc: Test SetKeyDownDuration
160 * @tc.type: FUNC
161 * @tc.require:
162 */
163 HWTEST_F(InputManagerTest, InputManagerTest_SetKeyDownDuration_02, TestSize.Level1)
164 {
165 CALL_TEST_DEBUG;
166 std::string businessId = "";
167 int32_t delay = 0;
168 int32_t ret = InputManager::GetInstance()->SetKeyDownDuration(businessId, delay);
169 EXPECT_EQ(ret, PARAMETER_ERROR);
170 }
171
172 /**
173 * @tc.name: InputManagerTest_SetMouseIcon_01
174 * @tc.desc: Test setMouseIcon
175 * @tc.type: FUNC
176 * @tc.require:
177 */
178 HWTEST_F(InputManagerTest, InputManagerTest_SetMouseIcon_01, TestSize.Level1)
179 {
180 CALL_TEST_DEBUG;
181 int32_t windowId = 2;
182 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
183 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerTest::SetMouseIconTest(iconPath);
184 ASSERT_NE(pixelMap, nullptr);
185
186 int32_t ret = InputManager::GetInstance()->SetMouseIcon(windowId, (void *)pixelMap.get());
187 EXPECT_EQ(ret, RET_OK);
188 }
189
190 /**
191 * @tc.name: InputManagerTest_EnableHardwareCursorStats_01
192 * @tc.desc: Test EnableHardwareCursorStats
193 * @tc.type: FUNC
194 * @tc.require:
195 */
196 HWTEST_F(InputManagerTest, InputManagerTest_EnableHardwareCursorStats_01, TestSize.Level1)
197 {
198 CALL_TEST_DEBUG;
199 bool enable = true;
200 int32_t ret = InputManager::GetInstance()->EnableHardwareCursorStats(enable);
201 EXPECT_NE(ret, RET_ERR);
202 }
203
204 /**
205 * @tc.name: InputManagerTest_EnableHardwareCursorStats_02
206 * @tc.desc: Test EnableHardwareCursorStats
207 * @tc.type: FUNC
208 * @tc.require:
209 */
210 HWTEST_F(InputManagerTest, InputManagerTest_EnableHardwareCursorStats_02, TestSize.Level1)
211 {
212 CALL_TEST_DEBUG;
213 bool enable = false;
214 int32_t ret = InputManager::GetInstance()->EnableHardwareCursorStats(enable);
215 EXPECT_EQ(ret, RET_OK);
216 }
217
218 /**
219 * @tc.name: InputManagerTest_GetWinSyncBatchSize
220 * @tc.desc: Test GetWinSyncBatchSize
221 * @tc.type: FUNC
222 * @tc.require:
223 */
224 HWTEST_F(InputManagerTest, InputManagerTest_GetWinSyncBatchSize, TestSize.Level1)
225 {
226 int32_t maxAreasCount = 1;
227 int32_t displayCount = 2;
228 int32_t ret = InputManager::GetInstance()->GetWinSyncBatchSize(maxAreasCount, displayCount);
229 EXPECT_NE(ret, 0);
230 }
231
232 /**
233 * @tc.name: InputManager_NotResponse_001
234 * @tc.desc: detection of not response
235 * @tc.type: FUNC
236 * @tc.require:AR000GJG6G
237 */
238 HWTEST_F(InputManagerTest, InputManager_NotResponse_001, TestSize.Level1)
239 {
240 CALL_TEST_DEBUG;
241 auto pointerEvent = PointerEvent::Create();
242 ASSERT_NE(pointerEvent, nullptr);
243
244 PointerEvent::PointerItem item;
245 item.SetPressure(POINTER_ITEM_PRESSURE);
246 item.SetPointerId(0);
247 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_TWO);
248 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_ONE);
249 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
250 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
251 pointerEvent->SetPointerId(0);
252 pointerEvent->AddPointerItem(item);
253 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
254 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
255 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
256 }
257
258 /**
259 * @tc.name: InputManager_NotResponse_002
260 * @tc.desc: detection of not response
261 * @tc.type: FUNC
262 * @tc.require:SR000GGN6G
263 */
264 HWTEST_F(InputManagerTest, InputManager_NotResponse_002, TestSize.Level1)
265 {
266 CALL_TEST_DEBUG;
267 auto pointerEvent = PointerEvent::Create();
268 ASSERT_NE(pointerEvent, nullptr);
269
270 PointerEvent::PointerItem item;
271 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_TWO);
272 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_ONE);
273 item.SetPressure(POINTER_ITEM_PRESSURE);
274 item.SetPointerId(0);
275 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
276 pointerEvent->SetPointerId(0);
277 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
278 pointerEvent->AddPointerItem(item);
279 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
280 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
281 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
282 }
283
284 /**
285 * @tc.name: InputManagerTest_SubscribeKeyEvent_001
286 * @tc.desc: Verify invalid parameter.
287 * @tc.type: FUNC
288 * @tc.require:SR000GGQL4 AR000GJNGN
289 * @tc.author: yangguang
290 */
291 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_001, TestSize.Level1)
292 {
293 CALL_TEST_DEBUG;
294 std::set<int32_t> preKeys;
295 std::shared_ptr<KeyOption> keyOption =
296 InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_MUTE, true, 0);
297 int32_t response = INVAID_VALUE;
298 response = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, nullptr);
299 EXPECT_TRUE(response < 0);
300 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
301 InputManager::GetInstance()->UnsubscribeKeyEvent(response);
302 }
303
304 /**
305 * @tc.name: InputManagerTest_SubscribeKeyEvent_02
306 * @tc.desc: Verify subscribe power key event.
307 * @tc.type: FUNC
308 * @tc.require:SR000GGQL4 AR000GJNGN
309 * @tc.author: zhaoxueyuan
310 */
311 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_02, TestSize.Level1)
312 {
313 CALL_TEST_DEBUG;
314 ASSERT_TRUE(MMIEventHdl.InitClient());
315 // 电源键长按按下订阅
316 std::set<int32_t> preKeys;
317 std::shared_ptr<KeyOption> keyOption =
318 InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_POWER, true, FINAL_KEY_DOWN_DURATION_TWO);
319 int32_t subscribeId1 = INVAID_VALUE;
__anon5b702e150202(std::shared_ptr<KeyEvent> keyEvent) 320 subscribeId1 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
321 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
322 MMI_HILOGD("Subscribe key event KEYCODE_POWER down trigger callback");
323 });
324 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
325 EXPECT_TRUE(subscribeId1 >= 0);
326 #else
327 EXPECT_TRUE(subscribeId1 < 0);
328 #endif // OHOS_BUILD_ENABLE_KEYBOARD
329
330 // 电源键抬起订阅
331 std::shared_ptr<KeyOption> keyOption2 = InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_POWER, false, 0);
332 int32_t subscribeId2 = INVAID_VALUE;
__anon5b702e150302(std::shared_ptr<KeyEvent> keyEvent) 333 subscribeId2 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption2, [](std::shared_ptr<KeyEvent> keyEvent) {
334 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
335 MMI_HILOGD("Subscribe key event KEYCODE_POWER up trigger callback");
336 });
337 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
338 EXPECT_TRUE(subscribeId2 >= 0);
339 #else
340 EXPECT_TRUE(subscribeId2 < 0);
341 #endif // OHOS_BUILD_ENABLE_KEYBOARD
342
343 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
344 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId1);
345 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId2);
346 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
347 }
348
349 /**
350 * @tc.name: InputManagerTest_SubscribeKeyEvent_03
351 * @tc.desc: Verify subscribe volume up key event.
352 * @tc.type: FUNC
353 * @tc.require:
354 */
355 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_03, TestSize.Level1)
356 {
357 CALL_TEST_DEBUG;
358 ASSERT_TRUE(MMIEventHdl.InitClient());
359 std::set<int32_t> preKeys;
360 std::shared_ptr<KeyOption> keyOption1 =
361 InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_UP, true, FINAL_KEY_DOWN_DURATION_ONE);
362 int32_t subscribeId1 = INVAID_VALUE;
__anon5b702e150402(std::shared_ptr<KeyEvent> keyEvent) 363 subscribeId1 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption1, [](std::shared_ptr<KeyEvent> keyEvent) {
364 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
365 MMI_HILOGD("Subscribe key event KEYCODE_VOLUME_UP down trigger callback");
366 });
367 std::shared_ptr<KeyOption> keyOption2 =
368 InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_UP, false, 0);
369 int32_t subscribeId2 = INVAID_VALUE;
__anon5b702e150502(std::shared_ptr<KeyEvent> keyEvent) 370 subscribeId2 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption2, [](std::shared_ptr<KeyEvent> keyEvent) {
371 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
372 MMI_HILOGD("Subscribe key event KEYCODE_VOLUME_UP up trigger callback");
373 });
374 std::shared_ptr<KeyOption> keyOption3 = InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_UP, true, 0);
375 int32_t subscribeId3 = INVAID_VALUE;
__anon5b702e150602(std::shared_ptr<KeyEvent> keyEvent) 376 subscribeId3 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption3, [](std::shared_ptr<KeyEvent> keyEvent) {
377 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
378 MMI_HILOGD("Subscribe key event KEYCODE_VOLUME_UP down trigger callback");
379 });
380 std::shared_ptr<KeyOption> keyOption4 =
381 InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_UP, false, 0);
382 int32_t subscribeId4 = INVAID_VALUE;
__anon5b702e150702(std::shared_ptr<KeyEvent> keyEvent) 383 subscribeId4 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption4, [](std::shared_ptr<KeyEvent> keyEvent) {
384 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
385 MMI_HILOGD("Subscribe key event KEYCODE_VOLUME_UP up trigger callback");
386 });
387
388 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
389 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId1);
390 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId2);
391 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId3);
392 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId4);
393 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
394 }
395
396 /**
397 * @tc.name: InputManagerTest_SubscribeKeyEvent_04
398 * @tc.desc: Verify subscribe key event.
399 * @tc.type: FUNC
400 * @tc.require:
401 * @tc.author:
402 */
403 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_04, TestSize.Level1)
404 {
405 CALL_TEST_DEBUG;
406 std::set<int32_t> preKeys;
407 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
408 keyOption->SetPreKeys(preKeys);
409 keyOption->SetFinalKey(KeyEvent::KEYCODE_VOLUME_DOWN);
410 keyOption->SetFinalKeyDown(true);
411 keyOption->SetFinalKeyDownDuration(INVAID_VALUE);
412 int32_t subscribeId = INVAID_VALUE;
__anon5b702e150802(std::shared_ptr<KeyEvent> keyEvent) 413 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
414 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
415 MMI_HILOGD("Subscribe key event KEYCODE_POWER down trigger callback");
416 });
417 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
418 EXPECT_TRUE(subscribeId >= 0);
419 #else
420 EXPECT_TRUE(subscribeId < 0);
421 #endif // OHOS_BUILD_ENABLE_KEYBOARD
422 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
423 ASSERT_TRUE(injectDownEvent != nullptr);
424 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
425 KeyEvent::KeyItem kitDown;
426 kitDown.SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
427 kitDown.SetPressed(true);
428 kitDown.SetDownTime(downTime);
429 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
430 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
431 injectDownEvent->AddPressedKeyItems(kitDown);
432 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
433 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
434 }
435
436 /**
437 * @tc.name: TestGetKeystrokeAbility_001
438 * @tc.desc: Verify SupportKeys
439 * @tc.type: FUNC
440 * @tc.require:
441 */
442 HWTEST_F(InputManagerTest, TestGetKeystrokeAbility_001, TestSize.Level1)
443 {
444 CALL_TEST_DEBUG;
445 std::vector<int32_t> keyCodes = {
446 KeyEvent::KEYCODE_VOLUME_DOWN, KeyEvent::KEYCODE_VOLUME_MUTE, KeyEvent::KEYCODE_DEL};
447 int32_t result = InputManager::GetInstance()->SupportKeys(
__anon5b702e150902(std::vector<bool> keystrokeAbility) 448 0, keyCodes, [](std::vector<bool> keystrokeAbility) { MMI_HILOGD("TestGetKeystrokeAbility_001 callback ok"); });
449 ASSERT_EQ(result, 0);
450 MMI_HILOGD("Stop TestGetKeystrokeAbility_001");
451 }
452
453 static int32_t g_deviceIDtest = 0;
GetKeyboardTypeCallback(int32_t keyboardType)454 static void GetKeyboardTypeCallback(int32_t keyboardType)
455 {
456 switch (keyboardType) {
457 case KEYBOARD_TYPE_NONE: {
458 MMI_HILOGD("g_deviceIDtest:%{public}d-->KeyboardType:%{public}s", g_deviceIDtest, "None");
459 break;
460 }
461 case KEYBOARD_TYPE_UNKNOWN: {
462 MMI_HILOGD("g_deviceIDtest:%{public}d-->KeyboardType:%{public}s", g_deviceIDtest, "unknown");
463 break;
464 }
465 case KEYBOARD_TYPE_ALPHABETICKEYBOARD: {
466 MMI_HILOGD("g_deviceIDtest:%{public}d-->KeyboardType:%{public}s", g_deviceIDtest, "alphabetickeyboard");
467 break;
468 }
469 case KEYBOARD_TYPE_DIGITALKEYBOARD: {
470 MMI_HILOGD("g_deviceIDtest:%{public}d-->KeyboardType:%{public}s", g_deviceIDtest, "digitalkeyboard");
471 break;
472 }
473 case KEYBOARD_TYPE_HANDWRITINGPEN: {
474 MMI_HILOGD("g_deviceIDtest:%{public}d-->KeyboardType:%{public}s", g_deviceIDtest, "handwritingpen");
475 break;
476 }
477 case KEYBOARD_TYPE_REMOTECONTROL: {
478 MMI_HILOGD("g_deviceIDtest:%{public}d-->KeyboardType:%{public}s", g_deviceIDtest, "remotecontrol");
479 break;
480 }
481 default: {
482 MMI_HILOGW("Error obtaining keyboard type");
483 break;
484 }
485 }
486 }
487
488 /**
489 * @tc.name: InputManagerTest_GetKeyboardType
490 * @tc.desc: Verify Get Keyboard Type
491 * @tc.type: FUNC
492 * @tc.require:
493 */
494 HWTEST_F(InputManagerTest, InputManagerTest_GetKeyboardType, TestSize.Level1)
495 {
496 MMI_HILOGD("Start InputManagerTest_GetKeyboardType");
497 for (int32_t i = 0; i < KEYBOARD_TYPE_SIZE; ++i) {
498 g_deviceIDtest = i;
499 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->GetKeyboardType(i, GetKeyboardTypeCallback));
500 MMI_HILOGD("i:%{public}d", i);
501 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
502 }
503 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
504 MMI_HILOGD("Stop InputManagerTest_GetKeyboardType");
505 }
506
507 /**
508 * @tc.name: InputManagerTest_SetKeyboardRepeatDelay
509 * @tc.desc: Verify Set Keyboard Repeat Delay
510 * @tc.type: FUNC
511 * @tc.require:
512 */
513 HWTEST_F(InputManagerTest, InputManagerTest_SetKeyboardRepeatDelay, TestSize.Level1)
514 {
515 MMI_HILOGD("Start InputManagerTest_SetKeyboardRepeatDelay");
516 int32_t ret = InputManager::GetInstance()->SetKeyboardRepeatDelay(KEY_REPEAT_DELAY);
517 ASSERT_EQ(ret, RET_OK);
518 MMI_HILOGD("Stop InputManagerTest_SetKeyboardRepeatDelay");
519 }
520
521 /**
522 * @tc.name: InputManagerTest_SetKeyboardRepeatRate
523 * @tc.desc: Verify Set Keyboard Repeat Rate
524 * @tc.type: FUNC
525 * @tc.require:
526 */
527 HWTEST_F(InputManagerTest, InputManagerTest_SetKeyboardRepeatRate, TestSize.Level1)
528 {
529 MMI_HILOGD("Start InputManagerTest_SetKeyboardRepeatRate");
530 int32_t ret = InputManager::GetInstance()->SetKeyboardRepeatRate(KEY_REPEAT_RATE);
531 ASSERT_EQ(ret, RET_OK);
532 MMI_HILOGD("Stop InputManagerTest_SetKeyboardRepeatRate");
533 }
534
535 /**
536 * @tc.name: InputManagerTest_GetKeyboardRepeatDelay
537 * @tc.desc: Verify Get Keyboard Repeat Delay
538 * @tc.type: FUNC
539 * @tc.require:
540 */
541 HWTEST_F(InputManagerTest, InputManagerTest_GetKeyboardRepeatDelay, TestSize.Level1)
542 {
543 MMI_HILOGD("Start InputManagerTest_GetKeyboardRepeatDelay");
__anon5b702e150a02(int32_t delay) 544 auto callback = [](int32_t delay) {
545 ASSERT_TRUE(delay == KEY_REPEAT_DELAY);
546 MMI_HILOGD("Get keyboard repeat delay success");
547 };
548 if (InputManager::GetInstance()->SetKeyboardRepeatDelay(KEY_REPEAT_DELAY) == RET_OK) {
549 ASSERT_TRUE(InputManager::GetInstance()->GetKeyboardRepeatDelay(callback) == RET_OK);
550 }
551 MMI_HILOGD("Stop InputManagerTest_GetKeyboardRepeatDelay");
552 }
553
554 /**
555 * @tc.name: InputManagerTest_GetKeyboardRepeatRate
556 * @tc.desc: Verify Get Keyboard Repeat Rate
557 * @tc.type: FUNC
558 * @tc.require:
559 */
560 HWTEST_F(InputManagerTest, InputManagerTest_GetKeyboardRepeatRate, TestSize.Level1)
561 {
562 MMI_HILOGD("Start InputManagerTest_GetKeyboardRepeatRate");
__anon5b702e150b02(int32_t rate) 563 auto callback = [](int32_t rate) {
564 ASSERT_TRUE(rate == KEY_REPEAT_RATE);
565 MMI_HILOGD("Get keyboard repeat rate success");
566 };
567 if (InputManager::GetInstance()->SetKeyboardRepeatRate(KEY_REPEAT_RATE) == RET_OK) {
568 ASSERT_TRUE(InputManager::GetInstance()->GetKeyboardRepeatRate(callback) == RET_OK);
569 }
570 MMI_HILOGD("Stop InputManagerTest_GetKeyboardRepeatRate");
571 }
572
573 HWTEST_F(InputManagerTest, InputManagerTest_GetProcCpuUsage, TestSize.Level1)
574 {
575 CALL_TEST_DEBUG;
576 SYSTEM_INFO::CpuInfo cpuInfo;
577 const std::string process_name = "multimodalinput";
578 auto usage = cpuInfo.GetProcCpuUsage(process_name);
579 MMI_HILOGD("The CPU usage of the %{public}s process is %{public}.2f", process_name.c_str(), usage);
580 ASSERT_TRUE(usage < SYSTEM_INFO::CPU_USAGE_LOAD && usage != SYSTEM_INFO::CPU_USAGE_UNKNOWN);
581 }
582
583 /**
584 * @tc.name: InputManagerTest_FunctionKeyState_001
585 * @tc.desc: Set NumLock for the keyboard enablement state to true
586 * @tc.type: FUNC
587 * @tc.require: I5HMCX
588 */
589 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_001, TestSize.Level1)
590 {
591 CALL_TEST_DEBUG;
592 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY, true);
593 bool state = false;
594 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY, state);
595 ASSERT_FALSE(state);
596 }
597
598 /**
599 * @tc.name: InputManagerTest_FunctionKeyState_002
600 * @tc.desc: Set NumLock for the keyboard enablement state to false
601 * @tc.type: FUNC
602 * @tc.require: I5HMCX
603 */
604 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_002, TestSize.Level1)
605 {
606 CALL_TEST_DEBUG;
607 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY, false);
608 bool state = true;
609 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY, state);
610 ASSERT_FALSE(state);
611 }
612
613 /**
614 * @tc.name: InputManagerTest_FunctionKeyState_003
615 * @tc.desc: Set ScrollLock for the keyboard enablement state to true
616 * @tc.type: FUNC
617 * @tc.require: I5HMCX
618 */
619 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_003, TestSize.Level1)
620 {
621 CALL_TEST_DEBUG;
622 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY, true);
623 bool state = false;
624 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY, state);
625 ASSERT_FALSE(state);
626 }
627
628 /**
629 * @tc.name: InputManagerTest_FunctionKeyState_004
630 * @tc.desc: Set ScrollLock for the keyboard enablement state to false
631 * @tc.type: FUNC
632 * @tc.require: I5HMCX
633 */
634 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_004, TestSize.Level1)
635 {
636 CALL_TEST_DEBUG;
637 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY, false);
638 bool state = true;
639 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY, state);
640 ASSERT_FALSE(state);
641 }
642
643 /**
644 * @tc.name: InputManagerTest_FunctionKeyState_005
645 * @tc.desc: Set CapsLock for the keyboard enablement state to true
646 * @tc.type: FUNC
647 * @tc.require: I5HMCX
648 */
649 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_005, TestSize.Level1)
650 {
651 CALL_TEST_DEBUG;
652 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY, true);
653 bool state = false;
654 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY, state);
655 ASSERT_FALSE(state);
656 }
657
658 /**
659 * @tc.name: InputManagerTest_FunctionKeyState_006
660 * @tc.desc: Set CapsLock for the keyboard enablement state to false
661 * @tc.type: FUNC
662 * @tc.require: I5HMCX
663 */
664 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_006, TestSize.Level1)
665 {
666 CALL_TEST_DEBUG;
667 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY, false);
668 bool state = true;
669 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY, state);
670 ASSERT_FALSE(state);
671 }
672
673 /**
674 * @tc.name: InputManagerTest_FunctionKeyState_007
675 * @tc.desc: Set other function keys
676 * @tc.type: FUNC
677 * @tc.require: I5HMCX
678 */
679 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_007, TestSize.Level1)
680 {
681 CALL_TEST_DEBUG;
682 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY, true);
683 bool state = true;
684 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY, state);
685 ASSERT_FALSE(state);
686
687 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY, false);
688 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY, state);
689 ASSERT_FALSE(state);
690 }
691
692 /**
693 * @tc.name: InputManagerTest_EnableCombineKey_001
694 * @tc.desc: Enable combine key
695 * @tc.type: FUNC
696 * @tc.require: I5HMCX
697 */
698 HWTEST_F(InputManagerTest, InputManagerTest_EnableCombineKey_001, TestSize.Level1)
699 {
700 CALL_TEST_DEBUG;
701 ASSERT_EQ(InputManager::GetInstance()->EnableCombineKey(false), RET_OK);
702 }
703
704 /**
705 * @tc.name: InputManagerTest_EnableCombineKey_002
706 * @tc.desc: Enable combine key
707 * @tc.type: FUNC
708 * @tc.require: I5HMCX
709 */
710 HWTEST_F(InputManagerTest, InputManagerTest_EnableCombineKey_002, TestSize.Level1)
711 {
712 CALL_TEST_DEBUG;
713 ASSERT_EQ(InputManager::GetInstance()->EnableCombineKey(true), RET_OK);
714 }
715
716 /**
717 * @tc.name: InputManagerTest_TouchScreenHotArea_001
718 * @tc.desc: Touch event Search window by defaultHotAreas
719 * @tc.type: FUNC
720 * @tc.require: I5HMCB
721 */
722 HWTEST_F(InputManagerTest, InputManagerTest_TouchScreenHotArea_001, TestSize.Level1)
723 {
724 CALL_TEST_DEBUG;
725 std::shared_ptr<PointerEvent> pointerEvent{InputManagerUtil::SetupTouchScreenEvent001()};
726 ASSERT_TRUE(pointerEvent != nullptr);
727 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
728 ASSERT_EQ(pointerEvent->GetSourceType(), PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
729 }
730
731 /**
732 * @tc.name: InputManagerTest_TouchScreenHotArea_002
733 * @tc.desc: Touch event Search window by pointerHotAreas
734 * @tc.type: FUNC
735 * @tc.require: I5HMCB
736 */
737 HWTEST_F(InputManagerTest, InputManagerTest_TouchScreenHotArea_002, TestSize.Level1)
738 {
739 CALL_TEST_DEBUG;
740 std::shared_ptr<PointerEvent> pointerEvent{InputManagerUtil::SetupTouchScreenEvent002()};
741 ASSERT_TRUE(pointerEvent != nullptr);
742 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
743 ASSERT_EQ(pointerEvent->GetSourceType(), PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
744 }
745
746 /**
747 * @tc.name: InputManagerTest_UpdateDisplayInfo
748 * @tc.desc: Update window information
749 * @tc.type: FUNC
750 * @tc.require:
751 */
752 HWTEST_F(InputManagerTest, InputManagerTest_UpdateDisplayInfo, TestSize.Level1)
753 {
754 CALL_TEST_DEBUG;
755 DisplayGroupInfo displayGroupInfo;
756 displayGroupInfo.focusWindowId = 0;
757 displayGroupInfo.width = 0;
758 displayGroupInfo.height = 0;
759 InputManager::GetInstance()->UpdateDisplayInfo(displayGroupInfo);
760 ASSERT_TRUE(displayGroupInfo.displaysInfo.empty());
761 }
762
763 /**
764 * @tc.name: InputManagerTest_UpdateDisplayInfo for 1 display and 1 window
765 * @tc.desc: Update window information
766 * @tc.type: FUNC
767 * @tc.require:
768 */
769 HWTEST_F(InputManagerTest, InputManagerTest_UpdateDisplayInfo001, TestSize.Level1)
770 {
771 CALL_TEST_DEBUG;
772 DisplayGroupInfo displayGroupInfo;
773 displayGroupInfo.focusWindowId = 1;
774 displayGroupInfo.width = 1000;
775 displayGroupInfo.height = 2000;
776 DisplayInfo displayInfo;
777 displayInfo.id = 0;
778 displayInfo.x =1;
779 displayInfo.y = 1;
780 displayInfo.width = 2;
781 displayInfo.height = 2;
782 displayInfo.dpi = 240;
783 displayInfo.name = "pp";
784 displayInfo.uniq = "pp";
785 displayInfo.direction = DIRECTION0;
786 displayGroupInfo.displaysInfo.push_back(displayInfo);
787 WindowInfo info;
788 info.id = 1;
789 info.pid = 1;
790 info.uid = 1;
791 info.area = {1, 1, 1, 1};
792 info.defaultHotAreas = { info.area };
793 info.pointerHotAreas = { info.area };
794 info.pointerChangeAreas = {16, 5, 16, 5, 16, 5, 16, 5};
795 info.transform = {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f};
796 info.agentWindowId = 1;
797 info.flags = 0;
798 info.displayId = 0;
799 displayGroupInfo.windowsInfo.push_back(info);
800 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateDisplayInfo(displayGroupInfo));
801 }
802
803 /**
804 * @tc.name: InputManagerTest_UpdateDisplayInfo for 1 display and max-windows
805 * @tc.desc: Update window information
806 * @tc.type: FUNC
807 * @tc.require:
808 */
809 HWTEST_F(InputManagerTest, InputManagerTest_UpdateDisplayInfo002, TestSize.Level1)
810 {
811 CALL_TEST_DEBUG;
812 DisplayGroupInfo displayGroupInfo;
813 displayGroupInfo.focusWindowId = 0;
814 displayGroupInfo.width = 1000;
815 displayGroupInfo.height = 2000;
816 DisplayInfo displayInfo;
817 displayInfo.id = 0;
818 displayInfo.x =1;
819 displayInfo.y = 1;
820 displayInfo.width = 2;
821 displayInfo.height = 2;
822 displayInfo.dpi = 240;
823 displayInfo.name = "pp";
824 displayInfo.uniq = "pp";
825 displayInfo.direction = DIRECTION0;
826 displayInfo.displayMode = DisplayMode::FULL;
827 displayGroupInfo.displaysInfo.push_back(displayInfo);
828 for (uint32_t i = 0; i < MAX_WINDOW_NUMS; i++) {
829 WindowInfo info;
830 info.id = i + 1;
831 info.pid = 1;
832 info.uid = 1;
833 info.area = {1, 1, 1, 1};
834 info.defaultHotAreas = { info.area };
835 info.pointerHotAreas = { info.area };
836 info.pointerChangeAreas = {16, 5, 16, 5, 16, 5, 16, 5};
837 info.transform = {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f};
838 info.agentWindowId = 1;
839 info.flags = 0;
840 info.displayId = 0;
841 info.zOrder = static_cast<float>(MAX_WINDOW_NUMS - i);
842 displayGroupInfo.windowsInfo.push_back(info);
843 }
844 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateDisplayInfo(displayGroupInfo));
845 }
846
847 /**
848 * @tc.name: InputManagerTest_UpdateDisplayInfo for 1 display and 1 window
849 * @tc.desc: Update window information
850 * @tc.type: FUNC
851 * @tc.require:
852 */
853 HWTEST_F(InputManagerTest, InputManagerTest_UpdateDisplayInfo003, TestSize.Level1)
854 {
855 CALL_TEST_DEBUG;
856 DisplayGroupInfo displayGroupInfo;
857 displayGroupInfo.focusWindowId = 1;
858 displayGroupInfo.width = 1000;
859 displayGroupInfo.height = 2000;
860 DisplayInfo displayInfo;
861 for (uint32_t i = 0; i < 2; i++) { // one is default-display and another is simulate display
862 displayInfo.id = i;
863 displayInfo.x =1;
864 displayInfo.y = 1;
865 displayInfo.width = 2;
866 displayInfo.height = 2;
867 displayInfo.dpi = 240;
868 displayInfo.name = "pp";
869 displayInfo.uniq = "pp";
870 displayInfo.direction = DIRECTION0;
871 displayGroupInfo.displaysInfo.push_back(displayInfo);
872 }
873 WindowInfo info;
874 for (uint32_t i = 0; i < 2; i++) { // 2 widnows for 2 display
875 info.id = 1;
876 info.pid = 1;
877 info.uid = 1;
878 info.defaultHotAreas = { {1, 1, 1, 1} };
879 info.agentWindowId = 1;
880 info.flags = 0;
881 info.displayId = i;
882 displayGroupInfo.windowsInfo.push_back(info);
883 }
884 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateDisplayInfo(displayGroupInfo));
885 }
886
887 /**
888 * @tc.name: InputManagerTest_UpdateWindowGroupInfo_001
889 * @tc.desc: Update window information
890 * @tc.type: FUNC
891 * @tc.require:
892 */
893 HWTEST_F(InputManagerTest, InputManagerTest_UpdateWindowGroupInfo_001, TestSize.Level1)
894 {
895 CALL_TEST_DEBUG;
896 WindowInfo window;
897 window.id = 1;
898 window.action = WINDOW_UPDATE_ACTION::ADD;
899 WindowGroupInfo windowGroupInfo;
900 windowGroupInfo.displayId = 0;
901 windowGroupInfo.focusWindowId = 1;
902 windowGroupInfo.windowsInfo = {window};
903 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateWindowInfo(windowGroupInfo));
904 }
905
906 /**
907 * @tc.name: InputManagerTest_UpdateWindowGroupInfo_002
908 * @tc.desc: Update window information
909 * @tc.type: FUNC
910 * @tc.require:
911 */
912 HWTEST_F(InputManagerTest, InputManagerTest_UpdateWindowGroupInfo_002, TestSize.Level1)
913 {
914 CALL_TEST_DEBUG;
915 WindowInfo window;
916 window.id = 1;
917 window.action = WINDOW_UPDATE_ACTION::CHANGE;
918 WindowGroupInfo windowGroupInfo;
919 windowGroupInfo.windowsInfo = {window};
920 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateWindowInfo(windowGroupInfo));
921 }
922
923 /**
924 * @tc.name: InputManagerTest_UpdateWindowGroupInfo_003
925 * @tc.desc: Update window information
926 * @tc.type: FUNC
927 * @tc.require:
928 */
929 HWTEST_F(InputManagerTest, InputManagerTest_UpdateWindowGroupInfo_003, TestSize.Level1)
930 {
931 CALL_TEST_DEBUG;
932 WindowInfo window;
933 window.id = 1;
934 window.action = WINDOW_UPDATE_ACTION::DEL;
935 WindowGroupInfo windowGroupInfo;
936 windowGroupInfo.windowsInfo = {window};
937 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateWindowInfo(windowGroupInfo));
938 }
939
940 /**
941 * @tc.name: InputManagerTest_UpdateWindowGroupInfo_004
942 * @tc.desc: Update window information
943 * @tc.type: FUNC
944 * @tc.require:
945 */
946 HWTEST_F(InputManagerTest, InputManagerTest_UpdateWindowGroupInfo_004, TestSize.Level1)
947 {
948 CALL_TEST_DEBUG;
949 WindowInfo window;
950 window.id = 1;
951 window.action = WINDOW_UPDATE_ACTION::UNKNOWN;
952
953 WindowGroupInfo windowGroupInfo;
954 windowGroupInfo.windowsInfo = {window};
955 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateWindowInfo(windowGroupInfo));
956 }
957
958 /**
959 * @tc.name: InputManagerTest_UpdateWindowGroupInfo_005
960 * @tc.desc: Update window information
961 * @tc.type: FUNC
962 * @tc.require:
963 */
964 HWTEST_F(InputManagerTest, InputManagerTest_UpdateWindowGroupInfo_005, TestSize.Level1)
965 {
966 CALL_TEST_DEBUG;
967 WindowInfo window;
968 window.id = 1;
969 window.action = WINDOW_UPDATE_ACTION::CHANGE;
970 #ifdef OHOS_BUILD_ENABLE_ANCO
971 window.flags |= SHELL_FLAGS_VALUE;
972 #endif // OHOS_BUILD_ENABLE_ANCO
973 WindowGroupInfo windowGroupInfo;
974 windowGroupInfo.windowsInfo = {window};
975 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateWindowInfo(windowGroupInfo));
976 }
977
978 #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT
979 /**
980 * @tc.name: InputManagerTest_SetEnhanceConfig_001
981 * @tc.desc: Set Secutity component enhance config
982 * @tc.type: FUNC
983 * @tc.require:
984 */
985 HWTEST_F(InputManagerTest, InputManagerTest_SetEnhanceConfig_001, TestSize.Level1)
986 {
987 CALL_TEST_DEBUG;
988 uint8_t cfgData[16] = {0};
989 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->SetEnhanceConfig(cfgData, 16));
990 }
991 #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT
992
993 /**
994 * @tc.name: InputManagerTest_GetDevice_001
995 * @tc.desc: Verify the fetch device info
996 * @tc.type: FUNC
997 * @tc.require:
998 */
999 HWTEST_F(InputManagerTest, InputManagerTest_GetDevice_001, TestSize.Level1)
1000 {
1001 CALL_TEST_DEBUG;
1002 int32_t deviceId = 0;
__anon5b702e150c02(std::shared_ptr<InputDevice> inputDevice) 1003 auto callback = [](std::shared_ptr<InputDevice> inputDevice) {
1004 MMI_HILOGD("Get device success");
1005 ASSERT_TRUE(inputDevice != nullptr);
1006 };
1007 InputManager::GetInstance()->GetDevice(deviceId, callback);
1008 }
1009
1010 /**
1011 * @tc.name: InputManagerTest_GetDevice_002
1012 * @tc.desc: Verify the fetch device info
1013 * @tc.type: FUNC
1014 * @tc.require:
1015 */
1016 HWTEST_F(InputManagerTest, InputManagerTest_GetDevice_002, TestSize.Level1)
1017 {
1018 CALL_TEST_DEBUG;
1019 int32_t deviceId = INVAID_VALUE;
__anon5b702e150d02(std::shared_ptr<InputDevice> inputDevice) 1020 auto callback = [](std::shared_ptr<InputDevice> inputDevice) {
1021 MMI_HILOGD("Get device success");
1022 ASSERT_TRUE(inputDevice != nullptr);
1023 };
1024 int32_t ret = InputManager::GetInstance()->GetDevice(deviceId, callback);
1025 ASSERT_NE(ret, RET_OK);
1026 }
1027
1028 /**
1029 * @tc.name: InputManagerTest_GetDeviceIds
1030 * @tc.desc: Verify the fetch device list
1031 * @tc.type: FUNC
1032 * @tc.require:
1033 */
1034 HWTEST_F(InputManagerTest, InputManagerTest_GetDeviceIds, TestSize.Level1)
1035 {
1036 CALL_TEST_DEBUG;
__anon5b702e150e02(std::vector<int32_t> ids) 1037 auto callback = [](std::vector<int32_t> ids) { MMI_HILOGD("Get device success"); };
1038 int32_t ret = InputManager::GetInstance()->GetDeviceIds(callback);
1039 ASSERT_EQ(ret, RET_OK);
1040 }
1041
1042 /**
1043 * @tc.name: InputManagerTest_EventTypeToString
1044 * @tc.desc: Verify inputevent interface
1045 * @tc.type: FUNC
1046 * @tc.require:
1047 */
1048 HWTEST_F(InputManagerTest, InputManagerTest_EventTypeToString, TestSize.Level1)
1049 {
1050 CALL_TEST_DEBUG;
1051 auto inputEvent = InputEvent::Create();
1052 ASSERT_NE(inputEvent, nullptr);
1053 auto ret = inputEvent->EventTypeToString(InputEvent::EVENT_TYPE_BASE);
1054 ASSERT_STREQ(ret, "base");
1055 ret = inputEvent->EventTypeToString(InputEvent::EVENT_TYPE_KEY);
1056 ASSERT_STREQ(ret, "key");
1057 ret = inputEvent->EventTypeToString(InputEvent::EVENT_TYPE_AXIS);
1058 ASSERT_STREQ(ret, "axis");
1059 ret = inputEvent->EventTypeToString(INVAID_VALUE);
1060 ASSERT_STREQ(ret, "unknown");
1061 }
1062
1063 /**
1064 * @tc.name: InputManagerTest_InputDeviceInterface_001
1065 * @tc.desc: Verify inputdevice interface
1066 * @tc.type: FUNC
1067 * @tc.require:
1068 */
1069 HWTEST_F(InputManagerTest, InputManagerTest_InputDeviceInterface_001, TestSize.Level1)
1070 {
1071 CALL_TEST_DEBUG;
1072 std::shared_ptr<InputDevice> inputDevice = std::make_shared<InputDevice>();
1073 ASSERT_NE(inputDevice, nullptr);
1074 inputDevice->SetId(0);
1075 ASSERT_EQ(inputDevice->GetId(), 0);
1076 inputDevice->SetName("name");
1077 ASSERT_STREQ(inputDevice->GetName().c_str(), "name");
1078 inputDevice->SetType(0);
1079 ASSERT_EQ(inputDevice->GetType(), 0);
1080 inputDevice->SetBus(0);
1081 ASSERT_EQ(inputDevice->GetBus(), 0);
1082 inputDevice->SetVersion(0);
1083 ASSERT_EQ(inputDevice->GetVersion(), 0);
1084 inputDevice->SetProduct(0);
1085 ASSERT_EQ(inputDevice->GetProduct(), 0);
1086 inputDevice->SetVendor(0);
1087 ASSERT_EQ(inputDevice->GetVendor(), 0);
1088 inputDevice->SetPhys("phys");
1089 ASSERT_STREQ(inputDevice->GetPhys().c_str(), "phys");
1090 inputDevice->SetUniq("uniq");
1091 ASSERT_STREQ(inputDevice->GetUniq().c_str(), "uniq");
1092 }
1093
1094 /**
1095 * @tc.name: InputManagerTest_InputDeviceInterface_002
1096 * @tc.desc: Verify inputdevice interface
1097 * @tc.type: FUNC
1098 * @tc.require:
1099 */
1100 HWTEST_F(InputManagerTest, InputManagerTest_InputDeviceInterface_002, TestSize.Level1)
1101 {
1102 CALL_TEST_DEBUG;
1103 std::shared_ptr<InputDevice> inputDevice = std::make_shared<InputDevice>();
1104 ASSERT_NE(inputDevice, nullptr);
1105 InputDevice::AxisInfo axis;
1106 axis.SetAxisType(0);
1107 axis.SetMinimum(0);
1108 axis.SetMaximum(1);
1109 axis.SetFuzz(0);
1110 axis.SetFlat(1);
1111 axis.SetResolution(0);
1112 inputDevice->AddAxisInfo(axis);
1113 auto iter = inputDevice->GetAxisInfo();
1114 ASSERT_EQ(iter[0].GetAxisType(), 0);
1115 ASSERT_EQ(iter[0].GetMinimum(), 0);
1116 ASSERT_EQ(iter[0].GetMaximum(), 1);
1117 ASSERT_EQ(iter[0].GetFuzz(), 0);
1118 ASSERT_EQ(iter[0].GetFlat(), 1);
1119 ASSERT_EQ(iter[0].GetResolution(), 0);
1120 }
1121
1122 /**
1123 * @tc.name: InputManagerTest_SetAnrObserver
1124 * @tc.desc: Verify the observer for events
1125 * @tc.type: FUNC
1126 * @tc.require:
1127 */
1128 HWTEST_F(InputManagerTest, InputManagerTest_SetAnrObserver, TestSize.Level1)
1129 {
1130 CALL_TEST_DEBUG;
1131 class IAnrObserverTest : public IAnrObserver {
1132 public:
IAnrObserverTest()1133 IAnrObserverTest() : IAnrObserver()
1134 {}
~IAnrObserverTest()1135 virtual ~IAnrObserverTest()
1136 {}
OnAnr(int32_t pid,int32_t eventId) const1137 void OnAnr(int32_t pid, int32_t eventId) const override
1138 {
1139 MMI_HILOGD("Set anr success");
1140 };
1141 };
1142
1143 std::shared_ptr<IAnrObserverTest> observer = std::make_shared<IAnrObserverTest>();
1144 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->SetAnrObserver(observer));
1145 }
1146
1147 /**
1148 * @tc.name: InputManagerTest_EnableInputDevice_001
1149 * @tc.desc: Enable input device
1150 * @tc.type: FUNC
1151 * @tc.require:
1152 */
1153 HWTEST_F(InputManagerTest, InputManagerTest_EnableInputDevice_001, TestSize.Level1)
1154 {
1155 CALL_TEST_DEBUG;
1156 auto ret = InputManager::GetInstance()->EnableInputDevice(false);
1157 ASSERT_EQ(ret, RET_OK);
1158 ret = InputManager::GetInstance()->EnableInputDevice(true);
1159 ASSERT_EQ(ret, RET_OK);
1160 }
1161
1162 /**
1163 * @tc.name: InputManagerTest_SensorInputTime_001
1164 * @tc.desc: Test SensorTime
1165 * @tc.type: FUNC
1166 * @tc.require:
1167 */
1168 HWTEST_F(InputManagerTest, InputManagerTest_SensorInputTime_001, TestSize.Level1)
1169 {
1170 CALL_TEST_DEBUG;
1171 auto pointerEvent = PointerEvent::Create();
1172 ASSERT_TRUE(pointerEvent != nullptr);
1173 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1174 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1175 pointerEvent->SetPointerId(0);
1176 pointerEvent->SetSensorInputTime(POINTER_SENSOR_INPUT_TIME);
1177 ASSERT_TRUE(pointerEvent->GetSensorInputTime() == POINTER_SENSOR_INPUT_TIME);
1178 }
1179
1180 /**
1181 * @tc.name: InputManagerTest_GetDisplayBindInfo_001
1182 * @tc.desc: Get diaplay bind information
1183 * @tc.type: FUNC
1184 * @tc.require:
1185 */
1186 HWTEST_F(InputManagerTest, InputManagerTest_GetDisplayBindInfo_001, TestSize.Level1)
1187 {
1188 CALL_TEST_DEBUG;
1189 OHOS::MMI::DisplayBindInfos infos;
1190 int32_t ret = InputManager::GetInstance()->GetDisplayBindInfo(infos);
1191 ASSERT_TRUE(ret == RET_OK);
1192 if (ret != RET_OK) {
1193 MMI_HILOGE("Call GetDisplayBindInfo failed, ret:%{public}d", ret);
1194 }
1195 }
1196
1197 /**
1198 * @tc.name: InputManagerTest_SetDisplayBind_001
1199 * @tc.desc: Set diaplay bind information
1200 * @tc.type: FUNC
1201 * @tc.require:
1202 */
1203 HWTEST_F(InputManagerTest, InputManagerTest_SetDisplayBind_001, TestSize.Level1)
1204 {
1205 CALL_TEST_DEBUG;
1206 int32_t deviceId = DEFAULT_DEVICE_ID;
1207 int32_t displayId = INVAID_VALUE;
1208 std::string msg;
1209 int32_t ret = InputManager::GetInstance()->SetDisplayBind(deviceId, displayId, msg);
1210 ASSERT_TRUE(ret == RET_OK);
1211 if (ret != RET_OK) {
1212 MMI_HILOGE("Call SetDisplayBind failed, ret:%{public}d", ret);
1213 }
1214 }
1215
1216 /**
1217 * @tc.name: InputManagerTest_MarkConsumed_001
1218 * @tc.desc: Mark Cosumer
1219 * @tc.type: FUNC
1220 * @tc.require:
1221 */
1222 HWTEST_F(InputManagerTest, InputManagerTest_MarkConsumed_001, TestSize.Level1)
1223 {
1224 CALL_TEST_DEBUG;
1225 auto consumer = GetPtr<InputEventConsumer>();
1226 ASSERT_TRUE(consumer != nullptr);
1227 int32_t monitorId = InputManager::GetInstance()->AddMonitor(consumer);
1228 auto pointerEvent = PointerEvent::Create();
1229 ASSERT_TRUE(pointerEvent != nullptr);
1230 auto eventId = pointerEvent->GetId();
1231 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->MarkConsumed(monitorId, eventId));
1232 }
1233
1234 /**
1235 * @tc.name: InputManagerTest_EnterCaptureMode_001
1236 * @tc.desc: Entering capture mode.
1237 * @tc.type: FUNC
1238 * @tc.require:
1239 */
1240 HWTEST_F(InputManagerTest, InputManagerTest_EnterCaptureMode_001, TestSize.Level1)
1241 {
1242 CALL_TEST_DEBUG;
1243 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1244 CHKPV(window);
1245 uint32_t windowId = window->GetWindowId();
1246 int32_t ret = InputManager::GetInstance()->EnterCaptureMode(windowId);
1247 ASSERT_TRUE(ret == RET_OK);
1248 if (ret != RET_OK) {
1249 MMI_HILOGE("Call EnterCaptureMode failed, ret:%{public}d", ret);
1250 }
1251 }
1252
1253 /**
1254 * @tc.name: InputManagerTest_LeaveCaptureMode_001
1255 * @tc.desc: Leaving capture mode.
1256 * @tc.type: FUNC
1257 * @tc.require:
1258 */
1259 HWTEST_F(InputManagerTest, InputManagerTest_LeaveCaptureMode_001, TestSize.Level1)
1260 {
1261 CALL_TEST_DEBUG;
1262 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1263 CHKPV(window);
1264 uint32_t windowId = window->GetWindowId();
1265 int32_t ret = InputManager::GetInstance()->LeaveCaptureMode(windowId);
1266 ASSERT_TRUE(ret == RET_OK);
1267 if (ret != RET_OK) {
1268 MMI_HILOGE("Call LeaveCaptureMode failed, ret:%{public}d", ret);
1269 }
1270 }
1271
1272 /**
1273 * @tc.name: InputManagerTest_GetWindowPid_001
1274 * @tc.desc: Get window pid.
1275 * @tc.type: FUNC
1276 * @tc.require:
1277 */
1278 HWTEST_F(InputManagerTest, InputManagerTest_GetWindowPid_001, TestSize.Level1)
1279 {
1280 CALL_TEST_DEBUG;
1281 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1282 CHKPV(window);
1283 uint32_t windowId = window->GetWindowId();
1284 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->GetWindowPid(windowId));
1285 int32_t ret = InputManager::GetInstance()->GetWindowPid(windowId);
1286 if (ret == RET_ERR) {
1287 MMI_HILOGE("Call GetWindowPid failed, ret:%{public}d", ret);
1288 }
1289 }
1290
1291 /**
1292 * @tc.name: InputManagerTest_SetHoverScrollState_001
1293 * @tc.desc: Set hover scroll state
1294 * @tc.type: FUNC
1295 * @tc.require:
1296 */
1297 HWTEST_F(InputManagerTest, InputManagerTest_SetHoverScrollState_001, TestSize.Level1)
1298 {
1299 CALL_TEST_DEBUG;
1300 auto ret = InputManager::GetInstance()->SetHoverScrollState(false);
1301 ASSERT_EQ(ret, RET_OK);
1302 ret = InputManager::GetInstance()->SetHoverScrollState(true);
1303 ASSERT_EQ(ret, RET_OK);
1304 }
1305
1306 /**
1307 * @tc.name: InputManagerTest_GetHoverScrollState_001
1308 * @tc.desc: Get hover scroll state
1309 * @tc.type: FUNC
1310 * @tc.require:
1311 */
1312 HWTEST_F(InputManagerTest, InputManagerTest_GetHoverScrollState_001, TestSize.Level1)
1313 {
1314 CALL_TEST_DEBUG;
1315 bool statefalse = false;
1316 auto ret = InputManager::GetInstance()->GetHoverScrollState(statefalse);
1317 ASSERT_EQ(ret, RET_OK);
1318 bool statetrue = true;
1319 ret = InputManager::GetInstance()->GetHoverScrollState(statetrue);
1320 ASSERT_EQ(ret, RET_OK);
1321 }
1322
1323 /**
1324 * @tc.name: InputManagerTest_SetPointerVisible_001
1325 * @tc.desc: Set pointer visible
1326 * @tc.type: FUNC
1327 * @tc.require:
1328 */
1329 HWTEST_F(InputManagerTest, InputManagerTest_SetPointerVisible_001, TestSize.Level1)
1330 {
1331 CALL_TEST_DEBUG;
1332 auto ret = InputManager::GetInstance()->SetPointerVisible(false);
1333 ASSERT_EQ(ret, RET_OK);
1334 bool isVisible{true};
1335 if (InputManager::GetInstance()->SetPointerVisible(isVisible) == RET_OK) {
1336 ASSERT_TRUE(InputManager::GetInstance()->IsPointerVisible() == isVisible);
1337 }
1338 }
1339
1340 /**
1341 * @tc.name: InputManagerTest_IsPointerVisible_001
1342 * @tc.desc: Test flag `InputEvent::EVENT_FLAG_HIDE_POINTER` on controlling pointer visibility
1343 * @tc.type: FUNC
1344 * @tc.require:
1345 */
1346 HWTEST_F(InputManagerTest, InputManagerTest_IsPointerVisible_001, TestSize.Level1)
1347 {
1348 CALL_TEST_DEBUG;
1349 PointerEvent::PointerItem item;
1350 item.SetPointerId(0);
1351 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_ONE);
1352 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_ONE);
1353
1354 auto pointerEvent = PointerEvent::Create();
1355 ASSERT_NE(pointerEvent, nullptr);
1356 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1357 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1358 pointerEvent->AddFlag(InputEvent::EVENT_FLAG_HIDE_POINTER);
1359 pointerEvent->SetPointerId(0);
1360 pointerEvent->AddPointerItem(item);
1361
1362 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
1363 ASSERT_TRUE(InputManager::GetInstance()->IsPointerVisible());
1364 }
1365
1366 /**
1367 * @tc.name: InputManagerTest_IsPointerVisible_002
1368 * @tc.desc: Test flag `InputEvent::EVENT_FLAG_HIDE_POINTER` on controlling pointer visibility
1369 * @tc.type: FUNC
1370 * @tc.require:
1371 */
1372 HWTEST_F(InputManagerTest, InputManagerTest_IsPointerVisible_002, TestSize.Level1)
1373 {
1374 CALL_TEST_DEBUG;
1375 PointerEvent::PointerItem item;
1376 item.SetPointerId(0);
1377 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_TWO);
1378 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_TWO);
1379
1380 auto pointerEvent = PointerEvent::Create();
1381 ASSERT_NE(pointerEvent, nullptr);
1382 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1383 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1384 pointerEvent->SetPointerId(0);
1385 pointerEvent->AddPointerItem(item);
1386
1387 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
1388 ASSERT_TRUE(InputManager::GetInstance()->IsPointerVisible());
1389 }
1390
1391 /**
1392 * @tc.name: InputManagerTest_SetTouchpadScrollSwitch_001
1393 * @tc.desc: Set touchpad scroll switch
1394 * @tc.type: FUNC
1395 * @tc.require:
1396 */
1397 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadScrollSwitch_001, TestSize.Level1)
1398 {
1399 CALL_TEST_DEBUG;
1400 auto ret = InputManager::GetInstance()->SetTouchpadScrollSwitch(false);
1401 ASSERT_EQ(ret, RET_OK);
1402 ret = InputManager::GetInstance()->SetTouchpadScrollSwitch(true);
1403 ASSERT_EQ(ret, RET_OK);
1404 }
1405
1406 /**
1407 * @tc.name: InputManagerTest_GetTouchpadScrollSwitch_001
1408 * @tc.desc: Get touchpad scroll switch
1409 * @tc.type: FUNC
1410 * @tc.require:
1411 */
1412 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadScrollSwitch_001, TestSize.Level1)
1413 {
1414 CALL_TEST_DEBUG;
1415 bool flagfalse = false;
1416 auto ret = InputManager::GetInstance()->GetTouchpadScrollSwitch(flagfalse);
1417 ASSERT_EQ(ret, RET_OK);
1418 bool flagtrue = true;
1419 ret = InputManager::GetInstance()->GetTouchpadScrollSwitch(flagtrue);
1420 ASSERT_EQ(ret, RET_OK);
1421 }
1422
1423 /**
1424 * @tc.name: InputManagerTest_SetTouchpadScrollDirection_001
1425 * @tc.desc: Set touchpad scroll direction
1426 * @tc.type: FUNC
1427 * @tc.require:
1428 */
1429 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadScrollDirection_001, TestSize.Level1)
1430 {
1431 CALL_TEST_DEBUG;
1432 auto ret = InputManager::GetInstance()->SetTouchpadScrollDirection(false);
1433 ASSERT_EQ(ret, RET_OK);
1434 ret = InputManager::GetInstance()->SetTouchpadScrollDirection(true);
1435 ASSERT_EQ(ret, RET_OK);
1436 }
1437
1438 /**
1439 * @tc.name: InputManagerTest_GetTouchpadScrollDirection_001
1440 * @tc.desc: Get touchpad scroll direction
1441 * @tc.type: FUNC
1442 * @tc.require:
1443 */
1444 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadScrollDirection_001, TestSize.Level1)
1445 {
1446 CALL_TEST_DEBUG;
1447 bool statefalse = false;
1448 auto ret = InputManager::GetInstance()->GetTouchpadScrollDirection(statefalse);
1449 ASSERT_EQ(ret, RET_OK);
1450 bool statetrue = true;
1451 ret = InputManager::GetInstance()->GetTouchpadScrollDirection(statetrue);
1452 ASSERT_EQ(ret, RET_OK);
1453 }
1454
1455 /**
1456 * @tc.name: InputManagerTest_SetPointerSpeed_001
1457 * @tc.desc: Set pointer speed
1458 * @tc.type: FUNC
1459 * @tc.require:
1460 */
1461 HWTEST_F(InputManagerTest, InputManagerTest_SetPointerSpeed_001, TestSize.Level1)
1462 {
1463 CALL_TEST_DEBUG;
1464 const int32_t speed = INVAID_VALUE;
1465 InputManager::GetInstance()->SetPointerSpeed(speed);
1466 int32_t speed1;
1467 InputManager::GetInstance()->GetPointerSpeed(speed1);
1468 ASSERT_EQ(speed1, 1);
1469 }
1470
1471 /**
1472 * @tc.name: InputManagerTest_SetPointerLocation_001
1473 * @tc.desc: Set pointer location
1474 * @tc.type: FUNC
1475 * @tc.require:
1476 */
1477 HWTEST_F(InputManagerTest, InputManagerTest_SetPointerLocation_001, TestSize.Level1)
1478 {
1479 CALL_TEST_DEBUG;
1480 int32_t x = 0;
1481 int32_t y = 0;
1482 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->SetPointerLocation(x, y));
1483 }
1484
1485 /**
1486 * @tc.name: InputManagerTest_GetTouchpadRightClickType_001
1487 * @tc.desc: Get touchpad right click type
1488 * @tc.type: FUNC
1489 * @tc.require:
1490 */
1491 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadRightClickType_001, TestSize.Level1)
1492 {
1493 CALL_TEST_DEBUG;
1494 int32_t newType = 1;
1495 int32_t ret = InputManager::GetInstance()->GetTouchpadRightClickType(newType);
1496 ASSERT_EQ(ret, RET_OK);
1497 }
1498
1499 /**
1500 * @tc.name: InputManagerTest_GetKeyState_001
1501 * @tc.desc: Get key state
1502 * @tc.type: FUNC
1503 * @tc.require:
1504 */
1505 HWTEST_F(InputManagerTest, InputManagerTest_GetKeyState_001, TestSize.Level1)
1506 {
1507 CALL_TEST_DEBUG;
1508 std::vector<int32_t> pressedKeys;
1509 std::map<int32_t, int32_t> specialKeysState;
1510 int32_t ret = InputManager::GetInstance()->GetKeyState(pressedKeys, specialKeysState);
1511 ASSERT_EQ(ret, RET_OK);
1512 }
1513
1514 /**
1515 * @tc.name: InputManagerTest_MarkProcessed_001
1516 * @tc.desc: Mark processed
1517 * @tc.type: FUNC
1518 * @tc.require:
1519 */
1520 HWTEST_F(InputManagerTest, InputManagerTest_MarkProcessed_001, TestSize.Level1)
1521 {
1522 CALL_TEST_DEBUG;
1523 int32_t x = 0;
1524 int64_t y = 0;
1525 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->MarkProcessed(x, y));
1526 }
1527
1528 /**
1529 * @tc.name: InputManagerTest_SetCustomCursor
1530 * @tc.desc: Test set the wrong windowId for SetCustomCursor
1531 * @tc.type: FUNC
1532 * @tc.require:
1533 */
1534 HWTEST_F(InputManagerTest, InputManagerTest_SetCustomCursor, TestSize.Level1)
1535 {
1536 CALL_TEST_DEBUG;
1537 int32_t fakeWindowId = 100;
1538 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
1539 PointerStyle pointerStyle;
1540 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
1541 ASSERT_NE(pixelMap, nullptr);
1542 pointerStyle.id = MOUSE_ICON::DEVELOPER_DEFINED_ICON;
1543 ASSERT_TRUE(InputManager::GetInstance()->SetCustomCursor(fakeWindowId, (void *)pixelMap.get(), 32, 32) == RET_ERR);
1544 }
1545
1546 /**
1547 * @tc.name: InputManagerTest_SetMouseIcon
1548 * @tc.desc: Test set the wrong windowId for SetMouseIcon
1549 * @tc.type: FUNC
1550 * @tc.require:
1551 */
1552 HWTEST_F(InputManagerTest, InputManagerTest_SetMouseIcon, TestSize.Level1)
1553 {
1554 CALL_TEST_DEBUG;
1555 int32_t fakeWindoId = 100;
1556 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
1557 PointerStyle pointerStyle;
1558 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
1559 ASSERT_NE(pixelMap, nullptr);
1560 pointerStyle.id = MOUSE_ICON::DEVELOPER_DEFINED_ICON;
1561 ASSERT_FALSE(InputManager::GetInstance()->SetMouseIcon(fakeWindoId, (void *)pixelMap.get()) == RET_ERR);
1562 }
1563
1564 /**
1565 * @tc.name: InputManagerTest_SetMouseHotSpot
1566 * @tc.desc: Test set the wrong windowId for SetMouseHotSpot
1567 * @tc.type: FUNC
1568 * @tc.require:
1569 */
1570 HWTEST_F(InputManagerTest, InputManagerTest_SetMouseHotSpot, TestSize.Level1)
1571 {
1572 CALL_TEST_DEBUG;
1573 PointerStyle pointerStyle;
1574 pointerStyle.id = MOUSE_ICON::CROSS;
1575 int32_t fakeWindoId = 100;
1576 int32_t mouseIcon = 20;
1577 ASSERT_TRUE(
1578 InputManager::GetInstance()->SetMouseHotSpot(fakeWindoId, mouseIcon, mouseIcon) == RET_ERR);
1579 }
1580
1581
1582 /**
1583 * @tc.name: InputManagerTest_SetKeyDownDuration_001
1584 * @tc.desc: Customize the delay time for starting the ability by using the shortcut key.
1585 * @tc.type: FUNC
1586 * @tc.require:
1587 */
1588 HWTEST_F(InputManagerTest, InputManagerTest_SetKeyDownDuration_001, TestSize.Level1)
1589 {
1590 CALL_TEST_DEBUG;
1591 std::string businessId = "";
1592 int32_t delay = KEY_DOWN_DURATION;
1593 ASSERT_EQ(PARAMETER_ERROR, InputManager::GetInstance()->SetKeyDownDuration(businessId, delay));
1594 }
1595
1596 /**
1597 * @tc.name: InputManagerTest_UnsubscribeSwitchEvent_001
1598 * @tc.desc: Unsubscribes from a switch input event.
1599 * @tc.type: FUNC
1600 * @tc.require:
1601 */
1602 HWTEST_F(InputManagerTest, InputManagerTest_UnsubscribeSwitchEvent_001, TestSize.Level1)
1603 {
1604 CALL_TEST_DEBUG;
1605 int32_t subscriberId = INVAID_VALUE;
1606 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UnsubscribeSwitchEvent(subscriberId));
1607 }
1608
1609 /**
1610 * @tc.name: InputManagerTest_ClearWindowPointerStyle_001
1611 * @tc.desc: Verify invalid parameter.
1612 * @tc.type: FUNC
1613 * @tc.require:SR000GGQL4 AR000GJNGN
1614 * @tc.author: yangguang
1615 */
1616 HWTEST_F(InputManagerTest, InputManagerTest_ClearWindowPointerStyle_001, TestSize.Level1)
1617 {
1618 CALL_TEST_DEBUG;
1619 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1620 CHKPV(window);
1621 uint32_t windowId = window->GetWindowId();
1622 PointerStyle pointerStyle;
1623 pointerStyle.id = MOUSE_ICON::CROSS;
1624 int32_t ret = InputManager::GetInstance()->SetPointerStyle(windowId, pointerStyle);
1625 InputManager::GetInstance()->ClearWindowPointerStyle(getpid(), windowId);
1626 PointerStyle style;
1627 ret = InputManager::GetInstance()->GetPointerStyle(windowId, style);
1628 EXPECT_TRUE(ret == RET_OK);
1629 }
1630
1631 HWTEST_F(InputManagerTest, InputManagerTest_SyncBundleName_001, TestSize.Level1)
1632 {
1633 CALL_TEST_DEBUG;
1634 auto mmiObserver = std::make_shared<IEventObserver>();
1635 InputManager::GetInstance()->AddInputEventObserver(mmiObserver);
1636 auto callbackPtr = GetPtr<InputEventCallback>();
1637 ASSERT_TRUE(callbackPtr != nullptr);
1638 int32_t monitorId = InputManagerUtil::TestAddMonitor(callbackPtr);
1639 InputManager::GetInstance()->SetNapStatus(10, 20, "bundleName_test", 0);
1640 std::map<std::tuple<int32_t, int32_t, std::string>, int32_t> mapBefore;
1641 InputManager::GetInstance()->GetAllMmiSubscribedEvents(mapBefore);
1642 for (auto map = mapBefore.begin(); map != mapBefore.end(); ++map) {
1643 if (std::get<TUPLE_PID>(map->first) == 10) {
1644 EXPECT_TRUE(std::get<TUPLE_UID>(map->first) == 20);
1645 EXPECT_TRUE(std::get<TUPLE_NAME>(map->first) == "bundleName_test");
1646 EXPECT_TRUE(map->second == 0);
1647 }
1648 }
1649 for (const auto& map : mapBefore) {
1650 MMI_HILOGD("All NapStatus in mapBefore pid:%{public}d, uid:%{public}d, name:%{public}s, status:%{public}d",
1651 std::get<TUPLE_PID>(map.first), std::get<TUPLE_UID>(map.first), std::get<TUPLE_NAME>(map.first).c_str(),
1652 map.second);
1653 }
1654 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1655 InputManagerUtil::TestRemoveMonitor(monitorId);
1656 InputManager::GetInstance()->SetNapStatus(10, 20, "bundleName_test", 2);
1657 std::map<std::tuple<int32_t, int32_t, std::string>, int32_t> mapAfter;
1658 InputManager::GetInstance()->GetAllMmiSubscribedEvents(mapAfter);
1659 for (const auto& map : mapAfter) {
1660 EXPECT_FALSE(std::get<TUPLE_PID>(map.first) == 10);
1661 EXPECT_FALSE(std::get<TUPLE_UID>(map.first) == 20);
1662 EXPECT_FALSE(std::get<TUPLE_NAME>(map.first) == "bundleName_test");
1663 }
1664 for (const auto& map : mapAfter) {
1665 MMI_HILOGD("All NapStatus in mapAfter pid:%{public}d, uid:%{public}d, name:%{public}s, status:%{public}d",
1666 std::get<TUPLE_PID>(map.first), std::get<TUPLE_UID>(map.first), std::get<TUPLE_NAME>(map.first).c_str(),
1667 map.second);
1668 }
1669 InputManager::GetInstance()->RemoveInputEventObserver(mmiObserver);
1670 }
1671
1672 /**
1673 * @tc.name: InputManager_InjectMouseEvent_001
1674 * @tc.desc: Injection interface detection
1675 * @tc.type: FUNC
1676 * @tc.require:AR000GJG6G
1677 */
1678 HWTEST_F(InputManagerTest, InputManager_InjectMouseEvent_001, TestSize.Level1)
1679 {
1680 CALL_TEST_DEBUG;
1681 auto pointerEvent = PointerEvent::Create();
1682 pointerEvent->SetButtonId(PointerEvent::MOUSE_BUTTON_LEFT);
1683 pointerEvent->SetButtonPressed(PointerEvent::MOUSE_BUTTON_LEFT);
1684 ASSERT_NE(pointerEvent, nullptr);
1685
1686 PointerEvent::PointerItem item;
1687 item.SetPointerId(0);
1688 item.SetDisplayX(200);
1689 item.SetDisplayY(200);
1690 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN);
1691 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1692 pointerEvent->SetPointerId(0);
1693 pointerEvent->AddPointerItem(item);
1694 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
1695 }
1696
1697 /**
1698 * @tc.name: InputManager_InjectMouseEvent_002
1699 * @tc.desc: Injection interface detection
1700 * @tc.type: FUNC
1701 * @tc.require:AR000GJG6G
1702 */
1703 HWTEST_F(InputManagerTest, InputManager_InjectMouseEvent_002, TestSize.Level1)
1704 {
1705 CALL_TEST_DEBUG;
1706 auto pointerEvent = PointerEvent::Create();
1707 pointerEvent->SetButtonId(PointerEvent::MOUSE_BUTTON_LEFT);
1708 pointerEvent->SetButtonPressed(PointerEvent::MOUSE_BUTTON_LEFT);
1709 ASSERT_NE(pointerEvent, nullptr);
1710
1711 PointerEvent::PointerItem item;
1712 item.SetPointerId(0);
1713 item.SetDisplayX(200);
1714 item.SetDisplayY(200);
1715 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_UP);
1716 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1717 pointerEvent->SetPointerId(0);
1718 pointerEvent->AddPointerItem(item);
1719 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
1720 }
1721
1722 /**
1723 * @tc.name: InputManager_InjectMouseEvent_003
1724 * @tc.desc: Injection interface detection
1725 * @tc.type: FUNC
1726 * @tc.require:AR000GJG6G
1727 */
1728 HWTEST_F(InputManagerTest, InputManager_InjectMouseEvent_003, TestSize.Level1)
1729 {
1730 CALL_TEST_DEBUG;
1731 auto pointerEvent = PointerEvent::Create();
1732 ASSERT_NE(pointerEvent, nullptr);
1733
1734 PointerEvent::PointerItem item;
1735 item.SetPointerId(0);
1736 item.SetDisplayX(200);
1737 item.SetDisplayY(200);
1738 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1739 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1740 pointerEvent->SetPointerId(0);
1741 pointerEvent->AddPointerItem(item);
1742 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
1743 }
1744
SimulateInputEventInjectKeyTest(int32_t keyAction,int32_t keyCode,bool isPressed,int32_t downTime)1745 static bool SimulateInputEventInjectKeyTest(int32_t keyAction, int32_t keyCode, bool isPressed, int32_t downTime)
1746 {
1747 auto keyEvent = KeyEvent::Create();
1748 if (keyEvent == nullptr) {
1749 return false;
1750 }
1751 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
1752 keyEvent->SetKeyCode(keyCode);
1753
1754 KeyEvent::KeyItem item;
1755 keyEvent->SetKeyAction(keyAction);
1756 item.SetKeyCode(keyCode);
1757 item.SetPressed(isPressed);
1758 item.SetDownTime(downTime);
1759 keyEvent->AddKeyItem(item);
1760 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
1761 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
1762 return true;
1763 }
1764
1765 /**
1766 * @tc.name: InputManager_InjectKeyEvent_001
1767 * @tc.desc: Injection interface detection
1768 * @tc.type: FUNC
1769 * @tc.require:
1770 */
1771 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_001, TestSize.Level1)
1772 {
1773 CALL_TEST_DEBUG;
__anon5b702e150f02(std::shared_ptr<KeyEvent> event) 1774 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
1775 MMI_HILOGD("Add monitor success");
1776 };
1777 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
1778 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
1779 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
1780 KeyEvent::KEYCODE_CALL_NOTIFICATION_CENTER, true, 500));
1781 InputManager::GetInstance()->RemoveMonitor(monitorId);
1782 }
1783
1784 /**
1785 * @tc.name: InputManager_InjectKeyEvent_002
1786 * @tc.desc: Injection interface detection
1787 * @tc.type: FUNC
1788 * @tc.require:
1789 */
1790 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_002, TestSize.Level1)
1791 {
1792 CALL_TEST_DEBUG;
__anon5b702e151002(std::shared_ptr<KeyEvent> event) 1793 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
1794 MMI_HILOGD("Add monitor success");
1795 };
1796 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
1797 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
1798 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
1799 KeyEvent::KEYCODE_CALL_CONTROL_CENTER, true, 500));
1800 InputManager::GetInstance()->RemoveMonitor(monitorId);
1801 }
1802
1803 /**
1804 * @tc.name: InputManager_InjectKeyEvent_003
1805 * @tc.desc: Injection interface detection
1806 * @tc.type: FUNC
1807 * @tc.require:
1808 */
1809 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_003, TestSize.Level1)
1810 {
1811 CALL_TEST_DEBUG;
__anon5b702e151102(std::shared_ptr<KeyEvent> event) 1812 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
1813 MMI_HILOGD("Add monitor success");
1814 };
1815 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
1816 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
1817 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
1818 KeyEvent::KEYCODE_CALL_NOTIFICATION_CENTER, false, 500));
1819 InputManager::GetInstance()->RemoveMonitor(monitorId);
1820 }
1821
1822 /**
1823 * @tc.name: InputManager_InjectKeyEvent_004
1824 * @tc.desc: Injection interface detection
1825 * @tc.type: FUNC
1826 * @tc.require:
1827 */
1828 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_004, TestSize.Level1)
1829 {
1830 CALL_TEST_DEBUG;
__anon5b702e151202(std::shared_ptr<KeyEvent> event) 1831 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
1832 MMI_HILOGD("Add monitor success");
1833 };
1834 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
1835 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
1836 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
1837 KeyEvent::KEYCODE_CALL_CONTROL_CENTER, false, 500));
1838 InputManager::GetInstance()->RemoveMonitor(monitorId);
1839 }
1840
1841 /**
1842 * @tc.name: InputManager_InjectKeyEvent_005
1843 * @tc.desc: Injection interface detection
1844 * @tc.type: FUNC
1845 * @tc.require:
1846 */
1847 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_005, TestSize.Level1)
1848 {
1849 CALL_TEST_DEBUG;
__anon5b702e151302(std::shared_ptr<KeyEvent> event) 1850 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
1851 MMI_HILOGD("Add monitor success");
1852 };
1853 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
1854 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
1855 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
1856 KeyEvent::KEYCODE_CALL_NOTIFICATION_CENTER, true, 1000));
1857 InputManager::GetInstance()->RemoveMonitor(monitorId);
1858 }
1859
1860 /**
1861 * @tc.name: InputManager_InjectKeyEvent_006
1862 * @tc.desc: Injection interface detection
1863 * @tc.type: FUNC
1864 * @tc.require:
1865 */
1866 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_006, TestSize.Level1)
1867 {
1868 CALL_TEST_DEBUG;
__anon5b702e151402(std::shared_ptr<KeyEvent> event) 1869 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
1870 MMI_HILOGD("Add monitor success");
1871 };
1872 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
1873 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
1874 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
1875 KeyEvent::KEYCODE_CALL_CONTROL_CENTER, true, 1000));
1876 InputManager::GetInstance()->RemoveMonitor(monitorId);
1877 }
1878
1879 /**
1880 * @tc.name: InputManager_InjectKeyEvent_007
1881 * @tc.desc: Injection interface detection
1882 * @tc.type: FUNC
1883 * @tc.require:
1884 */
1885 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_007, TestSize.Level1)
1886 {
1887 CALL_TEST_DEBUG;
__anon5b702e151502(std::shared_ptr<KeyEvent> event) 1888 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
1889 MMI_HILOGD("Add monitor success");
1890 };
1891 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
1892 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
1893 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
1894 KeyEvent::KEYCODE_CALL_NOTIFICATION_CENTER, false, 1000));
1895 InputManager::GetInstance()->RemoveMonitor(monitorId);
1896 }
1897
1898 /**
1899 * @tc.name: InputManager_InjectKeyEvent_008
1900 * @tc.desc: Injection interface detection
1901 * @tc.type: FUNC
1902 * @tc.require:
1903 */
1904 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_008, TestSize.Level1)
1905 {
1906 CALL_TEST_DEBUG;
__anon5b702e151602(std::shared_ptr<KeyEvent> event) 1907 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
1908 MMI_HILOGD("Add monitor success");
1909 };
1910 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
1911 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
1912 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
1913 KeyEvent::KEYCODE_CALL_CONTROL_CENTER, false, 1000));
1914 InputManager::GetInstance()->RemoveMonitor(monitorId);
1915 }
1916
1917 /**
1918 * @tc.name: InputManager_InjectKeyEvent_009
1919 * @tc.desc: Injection interface detection
1920 * @tc.type: FUNC
1921 * @tc.require:
1922 */
1923 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_009, TestSize.Level1)
1924 {
1925 CALL_TEST_DEBUG;
__anon5b702e151702(std::shared_ptr<KeyEvent> event) 1926 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
1927 MMI_HILOGD("Add monitor success");
1928 };
1929 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
1930 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
1931 auto keyEvent = KeyEvent::Create();
1932 ASSERT_NE(keyEvent, nullptr);
1933 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
1934
1935 KeyEvent::KeyItem itemFirst;
1936 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1937 keyEvent->SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
1938
1939 itemFirst.SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
1940 itemFirst.SetPressed(false);
1941 itemFirst.SetDownTime(1000);
1942 keyEvent->AddKeyItem(itemFirst);
1943
1944 KeyEvent::KeyItem itemSecond;
1945 itemSecond.SetKeyCode(KeyEvent::KEYCODE_R);
1946 itemSecond.SetPressed(true);
1947 itemSecond.SetDownTime(1000);
1948 keyEvent->AddKeyItem(itemSecond);
1949 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
1950 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
1951 InputManager::GetInstance()->RemoveMonitor(monitorId);
1952 }
1953
1954 /**
1955 * @tc.name: InputManager_InjectKeyEvent_010
1956 * @tc.desc: Injection interface detection
1957 * @tc.type: FUNC
1958 * @tc.require:
1959 */
1960 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_010, TestSize.Level1)
1961 {
1962 CALL_TEST_DEBUG;
__anon5b702e151802(std::shared_ptr<KeyEvent> event) 1963 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
1964 MMI_HILOGD("Add monitor success");
1965 };
1966 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
1967 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
1968 auto keyEvent = KeyEvent::Create();
1969 ASSERT_NE(keyEvent, nullptr);
1970 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
1971
1972 KeyEvent::KeyItem itemFirst;
1973 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1974 keyEvent->SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
1975
1976 itemFirst.SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
1977 itemFirst.SetPressed(false);
1978 itemFirst.SetDownTime(1000);
1979 keyEvent->AddKeyItem(itemFirst);
1980
1981 KeyEvent::KeyItem itemSecond;
1982 itemSecond.SetKeyCode(KeyEvent::KEYCODE_R);
1983 itemSecond.SetPressed(false);
1984 itemSecond.SetDownTime(1000);
1985 keyEvent->AddKeyItem(itemSecond);
1986 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
1987 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
1988 InputManager::GetInstance()->RemoveMonitor(monitorId);
1989 }
1990
1991 /**
1992 * @tc.name: InputManager_InjectKeyEvent_011
1993 * @tc.desc: Injection interface detection
1994 * @tc.type: FUNC
1995 * @tc.require:AR000GJG6G mymy
1996 */
1997 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_011, TestSize.Level1)
1998 {
1999 CALL_TEST_DEBUG;
__anon5b702e151902(std::shared_ptr<KeyEvent> event) 2000 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
2001 MMI_HILOGD("Add monitor success");
2002 };
2003 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
2004 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
2005 auto keyEvent = KeyEvent::Create();
2006 ASSERT_NE(keyEvent, nullptr);
2007 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
2008
2009 KeyEvent::KeyItem itemFirst;
2010 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
2011 keyEvent->SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
2012
2013 itemFirst.SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
2014 itemFirst.SetPressed(false);
2015 itemFirst.SetDownTime(500);
2016 keyEvent->AddKeyItem(itemFirst);
2017
2018 KeyEvent::KeyItem itemSecond;
2019 itemSecond.SetKeyCode(KeyEvent::KEYCODE_R);
2020 itemSecond.SetPressed(false);
2021 itemSecond.SetDownTime(500);
2022 keyEvent->AddKeyItem(itemSecond);
2023 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
2024 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2025 InputManager::GetInstance()->RemoveMonitor(monitorId);
2026 }
2027
2028 /**
2029 * @tc.name: InputManager_InjectKeyEvent_012
2030 * @tc.desc: Injection interface detection
2031 * @tc.type: FUNC
2032 * @tc.require:AR000GJG6G mymy
2033 */
2034 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_012, TestSize.Level1)
2035 {
2036 CALL_TEST_DEBUG;
__anon5b702e151a02(std::shared_ptr<KeyEvent> event) 2037 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
2038 MMI_HILOGD("Add monitor success");
2039 };
2040 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
2041 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
2042 auto keyEvent = KeyEvent::Create();
2043 ASSERT_NE(keyEvent, nullptr);
2044 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
2045
2046 KeyEvent::KeyItem itemFirst;
2047 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
2048 keyEvent->SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
2049
2050 itemFirst.SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
2051 itemFirst.SetPressed(false);
2052 itemFirst.SetDownTime(500);
2053 keyEvent->AddKeyItem(itemFirst);
2054
2055 KeyEvent::KeyItem itemSecond;
2056 itemSecond.SetKeyCode(KeyEvent::KEYCODE_R);
2057 itemSecond.SetPressed(true);
2058 itemSecond.SetDownTime(500);
2059 keyEvent->AddKeyItem(itemSecond);
2060 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
2061 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2062 InputManager::GetInstance()->RemoveMonitor(monitorId);
2063 }
2064
2065 /**
2066 * @tc.name: InputManager_InjectTouchEvent_001
2067 * @tc.desc: Injection interface detection
2068 * @tc.type: FUNC
2069 * @tc.require:AR000GJG6G
2070 */
2071 HWTEST_F(InputManagerTest, InputManager_InjectTouchEvent_001, TestSize.Level1)
2072 {
2073 CALL_TEST_DEBUG;
2074 auto pointerEvent = PointerEvent::Create();
2075 ASSERT_NE(pointerEvent, nullptr);
2076
2077 PointerEvent::PointerItem item;
2078 item.SetPointerId(0);
2079 item.SetDisplayX(200);
2080 item.SetDisplayY(200);
2081 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2082 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2083 pointerEvent->SetPointerId(0);
2084 pointerEvent->AddPointerItem(item);
2085 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2086 }
2087
2088 /**
2089 * @tc.name: InputManager_InjectTouchEvent_002
2090 * @tc.desc: Injection interface detection
2091 * @tc.type: FUNC
2092 * @tc.require:AR000GJG6G
2093 */
2094 HWTEST_F(InputManagerTest, InputManager_InjectTouchEvent_002, TestSize.Level1)
2095 {
2096 CALL_TEST_DEBUG;
2097 auto pointerEvent = PointerEvent::Create();
2098 ASSERT_NE(pointerEvent, nullptr);
2099
2100 PointerEvent::PointerItem item;
2101 item.SetPointerId(0);
2102 item.SetDisplayX(200);
2103 item.SetDisplayY(200);
2104 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2105 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2106 pointerEvent->SetPointerId(0);
2107 pointerEvent->AddPointerItem(item);
2108 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2109 }
2110
2111 /**
2112 * @tc.name: InputManager_InjectEvent_003
2113 * @tc.desc: Injection interface detection
2114 * @tc.type: FUNC
2115 * @tc.require:AR000GJG6G
2116 */
2117 HWTEST_F(InputManagerTest, InputManager_InjectEvent_003, TestSize.Level1)
2118 {
2119 CALL_TEST_DEBUG;
2120 auto keyEvent = KeyEvent::Create();
2121 ASSERT_NE(keyEvent, nullptr);
2122 ASSERT_NO_FATAL_FAILURE(keyEvent->SetRepeat(true));
2123 }
2124
2125 /**
2126 * @tc.name: InputManager_InjectEvent_001
2127 * @tc.desc: Injection interface detection
2128 * @tc.type: FUNC
2129 * @tc.require:AR000GJG6G
2130 */
2131 HWTEST_F(InputManagerTest, InputManager_InjectEvent_001, TestSize.Level1)
2132 {
2133 CALL_TEST_DEBUG;
2134 auto keyEvent = KeyEvent::Create();
2135 ASSERT_NE(keyEvent, nullptr);
2136 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
2137
2138 KeyEvent::KeyItem item;
2139 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
2140 item.SetKeyCode(2017);
2141 item.SetPressed(true);
2142 item.SetDownTime(500);
2143 keyEvent->AddKeyItem(item);
2144 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
2145 }
2146
2147 /**
2148 * @tc.name: InputManager_InjectEvent_002
2149 * @tc.desc: Injection interface detection
2150 * @tc.type: FUNC
2151 * @tc.require:AR000GJG6G
2152 */
2153 HWTEST_F(InputManagerTest, InputManager_InjectEvent_002, TestSize.Level1)
2154 {
2155 CALL_TEST_DEBUG;
2156 auto keyEvent = KeyEvent::Create();
2157 ASSERT_NE(keyEvent, nullptr);
2158 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
2159 std::vector<int32_t> downKey;
2160 downKey.push_back(2072);
2161 downKey.push_back(2017);
2162
2163 KeyEvent::KeyItem item[downKey.size()];
2164 for (size_t i = 0; i < downKey.size(); i++) {
2165 keyEvent->SetKeyCode(2072);
2166 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
2167 item[i].SetKeyCode(downKey[i]);
2168 item[i].SetPressed(true);
2169 item[i].SetDownTime(0);
2170 keyEvent->AddKeyItem(item[i]);
2171 }
2172 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
2173 }
2174
2175 /**
2176 * @tc.name: InputManagerTest_GetPointerColor_001
2177 * @tc.desc: Obtains the mouse color.
2178 * @tc.type: FUNC
2179 * @tc.require:
2180 */
2181 HWTEST_F(InputManagerTest, InputManagerTest_GetPointerColor_001, TestSize.Level1)
2182 {
2183 CALL_TEST_DEBUG;
2184 int32_t setColor = 0x000000;
2185 InputManager::GetInstance()->SetPointerColor(setColor);
2186 int32_t getColor = 3;
2187 ASSERT_TRUE(InputManager::GetInstance()->GetPointerColor(getColor) == RET_OK);
2188 }
2189
2190 /**
2191 * @tc.name: InputManagerTest_SimulateInputEventExt_001
2192 * @tc.desc: Obtains the mouse color.
2193 * @tc.type: FUNC
2194 * @tc.require:
2195 */
2196 HWTEST_F(InputManagerTest, InputManagerTest_SimulateInputEventExt_001, TestSize.Level1)
2197 {
2198 CALL_TEST_DEBUG;
2199 auto pointerEvent = PointerEvent::Create();
2200 ASSERT_NE(pointerEvent, nullptr);
2201
2202 PointerEvent::PointerItem item;
2203 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_TWO);
2204 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_ONE);
2205 item.SetPressure(POINTER_ITEM_PRESSURE);
2206 item.SetPointerId(0);
2207 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2208 pointerEvent->SetPointerId(0);
2209 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2210 pointerEvent->AddPointerItem(item);
2211
2212 #ifdef OHOS_BUILD_ENABLE_ANCO
2213 InputManager::GetInstance()->SimulateInputEventExt(pointerEvent);
2214 InputManager::GetInstance()->SimulateInputEventExt(pointerEvent);
2215 InputManager::GetInstance()->SimulateInputEventExt(pointerEvent);
2216 #endif // OHOS_BUILD_ENABLE_ANCO
2217 }
2218
2219 /**
2220 * @tc.name: InputManagerTest_SimulateInputEventExt_002
2221 * @tc.desc: Obtains the mouse color.
2222 * @tc.type: FUNC
2223 * @tc.require:
2224 */
2225 HWTEST_F(InputManagerTest, InputManagerTest_SimulateInputEventExt_002, TestSize.Level1)
2226 {
2227 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
2228 ASSERT_TRUE(injectDownEvent != nullptr);
2229 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
2230 KeyEvent::KeyItem kitDown;
2231 kitDown.SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
2232 kitDown.SetPressed(true);
2233 kitDown.SetDownTime(downTime);
2234 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
2235 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
2236 injectDownEvent->AddPressedKeyItems(kitDown);
2237
2238 #ifdef OHOS_BUILD_ENABLE_ANCO
2239 InputManager::GetInstance()->SimulateInputEventExt(injectDownEvent);
2240 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
2241 #endif // OHOS_BUILD_ENABLE_ANCO
2242 }
2243
2244 /**
2245 * @tc.name: InputManagerTest_SimulateInputEventZorder_001
2246 * @tc.desc: Simulate input evnet with zOrder.
2247 * @tc.type: FUNC
2248 * @tc.require:
2249 */
2250 HWTEST_F(InputManagerTest, InputManagerTest_SimulateInputEventZorder_001, TestSize.Level1)
2251 {
2252 CALL_TEST_DEBUG;
2253 auto pointerEvent = PointerEvent::Create();
2254 ASSERT_NE(pointerEvent, nullptr);
2255
2256 PointerEvent::PointerItem item;
2257 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_TWO);
2258 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_ONE);
2259 item.SetPressure(POINTER_ITEM_PRESSURE);
2260 item.SetPointerId(0);
2261 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2262 pointerEvent->SetPointerId(0);
2263 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2264 pointerEvent->AddPointerItem(item);
2265 pointerEvent->SetZOrder(10.0);
2266 InputManager::GetInstance()->SimulateInputEvent(pointerEvent, 10.0, false);
2267 }
2268
2269 /**
2270 * @tc.name: InputManagerTest_SetShieldStatus_001
2271 * @tc.desc: Test set shield status
2272 * @tc.type: FUNC
2273 * @tc.require:
2274 */
2275 HWTEST_F(InputManagerTest, InputManagerTest_SetShieldStatus_001, TestSize.Level1)
2276 {
2277 bool factoryModeStatus = false;
2278 bool oobeModeStatus = false;
2279 int32_t ret = InputManager::GetInstance()->SetShieldStatus(SHIELD_MODE::FACTORY_MODE, true);
2280 ASSERT_EQ(ret, RET_OK);
2281 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::FACTORY_MODE, factoryModeStatus);
2282 ASSERT_EQ(ret, RET_OK);
2283 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::OOBE_MODE, oobeModeStatus);
2284 ASSERT_EQ(ret, RET_OK);
2285 ASSERT_TRUE(factoryModeStatus);
2286 ASSERT_FALSE(oobeModeStatus);
2287 ret = InputManager::GetInstance()->SetShieldStatus(SHIELD_MODE::OOBE_MODE, true);
2288 ASSERT_EQ(ret, RET_OK);
2289 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::FACTORY_MODE, factoryModeStatus);
2290 ASSERT_EQ(ret, RET_OK);
2291 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::OOBE_MODE, oobeModeStatus);
2292 ASSERT_EQ(ret, RET_OK);
2293 ASSERT_FALSE(factoryModeStatus);
2294 ASSERT_TRUE(oobeModeStatus);
2295 ret = InputManager::GetInstance()->SetShieldStatus(SHIELD_MODE::OOBE_MODE, false);
2296 ASSERT_EQ(ret, RET_OK);
2297 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::FACTORY_MODE, factoryModeStatus);
2298 ASSERT_EQ(ret, RET_OK);
2299 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::OOBE_MODE, oobeModeStatus);
2300 ASSERT_EQ(ret, RET_OK);
2301 ASSERT_FALSE(factoryModeStatus);
2302 ASSERT_FALSE(oobeModeStatus);
2303 }
2304
2305 /**
2306 * @tc.name: InputManager_SimulateInputEvent_001
2307 * @tc.desc: Set SourceType to SOURCE_TYPE_MOUSE
2308 * @tc.type: FUNC
2309 * @tc.require:SR000GGN6G
2310 */
2311 HWTEST_F(InputManagerTest, InputManager_SimulateInputEvent_001, TestSize.Level1)
2312 {
2313 CALL_TEST_DEBUG;
2314 auto pointerEvent = PointerEvent::Create();
2315 ASSERT_NE(pointerEvent, nullptr);
2316 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
2317 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2318 }
2319
2320 /**
2321 * @tc.name: InputManager_SimulateInputEvent_002
2322 * @tc.desc: Set SourceType to SOURCE_TYPE_TOUCHPAD
2323 * @tc.type: FUNC
2324 * @tc.require:SR000GGN6G
2325 */
2326 HWTEST_F(InputManagerTest, InputManager_SimulateInputEvent_002, TestSize.Level1)
2327 {
2328 CALL_TEST_DEBUG;
2329 auto pointerEvent = PointerEvent::Create();
2330 ASSERT_NE(pointerEvent, nullptr);
2331 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD);
2332 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2333 }
2334
2335 /**
2336 * @tc.name: InputManager_SimulateInputEvent_003
2337 * @tc.desc: Set SourceType to SOURCE_TYPE_TOUCHSCREEN
2338 * @tc.type: FUNC
2339 * @tc.require:SR000GGN6G
2340 */
2341 HWTEST_F(InputManagerTest, InputManager_SimulateInputEvent_003, TestSize.Level1)
2342 {
2343 CALL_TEST_DEBUG;
2344 auto pointerEvent = PointerEvent::Create();
2345 ASSERT_NE(pointerEvent, nullptr);
2346 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2347 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2348 }
2349
2350 /**
2351 * @tc.name: InputManager_SimulateInputEvent_004
2352 * @tc.desc: Set SourceType to SOURCE_TYPE_JOYSTICK
2353 * @tc.type: FUNC
2354 * @tc.require:SR000GGN6G
2355 */
2356 HWTEST_F(InputManagerTest, InputManager_SimulateInputEvent_004, TestSize.Level1)
2357 {
2358 CALL_TEST_DEBUG;
2359 auto pointerEvent = PointerEvent::Create();
2360 ASSERT_NE(pointerEvent, nullptr);
2361 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_JOYSTICK);
2362 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2363 }
2364
2365 /**
2366 * @tc.name: InputManager_SimulateInputEvent_005
2367 * @tc.desc: Set SourceType to invalid
2368 * @tc.type: FUNC
2369 * @tc.require:SR000GGN6G
2370 */
2371 HWTEST_F(InputManagerTest, InputManager_SimulateInputEvent_005, TestSize.Level1)
2372 {
2373 CALL_TEST_DEBUG;
2374 auto pointerEvent = PointerEvent::Create();
2375 ASSERT_NE(pointerEvent, nullptr);
2376 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_UNKNOWN);
2377 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2378 }
2379
2380 /**
2381 * @tc.name: InputManager_SimulateInputEvent_001
2382 * @tc.desc: SimulateInputEvent interface detection
2383 * @tc.type: FUNC
2384 * @tc.require:SR000GGN6G
2385 */
2386 HWTEST_F(InputManagerTest, InputManager_SimulateInputKeyEvent_001, TestSize.Level1)
2387 {
2388 CALL_TEST_DEBUG;
2389 auto keyEvent = KeyEvent::Create();
2390 ASSERT_NE(keyEvent, nullptr);
2391 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
2392 }
2393
2394 /**
2395 * @tc.name: InputManagerTest_SetWindowPointerStyle_001
2396 * @tc.desc: Verify valid parameter.
2397 * @tc.type: FUNC
2398 * @tc.require:SR000GGQL4 AR000GJNGN
2399 */
2400 HWTEST_F(InputManagerTest, InputManagerTest_SetWindowPointerStyle_001, TestSize.Level1)
2401 {
2402 CALL_TEST_DEBUG;
2403 auto window = WindowUtilsTest::GetInstance()->GetWindow();
2404 CHKPV(window);
2405 uint32_t windowId = window->GetWindowId();
2406 InputManager::GetInstance()->SetWindowPointerStyle(WindowArea::ENTER, getpid(), windowId);
2407 InputManager::GetInstance()->SetWindowPointerStyle(WindowArea::FOCUS_ON_TOP, getpid(), windowId);
2408 InputManager::GetInstance()->SetWindowPointerStyle(WindowArea::FOCUS_ON_RIGHT, getpid(), windowId);
2409 InputManager::GetInstance()->SetWindowPointerStyle(WindowArea::FOCUS_ON_BOTTOM_LEFT, getpid(), windowId);
2410 InputManager::GetInstance()->SetWindowPointerStyle(WindowArea::TOP_LIMIT, getpid(), windowId);
2411 InputManager::GetInstance()->SetWindowPointerStyle(WindowArea::BOTTOM_RIGHT_LIMIT, getpid(), windowId);
2412 ASSERT_NO_FATAL_FAILURE(window->GetWindowId());
2413 }
2414
2415 /**
2416 * @tc.name: InputManagerTest_RemoveInputEventFilter_001
2417 * @tc.desc: When eventFilterService is empty
2418 * @tc.type: FUNC
2419 * @tc.require:
2420 */
2421 HWTEST_F(InputManagerTest, InputManagerTest_RemoveInputEventFilter_001, TestSize.Level1)
2422 {
2423 CALL_TEST_DEBUG;
2424 int32_t ret = InputManager::GetInstance()->RemoveInputEventFilter(-1);
2425 ASSERT_EQ(ret, RET_OK);
2426 ret = InputManager::GetInstance()->RemoveInputEventFilter(0);
2427 ASSERT_EQ(ret, RET_OK);
2428 ret = InputManager::GetInstance()->RemoveInputEventFilter(1);
2429 ASSERT_EQ(ret, RET_OK);
2430 }
2431
2432 /**
2433 * @tc.name: InputManagerTest_RemoveInputEventFilter_002
2434 * @tc.desc: When the eventFilterService is full
2435 * @tc.type: FUNC
2436 * @tc.require:
2437 */
2438 HWTEST_F(InputManagerTest, InputManagerTest_RemoveInputEventFilter_002, TestSize.Level1)
2439 {
2440 CALL_DEBUG_ENTER;
2441 struct KeyFilter : public IInputEventFilter {
OnInputEventOHOS::MMI::KeyFilter2442 bool OnInputEvent(std::shared_ptr<KeyEvent> keyEvent) const override
2443 {
2444 MMI_HILOGI("KeyFilter::OnInputEvent enter,pid: %{public}d", getpid());
2445 return false;
2446 }
OnInputEventOHOS::MMI::KeyFilter2447 bool OnInputEvent(std::shared_ptr<PointerEvent> pointerEvent) const override
2448 {
2449 return false;
2450 }
2451 };
__anon5b702e151b02() 2452 auto addFilter = []() -> int32_t {
2453 auto filter = std::make_shared<KeyFilter>();
2454 uint32_t touchTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX);
2455 const int32_t filterId = InputManager::GetInstance()->AddInputEventFilter(filter, 220, touchTags);
2456 return filterId;
2457 };
2458 const size_t singleClientSuportMaxNum = 4;
2459 for (size_t i = 0; i < singleClientSuportMaxNum; ++i) {
2460 int32_t filterId = addFilter();
2461 ASSERT_NE(filterId, 10);
2462 }
2463 int32_t filterId = addFilter();
2464 ASSERT_EQ(filterId, RET_ERR);
2465 auto ret = InputManager::GetInstance()->RemoveInputEventFilter(RET_ERR);
2466 ASSERT_EQ(ret, RET_OK);
2467 }
2468
2469 /**
2470 * @tc.name: InputManagerTest_RemoveInputEventFilter_003
2471 * @tc.desc: Verify valid parameter.
2472 * @tc.type: FUNC
2473 * @tc.require:
2474 */
2475 HWTEST_F(InputManagerTest, InputManagerTest_RemoveInputEventFilter_003, TestSize.Level1)
2476 {
2477 CALL_DEBUG_ENTER;
2478 struct KeyFilter : public IInputEventFilter {
OnInputEventOHOS::MMI::KeyFilter2479 bool OnInputEvent(std::shared_ptr<KeyEvent> keyEvent) const override
2480 {
2481 MMI_HILOGI("KeyFilter::OnInputEvent enter,pid: %{public}d", getpid());
2482 return false;
2483 }
OnInputEventOHOS::MMI::KeyFilter2484 bool OnInputEvent(std::shared_ptr<PointerEvent> pointerEvent) const override
2485 {
2486 return false;
2487 }
2488 };
__anon5b702e151c02() 2489 auto addFilter = []() -> int32_t {
2490 auto filter = std::make_shared<KeyFilter>();
2491 uint32_t touchTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX);
2492 int32_t filterId = InputManager::GetInstance()->AddInputEventFilter(filter, 220, touchTags);
2493 return filterId;
2494 };
2495 int32_t filterId = addFilter();
2496 ASSERT_NE(filterId, RET_ERR);
2497 auto ret = InputManager::GetInstance()->RemoveInputEventFilter(filterId);
2498 ASSERT_EQ(ret, RET_OK);
2499 filterId = addFilter();
2500 ASSERT_NE(filterId, RET_ERR);
2501 ret = InputManager::GetInstance()->RemoveInputEventFilter(filterId);
2502 ASSERT_EQ(ret, RET_OK);
2503 }
2504
2505 /**
2506 * @tc.name: InputManager_SlideUpBrightScreenUnlockEvent_001
2507 * @tc.desc: Injection interface detection
2508 * @tc.type: FUNC
2509 * @tc.require:AR000GJG6G
2510 */
2511 HWTEST_F(InputManagerTest, InputManager_SlideUpBrightScreenUnlockEvent_001, TestSize.Level1)
2512 {
2513 CALL_TEST_DEBUG;
2514 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
2515 ASSERT_NE(injectDownEvent, nullptr);
2516 injectDownEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
2517
2518 KeyEvent::KeyItem kitDown;
2519 kitDown.SetKeyCode(KeyEvent::KEYCODE_F5);
2520 kitDown.SetPressed(true);
2521 kitDown.SetDownTime(500);
2522 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_F5);
2523 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
2524 injectDownEvent->AddPressedKeyItems(kitDown);
2525 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
2526
2527 std::shared_ptr<KeyEvent> injectUpEvent = KeyEvent::Create();
2528 ASSERT_NE(injectUpEvent, nullptr);
2529 injectDownEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
2530
2531 KeyEvent::KeyItem kitUp;
2532 kitUp.SetKeyCode(KeyEvent::KEYCODE_F5);
2533 kitUp.SetPressed(false);
2534 kitUp.SetDownTime(500);
2535 injectUpEvent->SetKeyCode(KeyEvent::KEYCODE_F5);
2536 injectUpEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
2537 injectUpEvent->RemoveReleasedKeyItems(kitUp);
2538 InputManager::GetInstance()->SimulateInputEvent(injectUpEvent);
2539 }
2540
2541 /**
2542 * @tc.name: InputManager_SimulateEvent_001
2543 * @tc.desc: Injection interface detection
2544 * @tc.type: FUNC
2545 * @tc.require:AR20240223308600
2546 */
2547 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_001, TestSize.Level1)
2548 {
2549 CALL_TEST_DEBUG;
2550 auto pointerEvent = InputManagerUtil::SetupSimulateEvent001();
2551 MMI_HILOGI("Before handle SimulateInputEvent");
2552 InputManagerUtil::PrintPointerEventId(pointerEvent);
2553 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2554 MMI_HILOGI("After handle SimulateInputEvent");
2555 InputManagerUtil::PrintPointerEventId(pointerEvent);
2556 }
2557
2558 /**
2559 * @tc.name: InputManager_SimulateEvent_002
2560 * @tc.desc: Injection interface detection
2561 * @tc.type: FUNC
2562 * @tc.require:AR20240223308600
2563 */
2564 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_002, TestSize.Level1)
2565 {
2566 CALL_TEST_DEBUG;
2567 auto pointerEvent = InputManagerUtil::SetupSimulateEvent002();
2568 MMI_HILOGI("Before handle SimulateInputEvent");
2569 InputManagerUtil::PrintPointerEventId(pointerEvent);
2570 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2571 MMI_HILOGI("After handle SimulateInputEvent");
2572 InputManagerUtil::PrintPointerEventId(pointerEvent);
2573 }
2574
2575 /**
2576 * @tc.name: InputManager_SimulateEvent_003
2577 * @tc.desc: Injection interface detection
2578 * @tc.type: FUNC
2579 * @tc.require:AR20240223308600
2580 */
2581 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_003, TestSize.Level1)
2582 {
2583 CALL_TEST_DEBUG;
2584 auto pointerEvent = InputManagerUtil::SetupSimulateEvent003();
2585 MMI_HILOGI("Before handle SimulateInputEvent");
2586 InputManagerUtil::PrintPointerEventId(pointerEvent);
2587 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2588 MMI_HILOGI("After handle SimulateInputEvent");
2589 InputManagerUtil::PrintPointerEventId(pointerEvent);
2590 }
2591
2592 /**
2593 * @tc.name: InputManager_SimulateEvent_004
2594 * @tc.desc: Injection interface detection
2595 * @tc.type: FUNC
2596 * @tc.require:AR20240223308600
2597 */
2598 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_004, TestSize.Level1)
2599 {
2600 CALL_TEST_DEBUG;
2601 auto pointerEvent = InputManagerUtil::SetupSimulateEvent004();
2602 MMI_HILOGI("Before handle SimulateInputEvent");
2603 InputManagerUtil::PrintPointerEventId(pointerEvent);
2604 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2605 MMI_HILOGI("After handle SimulateInputEvent");
2606 InputManagerUtil::PrintPointerEventId(pointerEvent);
2607 }
2608
2609 /**
2610 * @tc.name: InputManager_SimulateEvent_005
2611 * @tc.desc: Injection interface detection
2612 * @tc.type: FUNC
2613 * @tc.require:AR20240223308600
2614 */
2615 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_005, TestSize.Level1)
2616 {
2617 CALL_TEST_DEBUG;
2618 auto pointerEvent = InputManagerUtil::SetupSimulateEvent005();
2619 MMI_HILOGI("Before handle SimulateInputEvent");
2620 InputManagerUtil::PrintPointerEventId(pointerEvent);
2621 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2622 MMI_HILOGI("After handle SimulateInputEvent");
2623 InputManagerUtil::PrintPointerEventId(pointerEvent);
2624 }
2625
2626 /**
2627 * @tc.name: InputManager_SimulateEvent_006
2628 * @tc.desc: Injection interface detection
2629 * @tc.type: FUNC
2630 * @tc.require:AR20240223308600
2631 */
2632 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_006, TestSize.Level1)
2633 {
2634 CALL_TEST_DEBUG;
2635 auto pointerEvent = InputManagerUtil::SetupSimulateEvent006();
2636 MMI_HILOGI("Before handle SimulateInputEvent");
2637 InputManagerUtil::PrintPointerEventId(pointerEvent);
2638 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2639 MMI_HILOGI("After handle SimulateInputEvent");
2640 InputManagerUtil::PrintPointerEventId(pointerEvent);
2641 }
2642
2643 /**
2644 * @tc.name: InputManager_SimulateEvent_007
2645 * @tc.desc: Injection interface detection
2646 * @tc.type: FUNC
2647 * @tc.require:AR20240223308600
2648 */
2649 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_007, TestSize.Level1)
2650 {
2651 CALL_TEST_DEBUG;
2652 auto pointerEvent = InputManagerUtil::SetupSimulateEvent007();
2653 MMI_HILOGI("Before handle SimulateInputEvent");
2654 InputManagerUtil::PrintPointerEventId(pointerEvent);
2655 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2656 MMI_HILOGI("After handle SimulateInputEvent");
2657 InputManagerUtil::PrintPointerEventId(pointerEvent);
2658 }
2659
2660 /**
2661 * @tc.name: InputManager_SimulateEvent_008
2662 * @tc.desc: Injection interface detection
2663 * @tc.type: FUNC
2664 * @tc.require:AR20240223308600
2665 */
2666 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_008, TestSize.Level1)
2667 {
2668 CALL_TEST_DEBUG;
2669 auto pointerEvent = InputManagerUtil::SetupSimulateEvent008();
2670 MMI_HILOGI("Before handle SimulateInputEvent");
2671 InputManagerUtil::PrintPointerEventId(pointerEvent);
2672 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2673 MMI_HILOGI("After handle SimulateInputEvent");
2674 InputManagerUtil::PrintPointerEventId(pointerEvent);
2675 }
2676
2677 class ServiceWatcher final : public IInputServiceWatcher {
2678 public:
2679 ServiceWatcher() = default;
2680 ~ServiceWatcher() = default;
2681
OnServiceDied()2682 void OnServiceDied() override
2683 {}
2684 };
2685
2686 /**
2687 * @tc.name: InputManagerTest_InputServiceWatcher
2688 * @tc.desc: Verify service watcher.
2689 * @tc.type: FUNC
2690 * @tc.require:
2691 */
2692 HWTEST_F(InputManagerTest, InputManagerTest_InputServiceWatcher, TestSize.Level1)
2693 {
2694 auto watcher = std::make_shared<ServiceWatcher>();
2695 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->AddServiceWatcher(watcher));
2696 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->RemoveServiceWatcher(watcher));
2697 }
2698
2699 /**
2700 * @tc.name: InputManagerTest_MoveMouse_001
2701 * @tc.desc: MoveMouse interface detection
2702 * @tc.type: FUNC
2703 * @tc.require:
2704 */
2705 HWTEST_F(InputManagerTest, InputManagerTest_MoveMouse_001, TestSize.Level1)
2706 {
2707 CALL_TEST_DEBUG;
2708 int32_t offsetX = 20;
2709 int32_t offsetY = 20;
2710 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->MoveMouse(offsetX, offsetY));
2711 }
2712
2713 /**
2714 * @tc.name: InputManagerTest_MouseScrollRows_001
2715 * @tc.desc: SetMouseScrollRows and GetMouseScrollRows interface detection
2716 * @tc.type: FUNC
2717 * @tc.require:
2718 */
2719 HWTEST_F(InputManagerTest, InputManagerTest_MouseScrollRows_001, TestSize.Level1)
2720 {
2721 CALL_TEST_DEBUG;
2722 int32_t rows = 1;
2723 int32_t result = InputManager::GetInstance()->SetMouseScrollRows(rows);
2724 ASSERT_EQ(result, RET_OK);
2725 result = InputManager::GetInstance()->GetMouseScrollRows(rows);
2726 ASSERT_EQ(rows, 1);
2727 ASSERT_EQ(result, RET_OK);
2728 }
2729
2730 /**
2731 * @tc.name: InputManagerTest_SetCustomCursor_001
2732 * @tc.desc: SetCustomCursor interface detection
2733 * @tc.type: FUNC
2734 * @tc.require:
2735 */
2736 HWTEST_F(InputManagerTest, InputManagerTest_SetCustomCursor_001, TestSize.Level1)
2737 {
2738 CALL_TEST_DEBUG;
2739 int32_t windowId = 500;
2740 void* pixelMap = nullptr;
2741 int32_t result = InputManager::GetInstance()->SetCustomCursor(windowId, pixelMap);
2742 ASSERT_EQ(result, RET_ERR);
2743 }
2744
2745 /**
2746 * @tc.name: InputManagerTest_SetMouseIcon_001
2747 * @tc.desc: SetMouseIcon interface detection
2748 * @tc.type: FUNC
2749 * @tc.require:
2750 */
2751 HWTEST_F(InputManagerTest, InputManagerTest_SetMouseIcon_001, TestSize.Level1)
2752 {
2753 CALL_TEST_DEBUG;
2754 int32_t windowId = 500;
2755 void* pixelMap = nullptr;
2756 int32_t result = InputManager::GetInstance()->SetMouseIcon(windowId, pixelMap);
2757 ASSERT_NE(result, RET_OK);
2758 }
2759
2760 /**
2761 * @tc.name: InputManagerTest_SetMouseHotSpot_001
2762 * @tc.desc: SetMouseHotSpot interface detection
2763 * @tc.type: FUNC
2764 * @tc.require:
2765 */
2766 HWTEST_F(InputManagerTest, InputManagerTest_SetMouseHotSpot_001, TestSize.Level1)
2767 {
2768 CALL_TEST_DEBUG;
2769 int32_t windowId = 500;
2770 int32_t hotSpotX = 20;
2771 int32_t hotSpotY = 20;
2772 int32_t result = InputManager::GetInstance()->SetMouseHotSpot(windowId, hotSpotX, hotSpotY);
2773 ASSERT_EQ(result, RET_ERR);
2774 }
2775
2776 /**
2777 * @tc.name: InputManagerTest_PointerSize_001
2778 * @tc.desc: SetPointerSize and GetPointerSize interface detection
2779 * @tc.type: FUNC
2780 * @tc.require:
2781 */
2782 HWTEST_F(InputManagerTest, InputManagerTest_PointerSize_001, TestSize.Level1)
2783 {
2784 CALL_TEST_DEBUG;
2785 int32_t size = 5;
2786 int32_t result = InputManager::GetInstance()->SetPointerSize(size);
2787 ASSERT_EQ(result, RET_OK);
2788 result = InputManager::GetInstance()->GetPointerSize(size);
2789 ASSERT_EQ(size, 5);
2790 ASSERT_EQ(result, RET_OK);
2791 }
2792
2793 /**
2794 * @tc.name: InputManagerTest_GetCursorSurfaceId_001
2795 * @tc.desc: SetPointerSize and GetPointerSize interface detection
2796 * @tc.type: FUNC
2797 * @tc.require:
2798 */
2799 HWTEST_F(InputManagerTest, InputManagerTest_GetCursorSurfaceId_001, TestSize.Level1)
2800 {
2801 CALL_TEST_DEBUG;
2802 uint64_t surfaceId {};
2803 auto result = InputManager::GetInstance()->GetCursorSurfaceId(surfaceId);
2804 ASSERT_EQ(result, RET_OK);
2805 std::cout << "CursorSurfaceId:" << surfaceId << std::endl;
2806 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->GetCursorSurfaceId(surfaceId));
2807 }
2808
2809 /**
2810 * @tc.name: InputManagerTest_MousePrimaryButton_001
2811 * @tc.desc: SetMousePrimaryButton and GetMousePrimaryButton interface detection
2812 * @tc.type: FUNC
2813 * @tc.require:
2814 */
2815 HWTEST_F(InputManagerTest, InputManagerTest_MousePrimaryButton_001, TestSize.Level1)
2816 {
2817 CALL_TEST_DEBUG;
2818 int32_t primaryButton = 2;
2819 int32_t result = InputManager::GetInstance()->SetMousePrimaryButton(primaryButton);
2820 ASSERT_EQ(result, RET_ERR);
2821 primaryButton = 1;
2822 result = InputManager::GetInstance()->SetMousePrimaryButton(primaryButton);
2823 ASSERT_EQ(result, RET_OK);
2824 result = InputManager::GetInstance()->GetMousePrimaryButton(primaryButton);
2825 ASSERT_EQ(primaryButton, 1);
2826 ASSERT_EQ(result, RET_OK);
2827 }
2828
2829 /**
2830 * @tc.name: InputManagerTest_TouchpadScrollDirection_001
2831 * @tc.desc: SetTouchpadScrollDirection and GetTouchpadScrollDirection interface detection
2832 * @tc.type: FUNC
2833 * @tc.require:
2834 */
2835 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadScrollDirection_001, TestSize.Level1)
2836 {
2837 CALL_TEST_DEBUG;
2838 bool state = true;
2839 int32_t result = InputManager::GetInstance()->SetTouchpadScrollDirection(state);
2840 ASSERT_EQ(result, RET_OK);
2841 result = InputManager::GetInstance()->GetTouchpadScrollDirection(state);
2842 ASSERT_EQ(state, true);
2843 ASSERT_EQ(result, RET_OK);
2844 }
2845
2846 /**
2847 * @tc.name: InputManagerTest_TouchpadScrollDirection_001
2848 * @tc.desc: SetTouchpadScrollDirection and GetTouchpadScrollDirection interface detection
2849 * @tc.type: FUNC
2850 * @tc.require:
2851 */
2852 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadScrollSwitch_001, TestSize.Level1)
2853 {
2854 CALL_TEST_DEBUG;
2855 bool switchFlag = true;
2856 int32_t result = InputManager::GetInstance()->SetTouchpadScrollSwitch(switchFlag);
2857 ASSERT_EQ(result, RET_OK);
2858 result = InputManager::GetInstance()->GetTouchpadScrollSwitch(switchFlag);
2859 ASSERT_EQ(switchFlag, true);
2860 ASSERT_EQ(result, RET_OK);
2861 }
2862
2863 /**
2864 * @tc.name: InputManagerTest_TouchpadPointerSpeed_001
2865 * @tc.desc: SetTouchpadPointerSpeed and GetTouchpadPointerSpeed interface detection
2866 * @tc.type: FUNC
2867 * @tc.require:
2868 */
2869 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadPointerSpeed_001, TestSize.Level1)
2870 {
2871 CALL_TEST_DEBUG;
2872 int32_t speed = 1;
2873 int32_t result = InputManager::GetInstance()->SetTouchpadPointerSpeed(speed);
2874 ASSERT_EQ(result, RET_OK);
2875 result = InputManager::GetInstance()->GetTouchpadPointerSpeed(speed);
2876 ASSERT_EQ(speed, 1);
2877 ASSERT_EQ(result, RET_OK);
2878 }
2879
2880 /**
2881 * @tc.name: InputManagerTest_TouchpadPinchSwitch_001
2882 * @tc.desc: SetTouchpadPinchSwitch and GetTouchpadPinchSwitch interface detection
2883 * @tc.type: FUNC
2884 * @tc.require:
2885 */
2886 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadPinchSwitch_001, TestSize.Level1)
2887 {
2888 CALL_TEST_DEBUG;
2889 bool switchFlag = true;
2890 int32_t result = InputManager::GetInstance()->SetTouchpadPinchSwitch(switchFlag);
2891 ASSERT_EQ(result, RET_OK);
2892 result = InputManager::GetInstance()->GetTouchpadPinchSwitch(switchFlag);
2893 ASSERT_EQ(switchFlag, true);
2894 ASSERT_EQ(result, RET_OK);
2895 }
2896
2897 /**
2898 * @tc.name: InputManagerTest_TouchpadSwipeSwitch_001
2899 * @tc.desc: SetTouchpadSwipeSwitch and GetTouchpadSwipeSwitch interface detection
2900 * @tc.type: FUNC
2901 * @tc.require:
2902 */
2903 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadSwipeSwitch_001, TestSize.Level1)
2904 {
2905 CALL_TEST_DEBUG;
2906 bool switchFlag = true;
2907 int32_t result = InputManager::GetInstance()->SetTouchpadSwipeSwitch(switchFlag);
2908 ASSERT_EQ(result, RET_OK);
2909 result = InputManager::GetInstance()->GetTouchpadSwipeSwitch(switchFlag);
2910 ASSERT_EQ(switchFlag, true);
2911 ASSERT_EQ(result, RET_OK);
2912 }
2913
2914 /**
2915 * @tc.name: InputManagerTest_TouchpadRightClickType_001
2916 * @tc.desc: SetTouchpadRightClickType and GetTouchpadRightClickType interface detection
2917 * @tc.type: FUNC
2918 * @tc.require:
2919 */
2920 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadRightClickType_001, TestSize.Level1)
2921 {
2922 CALL_TEST_DEBUG;
2923 int32_t type = 1;
2924 int32_t result = InputManager::GetInstance()->SetTouchpadRightClickType(type);
2925 ASSERT_EQ(result, RET_OK);
2926 result = InputManager::GetInstance()->GetTouchpadRightClickType(type);
2927 ASSERT_EQ(type, 1);
2928 ASSERT_EQ(result, RET_OK);
2929 }
2930
2931 /**
2932 * @tc.name: InputManagerTest_SetTouchpadTapSwitch_001
2933 * @tc.desc: Set touchpad tap switch
2934 * @tc.type: FUNC
2935 * @tc.require:
2936 */
2937 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadTapSwitch_001, TestSize.Level1)
2938 {
2939 CALL_TEST_DEBUG;
2940 bool flag = false;
2941 InputManager::GetInstance()->Authorize(true);
2942 ASSERT_TRUE(InputManager::GetInstance()->SetTouchpadTapSwitch(flag) == RET_OK);
2943 }
2944
2945 /**
2946 * @tc.name: InputManagerTest_GetTouchpadTapSwitch_001
2947 * @tc.desc: Get touchpad tap switch
2948 * @tc.type: FUNC
2949 * @tc.require:
2950 */
2951 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadTapSwitch_001, TestSize.Level1)
2952 {
2953 CALL_TEST_DEBUG;
2954 bool flag = true;
2955 InputManager::GetInstance()->SetTouchpadTapSwitch(flag);
2956 bool newFlag = true;
2957 InputManager::GetInstance()->Authorize(true);
2958 ASSERT_TRUE(InputManager::GetInstance()->GetTouchpadTapSwitch(newFlag) == RET_OK);
2959 ASSERT_TRUE(flag == newFlag);
2960 }
2961
2962 /**
2963 * @tc.name: InputManagerTest_SetCurrentUser_001
2964 * @tc.desc: set current user id
2965 * @tc.type: FUNC
2966 * @tc.require:
2967 */
2968 HWTEST_F(InputManagerTest, InputManagerTest_SetCurrentUser_001, TestSize.Level1)
2969 {
2970 int32_t userId = 10;
2971 int32_t ret = InputManager::GetInstance()->SetCurrentUser(userId);
2972 EXPECT_FALSE(ret == RET_OK);
2973 }
2974
2975 /**
2976 * @tc.name: InputManagerTest_HasIrEmitter
2977 * @tc.desc: Test HasIrEmitter
2978 * @tc.type: FUNC
2979 * @tc.require:
2980 */
2981 HWTEST_F(InputManagerTest, InputManagerTest_HasIrEmitter, TestSize.Level1)
2982 {
2983 bool hasIrEmitter = false;
2984 int32_t ret = InputManager::GetInstance()->HasIrEmitter(hasIrEmitter);
2985 EXPECT_EQ(ret, RET_OK);
2986 }
2987
2988 /**
2989 * @tc.name: InputManagerTest_GetInfraredFrequencies
2990 * @tc.desc: Test GetInfraredFrequencies
2991 * @tc.type: FUNC
2992 * @tc.require:
2993 */
2994 HWTEST_F(InputManagerTest, InputManagerTest_GetInfraredFrequencies, TestSize.Level1)
2995 {
2996 InfraredFrequency infraredFrequency;
2997 infraredFrequency.max_ = 30;
2998 infraredFrequency.min_ = 10;
2999 std::vector<InfraredFrequency> requencys;
3000 requencys.push_back(infraredFrequency);
3001 int32_t ret = InputManager::GetInstance()->GetInfraredFrequencies(requencys);
3002 EXPECT_EQ(ret, RET_OK);
3003 }
3004
3005 /**
3006 * @tc.name: InputManagerTest_TransmitInfrared
3007 * @tc.desc: Test TransmitInfrared
3008 * @tc.type: FUNC
3009 * @tc.require:
3010 */
3011 HWTEST_F(InputManagerTest, InputManagerTest_TransmitInfrared, TestSize.Level1)
3012 {
3013 int64_t number = 10;
3014 std::vector<int64_t> pattern = { 10, 20, 30 };
3015 int32_t ret = InputManager::GetInstance()->TransmitInfrared(number, pattern);
3016 EXPECT_EQ(ret, RET_OK);
3017 }
3018
3019 /**
3020 * @tc.name: InputManagerTest_SetTouchpadDoubleTapAndDragState_001
3021 * @tc.desc: Set Touchpad Double Tap And Drag State
3022 * @tc.type: FUNC
3023 * @tc.require:
3024 */
3025 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadDoubleTapAndDragState_001, TestSize.Level1)
3026 {
3027 CALL_TEST_DEBUG;
3028 bool switchFlag = true;
3029 int32_t ret = InputManager::GetInstance()->SetTouchpadDoubleTapAndDragState(switchFlag);
3030 EXPECT_EQ(ret, RET_ERR);
3031 }
3032
3033 /**
3034 * @tc.name: InputManagerTest_GetTouchpadDoubleTapAndDragState_001
3035 * @tc.desc: Get touchpad tap switch
3036 * @tc.type: FUNC
3037 * @tc.require:
3038 */
3039 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadDoubleTapAndDragState_001, TestSize.Level1)
3040 {
3041 CALL_TEST_DEBUG;
3042 bool flag = true;
3043 InputManager::GetInstance()->SetTouchpadDoubleTapAndDragState(flag);
3044 bool newFlag = true;
3045 ASSERT_TRUE(InputManager::GetInstance()->GetTouchpadDoubleTapAndDragState(newFlag) == RET_OK);
3046 ASSERT_TRUE(flag == newFlag);
3047 }
3048
3049 /**
3050 * @tc.name: InputManagerTest_SetTouchpadRotateSwitch_001
3051 * @tc.desc: Set touchpad rotate switch
3052 * @tc.type: FUNC
3053 * @tc.require:
3054 */
3055 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadRotateSwitch_001, TestSize.Level1)
3056 {
3057 CALL_TEST_DEBUG;
3058 bool rotateSwitch = false;
3059 ASSERT_TRUE(InputManager::GetInstance()->SetTouchpadRotateSwitch(rotateSwitch) == RET_OK);
3060 }
3061
3062 /**
3063 * @tc.name: InputManagerTest_GetTouchpadRotateSwitch_001
3064 * @tc.desc: Get touchpad rotate switch
3065 * @tc.type: FUNC
3066 * @tc.require:
3067 */
3068 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadRotateSwitch_001, TestSize.Level1)
3069 {
3070 CALL_TEST_DEBUG;
3071 bool rotateSwitch = true;
3072 InputManager::GetInstance()->SetTouchpadRotateSwitch(rotateSwitch);
3073 bool newRotateSwitch = true;
3074 ASSERT_TRUE(InputManager::GetInstance()->GetTouchpadRotateSwitch(newRotateSwitch) == RET_OK);
3075 ASSERT_TRUE(rotateSwitch == newRotateSwitch);
3076 }
3077
3078 /**
3079 * @tc.name: InputManagerTest_EnableHardwareCursorStats_001
3080 * @tc.desc: Enable hardware cursor stats
3081 * @tc.type: FUNC
3082 * @tc.require:
3083 */
3084 HWTEST_F(InputManagerTest, InputManagerTest_EnableHardwareCursorStats_001, TestSize.Level1)
3085 {
3086 CALL_TEST_DEBUG;
3087 #ifdef OHOS_BUILD_ENABLE_POINTER
3088 auto ret = InputManager::GetInstance()->EnableHardwareCursorStats(false);
3089 ASSERT_EQ(ret, RET_OK);
3090 ret = InputManager::GetInstance()->EnableHardwareCursorStats(true);
3091 ASSERT_EQ(ret, RET_OK);
3092 #else
3093 auto ret = InputManager::GetInstance()->EnableHardwareCursorStats(false);
3094 ASSERT_EQ(ret, ERROR_UNSUPPORT);
3095 ret = InputManager::GetInstance()->EnableHardwareCursorStats(true);
3096 ASSERT_EQ(ret, ERROR_UNSUPPORT);
3097 #endif // OHOS_BUILD_ENABLE_POINTER
3098 }
3099
3100 /**
3101 * @tc.name: InputManagerTest_GetHardwareCursorStats_001
3102 * @tc.desc: get hardware cursor stats
3103 * @tc.type: FUNC
3104 * @tc.require:
3105 */
3106 HWTEST_F(InputManagerTest, InputManagerTest_GetHardwareCursorStats_001, TestSize.Level1)
3107 {
3108 CALL_TEST_DEBUG;
3109 uint32_t frameCount = 1;
3110 uint32_t vsyncCount = 1;
3111 #ifdef OHOS_BUILD_ENABLE_POINTER
3112 auto ret = InputManager::GetInstance()->EnableHardwareCursorStats(true);
3113 ASSERT_EQ(ret, RET_OK);
3114 ret = InputManager::GetInstance()->EnableHardwareCursorStats(false);
3115 ASSERT_EQ(ret, RET_OK);
3116 ret = InputManager::GetInstance()->GetHardwareCursorStats(frameCount, vsyncCount);
3117 ASSERT_EQ(ret, RET_OK);
3118 ASSERT_EQ(frameCount, 0);
3119 ASSERT_EQ(vsyncCount, 0);
3120 #else
3121 auto ret = InputManager::GetInstance()->GetHardwareCursorStats(frameCount, vsyncCount);
3122 ASSERT_EQ(ret, ERROR_UNSUPPORT);
3123 #endif // OHOS_BUILD_ENABLE_POINTER
3124 }
3125
3126 /**
3127 * @tc.name: InputManagerTest_AppendExtraData_001
3128 * @tc.desc: Append Extra Data
3129 * @tc.type: FUNC
3130 * @tc.require:
3131 */
3132 HWTEST_F(InputManagerTest, InputManagerTest_AppendExtraData_001, TestSize.Level1)
3133 {
3134 CALL_TEST_DEBUG;
3135 ExtraData data;
3136 data.buffer.resize(1025);
3137 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->AppendExtraData(data));
3138 data.buffer.resize(512);
3139 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->AppendExtraData(data));
3140 }
3141
3142 #ifdef OHOS_BUILD_ENABLE_MAGICCURSOR
3143 /**
3144 * @tc.name: InputManagerTest_GetPointerSnapshot
3145 * @tc.desc: Test GetPointerSnapshot
3146 * @tc.require:
3147 */
3148 HWTEST_F(InputManagerTest, InputManagerTest_GetPointerSnapshot, TestSize.Level1)
3149 {
3150 CALL_TEST_DEBUG;
3151 void *pixelMap = nullptr;
3152 EXPECT_NE(InputManager::GetInstance()->GetPointerSnapshot(pixelMap), RET_OK);
3153 }
3154 #endif // OHOS_BUILD_ENABLE_MAGICCURSOR
3155
3156 /**
3157 * @tc.name: InputManagerTest_SkipPointerLayer_001
3158 * @tc.desc: Test SkipPointerLayer
3159 * @tc.require:
3160 */
3161 HWTEST_F(InputManagerTest, InputManagerTest_SkipPointerLayer_001, TestSize.Level1)
3162 {
3163 CALL_TEST_DEBUG;
3164 bool isSkip = true;
3165 int32_t ret = InputManager::GetInstance()->SkipPointerLayer(isSkip);
3166 EXPECT_EQ(ret, 305);
3167 isSkip = false;
3168 ret = InputManager::GetInstance()->SkipPointerLayer(isSkip);
3169 EXPECT_EQ(ret, 305);
3170 }
3171
3172 /**
3173 * @tc.name: InputManagerTest_ConvertToCapiKeyAction_001
3174 * @tc.desc: Test the funcation ConvertToCapiKeyAction
3175 * @tc.require:
3176 */
3177 HWTEST_F(InputManagerTest, InputManagerTest_ConvertToCapiKeyAction_001, TestSize.Level1)
3178 {
3179 CALL_TEST_DEBUG;
3180 int32_t keyAction = 0X00000002;
3181 int32_t ret = InputManager::GetInstance()->ConvertToCapiKeyAction(keyAction);
3182 EXPECT_NE(ret, -1);
3183 }
3184
3185 /**
3186 * @tc.name: InputManagerTest_GetIntervalSinceLastInput001
3187 * @tc.desc: GetIntervalSinceLastInput interface detection
3188 * @tc.type: FUNC
3189 * @tc.require:
3190 */
3191 HWTEST_F(InputManagerTest, InputManagerTest_GetIntervalSinceLastInput001, TestSize.Level1)
3192 {
3193 CALL_TEST_DEBUG;
3194 int64_t timeInterval = -1;
3195 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->GetIntervalSinceLastInput(timeInterval));
3196 }
3197
3198 /**
3199 * @tc.name: InputManagerTest_GetIntervalSinceLastInput002
3200 * @tc.desc: GetIntervalSinceLastInput interface detection
3201 * @tc.type: FUNC
3202 * @tc.require:
3203 */
3204 HWTEST_F(InputManagerTest, InputManagerTest_GetIntervalSinceLastInput002, TestSize.Level1)
3205 {
3206 CALL_TEST_DEBUG;
3207 auto pointerEvent = PointerEvent::Create();
3208 ASSERT_NE(pointerEvent, nullptr);
3209 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD);
3210 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3211 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3212 int64_t timeInterval = 0;
3213 int32_t result =InputManager::GetInstance()->GetIntervalSinceLastInput(timeInterval);
3214 ASSERT_EQ(result, RET_OK);
3215 EXPECT_GE(timeInterval, (TIME_WAIT_FOR_OP * SLEEP_MILLISECONDS));
3216 }
3217
3218 /**
3219 * @tc.name: InputManagerTest_GetIntervalSinceLastInput003
3220 * @tc.desc: GetIntervalSinceLastInput interface detection
3221 * @tc.type: FUNC
3222 * @tc.require:
3223 */
3224 HWTEST_F(InputManagerTest, InputManagerTest_GetIntervalSinceLastInput003, TestSize.Level1)
3225 {
3226 CALL_TEST_DEBUG;
3227 auto pointerEvent = PointerEvent::Create();
3228 ASSERT_NE(pointerEvent, nullptr);
3229 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD);
3230 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3231 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3232 auto keyEvent = KeyEvent::Create();
3233 ASSERT_NE(keyEvent, nullptr);
3234 KeyEvent::KeyItem itemSecond;
3235 itemSecond.SetKeyCode(KeyEvent::KEYCODE_R);
3236 itemSecond.SetPressed(true);
3237 itemSecond.SetDownTime(500);
3238 keyEvent->AddKeyItem(itemSecond);
3239 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3240 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3241 int64_t timeInterval = 0;
3242 int32_t result =InputManager::GetInstance()->GetIntervalSinceLastInput(timeInterval);
3243 ASSERT_EQ(result, RET_OK);
3244 EXPECT_GE(timeInterval, (TIME_WAIT_FOR_OP * SLEEP_MILLISECONDS));
3245 }
3246
3247 /**
3248 * @tc.name: InputManagerTest_SetCustomCursorEx_001
3249 * @tc.desc: Test SetCustomCursorEx_001
3250 * @tc.type: FUNC
3251 * @tc.require:
3252 */
3253 HWTEST_F(InputManagerTest, InputManagerTest_SetCustomCursorEx_001, TestSize.Level1)
3254 {
3255 CALL_TEST_DEBUG;
3256 int32_t fakeWindowId = 100;
3257 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
3258 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
3259 ASSERT_NE(pixelMap, nullptr);
3260 CustomCursor cursor;
3261 cursor.pixelMap = (void *)pixelMap.get();
3262 cursor.focusX = 32;
3263 cursor.focusY = 32;
3264 CursorOptions options;
3265 options.followSystem = true;
3266 ASSERT_TRUE(InputManager::GetInstance()->SetCustomCursor(fakeWindowId, cursor, options) != RET_ERR);
3267 }
3268
3269 /**
3270 * @tc.name: InputManagerTest_SetCustomCursorEx_002
3271 * @tc.desc: Test SetCustomCursorEx_002
3272 * @tc.type: FUNC
3273 * @tc.require:
3274 */
3275 HWTEST_F(InputManagerTest, InputManagerTest_SetCustomCursorEx_002, TestSize.Level1)
3276 {
3277 CALL_TEST_DEBUG;
3278 int32_t fakeWindowId = 100;
3279 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
3280 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
3281 ASSERT_NE(pixelMap, nullptr);
3282 CustomCursor cursor;
3283 cursor.pixelMap = (void *)pixelMap.get();
3284 cursor.focusX = 32;
3285 cursor.focusY = 32;
3286 CursorOptions options;
3287 options.followSystem = false;
3288 ASSERT_TRUE(InputManager::GetInstance()->SetCustomCursor(fakeWindowId, cursor, options) != RET_ERR);
3289 }
3290
3291 /**
3292 * @tc.name: InputManagerTest_SetCustomCursorEx_003
3293 * @tc.desc: Test SetCustomCursorEx_003
3294 * @tc.type: FUNC
3295 * @tc.require:
3296 */
3297 HWTEST_F(InputManagerTest, InputManagerTest_SetCustomCursorEx_003, TestSize.Level1)
3298 {
3299 CALL_TEST_DEBUG;
3300 int32_t fakeWindowId = 100;
3301 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
3302 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
3303 ASSERT_NE(pixelMap, nullptr);
3304 CustomCursor cursor;
3305 cursor.pixelMap = (void *)pixelMap.get();
3306 cursor.focusX = 512;
3307 cursor.focusY = 512;
3308 CursorOptions options;
3309 options.followSystem = false;
3310 ASSERT_TRUE(InputManager::GetInstance()->SetCustomCursor(fakeWindowId, cursor, options) != RET_ERR);
3311 }
3312
3313 /**
3314 * @tc.name: InputManagerTest_SetCustomCursorEx_004
3315 * @tc.desc: Test SetCustomCursorEx_004
3316 * @tc.type: FUNC
3317 * @tc.require:
3318 */
3319 HWTEST_F(InputManagerTest, InputManagerTest_SetCustomCursorEx_004, TestSize.Level1)
3320 {
3321 CALL_TEST_DEBUG;
3322 int32_t fakeWindowId = 100;
3323 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
3324 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
3325 ASSERT_NE(pixelMap, nullptr);
3326 Media::ImageInfo imageInfo;
3327 imageInfo.size.width = 280;
3328 imageInfo.size.height = 280;
3329 pixelMap->SetImageInfo(imageInfo);
3330 CustomCursor cursor;
3331 cursor.pixelMap = (void *)pixelMap.get();
3332 cursor.focusX = 32;
3333 cursor.focusY = 32;
3334 CursorOptions options;
3335 options.followSystem = false;
3336 ASSERT_TRUE(InputManager::GetInstance()->SetCustomCursor(fakeWindowId, cursor, options) != RET_ERR);
3337 }
3338
3339 /*
3340 * @tc.name: InputManagerTest_ShiftAppPointerEvent_001
3341 * @tc.desc: Test the funcation ShiftAppPointerEvent
3342 * @tc.type: FUNC
3343 * @tc.require:
3344 */
3345 HWTEST_F(InputManagerTest, InputManagerTest_ShiftAppPointerEvent_001, TestSize.Level1)
3346 {
3347 CALL_TEST_DEBUG;
3348 int32_t sourceWindowId = 99;
3349 int32_t targetWindowId = 99;
3350 ShiftWindowParam param {
3351 .sourceWindowId = sourceWindowId,
3352 .targetWindowId = targetWindowId,
3353 };
3354 bool autoGenDown = true;
3355 int32_t ret = InputManager::GetInstance()->ShiftAppPointerEvent(param, autoGenDown);
3356 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
3357 ASSERT_EQ(ret, ARGV_VALID);
3358 #else
3359 ASSERT_EQ(ret, ERROR_UNSUPPORT);
3360 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
3361 }
3362
3363 /*
3364 * @tc.name: InputManagerTest_ShiftAppPointerEvent_002
3365 * @tc.desc: Test the funcation ShiftAppPointerEvent
3366 * @tc.type: FUNC
3367 * @tc.require:
3368 */
3369 HWTEST_F(InputManagerTest, InputManagerTest_ShiftAppPointerEvent_002, TestSize.Level1)
3370 {
3371 CALL_TEST_DEBUG;
3372 int32_t sourceWindowId = -150;
3373 int32_t targetWindowId = -99;
3374 ShiftWindowParam param {
3375 .sourceWindowId = sourceWindowId,
3376 .targetWindowId = targetWindowId,
3377 };
3378 bool autoGenDown = true;
3379 int32_t ret = InputManager::GetInstance()->ShiftAppPointerEvent(param, autoGenDown);
3380 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
3381 ASSERT_EQ(ret, RET_ERR);
3382 #else
3383 ASSERT_EQ(ret, ERROR_UNSUPPORT);
3384 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
3385 }
3386 } // namespace MMI
3387 } // namespace OHOS
3388