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

Side by Side Diff: tools/usb_gadget/hid_descriptors_test.py

Issue 418603003: [usb_gadget p05] Add a HID mouse gadget. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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
« no previous file with comments | « no previous file | tools/usb_gadget/mouse_gadget.py » ('j') | tools/usb_gadget/mouse_gadget.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import unittest 6 import unittest
7 7
8 import hid_constants
9 import hid_descriptors 8 import hid_descriptors
10 import keyboard_gadget 9 import keyboard_gadget
10 import mouse_gadget
11 11
12 12
13 class HidTest(unittest.TestCase): 13 class HidTest(unittest.TestCase):
14 14
15 def test_keyboard_example(self): 15 def test_keyboard_example(self):
16 expected = ''.join(chr(x) for x in [ 16 expected = ''.join(chr(x) for x in [
17 0x05, 0x01, 0x09, 0x06, 0xA1, 0x01, 0x05, 0x07, 0x19, 0xE0, 0x29, 17 0x05, 0x01, 0x09, 0x06, 0xA1, 0x01, 0x05, 0x07, 0x19, 0xE0, 0x29,
18 0xE7, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x08, 0x81, 0x02, 18 0xE7, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x08, 0x81, 0x02,
19 0x95, 0x01, 0x75, 0x08, 0x81, 0x01, 0x95, 0x05, 0x75, 0x01, 0x05, 19 0x95, 0x01, 0x75, 0x08, 0x81, 0x01, 0x95, 0x05, 0x75, 0x01, 0x05,
20 0x08, 0x19, 0x01, 0x29, 0x05, 0x91, 0x02, 0x95, 0x01, 0x75, 0x03, 20 0x08, 0x19, 0x01, 0x29, 0x05, 0x91, 0x02, 0x95, 0x01, 0x75, 0x03,
21 0x91, 0x01, 0x95, 0x06, 0x75, 0x08, 0x15, 0x00, 0x25, 0x65, 0x05, 21 0x91, 0x01, 0x95, 0x06, 0x75, 0x08, 0x15, 0x00, 0x25, 0x65, 0x05,
22 0x07, 0x19, 0x00, 0x29, 0x65, 0x81, 0x00, 0xC0 22 0x07, 0x19, 0x00, 0x29, 0x65, 0x81, 0x00, 0xC0
23 ]) 23 ])
24 self.assertEquals(keyboard_gadget.KeyboardFeature.REPORT_DESC, expected) 24 self.assertEquals(keyboard_gadget.KeyboardFeature.REPORT_DESC, expected)
25 25
26 def test_mouse_example(self): 26 def test_mouse_example(self):
27 report_desc = hid_descriptors.ReportDescriptor(
28 hid_descriptors.UsagePage(0x01), # Generic Desktop
29 hid_descriptors.Usage(0x02), # Mouse
30 hid_descriptors.Collection(
31 hid_constants.CollectionType.APPLICATION,
32 hid_descriptors.Usage(0x01), # Pointer
33 hid_descriptors.Collection(
34 hid_constants.CollectionType.PHYSICAL,
35 hid_descriptors.UsagePage(0x09), # Buttons
36 hid_descriptors.UsageMinimum(1),
37 hid_descriptors.UsageMaximum(3),
38 hid_descriptors.LogicalMinimum(0, force_length=1),
39 hid_descriptors.LogicalMaximum(1),
40 hid_descriptors.ReportCount(3),
41 hid_descriptors.ReportSize(1),
42 hid_descriptors.Input(hid_descriptors.Data,
43 hid_descriptors.Variable,
44 hid_descriptors.Absolute),
45 hid_descriptors.ReportCount(1),
46 hid_descriptors.ReportSize(5),
47 hid_descriptors.Input(hid_descriptors.Constant),
48 hid_descriptors.UsagePage(0x01), # Generic Desktop
49 hid_descriptors.Usage(0x30), # X
50 hid_descriptors.Usage(0x31), # Y
51 hid_descriptors.LogicalMinimum(0x81), # -127
52 hid_descriptors.LogicalMaximum(127),
53 hid_descriptors.ReportSize(8),
54 hid_descriptors.ReportCount(2),
55 hid_descriptors.Input(hid_descriptors.Data,
56 hid_descriptors.Variable,
57 hid_descriptors.Relative)
58 )
59 )
60 )
61
62 expected = ''.join(chr(x) for x in [ 27 expected = ''.join(chr(x) for x in [
63 0x05, 0x01, 0x09, 0x02, 0xA1, 0x01, 0x09, 0x01, 0xA1, 0x00, 0x05, 0x09, 28 0x05, 0x01, 0x09, 0x02, 0xA1, 0x01, 0x09, 0x01, 0xA1, 0x00, 0x05, 0x09,
64 0x19, 0x01, 0x29, 0x03, 0x15, 0x00, 0x25, 0x01, 0x95, 0x03, 0x75, 0x01, 29 0x19, 0x01, 0x29, 0x03, 0x15, 0x00, 0x25, 0x01, 0x95, 0x03, 0x75, 0x01,
65 0x81, 0x02, 0x95, 0x01, 0x75, 0x05, 0x81, 0x01, 0x05, 0x01, 0x09, 0x30, 30 0x81, 0x02, 0x95, 0x01, 0x75, 0x05, 0x81, 0x01, 0x05, 0x01, 0x09, 0x30,
66 0x09, 0x31, 0x15, 0x81, 0x25, 0x7F, 0x75, 0x08, 0x95, 0x02, 0x81, 0x06, 31 0x09, 0x31, 0x15, 0x81, 0x25, 0x7F, 0x75, 0x08, 0x95, 0x02, 0x81, 0x06,
67 0xC0, 0xC0 32 0xC0, 0xC0
68 ]) 33 ])
69 self.assertEquals(report_desc, expected) 34 self.assertEquals(mouse_gadget.MouseFeature.REPORT_DESC, expected)
70 35
71 def test_tag(self): 36 def test_tag(self):
72 self.assertEquals(hid_descriptors.Push(), '\xa4') 37 self.assertEquals(hid_descriptors.Push(), '\xa4')
73 38
74 def test_2byte_tag(self): 39 def test_2byte_tag(self):
75 self.assertEquals(hid_descriptors.LogicalMaximum(0xFF00), '\x26\x00\xFF') 40 self.assertEquals(hid_descriptors.LogicalMaximum(0xFF00), '\x26\x00\xFF')
76 41
77 def test_4byte_tag(self): 42 def test_4byte_tag(self):
78 self.assertEquals(hid_descriptors.LogicalMaximum(0xFF884400), 43 self.assertEquals(hid_descriptors.LogicalMaximum(0xFF884400),
79 '\x27\x00\x44\x88\xFF') 44 '\x27\x00\x44\x88\xFF')
80 45
81 def test_long_tag(self): 46 def test_long_tag(self):
82 with self.assertRaises(NotImplementedError): 47 with self.assertRaises(NotImplementedError):
83 hid_descriptors.LogicalMaximum(0xFFFFFFFFFFFFFFFF) 48 hid_descriptors.LogicalMaximum(0xFFFFFFFFFFFFFFFF)
84 49
85 if __name__ == '__main__': 50 if __name__ == '__main__':
86 unittest.main() 51 unittest.main()
OLDNEW
« no previous file with comments | « no previous file | tools/usb_gadget/mouse_gadget.py » ('j') | tools/usb_gadget/mouse_gadget.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698