Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Side by Side Diff: device/hid/hid_report_descriptor_unittest.cc

Issue 317783010: chrome.hid: enrich model with report IDs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove HidConnection2 Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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) {
Ken Rockot(use gerrit already) 2014/06/27 14:50:22 It looks like if you get rid of this, you can get
jracle (use Gerrit) 2014/06/27 20:07:07 Sure, now we can indeed. On 2014/06/27 14:50:22,
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 GetDetails(const std::vector<HidCollectionInfo>& expected_collections,
Ken Rockot(use gerrit already) 2014/06/27 14:50:22 ValidateDetails?
jracle (use Gerrit) 2014/06/27 20:07:07 Much better, reflects what it does.. On 2014/06/2
419 const uint8_t* bytes, 664 const int expected_max_input_report_size,
420 size_t size) { 665 const int expected_max_output_report_size,
666 const int expected_max_feature_report_size,
667 const uint8_t* bytes,
668 size_t size) {
421 descriptor_ = new HidReportDescriptor(bytes, size); 669 descriptor_ = new HidReportDescriptor(bytes, size);
422 670
423 std::stringstream actual; 671 DumpDescriptor(*descriptor_);
424 actual << *descriptor_;
425 672
426 std::cout << "HID report descriptor:" << std::endl; 673 std::vector<HidCollectionInfo> actual_collections;
427 std::cout << actual.str(); 674 int actual_max_input_report_size;
675 int actual_max_output_report_size;
676 int actual_max_feature_report_size;
677 descriptor_->GetDetails(&actual_collections,
678 &actual_max_input_report_size,
679 &actual_max_output_report_size,
680 &actual_max_feature_report_size);
428 681
429 // TODO(jracle@logitech.com): refactor string comparison in favor of 682 ASSERT_EQ(expected_collections.size(), actual_collections.size());
430 // testing individual fields.
431 ASSERT_EQ(expected, actual.str());
432 }
433 683
434 void GetTopLevelCollections(const std::vector<HidUsageAndPage>& expected, 684 std::vector<HidCollectionInfo>::const_iterator actual_collections_iter =
435 const uint8_t* bytes, 685 actual_collections.begin();
436 size_t size) { 686 std::vector<HidCollectionInfo>::const_iterator expected_collections_iter =
437 descriptor_ = new HidReportDescriptor(bytes, size); 687 expected_collections.begin();
438 688
439 std::vector<HidUsageAndPage> actual; 689 while (expected_collections_iter != expected_collections.end() &&
440 descriptor_->GetTopLevelCollections(&actual); 690 actual_collections_iter != actual_collections.end()) {
691 HidCollectionInfo expected_collection = *expected_collections_iter;
692 HidCollectionInfo actual_collection = *actual_collections_iter;
441 693
442 std::cout << "HID top-level collections:" << std::endl; 694 ASSERT_EQ(expected_collection.usage.usage_page,
443 for (std::vector<HidUsageAndPage>::const_iterator iter = actual.begin(); 695 actual_collection.usage.usage_page);
444 iter != actual.end(); 696 ASSERT_EQ(expected_collection.usage.usage, actual_collection.usage.usage);
445 ++iter) { 697 ASSERT_THAT(actual_collection.report_ids,
446 std::cout << *iter << std::endl; 698 ContainerEq(expected_collection.report_ids));
699
700 expected_collections_iter++;
701 actual_collections_iter++;
447 } 702 }
448 703
449 ASSERT_THAT(actual, ContainerEq(expected)); 704 ASSERT_EQ(expected_max_input_report_size, actual_max_input_report_size);
705 ASSERT_EQ(expected_max_output_report_size, actual_max_output_report_size);
706 ASSERT_EQ(expected_max_feature_report_size, actual_max_feature_report_size);
450 } 707 }
451 708
452 private: 709 private:
453 HidReportDescriptor* descriptor_; 710 HidReportDescriptor* descriptor_;
454 }; 711 };
455 712
456 TEST_F(HidReportDescriptorTest, ParseDescriptor_Keyboard) { 713 TEST_F(HidReportDescriptorTest, GetDetails_Digitizer) {
457 const char expected[] = { 714 HidCollectionInfo digitizer;
458 "Usage Page (Generic Desktop)\n" 715 digitizer.usage = HidUsageAndPage(0x01, HidUsageAndPage::kPageDigitizer);
459 "Usage (0x6)\n" 716 digitizer.report_ids.insert(1);
460 "Collection (Physical)\n" 717 digitizer.report_ids.insert(2);
461 " Usage Page (Keyboard)\n" 718 digitizer.report_ids.insert(3);
462 " Usage Minimum (224)\n" 719 HidCollectionInfo expected[] = {digitizer};
463 " Usage Maximum (231)\n" 720 GetDetails(std::vector<HidCollectionInfo>(
464 " Logical Minimum (0)\n" 721 expected, expected + ARRAYSIZE_UNSAFE(expected)),
465 " Logical Maximum (1)\n" 722 7,
466 " Report Size (1)\n" 723 0,
467 " Report Count (8)\n" 724 0,
468 " Input (Dat|Arr|Rel|NoWrp|Lin|Prf|NoNull|BitF)\n" 725 kDigitizer,
469 " Report Count (1)\n" 726 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 } 727 }
493 728
494 TEST_F(HidReportDescriptorTest, TopLevelCollections_Keyboard) { 729 TEST_F(HidReportDescriptorTest, GetDetails_Keyboard) {
495 HidUsageAndPage expected[] = { 730 HidCollectionInfo keyboard;
496 HidUsageAndPage(0x06, HidUsageAndPage::kPageGenericDesktop)}; 731 keyboard.usage = HidUsageAndPage(0x06, HidUsageAndPage::kPageGenericDesktop);
497 732 HidCollectionInfo expected[] = {keyboard};
498 GetTopLevelCollections(std::vector<HidUsageAndPage>( 733 GetDetails(std::vector<HidCollectionInfo>(
499 expected, expected + ARRAYSIZE_UNSAFE(expected)), 734 expected, expected + ARRAYSIZE_UNSAFE(expected)),
500 kKeyboard, 735 8,
501 sizeof(kKeyboard)); 736 1,
737 0,
738 kKeyboard,
739 sizeof(kKeyboard));
502 } 740 }
503 741
504 TEST_F(HidReportDescriptorTest, ParseDescriptor_Mouse) { 742 TEST_F(HidReportDescriptorTest, GetDetails_Monitor) {
505 const char expected[] = { 743 HidCollectionInfo monitor;
506 "Usage Page (Generic Desktop)\n" 744 monitor.usage = HidUsageAndPage(0x01, HidUsageAndPage::kPageMonitor0);
507 "Usage (0x2)\n" 745 monitor.report_ids.insert(1);
508 "Collection (Physical)\n" 746 monitor.report_ids.insert(2);
509 " Usage (0x1)\n" 747 monitor.report_ids.insert(3);
510 " Collection (Physical)\n" 748 monitor.report_ids.insert(4);
511 " Usage Page (Button)\n" 749 monitor.report_ids.insert(5);
512 " Usage Minimum (1)\n" 750 HidCollectionInfo expected[] = {monitor};
513 " Usage Maximum (3)\n" 751 GetDetails(std::vector<HidCollectionInfo>(
514 " Logical Minimum (0)\n" 752 expected, expected + ARRAYSIZE_UNSAFE(expected)),
515 " Logical Maximum (1)\n" 753 0,
516 " Report Count (3)\n" 754 0,
517 " Report Size (1)\n" 755 244,
518 " Input (Dat|Arr|Rel|NoWrp|Lin|Prf|NoNull|BitF)\n" 756 kMonitor,
519 " Report Count (1)\n" 757 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 } 758 }
535 759
536 TEST_F(HidReportDescriptorTest, TopLevelCollections_Mouse) { 760 TEST_F(HidReportDescriptorTest, GetDetails_Mouse) {
537 HidUsageAndPage expected[] = { 761 HidCollectionInfo mouse;
538 HidUsageAndPage(0x02, HidUsageAndPage::kPageGenericDesktop)}; 762 mouse.usage = HidUsageAndPage(0x02, HidUsageAndPage::kPageGenericDesktop);
539 763 HidCollectionInfo expected[] = {mouse};
540 GetTopLevelCollections(std::vector<HidUsageAndPage>( 764 GetDetails(std::vector<HidCollectionInfo>(
541 expected, expected + ARRAYSIZE_UNSAFE(expected)), 765 expected, expected + ARRAYSIZE_UNSAFE(expected)),
542 kMouse, 766 3,
543 sizeof(kMouse)); 767 0,
768 0,
769 kMouse,
770 sizeof(kMouse));
544 } 771 }
545 772
546 TEST_F(HidReportDescriptorTest, ParseDescriptor_LogitechUnifyingReceiver) { 773 TEST_F(HidReportDescriptorTest, GetDetails_LogitechUnifyingReceiver) {
547 const char expected[] = { 774 HidCollectionInfo hidpp_short;
548 "Usage Page (Vendor)\n" 775 hidpp_short.usage = HidUsageAndPage(0x01, HidUsageAndPage::kPageVendor);
549 "Usage (0x1)\n" 776 hidpp_short.report_ids.insert(0x10);
550 "Collection (Physical)\n" 777 HidCollectionInfo hidpp_long;
551 " Report ID (0x10)\n" 778 hidpp_long.usage = HidUsageAndPage(0x02, HidUsageAndPage::kPageVendor);
552 " Report Size (8)\n" 779 hidpp_long.report_ids.insert(0x11);
553 " Report Count (6)\n" 780 HidCollectionInfo hidpp_dj;
554 " Logical Minimum (0)\n" 781 hidpp_dj.usage = HidUsageAndPage(0x04, HidUsageAndPage::kPageVendor);
555 " Logical Maximum (255)\n" 782 hidpp_dj.report_ids.insert(0x20);
556 " Usage (0x1)\n" 783 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 784
596 ParseDescriptor(std::string(expected), 785 HidCollectionInfo expected[] = {hidpp_short, hidpp_long, hidpp_dj};
597 kLogitechUnifyingReceiver, 786 GetDetails(std::vector<HidCollectionInfo>(
598 sizeof(kLogitechUnifyingReceiver)); 787 expected, expected + ARRAYSIZE_UNSAFE(expected)),
599 } 788 32,
600 789 32,
601 TEST_F(HidReportDescriptorTest, TopLevelCollections_LogitechUnifyingReceiver) { 790 0,
602 HidUsageAndPage expected[] = { 791 kLogitechUnifyingReceiver,
603 HidUsageAndPage(0x01, HidUsageAndPage::kPageVendor), 792 sizeof(kLogitechUnifyingReceiver));
604 HidUsageAndPage(0x02, HidUsageAndPage::kPageVendor),
605 HidUsageAndPage(0x04, HidUsageAndPage::kPageVendor), };
606
607 GetTopLevelCollections(std::vector<HidUsageAndPage>(
608 expected, expected + ARRAYSIZE_UNSAFE(expected)),
609 kLogitechUnifyingReceiver,
610 sizeof(kLogitechUnifyingReceiver));
611 } 793 }
612 794
613 } // namespace device 795 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698