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