OLD | NEW |
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 |
8 import usb_descriptors | 9 import usb_descriptors |
9 | 10 |
10 | 11 |
11 class DescriptorWithField(usb_descriptors.Descriptor): | 12 class DescriptorWithField(usb_descriptors.Descriptor): |
12 pass | 13 pass |
13 | 14 |
14 DescriptorWithField.AddField('bField', 'B') | 15 DescriptorWithField.AddField('bField', 'B') |
15 | 16 |
16 | 17 |
17 class DescriptorWithDefault(usb_descriptors.Descriptor): | 18 class DescriptorWithDefault(usb_descriptors.Descriptor): |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 bmAttributes=0xC0, | 189 bmAttributes=0xC0, |
189 MaxPower=100) | 190 MaxPower=100) |
190 configuration_desc.AddInterface(interface_desc) | 191 configuration_desc.AddInterface(interface_desc) |
191 self.assertEquals([interface_desc], configuration_desc.GetInterfaces()) | 192 self.assertEquals([interface_desc], configuration_desc.GetInterfaces()) |
192 encoded_configuration = ('\x09\x02\x19\x00\x01\x01\x00\xC0\x64' + | 193 encoded_configuration = ('\x09\x02\x19\x00\x01\x01\x00\xC0\x64' + |
193 encoded_interface) | 194 encoded_interface) |
194 self.assertEquals(configuration_desc.Encode(), encoded_configuration) | 195 self.assertEquals(configuration_desc.Encode(), encoded_configuration) |
195 | 196 |
196 def test_encode_hid_descriptor(self): | 197 def test_encode_hid_descriptor(self): |
197 hid_desc = usb_descriptors.HidDescriptor() | 198 hid_desc = usb_descriptors.HidDescriptor() |
198 hid_desc.AddDescriptor(0x22, 0x80) | 199 hid_desc.AddDescriptor(hid_constants.DescriptorType.REPORT, 0x80) |
199 hid_desc.AddDescriptor(0x23, 0x60) | 200 hid_desc.AddDescriptor(hid_constants.DescriptorType.PHYSICAL, 0x60) |
200 encoded_desc = '\x0C\x21\x11\x01\x00\x02\x22\x80\x00\x23\x60\x00' | 201 encoded_desc = '\x0C\x21\x11\x01\x00\x02\x22\x80\x00\x23\x60\x00' |
201 self.assertEquals(hid_desc.Encode(), encoded_desc) | 202 self.assertEquals(hid_desc.Encode(), encoded_desc) |
202 | 203 |
203 def test_print_hid_descriptor(self): | 204 def test_print_hid_descriptor(self): |
204 hid_desc = usb_descriptors.HidDescriptor() | 205 hid_desc = usb_descriptors.HidDescriptor() |
205 hid_desc.AddDescriptor(0x22, 0x80) | 206 hid_desc.AddDescriptor(hid_constants.DescriptorType.REPORT, 0x80) |
206 hid_desc.AddDescriptor(0x23, 0x60) | 207 hid_desc.AddDescriptor(hid_constants.DescriptorType.PHYSICAL, 0x60) |
207 string = str(hid_desc) | 208 string = str(hid_desc) |
208 self.assertIn('0x22', string) | 209 self.assertIn('0x22', string) |
209 self.assertIn('0x23', string) | 210 self.assertIn('0x23', string) |
210 | 211 |
211 | 212 |
212 if __name__ == '__main__': | 213 if __name__ == '__main__': |
213 unittest.main() | 214 unittest.main() |
OLD | NEW |