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 <gmock/gmock.h>
17 #include <gtest/gtest.h>
18 
19 #include "define_multimodal.h"
20 #include "libinput_mock.h"
21 #include "preferences_manager_mock.h"
22 #include "touchpad_transform_processor.h"
23 
24 #undef MMI_LOG_TAG
25 #define MMI_LOG_TAG "TouchPadGestureTest"
26 
27 namespace OHOS {
28 namespace MMI {
29 using namespace testing;
30 using namespace testing::ext;
31 
32 class TouchPadGestureTest : public testing::Test {
33 public:
34     static void SetUpTestCase(void);
35     static void TearDownTestCase(void);
36     void SetUp();
37     void TearDown();
38 };
39 
SetUpTestCase(void)40 void TouchPadGestureTest::SetUpTestCase(void)
41 {}
42 
TearDownTestCase(void)43 void TouchPadGestureTest::TearDownTestCase(void)
44 {}
45 
SetUp()46 void TouchPadGestureTest::SetUp()
47 {}
48 
TearDown()49 void TouchPadGestureTest::TearDown()
50 {}
51 
52 /**
53  * @tc.name: TouchPadGestureTest_OnEventTouchPadSwipeBegin_001
54  * @tc.desc: Test the funcation OnEventTouchPadSwipeBegin
55  * @tc.type: FUNC
56  * @tc.require:
57  */
58 HWTEST_F(TouchPadGestureTest, OnEventTouchPadSwipeBegin_001, TestSize.Level1)
59 {
60     libinput_event_gesture event {};
61 
62     NiceMock<LibinputInterfaceMock> libinputMock;
63     EXPECT_CALL(libinputMock, GetEventType).WillOnce(Return(LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN));
64     EXPECT_CALL(libinputMock, GetGestureEvent).WillOnce(Return(&event));
65     EXPECT_CALL(libinputMock, GestureEventGetTime).WillOnce(Return(1));
66     EXPECT_CALL(libinputMock, GestureEventGetFingerCount).WillOnce(Return(1));
67     EXPECT_CALL(libinputMock, GestureEventGetDevCoordsX).WillOnce(Return(150));
68     EXPECT_CALL(libinputMock, GestureEventGetDevCoordsY).WillOnce(Return(250));
69 
70     EXPECT_CALL(*PREFERENCES_MGR_MOCK, GetBoolValue).WillOnce(Return(true));
71 
72     int32_t deviceId = 6;
73     TouchPadTransformProcessor processor(deviceId);
74     auto pointerEvent = processor.OnEvent(&event.base);
75     ASSERT_TRUE(pointerEvent != nullptr);
76     EXPECT_EQ(pointerEvent->GetSourceType(), PointerEvent::SOURCE_TYPE_TOUCHPAD);
77     EXPECT_EQ(pointerEvent->GetPointerAction(), PointerEvent::POINTER_ACTION_SWIPE_BEGIN);
78 }
79 } // namespace MMI
80 } // namespace OHOS