1 /*
2 * Copyright (c) 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 "gtest/gtest.h"
17
18 #include <filesystem>
19 #include <fstream>
20 #include <iostream>
21
22 #include "input_display_bind_helper.h"
23 #include "mmi_log.h"
24
25 #undef MMI_LOG_TAG
26 #define MMI_LOG_TAG "InputDisplayBindHelperTest"
27
28 namespace OHOS {
29 namespace MMI {
30 namespace {
31 using namespace testing::ext;
32 const std::string INPUT_NODE_PATH = "/data/input0_test";
33 const std::string INPUT_DEVICE_NAME_FILE = "/data/input0_test/name";
34 const std::string INPUT_DEVICE_NAME_CONFIG = "/data/input_device_name.cfg";
35 const std::string DISPLAY_MAPPING = "0<=>wrapper";
36 const std::string INPUT_NODE_NAME = "wrapper";
37 } // namespace
38 namespace fs = std::filesystem;
39 class InputDisplayBindHelperTest : public testing::Test {
40 public:
SetUpTestCase(void)41 static void SetUpTestCase(void) {}
TearDownTestCase(void)42 static void TearDownTestCase(void) {}
43 static bool WriteConfigFile(const std::string &content);
44 static bool InitInputNode();
45 static bool InitConfigFile();
46 static inline const std::string bindCfgFile_ = "input_display_bind_helper.cfg";
GetCfgFileName()47 static std::string GetCfgFileName()
48 {
49 return bindCfgFile_;
50 }
51 };
52
WriteConfigFile(const std::string & content)53 bool InputDisplayBindHelperTest::WriteConfigFile(const std::string &content)
54 {
55 const std::string &fileName = InputDisplayBindHelperTest::bindCfgFile_;
56 std::ofstream ofs(fileName.c_str());
57 if (!ofs) {
58 MMI_HILOGE("Open file fail.%s\n", fileName.c_str());
59 return false;
60 }
61 ofs << content;
62 ofs.close();
63 return true;
64 }
65
InitInputNode()66 bool InputDisplayBindHelperTest::InitInputNode()
67 {
68 if (fs::exists(INPUT_NODE_PATH) && fs::is_directory(INPUT_NODE_PATH)) {
69 if (fs::remove_all(INPUT_NODE_PATH) == 0) {
70 MMI_HILOGI("Clear success, path:%{private}s", INPUT_NODE_PATH.c_str());
71 } else {
72 MMI_HILOGE("Clear fail, path:%{private}s", INPUT_NODE_PATH.c_str());
73 }
74 }
75 if (fs::create_directory(INPUT_NODE_PATH)) {
76 MMI_HILOGI("Create success, path:%{private}s", INPUT_NODE_PATH.c_str());
77 } else {
78 MMI_HILOGE("Create fail, path:%{private}s", INPUT_NODE_PATH.c_str());
79 return false;
80 }
81 std::ofstream file(INPUT_DEVICE_NAME_FILE);
82 if (!file.is_open()) {
83 MMI_HILOGE("Write fail, path:%{private}s", INPUT_DEVICE_NAME_FILE.c_str());
84 return false;
85 }
86 file << INPUT_NODE_NAME;
87 file.close();
88 MMI_HILOGI("Write success, path:%{private}s", INPUT_DEVICE_NAME_FILE.c_str());
89 return true;
90 }
91
InitConfigFile()92 bool InputDisplayBindHelperTest::InitConfigFile()
93 {
94 if (fs::exists(INPUT_DEVICE_NAME_CONFIG)) {
95 if (std::remove(INPUT_DEVICE_NAME_CONFIG.c_str()) == 0) {
96 MMI_HILOGI("Clear success, path:%{private}s", INPUT_DEVICE_NAME_CONFIG.c_str());
97 } else {
98 MMI_HILOGE("Clear fail, path:%{private}s", INPUT_DEVICE_NAME_CONFIG.c_str());
99 return false;
100 }
101 }
102 std::ofstream file(INPUT_DEVICE_NAME_CONFIG);
103 if (!file.is_open()) {
104 MMI_HILOGE("Write fail, path:%{private}s", INPUT_DEVICE_NAME_CONFIG.c_str());
105 return false;
106 }
107 file << DISPLAY_MAPPING;
108 file.close();
109 MMI_HILOGI("Write success, path:%{private}s", INPUT_DEVICE_NAME_CONFIG.c_str());
110 return true;
111 }
112
113 /**
114 * @tc.name: InputDisplayBindHelperTest_001
115 * @tc.desc: No bind info in disk
116 * @tc.type: FUNC
117 * @tc.require:
118 */
119 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_001, TestSize.Level1)
120 {
121 CALL_TEST_DEBUG;
122 InputDisplayBindHelperTest::WriteConfigFile("");
123 InputDisplayBindHelper bindInfo(InputDisplayBindHelperTest::GetCfgFileName());
124 // 多模初始化
125 bindInfo.Load();
126 // 检测到触摸板设备
127 bindInfo.AddInputDevice(1, "mouse", "mouse");
128 bindInfo.AddInputDevice(2, "keyboard", "keyboard");
129 // 窗口同步信息
130 bindInfo.AddDisplay(0, "hp 223");
131 bindInfo.AddDisplay(2, "think 123");
132 ASSERT_EQ(bindInfo.Dumps(), std::string("mouse<=>hp 223\nkeyboard<=>think 123\n"));
133 }
134
135 /**
136 * @tc.name: InputDisplayBindHelperTest_002
137 * @tc.desc: Has info with adding order in disk
138 * @tc.type: FUNC
139 * @tc.require:
140 */
141 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_002, TestSize.Level1)
142 {
143 CALL_TEST_DEBUG;
144 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
145 InputDisplayBindHelper bindInfo(InputDisplayBindHelperTest::GetCfgFileName());
146 // 多模初始化
147 bindInfo.Load();
148 // 检测到触摸板设备
149 bindInfo.AddInputDevice(1, "mouse", "mouse");
150 bindInfo.AddInputDevice(2, "keyboard", "keyboard");
151 // 窗口同步信息
152 bindInfo.AddDisplay(0, "hp 223");
153 bindInfo.AddDisplay(2, "think 123");
154 ASSERT_EQ(bindInfo.Dumps(), std::string("mouse<=>hp 223\nkeyboard<=>think 123\n"));
155 }
156
157 /**
158 * @tc.name: InputDisplayBindHelperTest_003
159 * @tc.desc: Has info without adding order in disk
160 * @tc.type: FUNC
161 * @tc.require:
162 */
163 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_003, TestSize.Level1)
164 {
165 CALL_TEST_DEBUG;
166 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>think 123\nkeyboard<=>hp 223\n");
167 InputDisplayBindHelper bindInfo(InputDisplayBindHelperTest::GetCfgFileName());
168 // 多模初始化
169 bindInfo.Load();
170 // 检测到触摸板设备
171 bindInfo.AddInputDevice(1, "mouse", "mouse");
172 bindInfo.AddInputDevice(2, "keyboard", "keyboard");
173 // 窗口同步信息
174 bindInfo.AddDisplay(0, "think 123");
175 bindInfo.AddDisplay(2, "hp 223");
176 ASSERT_EQ(bindInfo.Dumps(), std::string("mouse<=>think 123\nkeyboard<=>hp 223\n"));
177 }
178
179 /**
180 * @tc.name: InputDisplayBindHelperTest_004
181 * @tc.desc: Bind and remove test
182 * @tc.type: FUNC
183 * @tc.require:
184 */
185 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_004, TestSize.Level1)
186 {
187 CALL_TEST_DEBUG;
188 InputDisplayBindHelperTest::WriteConfigFile("");
189 InputDisplayBindHelper bindInfo(InputDisplayBindHelperTest::GetCfgFileName());
190 // 多模初始化
191 bindInfo.Load();
192 // 检测到触摸板设备
193 bindInfo.AddInputDevice(1, "mouse", "mouse");
194 bindInfo.AddInputDevice(2, "keyboard", "keyboard");
195 // 窗口同步信息
196 bindInfo.AddDisplay(0, "hp 223");
197 bindInfo.AddDisplay(2, "think 123");
198 // 显示屏移除
199 bindInfo.RemoveDisplay(2);
200 bindInfo.RemoveDisplay(0);
201 // 输入设备移除
202 bindInfo.RemoveInputDevice(1);
203 bindInfo.RemoveInputDevice(2);
204 bindInfo.RemoveInputDevice(3);
205 // 窗口同步信息
206 bindInfo.AddDisplay(0, "hp 223");
207 bindInfo.AddDisplay(2, "think 123");
208 // 检测到触摸板设备
209 bindInfo.AddInputDevice(1, "mouse", "mouse");
210 bindInfo.AddInputDevice(2, "keyboard", "keyboard");
211 bindInfo.AddInputDevice(3, "keyboard88", "keyboard88");
212
213 bindInfo.Store();
214 bindInfo.Load();
215 bindInfo.Dumps();
216 // 输入设备移除
217 bindInfo.RemoveInputDevice(1);
218 bindInfo.RemoveInputDevice(2);
219 // 触摸板设备移除
220 bindInfo.RemoveDisplay(2);
221 bindInfo.RemoveDisplay(0);
222 ASSERT_EQ(bindInfo.Dumps(), std::string(""));
223 }
224
225 /**
226 * @tc.name: InputDisplayBindHelperTest_005
227 * @tc.desc: Test GetBindDisplayNameByInputDevice
228 * @tc.type: FUNC
229 * @tc.require:
230 */
231 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetBindDisplayNameByInputDevice_005, TestSize.Level1)
232 {
233 CALL_TEST_DEBUG;
234 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>think 123\nkeyboard<=>hp 223\n");
235 InputDisplayBindHelper bindInfo(InputDisplayBindHelperTest::GetCfgFileName());
236 // 多模初始化
237 bindInfo.Load();
238 // 检测到触摸板设备
239 bindInfo.AddInputDevice(1, "mouse", "mouse");
240 bindInfo.AddInputDevice(2, "keyboard", "keyboard");
241 // 窗口同步信息
242 bindInfo.AddDisplay(0, "think 123");
243 bindInfo.AddDisplay(2, "hp 223");
244 ASSERT_EQ(bindInfo.Dumps(), std::string("mouse<=>think 123\nkeyboard<=>hp 223\n"));
245 // 获取
246 ASSERT_EQ(bindInfo.GetBindDisplayNameByInputDevice(1), std::string("think 123"));
247 ASSERT_EQ(bindInfo.GetBindDisplayNameByInputDevice(2), std::string("hp 223"));
248 ASSERT_EQ(bindInfo.GetBindDisplayNameByInputDevice(3), std::string());
249 // 删除display
250 bindInfo.RemoveDisplay(0);
251 ASSERT_EQ(bindInfo.GetBindDisplayNameByInputDevice(1), std::string());
252 ASSERT_EQ(bindInfo.GetBindDisplayNameByInputDevice(2), std::string("hp 223"));
253 bindInfo.RemoveDisplay(2);
254 ASSERT_EQ(bindInfo.GetBindDisplayNameByInputDevice(1), std::string());
255 ASSERT_EQ(bindInfo.GetBindDisplayNameByInputDevice(2), std::string());
256 }
257
258 /**
259 * @tc.name: InputDisplayBindHelperTest_IsDisplayAdd_006
260 * @tc.desc: Test GetBindDisplayNameByInputDevice
261 * @tc.type: FUNC
262 * @tc.require:
263 */
264 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_IsDisplayAdd_006, TestSize.Level1)
265 {
266 CALL_TEST_DEBUG;
267 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>think 123\nkeyboard<=>hp 223\n");
268 InputDisplayBindHelper bindInfo(InputDisplayBindHelperTest::GetCfgFileName());
269 // 多模初始化
270 bindInfo.Load();
271 ASSERT_FALSE(bindInfo.IsDisplayAdd(0, "hp 223"));
272 ASSERT_FALSE(bindInfo.IsDisplayAdd(2, "think 123"));
273 ASSERT_FALSE(bindInfo.IsDisplayAdd(1, "think 123"));
274 ASSERT_EQ(bindInfo.Dumps(), std::string());
275 // 检测到触摸板设备
276 bindInfo.AddInputDevice(1, "mouse", "mouse");
277 bindInfo.AddInputDevice(2, "keyboard", "keyboard");
278 // 窗口同步信息
279 bindInfo.AddDisplay(0, "think 123");
280 bindInfo.AddDisplay(2, "hp 223");
281 ASSERT_TRUE(bindInfo.IsDisplayAdd(0, "think 123"));
282 ASSERT_TRUE(bindInfo.IsDisplayAdd(2, "hp 223"));
283 ASSERT_FALSE(bindInfo.IsDisplayAdd(1, "think 123"));
284
285 ASSERT_EQ(bindInfo.Dumps(), std::string("mouse<=>think 123\nkeyboard<=>hp 223\n"));
286 }
287
288 /**
289 * @tc.name: InputDisplayBindHelperTest_GetDisplayIdNames_007
290 * @tc.desc: Test GetBindDisplayNameByInputDevice
291 * @tc.type: FUNC
292 * @tc.require:
293 */
294 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetDisplayIdNames_007, TestSize.Level1)
295 {
296 CALL_TEST_DEBUG;
297 using IdNames = std::set<std::pair<uint64_t, std::string>>;
298 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>think 123\nkeyboard<=>hp 223\n");
299 InputDisplayBindHelper bindInfo(InputDisplayBindHelperTest::GetCfgFileName());
300 // 多模初始化
301 bindInfo.Load();
302 IdNames idNames;
303 ASSERT_EQ(bindInfo.GetDisplayIdNames(), idNames);
304 bindInfo.AddDisplay(2, "hp 223");
305 idNames.insert(std::make_pair(2, "hp 223"));
306 ASSERT_EQ(bindInfo.GetDisplayIdNames(), idNames);
307
308 // 检测到触摸板设备
309 bindInfo.AddInputDevice(1, "mouse", "mouse");
310 bindInfo.AddInputDevice(2, "keyboard", "keyboard");
311
312 // 窗口同步信息
313 bindInfo.AddDisplay(0, "think 123");
314 idNames.insert(std::make_pair(0, "think 123"));
315 ASSERT_EQ(bindInfo.GetDisplayIdNames(), idNames);
316 bindInfo.AddDisplay(2, "hp 223");
317 idNames.insert(std::make_pair(2, "hp 223"));
318 ASSERT_EQ(bindInfo.GetDisplayIdNames(), idNames);
319 ASSERT_EQ(bindInfo.Dumps(), std::string("mouse<=>think 123\nkeyboard<=>hp 223\n"));
320 }
321
322 /**
323 * @tc.name: InputDisplayBindHelperTest_GetInputDeviceById_008
324 * @tc.desc: Test GetInputDeviceById
325 * @tc.type: FUNC
326 * @tc.require:
327 */
328 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetInputDeviceById_008, TestSize.Level1)
329 {
330 CALL_TEST_DEBUG;
331 InputDisplayBindHelper idh("/data/service/el1/public/multimodalinput/0.txt");
332 if (!(InputDisplayBindHelperTest::InitInputNode())) {
333 return;
334 }
335 if (!(InputDisplayBindHelperTest::InitConfigFile())) {
336 return;
337 }
338 // 读取输入节点名称
339 std::string content = idh.GetContent(INPUT_DEVICE_NAME_FILE);
340 ASSERT_EQ(content, INPUT_NODE_NAME);
341 // 根据输入节点名称获取输入节点
342 std::string inputNode = idh.GetInputNode(INPUT_NODE_NAME);
343 ASSERT_EQ(inputNode, "");
344 // 根据id获取输入节点名称
345 std::string inputNodeName = idh.GetInputNodeNameByCfg(1000);
346 ASSERT_EQ(inputNodeName, "");
347 // 根据id获取输入设备
348 std::string inputDevice = idh.GetInputDeviceById(1000);
349 ASSERT_EQ(inputDevice, "");
350 }
351
352 /**
353 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_01
354 * @tc.desc: Test SetDisplayBind
355 * @tc.type: FUNC
356 * @tc.require:
357 */
358 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_01, TestSize.Level1)
359 {
360 CALL_TEST_DEBUG;
361 int32_t deviceId;
362 int32_t displayId;
363 InputDisplayBindHelper idh("/data/service/el1/public/multimodalinput/0.txt");
364 std::string msg = "deviceId";
365 deviceId = -1;
366 displayId = -1;
367 int32_t ret1 = idh.SetDisplayBind(deviceId, displayId, msg);
368 EXPECT_EQ(ret1, RET_ERR);
369
370 deviceId = 1;
371 displayId = 2;
372 int32_t ret2 = idh.SetDisplayBind(deviceId, displayId, msg);
373 EXPECT_EQ(ret2, RET_ERR);
374 }
375
376 /**
377 * @tc.name: InputDisplayBindHelperTest_GetInputDeviceById_01
378 * @tc.desc: Test GetInputDeviceById
379 * @tc.type: FUNC
380 * @tc.require:
381 */
382 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetInputDeviceById_01, TestSize.Level1)
383 {
384 CALL_TEST_DEBUG;
385 InputDisplayBindHelper idh("/data/service/el1/public/multimodalinput/0.txt");
386 int32_t id = 3;
387 std::string ret1 = idh.GetInputDeviceById(id);
388 EXPECT_EQ(ret1, "");
389
390 id = 6;
391 std::string inputNodeName = "";
392 EXPECT_TRUE(inputNodeName.empty());
393 std::string ret2 = idh.GetInputDeviceById(id);
394 EXPECT_EQ(ret2, "");
395
396 id = 8;
397 std::string inputNode = "";
398 EXPECT_TRUE(inputNode.empty());
399 std::string ret3 = idh.GetInputDeviceById(id);
400 EXPECT_EQ(ret3, "");
401 }
402
403 /**
404 * @tc.name: InputDisplayBindHelperTest_GetInputNodeNameByCfg_01
405 * @tc.desc: Test GetInputNodeNameByCfg
406 * @tc.type: FUNC
407 * @tc.require:
408 */
409 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetInputNodeNameByCfg_01, TestSize.Level1)
410 {
411 CALL_TEST_DEBUG;
412 int32_t id = 3;
413 InputDisplayBindHelper idh("/data/service/el1/public/multimodalinput/0.txt");
414 std::ifstream file(INPUT_DEVICE_NAME_CONFIG);
415 EXPECT_TRUE(file.is_open());
416 std::string ret1 = idh.GetInputNodeNameByCfg(id);
417 EXPECT_EQ(ret1, "");
418
419 id = 2;
420 std::string res = "abc";
421 res.back() = '\n';
422 std::string ret2 = idh.GetInputNodeNameByCfg(id);
423 EXPECT_EQ(ret2, "");
424 }
425
426 /**
427 * @tc.name: InputDisplayBindHelperTest_AddInputDevice_01
428 * @tc.desc: Test AddInputDevice
429 * @tc.type: FUNC
430 * @tc.require:
431 */
432 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddInputDevice_01, TestSize.Level1)
433 {
434 CALL_TEST_DEBUG;
435 BindInfo bindInfo;
436 bindInfo.inputNodeName_ = "mouse";
437 ASSERT_NO_FATAL_FAILURE(bindInfo.AddInputDevice(1, "mouse", "mouse"));
438 }
439
440 /**
441 * @tc.name: InputDisplayBindHelperTest_AddInputDevice_02
442 * @tc.desc: Test AddInputDevice
443 * @tc.type: FUNC
444 * @tc.require:
445 */
446 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddInputDevice_02, TestSize.Level1)
447 {
448 CALL_TEST_DEBUG;
449 BindInfo bindInfo;
450 bindInfo.inputDeviceName_ = "mouse";
451 ASSERT_NO_FATAL_FAILURE(bindInfo.AddInputDevice(1, "mouse", "mouse"));
452 }
453
454 /**
455 * @tc.name: InputDisplayBindHelperTest_AddInputDevice_03
456 * @tc.desc: Test AddInputDevice
457 * @tc.type: FUNC
458 * @tc.require:
459 */
460 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddInputDevice_03, TestSize.Level1)
461 {
462 CALL_TEST_DEBUG;
463 BindInfo bindInfo;
464 bindInfo.inputDeviceId_ = 1;
465 ASSERT_NO_FATAL_FAILURE(bindInfo.AddInputDevice(1, "mouse", "mouse"));
466 }
467
468 /**
469 * @tc.name: InputDisplayBindHelperTest_AddInputDevice_04
470 * @tc.desc: Test AddInputDevice
471 * @tc.type: FUNC
472 * @tc.require:
473 */
474 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddInputDevice_04, TestSize.Level1)
475 {
476 CALL_TEST_DEBUG;
477 BindInfo bindInfo;
478 bindInfo.inputDeviceId_ = 1;
479 bindInfo.inputDeviceName_ = "mouse";
480 ASSERT_NO_FATAL_FAILURE(bindInfo.AddInputDevice(1, "mouse", "mouse"));
481 }
482
483 /**
484 * @tc.name: InputDisplayBindHelperTest_AddDisplay_01
485 * @tc.desc: Test AddDisplay
486 * @tc.type: FUNC
487 * @tc.require:
488 */
489 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddDisplay_01, TestSize.Level1)
490 {
491 CALL_TEST_DEBUG;
492 BindInfo bindInfo;
493 ASSERT_NO_FATAL_FAILURE(bindInfo.AddDisplay(0, "hp 223"));
494 }
495
496 /**
497 * @tc.name: InputDisplayBindHelperTest_AddDisplay_02
498 * @tc.desc: Test AddDisplay
499 * @tc.type: FUNC
500 * @tc.require:
501 */
502 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddDisplay_02, TestSize.Level1)
503 {
504 CALL_TEST_DEBUG;
505 BindInfo bindInfo;
506 bindInfo.displayName_ = "hp 223";
507 ASSERT_NO_FATAL_FAILURE(bindInfo.AddDisplay(0, "hp 223"));
508 }
509
510 /**
511 * @tc.name: InputDisplayBindHelperTest_AddDisplay_03
512 * @tc.desc: Test AddDisplay
513 * @tc.type: FUNC
514 * @tc.require:
515 */
516 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddDisplay_03, TestSize.Level1)
517 {
518 CALL_TEST_DEBUG;
519 BindInfo bindInfo;
520 bindInfo.displayId_ = 0;
521 ASSERT_NO_FATAL_FAILURE(bindInfo.AddDisplay(0, "hp 223"));
522 }
523
524 /**
525 * @tc.name: InputDisplayBindHelperTest_AddDisplay_04
526 * @tc.desc: Test AddDisplay
527 * @tc.type: FUNC
528 * @tc.require:
529 */
530 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddDisplay_04, TestSize.Level1)
531 {
532 CALL_TEST_DEBUG;
533 BindInfo bindInfo;
534 bindInfo.displayId_ = 0;
535 bindInfo.displayName_ = "hp 223";
536 ASSERT_NO_FATAL_FAILURE(bindInfo.AddDisplay(0, "hp 223"));
537 }
538
539 /**
540 * @tc.name: InputDisplayBindHelperTest_AddDisplay_05
541 * @tc.desc: Test AddDisplay
542 * @tc.type: FUNC
543 * @tc.require:
544 */
545 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddDisplay_05, TestSize.Level1)
546 {
547 CALL_TEST_DEBUG;
548 BindInfo bindInfo;
549 bindInfo.displayId_ = -1;
550 bindInfo.displayName_ = "";
551 bool ret = bindInfo.AddDisplay(1, "hp 223");
552 EXPECT_TRUE(ret);
553 }
554
555 /**
556 * @tc.name: InputDisplayBindHelperTest_AddDisplay_06
557 * @tc.desc: Test AddDisplay
558 * @tc.type: FUNC
559 * @tc.require:
560 */
561 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddDisplay_06, TestSize.Level1)
562 {
563 CALL_TEST_DEBUG;
564 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
565 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
566
567 int32_t id = 3;
568 std::string name = "display";
569 std::string deviceName = inputDisplayBindHelper.GetInputDeviceById(id);
570 EXPECT_TRUE(deviceName.empty());
571 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.AddDisplay(id, name));
572 }
573
574 /**
575 * @tc.name: InputDisplayBindHelperTest_GetDesc_01
576 * @tc.desc: Test GetDesc
577 * @tc.type: FUNC
578 * @tc.require:
579 */
580 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetDesc_01, TestSize.Level1)
581 {
582 CALL_TEST_DEBUG;
583 BindInfo bindInfo;
584 bindInfo.inputDeviceId_ = 1;
585 bindInfo.inputDeviceName_ = "mouse";
586 bindInfo.displayId_ = 0;
587 bindInfo.displayName_ = "hp 223";
588 ASSERT_NO_FATAL_FAILURE(bindInfo.GetDesc());
589 }
590
591 /**
592 * @tc.name: InputDisplayBindHelperTest_GetDesc_02
593 * @tc.desc: Test GetDesc
594 * @tc.type: FUNC
595 * @tc.require:
596 */
597 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetDesc_02, TestSize.Level1)
598 {
599 CALL_TEST_DEBUG;
600 BindInfos bindInfos;
601 BindInfo bindInfo;
602 bindInfo.inputDeviceId_ = 1;
603 bindInfo.inputDeviceName_ = "mouse";
604 bindInfo.displayId_ = 0;
605 bindInfo.displayName_ = "hp 223";
606 bindInfos.infos_.push_back(bindInfo);
607 ASSERT_NO_FATAL_FAILURE(bindInfos.GetDesc());
608 }
609
610 /**
611 * @tc.name: InputDisplayBindHelperTest_GetBindDisplayIdByInputDevice_01
612 * @tc.desc: Test GetBindDisplayIdByInputDevice
613 * @tc.type: FUNC
614 * @tc.require:
615 */
616 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetBindDisplayIdByInputDevice_01, TestSize.Level1)
617 {
618 CALL_TEST_DEBUG;
619 BindInfos bindInfos;
620 BindInfo bindInfo;
621 bindInfo.inputDeviceId_ = 1;
622 bindInfo.inputDeviceName_ = "mouse";
623 bindInfo.displayId_ = 0;
624 bindInfo.displayName_ = "hp 223";
625 bindInfos.infos_.push_back(bindInfo);
626 ASSERT_NO_FATAL_FAILURE(bindInfos.GetBindDisplayIdByInputDevice(1));
627 }
628
629 /**
630 * @tc.name: InputDisplayBindHelperTest_GetBindDisplayIdByInputDevice_02
631 * @tc.desc: Test GetBindDisplayIdByInputDevice
632 * @tc.type: FUNC
633 * @tc.require:
634 */
635 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetBindDisplayIdByInputDevice_02, TestSize.Level1)
636 {
637 CALL_TEST_DEBUG;
638 BindInfos bindInfos;
639 BindInfo bindInfo;
640 bindInfo.inputDeviceId_ = 1;
641 bindInfo.inputDeviceName_ = "mouse";
642 bindInfo.displayId_ = -1;
643 bindInfo.displayName_ = "hp 223";
644 bindInfos.infos_.push_back(bindInfo);
645 ASSERT_NO_FATAL_FAILURE(bindInfos.GetBindDisplayIdByInputDevice(1));
646 }
647
648 /**
649 * @tc.name: InputDisplayBindHelperTest_GetBindDisplayIdByInputDevice_03
650 * @tc.desc: Test GetBindDisplayIdByInputDevice
651 * @tc.type: FUNC
652 * @tc.require:
653 */
654 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetBindDisplayIdByInputDevice_03, TestSize.Level1)
655 {
656 CALL_TEST_DEBUG;
657 BindInfos bindInfos;
658 BindInfo bindInfo;
659 bindInfo.inputDeviceId_ = 1;
660 bindInfo.inputDeviceName_ = "mouse";
661 bindInfo.displayId_ = -1;
662 bindInfo.displayName_ = "hp 223";
663 bindInfos.infos_.push_back(bindInfo);
664 ASSERT_NO_FATAL_FAILURE(bindInfos.GetBindDisplayIdByInputDevice(2));
665 }
666
667 /**
668 * @tc.name: InputDisplayBindHelperTest_GetBindDisplayNameByInputDevice_01
669 * @tc.desc: Test GetBindDisplayNameByInputDevice
670 * @tc.type: FUNC
671 * @tc.require:
672 */
673 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetBindDisplayNameByInputDevice_01, TestSize.Level1)
674 {
675 CALL_TEST_DEBUG;
676 BindInfos bindInfos;
677 BindInfo bindInfo;
678 bindInfo.inputDeviceId_ = 1;
679 bindInfo.inputDeviceName_ = "mouse";
680 bindInfo.displayId_ = -1;
681 bindInfo.displayName_ = "hp 223";
682 bindInfos.infos_.push_back(bindInfo);
683 ASSERT_NO_FATAL_FAILURE(bindInfos.GetBindDisplayNameByInputDevice(1));
684 }
685
686 /**
687 * @tc.name: InputDisplayBindHelperTest_GetDisplayIdNames_01
688 * @tc.desc: Test GetDisplayIdNames
689 * @tc.type: FUNC
690 * @tc.require:
691 */
692 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetDisplayIdNames_01, TestSize.Level1)
693 {
694 CALL_TEST_DEBUG;
695 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
696 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
697 BindInfo bindInfo;
698 bindInfo.inputDeviceId_ = 1;
699 bindInfo.inputDeviceName_ = "mouse";
700 bindInfo.displayId_ = -1;
701 bindInfo.displayName_ = "hp 223";
702 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
703 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.GetDisplayIdNames());
704 }
705
706 /**
707 * @tc.name: InputDisplayBindHelperTest_AddLocalDisplay_02
708 * @tc.desc: Test AddLocalDisplay
709 * @tc.type: FUNC
710 * @tc.require:
711 */
712 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddLocalDisplay_02, TestSize.Level1)
713 {
714 CALL_TEST_DEBUG;
715 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
716 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
717 BindInfo bindInfo;
718 bindInfo.inputDeviceId_ = 1;
719 bindInfo.inputDeviceName_ = "mouse";
720 bindInfo.displayId_ = -1;
721 bindInfo.displayName_ = "hp 223";
722 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
723 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.AddLocalDisplay(0, "hp 223"));
724 }
725
726 /**
727 * @tc.name: InputDisplayBindHelperTest_AddLocalDisplay_03
728 * @tc.desc: Test AddLocalDisplay
729 * @tc.type: FUNC
730 * @tc.require:
731 */
732 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddLocalDisplay_03, TestSize.Level1)
733 {
734 CALL_TEST_DEBUG;
735 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
736 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
737 BindInfo bindInfo;
738 bindInfo.inputDeviceId_ = 1;
739 bindInfo.inputDeviceName_ = "mouse";
740 bindInfo.displayId_ = 0;
741 bindInfo.displayName_ = "hp 223";
742 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
743 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.AddLocalDisplay(0, "hp 223"));
744 }
745
746 /**
747 * @tc.name: InputDisplayBindHelperTest_GetInputDeviceById_02
748 * @tc.desc: Test GetInputDeviceById
749 * @tc.type: FUNC
750 * @tc.require:
751 */
752 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetInputDeviceById_02, TestSize.Level1)
753 {
754 CALL_TEST_DEBUG;
755 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
756 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
757 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.GetInputDeviceById(1));
758 }
759
760 /**
761 * @tc.name: InputDisplayBindHelperTest_GetInputDeviceById_03
762 * @tc.desc: Test GetInputDeviceById
763 * @tc.type: FUNC
764 * @tc.require:
765 */
766 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetInputDeviceById_03, TestSize.Level1)
767 {
768 CALL_TEST_DEBUG;
769 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
770 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
771 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.GetInputDeviceById(1));
772 }
773
774 /**
775 * @tc.name: InputDisplayBindHelperTest_GetInputDeviceById_04
776 * @tc.desc: Test GetInputDeviceById
777 * @tc.type: FUNC
778 * @tc.require:
779 */
780 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetInputDeviceById_04, TestSize.Level1)
781 {
782 CALL_TEST_DEBUG;
783 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
784 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
785 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.GetInputDeviceById(0));
786 }
787
788 #ifndef OHOS_BUILD_PC_UNIT_TEST
789 /**
790 * @tc.name: InputDisplayBindHelperTest_GetInputDeviceById_05
791 * @tc.desc: Test GetInputDeviceById
792 * @tc.type: FUNC
793 * @tc.require:
794 */
795 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetInputDeviceById_05, TestSize.Level1)
796 {
797 CALL_TEST_DEBUG;
798 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
799 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
800
801 int32_t id = 5;
802 std::string inputNodeName = inputDisplayBindHelper.GetInputNodeNameByCfg(id);
803 EXPECT_TRUE(inputNodeName.empty());
804
805 std::string inputNode = inputDisplayBindHelper.GetInputNode(inputNodeName);
806 EXPECT_TRUE(inputNode.empty());
807
808 std::string ret = inputDisplayBindHelper.GetInputDeviceById(id);
809 EXPECT_EQ(ret, "");
810 }
811 #endif // OHOS_BUILD_PC_UNIT_TEST
812
813 /**
814 * @tc.name: InputDisplayBindHelperTest_GetInputDeviceById_06
815 * @tc.desc: Test GetInputDeviceById
816 * @tc.type: FUNC
817 * @tc.require:
818 */
819 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetInputDeviceById_06, TestSize.Level1)
820 {
821 CALL_TEST_DEBUG;
822 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
823 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
824
825 int32_t id = 0;
826 std::string ret1 = inputDisplayBindHelper.GetInputDeviceById(id);
827 EXPECT_EQ(ret1, "");
828
829
830 std::string inputNodeName = "mouse";
831 EXPECT_FALSE(inputNodeName.empty());
832 std::string ret2 = inputDisplayBindHelper.GetInputDeviceById(id);
833 EXPECT_EQ(ret2, "");
834
835 std::string inputNode = "keyboard";
836 EXPECT_FALSE(inputNode.empty());
837 std::string ret3 = inputDisplayBindHelper.GetInputDeviceById(id);
838 EXPECT_EQ(ret3, "");
839
840 std::string inputEvent = inputNode;
841 size_t pos = inputEvent.find("input");
842 EXPECT_TRUE(pos == std::string::npos);
843 std::string ret4 = inputDisplayBindHelper.GetInputDeviceById(id);
844 EXPECT_EQ(ret4, "");
845 }
846
847 /**
848 * @tc.name: InputDisplayBindHelperTest_GetInputNodeNameByCfg_02
849 * @tc.desc: Test GetInputNodeNameByCfg
850 * @tc.type: FUNC
851 * @tc.require:
852 */
853 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetInputNodeNameByCfg_02, TestSize.Level1)
854 {
855 CALL_TEST_DEBUG;
856 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
857 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
858 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.GetInputNodeNameByCfg(0));
859 }
860
861 /**
862 * @tc.name: InputDisplayBindHelperTest_GetInputNodeNameByCfg_03
863 * @tc.desc: Test GetInputNodeNameByCfg
864 * @tc.type: FUNC
865 * @tc.require:
866 */
867 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetInputNodeNameByCfg_03, TestSize.Level1)
868 {
869 CALL_TEST_DEBUG;
870 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
871 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
872
873 int32_t id = 2;
874 std::string displayId = "";
875 std::string inputNodeName = "";
876 size_t pos;
877 pos = std::string::npos;
878 std::string ret = inputDisplayBindHelper.GetInputNodeNameByCfg(id);
879 EXPECT_EQ(ret, "");
880 }
881
882 /**
883 * @tc.name: InputDisplayBindHelperTest_GetInputNodeNameByCfg_04
884 * @tc.desc: Test GetInputNodeNameByCfg
885 * @tc.type: FUNC
886 * @tc.require:
887 */
888 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetInputNodeNameByCfg_04, TestSize.Level1)
889 {
890 CALL_TEST_DEBUG;
891 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
892 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
893
894 int32_t id = 2;
895 std::string displayId = "hp223";
896 std::string inputNodeName = "nodeName";
897 size_t pos;
898 pos = 3;
899 std::string ret = inputDisplayBindHelper.GetInputNodeNameByCfg(id);
900 EXPECT_EQ(ret, "");
901 }
902
903 /**
904 * @tc.name: InputDisplayBindHelperTest_GetInputNode_01
905 * @tc.desc: Test GetInputNode
906 * @tc.type: FUNC
907 * @tc.require:
908 */
909 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetInputNode_01, TestSize.Level1)
910 {
911 CALL_TEST_DEBUG;
912 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
913 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
914 std::string inputNodeName = "input5";
915 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.GetInputNode(inputNodeName));
916 }
917
918 /**
919 * @tc.name: InputDisplayBindHelperTest_GetInputNode_02
920 * @tc.desc: Test GetInputNode
921 * @tc.type: FUNC
922 * @tc.require:
923 */
924 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetInputNode_02, TestSize.Level1)
925 {
926 CALL_TEST_DEBUG;
927 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
928 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
929 std::string inputNodeName = "wrapper";
930 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.GetInputNode(inputNodeName));
931 }
932
933 /**
934 * @tc.name: InputDisplayBindHelperTest_Store_01
935 * @tc.desc: Test Store
936 * @tc.type: FUNC
937 * @tc.require:
938 */
939 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_Store_01, TestSize.Level1)
940 {
941 CALL_TEST_DEBUG;
942 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
943 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
944 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.Store());
945 }
946
947 /**
948 * @tc.name: InputDisplayBindHelperTest_Store_02
949 * @tc.desc: Test Store
950 * @tc.type: FUNC
951 * @tc.require:
952 */
953 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_Store_02, TestSize.Level1)
954 {
955 CALL_TEST_DEBUG;
956 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
957 InputDisplayBindHelper inputDisplayBindHelper("input_display_bind_helper_tmp.cfg");
958 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.Store());
959 }
960
961 /**
962 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_02
963 * @tc.desc: Test SetDisplayBind
964 * @tc.type: FUNC
965 * @tc.require:
966 */
967 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_02, TestSize.Level1)
968 {
969 CALL_TEST_DEBUG;
970 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
971 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
972 int32_t deviceId = -1;
973 int32_t displayId = -1;
974 std::string msg = "touch";
975 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
976 }
977
978 /**
979 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_03
980 * @tc.desc: Test SetDisplayBind
981 * @tc.type: FUNC
982 * @tc.require:
983 */
984 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_03, TestSize.Level1)
985 {
986 CALL_TEST_DEBUG;
987 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
988 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
989 int32_t deviceId = -1;
990 int32_t displayId = 0;
991 std::string msg = "touch";
992 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
993 }
994
995 /**
996 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_04
997 * @tc.desc: Test SetDisplayBind
998 * @tc.type: FUNC
999 * @tc.require:
1000 */
1001 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_04, TestSize.Level1)
1002 {
1003 CALL_TEST_DEBUG;
1004 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
1005 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
1006 int32_t deviceId = 1;
1007 int32_t displayId = -1;
1008 std::string msg = "touch";
1009 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
1010 }
1011
1012 /**
1013 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_05
1014 * @tc.desc: Test SetDisplayBind
1015 * @tc.type: FUNC
1016 * @tc.require:
1017 */
1018 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_05, TestSize.Level1)
1019 {
1020 CALL_TEST_DEBUG;
1021 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
1022 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
1023 int32_t deviceId = 1;
1024 int32_t displayId = 0;
1025 std::string msg = "touch";
1026 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
1027 }
1028
1029 /**
1030 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_06
1031 * @tc.desc: Test SetDisplayBind
1032 * @tc.type: FUNC
1033 * @tc.require:
1034 */
1035 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_06, TestSize.Level1)
1036 {
1037 CALL_TEST_DEBUG;
1038 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
1039 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
1040 int32_t deviceId = 1;
1041 int32_t displayId = 0;
1042 std::string msg = "touch";
1043 inputDisplayBindHelper.infos_ = nullptr;
1044 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
1045 }
1046
1047 /**
1048 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_07
1049 * @tc.desc: Test SetDisplayBind
1050 * @tc.type: FUNC
1051 * @tc.require:
1052 */
1053 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_07, TestSize.Level1)
1054 {
1055 CALL_TEST_DEBUG;
1056 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
1057 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
1058 BindInfo bindInfo;
1059 bindInfo.inputDeviceId_ = 1;
1060 bindInfo.inputDeviceName_ = "mouse";
1061 bindInfo.displayId_ = 0;
1062 bindInfo.displayName_ = "hp 223";
1063 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
1064 int32_t deviceId = 1;
1065 int32_t displayId = 0;
1066 std::string msg = "touch";
1067 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
1068 }
1069
1070 /**
1071 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_08
1072 * @tc.desc: Test SetDisplayBind
1073 * @tc.type: FUNC
1074 * @tc.require:
1075 */
1076 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_08, TestSize.Level1)
1077 {
1078 CALL_TEST_DEBUG;
1079 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
1080 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
1081 BindInfo bindInfo;
1082 bindInfo.inputDeviceId_ = 1;
1083 bindInfo.inputDeviceName_ = "mouse";
1084 bindInfo.displayId_ = 0;
1085 bindInfo.displayName_ = "hp 223";
1086 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
1087 int32_t deviceId = 2;
1088 int32_t displayId = 1;
1089 std::string msg = "touch";
1090 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
1091 }
1092
1093 /**
1094 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_09
1095 * @tc.desc: Test SetDisplayBind
1096 * @tc.type: FUNC
1097 * @tc.require:
1098 */
1099 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_09, TestSize.Level1)
1100 {
1101 CALL_TEST_DEBUG;
1102 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
1103 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
1104 BindInfo bindInfo;
1105 bindInfo.inputDeviceId_ = 1;
1106 bindInfo.inputDeviceName_ = "mouse";
1107 bindInfo.displayId_ = -1;
1108 bindInfo.displayName_ = "hp 223";
1109 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
1110 int32_t deviceId = 1;
1111 int32_t displayId = 0;
1112 std::string msg = "touch";
1113 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
1114 }
1115
1116 /**
1117 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_10
1118 * @tc.desc: Test SetDisplayBind
1119 * @tc.type: FUNC
1120 * @tc.require:
1121 */
1122 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_10, TestSize.Level1)
1123 {
1124 CALL_TEST_DEBUG;
1125 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
1126 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
1127 BindInfo bindInfo;
1128 bindInfo.inputDeviceId_ = 1;
1129 bindInfo.inputDeviceName_ = "mouse";
1130 bindInfo.displayId_ = 0;
1131 bindInfo.displayName_ = "hp 223";
1132 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
1133 bindInfo.inputDeviceId_ = 2;
1134 bindInfo.inputDeviceName_ = "mouse";
1135 bindInfo.displayId_ = 1;
1136 bindInfo.displayName_ = "hp 223";
1137 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
1138 int32_t deviceId = 1;
1139 int32_t displayId = 1;
1140 std::string msg = "touch";
1141 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
1142 }
1143
1144 /**
1145 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_11
1146 * @tc.desc: Test SetDisplayBind
1147 * @tc.type: FUNC
1148 * @tc.require:
1149 */
1150 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_11, TestSize.Level1)
1151 {
1152 CALL_TEST_DEBUG;
1153 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
1154 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
1155 BindInfo bindInfo;
1156 bindInfo.inputDeviceId_ = 1;
1157 bindInfo.inputDeviceName_ = "mouse";
1158 bindInfo.displayId_ = 0;
1159 bindInfo.displayName_ = "hp 223";
1160 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
1161 bindInfo.inputDeviceId_ = -1;
1162 bindInfo.inputDeviceName_ = "mouse";
1163 bindInfo.displayId_ = 1;
1164 bindInfo.displayName_ = "hp 223";
1165 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
1166 int32_t deviceId = 1;
1167 int32_t displayId = 1;
1168 std::string msg = "touch";
1169 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
1170 }
1171
1172 /**
1173 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_12
1174 * @tc.desc: Test SetDisplayBind
1175 * @tc.type: FUNC
1176 * @tc.require:
1177 */
1178 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_12, TestSize.Level1)
1179 {
1180 CALL_TEST_DEBUG;
1181 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
1182 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
1183 BindInfo bindInfo;
1184 bindInfo.inputDeviceId_ = 1;
1185 bindInfo.inputDeviceName_ = "mouse";
1186 bindInfo.displayId_ = -1;
1187 bindInfo.displayName_ = "hp 223";
1188 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
1189 bindInfo.inputDeviceId_ = 2;
1190 bindInfo.inputDeviceName_ = "mouse";
1191 bindInfo.displayId_ = 1;
1192 bindInfo.displayName_ = "hp 223";
1193 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
1194 int32_t deviceId = 1;
1195 int32_t displayId = 1;
1196 std::string msg = "touch";
1197 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
1198 }
1199
1200 /**
1201 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_13
1202 * @tc.desc: Test SetDisplayBind
1203 * @tc.type: FUNC
1204 * @tc.require:
1205 */
1206 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_13, TestSize.Level1)
1207 {
1208 CALL_TEST_DEBUG;
1209 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
1210 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
1211 BindInfo bindInfo;
1212 bindInfo.inputDeviceId_ = 1;
1213 bindInfo.inputDeviceName_ = "mouse";
1214 bindInfo.displayId_ = -1;
1215 bindInfo.displayName_ = "hp 223";
1216 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
1217 bindInfo.inputDeviceId_ = -1;
1218 bindInfo.inputDeviceName_ = "mouse";
1219 bindInfo.displayId_ = 1;
1220 bindInfo.displayName_ = "hp 223";
1221 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
1222 int32_t deviceId = 1;
1223 int32_t displayId = 1;
1224 std::string msg = "touch";
1225 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
1226 }
1227
1228 /**
1229 * @tc.name: InputDisplayBindHelperTest_AddLocalDisplay_01
1230 * @tc.desc: Test AddLocalDisplay
1231 * @tc.type: FUNC
1232 * @tc.require:
1233 */
1234 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddLocalDisplay_01, TestSize.Level1)
1235 {
1236 CALL_TEST_DEBUG;
1237 bool isStore;
1238 int32_t id = 3;
1239 std::string name = "localDisplay";
1240 InputDisplayBindHelper idh("/data/service/el1/public/multimodalinput/0.txt");
1241 isStore = false;
1242 ASSERT_NO_FATAL_FAILURE(idh.AddLocalDisplay(id, name));
1243 }
1244
1245 /**
1246 * @tc.name: InputDisplayBindHelperTest_GetDisplayBindInfo_02
1247 * @tc.desc: Test GetDisplayBindInfo
1248 * @tc.type: FUNC
1249 * @tc.require:
1250 */
1251 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetDisplayBindInfo_02, TestSize.Level1)
1252 {
1253 CALL_TEST_DEBUG;
1254 DisplayBindInfos infos;
1255 InputDisplayBindHelper idh("/data/service/el1/public/multimodalinput/0.txt");
1256 BindInfos bindInfos;
1257 BindInfo bindInfo;
1258 bindInfo.inputDeviceId_ = 1;
1259 bindInfo.inputDeviceName_ = "mouse";
1260 bindInfo.displayId_ = 0;
1261 bindInfo.displayName_ = "hp 223";
1262 bindInfos.infos_.push_back(bindInfo);
1263 bindInfo.inputDeviceId_ = -1;
1264 bindInfo.inputDeviceName_ = "mouse";
1265 bindInfo.displayId_ = 1;
1266 bindInfo.displayName_ = "hp 223";
1267 ASSERT_NO_FATAL_FAILURE(idh.GetDisplayBindInfo(infos));
1268 }
1269 } // namespace MMI
1270 } // namespace OHOS