1/*
2 * Copyright (c) 2021 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 "hdi_input_test.h"
17#include <cstdint>
18#include <cstdio>
19#include <cstdlib>
20#include <string>
21#include <unistd.h>
22#include <fcntl.h>
23#include <gtest/gtest.h>
24#include <securec.h>
25#include "osal_time.h"
26#include "hdf_log.h"
27#include "input_manager.h"
28
29using namespace testing::ext;
30
31IInputInterface *g_inputInterface;
32InputEventCb g_callback;
33InputHostCb g_hotplugCb;
34static bool g_hasDev = false;
35
36static void ReportHotPlugEventPkgCallback(const InputHotPlugEvent *msg);
37static void ReportEventPkgCallback(const InputEventPackage **pkgs, uint32_t count, uint32_t devIndex);
38static void CloseOnlineDev(InputDevDesc *sta, int32_t len);
39static void OpenOnlineDev(InputDevDesc *sta, int32_t len);
40
41class HdiInputTest : public testing::Test {
42public:
43    static void SetUpTestCase();
44    static void TearDownTestCase();
45    void SetUp();
46    void TearDown();
47};
48
49void HdiInputTest::SetUpTestCase()
50{
51    int32_t ret;
52    InputDevDesc sta[MAX_DEVICES];
53    ret = memset_s(sta, MAX_DEVICES * sizeof(InputDevDesc), 0, MAX_DEVICES * sizeof(InputDevDesc));
54    if (ret != 0) {
55        HDF_LOGE("memset failed");
56        return;
57    }
58    ret = GetInputInterface(&g_inputInterface);
59    if (ret != INPUT_SUCCESS) {
60        HDF_LOGE("%s: get input hdi failed, ret %d", __func__, ret);
61    }
62
63    g_callback.EventPkgCallback = ReportEventPkgCallback;
64    g_hotplugCb.HotPlugCallback = ReportHotPlugEventPkgCallback;
65    ret = g_inputInterface->iInputManager->ScanInputDevice(sta, MAX_DEVICES);
66    if (ret != INPUT_SUCCESS) {
67        HDF_LOGE("%s: scan device failed, ret %d", __func__, ret);
68    }
69    for (int32_t i = 0; i < MAX_DEVICES; i++) {
70        if (sta[i].devIndex == 0) {
71            break;
72        }
73        g_hasDev = true;
74    }
75}
76
77void HdiInputTest::TearDownTestCase()
78{
79    ReleaseInputInterface(&g_inputInterface);
80}
81
82void HdiInputTest::SetUp()
83{
84}
85
86void HdiInputTest::TearDown()
87{
88}
89
90#define INPUT_CHECK_NULL_POINTER(pointer, ret) do { \
91    if ((pointer) == NULL) { \
92        HDF_LOGE("%s: null pointer", __func__); \
93        ASSERT_EQ ((ret), INPUT_SUCCESS); \
94    } \
95} while (0)
96
97static void ReportEventPkgCallback(const InputEventPackage **pkgs, uint32_t count, uint32_t devIndex)
98{
99    if (pkgs == NULL) {
100        return;
101    }
102    for (uint32_t i = 0; i < count; i++) {
103        printf("%s: pkgs[%u] = 0x%x, 0x%x, %d\n", __func__, i, pkgs[i]->type, pkgs[i]->code, pkgs[i]->value);
104    }
105}
106
107static void ReportHotPlugEventPkgCallback(const InputHotPlugEvent *msg)
108{
109    int32_t ret;
110    if (msg == NULL) {
111        return;
112    }
113    HDF_LOGI("%s: status =%d devId=%d type =%d", __func__, msg->status, msg->devIndex, msg->devType);
114
115    if (msg->status == 0) {
116        ret = g_inputInterface->iInputManager->OpenInputDevice(msg->devIndex);
117        if (ret != INPUT_SUCCESS) {
118            HDF_LOGE("%s: open device[%u] failed, ret %d", __func__, msg->devIndex, ret);
119        }
120
121        ret  = g_inputInterface->iInputReporter->RegisterReportCallback(msg->devIndex, &g_callback);
122        if (ret != INPUT_SUCCESS) {
123            HDF_LOGE("%s: register callback failed for device[%d], ret %d", __func__, msg->devIndex, ret);
124        }
125    } else {
126        ret = g_inputInterface->iInputReporter->UnregisterReportCallback(msg->devIndex);
127        if (ret != INPUT_SUCCESS) {
128            HDF_LOGE("%s: unregister callback failed, ret %d", __func__, ret);
129        }
130
131        ret = g_inputInterface->iInputManager->CloseInputDevice(msg->devIndex);
132        if (ret != INPUT_SUCCESS) {
133            HDF_LOGE("%s: close device failed, ret %d", __func__, ret);
134        }
135    }
136}
137
138static void OpenOnlineDev(InputDevDesc *sta, int32_t len)
139{
140    int32_t ret = g_inputInterface->iInputManager->ScanInputDevice(sta, len);
141    if (ret != INPUT_SUCCESS) {
142        HDF_LOGE("%s: scan device failed, ret %d", __func__, ret);
143    }
144    ASSERT_EQ(ret, INPUT_SUCCESS);
145
146    for (int32_t i = 0; i < len; i++) {
147        if (sta[i].devIndex == 0) {
148            break;
149        }
150        ret = g_inputInterface->iInputManager->OpenInputDevice(sta[i].devIndex);
151        if (ret != INPUT_SUCCESS) {
152            HDF_LOGE("%s: open device[%d] failed, ret %d", __func__, sta[i].devIndex, ret);
153        }
154        ASSERT_EQ(ret, INPUT_SUCCESS);
155
156        ret  = g_inputInterface->iInputReporter->RegisterReportCallback(sta[i].devIndex, &g_callback);
157        if (ret != INPUT_SUCCESS) {
158            HDF_LOGE("%s: register callback failed for device[%d], ret %d", __func__, sta[i].devIndex, ret);
159        }
160        ASSERT_EQ(ret, INPUT_SUCCESS);
161    }
162}
163
164static void CloseOnlineDev(InputDevDesc *sta, int32_t len)
165{
166    int32_t ret = g_inputInterface->iInputManager->ScanInputDevice(sta, len);
167    if (ret != INPUT_SUCCESS) {
168        HDF_LOGE("%s: scan device failed, ret %d", __func__, ret);
169    }
170    ASSERT_EQ(ret, INPUT_SUCCESS);
171
172    for (int32_t i = 0; i < len; i++) {
173        if (sta[i].devIndex == 0) {
174            break;
175        }
176        ret = g_inputInterface->iInputReporter->UnregisterReportCallback(sta[i].devIndex);
177        if (ret != INPUT_SUCCESS) {
178            HDF_LOGE("%s: register callback failed for device[%d], ret %d", __func__, sta[i].devIndex, ret);
179        }
180        ASSERT_EQ(ret, INPUT_SUCCESS);
181
182        ret = g_inputInterface->iInputManager->CloseInputDevice(sta[i].devIndex);
183        if (ret != INPUT_SUCCESS) {
184            HDF_LOGE("%s: close device[%d] failed, ret %d", __func__, sta[i].devIndex, ret);
185        }
186        ASSERT_EQ(ret, INPUT_SUCCESS);
187    }
188}
189
190HWTEST_F(HdiInputTest, ScanInputDevice, TestSize.Level1)
191{
192    InputDevDesc sta[MAX_DEVICES];
193
194    HDF_LOGI("%s: [Input] RegisterCallbackAndReportData001 enter", __func__);
195    int32_t ret;
196
197    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
198    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR);
199
200    ret  = g_inputInterface->iInputManager->ScanInputDevice(sta, sizeof(sta)/sizeof(InputDevDesc));
201    if (!ret) {
202        HDF_LOGI("%s:%d, %d, %d, %d", __func__, sta[0].devType, sta[0].devIndex, sta[1].devType, sta[1].devIndex);
203    }
204
205    EXPECT_EQ(ret, INPUT_SUCCESS);
206}
207
208HWTEST_F(HdiInputTest, HotPlugCallback, TestSize.Level1)
209{
210    HDF_LOGI("%s: [Input] HotPlugCallback Testcase enter", __func__);
211    int32_t ret = INPUT_SUCCESS;
212    InputDevDesc sta[MAX_DEVICES];
213
214    ret = memset_s(sta, sizeof(sta), 0, sizeof(sta));
215    if (ret != 0) {
216        HDF_LOGE("%s: memcpy failed, line %d", __func__, __LINE__);
217    }
218
219    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
220    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputReporter, INPUT_NULL_PTR);
221    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR);
222
223    ret = g_inputInterface->iInputReporter->RegisterHotPlugCallback(&g_hotplugCb);
224    if (ret != INPUT_SUCCESS) {
225        HDF_LOGE("%s: register hotplug callback failed for device manager, ret %d", __func__, ret);
226    }
227    ASSERT_EQ(ret, INPUT_SUCCESS);
228
229    OpenOnlineDev(sta, MAX_DEVICES);
230
231    HDF_LOGI("%s: wait 15s for testing, pls hotplug now", __func__);
232    HDF_LOGI("%s: The event data is as following:", __func__);
233    OsalMSleep(KEEP_ALIVE_TIME_MS);
234
235    ret = memset_s(sta, sizeof(sta), 0, sizeof(sta));
236    if (ret != 0) {
237        HDF_LOGE("%s: memcpy failed, line %d", __func__, __LINE__);
238    }
239
240    CloseOnlineDev(sta, MAX_DEVICES);
241
242    ret = g_inputInterface->iInputReporter->UnregisterHotPlugCallback();
243    if (ret != INPUT_SUCCESS) {
244        HDF_LOGE("%s: unregister hotplug callback failed for device manager, ret %d", __func__, ret);
245    }
246    EXPECT_EQ(ret, INPUT_SUCCESS);
247}
248
249/**
250  * @tc.name: OpenInputDev001
251  * @tc.desc: open input device test
252  * @tc.type: FUNC
253  * @tc.require: AR000F867R, AR000F8QNL
254  */
255HWTEST_F(HdiInputTest, OpenInputDev001, TestSize.Level1)
256{
257    ASSERT_EQ(g_hasDev, true);
258    HDF_LOGI("%s: [Input] OpenInputDev001 enter", __func__);
259    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
260    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR);
261    int32_t ret = g_inputInterface->iInputManager->OpenInputDevice(TOUCH_INDEX);
262    if (ret != INPUT_SUCCESS) {
263        HDF_LOGE("%s: open device1 failed, ret %d", __func__, ret);
264    }
265    EXPECT_EQ(ret, INPUT_SUCCESS);
266}
267
268/**
269  * @tc.name: OpenInputDevice002
270  * @tc.desc: open input device test
271  * @tc.type: FUNC
272  * @tc.require: AR000F867R
273  */
274HWTEST_F(HdiInputTest, OpenInputDevice002, TestSize.Level1)
275{
276    ASSERT_EQ(g_hasDev, true);
277    HDF_LOGI("%s: [Input] OpenInputDev002 enter", __func__);
278    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
279    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR);
280    /* Device "5" is used for testing nonexistent device node */
281    int32_t ret = g_inputInterface->iInputManager->OpenInputDevice(INVALID_INDEX);
282    if (ret != INPUT_SUCCESS) {
283        HDF_LOGE("%s: device5 dose not exist, can't open it, ret %d", __func__, ret);
284    }
285    EXPECT_NE(ret, INPUT_SUCCESS);
286}
287
288/**
289  * @tc.name: CloseInputDevice001
290  * @tc.desc: close input device test
291  * @tc.type: FUNC
292  * @tc.require: AR000F867T, AR000F8QNL
293  */
294HWTEST_F(HdiInputTest, CloseInputDevice001, TestSize.Level1)
295{
296    ASSERT_EQ(g_hasDev, true);
297    HDF_LOGI("%s: [Input] CloseInputDev001 enter", __func__);
298    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
299    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR);
300    int32_t ret = g_inputInterface->iInputManager->CloseInputDevice(TOUCH_INDEX);
301    if (ret != INPUT_SUCCESS) {
302        HDF_LOGE("%s: close device1 failed, ret %d", __func__, ret);
303    }
304    EXPECT_EQ(ret, INPUT_SUCCESS);
305}
306
307/**
308  * @tc.name: CloseInputDevice002
309  * @tc.desc: close input device test
310  * @tc.type: FUNC
311  * @tc.require: AR000F867T
312  */
313HWTEST_F(HdiInputTest, CloseInputDevice002, TestSize.Level1)
314{
315    ASSERT_EQ(g_hasDev, true);
316    HDF_LOGI("%s: [Input] CloseInputDev002 enter", __func__);
317    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
318    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR);
319    /* Device "5" is used for testing nonexistent device node */
320    int32_t ret = g_inputInterface->iInputManager->CloseInputDevice(INVALID_INDEX);
321    if (ret != INPUT_SUCCESS) {
322        HDF_LOGE("%s: device5 doesn't exist, can't close it, ret %d", __func__, ret);
323    }
324    EXPECT_NE(ret, INPUT_SUCCESS);
325}
326
327/**
328  * @tc.name: GetInputDevice001
329  * @tc.desc: get input device info test
330  * @tc.type: FUNC
331  * @tc.require: AR000F867S
332  */
333HWTEST_F(HdiInputTest, GetInputDevice001, TestSize.Level1)
334{
335    ASSERT_EQ(g_hasDev, true);
336    HDF_LOGI("%s: [Input] GetInputDevice001 enter", __func__);
337    InputDeviceInfo *dev = NULL;
338    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
339    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR);
340
341    int32_t ret = g_inputInterface->iInputManager->OpenInputDevice(TOUCH_INDEX);
342    if (ret != INPUT_SUCCESS) {
343        HDF_LOGE("%s: open device1 failed, ret %d", __func__, ret);
344    }
345    ASSERT_EQ(ret, INPUT_SUCCESS);
346
347    ret = g_inputInterface->iInputManager->GetInputDevice(TOUCH_INDEX, &dev);
348    if (ret != INPUT_SUCCESS) {
349        HDF_LOGE("%s: get device1 failed, ret %d", __func__, ret);
350    }
351
352    HDF_LOGI("%s: devindex = %u, devType = %u", __func__, dev->devIndex,
353            dev->devType);
354    HDF_LOGI("%s: chipInfo = %s, vendorName = %s, chipName = %s",
355        __func__, dev->chipInfo, dev->vendorName, dev->chipName);
356    EXPECT_EQ(ret, INPUT_SUCCESS);
357}
358
359/**
360  * @tc.name: GetInputDeviceList001
361  * @tc.desc: get input device list info test
362  * @tc.type: FUNC
363  * @tc.require: AR000F8680
364  */
365HWTEST_F(HdiInputTest, GetInputDeviceList001, TestSize.Level1)
366{
367    ASSERT_EQ(g_hasDev, true);
368    HDF_LOGI("%s: [Input] GetInputDeviceList001 enter", __func__);
369    int32_t ret;
370    uint32_t num = 0;
371    InputDeviceInfo *dev[MAX_INPUT_DEV_NUM] = {0};
372
373    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
374    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR);
375    ret = g_inputInterface->iInputManager->GetInputDeviceList(&num, dev, MAX_INPUT_DEV_NUM);
376    if (ret != INPUT_SUCCESS) {
377        HDF_LOGE("%s: get device list failed, ret %d", __func__, ret);
378    }
379    ret = num <= MAX_INPUT_DEV_NUM ? HDF_SUCCESS : HDF_FAILURE;  /* num <= MAX_INPUT_DEV_NUM return true */
380    ASSERT_EQ(ret, INPUT_SUCCESS);
381
382
383    for (uint32_t i = 0; i < num; i++) {
384        HDF_LOGI("%s: num = %u, device[%d]'s info is:", __func__, num, i);
385        HDF_LOGI("%s: index = %u, devType = %u", __func__, dev[i]->devIndex,
386                dev[i]->devType);
387        HDF_LOGI("%s: chipInfo = %s, vendorName = %s, chipName = %s",
388            __func__, dev[i]->chipInfo, dev[i]->vendorName, dev[i]->chipName);
389    }
390    EXPECT_EQ(ret, INPUT_SUCCESS);
391}
392
393/**
394  * @tc.name: GetDeviceType001
395  * @tc.desc: get input device type test
396  * @tc.type: FUNC
397  * @tc.require: AR000F8681, AR000F8QNL
398  */
399HWTEST_F(HdiInputTest, GetDeviceType001, TestSize.Level1)
400{
401    ASSERT_EQ(g_hasDev, true);
402    HDF_LOGI("%s: [Input] GetDeviceType001 enter", __func__);
403    int32_t ret;
404    uint32_t devType = INIT_DEFAULT_VALUE;
405
406    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
407    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR);
408    ret = g_inputInterface->iInputController->GetDeviceType(TOUCH_INDEX, &devType);
409    if (ret != INPUT_SUCCESS) {
410        HDF_LOGE("%s: get device1's type failed, ret %d", __func__, ret);
411    }
412    HDF_LOGI("%s: device1's type is %u", __func__, devType);
413    EXPECT_EQ(ret, INPUT_SUCCESS);
414}
415
416/**
417  * @tc.name: GetChipInfo001
418  * @tc.desc: get input device chip info test
419  * @tc.type: FUNC
420  * @tc.require: AR000F8682
421  */
422HWTEST_F(HdiInputTest, GetChipInfo001, TestSize.Level1)
423{
424    ASSERT_EQ(g_hasDev, true);
425    HDF_LOGI("%s: [Input] GetChipInfo001 enter", __func__);
426    int32_t ret;
427    char chipInfo[CHIP_INFO_LEN] = {0};
428
429    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
430    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR);
431    ret = g_inputInterface->iInputController->GetChipInfo(TOUCH_INDEX, chipInfo, CHIP_INFO_LEN);
432    if (ret != INPUT_SUCCESS) {
433        HDF_LOGE("%s: get device1's chip info failed, ret %d", __func__, ret);
434    }
435    HDF_LOGI("%s: device1's chip info is %s", __func__, chipInfo);
436    EXPECT_EQ(ret, INPUT_SUCCESS);
437}
438
439/**
440  * @tc.name: GetInputDevice002
441  * @tc.desc: get input device chip info test
442  * @tc.type: FUNC
443  * @tc.require: AR000F8683
444  */
445HWTEST_F(HdiInputTest, GetInputDevice002, TestSize.Level1)
446{
447    ASSERT_EQ(g_hasDev, true);
448    HDF_LOGI("%s: [Input] GetInputDevice002 enter", __func__);
449    int32_t ret;
450    InputDeviceInfo *dev = NULL;
451
452    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
453    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR);
454    ret = g_inputInterface->iInputManager->GetInputDevice(TOUCH_INDEX, &dev);
455    if (ret != INPUT_SUCCESS) {
456        HDF_LOGE("%s: get device1 failed, ret %d", __func__, ret);
457    }
458
459    HDF_LOGI("%s: After fill the info, new device0's info is:", __func__);
460    HDF_LOGI("%s: new devindex = %u, devType = %u", __func__, dev->devIndex,
461            dev->devType);
462    HDF_LOGI("%s: new chipInfo = %s, vendorName = %s, chipName = %s",
463        __func__, dev->chipInfo, dev->vendorName, dev->chipName);
464    EXPECT_EQ(ret, INPUT_SUCCESS);
465}
466
467/**
468  * @tc.name: RegisterCallback001
469  * @tc.desc: get input device chip info test
470  * @tc.type: FUNC
471  * @tc.require: AR000F8684, AR000F8QNL
472  */
473HWTEST_F(HdiInputTest, RegisterCallback001, TestSize.Level1)
474{
475    ASSERT_EQ(g_hasDev, true);
476    HDF_LOGI("%s: [Input] RegisterCallbac001 enter", __func__);
477    int32_t ret;
478
479    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
480    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputReporter, INPUT_NULL_PTR);
481    /* Device "5" is used for testing nonexistent device node */
482    ret  = g_inputInterface->iInputReporter->RegisterReportCallback(INVALID_INDEX, &g_callback);
483    if (ret != INPUT_SUCCESS) {
484        HDF_LOGE("%s: device2 dose not exist, can't register callback to it, ret %d", __func__, ret);
485    }
486    EXPECT_NE(ret, INPUT_SUCCESS);
487}
488
489/**
490  * @tc.name: SetPowerStatus001
491  * @tc.desc: set device power status test
492  * @tc.type: FUNC
493  * @tc.require: AR000F867T
494  */
495HWTEST_F(HdiInputTest, SetPowerStatus001, TestSize.Level1)
496{
497    ASSERT_EQ(g_hasDev, true);
498    HDF_LOGI("%s: [Input] SetPowerStatus001 enter", __func__);
499    int32_t ret;
500    uint32_t setStatus = INPUT_LOW_POWER;
501
502    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
503    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR);
504    ret = g_inputInterface->iInputController->SetPowerStatus(TOUCH_INDEX, setStatus);
505    if (ret != INPUT_SUCCESS) {
506        HDF_LOGE("%s: set device1's power status failed, ret %d", __func__, ret);
507    }
508    EXPECT_EQ(ret, INPUT_SUCCESS);
509}
510
511/**
512  * @tc.name: SetPowerStatus002
513  * @tc.desc: set device power status test
514  * @tc.type: FUNC
515  * @tc.require: AR000F867T
516  */
517HWTEST_F(HdiInputTest, SetPowerStatus002, TestSize.Level1)
518{
519    ASSERT_EQ(g_hasDev, true);
520    HDF_LOGI("%s: [Input] SetPowerStatus002 enter", __func__);
521    int32_t ret;
522    uint32_t setStatus = INPUT_LOW_POWER;
523
524    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
525    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR);
526    /* Device "5" is used for testing nonexistent device node */
527    ret = g_inputInterface->iInputController->SetPowerStatus(INVALID_INDEX, setStatus);
528    if (ret != INPUT_SUCCESS) {
529        HDF_LOGE("%s: set device5's power status failed, ret %d", __func__, ret);
530    }
531    EXPECT_NE(ret, INPUT_SUCCESS);
532}
533
534/**
535  * @tc.name: GetPowerStatus001
536  * @tc.desc: get device power status test
537  * @tc.type: FUNC
538  * @tc.require: AR000F867S
539  */
540HWTEST_F(HdiInputTest, GetPowerStatus001, TestSize.Level1)
541{
542    ASSERT_EQ(g_hasDev, true);
543    HDF_LOGI("%s: [Input] GetPowerStatus001 enter", __func__);
544    int32_t ret;
545    uint32_t getStatus = 0;
546
547    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
548    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR);
549    ret = g_inputInterface->iInputController->GetPowerStatus(TOUCH_INDEX, &getStatus);
550    if (ret != INPUT_SUCCESS) {
551        HDF_LOGE("%s: get device1's power status failed, ret %d", __func__, ret);
552    }
553    HDF_LOGI("%s: device1's power status is %d:", __func__, getStatus);
554    EXPECT_EQ(ret, INPUT_SUCCESS);
555}
556
557/**
558  * @tc.name: GetPowerStatus002
559  * @tc.desc: get device power status test
560  * @tc.type: FUNC
561  * @tc.require: AR000F867S
562  */
563HWTEST_F(HdiInputTest, GetPowerStatus002, TestSize.Level1)
564{
565    ASSERT_EQ(g_hasDev, true);
566    HDF_LOGI("%s: [Input] GetPowerStatus002 enter", __func__);
567    int32_t ret;
568    uint32_t getStatus = 0;
569
570    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
571    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR);
572    /* Device "5" is used for testing nonexistent device node */
573    ret = g_inputInterface->iInputController->GetPowerStatus(INVALID_INDEX, &getStatus);
574    if (ret != INPUT_SUCCESS) {
575        HDF_LOGE("%s: get device5's power status failed, ret %d", __func__, ret);
576    }
577    EXPECT_NE(ret, INPUT_SUCCESS);
578}
579
580/**
581  * @tc.name: GetVendorName001
582  * @tc.desc: get device vendor name test
583  * @tc.type: FUNC
584  * @tc.require: AR000F867T
585  */
586HWTEST_F(HdiInputTest, GetVendorName001, TestSize.Level1)
587{
588    ASSERT_EQ(g_hasDev, true);
589    HDF_LOGI("%s: [Input] GetVendorName001 enter", __func__);
590    int32_t ret;
591    char vendorName[NAME_MAX_LEN] = {0};
592
593    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
594    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR);
595    ret = g_inputInterface->iInputController->GetVendorName(TOUCH_INDEX, vendorName, NAME_MAX_LEN);
596    if (ret != INPUT_SUCCESS) {
597        HDF_LOGE("%s: get device1's vendor name failed, ret %d", __func__, ret);
598    }
599    HDF_LOGI("%s: device1's vendor name is %s:", __func__, vendorName);
600    EXPECT_EQ(ret, INPUT_SUCCESS);
601}
602
603/**
604  * @tc.name: GetVendorName002
605  * @tc.desc: get device vendor name test
606  * @tc.type: FUNC
607  * @tc.require: AR000F867T
608  */
609HWTEST_F(HdiInputTest, GetVendorName002, TestSize.Level1)
610{
611    ASSERT_EQ(g_hasDev, true);
612    HDF_LOGI("%s: [Input] GetVendorName002 enter", __func__);
613    int32_t ret;
614    char vendorName[NAME_MAX_LEN] = {0};
615
616    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
617    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR);
618    /* Device "5" is used for testing nonexistent device node */
619    ret = g_inputInterface->iInputController->GetVendorName(INVALID_INDEX, vendorName, NAME_MAX_LEN);
620    if (ret != INPUT_SUCCESS) {
621        HDF_LOGE("%s: get device5's vendor name failed, ret %d", __func__, ret);
622    }
623    EXPECT_NE(ret, INPUT_SUCCESS);
624}
625
626/**
627  * @tc.name: GetChipName001
628  * @tc.desc: get device chip name test
629  * @tc.type: FUNC
630  * @tc.require: AR000F867S
631  */
632HWTEST_F(HdiInputTest, GetChipName001, TestSize.Level1)
633{
634    ASSERT_EQ(g_hasDev, true);
635    HDF_LOGI("%s: [Input] GetChipName001 enter", __func__);
636    int32_t ret;
637    char chipName[NAME_MAX_LEN] = {0};
638
639    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
640    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR);
641    ret = g_inputInterface->iInputController->GetChipName(TOUCH_INDEX, chipName, NAME_MAX_LEN);
642    if (ret != INPUT_SUCCESS) {
643        HDF_LOGE("%s: get device1's chip name failed, ret %d", __func__, ret);
644    }
645    HDF_LOGI("%s: device1's chip name is %s", __func__, chipName);
646    EXPECT_EQ(ret, INPUT_SUCCESS);
647}
648
649/**
650  * @tc.name: GetChipName002
651  * @tc.desc: get device chip name test
652  * @tc.type: FUNC
653  * @tc.require: AR000F867S
654  */
655HWTEST_F(HdiInputTest, GetChipName002, TestSize.Level1)
656{
657    ASSERT_EQ(g_hasDev, true);
658    HDF_LOGI("%s: [Input] GetChipName002 enter", __func__);
659    int32_t ret;
660    char chipName[NAME_MAX_LEN] = {0};
661
662    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
663    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR);
664    /* Device "5" is used for testing nonexistent device node */
665    ret = g_inputInterface->iInputController->GetChipName(INVALID_INDEX, chipName, NAME_MAX_LEN);
666    if (ret != INPUT_SUCCESS) {
667        HDF_LOGE("%s: get device5's chip name failed, ret %d", __func__, ret);
668    }
669    EXPECT_NE(ret, INPUT_SUCCESS);
670}
671
672/**
673  * @tc.name: SetGestureMode001
674  * @tc.desc: set device gesture mode test
675  * @tc.type: FUNC
676  * @tc.require: AR000F867S
677  */
678HWTEST_F(HdiInputTest, SetGestureMode001, TestSize.Level1)
679{
680    ASSERT_EQ(g_hasDev, true);
681    HDF_LOGI("%s: [Input] SetGestureMode001 enter", __func__);
682    int32_t ret;
683    uint32_t gestureMode = 1;
684
685    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
686    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR);
687    ret = g_inputInterface->iInputController->SetGestureMode(TOUCH_INDEX, gestureMode);
688    if (ret != INPUT_SUCCESS) {
689        HDF_LOGE("%s: get device1's gestureMode failed, ret %d", __func__, ret);
690    }
691    EXPECT_EQ(ret, INPUT_SUCCESS);
692}
693
694/**
695  * @tc.name: SetGestureMode002
696  * @tc.desc: set device gesture mode test
697  * @tc.type: FUNC
698  * @tc.require: AR000F867S
699  */
700HWTEST_F(HdiInputTest, SetGestureMode002, TestSize.Level1)
701{
702    ASSERT_EQ(g_hasDev, true);
703    HDF_LOGI("%s: [Input] SetGestureMode001 enter", __func__);
704    int32_t ret;
705    uint32_t gestureMode = 1;
706
707    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
708    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR);
709    /* Device "5" is used for testing nonexistent device node */
710    ret = g_inputInterface->iInputController->SetGestureMode(INVALID_INDEX, gestureMode);
711    if (ret != INPUT_SUCCESS) {
712        HDF_LOGE("%s: get device1's gestureMode failed, ret %d", __func__, ret);
713    }
714    EXPECT_NE(ret, INPUT_SUCCESS);
715}
716
717/**
718  * @tc.name: RunCapacitanceTest001
719  * @tc.desc: set device gesture mode test
720  * @tc.type: FUNC
721  * @tc.require: AR000F867R
722  */
723HWTEST_F(HdiInputTest, RunCapacitanceTest001, TestSize.Level1)
724{
725    ASSERT_EQ(g_hasDev, true);
726    HDF_LOGI("%s: [Input] RunCapacitanceTest001 enter", __func__);
727    int32_t ret;
728    char result[TEST_RESULT_LEN] = {0};
729    uint32_t testType = MMI_TEST;
730
731    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
732    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR);
733    ret = g_inputInterface->iInputController->RunCapacitanceTest(TOUCH_INDEX, testType, result, TEST_RESULT_LEN);
734    if (ret != INPUT_SUCCESS) {
735        HDF_LOGE("%s: get device1's gestureMode failed, ret %d", __func__, ret);
736    }
737    EXPECT_EQ(ret, INPUT_SUCCESS);
738}
739
740/**
741  * @tc.name: RunCapacitanceTest001
742  * @tc.desc: set device gesture mode test
743  * @tc.type: FUNC
744  * @tc.require: AR000F867R
745  */
746HWTEST_F(HdiInputTest, RunExtraCommand001, TestSize.Level1)
747{
748    ASSERT_EQ(g_hasDev, true);
749    HDF_LOGI("%s: [Input] RunExtraCommand001 enter", __func__);
750    int32_t ret;
751    InputExtraCmd extraCmd = {0};
752    extraCmd.cmdCode = "WakeUpMode";
753    extraCmd.cmdValue = "Enable";
754
755    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
756    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR);
757    ret = g_inputInterface->iInputController->RunExtraCommand(TOUCH_INDEX, &extraCmd);
758    if (ret != INPUT_SUCCESS) {
759        HDF_LOGE("%s: get device1's gestureMode failed, ret %d", __func__, ret);
760    }
761    EXPECT_EQ(ret, INPUT_SUCCESS);
762}
763
764/**
765  * @tc.name: RegisterCallbackAndReportData001
766  * @tc.desc: get input device chip info test
767  * @tc.type: FUNC
768  * @tc.require: AR000F8682, AR000F8QNL
769  */
770HWTEST_F(HdiInputTest, RegisterCallbackAndReportData001, TestSize.Level1)
771{
772    ASSERT_EQ(g_hasDev, true);
773    HDF_LOGI("%s: [Input] RegisterCallbackAndReportData001 enter", __func__);
774    int32_t ret;
775
776    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
777    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputReporter, INPUT_NULL_PTR);
778
779    ret  = g_inputInterface->iInputReporter->RegisterReportCallback(TOUCH_INDEX, &g_callback);
780    if (ret != INPUT_SUCCESS) {
781        HDF_LOGE("%s: register callback failed for device 1, ret %d", __func__, ret);
782    }
783    EXPECT_EQ(ret, INPUT_SUCCESS);
784    HDF_LOGI("%s: wait 15s for testing, pls touch the panel now", __func__);
785    HDF_LOGI("%s: The event data is as following:", __func__);
786    OsalMSleep(KEEP_ALIVE_TIME_MS);
787}
788
789/**
790  * @tc.name: UnregisterReportCallback001
791  * @tc.desc: get input device chip info test
792  * @tc.type: FUNC
793  * @tc.require: SR000F867Q
794  */
795HWTEST_F(HdiInputTest, UnregisterReportCallback001, TestSize.Level1)
796{
797    ASSERT_EQ(g_hasDev, true);
798    HDF_LOGI("%s: [Input] UnregisterReportCallback001 enter", __func__);
799    int32_t ret;
800    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
801    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputReporter, INPUT_NULL_PTR);
802    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR);
803
804    ret  = g_inputInterface->iInputReporter->UnregisterReportCallback(TOUCH_INDEX);
805    if (ret != INPUT_SUCCESS) {
806        HDF_LOGE("%s: unregister callback failed for device1, ret %d", __func__, ret);
807    }
808    EXPECT_EQ(ret, INPUT_SUCCESS);
809
810    ret = g_inputInterface->iInputManager->CloseInputDevice(TOUCH_INDEX);
811    if (ret != INPUT_SUCCESS) {
812        HDF_LOGE("%s: close device1 failed, ret %d", __func__, ret);
813    }
814    EXPECT_EQ(ret, INPUT_SUCCESS);
815    HDF_LOGI("%s: Close the device1 successfully after all test", __func__);
816}
817