• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 <gmock/gmock.h>
17 
18 #include <dlfcn.h>
19 #include "define_multimodal.h"
20 #include "fingersense_wrapper.h"
21 #include "pointer_event.h"
22 
23 #undef MMI_LOG_TAG
24 #define MMI_LOG_TAG "FingersenseWrapperTest"
25 
26 namespace OHOS {
27 namespace MMI {
28 namespace {
29 using namespace testing;
30 using namespace testing::ext;
31 
32 const float EPSILON = 10.0;
33 } // namespace
34 class FingersenseWrapperTest : public testing::Test {
35 public:
SetUpTestCase(void)36     static void SetUpTestCase(void){};
TearDownTestCase(void)37     static void TearDownTestCase(void){};
SetUp()38     void SetUp()
39     {
40         wrapper_ = std::make_shared<FingersenseWrapper>();
41     };
TearDown()42     void TearDown(){};
43 
44     std::shared_ptr<FingersenseWrapper> wrapper_;
45 };
46 
47 #ifdef OHOS_BUILD_ENABLE_FINGERSENSE
48 /* *
49  * @tc.name  : CrownTransformProcessorTest_SaveTouchInfo_001
50  * @tc.desc: Test the funcation SaveTouchInfo
51  * @tc.type: Function
52  * @tc.require:
53  */
54 HWTEST_F(FingersenseWrapperTest, CrownTransformProcessorTest_SaveTouchInfo_001, TestSize.Level1)
55 {
56     float pointX = 10.0f;
57     float pointY = 20.0f;
58     int32_t toolType = 1;
59     wrapper_->SaveTouchInfo(pointX, pointY, toolType);
60 
61     EXPECT_EQ(wrapper_->touchInfos_.size(), 1);
62     EXPECT_EQ(wrapper_->touchInfos_[0].x, pointX);
63     EXPECT_EQ(wrapper_->touchInfos_[0].y, pointY);
64     EXPECT_EQ(wrapper_->touchInfos_[0].touch_type, toolType);
65 }
66 
67 /* *
68  * @tc.name  : CrownTransformProcessorTest_SaveTouchInfo_002
69  * @tc.desc: Test the funcation SaveTouchInfo
70  * @tc.type: Function
71  * @tc.require:
72  */
73 HWTEST_F(FingersenseWrapperTest, CrownTransformProcessorTest_SaveTouchInfo_002, TestSize.Level1)
74 {
75     float pointX = 10.0f;
76     float pointY = 20.0f;
77     int32_t toolType = 1;
78     size_t vectorSize = 10;
79     size_t maxVectorSize = 10;
80 
81     for (size_t i = 0; i < vectorSize; i++) {
82         TouchInfo touchInfo;
83         touchInfo.x = pointX;
84         touchInfo.y = pointY;
85         touchInfo.touch_type = toolType;
86         wrapper_->touchInfos_.push_back(touchInfo);
87     }
88 
89     wrapper_->SaveTouchInfo(pointX, pointY, toolType);
90     EXPECT_EQ(wrapper_->touchInfos_.size(), maxVectorSize);
91 }
92 
93 /* *
94  * @tc.name  : CrownTransformProcessorTest_SaveTouchInfo_003
95  * @tc.desc: Test the funcation SaveTouchInfo
96  * @tc.type: Function
97  * @tc.require:
98  */
99 HWTEST_F(FingersenseWrapperTest, CrownTransformProcessorTest_SaveTouchInfo_003, TestSize.Level1)
100 {
101     float pointX = 10.0f;
102     float pointY = 20.0f;
103     int32_t toolType = 1;
104     size_t vectorSize = 20;
105     size_t maxVectorSize = 10;
106 
107     for (size_t i = 0; i < vectorSize; i++) {
108         TouchInfo touchInfo;
109         touchInfo.x = pointX;
110         touchInfo.y = pointY;
111         touchInfo.touch_type = toolType;
112         wrapper_->touchInfos_.push_back(touchInfo);
113     }
114 
115     wrapper_->SaveTouchInfo(pointX, pointY, toolType);
116     EXPECT_EQ(wrapper_->touchInfos_.size(), maxVectorSize);
117 }
118 
119 /* *
120  * @tc.name  : CrownTransformProcessorTest_IsEqual_001
121  * @tc.desc: Test the funcation IsEqual
122  * @tc.type: Function
123  * @tc.require:
124  */
125 HWTEST_F(FingersenseWrapperTest, CrownTransformProcessorTest_IsEqual_001, TestSize.Level1)
126 {
127     float a = 10.0f;
128     float b = 10.0f;
129     float epsilon = 0.001f;
130 
131     bool result = wrapper_->IsEqual(a, b, epsilon);
132     EXPECT_TRUE(result);
133 }
134 
135 /* *
136  * @tc.name  : CrownTransformProcessorTest_IsEqual_002
137  * @tc.desc: Test the funcation IsEqual
138  * @tc.type: Function
139  * @tc.require:
140  */
141 HWTEST_F(FingersenseWrapperTest, CrownTransformProcessorTest_IsEqual_002, TestSize.Level1)
142 {
143     float a = 10.0f;
144     float b = 10.1f;
145     float epsilon = 0.05f;
146 
147     bool result = wrapper_->IsEqual(a, b, epsilon);
148     EXPECT_FALSE(result);
149 }
150 
151 /* *
152  * @tc.name  : CrownTransformProcessorTest_CheckKnuckleEvent_001
153  * @tc.desc: Test the funcation CheckKnuckleEvent
154  * @tc.type: Function
155  * @tc.require:
156  */
157 HWTEST_F(FingersenseWrapperTest, CrownTransformProcessorTest_CheckKnuckleEvent_001, TestSize.Level1)
158 {
159     float pointX = 10.0f;
160     float pointY = 20.0f;
161     bool isKnuckleType = false;
162 
163     int32_t result = wrapper_->CheckKnuckleEvent(pointX, pointY, isKnuckleType);
164     EXPECT_EQ(result, RET_ERR);
165     EXPECT_FALSE(isKnuckleType);
166 }
167 
168 /* *
169  * @tc.name  : CrownTransformProcessorTest_CheckKnuckleEvent_002
170  * @tc.desc: Test the funcation CheckKnuckleEvent
171  * @tc.type: Function
172  * @tc.require:
173  */
174 HWTEST_F(FingersenseWrapperTest, CrownTransformProcessorTest_CheckKnuckleEvent_002, TestSize.Level1)
175 {
176     float pointX = 10.0f;
177     float pointY = 20.0f;
178     int32_t toolType = MMI::PointerEvent::TOOL_TYPE_KNUCKLE;
179     TouchInfo touchInfo;
180     touchInfo.x = pointX;
181     touchInfo.y = pointY;
182     touchInfo.touch_type = toolType;
183     wrapper_->touchInfos_.push_back(touchInfo);
184     bool isKnuckleType = false;
185 
186     int32_t result = wrapper_->CheckKnuckleEvent(pointX, pointY, isKnuckleType);
187     EXPECT_EQ(result, RET_OK);
188     EXPECT_TRUE(isKnuckleType);
189 }
190 
191 /* *
192  * @tc.name  : CrownTransformProcessorTest_CheckKnuckleEvent_003
193  * @tc.desc: Test the funcation CheckKnuckleEvent
194  * @tc.type: Function
195  * @tc.require:
196  */
197 HWTEST_F(FingersenseWrapperTest, CrownTransformProcessorTest_CheckKnuckleEvent_003, TestSize.Level1)
198 {
199     float pointX = 10.0f;
200     float pointY = 20.0f;
201     int32_t toolType = MMI::PointerEvent::TOOL_TYPE_KNUCKLE;
202     TouchInfo touchInfo;
203     touchInfo.x = pointX;
204     touchInfo.y = pointY + EPSILON;
205     touchInfo.touch_type = toolType;
206     wrapper_->touchInfos_.push_back(touchInfo);
207     bool isKnuckleType = false;
208 
209     int32_t result = wrapper_->CheckKnuckleEvent(pointX, pointY, isKnuckleType);
210     EXPECT_EQ(result, RET_ERR);
211     EXPECT_FALSE(isKnuckleType);
212 }
213 
214 /* *
215  * @tc.name  : CrownTransformProcessorTest_CheckKnuckleEvent_004
216  * @tc.desc: Test the funcation CheckKnuckleEvent
217  * @tc.type: Function
218  * @tc.require:
219  */
220 HWTEST_F(FingersenseWrapperTest, CrownTransformProcessorTest_CheckKnuckleEvent_004, TestSize.Level1)
221 {
222     float pointX = 10.0f;
223     float pointY = 20.0f;
224     int32_t toolType = MMI::PointerEvent::TOOL_TYPE_KNUCKLE;
225     TouchInfo touchInfo;
226     touchInfo.x = pointX;
227     touchInfo.y = pointY + EPSILON * 2;
228     touchInfo.touch_type = toolType;
229     wrapper_->touchInfos_.push_back(touchInfo);
230     bool isKnuckleType = false;
231 
232     int32_t result = wrapper_->CheckKnuckleEvent(pointX, pointY, isKnuckleType);
233     EXPECT_EQ(result, RET_ERR);
234     EXPECT_FALSE(isKnuckleType);
235 }
236 
237 /* *
238  * @tc.name  : CrownTransformProcessorTest_CheckKnuckleEvent_005
239  * @tc.desc: Test the funcation CheckKnuckleEvent
240  * @tc.type: Function
241  * @tc.require:
242  */
243 HWTEST_F(FingersenseWrapperTest, CrownTransformProcessorTest_CheckKnuckleEvent_005, TestSize.Level1)
244 {
245     float pointX = 10.0f;
246     float pointY = 20.0f;
247     int32_t toolType = MMI::PointerEvent::TOOL_TYPE_KNUCKLE;
248     TouchInfo touchInfo;
249     touchInfo.x = pointX + EPSILON;
250     touchInfo.y = pointY;
251     touchInfo.touch_type = toolType;
252     wrapper_->touchInfos_.push_back(touchInfo);
253     bool isKnuckleType = false;
254 
255     int32_t result = wrapper_->CheckKnuckleEvent(pointX, pointY, isKnuckleType);
256     EXPECT_EQ(result, RET_ERR);
257     EXPECT_FALSE(isKnuckleType);
258 }
259 
260 /* *
261  * @tc.name  : CrownTransformProcessorTest_CheckKnuckleEvent_006
262  * @tc.desc: Test the funcation CheckKnuckleEvent
263  * @tc.type: Function
264  * @tc.require:
265  */
266 HWTEST_F(FingersenseWrapperTest, CrownTransformProcessorTest_CheckKnuckleEvent_006, TestSize.Level1)
267 {
268     float pointX = 10.0f;
269     float pointY = 20.0f;
270     int32_t toolType = MMI::PointerEvent::TOOL_TYPE_KNUCKLE;
271     TouchInfo touchInfo;
272     touchInfo.x = pointX + EPSILON * 2;
273     touchInfo.y = pointY;
274     touchInfo.touch_type = toolType;
275     wrapper_->touchInfos_.push_back(touchInfo);
276     bool isKnuckleType = false;
277 
278     int32_t result = wrapper_->CheckKnuckleEvent(pointX, pointY, isKnuckleType);
279     EXPECT_EQ(result, RET_ERR);
280     EXPECT_FALSE(isKnuckleType);
281 }
282 #endif // OHOS_BUILD_ENABLE_FINGERSENSE
283 } // namespace MMI
284 } // namespace OHOS
285