123b3eb3cSopenharmony_ci/* 223b3eb3cSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License. 523b3eb3cSopenharmony_ci * You may obtain a copy of the License at 623b3eb3cSopenharmony_ci * 723b3eb3cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 823b3eb3cSopenharmony_ci * 923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and 1323b3eb3cSopenharmony_ci * limitations under the License. 1423b3eb3cSopenharmony_ci */ 1523b3eb3cSopenharmony_ci 1623b3eb3cSopenharmony_ci#include "gtest/gtest.h" 1723b3eb3cSopenharmony_ci#include "native_interface.h" 1823b3eb3cSopenharmony_ci#include "native_gesture.h" 1923b3eb3cSopenharmony_ci#include "event_converter.h" 2023b3eb3cSopenharmony_ci#include "native_node.h" 2123b3eb3cSopenharmony_ci#include "native_type.h" 2223b3eb3cSopenharmony_ci 2323b3eb3cSopenharmony_ciusing namespace testing; 2423b3eb3cSopenharmony_ciusing namespace testing::ext; 2523b3eb3cSopenharmony_ci 2623b3eb3cSopenharmony_ciclass NativeGestureTest : public testing::Test { 2723b3eb3cSopenharmony_cipublic: 2823b3eb3cSopenharmony_ci static void SetUpTestCase() {}; 2923b3eb3cSopenharmony_ci static void TearDownTestCase() {}; 3023b3eb3cSopenharmony_ci}; 3123b3eb3cSopenharmony_ci 3223b3eb3cSopenharmony_ci/** 3323b3eb3cSopenharmony_ci * @tc.name: NativeGestureTest001 3423b3eb3cSopenharmony_ci * @tc.desc: Test createTapGesture function. 3523b3eb3cSopenharmony_ci * @tc.type: FUNC 3623b3eb3cSopenharmony_ci */ 3723b3eb3cSopenharmony_ciHWTEST_F(NativeGestureTest, NativeGestureTest001, TestSize.Level1) 3823b3eb3cSopenharmony_ci{ 3923b3eb3cSopenharmony_ci auto gestureAPI = reinterpret_cast<ArkUI_NativeGestureAPI_1*>( 4023b3eb3cSopenharmony_ci OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_GESTURE, "ArkUI_NativeGestureAPI_1")); 4123b3eb3cSopenharmony_ci auto nodeAPI = reinterpret_cast<ArkUI_NativeNodeAPI_1*>( 4223b3eb3cSopenharmony_ci OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_NODE, "ArkUI_NativeNodeAPI_1")); 4323b3eb3cSopenharmony_ci auto gestureNode = nodeAPI->createNode(ARKUI_NODE_STACK); 4423b3eb3cSopenharmony_ci auto group = gestureAPI->createGroupGesture(EXCLUSIVE_GROUP); 4523b3eb3cSopenharmony_ci auto tapGesture = gestureAPI->createTapGesture(1, 1); 4623b3eb3cSopenharmony_ci auto tapGesture1 = gestureAPI->createTapGesture(0, 11); 4723b3eb3cSopenharmony_ci auto longPressGesture = gestureAPI->createLongPressGesture(1, true, 500); 4823b3eb3cSopenharmony_ci auto panGesture = gestureAPI->createPanGesture(1, GESTURE_DIRECTION_DOWN, 5); 4923b3eb3cSopenharmony_ci auto swipeGesture = gestureAPI->createSwipeGesture(1, 1, 5); 5023b3eb3cSopenharmony_ci auto pinchGesture = gestureAPI->createPinchGesture(2, 20); 5123b3eb3cSopenharmony_ci auto rotateGesture = gestureAPI->createRotationGesture(2, 90); 5223b3eb3cSopenharmony_ci gestureAPI->addChildGesture(group, tapGesture); 5323b3eb3cSopenharmony_ci gestureAPI->addChildGesture(group, tapGesture1); 5423b3eb3cSopenharmony_ci gestureAPI->addChildGesture(group, longPressGesture); 5523b3eb3cSopenharmony_ci auto onActionCallBack = [](ArkUI_GestureEvent *event, void *extraParam) {}; 5623b3eb3cSopenharmony_ci gestureAPI->setGestureEventTarget( 5723b3eb3cSopenharmony_ci longPressGesture, GESTURE_EVENT_ACTION_ACCEPT, 5823b3eb3cSopenharmony_ci gestureNode, onActionCallBack); 5923b3eb3cSopenharmony_ci auto onInterruptCallback = [](ArkUI_GestureInterruptInfo* info) -> ArkUI_GestureInterruptResult { 6023b3eb3cSopenharmony_ci return GESTURE_INTERRUPT_RESULT_REJECT; 6123b3eb3cSopenharmony_ci }; 6223b3eb3cSopenharmony_ci gestureAPI->setGestureInterrupterToNode(gestureNode, onInterruptCallback); 6323b3eb3cSopenharmony_ci auto ret = gestureAPI->addGestureToNode(gestureNode, group, PRIORITY, NORMAL_GESTURE_MASK); 6423b3eb3cSopenharmony_ci EXPECT_EQ(ret, 0); 6523b3eb3cSopenharmony_ci gestureAPI->removeGestureFromNode(gestureNode, group); 6623b3eb3cSopenharmony_ci gestureAPI->removeChildGesture(group, tapGesture); 6723b3eb3cSopenharmony_ci gestureAPI->removeChildGesture(group, tapGesture1); 6823b3eb3cSopenharmony_ci gestureAPI->removeChildGesture(group, longPressGesture); 6923b3eb3cSopenharmony_ci gestureAPI->dispose(tapGesture); 7023b3eb3cSopenharmony_ci gestureAPI->dispose(longPressGesture); 7123b3eb3cSopenharmony_ci gestureAPI->dispose(panGesture); 7223b3eb3cSopenharmony_ci gestureAPI->dispose(swipeGesture); 7323b3eb3cSopenharmony_ci gestureAPI->dispose(pinchGesture); 7423b3eb3cSopenharmony_ci gestureAPI->dispose(rotateGesture); 7523b3eb3cSopenharmony_ci} 7623b3eb3cSopenharmony_ci 7723b3eb3cSopenharmony_ci/** 7823b3eb3cSopenharmony_ci * @tc.name: NativeGestureTest002 7923b3eb3cSopenharmony_ci * @tc.desc: Test createTapGesture function. 8023b3eb3cSopenharmony_ci * @tc.type: FUNC 8123b3eb3cSopenharmony_ci */ 8223b3eb3cSopenharmony_ciHWTEST_F(NativeGestureTest, NativeGestureTest002, TestSize.Level1) 8323b3eb3cSopenharmony_ci{ 8423b3eb3cSopenharmony_ci auto gestureAPI = reinterpret_cast<ArkUI_NativeGestureAPI_1*>( 8523b3eb3cSopenharmony_ci OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_GESTURE, "ArkUI_NativeGestureAPI_1")); 8623b3eb3cSopenharmony_ci auto pinchGesture = gestureAPI->createPinchGesture(2, 0.0f); 8723b3eb3cSopenharmony_ci EXPECT_NE(pinchGesture, nullptr); 8823b3eb3cSopenharmony_ci auto swipeGesture = gestureAPI->createSwipeGesture(1, 1, 0.0f); 8923b3eb3cSopenharmony_ci EXPECT_NE(swipeGesture, nullptr); 9023b3eb3cSopenharmony_ci auto panGesture = gestureAPI->createPanGesture(0, GESTURE_DIRECTION_DOWN, 5); 9123b3eb3cSopenharmony_ci EXPECT_NE(panGesture, nullptr); 9223b3eb3cSopenharmony_ci gestureAPI->dispose(pinchGesture); 9323b3eb3cSopenharmony_ci gestureAPI->dispose(swipeGesture); 9423b3eb3cSopenharmony_ci gestureAPI->dispose(panGesture); 9523b3eb3cSopenharmony_ci EXPECT_NE(gestureAPI, nullptr); 9623b3eb3cSopenharmony_ci} 9723b3eb3cSopenharmony_ci 98