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 <fstream> 17 18 #include <gtest/gtest.h> 19 20 #include "gesture_monitor_handler.h" 21 #include "pointer_event.h" 22 #include "mmi_log.h" 23 24 #undef MMI_LOG_TAG 25 #define MMI_LOG_TAG "GestureMonitorHandlerTest" 26 namespace OHOS { 27 namespace MMI { 28 namespace { 29 using namespace testing::ext; 30 } // namespace 31 32 class GestureMonitorHandlerTest : public testing::Test { 33 public: SetUpTestCase(void)34 static void SetUpTestCase(void) {} TearDownTestCase(void)35 static void TearDownTestCase(void) {} 36 }; 37 38 /** 39 * @tc.name: EventMonitorHandlerTest_CheckMonitorValid 40 * @tc.desc: Test the funcation CheckMonitorValid 41 * @tc.type: FUNC 42 * @tc.require: 43 */ 44 HWTEST_F(GestureMonitorHandlerTest, EventMonitorHandlerTest_CheckMonitorValid, TestSize.Level1) 45 { 46 CALL_TEST_DEBUG; 47 GestureMonitorHandler handler; 48 TouchGestureType type = 2; 49 int32_t fingers = 0; 50 bool ret = handler.CheckMonitorValid(type, fingers); 51 ASSERT_TRUE(ret); 52 fingers = 4; 53 ret = handler.CheckMonitorValid(type, fingers); 54 ASSERT_TRUE(ret); 55 type = 1; 56 ret = handler.CheckMonitorValid(type, fingers); 57 ASSERT_TRUE(ret); 58 fingers = 10; 59 type = 0; 60 ret = handler.CheckMonitorValid(type, fingers); 61 ASSERT_FALSE(ret); 62 type = 5; 63 ret = handler.CheckMonitorValid(type, fingers); 64 ASSERT_FALSE(ret); 65 } 66 67 /** 68 * @tc.name: EventMonitorHandlerTest_IsTouchGestureEvent 69 * @tc.desc: Test the funcation IsTouchGestureEvent 70 * @tc.type: FUNC 71 * @tc.require: 72 */ 73 HWTEST_F(GestureMonitorHandlerTest, EventMonitorHandlerTest_IsTouchGestureEvent, TestSize.Level1) 74 { 75 CALL_TEST_DEBUG; 76 GestureMonitorHandler handler; 77 int32_t pointerAction = PointerEvent::TOUCH_ACTION_SWIPE_DOWN; 78 bool ret = handler.IsTouchGestureEvent(pointerAction); 79 ASSERT_TRUE(ret); 80 pointerAction = PointerEvent::TOUCH_ACTION_SWIPE_UP; 81 ret = handler.IsTouchGestureEvent(pointerAction); 82 ASSERT_TRUE(ret); 83 pointerAction = PointerEvent::TOUCH_ACTION_SWIPE_RIGHT; 84 ret = handler.IsTouchGestureEvent(pointerAction); 85 ASSERT_TRUE(ret); 86 pointerAction = PointerEvent::TOUCH_ACTION_SWIPE_LEFT; 87 ret = handler.IsTouchGestureEvent(pointerAction); 88 ASSERT_TRUE(ret); 89 pointerAction = PointerEvent::TOUCH_ACTION_PINCH_OPENED; 90 ret = handler.IsTouchGestureEvent(pointerAction); 91 ASSERT_TRUE(ret); 92 pointerAction = PointerEvent::TOUCH_ACTION_PINCH_CLOSEED; 93 ret = handler.IsTouchGestureEvent(pointerAction); 94 ASSERT_TRUE(ret); 95 pointerAction = PointerEvent::TOUCH_ACTION_GESTURE_END; 96 ret = handler.IsTouchGestureEvent(pointerAction); 97 ASSERT_TRUE(ret); 98 pointerAction = 99; 99 ret = handler.IsTouchGestureEvent(pointerAction); 100 ASSERT_FALSE(ret); 101 } 102 103 /** 104 * @tc.name: EventMonitorHandlerTest_IsMatchGesture_001 105 * @tc.desc: Test the funcation IsMatchGesture 106 * @tc.type: FUNC 107 * @tc.require: 108 */ 109 HWTEST_F(GestureMonitorHandlerTest, EventMonitorHandlerTest_IsMatchGesture_001, TestSize.Level1) 110 { 111 CALL_TEST_DEBUG; 112 GestureMonitorHandler handler; 113 int32_t action = PointerEvent::TOUCH_ACTION_GESTURE_END; 114 int32_t count = 0; 115 bool ret = handler.IsMatchGesture(action, count); 116 ASSERT_TRUE(ret); 117 action = PointerEvent::TOUCH_ACTION_SWIPE_DOWN; 118 ret = handler.IsMatchGesture(action, count); 119 ASSERT_FALSE(ret); 120 action = PointerEvent::TOUCH_ACTION_SWIPE_UP; 121 ret = handler.IsMatchGesture(action, count); 122 ASSERT_FALSE(ret); 123 action = PointerEvent::TOUCH_ACTION_SWIPE_RIGHT; 124 ret = handler.IsMatchGesture(action, count); 125 ASSERT_FALSE(ret); 126 action = PointerEvent::TOUCH_ACTION_SWIPE_LEFT; 127 ret = handler.IsMatchGesture(action, count); 128 ASSERT_FALSE(ret); 129 action = PointerEvent::TOUCH_ACTION_PINCH_OPENED; 130 ret = handler.IsMatchGesture(action, count); 131 ASSERT_FALSE(ret); 132 action = PointerEvent::TOUCH_ACTION_PINCH_CLOSEED; 133 ret = handler.IsMatchGesture(action, count); 134 ASSERT_FALSE(ret); 135 action = 90; 136 ret = handler.IsMatchGesture(action, count); 137 ASSERT_FALSE(ret); 138 } 139 140 /** 141 * @tc.name: EventMonitorHandlerTest_IsMatchGesture_002 142 * @tc.desc: Test the funcation IsMatchGesture 143 * @tc.type: FUNC 144 * @tc.require: 145 */ 146 HWTEST_F(GestureMonitorHandlerTest, EventMonitorHandlerTest_IsMatchGesture_002, TestSize.Level1) 147 { 148 CALL_TEST_DEBUG; 149 GestureMonitorHandler handler; 150 int32_t action = PointerEvent::TOUCH_ACTION_SWIPE_DOWN; 151 int32_t count = 1; 152 handler.touchGestureInfo_.insert(std::make_pair(100, std::set<int32_t>{1, 2, 3})); 153 bool ret = handler.IsMatchGesture(action, count); 154 ASSERT_FALSE(ret); 155 action = PointerEvent::TOUCH_ACTION_PINCH_OPENED; 156 ret = handler.IsMatchGesture(action, count); 157 ASSERT_FALSE(ret); 158 } 159 160 /** 161 * @tc.name: EventMonitorHandlerTest_AddGestureMonitor 162 * @tc.desc: Test the funcation AddGestureMonitor 163 * @tc.type: FUNC 164 * @tc.require: 165 */ 166 HWTEST_F(GestureMonitorHandlerTest, EventMonitorHandlerTest_AddGestureMonitor, TestSize.Level1) 167 { 168 CALL_TEST_DEBUG; 169 GestureMonitorHandler handler; 170 TouchGestureType type = TOUCH_GESTURE_TYPE_NONE; 171 int32_t fingers = THREE_FINGER_COUNT; 172 EXPECT_NO_FATAL_FAILURE(handler.AddGestureMonitor(type, fingers)); 173 type = TOUCH_GESTURE_TYPE_PINCH; 174 handler.touchGestureInfo_.insert(std::make_pair(2, std::set<int32_t>{1, 2})); 175 EXPECT_NO_FATAL_FAILURE(handler.AddGestureMonitor(type, fingers)); 176 type = TOUCH_GESTURE_TYPE_SWIPE; 177 EXPECT_NO_FATAL_FAILURE(handler.AddGestureMonitor(type, fingers)); 178 } 179 } // namespace MMI 180 } // namespace MMI