1f6603c60Sopenharmony_ci/* 2f6603c60Sopenharmony_ci # Copyright (c) 2024 Huawei Device Co., Ltd. 3f6603c60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4f6603c60Sopenharmony_ci * you may not use this file except in compliance with the License. 5f6603c60Sopenharmony_ci * You may obtain a copy of the License at 6f6603c60Sopenharmony_ci * 7f6603c60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8f6603c60Sopenharmony_ci * 9f6603c60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10f6603c60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11f6603c60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12f6603c60Sopenharmony_ci * See the License for the specific language governing permissions and 13f6603c60Sopenharmony_ci * limitations under the License. 14f6603c60Sopenharmony_ci */ 15f6603c60Sopenharmony_ci 16f6603c60Sopenharmony_ci#include <gtest/gtest.h> 17f6603c60Sopenharmony_ci 18f6603c60Sopenharmony_ci#include "oh_input_manager.h" 19f6603c60Sopenharmony_ci#include "oh_key_code.h" 20f6603c60Sopenharmony_ci 21f6603c60Sopenharmony_cinamespace OHOS { 22f6603c60Sopenharmony_cinamespace MMI { 23f6603c60Sopenharmony_cinamespace { 24f6603c60Sopenharmony_ciusing namespace testing::ext; 25f6603c60Sopenharmony_ci} // namespace 26f6603c60Sopenharmony_ci 27f6603c60Sopenharmony_ciclass InputNativeTest : public testing::Test { 28f6603c60Sopenharmony_cipublic: 29f6603c60Sopenharmony_ci static void SetUpTestCase(void) {} 30f6603c60Sopenharmony_ci static void TearDownTestCase(void) {} 31f6603c60Sopenharmony_ci 32f6603c60Sopenharmony_ci void SetUp() {} 33f6603c60Sopenharmony_ci void TearDown() {} 34f6603c60Sopenharmony_ci}; 35f6603c60Sopenharmony_ci 36f6603c60Sopenharmony_ci/** 37f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_KeyState_001 38f6603c60Sopenharmony_ci * @tc.desc: Verify the create and destroy of key states 39f6603c60Sopenharmony_ci * @tc.type: FUNC 40f6603c60Sopenharmony_ci * @tc.require: 41f6603c60Sopenharmony_ci */ 42f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_KeyState_001, TestSize.Level1) 43f6603c60Sopenharmony_ci{ 44f6603c60Sopenharmony_ci struct Input_KeyState *keyState = OH_Input_CreateKeyState(); 45f6603c60Sopenharmony_ci if (keyState == nullptr) { 46f6603c60Sopenharmony_ci ASSERT_EQ(keyState, nullptr); 47f6603c60Sopenharmony_ci } else { 48f6603c60Sopenharmony_ci ASSERT_NE(keyState, nullptr); 49f6603c60Sopenharmony_ci OH_Input_DestroyKeyState(&keyState); 50f6603c60Sopenharmony_ci } 51f6603c60Sopenharmony_ci} 52f6603c60Sopenharmony_ci 53f6603c60Sopenharmony_ci/** 54f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_KeyCode_001 55f6603c60Sopenharmony_ci * @tc.desc: Verify the set and get of key states 56f6603c60Sopenharmony_ci * @tc.type: FUNC 57f6603c60Sopenharmony_ci * @tc.require: 58f6603c60Sopenharmony_ci */ 59f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_KeyCode_001, TestSize.Level1) 60f6603c60Sopenharmony_ci{ 61f6603c60Sopenharmony_ci struct Input_KeyState *keyState = OH_Input_CreateKeyState(); 62f6603c60Sopenharmony_ci ASSERT_NE(keyState, nullptr); 63f6603c60Sopenharmony_ci OH_Input_SetKeyCode(keyState, 2000); 64f6603c60Sopenharmony_ci int32_t keyCode = OH_Input_GetKeyCode(keyState); 65f6603c60Sopenharmony_ci ASSERT_EQ(keyCode, 2000); 66f6603c60Sopenharmony_ci OH_Input_DestroyKeyState(&keyState); 67f6603c60Sopenharmony_ci} 68f6603c60Sopenharmony_ci 69f6603c60Sopenharmony_ci/** 70f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_KeyPressed_001 71f6603c60Sopenharmony_ci * @tc.desc: Verify the set and get of key pressed 72f6603c60Sopenharmony_ci * @tc.type: FUNC 73f6603c60Sopenharmony_ci * @tc.require: 74f6603c60Sopenharmony_ci */ 75f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_KeyPressed_001, TestSize.Level1) 76f6603c60Sopenharmony_ci{ 77f6603c60Sopenharmony_ci struct Input_KeyState *keyState = OH_Input_CreateKeyState(); 78f6603c60Sopenharmony_ci ASSERT_NE(keyState, nullptr); 79f6603c60Sopenharmony_ci OH_Input_SetKeyPressed(keyState, 0); 80f6603c60Sopenharmony_ci int32_t keyAction = OH_Input_GetKeyPressed(keyState); 81f6603c60Sopenharmony_ci ASSERT_EQ(keyAction, 0); 82f6603c60Sopenharmony_ci OH_Input_DestroyKeyState(&keyState); 83f6603c60Sopenharmony_ci} 84f6603c60Sopenharmony_ci 85f6603c60Sopenharmony_ci/** 86f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_KeySwitch_001 87f6603c60Sopenharmony_ci * @tc.desc: Verify the set and get of key switch 88f6603c60Sopenharmony_ci * @tc.type: FUNC 89f6603c60Sopenharmony_ci * @tc.require: 90f6603c60Sopenharmony_ci */ 91f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_KeySwitch_001, TestSize.Level1) 92f6603c60Sopenharmony_ci{ 93f6603c60Sopenharmony_ci struct Input_KeyState *keyState = OH_Input_CreateKeyState(); 94f6603c60Sopenharmony_ci ASSERT_NE(keyState, nullptr); 95f6603c60Sopenharmony_ci OH_Input_SetKeySwitch(keyState, 2); 96f6603c60Sopenharmony_ci int32_t keySwitch = OH_Input_GetKeySwitch(keyState); 97f6603c60Sopenharmony_ci ASSERT_EQ(keySwitch, 2); 98f6603c60Sopenharmony_ci OH_Input_DestroyKeyState(&keyState); 99f6603c60Sopenharmony_ci} 100f6603c60Sopenharmony_ci 101f6603c60Sopenharmony_ci/** 102f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_GetKeyState_001 103f6603c60Sopenharmony_ci * @tc.desc: Verify the GetKeyState 104f6603c60Sopenharmony_ci * @tc.type: FUNC 105f6603c60Sopenharmony_ci * @tc.require: 106f6603c60Sopenharmony_ci */ 107f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_GetKeyState_001, TestSize.Level1) 108f6603c60Sopenharmony_ci{ 109f6603c60Sopenharmony_ci struct Input_KeyState* keyState = OH_Input_CreateKeyState(); 110f6603c60Sopenharmony_ci ASSERT_NE(keyState, nullptr); 111f6603c60Sopenharmony_ci OH_Input_SetKeyCode(keyState, KEYCODE_DPAD_UP); 112f6603c60Sopenharmony_ci OH_Input_GetKeyState(keyState); 113f6603c60Sopenharmony_ci EXPECT_EQ(OH_Input_GetKeyPressed(keyState), KEY_RELEASED); 114f6603c60Sopenharmony_ci EXPECT_EQ(OH_Input_GetKeySwitch(keyState), KEY_DEFAULT); 115f6603c60Sopenharmony_ci EXPECT_EQ(OH_Input_GetKeyState(keyState), INPUT_SUCCESS); 116f6603c60Sopenharmony_ci OH_Input_DestroyKeyState(&keyState); 117f6603c60Sopenharmony_ci} 118f6603c60Sopenharmony_ci 119f6603c60Sopenharmony_ci/** 120f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_InjectKeyEvent_001 121f6603c60Sopenharmony_ci * @tc.desc: Verify the InjectKeyEvent 122f6603c60Sopenharmony_ci * @tc.type: FUNC 123f6603c60Sopenharmony_ci * @tc.require: 124f6603c60Sopenharmony_ci */ 125f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_InjectKeyEvent_001, TestSize.Level1) 126f6603c60Sopenharmony_ci{ 127f6603c60Sopenharmony_ci Input_KeyEvent *keyEvent = OH_Input_CreateKeyEvent(); 128f6603c60Sopenharmony_ci ASSERT_NE(keyEvent, nullptr); 129f6603c60Sopenharmony_ci OH_Input_SetKeyEventAction(keyEvent, KEY_ACTION_DOWN); 130f6603c60Sopenharmony_ci OH_Input_SetKeyEventKeyCode(keyEvent, KEYCODE_UNKNOWN); 131f6603c60Sopenharmony_ci OH_Input_SetKeyEventActionTime(keyEvent, -1); 132f6603c60Sopenharmony_ci int32_t retResult = OH_Input_InjectKeyEvent(keyEvent); 133f6603c60Sopenharmony_ci EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR); 134f6603c60Sopenharmony_ci OH_Input_SetKeyEventAction(keyEvent, KEY_ACTION_UP); 135f6603c60Sopenharmony_ci OH_Input_SetKeyEventKeyCode(keyEvent, KEYCODE_UNKNOWN); 136f6603c60Sopenharmony_ci OH_Input_SetKeyEventActionTime(keyEvent, -1); 137f6603c60Sopenharmony_ci retResult = OH_Input_InjectKeyEvent(keyEvent); 138f6603c60Sopenharmony_ci EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR); 139f6603c60Sopenharmony_ci OH_Input_CancelInjection(); 140f6603c60Sopenharmony_ci OH_Input_DestroyKeyEvent(&keyEvent); 141f6603c60Sopenharmony_ci EXPECT_EQ(keyEvent, nullptr); 142f6603c60Sopenharmony_ci} 143f6603c60Sopenharmony_ci 144f6603c60Sopenharmony_ci/** 145f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_KeyEventAction_001 146f6603c60Sopenharmony_ci * @tc.desc: Verify the set and get of keyEvent action 147f6603c60Sopenharmony_ci * @tc.type: FUNC 148f6603c60Sopenharmony_ci * @tc.require: 149f6603c60Sopenharmony_ci */ 150f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_KeyEventAction_001, TestSize.Level1) 151f6603c60Sopenharmony_ci{ 152f6603c60Sopenharmony_ci Input_KeyEvent *keyEvent = OH_Input_CreateKeyEvent(); 153f6603c60Sopenharmony_ci ASSERT_NE(keyEvent, nullptr); 154f6603c60Sopenharmony_ci OH_Input_SetKeyEventAction(keyEvent, KEY_ACTION_DOWN); 155f6603c60Sopenharmony_ci int32_t action = OH_Input_GetKeyEventAction(keyEvent); 156f6603c60Sopenharmony_ci EXPECT_EQ(action, KEY_ACTION_DOWN); 157f6603c60Sopenharmony_ci OH_Input_DestroyKeyEvent(&keyEvent); 158f6603c60Sopenharmony_ci EXPECT_EQ(keyEvent, nullptr); 159f6603c60Sopenharmony_ci} 160f6603c60Sopenharmony_ci 161f6603c60Sopenharmony_ci/** 162f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_KeyEventKeyCode_001 163f6603c60Sopenharmony_ci * @tc.desc: Verify the set and get of keyEvent code 164f6603c60Sopenharmony_ci * @tc.type: FUNC 165f6603c60Sopenharmony_ci * @tc.require: 166f6603c60Sopenharmony_ci */ 167f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_KeyEventKeyCode_001, TestSize.Level1) 168f6603c60Sopenharmony_ci{ 169f6603c60Sopenharmony_ci Input_KeyEvent *keyEvent = OH_Input_CreateKeyEvent(); 170f6603c60Sopenharmony_ci ASSERT_NE(keyEvent, nullptr); 171f6603c60Sopenharmony_ci OH_Input_SetKeyEventKeyCode(keyEvent, KEYCODE_A); 172f6603c60Sopenharmony_ci int32_t keyCode = OH_Input_GetKeyEventKeyCode(keyEvent); 173f6603c60Sopenharmony_ci EXPECT_EQ(keyCode, KEYCODE_A); 174f6603c60Sopenharmony_ci OH_Input_DestroyKeyEvent(&keyEvent); 175f6603c60Sopenharmony_ci EXPECT_EQ(keyEvent, nullptr); 176f6603c60Sopenharmony_ci} 177f6603c60Sopenharmony_ci 178f6603c60Sopenharmony_ci/** 179f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_KeyEventActionTime_001 180f6603c60Sopenharmony_ci * @tc.desc: Verify the set and get of keyEvent time 181f6603c60Sopenharmony_ci * @tc.type: FUNC 182f6603c60Sopenharmony_ci * @tc.require: 183f6603c60Sopenharmony_ci */ 184f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_KeyEventActionTime_001, TestSize.Level1) 185f6603c60Sopenharmony_ci{ 186f6603c60Sopenharmony_ci Input_KeyEvent *keyEvent = OH_Input_CreateKeyEvent(); 187f6603c60Sopenharmony_ci ASSERT_NE(keyEvent, nullptr); 188f6603c60Sopenharmony_ci OH_Input_SetKeyEventActionTime(keyEvent, 200); 189f6603c60Sopenharmony_ci int64_t actionTime = OH_Input_GetKeyEventActionTime(keyEvent); 190f6603c60Sopenharmony_ci EXPECT_EQ(actionTime, 200); 191f6603c60Sopenharmony_ci OH_Input_DestroyKeyEvent(&keyEvent); 192f6603c60Sopenharmony_ci EXPECT_EQ(keyEvent, nullptr); 193f6603c60Sopenharmony_ci} 194f6603c60Sopenharmony_ci 195f6603c60Sopenharmony_ci/** 196f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_InjectMouseEvent_001 197f6603c60Sopenharmony_ci * @tc.desc: Verify the InjectMouseEvent 198f6603c60Sopenharmony_ci * @tc.type: FUNC 199f6603c60Sopenharmony_ci * @tc.require: 200f6603c60Sopenharmony_ci */ 201f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_InjectMouseEvent_001, TestSize.Level1) 202f6603c60Sopenharmony_ci{ 203f6603c60Sopenharmony_ci Input_MouseEvent *mouseEvent = OH_Input_CreateMouseEvent(); 204f6603c60Sopenharmony_ci ASSERT_NE(mouseEvent, nullptr); 205f6603c60Sopenharmony_ci OH_Input_SetMouseEventAction(mouseEvent, MOUSE_ACTION_MOVE); 206f6603c60Sopenharmony_ci OH_Input_SetMouseEventDisplayX(mouseEvent, 350); 207f6603c60Sopenharmony_ci OH_Input_SetMouseEventDisplayY(mouseEvent, 350); 208f6603c60Sopenharmony_ci OH_Input_SetMouseEventButton(mouseEvent, -2); 209f6603c60Sopenharmony_ci OH_Input_SetMouseEventActionTime(mouseEvent, -1); 210f6603c60Sopenharmony_ci int32_t retResult = OH_Input_InjectMouseEvent(mouseEvent); 211f6603c60Sopenharmony_ci EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR); 212f6603c60Sopenharmony_ci OH_Input_DestroyMouseEvent(&mouseEvent); 213f6603c60Sopenharmony_ci EXPECT_EQ(mouseEvent, nullptr); 214f6603c60Sopenharmony_ci} 215f6603c60Sopenharmony_ci 216f6603c60Sopenharmony_ci/** 217f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_InjectMouseEvent_002 218f6603c60Sopenharmony_ci * @tc.desc: Verify the InjectMouseEvent 219f6603c60Sopenharmony_ci * @tc.type: FUNC 220f6603c60Sopenharmony_ci * @tc.require: 221f6603c60Sopenharmony_ci */ 222f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_InjectMouseEvent_002, TestSize.Level1) 223f6603c60Sopenharmony_ci{ 224f6603c60Sopenharmony_ci Input_MouseEvent *mouseEvent = OH_Input_CreateMouseEvent(); 225f6603c60Sopenharmony_ci ASSERT_NE(mouseEvent, nullptr); 226f6603c60Sopenharmony_ci OH_Input_SetMouseEventAction(mouseEvent, MOUSE_ACTION_AXIS_BEGIN); 227f6603c60Sopenharmony_ci OH_Input_SetMouseEventDisplayX(mouseEvent, 350); 228f6603c60Sopenharmony_ci OH_Input_SetMouseEventDisplayY(mouseEvent, 350); 229f6603c60Sopenharmony_ci OH_Input_SetMouseEventAxisType(mouseEvent, MOUSE_AXIS_SCROLL_VERTICAL); 230f6603c60Sopenharmony_ci OH_Input_SetMouseEventAxisValue(mouseEvent, 1.1); 231f6603c60Sopenharmony_ci OH_Input_SetMouseEventButton(mouseEvent, -2); 232f6603c60Sopenharmony_ci OH_Input_SetMouseEventActionTime(mouseEvent, -1); 233f6603c60Sopenharmony_ci int32_t retResult = OH_Input_InjectMouseEvent(mouseEvent); 234f6603c60Sopenharmony_ci EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR); 235f6603c60Sopenharmony_ci OH_Input_SetMouseEventAction(mouseEvent, MOUSE_ACTION_AXIS_END); 236f6603c60Sopenharmony_ci OH_Input_SetMouseEventDisplayX(mouseEvent, 350); 237f6603c60Sopenharmony_ci OH_Input_SetMouseEventDisplayY(mouseEvent, 350); 238f6603c60Sopenharmony_ci OH_Input_SetMouseEventAxisType(mouseEvent, MOUSE_AXIS_SCROLL_VERTICAL); 239f6603c60Sopenharmony_ci OH_Input_SetMouseEventAxisValue(mouseEvent, 1.1); 240f6603c60Sopenharmony_ci OH_Input_SetMouseEventButton(mouseEvent, -2); 241f6603c60Sopenharmony_ci OH_Input_SetMouseEventActionTime(mouseEvent, -1); 242f6603c60Sopenharmony_ci retResult = OH_Input_InjectMouseEvent(mouseEvent); 243f6603c60Sopenharmony_ci EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR); 244f6603c60Sopenharmony_ci OH_Input_DestroyMouseEvent(&mouseEvent); 245f6603c60Sopenharmony_ci EXPECT_EQ(mouseEvent, nullptr); 246f6603c60Sopenharmony_ci} 247f6603c60Sopenharmony_ci 248f6603c60Sopenharmony_ci/** 249f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_MouseEventAction_001 250f6603c60Sopenharmony_ci * @tc.desc: Verify the set and get of mouseEvent action 251f6603c60Sopenharmony_ci * @tc.type: FUNC 252f6603c60Sopenharmony_ci * @tc.require: 253f6603c60Sopenharmony_ci */ 254f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_MouseEventAction_001, TestSize.Level1) 255f6603c60Sopenharmony_ci{ 256f6603c60Sopenharmony_ci Input_MouseEvent *mouseEvent = OH_Input_CreateMouseEvent(); 257f6603c60Sopenharmony_ci ASSERT_NE(mouseEvent, nullptr); 258f6603c60Sopenharmony_ci OH_Input_SetMouseEventAction(mouseEvent, MOUSE_ACTION_BUTTON_DOWN); 259f6603c60Sopenharmony_ci int32_t action = OH_Input_GetMouseEventAction(mouseEvent); 260f6603c60Sopenharmony_ci EXPECT_EQ(action, MOUSE_ACTION_BUTTON_DOWN); 261f6603c60Sopenharmony_ci OH_Input_DestroyMouseEvent(&mouseEvent); 262f6603c60Sopenharmony_ci EXPECT_EQ(mouseEvent, nullptr); 263f6603c60Sopenharmony_ci} 264f6603c60Sopenharmony_ci 265f6603c60Sopenharmony_ci/** 266f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_MouseEventDisplayX_001 267f6603c60Sopenharmony_ci * @tc.desc: Verify the set and get of mouseEvent displayX 268f6603c60Sopenharmony_ci * @tc.type: FUNC 269f6603c60Sopenharmony_ci * @tc.require: 270f6603c60Sopenharmony_ci */ 271f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_MouseEventDisplayX_001, TestSize.Level1) 272f6603c60Sopenharmony_ci{ 273f6603c60Sopenharmony_ci Input_MouseEvent *mouseEvent = OH_Input_CreateMouseEvent(); 274f6603c60Sopenharmony_ci ASSERT_NE(mouseEvent, nullptr); 275f6603c60Sopenharmony_ci OH_Input_SetMouseEventDisplayX(mouseEvent, 100); 276f6603c60Sopenharmony_ci int32_t displayX = OH_Input_GetMouseEventDisplayX(mouseEvent); 277f6603c60Sopenharmony_ci EXPECT_EQ(displayX, 100); 278f6603c60Sopenharmony_ci OH_Input_DestroyMouseEvent(&mouseEvent); 279f6603c60Sopenharmony_ci EXPECT_EQ(mouseEvent, nullptr); 280f6603c60Sopenharmony_ci} 281f6603c60Sopenharmony_ci 282f6603c60Sopenharmony_ci/** 283f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_MouseEventDisplayY_001 284f6603c60Sopenharmony_ci * @tc.desc: Verify the set and get of mouseEvent displayY 285f6603c60Sopenharmony_ci * @tc.type: FUNC 286f6603c60Sopenharmony_ci * @tc.require: 287f6603c60Sopenharmony_ci */ 288f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_MouseEventDisplayY_001, TestSize.Level1) 289f6603c60Sopenharmony_ci{ 290f6603c60Sopenharmony_ci Input_MouseEvent *mouseEvent = OH_Input_CreateMouseEvent(); 291f6603c60Sopenharmony_ci ASSERT_NE(mouseEvent, nullptr); 292f6603c60Sopenharmony_ci OH_Input_SetMouseEventDisplayY(mouseEvent, 100); 293f6603c60Sopenharmony_ci int32_t displayY = OH_Input_GetMouseEventDisplayY(mouseEvent); 294f6603c60Sopenharmony_ci EXPECT_EQ(displayY, 100); 295f6603c60Sopenharmony_ci OH_Input_DestroyMouseEvent(&mouseEvent); 296f6603c60Sopenharmony_ci EXPECT_EQ(mouseEvent, nullptr); 297f6603c60Sopenharmony_ci} 298f6603c60Sopenharmony_ci 299f6603c60Sopenharmony_ci/** 300f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_MouseEventButton_001 301f6603c60Sopenharmony_ci * @tc.desc: Verify the set and get of mouseEvent button 302f6603c60Sopenharmony_ci * @tc.type: FUNC 303f6603c60Sopenharmony_ci * @tc.require: 304f6603c60Sopenharmony_ci */ 305f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_MouseEventButton_001, TestSize.Level1) 306f6603c60Sopenharmony_ci{ 307f6603c60Sopenharmony_ci Input_MouseEvent *mouseEvent = OH_Input_CreateMouseEvent(); 308f6603c60Sopenharmony_ci ASSERT_NE(mouseEvent, nullptr); 309f6603c60Sopenharmony_ci OH_Input_SetMouseEventButton(mouseEvent, MOUSE_BUTTON_LEFT); 310f6603c60Sopenharmony_ci int32_t button = OH_Input_GetMouseEventButton(mouseEvent); 311f6603c60Sopenharmony_ci EXPECT_EQ(button, MOUSE_BUTTON_LEFT); 312f6603c60Sopenharmony_ci OH_Input_DestroyMouseEvent(&mouseEvent); 313f6603c60Sopenharmony_ci EXPECT_EQ(mouseEvent, nullptr); 314f6603c60Sopenharmony_ci} 315f6603c60Sopenharmony_ci 316f6603c60Sopenharmony_ci/** 317f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_MouseEventAxisType_001 318f6603c60Sopenharmony_ci * @tc.desc: Verify the set and get of mouseEvent axisType 319f6603c60Sopenharmony_ci * @tc.type: FUNC 320f6603c60Sopenharmony_ci * @tc.require: 321f6603c60Sopenharmony_ci */ 322f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_MouseEventAxisType_001, TestSize.Level1) 323f6603c60Sopenharmony_ci{ 324f6603c60Sopenharmony_ci Input_MouseEvent *mouseEvent = OH_Input_CreateMouseEvent(); 325f6603c60Sopenharmony_ci ASSERT_NE(mouseEvent, nullptr); 326f6603c60Sopenharmony_ci OH_Input_SetMouseEventAxisType(mouseEvent, MOUSE_AXIS_SCROLL_VERTICAL); 327f6603c60Sopenharmony_ci int32_t axisType = OH_Input_GetMouseEventAxisType(mouseEvent); 328f6603c60Sopenharmony_ci EXPECT_EQ(axisType, MOUSE_BUTTON_LEFT); 329f6603c60Sopenharmony_ci OH_Input_DestroyMouseEvent(&mouseEvent); 330f6603c60Sopenharmony_ci EXPECT_EQ(mouseEvent, nullptr); 331f6603c60Sopenharmony_ci} 332f6603c60Sopenharmony_ci 333f6603c60Sopenharmony_ci/** 334f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_MouseEventAxisValue_001 335f6603c60Sopenharmony_ci * @tc.desc: Verify the set and get of mouseEvent axisValue 336f6603c60Sopenharmony_ci * @tc.type: FUNC 337f6603c60Sopenharmony_ci * @tc.require: 338f6603c60Sopenharmony_ci */ 339f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_MouseEventAxisValue_001, TestSize.Level1) 340f6603c60Sopenharmony_ci{ 341f6603c60Sopenharmony_ci Input_MouseEvent *mouseEvent = OH_Input_CreateMouseEvent(); 342f6603c60Sopenharmony_ci ASSERT_NE(mouseEvent, nullptr); 343f6603c60Sopenharmony_ci OH_Input_SetMouseEventAxisValue(mouseEvent, 15.0); 344f6603c60Sopenharmony_ci float axisValue = OH_Input_GetMouseEventAxisValue(mouseEvent); 345f6603c60Sopenharmony_ci EXPECT_EQ(axisValue, 15.0); 346f6603c60Sopenharmony_ci OH_Input_DestroyMouseEvent(&mouseEvent); 347f6603c60Sopenharmony_ci EXPECT_EQ(mouseEvent, nullptr); 348f6603c60Sopenharmony_ci} 349f6603c60Sopenharmony_ci 350f6603c60Sopenharmony_ci/** 351f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_MouseEventActionTime_001 352f6603c60Sopenharmony_ci * @tc.desc: Verify the set and get of mouseEvent actionTime 353f6603c60Sopenharmony_ci * @tc.type: FUNC 354f6603c60Sopenharmony_ci * @tc.require: 355f6603c60Sopenharmony_ci */ 356f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_MouseEventActionTime_001, TestSize.Level1) 357f6603c60Sopenharmony_ci{ 358f6603c60Sopenharmony_ci Input_MouseEvent *mouseEvent = OH_Input_CreateMouseEvent(); 359f6603c60Sopenharmony_ci ASSERT_NE(mouseEvent, nullptr); 360f6603c60Sopenharmony_ci OH_Input_SetMouseEventActionTime(mouseEvent, 200); 361f6603c60Sopenharmony_ci int64_t actionTime = OH_Input_GetMouseEventActionTime(mouseEvent); 362f6603c60Sopenharmony_ci EXPECT_EQ(actionTime, 200); 363f6603c60Sopenharmony_ci OH_Input_DestroyMouseEvent(&mouseEvent); 364f6603c60Sopenharmony_ci EXPECT_EQ(mouseEvent, nullptr); 365f6603c60Sopenharmony_ci} 366f6603c60Sopenharmony_ci 367f6603c60Sopenharmony_ci/** 368f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_InjectTouchEvent_001 369f6603c60Sopenharmony_ci * @tc.desc: Verify the InjectTouchEvent 370f6603c60Sopenharmony_ci * @tc.type: FUNC 371f6603c60Sopenharmony_ci * @tc.require: 372f6603c60Sopenharmony_ci */ 373f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_InjectTouchEvent_001, TestSize.Level1) 374f6603c60Sopenharmony_ci{ 375f6603c60Sopenharmony_ci Input_TouchEvent *touchEvent = OH_Input_CreateTouchEvent(); 376f6603c60Sopenharmony_ci ASSERT_NE(touchEvent, nullptr); 377f6603c60Sopenharmony_ci OH_Input_SetTouchEventAction(touchEvent, TOUCH_ACTION_DOWN); 378f6603c60Sopenharmony_ci OH_Input_SetTouchEventFingerId(touchEvent, 0); 379f6603c60Sopenharmony_ci OH_Input_SetTouchEventDisplayX(touchEvent, 671); 380f6603c60Sopenharmony_ci OH_Input_SetTouchEventDisplayY(touchEvent, -10); 381f6603c60Sopenharmony_ci OH_Input_SetTouchEventActionTime(touchEvent, -1); 382f6603c60Sopenharmony_ci int32_t retResult = OH_Input_InjectTouchEvent(touchEvent); 383f6603c60Sopenharmony_ci EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR); 384f6603c60Sopenharmony_ci OH_Input_SetTouchEventAction(touchEvent, TOUCH_ACTION_UP); 385f6603c60Sopenharmony_ci OH_Input_SetTouchEventFingerId(touchEvent, 0); 386f6603c60Sopenharmony_ci OH_Input_SetTouchEventDisplayX(touchEvent, 671); 387f6603c60Sopenharmony_ci OH_Input_SetTouchEventDisplayY(touchEvent, -10); 388f6603c60Sopenharmony_ci OH_Input_SetTouchEventActionTime(touchEvent, -1); 389f6603c60Sopenharmony_ci retResult = OH_Input_InjectTouchEvent(touchEvent); 390f6603c60Sopenharmony_ci EXPECT_EQ(retResult, INPUT_PARAMETER_ERROR); 391f6603c60Sopenharmony_ci OH_Input_DestroyTouchEvent(&touchEvent); 392f6603c60Sopenharmony_ci EXPECT_EQ(touchEvent, nullptr); 393f6603c60Sopenharmony_ci} 394f6603c60Sopenharmony_ci 395f6603c60Sopenharmony_ci/** 396f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_TouchEventAction_001 397f6603c60Sopenharmony_ci * @tc.desc: Verify the set and get of touchEvent action 398f6603c60Sopenharmony_ci * @tc.type: FUNC 399f6603c60Sopenharmony_ci * @tc.require: 400f6603c60Sopenharmony_ci */ 401f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_TouchEventAction_001, TestSize.Level1) 402f6603c60Sopenharmony_ci{ 403f6603c60Sopenharmony_ci Input_TouchEvent *touchEvent = OH_Input_CreateTouchEvent(); 404f6603c60Sopenharmony_ci ASSERT_NE(touchEvent, nullptr); 405f6603c60Sopenharmony_ci OH_Input_SetTouchEventAction(touchEvent, TOUCH_ACTION_DOWN); 406f6603c60Sopenharmony_ci int32_t action = OH_Input_GetTouchEventAction(touchEvent); 407f6603c60Sopenharmony_ci EXPECT_EQ(action, TOUCH_ACTION_DOWN); 408f6603c60Sopenharmony_ci OH_Input_DestroyTouchEvent(&touchEvent); 409f6603c60Sopenharmony_ci EXPECT_EQ(touchEvent, nullptr); 410f6603c60Sopenharmony_ci} 411f6603c60Sopenharmony_ci 412f6603c60Sopenharmony_ci/** 413f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_TouchEventFingerId_001 414f6603c60Sopenharmony_ci * @tc.desc: Verify the set and get of touchEvent id 415f6603c60Sopenharmony_ci * @tc.type: FUNC 416f6603c60Sopenharmony_ci * @tc.require: 417f6603c60Sopenharmony_ci */ 418f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_TouchEventFingerId_001, TestSize.Level1) 419f6603c60Sopenharmony_ci{ 420f6603c60Sopenharmony_ci Input_TouchEvent *touchEvent = OH_Input_CreateTouchEvent(); 421f6603c60Sopenharmony_ci ASSERT_NE(touchEvent, nullptr); 422f6603c60Sopenharmony_ci OH_Input_SetTouchEventFingerId(touchEvent, 0); 423f6603c60Sopenharmony_ci int32_t id = OH_Input_GetTouchEventFingerId(touchEvent); 424f6603c60Sopenharmony_ci EXPECT_EQ(id, 0); 425f6603c60Sopenharmony_ci OH_Input_DestroyTouchEvent(&touchEvent); 426f6603c60Sopenharmony_ci EXPECT_EQ(touchEvent, nullptr); 427f6603c60Sopenharmony_ci} 428f6603c60Sopenharmony_ci 429f6603c60Sopenharmony_ci/** 430f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_TouchEventDisplayX_001 431f6603c60Sopenharmony_ci * @tc.desc: Verify the set and get of touchEvent displayX 432f6603c60Sopenharmony_ci * @tc.type: FUNC 433f6603c60Sopenharmony_ci * @tc.require: 434f6603c60Sopenharmony_ci */ 435f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_TouchEventDisplayX_001, TestSize.Level1) 436f6603c60Sopenharmony_ci{ 437f6603c60Sopenharmony_ci Input_TouchEvent *touchEvent = OH_Input_CreateTouchEvent(); 438f6603c60Sopenharmony_ci ASSERT_NE(touchEvent, nullptr); 439f6603c60Sopenharmony_ci OH_Input_SetTouchEventDisplayX(touchEvent, 100); 440f6603c60Sopenharmony_ci int32_t displayX = OH_Input_GetTouchEventDisplayX(touchEvent); 441f6603c60Sopenharmony_ci EXPECT_EQ(displayX, 100); 442f6603c60Sopenharmony_ci OH_Input_DestroyTouchEvent(&touchEvent); 443f6603c60Sopenharmony_ci EXPECT_EQ(touchEvent, nullptr); 444f6603c60Sopenharmony_ci} 445f6603c60Sopenharmony_ci 446f6603c60Sopenharmony_ci/** 447f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_TouchEventDisplayY_001 448f6603c60Sopenharmony_ci * @tc.desc: Verify the set and get of touchEvent displayY 449f6603c60Sopenharmony_ci * @tc.type: FUNC 450f6603c60Sopenharmony_ci * @tc.require: 451f6603c60Sopenharmony_ci */ 452f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_TouchEventDisplayY_001, TestSize.Level1) 453f6603c60Sopenharmony_ci{ 454f6603c60Sopenharmony_ci Input_TouchEvent *touchEvent = OH_Input_CreateTouchEvent(); 455f6603c60Sopenharmony_ci ASSERT_NE(touchEvent, nullptr); 456f6603c60Sopenharmony_ci OH_Input_SetTouchEventDisplayY(touchEvent, 100); 457f6603c60Sopenharmony_ci int32_t displayY = OH_Input_GetTouchEventDisplayY(touchEvent); 458f6603c60Sopenharmony_ci EXPECT_EQ(displayY, 100); 459f6603c60Sopenharmony_ci OH_Input_DestroyTouchEvent(&touchEvent); 460f6603c60Sopenharmony_ci EXPECT_EQ(touchEvent, nullptr); 461f6603c60Sopenharmony_ci} 462f6603c60Sopenharmony_ci 463f6603c60Sopenharmony_ci/** 464f6603c60Sopenharmony_ci * @tc.name: InputNativeTest_TouchEventActionTime_001 465f6603c60Sopenharmony_ci * @tc.desc: Verify the set and get of touchEvent actionTime 466f6603c60Sopenharmony_ci * @tc.type: FUNC 467f6603c60Sopenharmony_ci * @tc.require: 468f6603c60Sopenharmony_ci */ 469f6603c60Sopenharmony_ciHWTEST_F(InputNativeTest, InputNativeTest_TouchEventActionTime_001, TestSize.Level1) 470f6603c60Sopenharmony_ci{ 471f6603c60Sopenharmony_ci Input_TouchEvent *touchEvent = OH_Input_CreateTouchEvent(); 472f6603c60Sopenharmony_ci ASSERT_NE(touchEvent, nullptr); 473f6603c60Sopenharmony_ci OH_Input_SetTouchEventActionTime(touchEvent, 200); 474f6603c60Sopenharmony_ci int64_t actionTime = OH_Input_GetTouchEventActionTime(touchEvent); 475f6603c60Sopenharmony_ci EXPECT_EQ(actionTime, 200); 476f6603c60Sopenharmony_ci OH_Input_DestroyTouchEvent(&touchEvent); 477f6603c60Sopenharmony_ci EXPECT_EQ(touchEvent, nullptr); 478f6603c60Sopenharmony_ci} 479f6603c60Sopenharmony_ci} // namespace MMI 480f6603c60Sopenharmony_ci} // namespace OHOS