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