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 #include "interfaces/native/ui_input_event.h" 18 #include "interfaces/native/event/ui_input_event_impl.h" 19 20 using namespace testing; 21 using namespace testing::ext; 22 23 namespace OHOS::Ace { 24 25 HWTEST_F(UIInputEventTest, OH_ArkUI_UIInputEvent_GetEventTargetWidth_Null, TestSize.Level0) 26 { 27 float result = OH_ArkUI_UIInputEvent_GetEventTargetWidth(nullptr); 28 EXPECT_FLOAT_EQ(result, 0.0f) << "event is nullptr, should return 0.0f"; 29 } 30 31 HWTEST_F(UIInputEventTest, OH_ArkUI_UIInputEvent_GetEventTargetWidth_AllCases, TestSize.Level0) 32 { 33 ArkUITouchEvent touchEvent = {}; 34 touchEvent.width = 11.1f; 35 36 OHOS::Ace::TouchEvent baseTouchEvent = {}; 37 baseTouchEvent.width = 12; 38 39 ArkUIAxisEvent axisEvent = {}; 40 axisEvent.width = 13.3f; 41 42 OHOS::Ace::AxisEvent baseAxisEvent = {}; 43 baseAxisEvent.width = 14.4f; 44 45 ArkUIMouseEvent mouseEvent = {}; 46 mouseEvent.width = 15.5f; 47 48 ArkUIHoverEvent hoverEvent = {}; 49 hoverEvent.width = 16.6f; 50 51 ArkUIClickEvent clickEvent = {}; 52 clickEvent.width = 17.7f; 53 54 ArkUIFocusAxisEvent focusAxisEvent = {}; 55 focusAxisEvent.width = 18.8f; 56 57 std::vector<std::pair<ArkUI_UIInputEvent, float>> testCases = { 58 { { ARKUI_UIINPUTEVENT_TYPE_TOUCH, C_TOUCH_EVENT_ID, &touchEvent }, 11.1f }, 59 { { ARKUI_UIINPUTEVENT_TYPE_TOUCH, TOUCH_EVENT_ID, &baseTouchEvent }, 12 }, 60 { { ARKUI_UIINPUTEVENT_TYPE_AXIS, C_AXIS_EVENT_ID, &axisEvent }, 13.3f }, 61 { { ARKUI_UIINPUTEVENT_TYPE_AXIS, AXIS_EVENT_ID, &baseAxisEvent }, 14.4f }, 62 { { ARKUI_UIINPUTEVENT_TYPE_MOUSE, C_MOUSE_EVENT_ID, &mouseEvent }, 15.5f }, 63 { { ARKUI_UIINPUTEVENT_TYPE_MOUSE, C_HOVER_EVENT_ID, &hoverEvent }, 16.6f }, 64 { { ARKUI_UIINPUTEVENT_TYPE_MOUSE, C_CLICK_EVENT_ID, &clickEvent }, 17.7f }, 65 { { ARKUI_UIINPUTEVENT_TYPE_AXIS, C_FOCUS_AXIS_EVENT_ID, &focusAxisEvent }, 18.8f }, 66 67 { { ARKUI_UIINPUTEVENT_TYPE_TOUCH, C_TOUCH_EVENT_ID, nullptr }, 0 }, 68 { { ARKUI_UIINPUTEVENT_TYPE_AXIS, C_KEY_EVENT_ID, &touchEvent }, 0.0f }, 69 { { ARKUI_UIINPUTEVENT_TYPE_MOUSE, AXIS_EVENT_ID, &mouseEvent }, 0.0f }, 70 }; 71 72 int count = 0; 73 for (const auto& test : testCases) { 74 float result = OH_ArkUI_UIInputEvent_GetEventTargetWidth(&test.first); 75 EXPECT_FLOAT_EQ(result, test.second) 76 << "index=" << count 77 << " : inputType=" << test.first.inputType 78 << " , eventTypeId=" << test.first.eventTypeId 79 << " , expect=" << test.second 80 << " , got=" << result; 81 count++; 82 } 83 } 84 85 } // namespace OHOS::Ace 86