• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2025 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 <gtest/gtest.h>
18 
19 #include "crown_transform_processor.h"
20 #include "general_crown.h"
21 #include "i_input_windows_manager.h"
22 #include "input_device_manager.h"
23 #include "input_event_handler.h"
24 #include "libinput_mock.h"
25 #include "libinput_wrapper.h"
26 #include "libinput.h"
27 #include "mmi_log.h"
28 #include "timer_manager.h"
29 #include "window_info.h"
30 
31 #undef MMI_LOG_TAG
32 #define MMI_LOG_TAG "CrownTransformProcessorTest"
33 
34 using namespace testing::ext;
35 using namespace testing;
36 
37 namespace OHOS {
38 namespace MMI {
IsExist(int32_t timerId)39 bool TimerManager::IsExist(int32_t timerId)
40 {
41     return true;
42 }
43 
44 class CrownTransformProcessorTest : public testing::Test {
45 public:
46     static void SetUpTestCase();
47     static void TearDownTestCase();
48     void SetUp();
49     void TearDown();
50 };
51 
SetUpTestCase()52 void CrownTransformProcessorTest::SetUpTestCase() {}
53 
TearDownTestCase()54 void CrownTransformProcessorTest::TearDownTestCase() {}
55 
SetUp()56 void CrownTransformProcessorTest::SetUp() {}
57 
TearDown()58 void CrownTransformProcessorTest::TearDown() {}
59 
60 /* *
61  * @tc.name: CrownTransformProcessorTest_GetPointerEvent_001
62  * @tc.desc: Test the funcation GetPointerEvent
63  * @tc.type: Function
64  * @tc.require:
65  */
66 HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_GetPointerEvent_001, TestSize.Level1)
67 {
68     CALL_TEST_DEBUG;
69     std::shared_ptr<CrownTransformProcessor> processor = std::make_shared<CrownTransformProcessor>();
70     auto ret = processor->GetPointerEvent();
71     ASSERT_NE(ret, nullptr);
72 }
73 
74 /* *
75  * @tc.name: CrownTransformProcessorTest_IsCrownEvent_001
76  * @tc.desc: Test the funcation IsCrownEvent
77  * @tc.type: Function
78  * @tc.require:
79  */
80 HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_IsCrownEvent_001, TestSize.Level1)
81 {
82     CALL_TEST_DEBUG;
83     std::shared_ptr<CrownTransformProcessor> processor = std::make_shared<CrownTransformProcessor>();
84     libinput_event *event = nullptr;
85     bool ret = processor->IsCrownEvent(event);
86     EXPECT_FALSE(ret);
87 }
88 
89 /* *
90  * @tc.name: CrownTransformProcessorTest_IsCrownEvent_004
91  * @tc.desc: Test the funcation IsCrownEvent
92  * @tc.type: Function
93  * @tc.require:
94  */
95 HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_IsCrownEvent_004, TestSize.Level1)
96 {
97     CALL_TEST_DEBUG;
98     std::shared_ptr<CrownTransformProcessor> processor = std::make_shared<CrownTransformProcessor>();
99     NiceMock<LibinputInterfaceMock> libinputMock;
100     libinput_device device;
101     libinput_event_pointer touchpadButtonEvent;
102     EXPECT_CALL(libinputMock, GetDevice).WillOnce(Return(&device));
103     EXPECT_CALL(libinputMock, DeviceGetName).WillOnce(Return(const_cast<char *>("Virtual Crown")));
104     EXPECT_CALL(libinputMock, GetEventType).WillOnce(Return(LIBINPUT_EVENT_NONE));
105     libinput_event event;
106     bool ret = processor->IsCrownEvent(&event);
107     EXPECT_FALSE(ret);
108 }
109 
110 /* *
111  * @tc.name: CrownTransformProcessorTest_IsCrownEvent_005
112  * @tc.desc: Test the funcation IsCrownEvent
113  * @tc.type: Function
114  * @tc.require:
115  */
116 HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_IsCrownEvent_005, TestSize.Level1)
117 {
118     CALL_TEST_DEBUG;
119     std::shared_ptr<CrownTransformProcessor> processor = std::make_shared<CrownTransformProcessor>();
120     NiceMock<LibinputInterfaceMock> libinputMock;
121     libinput_device device;
122     libinput_event_pointer touchpadButtonEvent;
123     EXPECT_CALL(libinputMock, GetDevice).WillOnce(Return(&device));
124     EXPECT_CALL(libinputMock, DeviceGetName).WillOnce(Return(const_cast<char *>("Other")));
125     libinput_event event;
126     bool ret = processor->IsCrownEvent(&event);
127     EXPECT_FALSE(ret);
128 }
129 
130 /* *
131  * @tc.name: CrownTransformProcessorTest_NormalizeRotateEvent_001
132  * @tc.desc: Test the funcation NormalizeRotateEvent
133  * @tc.type: Function
134  * @tc.require:
135  */
136 HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_NormalizeRotateEvent_001, TestSize.Level1)
137 {
138     CALL_TEST_DEBUG;
139     std::shared_ptr<CrownTransformProcessor> processor = std::make_shared<CrownTransformProcessor>();
140     libinput_event *event = nullptr;
141     int32_t ret = processor->NormalizeRotateEvent(event);
142     EXPECT_EQ(ret, ERROR_NULL_POINTER);
143 }
144 
145 /* *
146  * @tc.name: CrownTransformProcessorTest_NormalizeRotateEvent_002
147  * @tc.desc: Test the funcation NormalizeRotateEvent
148  * @tc.type: Function
149  * @tc.require:
150  */
151 HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_NormalizeRotateEvent_002, TestSize.Level1)
152 {
153     CALL_TEST_DEBUG;
154     std::shared_ptr<CrownTransformProcessor> processor = std::make_shared<CrownTransformProcessor>();
155     NiceMock<LibinputInterfaceMock> libinputMock;
156     libinput_device *device = nullptr;
157     EXPECT_CALL(libinputMock, GetDevice).WillOnce(Return(device));
158     libinput_event event;
159     int32_t ret = processor->NormalizeRotateEvent(&event);
160     EXPECT_EQ(ret, ERROR_NULL_POINTER);
161 }
162 
163 /* *
164  * @tc.name: CrownTransformProcessorTest_NormalizeRotateEvent_003
165  * @tc.desc: Test the funcation NormalizeRotateEvent
166  * @tc.type: Function
167  * @tc.require:
168  */
169 HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_NormalizeRotateEvent_003, TestSize.Level1)
170 {
171     CALL_TEST_DEBUG;
172     std::shared_ptr<CrownTransformProcessor> processor = std::make_shared<CrownTransformProcessor>();
173     NiceMock<LibinputInterfaceMock> libinputMock;
174     libinput_event_pointer touchpadButtonEvent;
175     libinput_device device;
176     EXPECT_CALL(libinputMock, GetDevice).WillOnce(Return(&device));
177     libinput_event event;
178     int32_t ret = processor->NormalizeRotateEvent(&event);
179     EXPECT_EQ(ret, RET_ERR);
180 }
181 
182 /* *
183  * @tc.name: CrownTransformProcessorTest_HandleCrownRotateBegin_001
184  * @tc.desc: Test the funcation HandleCrownRotateBegin
185  * @tc.type: Function
186  * @tc.require:
187  */
188 HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_HandleCrownRotateBegin_001, TestSize.Level1)
189 {
190     CALL_TEST_DEBUG;
191     std::shared_ptr<CrownTransformProcessor> processor = std::make_shared<CrownTransformProcessor>();
192     libinput_event_pointer *rawPointerEvent = nullptr;
193     int32_t ret = processor->HandleCrownRotateBegin(rawPointerEvent);
194     EXPECT_EQ(ret, ERROR_NULL_POINTER);
195 }
196 
197 /* *
198  * @tc.name: CrownTransformProcessorTest_HandleCrownRotateUpdate_001
199  * @tc.desc: Test the funcation HandleCrownRotateUpdate
200  * @tc.type: Function
201  * @tc.require:
202  */
203 HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_HandleCrownRotateUpdate_001, TestSize.Level1)
204 {
205     CALL_TEST_DEBUG;
206     std::shared_ptr<CrownTransformProcessor> processor = std::make_shared<CrownTransformProcessor>();
207     libinput_event_pointer *rawPointerEvent = nullptr;
208     int32_t ret = processor->HandleCrownRotateUpdate(rawPointerEvent);
209     EXPECT_EQ(ret, ERROR_NULL_POINTER);
210 }
211 
212 /* *
213  * @tc.name: CrownTransformProcessorTest_HandleCrownRotateEnd_001
214  * @tc.desc: Test the funcation HandleCrownRotateEnd
215  * @tc.type: Function
216  * @tc.require:
217  */
218 HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_HandleCrownRotateEnd_001, TestSize.Level1)
219 {
220     CALL_TEST_DEBUG;
221     std::shared_ptr<CrownTransformProcessor> processor = std::make_shared<CrownTransformProcessor>();
222     int32_t ret = processor->HandleCrownRotateEnd();
223     EXPECT_EQ(ret, RET_OK);
224 }
225 
226 /* *
227  * @tc.name: CrownTransformProcessorTest_HandleCrownRotateBeginAndUpdate_001
228  * @tc.desc: Test the funcation HandleCrownRotateBeginAndUpdate
229  * @tc.type: Function
230  * @tc.require:
231  */
232 HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_HandleCrownRotateBeginAndUpdate_001, TestSize.Level1)
233 {
234     CALL_TEST_DEBUG;
235     std::shared_ptr<CrownTransformProcessor> processor = std::make_shared<CrownTransformProcessor>();
236     libinput_event_pointer *rawPointerEvent = nullptr;
237     int32_t action = 0;
238     int32_t ret = processor->HandleCrownRotateBeginAndUpdate(rawPointerEvent, action);
239     EXPECT_EQ(ret, ERROR_NULL_POINTER);
240 }
241 
242 /* *
243  * @tc.name: CrownTransformProcessorTest_HandleCrownRotateBeginAndUpdate_002
244  * @tc.desc: Test the funcation HandleCrownRotateBeginAndUpdate
245  * @tc.type: Function
246  * @tc.require:
247  */
248 HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_HandleCrownRotateBeginAndUpdate_002, TestSize.Level1)
249 {
250     CALL_TEST_DEBUG;
251     std::shared_ptr<CrownTransformProcessor> processor = std::make_shared<CrownTransformProcessor>();
252     libinput_event_pointer *rawPointerEvent = nullptr;
253     int32_t action = PointerEvent::POINTER_ACTION_UNKNOWN;
254     int32_t ret = processor->HandleCrownRotateBeginAndUpdate(rawPointerEvent, action);
255     EXPECT_EQ(ret, ERROR_NULL_POINTER);
256 }
257 
258 /* *
259  * @tc.name: CrownTransformProcessorTest_HandleCrownRotatePostInner_001
260  * @tc.desc: Test the funcation HandleCrownRotatePostInner
261  * @tc.type: Function
262  * @tc.require:
263  */
264 HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_HandleCrownRotatePostInner_001, TestSize.Level1)
265 {
266     CALL_TEST_DEBUG;
267     std::shared_ptr<CrownTransformProcessor> processor = std::make_shared<CrownTransformProcessor>();
268     processor->pointerEvent_ = nullptr;
269     double velocity = 0;
270     double degree = 0;
271     int32_t action = 0;
272     EXPECT_NO_FATAL_FAILURE(processor->HandleCrownRotatePostInner(velocity, degree, action));
273 }
274 
275 /* *
276  * @tc.name: CrownTransformProcessorTest_Dump_001
277  * @tc.desc: Test the funcation Dump
278  * @tc.type: Function
279  * @tc.require:
280  */
281 HWTEST_F(CrownTransformProcessorTest, CrownTransformProcessorTest_Dump_001, TestSize.Level1)
282 {
283     CALL_TEST_DEBUG;
284     std::shared_ptr<CrownTransformProcessor> processor = std::make_shared<CrownTransformProcessor>();
285     processor->pointerEvent_ = nullptr;
286     int32_t fd = -1;
287     std::vector<std::string> args;
288     EXPECT_NO_FATAL_FAILURE(processor->Dump(fd, args));
289 }
290 } // namespace MMI
291 } // namespace OHOS
292