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

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

Issue 410813002: [usb_gadget p01] Functions for encoding HID descriptors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed copyright text and added specification references. 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 | « tools/usb_gadget/usb_descriptors.py ('k') | no next file » | no next file with comments »
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
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
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()
OLDNEW
« no previous file with comments | « tools/usb_gadget/usb_descriptors.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698