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 <cstdio>
17 #include <gtest/gtest.h>
18 
19 #include "joystick_transform_processor.h"
20 #include "libinput.h"
21 #include "libinput-private.h"
22 #include "mmi_log.h"
23 
24 #undef MMI_LOG_TAG
25 #define MMI_LOG_TAG "JoystickTransformProcessorTest"
26 
27 namespace OHOS {
28 namespace MMI {
29 namespace {
30 using namespace testing::ext;
31 }
32 class JoystickTransformProcessorTest : public testing::Test {
33 public:
SetUpTestCase(void)34     static void SetUpTestCase(void) {}
TearDownTestCase(void)35     static void TearDownTestCase(void) {}
SetUp()36     void SetUp() {}
TearDown()37     void TearDown() {}
38 };
39 
40 /**
41  * @tc.name: JoystickTransformProcessorTest_OnEvent_001
42  * @tc.desc: Verify that JoystickTransformProcessor can correctly handle events when receive
43  * @tc.type: FUNC
44  * @tc.require:
45  */
46 HWTEST_F(JoystickTransformProcessorTest, JoystickTransformProcessorTest_OnEvent_001, TestSize.Level1)
47 {
48     CALL_TEST_DEBUG;
49     int32_t deviceId = 6;
50     JoystickTransformProcessor processor(deviceId);
51     libinput_event *event = nullptr;
52     std::shared_ptr<PointerEvent> ret = processor.OnEvent(event);
53     ASSERT_EQ(ret, nullptr);
54 }
55 
56 /**
57  * @tc.name: JoystickTransformProcessorTest_OnEvent_002
58  * @tc.desc: Verify that JoystickTransformProcessor can correctly handle events when receive
59  * @tc.type: FUNC
60  * @tc.require:
61  */
62 HWTEST_F(JoystickTransformProcessorTest, JoystickTransformProcessorTest_OnEvent_002, TestSize.Level1)
63 {
64     CALL_TEST_DEBUG;
65     int32_t deviceId = 6;
66     JoystickTransformProcessor processor(deviceId);
67     libinput_event *event = nullptr;
68     std::shared_ptr<PointerEvent> ret = processor.OnEvent(event);
69     ASSERT_EQ(ret, nullptr);
70 }
71 
72 /**
73  * @tc.name: JoystickTransformProcessorTest_OnEventJoystickButton_001
74  * @tc.desc: test OnEventJoystickButton
75  * @tc.type: FUNC
76  * @tc.require:
77  */
78 HWTEST_F(JoystickTransformProcessorTest, JoystickTransformProcessorTest_OnEventJoystickButton_001, TestSize.Level1)
79 {
80     CALL_TEST_DEBUG;
81     int32_t deviceId = 6;
82     JoystickTransformProcessor processor(deviceId);
83     libinput_event* event = nullptr;
84     bool ret = processor.OnEventJoystickButton(event);
85     ASSERT_EQ(ret, false);
86 }
87 
88 /**
89  * @tc.name: JoystickTransformProcessorTest_OnEventJoystickAxis_001
90  * @tc.desc: test OnEventJoystickAxis
91  * @tc.type: FUNC
92  * @tc.require:
93  */
94 HWTEST_F(JoystickTransformProcessorTest, JoystickTransformProcessorTest_OnEventJoystickAxis_001, TestSize.Level1)
95 {
96     CALL_TEST_DEBUG;
97     int32_t deviceId = 6;
98     JoystickTransformProcessor processor(deviceId);
99     libinput_event* event = nullptr;
100     bool ret = processor.OnEventJoystickAxis(event);
101     ASSERT_EQ(ret, false);
102 }
103 
104 /**
105  * @tc.name: JoystickTransformProcessorTest_LibinputButtonToPointer_001
106  * @tc.desc: test LibinputButtonToPointer
107  * @tc.type: FUNC
108  * @tc.require:
109  */
110 HWTEST_F(JoystickTransformProcessorTest, JoystickTransformProcessorTest_LibinputButtonToPointer_001, TestSize.Level1)
111 {
112     CALL_TEST_DEBUG;
113     int32_t deviceId = 6;
114     uint32_t button = 1;
115     JoystickTransformProcessor processor(deviceId);
116     int32_t ret = processor.LibinputButtonToPointer(button);
117     ASSERT_EQ(ret, -1);
118 }
119 
120 /**
121  * @tc.name: JoystickTransformProcessorTest_LibinputButtonToPointer_002
122  * @tc.desc: test LibinputButtonToPointer
123  * @tc.type: FUNC
124  * @tc.require:
125  */
126 HWTEST_F(JoystickTransformProcessorTest, JoystickTransformProcessorTest_LibinputButtonToPointer_002, TestSize.Level1)
127 {
128     CALL_TEST_DEBUG;
129     int32_t deviceId = 6;
130     uint32_t button = 312;
131     JoystickTransformProcessor processor(deviceId);
132     int32_t ret = processor.LibinputButtonToPointer(button);
133     ASSERT_EQ(ret, 0);
134 }
135 } // namespace MMI
136 } // namespace OHOS
137