1/* 2 * Copyright (C) 2023-2025 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 16import deviceManager from '@ohos.driver.deviceManager' 17import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' 18 19describe("DeviceManagerJsTest", function () { 20 var deviceId = null; 21 22 function callback(data) { 23 console.info("callback" + JSON.stringify(data)); 24 expect(typeof(data.x)).assertEqual("number"); 25 } 26 27 function callback2() { 28 console.info("callback2" + JSON.stringify(data)); 29 expect(typeof(data.x)).assertEqual("number"); 30 } 31 32 beforeAll(function() { 33 console.info('beforeAll called'); 34 try { 35 var devices = deviceManager.queryDevices(deviceManager.BusType.USB); 36 if (devices != null && devices.length > 0 && devices[0] != null) { 37 deviceId = BigInt(devices[0].deviceId); 38 console.log('Device ID:', deviceId.toString()); 39 } else { 40 console.log('No devices found.'); 41 } 42 } catch (err) { 43 console.error('Error occurred:', err); 44 } 45 46 if (deviceId == null) { 47 console.log('Device ID has not been set.'); 48 } 49 console.info('beforeAll called end'); 50 }) 51 52 afterAll(function() { 53 console.info('afterAll called') 54 }) 55 56 beforeEach(function() { 57 console.info('beforeEach called') 58 }) 59 60 afterEach(function() { 61 console.info('afterEach called') 62 }) 63 64 const PARAMETER_ERROR_CODE = 401 65 const SERVICE_EXCEPTION_CODE = 22900001 66 const SERVICE_EXCEPTION_CODE_NEW = 26300001 67 const SERVICE_NOT_BOUND = 26300003 68 69 /* 70 * @tc.name:DeviceManager_queryDevices_001 71 * @tc.desc:verify queryDevice result 72 * @tc.type: FUNC 73 */ 74 it("DeviceManager_queryDevices_001", 0, function () { 75 console.info('----------------------DeviceManager_queryDevices_001---------------------------'); 76 try { 77 var devices = deviceManager.queryDevices(deviceManager.BusType.USB); 78 expect(devices != null).assertEqual(true); 79 if (devices.length > 0) { 80 expect(devices[0] != null).assertEqual(true); 81 expect(devices[0].vendorId != null).assertEqual(true); 82 expect(devices[0].productId != null).assertEqual(true); 83 } 84 } catch (err) { 85 expect(err.code).assertEqual(SERVICE_EXCEPTION_CODE); 86 } 87 }) 88 89 /* 90 * @tc.name:DeviceManager_queryDevices_002 91 * @tc.desc:verify queryDevice no param result 92 * @tc.type: FUNC 93 */ 94 it("DeviceManager_queryDevices_002", 0, function () { 95 console.info('----------------------DeviceManager_queryDevices_002---------------------------'); 96 try { 97 var devices = deviceManager.queryDevices(); 98 expect(devices != null).assertEqual(true); 99 } catch (err) { 100 expect(err.code).assertEqual(SERVICE_EXCEPTION_CODE); 101 } 102 }) 103 104 /* 105 * @tc.name:DeviceManager_bindDevices_003 106 * @tc.desc:verify bindDevice invalid param 107 * @tc.type: FUNC 108 */ 109 it("DeviceManager_bindDevices_003", 0, async function (done) { 110 console.info('----------------------DeviceManager_bindDevices_003---------------------------'); 111 try { 112 deviceManager.bindDevice('fakeid', (error, data) => { 113 expect(false).assertTrue(); 114 done(); 115 }, (error, data) => { 116 expect(false).assertTrue(); 117 done(); 118 }); 119 expect(false).assertTrue(); 120 done(); 121 } catch (error) { 122 expect(error.code).assertEqual(PARAMETER_ERROR_CODE); 123 done(); 124 } 125 }) 126 127 /* 128 * @tc.name:DeviceManager_bindDevices_004 129 * @tc.desc:verify bindDevice any device 130 * @tc.type: FUNC 131 */ 132 it("DeviceManager_bindDevices_004", 0, async function (done) { 133 console.info('----------------------DeviceManager_bindDevices_004---------------------------'); 134 try { 135 deviceManager.bindDevice(12345, (error, data) => { 136 expect(false).assertTrue(); 137 done(); 138 }, (error, data) => { 139 expect(error.code).assertEqual(SERVICE_EXCEPTION_CODE); 140 done(); 141 }); 142 expect(false).assertTrue(); 143 done(); 144 } catch (error) { 145 expect(error.code).assertEqual(SERVICE_EXCEPTION_CODE); 146 done(); 147 } 148 }) 149 150 /* 151 * @tc.name:DeviceManager_bindDeviceDriver_005 152 * @tc.desc:verify bindDeviceDriver any device 153 * @tc.type: FUNC 154 */ 155 it("DeviceManager_bindDeviceDriver_005", 0, async function (done) { 156 console.info('----------------------DeviceManager_bindDeviceDriver_005---------------------------'); 157 try { 158 deviceManager.bindDeviceDriver(12345, (error, data) => { 159 expect(false).assertTrue(); 160 done(); 161 }, (error, data) => { 162 expect(error.code).assertEqual(SERVICE_EXCEPTION_CODE); 163 done(); 164 }); 165 expect(false).assertTrue(); 166 done(); 167 } catch (error) { 168 expect(error.code).assertEqual(SERVICE_EXCEPTION_CODE); 169 done(); 170 } 171 }) 172 173 /* 174 * @tc.name:DeviceManager_bindDevices_006 175 * @tc.desc:verify bindDevice invalid param count 176 * @tc.type: FUNC 177 */ 178 it("DeviceManager_bindDevices_006", 0, async function (done) { 179 console.info('----------------------DeviceManager_bindDevices_006---------------------------'); 180 try { 181 deviceManager.bindDevice(); 182 expect(false).assertTrue(); 183 done(); 184 } catch (error) { 185 expect(error.code).assertEqual(PARAMETER_ERROR_CODE); 186 done(); 187 } 188 }) 189 190 /* 191 * @tc.name:DeviceManager_bindDevices_007 192 * @tc.desc:verify bindDevice invalid param 193 * @tc.type: FUNC 194 */ 195 it("DeviceManager_bindDevices_007", 0, async function (done) { 196 console.info('----------------------DeviceManager_bindDevices_007---------------------------'); 197 try { 198 deviceManager.bindDevice(12345); 199 expect(false).assertTrue(); 200 done(); 201 } catch (error) { 202 expect(error.code).assertEqual(PARAMETER_ERROR_CODE); 203 done(); 204 } 205 }) 206 207 /* 208 * @tc.name:DeviceManager_bindDevices_008 209 * @tc.desc:verify bindDevice invalid param 210 * @tc.type: FUNC 211 */ 212 it("DeviceManager_bindDevices_008", 0, async function (done) { 213 console.info('----------------------DeviceManager_bindDevices_008---------------------------'); 214 try { 215 deviceManager.bindDevice(12345, 23456); 216 expect(false).assertTrue(); 217 done(); 218 } catch (error) { 219 expect(error.code).assertEqual(PARAMETER_ERROR_CODE); 220 done(); 221 } 222 }) 223 224 /* 225 * @tc.name:DeviceManager_bindDevices_009 226 * @tc.desc:verify bindDevice promise 227 * @tc.type: FUNC 228 */ 229 it("DeviceManager_bindDevices_009", 0, async function (done) { 230 console.info('----------------------DeviceManager_bindDevices_009---------------------------'); 231 try { 232 deviceManager.bindDevice('fakeid', (error, data) => { 233 expect(false).assertTrue(); 234 done(); 235 }).then(data => { 236 expect(false).assertTrue(); 237 done(); 238 }, error => { 239 expect(false).assertTrue(); 240 done(); 241 }); 242 expect(false).assertTrue(); 243 done(); 244 } catch (error) { 245 expect(error.code).assertEqual(PARAMETER_ERROR_CODE); 246 done(); 247 } 248 }) 249 250 /* 251 * @tc.name:DeviceManager_bindDevices_010 252 * @tc.desc:verify bindDevice promise 253 * @tc.type: FUNC 254 */ 255 it("DeviceManager_bindDevices_010", 0, async function (done) { 256 console.info('----------------------DeviceManager_bindDevices_010---------------------------'); 257 try { 258 deviceManager.bindDevice(12345, (error, data) => { 259 expect(false).assertTrue(); 260 done(); 261 }).then(data => { 262 expect(false).assertTrue(); 263 done(); 264 }, error => { 265 expect(false).assertTrue(); 266 done(); 267 }); 268 expect(false).assertTrue(); 269 done(); 270 } catch (error) { 271 expect(error.code).assertEqual(SERVICE_EXCEPTION_CODE); 272 done(); 273 } 274 }) 275 276 /* 277 * @tc.name:DeviceManager_bindDeviceDriver_011 278 * @tc.desc:verify bindDeviceDriver promise 279 * @tc.type: FUNC 280 */ 281 it("DeviceManager_bindDeviceDriver_011", 0, async function (done) { 282 console.info('----------------------DeviceManager_bindDeviceDriver_011---------------------------'); 283 try { 284 deviceManager.bindDeviceDriver(12345, (error, data) => { 285 expect(false).assertTrue(); 286 done(); 287 }).then(data => { 288 expect(data != null).assertTrue(); 289 let remoteDeviceDriver = data; 290 expect(remoteDeviceDriver.deviceId != null).assertTrue(); 291 expect(remoteDeviceDriver.remote != null).assertTrue(); 292 done(); 293 }, error => { 294 expect(false).assertTrue(); 295 done(); 296 }); 297 expect(false).assertTrue(); 298 done(); 299 } catch (error) { 300 expect(error.code).assertEqual(SERVICE_EXCEPTION_CODE); 301 done(); 302 } 303 }) 304 305 /* 306 * @tc.name:DeviceManager_unbindDevices_012 307 * @tc.desc:verify unbindDevice any device 308 * @tc.type: FUNC 309 */ 310 it("DeviceManager_unbindDevices_012", 0, async function (done) { 311 console.info('----------------------DeviceManager_unbindDevices_012---------------------------'); 312 try { 313 deviceManager.unbindDevice('fakeid', (error, data) => { 314 expect(false).assertTrue(); 315 done(); 316 }); 317 expect(false).assertTrue(); 318 done(); 319 } catch (error) { 320 expect(error.code).assertEqual(PARAMETER_ERROR_CODE); 321 done(); 322 } 323 }) 324 325 /* 326 * @tc.name:DeviceManager_unbindDevices_013 327 * @tc.desc:verify unbindDevice any device 328 * @tc.type: FUNC 329 */ 330 it("DeviceManager_unbindDevices_013", 0, async function (done) { 331 console.info('----------------------DeviceManager_unbindDevices_013---------------------------'); 332 try { 333 deviceManager.unbindDevice(12345, (error, data) => { 334 expect(false).assertTrue(); 335 done(); 336 }); 337 expect(false).assertTrue(); 338 done(); 339 } catch (error) { 340 expect(error.code).assertEqual(SERVICE_EXCEPTION_CODE); 341 done(); 342 } 343 }) 344 345 /* 346 * @tc.name:DeviceManager_unbindDevices_014 347 * @tc.desc:verify unbindDevice invalid param 348 * @tc.type: FUNC 349 */ 350 it("DeviceManager_unbindDevices_014", 0, async function (done) { 351 console.info('----------------------DeviceManager_unbindDevices_014---------------------------'); 352 try { 353 deviceManager.unbindDevice(); 354 expect(false).assertTrue(); 355 done(); 356 } catch (error) { 357 expect(error.code).assertEqual(PARAMETER_ERROR_CODE); 358 done(); 359 } 360 }) 361 362 /* 363 * @tc.name:DeviceManager_unbindDevices_015 364 * @tc.desc:verify unbindDevice promise 365 * @tc.type: FUNC 366 */ 367 it("DeviceManager_unbindDevices_015", 0, async function (done) { 368 console.info('----------------------DeviceManager_unbindDevices_015---------------------------'); 369 try { 370 deviceManager.unbindDevice(12345).then(data => { 371 expect(false).assertTrue(); 372 done(); 373 }, error => { 374 expect(false).assertTrue(); 375 done(); 376 }); 377 expect(false).assertTrue(); 378 done(); 379 } catch (error) { 380 expect(error.code).assertEqual(SERVICE_EXCEPTION_CODE); 381 done(); 382 } 383 }) 384 385 /* 386 * @tc.name:DeviceManager_bindDriverWithDeviceId_001 387 * @tc.desc:verify bindDriverWithDeviceId invalid param count 388 * @tc.type: FUNC 389 */ 390 it("DeviceManager_bindDriverWithDeviceId_001", 0, async function (done) { 391 console.info('----------------------DeviceManager_bindDriverWithDeviceId_001---------------------------'); 392 try { 393 deviceManager.bindDriverWithDeviceId(); 394 expect(false).assertTrue(); 395 done(); 396 } catch (error) { 397 expect(error.code).assertEqual(PARAMETER_ERROR_CODE); 398 done(); 399 } 400 }) 401 402 /* 403 * @tc.name:DeviceManager_bindDriverWithDeviceId_002 404 * @tc.desc:verify bindDriverWithDeviceId invalid param 405 * @tc.type: FUNC 406 */ 407 it("DeviceManager_bindDriverWithDeviceId_002", 0, async function (done) { 408 console.info('----------------------DeviceManager_bindDriverWithDeviceId_002---------------------------'); 409 try { 410 deviceManager.bindDriverWithDeviceId(12345); 411 expect(false).assertTrue(); 412 done(); 413 } catch (error) { 414 expect(error.code).assertEqual(PARAMETER_ERROR_CODE); 415 done(); 416 } 417 }) 418 419 /* 420 * @tc.name:DeviceManager_bindDriverWithDeviceId_003 421 * @tc.desc:verify bindDriverWithDeviceId invalid param 422 * @tc.type: FUNC 423 */ 424 it("DeviceManager_bindDriverWithDeviceId_003", 0, async function (done) { 425 console.info('----------------------DeviceManager_bindDriverWithDeviceId_003---------------------------'); 426 try { 427 deviceManager.bindDriverWithDeviceId(12345, 23456); 428 expect(false).assertTrue(); 429 done(); 430 } catch (error) { 431 expect(error.code).assertEqual(PARAMETER_ERROR_CODE); 432 done(); 433 } 434 }) 435 436 /* 437 * @tc.name:DeviceManager_bindDriverWithDeviceId_004 438 * @tc.desc:verify bindDriverWithDeviceId promise 439 * @tc.type: FUNC 440 */ 441 it("DeviceManager_bindDriverWithDeviceId_004", 0, async function (done) { 442 console.info('----------------------DeviceManager_bindDriverWithDeviceId_004---------------------------'); 443 try { 444 deviceManager.bindDriverWithDeviceId('fakeid', (error, data) => { 445 expect(false).assertTrue(); 446 done(); 447 }).then(data => { 448 expect(false).assertTrue(); 449 done(); 450 }, error => { 451 expect(false).assertTrue(); 452 done(); 453 }); 454 expect(false).assertTrue(); 455 done(); 456 } catch (error) { 457 expect(error.code).assertEqual(PARAMETER_ERROR_CODE); 458 done(); 459 } 460 }) 461 462 /* 463 * @tc.name:DeviceManager_bindDriverWithDeviceId_005 464 * @tc.desc:verify bindDriverWithDeviceId promise 465 * @tc.type: FUNC 466 */ 467 it("DeviceManager_bindDriverWithDeviceId_005", 0, async function (done) { 468 console.info('----------------------DeviceManager_bindDriverWithDeviceId_005---------------------------'); 469 try { 470 deviceManager.bindDriverWithDeviceId(12345, (error, data) => { 471 expect(false).assertTrue(); 472 done(); 473 }).then(data => { 474 expect(false).assertTrue(); 475 done(); 476 }, error => { 477 expect(false).assertTrue(); 478 done(); 479 }); 480 expect(false).assertTrue(); 481 done(); 482 } catch (error) { 483 expect(error.code).assertEqual(SERVICE_EXCEPTION_CODE_NEW); 484 done(); 485 } 486 }) 487 488 /* 489 * @tc.name:DeviceManager_unbindDriverWithDeviceId_001 490 * @tc.desc:verify unbindDriverWithDeviceId invalid param 491 * @tc.type: FUNC 492 */ 493 it("DeviceManager_unbindDriverWithDeviceId_001", 0, async function (done) { 494 console.info('----------------------DeviceManager_unbindDriverWithDeviceId_001---------------------------'); 495 try { 496 deviceManager.unbindDriverWithDeviceId(); 497 expect(false).assertTrue(); 498 done(); 499 } catch (error) { 500 expect(error.code).assertEqual(PARAMETER_ERROR_CODE); 501 done(); 502 } 503 }) 504 505 /* 506 * @tc.name:DeviceManager_unbindDriverWithDeviceId_002 507 * @tc.desc:verify unbindDriverWithDeviceId promise 508 * @tc.type: FUNC 509 */ 510 it("DeviceManager_unbindDriverWithDeviceId_002", 0, async function (done) { 511 console.info('----------------------DeviceManager_unbindDriverWithDeviceId_002---------------------------'); 512 try { 513 deviceManager.unbindDriverWithDeviceId(12345).then(data => { 514 expect(false).assertTrue(); 515 done(); 516 }, error => { 517 expect(false).assertTrue(); 518 done(); 519 }); 520 expect(false).assertTrue(); 521 done(); 522 } catch (error) { 523 expect(error.code).assertEqual(SERVICE_EXCEPTION_CODE_NEW); 524 done(); 525 } 526 }) 527 528 /* 529 * @tc.name:DeviceManager_unbindDriverWithDeviceId_003 530 * @tc.desc:verify unbindDriverWithDeviceId promise 531 * @tc.type: FUNC 532 */ 533 it("DeviceManager_unbindDriverWithDeviceId_003", 0, async function (done) { 534 console.info('----------------------DeviceManager_unbindDriverWithDeviceId_003---------------------------'); 535 try { 536 if (deviceId == null) { 537 console.log('Device ID has not been set.'); 538 expect(true).assertTrue(); 539 done(); 540 return; 541 } 542 deviceManager.unbindDriverWithDeviceId(deviceId).then(data => { 543 expect(false).assertTrue(); 544 done(); 545 }, error => { 546 expect(false).assertTrue(); 547 done(); 548 }); 549 expect(false).assertTrue(); 550 done(); 551 } catch (error) { 552 expect(error.code).assertEqual(SERVICE_NOT_BOUND); 553 done(); 554 } 555 }) 556 557 /* 558 * @tc.name:DeviceManager_queryDeviceInfo_001 559 * @tc.desc:verify queryDeviceInfo invalid param 560 * @tc.type: FUNC 561 */ 562 it("DeviceManager_queryDeviceInfo_001", 0, async function () { 563 console.info('----------------------DeviceManager_queryDeviceInfo_001---------------------------'); 564 try { 565 deviceManager.queryDeviceInfo('invalidDeviceId'); 566 expect(false).assertTrue(); 567 } catch (error) { 568 expect(error.code).assertEqual(PARAMETER_ERROR_CODE); 569 } 570 }) 571 572 function isUsbDevice(deviceId) { 573 return (deviceId & 0x00000000FFFFFFFF) === deviceManager.BusType.USB; 574 } 575 576 function assertInterfaceDesc(interfaceDesc) { 577 expect(Object.prototype.toString.call(interfaceDesc)).assertEqual('[object Object]'); 578 console.log('interfaceDesc.bInterfaceNumber:' + interfaceDesc.bInterfaceNumber); 579 expect(typeof(interfaceDesc.bInterfaceNumber)).assertEqual('number'); 580 console.log('interfaceDesc.bClass:' + interfaceDesc.bClass); 581 expect(typeof(interfaceDesc.bClass)).assertEqual('number'); 582 console.log('interfaceDesc.bSubClass:' + interfaceDesc.bSubClass); 583 expect(typeof(interfaceDesc.bSubClass)).assertEqual('number'); 584 console.log('interfaceDesc.bProtocol:' + interfaceDesc.bProtocol); 585 expect(typeof(interfaceDesc.bProtocol)).assertEqual('number'); 586 } 587 588 function assertUsbDeviceInfoExt(usbDeviceInfo) { 589 expect(Object.prototype.toString.call(usbDeviceInfo)).assertEqual('[object Object]'); 590 console.log('usbDeviceInfo.vendorId:' + usbDeviceInfo.vendorId); 591 expect(typeof(usbDeviceInfo.vendorId)).assertEqual('number'); 592 console.log('usbDeviceInfo.productId:' + usbDeviceInfo.productId); 593 expect(typeof(usbDeviceInfo.productId)).assertEqual('number'); 594 expect(Array.isArray(usbDeviceInfo.interfaceDescList)).assertTrue(); 595 for (const desc of usbDeviceInfo.interfaceDescList) { 596 assertInterfaceDesc(desc); 597 } 598 } 599 600 function assertDeviceInfo(deviceInfo) { 601 expect(Object.prototype.toString.call(deviceInfo)).assertEqual('[object Object]'); 602 console.log('deviceInfo.deviceId:' + deviceInfo.deviceId); 603 expect(typeof(deviceInfo.deviceId)).assertEqual('number'); 604 console.log('deviceInfo.isDriverMatched:' + deviceInfo.isDriverMatched); 605 expect(typeof(deviceInfo.isDriverMatched)).assertEqual('boolean'); 606 if (deviceInfo.isDriverMatched) { 607 console.log('deviceInfo.driverUid:' + deviceInfo.driverUid); 608 expect(typeof(deviceInfo.driverUid)).assertEqual('string'); 609 } 610 if (isUsbDevice(deviceInfo.deviceId)) { 611 assertUsbDeviceInfoExt(deviceInfo) 612 } 613 } 614 615 /* 616 * @tc.name:DeviceManager_queryDeviceInfo_002 617 * @tc.desc:verify queryDeviceInfo none deviceId 618 * @tc.type: FUNC 619 */ 620 it("DeviceManager_queryDeviceInfo_002", 0, async function () { 621 console.info('----------------------DeviceManager_queryDeviceInfo_002---------------------------'); 622 try { 623 const deviceInfos = deviceManager.queryDeviceInfo(); 624 expect(Array.isArray(deviceInfos)).assertTrue(); 625 for (const deviceInfo of deviceInfos) { 626 assertDeviceInfo(deviceInfo); 627 } 628 } catch (error) { 629 expect(error.code).assertEqual(SERVICE_EXCEPTION_CODE_NEW); 630 } 631 }) 632 633 /* 634 * @tc.name:DeviceManager_queryDeviceInfo_003 635 * @tc.desc:verify queryDeviceInfo has deviceId 636 * @tc.type: FUNC 637 */ 638 it("DeviceManager_queryDeviceInfo_003", 0, async function () { 639 console.info('----------------------DeviceManager_queryDeviceInfo_003---------------------------'); 640 try { 641 const deviceInfos = deviceManager.queryDeviceInfo(12345); 642 expect(Array.isArray(deviceInfos)).assertTrue(); 643 for (const deviceInfo of deviceInfos) { 644 assertDeviceInfo(deviceInfo); 645 } 646 } catch (error) { 647 expect(error.code).assertEqual(SERVICE_EXCEPTION_CODE_NEW); 648 } 649 }) 650 651 /* 652 * @tc.name:DeviceManager_queryDriverInfo_001 653 * @tc.desc:verify queryDriverInfo invalid param 654 * @tc.type: FUNC 655 */ 656 it("DeviceManager_queryDriverInfo_001", 0, async function () { 657 console.info('----------------------DeviceManager_queryDriverInfo_001---------------------------'); 658 try { 659 deviceManager.queryDriverInfo(12345); 660 expect(false).assertTrue(); 661 } catch (error) { 662 expect(error.code).assertEqual(PARAMETER_ERROR_CODE); 663 } 664 }) 665 666 function assertDriverInfo(driverInfo) { 667 expect(Object.prototype.toString.call(driverInfo)).assertEqual('[object Object]'); 668 console.log('driverInfo.busType:' + driverInfo.busType); 669 expect(typeof(driverInfo.busType)).assertEqual('number'); 670 console.log('driverInfo.driverUid:' + driverInfo.driverUid); 671 expect(typeof(driverInfo.driverUid)).assertEqual('string'); 672 console.log('driverInfo.driverName:' + driverInfo.driverName); 673 expect(typeof(driverInfo.driverName)).assertEqual('string'); 674 console.log('driverInfo.driverVersion:' + driverInfo.driverVersion); 675 expect(typeof(driverInfo.driverVersion)).assertEqual('string'); 676 console.log('driverInfo.driverSize:' + driverInfo.driverSize); 677 expect(typeof(driverInfo.driverSize)).assertEqual('string'); 678 console.log('driverInfo.description:' + driverInfo.description); 679 expect(typeof(driverInfo.description)).assertEqual('string'); 680 if (driverInfo.busType === deviceManager.BusType.USB) { 681 console.log('driverInfo.productIdList:' + JSON.stringify(driverInfo.productIdList)); 682 expect(Array.isArray(driverInfo.productIdList)).assertTrue(); 683 console.log('driverInfo.vendorIdList:' + JSON.stringify(driverInfo.vendorIdList)); 684 expect(Array.isArray(driverInfo.vendorIdList)).assertTrue(); 685 for (const productId of driverInfo.productIdList) { 686 expect(typeof(productId)).assertEqual('number'); 687 } 688 for (const vendorId of driverInfo.vendorIdList) { 689 expect(typeof(vendorId)).assertEqual('number'); 690 } 691 } 692 } 693 694 /* 695 * @tc.name:DeviceManager_queryDriverInfo_002 696 * @tc.desc:verify queryDriverInfo none driverUid 697 * @tc.type: FUNC 698 */ 699 it("DeviceManager_queryDriverInfo_002", 0, async function () { 700 console.info('----------------------DeviceManager_queryDriverInfo_002---------------------------'); 701 try { 702 const driverInfos = deviceManager.queryDriverInfo(); 703 expect(Array.isArray(driverInfos)).assertTrue(); 704 for (const driverInfo of driverInfos) { 705 assertDriverInfo(driverInfo); 706 } 707 } catch (error) { 708 expect(error.code).assertEqual(SERVICE_EXCEPTION_CODE_NEW); 709 } 710 }) 711 712 /* 713 * @tc.name:DeviceManager_queryDriverInfo_003 714 * @tc.desc:verify queryDriverInfo has driverUid 715 * @tc.type: FUNC 716 */ 717 it("DeviceManager_queryDriverInfo_003", 0, async function () { 718 console.info('----------------------DeviceManager_queryDriverInfo_003---------------------------'); 719 try { 720 const driverInfos = deviceManager.queryDriverInfo('driver-12345'); 721 expect(Array.isArray(driverInfos)).assertTrue(); 722 for (const driverInfo of driverInfos) { 723 assertDriverInfo(driverInfo); 724 } 725 } catch (error) { 726 expect(error.code).assertEqual(SERVICE_EXCEPTION_CODE_NEW); 727 } 728 }) 729})