Skip to content

Commit 3cab91c

Browse files
committed
Fix toString method of SimpleUsbInterfaceDescriptor class
1 parent 525db33 commit 3cab91c

File tree

2 files changed

+29
-85
lines changed

2 files changed

+29
-85
lines changed

src/main/java/org/usb4java/javax/descriptors/SimpleUsbInterfaceDescriptor.java

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,6 @@ public boolean equals(final Object obj)
181181

182182
@Override
183183
public String toString()
184-
{
185-
return dump(this);
186-
}
187-
188-
/**
189-
* Dumps the specified USB interface descriptor into a string and returns
190-
* it.
191-
*
192-
* @param descriptor
193-
* The USB interface descriptor to dump.
194-
* @return The descriptor dump.
195-
*/
196-
public static String dump(final UsbInterfaceDescriptor descriptor)
197184
{
198185
return String.format(
199186
"Interface Descriptor:%n" +
@@ -206,15 +193,15 @@ public static String dump(final UsbInterfaceDescriptor descriptor)
206193
" bInterfaceSubClass %7d%n" +
207194
" bInterfaceProtocol %7d%n" +
208195
" iInterface %15d%n",
209-
descriptor.bLength(),
210-
descriptor.bDescriptorType(),
211-
descriptor.bInterfaceNumber() & 0xff,
212-
descriptor.bAlternateSetting() & 0xff,
213-
descriptor.bNumEndpoints() & 0xff,
214-
descriptor.bInterfaceClass() & 0xff,
215-
DescriptorUtils.getUSBClassName(descriptor.bInterfaceClass()),
216-
descriptor.bInterfaceSubClass() & 0xff,
217-
descriptor.bInterfaceProtocol() & 0xff,
218-
descriptor.iInterface() & 0xff);
196+
bLength() & 0xff,
197+
bDescriptorType() & 0xff,
198+
bInterfaceNumber() & 0xff,
199+
bAlternateSetting() & 0xff,
200+
bNumEndpoints() & 0xff,
201+
bInterfaceClass() & 0xff,
202+
DescriptorUtils.getUSBClassName(bInterfaceClass()),
203+
bInterfaceSubClass() & 0xff,
204+
bInterfaceProtocol() & 0xff,
205+
iInterface() & 0xff);
219206
}
220207
}

src/test/java/org/usb4java/javax/descriptors/SimpleUsbInterfaceDescriptorTest.java

Lines changed: 19 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77

88
import static org.junit.Assert.assertEquals;
99
import static org.junit.Assert.assertFalse;
10-
import static org.junit.Assert.assertNotEquals;
1110
import static org.junit.Assert.assertTrue;
1211

1312
import org.junit.BeforeClass;
1413
import org.junit.Test;
15-
import org.usb4java.javax.descriptors.SimpleUsbInterfaceDescriptor;
1614

1715
/**
1816
* Tests the {@link SimpleUsbInterfaceDescriptor}.
@@ -25,31 +23,31 @@ public class SimpleUsbInterfaceDescriptorTest
2523
private static SimpleUsbInterfaceDescriptor descriptor;
2624

2725
/** Value for {@link SimpleUsbInterfaceDescriptor#bLength()}. */
28-
private static final byte LENGTH = 1;
26+
private static final byte LENGTH = (byte) 0xff;
2927

3028
/** Value for {@link SimpleUsbInterfaceDescriptor#bDescriptorType()}. */
31-
private static final byte DESCRIPTOR_TYPE = 2;
29+
private static final byte DESCRIPTOR_TYPE = (byte) 0xfe;
3230

3331
/** Value for {@link SimpleUsbInterfaceDescriptor#bInterfaceNumber()}. */
34-
private static final byte INTERFACE_NUMBER = 3;
32+
private static final byte INTERFACE_NUMBER = (byte) 0xfd;
3533

3634
/** Value for {@link SimpleUsbInterfaceDescriptor#bAlternateSetting()}. */
37-
private static final byte ALTERNATE_SETTING = 4;
35+
private static final byte ALTERNATE_SETTING = (byte) 0xfc;
3836

3937
/** Value for {@link SimpleUsbInterfaceDescriptor#bNumEndpoints()}. */
40-
private static final byte NUM_ENDPOINTS = 5;
38+
private static final byte NUM_ENDPOINTS = (byte) 0xfb;
4139

4240
/** Value for {@link SimpleUsbInterfaceDescriptor#bInterfaceClass()}. */
43-
private static final byte INTERFACE_CLASS = 6;
41+
private static final byte INTERFACE_CLASS = (byte) 0xfa;
4442

4543
/** Value for {@link SimpleUsbInterfaceDescriptor#bInterfaceSubClass()}. */
46-
private static final byte INTERFACE_SUB_CLASS = 7;
44+
private static final byte INTERFACE_SUB_CLASS = (byte) 0xf9;
4745

4846
/** Value for {@link SimpleUsbInterfaceDescriptor#bInterfaceProtocol()}. */
49-
private static final byte INTERFACE_PROTOCOL = 8;
47+
private static final byte INTERFACE_PROTOCOL = (byte) 0xf8;
5048

5149
/** Value for {@link SimpleUsbInterfaceDescriptor#iInterface()}. */
52-
private static final byte INTERFACE = 9;
50+
private static final byte INTERFACE = (byte) 0xf7;
5351

5452
/** A wrong value for equality test. */
5553
private static final byte WRONG = 0;
@@ -221,56 +219,15 @@ public void testEquals()
221219
@Test
222220
public void testToString()
223221
{
224-
assertEquals(descriptor.toString(), descriptor.toString());
225-
assertEquals(descriptor.toString(),
226-
new SimpleUsbInterfaceDescriptor(
227-
LENGTH, DESCRIPTOR_TYPE, INTERFACE_NUMBER, ALTERNATE_SETTING,
228-
NUM_ENDPOINTS, INTERFACE_CLASS, INTERFACE_SUB_CLASS,
229-
INTERFACE_PROTOCOL, INTERFACE).toString());
230-
assertNotEquals(descriptor.toString(),
231-
new SimpleUsbInterfaceDescriptor(
232-
WRONG, DESCRIPTOR_TYPE, INTERFACE_NUMBER, ALTERNATE_SETTING,
233-
NUM_ENDPOINTS, INTERFACE_CLASS, INTERFACE_SUB_CLASS,
234-
INTERFACE_PROTOCOL, INTERFACE).toString());
235-
assertNotEquals(descriptor.toString(),
236-
new SimpleUsbInterfaceDescriptor(
237-
LENGTH, WRONG, INTERFACE_NUMBER, ALTERNATE_SETTING,
238-
NUM_ENDPOINTS, INTERFACE_CLASS, INTERFACE_SUB_CLASS,
239-
INTERFACE_PROTOCOL, INTERFACE).toString());
240-
assertNotEquals(descriptor.toString(),
241-
new SimpleUsbInterfaceDescriptor(
242-
LENGTH, DESCRIPTOR_TYPE, WRONG, ALTERNATE_SETTING,
243-
NUM_ENDPOINTS, INTERFACE_CLASS, INTERFACE_SUB_CLASS,
244-
INTERFACE_PROTOCOL, INTERFACE).toString());
245-
assertNotEquals(descriptor.toString(),
246-
new SimpleUsbInterfaceDescriptor(
247-
LENGTH, DESCRIPTOR_TYPE, INTERFACE_NUMBER, WRONG,
248-
NUM_ENDPOINTS, INTERFACE_CLASS, INTERFACE_SUB_CLASS,
249-
INTERFACE_PROTOCOL, INTERFACE).toString());
250-
assertNotEquals(descriptor.toString(),
251-
new SimpleUsbInterfaceDescriptor(
252-
LENGTH, DESCRIPTOR_TYPE, INTERFACE_NUMBER, ALTERNATE_SETTING,
253-
WRONG, INTERFACE_CLASS, INTERFACE_SUB_CLASS,
254-
INTERFACE_PROTOCOL, INTERFACE).toString());
255-
assertNotEquals(descriptor.toString(),
256-
new SimpleUsbInterfaceDescriptor(
257-
LENGTH, DESCRIPTOR_TYPE, INTERFACE_NUMBER, ALTERNATE_SETTING,
258-
NUM_ENDPOINTS, WRONG, INTERFACE_SUB_CLASS,
259-
INTERFACE_PROTOCOL, INTERFACE).toString());
260-
assertNotEquals(descriptor.toString(),
261-
new SimpleUsbInterfaceDescriptor(
262-
LENGTH, DESCRIPTOR_TYPE, INTERFACE_NUMBER, ALTERNATE_SETTING,
263-
NUM_ENDPOINTS, INTERFACE_CLASS, WRONG,
264-
INTERFACE_PROTOCOL, INTERFACE).toString());
265-
assertNotEquals(descriptor.toString(),
266-
new SimpleUsbInterfaceDescriptor(
267-
LENGTH, DESCRIPTOR_TYPE, INTERFACE_NUMBER, ALTERNATE_SETTING,
268-
NUM_ENDPOINTS, INTERFACE_CLASS, INTERFACE_SUB_CLASS,
269-
WRONG, INTERFACE).toString());
270-
assertNotEquals(descriptor.toString(),
271-
new SimpleUsbInterfaceDescriptor(
272-
LENGTH, DESCRIPTOR_TYPE, INTERFACE_NUMBER, ALTERNATE_SETTING,
273-
NUM_ENDPOINTS, INTERFACE_CLASS, INTERFACE_SUB_CLASS,
274-
INTERFACE_PROTOCOL, WRONG).toString());
222+
assertEquals(String.format("Interface Descriptor:%n"
223+
+ " bLength 255%n"
224+
+ " bDescriptorType 254%n"
225+
+ " bInterfaceNumber 253%n"
226+
+ " bAlternateSetting 252%n"
227+
+ " bNumEndpoints 251%n"
228+
+ " bInterfaceClass 250 Unknown%n"
229+
+ " bInterfaceSubClass 249%n"
230+
+ " bInterfaceProtocol 248%n"
231+
+ " iInterface 247%n"), descriptor.toString());
275232
}
276233
}

0 commit comments

Comments
 (0)