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 uint32_t ARKUI_HISTORY_POINTER_COUNT = 2; 23 constexpr uint32_t ARKUI_HISTORY_SIZE = 3; 24 } // namespace 25 26 namespace OHOS::Ace { 27 28 /** 29 * @tc.name: OH_ArkUI_PointerEvent_GetHistoryPointerCount001 30 * @tc.desc: Test the OH_ArkUI_PointerEvent_GetHistoryPointerCount function with null event. 31 * @tc.type: FUNC 32 */ 33 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_GetHistoryPointerCount001, TestSize.Level0) 34 { 35 auto result = OH_ArkUI_PointerEvent_GetHistoryPointerCount(nullptr, 0); 36 EXPECT_EQ(result, 0u); 37 } 38 39 /** 40 * @tc.name: OH_ArkUI_PointerEvent_GetHistoryPointerCount101 41 * @tc.desc: Test the OH_ArkUI_PointerEvent_GetHistoryPointerCount function with touch event. 42 * @tc.type: FUNC 43 */ 44 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_GetHistoryPointerCount101, TestSize.Level0) 45 { 46 ArkUITouchEvent inputEvent; 47 ArkUIEventTypeId eventTypeId = C_TOUCH_EVENT_ID; 48 49 // Setup valid history events with different pointer counts 50 ArkUIHistoryTouchEvent historyEvents[ARKUI_HISTORY_SIZE]; 51 historyEvents[0].touchPointSize = ARKUI_HISTORY_POINTER_COUNT; 52 historyEvents[1].touchPointSize = ARKUI_HISTORY_POINTER_COUNT + 1; 53 historyEvents[2].touchPointSize = ARKUI_HISTORY_POINTER_COUNT + 2; 54 inputEvent.historyEvents = historyEvents; 55 inputEvent.historySize = ARKUI_HISTORY_SIZE; 56 57 ArkUITouchEvent nullHistoryEvent; 58 nullHistoryEvent.historyEvents = nullptr; 59 nullHistoryEvent.historySize = ARKUI_HISTORY_SIZE; 60 61 ArkUITouchEvent emptyEvent; 62 63 std::vector<std::tuple<ArkUI_UIInputEvent, uint32_t, uint32_t>> testCases = { 64 // case 1: null touch event 65 { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, nullptr }, 0, 0 }, 66 // case 2: null history events 67 { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, &nullHistoryEvent }, 0, 0 }, 68 // case 3: empty touch event 69 { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, &emptyEvent }, 0, 0 }, 70 // case 4: invalid history index (negative) 71 { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, &inputEvent }, -1, 0 }, 72 // case 5: invalid history index (out of range) 73 { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, &inputEvent }, ARKUI_HISTORY_SIZE, 0 }, 74 // case 6: valid history index 0 75 { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, &inputEvent }, 0, 76 ARKUI_HISTORY_POINTER_COUNT }, 77 // case 7: valid history index 1 78 { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, &inputEvent }, 1, 79 ARKUI_HISTORY_POINTER_COUNT + 1 }, 80 // case 8: valid history index 2 81 { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, eventTypeId, &inputEvent }, 2, 82 ARKUI_HISTORY_POINTER_COUNT + 2 }, 83 }; 84 85 for (size_t i = 0; i < testCases.size(); ++i) { 86 const auto& testCase = testCases[i]; 87 auto result = OH_ArkUI_PointerEvent_GetHistoryPointerCount(&std::get<0>(testCase), std::get<1>(testCase)); 88 EXPECT_EQ(result, std::get<2>(testCase)) << "Test case " << i << " failed"; 89 } 90 } 91 92 /** 93 * @tc.name: OH_ArkUI_PointerEvent_GetHistoryPointerCount102 94 * @tc.desc: Test the OH_ArkUI_PointerEvent_GetHistoryPointerCount function with unsupported event types. 95 * @tc.type: FUNC 96 */ 97 HWTEST_F(UIInputEventTest, OH_ArkUI_PointerEvent_GetHistoryPointerCount102, TestSize.Level0) 98 { 99 ArkUIMouseEvent mouseEvent; 100 ArkUIAxisEvent axisEvent; 101 102 std::vector<std::pair<ArkUI_UIInputEvent, ArkUIEventTypeId>> testCases = { 103 // case 1: mouse event 104 { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, C_MOUSE_EVENT_ID, &mouseEvent }, C_MOUSE_EVENT_ID }, 105 // case 2: axis event 106 { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, C_AXIS_EVENT_ID, &axisEvent }, C_AXIS_EVENT_ID }, 107 // case 3: key event 108 { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, C_KEY_EVENT_ID, nullptr }, C_KEY_EVENT_ID }, 109 // case 4: hover event 110 { ArkUI_UIInputEvent { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, C_HOVER_EVENT_ID, nullptr }, C_HOVER_EVENT_ID }, 111 }; 112 113 for (size_t i = 0; i < testCases.size(); ++i) { 114 const auto& testCase = testCases[i]; 115 auto result = OH_ArkUI_PointerEvent_GetHistoryPointerCount(&testCase.first, 0); 116 EXPECT_EQ(result, 0u) << "Unsupported type test " << i << " failed"; 117 } 118 } 119 120 } // namespace OHOS::Ace