Skip to content

Commit 525db33

Browse files
committed
Fix toString method of SimpleUsbEndpointDescriptor class
1 parent 626a7c3 commit 525db33

File tree

2 files changed

+28
-54
lines changed

2 files changed

+28
-54
lines changed

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

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,6 @@ public boolean equals(final Object obj)
135135

136136
@Override
137137
public String toString()
138-
{
139-
return dump(this);
140-
}
141-
142-
/**
143-
* Dumps the specified USB endpoint descriptor into a string and returns it.
144-
*
145-
* @param descriptor
146-
* The USB endpoint descriptor to dump.
147-
* @return The descriptor dump.
148-
*/
149-
public static String dump(final UsbEndpointDescriptor descriptor)
150138
{
151139
return String.format(
152140
"Endpoint Descriptor:%n" +
@@ -159,16 +147,16 @@ public static String dump(final UsbEndpointDescriptor descriptor)
159147
" Usage Type %s%n" +
160148
" wMaxPacketSize %11d%n" +
161149
" bInterval %16d%n",
162-
descriptor.bLength(),
163-
descriptor.bDescriptorType(),
164-
String.format("0x%02x", descriptor.bEndpointAddress() & 0xff),
165-
descriptor.bEndpointAddress() & 0x0f,
166-
DescriptorUtils.getDirectionName(descriptor.bEndpointAddress()),
167-
descriptor.bmAttributes() & 0xff,
168-
DescriptorUtils.getTransferTypeName(descriptor.bmAttributes()),
169-
DescriptorUtils.getSynchTypeName(descriptor.bmAttributes()),
170-
DescriptorUtils.getUsageTypeName(descriptor.bmAttributes()),
171-
descriptor.wMaxPacketSize() & 0xffff,
172-
descriptor.bInterval() & 0xff);
150+
bLength() & 0xff,
151+
bDescriptorType() & 0xff,
152+
String.format("0x%02x", bEndpointAddress() & 0xff),
153+
bEndpointAddress() & 0x0f,
154+
DescriptorUtils.getDirectionName(bEndpointAddress()),
155+
bmAttributes() & 0xff,
156+
DescriptorUtils.getTransferTypeName(bmAttributes()),
157+
DescriptorUtils.getSynchTypeName(bmAttributes()),
158+
DescriptorUtils.getUsageTypeName(bmAttributes()),
159+
wMaxPacketSize() & 0xffff,
160+
bInterval() & 0xff);
173161
}
174162
}

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

Lines changed: 17 additions & 31 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.SimpleUsbEndpointDescriptor;
1614

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

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

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

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

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

3937
/** Value for {@link SimpleUsbEndpointDescriptor#wMaxPacketSize()}. */
40-
private static final short MAX_PACKET_SIZE = 5;
38+
private static final short MAX_PACKET_SIZE = (short) 0xffff;
4139

4240
/** Value for {@link SimpleUsbEndpointDescriptor#bInterval()}. */
43-
private static final byte INTERVAL = 6;
41+
private static final byte INTERVAL = (byte) 0xfb;
4442

4543
/** A wrong value for equality test. */
4644
private static final byte WRONG = 0;
@@ -55,7 +53,7 @@ public static void setUp()
5553
LENGTH, DESCRIPTOR_TYPE, ENDPOINT_ADDRESS, ATTRIBUTES,
5654
MAX_PACKET_SIZE, INTERVAL);
5755
}
58-
56+
5957
/**
6058
* Tests the {@link SimpleUsbEndpointDescriptor#bLength()} method.
6159
*/
@@ -161,27 +159,15 @@ public void testEquals()
161159
@Test
162160
public void testToString()
163161
{
164-
assertEquals(descriptor.toString(), descriptor.toString());
165-
assertEquals(descriptor.toString(), new SimpleUsbEndpointDescriptor(
166-
LENGTH, DESCRIPTOR_TYPE, ENDPOINT_ADDRESS, ATTRIBUTES,
167-
MAX_PACKET_SIZE, INTERVAL).toString());
168-
assertNotEquals(descriptor.toString(), new SimpleUsbEndpointDescriptor(
169-
WRONG, DESCRIPTOR_TYPE, ENDPOINT_ADDRESS, ATTRIBUTES,
170-
MAX_PACKET_SIZE, INTERVAL).toString());
171-
assertNotEquals(descriptor.toString(), new SimpleUsbEndpointDescriptor(
172-
LENGTH, WRONG, ENDPOINT_ADDRESS, ATTRIBUTES,
173-
MAX_PACKET_SIZE, INTERVAL).toString());
174-
assertNotEquals(descriptor.toString(), new SimpleUsbEndpointDescriptor(
175-
LENGTH, DESCRIPTOR_TYPE, WRONG, ATTRIBUTES,
176-
MAX_PACKET_SIZE, INTERVAL).toString());
177-
assertNotEquals(descriptor.toString(), new SimpleUsbEndpointDescriptor(
178-
LENGTH, DESCRIPTOR_TYPE, ENDPOINT_ADDRESS, WRONG,
179-
MAX_PACKET_SIZE, INTERVAL).toString());
180-
assertNotEquals(descriptor.toString(), new SimpleUsbEndpointDescriptor(
181-
LENGTH, DESCRIPTOR_TYPE, ENDPOINT_ADDRESS, ATTRIBUTES,
182-
WRONG, INTERVAL).toString());
183-
assertNotEquals(descriptor.toString(), new SimpleUsbEndpointDescriptor(
184-
LENGTH, DESCRIPTOR_TYPE, ENDPOINT_ADDRESS, ATTRIBUTES,
185-
MAX_PACKET_SIZE, WRONG).toString());
162+
assertEquals(String.format("Endpoint Descriptor:%n"
163+
+ " bLength 255%n"
164+
+ " bDescriptorType 254%n"
165+
+ " bEndpointAddress 0xfd EP 13 IN%n"
166+
+ " bmAttributes 252%n"
167+
+ " Transfer Type Control%n"
168+
+ " Synch Type Synchronous%n"
169+
+ " Usage Type Reserved%n"
170+
+ " wMaxPacketSize 65535%n"
171+
+ " bInterval 251%n"), descriptor.toString());
186172
}
187173
}

0 commit comments

Comments
 (0)