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");
128 bindInfo.AddInputDevice(2, "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");
150 bindInfo.AddInputDevice(2, "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");
172 bindInfo.AddInputDevice(2, "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");
194 bindInfo.AddInputDevice(2, "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");
210 bindInfo.AddInputDevice(2, "keyboard");
211 bindInfo.AddInputDevice(3, "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");
240 bindInfo.AddInputDevice(2, "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");
277 bindInfo.AddInputDevice(2, "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<int32_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");
310 bindInfo.AddInputDevice(2, "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_02
428 * @tc.desc: Test AddInputDevice
429 * @tc.type: FUNC
430 * @tc.require:
431 */
432 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddInputDevice_02, TestSize.Level1)
433 {
434 CALL_TEST_DEBUG;
435 BindInfo bindInfo;
436 bindInfo.inputDeviceName_ = "mouse";
437 ASSERT_NO_FATAL_FAILURE(bindInfo.AddInputDevice(1, "mouse"));
438 }
439
440 /**
441 * @tc.name: InputDisplayBindHelperTest_AddInputDevice_03
442 * @tc.desc: Test AddInputDevice
443 * @tc.type: FUNC
444 * @tc.require:
445 */
446 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddInputDevice_03, TestSize.Level1)
447 {
448 CALL_TEST_DEBUG;
449 BindInfo bindInfo;
450 bindInfo.inputDeviceId_ = 1;
451 ASSERT_NO_FATAL_FAILURE(bindInfo.AddInputDevice(1, "mouse"));
452 }
453
454 /**
455 * @tc.name: InputDisplayBindHelperTest_AddInputDevice_04
456 * @tc.desc: Test AddInputDevice
457 * @tc.type: FUNC
458 * @tc.require:
459 */
460 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddInputDevice_04, TestSize.Level1)
461 {
462 CALL_TEST_DEBUG;
463 BindInfo bindInfo;
464 bindInfo.inputDeviceId_ = 1;
465 bindInfo.inputDeviceName_ = "mouse";
466 ASSERT_NO_FATAL_FAILURE(bindInfo.AddInputDevice(1, "mouse"));
467 }
468
469 /**
470 * @tc.name: InputDisplayBindHelperTest_AddDisplay_01
471 * @tc.desc: Test AddDisplay
472 * @tc.type: FUNC
473 * @tc.require:
474 */
475 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddDisplay_01, TestSize.Level1)
476 {
477 CALL_TEST_DEBUG;
478 BindInfo bindInfo;
479 ASSERT_NO_FATAL_FAILURE(bindInfo.AddDisplay(0, "hp 223"));
480 }
481
482 /**
483 * @tc.name: InputDisplayBindHelperTest_AddDisplay_02
484 * @tc.desc: Test AddDisplay
485 * @tc.type: FUNC
486 * @tc.require:
487 */
488 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddDisplay_02, TestSize.Level1)
489 {
490 CALL_TEST_DEBUG;
491 BindInfo bindInfo;
492 bindInfo.displayName_ = "hp 223";
493 ASSERT_NO_FATAL_FAILURE(bindInfo.AddDisplay(0, "hp 223"));
494 }
495
496 /**
497 * @tc.name: InputDisplayBindHelperTest_AddDisplay_03
498 * @tc.desc: Test AddDisplay
499 * @tc.type: FUNC
500 * @tc.require:
501 */
502 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddDisplay_03, TestSize.Level1)
503 {
504 CALL_TEST_DEBUG;
505 BindInfo bindInfo;
506 bindInfo.displayId_ = 0;
507 ASSERT_NO_FATAL_FAILURE(bindInfo.AddDisplay(0, "hp 223"));
508 }
509
510 /**
511 * @tc.name: InputDisplayBindHelperTest_AddDisplay_04
512 * @tc.desc: Test AddDisplay
513 * @tc.type: FUNC
514 * @tc.require:
515 */
516 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddDisplay_04, TestSize.Level1)
517 {
518 CALL_TEST_DEBUG;
519 BindInfo bindInfo;
520 bindInfo.displayId_ = 0;
521 bindInfo.displayName_ = "hp 223";
522 ASSERT_NO_FATAL_FAILURE(bindInfo.AddDisplay(0, "hp 223"));
523 }
524
525 /**
526 * @tc.name: InputDisplayBindHelperTest_AddDisplay_05
527 * @tc.desc: Test AddDisplay
528 * @tc.type: FUNC
529 * @tc.require:
530 */
531 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddDisplay_05, TestSize.Level1)
532 {
533 CALL_TEST_DEBUG;
534 BindInfo bindInfo;
535 bindInfo.displayId_ = -1;
536 bindInfo.displayName_ = "";
537 bool ret = bindInfo.AddDisplay(1, "hp 223");
538 EXPECT_TRUE(ret);
539 }
540
541 /**
542 * @tc.name: InputDisplayBindHelperTest_AddDisplay_06
543 * @tc.desc: Test AddDisplay
544 * @tc.type: FUNC
545 * @tc.require:
546 */
547 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddDisplay_06, TestSize.Level1)
548 {
549 CALL_TEST_DEBUG;
550 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
551 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
552
553 int32_t id = 3;
554 std::string name = "display";
555 std::string deviceName = inputDisplayBindHelper.GetInputDeviceById(id);
556 EXPECT_TRUE(deviceName.empty());
557 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.AddDisplay(id, name));
558 }
559
560 /**
561 * @tc.name: InputDisplayBindHelperTest_GetDesc_01
562 * @tc.desc: Test GetDesc
563 * @tc.type: FUNC
564 * @tc.require:
565 */
566 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetDesc_01, TestSize.Level1)
567 {
568 CALL_TEST_DEBUG;
569 BindInfo bindInfo;
570 bindInfo.inputDeviceId_ = 1;
571 bindInfo.inputDeviceName_ = "mouse";
572 bindInfo.displayId_ = 0;
573 bindInfo.displayName_ = "hp 223";
574 ASSERT_NO_FATAL_FAILURE(bindInfo.GetDesc());
575 }
576
577 /**
578 * @tc.name: InputDisplayBindHelperTest_GetDesc_02
579 * @tc.desc: Test GetDesc
580 * @tc.type: FUNC
581 * @tc.require:
582 */
583 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetDesc_02, TestSize.Level1)
584 {
585 CALL_TEST_DEBUG;
586 BindInfos bindInfos;
587 BindInfo bindInfo;
588 bindInfo.inputDeviceId_ = 1;
589 bindInfo.inputDeviceName_ = "mouse";
590 bindInfo.displayId_ = 0;
591 bindInfo.displayName_ = "hp 223";
592 bindInfos.infos_.push_back(bindInfo);
593 ASSERT_NO_FATAL_FAILURE(bindInfos.GetDesc());
594 }
595
596 /**
597 * @tc.name: InputDisplayBindHelperTest_GetBindDisplayIdByInputDevice_01
598 * @tc.desc: Test GetBindDisplayIdByInputDevice
599 * @tc.type: FUNC
600 * @tc.require:
601 */
602 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetBindDisplayIdByInputDevice_01, TestSize.Level1)
603 {
604 CALL_TEST_DEBUG;
605 BindInfos bindInfos;
606 BindInfo bindInfo;
607 bindInfo.inputDeviceId_ = 1;
608 bindInfo.inputDeviceName_ = "mouse";
609 bindInfo.displayId_ = 0;
610 bindInfo.displayName_ = "hp 223";
611 bindInfos.infos_.push_back(bindInfo);
612 ASSERT_NO_FATAL_FAILURE(bindInfos.GetBindDisplayIdByInputDevice(1));
613 }
614
615 /**
616 * @tc.name: InputDisplayBindHelperTest_GetBindDisplayIdByInputDevice_02
617 * @tc.desc: Test GetBindDisplayIdByInputDevice
618 * @tc.type: FUNC
619 * @tc.require:
620 */
621 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetBindDisplayIdByInputDevice_02, TestSize.Level1)
622 {
623 CALL_TEST_DEBUG;
624 BindInfos bindInfos;
625 BindInfo bindInfo;
626 bindInfo.inputDeviceId_ = 1;
627 bindInfo.inputDeviceName_ = "mouse";
628 bindInfo.displayId_ = -1;
629 bindInfo.displayName_ = "hp 223";
630 bindInfos.infos_.push_back(bindInfo);
631 ASSERT_NO_FATAL_FAILURE(bindInfos.GetBindDisplayIdByInputDevice(1));
632 }
633
634 /**
635 * @tc.name: InputDisplayBindHelperTest_GetBindDisplayIdByInputDevice_03
636 * @tc.desc: Test GetBindDisplayIdByInputDevice
637 * @tc.type: FUNC
638 * @tc.require:
639 */
640 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetBindDisplayIdByInputDevice_03, TestSize.Level1)
641 {
642 CALL_TEST_DEBUG;
643 BindInfos bindInfos;
644 BindInfo bindInfo;
645 bindInfo.inputDeviceId_ = 1;
646 bindInfo.inputDeviceName_ = "mouse";
647 bindInfo.displayId_ = -1;
648 bindInfo.displayName_ = "hp 223";
649 bindInfos.infos_.push_back(bindInfo);
650 ASSERT_NO_FATAL_FAILURE(bindInfos.GetBindDisplayIdByInputDevice(2));
651 }
652
653 /**
654 * @tc.name: InputDisplayBindHelperTest_GetBindDisplayNameByInputDevice_01
655 * @tc.desc: Test GetBindDisplayNameByInputDevice
656 * @tc.type: FUNC
657 * @tc.require:
658 */
659 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetBindDisplayNameByInputDevice_01, TestSize.Level1)
660 {
661 CALL_TEST_DEBUG;
662 BindInfos bindInfos;
663 BindInfo bindInfo;
664 bindInfo.inputDeviceId_ = 1;
665 bindInfo.inputDeviceName_ = "mouse";
666 bindInfo.displayId_ = -1;
667 bindInfo.displayName_ = "hp 223";
668 bindInfos.infos_.push_back(bindInfo);
669 ASSERT_NO_FATAL_FAILURE(bindInfos.GetBindDisplayNameByInputDevice(1));
670 }
671
672 /**
673 * @tc.name: InputDisplayBindHelperTest_GetDisplayIdNames_01
674 * @tc.desc: Test GetDisplayIdNames
675 * @tc.type: FUNC
676 * @tc.require:
677 */
678 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetDisplayIdNames_01, TestSize.Level1)
679 {
680 CALL_TEST_DEBUG;
681 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
682 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
683 BindInfo bindInfo;
684 bindInfo.inputDeviceId_ = 1;
685 bindInfo.inputDeviceName_ = "mouse";
686 bindInfo.displayId_ = -1;
687 bindInfo.displayName_ = "hp 223";
688 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
689 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.GetDisplayIdNames());
690 }
691
692 /**
693 * @tc.name: InputDisplayBindHelperTest_AddLocalDisplay_02
694 * @tc.desc: Test AddLocalDisplay
695 * @tc.type: FUNC
696 * @tc.require:
697 */
698 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddLocalDisplay_02, TestSize.Level1)
699 {
700 CALL_TEST_DEBUG;
701 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
702 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
703 BindInfo bindInfo;
704 bindInfo.inputDeviceId_ = 1;
705 bindInfo.inputDeviceName_ = "mouse";
706 bindInfo.displayId_ = -1;
707 bindInfo.displayName_ = "hp 223";
708 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
709 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.AddLocalDisplay(0, "hp 223"));
710 }
711
712 /**
713 * @tc.name: InputDisplayBindHelperTest_AddLocalDisplay_03
714 * @tc.desc: Test AddLocalDisplay
715 * @tc.type: FUNC
716 * @tc.require:
717 */
718 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddLocalDisplay_03, TestSize.Level1)
719 {
720 CALL_TEST_DEBUG;
721 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
722 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
723 BindInfo bindInfo;
724 bindInfo.inputDeviceId_ = 1;
725 bindInfo.inputDeviceName_ = "mouse";
726 bindInfo.displayId_ = 0;
727 bindInfo.displayName_ = "hp 223";
728 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
729 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.AddLocalDisplay(0, "hp 223"));
730 }
731
732 /**
733 * @tc.name: InputDisplayBindHelperTest_GetInputDeviceById_02
734 * @tc.desc: Test GetInputDeviceById
735 * @tc.type: FUNC
736 * @tc.require:
737 */
738 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetInputDeviceById_02, TestSize.Level1)
739 {
740 CALL_TEST_DEBUG;
741 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
742 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
743 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.GetInputDeviceById(1));
744 }
745
746 /**
747 * @tc.name: InputDisplayBindHelperTest_GetInputDeviceById_03
748 * @tc.desc: Test GetInputDeviceById
749 * @tc.type: FUNC
750 * @tc.require:
751 */
752 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetInputDeviceById_03, 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_04
762 * @tc.desc: Test GetInputDeviceById
763 * @tc.type: FUNC
764 * @tc.require:
765 */
766 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetInputDeviceById_04, 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(0));
772 }
773
774 #ifndef OHOS_BUILD_PC_UNIT_TEST
775 /**
776 * @tc.name: InputDisplayBindHelperTest_GetInputDeviceById_05
777 * @tc.desc: Test GetInputDeviceById
778 * @tc.type: FUNC
779 * @tc.require:
780 */
781 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetInputDeviceById_05, TestSize.Level1)
782 {
783 CALL_TEST_DEBUG;
784 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
785 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
786
787 int32_t id = 5;
788 std::string inputNodeName = inputDisplayBindHelper.GetInputNodeNameByCfg(id);
789 EXPECT_TRUE(inputNodeName.empty());
790
791 std::string inputNode = inputDisplayBindHelper.GetInputNode(inputNodeName);
792 EXPECT_TRUE(inputNode.empty());
793
794 std::string ret = inputDisplayBindHelper.GetInputDeviceById(id);
795 EXPECT_EQ(ret, "");
796 }
797 #endif // OHOS_BUILD_PC_UNIT_TEST
798
799 /**
800 * @tc.name: InputDisplayBindHelperTest_GetInputDeviceById_06
801 * @tc.desc: Test GetInputDeviceById
802 * @tc.type: FUNC
803 * @tc.require:
804 */
805 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetInputDeviceById_06, TestSize.Level1)
806 {
807 CALL_TEST_DEBUG;
808 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
809 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
810
811 int32_t id = 0;
812 std::string ret1 = inputDisplayBindHelper.GetInputDeviceById(id);
813 EXPECT_EQ(ret1, "");
814
815
816 std::string inputNodeName = "mouse";
817 EXPECT_FALSE(inputNodeName.empty());
818 std::string ret2 = inputDisplayBindHelper.GetInputDeviceById(id);
819 EXPECT_EQ(ret2, "");
820
821 std::string inputNode = "keyboard";
822 EXPECT_FALSE(inputNode.empty());
823 std::string ret3 = inputDisplayBindHelper.GetInputDeviceById(id);
824 EXPECT_EQ(ret3, "");
825
826 std::string inputEvent = inputNode;
827 size_t pos = inputEvent.find("input");
828 EXPECT_TRUE(pos == std::string::npos);
829 std::string ret4 = inputDisplayBindHelper.GetInputDeviceById(id);
830 EXPECT_EQ(ret4, "");
831 }
832
833 /**
834 * @tc.name: InputDisplayBindHelperTest_GetInputNodeNameByCfg_02
835 * @tc.desc: Test GetInputNodeNameByCfg
836 * @tc.type: FUNC
837 * @tc.require:
838 */
839 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetInputNodeNameByCfg_02, TestSize.Level1)
840 {
841 CALL_TEST_DEBUG;
842 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
843 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
844 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.GetInputNodeNameByCfg(0));
845 }
846
847 /**
848 * @tc.name: InputDisplayBindHelperTest_GetInputNodeNameByCfg_03
849 * @tc.desc: Test GetInputNodeNameByCfg
850 * @tc.type: FUNC
851 * @tc.require:
852 */
853 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetInputNodeNameByCfg_03, TestSize.Level1)
854 {
855 CALL_TEST_DEBUG;
856 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
857 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
858
859 int32_t id = 2;
860 std::string displayId = "";
861 std::string inputNodeName = "";
862 size_t pos;
863 pos = std::string::npos;
864 std::string ret = inputDisplayBindHelper.GetInputNodeNameByCfg(id);
865 EXPECT_EQ(ret, "");
866 }
867
868 /**
869 * @tc.name: InputDisplayBindHelperTest_GetInputNodeNameByCfg_04
870 * @tc.desc: Test GetInputNodeNameByCfg
871 * @tc.type: FUNC
872 * @tc.require:
873 */
874 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetInputNodeNameByCfg_04, TestSize.Level1)
875 {
876 CALL_TEST_DEBUG;
877 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
878 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
879
880 int32_t id = 2;
881 std::string displayId = "hp223";
882 std::string inputNodeName = "nodeName";
883 size_t pos;
884 pos = 3;
885 std::string ret = inputDisplayBindHelper.GetInputNodeNameByCfg(id);
886 EXPECT_EQ(ret, "");
887 }
888
889 /**
890 * @tc.name: InputDisplayBindHelperTest_GetInputNode_01
891 * @tc.desc: Test GetInputNode
892 * @tc.type: FUNC
893 * @tc.require:
894 */
895 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetInputNode_01, TestSize.Level1)
896 {
897 CALL_TEST_DEBUG;
898 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
899 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
900 std::string inputNodeName = "input5";
901 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.GetInputNode(inputNodeName));
902 }
903
904 /**
905 * @tc.name: InputDisplayBindHelperTest_GetInputNode_02
906 * @tc.desc: Test GetInputNode
907 * @tc.type: FUNC
908 * @tc.require:
909 */
910 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetInputNode_02, TestSize.Level1)
911 {
912 CALL_TEST_DEBUG;
913 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
914 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
915 std::string inputNodeName = "wrapper";
916 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.GetInputNode(inputNodeName));
917 }
918
919 /**
920 * @tc.name: InputDisplayBindHelperTest_Store_01
921 * @tc.desc: Test Store
922 * @tc.type: FUNC
923 * @tc.require:
924 */
925 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_Store_01, TestSize.Level1)
926 {
927 CALL_TEST_DEBUG;
928 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
929 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
930 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.Store());
931 }
932
933 /**
934 * @tc.name: InputDisplayBindHelperTest_Store_02
935 * @tc.desc: Test Store
936 * @tc.type: FUNC
937 * @tc.require:
938 */
939 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_Store_02, TestSize.Level1)
940 {
941 CALL_TEST_DEBUG;
942 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
943 InputDisplayBindHelper inputDisplayBindHelper("input_display_bind_helper_tmp.cfg");
944 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.Store());
945 }
946
947 /**
948 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_02
949 * @tc.desc: Test SetDisplayBind
950 * @tc.type: FUNC
951 * @tc.require:
952 */
953 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_02, TestSize.Level1)
954 {
955 CALL_TEST_DEBUG;
956 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
957 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
958 int32_t deviceId = -1;
959 int32_t displayId = -1;
960 std::string msg = "touch";
961 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
962 }
963
964 /**
965 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_03
966 * @tc.desc: Test SetDisplayBind
967 * @tc.type: FUNC
968 * @tc.require:
969 */
970 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_03, TestSize.Level1)
971 {
972 CALL_TEST_DEBUG;
973 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
974 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
975 int32_t deviceId = -1;
976 int32_t displayId = 0;
977 std::string msg = "touch";
978 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
979 }
980
981 /**
982 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_04
983 * @tc.desc: Test SetDisplayBind
984 * @tc.type: FUNC
985 * @tc.require:
986 */
987 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_04, TestSize.Level1)
988 {
989 CALL_TEST_DEBUG;
990 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
991 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
992 int32_t deviceId = 1;
993 int32_t displayId = -1;
994 std::string msg = "touch";
995 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
996 }
997
998 /**
999 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_05
1000 * @tc.desc: Test SetDisplayBind
1001 * @tc.type: FUNC
1002 * @tc.require:
1003 */
1004 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_05, TestSize.Level1)
1005 {
1006 CALL_TEST_DEBUG;
1007 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
1008 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
1009 int32_t deviceId = 1;
1010 int32_t displayId = 0;
1011 std::string msg = "touch";
1012 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
1013 }
1014
1015 /**
1016 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_06
1017 * @tc.desc: Test SetDisplayBind
1018 * @tc.type: FUNC
1019 * @tc.require:
1020 */
1021 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_06, TestSize.Level1)
1022 {
1023 CALL_TEST_DEBUG;
1024 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
1025 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
1026 int32_t deviceId = 1;
1027 int32_t displayId = 0;
1028 std::string msg = "touch";
1029 inputDisplayBindHelper.infos_ = nullptr;
1030 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
1031 }
1032
1033 /**
1034 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_07
1035 * @tc.desc: Test SetDisplayBind
1036 * @tc.type: FUNC
1037 * @tc.require:
1038 */
1039 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_07, TestSize.Level1)
1040 {
1041 CALL_TEST_DEBUG;
1042 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
1043 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
1044 BindInfo bindInfo;
1045 bindInfo.inputDeviceId_ = 1;
1046 bindInfo.inputDeviceName_ = "mouse";
1047 bindInfo.displayId_ = 0;
1048 bindInfo.displayName_ = "hp 223";
1049 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
1050 int32_t deviceId = 1;
1051 int32_t displayId = 0;
1052 std::string msg = "touch";
1053 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
1054 }
1055
1056 /**
1057 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_08
1058 * @tc.desc: Test SetDisplayBind
1059 * @tc.type: FUNC
1060 * @tc.require:
1061 */
1062 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_08, TestSize.Level1)
1063 {
1064 CALL_TEST_DEBUG;
1065 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
1066 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
1067 BindInfo bindInfo;
1068 bindInfo.inputDeviceId_ = 1;
1069 bindInfo.inputDeviceName_ = "mouse";
1070 bindInfo.displayId_ = 0;
1071 bindInfo.displayName_ = "hp 223";
1072 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
1073 int32_t deviceId = 2;
1074 int32_t displayId = 1;
1075 std::string msg = "touch";
1076 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
1077 }
1078
1079 /**
1080 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_09
1081 * @tc.desc: Test SetDisplayBind
1082 * @tc.type: FUNC
1083 * @tc.require:
1084 */
1085 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_09, TestSize.Level1)
1086 {
1087 CALL_TEST_DEBUG;
1088 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
1089 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
1090 BindInfo bindInfo;
1091 bindInfo.inputDeviceId_ = 1;
1092 bindInfo.inputDeviceName_ = "mouse";
1093 bindInfo.displayId_ = -1;
1094 bindInfo.displayName_ = "hp 223";
1095 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
1096 int32_t deviceId = 1;
1097 int32_t displayId = 0;
1098 std::string msg = "touch";
1099 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
1100 }
1101
1102 /**
1103 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_10
1104 * @tc.desc: Test SetDisplayBind
1105 * @tc.type: FUNC
1106 * @tc.require:
1107 */
1108 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_10, TestSize.Level1)
1109 {
1110 CALL_TEST_DEBUG;
1111 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
1112 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
1113 BindInfo bindInfo;
1114 bindInfo.inputDeviceId_ = 1;
1115 bindInfo.inputDeviceName_ = "mouse";
1116 bindInfo.displayId_ = 0;
1117 bindInfo.displayName_ = "hp 223";
1118 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
1119 bindInfo.inputDeviceId_ = 2;
1120 bindInfo.inputDeviceName_ = "mouse";
1121 bindInfo.displayId_ = 1;
1122 bindInfo.displayName_ = "hp 223";
1123 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
1124 int32_t deviceId = 1;
1125 int32_t displayId = 1;
1126 std::string msg = "touch";
1127 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
1128 }
1129
1130 /**
1131 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_11
1132 * @tc.desc: Test SetDisplayBind
1133 * @tc.type: FUNC
1134 * @tc.require:
1135 */
1136 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_11, TestSize.Level1)
1137 {
1138 CALL_TEST_DEBUG;
1139 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
1140 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
1141 BindInfo bindInfo;
1142 bindInfo.inputDeviceId_ = 1;
1143 bindInfo.inputDeviceName_ = "mouse";
1144 bindInfo.displayId_ = 0;
1145 bindInfo.displayName_ = "hp 223";
1146 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
1147 bindInfo.inputDeviceId_ = -1;
1148 bindInfo.inputDeviceName_ = "mouse";
1149 bindInfo.displayId_ = 1;
1150 bindInfo.displayName_ = "hp 223";
1151 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
1152 int32_t deviceId = 1;
1153 int32_t displayId = 1;
1154 std::string msg = "touch";
1155 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
1156 }
1157
1158 /**
1159 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_12
1160 * @tc.desc: Test SetDisplayBind
1161 * @tc.type: FUNC
1162 * @tc.require:
1163 */
1164 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_12, TestSize.Level1)
1165 {
1166 CALL_TEST_DEBUG;
1167 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
1168 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
1169 BindInfo bindInfo;
1170 bindInfo.inputDeviceId_ = 1;
1171 bindInfo.inputDeviceName_ = "mouse";
1172 bindInfo.displayId_ = -1;
1173 bindInfo.displayName_ = "hp 223";
1174 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
1175 bindInfo.inputDeviceId_ = 2;
1176 bindInfo.inputDeviceName_ = "mouse";
1177 bindInfo.displayId_ = 1;
1178 bindInfo.displayName_ = "hp 223";
1179 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
1180 int32_t deviceId = 1;
1181 int32_t displayId = 1;
1182 std::string msg = "touch";
1183 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
1184 }
1185
1186 /**
1187 * @tc.name: InputDisplayBindHelperTest_SetDisplayBind_13
1188 * @tc.desc: Test SetDisplayBind
1189 * @tc.type: FUNC
1190 * @tc.require:
1191 */
1192 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_SetDisplayBind_13, TestSize.Level1)
1193 {
1194 CALL_TEST_DEBUG;
1195 InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n");
1196 InputDisplayBindHelper inputDisplayBindHelper(InputDisplayBindHelperTest::GetCfgFileName());
1197 BindInfo bindInfo;
1198 bindInfo.inputDeviceId_ = 1;
1199 bindInfo.inputDeviceName_ = "mouse";
1200 bindInfo.displayId_ = -1;
1201 bindInfo.displayName_ = "hp 223";
1202 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
1203 bindInfo.inputDeviceId_ = -1;
1204 bindInfo.inputDeviceName_ = "mouse";
1205 bindInfo.displayId_ = 1;
1206 bindInfo.displayName_ = "hp 223";
1207 inputDisplayBindHelper.infos_->infos_.push_back(bindInfo);
1208 int32_t deviceId = 1;
1209 int32_t displayId = 1;
1210 std::string msg = "touch";
1211 ASSERT_NO_FATAL_FAILURE(inputDisplayBindHelper.SetDisplayBind(deviceId, displayId, msg));
1212 }
1213
1214 /**
1215 * @tc.name: InputDisplayBindHelperTest_AddLocalDisplay_01
1216 * @tc.desc: Test AddLocalDisplay
1217 * @tc.type: FUNC
1218 * @tc.require:
1219 */
1220 HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_AddLocalDisplay_01, TestSize.Level1)
1221 {
1222 CALL_TEST_DEBUG;
1223 bool isStore;
1224 int32_t id = 3;
1225 std::string name = "localDisplay";
1226 InputDisplayBindHelper idh("/data/service/el1/public/multimodalinput/0.txt");
1227 isStore = false;
1228 ASSERT_NO_FATAL_FAILURE(idh.AddLocalDisplay(id, name));
1229 }
1230 } // namespace MMI
1231 } // namespace OHOS