• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 <fstream>
18 #include <gtest/gtest.h>
19 
20 #include "input_windows_manager.h"
21 #include "mmi_log.h"
22 #include "uds_server.h"
23 
24 namespace OHOS {
25 namespace MMI {
26 namespace {
27 using namespace testing::ext;
28 } // namespace
29 
30 class InputWindowsManagerTest : public testing::Test {
31 public:
SetUpTestCase(void)32     static void SetUpTestCase(void) {};
TearDownTestCase(void)33     static void TearDownTestCase(void) {};
SetUp(void)34     void SetUp(void)
35     {
36         // 创建displayGroupInfo_
37         DisplayGroupInfo displayGroupInfo;
38         displayGroupInfo.width = 20;
39         displayGroupInfo.height = 20;
40         displayGroupInfo.focusWindowId = 1;
41         uint32_t num = 1;
42         for (uint32_t i = 0; i < num; i++) {
43             WindowInfo info;
44             info.id = 1;
45             info.pid = 1;
46             info.uid = 1;
47             info.area = {1, 1, 1, 1};
48             info.defaultHotAreas = { info.area };
49             info.pointerHotAreas = { info.area };
50             info.agentWindowId = 1;
51             info.flags = 1;
52             displayGroupInfo.windowsInfo.push_back(info);
53         }
54         for (uint32_t i = 0; i < num; i++) {
55             DisplayInfo info;
56             info.id = 1;
57             info.x =1;
58             info.y = 1;
59             info.width = 2;
60             info.height = 2;
61             info.dpi = 240;
62             info.name = "pp";
63             info.uniq = "pp";
64             info.direction = DIRECTION0;
65             displayGroupInfo.displaysInfo.push_back(info);
66         }
67         WinMgr->UpdateDisplayInfo(displayGroupInfo);
68     } // void SetUp(void)
69 };
70 
71 
72 /**
73  * @tc.name: InputWindowsManagerTest_GetClientFd_001
74  * @tc.desc: Test GetClientFd
75  * @tc.type: FUNC
76  * @tc.require:
77  */
78 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_GetClientFd_001, TestSize.Level1)
79 {
80     auto pointerEvent = PointerEvent::Create();
81     UDSServer udsServer;
82     WinMgr->Init(udsServer);
83     WinMgr->GetDisplayGroupInfo();
84     int32_t idNames = -1;
85     ASSERT_EQ(WinMgr->GetClientFd(pointerEvent), idNames);
86 }
87 
88 /**
89  * @tc.name: InputWindowsManagerTest_GetPidAndUpdateTarget_002
90  * @tc.desc: Test GetPidAndUpdateTarget
91  * @tc.type: FUNC
92  * @tc.require:
93  */
94 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_GetPidAndUpdateTarget_002, TestSize.Level1)
95 {
96     UDSServer udsServer;
97     WinMgr->Init(udsServer);
98     auto inputEvent = InputEvent::Create();
99     ASSERT_NE(inputEvent, nullptr);
100     inputEvent->SetDeviceId(1);
101     inputEvent->SetTargetWindowId(1);
102     inputEvent->SetAgentWindowId(1);
103     ASSERT_EQ(WinMgr->GetPidAndUpdateTarget(inputEvent), 1);
104 }
105 
106 /**
107  * @tc.name: InputWindowsManagerTest_UpdateTarget_003
108  * @tc.desc: Test UpdateTarget
109  * @tc.type: FUNC
110  * @tc.require:
111  */
112 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateTarget_003, TestSize.Level1)
113 {
114     UDSServer udsServer;
115     WinMgr->Init(udsServer);
116     auto inputEvent = InputEvent::Create();
117     ASSERT_NE(inputEvent, nullptr);
118     inputEvent->SetDeviceId(1);
119     inputEvent->SetTargetWindowId(1);
120     inputEvent->SetAgentWindowId(1);
121     ASSERT_EQ(WinMgr->UpdateTarget(inputEvent), -1);
122 }
123 
124 /**
125  * @tc.name: InputWindowsManagerTest_UpdateDisplayId_004
126  * @tc.desc: Test UpdateDisplayId
127  * @tc.type: FUNC
128  * @tc.require:
129  */
130 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateDisplayId_004, TestSize.Level1)
131 {
132     // 创建displayGroupInfo_
133     DisplayGroupInfo displayGroupInfo;
134     displayGroupInfo.width = 20;
135     displayGroupInfo.height = 20;
136     displayGroupInfo.focusWindowId = 1;
137     uint32_t num = 1;
138     for (uint32_t i = 0; i < num; i++) {
139         WindowInfo info;
140         info.id = 1;
141         info.pid = 1;
142         info.uid = 1;
143         info.area = {1, 1, 1, 1};
144         info.defaultHotAreas = { info.area };
145         info.pointerHotAreas = { info.area };
146         info.agentWindowId = 1;
147         info.flags = 1;
148         displayGroupInfo.windowsInfo.push_back(info);
149     }
150 
151     for (uint32_t i = 0; i < num; i++) {
152         DisplayInfo info;
153         info.id = 1;
154         info.x =1;
155         info.y = 1;
156         info.width = 2;
157         info.height = 2;
158         info.dpi = 240;
159         info.name = "pp";
160         info.uniq = "pp";
161         info.direction = DIRECTION0;
162         displayGroupInfo.displaysInfo.push_back(info);
163     }
164     WinMgr->UpdateDisplayInfo(displayGroupInfo);
165 
166     UDSServer udsServer;
167     WinMgr->Init(udsServer);
168     WinMgr->UpdateDisplayInfo(displayGroupInfo);
169     int32_t displayId= 1;
170     double x = 0;
171     double y = 0;
172     WinMgr->UpdateAndAdjustMouseLocation(displayId, x, y);
173     ASSERT_EQ(WinMgr->UpdateDisplayId(displayId), true);
174     displayId= -1;
175     WinMgr->UpdateAndAdjustMouseLocation(displayId, x, y);
176     ASSERT_EQ(WinMgr->UpdateDisplayId(displayId), true);
177 }
178 
179 /**
180  * @tc.name: InputWindowsManagerTest_UpdateTargetPointer_005
181  * @tc.desc: Test UpdateTargetPointer
182  * @tc.type: FUNC
183  * @tc.require:
184  */
185 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateTargetPointer_005, TestSize.Level1)
186 {
187     UDSServer udsServer;
188     WinMgr->Init(udsServer);
189     auto pointerEvent = PointerEvent::Create();
190     ASSERT_EQ(WinMgr->UpdateTargetPointer(pointerEvent), -1);
191 }
192 
193 /**
194  * @tc.name: InputWindowsManagerTest_IsNeedRefreshLayer_006
195  * @tc.desc: Test IsNeedRefreshLayer
196  * @tc.type: FUNC
197  * @tc.require:
198  */
199 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_IsNeedRefreshLayer_006, TestSize.Level1)
200 {
201     UDSServer udsServer;
202     WinMgr->Init(udsServer);
203     ASSERT_EQ(WinMgr->IsNeedRefreshLayer(-1), false);
204     ASSERT_EQ(WinMgr->IsNeedRefreshLayer(0), false);
205     ASSERT_EQ(WinMgr->IsNeedRefreshLayer(1), false);
206 }
207 
208 /**
209  * @tc.name: InputWindowsManagerTest_GetWindowPid_007
210  * @tc.desc: Test GetWindowPid
211  * @tc.type: FUNC
212  * @tc.require:
213  */
214 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_GetWindowPid_002, TestSize.Level1)
215 {
216     UDSServer udsServer;
217     WinMgr->Init(udsServer);
218     ASSERT_EQ(WinMgr->GetWindowPid(1), 1);
219     ASSERT_EQ(WinMgr->GetWindowPid(2), -1);
220 }
221 
222 
223 /**
224  * @tc.name: InputWindowsManagerTest_SetMouseCaptureMode_008
225  * @tc.desc: Test SetMouseCaptureMode
226  * @tc.type: FUNC
227  * @tc.require:
228  */
229 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_SetMouseCaptureMode_008, TestSize.Level1)
230 {
231     UDSServer udsServer;
232     WinMgr->Init(udsServer);
233     bool isCaptureMode = false;
234     ASSERT_EQ(WinMgr->SetMouseCaptureMode(-1, isCaptureMode), -1);
235     ASSERT_EQ(WinMgr->SetMouseCaptureMode(1, isCaptureMode), 0);
236     isCaptureMode = true;
237     ASSERT_EQ(WinMgr->SetMouseCaptureMode(1, isCaptureMode), 0);
238 }
239 
240 /**
241  * @tc.name: InputWindowsManagerTest_SetDisplayBind_009
242  * @tc.desc: Test SetDisplayBind
243  * @tc.type: FUNC
244  * @tc.require:
245  */
246 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_SetDisplayBind_009, TestSize.Level1)
247 {
248     UDSServer udsServer;
249     WinMgr->Init(udsServer);
250     std::string sysUid = "james";
251     std::string devStatus = "add";
252     WinMgr->DeviceStatusChanged(2, sysUid, devStatus);
253     devStatus = "remove";
254     WinMgr->DeviceStatusChanged(2, sysUid, devStatus);
255     std::string msg = "There is in InputWindowsManagerTest_GetDisplayIdNames_009";
256     ASSERT_EQ(WinMgr->SetDisplayBind(-1, 1, msg), -1);
257 }
258 
259 /**
260  * @tc.name: InputWindowsManagerTest_SetHoverScrollState_010
261  * @tc.desc: Test SetHoverScrollState
262  * @tc.type: FUNC
263  * @tc.require:
264  */
265 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_SetHoverScrollState_010, TestSize.Level1)
266 {
267     ASSERT_TRUE(WinMgr->SetHoverScrollState(false) == RET_OK);
268     WinMgr->SetHoverScrollState(true);
269     const char *mouseFileName = "/data/service/el1/public/multimodalinput/mouse_settings.xml";
270     ASSERT_TRUE(remove(mouseFileName) == RET_OK);
271 }
272 
273 /**
274  * @tc.name: InputWindowsManagerTest_GetHoverScrollState_011
275  * @tc.desc: Test GetHoverScrollState
276  * @tc.type: FUNC
277  * @tc.require:
278  */
279 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_GetHoverScrollState_011, TestSize.Level1)
280 {
281     WinMgr->SetHoverScrollState(true);
282     ASSERT_TRUE(WinMgr->GetHoverScrollState());
283     const char *mouseFileName = "/data/service/el1/public/multimodalinput/mouse_settings.xml";
284     ASSERT_TRUE(remove(mouseFileName) == RET_OK);
285 }
286 } // namespace MMI
287 } // namespace OHOS
288