• 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 TOUCH_AREA_HEIGHT = 10.0f;
23 } // namespace
24 
25 namespace OHOS::Ace {
26 
27 namespace {
28 struct GetTouchAreaHeightTestInputType {
GetTouchAreaHeightTestInputTypeOHOS::Ace::__anoncd5601370211::GetTouchAreaHeightTestInputType29     explicit GetTouchAreaHeightTestInputType(const ArkUI_UIInputEvent event, uint32_t pointerIndex = 0)
30         : event(event), pointerIndex(pointerIndex) {};
31     ArkUI_UIInputEvent event;
32     uint32_t pointerIndex;
33 };
34 } // namespace
35 
36 /**
37  * @tc.name: OH_ArkUI_PointerEvent_GetTouchAreaHeight001
38  * @tc.desc: Test the OH_ArkUI_PointerEvent_GetTouchAreaHeight function with null event.
39  * @tc.type: FUNC
40  */
41 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_GetTouchAreaHeight001, TestSize.Level0)
42 {
43     auto result = OH_ArkUI_PointerEvent_GetTouchAreaHeight(nullptr, 0);
44     EXPECT_EQ(result, 0.0f);
45 }
46 
47 /**
48  * @tc.name: OH_ArkUI_PointerEvent_GetTouchAreaHeight101
49  * @tc.desc: Test the OH_ArkUI_PointerEvent_GetTouchAreaHeight function with touch event.
50  * @tc.type: FUNC
51  */
52 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_GetTouchAreaHeight101, TestSize.Level0)
53 {
54     ArkUITouchEvent inputEvent;
55     ArkUIEventTypeId eventTypeId = C_TOUCH_EVENT_ID;
56 
57     ArkUITouchPoint points[2];
58     points[0].contactAreaHeight = TOUCH_AREA_HEIGHT;
59     points[1].contactAreaHeight = TOUCH_AREA_HEIGHT + 5.0f;
60     inputEvent.touchPointes = &points[0];
61     inputEvent.touchPointSize = 2;
62 
63     ArkUITouchEvent inputEventEmpty;
64 
65     std::vector<std::pair<GetTouchAreaHeightTestInputType, float>> testCases = {
66         // case 1: null touch event
67         { GetTouchAreaHeightTestInputType(
68               ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, nullptr }, 0),
69             0.0f },
70         // case 2: empty touch points
71         { GetTouchAreaHeightTestInputType(
72               ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, &inputEventEmpty }, 0),
73             0.0f },
74         // case 3: valid case (returns last point's Height regardless of index)
75         { GetTouchAreaHeightTestInputType(
76               ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, &inputEvent }, 0),
77             TOUCH_AREA_HEIGHT + 5.0f },
78         { GetTouchAreaHeightTestInputType(
79               ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, &inputEvent }, 1),
80             TOUCH_AREA_HEIGHT + 5.0f },
81     };
82 
83     for (size_t i = 0; i < testCases.size(); ++i) {
84         const auto& testCase = testCases[i];
85         auto result = OH_ArkUI_PointerEvent_GetTouchAreaHeight(&testCase.first.event, testCase.first.pointerIndex);
86         EXPECT_FLOAT_EQ(result, testCase.second) << "Test case " << i << " failed";
87     }
88 }
89 
90 /**
91  * @tc.name: OH_ArkUI_PointerEvent_GetTouchAreaHeight102
92  * @tc.desc: Test the OH_ArkUI_PointerEvent_GetTouchAreaHeight function with unsupported event types.
93  * @tc.type: FUNC
94  */
95 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_GetTouchAreaHeight102, TestSize.Level0)
96 {
97     ArkUIMouseEvent mouseEvent;
98     ArkUIAxisEvent axisEvent;
99 
100     std::vector<std::pair<ArkUI_UIInputEvent, ArkUIEventTypeId>> testCases = {
101         // case 1: mouse event
102         { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, C_MOUSE_EVENT_ID, &mouseEvent }, C_MOUSE_EVENT_ID },
103         // case 2: axis event
104         { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, C_AXIS_EVENT_ID, &axisEvent }, C_AXIS_EVENT_ID },
105         // case 3: key event
106         { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, C_KEY_EVENT_ID, nullptr }, C_KEY_EVENT_ID },
107         // case 4: hover event
108         { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, C_HOVER_EVENT_ID, nullptr }, C_HOVER_EVENT_ID },
109     };
110 
111     uint32_t pointerIndex = 0;
112     for (size_t i = 0; i < testCases.size(); ++i) {
113         const auto& testCase = testCases[i];
114         auto result = OH_ArkUI_PointerEvent_GetTouchAreaHeight(&testCase.first, pointerIndex);
115         EXPECT_EQ(result, 0.0f) << "Unsupported type test " << i << " failed";
116     }
117 }
118 
119 } // namespace OHOS::Ace