• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <linux/input.h>
19 
20 #include "mmi_log.h"
21 #include "mock.h"
22 #include "mouse_transform_processor.h"
23 #include "parameters.h"
24 #include "input_windows_manager.h"
25 #include "i_input_windows_manager.h"
26 #include "libinput_mock.h"
27 
28 #undef MMI_LOG_TAG
29 #define MMI_LOG_TAG "MouseTransformProcessorExTest"
30 
31 namespace OHOS {
32 namespace MMI {
33 namespace {
34 using namespace testing::ext;
35 using namespace testing;
36 }
37 class MouseTransformProcessorExTest : public testing::Test {
38 public:
39     static void SetUpTestCase(void);
40     static void TearDownTestCase(void);
41     void SetUp();
42     void TearDown();
43 
44     static inline std::shared_ptr<MessageParcelMock> messageParcelMock_ = nullptr;
45 };
46 
SetUpTestCase(void)47 void MouseTransformProcessorExTest::SetUpTestCase(void)
48 {
49     messageParcelMock_ = std::make_shared<MessageParcelMock>();
50     MessageParcelMock::messageParcel = messageParcelMock_;
51 }
52 
TearDownTestCase(void)53 void MouseTransformProcessorExTest::TearDownTestCase(void)
54 {
55     MessageParcelMock::messageParcel = nullptr;
56     messageParcelMock_ = nullptr;
57 }
58 
SetUp()59 void MouseTransformProcessorExTest::SetUp() {}
60 
TearDown()61 void MouseTransformProcessorExTest::TearDown() {}
62 
63 /**
64  * @tc.name: MouseTransformProcessorExTest_GetDisplayDirection_001
65  * @tc.desc: Test the funcation GetDisplayDirection
66  * @tc.type: FUNC
67  * @tc.require:
68  */
69 HWTEST_F(MouseTransformProcessorExTest, MouseTransformProcessorTest_GetDisplayDirection_001, TestSize.Level1)
70 {
71     int32_t deviceId = 1;
72     MouseTransformProcessor processor(deviceId);
73     OLD::DisplayInfo displayInfo;
74     displayInfo.direction = DIRECTION0;
75     displayInfo.displayDirection = DIRECTION90;
76     EXPECT_CALL(*messageParcelMock_, IsSceneBoardEnabled()).WillRepeatedly(Return(true));
77     auto inputWindowsManager = std::static_pointer_cast<InputWindowsManager>(WIN_MGR);
78     Direction ret = processor.GetDisplayDirection(&displayInfo);
79     int32_t rotatePolicy = system::GetIntParameter("const.window.device.rotate_policy", 0);
80     if (inputWindowsManager->GetHardCursorEnabled()) {
81         if (rotatePolicy == 0) {
82             ASSERT_EQ(ret, DIRECTION270);
83         } else {
84             ASSERT_EQ(ret, DIRECTION0);
85         }
86     } else {
87         ASSERT_EQ(ret, DIRECTION270);
88     }
89 }
90 
91 #ifndef OHOS_BUILD_ENABLE_WATCH
92 /**
93  * @tc.name: MouseTransformProcessorTest_HandleTouchpadLeftButton_001
94  * @tc.desc: Test the funcation HandleTouchpadRightButton
95  * @tc.type: FUNC
96  * @tc.require:
97  */
98 HWTEST_F(MouseTransformProcessorExTest, MouseTransformProcessorTest_HandleTouchpadLeftButton_001, TestSize.Level1)
99 {
100     CALL_TEST_DEBUG;
101     NiceMock<LibinputInterfaceMock> libinputMock;
102     EXPECT_CALL(libinputMock, PointerEventGetFingerCount).WillOnce(Return(1));
103     EXPECT_CALL(libinputMock, PointerGetButtonArea).WillOnce(Return(280));
104     int32_t deviceId = 0;
105     MouseTransformProcessor processor(deviceId);
106     struct libinput_event_pointer* data = nullptr;
107     int32_t eventType = 1;
108     uint32_t button = 272;
109     ASSERT_NO_FATAL_FAILURE(processor.HandleTouchpadLeftButton(data, eventType, button));
110 }
111 
112 /**
113  * @tc.name: MouseTransformProcessorTest_HandleTouchpadLeftButton_002
114  * @tc.desc: Test the funcation HandleTouchpadRightButton
115  * @tc.type: FUNC
116  * @tc.require:
117  */
118 HWTEST_F(MouseTransformProcessorExTest, MouseTransformProcessorTest_HandleTouchpadLeftButton_002, TestSize.Level1)
119 {
120     CALL_TEST_DEBUG;
121     NiceMock<LibinputInterfaceMock> libinputMock;
122     EXPECT_CALL(libinputMock, PointerEventGetFingerCount).WillOnce(Return(1));
123     EXPECT_CALL(libinputMock, PointerGetButtonArea).WillOnce(Return(273));
124     int32_t deviceId = 0;
125     MouseTransformProcessor processor(deviceId);
126     struct libinput_event_pointer* data = nullptr;
127     int32_t eventType = 1;
128     uint32_t button = 272;
129     ASSERT_NO_FATAL_FAILURE(processor.HandleTouchpadLeftButton(data, eventType, button));
130 }
131 #endif // OHOS_BUILD_ENABLE_WATCH
132 
133 /**
134  * @tc.name: MouseTransformProcessorTest_GetPointerLocation_001
135  * @tc.desc: Test the funcation GetPointerLocation
136  * @tc.type: FUNC
137  * @tc.require:
138  */
139 HWTEST_F(MouseTransformProcessorExTest, MouseTransformProcessorTest_GetPointerLocation_001, TestSize.Level1)
140 {
141     int32_t deviceId = 1;
142     MouseTransformProcessor processor(deviceId);
143     int32_t displayId = 0;
144     double displayX = 0.0;
145     double displayY = 0.0;
146     int32_t ret = processor.GetPointerLocation(displayId, displayX, displayY);
147     EXPECT_EQ(ret, RET_OK);
148     EXPECT_EQ(displayId, -1);
149     EXPECT_EQ(displayX, 0);
150     EXPECT_EQ(displayY, 0);
151 }
152 
153 /**
154  * @tc.name: MouseTransformProcessorExTest_Normalize_001
155  * @tc.desc: Test the branch that handles mouse movement events
156  * @tc.type: FUNC
157  * @tc.require:
158  */
159 HWTEST_F(MouseTransformProcessorExTest, MouseTransformProcessorTest_Normalize_001, TestSize.Level1)
160 {
161     CALL_TEST_DEBUG;
162     int32_t deviceId = 1;
163     MouseTransformProcessor processor(deviceId);
164     libinput_event event {};
165     libinput_event_pointer pointer {};
166     NiceMock<LibinputInterfaceMock> libinputMock;
167     EXPECT_CALL(libinputMock, GetEventType).WillOnce(Return(LIBINPUT_EVENT_POINTER_MOTION));
168     EXPECT_CALL(libinputMock, LibinputGetPointerEvent).WillOnce(Return(&pointer));
169     processor.pointerEvent_ = PointerEvent::Create();
170     EXPECT_EQ(processor.Normalize(&event), RET_ERR);
171 }
172 
173 /**
174  * @tc.name: MouseTransformProcessorExTest_Normalize_002
175  * @tc.desc: Test the branch that handles mouse movement events
176  * @tc.type: FUNC
177  * @tc.require:
178  */
179 HWTEST_F(MouseTransformProcessorExTest, MouseTransformProcessorTest_Normalize_002, TestSize.Level1)
180 {
181     CALL_TEST_DEBUG;
182     int32_t deviceId = 1;
183     MouseTransformProcessor processor(deviceId);
184     libinput_event event {};
185     libinput_event_pointer pointer {};
186     NiceMock<LibinputInterfaceMock> libinputMock;
187     EXPECT_CALL(libinputMock, GetEventType).WillOnce(Return(LIBINPUT_EVENT_POINTER_MOTION));
188     EXPECT_CALL(libinputMock, LibinputGetPointerEvent).WillOnce(Return(&pointer));
189     processor.pointerEvent_ = PointerEvent::Create();
190     processor.pointerEvent_->AddFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY);
191     EXPECT_EQ(processor.Normalize(&event), RET_ERR);
192 }
193 }
194 }
195