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