| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <sstream> | 5 #include <sstream> |
| 6 | 6 |
| 7 #include "device/hid/hid_report_descriptor.h" | 7 #include "device/hid/hid_report_descriptor.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 ++items_iter) { | 364 ++items_iter) { |
| 365 linked_ptr<HidReportDescriptorItem> item = *items_iter; | 365 linked_ptr<HidReportDescriptorItem> item = *items_iter; |
| 366 size_t indentLevel = item->GetDepth(); | 366 size_t indentLevel = item->GetDepth(); |
| 367 for (size_t i = 0; i < indentLevel; i++) | 367 for (size_t i = 0; i < indentLevel; i++) |
| 368 os << kIndentStep; | 368 os << kIndentStep; |
| 369 os << *item.get() << std::endl; | 369 os << *item.get() << std::endl; |
| 370 } | 370 } |
| 371 return os; | 371 return os; |
| 372 } | 372 } |
| 373 | 373 |
| 374 // See 'E.6 Report Descriptor (Keyboard)' | 374 void DumpDescriptor(const HidReportDescriptor& descriptor) { |
| 375 // in HID specifications (v1.11) | 375 std::stringstream stream; |
| 376 stream << descriptor; |
| 377 |
| 378 std::cout << "HID report descriptor:" << std::endl; |
| 379 std::cout << stream.str(); |
| 380 } |
| 381 |
| 382 // Digitizer descriptor from HID descriptor tool |
| 383 // http://www.usb.org/developers/hidpage/dt2_4.zip |
| 384 const uint8_t kDigitizer[] = { |
| 385 0x05, 0x0d, // Usage Page (Digitizer) |
| 386 0x09, 0x01, // Usage (0x1) |
| 387 0xa1, 0x01, // Collection (Application) |
| 388 0x85, 0x01, // Report ID (0x1) |
| 389 0x09, 0x21, // Usage (0x21) |
| 390 0xa1, 0x00, // Collection (Physical) |
| 391 0x05, 0x01, // Usage Page (Generic Desktop) |
| 392 0x09, 0x30, // Usage (0x30) |
| 393 0x09, 0x31, // Usage (0x31) |
| 394 0x75, 0x10, // Report Size (16) |
| 395 0x95, 0x02, // Report Count (2) |
| 396 0x15, 0x00, // Logical Minimum (0) |
| 397 0x26, 0xe0, 0x2e, // Logical Maximum (12000) |
| 398 0x35, 0x00, // Physical Minimum (0) |
| 399 0x45, 0x0c, // Physical Maximum (12) |
| 400 0x65, 0x13, // Unit (19) |
| 401 0x55, 0x00, // Unit Exponent (0) |
| 402 0xa4, // Push |
| 403 0x81, 0x02, // Input (Dat|Arr|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 404 0x05, 0x0d, // Usage Page (Digitizer) |
| 405 0x09, 0x32, // Usage (0x32) |
| 406 0x09, 0x44, // Usage (0x44) |
| 407 0x09, 0x42, // Usage (0x42) |
| 408 0x15, 0x00, // Logical Minimum (0) |
| 409 0x25, 0x01, // Logical Maximum (1) |
| 410 0x35, 0x00, // Physical Minimum (0) |
| 411 0x45, 0x01, // Physical Maximum (1) |
| 412 0x75, 0x01, // Report Size (1) |
| 413 0x95, 0x03, // Report Count (3) |
| 414 0x65, 0x00, // Unit (0) |
| 415 0x81, 0x02, // Input (Dat|Arr|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 416 0x95, 0x01, // Report Count (1) |
| 417 0x75, 0x05, // Report Size (5) |
| 418 0x81, 0x03, // Input (Con|Arr|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 419 0xc0, // End Collection |
| 420 0x85, 0x02, // Report ID (0x2) |
| 421 0x09, 0x20, // Usage (0x20) |
| 422 0xa1, 0x00, // Collection (Physical) |
| 423 0xb4, // Pop |
| 424 0xa4, // Push |
| 425 0x09, 0x30, // Usage (0x30) |
| 426 0x09, 0x31, // Usage (0x31) |
| 427 0x81, 0x02, // Input (Dat|Arr|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 428 0x05, 0x0d, // Usage Page (Digitizer) |
| 429 0x09, 0x32, // Usage (0x32) |
| 430 0x15, 0x00, // Logical Minimum (0) |
| 431 0x25, 0x01, // Logical Maximum (1) |
| 432 0x35, 0x00, // Physical Minimum (0) |
| 433 0x45, 0x01, // Physical Maximum (1) |
| 434 0x65, 0x00, // Unit (0) |
| 435 0x75, 0x01, // Report Size (1) |
| 436 0x81, 0x02, // Input (Dat|Arr|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 437 0x05, 0x09, // Usage Page (Button) |
| 438 0x19, 0x00, // Usage Minimum (0) |
| 439 0x29, 0x10, // Usage Maximum (16) |
| 440 0x25, 0x10, // Logical Maximum (16) |
| 441 0x75, 0x05, // Report Size (5) |
| 442 0x81, 0x40, // Input (Dat|Var|Rel|NoWrp|Lin|Prf|Null|BitF) |
| 443 0x75, 0x02, // Report Size (2) |
| 444 0x81, 0x01, // Input (Con|Var|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 445 0xc0, // End Collection |
| 446 0x85, 0x03, // Report ID (0x3) |
| 447 0x05, 0x0d, // Usage Page (Digitizer) |
| 448 0x09, 0x20, // Usage (0x20) |
| 449 0xa1, 0x00, // Collection (Physical) |
| 450 0xb4, // Pop |
| 451 0x09, 0x30, // Usage (0x30) |
| 452 0x09, 0x31, // Usage (0x31) |
| 453 0x81, 0x02, // Input (Dat|Arr|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 454 0x05, 0x0d, // Usage Page (Digitizer) |
| 455 0x09, 0x32, // Usage (0x32) |
| 456 0x09, 0x44, // Usage (0x44) |
| 457 0x75, 0x01, // Report Size (1) |
| 458 0x15, 0x00, // Logical Minimum (0) |
| 459 0x25, 0x01, // Logical Maximum (1) |
| 460 0x35, 0x00, // Physical Minimum (0) |
| 461 0x45, 0x01, // Physical Maximum (1) |
| 462 0x65, 0x00, // Unit (0) |
| 463 0x81, 0x02, // Input (Dat|Arr|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 464 0x95, 0x06, // Report Count (6) |
| 465 0x81, 0x03, // Input (Con|Arr|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 466 0x09, 0x30, // Usage (0x30) |
| 467 0x15, 0x00, // Logical Minimum (0) |
| 468 0x25, 0x7f, // Logical Maximum (127) |
| 469 0x35, 0x00, // Physical Minimum (0) |
| 470 0x45, 0x2d, // Physical Maximum (45) |
| 471 0x67, 0x11, 0xe1, // Unit (57617) |
| 472 0x00, 0x00, // Default |
| 473 0x55, 0x04, // Unit Exponent (4) |
| 474 0x75, 0x08, // Report Size (8) |
| 475 0x95, 0x01, // Report Count (1) |
| 476 0x81, 0x12, // Input (Dat|Arr|Rel|NoWrp|NoLin|Prf|NoNull|BitF) |
| 477 0xc0, // End Collection |
| 478 0xc0 // End Collection |
| 479 }; |
| 480 |
| 481 // Keyboard descriptor from HID descriptor tool |
| 482 // http://www.usb.org/developers/hidpage/dt2_4.zip |
| 376 const uint8_t kKeyboard[] = { | 483 const uint8_t kKeyboard[] = { |
| 377 0x05, 0x01, 0x09, 0x06, 0xA1, 0x01, 0x05, 0x07, 0x19, 0xE0, 0x29, | 484 0x05, 0x01, // Usage Page (Generic Desktop) |
| 378 0xE7, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x08, 0x81, 0x02, | 485 0x09, 0x06, // Usage (0x6) |
| 379 0x95, 0x01, 0x75, 0x08, 0x81, 0x01, 0x95, 0x05, 0x75, 0x01, 0x05, | 486 0xa1, 0x01, // Collection (Application) |
| 380 0x08, 0x19, 0x01, 0x29, 0x05, 0x91, 0x02, 0x95, 0x01, 0x75, 0x03, | 487 0x05, 0x07, // Usage Page (Keyboard) |
| 381 0x91, 0x01, 0x95, 0x06, 0x75, 0x08, 0x15, 0x00, 0x25, 0x65, 0x05, | 488 0x19, 0xe0, // Usage Minimum (224) |
| 382 0x07, 0x19, 0x00, 0x29, 0x65, 0x81, 0x00, 0xC0}; | 489 0x29, 0xe7, // Usage Maximum (231) |
| 383 | 490 0x15, 0x00, // Logical Minimum (0) |
| 384 // See 'E.10 Report Descriptor (Mouse)' | 491 0x25, 0x01, // Logical Maximum (1) |
| 385 // in HID specifications (v1.11) | 492 0x75, 0x01, // Report Size (1) |
| 386 const uint8_t kMouse[] = {0x05, 0x01, 0x09, 0x02, 0xA1, 0x01, 0x09, 0x01, 0xA1, | 493 0x95, 0x08, // Report Count (8) |
| 387 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x03, 0x15, 0x00, | 494 0x81, 0x02, // Input (Dat|Arr|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 388 0x25, 0x01, 0x95, 0x03, 0x75, 0x01, 0x81, 0x02, 0x95, | 495 0x95, 0x01, // Report Count (1) |
| 389 0x01, 0x75, 0x05, 0x81, 0x01, 0x05, 0x01, 0x09, 0x30, | 496 0x75, 0x08, // Report Size (8) |
| 390 0x09, 0x31, 0x15, 0x81, 0x25, 0x7F, 0x75, 0x08, 0x95, | 497 0x81, 0x03, // Input (Con|Arr|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 391 0x02, 0x81, 0x06, 0xC0, 0xC0}; | 498 0x95, 0x05, // Report Count (5) |
| 392 | 499 0x75, 0x01, // Report Size (1) |
| 500 0x05, 0x08, // Usage Page (Led) |
| 501 0x19, 0x01, // Usage Minimum (1) |
| 502 0x29, 0x05, // Usage Maximum (5) |
| 503 0x91, 0x02, // Output (Dat|Arr|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 504 0x95, 0x01, // Report Count (1) |
| 505 0x75, 0x03, // Report Size (3) |
| 506 0x91, 0x03, // Output (Con|Arr|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 507 0x95, 0x06, // Report Count (6) |
| 508 0x75, 0x08, // Report Size (8) |
| 509 0x15, 0x00, // Logical Minimum (0) |
| 510 0x25, 0x65, // Logical Maximum (101) |
| 511 0x05, 0x07, // Usage Page (Keyboard) |
| 512 0x19, 0x00, // Usage Minimum (0) |
| 513 0x29, 0x65, // Usage Maximum (101) |
| 514 0x81, 0x00, // Input (Dat|Var|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 515 0xc0 // End Collection |
| 516 }; |
| 517 |
| 518 // Monitor descriptor from HID descriptor tool |
| 519 // http://www.usb.org/developers/hidpage/dt2_4.zip |
| 520 const uint8_t kMonitor[] = { |
| 521 0x05, 0x80, // Usage Page (Monitor 0) |
| 522 0x09, 0x01, // Usage (0x1) |
| 523 0xa1, 0x01, // Collection (Application) |
| 524 0x85, 0x01, // Report ID (0x1) |
| 525 0x15, 0x00, // Logical Minimum (0) |
| 526 0x26, 0xff, 0x00, // Logical Maximum (255) |
| 527 0x75, 0x08, // Report Size (8) |
| 528 0x95, 0x80, // Report Count (128) |
| 529 0x09, 0x02, // Usage (0x2) |
| 530 0xb2, 0x02, 0x01, // Feature (Dat|Arr|Rel|NoWrp|Lin|Prf|NoNull|Buff) |
| 531 0x85, 0x02, // Report ID (0x2) |
| 532 0x95, 0xf3, // Report Count (243) |
| 533 0x09, 0x03, // Usage (0x3) |
| 534 0xb2, 0x02, 0x01, // Feature (Dat|Arr|Rel|NoWrp|Lin|Prf|NoNull|Buff) |
| 535 0x85, 0x03, // Report ID (0x3) |
| 536 0x05, 0x82, // Usage Page (Monitor 2) |
| 537 0x95, 0x01, // Report Count (1) |
| 538 0x75, 0x10, // Report Size (16) |
| 539 0x26, 0xc8, 0x00, // Logical Maximum (200) |
| 540 0x09, 0x10, // Usage (0x10) |
| 541 0xb1, 0x02, // Feature (Dat|Arr|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 542 0x85, 0x04, // Report ID (0x4) |
| 543 0x25, 0x64, // Logical Maximum (100) |
| 544 0x09, 0x12, // Usage (0x12) |
| 545 0xb1, 0x02, // Feature (Dat|Arr|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 546 0x95, 0x06, // Report Count (6) |
| 547 0x26, 0xff, 0x00, // Logical Maximum (255) |
| 548 0x09, 0x16, // Usage (0x16) |
| 549 0x09, 0x18, // Usage (0x18) |
| 550 0x09, 0x1a, // Usage (0x1A) |
| 551 0x09, 0x6c, // Usage (0x6C) |
| 552 0x09, 0x6e, // Usage (0x6E) |
| 553 0x09, 0x70, // Usage (0x70) |
| 554 0xb1, 0x02, // Feature (Dat|Arr|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 555 0x85, 0x05, // Report ID (0x5) |
| 556 0x25, 0x7f, // Logical Maximum (127) |
| 557 0x09, 0x20, // Usage (0x20) |
| 558 0x09, 0x22, // Usage (0x22) |
| 559 0x09, 0x30, // Usage (0x30) |
| 560 0x09, 0x32, // Usage (0x32) |
| 561 0x09, 0x42, // Usage (0x42) |
| 562 0x09, 0x44, // Usage (0x44) |
| 563 0xb1, 0x02, // Feature (Dat|Arr|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 564 0xc0 // End Collection |
| 565 }; |
| 566 |
| 567 // Mouse descriptor from HID descriptor tool |
| 568 // http://www.usb.org/developers/hidpage/dt2_4.zip |
| 569 const uint8_t kMouse[] = { |
| 570 0x05, 0x01, // Usage Page (Generic Desktop) |
| 571 0x09, 0x02, // Usage (0x2) |
| 572 0xa1, 0x01, // Collection (Application) |
| 573 0x09, 0x01, // Usage (0x1) |
| 574 0xa1, 0x00, // Collection (Physical) |
| 575 0x05, 0x09, // Usage Page (Button) |
| 576 0x19, 0x01, // Usage Minimum (1) |
| 577 0x29, 0x03, // Usage Maximum (3) |
| 578 0x15, 0x00, // Logical Minimum (0) |
| 579 0x25, 0x01, // Logical Maximum (1) |
| 580 0x95, 0x03, // Report Count (3) |
| 581 0x75, 0x01, // Report Size (1) |
| 582 0x81, 0x02, // Input (Dat|Arr|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 583 0x95, 0x01, // Report Count (1) |
| 584 0x75, 0x05, // Report Size (5) |
| 585 0x81, 0x03, // Input (Con|Arr|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 586 0x05, 0x01, // Usage Page (Generic Desktop) |
| 587 0x09, 0x30, // Usage (0x30) |
| 588 0x09, 0x31, // Usage (0x31) |
| 589 0x15, 0x81, // Logical Minimum (129) |
| 590 0x25, 0x7f, // Logical Maximum (127) |
| 591 0x75, 0x08, // Report Size (8) |
| 592 0x95, 0x02, // Report Count (2) |
| 593 0x81, 0x06, // Input (Dat|Arr|Abs|NoWrp|Lin|Prf|NoNull|BitF) |
| 594 0xc0, // End Collection |
| 595 0xc0 // End Collection |
| 596 }; |
| 597 |
| 598 // Logitech Unifying receiver descriptor |
| 393 const uint8_t kLogitechUnifyingReceiver[] = { | 599 const uint8_t kLogitechUnifyingReceiver[] = { |
| 394 0x06, 0x00, 0xFF, 0x09, 0x01, 0xA1, 0x01, 0x85, 0x10, 0x75, 0x08, | 600 0x06, 0x00, 0xFF, // Usage Page (Vendor) |
| 395 0x95, 0x06, 0x15, 0x00, 0x26, 0xFF, 0x00, 0x09, 0x01, 0x81, 0x00, | 601 0x09, 0x01, // Usage (0x1) |
| 396 0x09, 0x01, 0x91, 0x00, 0xC0, 0x06, 0x00, 0xFF, 0x09, 0x02, 0xA1, | 602 0xA1, 0x01, // Collection (Application) |
| 397 0x01, 0x85, 0x11, 0x75, 0x08, 0x95, 0x13, 0x15, 0x00, 0x26, 0xFF, | 603 0x85, 0x10, // Report ID (0x10) |
| 398 0x00, 0x09, 0x02, 0x81, 0x00, 0x09, 0x02, 0x91, 0x00, 0xC0, 0x06, | 604 0x75, 0x08, // Report Size (8) |
| 399 0x00, 0xFF, 0x09, 0x04, 0xA1, 0x01, 0x85, 0x20, 0x75, 0x08, 0x95, | 605 0x95, 0x06, // Report Count (6) |
| 400 0x0E, 0x15, 0x00, 0x26, 0xFF, 0x00, 0x09, 0x41, 0x81, 0x00, 0x09, | 606 0x15, 0x00, // Logical Minimum (0) |
| 401 0x41, 0x91, 0x00, 0x85, 0x21, 0x95, 0x1F, 0x15, 0x00, 0x26, 0xFF, | 607 0x26, 0xFF, 0x00, // Logical Maximum (255) |
| 402 0x00, 0x09, 0x42, 0x81, 0x00, 0x09, 0x42, 0x91, 0x00, 0xC0}; | 608 0x09, 0x01, // Usage (0x1) |
| 609 0x81, 0x00, // Input (Dat|Var|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 610 0x09, 0x01, // Usage (0x1) |
| 611 0x91, 0x00, // Output (Dat|Var|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 612 0xC0, // End Collection |
| 613 0x06, 0x00, 0xFF, // Usage Page (Vendor) |
| 614 0x09, 0x02, // Usage (0x2) |
| 615 0xA1, 0x01, // Collection (Application) |
| 616 0x85, 0x11, // Report ID (0x11) |
| 617 0x75, 0x08, // Report Size (8) |
| 618 0x95, 0x13, // Report Count (19) |
| 619 0x15, 0x00, // Logical Minimum (0) |
| 620 0x26, 0xFF, 0x00, // Logical Maximum (255) |
| 621 0x09, 0x02, // Usage (0x2) |
| 622 0x81, 0x00, // Input (Dat|Var|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 623 0x09, 0x02, // Usage (0x2) |
| 624 0x91, 0x00, // Output (Dat|Var|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 625 0xC0, // End Collection |
| 626 0x06, 0x00, 0xFF, // Usage Page (Vendor) |
| 627 0x09, 0x04, // Usage (0x4) |
| 628 0xA1, 0x01, // Collection (Application) |
| 629 0x85, 0x20, // Report ID (0x20) |
| 630 0x75, 0x08, // Report Size (8) |
| 631 0x95, 0x0E, // Report Count (14) |
| 632 0x15, 0x00, // Logical Minimum (0) |
| 633 0x26, 0xFF, 0x00, // Logical Maximum (255) |
| 634 0x09, 0x41, // Usage (0x41) |
| 635 0x81, 0x00, // Input (Dat|Var|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 636 0x09, 0x41, // Usage (0x41) |
| 637 0x91, 0x00, // Output (Dat|Var|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 638 0x85, 0x21, // Report ID (0x21) |
| 639 0x95, 0x1F, // Report Count (31) |
| 640 0x15, 0x00, // Logical Minimum (0) |
| 641 0x26, 0xFF, 0x00, // Logical Maximum (255) |
| 642 0x09, 0x42, // Usage (0x42) |
| 643 0x81, 0x00, // Input (Dat|Var|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 644 0x09, 0x42, // Usage (0x42) |
| 645 0x91, 0x00, // Output (Dat|Var|Rel|NoWrp|Lin|Prf|NoNull|BitF) |
| 646 0xC0 // End Collection |
| 647 }; |
| 403 | 648 |
| 404 } // namespace | 649 } // namespace |
| 405 | 650 |
| 406 class HidReportDescriptorTest : public testing::Test { | 651 class HidReportDescriptorTest : public testing::Test { |
| 407 | 652 |
| 408 protected: | 653 protected: |
| 409 virtual void SetUp() OVERRIDE { descriptor_ = NULL; } | 654 virtual void SetUp() OVERRIDE { descriptor_ = NULL; } |
| 410 | 655 |
| 411 virtual void TearDown() OVERRIDE { | 656 virtual void TearDown() OVERRIDE { |
| 412 if (descriptor_) { | 657 if (descriptor_) { |
| 413 delete descriptor_; | 658 delete descriptor_; |
| 414 } | 659 } |
| 415 } | 660 } |
| 416 | 661 |
| 417 public: | 662 public: |
| 418 void ParseDescriptor(const std::string& expected, | 663 void GetTopLevelCollections( |
| 419 const uint8_t* bytes, | 664 const std::vector<HidCollectionInfo>& expected_collections, |
| 420 size_t size) { | 665 const int expected_max_input_report_size, |
| 666 const int expected_max_output_report_size, |
| 667 const int expected_max_feature_report_size, |
| 668 const uint8_t* bytes, |
| 669 size_t size) { |
| 421 descriptor_ = new HidReportDescriptor(bytes, size); | 670 descriptor_ = new HidReportDescriptor(bytes, size); |
| 422 | 671 |
| 423 std::stringstream actual; | 672 DumpDescriptor(*descriptor_); |
| 424 actual << *descriptor_; | |
| 425 | 673 |
| 426 std::cout << "HID report descriptor:" << std::endl; | 674 std::vector<HidCollectionInfo> actual_collections; |
| 427 std::cout << actual.str(); | 675 int actual_max_input_report_size; |
| 676 int actual_max_output_report_size; |
| 677 int actual_max_feature_report_size; |
| 678 descriptor_->GetTopLevelCollections(&actual_collections, |
| 679 &actual_max_input_report_size, |
| 680 &actual_max_output_report_size, |
| 681 &actual_max_feature_report_size); |
| 428 | 682 |
| 429 // TODO(jracle@logitech.com): refactor string comparison in favor of | 683 ASSERT_EQ(expected_collections.size(), actual_collections.size()); |
| 430 // testing individual fields. | |
| 431 ASSERT_EQ(expected, actual.str()); | |
| 432 } | |
| 433 | 684 |
| 434 void GetTopLevelCollections(const std::vector<HidUsageAndPage>& expected, | 685 std::vector<HidCollectionInfo>::const_iterator actual_collections_iter = |
| 435 const uint8_t* bytes, | 686 actual_collections.begin(); |
| 436 size_t size) { | 687 std::vector<HidCollectionInfo>::const_iterator expected_collections_iter = |
| 437 descriptor_ = new HidReportDescriptor(bytes, size); | 688 expected_collections.begin(); |
| 438 | 689 |
| 439 std::vector<HidUsageAndPage> actual; | 690 while (expected_collections_iter != expected_collections.end() && |
| 440 descriptor_->GetTopLevelCollections(&actual); | 691 actual_collections_iter != actual_collections.end()) { |
| 692 HidCollectionInfo expected_collection = *expected_collections_iter; |
| 693 HidCollectionInfo actual_collection = *actual_collections_iter; |
| 441 | 694 |
| 442 std::cout << "HID top-level collections:" << std::endl; | 695 ASSERT_EQ(expected_collection.usage.usage_page, |
| 443 for (std::vector<HidUsageAndPage>::const_iterator iter = actual.begin(); | 696 actual_collection.usage.usage_page); |
| 444 iter != actual.end(); | 697 ASSERT_EQ(expected_collection.usage.usage, actual_collection.usage.usage); |
| 445 ++iter) { | 698 ASSERT_THAT(actual_collection.report_ids, |
| 446 std::cout << *iter << std::endl; | 699 ContainerEq(expected_collection.report_ids)); |
| 700 |
| 701 expected_collections_iter++; |
| 702 actual_collections_iter++; |
| 447 } | 703 } |
| 448 | 704 |
| 449 ASSERT_THAT(actual, ContainerEq(expected)); | 705 ASSERT_EQ(expected_max_input_report_size, actual_max_input_report_size); |
| 706 ASSERT_EQ(expected_max_output_report_size, actual_max_output_report_size); |
| 707 ASSERT_EQ(expected_max_feature_report_size, actual_max_feature_report_size); |
| 450 } | 708 } |
| 451 | 709 |
| 452 private: | 710 private: |
| 453 HidReportDescriptor* descriptor_; | 711 HidReportDescriptor* descriptor_; |
| 454 }; | 712 }; |
| 455 | 713 |
| 456 TEST_F(HidReportDescriptorTest, ParseDescriptor_Keyboard) { | 714 TEST_F(HidReportDescriptorTest, TopLevelCollections_Digitizer) { |
| 457 const char expected[] = { | 715 HidCollectionInfo digitizer; |
| 458 "Usage Page (Generic Desktop)\n" | 716 digitizer.usage = HidUsageAndPage(0x01, HidUsageAndPage::kPageDigitizer); |
| 459 "Usage (0x6)\n" | 717 digitizer.report_ids.insert(1); |
| 460 "Collection (Physical)\n" | 718 digitizer.report_ids.insert(2); |
| 461 " Usage Page (Keyboard)\n" | 719 digitizer.report_ids.insert(3); |
| 462 " Usage Minimum (224)\n" | 720 HidCollectionInfo expected[] = {digitizer}; |
| 463 " Usage Maximum (231)\n" | 721 GetTopLevelCollections(std::vector<HidCollectionInfo>( |
| 464 " Logical Minimum (0)\n" | 722 expected, expected + ARRAYSIZE_UNSAFE(expected)), |
| 465 " Logical Maximum (1)\n" | 723 7, |
| 466 " Report Size (1)\n" | 724 0, |
| 467 " Report Count (8)\n" | 725 0, |
| 468 " Input (Dat|Arr|Rel|NoWrp|Lin|Prf|NoNull|BitF)\n" | 726 kDigitizer, |
| 469 " Report Count (1)\n" | 727 sizeof(kDigitizer)); |
| 470 " Report Size (8)\n" | |
| 471 " Input (Con|Var|Rel|NoWrp|Lin|Prf|NoNull|BitF)\n" | |
| 472 " Report Count (5)\n" | |
| 473 " Report Size (1)\n" | |
| 474 " Usage Page (Led)\n" | |
| 475 " Usage Minimum (1)\n" | |
| 476 " Usage Maximum (5)\n" | |
| 477 " Output (Dat|Arr|Rel|NoWrp|Lin|Prf|NoNull|BitF)\n" | |
| 478 " Report Count (1)\n" | |
| 479 " Report Size (3)\n" | |
| 480 " Output (Con|Var|Rel|NoWrp|Lin|Prf|NoNull|BitF)\n" | |
| 481 " Report Count (6)\n" | |
| 482 " Report Size (8)\n" | |
| 483 " Logical Minimum (0)\n" | |
| 484 " Logical Maximum (101)\n" | |
| 485 " Usage Page (Keyboard)\n" | |
| 486 " Usage Minimum (0)\n" | |
| 487 " Usage Maximum (101)\n" | |
| 488 " Input (Dat|Var|Rel|NoWrp|Lin|Prf|NoNull|BitF)\n" | |
| 489 "End Collection\n"}; | |
| 490 | |
| 491 ParseDescriptor(std::string(expected), kKeyboard, sizeof(kKeyboard)); | |
| 492 } | 728 } |
| 493 | 729 |
| 494 TEST_F(HidReportDescriptorTest, TopLevelCollections_Keyboard) { | 730 TEST_F(HidReportDescriptorTest, TopLevelCollections_Keyboard) { |
| 495 HidUsageAndPage expected[] = { | 731 HidCollectionInfo keyboard; |
| 496 HidUsageAndPage(0x06, HidUsageAndPage::kPageGenericDesktop)}; | 732 keyboard.usage = HidUsageAndPage(0x06, HidUsageAndPage::kPageGenericDesktop); |
| 497 | 733 HidCollectionInfo expected[] = {keyboard}; |
| 498 GetTopLevelCollections(std::vector<HidUsageAndPage>( | 734 GetTopLevelCollections(std::vector<HidCollectionInfo>( |
| 499 expected, expected + ARRAYSIZE_UNSAFE(expected)), | 735 expected, expected + ARRAYSIZE_UNSAFE(expected)), |
| 736 8, |
| 737 1, |
| 738 0, |
| 500 kKeyboard, | 739 kKeyboard, |
| 501 sizeof(kKeyboard)); | 740 sizeof(kKeyboard)); |
| 502 } | 741 } |
| 503 | 742 |
| 504 TEST_F(HidReportDescriptorTest, ParseDescriptor_Mouse) { | 743 TEST_F(HidReportDescriptorTest, TopLevelCollections_Monitor) { |
| 505 const char expected[] = { | 744 HidCollectionInfo monitor; |
| 506 "Usage Page (Generic Desktop)\n" | 745 monitor.usage = HidUsageAndPage(0x01, HidUsageAndPage::kPageMonitor0); |
| 507 "Usage (0x2)\n" | 746 monitor.report_ids.insert(1); |
| 508 "Collection (Physical)\n" | 747 monitor.report_ids.insert(2); |
| 509 " Usage (0x1)\n" | 748 monitor.report_ids.insert(3); |
| 510 " Collection (Physical)\n" | 749 monitor.report_ids.insert(4); |
| 511 " Usage Page (Button)\n" | 750 monitor.report_ids.insert(5); |
| 512 " Usage Minimum (1)\n" | 751 HidCollectionInfo expected[] = {monitor}; |
| 513 " Usage Maximum (3)\n" | 752 GetTopLevelCollections(std::vector<HidCollectionInfo>( |
| 514 " Logical Minimum (0)\n" | 753 expected, expected + ARRAYSIZE_UNSAFE(expected)), |
| 515 " Logical Maximum (1)\n" | 754 0, |
| 516 " Report Count (3)\n" | 755 0, |
| 517 " Report Size (1)\n" | 756 244, |
| 518 " Input (Dat|Arr|Rel|NoWrp|Lin|Prf|NoNull|BitF)\n" | 757 kMonitor, |
| 519 " Report Count (1)\n" | 758 sizeof(kMonitor)); |
| 520 " Report Size (5)\n" | |
| 521 " Input (Con|Var|Rel|NoWrp|Lin|Prf|NoNull|BitF)\n" | |
| 522 " Usage Page (Generic Desktop)\n" | |
| 523 " Usage (0x30)\n" | |
| 524 " Usage (0x31)\n" | |
| 525 " Logical Minimum (129)\n" | |
| 526 " Logical Maximum (127)\n" | |
| 527 " Report Size (8)\n" | |
| 528 " Report Count (2)\n" | |
| 529 " Input (Dat|Arr|Abs|NoWrp|Lin|Prf|NoNull|BitF)\n" | |
| 530 " End Collection\n" | |
| 531 "End Collection\n"}; | |
| 532 | |
| 533 ParseDescriptor(std::string(expected), kMouse, sizeof(kMouse)); | |
| 534 } | 759 } |
| 535 | 760 |
| 536 TEST_F(HidReportDescriptorTest, TopLevelCollections_Mouse) { | 761 TEST_F(HidReportDescriptorTest, TopLevelCollections_Mouse) { |
| 537 HidUsageAndPage expected[] = { | 762 HidCollectionInfo mouse; |
| 538 HidUsageAndPage(0x02, HidUsageAndPage::kPageGenericDesktop)}; | 763 mouse.usage = HidUsageAndPage(0x02, HidUsageAndPage::kPageGenericDesktop); |
| 539 | 764 HidCollectionInfo expected[] = {mouse}; |
| 540 GetTopLevelCollections(std::vector<HidUsageAndPage>( | 765 GetTopLevelCollections(std::vector<HidCollectionInfo>( |
| 541 expected, expected + ARRAYSIZE_UNSAFE(expected)), | 766 expected, expected + ARRAYSIZE_UNSAFE(expected)), |
| 767 3, |
| 768 0, |
| 769 0, |
| 542 kMouse, | 770 kMouse, |
| 543 sizeof(kMouse)); | 771 sizeof(kMouse)); |
| 544 } | 772 } |
| 545 | 773 |
| 546 TEST_F(HidReportDescriptorTest, ParseDescriptor_LogitechUnifyingReceiver) { | 774 TEST_F(HidReportDescriptorTest, TopLevelCollections_LogitechUnifyingReceiver) { |
| 547 const char expected[] = { | 775 HidCollectionInfo hidpp_short; |
| 548 "Usage Page (Vendor)\n" | 776 hidpp_short.usage = HidUsageAndPage(0x01, HidUsageAndPage::kPageVendor); |
| 549 "Usage (0x1)\n" | 777 hidpp_short.report_ids.insert(0x10); |
| 550 "Collection (Physical)\n" | 778 HidCollectionInfo hidpp_long; |
| 551 " Report ID (0x10)\n" | 779 hidpp_long.usage = HidUsageAndPage(0x02, HidUsageAndPage::kPageVendor); |
| 552 " Report Size (8)\n" | 780 hidpp_long.report_ids.insert(0x11); |
| 553 " Report Count (6)\n" | 781 HidCollectionInfo hidpp_dj; |
| 554 " Logical Minimum (0)\n" | 782 hidpp_dj.usage = HidUsageAndPage(0x04, HidUsageAndPage::kPageVendor); |
| 555 " Logical Maximum (255)\n" | 783 hidpp_dj.report_ids.insert(0x20); |
| 556 " Usage (0x1)\n" | 784 hidpp_dj.report_ids.insert(0x21); |
| 557 " Input (Dat|Var|Rel|NoWrp|Lin|Prf|NoNull|BitF)\n" | |
| 558 " Usage (0x1)\n" | |
| 559 " Output (Dat|Var|Rel|NoWrp|Lin|Prf|NoNull|BitF)\n" | |
| 560 "End Collection\n" | |
| 561 "Usage Page (Vendor)\n" | |
| 562 "Usage (0x2)\n" | |
| 563 "Collection (Physical)\n" | |
| 564 " Report ID (0x11)\n" | |
| 565 " Report Size (8)\n" | |
| 566 " Report Count (19)\n" | |
| 567 " Logical Minimum (0)\n" | |
| 568 " Logical Maximum (255)\n" | |
| 569 " Usage (0x2)\n" | |
| 570 " Input (Dat|Var|Rel|NoWrp|Lin|Prf|NoNull|BitF)\n" | |
| 571 " Usage (0x2)\n" | |
| 572 " Output (Dat|Var|Rel|NoWrp|Lin|Prf|NoNull|BitF)\n" | |
| 573 "End Collection\n" | |
| 574 "Usage Page (Vendor)\n" | |
| 575 "Usage (0x4)\n" | |
| 576 "Collection (Physical)\n" | |
| 577 " Report ID (0x20)\n" | |
| 578 " Report Size (8)\n" | |
| 579 " Report Count (14)\n" | |
| 580 " Logical Minimum (0)\n" | |
| 581 " Logical Maximum (255)\n" | |
| 582 " Usage (0x41)\n" | |
| 583 " Input (Dat|Var|Rel|NoWrp|Lin|Prf|NoNull|BitF)\n" | |
| 584 " Usage (0x41)\n" | |
| 585 " Output (Dat|Var|Rel|NoWrp|Lin|Prf|NoNull|BitF)\n" | |
| 586 " Report ID (0x21)\n" | |
| 587 " Report Count (31)\n" | |
| 588 " Logical Minimum (0)\n" | |
| 589 " Logical Maximum (255)\n" | |
| 590 " Usage (0x42)\n" | |
| 591 " Input (Dat|Var|Rel|NoWrp|Lin|Prf|NoNull|BitF)\n" | |
| 592 " Usage (0x42)\n" | |
| 593 " Output (Dat|Var|Rel|NoWrp|Lin|Prf|NoNull|BitF)\n" | |
| 594 "End Collection\n"}; | |
| 595 | 785 |
| 596 ParseDescriptor(std::string(expected), | 786 HidCollectionInfo expected[] = {hidpp_short, hidpp_long, hidpp_dj}; |
| 597 kLogitechUnifyingReceiver, | 787 GetTopLevelCollections(std::vector<HidCollectionInfo>( |
| 598 sizeof(kLogitechUnifyingReceiver)); | |
| 599 } | |
| 600 | |
| 601 TEST_F(HidReportDescriptorTest, TopLevelCollections_LogitechUnifyingReceiver) { | |
| 602 HidUsageAndPage expected[] = { | |
| 603 HidUsageAndPage(0x01, HidUsageAndPage::kPageVendor), | |
| 604 HidUsageAndPage(0x02, HidUsageAndPage::kPageVendor), | |
| 605 HidUsageAndPage(0x04, HidUsageAndPage::kPageVendor), }; | |
| 606 | |
| 607 GetTopLevelCollections(std::vector<HidUsageAndPage>( | |
| 608 expected, expected + ARRAYSIZE_UNSAFE(expected)), | 788 expected, expected + ARRAYSIZE_UNSAFE(expected)), |
| 789 32, |
| 790 32, |
| 791 0, |
| 609 kLogitechUnifyingReceiver, | 792 kLogitechUnifyingReceiver, |
| 610 sizeof(kLogitechUnifyingReceiver)); | 793 sizeof(kLogitechUnifyingReceiver)); |
| 611 } | 794 } |
| 612 | 795 |
| 613 } // namespace device | 796 } // namespace device |
| OLD | NEW |