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