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 <cmath>
17 #include <cstdio>
18 #include <unistd.h>
19 #include <gtest/gtest.h>
20 #include <securec.h>
21 #include <hdf_base.h>
22 #include <hdf_log.h>
23 #include "osal_time.h"
24 #include "v1_0/iinput_interfaces.h"
25 #include "input_type.h"
26 #include "input_callback_impl.h"
27
28 using namespace OHOS::HDI::Input::V1_0;
29 using namespace testing::ext;
30
31 namespace {
32 sptr<IInputInterfaces> g_inputInterfaces = nullptr;
33 sptr<IInputCallback> g_callback = nullptr;
34 sptr<IInputCallback> g_hotplugCb = nullptr;
35
36 constexpr int32_t INIT_DEFAULT_VALUE = 255;
37 constexpr int32_t KEEP_ALIVE_TIME_MS = 3000;
38 constexpr int32_t TOUCH_INDEX = 1;
39 constexpr int32_t INVALID_INDEX = 5;
40 constexpr int32_t MAX_DEVICES = 32;
41 constexpr int32_t TEST_RESULT_LEN = 32;
42 }
43
44 class HdfInputHdiTest : public testing::Test {
45 public:
46 static void SetUpTestCase();
47 static void TearDownTestCase();
48 void SetUp();
49 void TearDown();
50 };
51
SetUpTestCase()52 void HdfInputHdiTest::SetUpTestCase()
53 {
54 g_inputInterfaces = IInputInterfaces::Get(true);
55 if (g_inputInterfaces != nullptr) {
56 g_callback = new InputCallbackImpl(g_inputInterfaces, nullptr);
57 g_hotplugCb = new InputCallbackImpl(g_inputInterfaces, g_callback);
58 }
59 }
60
TearDownTestCase()61 void HdfInputHdiTest::TearDownTestCase()
62 {
63 }
64
SetUp()65 void HdfInputHdiTest::SetUp()
66 {
67 }
68
TearDown()69 void HdfInputHdiTest::TearDown()
70 {
71 }
72
OpenOnlineDev(std::vector<DevDesc> sta)73 static void OpenOnlineDev(std::vector<DevDesc> sta)
74 {
75 int32_t ret = g_inputInterfaces->ScanInputDevice(sta);
76 if (ret != INPUT_SUCCESS) {
77 HDF_LOGE("%s: scan device failed, ret %d", __func__, ret);
78 }
79 ASSERT_EQ(ret, INPUT_SUCCESS);
80
81 for (int32_t i = 0; i < MAX_DEVICES; i++) {
82 if (sta[i].devIndex == 0) {
83 break;
84 }
85 ret = g_inputInterfaces->OpenInputDevice(sta[i].devIndex);
86 if (ret != INPUT_SUCCESS) {
87 HDF_LOGE("%s: open device[%d] failed, ret %d", __func__, sta[i].devIndex, ret);
88 }
89 ASSERT_EQ(ret, INPUT_SUCCESS);
90
91 ret = g_inputInterfaces->RegisterReportCallback(sta[i].devIndex, g_callback);
92 if (ret != INPUT_SUCCESS) {
93 HDF_LOGE("%s: register callback failed for device[%d], ret %d", __func__, sta[i].devIndex, ret);
94 }
95 ASSERT_EQ(ret, INPUT_SUCCESS);
96 }
97 }
98
CloseOnlineDev(std::vector<DevDesc> sta)99 static void CloseOnlineDev(std::vector<DevDesc> sta)
100 {
101 int32_t ret = g_inputInterfaces->ScanInputDevice(sta);
102 if (ret != INPUT_SUCCESS) {
103 HDF_LOGE("%s: scan device failed, ret %d", __func__, ret);
104 }
105 ASSERT_EQ(ret, INPUT_SUCCESS);
106
107 for (int32_t i = 0; i < MAX_DEVICES; i++) {
108 if (sta[i].devIndex == 0) {
109 break;
110 }
111 ret = g_inputInterfaces->UnregisterReportCallback(sta[i].devIndex);
112 HDF_LOGE("%{public}s: index = %{public}d", __func__, i);
113 if (ret != INPUT_SUCCESS) {
114 HDF_LOGE("%s: register callback failed for device[%d], ret %d", __func__, sta[i].devIndex, ret);
115 }
116 ASSERT_EQ(ret, INPUT_SUCCESS);
117
118 ret = g_inputInterfaces->CloseInputDevice(sta[i].devIndex);
119 if (ret != INPUT_SUCCESS) {
120 HDF_LOGE("%s: close device[%d] failed, ret %d", __func__, sta[i].devIndex, ret);
121 }
122 ASSERT_EQ(ret, INPUT_SUCCESS);
123 }
124 }
125
126 /**
127 * @tc.number: SUB_Driver_Input_Passthrough_0900
128 * @tc.name: GetInputClient001
129 * @tc.desc: Get a client and check whether the client is empty.
130 * @tc.type: func
131 * @tc.require:
132 */
133 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_0900, Function | MediumTest | Level1)
134 {
135 ASSERT_NE(nullptr, g_inputInterfaces);
136 }
137
138 /**
139 * @tc.number: SUB_Driver_Input_Passthrough_3100
140 * @tc.name: ScanInputDevice001
141 * @tc.desc: scan input device test
142 * @tc.type: FUNC
143 * @tc.require:
144 */
145 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_3100, Function | MediumTest | Level1)
146 {
147 if (g_inputInterfaces == nullptr) {
148 ASSERT_NE(nullptr, g_inputInterfaces);
149 return;
150 }
151 std::vector<DevDesc> sta;
152
153 HDF_LOGI("%s: [Hdi-Input] ScanInputDevice001 enter", __func__);
154 int32_t ret;
155
156 ret = g_inputInterfaces->ScanInputDevice(sta);
157 if (ret == INPUT_SUCCESS) {
158 HDF_LOGE("%s: %d, %d, %d, %d", __func__, sta[0].devType, sta[0].devIndex, sta[1].devType, sta[1].devIndex);
159 }
160
161 EXPECT_EQ(ret, INPUT_SUCCESS);
162 }
163
164 /**
165 * @tc.number: SUB_Driver_Input_Passthrough_2000
166 * @tc.name: OpenInputDev001
167 * @tc.desc: open input device test
168 * @tc.type: func
169 * @tc.require:
170 */
171 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_2000, Function | MediumTest | Level1)
172 {
173 if (g_inputInterfaces == nullptr) {
174 ASSERT_NE(nullptr, g_inputInterfaces);
175 return;
176 }
177 HDF_LOGI("%s: [Hdi-Input] OpenInputDevice001 enter", __func__);
178
179 int32_t ret = g_inputInterfaces->OpenInputDevice(TOUCH_INDEX);
180 if (ret != INPUT_SUCCESS) {
181 HDF_LOGE("%s: open device failed, ret %d", __func__, ret);
182 }
183 EXPECT_EQ(ret, INPUT_SUCCESS);
184 }
185
186 /**
187 * @tc.number: SUB_Driver_Input_Passthrough_2100
188 * @tc.name: OpenInputDev002
189 * @tc.desc: open input device test
190 * @tc.type: func
191 * @tc.require:
192 */
193 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_2100, Function | MediumTest | Level1)
194 {
195 if (g_inputInterfaces == nullptr) {
196 ASSERT_NE(nullptr, g_inputInterfaces);
197 return;
198 }
199 HDF_LOGI("%s: [Hdi-Input] OpenInputDevice002 enter", __func__);
200
201 /* Device "5" is used for testing nonexistent device node */
202 int32_t ret = g_inputInterfaces->OpenInputDevice(INVALID_INDEX);
203 if (ret != INPUT_SUCCESS) {
204 HDF_LOGE("%s: device %d does not exist, can't open it, ret %d", __func__, INVALID_INDEX, ret);
205 }
206 EXPECT_NE(ret, INPUT_SUCCESS);
207 }
208
209 /**
210 * @tc.number: SUB_Driver_Input_Passthrough_0100
211 * @tc.name: CloseInputDevice001
212 * @tc.desc: close input device test
213 * @tc.type: func
214 * @tc.require:
215 */
216 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_0100, Function | MediumTest | Level1)
217 {
218 if (g_inputInterfaces == nullptr) {
219 ASSERT_NE(nullptr, g_inputInterfaces);
220 return;
221 }
222 HDF_LOGI("%s: [hdi-input] CloseInputDevice001 enter", __func__);
223
224 int32_t ret = g_inputInterfaces->CloseInputDevice(TOUCH_INDEX);
225 if (ret != INPUT_SUCCESS) {
226 HDF_LOGE("%s: close device failed, ret %d", __func__, ret);
227 }
228 EXPECT_EQ(ret, INPUT_SUCCESS);
229 }
230
231 /**
232 * @tc.number: SUB_Driver_Input_Passthrough_0200
233 * @tc.name: CloseInputDevice002
234 * @tc.desc: close input device test
235 * @tc.type: func
236 * @tc.require:
237 */
238 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_0200, Function | MediumTest | Level1)
239 {
240 if (g_inputInterfaces == nullptr) {
241 ASSERT_NE(nullptr, g_inputInterfaces);
242 return;
243 }
244 HDF_LOGI("%s: [hdi-input] CloseInputDevice002 enter", __func__);
245
246 /* Device "5" is used for testing nonexistent device node */
247 int32_t ret = g_inputInterfaces->CloseInputDevice(INVALID_INDEX);
248 if (ret != INPUT_SUCCESS) {
249 HDF_LOGE("%s: device %d doesn't exist, can't close it, ret %d", __func__, INVALID_INDEX, ret);
250 }
251 EXPECT_NE(ret, INPUT_SUCCESS);
252 }
253
254 /**
255 * @tc.number: SUB_Driver_Input_Passthrough_1000
256 * @tc.name: GetInputDevice001
257 * @tc.desc: get input device info test
258 * @tc.type: func
259 * @tc.require:
260 */
261 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_1000, Function | MediumTest | Level1)
262 {
263 if (g_inputInterfaces == nullptr) {
264 ASSERT_NE(nullptr, g_inputInterfaces);
265 return;
266 }
267 HDF_LOGI("%s: [hdi-input] GetInputDevice001 enter", __func__);
268 struct DeviceInfo dev;
269
270 int32_t ret = g_inputInterfaces->OpenInputDevice(TOUCH_INDEX);
271 if (ret != INPUT_SUCCESS) {
272 HDF_LOGE("%s: open device failed, ret %d", __func__, ret);
273 }
274 ASSERT_EQ(ret, INPUT_SUCCESS);
275
276 ret = g_inputInterfaces->GetInputDevice(TOUCH_INDEX, dev);
277 if (ret != INPUT_SUCCESS) {
278 HDF_LOGE("%s: get device failed, ret %d", __func__, ret);
279 }
280 ASSERT_EQ(ret, INPUT_SUCCESS);
281
282 HDF_LOGI("%s: devindex = %u, devType = %u", __func__, dev.devIndex, dev.devType);
283 HDF_LOGI("%s: chipInfo = %s, vendorName = %s, chipName = %s",
284 __func__, dev.chipInfo.c_str(), dev.vendorName.c_str(), dev.chipName.c_str());
285 EXPECT_EQ(ret, INPUT_SUCCESS);
286 }
287
288 /**
289 * @tc.number: SUB_Driver_Input_Passthrough_1100
290 * @tc.name: GetInputDevice002
291 * @tc.desc: get input device info test
292 * @tc.type: func
293 * @tc.require:
294 */
295 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_1100, Function | MediumTest | Level1)
296 {
297 if (g_inputInterfaces == nullptr) {
298 ASSERT_NE(nullptr, g_inputInterfaces);
299 return;
300 }
301 HDF_LOGI("%s: [hdi-input] GetInputDevice002 enter", __func__);
302 struct DeviceInfo dev;
303
304 int32_t ret = g_inputInterfaces->GetInputDevice(INVALID_INDEX, dev);
305 if (ret != INPUT_SUCCESS) {
306 HDF_LOGE("%s: get device failed, ret %d", __func__, ret);
307 }
308 ASSERT_NE(ret, INPUT_SUCCESS);
309
310 HDF_LOGI("%s: devindex = %u, devType = %u", __func__, dev.devIndex, dev.devType);
311 HDF_LOGI("%s: chipInfo = %s, vendorName = %s, chipName = %s",
312 __func__, dev.chipInfo.c_str(), dev.vendorName.c_str(), dev.chipName.c_str());
313 EXPECT_NE(ret, INPUT_SUCCESS);
314 }
315
316 /**
317 * @tc.number: SUB_Driver_Input_Passthrough_1400
318 * @tc.name: GetInputDeviceList001
319 * @tc.desc: get input device list info test
320 * @tc.type: func
321 * @tc.require:
322 */
323 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_1400, Function | MediumTest | Level1)
324 {
325 if (g_inputInterfaces == nullptr) {
326 ASSERT_NE(nullptr, g_inputInterfaces);
327 return;
328 }
329 HDF_LOGI("%s: [hdi-input] GetInputDeviceList001 enter", __func__);
330 int32_t ret;
331 uint32_t num = 0;
332 std::vector<DeviceInfo> dev;
333
334 ret = g_inputInterfaces->GetInputDeviceList(num, dev, MAX_INPUT_DEV_NUM);
335 if (ret != INPUT_SUCCESS) {
336 HDF_LOGE("%s: get device list failed, ret %d", __func__, ret);
337 }
338 ret = num <= MAX_INPUT_DEV_NUM ? HDF_SUCCESS : HDF_FAILURE; /* num <= MAX_INPUT_DEV_NUM return true */
339 ASSERT_EQ(ret, HDF_SUCCESS);
340
341
342 for (uint32_t i = 0; i < num; i++) {
343 HDF_LOGI("%s: num = %u, device[%u]'s info is:", __func__, num, i);
344 HDF_LOGI("%s: index = %u, devType = %u", __func__, dev[i].devIndex, dev[i].devType);
345 HDF_LOGI("%s: chipInfo = %s, vendorName = %s, chipName = %s",
346 __func__, dev[i].chipInfo.c_str(), dev[i].vendorName.c_str(), dev[i].chipName.c_str());
347 }
348 EXPECT_EQ(ret, INPUT_SUCCESS);
349 }
350
351 /**
352 * @tc.number: SUB_Driver_Input_Passthrough_0700
353 * @tc.name: GetDeviceType001
354 * @tc.desc: get input device type test
355 * @tc.type: func
356 * @tc.require:
357 */
358 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_0700, Function | MediumTest | Level1)
359 {
360 if (g_inputInterfaces == nullptr) {
361 ASSERT_NE(nullptr, g_inputInterfaces);
362 return;
363 }
364 HDF_LOGI("%s: [hdi-input] GetDeviceType001 enter", __func__);
365 int32_t ret;
366 uint32_t devType = INIT_DEFAULT_VALUE;
367
368 ret = g_inputInterfaces->GetDeviceType(TOUCH_INDEX, devType);
369 if (ret != INPUT_SUCCESS) {
370 HDF_LOGE("%s: get device's type failed, ret %d", __func__, ret);
371 }
372 ASSERT_EQ(ret, INPUT_SUCCESS);
373
374 HDF_LOGI("%s: device's type is %u", __func__, devType);
375 EXPECT_EQ(ret, INPUT_SUCCESS);
376 }
377
378 /**
379 * @tc.number: SUB_Driver_Input_Passthrough_0800
380 * @tc.name: GetDeviceType002
381 * @tc.desc: get input device type test
382 * @tc.type: func
383 * @tc.require:
384 */
385 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_0800, Function | MediumTest | Level1)
386 {
387 if (g_inputInterfaces == nullptr) {
388 ASSERT_NE(nullptr, g_inputInterfaces);
389 return;
390 }
391 HDF_LOGI("%s: [hdi-input] GetDeviceType002 enter", __func__);
392 int32_t ret;
393 uint32_t devType = INIT_DEFAULT_VALUE;
394
395 ret = g_inputInterfaces->GetDeviceType(INVALID_INDEX, devType);
396 if (ret != INPUT_SUCCESS) {
397 HDF_LOGE("%s: get device's type failed, ret %d", __func__, ret);
398 }
399 ASSERT_NE(ret, INPUT_SUCCESS);
400
401 HDF_LOGI("%s: device's type is %u", __func__, devType);
402 EXPECT_NE(ret, INPUT_SUCCESS);
403 }
404
405 /**
406 * @tc.number: SUB_Driver_Input_Passthrough_0300
407 * @tc.name: GetChipInfo001
408 * @tc.desc: get input device chip info test
409 * @tc.type: func
410 * @tc.require:
411 */
412 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_0300, Function | MediumTest | Level1)
413 {
414 if (g_inputInterfaces == nullptr) {
415 ASSERT_NE(nullptr, g_inputInterfaces);
416 return;
417 }
418 HDF_LOGI("%s: [hdi-input] GetChipInfo001 enter", __func__);
419 int32_t ret;
420 std::string chipInfo;
421
422 ret = g_inputInterfaces->GetChipInfo(TOUCH_INDEX, chipInfo);
423 if (ret != INPUT_SUCCESS) {
424 HDF_LOGE("%s: get device's chip info failed, ret %d", __func__, ret);
425 }
426 ASSERT_EQ(ret, INPUT_SUCCESS);
427
428 HDF_LOGI("%s: device's chip info is %s", __func__, chipInfo.c_str());
429 EXPECT_EQ(ret, INPUT_SUCCESS);
430 }
431
432 /**
433 * @tc.number: SUB_Driver_Input_Passthrough_0400
434 * @tc.name: GetChipInfo002
435 * @tc.desc: get input device chip info test
436 * @tc.type: func
437 * @tc.require:
438 */
439 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_0400, Function | MediumTest | Level1)
440 {
441 if (g_inputInterfaces == nullptr) {
442 ASSERT_NE(nullptr, g_inputInterfaces);
443 return;
444 }
445 HDF_LOGI("%s: [hdi-input] GetChipInfo002 enter", __func__);
446 int32_t ret;
447 std::string chipInfo;
448
449 ret = g_inputInterfaces->GetChipInfo(INVALID_INDEX, chipInfo);
450 if (ret != INPUT_SUCCESS) {
451 HDF_LOGE("%s: get device's chip info failed, ret %d", __func__, ret);
452 }
453 ASSERT_NE(ret, INPUT_SUCCESS);
454
455 HDF_LOGI("%s: device's chip info is %s", __func__, chipInfo.c_str());
456 EXPECT_NE(ret, INPUT_SUCCESS);
457 }
458
459 /**
460 * @tc.number: SUB_Driver_Input_Passthrough_1200
461 * @tc.name: GetInputDevice003
462 * @tc.desc: get input device chip info test
463 * @tc.type: FUNC
464 * @tc.require:
465 */
466 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_1200, Function | MediumTest | Level1)
467 {
468 if (g_inputInterfaces == nullptr) {
469 ASSERT_NE(nullptr, g_inputInterfaces);
470 return;
471 }
472
473 HDF_LOGI("%s: [hdi-input] GetInputDevice003 enter", __func__);
474 struct DeviceInfo dev;
475
476 int32_t ret = g_inputInterfaces->GetInputDevice(TOUCH_INDEX, dev);
477 if (ret != INPUT_SUCCESS) {
478 HDF_LOGE("%s: get device failed, ret %d", __func__, ret);
479 }
480
481 HDF_LOGI("%s: After fill the info, new device's info is:", __func__);
482 HDF_LOGI("%s: new devIndex = %u, devType = %u", __func__, dev.devIndex, dev.devType);
483 HDF_LOGI("%s: new chipInfo = %s, vendorName = %s, chipName = %s",
484 __func__, dev.chipInfo.c_str(), dev.vendorName.c_str(), dev.chipName.c_str());
485 EXPECT_EQ(ret, INPUT_SUCCESS);
486 }
487
488 /**
489 * @tc.number: SUB_Driver_Input_Passthrough_1300
490 * @tc.name: GetInputDevice004
491 * @tc.desc: get input device chip info test
492 * @tc.type: FUNC
493 * @tc.require:
494 */
495 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_1300, Function | MediumTest | Level1)
496 {
497 if (g_inputInterfaces == nullptr) {
498 ASSERT_NE(nullptr, g_inputInterfaces);
499 return;
500 }
501
502 HDF_LOGI("%s: [hdi-input] GetInputDevice004 enter", __func__);
503 struct DeviceInfo dev;
504
505 int32_t ret = g_inputInterfaces->GetInputDevice(INVALID_INDEX, dev);
506 if (ret != INPUT_SUCCESS) {
507 HDF_LOGE("%s: get device failed, ret %d", __func__, ret);
508 }
509
510 HDF_LOGI("%s: After fill the info, new device's info is:", __func__);
511 HDF_LOGI("%s: new devIndex = %u, devType = %u", __func__, dev.devIndex, dev.devType);
512 HDF_LOGI("%s: new chipInfo = %s, vendorName = %s, chipName = %s",
513 __func__, dev.chipInfo.c_str(), dev.vendorName.c_str(), dev.chipName.c_str());
514 EXPECT_NE(ret, INPUT_SUCCESS);
515 }
516
517 /**
518 * @tc.number: SUB_Driver_Input_Passthrough_2200
519 * @tc.name: RegisterCallback001
520 * @tc.desc: register input device report test
521 * @tc.type: FUNC
522 * @tc.require:
523 */
524 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_2200, Function | MediumTest | Level1)
525 {
526 if (g_inputInterfaces == nullptr) {
527 ASSERT_NE(nullptr, g_inputInterfaces);
528 return;
529 }
530 HDF_LOGI("%s: [hdi-input] RegisterCallback001 enter", __func__);
531
532 /* Device "5" is used for testing nonexistent device node */
533 int32_t ret = g_inputInterfaces->RegisterReportCallback(INVALID_INDEX, g_callback);
534 if (ret != INPUT_SUCCESS) {
535 HDF_LOGE("%s: device %d dose not exist, can't register callback to it, ret %d", __func__, INVALID_INDEX, ret);
536 }
537 EXPECT_NE(ret, INPUT_SUCCESS);
538 }
539
540 /**
541 * @tc.number: SUB_Driver_Input_Passthrough_3400
542 * @tc.name: SetPowerStatus001
543 * @tc.desc: set device power status test
544 * @tc.type: func
545 * @tc.require:
546 */
547 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_3400, Function | MediumTest | Level1)
548 {
549 if (g_inputInterfaces == nullptr) {
550 ASSERT_NE(nullptr, g_inputInterfaces);
551 return;
552 }
553 HDF_LOGI("%s: [hdi-input] SetPowerStatus001 enter", __func__);
554 int32_t ret;
555 uint32_t setStatus = INPUT_LOW_POWER;
556
557 ret = g_inputInterfaces->SetPowerStatus(TOUCH_INDEX, setStatus);
558 if (ret != INPUT_SUCCESS) {
559 HDF_LOGE("%s: set device's power status failed, ret %d", __func__, ret);
560 }
561 EXPECT_EQ(ret, INPUT_SUCCESS);
562 }
563
564 /**
565 * @tc.number: SUB_Driver_Input_Passthrough_3500
566 * @tc.name: SetPowerStatus002
567 * @tc.desc: set device power status test
568 * @tc.type: func
569 * @tc.require:
570 */
571 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_3500, Function | MediumTest | Level1)
572 {
573 if (g_inputInterfaces == nullptr) {
574 ASSERT_NE(nullptr, g_inputInterfaces);
575 return;
576 }
577 HDF_LOGI("%s: [hdi-input] SetPowerStatus002 enter", __func__);
578 int32_t ret;
579 uint32_t setStatus = INPUT_SUSPEND;
580
581 ret = g_inputInterfaces->SetPowerStatus(TOUCH_INDEX, setStatus);
582 if (ret != INPUT_SUCCESS) {
583 HDF_LOGE("%s: set device's power status failed, ret %d", __func__, ret);
584 }
585 EXPECT_EQ(ret, INPUT_SUCCESS);
586 }
587
588 /**
589 * @tc.number: SUB_Driver_Input_Passthrough_3600
590 * @tc.name: SetPowerStatus003
591 * @tc.desc: set device power status test
592 * @tc.type: func
593 * @tc.require:
594 */
595 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_3600, Function | MediumTest | Level1)
596 {
597 if (g_inputInterfaces == nullptr) {
598 ASSERT_NE(nullptr, g_inputInterfaces);
599 return;
600 }
601 HDF_LOGI("%s: [hdi-input] SetPowerStatus003 enter", __func__);
602 int32_t ret;
603 uint32_t setStatus = INPUT_RESUME;
604
605 ret = g_inputInterfaces->SetPowerStatus(TOUCH_INDEX, setStatus);
606 if (ret != INPUT_SUCCESS) {
607 HDF_LOGE("%s: set device's power status failed, ret %d", __func__, ret);
608 }
609 EXPECT_EQ(ret, INPUT_SUCCESS);
610 }
611
612 /**
613 * @tc.number: SUB_Driver_Input_Passthrough_3700
614 * @tc.name: SetPowerStatus004
615 * @tc.desc: set device power status test
616 * @tc.type: func
617 * @tc.require:
618 */
619 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_3700, Function | MediumTest | Level1)
620 {
621 if (g_inputInterfaces == nullptr) {
622 ASSERT_NE(nullptr, g_inputInterfaces);
623 return;
624 }
625 HDF_LOGI("%s: [hdi-input] SetPowerStatus004 enter", __func__);
626 int32_t ret;
627 uint32_t setStatus = INPUT_LOW_POWER;
628 /* Device "5" is used for testing nonexistent device node */
629 ret = g_inputInterfaces->SetPowerStatus(INVALID_INDEX, setStatus);
630 if (ret != INPUT_SUCCESS) {
631 HDF_LOGE("%s: set device %d's power status failed, ret %d", __func__, INVALID_INDEX, ret);
632 }
633 EXPECT_NE(ret, INPUT_SUCCESS);
634 }
635
636 /**
637 * @tc.number: SUB_Driver_Input_Passthrough_1500
638 * @tc.name: GetPowerStatus001
639 * @tc.desc: get device power status test
640 * @tc.type: func
641 * @tc.require:
642 */
643 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_1500, Function | MediumTest | Level1)
644 {
645 if (g_inputInterfaces == nullptr) {
646 ASSERT_NE(nullptr, g_inputInterfaces);
647 return;
648 }
649 HDF_LOGI("%s: [hdi-input] GetPowerStatus001 enter", __func__);
650 int32_t ret;
651 uint32_t getStatus = 0;
652
653 ret = g_inputInterfaces->GetPowerStatus(TOUCH_INDEX, getStatus);
654 if (ret != INPUT_SUCCESS) {
655 HDF_LOGE("%s: get device's power status failed, ret %d", __func__, ret);
656 }
657 ASSERT_EQ(ret, INPUT_SUCCESS);
658
659 HDF_LOGI("%s: device's power status is %u:", __func__, getStatus);
660 EXPECT_EQ(ret, INPUT_SUCCESS);
661 }
662
663 /**
664 * @tc.number: SUB_Driver_Input_Passthrough_1600
665 * @tc.name: GetPowerStatus002
666 * @tc.desc: get device power status test
667 * @tc.type: func
668 * @tc.require:
669 */
670 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_1600, Function | MediumTest | Level1)
671 {
672 if (g_inputInterfaces == nullptr) {
673 ASSERT_NE(nullptr, g_inputInterfaces);
674 return;
675 }
676 HDF_LOGI("%s: [hdi-input] GetPowerStatus002 enter", __func__);
677 int32_t ret;
678 uint32_t getStatus = 0;
679 /* Device "5" is used for testing nonexistent device node */
680 ret = g_inputInterfaces->GetPowerStatus(INVALID_INDEX, getStatus);
681 if (ret != INPUT_SUCCESS) {
682 HDF_LOGE("%s: get device %d's power status failed, ret %d", __func__, INVALID_INDEX, ret);
683 }
684
685 EXPECT_NE(ret, INPUT_SUCCESS);
686 }
687
688 /**
689 * @tc.number: SUB_Driver_Input_Passthrough_1700
690 * @tc.name: GetVendorName001
691 * @tc.desc: get device vendor name test
692 * @tc.type: func
693 * @tc.require:
694 */
695 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_1700, Function | MediumTest | Level1)
696 {
697 if (g_inputInterfaces == nullptr) {
698 ASSERT_NE(nullptr, g_inputInterfaces);
699 return;
700 }
701 HDF_LOGI("%s: [hdi-input] GetVendorName001 enter", __func__);
702 int32_t ret;
703 std::string vendorName;
704
705 ret = g_inputInterfaces->GetVendorName(TOUCH_INDEX, vendorName);
706 if (ret != INPUT_SUCCESS) {
707 HDF_LOGE("%s: get device's vendor name failed, ret %d", __func__, ret);
708 }
709 ASSERT_EQ(ret, INPUT_SUCCESS);
710
711 HDF_LOGI("%s: device's vendor name is %s:", __func__, vendorName.c_str());
712 EXPECT_EQ(ret, INPUT_SUCCESS);
713 }
714
715 /**
716 * @tc.number: SUB_Driver_Input_Passthrough_1800
717 * @tc.name: GetVendorName002
718 * @tc.desc: get device vendor name test
719 * @tc.type: func
720 * @tc.require:
721 */
722 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_1800, Function | MediumTest | Level1)
723 {
724 if (g_inputInterfaces == nullptr) {
725 ASSERT_NE(nullptr, g_inputInterfaces);
726 return;
727 }
728 HDF_LOGI("%s: [hdi-input] GetVendorName002 enter", __func__);
729 int32_t ret;
730 std::string vendorName;
731 /* Device "5" is used for testing nonexistent device node */
732 ret = g_inputInterfaces->GetVendorName(INVALID_INDEX, vendorName);
733 if (ret != INPUT_SUCCESS) {
734 HDF_LOGE("%s: get device %d's vendor name failed, ret %d", __func__, INVALID_INDEX, ret);
735 }
736
737 EXPECT_NE(ret, INPUT_SUCCESS);
738 }
739
740 /**
741 * @tc.number: SUB_Driver_Input_Passthrough_0500
742 * @tc.name: GetChipName001
743 * @tc.desc: get device chip name test
744 * @tc.type: func
745 * @tc.require:
746 */
747 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_0500, Function | MediumTest | Level1)
748 {
749 if (g_inputInterfaces == nullptr) {
750 ASSERT_NE(nullptr, g_inputInterfaces);
751 return;
752 }
753 HDF_LOGI("%s: [hdi-input] GetChipName001 enter", __func__);
754 int32_t ret;
755 std::string chipName;
756
757 ret = g_inputInterfaces->GetChipName(TOUCH_INDEX, chipName);
758 if (ret != INPUT_SUCCESS) {
759 HDF_LOGE("%s: get device's chip name failed, ret %d", __func__, ret);
760 }
761 ASSERT_EQ(ret, INPUT_SUCCESS);
762
763 HDF_LOGI("%s: device's chip name is %s", __func__, chipName.c_str());
764 EXPECT_EQ(ret, INPUT_SUCCESS);
765 }
766
767 /**
768 * @tc.number: SUB_Driver_Input_Passthrough_0600
769 * @tc.name: GetChipName002
770 * @tc.desc: get device chip name test
771 * @tc.type: func
772 * @tc.require:
773 */
774 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_0600, Function | MediumTest | Level1)
775 {
776 if (g_inputInterfaces == nullptr) {
777 ASSERT_NE(nullptr, g_inputInterfaces);
778 return;
779 }
780 HDF_LOGI("%s: [hdi-input] GetChipName002 enter", __func__);
781 int32_t ret;
782 std::string chipName;
783 /* Device "5" is used for testing nonexistent device node */
784 ret = g_inputInterfaces->GetChipName(INVALID_INDEX, chipName);
785 if (ret != INPUT_SUCCESS) {
786 HDF_LOGE("%s: get device %d's chip name failed, ret %d", __func__, INVALID_INDEX, ret);
787 }
788
789 EXPECT_NE(ret, INPUT_SUCCESS);
790 }
791
792 /**
793 * @tc.number: SUB_Driver_Input_Passthrough_3200
794 * @tc.name: SetGestureMode001
795 * @tc.desc: set device gesture mode test
796 * @tc.type: func
797 * @tc.require:
798 */
799 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_3200, Function | MediumTest | Level1)
800 {
801 if (g_inputInterfaces == nullptr) {
802 ASSERT_NE(nullptr, g_inputInterfaces);
803 return;
804 }
805 HDF_LOGI("%s: [hdi-input] SetGestureMode001 enter", __func__);
806 int32_t ret;
807 uint32_t gestureMode = 1;
808
809 ret = g_inputInterfaces->SetGestureMode(TOUCH_INDEX, gestureMode);
810 if (ret != INPUT_SUCCESS) {
811 HDF_LOGE("%s: set device's gestureMode failed, ret %d", __func__, ret);
812 }
813 EXPECT_EQ(ret, INPUT_SUCCESS);
814 }
815
816 /**
817 * @tc.number: SUB_Driver_Input_Passthrough_3300
818 * @tc.name: SetGestureMode002
819 * @tc.desc: set device gesture mode test
820 * @tc.type: func
821 * @tc.require:
822 */
823 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_3300, Function | MediumTest | Level1)
824 {
825 if (g_inputInterfaces == nullptr) {
826 ASSERT_NE(nullptr, g_inputInterfaces);
827 return;
828 }
829 HDF_LOGI("%s: [hdi-input] SetGestureMode002 enter", __func__);
830 int32_t ret;
831 uint32_t gestureMode = 1;
832 /* Device "5" is used for testing nonexistent device node */
833 ret = g_inputInterfaces->SetGestureMode(INVALID_INDEX, gestureMode);
834 if (ret != INPUT_SUCCESS) {
835 HDF_LOGE("%s: set device %d's gestureMode failed, ret %d", __func__, INVALID_INDEX, ret);
836 }
837 EXPECT_NE(ret, INPUT_SUCCESS);
838 }
839
840 /**
841 * @tc.number: SUB_Driver_Input_Passthrough_2400
842 * @tc.name: RunCapacitanceTest001
843 * @tc.desc: run capacitanceTest test
844 * @tc.type: FUNC
845 * @tc.require:
846 */
847 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_2400, Function | MediumTest | Level1)
848 {
849 if (g_inputInterfaces == nullptr) {
850 ASSERT_NE(nullptr, g_inputInterfaces);
851 return;
852 }
853 HDF_LOGI("%s: [hdi-input] RunCapacitanceTest001 enter", __func__);
854 int32_t ret;
855 std::string result;
856 uint32_t testType = MMI_TEST;
857
858 ret = g_inputInterfaces->RunCapacitanceTest(TOUCH_INDEX, testType, result, TEST_RESULT_LEN);
859 if (ret != INPUT_SUCCESS) {
860 HDF_LOGE("%s: run capacitanceTest failed, ret %d", __func__, ret);
861 }
862 EXPECT_EQ(ret, INPUT_SUCCESS);
863 }
864
865 /**
866 * @tc.number: SUB_Driver_Input_Passthrough_2500
867 * @tc.name: RunCapacitanceTest002
868 * @tc.desc: run capacitanceTest test
869 * @tc.type: FUNC
870 * @tc.require:
871 */
872 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_2500, Function | MediumTest | Level1)
873 {
874 if (g_inputInterfaces == nullptr) {
875 ASSERT_NE(nullptr, g_inputInterfaces);
876 return;
877 }
878 HDF_LOGI("%s: [hdi-input] RunCapacitanceTest002 enter", __func__);
879 int32_t ret;
880 std::string result;
881 uint32_t testType = BASE_TEST;
882
883 ret = g_inputInterfaces->RunCapacitanceTest(TOUCH_INDEX, testType, result, TEST_RESULT_LEN);
884 if (ret != INPUT_SUCCESS) {
885 HDF_LOGE("%s: run capacitanceTest failed, ret %d", __func__, ret);
886 }
887 EXPECT_EQ(ret, INPUT_SUCCESS);
888 }
889
890 /**
891 * @tc.number: SUB_Driver_Input_Passthrough_2600
892 * @tc.name: RunCapacitanceTest003
893 * @tc.desc: run capacitanceTest test
894 * @tc.type: FUNC
895 * @tc.require:
896 */
897 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_2600, Function | MediumTest | Level1)
898 {
899 if (g_inputInterfaces == nullptr) {
900 ASSERT_NE(nullptr, g_inputInterfaces);
901 return;
902 }
903 HDF_LOGI("%s: [hdi-input] RunCapacitanceTest003 enter", __func__);
904 int32_t ret;
905 std::string result;
906 uint32_t testType = FULL_TEST;
907
908 ret = g_inputInterfaces->RunCapacitanceTest(TOUCH_INDEX, testType, result, TEST_RESULT_LEN);
909 if (ret != INPUT_SUCCESS) {
910 HDF_LOGE("%s: run capacitanceTest failed, ret %d", __func__, ret);
911 }
912 EXPECT_EQ(ret, INPUT_SUCCESS);
913 }
914
915 /**
916 * @tc.number: SUB_Driver_Input_Passthrough_2700
917 * @tc.name: RunCapacitanceTest004
918 * @tc.desc: run capacitanceTest test
919 * @tc.type: FUNC
920 * @tc.require:
921 */
922 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_2700, Function | MediumTest | Level1)
923 {
924 if (g_inputInterfaces == nullptr) {
925 ASSERT_NE(nullptr, g_inputInterfaces);
926 return;
927 }
928 HDF_LOGI("%s: [hdi-input] RunCapacitanceTest004 enter", __func__);
929 int32_t ret;
930 std::string result;
931 uint32_t testType = RUNNING_TEST;
932
933 ret = g_inputInterfaces->RunCapacitanceTest(TOUCH_INDEX, testType, result, TEST_RESULT_LEN);
934 if (ret != INPUT_SUCCESS) {
935 HDF_LOGE("%s: run capacitanceTest failed, ret %d", __func__, ret);
936 }
937 EXPECT_EQ(ret, INPUT_SUCCESS);
938 }
939
940 /**
941 * @tc.number: SUB_Driver_Input_Passthrough_2800
942 * @tc.name: RunCapacitanceTest005
943 * @tc.desc: run capacitanceTest test
944 * @tc.type: FUNC
945 * @tc.require:
946 */
947 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_2800, Function | MediumTest | Level1)
948 {
949 if (g_inputInterfaces == nullptr) {
950 ASSERT_NE(nullptr, g_inputInterfaces);
951 return;
952 }
953 HDF_LOGI("%s: [hdi-input] RunCapacitanceTest005 enter", __func__);
954 int32_t ret;
955 std::string result;
956 uint32_t testType = MMI_TEST;
957
958 ret = g_inputInterfaces->RunCapacitanceTest(INVALID_INDEX, testType, result, TEST_RESULT_LEN);
959 if (ret != INPUT_SUCCESS) {
960 HDF_LOGE("%s: run capacitanceTest failed, ret %d", __func__, ret);
961 }
962 EXPECT_NE(ret, INPUT_SUCCESS);
963 }
964
965 /**
966 * @tc.number: SUB_Driver_Input_Passthrough_2900
967 * @tc.name: RunExtraCommand001
968 * @tc.desc: run extra command test
969 * @tc.type: FUNC
970 * @tc.require:
971 */
972 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_2900, Function | MediumTest | Level1)
973 {
974 if (g_inputInterfaces == nullptr) {
975 ASSERT_NE(nullptr, g_inputInterfaces);
976 return;
977 }
978 HDF_LOGI("%s: [hdi-input] RunExtraCommand001 enter", __func__);
979 int32_t ret;
980 struct ExtraCmd extraCmd;
981 extraCmd.cmdCode = "WakeUpMode";
982 extraCmd.cmdValue = "Enable";
983
984 ret = g_inputInterfaces->RunExtraCommand(TOUCH_INDEX, extraCmd);
985 if (ret != INPUT_SUCCESS) {
986 HDF_LOGE("%s: run extraCommand failed, ret %d", __func__, ret);
987 }
988 EXPECT_EQ(ret, INPUT_SUCCESS);
989 }
990
991 /**
992 * @tc.number: SUB_Driver_Input_Passthrough_3000
993 * @tc.name: RunExtraCommand002
994 * @tc.desc: run extra command test
995 * @tc.type: FUNC
996 * @tc.require:
997 */
998 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_3000, Function | MediumTest | Level1)
999 {
1000 if (g_inputInterfaces == nullptr) {
1001 ASSERT_NE(nullptr, g_inputInterfaces);
1002 return;
1003 }
1004 HDF_LOGI("%s: [hdi-input] RunExtraCommand002 enter", __func__);
1005 int32_t ret;
1006 struct ExtraCmd extraCmd;
1007 extraCmd.cmdCode = "WakeUpMode";
1008 extraCmd.cmdValue = "Enable";
1009
1010 ret = g_inputInterfaces->RunExtraCommand(INVALID_INDEX, extraCmd);
1011 if (ret != INPUT_SUCCESS) {
1012 HDF_LOGE("%s: run extraCommand failed, ret %d", __func__, ret);
1013 }
1014 EXPECT_NE(ret, INPUT_SUCCESS);
1015 }
1016
1017 /**
1018 * @tc.number: SUB_Driver_Input_Passthrough_2300
1019 * @tc.name: RegisterCallbackAndReportData001
1020 * @tc.desc: register callback and report data test
1021 * @tc.type: func
1022 * @tc.require:
1023 */
1024 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_2300, Function | MediumTest | Level1)
1025 {
1026 if (g_inputInterfaces == nullptr) {
1027 ASSERT_NE(nullptr, g_inputInterfaces);
1028 return;
1029 }
1030 HDF_LOGI("%s: [hdi-input] RegisterCallbackAndReportData001 enter", __func__);
1031 int32_t ret;
1032
1033 ret = g_inputInterfaces->RegisterReportCallback(TOUCH_INDEX, g_callback);
1034 if (ret != INPUT_SUCCESS) {
1035 HDF_LOGE("%s: register callback failed for device 1, ret %d", __func__, ret);
1036 }
1037 ASSERT_EQ(ret, INPUT_SUCCESS);
1038 printf("%s: wait 15s for testing, pls touch the panel now\n", __func__);
1039 printf("%s: The event data is as following:\n", __func__);
1040 OsalMSleep(KEEP_ALIVE_TIME_MS);
1041 }
1042
1043 /**
1044 * @tc.number: SUB_Driver_Input_Passthrough_3800
1045 * @tc.name: UnregisterReportCallback001
1046 * @tc.desc: unregister reportCallback test
1047 * @tc.type: func
1048 * @tc.require:
1049 */
1050 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_3800, Function | MediumTest | Level1)
1051 {
1052 if (g_inputInterfaces == nullptr) {
1053 ASSERT_NE(nullptr, g_inputInterfaces);
1054 return;
1055 }
1056 HDF_LOGI("%s: [hdi-input] UnregisterReportCallback001 enter", __func__);
1057 int32_t ret;
1058
1059 ret = g_inputInterfaces->UnregisterReportCallback(TOUCH_INDEX);
1060 if (ret != INPUT_SUCCESS) {
1061 HDF_LOGE("%s: unregister callback failed for device, ret %d", __func__, ret);
1062 }
1063 EXPECT_EQ(ret, INPUT_SUCCESS);
1064
1065 ret = g_inputInterfaces->CloseInputDevice(TOUCH_INDEX);
1066 if (ret != INPUT_SUCCESS) {
1067 HDF_LOGE("%s: close device failed, ret %d", __func__, ret);
1068 }
1069 ASSERT_EQ(ret, INPUT_SUCCESS);
1070 }
1071
1072 /**
1073 * @tc.number: SUB_Driver_Input_Passthrough_1900
1074 * @tc.name: HotPlugCallback001
1075 * @tc.desc: input device hot plug test
1076 * @tc.type: FUNC
1077 * @tc.require:
1078 */
1079 HWTEST_F(HdfInputHdiTest, SUB_Driver_Input_Passthrough_1900, Function | MediumTest | Level1)
1080 {
1081 if (g_inputInterfaces == nullptr) {
1082 ASSERT_NE(nullptr, g_inputInterfaces);
1083 return;
1084 }
1085
1086 HDF_LOGI("%s: [hdi-input] HotPlugCallback001 enter", __func__);
1087 int32_t ret = INPUT_SUCCESS;
1088 std::vector<DevDesc> sta;
1089
1090 ret = g_inputInterfaces->RegisterHotPlugCallback(g_hotplugCb);
1091 if (ret != INPUT_SUCCESS) {
1092 HDF_LOGE("%s: register hotplug callback failed for device manager, ret %d", __func__, ret);
1093 }
1094 ASSERT_EQ(ret, INPUT_SUCCESS);
1095 OpenOnlineDev(sta);
1096
1097 printf("%s: wait 15s for testing, pls hotplug now\n", __func__);
1098 printf("%s: The event data is as following:\n", __func__);
1099 OsalMSleep(KEEP_ALIVE_TIME_MS);
1100
1101 CloseOnlineDev(sta);
1102
1103 ret = g_inputInterfaces->UnregisterHotPlugCallback();
1104 if (ret != INPUT_SUCCESS) {
1105 HDF_LOGE("%s: unregister hotplug callback failed for device manager, ret %d", __func__, ret);
1106 }
1107 EXPECT_EQ(ret, INPUT_SUCCESS);
1108 }
1109