• 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 
18 #include "proto.h"
19 
20 #include "input_event_handler.h"
21 #include "mmi_log.h"
22 #include "mmi_service.h"
23 
24 #undef MMI_LOG_TAG
25 #define MMI_LOG_TAG "MMIServerTest"
26 namespace OHOS {
27 namespace MMI {
28 namespace {
29 using namespace testing::ext;
30 } // namespace
31 
32 class MMIServerTest : public testing::Test {
33 public:
SetUpTestCase(void)34     static void SetUpTestCase(void) {}
TearDownTestCase(void)35     static void TearDownTestCase(void) {}
36 };
37 
38 /**
39  * @tc.name: MMIServerTest_OnThread_01
40  * @tc.desc: Test OnThread
41  * @tc.type: FUNC
42  * @tc.require:
43  */
44 HWTEST_F(MMIServerTest, MMIServerTest_OnThread_01, TestSize.Level1)
45 {
46     MMIService mmiService;
47     EpollEventType epollType;
48     epollType = EPOLL_EVENT_INPUT;
49     ASSERT_NO_FATAL_FAILURE(mmiService.OnThread());
50 }
51 
52 /**
53  * @tc.name: ShiftAppPointerEvent_001
54  * @tc.desc: Test the function ShiftAppPointerEvent
55  * @tc.type: FUNC
56  * @tc.require:
57  */
58 HWTEST_F(MMIServerTest, ShiftAppPointerEvent_001, TestSize.Level1)
59 {
60     MMIService mmiService;
61     ShiftWindowParam param;
62     param.sourceWindowId = -100;
63     param.targetWindowId = -200;
64     bool autoGenDown = true;
65     int32_t ret = mmiService.ShiftAppPointerEvent(param, autoGenDown);
66     EXPECT_NE(ret, RET_OK);
67 }
68 
69 /**
70  * @tc.name: MMIServerTest_OnThread_02
71  * @tc.desc: Test OnThread
72  * @tc.type: FUNC
73  * @tc.require:
74  */
75 HWTEST_F(MMIServerTest, MMIServerTest_OnThread_02, TestSize.Level1)
76 {
77     MMIService mmiService;
78     EpollEventType epollType;
79     epollType = EPOLL_EVENT_SOCKET;
80     ASSERT_NO_FATAL_FAILURE(mmiService.OnThread());
81 }
82 
83 /**
84  * @tc.name: MMIServerTest_OnThread_03
85  * @tc.desc: Test OnThread
86  * @tc.type: FUNC
87  * @tc.require:
88  */
89 HWTEST_F(MMIServerTest, MMIServerTest_OnThread_03, TestSize.Level1)
90 {
91     MMIService mmiService;
92     EpollEventType epollType;
93     epollType = EPOLL_EVENT_SIGNAL;
94     ASSERT_NO_FATAL_FAILURE(mmiService.OnThread());
95 }
96 
97 /**
98  * @tc.name: MMIServerTest_OnThread_04
99  * @tc.desc: Test OnThread
100  * @tc.type: FUNC
101  * @tc.require:
102  */
103 HWTEST_F(MMIServerTest, MMIServerTest_OnThread_04, TestSize.Level1)
104 {
105     MMIService mmiService;
106     EpollEventType epollType;
107     epollType = EPOLL_EVENT_ETASK;
108     ASSERT_NO_FATAL_FAILURE(mmiService.OnThread());
109 }
110 
111 /**
112  * @tc.name: MMIServerTest_EnableInputDevice_01
113  * @tc.desc: Test EnableInputDevice
114  * @tc.type: FUNC
115  * @tc.require:
116  */
117 HWTEST_F(MMIServerTest, MMIServerTest_EnableInputDevice_01, TestSize.Level1)
118 {
119     MMIService mmiService;
120     bool enable = true;
121     int32_t ret = mmiService.EnableInputDevice(enable);
122     EXPECT_EQ(ret, ETASKS_POST_SYNCTASK_FAIL);
123 }
124 
125 /**
126  * @tc.name: MMIServerTest_EnableInputDevice_02
127  * @tc.desc: Test EnableInputDevice
128  * @tc.type: FUNC
129  * @tc.require:
130  */
131 HWTEST_F(MMIServerTest, MMIServerTest_EnableInputDevice_02, TestSize.Level1)
132 {
133     MMIService mmiService;
134     bool enable = false;
135     int32_t ret = mmiService.EnableInputDevice(enable);
136     EXPECT_EQ(ret, ETASKS_POST_SYNCTASK_FAIL);
137 }
138 
139 /**
140  * @tc.name: MMIServerTest_OnDisconnected_01
141  * @tc.desc: Test OnDisconnected
142  * @tc.type: FUNC
143  * @tc.require:
144  */
145 HWTEST_F(MMIServerTest, MMIServerTest_OnDisconnected_01, TestSize.Level1)
146 {
147     MMIService mmiService;
148     SessionPtr session;
149     auto ret1 = mmiService.RemoveInputEventFilter(-1);
150     EXPECT_EQ(ret1, ETASKS_POST_SYNCTASK_FAIL);
151     ASSERT_NO_FATAL_FAILURE(mmiService.OnDisconnected(session));
152 }
153 
154 /**
155  * @tc.name: MMIServerTest_OnDisconnected_02
156  * @tc.desc: Test OnDisconnected
157  * @tc.type: FUNC
158  * @tc.require:
159  */
160 HWTEST_F(MMIServerTest, MMIServerTest_OnDisconnected_02, TestSize.Level1)
161 {
162     MMIService mmiService;
163     SessionPtr session;
164     auto ret1 = mmiService.RemoveInputEventFilter(2);
165     EXPECT_EQ(ret1, ETASKS_POST_SYNCTASK_FAIL);
166     ASSERT_NO_FATAL_FAILURE(mmiService.OnDisconnected(session));
167 }
168 
169 /**
170  * @tc.name: MMIServerTest_AddInputHandler_01
171  * @tc.desc: Test the function AddInputHandler
172  * @tc.type: FUNC
173  * @tc.require:
174  */
175 HWTEST_F(MMIServerTest, MMIServerTest_AddInputHandler_01, TestSize.Level1)
176 {
177     MMIService mmiService;
178     InputHandlerType handlerType = InputHandlerType::MONITOR;
179     HandleEventType eventType = HANDLE_EVENT_TYPE_KEY;
180     int32_t priority = 1;
181     uint32_t deviceTags = 3;
182     int32_t ret = mmiService.AddInputHandler(handlerType, eventType, priority, deviceTags);
183     EXPECT_NE(ret, RET_ERR);
184 }
185 
186 /**
187  * @tc.name: MMIServerTest_RemoveInputHandler_01
188  * @tc.desc: Test the function RemoveInputHandler
189  * @tc.type: FUNC
190  * @tc.require:
191  */
192 HWTEST_F(MMIServerTest, MMIServerTest_RemoveInputHandler_01, TestSize.Level1)
193 {
194     MMIService mmiService;
195     InputHandlerType handlerType = InputHandlerType::INTERCEPTOR;
196     HandleEventType eventType = HANDLE_EVENT_TYPE_POINTER;
197     int32_t priority = 1;
198     uint32_t deviceTags = 2;
199     int32_t ret = mmiService.RemoveInputHandler(handlerType, eventType, priority, deviceTags);
200     EXPECT_NE(ret, RET_ERR);
201 }
202 
203 /**
204  * @tc.name: AddEpollAndDelEpoll_001
205  * @tc.desc: Test the function AddEpoll and DelEpoll
206  * @tc.type: FUNC
207  * @tc.require:
208  */
209 HWTEST_F(MMIServerTest, AddEpollAndDelEpoll_001, TestSize.Level1)
210 {
211     MMIService mmiService;
212     int32_t fd = -1;
213     int32_t ret = mmiService.AddEpoll(EPOLL_EVENT_INPUT, fd);
214     EXPECT_EQ(ret, RET_ERR);
215     ret = mmiService.DelEpoll(EPOLL_EVENT_INPUT, fd);
216     EXPECT_EQ(ret, RET_ERR);
217     fd = 1;
218     ret = mmiService.AddEpoll(EPOLL_EVENT_INPUT, fd);
219     EXPECT_EQ(ret, RET_ERR);
220     ret = mmiService.DelEpoll(EPOLL_EVENT_INPUT, fd);
221     EXPECT_EQ(ret, RET_ERR);
222     ret = mmiService.AddEpoll(EPOLL_EVENT_END, fd);
223     EXPECT_EQ(ret, RET_ERR);
224     ret = mmiService.DelEpoll(EPOLL_EVENT_END, fd);
225     EXPECT_EQ(ret, RET_ERR);
226 }
227 
228 /**
229  * @tc.name: InitLibinputService_001
230  * @tc.desc: Test the function InitLibinputService
231  * @tc.type: FUNC
232  * @tc.require:
233  */
234 HWTEST_F(MMIServerTest, InitLibinputService_001, TestSize.Level1)
235 {
236     MMIService mmiService;
237     bool ret = mmiService.InitService();
238     EXPECT_FALSE(ret);
239     ret = mmiService.InitDelegateTasks();
240     EXPECT_FALSE(ret);
241 }
242 
243 /**
244  * @tc.name: AddAppDebugListener_001
245  * @tc.desc: Test the function AddAppDebugListener and RemoveAppDebugListener
246  * @tc.type: FUNC
247  * @tc.require:
248  */
249 HWTEST_F(MMIServerTest, AddAppDebugListener_001, TestSize.Level1)
250 {
251     MMIService mmiService;
252     ASSERT_NO_FATAL_FAILURE(mmiService.AddAppDebugListener());
253     ASSERT_NO_FATAL_FAILURE(mmiService.RemoveAppDebugListener());
254 }
255 
256 /**
257  * @tc.name: AllocSocketFd_001
258  * @tc.desc: Test the function AllocSocketFd
259  * @tc.type: FUNC
260  * @tc.require:
261  */
262 HWTEST_F(MMIServerTest, AllocSocketFd_001, TestSize.Level1)
263 {
264     MMIService mmiService;
265     const std::string programName = "programName";
266     const int32_t moduleType = 1;
267     int32_t toReturnClientFd = 1;
268     int32_t tokenType = 1;
269     int32_t ret = mmiService.AllocSocketFd(programName, moduleType, toReturnClientFd, tokenType);
270     EXPECT_NE(ret, RET_ERR);
271 }
272 
273 /**
274  * @tc.name: AddInputEventFilter_001
275  * @tc.desc: Test the function AddInputEventFilter and RemoveInputEventFilter
276  * @tc.type: FUNC
277  * @tc.require:
278  */
279 HWTEST_F(MMIServerTest, AddInputEventFilter_001, TestSize.Level1)
280 {
281     MMIService mmiService;
282     int32_t filterId = 1;
283     int32_t priority = 1;
284     uint32_t deviceTags = 1;
285     int32_t returnCode0 = 65142804;
286     int32_t returnCode = 65142786;
287     sptr<IEventFilter> filter;
288     int32_t ret = mmiService.AddInputEventFilter(filter, filterId, priority, deviceTags);
289     EXPECT_EQ(ret, returnCode);
290     ret = mmiService.RemoveInputEventFilter(filterId);
291     EXPECT_EQ(ret, returnCode0);
292 }
293 
294 /**
295  * @tc.name: OnConnected_001
296  * @tc.desc: Test the function OnConnected and OnDisconnected
297  * @tc.type: FUNC
298  * @tc.require:
299  */
300 HWTEST_F(MMIServerTest, OnConnected_001, TestSize.Level1)
301 {
302     MMIService mmiService;
303     SessionPtr session;
304     ASSERT_NO_FATAL_FAILURE(mmiService.OnConnected(session));
305     ASSERT_NO_FATAL_FAILURE(mmiService.OnDisconnected(session));
306 }
307 
308 /**
309  * @tc.name: SetCustomCursor_001
310  * @tc.desc: Test the function SetCustomCursor
311  * @tc.type: FUNC
312  * @tc.require:
313  */
314 HWTEST_F(MMIServerTest, SetCustomCursor_001, TestSize.Level1)
315 {
316     MMIService mmiService;
317     int32_t windowId = 1;
318     int32_t focusX = 200;
319     int32_t focusY = 500;
320     void* pixelMap = nullptr;
321     int32_t ret = mmiService.SetCustomCursor(windowId, focusX, focusY, pixelMap);
322     EXPECT_NE(ret, RET_ERR);
323 }
324 
325 /**
326  * @tc.name: SetMouseIcon_001
327  * @tc.desc: Test the function SetMouseIcon
328  * @tc.type: FUNC
329  * @tc.require:
330  */
331 HWTEST_F(MMIServerTest, SetMouseIcon_001, TestSize.Level1)
332 {
333     MMIService mmiService;
334     int32_t windowId = 1;
335     void* pixelMap = nullptr;
336     int32_t ret = mmiService.SetMouseIcon(windowId, pixelMap);
337     EXPECT_NE(ret, RET_OK);
338 }
339 
340 /**
341  * @tc.name: SetMouseHotSpot_001
342  * @tc.desc: Test the function SetMouseHotSpot
343  * @tc.type: FUNC
344  * @tc.require:
345  */
346 HWTEST_F(MMIServerTest, SetMouseHotSpot_001, TestSize.Level1)
347 {
348     MMIService mmiService;
349     int32_t pid = 1;
350     int32_t windowId = 1;
351     int32_t hotSpotX = 100;
352     int32_t hotSpotY = 200;
353     int32_t ret = mmiService.SetMouseHotSpot(pid, windowId, hotSpotX, hotSpotY);
354     EXPECT_EQ(ret, RET_ERR);
355 }
356 
357 /**
358  * @tc.name: SetNapStatus_001
359  * @tc.desc: Test the function SetNapStatus
360  * @tc.type: FUNC
361  * @tc.require:
362  */
363 HWTEST_F(MMIServerTest, SetNapStatus_001, TestSize.Level1)
364 {
365     MMIService mmiService;
366     int32_t pid = 1;
367     int32_t uid = 2;
368     std::string bundleName = "bundleName";
369     int32_t napStatus = 1;
370     int32_t ret = mmiService.SetNapStatus(pid, uid, bundleName, napStatus);
371     EXPECT_EQ(ret, RET_ERR);
372 }
373 
374 /**
375  * @tc.name: ReadMouseScrollRows_001
376  * @tc.desc: Test the function ReadMouseScrollRows
377  * @tc.type: FUNC
378  * @tc.require:
379  */
380 HWTEST_F(MMIServerTest, ReadMouseScrollRows_001, TestSize.Level1)
381 {
382     MMIService mmiService;
383     int32_t rows = 1;
384     int32_t ret = mmiService.ReadMouseScrollRows(rows);
385     EXPECT_EQ(ret, RET_OK);
386 }
387 
388 /**
389  * @tc.name: SetMousePrimaryButton_001
390  * @tc.desc: Test the function SetMousePrimaryButton
391  * @tc.type: FUNC
392  * @tc.require:
393  */
394 HWTEST_F(MMIServerTest, SetMousePrimaryButton_001, TestSize.Level1)
395 {
396     MMIService mmiService;
397     int32_t primaryButton = 1;
398     int32_t returnCode = 65142804;
399     int32_t ret = mmiService.SetMousePrimaryButton(primaryButton);
400     EXPECT_EQ(ret, returnCode);
401 }
402 
403 /**
404  * @tc.name: ReadMousePrimaryButton_001
405  * @tc.desc: Test the function ReadMousePrimaryButton
406  * @tc.type: FUNC
407  * @tc.require:
408  */
409 HWTEST_F(MMIServerTest, ReadMousePrimaryButton_001, TestSize.Level1)
410 {
411     MMIService mmiService;
412     int32_t primaryButton = 1;
413     int32_t ret = mmiService.ReadMousePrimaryButton(primaryButton);
414     EXPECT_EQ(ret, RET_OK);
415 }
416 
417 /**
418  * @tc.name: GetMousePrimaryButton_001
419  * @tc.desc: Test the function GetMousePrimaryButton
420  * @tc.type: FUNC
421  * @tc.require:
422  */
423 HWTEST_F(MMIServerTest, GetMousePrimaryButton_001, TestSize.Level1)
424 {
425     MMIService mmiService;
426     int32_t primaryButton = 1;
427     int32_t ret = mmiService.GetMousePrimaryButton(primaryButton);
428     EXPECT_NE(ret, RET_ERR);
429 }
430 
431 /**
432  * @tc.name: CheckPointerVisible_001
433  * @tc.desc: Test the function CheckPointerVisible
434  * @tc.type: FUNC
435  * @tc.require:
436  */
437 HWTEST_F(MMIServerTest, CheckPointerVisible_001, TestSize.Level1)
438 {
439     MMIService mmiService;
440     bool visible = true;
441     int32_t ret = mmiService.CheckPointerVisible(visible);
442     EXPECT_EQ(ret, RET_OK);
443 }
444 
445 /**
446  * @tc.name: MarkProcessed_001
447  * @tc.desc: Test the function MarkProcessed
448  * @tc.type: FUNC
449  * @tc.require:
450  */
451 HWTEST_F(MMIServerTest, MarkProcessed_001, TestSize.Level1)
452 {
453     MMIService mmiService;
454     int32_t eventType = 1;
455     int32_t eventId = 1;
456     int32_t ret = mmiService.MarkProcessed(eventType, eventId);
457     EXPECT_NE(ret, RET_ERR);
458 }
459 
460 /**
461  * @tc.name: ReadPointerColor_001
462  * @tc.desc: Test the function ReadPointerColor
463  * @tc.type: FUNC
464  * @tc.require:
465  */
466 HWTEST_F(MMIServerTest, ReadPointerColor_001, TestSize.Level1)
467 {
468     MMIService mmiService;
469     int32_t color = 1;
470     int32_t ret = mmiService.ReadPointerColor(color);
471     EXPECT_EQ(ret, RET_OK);
472 }
473 
474 /**
475  * @tc.name: NotifyNapOnline_001
476  * @tc.desc: Test the function NotifyNapOnline
477  * @tc.type: FUNC
478  * @tc.require:
479  */
480 HWTEST_F(MMIServerTest, NotifyNapOnline_001, TestSize.Level1)
481 {
482     MMIService mmiService;
483     int32_t ret = mmiService.NotifyNapOnline();
484     EXPECT_EQ(ret, RET_OK);
485 }
486 
487 /**
488  * @tc.name: RemoveInputEventObserver_001
489  * @tc.desc: Test the function RemoveInputEventObserver
490  * @tc.type: FUNC
491  * @tc.require:
492  */
493 HWTEST_F(MMIServerTest, RemoveInputEventObserver_001, TestSize.Level1)
494 {
495     MMIService mmiService;
496     int32_t ret = mmiService.RemoveInputEventObserver();
497     EXPECT_EQ(ret, RET_OK);
498 }
499 
500 /**
501  * @tc.name: ClearWindowPointerStyle_001
502  * @tc.desc: Test the function ClearWindowPointerStyle
503  * @tc.type: FUNC
504  * @tc.require:
505  */
506 HWTEST_F(MMIServerTest, ClearWindowPointerStyle_001, TestSize.Level1)
507 {
508     MMIService mmiService;
509     int32_t pid = 1;
510     int32_t windowId = 2;
511     int32_t ret = mmiService.ClearWindowPointerStyle(pid, windowId);
512     EXPECT_EQ(ret, RET_ERR);
513 }
514 
515 /**
516  * @tc.name: ReadHoverScrollState_001
517  * @tc.desc: Test the function ReadHoverScrollState
518  * @tc.type: FUNC
519  * @tc.require:
520  */
521 HWTEST_F(MMIServerTest, ReadHoverScrollState_001, TestSize.Level1)
522 {
523     MMIService mmiService;
524     bool state = true;
525     int32_t ret = mmiService.ReadHoverScrollState(state);
526     EXPECT_EQ(ret, RET_OK);
527 }
528 
529 /**
530  * @tc.name: OnSupportKeys_001
531  * @tc.desc: Test the function OnSupportKeys
532  * @tc.type: FUNC
533  * @tc.require:
534  */
535 HWTEST_F(MMIServerTest, OnSupportKeys_001, TestSize.Level1)
536 {
537     MMIService mmiService;
538     int32_t deviceId = 1;
539     int32_t return_code = 401;
540     std::vector<int32_t> keys{ 1 };
541     std::vector<bool> keystroke{ true, true };
542     std::vector<bool> keystroke1{ true, true, true, true, true, true };
543     int32_t ret = mmiService.OnSupportKeys(deviceId, keys, keystroke);
544     EXPECT_EQ(ret, return_code);
545     ret = mmiService.OnSupportKeys(deviceId, keys, keystroke1);
546     EXPECT_NE(ret, RET_ERR);
547 }
548 
549 /**
550  * @tc.name: SupportKeys_001
551  * @tc.desc: Test the function SupportKeys
552  * @tc.type: FUNC
553  * @tc.require:
554  */
555 HWTEST_F(MMIServerTest, SupportKeys_001, TestSize.Level1)
556 {
557     MMIService mmiService;
558     int32_t deviceId = 1;
559     int32_t returnCode = 65142804;
560     std::vector<int32_t> keys{ 1 };
561     std::vector<bool> keystroke{ true, true };
562     int32_t ret = mmiService.SupportKeys(deviceId, keys, keystroke);
563     EXPECT_EQ(ret, returnCode);
564 }
565 
566 /**
567  * @tc.name: OnGetDeviceIds_001
568  * @tc.desc: Test the function OnGetDeviceIds
569  * @tc.type: FUNC
570  * @tc.require:
571  */
572 HWTEST_F(MMIServerTest, OnGetDeviceIds_001, TestSize.Level1)
573 {
574     MMIService mmiService;
575     std::vector<int32_t> ids{ 1 };
576     int32_t ret = mmiService.OnGetDeviceIds(ids);
577     EXPECT_EQ(ret, RET_OK);
578 }
579 
580 /**
581  * @tc.name: GetDeviceIds_001
582  * @tc.desc: Test the function GetDeviceIds
583  * @tc.type: FUNC
584  * @tc.require:
585  */
586 HWTEST_F(MMIServerTest, GetDeviceIds_001, TestSize.Level1)
587 {
588     MMIService mmiService;
589     std::vector<int32_t> ids{ 1 };
590     int32_t ret = mmiService.GetDeviceIds(ids);
591     EXPECT_NE(ret, RET_ERR);
592 }
593 
594 /**
595  * @tc.name: OnGetDevice_001
596  * @tc.desc: Test the function OnGetDevice
597  * @tc.type: FUNC
598  * @tc.require:
599  */
600 HWTEST_F(MMIServerTest, OnGetDevice_001, TestSize.Level1)
601 {
602     MMIService mmiService;
603     int32_t deviceId = 1;
604     int32_t return_code = 401;
605     std::shared_ptr<InputDevice> inputDevice = std::make_shared<InputDevice>();
606     int32_t ret = mmiService.OnGetDevice(deviceId, inputDevice);
607     EXPECT_EQ(ret, return_code);
608 }
609 
610 /**
611  * @tc.name: GetDevice_001
612  * @tc.desc: Test the function GetDevice
613  * @tc.type: FUNC
614  * @tc.require:
615  */
616 HWTEST_F(MMIServerTest, GetDevice_001, TestSize.Level1)
617 {
618     MMIService mmiService;
619     int32_t returnCode = 65142804;
620     int32_t deviceId = 1;
621     std::shared_ptr<InputDevice> inputDevice = std::make_shared<InputDevice>();
622     int32_t ret = mmiService.GetDevice(deviceId, inputDevice);
623     EXPECT_EQ(ret, returnCode);
624 }
625 
626 /**
627  * @tc.name: OnRegisterDevListener_001
628  * @tc.desc: Test the function OnRegisterDevListener
629  * @tc.type: FUNC
630  * @tc.require:
631  */
632 HWTEST_F(MMIServerTest, OnRegisterDevListener_001, TestSize.Level1)
633 {
634     MMIService mmiService;
635     int32_t pid = 1;
636     int32_t ret = mmiService.OnRegisterDevListener(pid);
637     EXPECT_EQ(ret, RET_ERR);
638 }
639 
640 /**
641  * @tc.name: RegisterDevListener_001
642  * @tc.desc: Test the function RegisterDevListener and OnUnregisterDevListener
643  * @tc.type: FUNC
644  * @tc.require:
645  */
646 HWTEST_F(MMIServerTest, RegisterDevListener_001, TestSize.Level1)
647 {
648     MMIService mmiService;
649     int32_t pid = 1;
650     int32_t ret = mmiService.RegisterDevListener();
651     EXPECT_NE(ret, RET_ERR);
652     ret = mmiService.UnregisterDevListener();
653     EXPECT_NE(ret, RET_ERR);
654     ret = mmiService.OnUnregisterDevListener(pid);
655     EXPECT_EQ(ret, RET_OK);
656 }
657 
658 /**
659  * @tc.name: OnGetKeyboardType_001
660  * @tc.desc: Test the function OnGetKeyboardType
661  * @tc.type: FUNC
662  * @tc.require:
663  */
664 HWTEST_F(MMIServerTest, OnGetKeyboardType_001, TestSize.Level1)
665 {
666     MMIService mmiService;
667     int32_t deviceId = 1;
668     int32_t keyboardType = 1;
669     int32_t return_code = 401;
670     int32_t ret = mmiService.OnGetKeyboardType(deviceId, keyboardType);
671     EXPECT_EQ(ret, return_code);
672 }
673 
674 /**
675  * @tc.name: GetKeyboardType_001
676  * @tc.desc: Test the function GetKeyboardType
677  * @tc.type: FUNC
678  * @tc.require:
679  */
680 HWTEST_F(MMIServerTest, GetKeyboardType_001, TestSize.Level1)
681 {
682     MMIService mmiService;
683     int32_t returnCode = 65142804;
684     int32_t deviceId = 1;
685     int32_t keyboardType = 1;
686     int32_t ret = mmiService.GetKeyboardType(deviceId, keyboardType);
687     EXPECT_EQ(ret, returnCode);
688 }
689 
690 /**
691  * @tc.name: GetKeyboardRepeatDelay_001
692  * @tc.desc: Test the function GetKeyboardRepeatDelay
693  * @tc.type: FUNC
694  * @tc.require:
695  */
696 HWTEST_F(MMIServerTest, GetKeyboardRepeatDelay_001, TestSize.Level1)
697 {
698     MMIService mmiService;
699     int32_t returnCode = 65142804;
700     int32_t delay = 1;
701     int32_t ret = mmiService.GetKeyboardRepeatDelay(delay);
702     EXPECT_EQ(ret, returnCode);
703 }
704 
705 /**
706  * @tc.name: GetKeyboardRepeatRate_001
707  * @tc.desc: Test the function GetKeyboardRepeatRate
708  * @tc.type: FUNC
709  * @tc.require:
710  */
711 HWTEST_F(MMIServerTest, GetKeyboardRepeatRate_001, TestSize.Level1)
712 {
713     MMIService mmiService;
714     int32_t returnCode = 65142804;
715     int32_t rate = 1;
716     int32_t ret = mmiService.GetKeyboardRepeatRate(rate);
717     EXPECT_EQ(ret, returnCode);
718 }
719 
720 /**
721  * @tc.name: CheckAddInput_001
722  * @tc.desc: Test the function CheckAddInput
723  * @tc.type: FUNC
724  * @tc.require:
725  */
726 HWTEST_F(MMIServerTest, CheckAddInput_001, TestSize.Level1)
727 {
728     MMIService mmiService;
729     int32_t returnCode = 65142786;
730     int32_t pid = 1;
731     InputHandlerType handlerType = InputHandlerType::MONITOR;
732     HandleEventType eventType = 10;
733     int32_t priority = 1;
734     uint32_t deviceTags = 1;
735     int32_t ret = mmiService.CheckAddInput(pid, handlerType, eventType, priority, deviceTags);
736     EXPECT_EQ(ret, returnCode);
737 }
738 
739 /**
740  * @tc.name: AddInputHandler_001
741  * @tc.desc: Test the function AddInputHandler
742  * @tc.type: FUNC
743  * @tc.require:
744  */
745 HWTEST_F(MMIServerTest, AddInputHandler_001, TestSize.Level1)
746 {
747     MMIService mmiService;
748     InputHandlerType handlerType = InputHandlerType::INTERCEPTOR;
749     HandleEventType eventType = 10;
750     int32_t priority = 1;
751     uint32_t deviceTags = 1;
752     int32_t ret = mmiService.AddInputHandler(handlerType, eventType, priority, deviceTags);
753     EXPECT_NE(ret, RET_ERR);
754 }
755 
756 /**
757  * @tc.name: CheckRemoveInput_001
758  * @tc.desc: Test the function CheckRemoveInput
759  * @tc.type: FUNC
760  * @tc.require:
761  */
762 HWTEST_F(MMIServerTest, CheckRemoveInput_001, TestSize.Level1)
763 {
764     MMIService mmiService;
765     int32_t returnCode = 65142786;
766     int32_t pid = 1;
767     InputHandlerType handlerType = InputHandlerType::INTERCEPTOR;
768     HandleEventType eventType = 1;
769     int32_t priority = 1;
770     uint32_t deviceTags = 1;
771     int32_t ret = mmiService.CheckRemoveInput(pid, handlerType, eventType, priority, deviceTags);
772     EXPECT_EQ(ret, returnCode);
773 }
774 
775 /**
776  * @tc.name: RemoveInputHandler_001
777  * @tc.desc: Test the function RemoveInputHandler
778  * @tc.type: FUNC
779  * @tc.require:
780  */
781 HWTEST_F(MMIServerTest, RemoveInputHandler_001, TestSize.Level1)
782 {
783     MMIService mmiService;
784     InputHandlerType handlerType = InputHandlerType::INTERCEPTOR;
785     HandleEventType eventType = 1;
786     int32_t priority = 1;
787     uint32_t deviceTags = 1;
788     int32_t ret = mmiService.RemoveInputHandler(handlerType, eventType, priority, deviceTags);
789     EXPECT_NE(ret, RET_ERR);
790 }
791 
792 /**
793  * @tc.name: CheckMarkConsumed_001
794  * @tc.desc: Test the function CheckMarkConsumed
795  * @tc.type: FUNC
796  * @tc.require:
797  */
798 HWTEST_F(MMIServerTest, CheckMarkConsumed_001, TestSize.Level1)
799 {
800     MMIService mmiService;
801     int32_t returnCode = 65142786;
802     int32_t pid = 1;
803     int32_t eventId = 1;
804     int32_t ret = mmiService.CheckMarkConsumed(pid, eventId);
805     EXPECT_EQ(ret, returnCode);
806 }
807 
808 /**
809  * @tc.name: MoveMouseEvent_001
810  * @tc.desc: Test the function MoveMouseEvent
811  * @tc.type: FUNC
812  * @tc.require:
813  */
814 HWTEST_F(MMIServerTest, MoveMouseEvent_001, TestSize.Level1)
815 {
816     MMIService mmiService;
817     int32_t offsetX = 100;
818     int32_t offsetY = 200;
819     int32_t ret = mmiService.MoveMouseEvent(offsetX, offsetY);
820     EXPECT_NE(ret, RET_ERR);
821 }
822 
823 /**
824  * @tc.name: CheckInjectKeyEvent_001
825  * @tc.desc: Test the function CheckInjectKeyEvent
826  * @tc.type: FUNC
827  * @tc.require:
828  */
829 HWTEST_F(MMIServerTest, CheckInjectKeyEvent_001, TestSize.Level1)
830 {
831     MMIService mmiService;
832     int32_t returnCode = 65142786;
833     std::shared_ptr<KeyEvent> Event{ nullptr };
834     int32_t pid = 1;
835     bool isNativeInject = false;
836     int32_t ret = mmiService.CheckInjectKeyEvent(Event, pid, isNativeInject);
837     EXPECT_EQ(ret, returnCode);
838 }
839 
840 /**
841  * @tc.name: OnAddSystemAbility_001
842  * @tc.desc: Test the function OnAddSystemAbility
843  * @tc.type: FUNC
844  * @tc.require:
845  */
846 HWTEST_F(MMIServerTest, OnAddSystemAbility_001, TestSize.Level1)
847 {
848     MMIService mmiService;
849     int32_t systemAbilityId = 1;
850     std::string deviceId = "device_id";
851     systemAbilityId = RES_SCHED_SYS_ABILITY_ID;
852     ASSERT_NO_FATAL_FAILURE(mmiService.OnAddSystemAbility(systemAbilityId, deviceId));
853     systemAbilityId = COMMON_EVENT_SERVICE_ID;
854     ASSERT_NO_FATAL_FAILURE(mmiService.OnAddSystemAbility(systemAbilityId, deviceId));
855     systemAbilityId = APP_MGR_SERVICE_ID;
856     ASSERT_NO_FATAL_FAILURE(mmiService.OnAddSystemAbility(systemAbilityId, deviceId));
857 }
858 
859 /**
860  * @tc.name: SubscribeKeyEvent_001
861  * @tc.desc: Test the function SubscribeKeyEvent
862  * @tc.type: FUNC
863  * @tc.require:
864  */
865 HWTEST_F(MMIServerTest, SubscribeKeyEvent_001, TestSize.Level1)
866 {
867     MMIService mmiService;
868     int32_t subscribeId = 1;
869     std::shared_ptr<KeyOption> option = std::make_shared<KeyOption>();
870     int32_t ret = mmiService.SubscribeKeyEvent(subscribeId, option);
871     EXPECT_NE(ret, RET_ERR);
872     ret = mmiService.UnsubscribeKeyEvent(subscribeId);
873     EXPECT_NE(ret, RET_ERR);
874 }
875 
876 /**
877  * @tc.name: GetDisplayBindInfo_001
878  * @tc.desc: Test the function GetDisplayBindInfo
879  * @tc.type: FUNC
880  * @tc.require:
881  */
882 HWTEST_F(MMIServerTest, GetDisplayBindInfo_001, TestSize.Level1)
883 {
884     MMIService mmiService;
885     DisplayBindInfos infos;
886     int32_t ret = mmiService.GetDisplayBindInfo(infos);
887     EXPECT_NE(ret, RET_ERR);
888 }
889 
890 /**
891  * @tc.name: SetDisplayBind_001
892  * @tc.desc: Test the function SetDisplayBind
893  * @tc.type: FUNC
894  * @tc.require:
895  */
896 HWTEST_F(MMIServerTest, SetDisplayBind_001, TestSize.Level1)
897 {
898     MMIService mmiService;
899     int32_t deviceId = 1;
900     int32_t displayId = 2;
901     std::string msg = "test";
902     int32_t ret = mmiService.SetDisplayBind(deviceId, displayId, msg);
903     EXPECT_NE(ret, RET_ERR);
904 }
905 
906 /**
907  * @tc.name: SetFunctionKeyState_001
908  * @tc.desc: Test the function SetFunctionKeyState
909  * @tc.type: FUNC
910  * @tc.require:
911  */
912 HWTEST_F(MMIServerTest, SetFunctionKeyState_001, TestSize.Level1)
913 {
914     MMIService mmiService;
915     int32_t funcKey = 1;
916     bool enable = true;
917     bool state = false;
918     int32_t ret = mmiService.SetFunctionKeyState(funcKey, enable);
919     EXPECT_NE(ret, RET_ERR);
920     ret = mmiService.GetFunctionKeyState(funcKey, state);
921     EXPECT_NE(ret, RET_ERR);
922 }
923 
924 /**
925  * @tc.name: OnDelegateTask_001
926  * @tc.desc: Test the function OnDelegateTask
927  * @tc.type: FUNC
928  * @tc.require:
929  */
930 HWTEST_F(MMIServerTest, OnDelegateTask_001, TestSize.Level1)
931 {
932     MMIService mmiService;
933     epoll_event ev;
934     ev.events = 0;
935     ASSERT_NO_FATAL_FAILURE(mmiService.OnDelegateTask(ev));
936     ev.events = 1;
937     ASSERT_NO_FATAL_FAILURE(mmiService.OnDelegateTask(ev));
938 }
939 
940 /**
941  * @tc.name: OnThread_001
942  * @tc.desc: Test the function OnThread
943  * @tc.type: FUNC
944  * @tc.require:
945  */
946 HWTEST_F(MMIServerTest, OnThread_001, TestSize.Level1)
947 {
948     MMIService mmiService;
949     ASSERT_NO_FATAL_FAILURE(mmiService.OnThread());
950 }
951 
952 /**
953  * @tc.name: InitSignalHandler_001
954  * @tc.desc: Test the function InitSignalHandler
955  * @tc.type: FUNC
956  * @tc.require:
957  */
958 HWTEST_F(MMIServerTest, InitSignalHandler_001, TestSize.Level1)
959 {
960     MMIService mmiService;
961     bool ret = mmiService.InitSignalHandler();
962     EXPECT_EQ(ret, false);
963 }
964 
965 /**
966  * @tc.name: AddReloadDeviceTimer_001
967  * @tc.desc: Test the function AddReloadDeviceTimer
968  * @tc.type: FUNC
969  * @tc.require:
970  */
971 HWTEST_F(MMIServerTest, AddReloadDeviceTimer_001, TestSize.Level1)
972 {
973     MMIService mmiService;
974     ASSERT_NO_FATAL_FAILURE(mmiService.AddReloadDeviceTimer());
975 }
976 
977 /**
978  * @tc.name: Dump_001
979  * @tc.desc: Test the function Dump
980  * @tc.type: FUNC
981  * @tc.require:
982  */
983 HWTEST_F(MMIServerTest, Dump_001, TestSize.Level1)
984 {
985     MMIService mmiService;
986     int32_t fd = -1;
987     std::vector<std::u16string> args;
988     int32_t ret = mmiService.Dump(fd, args);
989     EXPECT_EQ(ret, DUMP_PARAM_ERR);
990     fd = 1;
991     ret = mmiService.Dump(fd, args);
992     EXPECT_EQ(ret, DUMP_PARAM_ERR);
993 }
994 
995 /**
996  * @tc.name: SetMouseCaptureMode_001
997  * @tc.desc: Test the function SetMouseCaptureMode
998  * @tc.type: FUNC
999  * @tc.require:
1000  */
1001 HWTEST_F(MMIServerTest, SetMouseCaptureMode_001, TestSize.Level1)
1002 {
1003     MMIService mmiService;
1004     int32_t windowId = 1;
1005     bool isCaptureMode = false;
1006     int32_t ret = mmiService.SetMouseCaptureMode(windowId, isCaptureMode);
1007     EXPECT_NE(ret, RET_ERR);
1008     isCaptureMode = true;
1009     ret = mmiService.SetMouseCaptureMode(windowId, isCaptureMode);
1010     EXPECT_NE(ret, RET_ERR);
1011 }
1012 
1013 /**
1014  * @tc.name: OnGetWindowPid_001
1015  * @tc.desc: Test the function OnGetWindowPid
1016  * @tc.type: FUNC
1017  * @tc.require:
1018  */
1019 HWTEST_F(MMIServerTest, OnGetWindowPid_001, TestSize.Level1)
1020 {
1021     MMIService mmiService;
1022     int32_t windowId = 1;
1023     int32_t windowPid = 1;
1024     int32_t ret = mmiService.OnGetWindowPid(windowId, windowPid);
1025     EXPECT_EQ(ret, RET_ERR);
1026 }
1027 
1028 /**
1029  * @tc.name: GetWindowPid_001
1030  * @tc.desc: Test the function GetWindowPid
1031  * @tc.type: FUNC
1032  * @tc.require:
1033  */
1034 HWTEST_F(MMIServerTest, GetWindowPid_001, TestSize.Level1)
1035 {
1036     MMIService mmiService;
1037     int32_t windowId = 1;
1038     int32_t ret = mmiService.GetWindowPid(windowId);
1039     EXPECT_NE(ret, RET_ERR);
1040 }
1041 
1042 /**
1043  * @tc.name: CheckPidPermission_001
1044  * @tc.desc: Test the function CheckPidPermission
1045  * @tc.type: FUNC
1046  * @tc.require:
1047  */
1048 HWTEST_F(MMIServerTest, CheckPidPermission_001, TestSize.Level1)
1049 {
1050     MMIService mmiService;
1051     int32_t pid = 10;
1052     int32_t ret = mmiService.CheckPidPermission(pid);
1053     EXPECT_EQ(ret, RET_ERR);
1054 }
1055 
1056 /**
1057  * @tc.name: SetShieldStatus_001
1058  * @tc.desc: Test the function SetShieldStatus
1059  * @tc.type: FUNC
1060  * @tc.require:
1061  */
1062 HWTEST_F(MMIServerTest, SetShieldStatus_001, TestSize.Level1)
1063 {
1064     MMIService mmiService;
1065     int32_t returnCode = 65142804;
1066     int32_t shieldMode = 1;
1067     bool isShield = 0;
1068     int32_t ret = mmiService.SetShieldStatus(shieldMode, isShield);
1069     EXPECT_EQ(ret, returnCode);
1070     ret = mmiService.GetShieldStatus(shieldMode, isShield);
1071     EXPECT_EQ(ret, returnCode);
1072 }
1073 
1074 /**
1075  * @tc.name: MMIServerTest_InitService
1076  * @tc.desc: Test Init Service
1077  * @tc.type: FUNC
1078  * @tc.require:
1079  */
1080 HWTEST_F(MMIServerTest, MMIServerTest_InitService, TestSize.Level1)
1081 {
1082     MMIService service;
1083     service.state_ = ServiceRunningState::STATE_RUNNING;
1084     ASSERT_FALSE(service.InitService());
1085     service.state_ = ServiceRunningState::STATE_NOT_START;
1086     service.mmiFd_ = 1000;
1087     ASSERT_FALSE(service.InitService());
1088 }
1089 
1090 /**
1091  * @tc.name: MMIServerTest_OnAppDebugStoped_01
1092  * @tc.desc: Test OnAppDebugStoped
1093  * @tc.type: FUNC
1094  * @tc.require:
1095  */
1096 HWTEST_F(MMIServerTest, MMIServerTest_OnAppDebugStoped_01, TestSize.Level1)
1097 {
1098     AppDebugListener listener;
1099     std::vector<AppExecFwk::AppDebugInfo> debugInfos(1);
1100     ASSERT_NO_FATAL_FAILURE(listener.OnAppDebugStoped(debugInfos));
1101     listener.appDebugPid_ = 4;
1102     ASSERT_NO_FATAL_FAILURE(listener.OnAppDebugStoped(debugInfos));
1103 }
1104 } // namespace MMI
1105 } // namespace OHOS