1 /* 2 * Copyright (C) 2023-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 "joystick_event_normalize.h" 19 #include "mmi_log.h" 20 #include "define_multimodal.h" 21 #include "input_device_manager.h" 22 23 #undef MMI_LOG_DOMAIN 24 #define MMI_LOG_DOMAIN MMI_LOG_DISPATCH 25 26 #undef MMI_LOG_TAG 27 #define MMI_LOG_TAG "JoystickEventNormalizeTest" 28 29 struct udev_device { 30 uint32_t tags; 31 }; 32 33 struct libinput_device { 34 struct udev_device udevDev; 35 unsigned int busType; 36 unsigned int version; 37 unsigned int product; 38 unsigned int vendor; 39 std::string name; 40 }; 41 42 namespace OHOS { 43 namespace MMI { 44 namespace { 45 using namespace testing::ext; 46 } // namespace 47 48 class JoystickEventNormalizeTest : public testing::Test { 49 public: SetUpTestCase(void)50 static void SetUpTestCase(void) {} TearDownTestCase(void)51 static void TearDownTestCase(void) {} SetUp()52 void SetUp() {} TearDown()53 void TearDown() {} 54 }; 55 56 /** 57 * @tc.name: JoystickEventNormalizeTest_CheckIntention 58 * @tc.desc: Test GetMouseCoordsX 59 * @tc.type: FUNC 60 * @tc.require: 61 */ 62 HWTEST_F(JoystickEventNormalizeTest, JoystickEventNormalizeTest_CheckIntention, TestSize.Level1) 63 { 64 CALL_TEST_DEBUG; 65 auto joystickEvent = new JoystickEventNormalize(); 66 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 67 pointerEvent->SetDeviceId(2); 68 std::shared_ptr<JoystickEventProcessor> proceSsor; 69 struct libinput_device libDev { 70 .udevDev { 2 }, 71 .busType = 1, 72 .version = 1, 73 .product = 1, 74 .vendor = 1, 75 .name = "test", 76 }; 77 joystickEvent->processors_.insert( 78 pair<struct libinput_device*, std::shared_ptr<JoystickEventProcessor>>(&libDev, proceSsor)); 79 ASSERT_NO_FATAL_FAILURE( __anon1d14bc240202(std::shared_ptr<KeyEvent>) 80 joystickEvent->CheckIntention(pointerEvent, [=] (std::shared_ptr<KeyEvent>) { return; })); 81 } 82 83 /** 84 * @tc.name: JoystickEventNormalizeTest_GetProcessor 85 * @tc.desc: Test GetProcessor 86 * @tc.type: FUNC 87 * @tc.require: 88 */ 89 HWTEST_F(JoystickEventNormalizeTest, JoystickEventNormalizeTest_GetProcessor, TestSize.Level1) 90 { 91 CALL_TEST_DEBUG; 92 auto joystickEvent = new JoystickEventNormalize(); 93 libinput_device libDev; 94 ASSERT_NE(joystickEvent->GetProcessor(&libDev), nullptr); 95 } 96 97 /** 98 * @tc.name: JoystickEventNormalizeTest_FindProcessor 99 * @tc.desc: Test FindProcessor 100 * @tc.type: FUNC 101 * @tc.require: 102 */ 103 HWTEST_F(JoystickEventNormalizeTest, JoystickEventNormalizeTest_FindProcessor, TestSize.Level1) 104 { 105 CALL_TEST_DEBUG; 106 auto joystickEvent = new JoystickEventNormalize(); 107 int32_t deviceId = 2; 108 ASSERT_EQ(joystickEvent->FindProcessor(deviceId), nullptr); 109 } 110 } // namespace MMI 111 } // namespace OHOS 112