• 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 namespace OHOS::Ace {
21 
22 namespace {
23 struct ChangedPointerIdTestInputType {
ChangedPointerIdTestInputTypeOHOS::Ace::__anona1b105670111::ChangedPointerIdTestInputType24     explicit ChangedPointerIdTestInputType(const ArkUI_UIInputEvent event, uint32_t* pointerIndex = nullptr,
25         ArkUI_Uint32 touchPointSize = 0, ArkUI_Uint32 changedPointerId = 0)
26         : event(event), pointerIndex(pointerIndex), touchPointSize(touchPointSize), changedPointerId(changedPointerId)
27         {};
28     ArkUI_UIInputEvent event;
29     uint32_t* pointerIndex;
30     ArkUI_Uint32 touchPointSize;
31     ArkUI_Int32 changedPointerId;
32 };
33 } // namespace
34 
35 /**
36  * @tc.name: OH_ArkUI_PointerEvent_GetChangedPointerId001
37  * @tc.desc: Test the OH_ArkUI_PointerEvent_GetChangedPointerId function.
38  * @tc.type: FUNC
39  */
40 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_GetChangedPointerId001, TestSize.Level0)
41 {
42     /**
43      * @tc.steps: step1.call functions and return expected results.
44      */
45     auto result = OH_ArkUI_PointerEvent_GetChangedPointerId(nullptr, 0);
46     EXPECT_EQ(result, ARKUI_ERROR_CODE_PARAM_INVALID);
47 }
48 
49 /**
50  * @tc.name: OH_ArkUI_PointerEvent_GetChangedPointerId101
51  * @tc.desc: Test the OH_ArkUI_PointerEvent_GetChangedPointerId function.
52  * @tc.type: FUNC
53  */
54 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_GetChangedPointerId101, TestSize.Level0)
55 {
56     /**
57      * @tc.steps: step1.create and init ArkUI_UIInputEvent.
58      */
59     // 1 ArkUITouchEvent {C_TOUCH_EVENT_ID, touchEvent->changedPointerId, ARKUI_ERROR_CODE_NO_ERROR}
60     ArkUITouchEvent inputEvent;
61     ArkUIEventTypeId eventTypeId = C_TOUCH_EVENT_ID;
62     uint32_t pointerIndex = 1;
63 
64     std::vector<std::pair<ChangedPointerIdTestInputType, int32_t>> testCases = {
65         // case 1.2 !pointerIndex
66         { ChangedPointerIdTestInputType(
67             ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, &inputEvent}, nullptr, 0, 0),
68             ARKUI_ERROR_CODE_PARAM_INVALID },
69         // case 2.1 !touchEvent
70         { ChangedPointerIdTestInputType(
71             ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, nullptr}, &pointerIndex, 0, 0),
72             ARKUI_ERROR_CODE_PARAM_INVALID },
73         // case 2.2 touchEvent->touchPointSize <= 0
74         { ChangedPointerIdTestInputType(
75             ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, &inputEvent}, &pointerIndex, 0, 0),
76             ARKUI_ERROR_CODE_PARAM_INVALID },
77         // case 2.3 other
78         { ChangedPointerIdTestInputType(
79             ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, &inputEvent}, &pointerIndex, 1, 10),
80             ARKUI_ERROR_CODE_PARAM_INVALID },
81     };
82 
83     /**
84      * @tc.steps: step2. Init testCases and call functions.
85      * @tc.expected: Return expected results.
86      */
87     auto count = 0;
88     for (auto testCase : testCases) {
89         auto input = testCase.first;
90         auto expect = testCase.second;
91         auto result = OH_ArkUI_PointerEvent_GetChangedPointerId(&input.event, input.pointerIndex);
92         EXPECT_FLOAT_EQ(result, expect) << "index = " << count << ",result = " << result << ",expect = " << expect;
93         count++;
94     }
95 }
96 
97 /**
98  * @tc.name: OH_ArkUI_PointerEvent_GetChangedPointerId102
99  * @tc.desc: Test the OH_ArkUI_PointerEvent_GetChangedPointerId function.
100  * @tc.type: FUNC
101  */
102 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_GetChangedPointerId102, TestSize.Level0)
103 {
104     /**
105      * @tc.steps: step1.create and init ArkUI_UIInputEvent.
106      */
107     // 2 Other ArkUIEventTypeId
108     std::vector<ArkUIEventTypeId> typeIds = {
109         AXIS_EVENT_ID,
110         TOUCH_EVENT_ID,
111         C_MOUSE_EVENT_ID,
112         C_AXIS_EVENT_ID,
113         C_KEY_EVENT_ID,
114         C_FOCUS_AXIS_EVENT_ID,
115         C_CLICK_EVENT_ID,
116         C_HOVER_EVENT_ID,
117     };
118 
119     /**
120      * @tc.steps: step2. Init testCases and call functions.
121      * @tc.expected: Return expected results.
122      */
123     auto count = 0;
124     uint32_t pointerIndex = 0;
125     for (auto typeId : typeIds) {
126         auto uiInputEvent = ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, typeId, nullptr };
127         auto result = OH_ArkUI_PointerEvent_GetChangedPointerId(&uiInputEvent, &pointerIndex);
128         EXPECT_EQ(result, ARKUI_ERROR_CODE_PARAM_INVALID) << "other index = " << count;
129         count++;
130     }
131 }
132 
133 } // namespace OHOS::Ace