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;
__anon1bd2730b0202(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;
__anon1bd2730b0302(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;
__anon1bd2730b0402(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;
__anon1bd2730b0502(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;
__anon1bd2730b0602(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;
__anon1bd2730b0702(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;
__anon1bd2730b0802(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(
__anon1bd2730b0902(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");
__anon1bd2730b0a02(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");
__anon1bd2730b0b02(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 ASSERT_FALSE(InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY));
594 }
595
596 /**
597 * @tc.name: InputManagerTest_FunctionKeyState_002
598 * @tc.desc: Set NumLock for the keyboard enablement state to false
599 * @tc.type: FUNC
600 * @tc.require: I5HMCX
601 */
602 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_002, TestSize.Level1)
603 {
604 CALL_TEST_DEBUG;
605 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY, false);
606 bool result = InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY);
607 ASSERT_FALSE(result);
608 }
609
610 /**
611 * @tc.name: InputManagerTest_FunctionKeyState_003
612 * @tc.desc: Set ScrollLock for the keyboard enablement state to true
613 * @tc.type: FUNC
614 * @tc.require: I5HMCX
615 */
616 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_003, TestSize.Level1)
617 {
618 CALL_TEST_DEBUG;
619 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY, true);
620 ASSERT_FALSE(InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY));
621 }
622
623 /**
624 * @tc.name: InputManagerTest_FunctionKeyState_004
625 * @tc.desc: Set ScrollLock for the keyboard enablement state to false
626 * @tc.type: FUNC
627 * @tc.require: I5HMCX
628 */
629 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_004, TestSize.Level1)
630 {
631 CALL_TEST_DEBUG;
632 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY, false);
633 bool result = InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY);
634 ASSERT_FALSE(result);
635 }
636
637 /**
638 * @tc.name: InputManagerTest_FunctionKeyState_005
639 * @tc.desc: Set CapsLock for the keyboard enablement state to true
640 * @tc.type: FUNC
641 * @tc.require: I5HMCX
642 */
643 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_005, TestSize.Level1)
644 {
645 CALL_TEST_DEBUG;
646 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY, true);
647 ASSERT_FALSE(InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY));
648 }
649
650 /**
651 * @tc.name: InputManagerTest_FunctionKeyState_006
652 * @tc.desc: Set CapsLock for the keyboard enablement state to false
653 * @tc.type: FUNC
654 * @tc.require: I5HMCX
655 */
656 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_006, TestSize.Level1)
657 {
658 CALL_TEST_DEBUG;
659 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY, false);
660 bool result = InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY);
661 ASSERT_FALSE(result);
662 }
663
664 /**
665 * @tc.name: InputManagerTest_FunctionKeyState_007
666 * @tc.desc: Set other function keys
667 * @tc.type: FUNC
668 * @tc.require: I5HMCX
669 */
670 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_007, TestSize.Level1)
671 {
672 CALL_TEST_DEBUG;
673 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY, true);
674 bool result = InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY);
675 ASSERT_FALSE(result);
676
677 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY, false);
678 result = InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY);
679 ASSERT_FALSE(result);
680 }
681
682 /**
683 * @tc.name: InputManagerTest_EnableCombineKey_001
684 * @tc.desc: Enable combine key
685 * @tc.type: FUNC
686 * @tc.require: I5HMCX
687 */
688 HWTEST_F(InputManagerTest, InputManagerTest_EnableCombineKey_001, TestSize.Level1)
689 {
690 CALL_TEST_DEBUG;
691 ASSERT_EQ(InputManager::GetInstance()->EnableCombineKey(false), RET_OK);
692 }
693
694 /**
695 * @tc.name: InputManagerTest_EnableCombineKey_002
696 * @tc.desc: Enable combine key
697 * @tc.type: FUNC
698 * @tc.require: I5HMCX
699 */
700 HWTEST_F(InputManagerTest, InputManagerTest_EnableCombineKey_002, TestSize.Level1)
701 {
702 CALL_TEST_DEBUG;
703 ASSERT_EQ(InputManager::GetInstance()->EnableCombineKey(true), RET_OK);
704 }
705
706 /**
707 * @tc.name: InputManagerTest_TouchScreenHotArea_001
708 * @tc.desc: Touch event Search window by defaultHotAreas
709 * @tc.type: FUNC
710 * @tc.require: I5HMCB
711 */
712 HWTEST_F(InputManagerTest, InputManagerTest_TouchScreenHotArea_001, TestSize.Level1)
713 {
714 CALL_TEST_DEBUG;
715 std::shared_ptr<PointerEvent> pointerEvent{InputManagerUtil::SetupTouchScreenEvent001()};
716 ASSERT_TRUE(pointerEvent != nullptr);
717 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
718 ASSERT_EQ(pointerEvent->GetSourceType(), PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
719 }
720
721 /**
722 * @tc.name: InputManagerTest_TouchScreenHotArea_002
723 * @tc.desc: Touch event Search window by pointerHotAreas
724 * @tc.type: FUNC
725 * @tc.require: I5HMCB
726 */
727 HWTEST_F(InputManagerTest, InputManagerTest_TouchScreenHotArea_002, TestSize.Level1)
728 {
729 CALL_TEST_DEBUG;
730 std::shared_ptr<PointerEvent> pointerEvent{InputManagerUtil::SetupTouchScreenEvent002()};
731 ASSERT_TRUE(pointerEvent != nullptr);
732 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
733 ASSERT_EQ(pointerEvent->GetSourceType(), PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
734 }
735
736 /**
737 * @tc.name: InputManagerTest_UpdateDisplayInfo
738 * @tc.desc: Update window information
739 * @tc.type: FUNC
740 * @tc.require:
741 */
742 HWTEST_F(InputManagerTest, InputManagerTest_UpdateDisplayInfo, TestSize.Level1)
743 {
744 CALL_TEST_DEBUG;
745 DisplayGroupInfo displayGroupInfo;
746 displayGroupInfo.focusWindowId = 0;
747 displayGroupInfo.width = 0;
748 displayGroupInfo.height = 0;
749 InputManager::GetInstance()->UpdateDisplayInfo(displayGroupInfo);
750 ASSERT_TRUE(displayGroupInfo.displaysInfo.empty());
751 }
752
753 /**
754 * @tc.name: InputManagerTest_UpdateDisplayInfo for 1 display and 1 window
755 * @tc.desc: Update window information
756 * @tc.type: FUNC
757 * @tc.require:
758 */
759 HWTEST_F(InputManagerTest, InputManagerTest_UpdateDisplayInfo001, TestSize.Level1)
760 {
761 CALL_TEST_DEBUG;
762 DisplayGroupInfo displayGroupInfo;
763 displayGroupInfo.focusWindowId = 1;
764 displayGroupInfo.width = 1000;
765 displayGroupInfo.height = 2000;
766 DisplayInfo displayInfo;
767 displayInfo.id = 0;
768 displayInfo.x =1;
769 displayInfo.y = 1;
770 displayInfo.width = 2;
771 displayInfo.height = 2;
772 displayInfo.dpi = 240;
773 displayInfo.name = "pp";
774 displayInfo.uniq = "pp";
775 displayInfo.direction = DIRECTION0;
776 displayGroupInfo.displaysInfo.push_back(displayInfo);
777 WindowInfo info;
778 info.id = 1;
779 info.pid = 1;
780 info.uid = 1;
781 info.area = {1, 1, 1, 1};
782 info.defaultHotAreas = { info.area };
783 info.pointerHotAreas = { info.area };
784 info.pointerChangeAreas = {16, 5, 16, 5, 16, 5, 16, 5};
785 info.transform = {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f};
786 info.agentWindowId = 1;
787 info.flags = 0;
788 info.displayId = 0;
789 displayGroupInfo.windowsInfo.push_back(info);
790 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateDisplayInfo(displayGroupInfo));
791 }
792
793 /**
794 * @tc.name: InputManagerTest_UpdateDisplayInfo for 1 display and max-windows
795 * @tc.desc: Update window information
796 * @tc.type: FUNC
797 * @tc.require:
798 */
799 HWTEST_F(InputManagerTest, InputManagerTest_UpdateDisplayInfo002, TestSize.Level1)
800 {
801 CALL_TEST_DEBUG;
802 DisplayGroupInfo displayGroupInfo;
803 displayGroupInfo.focusWindowId = 0;
804 displayGroupInfo.width = 1000;
805 displayGroupInfo.height = 2000;
806 DisplayInfo displayInfo;
807 displayInfo.id = 0;
808 displayInfo.x =1;
809 displayInfo.y = 1;
810 displayInfo.width = 2;
811 displayInfo.height = 2;
812 displayInfo.dpi = 240;
813 displayInfo.name = "pp";
814 displayInfo.uniq = "pp";
815 displayInfo.direction = DIRECTION0;
816 displayInfo.displayMode = DisplayMode::FULL;
817 displayGroupInfo.displaysInfo.push_back(displayInfo);
818 for (uint32_t i = 0; i < MAX_WINDOW_NUMS; i++) {
819 WindowInfo info;
820 info.id = i + 1;
821 info.pid = 1;
822 info.uid = 1;
823 info.area = {1, 1, 1, 1};
824 info.defaultHotAreas = { info.area };
825 info.pointerHotAreas = { info.area };
826 info.pointerChangeAreas = {16, 5, 16, 5, 16, 5, 16, 5};
827 info.transform = {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f};
828 info.agentWindowId = 1;
829 info.flags = 0;
830 info.displayId = 0;
831 info.zOrder = static_cast<float>(MAX_WINDOW_NUMS - i);
832 displayGroupInfo.windowsInfo.push_back(info);
833 }
834 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateDisplayInfo(displayGroupInfo));
835 }
836
837 /**
838 * @tc.name: InputManagerTest_UpdateDisplayInfo for 1 display and 1 window
839 * @tc.desc: Update window information
840 * @tc.type: FUNC
841 * @tc.require:
842 */
843 HWTEST_F(InputManagerTest, InputManagerTest_UpdateDisplayInfo003, TestSize.Level1)
844 {
845 CALL_TEST_DEBUG;
846 DisplayGroupInfo displayGroupInfo;
847 displayGroupInfo.focusWindowId = 1;
848 displayGroupInfo.width = 1000;
849 displayGroupInfo.height = 2000;
850 DisplayInfo displayInfo;
851 for (uint32_t i = 0; i < 2; i++) { // one is default-display and another is simulate display
852 displayInfo.id = i;
853 displayInfo.x =1;
854 displayInfo.y = 1;
855 displayInfo.width = 2;
856 displayInfo.height = 2;
857 displayInfo.dpi = 240;
858 displayInfo.name = "pp";
859 displayInfo.uniq = "pp";
860 displayInfo.direction = DIRECTION0;
861 displayGroupInfo.displaysInfo.push_back(displayInfo);
862 }
863 WindowInfo info;
864 for (uint32_t i = 0; i < 2; i++) { // 2 widnows for 2 display
865 info.id = 1;
866 info.pid = 1;
867 info.uid = 1;
868 info.defaultHotAreas = { {1, 1, 1, 1} };
869 info.agentWindowId = 1;
870 info.flags = 0;
871 info.displayId = i;
872 displayGroupInfo.windowsInfo.push_back(info);
873 }
874 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateDisplayInfo(displayGroupInfo));
875 }
876
877 /**
878 * @tc.name: InputManagerTest_UpdateWindowGroupInfo_001
879 * @tc.desc: Update window information
880 * @tc.type: FUNC
881 * @tc.require:
882 */
883 HWTEST_F(InputManagerTest, InputManagerTest_UpdateWindowGroupInfo_001, TestSize.Level1)
884 {
885 CALL_TEST_DEBUG;
886 WindowInfo window;
887 window.id = 1;
888 window.action = WINDOW_UPDATE_ACTION::ADD;
889 WindowGroupInfo windowGroupInfo;
890 windowGroupInfo.displayId = 0;
891 windowGroupInfo.focusWindowId = 1;
892 windowGroupInfo.windowsInfo = {window};
893 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateWindowInfo(windowGroupInfo));
894 }
895
896 /**
897 * @tc.name: InputManagerTest_UpdateWindowGroupInfo_002
898 * @tc.desc: Update window information
899 * @tc.type: FUNC
900 * @tc.require:
901 */
902 HWTEST_F(InputManagerTest, InputManagerTest_UpdateWindowGroupInfo_002, TestSize.Level1)
903 {
904 CALL_TEST_DEBUG;
905 WindowInfo window;
906 window.id = 1;
907 window.action = WINDOW_UPDATE_ACTION::CHANGE;
908 WindowGroupInfo windowGroupInfo;
909 windowGroupInfo.windowsInfo = {window};
910 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateWindowInfo(windowGroupInfo));
911 }
912
913 /**
914 * @tc.name: InputManagerTest_UpdateWindowGroupInfo_003
915 * @tc.desc: Update window information
916 * @tc.type: FUNC
917 * @tc.require:
918 */
919 HWTEST_F(InputManagerTest, InputManagerTest_UpdateWindowGroupInfo_003, TestSize.Level1)
920 {
921 CALL_TEST_DEBUG;
922 WindowInfo window;
923 window.id = 1;
924 window.action = WINDOW_UPDATE_ACTION::DEL;
925 WindowGroupInfo windowGroupInfo;
926 windowGroupInfo.windowsInfo = {window};
927 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateWindowInfo(windowGroupInfo));
928 }
929
930 /**
931 * @tc.name: InputManagerTest_UpdateWindowGroupInfo_004
932 * @tc.desc: Update window information
933 * @tc.type: FUNC
934 * @tc.require:
935 */
936 HWTEST_F(InputManagerTest, InputManagerTest_UpdateWindowGroupInfo_004, TestSize.Level1)
937 {
938 CALL_TEST_DEBUG;
939 WindowInfo window;
940 window.id = 1;
941 window.action = WINDOW_UPDATE_ACTION::UNKNOWN;
942
943 WindowGroupInfo windowGroupInfo;
944 windowGroupInfo.windowsInfo = {window};
945 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateWindowInfo(windowGroupInfo));
946 }
947
948 /**
949 * @tc.name: InputManagerTest_UpdateWindowGroupInfo_005
950 * @tc.desc: Update window information
951 * @tc.type: FUNC
952 * @tc.require:
953 */
954 HWTEST_F(InputManagerTest, InputManagerTest_UpdateWindowGroupInfo_005, TestSize.Level1)
955 {
956 CALL_TEST_DEBUG;
957 WindowInfo window;
958 window.id = 1;
959 window.action = WINDOW_UPDATE_ACTION::CHANGE;
960 #ifdef OHOS_BUILD_ENABLE_ANCO
961 window.flags |= SHELL_FLAGS_VALUE;
962 #endif // OHOS_BUILD_ENABLE_ANCO
963 WindowGroupInfo windowGroupInfo;
964 windowGroupInfo.windowsInfo = {window};
965 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateWindowInfo(windowGroupInfo));
966 }
967
968 #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT
969 /**
970 * @tc.name: InputManagerTest_SetEnhanceConfig_001
971 * @tc.desc: Set Secutity component enhance config
972 * @tc.type: FUNC
973 * @tc.require:
974 */
975 HWTEST_F(InputManagerTest, InputManagerTest_SetEnhanceConfig_001, TestSize.Level1)
976 {
977 CALL_TEST_DEBUG;
978 uint8_t cfgData[16] = {0};
979 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->SetEnhanceConfig(cfgData, 16));
980 }
981 #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT
982
983 /**
984 * @tc.name: InputManagerTest_GetDevice_001
985 * @tc.desc: Verify the fetch device info
986 * @tc.type: FUNC
987 * @tc.require:
988 */
989 HWTEST_F(InputManagerTest, InputManagerTest_GetDevice_001, TestSize.Level1)
990 {
991 CALL_TEST_DEBUG;
992 int32_t deviceId = 0;
__anon1bd2730b0c02(std::shared_ptr<InputDevice> inputDevice) 993 auto callback = [](std::shared_ptr<InputDevice> inputDevice) {
994 MMI_HILOGD("Get device success");
995 ASSERT_TRUE(inputDevice != nullptr);
996 };
997 InputManager::GetInstance()->GetDevice(deviceId, callback);
998 }
999
1000 /**
1001 * @tc.name: InputManagerTest_GetDevice_002
1002 * @tc.desc: Verify the fetch device info
1003 * @tc.type: FUNC
1004 * @tc.require:
1005 */
1006 HWTEST_F(InputManagerTest, InputManagerTest_GetDevice_002, TestSize.Level1)
1007 {
1008 CALL_TEST_DEBUG;
1009 int32_t deviceId = INVAID_VALUE;
__anon1bd2730b0d02(std::shared_ptr<InputDevice> inputDevice) 1010 auto callback = [](std::shared_ptr<InputDevice> inputDevice) {
1011 MMI_HILOGD("Get device success");
1012 ASSERT_TRUE(inputDevice != nullptr);
1013 };
1014 int32_t ret = InputManager::GetInstance()->GetDevice(deviceId, callback);
1015 ASSERT_NE(ret, RET_OK);
1016 }
1017
1018 /**
1019 * @tc.name: InputManagerTest_GetDeviceIds
1020 * @tc.desc: Verify the fetch device list
1021 * @tc.type: FUNC
1022 * @tc.require:
1023 */
1024 HWTEST_F(InputManagerTest, InputManagerTest_GetDeviceIds, TestSize.Level1)
1025 {
1026 CALL_TEST_DEBUG;
__anon1bd2730b0e02(std::vector<int32_t> ids) 1027 auto callback = [](std::vector<int32_t> ids) { MMI_HILOGD("Get device success"); };
1028 int32_t ret = InputManager::GetInstance()->GetDeviceIds(callback);
1029 ASSERT_EQ(ret, RET_OK);
1030 }
1031
1032 /**
1033 * @tc.name: InputManagerTest_EventTypeToString
1034 * @tc.desc: Verify inputevent interface
1035 * @tc.type: FUNC
1036 * @tc.require:
1037 */
1038 HWTEST_F(InputManagerTest, InputManagerTest_EventTypeToString, TestSize.Level1)
1039 {
1040 CALL_TEST_DEBUG;
1041 auto inputEvent = InputEvent::Create();
1042 ASSERT_NE(inputEvent, nullptr);
1043 auto ret = inputEvent->EventTypeToString(InputEvent::EVENT_TYPE_BASE);
1044 ASSERT_STREQ(ret, "base");
1045 ret = inputEvent->EventTypeToString(InputEvent::EVENT_TYPE_KEY);
1046 ASSERT_STREQ(ret, "key");
1047 ret = inputEvent->EventTypeToString(InputEvent::EVENT_TYPE_AXIS);
1048 ASSERT_STREQ(ret, "axis");
1049 ret = inputEvent->EventTypeToString(INVAID_VALUE);
1050 ASSERT_STREQ(ret, "unknown");
1051 }
1052
1053 /**
1054 * @tc.name: InputManagerTest_InputDeviceInterface_001
1055 * @tc.desc: Verify inputdevice interface
1056 * @tc.type: FUNC
1057 * @tc.require:
1058 */
1059 HWTEST_F(InputManagerTest, InputManagerTest_InputDeviceInterface_001, TestSize.Level1)
1060 {
1061 CALL_TEST_DEBUG;
1062 std::shared_ptr<InputDevice> inputDevice = std::make_shared<InputDevice>();
1063 ASSERT_NE(inputDevice, nullptr);
1064 inputDevice->SetId(0);
1065 ASSERT_EQ(inputDevice->GetId(), 0);
1066 inputDevice->SetName("name");
1067 ASSERT_STREQ(inputDevice->GetName().c_str(), "name");
1068 inputDevice->SetType(0);
1069 ASSERT_EQ(inputDevice->GetType(), 0);
1070 inputDevice->SetBus(0);
1071 ASSERT_EQ(inputDevice->GetBus(), 0);
1072 inputDevice->SetVersion(0);
1073 ASSERT_EQ(inputDevice->GetVersion(), 0);
1074 inputDevice->SetProduct(0);
1075 ASSERT_EQ(inputDevice->GetProduct(), 0);
1076 inputDevice->SetVendor(0);
1077 ASSERT_EQ(inputDevice->GetVendor(), 0);
1078 inputDevice->SetPhys("phys");
1079 ASSERT_STREQ(inputDevice->GetPhys().c_str(), "phys");
1080 inputDevice->SetUniq("uniq");
1081 ASSERT_STREQ(inputDevice->GetUniq().c_str(), "uniq");
1082 }
1083
1084 /**
1085 * @tc.name: InputManagerTest_InputDeviceInterface_002
1086 * @tc.desc: Verify inputdevice interface
1087 * @tc.type: FUNC
1088 * @tc.require:
1089 */
1090 HWTEST_F(InputManagerTest, InputManagerTest_InputDeviceInterface_002, TestSize.Level1)
1091 {
1092 CALL_TEST_DEBUG;
1093 std::shared_ptr<InputDevice> inputDevice = std::make_shared<InputDevice>();
1094 ASSERT_NE(inputDevice, nullptr);
1095 InputDevice::AxisInfo axis;
1096 axis.SetAxisType(0);
1097 axis.SetMinimum(0);
1098 axis.SetMaximum(1);
1099 axis.SetFuzz(0);
1100 axis.SetFlat(1);
1101 axis.SetResolution(0);
1102 inputDevice->AddAxisInfo(axis);
1103 auto iter = inputDevice->GetAxisInfo();
1104 ASSERT_EQ(iter[0].GetAxisType(), 0);
1105 ASSERT_EQ(iter[0].GetMinimum(), 0);
1106 ASSERT_EQ(iter[0].GetMaximum(), 1);
1107 ASSERT_EQ(iter[0].GetFuzz(), 0);
1108 ASSERT_EQ(iter[0].GetFlat(), 1);
1109 ASSERT_EQ(iter[0].GetResolution(), 0);
1110 }
1111
1112 /**
1113 * @tc.name: InputManagerTest_SetAnrObserver
1114 * @tc.desc: Verify the observer for events
1115 * @tc.type: FUNC
1116 * @tc.require:
1117 */
1118 HWTEST_F(InputManagerTest, InputManagerTest_SetAnrObserver, TestSize.Level1)
1119 {
1120 CALL_TEST_DEBUG;
1121 class IAnrObserverTest : public IAnrObserver {
1122 public:
IAnrObserverTest()1123 IAnrObserverTest() : IAnrObserver()
1124 {}
~IAnrObserverTest()1125 virtual ~IAnrObserverTest()
1126 {}
OnAnr(int32_t pid,int32_t eventId) const1127 void OnAnr(int32_t pid, int32_t eventId) const override
1128 {
1129 MMI_HILOGD("Set anr success");
1130 };
1131 };
1132
1133 std::shared_ptr<IAnrObserverTest> observer = std::make_shared<IAnrObserverTest>();
1134 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->SetAnrObserver(observer));
1135 }
1136
1137 /**
1138 * @tc.name: InputManagerTest_EnableInputDevice_001
1139 * @tc.desc: Enable input device
1140 * @tc.type: FUNC
1141 * @tc.require:
1142 */
1143 HWTEST_F(InputManagerTest, InputManagerTest_EnableInputDevice_001, TestSize.Level1)
1144 {
1145 CALL_TEST_DEBUG;
1146 auto ret = InputManager::GetInstance()->EnableInputDevice(false);
1147 ASSERT_EQ(ret, RET_OK);
1148 ret = InputManager::GetInstance()->EnableInputDevice(true);
1149 ASSERT_EQ(ret, RET_OK);
1150 }
1151
1152 /**
1153 * @tc.name: InputManagerTest_SensorInputTime_001
1154 * @tc.desc: Test SensorTime
1155 * @tc.type: FUNC
1156 * @tc.require:
1157 */
1158 HWTEST_F(InputManagerTest, InputManagerTest_SensorInputTime_001, TestSize.Level1)
1159 {
1160 CALL_TEST_DEBUG;
1161 auto pointerEvent = PointerEvent::Create();
1162 ASSERT_TRUE(pointerEvent != nullptr);
1163 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1164 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1165 pointerEvent->SetPointerId(0);
1166 pointerEvent->SetSensorInputTime(POINTER_SENSOR_INPUT_TIME);
1167 ASSERT_TRUE(pointerEvent->GetSensorInputTime() == POINTER_SENSOR_INPUT_TIME);
1168 }
1169
1170 /**
1171 * @tc.name: InputManagerTest_GetDisplayBindInfo_001
1172 * @tc.desc: Get diaplay bind information
1173 * @tc.type: FUNC
1174 * @tc.require:
1175 */
1176 HWTEST_F(InputManagerTest, InputManagerTest_GetDisplayBindInfo_001, TestSize.Level1)
1177 {
1178 CALL_TEST_DEBUG;
1179 OHOS::MMI::DisplayBindInfos infos;
1180 int32_t ret = InputManager::GetInstance()->GetDisplayBindInfo(infos);
1181 ASSERT_TRUE(ret == RET_OK);
1182 if (ret != RET_OK) {
1183 MMI_HILOGE("Call GetDisplayBindInfo failed, ret:%{public}d", ret);
1184 }
1185 }
1186
1187 /**
1188 * @tc.name: InputManagerTest_SetDisplayBind_001
1189 * @tc.desc: Set diaplay bind information
1190 * @tc.type: FUNC
1191 * @tc.require:
1192 */
1193 HWTEST_F(InputManagerTest, InputManagerTest_SetDisplayBind_001, TestSize.Level1)
1194 {
1195 CALL_TEST_DEBUG;
1196 int32_t deviceId = DEFAULT_DEVICE_ID;
1197 int32_t displayId = INVAID_VALUE;
1198 std::string msg;
1199 int32_t ret = InputManager::GetInstance()->SetDisplayBind(deviceId, displayId, msg);
1200 ASSERT_TRUE(ret == RET_OK);
1201 if (ret != RET_OK) {
1202 MMI_HILOGE("Call SetDisplayBind failed, ret:%{public}d", ret);
1203 }
1204 }
1205
1206 /**
1207 * @tc.name: InputManagerTest_MarkConsumed_001
1208 * @tc.desc: Mark Cosumer
1209 * @tc.type: FUNC
1210 * @tc.require:
1211 */
1212 HWTEST_F(InputManagerTest, InputManagerTest_MarkConsumed_001, TestSize.Level1)
1213 {
1214 CALL_TEST_DEBUG;
1215 auto consumer = GetPtr<InputEventConsumer>();
1216 ASSERT_TRUE(consumer != nullptr);
1217 int32_t monitorId = InputManager::GetInstance()->AddMonitor(consumer);
1218 auto pointerEvent = PointerEvent::Create();
1219 ASSERT_TRUE(pointerEvent != nullptr);
1220 auto eventId = pointerEvent->GetId();
1221 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->MarkConsumed(monitorId, eventId));
1222 }
1223
1224 /**
1225 * @tc.name: InputManagerTest_EnterCaptureMode_001
1226 * @tc.desc: Entering capture mode.
1227 * @tc.type: FUNC
1228 * @tc.require:
1229 */
1230 HWTEST_F(InputManagerTest, InputManagerTest_EnterCaptureMode_001, TestSize.Level1)
1231 {
1232 CALL_TEST_DEBUG;
1233 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1234 CHKPV(window);
1235 uint32_t windowId = window->GetWindowId();
1236 int32_t ret = InputManager::GetInstance()->EnterCaptureMode(windowId);
1237 ASSERT_TRUE(ret == RET_OK);
1238 if (ret != RET_OK) {
1239 MMI_HILOGE("Call EnterCaptureMode failed, ret:%{public}d", ret);
1240 }
1241 }
1242
1243 /**
1244 * @tc.name: InputManagerTest_LeaveCaptureMode_001
1245 * @tc.desc: Leaving capture mode.
1246 * @tc.type: FUNC
1247 * @tc.require:
1248 */
1249 HWTEST_F(InputManagerTest, InputManagerTest_LeaveCaptureMode_001, TestSize.Level1)
1250 {
1251 CALL_TEST_DEBUG;
1252 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1253 CHKPV(window);
1254 uint32_t windowId = window->GetWindowId();
1255 int32_t ret = InputManager::GetInstance()->LeaveCaptureMode(windowId);
1256 ASSERT_TRUE(ret == RET_OK);
1257 if (ret != RET_OK) {
1258 MMI_HILOGE("Call LeaveCaptureMode failed, ret:%{public}d", ret);
1259 }
1260 }
1261
1262 /**
1263 * @tc.name: InputManagerTest_GetWindowPid_001
1264 * @tc.desc: Get window pid.
1265 * @tc.type: FUNC
1266 * @tc.require:
1267 */
1268 HWTEST_F(InputManagerTest, InputManagerTest_GetWindowPid_001, TestSize.Level1)
1269 {
1270 CALL_TEST_DEBUG;
1271 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1272 CHKPV(window);
1273 uint32_t windowId = window->GetWindowId();
1274 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->GetWindowPid(windowId));
1275 int32_t ret = InputManager::GetInstance()->GetWindowPid(windowId);
1276 if (ret == RET_ERR) {
1277 MMI_HILOGE("Call GetWindowPid failed, ret:%{public}d", ret);
1278 }
1279 }
1280
1281 /**
1282 * @tc.name: InputManagerTest_SetHoverScrollState_001
1283 * @tc.desc: Set hover scroll state
1284 * @tc.type: FUNC
1285 * @tc.require:
1286 */
1287 HWTEST_F(InputManagerTest, InputManagerTest_SetHoverScrollState_001, TestSize.Level1)
1288 {
1289 CALL_TEST_DEBUG;
1290 auto ret = InputManager::GetInstance()->SetHoverScrollState(false);
1291 ASSERT_EQ(ret, RET_OK);
1292 ret = InputManager::GetInstance()->SetHoverScrollState(true);
1293 ASSERT_EQ(ret, RET_OK);
1294 }
1295
1296 /**
1297 * @tc.name: InputManagerTest_GetHoverScrollState_001
1298 * @tc.desc: Get hover scroll state
1299 * @tc.type: FUNC
1300 * @tc.require:
1301 */
1302 HWTEST_F(InputManagerTest, InputManagerTest_GetHoverScrollState_001, TestSize.Level1)
1303 {
1304 CALL_TEST_DEBUG;
1305 bool statefalse = false;
1306 auto ret = InputManager::GetInstance()->GetHoverScrollState(statefalse);
1307 ASSERT_EQ(ret, RET_OK);
1308 bool statetrue = true;
1309 ret = InputManager::GetInstance()->GetHoverScrollState(statetrue);
1310 ASSERT_EQ(ret, RET_OK);
1311 }
1312
1313 /**
1314 * @tc.name: InputManagerTest_SetPointerVisible_001
1315 * @tc.desc: Set pointer visible
1316 * @tc.type: FUNC
1317 * @tc.require:
1318 */
1319 HWTEST_F(InputManagerTest, InputManagerTest_SetPointerVisible_001, TestSize.Level1)
1320 {
1321 CALL_TEST_DEBUG;
1322 auto ret = InputManager::GetInstance()->SetPointerVisible(false);
1323 ASSERT_EQ(ret, RET_OK);
1324 bool isVisible{true};
1325 if (InputManager::GetInstance()->SetPointerVisible(isVisible) == RET_OK) {
1326 ASSERT_TRUE(InputManager::GetInstance()->IsPointerVisible() == isVisible);
1327 }
1328 }
1329
1330 /**
1331 * @tc.name: InputManagerTest_IsPointerVisible_001
1332 * @tc.desc: Test flag `InputEvent::EVENT_FLAG_HIDE_POINTER` on controlling pointer visibility
1333 * @tc.type: FUNC
1334 * @tc.require:
1335 */
1336 HWTEST_F(InputManagerTest, InputManagerTest_IsPointerVisible_001, TestSize.Level1)
1337 {
1338 CALL_TEST_DEBUG;
1339 PointerEvent::PointerItem item;
1340 item.SetPointerId(0);
1341 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_ONE);
1342 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_ONE);
1343
1344 auto pointerEvent = PointerEvent::Create();
1345 ASSERT_NE(pointerEvent, nullptr);
1346 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1347 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1348 pointerEvent->AddFlag(InputEvent::EVENT_FLAG_HIDE_POINTER);
1349 pointerEvent->SetPointerId(0);
1350 pointerEvent->AddPointerItem(item);
1351
1352 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
1353 ASSERT_TRUE(InputManager::GetInstance()->IsPointerVisible());
1354 }
1355
1356 /**
1357 * @tc.name: InputManagerTest_IsPointerVisible_002
1358 * @tc.desc: Test flag `InputEvent::EVENT_FLAG_HIDE_POINTER` on controlling pointer visibility
1359 * @tc.type: FUNC
1360 * @tc.require:
1361 */
1362 HWTEST_F(InputManagerTest, InputManagerTest_IsPointerVisible_002, TestSize.Level1)
1363 {
1364 CALL_TEST_DEBUG;
1365 PointerEvent::PointerItem item;
1366 item.SetPointerId(0);
1367 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_TWO);
1368 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_TWO);
1369
1370 auto pointerEvent = PointerEvent::Create();
1371 ASSERT_NE(pointerEvent, nullptr);
1372 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1373 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1374 pointerEvent->SetPointerId(0);
1375 pointerEvent->AddPointerItem(item);
1376
1377 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
1378 ASSERT_TRUE(InputManager::GetInstance()->IsPointerVisible());
1379 }
1380
1381 /**
1382 * @tc.name: InputManagerTest_SetTouchpadScrollSwitch_001
1383 * @tc.desc: Set touchpad scroll switch
1384 * @tc.type: FUNC
1385 * @tc.require:
1386 */
1387 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadScrollSwitch_001, TestSize.Level1)
1388 {
1389 CALL_TEST_DEBUG;
1390 auto ret = InputManager::GetInstance()->SetTouchpadScrollSwitch(false);
1391 ASSERT_EQ(ret, RET_OK);
1392 ret = InputManager::GetInstance()->SetTouchpadScrollSwitch(true);
1393 ASSERT_EQ(ret, RET_OK);
1394 }
1395
1396 /**
1397 * @tc.name: InputManagerTest_GetTouchpadScrollSwitch_001
1398 * @tc.desc: Get touchpad scroll switch
1399 * @tc.type: FUNC
1400 * @tc.require:
1401 */
1402 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadScrollSwitch_001, TestSize.Level1)
1403 {
1404 CALL_TEST_DEBUG;
1405 bool flagfalse = false;
1406 auto ret = InputManager::GetInstance()->GetTouchpadScrollSwitch(flagfalse);
1407 ASSERT_EQ(ret, RET_OK);
1408 bool flagtrue = true;
1409 ret = InputManager::GetInstance()->GetTouchpadScrollSwitch(flagtrue);
1410 ASSERT_EQ(ret, RET_OK);
1411 }
1412
1413 /**
1414 * @tc.name: InputManagerTest_SetTouchpadScrollDirection_001
1415 * @tc.desc: Set touchpad scroll direction
1416 * @tc.type: FUNC
1417 * @tc.require:
1418 */
1419 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadScrollDirection_001, TestSize.Level1)
1420 {
1421 CALL_TEST_DEBUG;
1422 auto ret = InputManager::GetInstance()->SetTouchpadScrollDirection(false);
1423 ASSERT_EQ(ret, RET_OK);
1424 ret = InputManager::GetInstance()->SetTouchpadScrollDirection(true);
1425 ASSERT_EQ(ret, RET_OK);
1426 }
1427
1428 /**
1429 * @tc.name: InputManagerTest_GetTouchpadScrollDirection_001
1430 * @tc.desc: Get touchpad scroll direction
1431 * @tc.type: FUNC
1432 * @tc.require:
1433 */
1434 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadScrollDirection_001, TestSize.Level1)
1435 {
1436 CALL_TEST_DEBUG;
1437 bool statefalse = false;
1438 auto ret = InputManager::GetInstance()->GetTouchpadScrollDirection(statefalse);
1439 ASSERT_EQ(ret, RET_OK);
1440 bool statetrue = true;
1441 ret = InputManager::GetInstance()->GetTouchpadScrollDirection(statetrue);
1442 ASSERT_EQ(ret, RET_OK);
1443 }
1444
1445 /**
1446 * @tc.name: InputManagerTest_SetPointerSpeed_001
1447 * @tc.desc: Set pointer speed
1448 * @tc.type: FUNC
1449 * @tc.require:
1450 */
1451 HWTEST_F(InputManagerTest, InputManagerTest_SetPointerSpeed_001, TestSize.Level1)
1452 {
1453 CALL_TEST_DEBUG;
1454 const int32_t speed = INVAID_VALUE;
1455 InputManager::GetInstance()->SetPointerSpeed(speed);
1456 int32_t speed1;
1457 InputManager::GetInstance()->GetPointerSpeed(speed1);
1458 ASSERT_EQ(speed1, 1);
1459 }
1460
1461 /**
1462 * @tc.name: InputManagerTest_SetPointerLocation_001
1463 * @tc.desc: Set pointer location
1464 * @tc.type: FUNC
1465 * @tc.require:
1466 */
1467 HWTEST_F(InputManagerTest, InputManagerTest_SetPointerLocation_001, TestSize.Level1)
1468 {
1469 CALL_TEST_DEBUG;
1470 int32_t x = 0;
1471 int32_t y = 0;
1472 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->SetPointerLocation(x, y));
1473 }
1474
1475 /**
1476 * @tc.name: InputManagerTest_GetTouchpadRightClickType_001
1477 * @tc.desc: Get touchpad right click type
1478 * @tc.type: FUNC
1479 * @tc.require:
1480 */
1481 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadRightClickType_001, TestSize.Level1)
1482 {
1483 CALL_TEST_DEBUG;
1484 int32_t newType = 1;
1485 int32_t ret = InputManager::GetInstance()->GetTouchpadRightClickType(newType);
1486 ASSERT_EQ(ret, RET_OK);
1487 }
1488
1489 /**
1490 * @tc.name: InputManagerTest_GetKeyState_001
1491 * @tc.desc: Get key state
1492 * @tc.type: FUNC
1493 * @tc.require:
1494 */
1495 HWTEST_F(InputManagerTest, InputManagerTest_GetKeyState_001, TestSize.Level1)
1496 {
1497 CALL_TEST_DEBUG;
1498 std::vector<int32_t> pressedKeys;
1499 std::map<int32_t, int32_t> specialKeysState;
1500 int32_t ret = InputManager::GetInstance()->GetKeyState(pressedKeys, specialKeysState);
1501 ASSERT_EQ(ret, RET_OK);
1502 }
1503
1504 /**
1505 * @tc.name: InputManagerTest_MarkProcessed_001
1506 * @tc.desc: Mark processed
1507 * @tc.type: FUNC
1508 * @tc.require:
1509 */
1510 HWTEST_F(InputManagerTest, InputManagerTest_MarkProcessed_001, TestSize.Level1)
1511 {
1512 CALL_TEST_DEBUG;
1513 int32_t x = 0;
1514 int64_t y = 0;
1515 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->MarkProcessed(x, y));
1516 }
1517
1518 /**
1519 * @tc.name: InputManagerTest_SetCustomCursor
1520 * @tc.desc: Test set the wrong windowId for SetCustomCursor
1521 * @tc.type: FUNC
1522 * @tc.require:
1523 */
1524 HWTEST_F(InputManagerTest, InputManagerTest_SetCustomCursor, TestSize.Level1)
1525 {
1526 CALL_TEST_DEBUG;
1527 int32_t fakeWindowId = 100;
1528 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
1529 PointerStyle pointerStyle;
1530 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
1531 ASSERT_NE(pixelMap, nullptr);
1532 pointerStyle.id = MOUSE_ICON::DEVELOPER_DEFINED_ICON;
1533 ASSERT_TRUE(InputManager::GetInstance()->SetCustomCursor(fakeWindowId, (void *)pixelMap.get(), 32, 32) == RET_ERR);
1534 }
1535
1536 /**
1537 * @tc.name: InputManagerTest_SetMouseIcon
1538 * @tc.desc: Test set the wrong windowId for SetMouseIcon
1539 * @tc.type: FUNC
1540 * @tc.require:
1541 */
1542 HWTEST_F(InputManagerTest, InputManagerTest_SetMouseIcon, TestSize.Level1)
1543 {
1544 CALL_TEST_DEBUG;
1545 int32_t fakeWindoId = 100;
1546 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
1547 PointerStyle pointerStyle;
1548 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
1549 ASSERT_NE(pixelMap, nullptr);
1550 pointerStyle.id = MOUSE_ICON::DEVELOPER_DEFINED_ICON;
1551 ASSERT_FALSE(InputManager::GetInstance()->SetMouseIcon(fakeWindoId, (void *)pixelMap.get()) == RET_ERR);
1552 }
1553
1554 /**
1555 * @tc.name: InputManagerTest_SetMouseHotSpot
1556 * @tc.desc: Test set the wrong windowId for SetMouseHotSpot
1557 * @tc.type: FUNC
1558 * @tc.require:
1559 */
1560 HWTEST_F(InputManagerTest, InputManagerTest_SetMouseHotSpot, TestSize.Level1)
1561 {
1562 CALL_TEST_DEBUG;
1563 PointerStyle pointerStyle;
1564 pointerStyle.id = MOUSE_ICON::CROSS;
1565 int32_t fakeWindoId = 100;
1566 int32_t mouseIcon = 20;
1567 ASSERT_TRUE(
1568 InputManager::GetInstance()->SetMouseHotSpot(fakeWindoId, mouseIcon, mouseIcon) == RET_ERR);
1569 }
1570
1571
1572 /**
1573 * @tc.name: InputManagerTest_SetKeyDownDuration_001
1574 * @tc.desc: Customize the delay time for starting the ability by using the shortcut key.
1575 * @tc.type: FUNC
1576 * @tc.require:
1577 */
1578 HWTEST_F(InputManagerTest, InputManagerTest_SetKeyDownDuration_001, TestSize.Level1)
1579 {
1580 CALL_TEST_DEBUG;
1581 std::string businessId = "";
1582 int32_t delay = KEY_DOWN_DURATION;
1583 ASSERT_EQ(PARAMETER_ERROR, InputManager::GetInstance()->SetKeyDownDuration(businessId, delay));
1584 }
1585
1586 /**
1587 * @tc.name: InputManagerTest_UnsubscribeSwitchEvent_001
1588 * @tc.desc: Unsubscribes from a switch input event.
1589 * @tc.type: FUNC
1590 * @tc.require:
1591 */
1592 HWTEST_F(InputManagerTest, InputManagerTest_UnsubscribeSwitchEvent_001, TestSize.Level1)
1593 {
1594 CALL_TEST_DEBUG;
1595 int32_t subscriberId = INVAID_VALUE;
1596 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UnsubscribeSwitchEvent(subscriberId));
1597 }
1598
1599 /**
1600 * @tc.name: InputManagerTest_ClearWindowPointerStyle_001
1601 * @tc.desc: Verify invalid parameter.
1602 * @tc.type: FUNC
1603 * @tc.require:SR000GGQL4 AR000GJNGN
1604 * @tc.author: yangguang
1605 */
1606 HWTEST_F(InputManagerTest, InputManagerTest_ClearWindowPointerStyle_001, TestSize.Level1)
1607 {
1608 CALL_TEST_DEBUG;
1609 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1610 CHKPV(window);
1611 uint32_t windowId = window->GetWindowId();
1612 PointerStyle pointerStyle;
1613 pointerStyle.id = MOUSE_ICON::CROSS;
1614 int32_t ret = InputManager::GetInstance()->SetPointerStyle(windowId, pointerStyle);
1615 InputManager::GetInstance()->ClearWindowPointerStyle(getpid(), windowId);
1616 PointerStyle style;
1617 ret = InputManager::GetInstance()->GetPointerStyle(windowId, style);
1618 EXPECT_TRUE(ret == RET_OK);
1619 }
1620
1621 HWTEST_F(InputManagerTest, InputManagerTest_SyncBundleName_001, TestSize.Level1)
1622 {
1623 CALL_TEST_DEBUG;
1624 auto mmiObserver = std::make_shared<IEventObserver>();
1625 InputManager::GetInstance()->AddInputEventObserver(mmiObserver);
1626 auto callbackPtr = GetPtr<InputEventCallback>();
1627 ASSERT_TRUE(callbackPtr != nullptr);
1628 int32_t monitorId = InputManagerUtil::TestAddMonitor(callbackPtr);
1629 InputManager::GetInstance()->SetNapStatus(10, 20, "bundleName_test", 0);
1630 std::map<std::tuple<int32_t, int32_t, std::string>, int32_t> mapBefore;
1631 InputManager::GetInstance()->GetAllMmiSubscribedEvents(mapBefore);
1632 for (auto map = mapBefore.begin(); map != mapBefore.end(); ++map) {
1633 if (std::get<TUPLE_PID>(map->first) == 10) {
1634 EXPECT_TRUE(std::get<TUPLE_UID>(map->first) == 20);
1635 EXPECT_TRUE(std::get<TUPLE_NAME>(map->first) == "bundleName_test");
1636 EXPECT_TRUE(map->second == 0);
1637 }
1638 }
1639 for (const auto& map : mapBefore) {
1640 MMI_HILOGD("All NapStatus in mapBefore pid:%{public}d, uid:%{public}d, name:%{public}s, status:%{public}d",
1641 std::get<TUPLE_PID>(map.first), std::get<TUPLE_UID>(map.first), std::get<TUPLE_NAME>(map.first).c_str(),
1642 map.second);
1643 }
1644 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1645 InputManagerUtil::TestRemoveMonitor(monitorId);
1646 InputManager::GetInstance()->SetNapStatus(10, 20, "bundleName_test", 2);
1647 std::map<std::tuple<int32_t, int32_t, std::string>, int32_t> mapAfter;
1648 InputManager::GetInstance()->GetAllMmiSubscribedEvents(mapAfter);
1649 for (const auto& map : mapAfter) {
1650 EXPECT_FALSE(std::get<TUPLE_PID>(map.first) == 10);
1651 EXPECT_FALSE(std::get<TUPLE_UID>(map.first) == 20);
1652 EXPECT_FALSE(std::get<TUPLE_NAME>(map.first) == "bundleName_test");
1653 }
1654 for (const auto& map : mapAfter) {
1655 MMI_HILOGD("All NapStatus in mapAfter pid:%{public}d, uid:%{public}d, name:%{public}s, status:%{public}d",
1656 std::get<TUPLE_PID>(map.first), std::get<TUPLE_UID>(map.first), std::get<TUPLE_NAME>(map.first).c_str(),
1657 map.second);
1658 }
1659 InputManager::GetInstance()->RemoveInputEventObserver(mmiObserver);
1660 }
1661
1662 /**
1663 * @tc.name: InputManager_InjectMouseEvent_001
1664 * @tc.desc: Injection interface detection
1665 * @tc.type: FUNC
1666 * @tc.require:AR000GJG6G
1667 */
1668 HWTEST_F(InputManagerTest, InputManager_InjectMouseEvent_001, TestSize.Level1)
1669 {
1670 CALL_TEST_DEBUG;
1671 auto pointerEvent = PointerEvent::Create();
1672 pointerEvent->SetButtonId(PointerEvent::MOUSE_BUTTON_LEFT);
1673 pointerEvent->SetButtonPressed(PointerEvent::MOUSE_BUTTON_LEFT);
1674 ASSERT_NE(pointerEvent, nullptr);
1675
1676 PointerEvent::PointerItem item;
1677 item.SetPointerId(0);
1678 item.SetDisplayX(200);
1679 item.SetDisplayY(200);
1680 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN);
1681 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1682 pointerEvent->SetPointerId(0);
1683 pointerEvent->AddPointerItem(item);
1684 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
1685 }
1686
1687 /**
1688 * @tc.name: InputManager_InjectMouseEvent_002
1689 * @tc.desc: Injection interface detection
1690 * @tc.type: FUNC
1691 * @tc.require:AR000GJG6G
1692 */
1693 HWTEST_F(InputManagerTest, InputManager_InjectMouseEvent_002, TestSize.Level1)
1694 {
1695 CALL_TEST_DEBUG;
1696 auto pointerEvent = PointerEvent::Create();
1697 pointerEvent->SetButtonId(PointerEvent::MOUSE_BUTTON_LEFT);
1698 pointerEvent->SetButtonPressed(PointerEvent::MOUSE_BUTTON_LEFT);
1699 ASSERT_NE(pointerEvent, nullptr);
1700
1701 PointerEvent::PointerItem item;
1702 item.SetPointerId(0);
1703 item.SetDisplayX(200);
1704 item.SetDisplayY(200);
1705 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_UP);
1706 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1707 pointerEvent->SetPointerId(0);
1708 pointerEvent->AddPointerItem(item);
1709 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
1710 }
1711
1712 /**
1713 * @tc.name: InputManager_InjectMouseEvent_003
1714 * @tc.desc: Injection interface detection
1715 * @tc.type: FUNC
1716 * @tc.require:AR000GJG6G
1717 */
1718 HWTEST_F(InputManagerTest, InputManager_InjectMouseEvent_003, TestSize.Level1)
1719 {
1720 CALL_TEST_DEBUG;
1721 auto pointerEvent = PointerEvent::Create();
1722 ASSERT_NE(pointerEvent, nullptr);
1723
1724 PointerEvent::PointerItem item;
1725 item.SetPointerId(0);
1726 item.SetDisplayX(200);
1727 item.SetDisplayY(200);
1728 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1729 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1730 pointerEvent->SetPointerId(0);
1731 pointerEvent->AddPointerItem(item);
1732 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
1733 }
1734
SimulateInputEventInjectKeyTest(int32_t keyAction,int32_t keyCode,bool isPressed,int32_t downTime)1735 static bool SimulateInputEventInjectKeyTest(int32_t keyAction, int32_t keyCode, bool isPressed, int32_t downTime)
1736 {
1737 auto keyEvent = KeyEvent::Create();
1738 if (keyEvent == nullptr) {
1739 return false;
1740 }
1741 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
1742 keyEvent->SetKeyCode(keyCode);
1743
1744 KeyEvent::KeyItem item;
1745 keyEvent->SetKeyAction(keyAction);
1746 item.SetKeyCode(keyCode);
1747 item.SetPressed(isPressed);
1748 item.SetDownTime(downTime);
1749 keyEvent->AddKeyItem(item);
1750 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
1751 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
1752 return true;
1753 }
1754
1755 /**
1756 * @tc.name: InputManager_InjectKeyEvent_001
1757 * @tc.desc: Injection interface detection
1758 * @tc.type: FUNC
1759 * @tc.require:
1760 */
1761 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_001, TestSize.Level1)
1762 {
1763 CALL_TEST_DEBUG;
__anon1bd2730b0f02(std::shared_ptr<KeyEvent> event) 1764 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
1765 MMI_HILOGD("Add monitor success");
1766 };
1767 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
1768 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
1769 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
1770 KeyEvent::KEYCODE_CALL_NOTIFICATION_CENTER, true, 500));
1771 InputManager::GetInstance()->RemoveMonitor(monitorId);
1772 }
1773
1774 /**
1775 * @tc.name: InputManager_InjectKeyEvent_002
1776 * @tc.desc: Injection interface detection
1777 * @tc.type: FUNC
1778 * @tc.require:
1779 */
1780 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_002, TestSize.Level1)
1781 {
1782 CALL_TEST_DEBUG;
__anon1bd2730b1002(std::shared_ptr<KeyEvent> event) 1783 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
1784 MMI_HILOGD("Add monitor success");
1785 };
1786 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
1787 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
1788 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
1789 KeyEvent::KEYCODE_CALL_CONTROL_CENTER, true, 500));
1790 InputManager::GetInstance()->RemoveMonitor(monitorId);
1791 }
1792
1793 /**
1794 * @tc.name: InputManager_InjectKeyEvent_003
1795 * @tc.desc: Injection interface detection
1796 * @tc.type: FUNC
1797 * @tc.require:
1798 */
1799 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_003, TestSize.Level1)
1800 {
1801 CALL_TEST_DEBUG;
__anon1bd2730b1102(std::shared_ptr<KeyEvent> event) 1802 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
1803 MMI_HILOGD("Add monitor success");
1804 };
1805 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
1806 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
1807 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
1808 KeyEvent::KEYCODE_CALL_NOTIFICATION_CENTER, false, 500));
1809 InputManager::GetInstance()->RemoveMonitor(monitorId);
1810 }
1811
1812 /**
1813 * @tc.name: InputManager_InjectKeyEvent_004
1814 * @tc.desc: Injection interface detection
1815 * @tc.type: FUNC
1816 * @tc.require:
1817 */
1818 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_004, TestSize.Level1)
1819 {
1820 CALL_TEST_DEBUG;
__anon1bd2730b1202(std::shared_ptr<KeyEvent> event) 1821 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
1822 MMI_HILOGD("Add monitor success");
1823 };
1824 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
1825 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
1826 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
1827 KeyEvent::KEYCODE_CALL_CONTROL_CENTER, false, 500));
1828 InputManager::GetInstance()->RemoveMonitor(monitorId);
1829 }
1830
1831 /**
1832 * @tc.name: InputManager_InjectKeyEvent_005
1833 * @tc.desc: Injection interface detection
1834 * @tc.type: FUNC
1835 * @tc.require:
1836 */
1837 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_005, TestSize.Level1)
1838 {
1839 CALL_TEST_DEBUG;
__anon1bd2730b1302(std::shared_ptr<KeyEvent> event) 1840 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
1841 MMI_HILOGD("Add monitor success");
1842 };
1843 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
1844 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
1845 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
1846 KeyEvent::KEYCODE_CALL_NOTIFICATION_CENTER, true, 1000));
1847 InputManager::GetInstance()->RemoveMonitor(monitorId);
1848 }
1849
1850 /**
1851 * @tc.name: InputManager_InjectKeyEvent_006
1852 * @tc.desc: Injection interface detection
1853 * @tc.type: FUNC
1854 * @tc.require:
1855 */
1856 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_006, TestSize.Level1)
1857 {
1858 CALL_TEST_DEBUG;
__anon1bd2730b1402(std::shared_ptr<KeyEvent> event) 1859 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
1860 MMI_HILOGD("Add monitor success");
1861 };
1862 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
1863 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
1864 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
1865 KeyEvent::KEYCODE_CALL_CONTROL_CENTER, true, 1000));
1866 InputManager::GetInstance()->RemoveMonitor(monitorId);
1867 }
1868
1869 /**
1870 * @tc.name: InputManager_InjectKeyEvent_007
1871 * @tc.desc: Injection interface detection
1872 * @tc.type: FUNC
1873 * @tc.require:
1874 */
1875 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_007, TestSize.Level1)
1876 {
1877 CALL_TEST_DEBUG;
__anon1bd2730b1502(std::shared_ptr<KeyEvent> event) 1878 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
1879 MMI_HILOGD("Add monitor success");
1880 };
1881 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
1882 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
1883 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
1884 KeyEvent::KEYCODE_CALL_NOTIFICATION_CENTER, false, 1000));
1885 InputManager::GetInstance()->RemoveMonitor(monitorId);
1886 }
1887
1888 /**
1889 * @tc.name: InputManager_InjectKeyEvent_008
1890 * @tc.desc: Injection interface detection
1891 * @tc.type: FUNC
1892 * @tc.require:
1893 */
1894 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_008, TestSize.Level1)
1895 {
1896 CALL_TEST_DEBUG;
__anon1bd2730b1602(std::shared_ptr<KeyEvent> event) 1897 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
1898 MMI_HILOGD("Add monitor success");
1899 };
1900 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
1901 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
1902 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
1903 KeyEvent::KEYCODE_CALL_CONTROL_CENTER, false, 1000));
1904 InputManager::GetInstance()->RemoveMonitor(monitorId);
1905 }
1906
1907 /**
1908 * @tc.name: InputManager_InjectKeyEvent_009
1909 * @tc.desc: Injection interface detection
1910 * @tc.type: FUNC
1911 * @tc.require:
1912 */
1913 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_009, TestSize.Level1)
1914 {
1915 CALL_TEST_DEBUG;
__anon1bd2730b1702(std::shared_ptr<KeyEvent> event) 1916 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
1917 MMI_HILOGD("Add monitor success");
1918 };
1919 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
1920 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
1921 auto keyEvent = KeyEvent::Create();
1922 ASSERT_NE(keyEvent, nullptr);
1923 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
1924
1925 KeyEvent::KeyItem itemFirst;
1926 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1927 keyEvent->SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
1928
1929 itemFirst.SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
1930 itemFirst.SetPressed(false);
1931 itemFirst.SetDownTime(1000);
1932 keyEvent->AddKeyItem(itemFirst);
1933
1934 KeyEvent::KeyItem itemSecond;
1935 itemSecond.SetKeyCode(KeyEvent::KEYCODE_R);
1936 itemSecond.SetPressed(true);
1937 itemSecond.SetDownTime(1000);
1938 keyEvent->AddKeyItem(itemSecond);
1939 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
1940 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
1941 InputManager::GetInstance()->RemoveMonitor(monitorId);
1942 }
1943
1944 /**
1945 * @tc.name: InputManager_InjectKeyEvent_010
1946 * @tc.desc: Injection interface detection
1947 * @tc.type: FUNC
1948 * @tc.require:
1949 */
1950 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_010, TestSize.Level1)
1951 {
1952 CALL_TEST_DEBUG;
__anon1bd2730b1802(std::shared_ptr<KeyEvent> event) 1953 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
1954 MMI_HILOGD("Add monitor success");
1955 };
1956 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
1957 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
1958 auto keyEvent = KeyEvent::Create();
1959 ASSERT_NE(keyEvent, nullptr);
1960 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
1961
1962 KeyEvent::KeyItem itemFirst;
1963 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1964 keyEvent->SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
1965
1966 itemFirst.SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
1967 itemFirst.SetPressed(false);
1968 itemFirst.SetDownTime(1000);
1969 keyEvent->AddKeyItem(itemFirst);
1970
1971 KeyEvent::KeyItem itemSecond;
1972 itemSecond.SetKeyCode(KeyEvent::KEYCODE_R);
1973 itemSecond.SetPressed(false);
1974 itemSecond.SetDownTime(1000);
1975 keyEvent->AddKeyItem(itemSecond);
1976 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
1977 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
1978 InputManager::GetInstance()->RemoveMonitor(monitorId);
1979 }
1980
1981 /**
1982 * @tc.name: InputManager_InjectKeyEvent_011
1983 * @tc.desc: Injection interface detection
1984 * @tc.type: FUNC
1985 * @tc.require:AR000GJG6G mymy
1986 */
1987 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_011, TestSize.Level1)
1988 {
1989 CALL_TEST_DEBUG;
__anon1bd2730b1902(std::shared_ptr<KeyEvent> event) 1990 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
1991 MMI_HILOGD("Add monitor success");
1992 };
1993 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
1994 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
1995 auto keyEvent = KeyEvent::Create();
1996 ASSERT_NE(keyEvent, nullptr);
1997 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
1998
1999 KeyEvent::KeyItem itemFirst;
2000 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
2001 keyEvent->SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
2002
2003 itemFirst.SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
2004 itemFirst.SetPressed(false);
2005 itemFirst.SetDownTime(500);
2006 keyEvent->AddKeyItem(itemFirst);
2007
2008 KeyEvent::KeyItem itemSecond;
2009 itemSecond.SetKeyCode(KeyEvent::KEYCODE_R);
2010 itemSecond.SetPressed(false);
2011 itemSecond.SetDownTime(500);
2012 keyEvent->AddKeyItem(itemSecond);
2013 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
2014 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2015 InputManager::GetInstance()->RemoveMonitor(monitorId);
2016 }
2017
2018 /**
2019 * @tc.name: InputManager_InjectKeyEvent_012
2020 * @tc.desc: Injection interface detection
2021 * @tc.type: FUNC
2022 * @tc.require:AR000GJG6G mymy
2023 */
2024 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_012, TestSize.Level1)
2025 {
2026 CALL_TEST_DEBUG;
__anon1bd2730b1a02(std::shared_ptr<KeyEvent> event) 2027 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
2028 MMI_HILOGD("Add monitor success");
2029 };
2030 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
2031 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
2032 auto keyEvent = KeyEvent::Create();
2033 ASSERT_NE(keyEvent, nullptr);
2034 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
2035
2036 KeyEvent::KeyItem itemFirst;
2037 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
2038 keyEvent->SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
2039
2040 itemFirst.SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
2041 itemFirst.SetPressed(false);
2042 itemFirst.SetDownTime(500);
2043 keyEvent->AddKeyItem(itemFirst);
2044
2045 KeyEvent::KeyItem itemSecond;
2046 itemSecond.SetKeyCode(KeyEvent::KEYCODE_R);
2047 itemSecond.SetPressed(true);
2048 itemSecond.SetDownTime(500);
2049 keyEvent->AddKeyItem(itemSecond);
2050 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
2051 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2052 InputManager::GetInstance()->RemoveMonitor(monitorId);
2053 }
2054
2055 /**
2056 * @tc.name: InputManager_InjectTouchEvent_001
2057 * @tc.desc: Injection interface detection
2058 * @tc.type: FUNC
2059 * @tc.require:AR000GJG6G
2060 */
2061 HWTEST_F(InputManagerTest, InputManager_InjectTouchEvent_001, TestSize.Level1)
2062 {
2063 CALL_TEST_DEBUG;
2064 auto pointerEvent = PointerEvent::Create();
2065 ASSERT_NE(pointerEvent, nullptr);
2066
2067 PointerEvent::PointerItem item;
2068 item.SetPointerId(0);
2069 item.SetDisplayX(200);
2070 item.SetDisplayY(200);
2071 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2072 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2073 pointerEvent->SetPointerId(0);
2074 pointerEvent->AddPointerItem(item);
2075 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2076 }
2077
2078 /**
2079 * @tc.name: InputManager_InjectTouchEvent_002
2080 * @tc.desc: Injection interface detection
2081 * @tc.type: FUNC
2082 * @tc.require:AR000GJG6G
2083 */
2084 HWTEST_F(InputManagerTest, InputManager_InjectTouchEvent_002, TestSize.Level1)
2085 {
2086 CALL_TEST_DEBUG;
2087 auto pointerEvent = PointerEvent::Create();
2088 ASSERT_NE(pointerEvent, nullptr);
2089
2090 PointerEvent::PointerItem item;
2091 item.SetPointerId(0);
2092 item.SetDisplayX(200);
2093 item.SetDisplayY(200);
2094 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2095 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2096 pointerEvent->SetPointerId(0);
2097 pointerEvent->AddPointerItem(item);
2098 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2099 }
2100
2101 /**
2102 * @tc.name: InputManager_InjectEvent_003
2103 * @tc.desc: Injection interface detection
2104 * @tc.type: FUNC
2105 * @tc.require:AR000GJG6G
2106 */
2107 HWTEST_F(InputManagerTest, InputManager_InjectEvent_003, TestSize.Level1)
2108 {
2109 CALL_TEST_DEBUG;
2110 auto keyEvent = KeyEvent::Create();
2111 ASSERT_NE(keyEvent, nullptr);
2112 ASSERT_NO_FATAL_FAILURE(keyEvent->SetRepeat(true));
2113 }
2114
2115 /**
2116 * @tc.name: InputManager_InjectEvent_001
2117 * @tc.desc: Injection interface detection
2118 * @tc.type: FUNC
2119 * @tc.require:AR000GJG6G
2120 */
2121 HWTEST_F(InputManagerTest, InputManager_InjectEvent_001, TestSize.Level1)
2122 {
2123 CALL_TEST_DEBUG;
2124 auto keyEvent = KeyEvent::Create();
2125 ASSERT_NE(keyEvent, nullptr);
2126 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
2127
2128 KeyEvent::KeyItem item;
2129 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
2130 item.SetKeyCode(2017);
2131 item.SetPressed(true);
2132 item.SetDownTime(500);
2133 keyEvent->AddKeyItem(item);
2134 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
2135 }
2136
2137 /**
2138 * @tc.name: InputManager_InjectEvent_002
2139 * @tc.desc: Injection interface detection
2140 * @tc.type: FUNC
2141 * @tc.require:AR000GJG6G
2142 */
2143 HWTEST_F(InputManagerTest, InputManager_InjectEvent_002, TestSize.Level1)
2144 {
2145 CALL_TEST_DEBUG;
2146 auto keyEvent = KeyEvent::Create();
2147 ASSERT_NE(keyEvent, nullptr);
2148 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
2149 std::vector<int32_t> downKey;
2150 downKey.push_back(2072);
2151 downKey.push_back(2017);
2152
2153 KeyEvent::KeyItem item[downKey.size()];
2154 for (size_t i = 0; i < downKey.size(); i++) {
2155 keyEvent->SetKeyCode(2072);
2156 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
2157 item[i].SetKeyCode(downKey[i]);
2158 item[i].SetPressed(true);
2159 item[i].SetDownTime(0);
2160 keyEvent->AddKeyItem(item[i]);
2161 }
2162 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
2163 }
2164
2165 /**
2166 * @tc.name: InputManagerTest_GetPointerColor_001
2167 * @tc.desc: Obtains the mouse color.
2168 * @tc.type: FUNC
2169 * @tc.require:
2170 */
2171 HWTEST_F(InputManagerTest, InputManagerTest_GetPointerColor_001, TestSize.Level1)
2172 {
2173 CALL_TEST_DEBUG;
2174 int32_t setColor = 0x000000;
2175 InputManager::GetInstance()->SetPointerColor(setColor);
2176 int32_t getColor = 3;
2177 ASSERT_TRUE(InputManager::GetInstance()->GetPointerColor(getColor) == RET_OK);
2178 }
2179
2180 /**
2181 * @tc.name: InputManagerTest_SimulateInputEventExt_001
2182 * @tc.desc: Obtains the mouse color.
2183 * @tc.type: FUNC
2184 * @tc.require:
2185 */
2186 HWTEST_F(InputManagerTest, InputManagerTest_SimulateInputEventExt_001, TestSize.Level1)
2187 {
2188 CALL_TEST_DEBUG;
2189 auto pointerEvent = PointerEvent::Create();
2190 ASSERT_NE(pointerEvent, nullptr);
2191
2192 PointerEvent::PointerItem item;
2193 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_TWO);
2194 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_ONE);
2195 item.SetPressure(POINTER_ITEM_PRESSURE);
2196 item.SetPointerId(0);
2197 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2198 pointerEvent->SetPointerId(0);
2199 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2200 pointerEvent->AddPointerItem(item);
2201
2202 #ifdef OHOS_BUILD_ENABLE_ANCO
2203 InputManager::GetInstance()->SimulateInputEventExt(pointerEvent);
2204 InputManager::GetInstance()->SimulateInputEventExt(pointerEvent);
2205 InputManager::GetInstance()->SimulateInputEventExt(pointerEvent);
2206 #endif // OHOS_BUILD_ENABLE_ANCO
2207 }
2208
2209 /**
2210 * @tc.name: InputManagerTest_SimulateInputEventExt_002
2211 * @tc.desc: Obtains the mouse color.
2212 * @tc.type: FUNC
2213 * @tc.require:
2214 */
2215 HWTEST_F(InputManagerTest, InputManagerTest_SimulateInputEventExt_002, TestSize.Level1)
2216 {
2217 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
2218 ASSERT_TRUE(injectDownEvent != nullptr);
2219 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
2220 KeyEvent::KeyItem kitDown;
2221 kitDown.SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
2222 kitDown.SetPressed(true);
2223 kitDown.SetDownTime(downTime);
2224 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
2225 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
2226 injectDownEvent->AddPressedKeyItems(kitDown);
2227
2228 #ifdef OHOS_BUILD_ENABLE_ANCO
2229 InputManager::GetInstance()->SimulateInputEventExt(injectDownEvent);
2230 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
2231 #endif // OHOS_BUILD_ENABLE_ANCO
2232 }
2233
2234 /**
2235 * @tc.name: InputManagerTest_SimulateInputEventZorder_001
2236 * @tc.desc: Simulate input evnet with zOrder.
2237 * @tc.type: FUNC
2238 * @tc.require:
2239 */
2240 HWTEST_F(InputManagerTest, InputManagerTest_SimulateInputEventZorder_001, TestSize.Level1)
2241 {
2242 CALL_TEST_DEBUG;
2243 auto pointerEvent = PointerEvent::Create();
2244 ASSERT_NE(pointerEvent, nullptr);
2245
2246 PointerEvent::PointerItem item;
2247 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_TWO);
2248 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_ONE);
2249 item.SetPressure(POINTER_ITEM_PRESSURE);
2250 item.SetPointerId(0);
2251 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2252 pointerEvent->SetPointerId(0);
2253 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2254 pointerEvent->AddPointerItem(item);
2255 pointerEvent->SetZOrder(10.0);
2256
2257 InputManager::GetInstance()->SimulateInputEvent(pointerEvent, 10.0);
2258 }
2259
2260 /**
2261 * @tc.name: InputManagerTest_SetShieldStatus_001
2262 * @tc.desc: Test set shield status
2263 * @tc.type: FUNC
2264 * @tc.require:
2265 */
2266 HWTEST_F(InputManagerTest, InputManagerTest_SetShieldStatus_001, TestSize.Level1)
2267 {
2268 bool factoryModeStatus = false;
2269 bool oobeModeStatus = false;
2270 int32_t ret = InputManager::GetInstance()->SetShieldStatus(SHIELD_MODE::FACTORY_MODE, true);
2271 ASSERT_EQ(ret, RET_OK);
2272 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::FACTORY_MODE, factoryModeStatus);
2273 ASSERT_EQ(ret, RET_OK);
2274 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::OOBE_MODE, oobeModeStatus);
2275 ASSERT_EQ(ret, RET_OK);
2276 ASSERT_TRUE(factoryModeStatus);
2277 ASSERT_FALSE(oobeModeStatus);
2278 ret = InputManager::GetInstance()->SetShieldStatus(SHIELD_MODE::OOBE_MODE, true);
2279 ASSERT_EQ(ret, RET_OK);
2280 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::FACTORY_MODE, factoryModeStatus);
2281 ASSERT_EQ(ret, RET_OK);
2282 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::OOBE_MODE, oobeModeStatus);
2283 ASSERT_EQ(ret, RET_OK);
2284 ASSERT_FALSE(factoryModeStatus);
2285 ASSERT_TRUE(oobeModeStatus);
2286 ret = InputManager::GetInstance()->SetShieldStatus(SHIELD_MODE::OOBE_MODE, false);
2287 ASSERT_EQ(ret, RET_OK);
2288 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::FACTORY_MODE, factoryModeStatus);
2289 ASSERT_EQ(ret, RET_OK);
2290 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::OOBE_MODE, oobeModeStatus);
2291 ASSERT_EQ(ret, RET_OK);
2292 ASSERT_FALSE(factoryModeStatus);
2293 ASSERT_FALSE(oobeModeStatus);
2294 }
2295
2296 /**
2297 * @tc.name: InputManager_SimulateInputEvent_001
2298 * @tc.desc: Set SourceType to SOURCE_TYPE_MOUSE
2299 * @tc.type: FUNC
2300 * @tc.require:SR000GGN6G
2301 */
2302 HWTEST_F(InputManagerTest, InputManager_SimulateInputEvent_001, TestSize.Level1)
2303 {
2304 CALL_TEST_DEBUG;
2305 auto pointerEvent = PointerEvent::Create();
2306 ASSERT_NE(pointerEvent, nullptr);
2307 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
2308 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2309 }
2310
2311 /**
2312 * @tc.name: InputManager_SimulateInputEvent_002
2313 * @tc.desc: Set SourceType to SOURCE_TYPE_TOUCHPAD
2314 * @tc.type: FUNC
2315 * @tc.require:SR000GGN6G
2316 */
2317 HWTEST_F(InputManagerTest, InputManager_SimulateInputEvent_002, TestSize.Level1)
2318 {
2319 CALL_TEST_DEBUG;
2320 auto pointerEvent = PointerEvent::Create();
2321 ASSERT_NE(pointerEvent, nullptr);
2322 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD);
2323 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2324 }
2325
2326 /**
2327 * @tc.name: InputManager_SimulateInputEvent_003
2328 * @tc.desc: Set SourceType to SOURCE_TYPE_TOUCHSCREEN
2329 * @tc.type: FUNC
2330 * @tc.require:SR000GGN6G
2331 */
2332 HWTEST_F(InputManagerTest, InputManager_SimulateInputEvent_003, TestSize.Level1)
2333 {
2334 CALL_TEST_DEBUG;
2335 auto pointerEvent = PointerEvent::Create();
2336 ASSERT_NE(pointerEvent, nullptr);
2337 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2338 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2339 }
2340
2341 /**
2342 * @tc.name: InputManager_SimulateInputEvent_004
2343 * @tc.desc: Set SourceType to SOURCE_TYPE_JOYSTICK
2344 * @tc.type: FUNC
2345 * @tc.require:SR000GGN6G
2346 */
2347 HWTEST_F(InputManagerTest, InputManager_SimulateInputEvent_004, TestSize.Level1)
2348 {
2349 CALL_TEST_DEBUG;
2350 auto pointerEvent = PointerEvent::Create();
2351 ASSERT_NE(pointerEvent, nullptr);
2352 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_JOYSTICK);
2353 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2354 }
2355
2356 /**
2357 * @tc.name: InputManager_SimulateInputEvent_005
2358 * @tc.desc: Set SourceType to invalid
2359 * @tc.type: FUNC
2360 * @tc.require:SR000GGN6G
2361 */
2362 HWTEST_F(InputManagerTest, InputManager_SimulateInputEvent_005, TestSize.Level1)
2363 {
2364 CALL_TEST_DEBUG;
2365 auto pointerEvent = PointerEvent::Create();
2366 ASSERT_NE(pointerEvent, nullptr);
2367 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_UNKNOWN);
2368 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2369 }
2370
2371 /**
2372 * @tc.name: InputManager_SimulateInputEvent_001
2373 * @tc.desc: SimulateInputEvent interface detection
2374 * @tc.type: FUNC
2375 * @tc.require:SR000GGN6G
2376 */
2377 HWTEST_F(InputManagerTest, InputManager_SimulateInputKeyEvent_001, TestSize.Level1)
2378 {
2379 CALL_TEST_DEBUG;
2380 auto keyEvent = KeyEvent::Create();
2381 ASSERT_NE(keyEvent, nullptr);
2382 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
2383 }
2384
2385 /**
2386 * @tc.name: InputManagerTest_SetWindowPointerStyle_001
2387 * @tc.desc: Verify valid parameter.
2388 * @tc.type: FUNC
2389 * @tc.require:SR000GGQL4 AR000GJNGN
2390 */
2391 HWTEST_F(InputManagerTest, InputManagerTest_SetWindowPointerStyle_001, TestSize.Level1)
2392 {
2393 CALL_TEST_DEBUG;
2394 auto window = WindowUtilsTest::GetInstance()->GetWindow();
2395 CHKPV(window);
2396 uint32_t windowId = window->GetWindowId();
2397 InputManager::GetInstance()->SetWindowPointerStyle(WindowArea::ENTER, getpid(), windowId);
2398 InputManager::GetInstance()->SetWindowPointerStyle(WindowArea::FOCUS_ON_TOP, getpid(), windowId);
2399 InputManager::GetInstance()->SetWindowPointerStyle(WindowArea::FOCUS_ON_RIGHT, getpid(), windowId);
2400 InputManager::GetInstance()->SetWindowPointerStyle(WindowArea::FOCUS_ON_BOTTOM_LEFT, getpid(), windowId);
2401 InputManager::GetInstance()->SetWindowPointerStyle(WindowArea::TOP_LIMIT, getpid(), windowId);
2402 InputManager::GetInstance()->SetWindowPointerStyle(WindowArea::BOTTOM_RIGHT_LIMIT, getpid(), windowId);
2403 ASSERT_NO_FATAL_FAILURE(window->GetWindowId());
2404 }
2405
2406 /**
2407 * @tc.name: InputManagerTest_RemoveInputEventFilter_001
2408 * @tc.desc: When eventFilterService is empty
2409 * @tc.type: FUNC
2410 * @tc.require:
2411 */
2412 HWTEST_F(InputManagerTest, InputManagerTest_RemoveInputEventFilter_001, TestSize.Level1)
2413 {
2414 CALL_TEST_DEBUG;
2415 int32_t ret = InputManager::GetInstance()->RemoveInputEventFilter(-1);
2416 ASSERT_EQ(ret, RET_OK);
2417 ret = InputManager::GetInstance()->RemoveInputEventFilter(0);
2418 ASSERT_EQ(ret, RET_OK);
2419 ret = InputManager::GetInstance()->RemoveInputEventFilter(1);
2420 ASSERT_EQ(ret, RET_OK);
2421 }
2422
2423 /**
2424 * @tc.name: InputManagerTest_RemoveInputEventFilter_002
2425 * @tc.desc: When the eventFilterService is full
2426 * @tc.type: FUNC
2427 * @tc.require:
2428 */
2429 HWTEST_F(InputManagerTest, InputManagerTest_RemoveInputEventFilter_002, TestSize.Level1)
2430 {
2431 CALL_DEBUG_ENTER;
2432 struct KeyFilter : public IInputEventFilter {
OnInputEventOHOS::MMI::KeyFilter2433 bool OnInputEvent(std::shared_ptr<KeyEvent> keyEvent) const override
2434 {
2435 MMI_HILOGI("KeyFilter::OnInputEvent enter,pid: %{public}d", getpid());
2436 return false;
2437 }
OnInputEventOHOS::MMI::KeyFilter2438 bool OnInputEvent(std::shared_ptr<PointerEvent> pointerEvent) const override
2439 {
2440 return false;
2441 }
2442 };
__anon1bd2730b1b02() 2443 auto addFilter = []() -> int32_t {
2444 auto filter = std::make_shared<KeyFilter>();
2445 uint32_t touchTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX);
2446 const int32_t filterId = InputManager::GetInstance()->AddInputEventFilter(filter, 220, touchTags);
2447 return filterId;
2448 };
2449 const size_t singleClientSuportMaxNum = 4;
2450 for (size_t i = 0; i < singleClientSuportMaxNum; ++i) {
2451 int32_t filterId = addFilter();
2452 ASSERT_NE(filterId, 10);
2453 }
2454 int32_t filterId = addFilter();
2455 ASSERT_EQ(filterId, RET_ERR);
2456 auto ret = InputManager::GetInstance()->RemoveInputEventFilter(RET_ERR);
2457 ASSERT_EQ(ret, RET_OK);
2458 }
2459
2460 /**
2461 * @tc.name: InputManagerTest_RemoveInputEventFilter_003
2462 * @tc.desc: Verify valid parameter.
2463 * @tc.type: FUNC
2464 * @tc.require:
2465 */
2466 HWTEST_F(InputManagerTest, InputManagerTest_RemoveInputEventFilter_003, TestSize.Level1)
2467 {
2468 CALL_DEBUG_ENTER;
2469 struct KeyFilter : public IInputEventFilter {
OnInputEventOHOS::MMI::KeyFilter2470 bool OnInputEvent(std::shared_ptr<KeyEvent> keyEvent) const override
2471 {
2472 MMI_HILOGI("KeyFilter::OnInputEvent enter,pid: %{public}d", getpid());
2473 return false;
2474 }
OnInputEventOHOS::MMI::KeyFilter2475 bool OnInputEvent(std::shared_ptr<PointerEvent> pointerEvent) const override
2476 {
2477 return false;
2478 }
2479 };
__anon1bd2730b1c02() 2480 auto addFilter = []() -> int32_t {
2481 auto filter = std::make_shared<KeyFilter>();
2482 uint32_t touchTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX);
2483 int32_t filterId = InputManager::GetInstance()->AddInputEventFilter(filter, 220, touchTags);
2484 return filterId;
2485 };
2486 int32_t filterId = addFilter();
2487 ASSERT_NE(filterId, RET_ERR);
2488 auto ret = InputManager::GetInstance()->RemoveInputEventFilter(filterId);
2489 ASSERT_EQ(ret, RET_OK);
2490 filterId = addFilter();
2491 ASSERT_NE(filterId, RET_ERR);
2492 ret = InputManager::GetInstance()->RemoveInputEventFilter(filterId);
2493 ASSERT_EQ(ret, RET_OK);
2494 }
2495
2496 /**
2497 * @tc.name: InputManager_SlideUpBrightScreenUnlockEvent_001
2498 * @tc.desc: Injection interface detection
2499 * @tc.type: FUNC
2500 * @tc.require:AR000GJG6G
2501 */
2502 HWTEST_F(InputManagerTest, InputManager_SlideUpBrightScreenUnlockEvent_001, TestSize.Level1)
2503 {
2504 CALL_TEST_DEBUG;
2505 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
2506 ASSERT_NE(injectDownEvent, nullptr);
2507 injectDownEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
2508
2509 KeyEvent::KeyItem kitDown;
2510 kitDown.SetKeyCode(KeyEvent::KEYCODE_F5);
2511 kitDown.SetPressed(true);
2512 kitDown.SetDownTime(500);
2513 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_F5);
2514 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
2515 injectDownEvent->AddPressedKeyItems(kitDown);
2516 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
2517
2518 std::shared_ptr<KeyEvent> injectUpEvent = KeyEvent::Create();
2519 ASSERT_NE(injectUpEvent, nullptr);
2520 injectDownEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
2521
2522 KeyEvent::KeyItem kitUp;
2523 kitUp.SetKeyCode(KeyEvent::KEYCODE_F5);
2524 kitUp.SetPressed(false);
2525 kitUp.SetDownTime(500);
2526 injectUpEvent->SetKeyCode(KeyEvent::KEYCODE_F5);
2527 injectUpEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
2528 injectUpEvent->RemoveReleasedKeyItems(kitUp);
2529 InputManager::GetInstance()->SimulateInputEvent(injectUpEvent);
2530 }
2531
2532 /**
2533 * @tc.name: InputManager_SimulateEvent_001
2534 * @tc.desc: Injection interface detection
2535 * @tc.type: FUNC
2536 * @tc.require:AR20240223308600
2537 */
2538 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_001, TestSize.Level1)
2539 {
2540 CALL_TEST_DEBUG;
2541 auto pointerEvent = InputManagerUtil::SetupSimulateEvent001();
2542 MMI_HILOGI("Before handle SimulateInputEvent");
2543 InputManagerUtil::PrintPointerEventId(pointerEvent);
2544 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2545 MMI_HILOGI("After handle SimulateInputEvent");
2546 InputManagerUtil::PrintPointerEventId(pointerEvent);
2547 }
2548
2549 /**
2550 * @tc.name: InputManager_SimulateEvent_002
2551 * @tc.desc: Injection interface detection
2552 * @tc.type: FUNC
2553 * @tc.require:AR20240223308600
2554 */
2555 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_002, TestSize.Level1)
2556 {
2557 CALL_TEST_DEBUG;
2558 auto pointerEvent = InputManagerUtil::SetupSimulateEvent002();
2559 MMI_HILOGI("Before handle SimulateInputEvent");
2560 InputManagerUtil::PrintPointerEventId(pointerEvent);
2561 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2562 MMI_HILOGI("After handle SimulateInputEvent");
2563 InputManagerUtil::PrintPointerEventId(pointerEvent);
2564 }
2565
2566 /**
2567 * @tc.name: InputManager_SimulateEvent_003
2568 * @tc.desc: Injection interface detection
2569 * @tc.type: FUNC
2570 * @tc.require:AR20240223308600
2571 */
2572 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_003, TestSize.Level1)
2573 {
2574 CALL_TEST_DEBUG;
2575 auto pointerEvent = InputManagerUtil::SetupSimulateEvent003();
2576 MMI_HILOGI("Before handle SimulateInputEvent");
2577 InputManagerUtil::PrintPointerEventId(pointerEvent);
2578 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2579 MMI_HILOGI("After handle SimulateInputEvent");
2580 InputManagerUtil::PrintPointerEventId(pointerEvent);
2581 }
2582
2583 /**
2584 * @tc.name: InputManager_SimulateEvent_004
2585 * @tc.desc: Injection interface detection
2586 * @tc.type: FUNC
2587 * @tc.require:AR20240223308600
2588 */
2589 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_004, TestSize.Level1)
2590 {
2591 CALL_TEST_DEBUG;
2592 auto pointerEvent = InputManagerUtil::SetupSimulateEvent004();
2593 MMI_HILOGI("Before handle SimulateInputEvent");
2594 InputManagerUtil::PrintPointerEventId(pointerEvent);
2595 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2596 MMI_HILOGI("After handle SimulateInputEvent");
2597 InputManagerUtil::PrintPointerEventId(pointerEvent);
2598 }
2599
2600 /**
2601 * @tc.name: InputManager_SimulateEvent_005
2602 * @tc.desc: Injection interface detection
2603 * @tc.type: FUNC
2604 * @tc.require:AR20240223308600
2605 */
2606 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_005, TestSize.Level1)
2607 {
2608 CALL_TEST_DEBUG;
2609 auto pointerEvent = InputManagerUtil::SetupSimulateEvent005();
2610 MMI_HILOGI("Before handle SimulateInputEvent");
2611 InputManagerUtil::PrintPointerEventId(pointerEvent);
2612 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2613 MMI_HILOGI("After handle SimulateInputEvent");
2614 InputManagerUtil::PrintPointerEventId(pointerEvent);
2615 }
2616
2617 /**
2618 * @tc.name: InputManager_SimulateEvent_006
2619 * @tc.desc: Injection interface detection
2620 * @tc.type: FUNC
2621 * @tc.require:AR20240223308600
2622 */
2623 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_006, TestSize.Level1)
2624 {
2625 CALL_TEST_DEBUG;
2626 auto pointerEvent = InputManagerUtil::SetupSimulateEvent006();
2627 MMI_HILOGI("Before handle SimulateInputEvent");
2628 InputManagerUtil::PrintPointerEventId(pointerEvent);
2629 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2630 MMI_HILOGI("After handle SimulateInputEvent");
2631 InputManagerUtil::PrintPointerEventId(pointerEvent);
2632 }
2633
2634 /**
2635 * @tc.name: InputManager_SimulateEvent_007
2636 * @tc.desc: Injection interface detection
2637 * @tc.type: FUNC
2638 * @tc.require:AR20240223308600
2639 */
2640 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_007, TestSize.Level1)
2641 {
2642 CALL_TEST_DEBUG;
2643 auto pointerEvent = InputManagerUtil::SetupSimulateEvent007();
2644 MMI_HILOGI("Before handle SimulateInputEvent");
2645 InputManagerUtil::PrintPointerEventId(pointerEvent);
2646 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2647 MMI_HILOGI("After handle SimulateInputEvent");
2648 InputManagerUtil::PrintPointerEventId(pointerEvent);
2649 }
2650
2651 /**
2652 * @tc.name: InputManager_SimulateEvent_008
2653 * @tc.desc: Injection interface detection
2654 * @tc.type: FUNC
2655 * @tc.require:AR20240223308600
2656 */
2657 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_008, TestSize.Level1)
2658 {
2659 CALL_TEST_DEBUG;
2660 auto pointerEvent = InputManagerUtil::SetupSimulateEvent008();
2661 MMI_HILOGI("Before handle SimulateInputEvent");
2662 InputManagerUtil::PrintPointerEventId(pointerEvent);
2663 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2664 MMI_HILOGI("After handle SimulateInputEvent");
2665 InputManagerUtil::PrintPointerEventId(pointerEvent);
2666 }
2667
2668 class ServiceWatcher final : public IInputServiceWatcher {
2669 public:
2670 ServiceWatcher() = default;
2671 ~ServiceWatcher() = default;
2672
OnServiceDied()2673 void OnServiceDied() override
2674 {}
2675 };
2676
2677 /**
2678 * @tc.name: InputManagerTest_InputServiceWatcher
2679 * @tc.desc: Verify service watcher.
2680 * @tc.type: FUNC
2681 * @tc.require:
2682 */
2683 HWTEST_F(InputManagerTest, InputManagerTest_InputServiceWatcher, TestSize.Level1)
2684 {
2685 auto watcher = std::make_shared<ServiceWatcher>();
2686 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->AddServiceWatcher(watcher));
2687 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->RemoveServiceWatcher(watcher));
2688 }
2689
2690 /**
2691 * @tc.name: InputManagerTest_MoveMouse_001
2692 * @tc.desc: MoveMouse interface detection
2693 * @tc.type: FUNC
2694 * @tc.require:
2695 */
2696 HWTEST_F(InputManagerTest, InputManagerTest_MoveMouse_001, TestSize.Level1)
2697 {
2698 CALL_TEST_DEBUG;
2699 int32_t offsetX = 20;
2700 int32_t offsetY = 20;
2701 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->MoveMouse(offsetX, offsetY));
2702 }
2703
2704 /**
2705 * @tc.name: InputManagerTest_MouseScrollRows_001
2706 * @tc.desc: SetMouseScrollRows and GetMouseScrollRows interface detection
2707 * @tc.type: FUNC
2708 * @tc.require:
2709 */
2710 HWTEST_F(InputManagerTest, InputManagerTest_MouseScrollRows_001, TestSize.Level1)
2711 {
2712 CALL_TEST_DEBUG;
2713 int32_t rows = 1;
2714 int32_t result = InputManager::GetInstance()->SetMouseScrollRows(rows);
2715 ASSERT_EQ(result, RET_OK);
2716 result = InputManager::GetInstance()->GetMouseScrollRows(rows);
2717 ASSERT_EQ(rows, 1);
2718 ASSERT_EQ(result, RET_OK);
2719 }
2720
2721 /**
2722 * @tc.name: InputManagerTest_SetCustomCursor_001
2723 * @tc.desc: SetCustomCursor interface detection
2724 * @tc.type: FUNC
2725 * @tc.require:
2726 */
2727 HWTEST_F(InputManagerTest, InputManagerTest_SetCustomCursor_001, TestSize.Level1)
2728 {
2729 CALL_TEST_DEBUG;
2730 int32_t windowId = 500;
2731 void* pixelMap = nullptr;
2732 int32_t result = InputManager::GetInstance()->SetCustomCursor(windowId, pixelMap);
2733 ASSERT_EQ(result, RET_ERR);
2734 }
2735
2736 /**
2737 * @tc.name: InputManagerTest_SetMouseIcon_001
2738 * @tc.desc: SetMouseIcon interface detection
2739 * @tc.type: FUNC
2740 * @tc.require:
2741 */
2742 HWTEST_F(InputManagerTest, InputManagerTest_SetMouseIcon_001, TestSize.Level1)
2743 {
2744 CALL_TEST_DEBUG;
2745 int32_t windowId = 500;
2746 void* pixelMap = nullptr;
2747 int32_t result = InputManager::GetInstance()->SetMouseIcon(windowId, pixelMap);
2748 ASSERT_NE(result, RET_OK);
2749 }
2750
2751 /**
2752 * @tc.name: InputManagerTest_SetMouseHotSpot_001
2753 * @tc.desc: SetMouseHotSpot interface detection
2754 * @tc.type: FUNC
2755 * @tc.require:
2756 */
2757 HWTEST_F(InputManagerTest, InputManagerTest_SetMouseHotSpot_001, TestSize.Level1)
2758 {
2759 CALL_TEST_DEBUG;
2760 int32_t windowId = 500;
2761 int32_t hotSpotX = 20;
2762 int32_t hotSpotY = 20;
2763 int32_t result = InputManager::GetInstance()->SetMouseHotSpot(windowId, hotSpotX, hotSpotY);
2764 ASSERT_EQ(result, RET_ERR);
2765 }
2766
2767 /**
2768 * @tc.name: InputManagerTest_PointerSize_001
2769 * @tc.desc: SetPointerSize and GetPointerSize interface detection
2770 * @tc.type: FUNC
2771 * @tc.require:
2772 */
2773 HWTEST_F(InputManagerTest, InputManagerTest_PointerSize_001, TestSize.Level1)
2774 {
2775 CALL_TEST_DEBUG;
2776 int32_t size = 5;
2777 int32_t result = InputManager::GetInstance()->SetPointerSize(size);
2778 ASSERT_EQ(result, RET_OK);
2779 result = InputManager::GetInstance()->GetPointerSize(size);
2780 ASSERT_EQ(size, 5);
2781 ASSERT_EQ(result, RET_OK);
2782 }
2783
2784 /**
2785 * @tc.name: InputManagerTest_MousePrimaryButton_001
2786 * @tc.desc: SetMousePrimaryButton and GetMousePrimaryButton interface detection
2787 * @tc.type: FUNC
2788 * @tc.require:
2789 */
2790 HWTEST_F(InputManagerTest, InputManagerTest_MousePrimaryButton_001, TestSize.Level1)
2791 {
2792 CALL_TEST_DEBUG;
2793 int32_t primaryButton = 2;
2794 int32_t result = InputManager::GetInstance()->SetMousePrimaryButton(primaryButton);
2795 ASSERT_EQ(result, RET_ERR);
2796 primaryButton = 1;
2797 result = InputManager::GetInstance()->SetMousePrimaryButton(primaryButton);
2798 ASSERT_EQ(result, RET_OK);
2799 result = InputManager::GetInstance()->GetMousePrimaryButton(primaryButton);
2800 ASSERT_EQ(primaryButton, 1);
2801 ASSERT_EQ(result, RET_OK);
2802 }
2803
2804 /**
2805 * @tc.name: InputManagerTest_TouchpadScrollDirection_001
2806 * @tc.desc: SetTouchpadScrollDirection and GetTouchpadScrollDirection interface detection
2807 * @tc.type: FUNC
2808 * @tc.require:
2809 */
2810 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadScrollDirection_001, TestSize.Level1)
2811 {
2812 CALL_TEST_DEBUG;
2813 bool state = true;
2814 int32_t result = InputManager::GetInstance()->SetTouchpadScrollDirection(state);
2815 ASSERT_EQ(result, RET_OK);
2816 result = InputManager::GetInstance()->GetTouchpadScrollDirection(state);
2817 ASSERT_EQ(state, true);
2818 ASSERT_EQ(result, RET_OK);
2819 }
2820
2821 /**
2822 * @tc.name: InputManagerTest_TouchpadScrollDirection_001
2823 * @tc.desc: SetTouchpadScrollDirection and GetTouchpadScrollDirection interface detection
2824 * @tc.type: FUNC
2825 * @tc.require:
2826 */
2827 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadScrollSwitch_001, TestSize.Level1)
2828 {
2829 CALL_TEST_DEBUG;
2830 bool switchFlag = true;
2831 int32_t result = InputManager::GetInstance()->SetTouchpadScrollSwitch(switchFlag);
2832 ASSERT_EQ(result, RET_OK);
2833 result = InputManager::GetInstance()->GetTouchpadScrollSwitch(switchFlag);
2834 ASSERT_EQ(switchFlag, true);
2835 ASSERT_EQ(result, RET_OK);
2836 }
2837
2838 /**
2839 * @tc.name: InputManagerTest_TouchpadPointerSpeed_001
2840 * @tc.desc: SetTouchpadPointerSpeed and GetTouchpadPointerSpeed interface detection
2841 * @tc.type: FUNC
2842 * @tc.require:
2843 */
2844 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadPointerSpeed_001, TestSize.Level1)
2845 {
2846 CALL_TEST_DEBUG;
2847 int32_t speed = 1;
2848 int32_t result = InputManager::GetInstance()->SetTouchpadPointerSpeed(speed);
2849 ASSERT_EQ(result, RET_OK);
2850 result = InputManager::GetInstance()->GetTouchpadPointerSpeed(speed);
2851 ASSERT_EQ(speed, 1);
2852 ASSERT_EQ(result, RET_OK);
2853 }
2854
2855 /**
2856 * @tc.name: InputManagerTest_TouchpadPinchSwitch_001
2857 * @tc.desc: SetTouchpadPinchSwitch and GetTouchpadPinchSwitch interface detection
2858 * @tc.type: FUNC
2859 * @tc.require:
2860 */
2861 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadPinchSwitch_001, TestSize.Level1)
2862 {
2863 CALL_TEST_DEBUG;
2864 bool switchFlag = true;
2865 int32_t result = InputManager::GetInstance()->SetTouchpadPinchSwitch(switchFlag);
2866 ASSERT_EQ(result, RET_OK);
2867 result = InputManager::GetInstance()->GetTouchpadPinchSwitch(switchFlag);
2868 ASSERT_EQ(switchFlag, true);
2869 ASSERT_EQ(result, RET_OK);
2870 }
2871
2872 /**
2873 * @tc.name: InputManagerTest_TouchpadSwipeSwitch_001
2874 * @tc.desc: SetTouchpadSwipeSwitch and GetTouchpadSwipeSwitch interface detection
2875 * @tc.type: FUNC
2876 * @tc.require:
2877 */
2878 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadSwipeSwitch_001, TestSize.Level1)
2879 {
2880 CALL_TEST_DEBUG;
2881 bool switchFlag = true;
2882 int32_t result = InputManager::GetInstance()->SetTouchpadSwipeSwitch(switchFlag);
2883 ASSERT_EQ(result, RET_OK);
2884 result = InputManager::GetInstance()->GetTouchpadSwipeSwitch(switchFlag);
2885 ASSERT_EQ(switchFlag, true);
2886 ASSERT_EQ(result, RET_OK);
2887 }
2888
2889 /**
2890 * @tc.name: InputManagerTest_TouchpadRightClickType_001
2891 * @tc.desc: SetTouchpadRightClickType and GetTouchpadRightClickType interface detection
2892 * @tc.type: FUNC
2893 * @tc.require:
2894 */
2895 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadRightClickType_001, TestSize.Level1)
2896 {
2897 CALL_TEST_DEBUG;
2898 int32_t type = 1;
2899 int32_t result = InputManager::GetInstance()->SetTouchpadRightClickType(type);
2900 ASSERT_EQ(result, RET_OK);
2901 result = InputManager::GetInstance()->GetTouchpadRightClickType(type);
2902 ASSERT_EQ(type, 1);
2903 ASSERT_EQ(result, RET_OK);
2904 }
2905
2906 /**
2907 * @tc.name: InputManagerTest_SetTouchpadTapSwitch_001
2908 * @tc.desc: Set touchpad tap switch
2909 * @tc.type: FUNC
2910 * @tc.require:
2911 */
2912 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadTapSwitch_001, TestSize.Level1)
2913 {
2914 CALL_TEST_DEBUG;
2915 bool flag = false;
2916 InputManager::GetInstance()->Authorize(true);
2917 ASSERT_TRUE(InputManager::GetInstance()->SetTouchpadTapSwitch(flag) == RET_OK);
2918 }
2919
2920 /**
2921 * @tc.name: InputManagerTest_GetTouchpadTapSwitch_001
2922 * @tc.desc: Get touchpad tap switch
2923 * @tc.type: FUNC
2924 * @tc.require:
2925 */
2926 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadTapSwitch_001, TestSize.Level1)
2927 {
2928 CALL_TEST_DEBUG;
2929 bool flag = true;
2930 InputManager::GetInstance()->SetTouchpadTapSwitch(flag);
2931 bool newFlag = true;
2932 InputManager::GetInstance()->Authorize(true);
2933 ASSERT_TRUE(InputManager::GetInstance()->GetTouchpadTapSwitch(newFlag) == RET_OK);
2934 ASSERT_TRUE(flag == newFlag);
2935 }
2936
2937 /**
2938 * @tc.name: InputManagerTest_SetCurrentUser_001
2939 * @tc.desc: set current user id
2940 * @tc.type: FUNC
2941 * @tc.require:
2942 */
2943 HWTEST_F(InputManagerTest, InputManagerTest_SetCurrentUser_001, TestSize.Level1)
2944 {
2945 int32_t userId = 10;
2946 int32_t ret = InputManager::GetInstance()->SetCurrentUser(userId);
2947 EXPECT_FALSE(ret == RET_OK);
2948 }
2949
2950 /**
2951 * @tc.name: InputManagerTest_HasIrEmitter
2952 * @tc.desc: Test HasIrEmitter
2953 * @tc.type: FUNC
2954 * @tc.require:
2955 */
2956 HWTEST_F(InputManagerTest, InputManagerTest_HasIrEmitter, TestSize.Level1)
2957 {
2958 bool hasIrEmitter = false;
2959 int32_t ret = InputManager::GetInstance()->HasIrEmitter(hasIrEmitter);
2960 EXPECT_EQ(ret, RET_OK);
2961 }
2962
2963 /**
2964 * @tc.name: InputManagerTest_GetInfraredFrequencies
2965 * @tc.desc: Test GetInfraredFrequencies
2966 * @tc.type: FUNC
2967 * @tc.require:
2968 */
2969 HWTEST_F(InputManagerTest, InputManagerTest_GetInfraredFrequencies, TestSize.Level1)
2970 {
2971 InfraredFrequency infraredFrequency;
2972 infraredFrequency.max_ = 30;
2973 infraredFrequency.min_ = 10;
2974 std::vector<InfraredFrequency> requencys;
2975 requencys.push_back(infraredFrequency);
2976 int32_t ret = InputManager::GetInstance()->GetInfraredFrequencies(requencys);
2977 EXPECT_EQ(ret, RET_OK);
2978 }
2979
2980 /**
2981 * @tc.name: InputManagerTest_TransmitInfrared
2982 * @tc.desc: Test TransmitInfrared
2983 * @tc.type: FUNC
2984 * @tc.require:
2985 */
2986 HWTEST_F(InputManagerTest, InputManagerTest_TransmitInfrared, TestSize.Level1)
2987 {
2988 int64_t number = 10;
2989 std::vector<int64_t> pattern = { 10, 20, 30 };
2990 int32_t ret = InputManager::GetInstance()->TransmitInfrared(number, pattern);
2991 EXPECT_EQ(ret, RET_OK);
2992 }
2993
2994 /**
2995 * @tc.name: InputManagerTest_SetTouchpadDoubleTapAndDragState_001
2996 * @tc.desc: Set Touchpad Double Tap And Drag State
2997 * @tc.type: FUNC
2998 * @tc.require:
2999 */
3000 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadDoubleTapAndDragState_001, TestSize.Level1)
3001 {
3002 CALL_TEST_DEBUG;
3003 bool switchFlag = true;
3004 int32_t ret = InputManager::GetInstance()->SetTouchpadDoubleTapAndDragState(switchFlag);
3005 EXPECT_EQ(ret, RET_ERR);
3006 }
3007
3008 /**
3009 * @tc.name: InputManagerTest_GetTouchpadDoubleTapAndDragState_001
3010 * @tc.desc: Get touchpad tap switch
3011 * @tc.type: FUNC
3012 * @tc.require:
3013 */
3014 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadDoubleTapAndDragState_001, TestSize.Level1)
3015 {
3016 CALL_TEST_DEBUG;
3017 bool flag = true;
3018 InputManager::GetInstance()->SetTouchpadDoubleTapAndDragState(flag);
3019 bool newFlag = true;
3020 ASSERT_TRUE(InputManager::GetInstance()->GetTouchpadDoubleTapAndDragState(newFlag) == RET_OK);
3021 ASSERT_TRUE(flag == newFlag);
3022 }
3023
3024 /**
3025 * @tc.name: InputManagerTest_SetTouchpadRotateSwitch_001
3026 * @tc.desc: Set touchpad rotate switch
3027 * @tc.type: FUNC
3028 * @tc.require:
3029 */
3030 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadRotateSwitch_001, TestSize.Level1)
3031 {
3032 CALL_TEST_DEBUG;
3033 bool rotateSwitch = false;
3034 ASSERT_TRUE(InputManager::GetInstance()->SetTouchpadRotateSwitch(rotateSwitch) == RET_OK);
3035 }
3036
3037 /**
3038 * @tc.name: InputManagerTest_GetTouchpadRotateSwitch_001
3039 * @tc.desc: Get touchpad rotate switch
3040 * @tc.type: FUNC
3041 * @tc.require:
3042 */
3043 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadRotateSwitch_001, TestSize.Level1)
3044 {
3045 CALL_TEST_DEBUG;
3046 bool rotateSwitch = true;
3047 InputManager::GetInstance()->SetTouchpadRotateSwitch(rotateSwitch);
3048 bool newRotateSwitch = true;
3049 ASSERT_TRUE(InputManager::GetInstance()->GetTouchpadRotateSwitch(newRotateSwitch) == RET_OK);
3050 ASSERT_TRUE(rotateSwitch == newRotateSwitch);
3051 }
3052
3053 /**
3054 * @tc.name: InputManagerTest_EnableHardwareCursorStats_001
3055 * @tc.desc: Enable hardware cursor stats
3056 * @tc.type: FUNC
3057 * @tc.require:
3058 */
3059 HWTEST_F(InputManagerTest, InputManagerTest_EnableHardwareCursorStats_001, TestSize.Level1)
3060 {
3061 CALL_TEST_DEBUG;
3062 #ifdef OHOS_BUILD_ENABLE_POINTER
3063 auto ret = InputManager::GetInstance()->EnableHardwareCursorStats(false);
3064 ASSERT_EQ(ret, RET_OK);
3065 ret = InputManager::GetInstance()->EnableHardwareCursorStats(true);
3066 ASSERT_EQ(ret, RET_OK);
3067 #else
3068 auto ret = InputManager::GetInstance()->EnableHardwareCursorStats(false);
3069 ASSERT_EQ(ret, ERROR_UNSUPPORT);
3070 ret = InputManager::GetInstance()->EnableHardwareCursorStats(true);
3071 ASSERT_EQ(ret, ERROR_UNSUPPORT);
3072 #endif // OHOS_BUILD_ENABLE_POINTER
3073 }
3074
3075 /**
3076 * @tc.name: InputManagerTest_GetHardwareCursorStats_001
3077 * @tc.desc: get hardware cursor stats
3078 * @tc.type: FUNC
3079 * @tc.require:
3080 */
3081 HWTEST_F(InputManagerTest, InputManagerTest_GetHardwareCursorStats_001, TestSize.Level1)
3082 {
3083 CALL_TEST_DEBUG;
3084 uint32_t frameCount = 1;
3085 uint32_t vsyncCount = 1;
3086 #ifdef OHOS_BUILD_ENABLE_POINTER
3087 auto ret = InputManager::GetInstance()->EnableHardwareCursorStats(true);
3088 ASSERT_EQ(ret, RET_OK);
3089 ret = InputManager::GetInstance()->EnableHardwareCursorStats(false);
3090 ASSERT_EQ(ret, RET_OK);
3091 ret = InputManager::GetInstance()->GetHardwareCursorStats(frameCount, vsyncCount);
3092 ASSERT_EQ(ret, RET_OK);
3093 ASSERT_EQ(frameCount, 0);
3094 ASSERT_EQ(vsyncCount, 0);
3095 #else
3096 auto ret = InputManager::GetInstance()->GetHardwareCursorStats(frameCount, vsyncCount);
3097 ASSERT_EQ(ret, ERROR_UNSUPPORT);
3098 #endif // OHOS_BUILD_ENABLE_POINTER
3099 }
3100
3101 /**
3102 * @tc.name: InputManagerTest_AppendExtraData_001
3103 * @tc.desc: Append Extra Data
3104 * @tc.type: FUNC
3105 * @tc.require:
3106 */
3107 HWTEST_F(InputManagerTest, InputManagerTest_AppendExtraData_001, TestSize.Level1)
3108 {
3109 CALL_TEST_DEBUG;
3110 ExtraData data;
3111 data.buffer.resize(1025);
3112 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->AppendExtraData(data));
3113 data.buffer.resize(512);
3114 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->AppendExtraData(data));
3115 }
3116
3117 #ifdef OHOS_BUILD_ENABLE_MAGICCURSOR
3118 /**
3119 * @tc.name: InputManagerTest_GetPointerSnapshot
3120 * @tc.desc: Test GetPointerSnapshot
3121 * @tc.require:
3122 */
3123 HWTEST_F(InputManagerTest, InputManagerTest_GetPointerSnapshot, TestSize.Level1)
3124 {
3125 CALL_TEST_DEBUG;
3126 void *pixelMap = nullptr;
3127 EXPECT_NE(InputManager::GetInstance()->GetPointerSnapshot(pixelMap), RET_OK);
3128 }
3129 #endif // OHOS_BUILD_ENABLE_MAGICCURSOR
3130
3131 /**
3132 * @tc.name: InputManagerTest_SkipPointerLayer_001
3133 * @tc.desc: Test SkipPointerLayer
3134 * @tc.require:
3135 */
3136 HWTEST_F(InputManagerTest, InputManagerTest_SkipPointerLayer_001, TestSize.Level1)
3137 {
3138 CALL_TEST_DEBUG;
3139 bool isSkip = true;
3140 int32_t ret = InputManager::GetInstance()->SkipPointerLayer(isSkip);
3141 EXPECT_EQ(ret, 305);
3142 isSkip = false;
3143 ret = InputManager::GetInstance()->SkipPointerLayer(isSkip);
3144 EXPECT_EQ(ret, 305);
3145 }
3146
3147 /**
3148 * @tc.name: InputManagerTest_ConvertToCapiKeyAction_001
3149 * @tc.desc: Test the funcation ConvertToCapiKeyAction
3150 * @tc.require:
3151 */
3152 HWTEST_F(InputManagerTest, InputManagerTest_ConvertToCapiKeyAction_001, TestSize.Level1)
3153 {
3154 CALL_TEST_DEBUG;
3155 int32_t keyAction = 0X00000002;
3156 int32_t ret = InputManager::GetInstance()->ConvertToCapiKeyAction(keyAction);
3157 EXPECT_NE(ret, -1);
3158 }
3159
3160 /**
3161 * @tc.name: InputManagerTest_GetIntervalSinceLastInput001
3162 * @tc.desc: GetIntervalSinceLastInput interface detection
3163 * @tc.type: FUNC
3164 * @tc.require:
3165 */
3166 HWTEST_F(InputManagerTest, InputManagerTest_GetIntervalSinceLastInput001, TestSize.Level1)
3167 {
3168 CALL_TEST_DEBUG;
3169 int64_t timeInterval = -1;
3170 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->GetIntervalSinceLastInput(timeInterval));
3171 }
3172
3173 /**
3174 * @tc.name: InputManagerTest_GetIntervalSinceLastInput002
3175 * @tc.desc: GetIntervalSinceLastInput interface detection
3176 * @tc.type: FUNC
3177 * @tc.require:
3178 */
3179 HWTEST_F(InputManagerTest, InputManagerTest_GetIntervalSinceLastInput002, TestSize.Level1)
3180 {
3181 CALL_TEST_DEBUG;
3182 auto pointerEvent = PointerEvent::Create();
3183 ASSERT_NE(pointerEvent, nullptr);
3184 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD);
3185 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3186 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3187 int64_t timeInterval = 0;
3188 int32_t result =InputManager::GetInstance()->GetIntervalSinceLastInput(timeInterval);
3189 ASSERT_EQ(result, RET_OK);
3190 EXPECT_GE(timeInterval, (TIME_WAIT_FOR_OP * SLEEP_MILLISECONDS));
3191 }
3192
3193 /**
3194 * @tc.name: InputManagerTest_GetIntervalSinceLastInput003
3195 * @tc.desc: GetIntervalSinceLastInput interface detection
3196 * @tc.type: FUNC
3197 * @tc.require:
3198 */
3199 HWTEST_F(InputManagerTest, InputManagerTest_GetIntervalSinceLastInput003, TestSize.Level1)
3200 {
3201 CALL_TEST_DEBUG;
3202 auto pointerEvent = PointerEvent::Create();
3203 ASSERT_NE(pointerEvent, nullptr);
3204 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD);
3205 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3206 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3207 auto keyEvent = KeyEvent::Create();
3208 ASSERT_NE(keyEvent, nullptr);
3209 KeyEvent::KeyItem itemSecond;
3210 itemSecond.SetKeyCode(KeyEvent::KEYCODE_R);
3211 itemSecond.SetPressed(true);
3212 itemSecond.SetDownTime(500);
3213 keyEvent->AddKeyItem(itemSecond);
3214 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3215 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3216 int64_t timeInterval = 0;
3217 int32_t result =InputManager::GetInstance()->GetIntervalSinceLastInput(timeInterval);
3218 ASSERT_EQ(result, RET_OK);
3219 EXPECT_GE(timeInterval, (TIME_WAIT_FOR_OP * SLEEP_MILLISECONDS));
3220 }
3221 } // namespace MMI
3222 } // namespace OHOS
3223