• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gtest/gtest.h>
17 #include <gmock/gmock.h>
18 
19 #include "define_multimodal.h"
20 #include "error_multimodal.h"
21 #include "input_scene_board_judgement.h"
22 #include "input_manager_impl.h"
23 #include "multimodal_event_handler.h"
24 #include "multimodal_input_connect_manager.h"
25 #include "net_packet.h"
26 
27 #undef MMI_LOG_TAG
28 #define MMI_LOG_TAG "InputManagerImplTest"
29 
30 namespace OHOS {
31 namespace MMI {
32 namespace {
33 constexpr uint32_t MAX_WINDOW_SIZE = 1000;
34 constexpr size_t MAX_FILTER_NUM { 4 };
35 using namespace testing::ext;
36 } // namespace
37 
38 struct InputEventFilterMock : public IInputEventFilter {
39 public:
40     InputEventFilterMock() = default;
41     virtual ~InputEventFilterMock() = default;
OnInputEventOHOS::MMI::InputEventFilterMock42     bool OnInputEvent(std::shared_ptr<KeyEvent> keyEvent) const
43     {
44         return true;
45     }
OnInputEventOHOS::MMI::InputEventFilterMock46     bool OnInputEvent(std::shared_ptr<PointerEvent> pointerEvent) const
47     {
48         return true;
49     }
50 };
51 
52 class InputManagerImplTest : public testing::Test {
53 public:
SetUpTestCase(void)54     static void SetUpTestCase(void) {}
TearDownTestCase(void)55     static void TearDownTestCase(void) {}
56 };
57 
58 class TestInputEventConsumer : public IInputEventConsumer {
59 public:
60     TestInputEventConsumer() = default;
61     ~TestInputEventConsumer() = default;
OnInputEvent(std::shared_ptr<KeyEvent> keyEvent) const62     void OnInputEvent(std::shared_ptr<KeyEvent> keyEvent) const override
63     {
64         MMI_HILOGI("OnInputEvent KeyEvent enter");
65     }
OnInputEvent(std::shared_ptr<PointerEvent> pointerEvent) const66     void OnInputEvent(std::shared_ptr<PointerEvent> pointerEvent) const override
67     {
68         MMI_HILOGI("OnInputEvent PointerEvent enter");
69     }
OnInputEvent(std::shared_ptr<AxisEvent> axisEvent) const70     void OnInputEvent(std::shared_ptr<AxisEvent> axisEvent) const override
71     {}
72 };
73 
74 /**
75  * @tc.name: InputManagerImplTest_IsValiadWindowAreas
76  * @tc.desc: Test IsValiadWindowAreas
77  * @tc.type: FUNC
78  * @tc.require:
79  */
80 HWTEST_F(InputManagerImplTest, InputManagerImplTest_IsValiadWindowAreas, TestSize.Level1)
81 {
82     CALL_TEST_DEBUG;
83     WindowInfo windowInfo;
84     windowInfo.action = WINDOW_UPDATE_ACTION::UNKNOWN;
85     Rect rect;
86     rect.x = 100;
87     windowInfo.defaultHotAreas.push_back(rect);
88     windowInfo.pointerHotAreas.push_back(rect);
89     windowInfo.pointerChangeAreas.push_back(100);
90     windowInfo.transform.push_back(100.5);
91     std::vector<WindowInfo> windows;
92     windows.push_back(windowInfo);
93     EXPECT_FALSE(InputMgrImpl.IsValiadWindowAreas(windows));
94 
95     windows[0].pointerChangeAreas.clear();
96     EXPECT_FALSE(InputMgrImpl.IsValiadWindowAreas(windows));
97 }
98 
99 /**
100  * @tc.name: InputManagerImplTest_PrintWindowInfo
101  * @tc.desc: Test PrintWindowInfo
102  * @tc.type: FUNC
103  * @tc.require:
104  */
105 HWTEST_F(InputManagerImplTest, InputManagerImplTest_PrintWindowInfo, TestSize.Level2)
106 {
107     CALL_TEST_DEBUG;
108     WindowInfo windowInfo;
109     windowInfo.action = WINDOW_UPDATE_ACTION::UNKNOWN;
110     Rect rect {
111         .x = 100,
112         .y = 100,
113         .width = 300,
114         .height = 300,
115     };
116     windowInfo.id = 10;
117     windowInfo.pid = 1000;
118     windowInfo.uid = 100;
119     windowInfo.area.x = 100;
120     windowInfo.area.y = 100;
121     windowInfo.area.height = 200;
122     windowInfo.area.width = 200;
123     windowInfo.agentWindowId = 50;
124     windowInfo.flags = 0;
125     windowInfo.displayId = 30;
126     windowInfo.zOrder = 60;
127     windowInfo.defaultHotAreas.push_back(rect);
128     windowInfo.pointerHotAreas.push_back(rect);
129     windowInfo.pointerChangeAreas.push_back(100);
130     windowInfo.transform.push_back(100.5);
131     std::vector<WindowInfo> windows;
132     windows.push_back(windowInfo);
133     EXPECT_NO_FATAL_FAILURE(InputMgrImpl.PrintWindowInfo(windows));
134 }
135 
136 /**
137  * @tc.name: InputManagerImplTest_OnDisconnected_01
138  * @tc.desc: Test OnDisconnected
139  * @tc.type: FUNC
140  * @tc.require:
141  */
142 HWTEST_F(InputManagerImplTest, InputManagerImplTest_OnDisconnected_01, TestSize.Level1)
143 {
144     CALL_TEST_DEBUG;
145     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
146     ASSERT_NE(pointerEvent, nullptr);
147     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_UP;
148 
149     EXPECT_NO_FATAL_FAILURE(InputMgrImpl.OnDisconnected());
150 }
151 
152 /**
153  * @tc.name: InputManagerImplTest_OnDisconnected_02
154  * @tc.desc: Test OnDisconnected
155  * @tc.type: FUNC
156  * @tc.require:
157  */
158 HWTEST_F(InputManagerImplTest, InputManagerImplTest_OnDisconnected_02, TestSize.Level1)
159 {
160     CALL_TEST_DEBUG;
161     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
162     ASSERT_NE(pointerEvent, nullptr);
163     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_UP;
164 
165     EXPECT_NO_FATAL_FAILURE(InputMgrImpl.OnDisconnected());
166 }
167 
168 /**
169  * @tc.name: InputManagerImplTest_OnKeyEvent_01
170  * @tc.desc: Test OnKeyEvent
171  * @tc.type: FUNC
172  * @tc.require:
173  */
174 HWTEST_F(InputManagerImplTest, InputManagerImplTest_OnKeyEvent_01, TestSize.Level1)
175 {
176     CALL_TEST_DEBUG;
177     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
178     ASSERT_NE(keyEvent, nullptr);
179 
180     MMIClientPtr client = MMIEventHdl.GetMMIClient();
181     EXPECT_NO_FATAL_FAILURE(InputMgrImpl.OnKeyEvent(keyEvent));
182 }
183 
184 /**
185  * @tc.name: InputManagerImplTest_IsValiadWindowAreas_01
186  * @tc.desc: Test IsValiadWindowAreas
187  * @tc.type: FUNC
188  * @tc.require:
189  */
190 HWTEST_F(InputManagerImplTest, InputManagerImplTest_IsValiadWindowAreas_01, TestSize.Level3)
191 {
192     CALL_TEST_DEBUG;
193     std::vector<WindowInfo> windows;
194     WindowInfo window;
195     window.action = WINDOW_UPDATE_ACTION::DEL;
196 
197     bool ret = InputMgrImpl.IsValiadWindowAreas(windows);
198     EXPECT_TRUE(ret);
199 }
200 
201 /**
202  * @tc.name: InputManagerImplTest_IsValiadWindowAreas_02
203  * @tc.desc: Test IsValiadWindowAreas
204  * @tc.type: FUNC
205  * @tc.require:
206  */
207 HWTEST_F(InputManagerImplTest, InputManagerImplTest_IsValiadWindowAreas_02, TestSize.Level1)
208 {
209     CALL_TEST_DEBUG;
210     std::vector<WindowInfo> windows;
211     WindowInfo window;
212     window.action = WINDOW_UPDATE_ACTION::CHANGE;
213 
214     bool ret = InputMgrImpl.IsValiadWindowAreas(windows);
215     EXPECT_TRUE(ret);
216 }
217 
218 /**
219  * @tc.name: InputManagerImplTest_SubscribeLongPressEvent
220  * @tc.desc: Test SubscribeLongPressEvent
221  * @tc.type: FUNC
222  * @tc.require:
223  */
224 HWTEST_F(InputManagerImplTest, InputManagerImplTest_SubscribeLongPressEvent, TestSize.Level1)
225 {
226     CALL_TEST_DEBUG;
227     LongPressRequest longPR;
228     longPR.fingerCount = 3;
229     longPR.duration = 2;
230     int32_t ret = InputMgrImpl.SubscribeLongPressEvent(longPR, nullptr);
231     ASSERT_EQ(ret, RET_ERR);
232 }
233 
234 /**
235  * @tc.name: InputManagerImplTest_UnsubscribeLongPressEvent
236  * @tc.desc: Test UnsubscribeLongPressEvent
237  * @tc.type: FUNC
238  * @tc.require:
239  */
240 HWTEST_F(InputManagerImplTest, InputManagerImplTest_UnsubscribeLongPressEvent, TestSize.Level1)
241 {
242     CALL_TEST_DEBUG;
243     int32_t subscriberId = 0;
244     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.UnsubscribeLongPressEvent(subscriberId));
245 }
246 
247 /**
248  * @tc.name  : ConvertToCapiKeyAction_ShouldReturnInvalidValue_WhenKeyActionIsInvalid
249  * @tc.desc  : Test ConvertToCapiKeyAction function when keyAction is invalid.
250  * @tc.type: FUNC
251  * @tc.require:
252  */
253 
254 HWTEST_F(InputManagerImplTest, ConvertToCapiKeyAction_ShouldReturnInvalidValue_WhenKeyActionIsInvalid, TestSize.Level1)
255 {
256     CALL_TEST_DEBUG;
257     int32_t keyAction = -1;
258     int32_t expected = -1;
259     int32_t result = InputMgrImpl.ConvertToCapiKeyAction(keyAction);
260     EXPECT_EQ(result, expected);
261 }
262 /**
263  * @tc.name  : OnWindowStateError_WhenWindowStateCallbackIsNull
264  * @tc.desc  : OnWindowState Error Should Not Call Window State Callback When Window State Callback Is Null
265  * @tc.type: FUNC
266  * @tc.require:
267  */
268 HWTEST_F(InputManagerImplTest, OnWindowStateError_WhenWindowStateCallbackIsNull, TestSize.Level1)
269 {
270     CALL_TEST_DEBUG;
271     int32_t pid = 123;
272     int32_t windowId = 456;
273     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.OnWindowStateError(pid, windowId));
274 }
275 
276 
277 /**
278  * @tc.name  : SetCurrentUser_Test_001
279  * @tc.desc  : Test SetCurrentUser function when userId is less than 0.
280  * @tc.type: FUNC
281  * @tc.require:
282  */
283 HWTEST_F(InputManagerImplTest, SetCurrentUser_Test_001, TestSize.Level1)
284 {
285     CALL_TEST_DEBUG;
286     int32_t userId = -1;
287     int32_t ret = InputMgrImpl.SetCurrentUser(userId);
288     EXPECT_EQ(ret, RET_ERR);
289 }
290 
291 /**
292  * @tc.name  : SetPixelMapData_InvalidInput_Test
293  * @tc.desc  : Test SetPixelMapData function with invalid input.
294  * @tc.type: FUNC
295  * @tc.require:
296  */
297 HWTEST_F(InputManagerImplTest, SetPixelMapData_InvalidInput_Test, TestSize.Level1)
298 {
299     CALL_TEST_DEBUG;
300     int32_t infoId = -1;
301     int32_t ret = InputMgrImpl.SetPixelMapData(infoId, nullptr);
302     EXPECT_EQ(ret, RET_ERR);
303 }
304 
305 /**
306  * @tc.name  : CancelInjection_Success
307  * @tc.desc  : Test CancelInjection function when CancelInjection is successful.
308  * @tc.type: FUNC
309  * @tc.require:
310   */
311 HWTEST_F(InputManagerImplTest, CancelInjection_Success, TestSize.Level1)
312 {
313     CALL_TEST_DEBUG;
314     int32_t result = InputMgrImpl.CancelInjection();
315     EXPECT_EQ(result, RET_OK);
316 }
317 
318 /**
319  * @tc.name  : GetKeyState_ReturnsOk_WhenInputValid
320  * @tc.desc  : Test GetKeyState function when input is valid.
321  * @tc.type: FUNC
322  * @tc.require:
323  */
324 HWTEST_F(InputManagerImplTest, GetKeyState_ReturnsOk_WhenInputValid, TestSize.Level1)
325 {
326     CALL_TEST_DEBUG;
327     std::vector<int32_t> pressedKeys = {1, 2, 3};
328     std::map<int32_t, int32_t> specialKeysState = {{1, 1}, {2, 2}, {3, 3}};
329     int32_t result = InputMgrImpl.GetKeyState(pressedKeys, specialKeysState);
330     EXPECT_EQ(result, RET_OK);
331 }
332 
333 
334 /**
335  * @tc.name  : ReAddInputEventFilter_Test_001
336  * @tc.desc  : Test when eventFilterServices_ size is greater than MAX_FILTER_NUM, ReAddInputEventFilter should return
337  * @tc.type: FUNC
338  * @tc.require:
339  */
340 HWTEST_F(InputManagerImplTest, ReAddInputEventFilter_Test_001, TestSize.Level1)
341 {
342     CALL_TEST_DEBUG;
343     InputMgrImpl.eventFilterServices_.insert(std::make_pair(1, std::make_tuple(nullptr, 1, 1)));
344     InputMgrImpl.eventFilterServices_.insert(std::make_pair(2, std::make_tuple(nullptr, 2, 2)));
345     InputMgrImpl.eventFilterServices_.insert(std::make_pair(3, std::make_tuple(nullptr, 3, 3)));
346     InputMgrImpl.eventFilterServices_.insert(std::make_pair(4, std::make_tuple(nullptr, 4, 4)));
347     InputMgrImpl.eventFilterServices_.insert(std::make_pair(5, std::make_tuple(nullptr, 5, 5)));
348     InputMgrImpl.ReAddInputEventFilter();
349     ASSERT_EQ(InputMgrImpl.eventFilterServices_.size(), 5);
350 }
351 
352 
353 /**
354  * @tc.name  : SetPointerStyle_InvalidParam_Test
355  * @tc.desc  : Test SetPointerStyle function with invalid parameter.
356  * @tc.type: FUNC
357  * @tc.require:
358  */
359 HWTEST_F(InputManagerImplTest, SetPointerStyle_InvalidParam_Test, TestSize.Level1)
360 {
361     CALL_TEST_DEBUG;
362     PointerStyle pointerStyle;
363     pointerStyle.id = -1;
364     int32_t windowId = 1;
365     bool isUiExtension = false;
366     int32_t ret = InputMgrImpl.SetPointerStyle(windowId, pointerStyle, isUiExtension);
367     EXPECT_EQ(ret, RET_ERR);
368 }
369 
370 /**
371  * @tc.name  : SetMouseHotSpot_Test001
372  * @tc.desc  : Test SetMouseHotSpot function when windowId is invalid.
373  * @tc.type: FUNC
374  * @tc.require:
375  */
376 HWTEST_F(InputManagerImplTest, SetMouseHotSpot_Test001, TestSize.Level1)
377 {
378     CALL_TEST_DEBUG;
379     int32_t windowId = -1;
380     int32_t hotSpotX = 100;
381     int32_t hotSpotY = 200;
382     int32_t ret = InputMgrImpl.SetMouseHotSpot(windowId, hotSpotX, hotSpotY);
383     EXPECT_EQ(ret, RET_ERR);
384 }
385 
386 /**
387  * @tc.name  : AddInputEventFilter_Test001
388  * @tc.desc  : Test AddInputEventFilter
389  * @tc.type: FUNC
390  * @tc.require:
391  */
392 HWTEST_F(InputManagerImplTest, AddInputEventFilter_Test001, TestSize.Level1)
393 {
394     CALL_TEST_DEBUG;
395     auto filter = std::make_shared<InputEventFilterMock>();
396     int32_t priority = 0;
397     uint32_t deviceTags = 0;
398 
399     InputMgrImpl.eventFilterServices_.clear();
400     EventFilterService::filterIdSeed_ = 0;
401     int32_t filterId = EventFilterService::filterIdSeed_;
402     sptr<IEventFilter> service = new (std::nothrow) EventFilterService(filter);
403     ASSERT_NE(service, nullptr);
404 
405     InputMgrImpl.eventFilterServices_.emplace(filterId, std::make_tuple(service, priority, deviceTags));
406     int32_t ret = InputMgrImpl.AddInputEventFilter(filter, priority, deviceTags);
407     EXPECT_EQ(ret, filterId);
408 }
409 
410 /**
411  * @tc.name  : RemoveInputEventFilter_Test001
412  * @tc.desc  : Test RemoveInputEventFilter
413  * @tc.type: FUNC
414  * @tc.require:
415  */
416 HWTEST_F(InputManagerImplTest, RemoveInputEventFilter_Test001, TestSize.Level1)
417 {
418     CALL_TEST_DEBUG;
419 
420     InputMgrImpl.eventFilterServices_.clear();
421     auto filter = std::make_shared<InputEventFilterMock>();
422     sptr<IEventFilter> service = new (std::nothrow) EventFilterService(filter);
423     ASSERT_NE(service, nullptr);
424 
425     int32_t priority = 0;
426     uint32_t deviceTags = 0;
427     int32_t filterId = 5;
428     InputMgrImpl.eventFilterServices_.emplace(filterId, std::make_tuple(service, priority, deviceTags));
429     filterId = 0;
430 
431     int32_t ret = InputMgrImpl.RemoveInputEventFilter(filterId);
432     EXPECT_EQ(ret, RET_OK);
433 }
434 
435 /**
436  * @tc.name: InputManagerImplTest_RecoverPointerEvent
437  * @tc.desc: Test RecoverPointerEvent
438  * @tc.type: FUNC
439  * @tc.require:
440  */
441 HWTEST_F(InputManagerImplTest, InputManagerImplTest_RecoverPointerEvent, TestSize.Level1)
442 {
443     CALL_TEST_DEBUG;
444     InputMgrImpl.lastPointerEvent_ = PointerEvent::Create();
445     ASSERT_NE(InputMgrImpl.lastPointerEvent_, nullptr);
446     std::initializer_list<int32_t> pointerActionPullEvents { PointerEvent::POINTER_ACTION_MOVE,
447         PointerEvent::POINTER_ACTION_UP };
448     InputMgrImpl.lastPointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
449     EXPECT_FALSE(InputMgrImpl.RecoverPointerEvent(pointerActionPullEvents, PointerEvent::POINTER_ACTION_UP));
450 
451     PointerEvent::PointerItem item;
452     item.SetPointerId(1);
453     InputMgrImpl.lastPointerEvent_->SetPointerId(1);
454     InputMgrImpl.lastPointerEvent_->AddPointerItem(item);
455     EXPECT_TRUE(InputMgrImpl.RecoverPointerEvent(pointerActionPullEvents, PointerEvent::POINTER_ACTION_UP));
456 
457     InputMgrImpl.lastPointerEvent_->SetPointerId(2);
458     EXPECT_FALSE(InputMgrImpl.RecoverPointerEvent(pointerActionPullEvents, PointerEvent::POINTER_ACTION_UP));
459 }
460 
461 /**
462  * @tc.name: InputManagerImplTest_SetMouseHotSpot_02
463  * @tc.desc: Test SetMouseHotSpot
464  * @tc.type: FUNC
465  * @tc.require:
466  */
467 HWTEST_F(InputManagerImplTest, InputManagerImplTest_SetMouseHotSpot_02, TestSize.Level1)
468 {
469     CALL_TEST_DEBUG;
470     int32_t windowId = -5;
471     int32_t hotSpotX = 2;
472     int32_t hotSpotY = 3;
473 
474     int32_t winPid = InputMgrImpl.GetWindowPid(windowId);
475     EXPECT_FALSE(winPid != -1);
476     int32_t ret = InputMgrImpl.SetMouseHotSpot(windowId, hotSpotX, hotSpotY);
477     EXPECT_EQ(ret, RET_ERR);
478 }
479 
480 /**
481  * @tc.name: InputManagerImplTest_IsPointerVisible_01
482  * @tc.desc: Test IsPointerVisible
483  * @tc.type: FUNC
484  * @tc.require:
485  */
486 HWTEST_F(InputManagerImplTest, InputManagerImplTest_IsPointerVisible_01, TestSize.Level1)
487 {
488     CALL_TEST_DEBUG;
489     bool ret = InputMgrImpl.IsPointerVisible();
490     EXPECT_TRUE(ret);
491 }
492 
493 /**
494  * @tc.name: InputManagerImplTest_IsPointerVisible_02
495  * @tc.desc: Test IsPointerVisible
496  * @tc.type: FUNC
497  * @tc.require:
498  */
499 HWTEST_F(InputManagerImplTest, InputManagerImplTest_IsPointerVisible_02, TestSize.Level1)
500 {
501     CALL_TEST_DEBUG;
502     bool ret = InputMgrImpl.IsPointerVisible();
503     EXPECT_TRUE(ret);
504 }
505 
506 /**
507  * @tc.name: InputManagerImplTest_SetPointerColor_01
508  * @tc.desc: Test SetPointerColor
509  * @tc.type: FUNC
510  * @tc.require:
511  */
512 HWTEST_F(InputManagerImplTest, InputManagerImplTest_SetPointerColor_01, TestSize.Level1)
513 {
514     CALL_TEST_DEBUG;
515     int32_t color = 6;
516     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.SetPointerColor(color));
517 }
518 
519 /**
520  * @tc.name: InputManagerImplTest_SetPointerColor_02
521  * @tc.desc: Test SetPointerColor
522  * @tc.type: FUNC
523  * @tc.require:
524  */
525 HWTEST_F(InputManagerImplTest, InputManagerImplTest_SetPointerColor_02, TestSize.Level1)
526 {
527     CALL_TEST_DEBUG;
528     int32_t color = -10;
529     int32_t ret = InputMgrImpl.SetPointerColor(color);
530     EXPECT_NE(ret, -10);
531 }
532 
533 /**
534  * @tc.name: InputManagerImplTest_SetPointerSpeed_01
535  * @tc.desc: Test SetPointerSpeed
536  * @tc.type: FUNC
537  * @tc.require:
538  */
539 HWTEST_F(InputManagerImplTest, InputManagerImplTest_SetPointerSpeed_01, TestSize.Level1)
540 {
541     CALL_TEST_DEBUG;
542     int32_t speed = 10;
543     int32_t ret2 = InputMgrImpl.SetPointerSpeed(speed);
544     EXPECT_EQ(ret2, RET_OK);
545 }
546 
547 /**
548  * @tc.name: InputManagerImplTest_EnableCombineKey_01
549  * @tc.desc: Test EnableCombineKey
550  * @tc.type: FUNC
551  * @tc.require:
552  */
553 HWTEST_F(InputManagerImplTest, InputManagerImplTest_EnableCombineKey_01, TestSize.Level1)
554 {
555     CALL_TEST_DEBUG;
556     bool enable = true;
557     int32_t ret2 = InputMgrImpl.EnableCombineKey(enable);
558     EXPECT_EQ(ret2, RET_OK);
559 }
560 
561 /**
562  * @tc.name: InputManagerImplTest_EnableCombineKey_02
563  * @tc.desc: Test EnableCombineKey
564  * @tc.type: FUNC
565  * @tc.require:
566  */
567 HWTEST_F(InputManagerImplTest, InputManagerImplTest_EnableCombineKey_02, TestSize.Level1)
568 {
569     CALL_TEST_DEBUG;
570     bool enable = false;
571     int32_t ret2 = InputMgrImpl.EnableCombineKey(enable);
572     EXPECT_EQ(ret2, RET_OK);
573 }
574 
575 /**
576  * @tc.name: InputManagerImplTest_OnConnected_01
577  * @tc.desc: Test OnConnected
578  * @tc.type: FUNC
579  * @tc.require:
580  */
581 HWTEST_F(InputManagerImplTest, InputManagerImplTest_OnConnected_01, TestSize.Level1)
582 {
583     CALL_TEST_DEBUG;
584     DisplayGroupInfo displayGroupInfo {};
585     InputMgrImpl.userScreenInfo_.displayGroups.push_back(displayGroupInfo);
586     EXPECT_TRUE(InputMgrImpl.userScreenInfo_.displayGroups[DEFAULT_GROUP_ID].windowsInfo.empty());
587     EXPECT_TRUE(InputMgrImpl.userScreenInfo_.displayGroups[DEFAULT_GROUP_ID].displaysInfo.empty());
588     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.OnConnected());
589 }
590 
591 /**
592  * @tc.name: InputManagerImplTest_OnConnected_02
593  * @tc.desc: Test OnConnected
594  * @tc.type: FUNC
595  * @tc.require:
596  */
597 HWTEST_F(InputManagerImplTest, InputManagerImplTest_OnConnected_02, TestSize.Level1)
598 {
599     CALL_TEST_DEBUG;
600     DisplayGroupInfo displayGroupInfo {};
601     InputMgrImpl.userScreenInfo_.displayGroups.push_back(displayGroupInfo);
602     DisplayInfo displayInfo;
603     displayInfo.width = 50;
604     displayInfo.height = 60;
605     InputMgrImpl.userScreenInfo_.displayGroups[DEFAULT_GROUP_ID].displaysInfo.push_back(displayInfo);
606     WindowInfo windowInfo;
607     windowInfo.id = 1;
608     windowInfo.pid = 2;
609     InputMgrImpl.userScreenInfo_.displayGroups[DEFAULT_GROUP_ID].windowsInfo.push_back(windowInfo);
610     EXPECT_FALSE(InputMgrImpl.userScreenInfo_.displayGroups[DEFAULT_GROUP_ID].windowsInfo.empty());
611 
612     displayInfo.width = 10;
613     displayInfo.height = 20;
614     InputMgrImpl.userScreenInfo_.displayGroups[DEFAULT_GROUP_ID].displaysInfo.push_back(displayInfo);
615     EXPECT_FALSE(InputMgrImpl.userScreenInfo_.displayGroups[DEFAULT_GROUP_ID].displaysInfo.empty());
616 
617     EXPECT_TRUE(InputMgrImpl.anrObservers_.empty());
618     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.OnConnected());
619 }
620 
621 /**
622  * @tc.name: InputManagerImplTest_OnConnected_03
623  * @tc.desc: Test OnConnected
624  * @tc.type: FUNC
625  * @tc.require:
626  */
627 HWTEST_F(InputManagerImplTest, InputManagerImplTest_OnConnected_03, TestSize.Level1)
628 {
629     CALL_TEST_DEBUG;
630     DisplayInfo displayInfo;
631     displayInfo.width = 10;
632     displayInfo.height = 20;
633     DisplayGroupInfo displayGroupInfo {};
634     InputMgrImpl.userScreenInfo_.displayGroups.push_back(displayGroupInfo);
635     InputMgrImpl.userScreenInfo_.displayGroups[DEFAULT_GROUP_ID].displaysInfo.push_back(displayInfo);
636     EXPECT_FALSE(InputMgrImpl.userScreenInfo_.displayGroups[DEFAULT_GROUP_ID].displaysInfo.empty());
637     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.OnConnected());
638 }
639 
640 /**
641  * @tc.name: InputManagerImplTest_OnConnected_04
642  * @tc.desc: Test OnConnected
643  * @tc.type: FUNC
644  * @tc.require:
645  */
646 HWTEST_F(InputManagerImplTest, InputManagerImplTest_OnConnected_04, TestSize.Level1)
647 {
648     CALL_TEST_DEBUG;
649     DisplayGroupInfo displayGroupInfo {};
650     InputMgrImpl.userScreenInfo_.displayGroups.push_back(displayGroupInfo);
651     DisplayInfo displayInfo;
652     displayInfo.width = 50;
653     displayInfo.height = 60;
654     InputMgrImpl.userScreenInfo_.displayGroups[DEFAULT_GROUP_ID].displaysInfo.push_back(displayInfo);
655     WindowInfo windowInfo;
656     windowInfo.id = 1;
657     windowInfo.pid = 2;
658     InputMgrImpl.userScreenInfo_.displayGroups[DEFAULT_GROUP_ID].windowsInfo.push_back(windowInfo);
659     EXPECT_FALSE(InputMgrImpl.userScreenInfo_.displayGroups[DEFAULT_GROUP_ID].windowsInfo.empty());
660     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.OnConnected());
661 }
662 
663 /**
664  * @tc.name: InputManagerImplTest_OnConnected_05
665  * @tc.desc: Test OnConnected
666  * @tc.type: FUNC
667  * @tc.require:
668  */
669 HWTEST_F(InputManagerImplTest, InputManagerImplTest_OnConnected_05, TestSize.Level1)
670 {
671     CALL_TEST_DEBUG;
672     InputMgrImpl.anrObservers_.push_back(nullptr);
673     EXPECT_FALSE(InputMgrImpl.anrObservers_.empty());
674     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.OnConnected());
675 }
676 
677 /**
678  * @tc.name: InputManagerImplTest_OnConnected_06
679  * @tc.desc: Test OnConnected
680  * @tc.type: FUNC
681  * @tc.require:
682  */
683 HWTEST_F(InputManagerImplTest, InputManagerImplTest_OnConnected_06, TestSize.Level1)
684 {
685     CALL_TEST_DEBUG;
686     class IAnrObserverTest : public IAnrObserver {
687     public:
IAnrObserverTest()688         IAnrObserverTest() : IAnrObserver()
689         {}
~IAnrObserverTest()690         virtual ~IAnrObserverTest()
691         {}
OnAnr(int32_t pid,int32_t eventId) const692         void OnAnr(int32_t pid, int32_t eventId) const override
693         {
694             MMI_HILOGD("Set anr success");
695         };
696     };
697     std::shared_ptr<IAnrObserverTest> observer = std::make_shared<IAnrObserverTest>();
698     InputMgrImpl.anrObservers_.push_back(observer);
699     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.OnConnected());
700 }
701 
702 /**
703  * @tc.name: InputManagerImplTest_OnConnected_07
704  * @tc.desc: Test OnConnected
705  * @tc.type: FUNC
706  * @tc.require:
707  */
708 HWTEST_F(InputManagerImplTest, InputManagerImplTest_OnConnected_07, TestSize.Level1)
709 {
710     CALL_TEST_DEBUG;
711     InputMgrImpl.currentUserId_.store(42);
712     EXPECT_TRUE(InputMgrImpl.currentUserId_ != -1);
713     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.OnConnected());
714 }
715 
716 /**
717  * @tc.name: InputManagerImplTest_OnConnected_08
718  * @tc.desc: Test OnConnected
719  * @tc.type: FUNC
720  * @tc.require:
721  */
722 HWTEST_F(InputManagerImplTest, InputManagerImplTest_OnConnected_08, TestSize.Level1)
723 {
724     CALL_TEST_DEBUG;
725     InputMgrImpl.currentUserId_.store(-1);
726     EXPECT_TRUE(InputMgrImpl.currentUserId_ == -1);
727     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.OnConnected());
728 }
729 
730 /**
731  * @tc.name: InputManagerImplTest_SetPixelMapData_01
732  * @tc.desc: Test SetPixelMapData
733  * @tc.type: FUNC
734  * @tc.require:
735  */
736 HWTEST_F(InputManagerImplTest, InputManagerImplTest_SetPixelMapData_01, TestSize.Level1)
737 {
738     CALL_TEST_DEBUG;
739     int32_t infoId = -1;
740     void* pixelMap = nullptr;
741     int32_t ret = InputMgrImpl.SetPixelMapData(infoId, pixelMap);
742     EXPECT_EQ(ret, RET_ERR);
743 
744     infoId = 2;
745     int32_t ret2 = InputMgrImpl.SetPixelMapData(infoId, pixelMap);
746     EXPECT_EQ(ret2, RET_ERR);
747 }
748 
749 /**
750  * @tc.name: InputManagerImplTest_SendEnhanceConfig_01
751  * @tc.desc: Test SendEnhanceConfig
752  * @tc.type: FUNC
753  * @tc.require:
754  */
755 HWTEST_F(InputManagerImplTest, InputManagerImplTest_SendEnhanceConfig_01, TestSize.Level1)
756 {
757     CALL_TEST_DEBUG;
758     MmiMessageId idMsg = MmiMessageId::SCINFO_CONFIG;
759     NetPacket pkt(idMsg);
760     EXPECT_EQ(InputMgrImpl.PackEnhanceConfig(pkt), RET_ERR);
761     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.SendEnhanceConfig());
762 }
763 
764 /**
765  * @tc.name: InputManagerImplTest_SendEnhanceConfig_02
766  * @tc.desc: Test SendEnhanceConfig
767  * @tc.type: FUNC
768  * @tc.require:
769  */
770 HWTEST_F(InputManagerImplTest, InputManagerImplTest_SendEnhanceConfig_02, TestSize.Level1)
771 {
772     CALL_TEST_DEBUG;
773     MmiMessageId idMsg = MmiMessageId::INVALID;
774     NetPacket pkt(idMsg);
775     EXPECT_EQ(InputMgrImpl.PackEnhanceConfig(pkt), RET_ERR);
776     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.SendEnhanceConfig());
777 }
778 
779 /**
780  * @tc.name: InputManagerImplTest_GetPointerColor_01
781  * @tc.desc: Test GetPointerColor
782  * @tc.type: FUNC
783  * @tc.require:
784  */
785 HWTEST_F(InputManagerImplTest, InputManagerImplTest_GetPointerColor_01, TestSize.Level1)
786 {
787     CALL_TEST_DEBUG;
788     int32_t color = 5;
789     int32_t ret = InputMgrImpl.GetPointerColor(color);
790     EXPECT_EQ(ret, RET_OK);
791 
792     color = -1;
793     int32_t ret2 = InputMgrImpl.GetPointerColor(color);
794     EXPECT_EQ(ret2, RET_OK);
795 }
796 
797 /**
798  * @tc.name: InputManagerImplTest_GetMouseScrollRows_01
799  * @tc.desc: Test GetMouseScrollRows
800  * @tc.type: FUNC
801  * @tc.require:
802  */
803 HWTEST_F(InputManagerImplTest, InputManagerImplTest_GetMouseScrollRows_01, TestSize.Level1)
804 {
805     CALL_TEST_DEBUG;
806     int32_t rows = 8;
807     int32_t ret = InputMgrImpl.GetMouseScrollRows(rows);
808     EXPECT_EQ(ret, RET_OK);
809 
810     rows = -5;
811     int32_t ret2 = InputMgrImpl.GetMouseScrollRows(rows);
812     EXPECT_EQ(ret2, RET_OK);
813 }
814 
815 /**
816  * @tc.name: InputManagerImplTest_SetMouseScrollRows_01
817  * @tc.desc: Test SetMouseScrollRows
818  * @tc.type: FUNC
819  * @tc.require:
820  */
821 HWTEST_F(InputManagerImplTest, InputManagerImplTest_SetMouseScrollRows_01, TestSize.Level1)
822 {
823     CALL_TEST_DEBUG;
824     int32_t rows = 3;
825     int32_t ret = InputMgrImpl.SetMouseScrollRows(rows);
826     EXPECT_EQ(ret, RET_OK);
827 
828     rows = -2;
829     int32_t ret2 = InputMgrImpl.SetMouseScrollRows(rows);
830     EXPECT_EQ(ret2, RET_OK);
831 }
832 
833 /**
834  * @tc.name: InputManagerImplTest_LeaveCaptureMode_01
835  * @tc.desc: Test LeaveCaptureMode
836  * @tc.type: FUNC
837  * @tc.require:
838  */
839 HWTEST_F(InputManagerImplTest, InputManagerImplTest_LeaveCaptureMode_01, TestSize.Level1)
840 {
841     CALL_TEST_DEBUG;
842     int32_t windowId = 3;
843     int32_t ret = InputMgrImpl.LeaveCaptureMode(windowId);
844     EXPECT_EQ(ret, RET_OK);
845 }
846 
847 /**
848  * @tc.name: InputManagerImplTest_EnableInputDevice_01
849  * @tc.desc: Test EnableInputDevice
850  * @tc.type: FUNC
851  * @tc.require:
852  */
853 HWTEST_F(InputManagerImplTest, InputManagerImplTest_EnableInputDevice_01, TestSize.Level1)
854 {
855     CALL_TEST_DEBUG;
856     bool enable = false;
857     int32_t ret = InputMgrImpl.EnableInputDevice(enable);
858     EXPECT_EQ(ret, RET_OK);
859 
860     enable = true;
861     int32_t ret2 = InputMgrImpl.EnableInputDevice(enable);
862     EXPECT_EQ(ret2, RET_OK);
863 }
864 
865 /**
866  * @tc.name: InputManagerImplTest_ConvertToCapiKeyAction_001
867  * @tc.desc: Test the funcation ConvertToCapiKeyAction
868  * @tc.type: FUNC
869  * @tc.require:
870  */
871 HWTEST_F(InputManagerImplTest, InputManagerImplTest_ConvertToCapiKeyAction_001, TestSize.Level1)
872 {
873     CALL_TEST_DEBUG;
874     int32_t keyAction = KeyEvent::KEY_ACTION_DOWN;
875     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.ConvertToCapiKeyAction(keyAction));
876     keyAction = KeyEvent::KEY_ACTION_UP;
877     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.ConvertToCapiKeyAction(keyAction));
878     keyAction = KeyEvent::KEY_ACTION_CANCEL;
879     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.ConvertToCapiKeyAction(keyAction));
880     keyAction = 10;
881     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.ConvertToCapiKeyAction(keyAction));
882 }
883 
884 /**
885  * @tc.name: InputManagerImplTest_GetTouchpadThreeFingersTapSwitch_001
886  * @tc.desc: Test the funcation GetTouchpadThreeFingersTapSwitch
887  * @tc.type: FUNC
888  * @tc.require:
889  */
890 HWTEST_F(InputManagerImplTest, InputManagerImplTest_GetTouchpadThreeFingersTapSwitch_001, TestSize.Level1)
891 {
892     CALL_TEST_DEBUG;
893     bool switchFlag = true;
894     int32_t ret = InputMgrImpl.GetTouchpadThreeFingersTapSwitch(switchFlag);
895     EXPECT_EQ(ret, RET_OK);
896     switchFlag = true;
897     ret = InputMgrImpl.GetTouchpadThreeFingersTapSwitch(switchFlag);
898     EXPECT_EQ(ret, RET_OK);
899 }
900 
901 /**
902  * @tc.name: InputManagerImplTest_SetTouchpadThreeFingersTapSwitch_001
903  * @tc.desc: Test the funcation SetTouchpadThreeFingersTapSwitch
904  * @tc.type: FUNC
905  * @tc.require:
906  */
907 HWTEST_F(InputManagerImplTest, InputManagerImplTest_SetTouchpadThreeFingersTapSwitch_001, TestSize.Level1)
908 {
909     CALL_TEST_DEBUG;
910     bool switchFlag = true;
911     int32_t ret = InputMgrImpl.SetTouchpadThreeFingersTapSwitch(switchFlag);
912     EXPECT_EQ(ret, RET_OK);
913     switchFlag = true;
914     ret = InputMgrImpl.SetTouchpadThreeFingersTapSwitch(switchFlag);
915     EXPECT_EQ(ret, RET_OK);
916 }
917 
918 /**
919  * @tc.name: InputManagerImplTest_SetCurrentUser_001
920  * @tc.desc: Test the funcation SetCurrentUser
921  * @tc.type: FUNC
922  * @tc.require:
923  */
924 HWTEST_F(InputManagerImplTest, InputManagerImplTest_SetCurrentUser_001, TestSize.Level1)
925 {
926     CALL_TEST_DEBUG;
927     int32_t userId = 1;
928     int32_t ret = InputMgrImpl.SetCurrentUser(userId);
929     EXPECT_EQ(ret, RET_ERR);
930     userId = 0;
931     ret = InputMgrImpl.SetCurrentUser(userId);
932     EXPECT_EQ(ret, RET_ERR);
933     userId = -1;
934     ret = InputMgrImpl.SetCurrentUser(userId);
935     EXPECT_EQ(ret, RET_ERR);
936 }
937 
938 /**
939  * @tc.name: InputManagerImplTest_Authorize_001
940  * @tc.desc: Test the funcation Authorize
941  * @tc.type: FUNC
942  * @tc.require:
943  */
944 HWTEST_F(InputManagerImplTest, InputManagerImplTest_Authorize_001, TestSize.Level1)
945 {
946     CALL_TEST_DEBUG;
947     bool isAuthorize = true;
948     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.Authorize(isAuthorize));
949     isAuthorize = false;
950     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.Authorize(isAuthorize));
951 }
952 
953 #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT
954 /**
955  * @tc.name: InputManagerImplTest_SetEnhanceConfig_001
956  * @tc.desc: Test SetEnhanceConfig
957  * @tc.type: FUNC
958  * @tc.require:
959  */
960 HWTEST_F(InputManagerImplTest, InputManagerImplTest_SetEnhanceConfig_001, TestSize.Level1)
961 {
962     CALL_TEST_DEBUG;
963     uint8_t *cfg = nullptr;
964     uint32_t cfgLen = 0;
965     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.SetEnhanceConfig(cfg, cfgLen));
966 
967     uint8_t data = 1;
968     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.SetEnhanceConfig(&data, cfgLen));
969 }
970 #endif
971 
972 /**
973  * @tc.name: InputManagerImplTest_SetInputDeviceConsumer
974  * @tc.desc: Test SetInputDeviceConsumer
975  * @tc.type: FUNC
976  * @tc.require:
977  */
978 HWTEST_F(InputManagerImplTest, InputManagerImplTest_SetInputDeviceConsumer, TestSize.Level1)
979 {
980     CALL_TEST_DEBUG;
981     std::vector<std::string> deviceNames;
982     deviceNames.push_back("test1");
983     deviceNames.push_back("test2");
984     std::shared_ptr<IInputEventConsumer> consumer = nullptr;
985     auto ret = InputMgrImpl.SetInputDeviceConsumer(deviceNames, consumer);
986     ASSERT_NE(ret, RET_OK);
987 }
988 
989 /**
990  * @tc.name  : SubscribeInputActive_Test001
991  * @tc.desc  : Test SubscribeInputActive
992  * @tc.type: FUNC
993  * @tc.require:
994  */
995 HWTEST_F(InputManagerImplTest, SubscribeInputActive_Test001, TestSize.Level1)
996 {
997     CALL_TEST_DEBUG;
998     std::shared_ptr<TestInputEventConsumer> inputEventConsumer = std::make_shared<TestInputEventConsumer>();
999     EXPECT_NE(inputEventConsumer, nullptr);
1000     int64_t interval = -1; // ms
1001     int32_t subscriberId = InputMgrImpl.SubscribeInputActive(
1002         std::static_pointer_cast<IInputEventConsumer>(inputEventConsumer), interval);
1003     EXPECT_LT(subscriberId, 0);
1004 
1005     interval = 0; // ms
1006     subscriberId = InputMgrImpl.SubscribeInputActive(
1007         std::static_pointer_cast<IInputEventConsumer>(inputEventConsumer), interval);
1008     EXPECT_GE(subscriberId, 0);
1009     InputMgrImpl.UnsubscribeInputActive(subscriberId);
1010     interval = 1; // ms
1011     subscriberId = InputMgrImpl.SubscribeInputActive(
1012         std::static_pointer_cast<IInputEventConsumer>(inputEventConsumer), interval);
1013     EXPECT_GE(subscriberId, 0);
1014     InputMgrImpl.UnsubscribeInputActive(subscriberId);
1015 
1016     interval = 499; // ms
1017     subscriberId = InputMgrImpl.SubscribeInputActive(
1018         std::static_pointer_cast<IInputEventConsumer>(inputEventConsumer), interval);
1019     EXPECT_GE(subscriberId, 0);
1020     InputMgrImpl.UnsubscribeInputActive(subscriberId);
1021 
1022     interval = 500; // ms
1023     subscriberId = InputMgrImpl.SubscribeInputActive(
1024         std::static_pointer_cast<IInputEventConsumer>(inputEventConsumer), interval);
1025     EXPECT_GE(subscriberId, 0);
1026     InputMgrImpl.UnsubscribeInputActive(subscriberId);
1027 
1028     interval = 2000; // ms
1029     subscriberId = InputMgrImpl.SubscribeInputActive(
1030         std::static_pointer_cast<IInputEventConsumer>(inputEventConsumer), interval);
1031     EXPECT_GE(subscriberId, 0);
1032     InputMgrImpl.UnsubscribeInputActive(subscriberId);
1033 
1034     interval = 2001; // ms
1035     subscriberId = InputMgrImpl.SubscribeInputActive(
1036         std::static_pointer_cast<IInputEventConsumer>(inputEventConsumer), interval);
1037     EXPECT_GE(subscriberId, 0);
1038     InputMgrImpl.UnsubscribeInputActive(subscriberId);
1039 }
1040 
1041 /**
1042  * @tc.name: InputManagerImplTest_GetPointerLocation001
1043  * @tc.desc: Test AboutPoint
1044  * @tc.type: FUNC
1045  * @tc.require:
1046  */
1047 HWTEST_F(InputManagerImplTest, InputManagerImplTest_GetPointerLocation001, TestSize.Level1)
1048 {
1049     CALL_TEST_DEBUG;
1050     int32_t displayId = 0;
1051     double displayX = 0.0;
1052     double displayY = 0.0;
1053     EXPECT_EQ(InputMgrImpl.GetPointerLocation(displayId, displayX, displayY), ERROR_APP_NOT_FOCUSED);
1054 }
1055 
1056 /**
1057  * @tc.name: InputManagerImplTest_TestUpdateDisplayInfo_001
1058  * @tc.desc: Test UpdateDisplayInfo
1059  * @tc.type: FUNC
1060  * @tc.require:
1061  */
1062 HWTEST_F(InputManagerImplTest, InputManagerImplTest_TestUpdateDisplayInfo_001, TestSize.Level1)
1063 {
1064     CALL_TEST_DEBUG;
1065     OHOS::MMI::DisplayInfo displayInfo;
1066     displayInfo.id = 0;
1067     displayInfo.width = 1920;
1068     displayInfo.height = 1080;
1069     displayInfo.name = "Main Display";
1070     OHOS::MMI::DisplayGroupInfo displayGroupInfo;
1071     displayGroupInfo.id = 1;
1072     displayGroupInfo.name = "Main Display Group";
1073     displayGroupInfo.type = OHOS::MMI::GroupType::GROUP_DEFAULT;
1074     displayGroupInfo.focusWindowId = 1;
1075     displayGroupInfo.mainDisplayId = displayInfo.id;
1076     displayGroupInfo.displaysInfo.push_back(displayInfo);
1077     OHOS::MMI::UserScreenInfo userScreenInfo;
1078     userScreenInfo.userId = 100;
1079     userScreenInfo.displayGroups.push_back(displayGroupInfo);
1080     int32_t result = InputMgrImpl.UpdateDisplayInfo(userScreenInfo);
1081     EXPECT_EQ(result, RET_OK);
1082 }
1083 
1084 class MockNetPacket : public NetPacket {
1085 public:
MockNetPacket(MmiMessageId msgId)1086     explicit MockNetPacket(MmiMessageId msgId) : NetPacket(msgId) {}
1087     MOCK_METHOD(bool, Write, (const char* data, size_t size), (override));
1088 };
1089 
1090 /**
1091  * @tc.name: InputManagerImplTest_TestPackDisplayData_WriteFailure
1092  * @tc.desc: Test PackDisplayData_WriteFailure
1093  * @tc.type: FUNC
1094  * @tc.require:
1095  */
1096 HWTEST_F(InputManagerImplTest, InputManagerImplTest_TestPackDisplayData_WriteFailure, TestSize.Level1)
1097 {
1098     CALL_TEST_DEBUG;
1099     UserScreenInfo userScreenInfo;
1100     userScreenInfo.userId = 0;
1101     DisplayGroupInfo group;
1102     group.id = 1;
1103     group.name = "MainGroup";
1104     group.type = GroupType::GROUP_DEFAULT;
1105     group.mainDisplayId = 2;
1106     group.focusWindowId = 123;
1107     group.windowsInfo.push_back(WindowInfo());
1108     group.displaysInfo.push_back(DisplayInfo());
1109     DisplayInfo display;
1110     display.width = 1920;
1111     display.height = 1080;
1112     group.displaysInfo.push_back(display);
1113     WindowInfo window;
1114     window.groupId = 0;
1115     window.id = 123;
1116     group.windowsInfo.push_back(window);
1117     userScreenInfo.displayGroups.push_back(group);
1118     userScreenInfo.screens.push_back(ScreenInfo());
1119     MockNetPacket mock_pkt(MmiMessageId::DISPLAY_INFO);
1120     EXPECT_CALL(mock_pkt, Write(testing::_, testing::_)).WillRepeatedly(testing::Return(false));
1121     int32_t result = InputMgrImpl.PackDisplayData(mock_pkt, userScreenInfo);
1122     EXPECT_EQ(result, RET_OK);
1123 }
1124 
1125 /**
1126  * @tc.name: InputManagerImplTest_TestPackWindowInfoReturnsError
1127  * @tc.desc: Test TestPackWindowInfoReturnsError
1128  * @tc.type: FUNC
1129  * @tc.require:
1130  */
1131 HWTEST_F(InputManagerImplTest, InputManagerImplTest_TestPackWindowInfoReturnsError, TestSize.Level1)
1132 {
1133     CALL_TEST_DEBUG;
1134     DisplayGroupInfo displayGroupInfo;
1135     displayGroupInfo.id = 101;
1136     displayGroupInfo.type = GroupType::GROUP_DEFAULT;
1137     displayGroupInfo.focusWindowId = 123;
1138     displayGroupInfo.mainDisplayId = 0;
1139     WindowInfo windowInfo;
1140     displayGroupInfo.windowsInfo.push_back(windowInfo);
1141     UserScreenInfo userScreenInfo;
1142     userScreenInfo.userId = 0;
1143     userScreenInfo.displayGroups.push_back(displayGroupInfo);
1144     MockNetPacket mockPacket(MmiMessageId::DISPLAY_INFO);
1145     int writeCallCount = 0;
1146     EXPECT_CALL(mockPacket, Write(testing::_, testing::_))
__anone3e3a0100202(const char*, size_t) 1147         .WillRepeatedly(testing::Invoke([&writeCallCount](const char*, size_t) {
1148             bool success = (writeCallCount < 6);
1149             writeCallCount++;
1150             return success;
1151         }));
1152     int32_t result = InputMgrImpl.PackDisplayData(mockPacket, userScreenInfo);
1153     EXPECT_NE(result, RET_ERR);
1154 }
1155 
1156 /**
1157  * @tc.name: InputManagerImplTest_PrintDisplayInfo_004
1158  * @tc.desc: Test TestPrintDisplayInfo
1159  * @tc.type: FUNC
1160  * @tc.require:
1161  */
1162 HWTEST_F(InputManagerImplTest, InputManagerImplTest_PrintDisplayInfo_004, TestSize.Level1)
1163 {
1164     CALL_TEST_DEBUG;
1165     UserScreenInfo userScreenInfo;
1166     userScreenInfo.userId = 0;
1167     DisplayGroupInfo group;
1168     int32_t mainDisplayId = 0;
1169     group.mainDisplayId = mainDisplayId;
1170     DisplayInfo displayInfo;
1171     displayInfo.id = mainDisplayId;
1172     displayInfo.name = "Display 0";
1173     displayInfo.width = 1920;
1174     displayInfo.height = 1080;
1175     group.displaysInfo.push_back(displayInfo);
1176     WindowInfo windowInfo;
1177     windowInfo.id = 123;
1178     windowInfo.displayId = mainDisplayId;
1179     group.windowsInfo.push_back(windowInfo);
1180     userScreenInfo.displayGroups.push_back(group);
1181     EXPECT_NO_FATAL_FAILURE(InputMgrImpl.PrintDisplayInfo(userScreenInfo));
1182     DisplayGroupInfo newGroup;
1183     newGroup.mainDisplayId = 1;
1184     DisplayInfo newDisplayInfo;
1185     newDisplayInfo.id = 1;
1186     newDisplayInfo.name = "Display 1";
1187     newDisplayInfo.width = 1440;
1188     newDisplayInfo.height = 900;
1189     newGroup.displaysInfo.push_back(newDisplayInfo);
1190     WindowInfo newWindowInfo;
1191     newWindowInfo.id = 1;
1192     newWindowInfo.displayId = 1;
1193     newGroup.windowsInfo.push_back(newWindowInfo);
1194     userScreenInfo.displayGroups.push_back(newGroup);
1195     int32_t result = InputMgrImpl.UpdateDisplayInfo(userScreenInfo);
1196     EXPECT_EQ(result, RET_OK);
1197 }
1198 
1199 /**
1200  * @tc.name: InputManagerImplTest_TestPackDisplayData_WriteFailure
1201  * @tc.desc: Test PackDisplayData_001
1202  * @tc.type: FUNC
1203  * @tc.require:
1204  */
1205 HWTEST_F(InputManagerImplTest, InputManagerImplTest_TestPackDisplayData_001, TestSize.Level1)
1206 {
1207     CALL_TEST_DEBUG;
1208     UserScreenInfo userScreenInfo;
1209     userScreenInfo.userId = 0;
1210     DisplayGroupInfo group;
1211     group.id = 1;
1212     group.name = "MainGroup";
1213     group.type = GroupType::GROUP_DEFAULT;
1214     group.mainDisplayId = 2;
1215     group.focusWindowId = 123;
1216     group.windowsInfo.push_back(WindowInfo());
1217     group.displaysInfo.push_back(DisplayInfo());
1218     DisplayInfo display;
1219     display.width = 1920;
1220     display.height = 1080;
1221     group.displaysInfo.push_back(display);
1222     WindowInfo window;
1223     window.groupId = 1;
1224     window.id = 123;
1225     group.windowsInfo.push_back(window);
1226     userScreenInfo.displayGroups.push_back(group);
1227     userScreenInfo.screens.push_back(ScreenInfo());
1228     NetPacket pkt(MmiMessageId::INVALID);
1229     EXPECT_FALSE(pkt.ChkRWError());
1230     int32_t r3;
1231     pkt >> r3;
1232     EXPECT_TRUE(pkt.ChkRWError());
1233     auto result = InputMgrImpl.PackDisplayData(pkt, userScreenInfo);
1234     EXPECT_EQ(result, RET_ERR);
1235 }
1236 
1237 /**
1238  * @tc.name: InputManagerImplTest_TestPackScreensInfo
1239  * @tc.desc: Test PackScreensInfo_001
1240  * @tc.type: FUNC
1241  * @tc.require:
1242  */
1243 HWTEST_F(InputManagerImplTest, InputManagerImplTest_TestPackScreensInfo_001, TestSize.Level1)
1244 {
1245     CALL_TEST_DEBUG;
1246     NetPacket pkt(MmiMessageId::INVALID);
1247     EXPECT_FALSE(pkt.ChkRWError());
1248     int32_t r3;
1249     pkt >> r3;
1250     EXPECT_TRUE(pkt.ChkRWError());
1251     std::vector<ScreenInfo> screens;
1252     auto result = InputMgrImpl.PackScreensInfo(pkt, screens);
1253     EXPECT_EQ(result, RET_ERR);
1254 }
1255 
1256 /**
1257  * @tc.name: InputManagerImplTest_TestPackDisplayGroupsInfo
1258  * @tc.desc: Test PackDisplayGroupsInfo_001
1259  * @tc.type: FUNC
1260  * @tc.require:
1261  */
1262 HWTEST_F(InputManagerImplTest, InputManagerImplTest_TestPackDisplayGroupsInfo_001, TestSize.Level1)
1263 {
1264     CALL_TEST_DEBUG;
1265     NetPacket pkt(MmiMessageId::INVALID);
1266     EXPECT_FALSE(pkt.ChkRWError());
1267     int32_t r3;
1268     pkt >> r3;
1269     EXPECT_TRUE(pkt.ChkRWError());
1270     std::vector<DisplayGroupInfo> group;
1271     auto result = InputMgrImpl.PackDisplayGroupsInfo(pkt, group);
1272     EXPECT_EQ(result, RET_ERR);
1273 }
1274 
1275 /**
1276  * @tc.name: InputManagerImplTest_TestPackDisplaysInfo
1277  * @tc.desc: Test PackDisplaysInfo_001
1278  * @tc.type: FUNC
1279  * @tc.require:
1280  */
1281 HWTEST_F(InputManagerImplTest, InputManagerImplTest_TestPackDisplaysInfo_001, TestSize.Level1)
1282 {
1283     CALL_TEST_DEBUG;
1284     NetPacket pkt(MmiMessageId::INVALID);
1285     EXPECT_FALSE(pkt.ChkRWError());
1286     int32_t r3;
1287     pkt >> r3;
1288     EXPECT_TRUE(pkt.ChkRWError());
1289     std::vector<DisplayInfo> displayInfo;
1290     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.PackDisplaysInfo(pkt, displayInfo));
1291 }
1292 
1293 /**
1294  * @tc.name: InputManagerImplTest_TestUpdateDisplayInfo_002
1295  * @tc.desc: Test UpdateDisplayInfo
1296  * @tc.type: FUNC
1297  * @tc.require:
1298  */
1299 HWTEST_F(InputManagerImplTest, InputManagerImplTest_TestUpdateDisplayInfo_002, TestSize.Level1)
1300 {
1301     CALL_TEST_DEBUG;
1302     OHOS::MMI::DisplayInfo displayInfo;
1303     displayInfo.id = 0;
1304     displayInfo.width = 1920;
1305     displayInfo.height = 1080;
1306     displayInfo.name = "Main Display";
1307     OHOS::MMI::DisplayGroupInfo displayGroupInfo;
1308     displayGroupInfo.id = 1;
1309     displayGroupInfo.name = "Main Display Group";
1310     displayGroupInfo.type = OHOS::MMI::GroupType::GROUP_DEFAULT;
1311     displayGroupInfo.focusWindowId = 1;
1312     displayGroupInfo.mainDisplayId = displayInfo.id;
1313     displayGroupInfo.displaysInfo.push_back(displayInfo);
1314     OHOS::MMI::UserScreenInfo userScreenInfo;
1315     userScreenInfo.userId = 100;
1316     userScreenInfo.displayGroups.push_back(displayGroupInfo);
1317     userScreenInfo.displayGroups.resize(110);
1318     int32_t result = InputMgrImpl.UpdateDisplayInfo(userScreenInfo);
1319     EXPECT_EQ(result, RET_ERR);
1320     userScreenInfo.screens.resize(1100);
1321     result = InputMgrImpl.UpdateDisplayInfo(userScreenInfo);
1322     EXPECT_EQ(result, RET_ERR);
1323 }
1324 
1325 /**
1326  * @tc.name: InputManagerImplTest_TestPackDisplayData_002
1327  * @tc.desc: Test PackDisplayData_002
1328  * @tc.type: FUNC
1329  * @tc.require:
1330  */
1331 HWTEST_F(InputManagerImplTest, InputManagerImplTest_TestPackDisplayData_002, TestSize.Level1)
1332 {
1333     CALL_TEST_DEBUG;
1334     UserScreenInfo userScreenInfo;
1335     std::vector<DisplayGroupInfo> group;
1336     userScreenInfo.userId = 0;
1337 
1338     NetPacket pkt(MmiMessageId::INVALID);
1339     EXPECT_FALSE(pkt.ChkRWError());
1340     int32_t r3;
1341     pkt >> r3;
1342     EXPECT_TRUE(pkt.ChkRWError());
1343     auto result = InputMgrImpl.PackDisplayGroupsInfo(pkt, group);
1344     EXPECT_EQ(result, RET_ERR);
1345     result = InputMgrImpl.PackDisplayData(pkt, userScreenInfo);
1346     EXPECT_EQ(result, RET_ERR);
1347 }
1348 
1349 /**
1350  * @tc.name: InputManagerImplTest_TestPackDisplayData_003
1351  * @tc.desc: Test PackDisplayData_003
1352  * @tc.type: FUNC
1353  * @tc.require:
1354  */
1355 HWTEST_F(InputManagerImplTest, InputManagerImplTest_TestPackDisplayData_003, TestSize.Level1)
1356 {
1357     CALL_TEST_DEBUG;
1358     UserScreenInfo userScreenInfo;
1359     userScreenInfo.userId = 0;
1360     NetPacket pkt(MmiMessageId::INVALID);
1361     EXPECT_FALSE(pkt.ChkRWError());
1362     int32_t r3;
1363     pkt >> r3;
1364     EXPECT_TRUE(pkt.ChkRWError());
1365     auto result = InputMgrImpl.PackDisplayData(pkt, userScreenInfo);
1366     EXPECT_EQ(result, RET_ERR);
1367 }
1368 
1369 /**
1370  * @tc.name: InputManagerImplTest_TestUpdateDisplayInfo_003
1371  * @tc.desc: Test UpdateDisplayInfo
1372  * @tc.type: FUNC
1373  * @tc.require:
1374  */
1375 HWTEST_F(InputManagerImplTest, InputManagerImplTest_TestUpdateDisplayInfo_003, TestSize.Level1)
1376 {
1377     CALL_TEST_DEBUG;
1378     OHOS::MMI::DisplayInfo displayInfo;
1379     displayInfo.id = 0;
1380     displayInfo.width = 1920;
1381     displayInfo.height = 1080;
1382     displayInfo.name = "Main Display";
1383     OHOS::MMI::DisplayGroupInfo displayGroupInfo;
1384     displayGroupInfo.id = 1;
1385     displayGroupInfo.name = "Main Display Group";
1386     displayGroupInfo.type = OHOS::MMI::GroupType::GROUP_DEFAULT;
1387     displayGroupInfo.focusWindowId = 1;
1388     displayGroupInfo.mainDisplayId = displayInfo.id;
1389     displayGroupInfo.displaysInfo.push_back(displayInfo);
1390     OHOS::MMI::UserScreenInfo userScreenInfo;
1391     userScreenInfo.userId = 100;
1392     userScreenInfo.displayGroups.push_back(displayGroupInfo);
1393     userScreenInfo.displayGroups.resize(1110);
1394     int32_t result = InputMgrImpl.UpdateDisplayInfo(userScreenInfo);
1395     EXPECT_EQ(result, RET_ERR);
1396     userScreenInfo.screens.resize(1100);
1397     result = InputMgrImpl.UpdateDisplayInfo(userScreenInfo);
1398     EXPECT_EQ(result, RET_ERR);
1399 }
1400 
1401 
1402 /**
1403  * @tc.name: InputManagerImplTest_TestPackDisplayData_004
1404  * @tc.desc: Test PackDisplayData_004
1405  * @tc.type: FUNC
1406  * @tc.require:
1407  */
1408 HWTEST_F(InputManagerImplTest, InputManagerImplTest_TestPackDisplayData_004, TestSize.Level1)
1409 {
1410     CALL_TEST_DEBUG;
1411     UserScreenInfo userScreenInfo;
1412     userScreenInfo.userId = 0;
1413     NetPacket pkt(MmiMessageId::INVALID);
1414     auto screelet = InputMgrImpl.PackScreensInfo(pkt, userScreenInfo.screens);
1415     EXPECT_EQ(screelet, RET_OK);
1416     auto groplet = InputMgrImpl.PackDisplayGroupsInfo(pkt, userScreenInfo.displayGroups);
1417     EXPECT_EQ(groplet, RET_OK);
1418     auto result = InputMgrImpl.PackDisplayData(pkt, userScreenInfo);
1419     EXPECT_EQ(result, RET_OK);
1420 }
1421 
1422 /**
1423  * @tc.name: InputManagerImplTest_TestPrintScreens
1424  * @tc.desc: Test PrintScreens
1425  * @tc.type: FUNC
1426  * @tc.require:
1427  */
1428 HWTEST_F(InputManagerImplTest, InputManagerImplTest_TestPrintScreens, TestSize.Level1)
1429 {
1430     CALL_TEST_DEBUG;
1431     UserScreenInfo userScreenInfo;
1432     userScreenInfo.userId = 0;
1433     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.PrintScreens(userScreenInfo.screens));
1434 }
1435 
1436 /**
1437  * @tc.name: InputManagerImplTest_TestPrintDisplayGroups
1438  * @tc.desc: Test PrintDisplayGroups
1439  * @tc.type: FUNC
1440  * @tc.require:
1441  */
1442 HWTEST_F(InputManagerImplTest, InputManagerImplTest_TestPrintDisplayGroups, TestSize.Level1)
1443 {
1444     CALL_TEST_DEBUG;
1445     UserScreenInfo userScreenInfo;
1446     userScreenInfo.userId = 0;
1447     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.PrintDisplayGroups(userScreenInfo.displayGroups));
1448 }
1449 
1450 /**
1451  * @tc.name: InputManagerImplTest_TestPrintDisplaysInfo
1452  * @tc.desc: Test PrintDisplaysInfo
1453  * @tc.type: FUNC
1454  * @tc.require:
1455  */
1456 HWTEST_F(InputManagerImplTest, InputManagerImplTest_TestPrintDisplaysInfo, TestSize.Level1)
1457 {
1458     CALL_TEST_DEBUG;
1459     OHOS::MMI::DisplayInfo displayInfo;
1460     displayInfo.id = 0;
1461     displayInfo.width = 1920;
1462     displayInfo.height = 1080;
1463     displayInfo.name = "Main Display";
1464     OHOS::MMI::DisplayGroupInfo displayGroupInfo;
1465     displayGroupInfo.id = 1;
1466     displayGroupInfo.name = "Main Display Group";
1467     displayGroupInfo.type = OHOS::MMI::GroupType::GROUP_DEFAULT;
1468     displayGroupInfo.focusWindowId = 1;
1469     displayGroupInfo.mainDisplayId = displayInfo.id;
1470     displayGroupInfo.displaysInfo.push_back(displayInfo);
1471     DisplayGroupInfo userScreenInfo;
1472     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.PrintDisplaysInfo(displayGroupInfo.displaysInfo));
1473 }
1474 
1475 /**
1476  * @tc.name: InputManagerImplTest_GetDisplayBindInfo_001
1477  * @tc.desc: Get diaplay bind information
1478  * @tc.type: FUNC
1479  * @tc.require:
1480  */
1481 HWTEST_F(InputManagerImplTest, InputManagerImplTest_GetDisplayBindInfo_001, TestSize.Level1)
1482 {
1483     CALL_TEST_DEBUG;
1484     OHOS::MMI::DisplayBindInfos infos;
1485     int32_t ret = InputMgrImpl.GetDisplayBindInfo(infos);
1486     EXPECT_EQ(ret, RET_OK);
1487     if (ret != RET_OK) {
1488         MMI_HILOGE("Call GetDisplayBindInfo failed, ret:%{public}d", ret);
1489     }
1490 }
1491 
1492 /**
1493  * @tc.name: InputManagerImplTest_GetAllMmiSubscribedEvents_001
1494  * @tc.desc: Test get all mmi subscribed events
1495  * @tc.type: FUNC
1496  * @tc.require:
1497  */
1498 HWTEST_F(InputManagerImplTest, InputManagerImplTest_GetAllMmiSubscribedEvents_001, TestSize.Level1)
1499 {
1500     std::map<std::tuple<int32_t, int32_t, std::string>, int32_t> datas;
1501     ASSERT_EQ(InputMgrImpl.GetAllMmiSubscribedEvents(datas), RET_OK);
1502     ASSERT_FALSE(datas.empty());
1503 }
1504 
1505 /**
1506  * @tc.name: InputManagerImplTest_SetDisplayBind_001
1507  * @tc.desc: Set diaplay bind information
1508  * @tc.type: FUNC
1509  * @tc.require:
1510  */
1511 HWTEST_F(InputManagerImplTest, InputManagerImplTest_SetDisplayBind_001, TestSize.Level1)
1512 {
1513     CALL_TEST_DEBUG;
1514     int32_t deviceId = 0;
1515     int32_t displayId = -1;
1516     std::string msg;
1517     int32_t ret = InputMgrImpl.SetDisplayBind(deviceId, displayId, msg);
1518     ASSERT_TRUE(ret != RET_OK);
1519     if (ret != RET_OK) {
1520         MMI_HILOGE("Call SetDisplayBind failed, ret:%{public}d", ret);
1521     }
1522 }
1523 
1524 /**
1525  * @tc.name: InputManagerImplTest_TestUpdateDisplayInfo_004
1526  * @tc.desc: Test UpdateDisplayInfo
1527  * @tc.type: FUNC
1528  * @tc.require:
1529  */
1530 HWTEST_F(InputManagerImplTest, InputManagerImplTest_TestUpdateDisplayInfo_004, TestSize.Level1)
1531 {
1532     CALL_TEST_DEBUG;
1533     OHOS::MMI::DisplayInfo info;
1534     info.id = 0;
1535     info.width = 1920;
1536     info.height = 1080;
1537     info.name = "Main Display";
1538     OHOS::MMI::DisplayGroupInfo displayGroupInfo;
1539     displayGroupInfo.id = 111;
1540     displayGroupInfo.name = "Main Display Group";
1541     displayGroupInfo.type = OHOS::MMI::GroupType::GROUP_SPECIAL;
1542     displayGroupInfo.focusWindowId = 111;
1543     displayGroupInfo.mainDisplayId = info.id;
1544     displayGroupInfo.displaysInfo.push_back(info);
1545     OHOS::MMI::UserScreenInfo screenInfo;
1546     screenInfo.userId = 100;
1547     screenInfo.displayGroups.push_back(displayGroupInfo);
1548     screenInfo.displayGroups.resize(10);
1549     screenInfo.screens.resize(10);
1550     auto result = InputMgrImpl.UpdateDisplayInfo(screenInfo);
1551     EXPECT_EQ(result, RET_OK);
1552 }
1553 
1554 /**
1555  * @tc.name: InputManagerImplTest_TestUpdateDisplayInfo_005
1556  * @tc.desc: Test UpdateDisplayInfo
1557  * @tc.type: FUNC
1558  * @tc.require:
1559  */
1560 HWTEST_F(InputManagerImplTest, InputManagerImplTest_TestUpdateDisplayInfo_005, TestSize.Level1)
1561 {
1562     WindowGroupInfo initialWindowGroupInfo;
1563     for (int i = 0; i < 10; ++i) {
1564         WindowInfo window;
1565         initialWindowGroupInfo.windowsInfo.push_back(window);
1566     }
1567 
1568     UserScreenInfo userScreenInfo;
1569     DisplayGroupInfo group;
1570     for (int i = 0; i < MAX_WINDOW_SIZE - 1; ++i) {
1571         WindowInfo window;
1572         group.windowsInfo.push_back(window);
1573     }
1574     userScreenInfo.displayGroups.push_back(group);
1575 
1576     DisplayInfo display;
1577     group.displaysInfo.push_back(display);
1578     userScreenInfo.screens.push_back(ScreenInfo());
1579 
1580     int32_t result = InputMgrImpl.UpdateDisplayInfo(userScreenInfo);
1581 
1582     EXPECT_EQ(result, RET_ERR);
1583 }
1584 
1585 /**
1586  * @tc.name: InputManagerImplTest_TestUpdateDisplayInfo_006
1587  * @tc.desc: Test UpdateDisplayInfo
1588  * @tc.type: FUNC
1589  * @tc.require:
1590  */
1591 HWTEST_F(InputManagerImplTest, InputManagerImplTest_TestUpdateDisplayInfo_006, TestSize.Level1)
1592 {
1593     UserScreenInfo userScreenInfo;
1594 
1595     DisplayGroupInfo group;
1596     group.id = 1;
1597     group.name = "Main Display Group";
1598     group.type = OHOS::MMI::GroupType::GROUP_DEFAULT;
1599     group.focusWindowId = 1;
1600     DisplayInfo display;
1601     group.displaysInfo.push_back(display);
1602     userScreenInfo.displayGroups.push_back(group);
1603     ScreenInfo screen;
1604     userScreenInfo.screens.push_back(screen);
1605     for (int i = 0; i < MAX_WINDOW_SIZE; ++i) {
1606         WindowInfo window;
1607         group.windowsInfo.push_back(window);
1608     }
1609 
1610     int32_t result = InputMgrImpl.UpdateDisplayInfo(userScreenInfo);
1611     EXPECT_EQ(result, RET_OK);
1612 }
1613 
1614 /**
1615  * @tc.name: InputManagerImplTest_TestUpdateDisplayInfo_007
1616  * @tc.desc: Test UpdateDisplayInfo
1617  * @tc.type: FUNC
1618  * @tc.require:
1619  */
1620 HWTEST_F(InputManagerImplTest, InputManagerImplTest_TestUpdateDisplayInfo_007, TestSize.Level1)
1621 {
1622     UserScreenInfo userScreenInfo;
1623     for (size_t i = 0; i < MAX_DISPLAY_GROUP_SIZE; ++i) {
1624         DisplayGroupInfo group;
1625         userScreenInfo.displayGroups.push_back(group);
1626     }
1627 
1628     for (size_t i = 0; i < MAX_SCREEN_SIZE; ++i) {
1629         ScreenInfo screen;
1630         userScreenInfo.screens.push_back(screen);
1631     }
1632 
1633     size_t totalDisplays = 0;
1634     for (const auto& group : userScreenInfo.displayGroups) {
1635         totalDisplays += group.displaysInfo.size();
1636     }
1637 
1638     if (totalDisplays <= MAX_DISPLAY_SIZE) {
1639         int32_t result = InputMgrImpl.UpdateDisplayInfo(userScreenInfo);
1640         EXPECT_EQ(result, RET_ERR);
1641     }
1642 }
1643 
1644 /**
1645  * @tc.name: InputManagerImplTest_UpdateWindowInfo
1646  * @tc.desc: Test the funcation UpdateWindowInfo
1647  * @tc.type: FUNC
1648  * @tc.require:
1649  */
1650 HWTEST_F(InputManagerImplTest, InputManagerImplTest_UpdateWindowInfo, TestSize.Level1)
1651 {
1652     CALL_TEST_DEBUG;
1653     WindowGroupInfo initialWindowGroupInfo;
1654     for (int i = 0; i < 10; ++i) {
1655         WindowInfo window;
1656         initialWindowGroupInfo.windowsInfo.push_back(window);
1657     }
1658 
1659     EXPECT_NO_FATAL_FAILURE(InputMgrImpl.UpdateWindowInfo(initialWindowGroupInfo));
1660 }
1661 
1662 /**
1663  * @tc.name: InputManagerImplTest_UpdateWindowInfo_001
1664  * @tc.desc: Test the funcation UpdateWindowInfo
1665  * @tc.type: FUNC
1666  * @tc.require:
1667  */
1668 HWTEST_F(InputManagerImplTest, InputManagerImplTest_UpdateWindowInfo_001, TestSize.Level1)
1669 {
1670     CALL_TEST_DEBUG;
1671     WindowGroupInfo windowGroupInfo;
1672     WindowInfo window;
1673     window.id = 1;
1674     window.pid = 1000;
1675     window.uid = 10000;
1676     Rect hotArea {
1677         .x = 0,
1678         .y = 0,
1679         .width = 100,
1680         .height = 100,
1681     };
1682     window.defaultHotAreas.push_back(hotArea);
1683     window.pointerHotAreas.push_back(hotArea);
1684     windowGroupInfo.windowsInfo.push_back(window);
1685     int32_t result = InputMgrImpl.UpdateWindowInfo(windowGroupInfo);
1686     EXPECT_EQ(result, RET_OK);
1687 }
1688 
1689 /**
1690  * @tc.name: InputManagerImplTest_UpdateWindowInfo_002
1691  * @tc.desc: Test the funcation UpdateWindowInfo
1692  * @tc.type: FUNC
1693  * @tc.require:
1694  */
1695 HWTEST_F(InputManagerImplTest, InputManagerImplTest_UpdateWindowInfo_002, TestSize.Level1)
1696 {
1697     CALL_TEST_DEBUG;
1698     WindowGroupInfo windowGroupInfo;
1699     WindowInfo window;
1700     window.id = 1;
1701     window.pid = 1000;
1702     window.uid = 10000;
1703 
1704     Rect pointerHotArea = {0, 0, 100, 100};
1705     window.pointerHotAreas.push_back(pointerHotArea);
1706     windowGroupInfo.windowsInfo.push_back(window);
1707     int32_t result = InputMgrImpl.UpdateWindowInfo(windowGroupInfo);
1708     EXPECT_EQ(result, PARAM_INPUT_INVALID);
1709 }
1710 
1711 /**
1712  * @tc.name: InputManagerImplTest_UpdateWindowInfo_003
1713  * @tc.desc: Test the funcation UpdateWindowInfo
1714  * @tc.type: FUNC
1715  * @tc.require:
1716  */
1717 HWTEST_F(InputManagerImplTest, InputManagerImplTest_UpdateWindowInfo_003, TestSize.Level1)
1718 {
1719     CALL_TEST_DEBUG;
1720     WindowGroupInfo windowGroupInfo;
1721     WindowInfo window;
1722     window.id = 1;
1723     window.pid = 1000;
1724     window.uid = 10000;
1725 
1726     Rect hotArea = {0, 0, 100, 100};
1727     window.defaultHotAreas.push_back(hotArea);
1728     window.pointerHotAreas.push_back(hotArea);
1729 
1730     window.pointerChangeAreas.push_back(1);
1731 
1732     windowGroupInfo.windowsInfo.push_back(window);
1733 
1734     int32_t result = InputMgrImpl.UpdateWindowInfo(windowGroupInfo);
1735     EXPECT_EQ(result, PARAM_INPUT_INVALID);
1736 }
1737 
1738 /**
1739  * @tc.name: InputManagerImplTest_UpdateWindowInfo_004
1740  * @tc.desc: Test the funcation UpdateWindowInfo
1741  * @tc.type: FUNC
1742  * @tc.require:
1743  */
1744 HWTEST_F(InputManagerImplTest, InputManagerImplTest_UpdateWindowInfo_004, TestSize.Level1)
1745 {
1746     CALL_TEST_DEBUG;
1747     WindowGroupInfo windowGroupInfo;
1748     windowGroupInfo.focusWindowId = 10;
1749     windowGroupInfo.displayId = 1;
1750 
1751     WindowInfo window;
1752     window.id = 1;
1753     window.pid = 1000;
1754     window.uid = 10000;
1755     window.area = {0, 0, 1920, 1080};
1756     Rect hotArea = {0, 0, 100, 100};
1757     window.defaultHotAreas.push_back(hotArea);
1758     window.pointerHotAreas.push_back(hotArea);
1759     windowGroupInfo.windowsInfo.push_back(window);
1760     int32_t result = InputMgrImpl.UpdateWindowInfo(windowGroupInfo);
1761     EXPECT_EQ(result, RET_OK);
1762 }
1763 
1764 /**
1765  * @tc.name: InputManagerImplTest_UpdateWindowInfo_005
1766  * @tc.desc: Test the funcation UpdateWindowInfo
1767  * @tc.type: FUNC
1768  * @tc.require:
1769  */
1770 HWTEST_F(InputManagerImplTest, InputManagerImplTest_UpdateWindowInfo_005, TestSize.Level1)
1771 {
1772     CALL_TEST_DEBUG;
1773     WindowGroupInfo windowGroupInfo;
1774     windowGroupInfo.focusWindowId = 10;
1775     windowGroupInfo.displayId = 1;
1776     WindowInfo window;
1777     window.id = 1;
1778     window.pid = 1000;
1779     window.uid = 10000;
1780     window.area = {0, 0, 1920, 1080};
1781     window.agentWindowId = 0;
1782     window.flags = 0;
1783     window.action = WINDOW_UPDATE_ACTION::ADD;
1784     window.displayId = 1;
1785     window.groupId = 1;
1786     window.zOrder = 1.0;
1787     Rect defaultHotArea = {0, 0, 1920, 1080};
1788     Rect pointerHotArea = {0, 0, 1920, 1080};
1789     window.defaultHotAreas.push_back(defaultHotArea);
1790     window.pointerHotAreas.push_back(pointerHotArea);
1791     for (int i = 0; i < WindowInfo::POINTER_CHANGEAREA_COUNT; i++) {
1792         window.pointerChangeAreas.push_back(i);
1793     }
1794 
1795     for (int i = 0; i < WindowInfo::WINDOW_TRANSFORM_SIZE; i++) {
1796         window.transform.push_back(1.0f);
1797     }
1798     windowGroupInfo.windowsInfo.push_back(window);
1799 
1800     int32_t result = InputMgrImpl.UpdateWindowInfo(windowGroupInfo);
1801     EXPECT_EQ(result, RET_OK);
1802 }
1803 
1804 /**
1805  * @tc.name  : AddInputEventFilter_Test002
1806  * @tc.desc  : Test AddInputEventFilter
1807  * @tc.type: FUNC
1808  * @tc.require:
1809  */
1810 HWTEST_F(InputManagerImplTest, AddInputEventFilter_Test002, TestSize.Level1)
1811 {
1812     CALL_TEST_DEBUG;
1813     std::shared_ptr<IInputEventFilter> filter = nullptr;
1814     int32_t priority = 100;
1815     uint32_t deviceTags = 1;
1816     int32_t result = InputMgrImpl.AddInputEventFilter(filter, priority, deviceTags);
1817     EXPECT_EQ(result, RET_ERR);
1818 
1819     filter = std::make_shared<InputEventFilterMock>();
1820     priority = INT32_MAX;
1821     deviceTags = 1;
1822     result = InputMgrImpl.AddInputEventFilter(filter, priority, deviceTags);
1823     EXPECT_TRUE(result > 0 || result == RET_ERR);
1824 }
1825 
1826 /**
1827  * @tc.name  : AddInputEventFilter_Test003
1828  * @tc.desc  : Test AddInputEventFilter
1829  * @tc.type: FUNC
1830  * @tc.require:
1831  */
1832 HWTEST_F(InputManagerImplTest, AddInputEventFilter_Test003, TestSize.Level1)
1833 {
1834     CALL_TEST_DEBUG;
1835     for (size_t i = 0; i < MAX_FILTER_NUM; ++i) {
1836         auto filter = std::make_shared<InputEventFilterMock>();
1837         int32_t result = InputMgrImpl.AddInputEventFilter(filter, 100, 1);
1838         EXPECT_NE(result, 0);
1839     }
1840 
1841     auto filter = std::make_shared<InputEventFilterMock>();
1842     int32_t result = InputMgrImpl.AddInputEventFilter(filter, 100, 1);
1843     EXPECT_EQ(result, RET_ERR);
1844 }
1845 
1846 /**
1847  * @tc.name  : AddInputEventFilter_Test004
1848  * @tc.desc  : Test AddInputEventFilter
1849  * @tc.type: FUNC
1850  * @tc.require:
1851  */
1852 HWTEST_F(InputManagerImplTest, AddInputEventFilter_Test004, TestSize.Level1)
1853 {
1854     CALL_TEST_DEBUG;
1855     auto filter1 = std::make_shared<InputEventFilterMock>();
1856     auto filter2 = std::make_shared<InputEventFilterMock>();
1857     int32_t result1 = InputMgrImpl.AddInputEventFilter(filter1, 100, 1);
1858     int32_t result2 =InputMgrImpl.AddInputEventFilter(filter2, 100, 1);
1859 
1860     EXPECT_NE(result1, 0);
1861     EXPECT_NE(result2, 0);
1862 }
1863 
1864 /**
1865  * @tc.name  : AddInputEventFilter_Test005
1866  * @tc.desc  : Test AddInputEventFilter
1867  * @tc.type: FUNC
1868  * @tc.require:
1869  */
1870 HWTEST_F(InputManagerImplTest, AddInputEventFilter_Test005, TestSize.Level1)
1871 {
1872     CALL_TEST_DEBUG;
1873     auto filter = std::make_shared<InputEventFilterMock>();
1874     int32_t priority = 100;
1875     uint32_t deviceTags = 1;
1876 
1877     int32_t result = InputMgrImpl.AddInputEventFilter(filter, priority, deviceTags);
1878     EXPECT_NE(result, 0);
1879 
1880     auto filter2 = std::make_shared<InputEventFilterMock>();
1881     int32_t result2 = InputMgrImpl.AddInputEventFilter(filter2, priority, deviceTags);
1882     EXPECT_NE(result, 0);
1883     EXPECT_EQ(result, result2);
1884 }
1885 
1886 /**
1887  * @tc.name  : RemoveInputEventFilter_Test002
1888  * @tc.desc  : Test RemoveInputEventFilter
1889  * @tc.type: FUNC
1890  * @tc.require:
1891  */
1892 HWTEST_F(InputManagerImplTest, RemoveInputEventFilter_Test002, TestSize.Level1)
1893 {
1894     CALL_TEST_DEBUG;
1895 
1896     InputMgrImpl.eventFilterServices_.clear();
1897     std::shared_ptr<IInputEventFilter> filter = std::make_shared<InputEventFilterMock>();
1898     int32_t filterId = InputMgrImpl.AddInputEventFilter(filter, 1, 0);
1899     EXPECT_GT(filterId, 0);
1900 
1901     int32_t result = InputMgrImpl.RemoveInputEventFilter(filterId + 1);
1902     EXPECT_EQ(result, RET_OK);
1903 }
1904 
1905 /**
1906  * @tc.name  : RemoveInputEventFilter_Test003
1907  * @tc.desc  : Test RemoveInputEventFilter
1908  * @tc.type: FUNC
1909  * @tc.require:
1910  */
1911 HWTEST_F(InputManagerImplTest, RemoveInputEventFilter_Test003, TestSize.Level1)
1912 {
1913     CALL_TEST_DEBUG;
1914     std::shared_ptr<IInputEventFilter> filter1 = std::make_shared<InputEventFilterMock>();
1915     std::shared_ptr<IInputEventFilter> filter2 = std::make_shared<InputEventFilterMock>();
1916     int32_t filterId1 = InputMgrImpl.AddInputEventFilter(filter1, 1, 0);
1917     int32_t filterId2 = InputMgrImpl.AddInputEventFilter(filter2, 2, 0);
1918     EXPECT_GT(filterId1, 0);
1919     EXPECT_GT(filterId2, 0);
1920 
1921     int32_t result = InputMgrImpl.RemoveInputEventFilter(-1);
1922     EXPECT_EQ(result, RET_OK);
1923 }
1924 
1925 /**
1926  * @tc.name  : RemoveInputEventFilter_Test004
1927  * @tc.desc  : Test RemoveInputEventFilter
1928  * @tc.type: FUNC
1929  * @tc.require:
1930  */
1931 HWTEST_F(InputManagerImplTest, RemoveInputEventFilter_Test004, TestSize.Level1)
1932 {
1933     CALL_TEST_DEBUG;
1934     std::shared_ptr<IInputEventFilter> filter = std::make_shared<InputEventFilterMock>();
1935     int32_t filterId = InputMgrImpl.AddInputEventFilter(filter, 1, 0);
1936     EXPECT_GT(filterId, 0);
1937 
1938     int32_t result1 = InputMgrImpl.RemoveInputEventFilter(filterId);
1939     EXPECT_EQ(result1, RET_OK);
1940 
1941     int32_t result2 = InputMgrImpl.RemoveInputEventFilter(filterId);
1942     EXPECT_EQ(result2, RET_OK);
1943 }
1944 
1945 /*
1946  * @tc.name: InputManagerImplTest_SubscribeKeyMonitor_001
1947  * @tc.desc: SubscribeKeyMonitor.
1948  * @tc.type: FUNC
1949  * @tc.require:
1950  */
1951 HWTEST_F(InputManagerImplTest, InputManagerTest_SubscribeKeyMonitor_001, TestSize.Level1)
1952 {
1953     CALL_TEST_DEBUG;
1954     KeyMonitorOption keyOption;
1955     std::function<void(std::shared_ptr<KeyEvent>)> callback;
1956     int32_t ret = InputMgrImpl.SubscribeKeyMonitor(keyOption, callback);
1957     EXPECT_NE(ret, -1);
1958 }
1959 
1960 /*
1961  * @tc.name: InputManagerImplTest_UnsubscribeKeyMonitor_001
1962  * @tc.desc: UnsubscribeKeyMonitor.
1963  * @tc.type: FUNC
1964  * @tc.require:
1965  */
1966 HWTEST_F(InputManagerImplTest, InputManagerTest_UnsubscribeKeyMonitor_001, TestSize.Level1)
1967 {
1968     CALL_TEST_DEBUG;
1969     int32_t subscriberId = 1;
1970     ASSERT_NO_FATAL_FAILURE(InputMgrImpl.UnsubscribeKeyMonitor(subscriberId));
1971     KeyMonitorOption keyOption;
1972     keyOption.SetKey(KeyEvent::KEYCODE_VOLUME_UP);
1973     keyOption.SetAction(KeyEvent::KEY_ACTION_UP);
1974     keyOption.SetRepeat(false);
__anone3e3a0100302(std::shared_ptr<KeyEvent> event) 1975     auto myCallback = [](std::shared_ptr<KeyEvent> event) {
1976         MMI_HILOGD("Add monitor success");
1977     };
1978     auto rlt = InputMgrImpl.SubscribeKeyMonitor(keyOption, myCallback);
1979     EXPECT_NE(rlt, 0);
1980 }
1981 
1982 /**
1983  * @tc.name: InputManagerImplTest_OnKeyEvent_02
1984  * @tc.desc: Test OnKeyEvent
1985  * @tc.type: FUNC
1986  * @tc.require:
1987  */
1988 HWTEST_F(InputManagerImplTest, InputManagerImplTest_OnKeyEvent_02, TestSize.Level1)
1989 {
1990     CALL_TEST_DEBUG;
1991     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1992     ASSERT_NE(keyEvent, nullptr);
1993 
1994     keyEvent->SetId(1001);
1995     keyEvent->SetKeyCode(KeyEvent::KEYCODE_A);
1996     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1997     EXPECT_NO_FATAL_FAILURE(InputMgrImpl.OnKeyEvent(keyEvent));
1998 }
1999 
2000 /**
2001  * @tc.name: InputManagerImplTest_OnKeyEvent_03
2002  * @tc.desc: Test OnKeyEvent
2003  * @tc.type: FUNC
2004  * @tc.require:
2005  */
2006 HWTEST_F(InputManagerImplTest, InputManagerImplTest_OnKeyEvent_03, TestSize.Level1)
2007 {
2008     CALL_TEST_DEBUG;
2009     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2010     ASSERT_NE(keyEvent, nullptr);
2011     keyEvent->SetId(1002);
2012     keyEvent->SetKeyCode(KeyEvent::KEYCODE_B);
2013     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
2014 
2015     auto eventHandler = std::make_shared<AppExecFwk::EventHandler>();
2016     std::shared_ptr<IInputEventConsumer> consumer = nullptr;
2017     int32_t ret = InputMgrImpl.SetWindowInputEventConsumer(consumer, eventHandler);
2018     EXPECT_EQ(ret, RET_ERR);
2019     EXPECT_NO_FATAL_FAILURE(InputMgrImpl.OnKeyEvent(keyEvent));
2020 }
2021 
2022 /**
2023  * @tc.name: InputManagerImplTest_OnPointerEvent_01
2024  * @tc.desc: Test OnPointerEvent
2025  * @tc.type: FUNC
2026  * @tc.require:
2027  */
2028 HWTEST_F(InputManagerImplTest, InputManagerImplTest_OnPointerEvent_01, TestSize.Level1)
2029 {
2030     CALL_TEST_DEBUG;
2031     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
2032     ASSERT_NE(pointerEvent, nullptr);
2033     pointerEvent->SetId(2002);
2034     pointerEvent->SetPointerId(1);
2035     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2036     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2037 
2038     auto eventHandler = std::make_shared<AppExecFwk::EventHandler>();
2039     std::shared_ptr<IInputEventConsumer> consumer;
2040     int32_t ret = InputMgrImpl.SetWindowInputEventConsumer(consumer, eventHandler);
2041     EXPECT_EQ(ret, RET_ERR);
2042     EXPECT_NO_FATAL_FAILURE(InputMgrImpl.OnPointerEvent(pointerEvent));
2043 
2044     pointerEvent->SetId(2004);
2045     pointerEvent->SetPointerId(1);
2046     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2047     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
2048     pointerEvent->SetButtonId(PointerEvent::MOUSE_BUTTON_LEFT);
2049     EXPECT_NO_FATAL_FAILURE(InputMgrImpl.OnPointerEvent(pointerEvent));
2050 }
2051 
2052 /**
2053  * @tc.name: InputManagerImplTest_OnPointerEvent_02
2054  * @tc.desc: Test OnPointerEvent
2055  * @tc.type: FUNC
2056  * @tc.require:
2057  */
2058 HWTEST_F(InputManagerImplTest, InputManagerImplTest_OnPointerEvent_02, TestSize.Level1)
2059 {
2060     CALL_TEST_DEBUG;
2061     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
2062     ASSERT_NE(pointerEvent, nullptr);
2063     pointerEvent->SetId(2005);
2064     pointerEvent->SetPointerId(1);
2065     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2066     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2067 
2068     auto eventHandler = std::make_shared<AppExecFwk::EventHandler>();
2069     std::shared_ptr<IInputEventConsumer> consumer;
2070     int32_t ret = InputMgrImpl.SetWindowInputEventConsumer(consumer, eventHandler);
2071     EXPECT_EQ(ret, RET_ERR);
2072     EXPECT_NO_FATAL_FAILURE(InputMgrImpl.OnPointerEvent(pointerEvent));
2073 
2074     pointerEvent->SetId(2006);
2075     pointerEvent->SetPointerId(1);
2076     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2077     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2078     EXPECT_NO_FATAL_FAILURE(InputMgrImpl.OnPointerEvent(pointerEvent));
2079 }
2080 
2081 /**
2082  * @tc.name: InputManagerImplTest_OnPointerEvent_03
2083  * @tc.desc: Test OnPointerEvent
2084  * @tc.type: FUNC
2085  * @tc.require:
2086  */
2087 HWTEST_F(InputManagerImplTest, InputManagerImplTest_OnPointerEvent_03, TestSize.Level1)
2088 {
2089     CALL_TEST_DEBUG;
2090     auto eventHandler = std::make_shared<AppExecFwk::EventHandler>();
2091     std::shared_ptr<IInputEventConsumer> consumer;
2092     int32_t ret = InputMgrImpl.SetWindowInputEventConsumer(consumer, eventHandler);
2093     EXPECT_EQ(ret, RET_ERR);
2094 
2095     std::shared_ptr<PointerEvent> pointerEventDown = PointerEvent::Create();
2096     ASSERT_NE(pointerEventDown, nullptr);
2097     pointerEventDown->SetId(2007);
2098     pointerEventDown->SetPointerId(1);
2099     pointerEventDown->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2100     pointerEventDown->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2101     EXPECT_NO_FATAL_FAILURE(InputMgrImpl.OnPointerEvent(pointerEventDown));
2102 
2103     std::shared_ptr<PointerEvent> pointerEventUp = PointerEvent::Create();
2104     ASSERT_NE(pointerEventUp, nullptr);
2105     pointerEventUp->SetId(2008);
2106     pointerEventUp->SetPointerId(1);
2107     pointerEventUp->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2108     pointerEventUp->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2109     EXPECT_NO_FATAL_FAILURE(InputMgrImpl.OnPointerEvent(pointerEventUp));
2110 
2111     std::shared_ptr<PointerEvent> pointerEventMove = PointerEvent::Create();
2112     ASSERT_NE(pointerEventMove, nullptr);
2113     pointerEventMove->SetId(2009);
2114     pointerEventMove->SetPointerId(1);
2115     pointerEventMove->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
2116     pointerEventMove->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2117     EXPECT_NO_FATAL_FAILURE(InputMgrImpl.OnPointerEvent(pointerEventMove));
2118 
2119     std::shared_ptr<PointerEvent> pointerEventCancel = PointerEvent::Create();
2120     ASSERT_NE(pointerEventCancel, nullptr);
2121     pointerEventCancel->SetId(2010);
2122     pointerEventCancel->SetPointerId(1);
2123     pointerEventCancel->SetPointerAction(PointerEvent::POINTER_ACTION_CANCEL);
2124     pointerEventCancel->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2125     EXPECT_NO_FATAL_FAILURE(InputMgrImpl.OnPointerEvent(pointerEventCancel));
2126 }
2127 
2128 /**
2129  * @tc.name: InputManagerImplTest_OnPointerEvent_04
2130  * @tc.desc: Test OnPointerEvent
2131  * @tc.type: FUNC
2132  * @tc.require:
2133  */
2134 HWTEST_F(InputManagerImplTest, InputManagerImplTest_OnPointerEvent_04, TestSize.Level1)
2135 {
2136     CALL_TEST_DEBUG;
2137     auto eventHandler = std::make_shared<AppExecFwk::EventHandler>();
2138     std::shared_ptr<IInputEventConsumer> consumer;
2139     int32_t ret = InputMgrImpl.SetWindowInputEventConsumer(consumer, eventHandler);
2140     EXPECT_EQ(ret, RET_ERR);
2141 
2142     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
2143     ASSERT_NE(pointerEvent, nullptr);
2144     pointerEvent->SetId(2014);
2145     pointerEvent->SetPointerId(1);
2146     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2147     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2148     EXPECT_NO_FATAL_FAILURE(InputMgrImpl.OnPointerEvent(pointerEvent));
2149 
2150     std::shared_ptr<PointerEvent> mouseEvent = PointerEvent::Create();
2151     ASSERT_NE(mouseEvent, nullptr);
2152     mouseEvent->SetId(2015);
2153     mouseEvent->SetPointerId(1);
2154     mouseEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2155     mouseEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
2156     mouseEvent->SetButtonId(PointerEvent::MOUSE_BUTTON_RIGHT);
2157     EXPECT_NO_FATAL_FAILURE(InputMgrImpl.OnPointerEvent(mouseEvent));
2158 }
2159 
2160 /**
2161  * @tc.name: InputManagerImplTest_TestPackDisplayData_005
2162  * @tc.desc: Test PackDisplayData_005
2163  * @tc.type: FUNC
2164  * @tc.require:
2165  */
2166 HWTEST_F(InputManagerImplTest, InputManagerImplTest_TestPackDisplayData_005, TestSize.Level1)
2167 {
2168     CALL_TEST_DEBUG;
2169     NetPacket pkt(MmiMessageId::DISPLAY_INFO);
2170     UserScreenInfo userScreenInfo;
2171     userScreenInfo.userId = 1001;
2172 
2173     for (int i = 0; i < 10000; i++) {
2174         ScreenInfo screenInfo;
2175         screenInfo.id = i;
2176         screenInfo.uniqueId = "screen_" + std::to_string(i);
2177         screenInfo.width = 1920;
2178         screenInfo.height = 1080;
2179         screenInfo.physicalWidth = 1920;
2180         screenInfo.physicalHeight = 1080;
2181         screenInfo.dpi = 240;
2182         screenInfo.ppi = 240;
2183         userScreenInfo.screens.push_back(screenInfo);
2184     }
2185     int32_t ret = InputMgrImpl.PackDisplayData(pkt, userScreenInfo);
2186     EXPECT_EQ(ret, RET_ERR);
2187 }
2188 
2189 /**
2190  * @tc.name: InputManagerImplTest_TestPackWindowGroupInfo_001
2191  * @tc.desc: Test PackWindowGroupInfo
2192  * @tc.type: FUNC
2193  * @tc.require:
2194  */
2195 HWTEST_F(InputManagerImplTest, InputManagerImplTest_TestPackWindowGroupInfo_001, TestSize.Level1)
2196 {
2197     CALL_TEST_DEBUG;
2198     NetPacket pkt(MmiMessageId::WINDOW_INFO);
2199     InputMgrImpl.windowGroupInfo_.focusWindowId = 100;
2200     InputMgrImpl.windowGroupInfo_.displayId = 1;
2201     WindowInfo windowInfo;
2202     windowInfo.id = 1;
2203     windowInfo.pid = 1234;
2204     windowInfo.uid = 5678;
2205     windowInfo.area = {0, 0, 1080, 1920};
2206     windowInfo.defaultHotAreas.push_back({100, 100, 200, 200});
2207     windowInfo.pointerHotAreas.push_back({150, 150, 100, 100});
2208     windowInfo.agentWindowId = 2;
2209     windowInfo.flags = 0;
2210     windowInfo.action = WINDOW_UPDATE_ACTION::ADD;
2211     windowInfo.displayId = 1;
2212     windowInfo.groupId = 1;
2213     windowInfo.zOrder = 1.0;
2214     windowInfo.pointerChangeAreas = {1, 2, 3, 4};
2215     windowInfo.transform = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0};
2216     windowInfo.windowType = 1;
2217     windowInfo.isSkipSelfWhenShowOnVirtualScreen = false;
2218     windowInfo.windowNameType = 0;
2219     windowInfo.rectChangeBySystem = false;
2220     InputMgrImpl.windowGroupInfo_.windowsInfo.push_back(windowInfo);
2221 
2222     int32_t result = InputMgrImpl.PackWindowGroupInfo(pkt);
2223     EXPECT_EQ(result, RET_OK);
2224     EXPECT_FALSE(pkt.ChkRWError());
2225 }
2226 
2227 /**
2228  * @tc.name: InputManagerImplTest_TestPackWindowGroupInfo_002
2229  * @tc.desc: Test PackWindowGroupInfo
2230  * @tc.type: FUNC
2231  * @tc.require:
2232  */
2233 HWTEST_F(InputManagerImplTest, InputManagerImplTest_TestPackWindowGroupInfo_002, TestSize.Level1)
2234 {
2235     CALL_TEST_DEBUG;
2236     NetPacket pkt(MmiMessageId::WINDOW_INFO);
2237     InputMgrImpl.windowGroupInfo_.focusWindowId = 50;
2238     InputMgrImpl.windowGroupInfo_.displayId = 2;
2239     int32_t result = InputMgrImpl.PackWindowGroupInfo(pkt);
2240     EXPECT_EQ(result, RET_OK);
2241     EXPECT_FALSE(pkt.ChkRWError());
2242 }
2243 } // namespace MMI
2244 } // namespace OHOS