• 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 "../ui_input_event_test.h"
17 
18 using namespace testing;
19 using namespace testing::ext;
20 
21 namespace {
22 constexpr float ARKUI_EVENT_X = 2.0;
23 } // namespace
24 
25 namespace OHOS::Ace {
26 
27 /**
28  * @tc.name: OH_ArkUI_PointerEvent_GetX001
29  * @tc.desc: Test the OH_ArkUI_PointerEvent_GetX function.
30  * @tc.type: FUNC
31  */
32 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_GetX001, TestSize.Level0)
33 {
34     /**
35      * @tc.steps: step1.call functions and return expected results.
36      */
37     auto result = OH_ArkUI_PointerEvent_GetX(nullptr);
38     EXPECT_EQ(result, 0.0f);
39 }
40 
41 /**
42  * @tc.name: OH_ArkUI_PointerEvent_GetX101
43  * @tc.desc: Test the OH_ArkUI_PointerEvent_GetX function.
44  * @tc.type: FUNC
45  */
46 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_GetX101, TestSize.Level0)
47 {
48     /**
49      * @tc.steps: step1.create and init ArkUI_UIInputEvent.
50      */
51     // 1 ArkUITouchEvent {C_TOUCH_EVENT_ID, HandleCTouchEventX}
52     ArkUITouchEvent inputEvent;
53     ArkUIEventTypeId eventTypeId = C_TOUCH_EVENT_ID;
54 
55     std::vector<std::pair<ArkUI_UIInputEvent, float>> testCases = {
56         { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, nullptr }, 0.0f },
57         { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, &inputEvent }, ARKUI_EVENT_X - 1 }
58     };
59 
60     /**
61      * @tc.steps: step2. Init testCases and call functions.
62      * @tc.expected: Return expected results.
63      */
64     auto count = 0;
65     for (auto testCase : testCases) {
66         auto input = testCase.first;
67         auto expect = testCase.second;
68 
69         auto* touchEvent = reinterpret_cast<ArkUITouchEvent*>(input.inputEvent);
70         if (touchEvent) {
71             touchEvent->actionTouchPoint.nodeX = expect;
72         }
73 
74         auto result = OH_ArkUI_PointerEvent_GetX(&input);
75         EXPECT_FLOAT_EQ(result, expect) << "index = " << count << ",result = " << result << ",expect = " << expect;
76         count++;
77     }
78 }
79 
80 /**
81  * @tc.name: OH_ArkUI_PointerEvent_GetX102
82  * @tc.desc: Test the OH_ArkUI_PointerEvent_GetX function.
83  * @tc.type: FUNC
84  */
85 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_GetX102, TestSize.Level0)
86 {
87     /**
88      * @tc.steps: step1.create and init ArkUI_UIInputEvent.
89      */
90     // 2 ArkUIMouseEvent {C_MOUSE_EVENT_ID, HandleCMouseEventX}
91     ArkUIMouseEvent inputEvent;
92     ArkUIEventTypeId eventTypeId = C_MOUSE_EVENT_ID;
93 
94     std::vector<std::pair<ArkUI_UIInputEvent, float>> testCases = {
95         { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, nullptr }, 0.0f },
96         { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, &inputEvent }, ARKUI_EVENT_X - 1 }
97     };
98 
99     /**
100      * @tc.steps: step2. Init testCases and call functions.
101      * @tc.expected: Return expected results.
102      */
103     auto count = 0;
104     for (auto testCase : testCases) {
105         auto input = testCase.first;
106         auto expect = testCase.second;
107 
108         auto* touchEvent = reinterpret_cast<ArkUIMouseEvent*>(input.inputEvent);
109         if (touchEvent) {
110             touchEvent->actionTouchPoint.nodeX = expect;
111         }
112 
113         auto result = OH_ArkUI_PointerEvent_GetX(&input);
114         EXPECT_FLOAT_EQ(result, expect) << "index = " << count << ",result = " << result << ",expect = " << expect;
115         count++;
116     }
117 }
118 
119 /**
120  * @tc.name: OH_ArkUI_PointerEvent_GetX103
121  * @tc.desc: Test the OH_ArkUI_PointerEvent_GetX function.
122  * @tc.type: FUNC
123  */
124 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_GetX103, TestSize.Level0)
125 {
126     /**
127      * @tc.steps: step1.create and init ArkUI_UIInputEvent.
128      */
129     // 3 ArkUIAxisEvent {C_AXIS_EVENT_ID, HandleCAxisEventX}
130     ArkUIAxisEvent inputEvent;
131     ArkUIEventTypeId eventTypeId = C_AXIS_EVENT_ID;
132 
133     std::vector<std::pair<ArkUI_UIInputEvent, float>> testCases = {
134         { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, nullptr }, 0.0f },
135         { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, &inputEvent }, ARKUI_EVENT_X - 1 }
136     };
137 
138     /**
139      * @tc.steps: step2. Init testCases and call functions.
140      * @tc.expected: Return expected results.
141      */
142     auto count = 0;
143     for (auto testCase : testCases) {
144         auto input = testCase.first;
145         auto expect = testCase.second;
146 
147         auto* touchEvent = reinterpret_cast<ArkUIAxisEvent*>(input.inputEvent);
148         if (touchEvent) {
149             touchEvent->actionTouchPoint.nodeX = expect;
150         }
151 
152         auto result = OH_ArkUI_PointerEvent_GetX(&input);
153         EXPECT_FLOAT_EQ(result, expect) << "index = " << count << ",result = " << result << ",expect = " << expect;
154         count++;
155     }
156 }
157 
158 /**
159  * @tc.name: OH_ArkUI_PointerEvent_GetX104
160  * @tc.desc: Test the OH_ArkUI_PointerEvent_GetX function.
161  * @tc.type: FUNC
162  */
163 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_GetX104, TestSize.Level0)
164 {
165     /**
166      * @tc.steps: step1.create and init ArkUI_UIInputEvent.
167      */
168     // 4 ArkUIClickEvent {C_CLICK_EVENT_ID, HandleCClickEventX}
169     ArkUIClickEvent inputEvent;
170     ArkUIEventTypeId eventTypeId = C_CLICK_EVENT_ID;
171 
172     std::vector<std::pair<ArkUI_UIInputEvent, float>> testCases = {
173         { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, nullptr }, 0.0f },
174         { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, &inputEvent }, ARKUI_EVENT_X - 1 }
175     };
176 
177     /**
178      * @tc.steps: step2. Init testCases and call functions.
179      * @tc.expected: Return expected results.
180      */
181     auto count = 0;
182     for (auto testCase : testCases) {
183         auto input = testCase.first;
184         auto expect = testCase.second;
185 
186         auto* touchEvent = reinterpret_cast<ArkUIClickEvent*>(input.inputEvent);
187         if (touchEvent) {
188             touchEvent->localX = expect;
189         }
190 
191         auto result = OH_ArkUI_PointerEvent_GetX(&input);
192         EXPECT_FLOAT_EQ(result, expect) << "index = " << count << ",result = " << result << ",expect = " << expect;
193         count++;
194     }
195 }
196 
197 /**
198  * @tc.name: OH_ArkUI_PointerEvent_GetX105
199  * @tc.desc: Test the OH_ArkUI_PointerEvent_GetX function.
200  * @tc.type: FUNC
201  */
202 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_GetX105, TestSize.Level0)
203 {
204     /**
205      * @tc.steps: step1.create and init ArkUI_UIInputEvent.
206      */
207     // 5 OHOS::Ace::AxisEvent {AXIS_EVENT_ID, HandleAxisEventX}
208     OHOS::Ace::AxisEvent inputEvent;
209     ArkUIEventTypeId eventTypeId = AXIS_EVENT_ID;
210 
211     std::vector<std::pair<ArkUI_UIInputEvent, float>> testCases = {
212         { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, nullptr }, 0.0f },
213         { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, &inputEvent }, ARKUI_EVENT_X - 1 }
214     };
215 
216     /**
217      * @tc.steps: step2. Init testCases and call functions.
218      * @tc.expected: Return expected results.
219      */
220     auto count = 0;
221     for (auto testCase : testCases) {
222         auto input = testCase.first;
223         auto expect = testCase.second;
224 
225         auto* touchEvent = reinterpret_cast<OHOS::Ace::AxisEvent*>(input.inputEvent);
226         if (touchEvent) {
227             touchEvent->localX = expect;
228         }
229 
230         auto result = OH_ArkUI_PointerEvent_GetX(&input);
231         EXPECT_FLOAT_EQ(result, expect) << "index = " << count << ",result = " << result << ",expect = " << expect;
232         count++;
233     }
234 }
235 
236 /**
237  * @tc.name: OH_ArkUI_PointerEvent_GetX106
238  * @tc.desc: Test the OH_ArkUI_PointerEvent_GetX function.
239  * @tc.type: FUNC
240  */
241 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_GetX106, TestSize.Level0)
242 {
243     /**
244      * @tc.steps: step1.create and init ArkUI_UIInputEvent.
245      */
246     // 6 OHOS::Ace::TouchEvent {TOUCH_EVENT_ID, HandleTouchEventX}
247     OHOS::Ace::TouchEvent inputEvent;
248     ArkUIEventTypeId eventTypeId = TOUCH_EVENT_ID;
249 
250     std::vector<std::pair<ArkUI_UIInputEvent, float>> testCases = {
251         { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, nullptr },
252             0.0f },
253         { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, &inputEvent },
254             ARKUI_EVENT_X - 1 }
255     };
256 
257     /**
258      * @tc.steps: step2. Init testCases and call functions.
259      * @tc.expected: Return expected results.
260      */
261     auto count = 0;
262     for (auto testCase : testCases) {
263         auto input = testCase.first;
264         auto expect = testCase.second;
265 
266         auto* touchEvent = reinterpret_cast<OHOS::Ace::TouchEvent*>(input.inputEvent);
267         if (touchEvent) {
268             touchEvent->localX = expect;
269         }
270 
271         auto result = OH_ArkUI_PointerEvent_GetX(&input);
272         EXPECT_FLOAT_EQ(result, expect) << "index = " << count << ",result = " << result << ",expect = " << expect;
273         count++;
274     }
275 }
276 
277 /**
278  * @tc.name: OH_ArkUI_PointerEvent_GetX107
279  * @tc.desc: Test the OH_ArkUI_PointerEvent_GetX function.
280  * @tc.type: FUNC
281  */
282 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_GetX107, TestSize.Level0)
283 {
284     /**
285      * @tc.steps: step1.create and init ArkUI_UIInputEvent.
286      */
287     // 2 Other ArkUIEventTypeId
288     std::vector<ArkUIEventTypeId> typeIds = {
289         C_KEY_EVENT_ID,
290         C_FOCUS_AXIS_EVENT_ID,
291         C_HOVER_EVENT_ID
292     };
293 
294     /**
295      * @tc.steps: step2. Init testCases and call functions.
296      * @tc.expected: Return expected results.
297      */
298     auto count = 0;
299     for (auto typeId : typeIds) {
300         auto uiInputEvent = ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, typeId, nullptr };
301         auto result = OH_ArkUI_PointerEvent_GetX(&uiInputEvent);
302         EXPECT_EQ(result, static_cast<int32_t>(UI_INPUT_EVENT_SOURCE_TYPE_UNKNOWN)) << "other index = " << count;
303         count++;
304     }
305 }
306 
307 } // namespace OHOS::Ace