77
88import static org .junit .Assert .assertEquals ;
99import static org .junit .Assert .assertFalse ;
10- import static org .junit .Assert .assertNotEquals ;
1110import static org .junit .Assert .assertTrue ;
1211
1312import org .junit .BeforeClass ;
1413import org .junit .Test ;
15- import org .usb4java .javax .descriptors .SimpleUsbConfigurationDescriptor ;
1614
1715/**
1816 * Tests the {@link SimpleUsbConfigurationDescriptor}.
@@ -25,30 +23,30 @@ public class SimpleUsbConfigurationDescriptorTest
2523 private static SimpleUsbConfigurationDescriptor descriptor ;
2624
2725 /** Value for {@link SimpleUsbConfigurationDescriptor#bLength()}. */
28- private static final byte LENGTH = 1 ;
26+ private static final byte LENGTH = ( byte ) 0xff ;
2927
3028 /** Value for {@link SimpleUsbConfigurationDescriptor#bDescriptorType()}. */
31- private static final byte DESCRIPTOR_TYPE = 2 ;
29+ private static final byte DESCRIPTOR_TYPE = ( byte ) 0xfe ;
3230
3331 /** Value for {@link SimpleUsbConfigurationDescriptor#wTotalLength()}. */
34- private static final short TOTAL_LENGTH = 3 ;
32+ private static final short TOTAL_LENGTH = ( short ) 0xffff ;
3533
3634 /** Value for {@link SimpleUsbConfigurationDescriptor#bNumInterfaces()}. */
37- private static final byte NUM_INTERFACES = 4 ;
35+ private static final byte NUM_INTERFACES = ( byte ) 0xfc ;
3836
3937 /**
4038 * Value for {@link SimpleUsbConfigurationDescriptor#bConfigurationValue()}.
4139 */
42- private static final byte CONFIGURATION_VALUE = 5 ;
40+ private static final byte CONFIGURATION_VALUE = ( byte ) 0xfb ;
4341
4442 /** Value for {@link SimpleUsbConfigurationDescriptor#iConfiguration()}. */
45- private static final byte CONFIGURATION = 6 ;
43+ private static final byte CONFIGURATION = ( byte ) 0xfa ;
4644
4745 /** Value for {@link SimpleUsbConfigurationDescriptor#bmAttributes()}. */
48- private static final byte ATTRIBUTES = 7 ;
46+ private static final byte ATTRIBUTES = ( byte ) 0xf9 ;
4947
5048 /** Value for {@link SimpleUsbConfigurationDescriptor#bMaxPower()}. */
51- private static final byte MAX_POWER = 8 ;
49+ private static final byte MAX_POWER = ( byte ) 0xf8 ;
5250
5351 /** A wrong value for equality test. */
5452 private static final byte WRONG = 0 ;
@@ -150,7 +148,7 @@ public void testHashCode()
150148 assertEquals (code , descriptor .hashCode ());
151149 assertEquals (code , new SimpleUsbConfigurationDescriptor (
152150 LENGTH , DESCRIPTOR_TYPE , TOTAL_LENGTH , NUM_INTERFACES ,
153- CONFIGURATION_VALUE , CONFIGURATION , ATTRIBUTES ,
151+ CONFIGURATION_VALUE , CONFIGURATION , ATTRIBUTES ,
154152 MAX_POWER ).hashCode ());
155153 }
156154
@@ -198,50 +196,30 @@ public void testEquals()
198196 @ Test
199197 public void testToString ()
200198 {
201- assertEquals (descriptor .toString (), descriptor .toString ());
202- assertEquals (descriptor .toString (),
203- new SimpleUsbConfigurationDescriptor (
204- LENGTH , DESCRIPTOR_TYPE , TOTAL_LENGTH , NUM_INTERFACES ,
205- CONFIGURATION_VALUE , CONFIGURATION , ATTRIBUTES ,
206- MAX_POWER ).toString ());
207- assertNotEquals (descriptor .toString (),
208- new SimpleUsbConfigurationDescriptor (
209- WRONG , DESCRIPTOR_TYPE , TOTAL_LENGTH , NUM_INTERFACES ,
210- CONFIGURATION_VALUE , CONFIGURATION , ATTRIBUTES , MAX_POWER )
211- .toString ());
212- assertNotEquals (descriptor .toString (),
213- new SimpleUsbConfigurationDescriptor (
214- LENGTH , WRONG , TOTAL_LENGTH , NUM_INTERFACES ,
215- CONFIGURATION_VALUE , CONFIGURATION , ATTRIBUTES , MAX_POWER )
216- .toString ());
217- assertNotEquals (descriptor .toString (),
218- new SimpleUsbConfigurationDescriptor (
219- LENGTH , DESCRIPTOR_TYPE , WRONG , NUM_INTERFACES ,
220- CONFIGURATION_VALUE , CONFIGURATION , ATTRIBUTES , MAX_POWER )
221- .toString ());
222- assertNotEquals (descriptor .toString (),
223- new SimpleUsbConfigurationDescriptor (
224- LENGTH , DESCRIPTOR_TYPE , TOTAL_LENGTH , WRONG ,
225- CONFIGURATION_VALUE , CONFIGURATION , ATTRIBUTES , MAX_POWER )
226- .toString ());
227- assertNotEquals (descriptor .toString (),
228- new SimpleUsbConfigurationDescriptor (
229- LENGTH , DESCRIPTOR_TYPE , TOTAL_LENGTH , NUM_INTERFACES ,
230- WRONG , CONFIGURATION , ATTRIBUTES , MAX_POWER ).toString ());
231- assertNotEquals (descriptor .toString (),
232- new SimpleUsbConfigurationDescriptor (
233- LENGTH , DESCRIPTOR_TYPE , TOTAL_LENGTH , NUM_INTERFACES ,
234- CONFIGURATION_VALUE , WRONG , ATTRIBUTES , MAX_POWER )
235- .toString ());
236- assertNotEquals (descriptor .toString (),
199+ assertEquals (String .format ("Configuration Descriptor:%n"
200+ + " bLength 255%n"
201+ + " bDescriptorType 254%n"
202+ + " wTotalLength 65535%n"
203+ + " bNumInterfaces 252%n"
204+ + " bConfigurationValue 251%n"
205+ + " iConfiguration 250%n"
206+ + " bmAttributes 0xf9%n"
207+ + " Self Powered%n"
208+ + " Remote Wakeup%n"
209+ + " bMaxPower 496mA%n" ), descriptor .toString ());
210+ assertEquals (String .format ("Configuration Descriptor:%n"
211+ + " bLength 255%n"
212+ + " bDescriptorType 254%n"
213+ + " wTotalLength 65535%n"
214+ + " bNumInterfaces 252%n"
215+ + " bConfigurationValue 251%n"
216+ + " iConfiguration 250%n"
217+ + " bmAttributes 0x00%n"
218+ + " (Bus Powered)%n"
219+ + " bMaxPower 496mA%n" ),
237220 new SimpleUsbConfigurationDescriptor (
238221 LENGTH , DESCRIPTOR_TYPE , TOTAL_LENGTH , NUM_INTERFACES ,
239222 CONFIGURATION_VALUE , CONFIGURATION , WRONG , MAX_POWER )
240223 .toString ());
241- assertNotEquals (descriptor .toString (),
242- new SimpleUsbConfigurationDescriptor (
243- LENGTH , DESCRIPTOR_TYPE , TOTAL_LENGTH , NUM_INTERFACES ,
244- CONFIGURATION_VALUE , CONFIGURATION , ATTRIBUTES , WRONG )
245- .toString ());
246224 }
247225}
0 commit comments