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 "gtest/gtest.h" 17 #include "native_interface.h" 18 #include "native_gesture.h" 19 #include "event_converter.h" 20 #include "native_node.h" 21 #include "native_type.h" 22 23 using namespace testing; 24 using namespace testing::ext; 25 26 class NativeGestureTest : public testing::Test { 27 public: SetUpTestCase()28 static void SetUpTestCase() {}; TearDownTestCase()29 static void TearDownTestCase() {}; 30 }; 31 32 /** 33 * @tc.name: NativeGestureTest001 34 * @tc.desc: Test createTapGesture function. 35 * @tc.type: FUNC 36 */ 37 HWTEST_F(NativeGestureTest, NativeGestureTest001, TestSize.Level1) 38 { 39 auto gestureAPI = reinterpret_cast<ArkUI_NativeGestureAPI_1*>( 40 OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_GESTURE, "ArkUI_NativeGestureAPI_1")); 41 auto nodeAPI = reinterpret_cast<ArkUI_NativeNodeAPI_1*>( 42 OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_NODE, "ArkUI_NativeNodeAPI_1")); 43 auto gestureNode = nodeAPI->createNode(ARKUI_NODE_STACK); 44 auto group = gestureAPI->createGroupGesture(EXCLUSIVE_GROUP); 45 auto tapGesture = gestureAPI->createTapGesture(1, 1); 46 auto tapGesture1 = gestureAPI->createTapGesture(0, 11); 47 auto longPressGesture = gestureAPI->createLongPressGesture(1, true, 500); 48 auto panGesture = gestureAPI->createPanGesture(1, GESTURE_DIRECTION_DOWN, 5); 49 auto swipeGesture = gestureAPI->createSwipeGesture(1, 1, 5); 50 auto pinchGesture = gestureAPI->createPinchGesture(2, 20); 51 auto rotateGesture = gestureAPI->createRotationGesture(2, 90); 52 gestureAPI->addChildGesture(group, tapGesture); 53 gestureAPI->addChildGesture(group, tapGesture1); 54 gestureAPI->addChildGesture(group, longPressGesture); __anon195598a50102(ArkUI_GestureEvent *event, void *extraParam) 55 auto onActionCallBack = [](ArkUI_GestureEvent *event, void *extraParam) {}; 56 gestureAPI->setGestureEventTarget( 57 longPressGesture, GESTURE_EVENT_ACTION_ACCEPT, 58 gestureNode, onActionCallBack); __anon195598a50202(ArkUI_GestureInterruptInfo* info) 59 auto onInterruptCallback = [](ArkUI_GestureInterruptInfo* info) -> ArkUI_GestureInterruptResult { 60 return GESTURE_INTERRUPT_RESULT_REJECT; 61 }; 62 gestureAPI->setGestureInterrupterToNode(gestureNode, onInterruptCallback); 63 auto ret = gestureAPI->addGestureToNode(gestureNode, group, PRIORITY, NORMAL_GESTURE_MASK); 64 EXPECT_EQ(ret, 0); 65 gestureAPI->removeGestureFromNode(gestureNode, group); 66 gestureAPI->removeChildGesture(group, tapGesture); 67 gestureAPI->removeChildGesture(group, tapGesture1); 68 gestureAPI->removeChildGesture(group, longPressGesture); 69 gestureAPI->dispose(tapGesture); 70 gestureAPI->dispose(longPressGesture); 71 gestureAPI->dispose(panGesture); 72 gestureAPI->dispose(swipeGesture); 73 gestureAPI->dispose(pinchGesture); 74 gestureAPI->dispose(rotateGesture); 75 } 76 77 /** 78 * @tc.name: NativeGestureTest002 79 * @tc.desc: Test createTapGesture function. 80 * @tc.type: FUNC 81 */ 82 HWTEST_F(NativeGestureTest, NativeGestureTest002, TestSize.Level1) 83 { 84 auto gestureAPI = reinterpret_cast<ArkUI_NativeGestureAPI_1*>( 85 OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_GESTURE, "ArkUI_NativeGestureAPI_1")); 86 auto pinchGesture = gestureAPI->createPinchGesture(2, 0.0f); 87 auto swipeGesture = gestureAPI->createSwipeGesture(1, 1, 0.0f); 88 auto panGesture = gestureAPI->createPanGesture(0, GESTURE_DIRECTION_DOWN, 5); 89 gestureAPI->dispose(pinchGesture); 90 gestureAPI->dispose(swipeGesture); 91 gestureAPI->dispose(panGesture); 92 } 93 94