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