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