1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <cstdio>
17 #include <fstream>
18 #include <gtest/gtest.h>
19 #include <map>
20
21 #include "oh_input_manager.h"
22 #include "input_manager.h"
23 #include "pointer_event.h"
24 #include "mmi_log.h"
25
26 #undef MMI_LOG_TAG
27 #define MMI_LOG_TAG "OHInputManagerTest"
28
29 struct Input_KeyState {
30 int32_t keyCode;
31 int32_t keyState;
32 int32_t keySwitch;
33 };
34
35 struct Input_KeyEvent {
36 int32_t action;
37 int32_t keyCode;
38 int64_t actionTime { -1 };
39 int32_t windowId { -1 };
40 int32_t displayId { -1 };
41 };
42
43 struct Input_MouseEvent {
44 int32_t action;
45 int32_t displayX;
46 int32_t displayY;
47 int32_t globalX { INT32_MAX };
48 int32_t globalY { INT32_MAX };
49 int32_t button { -1 };
50 int32_t axisType { -1 };
51 float axisValue { 0.0f };
52 int64_t actionTime { -1 };
53 int32_t windowId { -1 };
54 int32_t displayId { -1 };
55 };
56
57 struct Input_TouchEvent {
58 int32_t action;
59 int32_t id;
60 int32_t displayX;
61 int32_t displayY;
62 int32_t globalX { INT32_MAX };
63 int32_t globalY { INT32_MAX };
64 int64_t actionTime { -1 };
65 int32_t windowId { -1 };
66 int32_t displayId { -1 };
67 };
68
69 struct Input_AxisEvent {
70 int32_t axisAction;
71 float displayX;
72 float displayY;
73 int32_t globalX;
74 int32_t globalY;
75 std::map<int32_t, double> axisValues;
76 int64_t actionTime { -1 };
77 int32_t sourceType;
78 int32_t axisEventType { -1 };
79 int32_t windowId { -1 };
80 int32_t displayId { -1 };
81 };
82 static std::shared_ptr<OHOS::MMI::PointerEvent> g_touchEvent = OHOS::MMI::PointerEvent::Create();
83 static bool g_interceptorTriggered = false;
MyKeyEventCallback(const Input_KeyEvent * keyEvent)84 void MyKeyEventCallback(const Input_KeyEvent* keyEvent)
85 {
86 if (keyEvent != nullptr) {
87 g_interceptorTriggered = true;
88 }
89 return;
90 }
DummyCallback(const Input_KeyEvent * keyEvent)91 void DummyCallback(const Input_KeyEvent* keyEvent)
92 {
93 return;
94 }
95 namespace OHOS {
96 namespace MMI {
97 namespace {
98 using namespace testing::ext;
99
100 constexpr int32_t MIN_MULTI_TOUCH_POINT_NUM { 0 };
101 constexpr int32_t MAX_MULTI_TOUCH_POINT_NUM { 10 };
102 constexpr int32_t UNKNOWN_MULTI_TOUCH_POINT_NUM { -1 };
103 constexpr int32_t DEFAULT_GLOBAL_X { -1 };
104 constexpr int32_t DEFAULT_GLOBAL_Y { -1 };
105 constexpr int32_t REQUEST_INJECTION_TIME_MS { 4000 };
106 } // namespace
107
108 class OHInputManagerTest : public testing::Test {
109 public:
SetUpTestCase(void)110 static void SetUpTestCase(void) {}
TearDownTestCase(void)111 static void TearDownTestCase(void) {}
112 };
113
114 /**
115 * @tc.name: OHInputManagerTest_OH_Input_CreateKeyState
116 * @tc.desc: Test the funcation OH_Input_CreateKeyState
117 * @tc.type: FUNC
118 * @tc.require:
119 */
120 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_CreateKeyState, TestSize.Level1)
121 {
122 CALL_TEST_DEBUG;
123 auto keyState = OH_Input_CreateKeyState();
124 EXPECT_EQ(keyState != nullptr, true);
125 EXPECT_NO_FATAL_FAILURE(OH_Input_DestroyKeyState(&keyState));
126 }
127
128 /**
129 * @tc.name: OHInputManagerTest_OH_Input_GetKeyState
130 * @tc.desc: Test the funcation OH_Input_GetKeyState
131 * @tc.type: FUNC
132 * @tc.require:
133 */
134 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetKeyState, TestSize.Level1)
135 {
136 CALL_TEST_DEBUG;
137 Input_KeyState inputKeyState;
138 inputKeyState.keyCode = -1;
139 EXPECT_EQ(OH_Input_GetKeyState(&inputKeyState), INPUT_PARAMETER_ERROR);
140 inputKeyState.keyCode = 2123;
141 EXPECT_EQ(OH_Input_GetKeyState(&inputKeyState), INPUT_PARAMETER_ERROR);
142 inputKeyState.keyCode = 2018;
143 EXPECT_EQ(OH_Input_GetKeyState(&inputKeyState), INPUT_PARAMETER_ERROR);
144 }
145
146 /**
147 * @tc.name: OHInputManagerTest_OH_Input_GetKeyState_001
148 * @tc.desc: Test the funcation OH_Input_GetKeyState
149 * @tc.type: FUNC
150 * @tc.require:
151 */
152 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetKeyState_001, TestSize.Level3)
153 {
154 CALL_TEST_DEBUG;
155 Input_KeyState inputKeyState;
156 inputKeyState.keyCode = KEYCODE_F12;
157 EXPECT_EQ(OH_Input_GetKeyState(&inputKeyState), INPUT_SUCCESS);
158 }
159
160 /**
161 * @tc.name: OHInputManagerTest_OH_Input_InjectKeyEvent
162 * @tc.desc: Test the funcation OH_Input_InjectKeyEvent
163 * @tc.type: FUNC
164 * @tc.require:
165 */
166 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_InjectKeyEvent, TestSize.Level1)
167 {
168 CALL_TEST_DEBUG;
169 Input_KeyEvent inputKeyEvent;
170 inputKeyEvent.keyCode = -1;
171 EXPECT_EQ(OH_Input_InjectKeyEvent(&inputKeyEvent), INPUT_PARAMETER_ERROR);
172 inputKeyEvent.keyCode = 2024;
173 inputKeyEvent.actionTime = -1;
174 inputKeyEvent.action = KEY_ACTION_DOWN;
175 EXPECT_EQ(OH_Input_InjectKeyEvent(&inputKeyEvent), INPUT_SUCCESS);
176 inputKeyEvent.actionTime = 100;
177 inputKeyEvent.action = KEY_ACTION_UP;
178 EXPECT_EQ(OH_Input_InjectKeyEvent(&inputKeyEvent), INPUT_SUCCESS);
179 inputKeyEvent.action = KEY_ACTION_CANCEL;
180 EXPECT_EQ(OH_Input_InjectKeyEvent(&inputKeyEvent), INPUT_SUCCESS);
181 }
182
183 /**
184 * @tc.name: OHInputManagerTest_OH_Input_InjectMouseEvent
185 * @tc.desc: Test the funcation OH_Input_InjectMouseEvent
186 * @tc.type: FUNC
187 * @tc.require:
188 */
189 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_InjectMouseEvent, TestSize.Level2)
190 {
191 CALL_TEST_DEBUG;
192 Input_MouseEvent inputMouseEvent;
193 inputMouseEvent.actionTime = -1;
194 inputMouseEvent.action = MOUSE_ACTION_CANCEL;
195 inputMouseEvent.axisType = MOUSE_AXIS_SCROLL_VERTICAL;
196 inputMouseEvent.button = MOUSE_BUTTON_NONE;
197 EXPECT_EQ(OH_Input_InjectMouseEvent(&inputMouseEvent), INPUT_PERMISSION_DENIED);
198
199 inputMouseEvent.actionTime = 100;
200 inputMouseEvent.action = MOUSE_ACTION_MOVE;
201 inputMouseEvent.axisType = MOUSE_AXIS_SCROLL_HORIZONTAL;
202 inputMouseEvent.button = MOUSE_BUTTON_LEFT;
203 EXPECT_EQ(OH_Input_InjectMouseEvent(&inputMouseEvent), INPUT_PERMISSION_DENIED);
204
205 inputMouseEvent.action = MOUSE_ACTION_BUTTON_DOWN;
206 inputMouseEvent.button = MOUSE_BUTTON_MIDDLE;
207 EXPECT_EQ(OH_Input_InjectMouseEvent(&inputMouseEvent), INPUT_PERMISSION_DENIED);
208
209 inputMouseEvent.action = MOUSE_ACTION_BUTTON_UP;
210 inputMouseEvent.button = MOUSE_BUTTON_RIGHT;
211 EXPECT_EQ(OH_Input_InjectMouseEvent(&inputMouseEvent), INPUT_PERMISSION_DENIED);
212
213 inputMouseEvent.action = MOUSE_ACTION_AXIS_BEGIN;
214 inputMouseEvent.button = MOUSE_BUTTON_FORWARD;
215 EXPECT_EQ(OH_Input_InjectMouseEvent(&inputMouseEvent), INPUT_PERMISSION_DENIED);
216
217 inputMouseEvent.action = MOUSE_ACTION_AXIS_UPDATE;
218 inputMouseEvent.button = MOUSE_BUTTON_BACK;
219 EXPECT_EQ(OH_Input_InjectMouseEvent(&inputMouseEvent), INPUT_PERMISSION_DENIED);
220
221 inputMouseEvent.globalX = 300;
222 inputMouseEvent.globalY = 300;
223 EXPECT_EQ(OH_Input_InjectMouseEvent(&inputMouseEvent), INPUT_PERMISSION_DENIED);
224
225 inputMouseEvent.globalX = INT32_MAX;
226 inputMouseEvent.globalY = 300;
227 EXPECT_EQ(OH_Input_InjectMouseEvent(&inputMouseEvent), INPUT_PERMISSION_DENIED);
228
229 inputMouseEvent.globalX = 300;
230 inputMouseEvent.globalY = INT32_MAX;
231 EXPECT_EQ(OH_Input_InjectMouseEvent(&inputMouseEvent), INPUT_PERMISSION_DENIED);
232
233 inputMouseEvent.globalX = INT32_MAX;
234 inputMouseEvent.globalY = INT32_MAX;
235 EXPECT_EQ(OH_Input_InjectMouseEvent(&inputMouseEvent), INPUT_PERMISSION_DENIED);
236 }
237
238 /**
239 * @tc.name: OHInputManagerTest_OH_Input_InjectTouchEvent
240 * @tc.desc: Test the funcation OH_Input_InjectTouchEvent
241 * @tc.type: FUNC
242 * @tc.require:
243 */
244 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_InjectTouchEvent, TestSize.Level1)
245 {
246 CALL_TEST_DEBUG;
247 Input_TouchEvent inputTouchEvent;
248 inputTouchEvent.actionTime = -1;
249 inputTouchEvent.action = TOUCH_ACTION_CANCEL;
250 EXPECT_EQ(OH_Input_InjectTouchEvent(&inputTouchEvent), INPUT_PARAMETER_ERROR);
251 }
252
253 /**
254 * @tc.name: OHInputManagerTest_OH_Input_InjectTouchEvent_001
255 * @tc.desc: Test the funcation OH_Input_InjectTouchEvent
256 * @tc.type: FUNC
257 * @tc.require:
258 */
259 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_InjectTouchEvent_001, TestSize.Level2)
260 {
261 CALL_TEST_DEBUG;
262 Input_TouchEvent inputTouchEvent;
263 inputTouchEvent.actionTime = 100;
264 inputTouchEvent.displayX = -1;
265 inputTouchEvent.action = TOUCH_ACTION_DOWN;
266 EXPECT_EQ(OH_Input_InjectTouchEvent(&inputTouchEvent), INPUT_PARAMETER_ERROR);
267 }
268
269 /**
270 * @tc.name: OHInputManagerTest_OH_Input_InjectTouchEvent_002
271 * @tc.desc: Test the funcation OH_Input_InjectTouchEvent
272 * @tc.type: FUNC
273 * @tc.require:
274 */
275 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_InjectTouchEvent_002, TestSize.Level1)
276 {
277 CALL_TEST_DEBUG;
278 Input_TouchEvent inputTouchEvent;
279 inputTouchEvent.actionTime = 100;
280 inputTouchEvent.action = TOUCH_ACTION_MOVE;
281 EXPECT_EQ(OH_Input_InjectTouchEvent(&inputTouchEvent), INPUT_PARAMETER_ERROR);
282 }
283
284 /**
285 * @tc.name: OHInputManagerTest_OH_Input_InjectTouchEvent_003
286 * @tc.desc: Test the funcation OH_Input_InjectTouchEvent
287 * @tc.type: FUNC
288 * @tc.require:
289 */
290 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_InjectTouchEvent_003, TestSize.Level1)
291 {
292 CALL_TEST_DEBUG;
293 Input_TouchEvent inputTouchEvent;
294 inputTouchEvent.actionTime = 100;
295 inputTouchEvent.action = TOUCH_ACTION_UP;
296 EXPECT_EQ(OH_Input_InjectTouchEvent(&inputTouchEvent), INPUT_PARAMETER_ERROR);
297 }
298
299 /**
300 * @tc.name: OHInputManagerTest_OH_Input_InjectTouchEvent_004
301 * @tc.desc: Test the funcation OH_Input_InjectTouchEvent
302 * @tc.type: FUNC
303 * @tc.require:
304 */
305 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_InjectTouchEvent_004, TestSize.Level1)
306 {
307 CALL_TEST_DEBUG;
308 Input_TouchEvent inputTouchEvent;
309 inputTouchEvent.actionTime = 100;
310 inputTouchEvent.action = static_cast<Input_TouchEventAction>(10);
311 EXPECT_EQ(OH_Input_InjectTouchEvent(&inputTouchEvent), INPUT_PARAMETER_ERROR);
312 }
313
314 /**
315 * @tc.name: OHInputManagerTest_OH_Input_InjectTouchEvent_005
316 * @tc.desc: Test the funcation OH_Input_InjectTouchEvent
317 * @tc.type: FUNC
318 * @tc.require:
319 */
320 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_InjectTouchEvent_005, TestSize.Level1)
321 {
322 CALL_TEST_DEBUG;
323 Input_TouchEvent inputTouchEvent;
324 inputTouchEvent.actionTime = 100;
325 inputTouchEvent.displayX = 300;
326 inputTouchEvent.displayY = -1;
327 inputTouchEvent.action = TOUCH_ACTION_DOWN;
328 EXPECT_EQ(OH_Input_InjectTouchEvent(&inputTouchEvent), INPUT_PARAMETER_ERROR);
329 }
330
331 /**
332 * @tc.name: OHInputManagerTest_OH_Input_InjectTouchEvent_006
333 * @tc.desc: Test the funcation OH_Input_InjectTouchEvent
334 * @tc.type: FUNC
335 * @tc.require:
336 */
337 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_InjectTouchEvent_006, TestSize.Level1)
338 {
339 CALL_TEST_DEBUG;
340 Input_TouchEvent inputTouchEvent;
341 inputTouchEvent.actionTime = 100;
342 inputTouchEvent.displayX = 300;
343 inputTouchEvent.displayY = 300;
344 inputTouchEvent.action = TOUCH_ACTION_DOWN;
345 EXPECT_EQ(OH_Input_InjectTouchEvent(&inputTouchEvent), INPUT_SUCCESS);
346
347 inputTouchEvent.action = TOUCH_ACTION_DOWN;
348 inputTouchEvent.globalX = 300;
349 inputTouchEvent.globalY = 300;
350 EXPECT_EQ(OH_Input_InjectTouchEvent(&inputTouchEvent), INPUT_SUCCESS);
351
352 inputTouchEvent.globalX = INT32_MAX;
353 inputTouchEvent.globalY = INT32_MAX;
354 EXPECT_EQ(OH_Input_InjectTouchEvent(&inputTouchEvent), INPUT_SUCCESS);
355
356 inputTouchEvent.globalX = INT32_MAX;
357 inputTouchEvent.globalY = 300;
358 EXPECT_EQ(OH_Input_InjectTouchEvent(&inputTouchEvent), INPUT_SUCCESS);
359
360 inputTouchEvent.globalX = 300;
361 inputTouchEvent.globalY = INT32_MAX;
362 EXPECT_EQ(OH_Input_InjectTouchEvent(&inputTouchEvent), INPUT_SUCCESS);
363 }
364
365 /**
366 * @tc.name: OHInputManagerTest_OH_Input_DestroyAxisEvent
367 * @tc.desc: Test the funcation OH_Input_DestroyAxisEvent
368 * @tc.type: FUNC
369 * @tc.require:
370 */
371 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_DestroyAxisEvent, TestSize.Level3)
372 {
373 CALL_TEST_DEBUG;
374 Input_AxisEvent *inputAxisEvent = nullptr;
375 EXPECT_EQ(OH_Input_DestroyAxisEvent(&inputAxisEvent), INPUT_PARAMETER_ERROR);
376 delete inputAxisEvent;
377 inputAxisEvent = nullptr;
378 }
379
380 /**
381 * @tc.name: OHInputManagerTest_OH_Input_CreateMouseEvent
382 * @tc.desc: Test the funcation OH_Input_CreateMouseEvent
383 * @tc.type: FUNC
384 * @tc.require:
385 */
386 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_CreateMouseEvent, TestSize.Level3)
387 {
388 CALL_TEST_DEBUG;
389 auto event = OH_Input_CreateMouseEvent();
390 EXPECT_EQ(event != nullptr, true);
391 EXPECT_NO_FATAL_FAILURE(OH_Input_DestroyMouseEvent(&event));
392 EXPECT_NO_FATAL_FAILURE(OH_Input_DestroyMouseEvent(nullptr));
393 }
394
395 /**
396 * @tc.name: OHInputManagerTest_OH_Input_DestroyAxisEvent_001
397 * @tc.desc: Test the funcation OH_Input_DestroyAxisEvent
398 * @tc.type: FUNC
399 * @tc.require:
400 */
401 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_DestroyAxisEvent_001, TestSize.Level3)
402 {
403 CALL_TEST_DEBUG;
404 Input_AxisEvent *inputAxisEvent = new (std::nothrow) Input_AxisEvent();
405 ASSERT_NE(inputAxisEvent, nullptr);
406 EXPECT_EQ(OH_Input_DestroyAxisEvent(&inputAxisEvent), INPUT_SUCCESS);
407 }
408
409 /**
410 * @tc.name: OHInputManagerTest_OH_Input_SetKeySwitch
411 * @tc.desc: Test the funcation OH_Input_SetKeySwitch
412 * @tc.type: FUNC
413 * @tc.require:
414 */
415 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_SetKeySwitch, TestSize.Level3)
416 {
417 CALL_TEST_DEBUG;
418 Input_KeyState keyState;
419 int32_t keySwitch = 1;
420 EXPECT_NO_FATAL_FAILURE(OH_Input_SetKeySwitch(nullptr, keySwitch));
421 EXPECT_NO_FATAL_FAILURE(OH_Input_SetKeySwitch(&keyState, keySwitch));
422 EXPECT_EQ(OH_Input_GetKeySwitch(nullptr), -1);
423 EXPECT_EQ(OH_Input_GetKeySwitch(&keyState), 1);
424 }
425
426 /**
427 * @tc.name: OHInputManagerTest_OH_Input_SetKeyPressed
428 * @tc.desc: Test the funcation OH_Input_SetKeyPressed
429 * @tc.type: FUNC
430 * @tc.require:
431 */
432 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_SetKeyPressed, TestSize.Level3)
433 {
434 CALL_TEST_DEBUG;
435 Input_KeyState keyState;
436 int32_t keyAction = 1;
437 EXPECT_NO_FATAL_FAILURE(OH_Input_SetKeyPressed(nullptr, keyAction));
438 EXPECT_NO_FATAL_FAILURE(OH_Input_SetKeyPressed(&keyState, keyAction));
439 EXPECT_EQ(OH_Input_GetKeyPressed(&keyState), 1);
440 EXPECT_EQ(OH_Input_GetKeyPressed(nullptr), -1);
441 }
442
443 /**
444 * @tc.name: OHInputManagerTest_OH_Input_GetKeyEventActionTime
445 * @tc.desc: Test the funcation OH_Input_GetKeyEventActionTime
446 * @tc.type: FUNC
447 * @tc.require:
448 */
449 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetKeyEventActionTime, TestSize.Level3)
450 {
451 CALL_TEST_DEBUG;
452 Input_KeyEvent keyEvent;
453 int32_t action = 1;
454 EXPECT_NO_FATAL_FAILURE(OH_Input_SetKeyEventActionTime(nullptr, action));
455 EXPECT_NO_FATAL_FAILURE(OH_Input_SetKeyEventActionTime(&keyEvent, action));
456 EXPECT_EQ(OH_Input_GetKeyEventActionTime(&keyEvent), 1);
457 EXPECT_EQ(OH_Input_GetKeyEventActionTime(nullptr), -1);
458 }
459
460 /**
461 * @tc.name: OHInputManagerTest_OH_Input_GetKeyEventWindowId
462 * @tc.desc: Test the funcation OH_Input_GetKeyEventWindowId
463 * @tc.type: FUNC
464 * @tc.require:
465 */
466 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetKeyEventWindowId, TestSize.Level3)
467 {
468 CALL_TEST_DEBUG;
469 Input_KeyEvent keyEvent;
470 int32_t action = 1;
471 EXPECT_NO_FATAL_FAILURE(OH_Input_SetKeyEventWindowId(nullptr, action));
472 EXPECT_NO_FATAL_FAILURE(OH_Input_SetKeyEventWindowId(&keyEvent, action));
473 EXPECT_EQ(OH_Input_GetKeyEventWindowId(&keyEvent), 1);
474 EXPECT_EQ(OH_Input_GetKeyEventWindowId(nullptr), -1);
475 }
476
477 /**
478 * @tc.name: OHInputManagerTest_OH_Input_GetKeyEventDisplayId
479 * @tc.desc: Test the funcation OH_Input_GetKeyEventDisplayId
480 * @tc.type: FUNC
481 * @tc.require:
482 */
483 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetKeyEventDisplayId, TestSize.Level3)
484 {
485 CALL_TEST_DEBUG;
486 Input_KeyEvent keyEvent;
487 int32_t action = 1;
488 EXPECT_NO_FATAL_FAILURE(OH_Input_SetKeyEventDisplayId(nullptr, action));
489 EXPECT_NO_FATAL_FAILURE(OH_Input_SetKeyEventDisplayId(&keyEvent, action));
490 EXPECT_EQ(OH_Input_GetKeyEventDisplayId(&keyEvent), 1);
491 EXPECT_EQ(OH_Input_GetKeyEventDisplayId(nullptr), -1);
492 }
493
494 /**
495 * @tc.name: OHInputManagerTest_OH_Input_GetKeyEventKeyCode
496 * @tc.desc: Test the funcation OH_Input_GetKeyEventKeyCode
497 * @tc.type: FUNC
498 * @tc.require:
499 */
500 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetKeyEventKeyCode, TestSize.Level3)
501 {
502 CALL_TEST_DEBUG;
503 Input_KeyEvent keyEvent;
504 int32_t keyCode = 1;
505 EXPECT_NO_FATAL_FAILURE(OH_Input_SetKeyEventKeyCode(nullptr, keyCode));
506 EXPECT_NO_FATAL_FAILURE(OH_Input_SetKeyEventKeyCode(&keyEvent, keyCode));
507 EXPECT_EQ(OH_Input_GetKeyEventKeyCode(&keyEvent), 1);
508 EXPECT_EQ(OH_Input_GetKeyEventKeyCode(nullptr), -1);
509 }
510
511 /**
512 * @tc.name: OHInputManagerTest_OH_Input_GetMouseEventAction
513 * @tc.desc: Test the funcation OH_Input_GetMouseEventAction
514 * @tc.type: FUNC
515 * @tc.require:
516 */
517 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetMouseEventAction, TestSize.Level3)
518 {
519 CALL_TEST_DEBUG;
520 Input_MouseEvent event;
521 int32_t action = 1;
522 EXPECT_NO_FATAL_FAILURE(OH_Input_SetMouseEventAction(nullptr, action));
523 EXPECT_NO_FATAL_FAILURE(OH_Input_SetMouseEventAction(&event, action));
524 EXPECT_EQ(OH_Input_GetMouseEventAction(&event), 1);
525 EXPECT_EQ(OH_Input_GetMouseEventAction(nullptr), -1);
526 }
527
528 /**
529 * @tc.name: OHInputManagerTest_OH_Input_GetMouseEventDisplayX
530 * @tc.desc: Test the funcation OH_Input_GetMouseEventDisplayX
531 * @tc.type: FUNC
532 * @tc.require:
533 */
534 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetMouseEventDisplayX, TestSize.Level3)
535 {
536 CALL_TEST_DEBUG;
537 Input_MouseEvent event;
538 int32_t displayX = 1;
539 EXPECT_NO_FATAL_FAILURE(OH_Input_SetMouseEventDisplayX(nullptr, displayX));
540 EXPECT_NO_FATAL_FAILURE(OH_Input_SetMouseEventDisplayX(&event, displayX));
541 EXPECT_EQ(OH_Input_GetMouseEventDisplayX(&event), 1);
542 EXPECT_EQ(OH_Input_GetMouseEventDisplayX(nullptr), -1);
543 }
544
545 /**
546 * @tc.name: OHInputManagerTest_OH_Input_GetMouseEventDisplayY
547 * @tc.desc: Test the funcation OH_Input_GetMouseEventDisplayY
548 * @tc.type: FUNC
549 * @tc.require:
550 */
551 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetMouseEventDisplayY, TestSize.Level3)
552 {
553 CALL_TEST_DEBUG;
554 Input_MouseEvent event;
555 int32_t displayY = 1;
556 EXPECT_NO_FATAL_FAILURE(OH_Input_SetMouseEventDisplayY(nullptr, displayY));
557 EXPECT_NO_FATAL_FAILURE(OH_Input_SetMouseEventDisplayY(&event, displayY));
558 EXPECT_EQ(OH_Input_GetMouseEventDisplayY(&event), 1);
559 EXPECT_EQ(OH_Input_GetMouseEventDisplayY(nullptr), -1);
560 }
561
562 /**
563 * @tc.name: OHInputManagerTest_OH_Input_GetMouseEventButton
564 * @tc.desc: Test the funcation OH_Input_GetMouseEventButton
565 * @tc.type: FUNC
566 * @tc.require:
567 */
568 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetMouseEventButton, TestSize.Level3)
569 {
570 CALL_TEST_DEBUG;
571 Input_MouseEvent event;
572 int32_t button = 1;
573 EXPECT_NO_FATAL_FAILURE(OH_Input_SetMouseEventButton(nullptr, button));
574 EXPECT_NO_FATAL_FAILURE(OH_Input_SetMouseEventButton(&event, button));
575 EXPECT_EQ(OH_Input_GetMouseEventButton(&event), 1);
576 EXPECT_EQ(OH_Input_GetMouseEventButton(nullptr), -1);
577 }
578
579 /**
580 * @tc.name: OHInputManagerTest_OH_Input_GetMouseEventWindowId
581 * @tc.desc: Test the funcation OH_Input_GetMouseEventWindowId
582 * @tc.type: FUNC
583 * @tc.require:
584 */
585 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetMouseEventWindowId, TestSize.Level3)
586 {
587 CALL_TEST_DEBUG;
588 Input_MouseEvent event;
589 int32_t windowId = 1;
590 EXPECT_NO_FATAL_FAILURE(OH_Input_SetMouseEventWindowId(nullptr, windowId));
591 EXPECT_NO_FATAL_FAILURE(OH_Input_SetMouseEventWindowId(&event, windowId));
592 EXPECT_EQ(OH_Input_GetMouseEventWindowId(&event), 1);
593 EXPECT_EQ(OH_Input_GetMouseEventWindowId(nullptr), -1);
594 }
595
596 /**
597 * @tc.name: OHInputManagerTest_OH_Input_GetMouseEventDisplayId
598 * @tc.desc: Test the funcation OH_Input_GetMouseEventDisplayId
599 * @tc.type: FUNC
600 * @tc.require:
601 */
602 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetMouseEventDisplayId, TestSize.Level3)
603 {
604 CALL_TEST_DEBUG;
605 Input_MouseEvent event;
606 int32_t displayId = 1;
607 EXPECT_NO_FATAL_FAILURE(OH_Input_SetMouseEventDisplayId(nullptr, displayId));
608 EXPECT_NO_FATAL_FAILURE(OH_Input_SetMouseEventDisplayId(&event, displayId));
609 EXPECT_EQ(OH_Input_GetMouseEventDisplayId(&event), 1);
610 EXPECT_EQ(OH_Input_GetMouseEventDisplayId(nullptr), -1);
611 }
612
613 /**
614 * @tc.name: OHInputManagerTest_OH_Input_GetMouseEventAxisType
615 * @tc.desc: Test the funcation OH_Input_GetMouseEventAxisType
616 * @tc.type: FUNC
617 * @tc.require:
618 */
619 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetMouseEventAxisType, TestSize.Level3)
620 {
621 CALL_TEST_DEBUG;
622 Input_MouseEvent event;
623 int32_t axisType = 1;
624 EXPECT_NO_FATAL_FAILURE(OH_Input_SetMouseEventAxisType(nullptr, axisType));
625 EXPECT_NO_FATAL_FAILURE(OH_Input_SetMouseEventAxisType(&event, axisType));
626 EXPECT_EQ(OH_Input_GetMouseEventAxisType(&event), 1);
627 EXPECT_EQ(OH_Input_GetMouseEventAxisType(nullptr), -1);
628 }
629
630 /**
631 * @tc.name: OHInputManagerTest_OH_Input_GetMouseEventActionTime
632 * @tc.desc: Test the funcation OH_Input_GetMouseEventActionTime
633 * @tc.type: FUNC
634 * @tc.require:
635 */
636 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetMouseEventActionTime, TestSize.Level3)
637 {
638 CALL_TEST_DEBUG;
639 Input_MouseEvent event;
640 int32_t actionTime = 1;
641 EXPECT_NO_FATAL_FAILURE(OH_Input_SetMouseEventActionTime(nullptr, actionTime));
642 EXPECT_NO_FATAL_FAILURE(OH_Input_SetMouseEventActionTime(&event, actionTime));
643 EXPECT_EQ(OH_Input_GetMouseEventActionTime(&event), 1);
644 EXPECT_EQ(OH_Input_GetMouseEventActionTime(nullptr), -1);
645 }
646
647 /**
648 * @tc.name: OHInputManagerTest_OH_Input_GetMouseEventAxisValue
649 * @tc.desc: Test the funcation OH_Input_GetMouseEventAxisValue
650 * @tc.type: FUNC
651 * @tc.require:
652 */
653 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetMouseEventAxisValue, TestSize.Level3)
654 {
655 CALL_TEST_DEBUG;
656 Input_MouseEvent event;
657 float axisValue = 1.0;
658 EXPECT_NO_FATAL_FAILURE(OH_Input_SetMouseEventAxisValue(nullptr, axisValue));
659 EXPECT_NO_FATAL_FAILURE(OH_Input_SetMouseEventAxisValue(&event, axisValue));
660 EXPECT_EQ(OH_Input_GetMouseEventAxisValue(&event), axisValue);
661 EXPECT_EQ(OH_Input_GetMouseEventAxisValue(nullptr), -1);
662 }
663
664 /**
665 * @tc.name: OHInputManagerTest_OH_Input_GetKeyEventAction
666 * @tc.desc: Test the funcation OH_Input_GetKeyEventAction
667 * @tc.type: FUNC
668 * @tc.require:
669 */
670 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetKeyEventAction, TestSize.Level3)
671 {
672 CALL_TEST_DEBUG;
673 Input_KeyEvent keyEvent;
674 int32_t action = 1;
675 EXPECT_NO_FATAL_FAILURE(OH_Input_SetKeyEventAction(nullptr, action));
676 EXPECT_NO_FATAL_FAILURE(OH_Input_SetKeyEventAction(&keyEvent, action));
677 EXPECT_EQ(OH_Input_GetKeyEventAction(&keyEvent), 1);
678 EXPECT_EQ(OH_Input_GetKeyEventAction(nullptr), -1);
679 }
680
681 /**
682 * @tc.name: OHInputManagerTest_OH_Input_GetTouchEventFingerId
683 * @tc.desc: Test the funcation OH_Input_GetTouchEventFingerId
684 * @tc.type: FUNC
685 * @tc.require:
686 */
687 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetTouchEventFingerId, TestSize.Level3)
688 {
689 CALL_TEST_DEBUG;
690 Input_TouchEvent event;
691 int32_t id = 1;
692 EXPECT_NO_FATAL_FAILURE(OH_Input_SetTouchEventFingerId(nullptr, id));
693 EXPECT_NO_FATAL_FAILURE(OH_Input_SetTouchEventFingerId(&event, id));
694 EXPECT_EQ(OH_Input_GetTouchEventFingerId(&event), 1);
695 EXPECT_EQ(OH_Input_GetTouchEventFingerId(nullptr), -1);
696 }
697
698 /**
699 * @tc.name: OHInputManagerTest_OH_Input_GetTouchEventDisplayY
700 * @tc.desc: Test the funcation OH_Input_GetTouchEventDisplayY
701 * @tc.type: FUNC
702 * @tc.require:
703 */
704 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetTouchEventDisplayY, TestSize.Level3)
705 {
706 CALL_TEST_DEBUG;
707 Input_TouchEvent event;
708 int32_t displayX = 1;
709 EXPECT_NO_FATAL_FAILURE(OH_Input_SetTouchEventDisplayY(nullptr, displayX));
710 EXPECT_NO_FATAL_FAILURE(OH_Input_SetTouchEventDisplayY(&event, displayX));
711 EXPECT_EQ(OH_Input_GetTouchEventDisplayY(&event), 1);
712 EXPECT_EQ(OH_Input_GetTouchEventDisplayY(nullptr), -1);
713 }
714
715 /**
716 * @tc.name: OHInputManagerTest_OH_Input_GetTouchEventWindowId
717 * @tc.desc: Test the funcation OH_Input_GetTouchEventWindowId
718 * @tc.type: FUNC
719 * @tc.require:
720 */
721 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetTouchEventWindowId, TestSize.Level3)
722 {
723 CALL_TEST_DEBUG;
724 Input_TouchEvent event;
725 int32_t windowId = 1;
726 EXPECT_NO_FATAL_FAILURE(OH_Input_SetTouchEventWindowId(nullptr, windowId));
727 EXPECT_NO_FATAL_FAILURE(OH_Input_SetTouchEventWindowId(&event, windowId));
728 EXPECT_EQ(OH_Input_GetTouchEventWindowId(&event), 1);
729 EXPECT_EQ(OH_Input_GetTouchEventWindowId(nullptr), -1);
730 }
731
732 /**
733 * @tc.name: OHInputManagerTest_OH_Input_GetAxisEventAction
734 * @tc.desc: Test the funcation OH_Input_GetAxisEventAction
735 * @tc.type: FUNC
736 * @tc.require:
737 */
738 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetAxisEventAction, TestSize.Level3)
739 {
740 CALL_TEST_DEBUG;
741 auto event = OH_Input_CreateAxisEvent();
742 EXPECT_NO_FATAL_FAILURE(OH_Input_SetAxisEventAction(nullptr, InputEvent_AxisAction::AXIS_ACTION_BEGIN));
743 EXPECT_NO_FATAL_FAILURE(OH_Input_SetAxisEventAction(event, InputEvent_AxisAction::AXIS_ACTION_BEGIN));
744 InputEvent_AxisAction action;
745 OH_Input_GetAxisEventAction(event, &action);
746 EXPECT_EQ(action, InputEvent_AxisAction::AXIS_ACTION_BEGIN);
747 EXPECT_EQ(OH_Input_GetAxisEventAction(nullptr, &action), INPUT_PARAMETER_ERROR);
748 EXPECT_EQ(OH_Input_GetAxisEventAction(nullptr, nullptr), INPUT_PARAMETER_ERROR);
749 OH_Input_DestroyAxisEvent(&event);
750 }
751
752 /**
753 * @tc.name: OHInputManagerTest_OH_Input_GetAxisEventAxisValue
754 * @tc.desc: Test the funcation OH_Input_GetAxisEventAxisValue
755 * @tc.type: FUNC
756 * @tc.require:
757 */
758 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetAxisEventAxisValue, TestSize.Level3)
759 {
760 CALL_TEST_DEBUG;
761 auto event = OH_Input_CreateAxisEvent();
762 InputEvent_AxisType type = InputEvent_AxisType::AXIS_TYPE_PINCH;
763 EXPECT_NO_FATAL_FAILURE(OH_Input_SetAxisEventAxisValue(nullptr, type, 1));
764 EXPECT_NO_FATAL_FAILURE(OH_Input_SetAxisEventAxisValue(event, type, 1));
765 double axisValue;
766 OH_Input_GetAxisEventAxisValue(event, type, &axisValue);
767 EXPECT_EQ(axisValue, 1);
768 EXPECT_EQ(OH_Input_GetAxisEventAxisValue(nullptr, type, &axisValue), INPUT_PARAMETER_ERROR);
769 EXPECT_EQ(OH_Input_GetAxisEventAxisValue(event, type, nullptr), INPUT_PARAMETER_ERROR);
770 OH_Input_DestroyAxisEvent(&event);
771 }
772
773 /**
774 * @tc.name: OHInputManagerTest_OH_Input_GetAxisEventActionTime
775 * @tc.desc: Test the funcation OH_Input_GetAxisEventActionTime
776 * @tc.type: FUNC
777 * @tc.require:
778 */
779 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetAxisEventActionTime, TestSize.Level3)
780 {
781 CALL_TEST_DEBUG;
782 auto event = OH_Input_CreateAxisEvent();
783 int64_t actionTime = 1;
784 EXPECT_NO_FATAL_FAILURE(OH_Input_SetAxisEventActionTime(nullptr, actionTime));
785 EXPECT_NO_FATAL_FAILURE(OH_Input_SetAxisEventActionTime(event, actionTime));
786 actionTime = 0;
787 OH_Input_GetAxisEventActionTime(event, &actionTime);
788 EXPECT_EQ(actionTime, 1);
789 EXPECT_EQ(OH_Input_GetAxisEventActionTime(nullptr, &actionTime), INPUT_PARAMETER_ERROR);
790 EXPECT_EQ(OH_Input_GetAxisEventActionTime(event, nullptr), INPUT_PARAMETER_ERROR);
791 OH_Input_DestroyAxisEvent(&event);
792 }
793
794 /**
795 * @tc.name: OHInputManagerTest_OH_Input_GetAxisEventType
796 * @tc.desc: Test the funcation OH_Input_GetAxisEventType
797 * @tc.type: FUNC
798 * @tc.require:
799 */
800 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetAxisEventType, TestSize.Level3)
801 {
802 CALL_TEST_DEBUG;
803 auto event = OH_Input_CreateAxisEvent();
804 InputEvent_AxisEventType axisEventType = InputEvent_AxisEventType::AXIS_EVENT_TYPE_PINCH;
805 EXPECT_NO_FATAL_FAILURE(OH_Input_SetAxisEventType(nullptr, axisEventType));
806 EXPECT_NO_FATAL_FAILURE(OH_Input_SetAxisEventType(event, axisEventType));
807 axisEventType = InputEvent_AxisEventType::AXIS_EVENT_TYPE_SCROLL;
808 OH_Input_GetAxisEventType(event, &axisEventType);
809 EXPECT_EQ(axisEventType, InputEvent_AxisEventType::AXIS_EVENT_TYPE_PINCH);
810 EXPECT_EQ(OH_Input_GetAxisEventType(nullptr, &axisEventType), INPUT_PARAMETER_ERROR);
811 EXPECT_EQ(OH_Input_GetAxisEventType(event, nullptr), INPUT_PARAMETER_ERROR);
812 OH_Input_DestroyAxisEvent(&event);
813 }
814
815 /**
816 * @tc.name: OHInputManagerTest_OH_Input_GetAxisEventSourceType
817 * @tc.desc: Test the funcation OH_Input_GetAxisEventSourceType
818 * @tc.type: FUNC
819 * @tc.require:
820 */
821 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetAxisEventSourceType, TestSize.Level3)
822 {
823 CALL_TEST_DEBUG;
824 auto event = OH_Input_CreateAxisEvent();
825 InputEvent_SourceType type = InputEvent_SourceType::SOURCE_TYPE_TOUCHSCREEN;
826 EXPECT_NO_FATAL_FAILURE(OH_Input_SetAxisEventSourceType(nullptr, type));
827 EXPECT_NO_FATAL_FAILURE(OH_Input_SetAxisEventSourceType(event, type));
828 type = InputEvent_SourceType::SOURCE_TYPE_MOUSE;
829 OH_Input_GetAxisEventSourceType(event, &type);
830 EXPECT_EQ(type, InputEvent_SourceType::SOURCE_TYPE_TOUCHSCREEN);
831 EXPECT_EQ(OH_Input_GetAxisEventSourceType(nullptr, &type), INPUT_PARAMETER_ERROR);
832 EXPECT_EQ(OH_Input_GetAxisEventSourceType(event, nullptr), INPUT_PARAMETER_ERROR);
833 OH_Input_DestroyAxisEvent(&event);
834 }
835
836 /**
837 * @tc.name: OHInputManagerTest_OH_Input_GetAxisEventWindowId
838 * @tc.desc: Test the funcation OH_Input_GetAxisEventWindowId
839 * @tc.type: FUNC
840 * @tc.require:
841 */
842 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetAxisEventWindowId, TestSize.Level3)
843 {
844 CALL_TEST_DEBUG;
845 auto event = OH_Input_CreateAxisEvent();
846 int32_t windowId = 1;
847 EXPECT_NO_FATAL_FAILURE(OH_Input_SetAxisEventWindowId(nullptr, windowId));
848 EXPECT_NO_FATAL_FAILURE(OH_Input_SetAxisEventWindowId(event, windowId));
849 windowId = 0;
850 OH_Input_GetAxisEventWindowId(event, &windowId);
851 EXPECT_EQ(windowId, 1);
852 EXPECT_EQ(OH_Input_GetAxisEventWindowId(nullptr, &windowId), INPUT_PARAMETER_ERROR);
853 EXPECT_EQ(OH_Input_GetAxisEventWindowId(event, nullptr), INPUT_PARAMETER_ERROR);
854 OH_Input_DestroyAxisEvent(&event);
855 }
856
857 /**
858 * @tc.name: OHInputManagerTest_OH_Input_GetAxisEventDisplayId
859 * @tc.desc: Test the funcation OH_Input_GetAxisEventDisplayId
860 * @tc.type: FUNC
861 * @tc.require:
862 */
863 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetAxisEventDisplayId, TestSize.Level3)
864 {
865 CALL_TEST_DEBUG;
866 auto event = OH_Input_CreateAxisEvent();
867 int32_t displayId = 1;
868 EXPECT_NO_FATAL_FAILURE(OH_Input_SetAxisEventDisplayId(nullptr, displayId));
869 EXPECT_NO_FATAL_FAILURE(OH_Input_SetAxisEventDisplayId(event, displayId));
870 displayId = 0;
871 OH_Input_GetAxisEventDisplayId(event, &displayId);
872 EXPECT_EQ(displayId, 1);
873 EXPECT_EQ(OH_Input_GetAxisEventDisplayId(nullptr, &displayId), INPUT_PARAMETER_ERROR);
874 EXPECT_EQ(OH_Input_GetAxisEventDisplayId(event, nullptr), INPUT_PARAMETER_ERROR);
875 OH_Input_DestroyAxisEvent(&event);
876 }
877
878 /**
879 * @tc.name: OHInputManagerTest_OH_Input_GetAxisEventGlobalX
880 * @tc.desc: Test the funcation OH_Input_GetAxisEventGlobalX
881 * @tc.type: FUNC
882 * @tc.require:
883 */
884 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetAxisEventGlobalX, TestSize.Level3)
885 {
886 CALL_TEST_DEBUG;
887 auto event = OH_Input_CreateAxisEvent();
888 int32_t globalX = 1;
889 EXPECT_NO_FATAL_FAILURE(OH_Input_SetAxisEventGlobalX(nullptr, globalX));
890 EXPECT_NO_FATAL_FAILURE(OH_Input_SetAxisEventGlobalX(event, globalX));
891 globalX = 0;
892 OH_Input_GetAxisEventGlobalX(event, &globalX);
893 EXPECT_EQ(globalX, 1);
894 EXPECT_EQ(OH_Input_GetAxisEventGlobalX(nullptr, &globalX), INPUT_PARAMETER_ERROR);
895 EXPECT_EQ(OH_Input_GetAxisEventGlobalX(event, nullptr), INPUT_PARAMETER_ERROR);
896 OH_Input_DestroyAxisEvent(&event);
897 }
898
899 /**
900 * @tc.name: OHInputManagerTest_OH_Input_GetAxisEventGlobalY
901 * @tc.desc: Test the funcation OH_Input_GetAxisEventGlobalY
902 * @tc.type: FUNC
903 * @tc.require:
904 */
905 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetAxisEventGlobalY, TestSize.Level3)
906 {
907 CALL_TEST_DEBUG;
908 auto event = OH_Input_CreateAxisEvent();
909 int32_t globalY = 1;
910 EXPECT_NO_FATAL_FAILURE(OH_Input_SetAxisEventGlobalY(nullptr, globalY));
911 EXPECT_NO_FATAL_FAILURE(OH_Input_SetAxisEventGlobalY(event, globalY));
912 globalY = 0;
913 OH_Input_GetAxisEventGlobalY(event, &globalY);
914 EXPECT_EQ(globalY, 1);
915 EXPECT_EQ(OH_Input_GetAxisEventGlobalY(nullptr, &globalY), INPUT_PARAMETER_ERROR);
916 EXPECT_EQ(OH_Input_GetAxisEventGlobalY(event, nullptr), INPUT_PARAMETER_ERROR);
917 OH_Input_DestroyAxisEvent(&event);
918 }
919
920 /**
921 * @tc.name: OHInputManagerTest_OH_Input_GetIntervalSinceLastInput
922 * @tc.desc: Test the funcation OH_Input_GetIntervalSinceLastInput
923 * @tc.type: FUNC
924 * @tc.require:
925 */
926 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetIntervalSinceLastInput, TestSize.Level3)
927 {
928 CALL_TEST_DEBUG;
929 int64_t time = 1;
930 EXPECT_EQ(OH_Input_GetIntervalSinceLastInput(nullptr), INPUT_PARAMETER_ERROR);
931 EXPECT_NO_FATAL_FAILURE(OH_Input_GetIntervalSinceLastInput(&time));
932 }
933
934 /**
935 * @tc.name: OHInputManagerTest_OH_Input_RemoveInputEventInterceptor
936 * @tc.desc: Test the funcation OH_Input_RemoveInputEventInterceptor
937 * @tc.type: FUNC
938 * @tc.require:
939 */
940 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_RemoveInputEventInterceptor, TestSize.Level3)
941 {
942 CALL_TEST_DEBUG;
943 EXPECT_NO_FATAL_FAILURE(OH_Input_RemoveInputEventInterceptor());
944 EXPECT_NO_FATAL_FAILURE(OH_Input_RemoveKeyEventInterceptor());
945 }
946
947 /**
948 * @tc.name: OHInputManagerTest_OH_Input_GetRepeat
949 * @tc.desc: Test the funcation OH_Input_GetRepeat
950 * @tc.type: FUNC
951 * @tc.require:
952 */
953 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetRepeat, TestSize.Level3)
954 {
955 CALL_TEST_DEBUG;
956 auto key = OH_Input_CreateHotkey();
957 bool isRepeat = true;
958 EXPECT_NO_FATAL_FAILURE(OH_Input_SetRepeat(key, isRepeat));
959 EXPECT_EQ(OH_Input_GetRepeat(nullptr, nullptr), INPUT_PARAMETER_ERROR);
960 EXPECT_EQ(OH_Input_GetRepeat(key, nullptr), INPUT_PARAMETER_ERROR);
961 EXPECT_EQ(OH_Input_GetRepeat(key, &isRepeat), INPUT_SUCCESS);
962 OH_Input_DestroyHotkey(&key);
963 }
964
965 /**
966 * @tc.name: OHInputManagerTest_OH_Input_GetAllSystemHotkeys
967 * @tc.desc: Test the funcation OH_Input_GetAllSystemHotkeys
968 * @tc.type: FUNC
969 * @tc.require:
970 */
971 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetAllSystemHotkeys, TestSize.Level3)
972 {
973 CALL_TEST_DEBUG;
974 int32_t count = 256;
975 Input_Hotkey **key = OH_Input_CreateAllSystemHotkeys(count);
976 EXPECT_EQ(OH_Input_GetAllSystemHotkeys(nullptr, nullptr), INPUT_PARAMETER_ERROR);
977 EXPECT_EQ(OH_Input_GetAllSystemHotkeys(key, nullptr), INPUT_PARAMETER_ERROR);
978 EXPECT_EQ(OH_Input_GetAllSystemHotkeys(key, &count), INPUT_SUCCESS);
979 EXPECT_NO_FATAL_FAILURE(OH_Input_DestroyAllSystemHotkeys(key, count));
980
981 count = 3;
982 auto keys = OH_Input_CreateAllSystemHotkeys(count);
983 EXPECT_NO_FATAL_FAILURE(OH_Input_DestroyAllSystemHotkeys(keys, count));
984 }
985
986 /**
987 * @tc.name: OHInputManagerTest_OH_Input_GetFinalKey
988 * @tc.desc: Test the funcation OH_Input_GetFinalKey
989 * @tc.type: FUNC
990 * @tc.require:
991 */
992 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetFinalKey, TestSize.Level3)
993 {
994 CALL_TEST_DEBUG;
995 Input_Hotkey *key = OH_Input_CreateHotkey();
996 int32_t finalKey = 1;
997 EXPECT_NO_FATAL_FAILURE(OH_Input_SetFinalKey(nullptr, finalKey));
998 EXPECT_NO_FATAL_FAILURE(OH_Input_SetFinalKey(key, finalKey));
999 finalKey = 0;
1000 EXPECT_EQ(OH_Input_GetFinalKey(nullptr, nullptr), INPUT_PARAMETER_ERROR);
1001 EXPECT_EQ(OH_Input_GetFinalKey(key, nullptr), INPUT_PARAMETER_ERROR);
1002 EXPECT_EQ(OH_Input_GetFinalKey(key, &finalKey), INPUT_SUCCESS);
1003 OH_Input_DestroyHotkey(&key);
1004 }
1005
1006 /**
1007 * @tc.name: OHInputManagerTest_OH_Input_AddKeyEventMonitor
1008 * @tc.desc: Test the funcation OH_Input_AddKeyEventMonitor
1009 * @tc.type: FUNC
1010 * @tc.require:
1011 */
1012 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_AddKeyEventMonitor_001, TestSize.Level3)
1013 {
1014 CALL_TEST_DEBUG;
__anonaa5665ab0202(const Input_KeyEvent *keyEvent) 1015 Input_KeyEventCallback callback1 = [](const Input_KeyEvent *keyEvent) {};
1016 EXPECT_NO_FATAL_FAILURE(OH_Input_AddKeyEventMonitor(nullptr));
1017 EXPECT_NO_FATAL_FAILURE(OH_Input_AddKeyEventMonitor(callback1));
1018 EXPECT_NO_FATAL_FAILURE(OH_Input_RemoveKeyEventMonitor(nullptr));
1019 EXPECT_NO_FATAL_FAILURE(OH_Input_RemoveKeyEventMonitor(callback1));
1020
__anonaa5665ab0302(auto mouseEvent) 1021 Input_MouseEventCallback callback2 = [](auto mouseEvent) {};
1022 EXPECT_NO_FATAL_FAILURE(OH_Input_AddMouseEventMonitor(nullptr));
1023 EXPECT_NO_FATAL_FAILURE(OH_Input_AddMouseEventMonitor(callback2));
1024 EXPECT_NO_FATAL_FAILURE(OH_Input_RemoveMouseEventMonitor(nullptr));
1025 EXPECT_NO_FATAL_FAILURE(OH_Input_RemoveMouseEventMonitor(callback2));
1026
__anonaa5665ab0402(auto mouseEvent) 1027 Input_TouchEventCallback callback3 = [](auto mouseEvent) {};
1028 EXPECT_NO_FATAL_FAILURE(OH_Input_AddTouchEventMonitor(nullptr));
1029 EXPECT_NO_FATAL_FAILURE(OH_Input_AddTouchEventMonitor(callback3));
1030 EXPECT_NO_FATAL_FAILURE(OH_Input_RemoveTouchEventMonitor(nullptr));
1031 EXPECT_NO_FATAL_FAILURE(OH_Input_RemoveTouchEventMonitor(callback3));
1032
__anonaa5665ab0502(auto mouseEvent) 1033 Input_AxisEventCallback callback4 = [](auto mouseEvent) {};
1034 EXPECT_NO_FATAL_FAILURE(OH_Input_AddAxisEventMonitorForAll(nullptr));
1035 EXPECT_NO_FATAL_FAILURE(OH_Input_AddAxisEventMonitorForAll(callback4));
1036 EXPECT_NO_FATAL_FAILURE(OH_Input_RemoveAxisEventMonitorForAll(nullptr));
1037 EXPECT_NO_FATAL_FAILURE(OH_Input_RemoveAxisEventMonitorForAll(callback4));
1038 }
1039
1040 /**
1041 * @tc.name: OHInputManagerTest_OH_Input_AddAxisEventMonitor
1042 * @tc.desc: Test the funcation OH_Input_AddAxisEventMonitor
1043 * @tc.type: FUNC
1044 * @tc.require:
1045 */
1046 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_AddAxisEventMonitor, TestSize.Level3)
1047 {
1048 CALL_TEST_DEBUG;
1049 InputEvent_AxisEventType type = InputEvent_AxisEventType::AXIS_EVENT_TYPE_PINCH;
1050 EXPECT_EQ(OH_Input_AddAxisEventMonitor(type, nullptr), INPUT_PARAMETER_ERROR);
__anonaa5665ab0602(const Input_AxisEvent *axisEvent) 1051 auto callback = [](const Input_AxisEvent *axisEvent) {};
1052 EXPECT_NO_FATAL_FAILURE(OH_Input_AddAxisEventMonitor(type, callback));
1053 }
1054
1055 /**
1056 * @tc.name: OHInputManagerTest_OH_Input_GetAxisEventDisplayY
1057 * @tc.desc: Test the funcation OH_Input_GetAxisEventDisplayY
1058 * @tc.type: FUNC
1059 * @tc.require:
1060 */
1061 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetAxisEventDisplayY, TestSize.Level3)
1062 {
1063 CALL_TEST_DEBUG;
1064 auto event = OH_Input_CreateAxisEvent();
1065 EXPECT_NO_FATAL_FAILURE(OH_Input_SetAxisEventDisplayY(nullptr, 1));
1066 EXPECT_NO_FATAL_FAILURE(OH_Input_SetAxisEventDisplayY(event, 1));
1067 float displayY;
1068 OH_Input_GetAxisEventDisplayY(event, &displayY);
1069 EXPECT_EQ(displayY, 1);
1070 EXPECT_EQ(OH_Input_GetAxisEventDisplayY(nullptr, &displayY), INPUT_PARAMETER_ERROR);
1071 EXPECT_EQ(OH_Input_GetAxisEventDisplayY(nullptr, nullptr), INPUT_PARAMETER_ERROR);
1072 OH_Input_DestroyAxisEvent(&event);
1073 }
1074
1075 /**
1076 * @tc.name: OHInputManagerTest_OH_Input_GetAxisEventDisplayX
1077 * @tc.desc: Test the funcation OH_Input_GetAxisEventDisplayX
1078 * @tc.type: FUNC
1079 * @tc.require:
1080 */
1081 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetAxisEventDisplayX, TestSize.Level3)
1082 {
1083 CALL_TEST_DEBUG;
1084 auto event = OH_Input_CreateAxisEvent();
1085 EXPECT_NO_FATAL_FAILURE(OH_Input_SetAxisEventDisplayX(nullptr, 1));
1086 EXPECT_NO_FATAL_FAILURE(OH_Input_SetAxisEventDisplayX(event, 1));
1087 float displayX;
1088 OH_Input_GetAxisEventDisplayX(event, &displayX);
1089 EXPECT_EQ(displayX, 1);
1090 EXPECT_EQ(OH_Input_GetAxisEventDisplayX(nullptr, &displayX), INPUT_PARAMETER_ERROR);
1091 EXPECT_EQ(OH_Input_GetAxisEventDisplayX(nullptr, nullptr), INPUT_PARAMETER_ERROR);
1092 OH_Input_DestroyAxisEvent(&event);
1093 }
1094
1095 /**
1096 * @tc.name: OHInputManagerTest_OH_Input_GetTouchEventActionTime
1097 * @tc.desc: Test the funcation OH_Input_GetTouchEventActionTime
1098 * @tc.type: FUNC
1099 * @tc.require:
1100 */
1101 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetTouchEventActionTime, TestSize.Level3)
1102 {
1103 CALL_TEST_DEBUG;
1104 Input_TouchEvent event;
1105 int64_t actionTime = 1;
1106 EXPECT_NO_FATAL_FAILURE(OH_Input_SetTouchEventActionTime(nullptr, actionTime));
1107 EXPECT_NO_FATAL_FAILURE(OH_Input_SetTouchEventActionTime(&event, actionTime));
1108 EXPECT_EQ(OH_Input_GetTouchEventActionTime(&event), 1);
1109 EXPECT_EQ(OH_Input_GetTouchEventActionTime(nullptr), -1);
1110 }
1111
1112 /**
1113 * @tc.name: OHInputManagerTest_OH_Input_GetTouchEventDisplayId
1114 * @tc.desc: Test the funcation OH_Input_GetTouchEventDisplayId
1115 * @tc.type: FUNC
1116 * @tc.require:
1117 */
1118 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetTouchEventDisplayId, TestSize.Level3)
1119 {
1120 CALL_TEST_DEBUG;
1121 Input_TouchEvent event;
1122 int32_t displayId = 1;
1123 EXPECT_NO_FATAL_FAILURE(OH_Input_SetTouchEventDisplayId(nullptr, displayId));
1124 EXPECT_NO_FATAL_FAILURE(OH_Input_SetTouchEventDisplayId(&event, displayId));
1125 EXPECT_EQ(OH_Input_GetTouchEventDisplayId(&event), 1);
1126 EXPECT_EQ(OH_Input_GetTouchEventDisplayId(nullptr), -1);
1127 }
1128
1129 /**
1130 * @tc.name: OHInputManagerTest_OH_Input_GetTouchEventDisplayX
1131 * @tc.desc: Test the funcation OH_Input_GetTouchEventDisplayX
1132 * @tc.type: FUNC
1133 * @tc.require:
1134 */
1135 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetTouchEventDisplayX, TestSize.Level3)
1136 {
1137 CALL_TEST_DEBUG;
1138 Input_TouchEvent event;
1139 int32_t displayX = 1;
1140 EXPECT_NO_FATAL_FAILURE(OH_Input_SetTouchEventDisplayX(nullptr, displayX));
1141 EXPECT_NO_FATAL_FAILURE(OH_Input_SetTouchEventDisplayX(&event, displayX));
1142 EXPECT_EQ(OH_Input_GetTouchEventDisplayX(&event), 1);
1143 EXPECT_EQ(OH_Input_GetTouchEventDisplayX(nullptr), -1);
1144 }
1145
1146 /**
1147 * @tc.name: OHInputManagerTest_OH_Input_GetTouchEventAction
1148 * @tc.desc: Test the funcation OH_Input_GetTouchEventAction
1149 * @tc.type: FUNC
1150 * @tc.require:
1151 */
1152 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetTouchEventAction, TestSize.Level3)
1153 {
1154 CALL_TEST_DEBUG;
1155 Input_TouchEvent event;
1156 int32_t action = 1;
1157 EXPECT_NO_FATAL_FAILURE(OH_Input_SetTouchEventAction(nullptr, action));
1158 EXPECT_NO_FATAL_FAILURE(OH_Input_SetTouchEventAction(&event, action));
1159 EXPECT_EQ(OH_Input_GetTouchEventAction(&event), 1);
1160 EXPECT_EQ(OH_Input_GetTouchEventAction(nullptr), -1);
1161 }
1162
1163 /**
1164 * @tc.name: OHInputManagerTest_OH_Input_CreateAxisEvent
1165 * @tc.desc: Test the funcation OH_Input_CreateAxisEvent
1166 * @tc.type: FUNC
1167 * @tc.require:
1168 */
1169 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_CreateAxisEvent, TestSize.Level3)
1170 {
1171 CALL_TEST_DEBUG;
1172 auto event = OH_Input_CreateAxisEvent();
1173 EXPECT_EQ(event != nullptr, true);
1174 EXPECT_NO_FATAL_FAILURE(OH_Input_DestroyAxisEvent(&event));
1175 EXPECT_NO_FATAL_FAILURE(OH_Input_DestroyAxisEvent(nullptr));
1176 }
1177
1178 /**
1179 * @tc.name: OHInputManagerTest_OH_Input_CreateKeyEvent
1180 * @tc.desc: Test the funcation OH_Input_CreateKeyEvent
1181 * @tc.type: FUNC
1182 * @tc.require:
1183 */
1184 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_CreateKeyEvent, TestSize.Level3)
1185 {
1186 CALL_TEST_DEBUG;
1187 auto event = OH_Input_CreateKeyEvent();
1188 EXPECT_EQ(event != nullptr, true);
1189 EXPECT_NO_FATAL_FAILURE(OH_Input_DestroyKeyEvent(&event));
1190 EXPECT_NO_FATAL_FAILURE(OH_Input_DestroyKeyEvent(nullptr));
1191 }
1192
1193 /**
1194 * @tc.name: OHInputManagerTest_OH_Input_CreateTouchEvent
1195 * @tc.desc: Test the funcation OH_Input_CreateTouchEvent
1196 * @tc.type: FUNC
1197 * @tc.require:
1198 */
1199 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_CreateTouchEvent, TestSize.Level3)
1200 {
1201 CALL_TEST_DEBUG;
1202 auto event = OH_Input_CreateTouchEvent();
1203 EXPECT_EQ(event != nullptr, true);
1204 EXPECT_NO_FATAL_FAILURE(OH_Input_DestroyTouchEvent(&event));
1205 EXPECT_NO_FATAL_FAILURE(OH_Input_DestroyTouchEvent(nullptr));
1206 }
1207
1208 /**
1209 * @tc.name: OHInputManagerTest_OH_Input_InjectTouchEventGlobal
1210 * @tc.desc: Test the funcation OH_Input_InjectTouchEventGlobal
1211 * @tc.type: FUNC
1212 * @tc.require:
1213 */
1214 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_InjectTouchEventGlobal, TestSize.Level3)
1215 {
1216 CALL_TEST_DEBUG;
1217 Input_TouchEvent touchEvent;
1218 EXPECT_EQ(OH_Input_InjectTouchEventGlobal(nullptr), INPUT_PARAMETER_ERROR);
1219 touchEvent.action = TOUCH_ACTION_DOWN;
1220 touchEvent.displayX = 1;
1221 touchEvent.displayY = 1;
1222 touchEvent.globalX = 1;
1223 touchEvent.globalY = 1;
1224 EXPECT_EQ(OH_Input_InjectTouchEventGlobal(&touchEvent), INPUT_PERMISSION_DENIED);
1225
1226 touchEvent.globalX = INT32_MAX;
1227 touchEvent.globalY = INT32_MAX;
1228 EXPECT_EQ(OH_Input_InjectTouchEventGlobal(&touchEvent), INPUT_PARAMETER_ERROR);
1229
1230 touchEvent.displayX = -1;
1231 touchEvent.displayY = -1;
1232 EXPECT_EQ(OH_Input_InjectTouchEventGlobal(&touchEvent), INPUT_PARAMETER_ERROR);
1233
1234 touchEvent.action = -1;
1235 EXPECT_EQ(OH_Input_InjectTouchEventGlobal(&touchEvent), INPUT_PARAMETER_ERROR);
1236 }
1237
1238 /**
1239 * @tc.name: OHInputManagerTest_OH_Input_SetKeyCode
1240 * @tc.desc: Test the funcation OH_Input_SetKeyCode
1241 * @tc.type: FUNC
1242 * @tc.require:
1243 */
1244 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_SetKeyCode, TestSize.Level3)
1245 {
1246 CALL_TEST_DEBUG;
1247 Input_KeyState keyState;
1248 int32_t keyCode = -1;
1249 EXPECT_NO_FATAL_FAILURE(OH_Input_SetKeyCode(&keyState, keyCode));
1250 keyCode = 2020;
1251 keyState.keyCode = 2300;
1252 EXPECT_NO_FATAL_FAILURE(OH_Input_SetKeyCode(&keyState, keyCode));
1253 keyState.keyCode = KEYCODE_F1;
1254 EXPECT_NO_FATAL_FAILURE(OH_Input_SetKeyCode(&keyState, keyCode));
1255 const Input_KeyState keyState1 {.keyCode = KEYCODE_F1};
1256 EXPECT_EQ(OH_Input_GetKeyCode(&keyState1), KEYCODE_F1);
1257 }
1258
1259 /**
1260 * @tc.name: OHInputManagerTest_OH_Input_RegisterDeviceListener
1261 * @tc.desc: Test the funcation OH_Input_RegisterDeviceListener
1262 * @tc.type: FUNC
1263 * @tc.require:
1264 */
1265 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_RegisterDeviceListener, TestSize.Level2)
1266 {
1267 auto listener1 = new (std::nothrow) Input_DeviceListener();
1268 if (listener1 == nullptr) {
1269 MMI_HILOGE("Failed to new Input_DeviceListener");
1270 return;
1271 }
__anonaa5665ab0702(int32_t deviceId) 1272 listener1->deviceAddedCallback = [](int32_t deviceId) {
1273 MMI_HILOGI("deviceAddedCallback1:deviceId:%{public}d", deviceId);
1274 };
__anonaa5665ab0802(int32_t deviceId) 1275 listener1->deviceRemovedCallback = [](int32_t deviceId) {
1276 MMI_HILOGI("deviceRemovedCallback1:deviceId:%{public}d", deviceId);
1277 };
1278 EXPECT_EQ(OH_Input_RegisterDeviceListener(listener1), INPUT_SUCCESS);
1279
1280 auto listener2 = new (std::nothrow) Input_DeviceListener();
1281 if (listener2 == nullptr) {
1282 MMI_HILOGE("Failed to new Input_DeviceListener");
1283 return;
1284 }
__anonaa5665ab0902(int32_t deviceId) 1285 listener2->deviceAddedCallback = [](int32_t deviceId) {
1286 MMI_HILOGI("deviceAddedCallback2:deviceId:%{public}d", deviceId);
1287 };
__anonaa5665ab0a02(int32_t deviceId) 1288 listener2->deviceRemovedCallback = [](int32_t deviceId) {
1289 MMI_HILOGI("deviceRemovedCallback2:deviceId:%{public}d", deviceId);
1290 };
1291 EXPECT_EQ(OH_Input_RegisterDeviceListener(listener2), INPUT_SUCCESS);
1292 EXPECT_EQ(OH_Input_UnregisterDeviceListener(listener1), INPUT_SUCCESS);
1293 EXPECT_EQ(OH_Input_UnregisterDeviceListener(listener2), INPUT_SUCCESS);
1294 delete listener1;
1295 delete listener2;
1296 }
1297
1298 /**
1299 * @tc.name: OHInputManagerTest_OH_Input_UnregisterDeviceListeners
1300 * @tc.desc: Test the funcation OH_Input_UnregisterDeviceListeners
1301 * @tc.type: FUNC
1302 * @tc.require:
1303 */
1304 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_UnregisterDeviceListeners, TestSize.Level1)
1305 {
1306 auto listener1 = new (std::nothrow) Input_DeviceListener();
1307 if (listener1 == nullptr) {
1308 MMI_HILOGE("Failed to new Input_DeviceListener");
1309 return;
1310 }
__anonaa5665ab0b02(int32_t deviceId) 1311 listener1->deviceAddedCallback = [](int32_t deviceId) {
1312 MMI_HILOGI("deviceAddedCallback1:deviceId:%{public}d", deviceId);
1313 };
__anonaa5665ab0c02(int32_t deviceId) 1314 listener1->deviceRemovedCallback = [](int32_t deviceId) {
1315 MMI_HILOGI("deviceRemovedCallback1:deviceId:%{public}d", deviceId);
1316 };
1317 EXPECT_EQ(OH_Input_RegisterDeviceListener(listener1), INPUT_SUCCESS);
1318
1319 auto listener2 = new (std::nothrow) Input_DeviceListener();
1320 if (listener2 == nullptr) {
1321 MMI_HILOGE("Failed to new Input_DeviceListener");
1322 return;
1323 }
__anonaa5665ab0d02(int32_t deviceId) 1324 listener2->deviceAddedCallback = [](int32_t deviceId) {
1325 MMI_HILOGI("deviceAddedCallback2:deviceId:%{public}d", deviceId);
1326 };
__anonaa5665ab0e02(int32_t deviceId) 1327 listener2->deviceRemovedCallback = [](int32_t deviceId) {
1328 MMI_HILOGI("deviceRemovedCallback2:deviceId:%{public}d", deviceId);
1329 };
1330 EXPECT_EQ(OH_Input_RegisterDeviceListener(listener2), INPUT_SUCCESS);
1331 EXPECT_EQ(OH_Input_UnregisterDeviceListeners(), INPUT_SUCCESS);
1332 delete listener1;
1333 delete listener2;
1334 }
1335
1336 /*
1337 * @tc.name: OHInputManagerTest_OH_Input_RegisterDeviceListener_Error
1338 * @tc.desc: Test the funcation OH_Input_RegisterDeviceListener
1339 * @tc.type: FUNC
1340 * @tc.require:
1341 */
1342 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_RegisterDeviceListener_Error001, TestSize.Level1)
1343 {
1344 Input_DeviceListener *listener = nullptr;
1345 EXPECT_EQ(OH_Input_RegisterDeviceListener(listener), INPUT_PARAMETER_ERROR);
1346 EXPECT_EQ(OH_Input_UnregisterDeviceListener(listener), INPUT_PARAMETER_ERROR);
1347 }
1348
1349 /*
1350 * @tc.name: OHInputManagerTest_OH_Input_RegisterDeviceListener_Error
1351 * @tc.desc: Test the funcation OH_Input_RegisterDeviceListener
1352 * @tc.type: FUNC
1353 * @tc.require:
1354 */
1355 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_RegisterDeviceListener_Error002, TestSize.Level1)
1356 {
1357 Input_DeviceListener listener = {
1358 nullptr,
1359 nullptr,
1360 };
1361 EXPECT_EQ(OH_Input_RegisterDeviceListener(&listener), INPUT_PARAMETER_ERROR);
1362 EXPECT_EQ(OH_Input_UnregisterDeviceListener(&listener), INPUT_PARAMETER_ERROR);
1363 }
1364
1365 /*
1366 * @tc.name: OHInputManagerTest_OH_Input_RegisterDeviceListener_Error
1367 * @tc.desc: Test the funcation OH_Input_RegisterDeviceListener
1368 * @tc.type: FUNC
1369 * @tc.require:
1370 */
1371 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_RegisterDeviceListener_Error003, TestSize.Level3)
1372 {
1373 Input_DeviceListener listener = {
1374 nullptr,
__anonaa5665ab0f02() 1375 [](int32_t deviceId) {},
1376 };
1377 EXPECT_EQ(OH_Input_RegisterDeviceListener(&listener), INPUT_PARAMETER_ERROR);
1378 EXPECT_EQ(OH_Input_UnregisterDeviceListener(&listener), INPUT_PARAMETER_ERROR);
1379 }
1380
1381 /*
1382 * @tc.name: OHInputManagerTest_OH_Input_RegisterDeviceListener_Error
1383 * @tc.desc: Test the funcation OH_Input_RegisterDeviceListener
1384 * @tc.type: FUNC
1385 * @tc.require:
1386 */
1387 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_RegisterDeviceListener_Error004, TestSize.Level1)
1388 {
1389 Input_DeviceListener listener = {
__anonaa5665ab1002() 1390 [](int32_t deviceId) {},
1391 nullptr,
1392 };
1393 EXPECT_EQ(OH_Input_RegisterDeviceListener(&listener), INPUT_PARAMETER_ERROR);
1394 EXPECT_EQ(OH_Input_UnregisterDeviceListener(&listener), INPUT_PARAMETER_ERROR);
1395 }
1396
1397 /**
1398 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceIds
1399 * @tc.desc: Test the funcation OH_Input_GetDeviceIds
1400 * @tc.type: FUNC
1401 * @tc.require:
1402 */
1403 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceIds_001, TestSize.Level1)
1404 {
1405 const int32_t inSize = 64;
1406 int32_t outSize = 0;
1407 int32_t deviceIds[inSize] = {0};
1408 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
1409 EXPECT_EQ(retResult, INPUT_SUCCESS);
1410 }
1411
1412 /**
1413 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceIds
1414 * @tc.desc: Test the funcation OH_Input_GetDeviceIds
1415 * @tc.type: FUNC
1416 * @tc.require:
1417 */
1418 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceIds_002, TestSize.Level1)
1419 {
1420 const int32_t inSize = 1;
1421 int32_t outSize = 0;
1422 int32_t deviceIds[inSize] = {0};
1423 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
1424 EXPECT_EQ(retResult, INPUT_SUCCESS);
1425 EXPECT_EQ(outSize, 1);
1426 }
1427
1428 /**
1429 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceIds
1430 * @tc.desc: Test the funcation OH_Input_GetDeviceIds
1431 * @tc.type: FUNC
1432 * @tc.require:
1433 */
1434 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceIds_003, TestSize.Level1)
1435 {
1436 const int32_t inSize = 64;
1437 int32_t *outSize = nullptr;
1438 int32_t deviceIds[inSize] = {0};
1439 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, outSize);
1440 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
1441 }
1442
1443 /**
1444 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceIds
1445 * @tc.desc: Test the funcation OH_Input_GetDeviceIds
1446 * @tc.type: FUNC
1447 * @tc.require:
1448 */
1449 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceIds_004, TestSize.Level1)
1450 {
1451 const int32_t inSize = 64;
1452 int32_t outSize = 0;
1453 int32_t *deviceIds = nullptr;
1454 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
1455 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
1456 }
1457
1458 /**
1459 * @tc.name: OHInputManagerTest_OH_Input_GetKeyboardType
1460 * @tc.desc: Test the funcation OH_Input_GetKeyboardType
1461 * @tc.type: FUNC
1462 * @tc.require:
1463 */
1464 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetKeyboardType_001, TestSize.Level1)
1465 {
1466 int32_t deviceId = 3;
1467 int32_t keyboardType = -1;
1468 Input_Result retResult = OH_Input_GetKeyboardType(deviceId, &keyboardType);
1469 EXPECT_EQ(retResult, INPUT_SUCCESS);
1470 MMI_HILOGD("keyboardType:%{public}d", keyboardType);
1471 }
1472
1473 /**
1474 * @tc.name: OHInputManagerTest_OH_Input_GetKeyboardType
1475 * @tc.desc: Test the funcation OH_Input_GetKeyboardType
1476 * @tc.type: FUNC
1477 * @tc.require:
1478 */
1479 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetKeyboardType_002, TestSize.Level2)
1480 {
1481 int32_t deviceId = 3;
1482 int32_t *keyboardType = nullptr;
1483 Input_Result retResult = OH_Input_GetKeyboardType(deviceId, keyboardType);
1484 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
1485 }
1486
1487 /**
1488 * @tc.name: OHInputManagerTest_OH_Input_GetKeyboardType
1489 * @tc.desc: Test the funcation OH_Input_GetKeyboardType
1490 * @tc.type: FUNC
1491 * @tc.require:
1492 */
1493 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetKeyboardType_003, TestSize.Level2)
1494 {
1495 int32_t deviceId = -1;
1496 int32_t keyboardType = -1;
1497 Input_Result retResult = OH_Input_GetKeyboardType(deviceId, &keyboardType);
1498 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
1499 }
1500
1501 /**
1502 * @tc.name: OHInputManagerTest_OH_Input_GetKeyboardType
1503 * @tc.desc: Test the funcation OH_Input_GetKeyboardType
1504 * @tc.type: FUNC
1505 * @tc.require:
1506 */
1507 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetKeyboardType_004, TestSize.Level1)
1508 {
1509 const int32_t inSize = 64;
1510 int32_t outSize = 0;
1511 int32_t deviceIds[inSize] = {0};
1512 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
1513 EXPECT_EQ(retResult, INPUT_SUCCESS);
1514 int32_t deviceId = outSize;
1515 int32_t keyboardType = -1;
1516 retResult = OH_Input_GetKeyboardType(deviceId, &keyboardType);
1517 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
1518 }
1519
1520 /**
1521 * @tc.name: OHInputManagerTest_OH_Input_GetDevice
1522 * @tc.desc: Test the funcation OH_Input_GetDevice
1523 * @tc.type: FUNC
1524 * @tc.require:
1525 */
1526 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDevice_001, TestSize.Level1)
1527 {
1528 const int32_t inSize = 64;
1529 int32_t outSize = 0;
1530 int32_t deviceIds[inSize] = {0};
1531 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
1532 EXPECT_EQ(retResult, INPUT_SUCCESS);
1533 int32_t deviceId = outSize - 1;
1534 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
1535 retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
1536 EXPECT_EQ(retResult, INPUT_SUCCESS);
1537 OH_Input_DestroyDeviceInfo(&deviceInfo);
1538 }
1539
1540 /**
1541 * @tc.name: OHInputManagerTest_OH_Input_GetDevice
1542 * @tc.desc: Test the funcation OH_Input_GetDevice
1543 * @tc.type: FUNC
1544 * @tc.require:
1545 */
1546 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDevice_002, TestSize.Level1)
1547 {
1548 const int32_t inSize = 64;
1549 int32_t outSize = 0;
1550 int32_t deviceIds[inSize] = {0};
1551 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
1552 EXPECT_EQ(retResult, INPUT_SUCCESS);
1553 int32_t deviceId = outSize;
1554 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
1555 retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
1556 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
1557 OH_Input_DestroyDeviceInfo(&deviceInfo);
1558 }
1559
1560 /**
1561 * @tc.name: OHInputManagerTest_OH_Input_GetDevice
1562 * @tc.desc: Test the funcation OH_Input_GetDevice
1563 * @tc.type: FUNC
1564 * @tc.require:
1565 */
1566 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDevice_003, TestSize.Level1)
1567 {
1568 int32_t deviceId = -1;
1569 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
1570 Input_Result retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
1571 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
1572 OH_Input_DestroyDeviceInfo(&deviceInfo);
1573 }
1574
1575 /**
1576 * @tc.name: OHInputManagerTest_OH_Input_GetDevice
1577 * @tc.desc: Test the funcation OH_Input_GetDevice
1578 * @tc.type: FUNC
1579 * @tc.require:
1580 */
1581 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDevice_004, TestSize.Level2)
1582 {
1583 int32_t deviceId = 0;
1584 Input_DeviceInfo *deviceInfo = nullptr;
1585 Input_Result retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
1586 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
1587 }
1588
1589 /**
1590 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceName
1591 * @tc.desc: Test the funcation OH_Input_GetDeviceName
1592 * @tc.type: FUNC
1593 * @tc.require:
1594 */
1595 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceName_001, TestSize.Level1)
1596 {
1597 const int32_t inSize = 64;
1598 int32_t outSize = 0;
1599 int32_t deviceIds[inSize] = {0};
1600 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
1601 EXPECT_EQ(retResult, INPUT_SUCCESS);
1602 int32_t deviceId = outSize - 1;
1603 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
1604 retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
1605 EXPECT_EQ(retResult, INPUT_SUCCESS);
1606 char *name = nullptr;
1607 retResult = OH_Input_GetDeviceName(deviceInfo, &name);
1608 EXPECT_EQ(retResult, INPUT_SUCCESS);
1609 EXPECT_GT(std::strlen(name), 0);
1610 MMI_HILOGD("outSize:%{public}d", outSize);
1611 OH_Input_DestroyDeviceInfo(&deviceInfo);
1612 }
1613
1614 /**
1615 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceName
1616 * @tc.desc: Test the funcation OH_Input_GetDeviceName
1617 * @tc.type: FUNC
1618 * @tc.require:
1619 */
1620 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceName_002, TestSize.Level1)
1621 {
1622 const int32_t inSize = 64;
1623 int32_t outSize = 0;
1624 int32_t deviceIds[inSize] = {0};
1625 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
1626 EXPECT_EQ(retResult, INPUT_SUCCESS);
1627 int32_t deviceId = outSize - 1;
1628 Input_DeviceInfo *deviceInfo = nullptr;
1629 retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
1630 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
1631 char *name = nullptr;
1632 retResult = OH_Input_GetDeviceName(deviceInfo, &name);
1633 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
1634 }
1635
1636 /**
1637 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceName
1638 * @tc.desc: Test the funcation OH_Input_GetDeviceName
1639 * @tc.type: FUNC
1640 * @tc.require:
1641 */
1642 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceName_003, TestSize.Level1)
1643 {
1644 const int32_t inSize = 64;
1645 int32_t outSize = 0;
1646 int32_t deviceIds[inSize] = {0};
1647 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
1648 EXPECT_EQ(retResult, INPUT_SUCCESS);
1649 int32_t deviceId = outSize - 1;
1650 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
1651 retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
1652 EXPECT_EQ(retResult, INPUT_SUCCESS);
1653 char **name = nullptr;
1654 retResult = OH_Input_GetDeviceName(deviceInfo, name);
1655 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
1656 OH_Input_DestroyDeviceInfo(&deviceInfo);
1657 }
1658
1659 /**
1660 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceName
1661 * @tc.desc: Test the funcation OH_Input_GetDeviceName
1662 * @tc.type: FUNC
1663 * @tc.require:
1664 */
1665 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceName_004, TestSize.Level1)
1666 {
1667 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
1668 char *name = nullptr;
1669 Input_Result retResult = OH_Input_GetDeviceName(deviceInfo, &name);
1670 EXPECT_EQ(retResult, INPUT_SUCCESS);
1671 EXPECT_EQ(std::strlen(name), 0);
1672 OH_Input_DestroyDeviceInfo(&deviceInfo);
1673 }
1674
1675 /**
1676 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceAddress
1677 * @tc.desc: Test the funcation OH_Input_GetDeviceAddress
1678 * @tc.type: FUNC
1679 * @tc.require:
1680 */
1681 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceAddress_001, TestSize.Level2)
1682 {
1683 const int32_t inSize = 64;
1684 int32_t outSize = 0;
1685 int32_t deviceIds[inSize] = {0};
1686 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
1687 EXPECT_EQ(retResult, INPUT_SUCCESS);
1688 int32_t deviceId = outSize - 1;
1689 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
1690 retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
1691 EXPECT_EQ(retResult, INPUT_SUCCESS);
1692
1693 char *address = nullptr;
1694 retResult = OH_Input_GetDeviceAddress(deviceInfo, &address);
1695 EXPECT_EQ(retResult, INPUT_SUCCESS);
1696 EXPECT_GT(std::strlen(address), 0);
1697 OH_Input_DestroyDeviceInfo(&deviceInfo);
1698 }
1699
1700 /**
1701 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceAddress
1702 * @tc.desc: Test the funcation OH_Input_GetDeviceAddress
1703 * @tc.type: FUNC
1704 * @tc.require:
1705 */
1706 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceAddress_002, TestSize.Level1)
1707 {
1708 const int32_t inSize = 64;
1709 int32_t outSize = 0;
1710 int32_t deviceIds[inSize] = {0};
1711 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
1712 EXPECT_EQ(retResult, INPUT_SUCCESS);
1713 int32_t deviceId = outSize - 1;
1714 Input_DeviceInfo *deviceInfo = nullptr;
1715 retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
1716 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
1717
1718 char *address = nullptr;
1719 retResult = OH_Input_GetDeviceAddress(deviceInfo, &address);
1720 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
1721 }
1722
1723 /**
1724 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceAddress
1725 * @tc.desc: Test the funcation OH_Input_GetDeviceAddress
1726 * @tc.type: FUNC
1727 * @tc.require:
1728 */
1729 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceAddress_003, TestSize.Level1)
1730 {
1731 const int32_t inSize = 64;
1732 int32_t outSize = 0;
1733 int32_t deviceIds[inSize] = {0};
1734 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
1735 EXPECT_EQ(retResult, INPUT_SUCCESS);
1736 int32_t deviceId = outSize - 1;
1737 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
1738 retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
1739 EXPECT_EQ(retResult, INPUT_SUCCESS);
1740
1741 char **address = nullptr;
1742 retResult = OH_Input_GetDeviceAddress(deviceInfo, address);
1743 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
1744 OH_Input_DestroyDeviceInfo(&deviceInfo);
1745 }
1746
1747 /**
1748 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceAddress
1749 * @tc.desc: Test the funcation OH_Input_GetDeviceAddress
1750 * @tc.type: FUNC
1751 * @tc.require:
1752 */
1753 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceAddress_004, TestSize.Level1)
1754 {
1755 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
1756 char *address = nullptr;
1757 Input_Result retResult = OH_Input_GetDeviceAddress(deviceInfo, &address);
1758 EXPECT_EQ(retResult, INPUT_SUCCESS);
1759 EXPECT_EQ(std::strlen(address), 0);
1760 OH_Input_DestroyDeviceInfo(&deviceInfo);
1761 }
1762
1763 /**
1764 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceId
1765 * @tc.desc: Test the funcation OH_Input_GetDeviceId
1766 * @tc.type: FUNC
1767 * @tc.require:
1768 */
1769 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceId_001, TestSize.Level2)
1770 {
1771 const int32_t inSize = 64;
1772 int32_t outSize = 0;
1773 int32_t deviceIds[inSize] = {0};
1774 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
1775 EXPECT_EQ(retResult, INPUT_SUCCESS);
1776 int32_t deviceId = outSize - 1;
1777 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
1778 retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
1779 EXPECT_EQ(retResult, INPUT_SUCCESS);
1780
1781 int32_t id = -1;
1782 retResult = OH_Input_GetDeviceId(deviceInfo, &id);
1783 EXPECT_EQ(retResult, INPUT_SUCCESS);
1784
1785 EXPECT_EQ(id, outSize - 1);
1786 OH_Input_DestroyDeviceInfo(&deviceInfo);
1787 }
1788
1789 /**
1790 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceId
1791 * @tc.desc: Test the funcation OH_Input_GetDeviceId
1792 * @tc.type: FUNC
1793 * @tc.require:
1794 */
1795 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceId_002, TestSize.Level1)
1796 {
1797 const int32_t inSize = 64;
1798 int32_t outSize = 0;
1799 int32_t deviceIds[inSize] = {0};
1800 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
1801 EXPECT_EQ(retResult, INPUT_SUCCESS);
1802 int32_t deviceId = outSize - 1;
1803 Input_DeviceInfo *deviceInfo = nullptr;
1804 retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
1805 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
1806
1807 int32_t id = -1;
1808 retResult = OH_Input_GetDeviceId(deviceInfo, &id);
1809 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
1810 }
1811
1812 /**
1813 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceId
1814 * @tc.desc: Test the funcation OH_Input_GetDeviceId
1815 * @tc.type: FUNC
1816 * @tc.require:
1817 */
1818 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceId_003, TestSize.Level2)
1819 {
1820 const int32_t inSize = 64;
1821 int32_t outSize = 0;
1822 int32_t deviceIds[inSize] = {0};
1823 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
1824 EXPECT_EQ(retResult, INPUT_SUCCESS);
1825 int32_t deviceId = outSize - 1;
1826 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
1827 retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
1828 EXPECT_EQ(retResult, INPUT_SUCCESS);
1829
1830 int32_t *id = nullptr;
1831 retResult = OH_Input_GetDeviceId(deviceInfo, id);
1832 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
1833 OH_Input_DestroyDeviceInfo(&deviceInfo);
1834 }
1835
1836 /**
1837 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceId
1838 * @tc.desc: Test the funcation OH_Input_GetDeviceId
1839 * @tc.type: FUNC
1840 * @tc.require:
1841 */
1842 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceId_004, TestSize.Level1)
1843 {
1844 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
1845 int32_t id = -1;
1846 Input_Result retResult = OH_Input_GetDeviceId(deviceInfo, &id);
1847 EXPECT_EQ(retResult, INPUT_SUCCESS);
1848 EXPECT_LT(id, 0);
1849 OH_Input_DestroyDeviceInfo(&deviceInfo);
1850 }
1851
1852 /**
1853 * @tc.name: OHInputManagerTest_OH_Input_GetCapabilities
1854 * @tc.desc: Test the funcation OH_Input_GetCapabilities
1855 * @tc.type: FUNC
1856 * @tc.require:
1857 */
1858 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetCapabilities_001, TestSize.Level1)
1859 {
1860 const int32_t inSize = 64;
1861 int32_t outSize = 0;
1862 int32_t deviceIds[inSize] = {0};
1863 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
1864 EXPECT_EQ(retResult, INPUT_SUCCESS);
1865 int32_t deviceId = outSize - 1;
1866 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
1867 retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
1868 EXPECT_EQ(retResult, INPUT_SUCCESS);
1869
1870 int32_t capabilities = -1;
1871 retResult = OH_Input_GetCapabilities(deviceInfo, &capabilities);
1872 EXPECT_EQ(retResult, INPUT_SUCCESS);
1873 OH_Input_DestroyDeviceInfo(&deviceInfo);
1874 }
1875
1876 /**
1877 * @tc.name: OHInputManagerTest_OH_Input_GetCapabilities
1878 * @tc.desc: Test the funcation OH_Input_GetCapabilities
1879 * @tc.type: FUNC
1880 * @tc.require:
1881 */
1882 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetCapabilities_002, TestSize.Level1)
1883 {
1884 const int32_t inSize = 64;
1885 int32_t outSize = 0;
1886 int32_t deviceIds[inSize] = {0};
1887 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
1888 EXPECT_EQ(retResult, INPUT_SUCCESS);
1889 int32_t deviceId = outSize - 1;
1890 Input_DeviceInfo *deviceInfo = nullptr;
1891 retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
1892 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
1893
1894 int32_t capabilities = -1;
1895 retResult = OH_Input_GetCapabilities(deviceInfo, &capabilities);
1896 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
1897 }
1898
1899 /**
1900 * @tc.name: OHInputManagerTest_OH_Input_GetCapabilities
1901 * @tc.desc: Test the funcation OH_Input_GetCapabilities
1902 * @tc.type: FUNC
1903 * @tc.require:
1904 */
1905 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetCapabilities_003, TestSize.Level1)
1906 {
1907 const int32_t inSize = 64;
1908 int32_t outSize = 0;
1909 int32_t deviceIds[inSize] = {0};
1910 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
1911 EXPECT_EQ(retResult, INPUT_SUCCESS);
1912 int32_t deviceId = outSize - 1;
1913 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
1914 retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
1915 EXPECT_EQ(retResult, INPUT_SUCCESS);
1916
1917 int32_t *capabilities = nullptr;
1918 retResult = OH_Input_GetCapabilities(deviceInfo, capabilities);
1919 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
1920 OH_Input_DestroyDeviceInfo(&deviceInfo);
1921 }
1922
1923 /**
1924 * @tc.name: OHInputManagerTest_OH_Input_GetCapabilities
1925 * @tc.desc: Test the funcation OH_Input_GetCapabilities
1926 * @tc.type: FUNC
1927 * @tc.require:
1928 */
1929 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetCapabilities_004, TestSize.Level1)
1930 {
1931 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
1932 int32_t capabilities = -1;
1933 Input_Result retResult = OH_Input_GetCapabilities(deviceInfo, &capabilities);
1934 EXPECT_EQ(retResult, INPUT_SUCCESS);
1935 EXPECT_LT(capabilities, 0);
1936 OH_Input_DestroyDeviceInfo(&deviceInfo);
1937 }
1938
1939 /**
1940 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceVersion
1941 * @tc.desc: Test the funcation OH_Input_GetDeviceVersion
1942 * @tc.type: FUNC
1943 * @tc.require:
1944 */
1945 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceVersion_001, TestSize.Level1)
1946 {
1947 const int32_t inSize = 64;
1948 int32_t outSize = 0;
1949 int32_t deviceIds[inSize] = {0};
1950 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
1951 EXPECT_EQ(retResult, INPUT_SUCCESS);
1952 int32_t deviceId = outSize - 1;
1953 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
1954 retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
1955 EXPECT_EQ(retResult, INPUT_SUCCESS);
1956
1957 int32_t version = -1;
1958 retResult = OH_Input_GetDeviceVersion(deviceInfo, &version);
1959 EXPECT_EQ(retResult, INPUT_SUCCESS);
1960 OH_Input_DestroyDeviceInfo(&deviceInfo);
1961 }
1962
1963 /**
1964 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceVersion
1965 * @tc.desc: Test the funcation OH_Input_GetDeviceVersion
1966 * @tc.type: FUNC
1967 * @tc.require:
1968 */
1969 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceVersion_002, TestSize.Level1)
1970 {
1971 const int32_t inSize = 64;
1972 int32_t outSize = 0;
1973 int32_t deviceIds[inSize] = {0};
1974 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
1975 EXPECT_EQ(retResult, INPUT_SUCCESS);
1976 int32_t deviceId = outSize - 1;
1977 Input_DeviceInfo *deviceInfo = nullptr;
1978 retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
1979 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
1980
1981 int32_t version = -1;
1982 retResult = OH_Input_GetDeviceVersion(deviceInfo, &version);
1983 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
1984 }
1985
1986 /**
1987 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceVersion
1988 * @tc.desc: Test the funcation OH_Input_GetDeviceVersion
1989 * @tc.type: FUNC
1990 * @tc.require:
1991 */
1992 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceVersion_003, TestSize.Level3)
1993 {
1994 const int32_t inSize = 64;
1995 int32_t outSize = 0;
1996 int32_t deviceIds[inSize] = {0};
1997 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
1998 EXPECT_EQ(retResult, INPUT_SUCCESS);
1999 int32_t deviceId = outSize - 1;
2000 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
2001 retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
2002 EXPECT_EQ(retResult, INPUT_SUCCESS);
2003
2004 int32_t *version = nullptr;
2005 retResult = OH_Input_GetDeviceVersion(deviceInfo, version);
2006 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
2007 OH_Input_DestroyDeviceInfo(&deviceInfo);
2008 }
2009
2010 /**
2011 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceVersion
2012 * @tc.desc: Test the funcation OH_Input_GetDeviceVersion
2013 * @tc.type: FUNC
2014 * @tc.require:
2015 */
2016 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceVersion_004, TestSize.Level2)
2017 {
2018 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
2019 int32_t version = -1;
2020 Input_Result retResult = OH_Input_GetDeviceVersion(deviceInfo, &version);
2021 EXPECT_EQ(retResult, INPUT_SUCCESS);
2022 EXPECT_LT(version, 0);
2023 OH_Input_DestroyDeviceInfo(&deviceInfo);
2024 }
2025
2026 /**
2027 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceProduct
2028 * @tc.desc: Test the funcation OH_Input_GetDeviceProduct
2029 * @tc.type: FUNC
2030 * @tc.require:
2031 */
2032 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceProduct_001, TestSize.Level2)
2033 {
2034 const int32_t inSize = 64;
2035 int32_t outSize = 0;
2036 int32_t deviceIds[inSize] = {0};
2037 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
2038 EXPECT_EQ(retResult, INPUT_SUCCESS);
2039 int32_t deviceId = outSize - 1;
2040 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
2041 retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
2042 EXPECT_EQ(retResult, INPUT_SUCCESS);
2043
2044 int32_t product = -1;
2045 retResult = OH_Input_GetDeviceProduct(deviceInfo, &product);
2046 EXPECT_EQ(retResult, INPUT_SUCCESS);
2047 OH_Input_DestroyDeviceInfo(&deviceInfo);
2048 }
2049
2050 /**
2051 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceProduct
2052 * @tc.desc: Test the funcation OH_Input_GetDeviceProduct
2053 * @tc.type: FUNC
2054 * @tc.require:
2055 */
2056 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceProduct_002, TestSize.Level2)
2057 {
2058 const int32_t inSize = 64;
2059 int32_t outSize = 0;
2060 int32_t deviceIds[inSize] = {0};
2061 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
2062 EXPECT_EQ(retResult, INPUT_SUCCESS);
2063 int32_t deviceId = outSize - 1;
2064 Input_DeviceInfo *deviceInfo = nullptr;
2065 retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
2066 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
2067
2068 int32_t product = -1;
2069 retResult = OH_Input_GetDeviceProduct(deviceInfo, &product);
2070 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
2071 }
2072
2073 /**
2074 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceProduct
2075 * @tc.desc: Test the funcation OH_Input_GetDeviceProduct
2076 * @tc.type: FUNC
2077 * @tc.require:
2078 */
2079 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceProduct_003, TestSize.Level2)
2080 {
2081 const int32_t inSize = 64;
2082 int32_t outSize = 0;
2083 int32_t deviceIds[inSize] = {0};
2084 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
2085 EXPECT_EQ(retResult, INPUT_SUCCESS);
2086 int32_t deviceId = outSize - 1;
2087 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
2088 retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
2089 EXPECT_EQ(retResult, INPUT_SUCCESS);
2090
2091 int32_t *product = nullptr;
2092 retResult = OH_Input_GetDeviceProduct(deviceInfo, product);
2093 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
2094 OH_Input_DestroyDeviceInfo(&deviceInfo);
2095 }
2096
2097 /**
2098 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceProduct
2099 * @tc.desc: Test the funcation OH_Input_GetDeviceProduct
2100 * @tc.type: FUNC
2101 * @tc.require:
2102 */
2103 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceProduct_004, TestSize.Level1)
2104 {
2105 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
2106 int32_t product = -1;
2107 Input_Result retResult = OH_Input_GetDeviceProduct(deviceInfo, &product);
2108 EXPECT_EQ(retResult, INPUT_SUCCESS);
2109 EXPECT_LT(product, 0);
2110 OH_Input_DestroyDeviceInfo(&deviceInfo);
2111 }
2112
2113 /**
2114 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceVendor
2115 * @tc.desc: Test the funcation OH_Input_GetDeviceVendor
2116 * @tc.type: FUNC
2117 * @tc.require:
2118 */
2119 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceVendor_001, TestSize.Level2)
2120 {
2121 const int32_t inSize = 64;
2122 int32_t outSize = 0;
2123 int32_t deviceIds[inSize] = {0};
2124 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
2125 EXPECT_EQ(retResult, INPUT_SUCCESS);
2126 int32_t deviceId = outSize - 1;
2127 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
2128 retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
2129 EXPECT_EQ(retResult, INPUT_SUCCESS);
2130
2131 int32_t vendor = -1;
2132 retResult = OH_Input_GetDeviceVendor(deviceInfo, &vendor);
2133 EXPECT_EQ(retResult, INPUT_SUCCESS);
2134 OH_Input_DestroyDeviceInfo(&deviceInfo);
2135 }
2136
2137 /**
2138 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceVendor
2139 * @tc.desc: Test the funcation OH_Input_GetDeviceVendor
2140 * @tc.type: FUNC
2141 * @tc.require:
2142 */
2143 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceVendor_002, TestSize.Level1)
2144 {
2145 const int32_t inSize = 64;
2146 int32_t outSize = 0;
2147 int32_t deviceIds[inSize] = {0};
2148 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
2149 EXPECT_EQ(retResult, INPUT_SUCCESS);
2150 int32_t deviceId = outSize - 1;
2151 Input_DeviceInfo *deviceInfo = nullptr;
2152 retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
2153 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
2154
2155 int32_t vendor = -1;
2156 retResult = OH_Input_GetDeviceVendor(deviceInfo, &vendor);
2157 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
2158 }
2159
2160 /**
2161 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceVendor
2162 * @tc.desc: Test the funcation OH_Input_GetDeviceVendor
2163 * @tc.type: FUNC
2164 * @tc.require:
2165 */
2166 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceVendor_003, TestSize.Level1)
2167 {
2168 const int32_t inSize = 64;
2169 int32_t outSize = 0;
2170 int32_t deviceIds[inSize] = {0};
2171 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
2172 EXPECT_EQ(retResult, INPUT_SUCCESS);
2173 int32_t deviceId = outSize - 1;
2174 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
2175 retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
2176 EXPECT_EQ(retResult, INPUT_SUCCESS);
2177
2178 int32_t *vendor = nullptr;
2179 retResult = OH_Input_GetDeviceVendor(deviceInfo, vendor);
2180 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
2181 OH_Input_DestroyDeviceInfo(&deviceInfo);
2182 }
2183
2184 /**
2185 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceVendor
2186 * @tc.desc: Test the funcation OH_Input_GetDeviceVendor
2187 * @tc.type: FUNC
2188 * @tc.require:
2189 */
2190 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceVendor_004, TestSize.Level1)
2191 {
2192 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
2193 int32_t vendor = -1;
2194 Input_Result retResult = OH_Input_GetDeviceVendor(deviceInfo, &vendor);
2195 EXPECT_EQ(retResult, INPUT_SUCCESS);
2196 EXPECT_LT(vendor, 0);
2197 OH_Input_DestroyDeviceInfo(&deviceInfo);
2198 }
2199
2200 /**
2201 * @tc.name: OHInputManagerTest_OH_Input_DestroyDeviceInfo
2202 * @tc.desc: Test the funcation OH_Input_DestroyDeviceInfo
2203 * @tc.type: FUNC
2204 * @tc.require:
2205 */
2206 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_DestroyDeviceInfo_001, TestSize.Level1)
2207 {
2208 Input_DeviceInfo *deviceInfo = nullptr;
2209 OH_Input_DestroyDeviceInfo(&deviceInfo);
2210 EXPECT_EQ(deviceInfo, nullptr);
2211 }
2212
HotkeyCallback(Input_Hotkey * hotkey)2213 static void HotkeyCallback(Input_Hotkey *hotkey) {}
2214
2215 /**
2216 * @tc.name: OHInputManagerTest_OH_Input_AddHotkeyMonitor_001
2217 * @tc.desc: Duplicate subscription of identical hotkey will fail.
2218 * @tc.type: FUNC
2219 * @tc.require:
2220 */
2221 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_AddHotkeyMonitor_001, TestSize.Level1)
2222 {
2223 Input_Hotkey *hotkey = OH_Input_CreateHotkey();
2224 ASSERT_NE(hotkey, nullptr);
2225 int32_t preKeys[] {KEYCODE_CTRL_LEFT};
2226 OH_Input_SetPreKeys(hotkey, preKeys, sizeof(preKeys) / sizeof(int32_t));
2227 OH_Input_SetFinalKey(hotkey, KEYCODE_TAB);
2228 OH_Input_SetRepeat(hotkey, false);
2229 Input_Result result = OH_Input_AddHotkeyMonitor(hotkey, &HotkeyCallback);
2230 EXPECT_EQ(result, Input_Result::INPUT_SUCCESS);
2231 result = OH_Input_AddHotkeyMonitor(hotkey, &HotkeyCallback);
2232 EXPECT_EQ(result, Input_Result::INPUT_PARAMETER_ERROR);
2233 result = OH_Input_RemoveHotkeyMonitor(hotkey, &HotkeyCallback);
2234 EXPECT_EQ(result, Input_Result::INPUT_SUCCESS);
2235 OH_Input_DestroyHotkey(&hotkey);
2236 }
2237
2238 /**
2239 * @tc.name: OHInputManagerTest_OH_Input_GetFunctionKeyState_002
2240 * @tc.desc: Test the funcation OH_Input_GetFunctionKeyState
2241 * @tc.type: FUNC
2242 * @tc.require:
2243 */
2244 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetFunctionKeyState_002, TestSize.Level1)
2245 {
2246 CALL_TEST_DEBUG;
2247 int32_t keyCode = 1;
2248 int32_t state = -1;
2249 Input_Result retResult = OH_Input_GetFunctionKeyState(keyCode, &state);
2250 EXPECT_EQ(retResult, INPUT_KEYBOARD_DEVICE_NOT_EXIST);
2251 keyCode = -5;
2252 retResult = OH_Input_GetFunctionKeyState(keyCode, &state);
2253 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
2254 keyCode = 5;
2255 retResult = OH_Input_GetFunctionKeyState(keyCode, &state);
2256 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
2257 }
2258
2259 /**
2260 * @tc.name: OHInputManagerTest_OH_Input_InjectTouchEvent_007
2261 * @tc.desc: Test the funcation OH_Input_InjectTouchEvent
2262 * @tc.type: FUNC
2263 * @tc.require:
2264 */
2265 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_InjectTouchEvent_007, TestSize.Level1)
2266 {
2267 CALL_TEST_DEBUG;
2268 Input_TouchEvent inputTouchEvent;
2269 inputTouchEvent.actionTime = 100;
2270 inputTouchEvent.displayX = 300;
2271 inputTouchEvent.displayY = 300;
2272 inputTouchEvent.action = TOUCH_ACTION_UP;
2273 EXPECT_EQ(OH_Input_InjectTouchEvent(&inputTouchEvent), 0);
2274 }
2275
2276 /**
2277 * @tc.name: OHInputManagerTest_OH_Input_GetKeyboardType_005
2278 * @tc.desc: Test the funcation OH_Input_GetKeyboardType
2279 * @tc.type: FUNC
2280 * @tc.require:
2281 */
2282 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetKeyboardType_005, TestSize.Level1)
2283 {
2284 CALL_TEST_DEBUG;
2285 int32_t deviceId = -3;
2286 int32_t keyboardType = -1;
2287 Input_Result retResult = OH_Input_GetKeyboardType(deviceId, &keyboardType);
2288 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
2289 }
2290
2291 /**
2292 * @tc.name: OHInputManagerTest_OH_Input_GetDevice_005
2293 * @tc.desc: Test the funcation OH_Input_GetDevice
2294 * @tc.type: FUNC
2295 * @tc.require:
2296 */
2297 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDevice_005, TestSize.Level3)
2298 {
2299 CALL_TEST_DEBUG;
2300 int32_t deviceId = -5;
2301 Input_DeviceInfo *deviceInfo = OH_Input_CreateDeviceInfo();
2302 Input_Result retResult = OH_Input_GetDevice(deviceId, &deviceInfo);
2303 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
2304 }
2305
2306 /**
2307 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceIds_005
2308 * @tc.desc: Test the funcation OH_Input_GetDeviceIds
2309 * @tc.type: FUNC
2310 * @tc.require:
2311 */
2312 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceIds_005, TestSize.Level2)
2313 {
2314 CALL_TEST_DEBUG;
2315 const int32_t inSize = -5;
2316 int32_t outSize = 0;
2317 int32_t *deviceIds = nullptr;
2318 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
2319 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
2320 OH_Input_UnregisterDeviceListeners();
2321 }
2322
2323 /**
2324 * @tc.name: OHInputManagerTest_OH_Input_GetPreKeys_001
2325 * @tc.desc: Test the funcation OH_Input_GetPreKeys
2326 * @tc.type: FUNC
2327 * @tc.require:
2328 */
2329 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetPreKeys_001, TestSize.Level1)
2330 {
2331 CALL_TEST_DEBUG;
2332 Input_Hotkey *hotkey = OH_Input_CreateHotkey();
2333 ASSERT_NE(hotkey, nullptr);
2334 int32_t prekeys[2] = {KEYCODE_ALT_LEFT, KEYCODE_ALT_RIGHT};
2335 OH_Input_SetPreKeys(hotkey, prekeys, 2);
2336 int32_t key = 0;
2337 int32_t key1 = 0;
2338 int32_t *pressedKeys[2] = {&key, &key1};
2339 int32_t pressedKeyNum = 0;
2340 Input_Result result = OH_Input_GetPreKeys(hotkey, pressedKeys, &pressedKeyNum);
2341 EXPECT_EQ(result, INPUT_SUCCESS);
2342 }
2343
2344 /**
2345 * @tc.name: OHInputManagerTest_OH_Input_SetPreKeys_001
2346 * @tc.desc: Test the funcation OH_Input_SetPreKeys
2347 * @tc.type: FUNC
2348 * @tc.require:
2349 */
2350 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_SetPreKeys_001, TestSize.Level1)
2351 {
2352 CALL_TEST_DEBUG;
2353 Input_Hotkey *hotkey = OH_Input_CreateHotkey();
2354 ASSERT_NE(hotkey, nullptr);
2355 int32_t size = -5;
2356 int32_t prekeys[2] = {KEYCODE_ALT_LEFT, KEYCODE_ALT_RIGHT};
2357 ASSERT_NO_FATAL_FAILURE(OH_Input_SetPreKeys(hotkey, prekeys, size));
2358 }
2359
2360 /**
2361 * @tc.name: OHInputManagerTest_OH_Input_CreateAllSystemHotkeys_001
2362 * @tc.desc: Test the funcation OH_Input_CreateAllSystemHotkeys
2363 * @tc.type: FUNC
2364 * @tc.require:
2365 */
2366 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_CreateAllSystemHotkeys_001, TestSize.Level1)
2367 {
2368 CALL_TEST_DEBUG;
2369 int32_t count = -5;
2370 auto ret = OH_Input_CreateAllSystemHotkeys(count);
2371 EXPECT_EQ(ret, nullptr);
2372 }
2373
MouseEventCallback(const struct Input_MouseEvent * mouseEvent)2374 static void MouseEventCallback(const struct Input_MouseEvent *mouseEvent)
2375 {
2376 EXPECT_NE(mouseEvent, nullptr);
2377 int32_t action = OH_Input_GetMouseEventAction(mouseEvent);
2378 int32_t displayX = OH_Input_GetMouseEventDisplayX(mouseEvent);
2379 int32_t displayY = OH_Input_GetMouseEventDisplayY(mouseEvent);
2380 MMI_HILOGI("MouseEventCallback, action:%{public}d, displayX:%{private}d, displayY:%{private}d",
2381 action, displayX, displayY);
2382 }
2383
TouchEventCallback(const struct Input_TouchEvent * touchEvent)2384 static void TouchEventCallback(const struct Input_TouchEvent *touchEvent)
2385 {
2386 EXPECT_NE(touchEvent, nullptr);
2387 int32_t action = OH_Input_GetTouchEventAction(touchEvent);
2388 int32_t id = OH_Input_GetTouchEventFingerId(touchEvent);
2389 MMI_HILOGI("TouchEventCallback, action:%{public}d, id:%{public}d", action, id);
2390 }
2391
2392 /**
2393 * @tc.name: OHInputManagerTest_OH_Input_InjectMouseEventGlobal
2394 * @tc.desc: Test the funcation OH_Input_InjectMouseEventGlobal
2395 * @tc.type: FUNC
2396 * @tc.require:nhj
2397 */
2398 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_InjectMouseEventGlobal001, TestSize.Level2)
2399 {
2400 CALL_TEST_DEBUG;
2401 Input_MouseEvent inputMouseEvent;
2402 inputMouseEvent.actionTime = 1;
2403 inputMouseEvent.action = MOUSE_ACTION_CANCEL;
2404 inputMouseEvent.axisType = MOUSE_AXIS_SCROLL_VERTICAL;
2405 inputMouseEvent.button = MOUSE_BUTTON_LEFT;
2406 EXPECT_EQ(OH_Input_InjectMouseEventGlobal(&inputMouseEvent), INPUT_PARAMETER_ERROR);
2407
2408 inputMouseEvent.actionTime = 100;
2409 inputMouseEvent.displayX = 300;
2410 inputMouseEvent.displayY = 300;
2411 inputMouseEvent.action = TOUCH_ACTION_DOWN;
2412 EXPECT_EQ(OH_Input_InjectMouseEventGlobal(&inputMouseEvent), INPUT_PARAMETER_ERROR);
2413
2414 inputMouseEvent.action = MOUSE_ACTION_AXIS_END;
2415 inputMouseEvent.button = static_cast<Input_MouseEventButton>(10);
2416 EXPECT_EQ(OH_Input_InjectMouseEventGlobal(&inputMouseEvent), INPUT_PARAMETER_ERROR);
2417
2418 inputMouseEvent.actionTime = -1;
2419 inputMouseEvent.displayX = 300;
2420 inputMouseEvent.displayY = 300;
2421 inputMouseEvent.action = TOUCH_ACTION_DOWN;
2422 EXPECT_EQ(OH_Input_InjectMouseEventGlobal(&inputMouseEvent), INPUT_PARAMETER_ERROR);
2423
2424 inputMouseEvent.actionTime = 100;
2425 inputMouseEvent.globalX = 0;
2426 inputMouseEvent.globalY = 0;
2427 EXPECT_EQ(OH_Input_InjectMouseEventGlobal(&inputMouseEvent), INPUT_PARAMETER_ERROR);
2428 }
2429
KeyEventCallback(const struct Input_KeyEvent * keyEvent)2430 static void KeyEventCallback(const struct Input_KeyEvent *keyEvent)
2431 {
2432 EXPECT_NE(keyEvent, nullptr);
2433 int32_t action = OH_Input_GetKeyEventAction(keyEvent);
2434 int32_t id = OH_Input_GetKeyEventDisplayId(keyEvent);
2435 MMI_HILOGI("KeyEventCallback, action:%{public}d, id:%{public}d", action, id);
2436 }
2437
AxisEventCallback(const struct Input_AxisEvent * axisEvent)2438 static void AxisEventCallback(const struct Input_AxisEvent *axisEvent)
2439 {
2440 EXPECT_NE(axisEvent, nullptr);
2441 InputEvent_AxisAction axisAction = AXIS_ACTION_BEGIN;
2442 OH_Input_GetAxisEventAction(axisEvent, &axisAction);
2443 InputEvent_AxisEventType sourceType = AXIS_EVENT_TYPE_PINCH;
2444 OH_Input_GetAxisEventType(axisEvent, &sourceType);
2445 InputEvent_SourceType axisEventType = SOURCE_TYPE_MOUSE;
2446 OH_Input_GetAxisEventSourceType(axisEvent, &axisEventType);
2447 MMI_HILOGI("AxisEventCallback, axisAction:%{public}d, sourceType:%{public}d, axisEventType:%{public}d", axisAction,
2448 sourceType, axisEventType);
2449 }
2450
2451 /**
2452 * @tc.name: OHInputManagerTest_OH_Input_AddInputEventInterceptor_001
2453 * @tc.desc: Test the funcation OH_Input_AddInputEventInterceptor
2454 * @tc.type: FUNC
2455 * @tc.require:
2456 */
2457 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_AddInputEventInterceptor_001, TestSize.Level1)
2458 {
2459 CALL_TEST_DEBUG;
2460 Input_InterceptorEventCallback callback;
2461 callback.mouseCallback = MouseEventCallback;
2462 callback.touchCallback = TouchEventCallback;
2463 callback.axisCallback = AxisEventCallback;
2464 Input_InterceptorOptions *option = nullptr;
2465 std::shared_ptr<OHOS::MMI::PointerEvent> event = OHOS::MMI::PointerEvent::Create();
2466 ASSERT_NE(event, nullptr);
2467 event->SetSourceType(SOURCE_TYPE_TOUCHSCREEN);
2468 Input_Result ret = OH_Input_AddInputEventInterceptor(&callback, option);
2469 EXPECT_EQ(ret, INPUT_SUCCESS);
2470 event->SetSourceType(SOURCE_TYPE_MOUSE);
2471 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_BEGIN);
2472 ret = OH_Input_AddInputEventInterceptor(&callback, option);
2473 EXPECT_EQ(ret, INPUT_REPEAT_INTERCEPTOR);
2474 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_UPDATE);
2475 ret = OH_Input_AddInputEventInterceptor(&callback, option);
2476 EXPECT_EQ(ret, INPUT_REPEAT_INTERCEPTOR);
2477 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_END);
2478 ret = OH_Input_AddInputEventInterceptor(&callback, option);
2479 EXPECT_EQ(ret, INPUT_REPEAT_INTERCEPTOR);
2480 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN);
2481 ret = OH_Input_AddInputEventInterceptor(&callback, option);
2482 EXPECT_EQ(ret, INPUT_REPEAT_INTERCEPTOR);
__anonaa5665ab1102(auto event) 2483 Input_KeyEventCallback callback1 = [](auto event) {};
2484 EXPECT_EQ(OH_Input_AddKeyEventInterceptor(nullptr, option), INPUT_PARAMETER_ERROR);
2485 EXPECT_NO_FATAL_FAILURE(OH_Input_AddKeyEventInterceptor(callback1, option));
2486 }
2487
2488 /**
2489 * @tc.name: OHInputManagerTest_OH_Input_AddInputEventInterceptor_002
2490 * @tc.desc: Test the funcation OH_Input_AddInputEventInterceptor
2491 * @tc.type: FUNC
2492 * @tc.require:
2493 */
2494 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_AddInputEventInterceptor_002, TestSize.Level1)
2495 {
2496 CALL_TEST_DEBUG;
2497 Input_InterceptorEventCallback callback;
2498 callback.mouseCallback = MouseEventCallback;
2499 callback.touchCallback = TouchEventCallback;
2500 callback.axisCallback = AxisEventCallback;
2501 Input_InterceptorOptions *option = nullptr;
2502 std::shared_ptr<OHOS::MMI::PointerEvent> event = OHOS::MMI::PointerEvent::Create();
2503 ASSERT_NE(event, nullptr);
2504 event->SetSourceType(SOURCE_TYPE_TOUCHSCREEN);
2505 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_BEGIN);
2506 Input_Result ret = OH_Input_AddInputEventInterceptor(&callback, option);
2507 EXPECT_EQ(ret, INPUT_REPEAT_INTERCEPTOR);
2508 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_UPDATE);
2509 ret = OH_Input_AddInputEventInterceptor(&callback, option);
2510 EXPECT_EQ(ret, INPUT_REPEAT_INTERCEPTOR);
2511 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_END);
2512 ret = OH_Input_AddInputEventInterceptor(&callback, option);
2513 EXPECT_EQ(ret, INPUT_REPEAT_INTERCEPTOR);
2514 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN);
2515 ret = OH_Input_AddInputEventInterceptor(&callback, option);
2516 EXPECT_EQ(ret, INPUT_REPEAT_INTERCEPTOR);
2517 }
2518
2519 /**
2520 * @tc.name: OHInputManagerTest_OH_Input_AddInputEventInterceptor_003
2521 * @tc.desc: Test the funcation OH_Input_AddInputEventInterceptor
2522 * @tc.type: FUNC
2523 * @tc.require:
2524 */
2525 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_AddInputEventInterceptor_003, TestSize.Level1)
2526 {
2527 CALL_TEST_DEBUG;
2528 Input_InterceptorEventCallback callback;
2529 callback.mouseCallback = MouseEventCallback;
2530 callback.touchCallback = TouchEventCallback;
2531 callback.axisCallback = AxisEventCallback;
2532 Input_InterceptorOptions *option = nullptr;
2533 std::shared_ptr<OHOS::MMI::PointerEvent> event = OHOS::MMI::PointerEvent::Create();
2534 ASSERT_NE(event, nullptr);
2535 event->SetSourceType(SOURCE_TYPE_TOUCHPAD);
2536 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_BEGIN);
2537 Input_Result ret = OH_Input_AddInputEventInterceptor(&callback, option);
2538 EXPECT_EQ(ret, INPUT_REPEAT_INTERCEPTOR);
2539 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_UPDATE);
2540 ret = OH_Input_AddInputEventInterceptor(&callback, option);
2541 EXPECT_EQ(ret, INPUT_REPEAT_INTERCEPTOR);
2542 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_END);
2543 ret = OH_Input_AddInputEventInterceptor(&callback, option);
2544 EXPECT_EQ(ret, INPUT_REPEAT_INTERCEPTOR);
2545 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN);
2546 ret = OH_Input_AddInputEventInterceptor(&callback, option);
2547 EXPECT_EQ(ret, INPUT_REPEAT_INTERCEPTOR);
2548 }
2549
2550 /**
2551 * @tc.name: OHInputManagerTest_PointerEventMonitorCallback_001
2552 * @tc.desc: Test the funcation PointerEventMonitorCallback
2553 * @tc.type: FUNC
2554 * @tc.require:
2555 */
2556 HWTEST_F(OHInputManagerTest, OHInputManagerTest_PointerEventMonitorCallback_001, TestSize.Level1)
2557 {
2558 CALL_TEST_DEBUG;
2559 Input_MouseEventCallback callback;
2560 callback = MouseEventCallback;
2561 std::shared_ptr<OHOS::MMI::PointerEvent> event = OHOS::MMI::PointerEvent::Create();
2562 ASSERT_NE(event, nullptr);
2563 event->SetSourceType(SOURCE_TYPE_TOUCHSCREEN);
2564 Input_Result ret = OH_Input_AddMouseEventMonitor(callback);
2565 EXPECT_EQ(ret, INPUT_SUCCESS);
2566 event->SetSourceType(SOURCE_TYPE_MOUSE);
2567 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_BEGIN);
2568 ret = OH_Input_AddMouseEventMonitor(callback);
2569 EXPECT_EQ(ret, INPUT_SUCCESS);
2570 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_UPDATE);
2571 ret = OH_Input_AddMouseEventMonitor(callback);
2572 EXPECT_EQ(ret, INPUT_SUCCESS);
2573 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_END);
2574 ret = OH_Input_AddMouseEventMonitor(callback);
2575 EXPECT_EQ(ret, INPUT_SUCCESS);
2576 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN);
2577 ret = OH_Input_AddMouseEventMonitor(callback);
2578 EXPECT_EQ(ret, INPUT_SUCCESS);
2579 }
2580
2581 /**
2582 * @tc.name: OHInputManagerTest_PointerEventMonitorCallback_002
2583 * @tc.desc: Test the funcation PointerEventMonitorCallback
2584 * @tc.type: FUNC
2585 * @tc.require:
2586 */
2587 HWTEST_F(OHInputManagerTest, OHInputManagerTest_PointerEventMonitorCallback_002, TestSize.Level1)
2588 {
2589 CALL_TEST_DEBUG;
2590 Input_MouseEventCallback callback;
2591 callback = MouseEventCallback;
2592 std::shared_ptr<OHOS::MMI::PointerEvent> event = OHOS::MMI::PointerEvent::Create();
2593 ASSERT_NE(event, nullptr);
2594 event->SetSourceType(SOURCE_TYPE_TOUCHSCREEN);
2595 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_BEGIN);
2596 Input_Result ret = OH_Input_AddMouseEventMonitor(callback);
2597 EXPECT_EQ(ret, INPUT_SUCCESS);
2598 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_UPDATE);
2599 ret = OH_Input_AddMouseEventMonitor(callback);
2600 EXPECT_EQ(ret, INPUT_SUCCESS);
2601 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_END);
2602 ret = OH_Input_AddMouseEventMonitor(callback);
2603 EXPECT_EQ(ret, INPUT_SUCCESS);
2604 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN);
2605 ret = OH_Input_AddMouseEventMonitor(callback);
2606 EXPECT_EQ(ret, INPUT_SUCCESS);
2607 }
2608
2609 /**
2610 * @tc.name: OHInputManagerTest_PointerEventMonitorCallback_003
2611 * @tc.desc: Test the funcation PointerEventMonitorCallback
2612 * @tc.type: FUNC
2613 * @tc.require:
2614 */
2615 HWTEST_F(OHInputManagerTest, OHInputManagerTest_PointerEventMonitorCallback_003, TestSize.Level1)
2616 {
2617 CALL_TEST_DEBUG;
2618 Input_MouseEventCallback callback;
2619 callback = MouseEventCallback;
2620 std::shared_ptr<OHOS::MMI::PointerEvent> event = OHOS::MMI::PointerEvent::Create();
2621 ASSERT_NE(event, nullptr);
2622 event->SetSourceType(SOURCE_TYPE_TOUCHPAD);
2623 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_BEGIN);
2624 Input_Result ret = OH_Input_AddMouseEventMonitor(callback);
2625 EXPECT_EQ(ret, INPUT_SUCCESS);
2626 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_UPDATE);
2627 ret = OH_Input_AddMouseEventMonitor(callback);
2628 EXPECT_EQ(ret, INPUT_SUCCESS);
2629 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_END);
2630 ret = OH_Input_AddMouseEventMonitor(callback);
2631 EXPECT_EQ(ret, INPUT_SUCCESS);
2632 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN);
2633 ret = OH_Input_AddMouseEventMonitor(callback);
2634 EXPECT_EQ(ret, INPUT_SUCCESS);
2635 }
2636
2637 /**
2638 * @tc.name: OHInputManagerTest_OH_Input_InjectMouseEvent
2639 * @tc.desc: Test the funcation OH_Input_InjectMouseEvent
2640 * @tc.type: FUNC
2641 * @tc.require:nhj
2642 */
2643 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_InjectMouseEvent001, TestSize.Level2)
2644 {
2645 CALL_TEST_DEBUG;
2646 Input_MouseEvent inputMouseEvent;
2647 inputMouseEvent.actionTime = 1;
2648 inputMouseEvent.action = MOUSE_ACTION_CANCEL;
2649 inputMouseEvent.axisType = MOUSE_AXIS_SCROLL_VERTICAL;
2650 inputMouseEvent.button = MOUSE_BUTTON_LEFT;
2651 EXPECT_EQ(OH_Input_InjectMouseEvent(&inputMouseEvent), INPUT_PERMISSION_DENIED);
2652
2653 inputMouseEvent.actionTime = 100;
2654 inputMouseEvent.displayX = 300;
2655 inputMouseEvent.displayY = 300;
2656 inputMouseEvent.action = TOUCH_ACTION_DOWN;
2657 EXPECT_EQ(OH_Input_InjectMouseEvent(&inputMouseEvent), INPUT_PERMISSION_DENIED);
2658
2659 inputMouseEvent.action = MOUSE_ACTION_AXIS_END;
2660 inputMouseEvent.button = static_cast<Input_MouseEventButton>(10);
2661 EXPECT_EQ(OH_Input_InjectMouseEvent(&inputMouseEvent), INPUT_PARAMETER_ERROR);
2662 }
2663
2664 /**
2665 * @tc.name: OHInputManagerTest_OH_Input_InjectTouchEvent
2666 * @tc.desc: Test the funcation OH_Input_InjectTouchEvent
2667 * @tc.type: FUNC
2668 * @tc.require:
2669 */
2670 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_InjectTouchEvent_008, TestSize.Level2)
2671 {
2672 CALL_TEST_DEBUG;
2673 Input_TouchEvent inputTouchEvent;
2674 inputTouchEvent.actionTime = -100;
2675 inputTouchEvent.displayX = -1;
2676 inputTouchEvent.action = TOUCH_ACTION_DOWN;
2677 EXPECT_EQ(OH_Input_InjectTouchEvent(&inputTouchEvent), INPUT_PARAMETER_ERROR);
2678 }
2679
2680 /**
2681 * @tc.name: OHInputManagerTest_OH_Input_InjectTouchEvent
2682 * @tc.desc: Test the funcation OH_Input_InjectTouchEvent
2683 * @tc.type: FUNC
2684 * @tc.require:
2685 */
2686 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_InjectTouchEvent_009, TestSize.Level1)
2687 {
2688 CALL_TEST_DEBUG;
2689 Input_TouchEvent inputTouchEvent;
2690 inputTouchEvent.actionTime = 100;
2691 inputTouchEvent.action = TOUCH_ACTION_UP;
2692 std::shared_ptr<OHOS::MMI::PointerEvent> event = OHOS::MMI::PointerEvent::Create();
2693 int32_t pointerId = 3;
2694 event->SetPointerId(pointerId);
2695 auto pointerIds = event->GetPointerIds();
2696 EXPECT_TRUE(pointerIds.empty());
2697 EXPECT_EQ(OH_Input_InjectTouchEvent(&inputTouchEvent), INPUT_PARAMETER_ERROR);
2698 }
2699
2700 /**
2701 * @tc.name: OHInputManagerTest_OH_Input_InjectTouchEvent_005
2702 * @tc.desc: Test the funcation OH_Input_InjectTouchEvent
2703 * @tc.type: FUNC
2704 * @tc.require:
2705 */
2706 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_InjectTouchEvent_010, TestSize.Level1)
2707 {
2708 CALL_TEST_DEBUG;
2709 Input_TouchEvent inputTouchEvent;
2710 inputTouchEvent.actionTime = 100;
2711 inputTouchEvent.displayX = 300;
2712 inputTouchEvent.displayY = -1;
2713 inputTouchEvent.action = TOUCH_ACTION_CANCEL;
2714 EXPECT_EQ(OH_Input_InjectTouchEvent(&inputTouchEvent), INPUT_PARAMETER_ERROR);
2715 }
2716
2717 /**
2718 * @tc.name: OHInputManagerTest_OH_Input_AddKeyEventMonitor
2719 * @tc.desc: Test the funcation OH_Input_AddKeyEventMonitor
2720 * @tc.type: FUNC
2721 * @tc.require:
2722 */
2723 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_AddKeyEventMonitor, TestSize.Level1)
2724 {
2725 CALL_TEST_DEBUG;
2726 Input_KeyEventCallback callback;
2727 callback = KeyEventCallback;
2728 std::shared_ptr<OHOS::MMI::PointerEvent> event = OHOS::MMI::PointerEvent::Create();
2729 ASSERT_NE(event, nullptr);
2730 Input_Result retResult = OH_Input_RemoveKeyEventMonitor(callback);
2731 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
2732 event->SetSourceType(SOURCE_TYPE_TOUCHSCREEN);
2733 Input_Result ret = OH_Input_AddKeyEventMonitor(callback);
2734 EXPECT_EQ(ret, INPUT_SUCCESS);
2735 event->SetSourceType(SOURCE_TYPE_MOUSE);
2736 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_BEGIN);
2737 ret = OH_Input_AddKeyEventMonitor(callback);
2738 EXPECT_EQ(ret, INPUT_SUCCESS);
2739 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_UPDATE);
2740 ret = OH_Input_AddKeyEventMonitor(callback);
2741 EXPECT_EQ(ret, INPUT_SUCCESS);
2742 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_END);
2743 ret = OH_Input_AddKeyEventMonitor(callback);
2744 EXPECT_EQ(ret, INPUT_SUCCESS);
2745 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN);
2746 ret = OH_Input_AddKeyEventMonitor(callback);
2747 EXPECT_EQ(ret, INPUT_SUCCESS);
2748 }
2749
2750 /**
2751 * @tc.name: OHInputManagerTest_OH_Input_GetFunctionKeyState_003
2752 * @tc.desc: Test the funcation OH_Input_GetFunctionKeyState
2753 * @tc.type: FUNC
2754 * @tc.require:
2755 */
2756 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetFunctionKeyState_003, TestSize.Level1)
2757 {
2758 CALL_TEST_DEBUG;
2759 int32_t keyCode = 1;
2760 int32_t state = 1;
2761 Input_Result retResult = OH_Input_GetFunctionKeyState(keyCode, &state);
2762 EXPECT_EQ(retResult, INPUT_KEYBOARD_DEVICE_NOT_EXIST);
2763 keyCode = -1;
2764 retResult = OH_Input_GetFunctionKeyState(keyCode, &state);
2765 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
2766 keyCode = 5;
2767 retResult = OH_Input_GetFunctionKeyState(keyCode, &state);
2768 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
2769 state = -1;
2770 retResult = OH_Input_GetFunctionKeyState(keyCode, &state);
2771 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
2772 }
2773
2774 /**
2775 * @tc.name: OHInputManagerTest_OH_Input_GetFunctionKeyState
2776 * @tc.desc: Test the funcation OH_Input_GetFunctionKeyState
2777 * @tc.type: FUNC
2778 * @tc.require:
2779 */
2780 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetFunctionKeyState_001, TestSize.Level1)
2781 {
2782 CALL_TEST_DEBUG;
2783 int32_t keyCode = 1;
2784 int32_t state = -1;
2785 bool resultState = true;
2786 Input_Result retResult = OH_Input_GetFunctionKeyState(keyCode, &state);
2787 int32_t napiCode = OHOS::MMI::InputManager::GetInstance()->GetFunctionKeyState(keyCode, resultState);
2788 EXPECT_EQ(napiCode, INPUT_KEYBOARD_DEVICE_NOT_EXIST);
2789 EXPECT_EQ(retResult, INPUT_KEYBOARD_DEVICE_NOT_EXIST);
2790 }
2791
2792 /**
2793 * @tc.name: OHInputManagerTest_OH_Input_GetKeyboardType
2794 * @tc.desc: Test the funcation OH_Input_GetKeyboardType
2795 * @tc.type: FUNC
2796 * @tc.require:
2797 */
2798 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetKeyboardType_006, TestSize.Level2)
2799 {
2800 int32_t deviceId = 0;
2801 int32_t keyboardType = 0;
2802 Input_Result ret = OH_Input_GetKeyboardType(deviceId, &keyboardType); // 假设 deviceId=0 是有效设备
2803 EXPECT_EQ(ret, INPUT_SUCCESS);
2804 EXPECT_NE(keyboardType, 0);
2805 }
2806
2807 /**
2808 * @tc.name: OHInputManagerTest_OH_Input_GetKeyboardType
2809 * @tc.desc: Test the funcation OH_Input_GetKeyboardType
2810 * @tc.type: FUNC
2811 * @tc.require:
2812 */
2813 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetKeyboardType_007, TestSize.Level1)
2814 {
2815 int32_t deviceId = 99999;
2816 int32_t keyboardType = -1;
2817 Input_Result retResult = OH_Input_GetKeyboardType(deviceId, &keyboardType);
2818 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
2819 }
2820
2821 /**
2822 * @tc.name: OHInputManagerTest_OH_Input_GetDeviceIds
2823 * @tc.desc: Test the funcation OH_Input_GetDeviceIds
2824 * @tc.type: FUNC
2825 * @tc.require:
2826 */
2827 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetDeviceIds_006, TestSize.Level1)
2828 {
2829 const int32_t inSize = 0;
2830 int32_t outSize = 1;
2831 int32_t deviceIds[inSize] = {};
2832 Input_Result retResult = OH_Input_GetDeviceIds(deviceIds, inSize, &outSize);
2833 EXPECT_EQ(retResult, INPUT_SUCCESS);
2834 EXPECT_EQ(outSize, 0);
2835 }
2836
2837 /**
2838 * @tc.name: OHInputManagerTest_PointerEventMonitorCallback_004
2839 * @tc.desc: Test the funcation OH_Input_AddMouseEventMonitor
2840 * @tc.type: FUNC
2841 * @tc.require:
2842 */
2843 HWTEST_F(OHInputManagerTest, OHInputManagerTest_PointerEventMonitorCallback_004, TestSize.Level1)
2844 {
2845 CALL_TEST_DEBUG;
2846 Input_MouseEventCallback callback;
2847 callback = MouseEventCallback;
2848 std::shared_ptr<OHOS::MMI::PointerEvent> event = OHOS::MMI::PointerEvent::Create();
2849 ASSERT_NE(event, nullptr);
2850 event->SetSourceType(SOURCE_TYPE_TOUCHSCREEN);
2851 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_DOWN);
2852 Input_Result ret = OH_Input_AddMouseEventMonitor(callback);
2853 EXPECT_EQ(ret, INPUT_SUCCESS);
2854 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_MOVE);
2855 ret = OH_Input_AddMouseEventMonitor(callback);
2856 EXPECT_EQ(ret, INPUT_SUCCESS);
2857 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_UP);
2858 ret = OH_Input_AddMouseEventMonitor(callback);
2859 EXPECT_EQ(ret, INPUT_SUCCESS);
2860 event->SetPointerAction(OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_IN_WINDOW);
2861 ret = OH_Input_AddMouseEventMonitor(callback);
2862 EXPECT_EQ(ret, INPUT_SUCCESS);
2863 ret = OH_Input_RemoveMouseEventMonitor(callback);
2864 EXPECT_EQ(ret, INPUT_SUCCESS);
2865 }
2866
2867 /*
2868 * @tc.name: OHInputManagerTest_QueryMaxTouchPoints_001
2869 * @tc.desc: GetMaxMultiTouchPointNum
2870 * @tc.type: FUNC
2871 * @tc.require:
2872 */
2873 HWTEST_F(OHInputManagerTest, OHInputManagerTest_QueryMaxTouchPoints_001, TestSize.Level1)
2874 {
2875 CALL_TEST_DEBUG;
2876 auto ret = OH_Input_QueryMaxTouchPoints(nullptr);
2877 EXPECT_EQ(ret, INPUT_PARAMETER_ERROR);
2878 }
2879
2880 /*
2881 * @tc.name: OHInputManagerTest_QueryMaxTouchPoints_002
2882 * @tc.desc: GetMaxMultiTouchPointNum
2883 * @tc.type: FUNC
2884 * @tc.require:
2885 */
2886 HWTEST_F(OHInputManagerTest, OHInputManagerTest_QueryMaxTouchPoints_002, TestSize.Level1)
2887 {
2888 CALL_TEST_DEBUG;
2889 int32_t pointNum {UNKNOWN_MULTI_TOUCH_POINT_NUM};
2890 auto ret = OH_Input_QueryMaxTouchPoints(&pointNum);
2891 EXPECT_EQ(ret, INPUT_SUCCESS);
2892 EXPECT_TRUE((pointNum == UNKNOWN_MULTI_TOUCH_POINT_NUM) ||
2893 ((pointNum >= MIN_MULTI_TOUCH_POINT_NUM) && (pointNum <= MAX_MULTI_TOUCH_POINT_NUM)));
2894 }
2895
2896 /*
2897 * @tc.name: OHInputManagerTest_TouchMouseGlobalCoordinates
2898 * @tc.desc: OH_Input_SetTouchMouseGlobalX OH_Input_SetTouchMouseGlobalY
2899 * OH_Input_GetTouchMouseGlobalX OH_Input_GetMouseEventGlobalY
2900 * @tc.type: FUNC
2901 * @tc.require:
2902 */
2903 HWTEST_F(OHInputManagerTest, OHInputManagerTest_TouchMouseGlobalCoordinates, TestSize.Level1)
2904 {
2905 Input_MouseEvent mouseEvent;
2906 OH_Input_SetMouseEventGlobalX(&mouseEvent, DEFAULT_GLOBAL_X);
2907 OH_Input_SetMouseEventGlobalY(&mouseEvent, DEFAULT_GLOBAL_Y);
2908 int32_t globalX = OH_Input_GetMouseEventGlobalX(&mouseEvent);
2909 int32_t globalY = OH_Input_GetMouseEventGlobalY(&mouseEvent);
2910 EXPECT_TRUE((globalX == DEFAULT_GLOBAL_X) && (globalY == DEFAULT_GLOBAL_Y));
2911 }
2912
2913 /*
2914 * @tc.name: OHInputManagerTest_TouchEventGlobalCoordinates
2915 * @tc.desc: OH_Input_SetTouchEventGlobalX OH_Input_SetTouchEventGlobalY
2916 * OH_Input_GetTouchEventGlobalX OH_Input_GetTouchEventGlobalY
2917 * @tc.type: FUNC
2918 * @tc.require:
2919 */
2920 HWTEST_F(OHInputManagerTest, OHInputManagerTest_TouchEventGlobalCoordinates, TestSize.Level1)
2921 {
2922 Input_TouchEvent touchEvent;
2923 OH_Input_SetTouchEventGlobalX(&touchEvent, DEFAULT_GLOBAL_X);
2924 OH_Input_SetTouchEventGlobalY(&touchEvent, DEFAULT_GLOBAL_Y);
2925 int32_t globalX = OH_Input_GetTouchEventGlobalX(&touchEvent);
2926 int32_t globalY = OH_Input_GetTouchEventGlobalY(&touchEvent);
2927 EXPECT_TRUE((globalX == DEFAULT_GLOBAL_X) && (globalY == DEFAULT_GLOBAL_Y));
2928 }
2929
2930 /*
2931 * @tc.name: OHInputManagerTest_AxisEventGlobalCoordinates
2932 * @tc.desc: OH_Input_SetAxisEventGlobalX OH_Input_SetAxisEventGlobalY
2933 * OH_Input_GetAxisEventGlobalX OH_Input_GetAxisEventGlobalY
2934 * @tc.type: FUNC
2935 * @tc.require:
2936 */
2937 HWTEST_F(OHInputManagerTest, OHInputManagerTest_AxisEventGlobalCoordinates, TestSize.Level1)
2938 {
2939 Input_AxisEvent axisEvent;
2940 OH_Input_SetAxisEventGlobalX(&axisEvent, DEFAULT_GLOBAL_X);
2941 OH_Input_SetAxisEventGlobalY(&axisEvent, DEFAULT_GLOBAL_Y);
2942 int32_t globalX {0};
2943 int32_t globalY {0};
2944 ASSERT_EQ(OH_Input_GetAxisEventGlobalX(&axisEvent, &globalX), INPUT_SUCCESS);
2945 ASSERT_EQ(OH_Input_GetAxisEventGlobalY(&axisEvent, &globalY), INPUT_SUCCESS);
2946 EXPECT_TRUE((globalX == DEFAULT_GLOBAL_X) && (globalY == DEFAULT_GLOBAL_Y));
2947 }
2948
2949 /**
2950 * @tc.name: OHInputManagerTest_RequestInjection_001
2951 * @tc.desc: Verify the RequestInjection
2952 * @tc.type: FUNC
2953 * @tc.require:
2954 */
2955 HWTEST_F(OHInputManagerTest, OHInputManagerTest_RequestInjection_001, TestSize.Level1)
2956 {
2957 auto retResult = OH_Input_RequestInjection(nullptr);
2958 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
2959 retResult = OH_Input_QueryAuthorizedStatus(nullptr);
2960 EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR);
__anonaa5665ab1202(Input_InjectionStatus authorizedStatus) 2961 auto fnCallBack = [](Input_InjectionStatus authorizedStatus) {
2962 MMI_HILOGI("OH_Input_RequestInjection callbak:status:%{public}d", authorizedStatus);
2963 };
2964 #ifndef OHOS_BUILD_PC_PRIORITY
2965 retResult = OH_Input_RequestInjection(fnCallBack);
2966 EXPECT_EQ(retResult, INPUT_DEVICE_NOT_SUPPORTED);
2967 return;
2968 #endif
2969 Input_InjectionStatus status = Input_InjectionStatus::UNAUTHORIZED;
2970 InputManager::GetInstance()->Authorize(false);
2971 retResult = OH_Input_QueryAuthorizedStatus(&status);
2972 EXPECT_EQ(retResult, INPUT_SUCCESS);
2973 EXPECT_EQ(status, Input_InjectionStatus::UNAUTHORIZED);
2974
2975 retResult = OH_Input_RequestInjection(fnCallBack);
2976 EXPECT_EQ(retResult, INPUT_SUCCESS);
2977
2978 retResult = OH_Input_RequestInjection(fnCallBack);
2979 EXPECT_EQ(retResult, INPUT_INJECTION_AUTHORIZING);
2980
2981 retResult = OH_Input_QueryAuthorizedStatus(&status);
2982 EXPECT_EQ(retResult, INPUT_SUCCESS);
2983 EXPECT_EQ(status, Input_InjectionStatus::AUTHORIZING);
2984
2985 InputManager::GetInstance()->Authorize(true);
2986
2987 retResult = OH_Input_RequestInjection(fnCallBack);
2988 EXPECT_EQ(retResult, INPUT_INJECTION_AUTHORIZED);
2989
2990 retResult = OH_Input_QueryAuthorizedStatus(&status);
2991 EXPECT_EQ(retResult, INPUT_SUCCESS);
2992 EXPECT_EQ(status, Input_InjectionStatus::AUTHORIZED);
2993
2994 InputManager::GetInstance()->Authorize(false);
2995 OH_Input_CancelInjection();
2996 retResult = OH_Input_QueryAuthorizedStatus(&status);
2997 EXPECT_EQ(retResult, INPUT_SUCCESS);
2998 EXPECT_EQ(status, Input_InjectionStatus::UNAUTHORIZED);
2999 }
3000
3001 /**
3002 * @tc.name: OHInputManagerTest_RequestInjection_002
3003 * @tc.desc: Verify the RequestInjection
3004 * @tc.type: FUNC
3005 * @tc.require:
3006 */
3007 HWTEST_F(OHInputManagerTest, OHInputManagerTest_RequestInjection_002, TestSize.Level1)
3008 {
3009 Input_InjectionStatus status = Input_InjectionStatus::UNAUTHORIZED;
3010 auto retResult = OH_Input_QueryAuthorizedStatus(&status);
3011 EXPECT_EQ(retResult, INPUT_SUCCESS);
3012 #ifndef OHOS_BUILD_PC_PRIORITY
3013 return;
3014 #endif
__anonaa5665ab1302(Input_InjectionStatus authorizedStatus) 3015 auto fnCallBack = [](Input_InjectionStatus authorizedStatus) {
3016 MMI_HILOGI("OH_Input_RequestInjection callbak:status:%{public}d", authorizedStatus);
3017 };
3018 InputManager::GetInstance()->Authorize(false);
3019 OH_Input_CancelInjection();
3020 std::this_thread::sleep_for(std::chrono::milliseconds(REQUEST_INJECTION_TIME_MS));
3021 retResult = OH_Input_RequestInjection(fnCallBack);
3022 EXPECT_EQ(retResult, INPUT_SUCCESS);
3023 InputManager::GetInstance()->Authorize(false);
3024 retResult = OH_Input_QueryAuthorizedStatus(&status);
3025 EXPECT_EQ(retResult, INPUT_SUCCESS);
3026 EXPECT_EQ(status, Input_InjectionStatus::UNAUTHORIZED);
3027
3028 InputManager::GetInstance()->Authorize(false);
3029 retResult = OH_Input_RequestInjection(fnCallBack);
3030 EXPECT_EQ(retResult, INPUT_INJECTION_OPERATION_FREQUENT);
3031
3032 retResult = OH_Input_QueryAuthorizedStatus(&status);
3033 EXPECT_EQ(retResult, INPUT_SUCCESS);
3034 EXPECT_EQ(status, Input_InjectionStatus::UNAUTHORIZED);
3035 InputManager::GetInstance()->Authorize(false);
3036 OH_Input_CancelInjection();
3037 }
3038
3039 /**
3040 * @tc.name: OHInputManagerTest_OH_Input_InjectTouchEventGlobal_001
3041 * @tc.desc: Test the funcation OH_Input_InjectTouchEventGlobal
3042 * @tc.type: FUNC
3043 * @tc.require:
3044 */
3045 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_InjectTouchEventGlobal_001, TestSize.Level1)
3046 {
3047 CALL_TEST_DEBUG;
3048 EXPECT_EQ(OH_Input_InjectTouchEventGlobal(nullptr), INPUT_PARAMETER_ERROR);
3049 }
3050
3051 /**
3052 * @tc.name: OHInputManagerTest_OH_Input_InjectTouchEventGlobal_002
3053 * @tc.desc: Test the funcation OH_Input_InjectTouchEventGlobal
3054 * @tc.type: FUNC
3055 * @tc.require:
3056 */
3057 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_InjectTouchEventGlobal_002, TestSize.Level1)
3058 {
3059 CALL_TEST_DEBUG;
3060 Input_TouchEvent touchEvent;
3061 touchEvent.action = TOUCH_ACTION_DOWN;
3062 touchEvent.displayX = 100;
3063 touchEvent.displayY = 100;
3064 touchEvent.globalX = 100;
3065 touchEvent.globalY = 100;
3066 auto origin = g_touchEvent;
3067 g_touchEvent = nullptr;
3068 EXPECT_EQ(OH_Input_InjectTouchEventGlobal(&touchEvent), INPUT_PERMISSION_DENIED);
3069 g_touchEvent = origin;
3070 }
3071
3072 /**
3073 * @tc.name: OHInputManagerTest_OH_Input_InjectTouchEventGlobal_003
3074 * @tc.desc: Test the funcation OH_Input_InjectTouchEventGlobal
3075 * @tc.type: FUNC
3076 * @tc.require:
3077 */
3078 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_InjectTouchEventGlobal_003, TestSize.Level1)
3079 {
3080 CALL_TEST_DEBUG;
3081 Input_TouchEvent touchEvent;
3082 touchEvent.action = -1;
3083 touchEvent.displayX = 100;
3084 touchEvent.displayY = 100;
3085 touchEvent.globalX = 100;
3086 touchEvent.globalY = 100;
3087 EXPECT_EQ(OH_Input_InjectTouchEventGlobal(&touchEvent), INPUT_PARAMETER_ERROR);
3088 }
3089
3090 /**
3091 * @tc.name: OHInputManagerTest_OH_Input_InjectTouchEventGlobal_004
3092 * @tc.desc: Test the funcation OH_Input_InjectTouchEventGlobal
3093 * @tc.type: FUNC
3094 * @tc.require:
3095 */
3096 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_InjectTouchEventGlobal_004, TestSize.Level1)
3097 {
3098 CALL_TEST_DEBUG;
3099 Input_TouchEvent touchEvent;
3100 touchEvent.action = TOUCH_ACTION_DOWN;
3101 touchEvent.displayX = 100;
3102 touchEvent.displayY = 100;
3103 touchEvent.globalX = INT32_MAX;
3104 touchEvent.globalY = INT32_MAX;
3105 EXPECT_EQ(OH_Input_InjectTouchEventGlobal(&touchEvent), INPUT_PARAMETER_ERROR);
3106 }
3107
3108 /**
3109 * @tc.name: OHInputManagerTest_OH_Input_InjectTouchEventGlobal_005
3110 * @tc.desc: Test the funcation OH_Input_InjectTouchEventGlobal
3111 * @tc.type: FUNC
3112 * @tc.require:
3113 */
3114 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_InjectTouchEventGlobal_005, TestSize.Level1)
3115 {
3116 CALL_TEST_DEBUG;
3117 Input_TouchEvent touchEvent;
3118 touchEvent.action = TOUCH_ACTION_DOWN;
3119 touchEvent.displayX = 10;
3120 touchEvent.displayY = 10;
3121 touchEvent.globalX = 10;
3122 touchEvent.globalY = 10;
3123 EXPECT_EQ(OH_Input_InjectTouchEventGlobal(&touchEvent), INPUT_PERMISSION_DENIED);
3124 }
3125
3126 /**
3127 * @tc.name: OHInputManagerTest_OH_Input_InjectMouseEventGlobal_002
3128 * @tc.desc: Test the funcation OH_Input_InjectMouseEventGlobal
3129 * @tc.type: FUNC
3130 * @tc.require:
3131 */
3132 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_InjectMouseEventGlobal_002, TestSize.Level1)
3133 {
3134 CALL_TEST_DEBUG;
3135 Input_MouseEvent inputMouseEvent {};
3136 inputMouseEvent.actionTime = 100;
3137 inputMouseEvent.displayX = 300;
3138 inputMouseEvent.displayY = 300;
3139 inputMouseEvent.globalX = 300;
3140 inputMouseEvent.globalY = 300;
3141 inputMouseEvent.action = MOUSE_ACTION_BUTTON_DOWN;
3142 inputMouseEvent.button = MOUSE_BUTTON_LEFT;
3143 int32_t ret = OH_Input_InjectMouseEventGlobal(&inputMouseEvent);
3144 EXPECT_EQ(ret, INPUT_PERMISSION_DENIED);
3145 }
3146
3147 /**
3148 * @tc.name: OHInputManagerTest_OH_Input_AddKeyEventInterceptor_001
3149 * @tc.desc: Verify OH_Input_AddKeyEventInterceptor success path
3150 * @tc.type: FUNC
3151 * @tc.require:
3152 */
3153 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_AddKeyEventInterceptor_001, TestSize.Level1)
3154 {
3155 CALL_TEST_DEBUG;
3156 g_interceptorTriggered = false;
3157 InputManager::GetInstance()->Authorize(false);
3158 OH_Input_CancelInjection();
3159 Input_Result ret = OH_Input_AddKeyEventInterceptor(MyKeyEventCallback, nullptr);
3160 if (ret == INPUT_REPEAT_INTERCEPTOR) {
3161 MMI_HILOGI("[TEST] Interceptor already added");
3162 SUCCEED();
3163 return;
3164 }
3165 EXPECT_EQ(ret, INPUT_SUCCESS);
3166 std::this_thread::sleep_for(std::chrono::seconds(2));
3167 EXPECT_TRUE(g_interceptorTriggered);
3168 }
3169
3170 /**
3171 * @tc.name: OHInputManagerTest_OH_Input_AddKeyEventInterceptor_002
3172 * @tc.desc: Verify duplicate OH_Input_AddKeyEventInterceptor fails with INPUT_REPEAT_INTERCEPTOR
3173 * @tc.type: FUNC
3174 * @tc.require:
3175 */
3176 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_AddKeyEventInterceptor_002, TestSize.Level1)
3177 {
3178 CALL_TEST_DEBUG;
3179 (void)OH_Input_RemoveKeyEventInterceptor();
3180 Input_Result ret1 = OH_Input_AddKeyEventInterceptor(DummyCallback, nullptr);
3181 EXPECT_EQ(ret1, INPUT_SUCCESS);
3182 Input_Result ret2 = OH_Input_AddKeyEventInterceptor(DummyCallback, nullptr);
3183 EXPECT_EQ(ret2, INPUT_REPEAT_INTERCEPTOR);
3184 Input_Result retRm = OH_Input_RemoveKeyEventInterceptor();
3185 EXPECT_EQ(retRm, INPUT_SUCCESS);
3186 }
3187
3188 /**
3189 * @tc.name: OHInputManagerTest_OH_Input_AddHotkeyMonitor_002
3190 * @tc.desc: Test AddHotkeyMonitor with nullptr parameters.
3191 * @tc.type: FUNC
3192 * @tc.require:
3193 */
3194 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_AddHotkeyMonitor_002, TestSize.Level1)
3195 {
3196 Input_Result result = OH_Input_AddHotkeyMonitor(nullptr, &HotkeyCallback);
3197 EXPECT_EQ(result, INPUT_PARAMETER_ERROR);
3198 Input_Hotkey *hotkey = OH_Input_CreateHotkey();
3199 ASSERT_NE(hotkey, nullptr);
3200 int32_t preKeys[] { KEYCODE_CTRL_LEFT };
3201 OH_Input_SetPreKeys(hotkey, preKeys, sizeof(preKeys) / sizeof(int32_t));
3202 OH_Input_SetFinalKey(hotkey, KEYCODE_TAB);
3203 OH_Input_SetRepeat(hotkey, false);
3204 result = OH_Input_AddHotkeyMonitor(hotkey, nullptr);
3205 EXPECT_EQ(result, INPUT_PARAMETER_ERROR);
3206 OH_Input_DestroyHotkey(&hotkey);
3207 }
3208
3209 /**
3210 * @tc.name: OHInputManagerTest_OH_Input_AddHotkeyMonitor_003
3211 * @tc.desc: Test AddHotkeyMonitor system/other occupied and unsupported.
3212 * @tc.type: FUNC
3213 * @tc.require:
3214 */
3215 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_AddHotkeyMonitor_003, TestSize.Level1)
3216 {
3217 Input_Hotkey *hotkey = OH_Input_CreateHotkey();
3218 ASSERT_NE(hotkey, nullptr);
3219 int32_t preKeys[] { KEYCODE_CTRL_LEFT };
3220 OH_Input_SetPreKeys(hotkey, preKeys, sizeof(preKeys) / sizeof(int32_t));
3221 OH_Input_SetFinalKey(hotkey, KEYCODE_TAB);
3222 OH_Input_SetRepeat(hotkey, false);
3223 Input_Result result = OH_Input_AddHotkeyMonitor(hotkey, &HotkeyCallback);
3224 EXPECT_EQ(result, INPUT_SUCCESS);
3225 result = OH_Input_RemoveHotkeyMonitor(hotkey, &HotkeyCallback);
3226 EXPECT_EQ(result, INPUT_SUCCESS);
3227 result = OH_Input_AddHotkeyMonitor(hotkey, &HotkeyCallback);
3228 EXPECT_EQ(result, INPUT_SUCCESS);
3229 result = OH_Input_RemoveHotkeyMonitor(hotkey, &HotkeyCallback);
3230 EXPECT_EQ(result, INPUT_SUCCESS);
3231 OH_Input_DestroyHotkey(&hotkey);
3232 }
3233
3234 /**
3235 * @tc.name: OHInputManagerTest_OH_Input_RemoveHotkeyMonitor_001
3236 * @tc.desc: Return INPUT_PARAMETER_ERROR when hotkey is null
3237 * @tc.type: FUNC
3238 * @tc.require:
3239 */
3240 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_RemoveHotkeyMonitor_001, TestSize.Level1)
3241 {
3242 Input_Result result = OH_Input_RemoveHotkeyMonitor(nullptr, &HotkeyCallback);
3243 EXPECT_EQ(result, INPUT_PARAMETER_ERROR);
3244 }
3245
3246 /**
3247 * @tc.name: OHInputManagerTest_OH_Input_RemoveHotkeyMonitor_002
3248 * @tc.desc: Return INPUT_PARAMETER_ERROR when callback is null
3249 * @tc.type: FUNC
3250 * @tc.require:
3251 */
3252 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_RemoveHotkeyMonitor_002, TestSize.Level1)
3253 {
3254 Input_Hotkey* hotkey = OH_Input_CreateHotkey();
3255 ASSERT_NE(hotkey, nullptr);
3256 Input_Result result = OH_Input_RemoveHotkeyMonitor(hotkey, nullptr);
3257 EXPECT_EQ(result, INPUT_PARAMETER_ERROR);
3258 OH_Input_DestroyHotkey(&hotkey);
3259 }
3260
3261 /**
3262 * @tc.name: OHInputManagerTest_OH_Input_RemoveHotkeyMonitor_003
3263 * @tc.desc: Return INPUT_PARAMETER_ERROR when MakeHotkeyInfo fails
3264 * @tc.type: FUNC
3265 * @tc.require:
3266 */
3267 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_RemoveHotkeyMonitor_003, TestSize.Level1)
3268 {
3269 Input_Hotkey* hotkey = OH_Input_CreateHotkey();
3270 ASSERT_NE(hotkey, nullptr);
3271 Input_Result result = OH_Input_RemoveHotkeyMonitor(hotkey, &HotkeyCallback);
3272 EXPECT_EQ(result, INPUT_PARAMETER_ERROR);
3273 OH_Input_DestroyHotkey(&hotkey);
3274 }
3275
3276 /**
3277 * @tc.name: OHInputManagerTest_OH_Input_RemoveHotkeyMonitor_004
3278 * @tc.desc: Return INPUT_SERVICE_EXCEPTION when DelEventCallback fails
3279 * @tc.type: FUNC
3280 * @tc.require:
3281 */
3282 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_RemoveHotkeyMonitor_004, TestSize.Level1)
3283 {
3284 Input_Hotkey* hotkey = OH_Input_CreateHotkey();
3285 ASSERT_NE(hotkey, nullptr);
3286 OH_Input_SetFinalKey(hotkey, 123);
3287 OH_Input_SetRepeat(hotkey, true);
3288 Input_Result result = OH_Input_RemoveHotkeyMonitor(hotkey, &HotkeyCallback);
3289 EXPECT_EQ(result, INPUT_PARAMETER_ERROR);
3290 OH_Input_DestroyHotkey(&hotkey);
3291 }
3292
3293 /**
3294 * @tc.name: OHInputManagerTest_OH_Input_RemoveHotkeyMonitor_005
3295 * @tc.desc: Return INPUT_SUCCESS when unregistering a valid registered hotkey
3296 * @tc.type: FUNC
3297 * @tc.require:
3298 */
3299 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_RemoveHotkeyMonitor_005, TestSize.Level1)
3300 {
3301 Input_Hotkey* hotkey = OH_Input_CreateHotkey();
3302 ASSERT_NE(hotkey, nullptr);
3303 int32_t preKeys[] = { KEYCODE_CTRL_LEFT };
3304 OH_Input_SetPreKeys(hotkey, preKeys, sizeof(preKeys) / sizeof(int32_t));
3305 OH_Input_SetFinalKey(hotkey, KEYCODE_TAB);
3306 OH_Input_SetRepeat(hotkey, false);
3307 Input_Result result = OH_Input_AddHotkeyMonitor(hotkey, &HotkeyCallback);
3308 EXPECT_EQ(result, INPUT_SUCCESS);
3309 result = OH_Input_RemoveHotkeyMonitor(hotkey, &HotkeyCallback);
3310 EXPECT_EQ(result, INPUT_SUCCESS);
3311 OH_Input_DestroyHotkey(&hotkey);
3312 }
3313
3314 /**
3315 * @tc.name: OHInputManagerTest_OH_Input_QueryAuthorizedStatus_001
3316 * @tc.desc: Return INPUT_PARAMETER_ERROR when status is null
3317 * @tc.type: FUNC
3318 * @tc.require:
3319 */
3320 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_QueryAuthorizedStatus_001, TestSize.Level1)
3321 {
3322 Input_Result result = OH_Input_QueryAuthorizedStatus(nullptr);
3323 EXPECT_EQ(result, INPUT_PARAMETER_ERROR);
3324 }
3325
3326 /**
3327 * @tc.name: OHInputManagerTest_OH_Input_QueryAuthorizedStatus_002
3328 * @tc.desc: Return success and valid status when service responds correctly
3329 * @tc.type: FUNC
3330 * @tc.require:
3331 */
3332 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_QueryAuthorizedStatus_002, TestSize.Level1)
3333 {
3334 Input_InjectionStatus status = Input_InjectionStatus::UNAUTHORIZED;
3335 Input_Result result = OH_Input_QueryAuthorizedStatus(&status);
3336 EXPECT_EQ(result, INPUT_SUCCESS);
3337 EXPECT_TRUE(status == Input_InjectionStatus::UNAUTHORIZED ||
3338 status == Input_InjectionStatus::AUTHORIZING ||
3339 status == Input_InjectionStatus::AUTHORIZED);
3340 }
3341
3342 /**
3343 * @tc.name: OHInputManagerTest_OH_Input_GetPreKeys_002
3344 * @tc.desc: Return error when hotkey is null
3345 * @tc.type: FUNC
3346 * @tc.require:
3347 */
3348 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetPreKeys_002, TestSize.Level1)
3349 {
3350 CALL_TEST_DEBUG;
3351 int32_t key0 = 0;
3352 int32_t *pressedKeys[1] = {&key0};
3353 int32_t pressedKeyNum = 0;
3354 Input_Result result = OH_Input_GetPreKeys(nullptr, pressedKeys, &pressedKeyNum);
3355 EXPECT_EQ(result, INPUT_PARAMETER_ERROR);
3356 }
3357
3358 /**
3359 * @tc.name: OHInputManagerTest_OH_Input_GetPreKeys_003
3360 * @tc.desc: Return error when preKeys is null
3361 * @tc.type: FUNC
3362 * @tc.require:
3363 */
3364 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetPreKeys_003, TestSize.Level1)
3365 {
3366 CALL_TEST_DEBUG;
3367 Input_Hotkey *hotkey = OH_Input_CreateHotkey();
3368 ASSERT_NE(hotkey, nullptr);
3369 int32_t pressedKeyNum = 0;
3370 Input_Result result = OH_Input_GetPreKeys(hotkey, nullptr, &pressedKeyNum);
3371 EXPECT_EQ(result, INPUT_PARAMETER_ERROR);
3372 OH_Input_DestroyHotkey(&hotkey);
3373 }
3374
3375 /**
3376 * @tc.name: OHInputManagerTest_OH_Input_GetPreKeys_004
3377 * @tc.desc: Return error when *preKeys is null
3378 * @tc.type: FUNC
3379 * @tc.require:
3380 */
3381 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetPreKeys_004, TestSize.Level1)
3382 {
3383 CALL_TEST_DEBUG;
3384 Input_Hotkey *hotkey = OH_Input_CreateHotkey();
3385 ASSERT_NE(hotkey, nullptr);
3386 int32_t *pressedKeys[1] = {nullptr};
3387 int32_t pressedKeyNum = 0;
3388 Input_Result result = OH_Input_GetPreKeys(hotkey, pressedKeys, &pressedKeyNum);
3389 EXPECT_EQ(result, INPUT_PARAMETER_ERROR);
3390 OH_Input_DestroyHotkey(&hotkey);
3391 }
3392
3393 /**
3394 * @tc.name: OHInputManagerTest_OH_Input_GetPreKeys_005
3395 * @tc.desc: Return error when preKeys set is empty
3396 * @tc.type: FUNC
3397 * @tc.require:
3398 */
3399 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetPreKeys_005, TestSize.Level1)
3400 {
3401 CALL_TEST_DEBUG;
3402 Input_Hotkey *hotkey = OH_Input_CreateHotkey();
3403 ASSERT_NE(hotkey, nullptr);
3404 int32_t key = 0;
3405 int32_t *pressedKeys[1] = {&key};
3406 int32_t pressedKeyNum = 0;
3407 Input_Result result = OH_Input_GetPreKeys(hotkey, pressedKeys, &pressedKeyNum);
3408 EXPECT_EQ(result, INPUT_SERVICE_EXCEPTION);
3409 OH_Input_DestroyHotkey(&hotkey);
3410 }
3411
3412 /**
3413 * @tc.name: OHInputManagerTest_OH_Input_GetPreKeys_006
3414 * @tc.desc: Return error when preKeyCount is null
3415 * @tc.type: FUNC
3416 * @tc.require:
3417 */
3418 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetPreKeys_006, TestSize.Level1)
3419 {
3420 CALL_TEST_DEBUG;
3421 Input_Hotkey *hotkey = OH_Input_CreateHotkey();
3422 ASSERT_NE(hotkey, nullptr);
3423 int32_t key0 = 0;
3424 int32_t *pressedKeys[1] = {&key0};
3425 Input_Result result = OH_Input_GetPreKeys(hotkey, pressedKeys, nullptr);
3426 EXPECT_EQ(result, INPUT_PARAMETER_ERROR);
3427 OH_Input_DestroyHotkey(&hotkey);
3428 }
3429
3430 /**
3431 * @tc.name: OHInputManagerTest_OH_Input_SetPreKeys_002
3432 * @tc.desc: Verify that OH_Input_SetPreKeys handles nullptr hotkey
3433 * @tc.type: FUNC
3434 * @tc.require:
3435 */
3436 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_SetPreKeys_002, TestSize.Level1)
3437 {
3438 CALL_TEST_DEBUG;
3439 int32_t prekeys[2] = {KEYCODE_ALT_LEFT, KEYCODE_ALT_RIGHT};
3440 ASSERT_NO_FATAL_FAILURE(OH_Input_SetPreKeys(nullptr, prekeys, 2));
3441 }
3442
3443 /**
3444 * @tc.name: OHInputManagerTest_OH_Input_SetPreKeys_003
3445 * @tc.desc: Verify that OH_Input_SetPreKeys handles nullptr preKeys
3446 * @tc.type: FUNC
3447 * @tc.require:
3448 */
3449 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_SetPreKeys_003, TestSize.Level1)
3450 {
3451 CALL_TEST_DEBUG;
3452 Input_Hotkey *hotkey = OH_Input_CreateHotkey();
3453 ASSERT_NE(hotkey, nullptr);
3454 ASSERT_NO_FATAL_FAILURE(OH_Input_SetPreKeys(hotkey, nullptr, 2));
3455 int32_t key = -1;
3456 int32_t *pressedKeys[1] = {&key};
3457 int32_t count = 0;
3458 Input_Result ret = OH_Input_GetPreKeys(hotkey, pressedKeys, &count);
3459 EXPECT_NE(ret, INPUT_SUCCESS);
3460 OH_Input_DestroyHotkey(&hotkey);
3461 }
3462
3463 /**
3464 * @tc.name: OHInputManagerTest_OH_Input_SetPreKeys_004
3465 * @tc.desc: Verify that OH_Input_SetPreKeys ignores size <= 0
3466 * @tc.type: FUNC
3467 * @tc.require:
3468 */
3469 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_SetPreKeys_004, TestSize.Level1)
3470 {
3471 CALL_TEST_DEBUG;
3472 Input_Hotkey *hotkey = OH_Input_CreateHotkey();
3473 ASSERT_NE(hotkey, nullptr);
3474 int32_t prekeys[2] = {KEYCODE_ALT_LEFT, KEYCODE_ALT_RIGHT};
3475 ASSERT_NO_FATAL_FAILURE(OH_Input_SetPreKeys(hotkey, prekeys, 0));
3476 int32_t key = -1;
3477 int32_t *pressedKeys[1] = {&key};
3478 int32_t count = 0;
3479 Input_Result ret = OH_Input_GetPreKeys(hotkey, pressedKeys, &count);
3480 EXPECT_NE(ret, INPUT_SUCCESS);
3481 OH_Input_DestroyHotkey(&hotkey);
3482 }
3483
3484 /**
3485 * @tc.name: OHInputManagerTest_OH_Input_GetAllSystemHotkeys_002
3486 * @tc.desc: Verify OH_Input_GetAllSystemHotkeys returns error when count is null
3487 * @tc.type: FUNC
3488 * @tc.require:
3489 */
3490 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetAllSystemHotkeys_002, TestSize.Level1)
3491 {
3492 CALL_TEST_DEBUG;
3493 Input_Hotkey **hotkey = nullptr;
3494 Input_Result ret = OH_Input_GetAllSystemHotkeys(hotkey, nullptr);
3495 EXPECT_EQ(ret, INPUT_PARAMETER_ERROR);
3496 }
3497
3498 /**
3499 * @tc.name: OHInputManagerTest_OH_Input_GetAllSystemHotkeys_003
3500 * @tc.desc: Test the function OH_Input_GetAllSystemHotkeys with valid parameters
3501 * @tc.type: FUNC
3502 * @tc.require:
3503 */
3504 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetAllSystemHotkeys_003, TestSize.Level1)
3505 {
3506 CALL_TEST_DEBUG;
3507 int32_t count = 0;
3508 Input_Result ret = OH_Input_GetAllSystemHotkeys(nullptr, &count);
3509 ASSERT_EQ(ret, INPUT_SUCCESS);
3510 ASSERT_GT(count, 0);
3511 Input_Hotkey **hotkey = OH_Input_CreateAllSystemHotkeys(count);
3512 ASSERT_NE(hotkey, nullptr);
3513 ret = OH_Input_GetAllSystemHotkeys(hotkey, &count);
3514 EXPECT_EQ(ret, INPUT_SUCCESS);
3515 for (int i = 0; i < count; ++i) {
3516 ASSERT_NE(hotkey[i], nullptr);
3517 }
3518
3519 // Step 5: Destroy hotkeys
3520 OH_Input_DestroyAllSystemHotkeys(hotkey, count);
3521 }
3522
3523 /**
3524 * @tc.name: OHInputManagerTest_OH_Input_CreateAllSystemHotkeys_002
3525 * @tc.desc: Test OH_Input_CreateAllSystemHotkeys with count not matching actual hotkeyCount
3526 * @tc.type: FUNC
3527 * @tc.require:
3528 */
3529 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_CreateAllSystemHotkeys_002, TestSize.Level1)
3530 {
3531 CALL_TEST_DEBUG;
3532 int32_t count = 1000;
3533 auto ret = OH_Input_CreateAllSystemHotkeys(count);
3534 EXPECT_EQ(ret, nullptr);
3535 }
3536
3537 /**
3538 * @tc.name: OHInputManagerTest_OH_Input_CreateAllSystemHotkeys_003
3539 * @tc.desc: Test OH_Input_CreateAllSystemHotkeys with correct count returned by GetAllSystemHotkeys
3540 * @tc.type: FUNC
3541 * @tc.require:
3542 */
3543 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_CreateAllSystemHotkeys_003, TestSize.Level1)
3544 {
3545 CALL_TEST_DEBUG;
3546 int32_t count = 0;
3547 Input_Result ret = OH_Input_GetAllSystemHotkeys(nullptr, &count);
3548 ASSERT_EQ(ret, INPUT_SUCCESS);
3549 ASSERT_GT(count, 0);
3550 Input_Hotkey **hotkeys = OH_Input_CreateAllSystemHotkeys(count);
3551 ASSERT_NE(hotkeys, nullptr);
3552 for (int i = 0; i < count; ++i) {
3553 ASSERT_NE(hotkeys[i], nullptr);
3554 }
3555 OH_Input_DestroyAllSystemHotkeys(hotkeys, count);
3556 }
3557
3558 /**
3559 * @tc.name: OHInputManagerTest_OH_Input_GetIntervalSinceLastInput_002
3560 * @tc.desc: Verify OH_Input_GetIntervalSinceLastInput returns correct interval time
3561 * @tc.type: FUNC
3562 * @tc.require:
3563 */
3564 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_GetIntervalSinceLastInput_002, TestSize.Level3)
3565 {
3566 CALL_TEST_DEBUG;
3567 int64_t interval = -1;
3568 int32_t result = OH_Input_GetIntervalSinceLastInput(&interval);
3569 EXPECT_EQ(result, INPUT_SUCCESS);
3570 EXPECT_GE(interval, 0);
3571 }
3572
3573 /**
3574 * @tc.name: OHInputManagerTest_OH_Input_RemoveAxisEventMonitorForAll_001
3575 * @tc.desc: Test RemoveAxisEventMonitorForAll with nullptr callback
3576 * @tc.type: FUNC
3577 * @tc.require:
3578 */
3579 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_RemoveAxisEventMonitorForAll_001, TestSize.Level3)
3580 {
3581 CALL_TEST_DEBUG;
3582 Input_Result result = OH_Input_RemoveAxisEventMonitorForAll(nullptr);
3583 EXPECT_EQ(result, INPUT_PARAMETER_ERROR);
3584 }
3585
3586 /**
3587 * @tc.name: OHInputManagerTest_OH_Input_RemoveAxisEventMonitorForAll_002
3588 * @tc.desc: Test RemoveAxisEventMonitorForAll with callback not registered
3589 * @tc.type: FUNC
3590 * @tc.require:
3591 */
3592 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_RemoveAxisEventMonitorForAll_002, TestSize.Level3)
3593 {
3594 CALL_TEST_DEBUG;
__anonaa5665ab1402(const Input_AxisEvent* event) 3595 auto dummyCallback = [](const Input_AxisEvent* event) {};
3596 Input_Result result = OH_Input_RemoveAxisEventMonitorForAll(dummyCallback);
3597 EXPECT_EQ(result, INPUT_PARAMETER_ERROR);
3598 }
3599
3600 /**
3601 * @tc.name: OHInputManagerTest_OH_Input_RemoveAxisEventMonitorForAll_003
3602 * @tc.desc: Test RemoveAxisEventMonitorForAll with valid registered callback
3603 * @tc.type: FUNC
3604 * @tc.require:
3605 */
3606 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_RemoveAxisEventMonitorForAll_003, TestSize.Level3)
3607 {
3608 CALL_TEST_DEBUG;
__anonaa5665ab1502(const Input_AxisEvent* event) 3609 auto callback = [](const Input_AxisEvent* event) {};
3610 Input_Result addResult = OH_Input_AddAxisEventMonitorForAll(callback);
3611 EXPECT_EQ(addResult, INPUT_SUCCESS);
3612 Input_Result removeResult = OH_Input_RemoveAxisEventMonitorForAll(callback);
3613 EXPECT_EQ(removeResult, INPUT_SUCCESS);
3614 }
3615
3616 /**
3617 * @tc.name: OHInputManagerTest_OH_Input_RemoveTouchEventMonitor_001
3618 * @tc.desc: Test RemoveTouchEventMonitor with nullptr callback
3619 * @tc.type: FUNC
3620 * @tc.require:
3621 */
3622 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_RemoveTouchEventMonitor_001, TestSize.Level3)
3623 {
3624 CALL_TEST_DEBUG;
3625 Input_Result result = OH_Input_RemoveTouchEventMonitor(nullptr);
3626 EXPECT_EQ(result, INPUT_PARAMETER_ERROR);
3627 }
3628
3629 /**
3630 * @tc.name: OHInputManagerTest_OH_Input_RemoveTouchEventMonitor_002
3631 * @tc.desc: Test RemoveTouchEventMonitor with callback not registered
3632 * @tc.type: FUNC
3633 * @tc.require:
3634 */
3635 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_RemoveTouchEventMonitor_002, TestSize.Level3)
3636 {
3637 CALL_TEST_DEBUG;
__anonaa5665ab1602(const Input_TouchEvent* event) 3638 auto dummyCallback = [](const Input_TouchEvent* event) {};
3639 Input_Result result = OH_Input_RemoveTouchEventMonitor(dummyCallback);
3640 EXPECT_EQ(result, INPUT_PARAMETER_ERROR);
3641 }
3642
3643 /**
3644 * @tc.name: OHInputManagerTest_OH_Input_RemoveTouchEventMonitor_003
3645 * @tc.desc: Test RemoveTouchEventMonitor after adding callback
3646 * @tc.type: FUNC
3647 * @tc.require:
3648 */
3649 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_RemoveTouchEventMonitor_003, TestSize.Level3)
3650 {
3651 CALL_TEST_DEBUG;
__anonaa5665ab1702(const Input_TouchEvent* event) 3652 auto callback = [](const Input_TouchEvent* event) {};
3653 Input_Result addResult = OH_Input_AddTouchEventMonitor(callback);
3654 EXPECT_EQ(addResult, INPUT_SUCCESS);
3655 Input_Result removeResult = OH_Input_RemoveTouchEventMonitor(callback);
3656 EXPECT_EQ(removeResult, INPUT_SUCCESS);
3657 }
3658
3659 /**
3660 * @tc.name: OHInputManagerTest_OH_Input_RemoveMouseEventMonitor_001
3661 * @tc.desc: Test RemoveMouseEventMonitor with nullptr callback
3662 * @tc.type: FUNC
3663 * @tc.require:
3664 */
3665 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_RemoveMouseEventMonitor_001, TestSize.Level3)
3666 {
3667 CALL_TEST_DEBUG;
3668 Input_Result result = OH_Input_RemoveMouseEventMonitor(nullptr);
3669 EXPECT_EQ(result, INPUT_PARAMETER_ERROR);
3670 }
3671
3672 /**
3673 * @tc.name: OHInputManagerTest_OH_Input_RemoveMouseEventMonitor_002
3674 * @tc.desc: Test RemoveMouseEventMonitor with callback not registered
3675 * @tc.type: FUNC
3676 * @tc.require:
3677 */
3678 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_RemoveMouseEventMonitor_002, TestSize.Level3)
3679 {
3680 CALL_TEST_DEBUG;
__anonaa5665ab1802(const Input_MouseEvent *event) 3681 auto dummyCallback = [](const Input_MouseEvent *event) {
3682 (void)event;
3683 };
3684 Input_Result result = OH_Input_RemoveMouseEventMonitor(dummyCallback);
3685 EXPECT_EQ(result, INPUT_PARAMETER_ERROR);
3686 }
3687
3688 /**
3689 * @tc.name: OHInputManagerTest_OH_Input_RemoveMouseEventMonitor_003
3690 * @tc.desc: Test RemoveMouseEventMonitor after adding a callback
3691 * @tc.type: FUNC
3692 * @tc.require:
3693 */
3694 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_RemoveMouseEventMonitor_003, TestSize.Level3)
3695 {
3696 CALL_TEST_DEBUG;
__anonaa5665ab1902(const Input_MouseEvent *event) 3697 auto mouseCallback = [](const Input_MouseEvent *event) {
3698 (void)event;
3699 };
3700 Input_Result addResult = OH_Input_AddMouseEventMonitor(mouseCallback);
3701 EXPECT_EQ(addResult, INPUT_SUCCESS);
3702 Input_Result removeResult = OH_Input_RemoveMouseEventMonitor(mouseCallback);
3703 EXPECT_EQ(removeResult, INPUT_SUCCESS);
3704 }
3705
3706 /**
3707 * @tc.name: OHInputManagerTest_OH_Input_RemoveKeyEventMonitor_001
3708 * @tc.desc: Test RemoveKeyEventMonitor with nullptr callback
3709 * @tc.type: FUNC
3710 * @tc.require:
3711 */
3712 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_RemoveKeyEventMonitor_001, TestSize.Level1)
3713 {
3714 CALL_TEST_DEBUG;
3715 Input_Result result = OH_Input_RemoveKeyEventMonitor(nullptr);
3716 EXPECT_EQ(result, INPUT_PARAMETER_ERROR);
3717 }
3718
3719 /**
3720 * @tc.name: OHInputManagerTest_OH_Input_RemoveKeyEventMonitor_002
3721 * @tc.desc: Test RemoveKeyEventMonitor with unregistered callback
3722 * @tc.type: FUNC
3723 * @tc.require:
3724 */
3725 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_RemoveKeyEventMonitor_002, TestSize.Level1)
3726 {
3727 CALL_TEST_DEBUG;
__anonaa5665ab1a02(const Input_KeyEvent *event) 3728 auto dummyCallback = [](const Input_KeyEvent *event) {
3729 (void)event;
3730 };
3731 Input_Result result = OH_Input_RemoveKeyEventMonitor(dummyCallback);
3732 EXPECT_EQ(result, INPUT_PARAMETER_ERROR);
3733 }
3734
3735 /**
3736 * @tc.name: OHInputManagerTest_OH_Input_RemoveKeyEventMonitor_003
3737 * @tc.desc: Test RemoveKeyEventMonitor after adding a callback
3738 * @tc.type: FUNC
3739 * @tc.require:
3740 */
3741 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_RemoveKeyEventMonitor_003, TestSize.Level1)
3742 {
3743 CALL_TEST_DEBUG;
__anonaa5665ab1b02(const Input_KeyEvent *event) 3744 auto keyCallback = [](const Input_KeyEvent *event) {
3745 (void)event;
3746 };
3747 Input_Result addResult = OH_Input_AddKeyEventMonitor(keyCallback);
3748 EXPECT_EQ(addResult, INPUT_SUCCESS);
3749 Input_Result removeResult = OH_Input_RemoveKeyEventMonitor(keyCallback);
3750 EXPECT_EQ(removeResult, INPUT_SUCCESS);
3751 }
3752
3753 /**
3754 * @tc.name: OHInputManagerTest_OH_Input_AddAxisEventMonitor_002
3755 * @tc.desc: Test AddAxisEventMonitor with valid callback
3756 * @tc.type: FUNC
3757 * @tc.require:
3758 */
3759 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_AddAxisEventMonitor_002, TestSize.Level1)
3760 {
3761 CALL_TEST_DEBUG;
3762 InputEvent_AxisEventType type = InputEvent_AxisEventType::AXIS_EVENT_TYPE_PINCH;
__anonaa5665ab1c02(const Input_AxisEvent *axisEvent) 3763 auto callback = [](const Input_AxisEvent *axisEvent) {
3764 (void)axisEvent;
3765 };
3766 Input_Result result = OH_Input_AddAxisEventMonitor(type, callback);
3767 EXPECT_EQ(result, INPUT_SUCCESS);
3768 }
3769
3770 /**
3771 * @tc.name: OHInputManagerTest_OH_Input_AddAxisEventMonitor_003
3772 * @tc.desc: Test AddAxisEventMonitor with same type and callback multiple times
3773 * @tc.type: FUNC
3774 * @tc.require:
3775 */
3776 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_AddAxisEventMonitor_003, TestSize.Level1)
3777 {
3778 CALL_TEST_DEBUG;
3779 InputEvent_AxisEventType type = InputEvent_AxisEventType::AXIS_EVENT_TYPE_SCROLL;
__anonaa5665ab1d02(const Input_AxisEvent *axisEvent) 3780 auto callback = [](const Input_AxisEvent *axisEvent) {
3781 (void)axisEvent;
3782 };
3783 Input_Result result1 = OH_Input_AddAxisEventMonitor(type, callback);
3784 EXPECT_EQ(result1, INPUT_SUCCESS);
3785 Input_Result result2 = OH_Input_AddAxisEventMonitor(type, callback);
3786 EXPECT_EQ(result2, INPUT_SUCCESS);
3787 }
3788
3789 /**
3790 * @tc.name: OHInputManagerTest_OH_Input_AddAxisEventMonitorForAll_001
3791 * @tc.desc: Test AddAxisEventMonitorForAll with nullptr callback
3792 * @tc.type: FUNC
3793 * @tc.require:
3794 */
3795 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_AddAxisEventMonitorForAll_001, TestSize.Level1)
3796 {
3797 CALL_TEST_DEBUG;
3798 EXPECT_EQ(OH_Input_AddAxisEventMonitorForAll(nullptr), INPUT_PARAMETER_ERROR);
3799 }
3800
3801 /**
3802 * @tc.name: OHInputManagerTest_OH_Input_AddAxisEventMonitorForAll_002
3803 * @tc.desc: Test AddAxisEventMonitorForAll with valid callback
3804 * @tc.type: FUNC
3805 * @tc.require:
3806 */
3807 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_AddAxisEventMonitorForAll_002, TestSize.Level1)
3808 {
3809 CALL_TEST_DEBUG;
__anonaa5665ab1e02(const Input_AxisEvent *axisEvent) 3810 auto callback = [](const Input_AxisEvent *axisEvent) {
3811 (void)axisEvent;
3812 };
3813 Input_Result result = OH_Input_AddAxisEventMonitorForAll(callback);
3814 EXPECT_EQ(result, INPUT_SUCCESS);
3815 }
3816
3817 /**
3818 * @tc.name: OHInputManagerTest_OH_Input_AddAxisEventMonitorForAll_003
3819 * @tc.desc: Test AddAxisEventMonitorForAll with same callback multiple times
3820 * @tc.type: FUNC
3821 * @tc.require:
3822 */
3823 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_AddAxisEventMonitorForAll_003, TestSize.Level1)
3824 {
3825 CALL_TEST_DEBUG;
__anonaa5665ab1f02(const Input_AxisEvent *axisEvent) 3826 auto callback = [](const Input_AxisEvent *axisEvent) {
3827 (void)axisEvent;
3828 };
3829 Input_Result firstResult = OH_Input_AddAxisEventMonitorForAll(callback);
3830 EXPECT_EQ(firstResult, INPUT_SUCCESS);
3831 Input_Result secondResult = OH_Input_AddAxisEventMonitorForAll(callback);
3832 EXPECT_EQ(secondResult, INPUT_SUCCESS);
3833 }
3834
3835 /**
3836 * @tc.name: OHInputManagerTest_OH_Input_AddTouchEventMonitor_001
3837 * @tc.desc: Test AddTouchEventMonitor with nullptr callback
3838 * @tc.type: FUNC
3839 * @tc.require:
3840 */
3841 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_AddTouchEventMonitor_001, TestSize.Level1)
3842 {
3843 CALL_TEST_DEBUG;
3844 EXPECT_EQ(OH_Input_AddTouchEventMonitor(nullptr), INPUT_PARAMETER_ERROR);
3845 }
3846
3847 /**
3848 * @tc.name: OHInputManagerTest_OH_Input_AddTouchEventMonitor_002
3849 * @tc.desc: Test AddTouchEventMonitor with valid callback
3850 * @tc.type: FUNC
3851 * @tc.require:
3852 */
3853 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_AddTouchEventMonitor_002, TestSize.Level1)
3854 {
3855 CALL_TEST_DEBUG;
__anonaa5665ab2002(const Input_TouchEvent *touchEvent) 3856 auto callback = [](const Input_TouchEvent *touchEvent) {
3857 (void)touchEvent;
3858 };
3859 Input_Result result = OH_Input_AddTouchEventMonitor(callback);
3860 EXPECT_EQ(result, INPUT_SUCCESS);
3861 }
3862
3863 /**
3864 * @tc.name: OHInputManagerTest_OH_Input_AddTouchEventMonitor_003
3865 * @tc.desc: Test AddTouchEventMonitor with same callback multiple times
3866 * @tc.type: FUNC
3867 * @tc.require:
3868 */
3869 HWTEST_F(OHInputManagerTest, OHInputManagerTest_OH_Input_AddTouchEventMonitor_003, TestSize.Level1)
3870 {
3871 CALL_TEST_DEBUG;
__anonaa5665ab2102(const Input_TouchEvent *touchEvent) 3872 auto callback = [](const Input_TouchEvent *touchEvent) {
3873 (void)touchEvent;
3874 };
3875 Input_Result firstResult = OH_Input_AddTouchEventMonitor(callback);
3876 EXPECT_EQ(firstResult, INPUT_SUCCESS);
3877 Input_Result secondResult = OH_Input_AddTouchEventMonitor(callback);
3878 EXPECT_EQ(secondResult, INPUT_SUCCESS);
3879 }
3880 } // namespace MMI
3881 } // namespace OHOS