• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.name: GetInputClient001
128   * @tc.desc: Get a client and check whether the client is empty.
129   * @tc.type: func
130   * @tc.require:
131   */
132 HWTEST_F(HdfInputHdiTest, GetInputClient001, TestSize.Level1)
133 {
134     ASSERT_NE(nullptr, g_inputInterfaces);
135 }
136 
137 /**
138   * @tc.name: ScanInputDevice001
139   * @tc.desc: scan input device test
140   * @tc.type: FUNC
141   * @tc.require:
142   */
143 HWTEST_F(HdfInputHdiTest, ScanInputDevice001, TestSize.Level1)
144 {
145     if (g_inputInterfaces == nullptr) {
146         ASSERT_NE(nullptr, g_inputInterfaces);
147         return;
148     }
149     std::vector<DevDesc> sta;
150 
151     HDF_LOGI("%s: [Hdi-Input] ScanInputDevice001 enter", __func__);
152     int32_t ret;
153 
154     ret  = g_inputInterfaces->ScanInputDevice(sta);
155     if (ret == INPUT_SUCCESS) {
156         HDF_LOGE("%s: %d, %d, %d, %d", __func__, sta[0].devType, sta[0].devIndex, sta[1].devType, sta[1].devIndex);
157     }
158 
159     EXPECT_EQ(ret, INPUT_SUCCESS);
160 }
161 
162 /**
163   * @tc.name: OpenInputDev001
164   * @tc.desc: open input device test
165   * @tc.type: func
166   * @tc.require:
167   */
168 HWTEST_F(HdfInputHdiTest, OpenInputDevice001, TestSize.Level1)
169 {
170     if (g_inputInterfaces == nullptr) {
171         ASSERT_NE(nullptr, g_inputInterfaces);
172         return;
173     }
174     HDF_LOGI("%s: [Hdi-Input] OpenInputDevice001 enter", __func__);
175 
176     int32_t ret = g_inputInterfaces->OpenInputDevice(TOUCH_INDEX);
177     if (ret != INPUT_SUCCESS) {
178         HDF_LOGE("%s: open device failed, ret %d", __func__, ret);
179     }
180     EXPECT_EQ(ret, INPUT_SUCCESS);
181 }
182 
183 /**
184   * @tc.name: OpenInputDev002
185   * @tc.desc: open input device test
186   * @tc.type: func
187   * @tc.require:
188   */
189 HWTEST_F(HdfInputHdiTest, OpenInputDevice002, TestSize.Level1)
190 {
191     if (g_inputInterfaces == nullptr) {
192         ASSERT_NE(nullptr, g_inputInterfaces);
193         return;
194     }
195     HDF_LOGI("%s: [Hdi-Input] OpenInputDevice002 enter", __func__);
196 
197     /* Device "5" is used for testing nonexistent device node */
198     int32_t ret = g_inputInterfaces->OpenInputDevice(INVALID_INDEX);
199     if (ret != INPUT_SUCCESS) {
200         HDF_LOGE("%s: device %d does not exist, can't open it, ret %d", __func__, INVALID_INDEX, ret);
201     }
202     EXPECT_NE(ret, INPUT_SUCCESS);
203 }
204 
205 /**
206   * @tc.name: CloseInputDevice001
207   * @tc.desc: close input device test
208   * @tc.type: func
209   * @tc.require:
210   */
211 HWTEST_F(HdfInputHdiTest, CloseInputDevice001, TestSize.Level1)
212 {
213     if (g_inputInterfaces == nullptr) {
214         ASSERT_NE(nullptr, g_inputInterfaces);
215         return;
216     }
217     HDF_LOGI("%s: [hdi-input] CloseInputDevice001 enter", __func__);
218 
219     int32_t ret = g_inputInterfaces->CloseInputDevice(TOUCH_INDEX);
220     if (ret != INPUT_SUCCESS) {
221         HDF_LOGE("%s: close device failed, ret %d", __func__, ret);
222     }
223     EXPECT_EQ(ret, INPUT_SUCCESS);
224 }
225 
226 /**
227   * @tc.name: CloseInputDevice002
228   * @tc.desc: close input device test
229   * @tc.type: func
230   * @tc.require:
231   */
232 HWTEST_F(HdfInputHdiTest, CloseInputDevice002, TestSize.Level1)
233 {
234     if (g_inputInterfaces == nullptr) {
235         ASSERT_NE(nullptr, g_inputInterfaces);
236         return;
237     }
238     HDF_LOGI("%s: [hdi-input] CloseInputDevice002 enter", __func__);
239 
240     /* Device "5" is used for testing nonexistent device node */
241     int32_t ret = g_inputInterfaces->CloseInputDevice(INVALID_INDEX);
242     if (ret != INPUT_SUCCESS) {
243         HDF_LOGE("%s: device %d doesn't exist, can't close it, ret %d", __func__, INVALID_INDEX, ret);
244     }
245     EXPECT_NE(ret, INPUT_SUCCESS);
246 }
247 
248 /**
249   * @tc.name: GetInputDevice001
250   * @tc.desc: get input device info test
251   * @tc.type: func
252   * @tc.require:
253   */
254 HWTEST_F(HdfInputHdiTest, GetInputDevice001, TestSize.Level1)
255 {
256     if (g_inputInterfaces == nullptr) {
257         ASSERT_NE(nullptr, g_inputInterfaces);
258         return;
259     }
260     HDF_LOGI("%s: [hdi-input] GetInputDevice001 enter", __func__);
261     struct DeviceInfo dev;
262 
263     int32_t ret = g_inputInterfaces->OpenInputDevice(TOUCH_INDEX);
264     if (ret != INPUT_SUCCESS) {
265         HDF_LOGE("%s: open device failed, ret %d", __func__, ret);
266     }
267     ASSERT_EQ(ret, INPUT_SUCCESS);
268 
269     ret = g_inputInterfaces->GetInputDevice(TOUCH_INDEX, dev);
270     if (ret != INPUT_SUCCESS) {
271         HDF_LOGE("%s: get device failed, ret %d", __func__, ret);
272     }
273     ASSERT_EQ(ret, INPUT_SUCCESS);
274 
275     HDF_LOGI("%s: devindex = %u, devType = %u", __func__, dev.devIndex, dev.devType);
276     HDF_LOGI("%s: chipInfo = %s, vendorName = %s, chipName = %s",
277         __func__, dev.chipInfo.c_str(), dev.vendorName.c_str(), dev.chipName.c_str());
278     EXPECT_EQ(ret, INPUT_SUCCESS);
279 }
280 
281 /**
282   * @tc.name: GetInputDeviceList001
283   * @tc.desc: get input device list info test
284   * @tc.type: func
285   * @tc.require:
286   */
287 HWTEST_F(HdfInputHdiTest, GetInputDeviceList001, TestSize.Level1)
288 {
289     if (g_inputInterfaces == nullptr) {
290         ASSERT_NE(nullptr, g_inputInterfaces);
291         return;
292     }
293     HDF_LOGI("%s: [hdi-input] GetInputDeviceList001 enter", __func__);
294     int32_t ret;
295     uint32_t num = 0;
296     std::vector<DeviceInfo> dev;
297 
298     ret = g_inputInterfaces->GetInputDeviceList(num, dev, MAX_INPUT_DEV_NUM);
299     if (ret != INPUT_SUCCESS) {
300         HDF_LOGE("%s: get device list failed, ret %d", __func__, ret);
301     }
302     ret = num <= MAX_INPUT_DEV_NUM ? HDF_SUCCESS : HDF_FAILURE;  /* num <= MAX_INPUT_DEV_NUM return true */
303     ASSERT_EQ(ret, HDF_SUCCESS);
304 
305 
306     for (uint32_t i = 0; i < num; i++) {
307         HDF_LOGI("%s: num = %u, device[%u]'s info is:", __func__, num, i);
308         HDF_LOGI("%s: index = %u, devType = %u", __func__, dev[i].devIndex, dev[i].devType);
309         HDF_LOGI("%s: chipInfo = %s, vendorName = %s, chipName = %s",
310             __func__, dev[i].chipInfo.c_str(), dev[i].vendorName.c_str(), dev[i].chipName.c_str());
311     }
312     EXPECT_EQ(ret, INPUT_SUCCESS);
313 }
314 
315 /**
316   * @tc.name: GetDeviceType001
317   * @tc.desc: get input device type test
318   * @tc.type: func
319   * @tc.require:
320   */
321 HWTEST_F(HdfInputHdiTest, GetDeviceType001, TestSize.Level1)
322 {
323     if (g_inputInterfaces == nullptr) {
324         ASSERT_NE(nullptr, g_inputInterfaces);
325         return;
326     }
327     HDF_LOGI("%s: [hdi-input] GetDeviceType001 enter", __func__);
328     int32_t ret;
329     uint32_t devType = INIT_DEFAULT_VALUE;
330 
331     ret = g_inputInterfaces->GetDeviceType(TOUCH_INDEX, devType);
332     if (ret != INPUT_SUCCESS) {
333         HDF_LOGE("%s: get device's type failed, ret %d", __func__, ret);
334     }
335     ASSERT_EQ(ret, INPUT_SUCCESS);
336 
337     HDF_LOGI("%s: device's type is %u", __func__, devType);
338     EXPECT_EQ(ret, INPUT_SUCCESS);
339 }
340 
341 /**
342   * @tc.name: GetChipInfo001
343   * @tc.desc: get input device chip info test
344   * @tc.type: func
345   * @tc.require:
346   */
347 HWTEST_F(HdfInputHdiTest, GetChipInfo001, TestSize.Level1)
348 {
349     if (g_inputInterfaces == nullptr) {
350         ASSERT_NE(nullptr, g_inputInterfaces);
351         return;
352     }
353     HDF_LOGI("%s: [hdi-input] GetChipInfo001 enter", __func__);
354     int32_t ret;
355     std::string chipInfo;
356 
357     ret = g_inputInterfaces->GetChipInfo(TOUCH_INDEX, chipInfo);
358     if (ret != INPUT_SUCCESS) {
359         HDF_LOGE("%s: get device's chip info failed, ret %d", __func__, ret);
360     }
361     ASSERT_EQ(ret, INPUT_SUCCESS);
362 
363     HDF_LOGI("%s: device's chip info is %s", __func__, chipInfo.c_str());
364     EXPECT_EQ(ret, INPUT_SUCCESS);
365 }
366 
367 /**
368   * @tc.name: GetInputDevice002
369   * @tc.desc: get input device chip info test
370   * @tc.type: FUNC
371   * @tc.require:
372   */
373 HWTEST_F(HdfInputHdiTest, GetInputDevice002, TestSize.Level1)
374 {
375     if (g_inputInterfaces == nullptr) {
376         ASSERT_NE(nullptr, g_inputInterfaces);
377         return;
378     }
379 
380     HDF_LOGI("%s: [hdi-input] GetInputDevice002 enter", __func__);
381     struct DeviceInfo dev;
382 
383     int32_t ret = g_inputInterfaces->GetInputDevice(TOUCH_INDEX, dev);
384     if (ret != INPUT_SUCCESS) {
385         HDF_LOGE("%s: get device failed, ret %d", __func__, ret);
386     }
387 
388     HDF_LOGI("%s: After fill the info, new device's info is:", __func__);
389     HDF_LOGI("%s: new devIndex = %u, devType = %u", __func__, dev.devIndex, dev.devType);
390     HDF_LOGI("%s: new chipInfo = %s, vendorName = %s, chipName = %s",
391         __func__, dev.chipInfo.c_str(), dev.vendorName.c_str(), dev.chipName.c_str());
392     EXPECT_EQ(ret, INPUT_SUCCESS);
393 }
394 
395 /**
396   * @tc.name: RegisterCallback001
397   * @tc.desc: register input device report test
398   * @tc.type: FUNC
399   * @tc.require:
400   */
401 HWTEST_F(HdfInputHdiTest, RegisterCallback001, TestSize.Level1)
402 {
403     if (g_inputInterfaces == nullptr) {
404         ASSERT_NE(nullptr, g_inputInterfaces);
405         return;
406     }
407     HDF_LOGI("%s: [hdi-input] RegisterCallback001 enter", __func__);
408 
409     /* Device "5" is used for testing nonexistent device node */
410     int32_t ret  = g_inputInterfaces->RegisterReportCallback(INVALID_INDEX, g_callback);
411     if (ret != INPUT_SUCCESS) {
412         HDF_LOGE("%s: device %d dose not exist, can't register callback to it, ret %d", __func__, INVALID_INDEX, ret);
413     }
414     EXPECT_NE(ret, INPUT_SUCCESS);
415 }
416 
417 /**
418   * @tc.name: SetPowerStatus001
419   * @tc.desc: set device power status test
420   * @tc.type: func
421   * @tc.require:
422   */
423 HWTEST_F(HdfInputHdiTest, SetPowerStatus001, TestSize.Level1)
424 {
425     if (g_inputInterfaces == nullptr) {
426         ASSERT_NE(nullptr, g_inputInterfaces);
427         return;
428     }
429     HDF_LOGI("%s: [hdi-input] SetPowerStatus001 enter", __func__);
430     int32_t ret;
431     uint32_t setStatus = INPUT_LOW_POWER;
432 
433     ret = g_inputInterfaces->SetPowerStatus(TOUCH_INDEX, setStatus);
434     if (ret != INPUT_SUCCESS) {
435         HDF_LOGE("%s: set device's power status failed, ret %d", __func__, ret);
436     }
437     EXPECT_EQ(ret, INPUT_SUCCESS);
438 }
439 
440 /**
441   * @tc.name: SetPowerStatus002
442   * @tc.desc: set device power status test
443   * @tc.type: func
444   * @tc.require:
445   */
446 HWTEST_F(HdfInputHdiTest, SetPowerStatus002, TestSize.Level1)
447 {
448     if (g_inputInterfaces == nullptr) {
449         ASSERT_NE(nullptr, g_inputInterfaces);
450         return;
451     }
452     HDF_LOGI("%s: [hdi-input] SetPowerStatus002 enter", __func__);
453     int32_t ret;
454     uint32_t setStatus = INPUT_LOW_POWER;
455     /* Device "5" is used for testing nonexistent device node */
456     ret = g_inputInterfaces->SetPowerStatus(INVALID_INDEX, setStatus);
457     if (ret != INPUT_SUCCESS) {
458         HDF_LOGE("%s: set device %d's power status failed, ret %d", __func__, INVALID_INDEX, ret);
459     }
460     EXPECT_NE(ret, INPUT_SUCCESS);
461 }
462 
463 /**
464   * @tc.name: GetPowerStatus001
465   * @tc.desc: get device power status test
466   * @tc.type: func
467   * @tc.require:
468   */
469 HWTEST_F(HdfInputHdiTest, GetPowerStatus001, TestSize.Level1)
470 {
471     if (g_inputInterfaces == nullptr) {
472         ASSERT_NE(nullptr, g_inputInterfaces);
473         return;
474     }
475     HDF_LOGI("%s: [hdi-input] GetPowerStatus001 enter", __func__);
476     int32_t ret;
477     uint32_t getStatus = 0;
478 
479     ret = g_inputInterfaces->GetPowerStatus(TOUCH_INDEX, getStatus);
480     if (ret != INPUT_SUCCESS) {
481         HDF_LOGE("%s: get device's power status failed, ret %d", __func__, ret);
482     }
483     ASSERT_EQ(ret, INPUT_SUCCESS);
484 
485     HDF_LOGI("%s: device's power status is %u:", __func__, getStatus);
486     EXPECT_EQ(ret, INPUT_SUCCESS);
487 }
488 
489 /**
490   * @tc.name: GetPowerStatus002
491   * @tc.desc: get device power status test
492   * @tc.type: func
493   * @tc.require:
494   */
495 HWTEST_F(HdfInputHdiTest, GetPowerStatus002, TestSize.Level1)
496 {
497     if (g_inputInterfaces == nullptr) {
498         ASSERT_NE(nullptr, g_inputInterfaces);
499         return;
500     }
501     HDF_LOGI("%s: [hdi-input] GetPowerStatus002 enter", __func__);
502     int32_t ret;
503     uint32_t getStatus = 0;
504     /* Device "5" is used for testing nonexistent device node */
505     ret = g_inputInterfaces->GetPowerStatus(INVALID_INDEX, getStatus);
506     if (ret != INPUT_SUCCESS) {
507         HDF_LOGE("%s: get device %d's power status failed, ret %d", __func__, INVALID_INDEX, ret);
508     }
509 
510     EXPECT_NE(ret, INPUT_SUCCESS);
511 }
512 
513 /**
514   * @tc.name: GetVendorName001
515   * @tc.desc: get device vendor name test
516   * @tc.type: func
517   * @tc.require:
518   */
519 HWTEST_F(HdfInputHdiTest, GetVendorName001, TestSize.Level1)
520 {
521     if (g_inputInterfaces == nullptr) {
522         ASSERT_NE(nullptr, g_inputInterfaces);
523         return;
524     }
525     HDF_LOGI("%s: [hdi-input] GetVendorName001 enter", __func__);
526     int32_t ret;
527     std::string vendorName;
528 
529     ret = g_inputInterfaces->GetVendorName(TOUCH_INDEX, vendorName);
530     if (ret != INPUT_SUCCESS) {
531         HDF_LOGE("%s: get device's vendor name failed, ret %d", __func__, ret);
532     }
533     ASSERT_EQ(ret, INPUT_SUCCESS);
534 
535     HDF_LOGI("%s: device's vendor name is %s:", __func__, vendorName.c_str());
536     EXPECT_EQ(ret, INPUT_SUCCESS);
537 }
538 
539 /**
540   * @tc.name: GetVendorName002
541   * @tc.desc: get device vendor name test
542   * @tc.type: func
543   * @tc.require:
544   */
545 HWTEST_F(HdfInputHdiTest, GetVendorName002, TestSize.Level1)
546 {
547     if (g_inputInterfaces == nullptr) {
548         ASSERT_NE(nullptr, g_inputInterfaces);
549         return;
550     }
551     HDF_LOGI("%s: [hdi-input] GetVendorName002 enter", __func__);
552     int32_t ret;
553     std::string vendorName;
554     /* Device "5" is used for testing nonexistent device node */
555     ret = g_inputInterfaces->GetVendorName(INVALID_INDEX, vendorName);
556     if (ret != INPUT_SUCCESS) {
557         HDF_LOGE("%s: get device %d's vendor name failed, ret %d", __func__, INVALID_INDEX, ret);
558     }
559 
560     EXPECT_NE(ret, INPUT_SUCCESS);
561 }
562 
563 /**
564   * @tc.name: GetChipName001
565   * @tc.desc: get device chip name test
566   * @tc.type: func
567   * @tc.require:
568   */
569 HWTEST_F(HdfInputHdiTest, GetChipName001, TestSize.Level1)
570 {
571     if (g_inputInterfaces == nullptr) {
572         ASSERT_NE(nullptr, g_inputInterfaces);
573         return;
574     }
575     HDF_LOGI("%s: [hdi-input] GetChipName001 enter", __func__);
576     int32_t ret;
577     std::string chipName;
578 
579     ret = g_inputInterfaces->GetChipName(TOUCH_INDEX, chipName);
580     if (ret != INPUT_SUCCESS) {
581         HDF_LOGE("%s: get device's chip name failed, ret %d", __func__, ret);
582     }
583     ASSERT_EQ(ret, INPUT_SUCCESS);
584 
585     HDF_LOGI("%s: device's chip name is %s", __func__, chipName.c_str());
586     EXPECT_EQ(ret, INPUT_SUCCESS);
587 }
588 
589 /**
590   * @tc.name: GetChipName002
591   * @tc.desc: get device chip name test
592   * @tc.type: func
593   * @tc.require:
594   */
595 HWTEST_F(HdfInputHdiTest, GetChipName002, TestSize.Level1)
596 {
597     if (g_inputInterfaces == nullptr) {
598         ASSERT_NE(nullptr, g_inputInterfaces);
599         return;
600     }
601     HDF_LOGI("%s: [hdi-input] GetChipName002 enter", __func__);
602     int32_t ret;
603     std::string chipName;
604     /* Device "5" is used for testing nonexistent device node */
605     ret = g_inputInterfaces->GetChipName(INVALID_INDEX, chipName);
606     if (ret != INPUT_SUCCESS) {
607         HDF_LOGE("%s: get device %d's chip name failed, ret %d", __func__, INVALID_INDEX, ret);
608     }
609 
610     EXPECT_NE(ret, INPUT_SUCCESS);
611 }
612 
613 /**
614   * @tc.name: SetGestureMode001
615   * @tc.desc: set device gesture mode test
616   * @tc.type: func
617   * @tc.require:
618   */
619 HWTEST_F(HdfInputHdiTest, SetGestureMode001, TestSize.Level1)
620 {
621     if (g_inputInterfaces == nullptr) {
622         ASSERT_NE(nullptr, g_inputInterfaces);
623         return;
624     }
625     HDF_LOGI("%s: [hdi-input] SetGestureMode001 enter", __func__);
626     int32_t ret;
627     uint32_t gestureMode = 1;
628 
629     ret = g_inputInterfaces->SetGestureMode(TOUCH_INDEX, gestureMode);
630     if (ret != INPUT_SUCCESS) {
631         HDF_LOGE("%s: set device's gestureMode failed, ret %d", __func__, ret);
632     }
633     EXPECT_EQ(ret, INPUT_SUCCESS);
634 }
635 
636 /**
637   * @tc.name: SetGestureMode002
638   * @tc.desc: set device gesture mode test
639   * @tc.type: func
640   * @tc.require:
641   */
642 HWTEST_F(HdfInputHdiTest, SetGestureMode002, TestSize.Level1)
643 {
644     if (g_inputInterfaces == nullptr) {
645         ASSERT_NE(nullptr, g_inputInterfaces);
646         return;
647     }
648     HDF_LOGI("%s: [hdi-input] SetGestureMode002 enter", __func__);
649     int32_t ret;
650     uint32_t gestureMode = 1;
651     /* Device "5" is used for testing nonexistent device node */
652     ret = g_inputInterfaces->SetGestureMode(INVALID_INDEX, gestureMode);
653     if (ret != INPUT_SUCCESS) {
654         HDF_LOGE("%s: set device %d's gestureMode failed, ret %d", __func__, INVALID_INDEX, ret);
655     }
656     EXPECT_NE(ret, INPUT_SUCCESS);
657 }
658 
659 /**
660   * @tc.name: RunCapacitanceTest001
661   * @tc.desc: run capacitanceTest test
662   * @tc.type: FUNC
663   * @tc.require:
664   */
665 HWTEST_F(HdfInputHdiTest, RunCapacitanceTest001, TestSize.Level1)
666 {
667     if (g_inputInterfaces == nullptr) {
668         ASSERT_NE(nullptr, g_inputInterfaces);
669         return;
670     }
671     HDF_LOGI("%s: [hdi-input] RunCapacitanceTest001 enter", __func__);
672     int32_t ret;
673     std::string result;
674     uint32_t testType = MMI_TEST;
675 
676     ret = g_inputInterfaces->RunCapacitanceTest(TOUCH_INDEX, testType, result, TEST_RESULT_LEN);
677     if (ret != INPUT_SUCCESS) {
678         HDF_LOGE("%s: run capacitanceTest failed, ret %d", __func__, ret);
679     }
680     EXPECT_EQ(ret, INPUT_SUCCESS);
681 }
682 
683 /**
684   * @tc.name: RunExtraCommand001
685   * @tc.desc: run extra command test
686   * @tc.type: FUNC
687   * @tc.require:
688   */
689 HWTEST_F(HdfInputHdiTest, RunExtraCommand001, TestSize.Level1)
690 {
691     if (g_inputInterfaces == nullptr) {
692         ASSERT_NE(nullptr, g_inputInterfaces);
693         return;
694     }
695     HDF_LOGI("%s: [hdi-input] RunExtraCommand001 enter", __func__);
696     int32_t ret;
697     struct ExtraCmd extraCmd;
698     extraCmd.cmdCode = "WakeUpMode";
699     extraCmd.cmdValue = "Enable";
700 
701     ret = g_inputInterfaces->RunExtraCommand(TOUCH_INDEX, extraCmd);
702     if (ret != INPUT_SUCCESS) {
703         HDF_LOGE("%s: run extraCommand failed, ret %d", __func__, ret);
704     }
705     EXPECT_EQ(ret, INPUT_SUCCESS);
706 }
707 
708 /**
709   * @tc.name: RegisterCallbackAndReportData001
710   * @tc.desc: register callback and report data test
711   * @tc.type: func
712   * @tc.require:
713   */
714 HWTEST_F(HdfInputHdiTest, RegisterCallbackAndReportData001, TestSize.Level1)
715 {
716     if (g_inputInterfaces == nullptr) {
717         ASSERT_NE(nullptr, g_inputInterfaces);
718         return;
719     }
720     HDF_LOGI("%s: [hdi-input] RegisterCallbackAndReportData001 enter", __func__);
721     int32_t ret;
722 
723     ret = g_inputInterfaces->RegisterReportCallback(TOUCH_INDEX, g_callback);
724     if (ret != INPUT_SUCCESS) {
725         HDF_LOGE("%s: register callback failed for device 1, ret %d", __func__, ret);
726     }
727     ASSERT_EQ(ret, INPUT_SUCCESS);
728     printf("%s: wait 15s for testing, pls touch the panel now\n", __func__);
729     printf("%s: The event data is as following:\n", __func__);
730     OsalMSleep(KEEP_ALIVE_TIME_MS);
731 }
732 
733 /**
734   * @tc.name: UnregisterReportCallback001
735   * @tc.desc: unregister reportCallback test
736   * @tc.type: func
737   * @tc.require:
738   */
739 HWTEST_F(HdfInputHdiTest, UnregisterReportCallback001, TestSize.Level1)
740 {
741     if (g_inputInterfaces == nullptr) {
742         ASSERT_NE(nullptr, g_inputInterfaces);
743         return;
744     }
745     HDF_LOGI("%s: [hdi-input] UnregisterReportCallback001 enter", __func__);
746     int32_t ret;
747 
748     ret  = g_inputInterfaces->UnregisterReportCallback(TOUCH_INDEX);
749     if (ret != INPUT_SUCCESS) {
750         HDF_LOGE("%s: unregister callback failed for device, ret %d", __func__, ret);
751     }
752     EXPECT_EQ(ret, INPUT_SUCCESS);
753 
754     ret = g_inputInterfaces->CloseInputDevice(TOUCH_INDEX);
755     if (ret != INPUT_SUCCESS) {
756         HDF_LOGE("%s: close device failed, ret %d", __func__, ret);
757     }
758     ASSERT_EQ(ret, INPUT_SUCCESS);
759 }
760 
761 /**
762   * @tc.name: HotPlugCallback001
763   * @tc.desc: input device hot plug test
764   * @tc.type: FUNC
765   * @tc.require:
766   */
767 HWTEST_F(HdfInputHdiTest, HotPlugCallback001, TestSize.Level1)
768 {
769     if (g_inputInterfaces == nullptr) {
770         ASSERT_NE(nullptr, g_inputInterfaces);
771         return;
772     }
773 
774     HDF_LOGI("%s: [hdi-input] HotPlugCallback001 enter", __func__);
775     int32_t ret = INPUT_SUCCESS;
776     std::vector<DevDesc> sta;
777 
778     ret = g_inputInterfaces->RegisterHotPlugCallback(g_hotplugCb);
779     if (ret != INPUT_SUCCESS) {
780         HDF_LOGE("%s: register hotplug callback failed for device manager, ret %d", __func__, ret);
781     }
782     ASSERT_EQ(ret, INPUT_SUCCESS);
783     OpenOnlineDev(sta);
784 
785     printf("%s: wait 15s for testing, pls hotplug now\n", __func__);
786     printf("%s: The event data is as following:\n", __func__);
787     OsalMSleep(KEEP_ALIVE_TIME_MS);
788 
789     CloseOnlineDev(sta);
790 
791     ret = g_inputInterfaces->UnregisterHotPlugCallback();
792     if (ret != INPUT_SUCCESS) {
793         HDF_LOGE("%s: unregister hotplug callback failed for device manager, ret %d", __func__, ret);
794     }
795     EXPECT_EQ(ret, INPUT_SUCCESS);
796 }
797