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 <cstdio>
17 #include <gmock/gmock.h>
18 #include <gtest/gtest.h>
19 
20 #include "define_multimodal.h"
21 #include "gesture_transform_processor.h"
22 #include "libinput_mock.h"
23 #include "input_device_manager.h"
24 
25 #undef MMI_LOG_TAG
26 #define MMI_LOG_TAG "GestureTransformProcessorMockTest"
27 
28 namespace OHOS {
29 namespace MMI {
30 using namespace testing;
31 using namespace testing::ext;
32 
33 class GestureTransformProcessorMockTest : public testing::Test {
34 public:
35     static void SetUpTestCase(void);
36     static void TearDownTestCase(void);
37     void SetUp();
38     void TearDown();
39 };
40 
SetUpTestCase(void)41 void GestureTransformProcessorMockTest::SetUpTestCase(void)
42 {}
43 
TearDownTestCase(void)44 void GestureTransformProcessorMockTest::TearDownTestCase(void)
45 {}
46 
SetUp()47 void GestureTransformProcessorMockTest::SetUp()
48 {}
49 
TearDown()50 void GestureTransformProcessorMockTest::TearDown()
51 {}
52 
53 /**
54  * @tc.name: GestureTransformProcessorMockTest_OnEvent_02
55  * @tc.desc: OnEvent
56  * @tc.type: FUNC
57  * @tc.require:
58  */
59 HWTEST_F(GestureTransformProcessorMockTest, GestureTransformProcessorMockTest_OnEvent_02, TestSize.Level1)
60 {
61     CALL_TEST_DEBUG;
62     int32_t deviceId = 2;
63     GestureTransformProcessor processor(deviceId);
64     processor.pointerEvent_ = PointerEvent::Create();
65     ASSERT_TRUE(processor.pointerEvent_ != nullptr);
66     libinput_event event {};
67     libinput_event_gesture gestureEvent {};
68 
69     NiceMock<LibinputInterfaceMock> libinputMock;
70     EXPECT_CALL(libinputMock, GetGestureEvent).WillRepeatedly(testing::Return(&gestureEvent));
71     EXPECT_CALL(libinputMock, GetEventType).WillRepeatedly(testing::Return(LIBINPUT_EVENT_GESTURE_PINCH_UPDATE));
72 
73     auto pointerEvent = processor.OnEvent(&event);
74     ASSERT_TRUE(pointerEvent != nullptr);
75 }
76 
77 /**
78  * @tc.name: GestureTransformProcessorMockTest_OnEvent_03
79  * @tc.desc: OnEvent
80  * @tc.type: FUNC
81  * @tc.require:
82  */
83 HWTEST_F(GestureTransformProcessorMockTest, GestureTransformProcessorMockTest_OnEvent_03, TestSize.Level1)
84 {
85     CALL_TEST_DEBUG;
86     int32_t deviceId = 3;
87     GestureTransformProcessor processor(deviceId);
88     processor.pointerEvent_ = PointerEvent::Create();
89     ASSERT_TRUE(processor.pointerEvent_ != nullptr);
90     libinput_event event {};
91     libinput_event_gesture gestureEvent {};
92 
93     NiceMock<LibinputInterfaceMock> libinputMock;
94     EXPECT_CALL(libinputMock, GetGestureEvent).WillRepeatedly(testing::Return(&gestureEvent));
95     EXPECT_CALL(libinputMock, GetEventType).WillRepeatedly(testing::Return(LIBINPUT_EVENT_GESTURE_PINCH_END));
96 
97     auto pointerEvent = processor.OnEvent(&event);
98     ASSERT_TRUE(pointerEvent != nullptr);
99 }
100 
101 /**
102  * @tc.name: GestureTransformProcessorMockTest_OnEvent_04
103  * @tc.desc: OnEvent
104  * @tc.type: FUNC
105  * @tc.require:
106  */
107 HWTEST_F(GestureTransformProcessorMockTest, GestureTransformProcessorMockTest_OnEvent_04, TestSize.Level1)
108 {
109     CALL_TEST_DEBUG;
110     int32_t deviceId = 4;
111     GestureTransformProcessor processor(deviceId);
112     processor.pointerEvent_ = PointerEvent::Create();
113     ASSERT_TRUE(processor.pointerEvent_ != nullptr);
114     libinput_event event {};
115     libinput_event_gesture gestureEvent {};
116 
117     NiceMock<LibinputInterfaceMock> libinputMock;
118     EXPECT_CALL(libinputMock, GetGestureEvent).WillRepeatedly(testing::Return(&gestureEvent));
119     EXPECT_CALL(libinputMock, GetEventType).WillRepeatedly(testing::Return(LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN));
120 
121     auto pointerEvent = processor.OnEvent(&event);
122     ASSERT_TRUE(pointerEvent == nullptr);
123 }
124 
125 /**
126  * @tc.name: GestureTransformProcessorMockTest_OnEvent_05
127  * @tc.desc: OnEvent
128  * @tc.type: FUNC
129  * @tc.require:
130  */
131 HWTEST_F(GestureTransformProcessorMockTest, GestureTransformProcessorMockTest_OnEvent_05, TestSize.Level1)
132 {
133     CALL_TEST_DEBUG;
134     int32_t deviceId = 5;
135     GestureTransformProcessor processor(deviceId);
136     processor.pointerEvent_ = PointerEvent::Create();
137     ASSERT_TRUE(processor.pointerEvent_ != nullptr);
138     libinput_event event {};
139     libinput_event_gesture gestureEvent {};
140 
141     NiceMock<LibinputInterfaceMock> libinputMock;
142     EXPECT_CALL(libinputMock, GetGestureEvent).WillRepeatedly(testing::Return(&gestureEvent));
143     EXPECT_CALL(libinputMock, GetEventType).WillRepeatedly(testing::Return(LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE));
144 
145     auto pointerEvent = processor.OnEvent(&event);
146     ASSERT_TRUE(pointerEvent == nullptr);
147 }
148 
149 /**
150  * @tc.name: GestureTransformProcessorMockTest_OnEvent_06
151  * @tc.desc: OnEvent
152  * @tc.type: FUNC
153  * @tc.require:
154  */
155 HWTEST_F(GestureTransformProcessorMockTest, GestureTransformProcessorMockTest_OnEvent_06, TestSize.Level1)
156 {
157     CALL_TEST_DEBUG;
158     int32_t deviceId = 6;
159     GestureTransformProcessor processor(deviceId);
160     processor.pointerEvent_ = PointerEvent::Create();
161     ASSERT_TRUE(processor.pointerEvent_ != nullptr);
162     libinput_event event {};
163     libinput_event_gesture gestureEvent {};
164 
165     NiceMock<LibinputInterfaceMock> libinputMock;
166     EXPECT_CALL(libinputMock, GetGestureEvent).WillRepeatedly(testing::Return(&gestureEvent));
167     EXPECT_CALL(libinputMock, GetEventType).WillRepeatedly(testing::Return(LIBINPUT_EVENT_GESTURE_SWIPE_END));
168 
169     auto pointerEvent = processor.OnEvent(&event);
170     ASSERT_TRUE(pointerEvent == nullptr);
171 }
172 } // namespace MMI
173 } // namespace OHOS