1 /* 2 * Copyright (c) 2024 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 "event/ui_input_event_impl.h" 17 #include "gtest/gtest.h" 18 #include "interfaces/native/node/event_converter.h" 19 #include "native_node.h" 20 #include "ui_input_event.h" 21 22 #include "frameworks/core/event/ace_events.h" 23 24 using namespace testing; 25 using namespace testing::ext; 26 namespace OHOS::Ace { 27 namespace { 28 constexpr int32_t ARKUI_DEVICE_ID = 1; 29 constexpr uint64_t ARKUI_TIME = 20; 30 } // namespace 31 class UIInputEventTest : public testing::Test { 32 public: SetUpTestSuite()33 static void SetUpTestSuite() {} TearDownTestSuite()34 static void TearDownTestSuite() {} 35 }; 36 37 /** 38 * @tc.name: UIInputEventTest001 39 * @tc.desc: Test the UIInputEvent property functions in focus axis event case. 40 * @tc.type: FUNC 41 */ 42 HWTEST_F(UIInputEventTest, UIInputEventTest001, TestSize.Level1) 43 { 44 /** 45 * @tc.steps: step1.create ArkUI_NodeEvent, related function is called. 46 */ 47 ArkUI_NodeEvent nodeEvent; 48 ArkUINodeEvent event; 49 ArkUI_UIInputEvent uiInputEvent; 50 event.kind = ArkUIEventCategory::FOCUS_AXIS_EVENT; 51 event.focusAxisEvent.subKind = ArkUIEventSubKind::ON_FOCUS_AXIS; 52 event.focusAxisEvent.absXValue = 0.5; 53 event.focusAxisEvent.absYValue = 0.5; 54 event.focusAxisEvent.absZValue = 0.5; 55 event.focusAxisEvent.absRzValue = 0.5; 56 event.focusAxisEvent.absHat0XValue = 1; 57 event.focusAxisEvent.absHat0YValue = 1; 58 event.focusAxisEvent.absBrakeValue = 0.5; 59 event.focusAxisEvent.absGasValue = 0.5; 60 event.focusAxisEvent.sourceType = static_cast<int32_t>(SourceType::MOUSE); 61 event.focusAxisEvent.toolType = static_cast<int32_t>(SourceTool::JOYSTICK); 62 event.focusAxisEvent.deviceId = ARKUI_DEVICE_ID; 63 event.focusAxisEvent.timeStamp = ARKUI_TIME; 64 uiInputEvent.inputEvent = &event.focusAxisEvent; 65 uiInputEvent.eventTypeId = C_FOCUS_AXIS_EVENT_ID; 66 nodeEvent.origin = &uiInputEvent; 67 nodeEvent.category = NodeEventCategory::NODE_EVENT_CATEGORY_INPUT_EVENT; 68 auto inputEvent = OH_ArkUI_NodeEvent_GetInputEvent(&nodeEvent); 69 70 /** 71 * @tc.steps: step2. call functions. 72 */ 73 auto absXValue = OH_ArkUI_FocusAxisEvent_GetAxisValue(inputEvent, UI_FOCUS_AXIS_EVENT_ABS_X); 74 auto absYValue = OH_ArkUI_FocusAxisEvent_GetAxisValue(inputEvent, UI_FOCUS_AXIS_EVENT_ABS_Y); 75 auto absZValue = OH_ArkUI_FocusAxisEvent_GetAxisValue(inputEvent, UI_FOCUS_AXIS_EVENT_ABS_Z); 76 auto absRzValue = OH_ArkUI_FocusAxisEvent_GetAxisValue(inputEvent, UI_FOCUS_AXIS_EVENT_ABS_RZ); 77 auto absHat0XValue = OH_ArkUI_FocusAxisEvent_GetAxisValue(inputEvent, UI_FOCUS_AXIS_EVENT_ABS_HAT0X); 78 auto absHat0YValue = OH_ArkUI_FocusAxisEvent_GetAxisValue(inputEvent, UI_FOCUS_AXIS_EVENT_ABS_HAT0Y); 79 auto absBrakeValue = OH_ArkUI_FocusAxisEvent_GetAxisValue(inputEvent, UI_FOCUS_AXIS_EVENT_ABS_BRAKE); 80 auto absGasValue = OH_ArkUI_FocusAxisEvent_GetAxisValue(inputEvent, UI_FOCUS_AXIS_EVENT_ABS_GAS); 81 auto diviceId = OH_ArkUI_UIInputEvent_GetDeviceId(inputEvent); 82 auto time = OH_ArkUI_UIInputEvent_GetEventTime(inputEvent); 83 auto sourceType = OH_ArkUI_UIInputEvent_GetSourceType(inputEvent); 84 auto toolType = OH_ArkUI_UIInputEvent_GetToolType(inputEvent); 85 86 /** 87 * @tc.expected: Return expected results. 88 */ 89 EXPECT_EQ(absXValue, 0.5); 90 EXPECT_EQ(absYValue, 0.5); 91 EXPECT_EQ(absZValue, 0.5); 92 EXPECT_EQ(absRzValue, 0.5); 93 EXPECT_EQ(absHat0XValue, 1); 94 EXPECT_EQ(absHat0YValue, 1); 95 EXPECT_EQ(absBrakeValue, 0.5); 96 EXPECT_EQ(absGasValue, 0.5); 97 EXPECT_EQ(diviceId, ARKUI_DEVICE_ID); 98 EXPECT_EQ(time, ARKUI_TIME); 99 EXPECT_EQ(sourceType, UI_INPUT_EVENTT_SOURCE_TYPE_MOUSE); 100 EXPECT_EQ(toolType, UI_INPUT_EVENT_TOOL_TYPE_JOYSTICK); 101 } 102 } // namespace OHOS::Ace