• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "define_multimodal.h"
20 #include "joystick_transform_processor.h"
21 #include "touch_transform_processor.h"
22 #include "touch_event_normalize.h"
23 
24 #undef MMI_LOG_TAG
25 #define MMI_LOG_TAG "TouchEventNormalizeTest"
26 
27 namespace OHOS {
28 namespace MMI {
29 namespace {
30 using namespace testing::ext;
31 constexpr int32_t LIBINPUT_HOMEPAGE_BUTTON_CODE = 172;
32 constexpr int32_t LIBINPUT_BUTTON_NONE = -1;
33 } // namespace
34 class TouchEventNormalizeTest : public testing::Test {
35 public:
36     void SetUp();
37     void TearDown();
38 
39 private:
40     bool prePinchSwitch_ { true };
41     bool preSwipeSwitch_ { true };
42     bool preRotateSwitch_ { true };
43 };
44 
45 class JoystickTransformProcessorTest : public testing::Test {
46 public:
SetUpTestCase(void)47     static void SetUpTestCase(void) {}
TearDownTestCase(void)48     static void TearDownTestCase(void) {}
49 };
50 
51 class TouchTransformProcessorTest : public testing::Test {
52 public:
SetUpTestCase(void)53     static void SetUpTestCase(void) {}
TearDownTestCase(void)54     static void TearDownTestCase(void) {}
55 };
56 
SetUp()57 void TouchEventNormalizeTest::SetUp()
58 {
59     TOUCH_EVENT_HDR->GetTouchpadPinchSwitch(prePinchSwitch_);
60     TOUCH_EVENT_HDR->GetTouchpadSwipeSwitch(preSwipeSwitch_);
61     TOUCH_EVENT_HDR->GetTouchpadRotateSwitch(preRotateSwitch_);
62 }
63 
TearDown()64 void TouchEventNormalizeTest::TearDown()
65 {
66     TOUCH_EVENT_HDR->SetTouchpadPinchSwitch(prePinchSwitch_);
67     TOUCH_EVENT_HDR->SetTouchpadSwipeSwitch(preSwipeSwitch_);
68     TOUCH_EVENT_HDR->SetTouchpadRotateSwitch(preRotateSwitch_);
69 }
70 
71 /**
72  * @tc.name: JoystickTransformProcessorTest_LibinputButtonToPointer
73  * @tc.desc: Test LibinputButtonToPointer
74  * @tc.type: FUNC
75  * @tc.require:
76  */
77 HWTEST_F(JoystickTransformProcessorTest, JoystickTransformProcessorTest_LibinputButtonToPointer, TestSize.Level1)
78 {
79     int32_t deviceId = 123;
80     JoystickTransformProcessor joystickTransformProcessor(deviceId);
81     uint32_t button = LIBINPUT_HOMEPAGE_BUTTON_CODE;
82     ASSERT_EQ(joystickTransformProcessor.LibinputButtonToPointer(button), PointerEvent::JOYSTICK_BUTTON_HOMEPAGE);
83 
84     button = LIBINPUT_BUTTON_NONE;
85     ASSERT_EQ(joystickTransformProcessor.LibinputButtonToPointer(button), PointerEvent::BUTTON_NONE);
86 }
87 
88 /**
89  * @tc.name: TouchTransformProcessorTest_UpdatePointerItemProperties
90  * @tc.desc: Test UpdatePointerItemProperties
91  * @tc.type: FUNC
92  * @tc.require:
93  */
94 HWTEST_F(TouchTransformProcessorTest, TouchTransformProcessorTest_UpdatePointerItemProperties, TestSize.Level1)
95 {
96     CALL_TEST_DEBUG;
97     int32_t deviceId = 6;
98     TouchTransformProcessor touchTransformProcessor(deviceId);
99     PointerEvent::PointerItem item;
100     EventTouch touchInfo;
101     touchInfo.point.x = 125;
102     touchInfo.point.y = 300;
103     touchInfo.toolRect.point.x = 300;
104     touchInfo.toolRect.point.y = 600;
105     touchInfo.toolRect.width = 720;
106     touchInfo.toolRect.height = 1000;
107     ASSERT_NO_FATAL_FAILURE(touchTransformProcessor.UpdatePointerItemProperties(item, touchInfo));
108 }
109 
110 /**
111  * @tc.name: TouchEventNormalizeTest_MakeTransformProcessor
112  * @tc.desc: Test Gets the TransformProcessor pointer based on the device type
113  * @tc.type: FUNC
114  * @tc.require:
115  */
116 HWTEST_F(TouchEventNormalizeTest, TouchEventNormalizeTest_MakeTransformProcessor, TestSize.Level1)
117 {
118     CALL_TEST_DEBUG;
119     int32_t deviceId = 123456;
120     ASSERT_NE(TOUCH_EVENT_HDR->MakeTransformProcessor(deviceId, TouchEventNormalize::DeviceType::TOUCH), nullptr);
121     ASSERT_NE(TOUCH_EVENT_HDR->MakeTransformProcessor(deviceId, TouchEventNormalize::DeviceType::TABLET_TOOL), nullptr);
122     ASSERT_NE(TOUCH_EVENT_HDR->MakeTransformProcessor(deviceId, TouchEventNormalize::DeviceType::TOUCH_PAD), nullptr);
123     ASSERT_NE(TOUCH_EVENT_HDR->MakeTransformProcessor(deviceId, TouchEventNormalize::DeviceType::GESTURE), nullptr);
124     ASSERT_NE(TOUCH_EVENT_HDR->MakeTransformProcessor(deviceId, TouchEventNormalize::DeviceType::JOYSTICK), nullptr);
125     ASSERT_EQ(TOUCH_EVENT_HDR->MakeTransformProcessor(deviceId, TouchEventNormalize::DeviceType::KNUCKLE), nullptr);
126 }
127 
128 /**
129  * @tc.name: TouchEventNormalizeTest_SetTouchpadPinchSwitch_01
130  * @tc.desc: Test SetTouchpadPinchSwitch
131  * @tc.type: FUNC
132  * @tc.require:
133  */
134 HWTEST_F(TouchEventNormalizeTest, TouchEventNormalizeTest_SetTouchpadPinchSwitch_01, TestSize.Level1)
135 {
136     CALL_TEST_DEBUG;
137     bool flag = false;
138     ASSERT_TRUE(TOUCH_EVENT_HDR->SetTouchpadPinchSwitch(flag) == RET_OK);
139 }
140 
141 /**
142  * @tc.name: TouchEventNormalizeTest_GetTouchpadPinchSwitch_02
143  * @tc.desc: Test GetTouchpadPinchSwitch
144  * @tc.type: FUNC
145  * @tc.require:
146  */
147 HWTEST_F(TouchEventNormalizeTest, TouchEventNormalizeTest_GetTouchpadPinchSwitch_02, TestSize.Level1)
148 {
149     CALL_TEST_DEBUG;
150     bool flag = true;
151     TOUCH_EVENT_HDR->SetTouchpadPinchSwitch(flag);
152     bool newFlag = true;
153     TOUCH_EVENT_HDR->GetTouchpadPinchSwitch(flag);
154     ASSERT_TRUE(flag == newFlag);
155 }
156 
157 /**
158  * @tc.name: TouchEventNormalizeTest_SetTouchpadSwipeSwitch_03
159  * @tc.desc: Test SetTouchpadSwipeSwitch
160  * @tc.type: FUNC
161  * @tc.require:
162  */
163 HWTEST_F(TouchEventNormalizeTest, TouchEventNormalizeTest_SetTouchpadSwipeSwitch_03, TestSize.Level1)
164 {
165     CALL_TEST_DEBUG;
166     bool flag = false;
167     ASSERT_TRUE(TOUCH_EVENT_HDR->SetTouchpadSwipeSwitch(flag) == RET_OK);
168 }
169 
170 /**
171  * @tc.name: TouchEventNormalizeTest_GetTouchpadSwipeSwitch_04
172  * @tc.desc: Test GetTouchpadSwipeSwitch
173  * @tc.type: FUNC
174  * @tc.require:
175  */
176 HWTEST_F(TouchEventNormalizeTest, TouchEventNormalizeTest_GetTouchpadSwipeSwitch_04, TestSize.Level1)
177 {
178     CALL_TEST_DEBUG;
179     bool flag = true;
180     TOUCH_EVENT_HDR->SetTouchpadSwipeSwitch(flag);
181     bool newFlag = true;
182     TOUCH_EVENT_HDR->GetTouchpadSwipeSwitch(flag);
183     ASSERT_TRUE(flag == newFlag);
184 }
185 
186 /**
187  * @tc.name: TouchEventNormalizeTest_SetTouchpadRotateSwitch_05
188  * @tc.desc: Test SetTouchpadRotateSwitch
189  * @tc.type: FUNC
190  * @tc.require:
191  */
192 HWTEST_F(TouchEventNormalizeTest, TouchEventNormalizeTest_SetTouchpadRotateSwitch_05, TestSize.Level1)
193 {
194     CALL_TEST_DEBUG;
195     bool rotateSwitch = false;
196     ASSERT_TRUE(TOUCH_EVENT_HDR->SetTouchpadRotateSwitch(rotateSwitch) == RET_OK);
197 }
198 
199 /**
200  * @tc.name: TouchEventNormalizeTest_GetTouchpadRotateSwitch_06
201  * @tc.desc: Test GetTouchpadRotateSwitch
202  * @tc.type: FUNC
203  * @tc.require:
204  */
205 HWTEST_F(TouchEventNormalizeTest, TouchEventNormalizeTest_GetTouchpadRotateSwitch_06, TestSize.Level1)
206 {
207     CALL_TEST_DEBUG;
208     bool rotateSwitch = true;
209     TOUCH_EVENT_HDR->SetTouchpadRotateSwitch(rotateSwitch);
210     bool newRotateSwitch = true;
211     TOUCH_EVENT_HDR->GetTouchpadRotateSwitch(rotateSwitch);
212     ASSERT_TRUE(rotateSwitch == newRotateSwitch);
213 }
214 } // namespace MMI
215 } // namespace OHOS