• 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 ArkUI_InteractionHand ARKUI_LEFT_HAND = ARKUI_EVENT_HAND_LEFT;
23 constexpr ArkUI_InteractionHand ARKUI_RIGHT_HAND = ARKUI_EVENT_HAND_RIGHT;
24 } // namespace
25 
26 namespace OHOS::Ace {
27 
28 /**
29  * @tc.name: OH_ArkUI_PointerEvent_GetInteractionHand001
30  * @tc.desc: Test the OH_ArkUI_PointerEvent_GetInteractionHand function with null parameters.
31  * @tc.type: FUNC
32  */
33 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_GetInteractionHand001, TestSize.Level0)
34 {
35     ArkUI_InteractionHand hand;
36     ArkUI_UIInputEvent event = { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, C_TOUCH_EVENT_ID, nullptr };
37 
38     // case 1: null event
39     auto result1 = OH_ArkUI_PointerEvent_GetInteractionHand(nullptr, &hand);
40     EXPECT_EQ(result1, ARKUI_ERROR_CODE_PARAM_INVALID);
41 
42     // case 2: null hand
43     auto result2 = OH_ArkUI_PointerEvent_GetInteractionHand(&event, nullptr);
44     EXPECT_EQ(result2, ARKUI_ERROR_CODE_PARAM_INVALID);
45 }
46 
47 /**
48  * @tc.name: OH_ArkUI_PointerEvent_GetInteractionHand101
49  * @tc.desc: Test the OH_ArkUI_PointerEvent_GetInteractionHand function with touch event.
50  * @tc.type: FUNC
51  */
52 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_GetInteractionHand101, TestSize.Level0)
53 {
54     ArkUIEventTypeId eventTypeId = C_TOUCH_EVENT_ID;
55     ArkUI_InteractionHand hand;
56 
57     // Test left hand case
58     ArkUITouchEvent leftInputEvent;
59     leftInputEvent.actionTouchPoint.operatingHand = static_cast<int32_t>(ARKUI_LEFT_HAND);
60     ArkUI_UIInputEvent leftHandEvent = { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, &leftInputEvent };
61 
62     auto leftResult = OH_ArkUI_PointerEvent_GetInteractionHand(&leftHandEvent, &hand);
63     EXPECT_EQ(leftResult, ARKUI_ERROR_CODE_NO_ERROR);
64     EXPECT_EQ(hand, ARKUI_LEFT_HAND) << "Left hand test failed";
65 
66     // Test right hand case
67     ArkUITouchEvent rightInputEvent;
68     rightInputEvent.actionTouchPoint.operatingHand = static_cast<int32_t>(ARKUI_RIGHT_HAND);
69     ArkUI_UIInputEvent rightHandEvent = { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, &rightInputEvent };
70 
71     auto rightResult = OH_ArkUI_PointerEvent_GetInteractionHand(&rightHandEvent, &hand);
72     EXPECT_EQ(rightResult, ARKUI_ERROR_CODE_NO_ERROR);
73     EXPECT_EQ(hand, ARKUI_RIGHT_HAND) << "Right hand test failed";
74 }
75 
76 /**
77  * @tc.name: OH_ArkUI_PointerEvent_GetInteractionHand102
78  * @tc.desc: Test the OH_ArkUI_PointerEvent_GetInteractionHand function with unsupported event types.
79  * @tc.type: FUNC
80  */
81 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_GetInteractionHand102, TestSize.Level0)
82 {
83     ArkUIMouseEvent mouseEvent;
84     ArkUIAxisEvent axisEvent;
85     ArkUI_InteractionHand hand;
86 
87     ArkUI_UIInputEvent mouseEventWrapper = { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, C_MOUSE_EVENT_ID, &mouseEvent };
88     ArkUI_UIInputEvent axisEventWrapper = { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, C_AXIS_EVENT_ID, &axisEvent };
89     ArkUI_UIInputEvent keyEventWrapper = { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, C_KEY_EVENT_ID, nullptr };
90     ArkUI_UIInputEvent hoverEventWrapper = { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, C_HOVER_EVENT_ID, nullptr };
91 
92     // case 1: mouse event
93     auto result1 = OH_ArkUI_PointerEvent_GetInteractionHand(&mouseEventWrapper, &hand);
94     EXPECT_EQ(result1, ARKUI_ERROR_CODE_NO_ERROR);
95 
96     // case 2: axis event
97     auto result2 = OH_ArkUI_PointerEvent_GetInteractionHand(&axisEventWrapper, &hand);
98     EXPECT_EQ(result2, ARKUI_ERROR_CODE_NO_ERROR);
99 
100     // case 3: key event
101     auto result3 = OH_ArkUI_PointerEvent_GetInteractionHand(&keyEventWrapper, &hand);
102     EXPECT_EQ(result3, ARKUI_ERROR_CODE_NO_ERROR);
103 
104     // case 4: hover event
105     auto result4 = OH_ArkUI_PointerEvent_GetInteractionHand(&hoverEventWrapper, &hand);
106     EXPECT_EQ(result4, ARKUI_ERROR_CODE_NO_ERROR);
107 }
108 
109 } // namespace OHOS::Ace