• 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 #include "interfaces/native/event/ui_input_event_impl.h"
18 #include "interfaces/native/ui_input_event.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 namespace OHOS::Ace {
23 HWTEST_F(UIInputEventTest, OH_ArkUI_FocusAxisEvent_GetAxisValue_NullEvent, TestSize.Level0)
24 {
25     auto result = OH_ArkUI_FocusAxisEvent_GetAxisValue(nullptr, UI_FOCUS_AXIS_EVENT_ABS_X);
26     EXPECT_EQ(result, 0.0) << "Input event is nullptr, expected 0.0, got " << result;
27 }
28 
29 HWTEST_F(UIInputEventTest, OH_ArkUI_FocusAxisEvent_GetAxisValue_WrongEventTypeId, TestSize.Level0)
30 {
31     ArkUIFocusAxisEvent axisEvent = {};
32     ArkUI_UIInputEvent inputEvent = { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN,
33         C_AXIS_EVENT_ID, // not C_FOCUS_AXIS_EVENT_ID
34         &axisEvent };
35     auto result = OH_ArkUI_FocusAxisEvent_GetAxisValue(&inputEvent, UI_FOCUS_AXIS_EVENT_ABS_X);
36     EXPECT_EQ(result, 0.0) << "EventTypeId != C_FOCUS_AXIS_EVENT_ID, expected 0.0, got " << result;
37 }
38 
39 HWTEST_F(UIInputEventTest, OH_ArkUI_FocusAxisEvent_GetAxisValue_InputEventNull, TestSize.Level0)
40 {
41     ArkUI_UIInputEvent inputEvent = { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, C_FOCUS_AXIS_EVENT_ID, nullptr };
42     auto result = OH_ArkUI_FocusAxisEvent_GetAxisValue(&inputEvent, UI_FOCUS_AXIS_EVENT_ABS_X);
43     EXPECT_EQ(result, 0.0) << "inputEvent is nullptr, expected 0.0, got " << result;
44 }
45 
46 HWTEST_F(UIInputEventTest, OH_ArkUI_FocusAxisEvent_GetAxisValue_AxisVariants, TestSize.Level0)
47 {
48     ArkUIFocusAxisEvent axisEvent = {};
49     axisEvent.absXValue = 1.1;
50     axisEvent.absYValue = 2.2;
51     axisEvent.absZValue = 3.3;
52     axisEvent.absRzValue = 4.4;
53     axisEvent.absGasValue = 5.5;
54     axisEvent.absBrakeValue = 6.6;
55     axisEvent.absHat0XValue = 7.7;
56     axisEvent.absHat0YValue = 8.8;
57 
58     ArkUI_UIInputEvent inputEvent = { ARKUI_UIINPUTEVENT_TYPE_UNKNOWN, C_FOCUS_AXIS_EVENT_ID, &axisEvent };
59 
60     struct AxisTestCase {
61         int32_t axis;
62         double expected;
63         const char* axisName;
64     };
65     std::vector<AxisTestCase> cases = {
66         { UI_FOCUS_AXIS_EVENT_ABS_X, axisEvent.absXValue, "ABS_X" },
67         { UI_FOCUS_AXIS_EVENT_ABS_Y, axisEvent.absYValue, "ABS_Y" },
68         { UI_FOCUS_AXIS_EVENT_ABS_Z, axisEvent.absZValue, "ABS_Z" },
69         { UI_FOCUS_AXIS_EVENT_ABS_RZ, axisEvent.absRzValue, "ABS_RZ" },
70         { UI_FOCUS_AXIS_EVENT_ABS_GAS, axisEvent.absGasValue, "ABS_GAS" },
71         { UI_FOCUS_AXIS_EVENT_ABS_BRAKE, axisEvent.absBrakeValue, "ABS_BRAKE" },
72         { UI_FOCUS_AXIS_EVENT_ABS_HAT0X, axisEvent.absHat0XValue, "ABS_HAT0X" },
73         { UI_FOCUS_AXIS_EVENT_ABS_HAT0Y, axisEvent.absHat0YValue, "ABS_HAT0Y" },
74         { 999, 0.0, "UNKNOWN_AXIS" }, // Invalid axis
75     };
76     int count = 0;
77     for (const auto& testCase : cases) {
78         double result = OH_ArkUI_FocusAxisEvent_GetAxisValue(&inputEvent, testCase.axis);
79         EXPECT_DOUBLE_EQ(result, testCase.expected) << "index = " << count << " : axis = " << testCase.axisName
80                                                     << " expected = " << testCase.expected << " actual = " << result;
81         count++;
82     }
83 }
84 } // namespace OHOS::Ace
85