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 <fstream>
20
21 #include "libinput-private.h"
22
23 #include "input_device_manager.h"
24 #include "key_auto_repeat.h"
25 #include "mmi_log.h"
26 #include "uds_server.h"
27 #include "uds_session.h"
28
29 namespace OHOS {
30 namespace MMI {
31 namespace {
32 using namespace testing::ext;
33 } // namespace
34
35 class InputDeviceManagerTest : public testing::Test {
36 public:
SetUpTestCase(void)37 static void SetUpTestCase(void) {}
TearDownTestCase(void)38 static void TearDownTestCase(void) {}
39 };
40
41 class MockUDSSession : public UDSSession {
42 public:
43 MOCK_METHOD1(SendMsg, int32_t(NetPacket &));
MockUDSSession(const std::string &programName, const int32_t moduleType, const int32_t fd, const int32_t uid, const int32_t pid)44 MockUDSSession(const std::string &programName, const int32_t moduleType, const int32_t fd, const int32_t uid,
45 const int32_t pid) : UDSSession(programName, moduleType, fd, uid, pid) {}
46 };
47
48 class MockInputDevice {
49 public:
50 MOCK_METHOD1(SetId, void(int32_t deviceId));
51 MOCK_METHOD0(MakeVirtualDeviceInfo, int());
52 };
53
54 /**
55 * @tc.name: InputDeviceManagerTest_GetInputDeviceIds_003
56 * @tc.desc: Test the function GetInputDeviceIds
57 * @tc.type: FUNC
58 * @tc.require:
59 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetInputDeviceIds_003, TestSize.Level1)60 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetInputDeviceIds_003, TestSize.Level1)
61 {
62 CALL_TEST_DEBUG;
63 InputDeviceManager manager;
64 InputDeviceManager::InputDeviceInfo info1;
65 info1.networkIdOrigin = "device1";
66 info1.enable = true;
67 manager.inputDevice_[1] = info1;
68 InputDeviceManager::InputDeviceInfo info2;
69 info2.networkIdOrigin = "device2";
70 info2.enable = false;
71 manager.inputDevice_[2] = info2;
72 InputDeviceManager::InputDeviceInfo info3;
73 info3.networkIdOrigin = "device3";
74 info3.enable = true;
75 manager.inputDevice_[3] = info3;
76 auto ids = manager.GetInputDeviceIds();
77 ASSERT_EQ(ids.size(), 2);
78 EXPECT_EQ(ids[0], 1);
79 EXPECT_EQ(ids[1], 3);
80 }
81
82 /**
83 * @tc.name: InputDeviceManagerTest_SupportKeys_003
84 * @tc.desc: Test the function SupportKeys
85 * @tc.type: FUNC
86 * @tc.require:
87 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_SupportKeys_003, TestSize.Level1)88 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_SupportKeys_003, TestSize.Level1)
89 {
90 CALL_TEST_DEBUG;
91 InputDeviceManager manager;
92 InputDeviceManager::InputDeviceInfo info;
93 info.networkIdOrigin = "device1";
94 info.enable = true;
95 manager.inputDevice_[1] = info;
96 std::vector<int32_t> keyCodes = {1};
97 std::vector<bool> keystroke;
98 int32_t ret = manager.SupportKeys(1, keyCodes, keystroke);
99 ASSERT_EQ(ret, RET_OK);
100 ASSERT_EQ(keystroke.size(), 1);
101 EXPECT_EQ(keystroke[0], true);
102 }
103
104 /**
105 * @tc.name: InputDeviceManagerTest_GetDeviceConfig_003
106 * @tc.desc: Test the function GetDeviceConfig
107 * @tc.type: FUNC
108 * @tc.require:
109 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetDeviceConfig_003, TestSize.Level1)110 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetDeviceConfig_003, TestSize.Level1)
111 {
112 CALL_TEST_DEBUG;
113 InputDeviceManager manager;
114 int32_t keyboardType;
115 int32_t ret = manager.GetDeviceConfig(-1, keyboardType);
116 ASSERT_EQ(ret, false);
117 InputDeviceManager::InputDeviceInfo info;
118 info.networkIdOrigin = "device1";
119 manager.inputDevice_[1] = info;
120 ret = manager.GetDeviceConfig(1, keyboardType);
121 ASSERT_EQ(ret, false);
122 std::map<int32_t, DeviceConfig> deviceConfig;
123 DeviceConfig config;
124 config.keyboardType = 1;
125 deviceConfig[1] = config;
126 ret = manager.GetDeviceConfig(1, keyboardType);
127 ASSERT_EQ(ret, RET_OK);
128 ASSERT_EQ(keyboardType, RET_OK);
129 }
130
131 /**
132 * @tc.name: InputDeviceManagerTest_NotifyDevRemoveCallback_002
133 * @tc.desc: Test the function NotifyDevRemoveCallback
134 * @tc.type: FUNC
135 * @tc.require:
136 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_NotifyDevRemoveCallback_002, TestSize.Level1)137 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_NotifyDevRemoveCallback_002, TestSize.Level1)
138 {
139 CALL_TEST_DEBUG;
140 InputDeviceManager deviceManager;
141 int32_t deviceId = 1;
142 InputDeviceManager::InputDeviceInfo deviceInfo;
143 deviceInfo.sysUid = "";
144 ASSERT_NO_FATAL_FAILURE(deviceManager.NotifyDevRemoveCallback(deviceId, deviceInfo));
145 }
146
147 /**
148 * @tc.name: InputDeviceManagerTest_GenerateVirtualDeviceId_001
149 * @tc.desc: Test the function GenerateVirtualDeviceId
150 * @tc.type: FUNC
151 * @tc.require:
152 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GenerateVirtualDeviceId_001, TestSize.Level1)153 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GenerateVirtualDeviceId_001, TestSize.Level1)
154 {
155 CALL_TEST_DEBUG;
156 InputDeviceManager deviceManager;
157 int32_t deviceId = 0;
158 int32_t MAX_VIRTUAL_INPUT_DEVICE_NUM = 128;
159 for (int i = 0; i < MAX_VIRTUAL_INPUT_DEVICE_NUM; i++) {
160 deviceManager.virtualInputDevices_.insert(std::make_pair(i, std::make_shared<InputDevice>()));
161 }
162 EXPECT_EQ(deviceManager.GenerateVirtualDeviceId(deviceId), RET_ERR);
163 }
164
165 /**
166 * @tc.name: InputDeviceManagerTest_GenerateVirtualDeviceId_002
167 * @tc.desc: Test the function GenerateVirtualDeviceId
168 * @tc.type: FUNC
169 * @tc.require:
170 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GenerateVirtualDeviceId_002, TestSize.Level1)171 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GenerateVirtualDeviceId_002, TestSize.Level1)
172 {
173 CALL_TEST_DEBUG;
174 InputDeviceManager deviceManager;
175 int32_t deviceId = 0;
176 deviceManager.virtualInputDevices_.insert(std::make_pair(1, std::make_shared<InputDevice>()));
177 EXPECT_EQ(deviceManager.GenerateVirtualDeviceId(deviceId), RET_OK);
178 }
179
180 /**
181 * @tc.name: InputDeviceManagerTest_GenerateVirtualDeviceId_003
182 * @tc.desc: Test the function GenerateVirtualDeviceId
183 * @tc.type: FUNC
184 * @tc.require:
185 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GenerateVirtualDeviceId_003, TestSize.Level1)186 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GenerateVirtualDeviceId_003, TestSize.Level1)
187 {
188 CALL_TEST_DEBUG;
189 InputDeviceManager deviceManager;
190 int32_t deviceId = 0;
191 EXPECT_EQ(deviceManager.GenerateVirtualDeviceId(deviceId), RET_OK);
192 }
193
194 /**
195 * @tc.name: InputDeviceManagerTest_RemoveVirtualInputDevice_001
196 * @tc.desc: Test the function RemoveVirtualInputDevice
197 * @tc.type: FUNC
198 * @tc.require:
199 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_RemoveVirtualInputDevice_001, TestSize.Level1)200 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_RemoveVirtualInputDevice_001, TestSize.Level1)
201 {
202 CALL_TEST_DEBUG;
203 InputDeviceManager deviceManager;
204 int32_t deviceId = 1;
205 EXPECT_EQ(deviceManager.RemoveVirtualInputDevice(deviceId), RET_ERR);
206 }
207
208 /**
209 * @tc.name: InputDeviceManagerTest_RemoveVirtualInputDevice_002
210 * @tc.desc: Test the function RemoveVirtualInputDevice
211 * @tc.type: FUNC
212 * @tc.require:
213 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_RemoveVirtualInputDevice_002, TestSize.Level1)214 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_RemoveVirtualInputDevice_002, TestSize.Level1)
215 {
216 CALL_TEST_DEBUG;
217 InputDeviceManager deviceManager;
218 int32_t deviceId = 1;
219 deviceManager.virtualInputDevices_[deviceId] = std::make_shared<InputDevice>();
220 EXPECT_EQ(deviceManager.RemoveVirtualInputDevice(deviceId), RET_OK);
221 }
222
223 /**
224 * @tc.name: InputDeviceManagerTest_RemoveVirtualInputDevice_003
225 * @tc.desc: Test the function RemoveVirtualInputDevice
226 * @tc.type: FUNC
227 * @tc.require:
228 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_RemoveVirtualInputDevice_003, TestSize.Level1)229 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_RemoveVirtualInputDevice_003, TestSize.Level1)
230 {
231 CALL_TEST_DEBUG;
232 InputDeviceManager deviceManager;
233 int32_t deviceId = 1;
234 auto device = std::make_shared<InputDevice>();
235 deviceManager.virtualInputDevices_[deviceId] = device;
236 EXPECT_EQ(deviceManager.RemoveVirtualInputDevice(deviceId), RET_OK);
237 EXPECT_EQ(deviceManager.virtualInputDevices_.find(deviceId), deviceManager.virtualInputDevices_.end());
238 }
239
240 /**
241 * @tc.name: InputDeviceManagerTest_AddVirtualInputDevice_001
242 * @tc.desc: Test the function AddVirtualInputDevice
243 * @tc.type: FUNC
244 * @tc.require:
245 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_AddVirtualInputDevice_001, TestSize.Level1)246 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_AddVirtualInputDevice_001, TestSize.Level1)
247 {
248 CALL_TEST_DEBUG;
249 InputDeviceManager manager;
250 std::shared_ptr<MockInputDevice> mockDevice = std::make_shared<MockInputDevice>();
251 int32_t deviceId = 0;
252 std::shared_ptr<InputDevice> device;
253 EXPECT_CALL(*mockDevice, MakeVirtualDeviceInfo()).WillRepeatedly(testing::Return(RET_ERR));
254 int32_t ret = manager.AddVirtualInputDevice(device, deviceId);
255 EXPECT_EQ(ret, RET_ERR);
256 EXPECT_EQ(deviceId, RET_OK);
257 }
258
259 /**
260 * @tc.name: InputDeviceManagerTest_AddVirtualInputDevice_002
261 * @tc.desc: Test the function AddVirtualInputDevice
262 * @tc.type: FUNC
263 * @tc.require:
264 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_AddVirtualInputDevice_002, TestSize.Level1)265 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_AddVirtualInputDevice_002, TestSize.Level1)
266 {
267 CALL_TEST_DEBUG;
268 InputDeviceManager manager;
269 std::shared_ptr<MockInputDevice> mockDevice = std::make_shared<MockInputDevice>();
270 int32_t deviceId = 1;
271 std::shared_ptr<InputDevice> device;
272 EXPECT_CALL(*mockDevice, MakeVirtualDeviceInfo()).WillRepeatedly(testing::Return(RET_ERR));
273 int32_t ret = manager.AddVirtualInputDevice(device, deviceId);
274 EXPECT_EQ(ret, RET_ERR);
275 }
276
277 /**
278 * @tc.name: InputDeviceManagerTest_AddVirtualInputDevice_003
279 * @tc.desc: Test the function AddVirtualInputDevice
280 * @tc.type: FUNC
281 * @tc.require:
282 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_AddVirtualInputDevice_003, TestSize.Level1)283 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_AddVirtualInputDevice_003, TestSize.Level1)
284 {
285 CALL_TEST_DEBUG;
286 InputDeviceManager manager;
287 std::shared_ptr<MockInputDevice> mockDevice = std::make_shared<MockInputDevice>();
288 int32_t deviceId = 1;
289 std::shared_ptr<InputDevice> device;
290 EXPECT_CALL(*mockDevice, MakeVirtualDeviceInfo()).WillRepeatedly(testing::Return(RET_OK));
291 int32_t ret = manager.AddVirtualInputDevice(device, deviceId);
292 EXPECT_EQ(ret, RET_ERR);
293 }
294
295 /**
296 * @tc.name: InputDeviceManagerTest_AddVirtualInputDevice_004
297 * @tc.desc: Test the function AddVirtualInputDevice
298 * @tc.type: FUNC
299 * @tc.require:
300 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_AddVirtualInputDevice_004, TestSize.Level1)301 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_AddVirtualInputDevice_004, TestSize.Level1)
302 {
303 CALL_TEST_DEBUG;
304 InputDeviceManager deviceManager;
305 int32_t deviceId = 1;
306 std::shared_ptr<InputDevice> device;
307
308 int32_t MAX_VIRTUAL_INPUT_DEVICE_NUM = 128;
309 for (int i = 0; i < MAX_VIRTUAL_INPUT_DEVICE_NUM; i++) {
310 deviceManager.virtualInputDevices_.insert(std::make_pair(i, std::make_shared<InputDevice>()));
311 }
312
313 EXPECT_EQ(deviceManager.GenerateVirtualDeviceId(deviceId), RET_ERR);
314 int32_t ret = INPUT_DEV_MGR->AddVirtualInputDevice(device, deviceId);
315 EXPECT_EQ(ret, RET_ERR);
316 }
317
318 /**
319 * @tc.name: InputDeviceManagerTest_AddVirtualInputDevice_005
320 * @tc.desc: Test the function AddVirtualInputDevice
321 * @tc.type: FUNC
322 * @tc.require:
323 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_AddVirtualInputDevice_005, TestSize.Level1)324 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_AddVirtualInputDevice_005, TestSize.Level1)
325 {
326 CALL_TEST_DEBUG;
327 InputDeviceManager deviceManager;
328 int32_t deviceId = 2;
329 std::shared_ptr<InputDevice> device;
330 deviceManager.virtualInputDevices_.insert(std::make_pair(1, std::make_shared<InputDevice>()));
331 EXPECT_EQ(deviceManager.GenerateVirtualDeviceId(deviceId), RET_OK);
332
333 int32_t ret = INPUT_DEV_MGR->AddVirtualInputDevice(device, deviceId);
334 EXPECT_EQ(ret, RET_ERR);
335 }
336
337 /**
338 * @tc.name: InputDeviceManagerTest_AddVirtualInputDevice_006
339 * @tc.desc: Test the function AddVirtualInputDevice
340 * @tc.type: FUNC
341 * @tc.require:
342 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_AddVirtualInputDevice_006, TestSize.Level1)343 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_AddVirtualInputDevice_006, TestSize.Level1)
344 {
345 CALL_TEST_DEBUG;
346 InputDeviceManager deviceManager;
347 int32_t deviceId = 2;
348 std::shared_ptr<InputDevice> device;
349 std::shared_ptr<MockInputDevice> mockDevice = std::make_shared<MockInputDevice>();
350 deviceManager.virtualInputDevices_.insert(std::make_pair(1, std::make_shared<InputDevice>()));
351 EXPECT_EQ(deviceManager.GenerateVirtualDeviceId(deviceId), RET_OK);
352 EXPECT_CALL(*mockDevice, MakeVirtualDeviceInfo()).WillRepeatedly(testing::Return(RET_ERR));
353
354 int32_t ret = INPUT_DEV_MGR->AddVirtualInputDevice(device, deviceId);
355 EXPECT_EQ(ret, RET_ERR);
356 }
357
358 /**
359 * @tc.name: InputDeviceManagerTest_AddVirtualInputDevice_007
360 * @tc.desc: Test the function AddVirtualInputDevice
361 * @tc.type: FUNC
362 * @tc.require:
363 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_AddVirtualInputDevice_007, TestSize.Level1)364 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_AddVirtualInputDevice_007, TestSize.Level1)
365 {
366 CALL_TEST_DEBUG;
367 InputDeviceManager deviceManager;
368 int32_t deviceId = 2;
369 std::shared_ptr<InputDevice> device;
370 std::shared_ptr<MockInputDevice> mockDevice = std::make_shared<MockInputDevice>();
371 deviceManager.virtualInputDevices_.insert(std::make_pair(1, std::make_shared<InputDevice>()));
372 EXPECT_EQ(deviceManager.GenerateVirtualDeviceId(deviceId), RET_OK);
373 EXPECT_CALL(*mockDevice, MakeVirtualDeviceInfo()).WillRepeatedly(testing::Return(RET_OK));
374
375 int32_t ret = INPUT_DEV_MGR->AddVirtualInputDevice(device, deviceId);
376 EXPECT_EQ(ret, RET_ERR);
377 }
378
379 /**
380 * @tc.name: InputDeviceManagerTest_GetKeyboardType_003
381 * @tc.desc: Test the function GetKeyboardType
382 * @tc.type: FUNC
383 * @tc.require:
384 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetKeyboardType_003, TestSize.Level1)385 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetKeyboardType_003, TestSize.Level1)
386 {
387 CALL_TEST_DEBUG;
388 InputDeviceManager inputDeviceManager;
389 int32_t deviceId = 1;
390 int32_t keyboardType = 0;
391 std::shared_ptr<InputDevice> device = std::make_shared<InputDevice>();
392 inputDeviceManager.virtualInputDevices_.insert(std::make_pair(deviceId, device));
393 EXPECT_EQ(inputDeviceManager.GetKeyboardType(deviceId, keyboardType), RET_OK);
394 EXPECT_EQ(keyboardType, KEYBOARD_TYPE_NONE);
395 }
396
397 /**
398 * @tc.name: InputDeviceManagerTest_GetKeyboardType_004
399 * @tc.desc: Test the function GetKeyboardType
400 * @tc.type: FUNC
401 * @tc.require:
402 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetKeyboardType_004, TestSize.Level1)403 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetKeyboardType_004, TestSize.Level1)
404 {
405 CALL_TEST_DEBUG;
406 InputDeviceManager inputDeviceManager;
407 int32_t deviceId = 2;
408 int32_t keyboardType = 0;
409 std::shared_ptr<InputDevice> device = std::make_shared<InputDevice>();
410 inputDeviceManager.virtualInputDevices_.insert(std::make_pair(deviceId, device));
411 EXPECT_EQ(inputDeviceManager.GetKeyboardType(deviceId, keyboardType), RET_OK);
412 EXPECT_EQ(keyboardType, KEYBOARD_TYPE_NONE);
413 }
414
415 /**
416 * @tc.name: InputDeviceManagerTest_GetKeyboardType_005
417 * @tc.desc: Test the function GetKeyboardType
418 * @tc.type: FUNC
419 * @tc.require:
420 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetKeyboardType_005, TestSize.Level1)421 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetKeyboardType_005, TestSize.Level1)
422 {
423 CALL_TEST_DEBUG;
424 InputDeviceManager inputDeviceManager;
425 int32_t deviceId = 3;
426 int32_t keyboardType = 0;
427 inputDeviceManager.inputDevice_.insert(std::make_pair(deviceId, InputDeviceManager::InputDeviceInfo()));
428 inputDeviceManager.inputDevice_[deviceId].enable = false;
429 EXPECT_EQ(inputDeviceManager.GetKeyboardType(deviceId, keyboardType), RET_ERR);
430 }
431
432 /**
433 * @tc.name: InputDeviceManagerTest_OnEnableInputDevice_Test_001
434 * @tc.desc: Test the function OnEnableInputDevice
435 * @tc.type: FUNC
436 * @tc.require:
437 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_OnEnableInputDevice_Test_001, TestSize.Level1)438 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_OnEnableInputDevice_Test_001, TestSize.Level1)
439 {
440 CALL_TEST_DEBUG;
441 InputDeviceManager inputDevice;
442 bool enable = true;
443 int32_t keyboardType = KEYBOARD_TYPE_NONE;
444 EXPECT_TRUE(keyboardType != KEYBOARD_TYPE_ALPHABETICKEYBOARD);
445 int32_t ret = inputDevice.OnEnableInputDevice(enable);
446 EXPECT_EQ(ret, RET_OK);
447 }
448
449 /**
450 * @tc.name: InputDeviceManagerTest_OnEnableInputDevice_Test_02
451 * @tc.desc: Test the function OnEnableInputDevice
452 * @tc.type: FUNC
453 * @tc.require:
454 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_OnEnableInputDevice_Test_02, TestSize.Level1)455 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_OnEnableInputDevice_Test_02, TestSize.Level1)
456 {
457 CALL_TEST_DEBUG;
458 InputDeviceManager inputDevice;
459 int32_t deviceId = 3;
460 bool enable = true;
461
462 InputDeviceManager::InputDeviceInfo deviceInfo;
463 deviceInfo.isRemote = true;
464 deviceInfo.enable = false;
465 inputDevice.inputDevice_.insert(std::make_pair(deviceId, deviceInfo));
466
467 int32_t ret = inputDevice.OnEnableInputDevice(enable);
468 EXPECT_EQ(ret, RET_OK);
469 }
470
471 /**
472 * @tc.name: InputDeviceManagerTest_OnEnableInputDevice_Test_03
473 * @tc.desc: Test the function OnEnableInputDevice
474 * @tc.type: FUNC
475 * @tc.require:
476 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_OnEnableInputDevice_Test_03, TestSize.Level1)477 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_OnEnableInputDevice_Test_03, TestSize.Level1)
478 {
479 CALL_TEST_DEBUG;
480 InputDeviceManager inputDevice;
481 int32_t deviceId = 3;
482 bool enable = true;
483
484 InputDeviceManager::InputDeviceInfo deviceInfo;
485 deviceInfo.isRemote = false;
486 deviceInfo.enable = true;
487 inputDevice.inputDevice_.insert(std::make_pair(deviceId, deviceInfo));
488
489 int32_t ret = inputDevice.OnEnableInputDevice(enable);
490 EXPECT_EQ(ret, RET_OK);
491 }
492
493 /**
494 * @tc.name: InputDeviceManagerTest_OnEnableInputDevice_Test_04
495 * @tc.desc: Test the function OnEnableInputDevice
496 * @tc.type: FUNC
497 * @tc.require:
498 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_OnEnableInputDevice_Test_04, TestSize.Level1)499 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_OnEnableInputDevice_Test_04, TestSize.Level1)
500 {
501 CALL_TEST_DEBUG;
502 InputDeviceManager inputDevice;
503 int32_t deviceId = 5;
504 bool enable = true;
505
506 InputDeviceManager::InputDeviceInfo deviceInfo;
507 deviceInfo.isRemote = false;
508 deviceInfo.enable = false;
509 deviceInfo.isPointerDevice = false;
510 inputDevice.inputDevice_.insert(std::make_pair(deviceId, deviceInfo));
511
512 int32_t ret = inputDevice.OnEnableInputDevice(enable);
513 EXPECT_EQ(ret, RET_OK);
514 }
515
516 /**
517 * @tc.name: InputDeviceManagerTest_OnEnableInputDevice_Test_05
518 * @tc.desc: Test the function OnEnableInputDevice
519 * @tc.type: FUNC
520 * @tc.require:
521 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_OnEnableInputDevice_Test_05, TestSize.Level1)522 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_OnEnableInputDevice_Test_05, TestSize.Level1)
523 {
524 CALL_TEST_DEBUG;
525 InputDeviceManager inputDevice;
526 int32_t deviceId = 3;
527 bool enable = true;
528
529 InputDeviceManager::InputDeviceInfo deviceInfo;
530 deviceInfo.isRemote = false;
531 deviceInfo.enable = false;
532 deviceInfo.isPointerDevice = true;
533 inputDevice.inputDevice_.insert(std::make_pair(deviceId, deviceInfo));
534
535 int32_t ret = inputDevice.OnEnableInputDevice(enable);
536 EXPECT_EQ(ret, RET_OK);
537 }
538
539 /**
540 * @tc.name: InputDeviceManagerTest_OnEnableInputDevice_Test_06
541 * @tc.desc: Test the function OnEnableInputDevice
542 * @tc.type: FUNC
543 * @tc.require:
544 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_OnEnableInputDevice_Test_06, TestSize.Level1)545 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_OnEnableInputDevice_Test_06, TestSize.Level1)
546 {
547 CALL_TEST_DEBUG;
548 InputDeviceManager inputDevice;
549 int32_t deviceId = 3;
550 bool enable = true;
551
552 InputDeviceManager::InputDeviceInfo deviceInfo;
553 deviceInfo.isRemote = false;
554 deviceInfo.enable = true;
555 deviceInfo.isPointerDevice = true;
556 inputDevice.inputDevice_.insert(std::make_pair(deviceId, deviceInfo));
557
558 int32_t ret = inputDevice.OnEnableInputDevice(enable);
559 EXPECT_EQ(ret, RET_OK);
560 }
561
562 /**
563 * @tc.name: InputDeviceManagerTest_GetKeyboardDevice_Test_001
564 * @tc.desc: Test the function GetKeyboardDevice
565 * @tc.type: FUNC
566 * @tc.require:
567 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetKeyboardDevice_Test_001, TestSize.Level1)568 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetKeyboardDevice_Test_001, TestSize.Level1)
569 {
570 CALL_TEST_DEBUG;
571 InputDeviceManager inputDevice;
572 struct libinput_device *device = nullptr;
573 std::vector<int32_t> keyCodes;
574 keyCodes.push_back(KeyEvent::KEYCODE_Q);
575 keyCodes.push_back(KeyEvent::KEYCODE_NUMPAD_1);
576
577 bool ret1 = inputDevice.IsMatchKeys(device, keyCodes);
578 EXPECT_FALSE(ret1);
579 auto ret2 = inputDevice.GetKeyboardDevice();
580 EXPECT_EQ(ret2, nullptr);
581 }
582
583 /**
584 * @tc.name: InputDeviceManagerTest_OnInputDeviceAdded_Test_001
585 * @tc.desc: Test the function OnInputDeviceAdded
586 * @tc.type: FUNC
587 * @tc.require:
588 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_OnInputDeviceAdded_Test_001, TestSize.Level1)589 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_OnInputDeviceAdded_Test_001, TestSize.Level1)
590 {
591 CALL_TEST_DEBUG;
592 InputDeviceManager inputDevice;
593 int32_t deviceId;
594 struct libinput_device *device = nullptr;
595 deviceId = 2;
596 ASSERT_NO_FATAL_FAILURE(inputDevice.OnInputDeviceAdded(device));
597 }
598
599 /**
600 * @tc.name: InputDeviceManagerTest_GetDeviceSupportKey_Test_001
601 * @tc.desc: Test the function GetDeviceSupportKey
602 * @tc.type: FUNC
603 * @tc.require:
604 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetDeviceSupportKey_Test_001, TestSize.Level1)605 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetDeviceSupportKey_Test_001, TestSize.Level1)
606 {
607 CALL_TEST_DEBUG;
608 std::vector<int32_t> keyCodes;
609 int32_t deviceId = 1;
610 int32_t keyboardType = KEYBOARD_TYPE_REMOTECONTROL;
611 std::map<int32_t, bool> determineKbType;
612 int32_t returnCode1 = 401;
613 int32_t returnCode2 = 65142786;
614 InputDeviceManager inputDevice;
615 keyCodes.push_back(KeyEvent::KEYCODE_Q);
616 keyCodes.push_back(KeyEvent::KEYCODE_HOME);
617 keyCodes.push_back(KeyEvent::KEYCODE_CTRL_LEFT);
618 keyCodes.push_back(KeyEvent::KEYCODE_F2);
619
620 int32_t ret1 = inputDevice.GetKeyboardBusMode(deviceId);
621 EXPECT_EQ(ret1, returnCode2);
622 int32_t ret2 = inputDevice.GetDeviceSupportKey(deviceId, keyboardType);
623 EXPECT_EQ(ret2, returnCode1);
624 }
625
626 /**
627 * @tc.name: GetInputDevice_Test_001
628 * @tc.desc: Test the function GetInputDevice
629 * @tc.type: FUNC
630 * @tc.require:
631 */
HWTEST_F(InputDeviceManagerTest, GetInputDevice_Test_001, TestSize.Level1)632 HWTEST_F(InputDeviceManagerTest, GetInputDevice_Test_001, TestSize.Level1)
633 {
634 CALL_TEST_DEBUG;
635 InputDeviceManager inputDevice;
636 std::shared_ptr<InputDevice> inputDeviceManager{nullptr};
637 int32_t id = 1;
638 bool checked = true;
639 inputDeviceManager = inputDevice.GetInputDevice(id, checked);
640 EXPECT_EQ(inputDeviceManager, nullptr);
641 }
642
643 /**
644 * @tc.name: GetInputDeviceIds_Test_001
645 * @tc.desc: Test the function GetInputDeviceIds
646 * @tc.type: FUNC
647 * @tc.require:
648 */
HWTEST_F(InputDeviceManagerTest, GetInputDeviceIds_Test_001, TestSize.Level1)649 HWTEST_F(InputDeviceManagerTest, GetInputDeviceIds_Test_001, TestSize.Level1)
650 {
651 CALL_TEST_DEBUG;
652 InputDeviceManager inputDevice;
653 ASSERT_NO_FATAL_FAILURE(inputDevice.GetInputDeviceIds());
654 }
655
656 /**
657 * @tc.name: SupportKeys_Test_001
658 * @tc.desc: Test the function SupportKeys
659 * @tc.type: FUNC
660 * @tc.require:
661 */
HWTEST_F(InputDeviceManagerTest, SupportKeys_Test_001, TestSize.Level1)662 HWTEST_F(InputDeviceManagerTest, SupportKeys_Test_001, TestSize.Level1)
663 {
664 CALL_TEST_DEBUG;
665 InputDeviceManager inputDevice;
666 int32_t deviceId = 1;
667 std::vector<int32_t> keyCodes{12};
668 std::vector<bool> keystroke{true};
669 int32_t returnCode = 401;
670 int32_t ret = inputDevice.SupportKeys(deviceId, keyCodes, keystroke);
671 EXPECT_EQ(ret, returnCode);
672 }
673
674 /**
675 * @tc.name: GetDeviceConfig_Test_001
676 * @tc.desc: Test the function GetDeviceConfig
677 * @tc.type: FUNC
678 * @tc.require:
679 */
HWTEST_F(InputDeviceManagerTest, GetDeviceConfig_Test_001, TestSize.Level1)680 HWTEST_F(InputDeviceManagerTest, GetDeviceConfig_Test_001, TestSize.Level1)
681 {
682 CALL_TEST_DEBUG;
683 InputDeviceManager inputDevice;
684 int32_t deviceId = 1;
685 int32_t keyboardType = 1;
686 bool ret = inputDevice.GetDeviceConfig(deviceId, keyboardType);
687 EXPECT_FALSE(ret);
688 }
689
690 /**
691 * @tc.name: GetDeviceSupportKey_Test_001
692 * @tc.desc: Test the function GetDeviceSupportKey
693 * @tc.type: FUNC
694 * @tc.require:
695 */
HWTEST_F(InputDeviceManagerTest, GetDeviceSupportKey_Test_001, TestSize.Level1)696 HWTEST_F(InputDeviceManagerTest, GetDeviceSupportKey_Test_001, TestSize.Level1)
697 {
698 CALL_TEST_DEBUG;
699 InputDeviceManager inputDevice;
700 int32_t deviceId = 1;
701 int32_t keyboardType = 1;
702 int32_t returnCode = 401;
703 int32_t ret = inputDevice.GetDeviceSupportKey(deviceId, keyboardType);
704 EXPECT_EQ(ret, returnCode);
705 }
706
707 /**
708 * @tc.name: GetKeyboardType_Test_001
709 * @tc.desc: Test the function GetKeyboardType
710 * @tc.type: FUNC
711 * @tc.require:
712 */
HWTEST_F(InputDeviceManagerTest, GetKeyboardType_Test_001, TestSize.Level1)713 HWTEST_F(InputDeviceManagerTest, GetKeyboardType_Test_001, TestSize.Level1)
714 {
715 CALL_TEST_DEBUG;
716 InputDeviceManager inputDevice;
717 int32_t deviceId = 1;
718 int32_t keyboardType = 1;
719 int32_t returnCode = 401;
720 int32_t ret = inputDevice.GetKeyboardType(deviceId, keyboardType);
721 EXPECT_EQ(ret, returnCode);
722 }
723
724 /**
725 * @tc.name: HasTouchDevice_Test_001
726 * @tc.desc: Test the function HasTouchDevice
727 * @tc.type: FUNC
728 * @tc.require:
729 */
HWTEST_F(InputDeviceManagerTest, HasTouchDevice_Test_001, TestSize.Level1)730 HWTEST_F(InputDeviceManagerTest, HasTouchDevice_Test_001, TestSize.Level1)
731 {
732 CALL_TEST_DEBUG;
733 InputDeviceManager inputDevice;
734 bool ret = inputDevice.HasTouchDevice();
735 EXPECT_FALSE(ret);
736 }
737
738 /**
739 * @tc.name: ScanPointerDevice_Test_001
740 * @tc.desc: Test the function ScanPointerDevice
741 * @tc.type: FUNC
742 * @tc.require:
743 */
HWTEST_F(InputDeviceManagerTest, ScanPointerDevice_Test_001, TestSize.Level1)744 HWTEST_F(InputDeviceManagerTest, ScanPointerDevice_Test_001, TestSize.Level1)
745 {
746 CALL_TEST_DEBUG;
747 InputDeviceManager inputDevice;
748 ASSERT_NO_FATAL_FAILURE(inputDevice.ScanPointerDevice());
749 }
750
751 /**
752 * @tc.name: Dump_Test_001
753 * @tc.desc: Test the function Dump
754 * @tc.type: FUNC
755 * @tc.require:
756 */
HWTEST_F(InputDeviceManagerTest, Dump_Test_001, TestSize.Level1)757 HWTEST_F(InputDeviceManagerTest, Dump_Test_001, TestSize.Level1)
758 {
759 CALL_TEST_DEBUG;
760 InputDeviceManager inputDevice;
761 int32_t fd = 1;
762 std::vector<std::string> args{"test"};
763 ASSERT_NO_FATAL_FAILURE(inputDevice.Dump(fd, args));
764 }
765
766 /**
767 * @tc.name: DumpDeviceList_Test_001
768 * @tc.desc: Test the function DumpDeviceList
769 * @tc.type: FUNC
770 * @tc.require:
771 */
HWTEST_F(InputDeviceManagerTest, DumpDeviceList_Test_001, TestSize.Level1)772 HWTEST_F(InputDeviceManagerTest, DumpDeviceList_Test_001, TestSize.Level1)
773 {
774 CALL_TEST_DEBUG;
775 InputDeviceManager inputDevice;
776 int32_t fd = 1;
777 std::vector<std::string> args{"test"};
778 ASSERT_NO_FATAL_FAILURE(inputDevice.DumpDeviceList(fd, args));
779 }
780
781 /**
782 * @tc.name: GetVendorConfig_Test_001
783 * @tc.desc: Test the function GetVendorConfig
784 * @tc.type: FUNC
785 * @tc.require:
786 */
HWTEST_F(InputDeviceManagerTest, GetVendorConfig_Test_001, TestSize.Level1)787 HWTEST_F(InputDeviceManagerTest, GetVendorConfig_Test_001, TestSize.Level1)
788 {
789 CALL_TEST_DEBUG;
790 InputDeviceManager inputDevice;
791 int32_t deviceId = 1;
792 ASSERT_NO_FATAL_FAILURE(inputDevice.GetVendorConfig(deviceId));
793 }
794
795 /**
796 * @tc.name: OnEnableInputDevice_Test_001
797 * @tc.desc: Test the function OnEnableInputDevice
798 * @tc.type: FUNC
799 * @tc.require:
800 */
HWTEST_F(InputDeviceManagerTest, OnEnableInputDevice_Test_001, TestSize.Level1)801 HWTEST_F(InputDeviceManagerTest, OnEnableInputDevice_Test_001, TestSize.Level1)
802 {
803 CALL_TEST_DEBUG;
804 InputDeviceManager inputDevice;
805 bool enable = true;
806 int32_t ret = inputDevice.OnEnableInputDevice(enable);
807 EXPECT_EQ(ret, RET_OK);
808 enable = false;
809 ret = inputDevice.OnEnableInputDevice(enable);
810 EXPECT_EQ(ret, RET_OK);
811 }
812
813 /**
814 * @tc.name: InitSessionLostCallback_Test_001
815 * @tc.desc: Test the function InitSessionLostCallback
816 * @tc.type: FUNC
817 * @tc.require:
818 */
HWTEST_F(InputDeviceManagerTest, InitSessionLostCallback_Test_001, TestSize.Level1)819 HWTEST_F(InputDeviceManagerTest, InitSessionLostCallback_Test_001, TestSize.Level1)
820 {
821 CALL_TEST_DEBUG;
822 InputDeviceManager inputDevice;
823 ASSERT_NO_FATAL_FAILURE(inputDevice.InitSessionLostCallback());
824 }
825
826 /**
827 * @tc.name: InitSessionLostCallback_Test_002
828 * @tc.desc: Test the function InitSessionLostCallback
829 * @tc.type: FUNC
830 * @tc.require:
831 */
HWTEST_F(InputDeviceManagerTest, InitSessionLostCallback_Test_002, TestSize.Level1)832 HWTEST_F(InputDeviceManagerTest, InitSessionLostCallback_Test_002, TestSize.Level1)
833 {
834 CALL_TEST_DEBUG;
835 InputDeviceManager inputDevice;
836 inputDevice.sessionLostCallbackInitialized_ = true;
837 ASSERT_NO_FATAL_FAILURE(inputDevice.InitSessionLostCallback());
838 }
839
840 /**
841 * @tc.name: InitSessionLostCallback_Test_003
842 * @tc.desc: Test the function InitSessionLostCallback
843 * @tc.type: FUNC
844 * @tc.require:
845 */
HWTEST_F(InputDeviceManagerTest, InitSessionLostCallback_Test_003, TestSize.Level1)846 HWTEST_F(InputDeviceManagerTest, InitSessionLostCallback_Test_003, TestSize.Level1)
847 {
848 CALL_TEST_DEBUG;
849 InputDeviceManager inputDevice;
850 inputDevice.sessionLostCallbackInitialized_ = false;
851 ASSERT_NO_FATAL_FAILURE(inputDevice.InitSessionLostCallback());
852 EXPECT_FALSE(inputDevice.sessionLostCallbackInitialized_);
853 }
854
855 /**
856 * @tc.name: OnSessionLost_Test_001
857 * @tc.desc: Test the function OnSessionLost
858 * @tc.type: FUNC
859 * @tc.require:
860 */
HWTEST_F(InputDeviceManagerTest, OnSessionLost_Test_001, TestSize.Level1)861 HWTEST_F(InputDeviceManagerTest, OnSessionLost_Test_001, TestSize.Level1)
862 {
863 CALL_TEST_DEBUG;
864 InputDeviceManager inputDevice;
865 std::string programName = "program";
866 int32_t moduleType = 1;
867 int32_t fd = 2;
868 int32_t uid = 3;
869 int32_t pid = 4;
870 std::shared_ptr<MockUDSSession> session = std::make_shared<MockUDSSession>
871 (programName, moduleType, fd, uid, pid);
872 ASSERT_NE(session, nullptr);
873 ASSERT_NO_FATAL_FAILURE(inputDevice.OnSessionLost(session));
874 session = nullptr;
875 ASSERT_NO_FATAL_FAILURE(inputDevice.OnSessionLost(session));
876 }
877
878
879 /**
880 * @tc.name: NotifyMessage_Test_001
881 * @tc.desc: Test the function NotifyMessage
882 * @tc.type: FUNC
883 * @tc.require:
884 */
HWTEST_F(InputDeviceManagerTest, NotifyMessage_Test_001, TestSize.Level1)885 HWTEST_F(InputDeviceManagerTest, NotifyMessage_Test_001, TestSize.Level1)
886 {
887 CALL_TEST_DEBUG;
888 InputDeviceManager inputDevice;
889 std::string programName = "program";
890 int32_t moduleType = 1;
891 int32_t fd = 2;
892 int32_t uid = 3;
893 int32_t pid = 4;
894 std::shared_ptr<MockUDSSession> mockSession = std::make_shared<MockUDSSession>
895 (programName, moduleType, fd, uid, pid);
896 EXPECT_CALL(*mockSession, SendMsg(testing::_)).WillRepeatedly(testing::Return(true));
897 int32_t result = inputDevice.NotifyMessage(mockSession, 1, "type");
898 EXPECT_EQ(result, RET_OK);
899 }
900
901 /**
902 * @tc.name: NotifyMessage_Test_002
903 * @tc.desc: Test the function NotifyMessage
904 * @tc.type: FUNC
905 * @tc.require:
906 */
HWTEST_F(InputDeviceManagerTest, NotifyMessage_Test_002, TestSize.Level1)907 HWTEST_F(InputDeviceManagerTest, NotifyMessage_Test_002, TestSize.Level1)
908 {
909 CALL_TEST_DEBUG;
910 InputDeviceManager inputDevice;
911 std::string programName = "program";
912 int32_t moduleType = 1;
913 int32_t fd = 2;
914 int32_t uid = 3;
915 int32_t pid = 4;
916 std::shared_ptr<MockUDSSession> mockSession = std::make_shared<MockUDSSession>
917 (programName, moduleType, fd, uid, pid);
918 EXPECT_CALL(*mockSession, SendMsg(testing::_)).WillRepeatedly(testing::Return(false));
919 int32_t result = inputDevice.NotifyMessage(mockSession, 1, "type");
920 EXPECT_EQ(result, RET_OK);
921 }
922
923 /**
924 * @tc.name: NotifyMessage_Test_003
925 * @tc.desc: Test the function NotifyMessage
926 * @tc.type: FUNC
927 * @tc.require:
928 */
HWTEST_F(InputDeviceManagerTest, NotifyMessage_Test_003, TestSize.Level1)929 HWTEST_F(InputDeviceManagerTest, NotifyMessage_Test_003, TestSize.Level1)
930 {
931 CALL_TEST_DEBUG;
932 InputDeviceManager inputDevice;
933 std::string programName = "program";
934 int32_t moduleType = 1;
935 int32_t fd = 2;
936 int32_t uid = 3;
937 int32_t pid = 4;
938 std::shared_ptr<MockUDSSession> mockSession = std::make_shared<MockUDSSession>
939 (programName, moduleType, fd, uid, pid);
940 EXPECT_CALL(*mockSession, SendMsg(testing::_)).WillRepeatedly(testing::Return(false));
941 SessionPtr nullSession = nullptr;
942 int32_t result = inputDevice.NotifyMessage(nullSession, 1, "type");
943 EXPECT_NE(result, RET_OK);
944 }
945
946 /**
947 * @tc.name: GetInputDevice_Test_002
948 * @tc.desc: Test the function GetInputDevice
949 * @tc.type: FUNC
950 * @tc.require:
951 */
HWTEST_F(InputDeviceManagerTest, GetInputDevice_Test_002, TestSize.Level1)952 HWTEST_F(InputDeviceManagerTest, GetInputDevice_Test_002, TestSize.Level1)
953 {
954 CALL_TEST_DEBUG;
955 InputDeviceManager inputDevice;
956
957 int32_t id = -1;
958 bool checked = true;
959 std::shared_ptr inputDeviceManager = inputDevice.GetInputDevice(id, checked);
960 EXPECT_EQ(inputDeviceManager, nullptr);
961 id = 1;
962 checked = false;
963 inputDeviceManager = inputDevice.GetInputDevice(id, checked);
964 EXPECT_EQ(inputDeviceManager, nullptr);
965 id = -1;
966 checked = false;
967 inputDeviceManager = inputDevice.GetInputDevice(id, checked);
968 EXPECT_EQ(inputDeviceManager, nullptr);
969 }
970
971 /**
972 * @tc.name: GetInputDeviceIds_Test_002
973 * @tc.desc: Test the function GetInputDeviceIds
974 * @tc.type: FUNC
975 * @tc.require:
976 */
HWTEST_F(InputDeviceManagerTest, GetInputDeviceIds_Test_002, TestSize.Level1)977 HWTEST_F(InputDeviceManagerTest, GetInputDeviceIds_Test_002, TestSize.Level1)
978 {
979 CALL_TEST_DEBUG;
980 InputDeviceManager manager;
981 std::vector<int32_t> expectedIds = {1, 2, 3};
982 std::vector<int32_t> actualIds = manager.GetInputDeviceIds();
983 ASSERT_NE(expectedIds, actualIds);
984 }
985
986 /**
987 * @tc.name: SupportKeys_Test_002
988 * @tc.desc: Test the function SupportKeys
989 * @tc.type: FUNC
990 * @tc.require:
991 */
HWTEST_F(InputDeviceManagerTest, SupportKeys_Test_002, TestSize.Level1)992 HWTEST_F(InputDeviceManagerTest, SupportKeys_Test_002, TestSize.Level1)
993 {
994 CALL_TEST_DEBUG;
995 InputDeviceManager inputDevice;
996 int32_t deviceId = 1;
997 int32_t COMMON_PARAMETER_ERROR = 401;
998 std::vector<int32_t> keyCodes = {1, 2, 3};
999 std::vector<bool> keystrokes{true};
1000 int32_t ret = inputDevice.SupportKeys(deviceId, keyCodes, keystrokes);
1001 EXPECT_EQ(ret, COMMON_PARAMETER_ERROR);
1002 EXPECT_NE(keystrokes.size(), keyCodes.size());
1003 EXPECT_TRUE(keystrokes[0]);
1004 EXPECT_FALSE(keystrokes[1]);
1005 EXPECT_FALSE(keystrokes[2]);
1006 deviceId = -1;
1007 keyCodes = {1, 2, 3};
1008 ret = inputDevice.SupportKeys(deviceId, keyCodes, keystrokes);
1009 EXPECT_EQ(ret, COMMON_PARAMETER_ERROR);
1010 EXPECT_FALSE(keystrokes.empty());
1011 deviceId = 100;
1012 keyCodes = {1, 2, 3};
1013 ret = inputDevice.SupportKeys(deviceId, keyCodes, keystrokes);
1014 EXPECT_EQ(ret, COMMON_PARAMETER_ERROR);
1015 EXPECT_FALSE(keystrokes.empty());
1016 deviceId = 1;
1017 keyCodes.clear();
1018 keystrokes.clear();
1019 ret = inputDevice.SupportKeys(deviceId, keyCodes, keystrokes);
1020 EXPECT_EQ(ret, COMMON_PARAMETER_ERROR);
1021 EXPECT_TRUE(keystrokes.empty());
1022 }
1023
1024 /**
1025 * @tc.name: GetDeviceConfig_Test_002
1026 * @tc.desc: Test the function GetDeviceConfig
1027 * @tc.type: FUNC
1028 * @tc.require:
1029 */
HWTEST_F(InputDeviceManagerTest, GetDeviceConfig_Test_002, TestSize.Level1)1030 HWTEST_F(InputDeviceManagerTest, GetDeviceConfig_Test_002, TestSize.Level1)
1031 {
1032 CALL_TEST_DEBUG;
1033 InputDeviceManager inputDevice;
1034 int32_t deviceId = -1;
1035 int32_t keyboardType = 5;
1036 bool ret = inputDevice.GetDeviceConfig(deviceId, keyboardType);
1037 EXPECT_FALSE(ret);
1038 deviceId = 10;
1039 keyboardType = -3;
1040 ret = inputDevice.GetDeviceConfig(deviceId, keyboardType);
1041 EXPECT_FALSE(ret);
1042 deviceId = -8;
1043 keyboardType = -10;
1044 ret = inputDevice.GetDeviceConfig(deviceId, keyboardType);
1045 EXPECT_FALSE(ret);
1046 }
1047
1048 /**
1049 * @tc.name: GetKeyboardBusMode_Test_002
1050 * @tc.desc: Test the function GetKeyboardBusMode
1051 * @tc.type: FUNC
1052 * @tc.require:
1053 */
HWTEST_F(InputDeviceManagerTest, GetKeyboardBusMode_Test_002, TestSize.Level1)1054 HWTEST_F(InputDeviceManagerTest, GetKeyboardBusMode_Test_002, TestSize.Level1)
1055 {
1056 CALL_TEST_DEBUG;
1057 InputDeviceManager inputDevice;
1058 int32_t deviceId = 1;
1059 int32_t ret = inputDevice.GetKeyboardBusMode(deviceId);
1060 EXPECT_NE(ret, 0);
1061 deviceId = 0;
1062 ret = inputDevice.GetKeyboardBusMode(deviceId);
1063 EXPECT_NE(ret, 0);
1064 deviceId = -5;
1065 ret = inputDevice.GetKeyboardBusMode(deviceId);
1066 EXPECT_NE(ret, 0);
1067 EXPECT_TRUE(ret);
1068 }
1069
1070 /**
1071 * @tc.name: GetDeviceSupportKey_Test_002
1072 * @tc.desc: Test the function GetDeviceSupportKey
1073 * @tc.type: FUNC
1074 * @tc.require:
1075 */
HWTEST_F(InputDeviceManagerTest, GetDeviceSupportKey_Test_002, TestSize.Level1)1076 HWTEST_F(InputDeviceManagerTest, GetDeviceSupportKey_Test_002, TestSize.Level1)
1077 {
1078 CALL_TEST_DEBUG;
1079 InputDeviceManager inputDevice;
1080 int32_t deviceId = 1;
1081 int32_t keyboardType = -5;
1082 int32_t returnCode = 401;
1083 int32_t ret = inputDevice.GetDeviceSupportKey(deviceId, keyboardType);
1084 EXPECT_EQ(ret, returnCode);
1085 deviceId = -1;
1086 keyboardType = 2;
1087 ret = inputDevice.GetDeviceSupportKey(deviceId, keyboardType);
1088 EXPECT_EQ(ret, returnCode);
1089 deviceId = -1;
1090 keyboardType = -2;
1091 ret = inputDevice.GetDeviceSupportKey(deviceId, keyboardType);
1092 EXPECT_EQ(ret, returnCode);
1093 }
1094
1095 /**
1096 * @tc.name: GetKeyboardType_Test_002
1097 * @tc.desc: Test the function GetKeyboardType
1098 * @tc.type: FUNC
1099 * @tc.require:
1100 */
HWTEST_F(InputDeviceManagerTest, GetKeyboardType_Test_002, TestSize.Level1)1101 HWTEST_F(InputDeviceManagerTest, GetKeyboardType_Test_002, TestSize.Level1)
1102 {
1103 CALL_TEST_DEBUG;
1104 InputDeviceManager inputDevice;
1105 int32_t deviceId = 1;
1106 int32_t keyboardType = -100;
1107 int32_t returnCode = 401;
1108 int32_t ret = inputDevice.GetKeyboardType(deviceId, keyboardType);
1109 EXPECT_EQ(ret, returnCode);
1110 deviceId = -1;
1111 keyboardType = 1;
1112 ret = inputDevice.GetKeyboardType(deviceId, keyboardType);
1113 EXPECT_EQ(ret, returnCode);
1114 deviceId = -10;
1115 keyboardType = -5;
1116 ret = inputDevice.GetKeyboardType(deviceId, keyboardType);
1117 EXPECT_EQ(ret, returnCode);
1118 }
1119
1120 /**
1121 * @tc.name: SetInputStatusChangeCallback_Test_001
1122 * @tc.desc: Test the function SetInputStatusChangeCallback
1123 * @tc.type: FUNC
1124 * @tc.require:
1125 */
HWTEST_F(InputDeviceManagerTest, SetInputStatusChangeCallback_Test_001, TestSize.Level1)1126 HWTEST_F(InputDeviceManagerTest, SetInputStatusChangeCallback_Test_001, TestSize.Level1)
1127 {
1128 CALL_TEST_DEBUG;
1129 InputDeviceManager inputDevice;
1130 using InputDeviceCallback = std::function<void(int, std::string, std::string)>;
1131 InputDeviceCallback callback = [](int status, const std::string& deviceName, const std::string& deviceId) {
1132 };
1133 ASSERT_NO_FATAL_FAILURE(inputDevice.SetInputStatusChangeCallback(callback));
1134 }
1135
1136 /**
1137 * @tc.name: AddDevListener_Test_001
1138 * @tc.desc: Test the function AddDevListener
1139 * @tc.type: FUNC
1140 * @tc.require:
1141 */
HWTEST_F(InputDeviceManagerTest, AddDevListener_Test_001, TestSize.Level1)1142 HWTEST_F(InputDeviceManagerTest, AddDevListener_Test_001, TestSize.Level1)
1143 {
1144 CALL_TEST_DEBUG;
1145 InputDeviceManager inputDevice;
1146 SessionPtr session = std::shared_ptr<OHOS::MMI::UDSSession>();
1147 ASSERT_NO_FATAL_FAILURE(inputDevice.AddDevListener(session));
1148 }
1149
1150 /**
1151 * @tc.name: RemoveDevListener_Test_001
1152 * @tc.desc: Test the function RemoveDevListener
1153 * @tc.type: FUNC
1154 * @tc.require:
1155 */
HWTEST_F(InputDeviceManagerTest, RemoveDevListener_Test_001, TestSize.Level1)1156 HWTEST_F(InputDeviceManagerTest, RemoveDevListener_Test_001, TestSize.Level1)
1157 {
1158 CALL_TEST_DEBUG;
1159 InputDeviceManager inputDevice;
1160 SessionPtr session = std::shared_ptr<OHOS::MMI::UDSSession>();
1161 ASSERT_NO_FATAL_FAILURE(inputDevice.RemoveDevListener(session));
1162 }
1163
1164 /**
1165 * @tc.name: HasPointerDevice_Test_001
1166 * @tc.desc: Test the function HasPointerDevice
1167 * @tc.type: FUNC
1168 * @tc.require:
1169 */
HWTEST_F(InputDeviceManagerTest, HasPointerDevice_Test_001, TestSize.Level1)1170 HWTEST_F(InputDeviceManagerTest, HasPointerDevice_Test_001, TestSize.Level1)
1171 {
1172 CALL_TEST_DEBUG;
1173 InputDeviceManager inputDevice;
1174 bool ret = inputDevice.HasPointerDevice();
1175 EXPECT_FALSE(ret);
1176 ret = inputDevice.HasTouchDevice();
1177 EXPECT_FALSE(ret);
1178 }
1179
1180 /**
1181 * @tc.name: NotifyDevCallback_Test_001
1182 * @tc.desc: Test the function NotifyDevCallback
1183 * @tc.type: FUNC
1184 * @tc.require:
1185 */
HWTEST_F(InputDeviceManagerTest, NotifyDevCallback_Test_001, TestSize.Level1)1186 HWTEST_F(InputDeviceManagerTest, NotifyDevCallback_Test_001, TestSize.Level1)
1187 {
1188 CALL_TEST_DEBUG;
1189 InputDeviceManager inputDevice;
1190 int32_t deviceId = 1;
1191 InputDeviceManager::InputDeviceInfo inDevice;
1192 ASSERT_NO_FATAL_FAILURE(inputDevice.NotifyDevCallback(deviceId, inDevice));
1193 }
1194
1195 /**
1196 * @tc.name: OnInputDeviceAdded_Test_001
1197 * @tc.desc: Test the function OnInputDeviceAdded
1198 * @tc.type: FUNC
1199 * @tc.require:
1200 */
HWTEST_F(InputDeviceManagerTest, OnInputDeviceAdded_Test_001, TestSize.Level1)1201 HWTEST_F(InputDeviceManagerTest, OnInputDeviceAdded_Test_001, TestSize.Level1)
1202 {
1203 CALL_TEST_DEBUG;
1204 InputDeviceManager inputDevice;
1205 libinput_device* inputDevices = nullptr;
1206 ASSERT_NO_FATAL_FAILURE(inputDevice.OnInputDeviceAdded(inputDevices));
1207 }
1208
1209 /**
1210 * @tc.name: OnInputDeviceRemoved_Test_001
1211 * @tc.desc: Test the function OnInputDeviceRemoved
1212 * @tc.type: FUNC
1213 * @tc.require:
1214 */
HWTEST_F(InputDeviceManagerTest, OnInputDeviceRemoved_Test_001, TestSize.Level1)1215 HWTEST_F(InputDeviceManagerTest, OnInputDeviceRemoved_Test_001, TestSize.Level1)
1216 {
1217 CALL_TEST_DEBUG;
1218 InputDeviceManager inputDevice;
1219 libinput_device* inputDevices = nullptr;
1220 ASSERT_NO_FATAL_FAILURE(inputDevice.OnInputDeviceRemoved(inputDevices));
1221 }
1222
1223 /**
1224 * @tc.name: InputDeviceManagerTest_IsRemote
1225 * @tc.desc: Test Cover the else branch of if (device != inputDevice_.end())
1226 * @tc.type: FUNC
1227 * @tc.require:
1228 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_IsRemote, TestSize.Level1)1229 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_IsRemote, TestSize.Level1)
1230 {
1231 CALL_TEST_DEBUG;
1232 InputDeviceManager inputDevice;
1233 int32_t id = 30;
1234 ASSERT_FALSE(inputDevice.IsRemote(id));
1235 }
1236
1237 /**
1238 * @tc.name: InputDeviceManagerTest_IsRemote_001
1239 * @tc.desc: Test Cover the if (device != inputDevice_.end()) branch
1240 * @tc.type: FUNC
1241 * @tc.require:
1242 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_IsRemote_001, TestSize.Level1)1243 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_IsRemote_001, TestSize.Level1)
1244 {
1245 CALL_TEST_DEBUG;
1246 InputDeviceManager inputDevice;
1247 InputDeviceManager::InputDeviceInfo inputDeviceInfo;
1248 int32_t id = 30;
1249 inputDeviceInfo.isRemote = true;
1250 inputDevice.inputDevice_.insert(std::make_pair(id, inputDeviceInfo));
1251 ASSERT_TRUE(inputDevice.IsRemote(id));
1252 }
1253
1254 /**
1255 * @tc.name: InputDeviceManagerTest_NotifyDevCallback
1256 * @tc.desc: Test Cover the if (!inDevice.isTouchableDevice || (deviceId < 0)) branch
1257 * @tc.type: FUNC
1258 * @tc.require:
1259 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_NotifyDevCallback, TestSize.Level1)1260 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_NotifyDevCallback, TestSize.Level1)
1261 {
1262 CALL_TEST_DEBUG;
1263 InputDeviceManager inputDevice;
1264 InputDeviceManager::InputDeviceInfo inDevice;
1265 int32_t deviceid = -1;
1266 inDevice.isTouchableDevice = false;
1267 ASSERT_NO_FATAL_FAILURE(inputDevice.NotifyDevCallback(deviceid, inDevice));
1268 inDevice.isTouchableDevice = true;
1269 ASSERT_NO_FATAL_FAILURE(inputDevice.NotifyDevCallback(deviceid, inDevice));
1270 }
1271
1272 /**
1273 * @tc.name: InputDeviceManagerTest_NotifyDevCallback_001
1274 * @tc.desc: Test Cover the if (!inDevice.sysUid.empty()) branch
1275 * @tc.type: FUNC
1276 * @tc.require:
1277 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_NotifyDevCallback_001, TestSize.Level1)1278 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_NotifyDevCallback_001, TestSize.Level1)
1279 {
1280 CALL_TEST_DEBUG;
1281 InputDeviceManager inputDevice;
1282 InputDeviceManager::InputDeviceInfo inDevice;
1283 int32_t deviceid = 1;
1284 inDevice.isTouchableDevice = true;
1285 inDevice.sysUid = "123456";
1286 using inputDeviceCallback = std::function<void(int32_t deviceId, std::string devName, std::string devStatus)>;
1287 inputDeviceCallback callback = [](int32_t deviceId, std::string devName, std::string devStatus) {};
1288 inputDevice.SetInputStatusChangeCallback(callback);
1289 ASSERT_NO_FATAL_FAILURE(inputDevice.NotifyDevCallback(deviceid, inDevice));
1290 inDevice.sysUid.clear();
1291 ASSERT_NO_FATAL_FAILURE(inputDevice.NotifyDevCallback(deviceid, inDevice));
1292 }
1293
1294 /**
1295 * @tc.name: InputDeviceManagerTest_ScanPointerDevice
1296 * @tc.desc: Test Cover the if (it->second.isPointerDevice && it->second.enable) branch
1297 * @tc.type: FUNC
1298 * @tc.require:
1299 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_ScanPointerDevice, TestSize.Level1)1300 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_ScanPointerDevice, TestSize.Level1)
1301 {
1302 CALL_TEST_DEBUG;
1303 InputDeviceManager inputDevice;
1304 InputDeviceManager::InputDeviceInfo inDevice;
1305 int32_t deviceId = 10;
1306 inDevice.isPointerDevice = false;
1307 inDevice.enable = false;
1308 inputDevice.inputDevice_.insert(std::make_pair(deviceId, inDevice));
1309 deviceId = 15;
1310 inDevice.isPointerDevice = true;
1311 inDevice.enable = true;
1312 inputDevice.inputDevice_.insert(std::make_pair(deviceId, inDevice));
1313 ASSERT_NO_FATAL_FAILURE(inputDevice.ScanPointerDevice());
1314 }
1315
1316 /**
1317 * @tc.name: InputDeviceManagerTest_ScanPointerDevice_001
1318 * @tc.desc: Test Cover the if (!hasPointerDevice) branch
1319 * @tc.type: FUNC
1320 * @tc.require:
1321 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_ScanPointerDevice_001, TestSize.Level1)1322 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_ScanPointerDevice_001, TestSize.Level1)
1323 {
1324 CALL_TEST_DEBUG;
1325 InputDeviceManager inputDevice;
1326 InputDeviceManager::InputDeviceInfo inDevice;
1327 int32_t deviceId = 10;
1328 inDevice.isPointerDevice = false;
1329 inDevice.enable = false;
1330 inputDevice.inputDevice_.insert(std::make_pair(deviceId, inDevice));
1331 ASSERT_NO_FATAL_FAILURE(inputDevice.ScanPointerDevice());
1332 }
1333
1334 /**
1335 * @tc.name: InputDeviceManagerTest_OnEnableInputDevice
1336 * @tc.desc: Test Cover the if (enable) and if (keyboardType != KEYBOARD_TYPE_ALPHABETICKEYBOARD) and
1337 * <br> if (item.second.isPointerDevice && item.second.enable) branch
1338 * @tc.type: FUNC
1339 * @tc.require:
1340 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_OnEnableInputDevice, TestSize.Level1)1341 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_OnEnableInputDevice, TestSize.Level1)
1342 {
1343 CALL_TEST_DEBUG;
1344 InputDeviceManager::InputDeviceInfo inDevice;
1345 DeviceConfig deviceConfig;
1346 deviceConfig.keyboardType = KEYBOARD_TYPE_NONE;
1347 bool enable = true;
1348 int32_t deviceId = 10;
1349 inDevice.isRemote = true;
1350 inDevice.enable = false;
1351 inDevice.isPointerDevice = true;
1352 INPUT_DEV_MGR->inputDevice_.insert(std::make_pair(deviceId, inDevice));
1353 KeyRepeat->deviceConfig_.insert(std::make_pair(deviceId, deviceConfig));
1354 ASSERT_EQ(INPUT_DEV_MGR->OnEnableInputDevice(enable), RET_OK);
1355 INPUT_DEV_MGR->inputDevice_.clear();
1356 KeyRepeat->deviceConfig_.clear();
1357 }
1358
1359 /**
1360 * @tc.name: InputDeviceManagerTest_OnEnableInputDevice_001
1361 * @tc.desc: Test Cover the else branch of the OnEnableInputDevice function
1362 * @tc.type: FUNC
1363 * @tc.require:
1364 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_OnEnableInputDevice_001, TestSize.Level1)1365 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_OnEnableInputDevice_001, TestSize.Level1)
1366 {
1367 CALL_TEST_DEBUG;
1368 InputDeviceManager::InputDeviceInfo inDevice;
1369 DeviceConfig deviceConfig;
1370 deviceConfig.keyboardType = KEYBOARD_TYPE_ALPHABETICKEYBOARD;
1371 bool enable = false;
1372 int32_t deviceId = 20;
1373 inDevice.isRemote = true;
1374 inDevice.enable = true;
1375 inDevice.isPointerDevice = false;
1376 INPUT_DEV_MGR->inputDevice_.insert(std::make_pair(deviceId, inDevice));
1377 KeyRepeat->deviceConfig_.insert(std::make_pair(deviceId, deviceConfig));
1378 deviceId = 30;
1379 inDevice.isRemote = false;
1380 inDevice.enable = false;
1381 INPUT_DEV_MGR->inputDevice_.insert(std::make_pair(deviceId, inDevice));
1382 ASSERT_EQ(INPUT_DEV_MGR->OnEnableInputDevice(enable), RET_OK);
1383 INPUT_DEV_MGR->inputDevice_.clear();
1384 KeyRepeat->deviceConfig_.clear();
1385 }
1386
1387 /**
1388 * @tc.name: InputDeviceManagerTest_GetTouchPadIds_001
1389 * @tc.desc: Test GetTouchPadIds
1390 * @tc.type: FUNC
1391 * @tc.require:
1392 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetTouchPadIds_001, TestSize.Level1)1393 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetTouchPadIds_001, TestSize.Level1)
1394 {
1395 CALL_TEST_DEBUG;
1396 InputDeviceManager inputDevice;
1397 InputDeviceManager::InputDeviceInfo inDevice;
1398 int32_t deviceId = 5;
1399 inDevice.isPointerDevice = false;
1400 inDevice.enable = false;
1401 inDevice.dhid = 2;
1402 inputDevice.inputDevice_.insert(std::make_pair(deviceId, inDevice));
1403 ASSERT_NO_FATAL_FAILURE(INPUT_DEV_MGR->GetTouchPadIds());
1404 }
1405
1406 /**
1407 * @tc.name: InputDeviceManagerTest_GetTouchPadIds_002
1408 * @tc.desc: Test GetTouchPadIds
1409 * @tc.type: FUNC
1410 * @tc.require:
1411 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetTouchPadIds_002, TestSize.Level1)1412 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetTouchPadIds_002, TestSize.Level1)
1413 {
1414 CALL_TEST_DEBUG;
1415 InputDeviceManager inputDevice;
1416 InputDeviceManager::InputDeviceInfo inDevice;
1417 int32_t deviceId = 3;
1418 inDevice.enable = false;
1419 inDevice.dhid = 2;
1420 inputDevice.inputDevice_.insert(std::make_pair(deviceId, inDevice));
1421 inputDevice.inputDevice_.clear();
1422 ASSERT_NO_FATAL_FAILURE(INPUT_DEV_MGR->GetTouchPadIds());
1423 }
1424
1425 /**
1426 * @tc.name: InputDeviceManagerTest_IsMatchKeys_001
1427 * @tc.desc: Test IsMatchKeys
1428 * @tc.type: FUNC
1429 * @tc.require:
1430 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_IsMatchKeys_001, TestSize.Level1)1431 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_IsMatchKeys_001, TestSize.Level1)
1432 {
1433 CALL_TEST_DEBUG;
1434 struct libinput_device *device = nullptr;
1435 std::vector<int32_t> keyCodes;
1436 keyCodes.push_back(KeyEvent::KEYCODE_T);
1437 keyCodes.push_back(KeyEvent::KEYCODE_NUMPAD_1);
1438
1439 bool ret1 = INPUT_DEV_MGR->IsMatchKeys(device, keyCodes);
1440 EXPECT_FALSE(ret1);
1441 }
1442
1443 /**
1444 * @tc.name: InputDeviceManagerTest_OnInputDeviceAdded_Test_01
1445 * @tc.desc: Test the function OnInputDeviceAdded
1446 * @tc.type: FUNC
1447 * @tc.require:
1448 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_OnInputDeviceAdded_Test_01, TestSize.Level1)1449 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_OnInputDeviceAdded_Test_01, TestSize.Level1)
1450 {
1451 CALL_TEST_DEBUG;
1452 InputDeviceManager deviceMgr;
1453 int32_t deviceId = 3;
1454 struct libinput_device *inputDevice = nullptr;
1455
1456 InputDeviceManager::InputDeviceInfo deviceInfo;
1457 deviceInfo.inputDeviceOrigin = nullptr;
1458 deviceMgr.inputDevice_.insert(std::make_pair(deviceId, deviceInfo));
1459 EXPECT_TRUE(deviceInfo.inputDeviceOrigin == inputDevice);
1460 ASSERT_NO_FATAL_FAILURE(deviceMgr.OnInputDeviceAdded(inputDevice));
1461 }
1462
1463 /**
1464 * @tc.name: InputDeviceManagerTest_OnInputDeviceAdded_Test_02
1465 * @tc.desc: Test the function OnInputDeviceAdded
1466 * @tc.type: FUNC
1467 * @tc.require:
1468 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_OnInputDeviceAdded_Test_02, TestSize.Level1)1469 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_OnInputDeviceAdded_Test_02, TestSize.Level1)
1470 {
1471 CALL_TEST_DEBUG;
1472 InputDeviceManager deviceMgr;
1473 int32_t deviceId = 3;
1474 struct libinput_device *inputDevice = nullptr;
1475
1476 InputDeviceManager::InputDeviceInfo deviceInfo;
1477 deviceInfo.isRemote = false;
1478 deviceInfo.isPointerDevice = true;
1479 deviceInfo.enable = true;
1480 deviceMgr.inputDevice_.insert(std::make_pair(deviceId, deviceInfo));
1481 ASSERT_NO_FATAL_FAILURE(deviceMgr.OnInputDeviceAdded(inputDevice));
1482 }
1483
1484 /**
1485 * @tc.name: OnInputDeviceRemoved_Test_01
1486 * @tc.desc: Test the function OnInputDeviceRemoved
1487 * @tc.type: FUNC
1488 * @tc.require:
1489 */
HWTEST_F(InputDeviceManagerTest, OnInputDeviceRemoved_Test_01, TestSize.Level1)1490 HWTEST_F(InputDeviceManagerTest, OnInputDeviceRemoved_Test_01, TestSize.Level1)
1491 {
1492 CALL_TEST_DEBUG;
1493 InputDeviceManager deviceMgr;
1494 int32_t deviceId = 5;
1495 struct libinput_device *inputDevice = nullptr;
1496
1497 InputDeviceManager::InputDeviceInfo deviceInfo;
1498 deviceInfo.inputDeviceOrigin = nullptr;
1499 deviceMgr.inputDevice_.insert(std::make_pair(deviceId, deviceInfo));
1500 EXPECT_TRUE(deviceInfo.inputDeviceOrigin == inputDevice);
1501 ASSERT_NO_FATAL_FAILURE(deviceMgr.OnInputDeviceRemoved(inputDevice));
1502 }
1503
1504 /**
1505 * @tc.name: OnInputDeviceRemoved_Test_02
1506 * @tc.desc: Test the function OnInputDeviceRemoved
1507 * @tc.type: FUNC
1508 * @tc.require:
1509 */
HWTEST_F(InputDeviceManagerTest, OnInputDeviceRemoved_Test_02, TestSize.Level1)1510 HWTEST_F(InputDeviceManagerTest, OnInputDeviceRemoved_Test_02, TestSize.Level1)
1511 {
1512 CALL_TEST_DEBUG;
1513 InputDeviceManager deviceMgr;
1514 int32_t deviceId = 5;
1515 struct libinput_device *inputDevice = nullptr;
1516
1517 InputDeviceManager::InputDeviceInfo deviceInfo;
1518 deviceInfo.isRemote = false;
1519 deviceInfo.isPointerDevice = true;
1520 deviceMgr.inputDevice_.insert(std::make_pair(deviceId, deviceInfo));
1521
1522 std::string sysUid;
1523 EXPECT_TRUE(sysUid.empty());
1524 ASSERT_NO_FATAL_FAILURE(deviceMgr.OnInputDeviceRemoved(inputDevice));
1525 }
1526
1527 /**
1528 * @tc.name: InputDeviceManagerTest_GetKeyboardDevice_Test_01
1529 * @tc.desc: Test the function GetKeyboardDevice
1530 * @tc.type: FUNC
1531 * @tc.require:
1532 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetKeyboardDevice_Test_01, TestSize.Level1)1533 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetKeyboardDevice_Test_01, TestSize.Level1)
1534 {
1535 CALL_TEST_DEBUG;
1536 InputDeviceManager deviceMgr;
1537 struct libinput_device *device = nullptr;
1538 std::vector<int32_t> keyCodes;
1539 keyCodes.push_back(KeyEvent::KEYCODE_Q);
1540 keyCodes.push_back(KeyEvent::KEYCODE_NUMPAD_1);
1541
1542 bool ret1 = INPUT_DEV_MGR->IsMatchKeys(device, keyCodes);
1543 EXPECT_FALSE(ret1);
1544 auto ret2 = deviceMgr.GetKeyboardDevice();
1545 EXPECT_EQ(ret2, nullptr);
1546 }
1547
1548 /**
1549 * @tc.name: InputDeviceManagerTest_GetKeyboardDevice_Test_02
1550 * @tc.desc: Test the function GetKeyboardDevice
1551 * @tc.type: FUNC
1552 * @tc.require:
1553 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetKeyboardDevice_Test_02, TestSize.Level1)1554 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetKeyboardDevice_Test_02, TestSize.Level1)
1555 {
1556 CALL_TEST_DEBUG;
1557 InputDeviceManager deviceMgr;
1558 struct libinput_device *device = nullptr;
1559 std::vector<int32_t> keyCodes;
1560 keyCodes.push_back(KeyEvent::KEYCODE_Q);
1561 keyCodes.push_back(KeyEvent::KEYCODE_NUMPAD_1);
1562 INPUT_DEV_MGR->inputDevice_.clear();
1563 bool ret1 = INPUT_DEV_MGR->IsMatchKeys(device, keyCodes);
1564 EXPECT_FALSE(ret1);
1565 auto ret2 = deviceMgr.GetKeyboardDevice();
1566 EXPECT_EQ(ret2, nullptr);
1567 }
1568
1569 /**
1570 * @tc.name: InputDeviceManagerTest_GetDeviceSupportKey_Test_01
1571 * @tc.desc: Test the function GetDeviceSupportKey
1572 * @tc.type: FUNC
1573 * @tc.require:
1574 */
HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetDeviceSupportKey_Test_01, TestSize.Level1)1575 HWTEST_F(InputDeviceManagerTest, InputDeviceManagerTest_GetDeviceSupportKey_Test_01, TestSize.Level1)
1576 {
1577 CALL_TEST_DEBUG;
1578 std::vector<int32_t> keyCodes;
1579 int32_t deviceId = 1;
1580 int32_t keyboardType = KEYBOARD_TYPE_REMOTECONTROL;
1581 std::vector<bool> supportKey;
1582 int32_t returnCode1 = 401;
1583
1584 InputDeviceManager inputDevice;
1585 keyCodes.push_back(KeyEvent::KEYCODE_Q);
1586 keyCodes.push_back(KeyEvent::KEYCODE_HOME);
1587 keyCodes.push_back(KeyEvent::KEYCODE_CTRL_LEFT);
1588 keyCodes.push_back(KeyEvent::KEYCODE_F2);
1589
1590 int32_t ret = INPUT_DEV_MGR->SupportKeys(deviceId, keyCodes, supportKey);
1591 EXPECT_NE(ret, RET_OK);
1592 int32_t ret2 = inputDevice.GetDeviceSupportKey(deviceId, keyboardType);
1593 EXPECT_EQ(ret2, returnCode1);
1594 }
1595 } // namespace MMI
1596 } // namespace OHOS
1597