How we interact with libusb from Java is quite inconsistent, and it mainly stems from the fact Java has no
unsigned integers, which is what libusb uses everywhere.
As it was before, there are parts of the library that return bytes & shorts, like the Descriptors (mostly to
be compatible with javax.usb), and others that take and return int, even where an 8 or 16-bit quantity would
be expected by libusb. I suspect this was done to avoid casting and try to side-step the sign-extension
problem with Java as much as possible, but in the end it leads to an API that's inconsistent, that doesn't
express the ranges it can use well (it's an int but in reality only 16 bits for libusb and so on). It also
fails at basic operations in ways you'd not expect because of the above inconsistencies:
if (deviceDescriptor.bDeviceClass() == LibUsb.CLASS_VENDOR_SPEC) { do something; }
will never work, since the constant is an int and the returned short from bDeviceClass() will be cast up to an
int too, but CLASS_VENDOR_SPEC is 0xFF (MSB=1), it will be sign-extended and the comparison will fail always.
There are two solutions I can see here:
A) consistently use int/long everywhere, both input and output. Everything becomes simpler to write, with less
casts, BUT javax.usb compatibility is gone for the Descriptors and it becomes even unclearer what those values
effectively mean and what range they support.
B) restrict the API to use the proper integer sizes as the C API, ie. 8-bit quantities (char, uint8_t, int8_t)
are represented by jbyte, 16-bit by jshort, and all the constants get properly sized too. With this approach
the sizes and ranges are much clearer, comparisons like the above work out-of-the-box, javax.usb compatibility
is maintained for the Descriptors. The downside is more casting and the occasional need to mask off returned
values to kill the sign-extension when you want to use those values as integers (like when printing stuff in
decimal notation).
I chose to try out the approach from B) for now, this commit implements it as explained above.
It requires minimal changes to the javax.usb implementation, just two casts to byte in AbstractDevice.java.
This commit is contained in:
parent
a50fd0ecb5
commit
c0ea9ba0f6
@ -239,11 +239,11 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, getDeviceSpeed)
|
||||
}
|
||||
|
||||
/**
|
||||
* int getMaxPacketSize(Device, int)
|
||||
* int getMaxPacketSize(Device, byte)
|
||||
*/
|
||||
JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, getMaxPacketSize)
|
||||
(
|
||||
JNIEnv *env, jclass class, jobject device, jint endpoint
|
||||
JNIEnv *env, jclass class, jobject device, jbyte endpoint
|
||||
)
|
||||
{
|
||||
NOT_NULL(env, device, return 0);
|
||||
@ -254,11 +254,11 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, getMaxPacketSize)
|
||||
}
|
||||
|
||||
/**
|
||||
* int getMaxIsoPacketSize(Device, int)
|
||||
* int getMaxIsoPacketSize(Device, byte)
|
||||
*/
|
||||
JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, getMaxIsoPacketSize)
|
||||
(
|
||||
JNIEnv *env, jclass class, jobject device, jint endpoint
|
||||
JNIEnv *env, jclass class, jobject device, jbyte endpoint
|
||||
)
|
||||
{
|
||||
NOT_NULL(env, device, return 0);
|
||||
@ -320,12 +320,12 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, open)
|
||||
}
|
||||
|
||||
/**
|
||||
* DeviceHandle openDeviceWithVidPid(Context, int, int)
|
||||
* DeviceHandle openDeviceWithVidPid(Context, short, short)
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL METHOD_NAME(LibUsb, openDeviceWithVidPid)
|
||||
(
|
||||
JNIEnv *env, jclass class, jobject context, jint vendorId,
|
||||
jint productId
|
||||
JNIEnv *env, jclass class, jobject context, jshort vendorId,
|
||||
jshort productId
|
||||
)
|
||||
{
|
||||
libusb_context *ctx = unwrapContext(env, context);
|
||||
@ -451,11 +451,11 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, setInterfaceAltSetting)
|
||||
}
|
||||
|
||||
/**
|
||||
* int clearHalt(DeviceHandle, int)
|
||||
* int clearHalt(DeviceHandle, byte)
|
||||
*/
|
||||
JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, clearHalt)
|
||||
(
|
||||
JNIEnv *env, jclass class, jobject handle, jint endpoint
|
||||
JNIEnv *env, jclass class, jobject handle, jbyte endpoint
|
||||
)
|
||||
{
|
||||
NOT_NULL(env, handle, return 0);
|
||||
@ -559,25 +559,25 @@ JNIEXPORT jobject JNICALL METHOD_NAME(LibUsb, getVersion)
|
||||
}
|
||||
|
||||
/**
|
||||
* int le16ToCpu(int)
|
||||
* short le16ToCpu(short)
|
||||
*/
|
||||
JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, le16ToCpu)
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(LibUsb, le16ToCpu)
|
||||
(
|
||||
JNIEnv *env, jclass class, jint x
|
||||
JNIEnv *env, jclass class, jshort x
|
||||
)
|
||||
{
|
||||
return libusb_le16_to_cpu((uint16_t) x);
|
||||
return (jshort) libusb_le16_to_cpu((uint16_t) x);
|
||||
}
|
||||
|
||||
/**
|
||||
* int cpuToLe16(int)
|
||||
* short cpuToLe16(short)
|
||||
*/
|
||||
JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, cpuToLe16)
|
||||
JNIEXPORT jshort JNICALL METHOD_NAME(LibUsb, cpuToLe16)
|
||||
(
|
||||
JNIEnv *env, jclass class, jint x
|
||||
JNIEnv *env, jclass class, jshort x
|
||||
)
|
||||
{
|
||||
return libusb_cpu_to_le16((uint16_t) x);
|
||||
return (jshort) libusb_cpu_to_le16((uint16_t) x);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -646,11 +646,11 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, getActiveConfigDescriptor)
|
||||
}
|
||||
|
||||
/**
|
||||
* int getConfigDescriptor(Device, int, ConfigDescriptor)
|
||||
* int getConfigDescriptor(Device, byte, ConfigDescriptor)
|
||||
*/
|
||||
JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, getConfigDescriptor)
|
||||
(
|
||||
JNIEnv *env, jclass class, jobject device, jint index, jobject descriptor
|
||||
JNIEnv *env, jclass class, jobject device, jbyte index, jobject descriptor
|
||||
)
|
||||
{
|
||||
NOT_NULL(env, device, return 0);
|
||||
@ -666,11 +666,11 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, getConfigDescriptor)
|
||||
}
|
||||
|
||||
/**
|
||||
* int getConfigDescriptorByValue(Device, int, ConfigDescriptor)
|
||||
* int getConfigDescriptorByValue(Device, byte, ConfigDescriptor)
|
||||
*/
|
||||
JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, getConfigDescriptorByValue)
|
||||
(
|
||||
JNIEnv *env, jclass class, jobject device, jint index, jobject descriptor
|
||||
JNIEnv *env, jclass class, jobject device, jbyte index, jobject descriptor
|
||||
)
|
||||
{
|
||||
NOT_NULL(env, device, return 0);
|
||||
@ -704,11 +704,11 @@ JNIEXPORT void JNICALL METHOD_NAME(LibUsb, freeConfigDescriptor)
|
||||
}
|
||||
|
||||
/**
|
||||
* int getStringDescriptorAscii(DeviceHandle, int, StringBuffer)
|
||||
* int getStringDescriptorAscii(DeviceHandle, byte, StringBuffer)
|
||||
*/
|
||||
JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, getStringDescriptorAscii)
|
||||
(
|
||||
JNIEnv *env, jclass class, jobject handle, jint index, jobject string
|
||||
JNIEnv *env, jclass class, jobject handle, jbyte index, jobject string
|
||||
)
|
||||
{
|
||||
NOT_NULL(env, handle, return 0);
|
||||
@ -734,12 +734,12 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, getStringDescriptorAscii)
|
||||
}
|
||||
|
||||
/**
|
||||
* int controlTransfer(DeviceHandle, int, int, int, int, ByteBuffer, long)
|
||||
* int controlTransfer(DeviceHandle, byte, byte, short, short, ByteBuffer, long)
|
||||
*/
|
||||
JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, controlTransfer)
|
||||
(
|
||||
JNIEnv *env, jclass class, jobject handle, jint bmRequestType,
|
||||
jint bRequest, jint wValue, jint wIndex, jobject data, jlong timeout
|
||||
JNIEnv *env, jclass class, jobject handle, jbyte bmRequestType,
|
||||
jbyte bRequest, jshort wValue, jshort wIndex, jobject data, jlong timeout
|
||||
)
|
||||
{
|
||||
NOT_NULL(env, handle, return 0);
|
||||
@ -755,11 +755,11 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, controlTransfer)
|
||||
}
|
||||
|
||||
/**
|
||||
* int bulkTransfer(DeviceHandle, int, ByteBuffer, IntBuffer, long)
|
||||
* int bulkTransfer(DeviceHandle, byte, ByteBuffer, IntBuffer, long)
|
||||
*/
|
||||
JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, bulkTransfer)
|
||||
(
|
||||
JNIEnv *env, jclass class, jobject handle, jint endpoint,
|
||||
JNIEnv *env, jclass class, jobject handle, jbyte endpoint,
|
||||
jobject data, jobject transferred, jlong timeout
|
||||
)
|
||||
{
|
||||
@ -785,11 +785,11 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, bulkTransfer)
|
||||
}
|
||||
|
||||
/**
|
||||
* int interruptTransfer(DeviceHandle, int, ByteBuffer, IntBuffer, long)
|
||||
* int interruptTransfer(DeviceHandle, byte, ByteBuffer, IntBuffer, long)
|
||||
*/
|
||||
JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, interruptTransfer)
|
||||
(
|
||||
JNIEnv *env, jclass class, jobject handle, jint endpoint,
|
||||
JNIEnv *env, jclass class, jobject handle, jbyte endpoint,
|
||||
jobject data, jobject transferred, jlong timeout
|
||||
)
|
||||
{
|
||||
|
||||
@ -63,11 +63,11 @@ JNIEXPORT jobject JNICALL METHOD_NAME(Transfer, devHandle)
|
||||
}
|
||||
|
||||
/**
|
||||
* void setFlags(int)
|
||||
* void setFlags(byte)
|
||||
*/
|
||||
JNIEXPORT void JNICALL METHOD_NAME(Transfer, setFlags)
|
||||
(
|
||||
JNIEnv *env, jobject this, jint flags
|
||||
JNIEnv *env, jobject this, jbyte flags
|
||||
)
|
||||
{
|
||||
struct libusb_transfer *transfer = unwrapTransfer(env, this);
|
||||
@ -91,11 +91,11 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(Transfer, flags)
|
||||
}
|
||||
|
||||
/**
|
||||
* void setEndpoint(int)
|
||||
* void setEndpoint(byte)
|
||||
*/
|
||||
JNIEXPORT void JNICALL METHOD_NAME(Transfer, setEndpoint)
|
||||
(
|
||||
JNIEnv *env, jobject this, jint endpoint
|
||||
JNIEnv *env, jobject this, jbyte endpoint
|
||||
)
|
||||
{
|
||||
struct libusb_transfer *transfer = unwrapTransfer(env, this);
|
||||
@ -119,11 +119,11 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(Transfer, endpoint)
|
||||
}
|
||||
|
||||
/**
|
||||
* void setType(int)
|
||||
* void setType(byte)
|
||||
*/
|
||||
JNIEXPORT void JNICALL METHOD_NAME(Transfer, setType)
|
||||
(
|
||||
JNIEnv *env, jobject this, jint type
|
||||
JNIEnv *env, jobject this, jbyte type
|
||||
)
|
||||
{
|
||||
struct libusb_transfer *transfer = unwrapTransfer(env, this);
|
||||
|
||||
@ -121,7 +121,7 @@ abstract class AbstractDevice implements UsbDevice
|
||||
for (int i = 0; i < numConfigurations; i += 1)
|
||||
{
|
||||
final ConfigDescriptor configDescriptor = new ConfigDescriptor();
|
||||
final int result = LibUsb.getConfigDescriptor(device, i,
|
||||
final int result = LibUsb.getConfigDescriptor(device, (byte) i,
|
||||
configDescriptor);
|
||||
if (result < 0)
|
||||
{
|
||||
@ -521,8 +521,8 @@ abstract class AbstractDevice implements UsbDevice
|
||||
{
|
||||
final DeviceHandle handle = open();
|
||||
final ByteBuffer buffer = ByteBuffer.allocateDirect(256);
|
||||
final int result = LibUsb.getDescriptor(handle, LibUsb.DT_STRING, 0,
|
||||
buffer);
|
||||
final int result = LibUsb.getDescriptor(handle, LibUsb.DT_STRING,
|
||||
(byte) 0, buffer);
|
||||
if (result < 0)
|
||||
throw new LibUsbException(
|
||||
"Unable to get string descriptor languages", result);
|
||||
|
||||
@ -37,9 +37,9 @@ public final class ControlSetup
|
||||
return controlSetup.get(0);
|
||||
}
|
||||
|
||||
public void setBmRequestType(final int bmRequestType)
|
||||
public void setBmRequestType(final byte bmRequestType)
|
||||
{
|
||||
controlSetup.put(0, (byte) bmRequestType);
|
||||
controlSetup.put(0, bmRequestType);
|
||||
}
|
||||
|
||||
public byte bRequest()
|
||||
@ -47,9 +47,9 @@ public final class ControlSetup
|
||||
return controlSetup.get(1);
|
||||
}
|
||||
|
||||
public void setBRequest(final int bRequest)
|
||||
public void setBRequest(final byte bRequest)
|
||||
{
|
||||
controlSetup.put(1, (byte) bRequest);
|
||||
controlSetup.put(1, bRequest);
|
||||
}
|
||||
|
||||
public short wValue()
|
||||
@ -57,9 +57,9 @@ public final class ControlSetup
|
||||
return controlSetup.getShort(2);
|
||||
}
|
||||
|
||||
public void setWValue(final int wValue)
|
||||
public void setWValue(final short wValue)
|
||||
{
|
||||
controlSetup.putShort(2, (short) wValue);
|
||||
controlSetup.putShort(2, wValue);
|
||||
}
|
||||
|
||||
public short wIndex()
|
||||
@ -67,9 +67,9 @@ public final class ControlSetup
|
||||
return controlSetup.getShort(4);
|
||||
}
|
||||
|
||||
public void setWIndex(final int wIndex)
|
||||
public void setWIndex(final short wIndex)
|
||||
{
|
||||
controlSetup.putShort(4, (short) wIndex);
|
||||
controlSetup.putShort(4, wIndex);
|
||||
}
|
||||
|
||||
public short wLength()
|
||||
@ -77,8 +77,8 @@ public final class ControlSetup
|
||||
return controlSetup.getShort(6);
|
||||
}
|
||||
|
||||
public void setWLength(final int wLength)
|
||||
public void setWLength(final short wLength)
|
||||
{
|
||||
controlSetup.putShort(6, (short) wLength);
|
||||
controlSetup.putShort(6, wLength);
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,75 +118,75 @@ public final class LibUsb
|
||||
// Standard requests, as defined in table 9-5 of the USB 3.0 specifications.
|
||||
|
||||
/** Request status of the specific recipient. */
|
||||
public static final int REQUEST_GET_STATUS = 0x00;
|
||||
public static final byte REQUEST_GET_STATUS = 0x00;
|
||||
|
||||
/** Clear or disable a specific feature. */
|
||||
public static final int REQUEST_CLEAR_FEATURE = 0x01;
|
||||
public static final byte REQUEST_CLEAR_FEATURE = 0x01;
|
||||
|
||||
/** Set or enable a specific feature. */
|
||||
public static final int REQUEST_SET_FEATURE = 0x03;
|
||||
public static final byte REQUEST_SET_FEATURE = 0x03;
|
||||
|
||||
/** Set device address for all future accesses. */
|
||||
public static final int REQUEST_SET_ADDRESS = 0x05;
|
||||
public static final byte REQUEST_SET_ADDRESS = 0x05;
|
||||
|
||||
/** Set device address for all future accesses. */
|
||||
public static final int REQUEST_GET_DESCRIPTOR = 0x06;
|
||||
public static final byte REQUEST_GET_DESCRIPTOR = 0x06;
|
||||
|
||||
/** Set device address for all future accesses. */
|
||||
public static final int REQUEST_SET_DESCRIPTOR = 0x07;
|
||||
public static final byte REQUEST_SET_DESCRIPTOR = 0x07;
|
||||
|
||||
/** Get the current device configuration value. */
|
||||
public static final int REQUEST_GET_CONFIGURATION = 0x08;
|
||||
public static final byte REQUEST_GET_CONFIGURATION = 0x08;
|
||||
|
||||
/** Get the current device configuration value. */
|
||||
public static final int REQUEST_SET_CONFIGURATION = 0x09;
|
||||
public static final byte REQUEST_SET_CONFIGURATION = 0x09;
|
||||
|
||||
/** Return the selected alternate setting for the specified interface. */
|
||||
public static final int REQUEST_GET_INTERFACE = 0x0a;
|
||||
public static final byte REQUEST_GET_INTERFACE = 0x0A;
|
||||
|
||||
/** Select an alternate interface for the specified interface. */
|
||||
public static final int REQUEST_SET_INTERFACE = 0x0b;
|
||||
public static final byte REQUEST_SET_INTERFACE = 0x0B;
|
||||
|
||||
/** Set then report an endpoint's synchronization frame. */
|
||||
public static final int REQUEST_SYNCH_FRAME = 0x0c;
|
||||
public static final byte REQUEST_SYNCH_FRAME = 0x0C;
|
||||
|
||||
/** Sets both the U1 and U2 Exit Latency. */
|
||||
public static final int REQUEST_SET_SEL = 0x30;
|
||||
public static final byte REQUEST_SET_SEL = 0x30;
|
||||
|
||||
/**
|
||||
* Delay from the time a host transmits a packet to the time it is received
|
||||
* by the device.
|
||||
*/
|
||||
public static final int SET_ISOCH_DELAY = 0x31;
|
||||
public static final byte SET_ISOCH_DELAY = 0x31;
|
||||
|
||||
// Request type bits of the bmRequestType field in control transfers.
|
||||
|
||||
/** Standard. */
|
||||
public static final int REQUEST_TYPE_STANDARD = 0;
|
||||
public static final byte REQUEST_TYPE_STANDARD = 0;
|
||||
|
||||
/** Class. */
|
||||
public static final int REQUEST_TYPE_CLASS = 32;
|
||||
public static final byte REQUEST_TYPE_CLASS = 32;
|
||||
|
||||
/** Vendor. */
|
||||
public static final int REQUEST_TYPE_VENDOR = 64;
|
||||
public static final byte REQUEST_TYPE_VENDOR = 64;
|
||||
|
||||
/** Reserved. */
|
||||
public static final int REQUEST_TYPE_RESERVED = 96;
|
||||
public static final byte REQUEST_TYPE_RESERVED = 96;
|
||||
|
||||
// Recipient bits of the bmRequestType field in control transfers.
|
||||
// Values 4 through 31 are reserved.
|
||||
|
||||
/** Device. */
|
||||
public static final int RECIPIENT_DEVICE = 0x00;
|
||||
public static final byte RECIPIENT_DEVICE = 0x00;
|
||||
|
||||
/** Interface. */
|
||||
public static final int RECIPIENT_INTERFACE = 0x01;
|
||||
public static final byte RECIPIENT_INTERFACE = 0x01;
|
||||
|
||||
/** Endpoint. */
|
||||
public static final int RECIPIENT_ENDPOINT = 0x02;
|
||||
public static final byte RECIPIENT_ENDPOINT = 0x02;
|
||||
|
||||
/** Other. */
|
||||
public static final int RECIPIENT_OTHER = 0x03;
|
||||
public static final byte RECIPIENT_OTHER = 0x03;
|
||||
|
||||
// Capabilities supported by this instance of libusb. Test if the loaded
|
||||
// library supports a given capability by calling hasCapability().
|
||||
@ -211,7 +211,7 @@ public final class LibUsb
|
||||
*/
|
||||
public static final int CAP_SUPPORTS_DETACH_KERNEL_DRIVER = 0x0101;
|
||||
|
||||
public static final int CONTROL_SETUP_SIZE = 8;
|
||||
public static final short CONTROL_SETUP_SIZE = 8;
|
||||
|
||||
// Device and/or Interface Class codes.
|
||||
|
||||
@ -220,61 +220,61 @@ public final class LibUsb
|
||||
* that each interface specifies its own class information and all
|
||||
* interfaces operate independently.
|
||||
*/
|
||||
public static final int CLASS_PER_INTERFACE = 0;
|
||||
public static final byte CLASS_PER_INTERFACE = 0;
|
||||
|
||||
/** Audio class. */
|
||||
public static final int CLASS_AUDIO = 1;
|
||||
public static final byte CLASS_AUDIO = 1;
|
||||
|
||||
/** Communications class. */
|
||||
public static final int CLASS_COMM = 2;
|
||||
public static final byte CLASS_COMM = 2;
|
||||
|
||||
/** Human Interface Device class. */
|
||||
public static final int CLASS_HID = 3;
|
||||
public static final byte CLASS_HID = 3;
|
||||
|
||||
/** Physical. */
|
||||
public static final int CLASS_PHYSICAL = 5;
|
||||
public static final byte CLASS_PHYSICAL = 5;
|
||||
|
||||
/** Image class. */
|
||||
public static final int CLASS_PTP = 6;
|
||||
public static final byte CLASS_PTP = 6;
|
||||
|
||||
/** Image class. */
|
||||
public static final int CLASS_IMAGE = 6;
|
||||
public static final byte CLASS_IMAGE = 6;
|
||||
|
||||
/** Printer class. */
|
||||
public static final int CLASS_PRINTER = 7;
|
||||
public static final byte CLASS_PRINTER = 7;
|
||||
|
||||
/** Mass storage class. */
|
||||
public static final int CLASS_MASS_STORAGE = 8;
|
||||
public static final byte CLASS_MASS_STORAGE = 8;
|
||||
|
||||
/** Hub class. */
|
||||
public static final int CLASS_HUB = 9;
|
||||
public static final byte CLASS_HUB = 9;
|
||||
|
||||
/** Data class. */
|
||||
public static final int CLASS_DATA = 10;
|
||||
public static final byte CLASS_DATA = 10;
|
||||
|
||||
/** Smart Card. */
|
||||
public static final int CLASS_SMART_CARD = 0x0b;
|
||||
public static final byte CLASS_SMART_CARD = 0x0B;
|
||||
|
||||
/** Content Security. */
|
||||
public static final int CLASS_CONTENT_SECURITY = 0x0d;
|
||||
public static final byte CLASS_CONTENT_SECURITY = 0x0D;
|
||||
|
||||
/** Video. */
|
||||
public static final int CLASS_VIDEO = 0x0e;
|
||||
public static final byte CLASS_VIDEO = 0x0E;
|
||||
|
||||
/** Personal Healthcare. */
|
||||
public static final int CLASS_PERSONAL_HEALTHCARE = 0x0f;
|
||||
public static final byte CLASS_PERSONAL_HEALTHCARE = 0x0F;
|
||||
|
||||
/** Diagnostic Device. */
|
||||
public static final int CLASS_DIAGNOSTIC_DEVICE = 0xdc;
|
||||
public static final byte CLASS_DIAGNOSTIC_DEVICE = (byte) 0xDC;
|
||||
|
||||
/** Wireless class. */
|
||||
public static final int CLASS_WIRELESS = 0xe0;
|
||||
public static final byte CLASS_WIRELESS = (byte) 0xE0;
|
||||
|
||||
/** Application class. */
|
||||
public static final int CLASS_APPLICATION = 0xfe;
|
||||
public static final byte CLASS_APPLICATION = (byte) 0xFE;
|
||||
|
||||
/** Class is vendor-specific. */
|
||||
public static final int CLASS_VENDOR_SPEC = 0xff;
|
||||
public static final byte CLASS_VENDOR_SPEC = (byte) 0xFF;
|
||||
|
||||
// Descriptor types as defined by the USB specification.
|
||||
|
||||
@ -283,135 +283,135 @@ public final class LibUsb
|
||||
*
|
||||
* @see DeviceDescriptor
|
||||
*/
|
||||
public static final int DT_DEVICE = 0x01;
|
||||
public static final byte DT_DEVICE = 0x01;
|
||||
|
||||
/**
|
||||
* Configuration descriptor.
|
||||
*
|
||||
* @see ConfigDescriptor
|
||||
*/
|
||||
public static final int DT_CONFIG = 0x02;
|
||||
public static final byte DT_CONFIG = 0x02;
|
||||
|
||||
/** String descriptor. */
|
||||
public static final int DT_STRING = 0x03;
|
||||
public static final byte DT_STRING = 0x03;
|
||||
|
||||
/**
|
||||
* Interface descriptor.
|
||||
*
|
||||
* @see InterfaceDescriptor
|
||||
*/
|
||||
public static final int DT_INTERFACE = 0x04;
|
||||
public static final byte DT_INTERFACE = 0x04;
|
||||
|
||||
/**
|
||||
* Endpoint descriptor.
|
||||
*
|
||||
* @see EndpointDescriptor
|
||||
*/
|
||||
public static final int DT_ENDPOINT = 0x05;
|
||||
public static final byte DT_ENDPOINT = 0x05;
|
||||
|
||||
/** HID descriptor. */
|
||||
public static final int DT_HID = 0x21;
|
||||
public static final byte DT_HID = 0x21;
|
||||
|
||||
/** HID report descriptor. */
|
||||
public static final int DT_REPORT = 0x22;
|
||||
public static final byte DT_REPORT = 0x22;
|
||||
|
||||
/** Physical descriptor. */
|
||||
public static final int DT_PHYSICAL = 0x23;
|
||||
public static final byte DT_PHYSICAL = 0x23;
|
||||
|
||||
/** Hub descriptor. */
|
||||
public static final int DT_HUB = 0x29;
|
||||
public static final byte DT_HUB = 0x29;
|
||||
|
||||
/** Hub descriptor. */
|
||||
public static final int DT_SUPERSPEED_HUB = 0x2a;
|
||||
public static final byte DT_SUPERSPEED_HUB = 0x2A;
|
||||
|
||||
// Descriptor sizes per descriptor type
|
||||
|
||||
/** Size of a device descriptor. */
|
||||
public static final int DT_DEVICE_SIZE = 18;
|
||||
public static final byte DT_DEVICE_SIZE = 18;
|
||||
|
||||
/** Size of a config descriptor. */
|
||||
public static final int DT_CONFIG_SIZE = 9;
|
||||
public static final byte DT_CONFIG_SIZE = 9;
|
||||
|
||||
/** Size of an interface descriptor. */
|
||||
public static final int DT_INTERFACE_SIZE = 9;
|
||||
public static final byte DT_INTERFACE_SIZE = 9;
|
||||
|
||||
/** Size of an interface descriptor. */
|
||||
public static final int DT_ENDPOINT_SIZE = 7;
|
||||
public static final byte DT_ENDPOINT_SIZE = 7;
|
||||
|
||||
/** Size of an interface descriptor. */
|
||||
public static final int DT_ENDPOINT_AUDIO_SIZE = 9;
|
||||
public static final byte DT_ENDPOINT_AUDIO_SIZE = 9;
|
||||
|
||||
/** Size of an interface descriptor. */
|
||||
public static final int DT_HUB_NONVAR_SIZE = 7;
|
||||
public static final byte DT_HUB_NONVAR_SIZE = 7;
|
||||
|
||||
// Endpoint direction. Values for bit 7 of the endpoint address scheme.
|
||||
|
||||
/** In: device-to-host. */
|
||||
public static final int ENDPOINT_IN = 0x80;
|
||||
public static final byte ENDPOINT_IN = (byte) 0x80;
|
||||
|
||||
/** Out: host-to-device. */
|
||||
public static final int ENDPOINT_OUT = 0x00;
|
||||
public static final byte ENDPOINT_OUT = 0x00;
|
||||
|
||||
// === Masks =============================================================
|
||||
|
||||
/** Endpoint address mask. */
|
||||
public static final int ENDPOINT_ADDRESS_MASK = 0x0f;
|
||||
public static final byte ENDPOINT_ADDRESS_MASK = 0x0F;
|
||||
|
||||
/** Endpoint direction mask. */
|
||||
public static final int ENDPOINT_DIR_MASK = 0x80;
|
||||
public static final byte ENDPOINT_DIR_MASK = (byte) 0x80;
|
||||
|
||||
/** Transfer type mask. */
|
||||
public static final int TRANSFER_TYPE_MASK = 0x03;
|
||||
public static final byte TRANSFER_TYPE_MASK = 0x03;
|
||||
|
||||
// Endpoint transfer type. Values for bits 0:1 of the endpoint attributes
|
||||
// field.
|
||||
|
||||
/** Control endpoint. */
|
||||
public static final int TRANSFER_TYPE_CONTROL = 0;
|
||||
public static final byte TRANSFER_TYPE_CONTROL = 0;
|
||||
|
||||
/** Isochronous endpoint. */
|
||||
public static final int TRANSFER_TYPE_ISOCHRONOUS = 1;
|
||||
public static final byte TRANSFER_TYPE_ISOCHRONOUS = 1;
|
||||
|
||||
/** Bulk endpoint. */
|
||||
public static final int TRANSFER_TYPE_BULK = 2;
|
||||
public static final byte TRANSFER_TYPE_BULK = 2;
|
||||
|
||||
/** Interrupt endpoint. */
|
||||
public static final int TRANSFER_TYPE_INTERRUPT = 3;
|
||||
public static final byte TRANSFER_TYPE_INTERRUPT = 3;
|
||||
|
||||
// Synchronization type for isochronous endpoints.
|
||||
// Values for bits 2:3 of the bmAttributes field in
|
||||
// EndpointDescriptor.
|
||||
|
||||
public static final int ISO_SYNC_TYPE_MASK = 0x0C;
|
||||
public static final byte ISO_SYNC_TYPE_MASK = 0x0C;
|
||||
|
||||
/** No synchronization. */
|
||||
public static final int ISO_SYNC_TYPE_NONE = 0;
|
||||
public static final byte ISO_SYNC_TYPE_NONE = 0;
|
||||
|
||||
/** Asynchronous. */
|
||||
public static final int ISO_SYNC_TYPE_ASYNC = 1;
|
||||
public static final byte ISO_SYNC_TYPE_ASYNC = 1;
|
||||
|
||||
/** Adaptive. */
|
||||
public static final int ISO_SYNC_TYPE_ADAPTIVE = 2;
|
||||
public static final byte ISO_SYNC_TYPE_ADAPTIVE = 2;
|
||||
|
||||
/** Synchronous. */
|
||||
public static final int ISO_SYNC_TYPE_SYNC = 3;
|
||||
public static final byte ISO_SYNC_TYPE_SYNC = 3;
|
||||
|
||||
// Usage type for isochronous endpoints. Values for bits 4:5 of the
|
||||
// bmAttributes field in EndpointDescriptor.
|
||||
|
||||
public static final int ISO_USAGE_TYPE_MASK = 0x30;
|
||||
public static final byte ISO_USAGE_TYPE_MASK = 0x30;
|
||||
|
||||
/** Data endpoint. */
|
||||
public static final int ISO_USAGE_TYPE_DATA = 0;
|
||||
public static final byte ISO_USAGE_TYPE_DATA = 0;
|
||||
|
||||
/** Feedback endpoint. */
|
||||
public static final int ISO_USAGE_TYPE_FEEDBACK = 1;
|
||||
public static final byte ISO_USAGE_TYPE_FEEDBACK = 1;
|
||||
|
||||
/** Implicit feedback Data endpoint. */
|
||||
public static final int ISO_USAGE_TYPE_IMPLICIT = 2;
|
||||
public static final byte ISO_USAGE_TYPE_IMPLICIT = 2;
|
||||
|
||||
/** Report short frames as errors. */
|
||||
public static final int TRANSFER_SHORT_NOT_OK = 1;
|
||||
public static final byte TRANSFER_SHORT_NOT_OK = 1;
|
||||
|
||||
// Transfer flags
|
||||
|
||||
@ -425,7 +425,7 @@ public final class LibUsb
|
||||
* needed action to take, and it is already done by the
|
||||
* TRANSFER_FREE_TRANSFER flag.
|
||||
*/
|
||||
public static final int TRANSFER_FREE_BUFFER = 0; // Originally 2
|
||||
public static final byte TRANSFER_FREE_BUFFER = 0; // Originally 2
|
||||
|
||||
/**
|
||||
* Automatically call {@link #freeTransfer(Transfer)} after callback
|
||||
@ -435,7 +435,7 @@ public final class LibUsb
|
||||
* {@link #freeTransfer(Transfer)} from your transfer callback, as this will
|
||||
* result in a double-free when this flag is acted upon.
|
||||
*/
|
||||
public static final int TRANSFER_FREE_TRANSFER = 4;
|
||||
public static final byte TRANSFER_FREE_TRANSFER = 4;
|
||||
|
||||
/**
|
||||
* Terminate transfers that are a multiple of the endpoint's wMaxPacketSize
|
||||
@ -459,7 +459,7 @@ public final class LibUsb
|
||||
* libusb_submit_transfer() will return {@link #ERROR_NOT_SUPPORTED} for
|
||||
* every transfer where this flag is set.
|
||||
*/
|
||||
public static final int TRANSFER_ADD_ZERO_PACKET = 8;
|
||||
public static final byte TRANSFER_ADD_ZERO_PACKET = 8;
|
||||
|
||||
// Transfer status codes
|
||||
|
||||
@ -700,7 +700,7 @@ public final class LibUsb
|
||||
* does not exist {@link #ERROR_OTHER} on other failure
|
||||
*/
|
||||
public static native int getMaxPacketSize(final Device device,
|
||||
final int endpoint);
|
||||
final byte endpoint);
|
||||
|
||||
/**
|
||||
* Calculate the maximum packet size which a specific endpoint is capable
|
||||
@ -729,7 +729,7 @@ public final class LibUsb
|
||||
* {@link #ERROR_OTHER} on other failure.
|
||||
*/
|
||||
public static native int getMaxIsoPacketSize(final Device device,
|
||||
final int endpoint);
|
||||
final byte endpoint);
|
||||
|
||||
/**
|
||||
* Increment the reference count of a device.
|
||||
@ -797,7 +797,7 @@ public final class LibUsb
|
||||
* device could not be found.
|
||||
*/
|
||||
public static native DeviceHandle openDeviceWithVidPid(
|
||||
final Context context, final int vendorId, final int productId);
|
||||
final Context context, final short vendorId, final short productId);
|
||||
|
||||
/**
|
||||
* Close a device handle.
|
||||
@ -913,7 +913,7 @@ public final class LibUsb
|
||||
*
|
||||
* @param handle
|
||||
* A device handle.
|
||||
* @param iface
|
||||
* @param interfaceNumber
|
||||
* The bInterfaceNumber of the interface you wish to claim.
|
||||
* @return 0 on success, {@link #ERROR_NOT_FOUND} if the requested interface
|
||||
* does not exist, {@link #ERROR_BUSY} if another program or driver
|
||||
@ -921,7 +921,7 @@ public final class LibUsb
|
||||
* has been disconnected, another error code on other failure
|
||||
*/
|
||||
public static native int claimInterface(final DeviceHandle handle,
|
||||
final int iface);
|
||||
final int interfaceNumber);
|
||||
|
||||
/**
|
||||
* Release an interface previously claimed with
|
||||
@ -934,14 +934,14 @@ public final class LibUsb
|
||||
*
|
||||
* @param handle
|
||||
* a device handle.
|
||||
* @param iface
|
||||
* @param interfaceNumber
|
||||
* The bInterfaceNumber of the previously-claimed interface
|
||||
* @return 0 on success, {@link #ERROR_NOT_FOUND} if the interface was not
|
||||
* claimed, {@link #ERROR_NO_DEVICE} if the device has been
|
||||
* disconnected, another ERROR code on other failure
|
||||
*/
|
||||
public static native int releaseInterface(final DeviceHandle handle,
|
||||
final int iface);
|
||||
final int interfaceNumber);
|
||||
|
||||
/**
|
||||
* Activate an alternate setting for an interface.
|
||||
@ -989,7 +989,7 @@ public final class LibUsb
|
||||
* disconnected, another ERROR code on other failure.
|
||||
*/
|
||||
public static native int clearHalt(final DeviceHandle handle,
|
||||
final int endpoint);
|
||||
final byte endpoint);
|
||||
|
||||
/**
|
||||
* Perform a USB port reset to reinitialize a device.
|
||||
@ -1127,7 +1127,7 @@ public final class LibUsb
|
||||
* The little-endian value to convert
|
||||
* @return the value in host-endian byte order
|
||||
*/
|
||||
public static native int le16ToCpu(final int x);
|
||||
public static native short le16ToCpu(final short x);
|
||||
|
||||
/**
|
||||
* Convert a 16-bit value from host-endian to little-endian format.
|
||||
@ -1139,7 +1139,7 @@ public final class LibUsb
|
||||
* The host-endian value to convert
|
||||
* @return the value in little-endian byte order
|
||||
*/
|
||||
public static native int cpuToLe16(final int x);
|
||||
public static native short cpuToLe16(final short x);
|
||||
|
||||
/**
|
||||
* Get the USB device descriptor for a given device.
|
||||
@ -1215,7 +1215,7 @@ public final class LibUsb
|
||||
* @see #getConfigDescriptorByValue(Device, int, ConfigDescriptor)
|
||||
*/
|
||||
public static native int getConfigDescriptor(final Device device,
|
||||
final int index, final ConfigDescriptor descriptor);
|
||||
final byte index, final ConfigDescriptor descriptor);
|
||||
|
||||
/**
|
||||
* Get a USB configuration descriptor with a specific bConfigurationValue.
|
||||
@ -1239,7 +1239,7 @@ public final class LibUsb
|
||||
* @see #getConfigDescriptor(Device, int, ConfigDescriptor)
|
||||
*/
|
||||
public static native int getConfigDescriptorByValue(final Device device,
|
||||
final int value, final ConfigDescriptor descriptor);
|
||||
final byte value, final ConfigDescriptor descriptor);
|
||||
|
||||
/**
|
||||
* Free a configuration descriptor obtained from
|
||||
@ -1267,7 +1267,7 @@ public final class LibUsb
|
||||
* @return Number of bytes returned in data, or ERROR code on failure.
|
||||
*/
|
||||
public static native int getStringDescriptorAscii(
|
||||
final DeviceHandle handle, final int index, final StringBuffer string);
|
||||
final DeviceHandle handle, final byte index, final StringBuffer string);
|
||||
|
||||
/**
|
||||
* A simple wrapper around
|
||||
@ -1285,7 +1285,7 @@ public final class LibUsb
|
||||
* @return The string or null if it could not be read.
|
||||
*/
|
||||
public static String getStringDescriptor(final DeviceHandle handle,
|
||||
final int index)
|
||||
final byte index)
|
||||
{
|
||||
if ((handle == null) || (index == 0))
|
||||
{
|
||||
@ -1319,11 +1319,11 @@ public final class LibUsb
|
||||
* @return number of bytes returned in data, or ERROR code on failure
|
||||
*
|
||||
*/
|
||||
public static int getDescriptor(final DeviceHandle handle, final int type,
|
||||
final int index, final ByteBuffer data)
|
||||
public static int getDescriptor(final DeviceHandle handle, final byte type,
|
||||
final byte index, final ByteBuffer data)
|
||||
{
|
||||
return controlTransfer(handle, ENDPOINT_IN, REQUEST_GET_DESCRIPTOR,
|
||||
(type << 8) | index, 0, data, 1000);
|
||||
(short)((type << 8) | index), (short) 0, data, 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1345,10 +1345,10 @@ public final class LibUsb
|
||||
* @see #getStringDescriptorAscii(DeviceHandle, int, StringBuffer)
|
||||
*/
|
||||
public static int getStringDescriptor(final DeviceHandle handle,
|
||||
final int index, final int langId, final ByteBuffer data)
|
||||
final byte index, final short langId, final ByteBuffer data)
|
||||
{
|
||||
return controlTransfer(handle, ENDPOINT_IN, REQUEST_GET_DESCRIPTOR,
|
||||
(DT_STRING << 8) | index, langId, data, 1000);
|
||||
(short)((DT_STRING << 8) | index), langId, data, 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1384,8 +1384,8 @@ public final class LibUsb
|
||||
* disconnected, another ERROR code on other failures
|
||||
*/
|
||||
public static native int controlTransfer(final DeviceHandle handle,
|
||||
final int bmRequestType, final int bRequest, final int wValue,
|
||||
final int wIndex, final ByteBuffer data, final long timeout);
|
||||
final byte bmRequestType, final byte bRequest, final short wValue,
|
||||
final short wIndex, final ByteBuffer data, final long timeout);
|
||||
|
||||
/**
|
||||
* Perform a USB bulk transfer.
|
||||
@ -1429,7 +1429,7 @@ public final class LibUsb
|
||||
* been disconnected, another ERROR code on other failures.
|
||||
*/
|
||||
public static native int bulkTransfer(final DeviceHandle handle,
|
||||
final int endpoint, final ByteBuffer data, final IntBuffer transferred,
|
||||
final byte endpoint, final ByteBuffer data, final IntBuffer transferred,
|
||||
final long timeout);
|
||||
|
||||
/**
|
||||
@ -1475,7 +1475,7 @@ public final class LibUsb
|
||||
* has been disconnected, another ERROR code on other error
|
||||
*/
|
||||
public static native int interruptTransfer(final DeviceHandle handle,
|
||||
final int endpoint, final ByteBuffer data, final IntBuffer transferred,
|
||||
final byte endpoint, final ByteBuffer data, final IntBuffer transferred,
|
||||
final long timeout);
|
||||
|
||||
/**
|
||||
@ -2039,8 +2039,8 @@ public final class LibUsb
|
||||
}
|
||||
|
||||
public static void fillControlSetup(final ByteBuffer buffer,
|
||||
final int bmRequestType, final int bRequest, final int wValue,
|
||||
final int wIndex, final int wLength)
|
||||
final byte bmRequestType, final byte bRequest, final short wValue,
|
||||
final short wIndex, final short wLength)
|
||||
{
|
||||
final ControlSetup setup = new ControlSetup(buffer);
|
||||
setup.setBmRequestType(bmRequestType);
|
||||
@ -2056,7 +2056,7 @@ public final class LibUsb
|
||||
final long timeout)
|
||||
{
|
||||
transfer.setDevHandle(handle);
|
||||
transfer.setEndpoint(0);
|
||||
transfer.setEndpoint((byte) 0);
|
||||
transfer.setType(TRANSFER_TYPE_CONTROL);
|
||||
transfer.setTimeout(timeout);
|
||||
transfer.setBuffer(buffer);
|
||||
@ -2065,11 +2065,11 @@ public final class LibUsb
|
||||
|
||||
// Set length based on wLength from Control Setup.
|
||||
final ControlSetup setup = new ControlSetup(buffer);
|
||||
transfer.setLength(CONTROL_SETUP_SIZE + setup.wLength());
|
||||
transfer.setLength(CONTROL_SETUP_SIZE + (setup.wLength() & 0xFFFF));
|
||||
}
|
||||
|
||||
public static void fillBulkTransfer(final Transfer transfer,
|
||||
final DeviceHandle handle, final int endpoint, final ByteBuffer buffer,
|
||||
final DeviceHandle handle, final byte endpoint, final ByteBuffer buffer,
|
||||
final TransferCallback callback, final Object userData,
|
||||
final long timeout)
|
||||
{
|
||||
@ -2083,7 +2083,7 @@ public final class LibUsb
|
||||
}
|
||||
|
||||
public static void fillInterruptTransfer(final Transfer transfer,
|
||||
final DeviceHandle handle, final int endpoint, final ByteBuffer buffer,
|
||||
final DeviceHandle handle, final byte endpoint, final ByteBuffer buffer,
|
||||
final TransferCallback callback, final Object userData,
|
||||
final long timeout)
|
||||
{
|
||||
@ -2097,7 +2097,7 @@ public final class LibUsb
|
||||
}
|
||||
|
||||
public static void fillIsoTransfer(final Transfer transfer,
|
||||
final DeviceHandle handle, final int endpoint, final ByteBuffer buffer,
|
||||
final DeviceHandle handle, final byte endpoint, final ByteBuffer buffer,
|
||||
final int numIsoPackets, final TransferCallback callback,
|
||||
final Object userData, final long timeout)
|
||||
{
|
||||
|
||||
@ -82,7 +82,7 @@ public final class Transfer
|
||||
* @param flags
|
||||
* The transfer flags to set.
|
||||
*/
|
||||
public native void setFlags(final int flags);
|
||||
public native void setFlags(final byte flags);
|
||||
|
||||
/**
|
||||
* Returns the address of the endpoint where this transfer will be sent.
|
||||
@ -97,7 +97,7 @@ public final class Transfer
|
||||
* @param endpoint
|
||||
* The endpoint address to set
|
||||
*/
|
||||
public native void setEndpoint(final int endpoint);
|
||||
public native void setEndpoint(final byte endpoint);
|
||||
|
||||
/**
|
||||
* Returns the type of the endpoint.
|
||||
@ -112,7 +112,7 @@ public final class Transfer
|
||||
* @param type
|
||||
* The endpoint type to set.
|
||||
*/
|
||||
public native void setType(final int type);
|
||||
public native void setType(final byte type);
|
||||
|
||||
/**
|
||||
* Returns the timeout for this transfer in milliseconds. A value of 0
|
||||
|
||||
@ -24,8 +24,8 @@ import de.ailis.usb4java.libusb.LibUsb;
|
||||
public final class DescriptorUtils
|
||||
{
|
||||
/** Mapping from USB class id to USB class name. */
|
||||
private static final Map<Integer, String> CLASS_NAMES =
|
||||
new HashMap<Integer, String>();
|
||||
private static final Map<Byte, String> CLASS_NAMES =
|
||||
new HashMap<Byte, String>();
|
||||
|
||||
static
|
||||
{
|
||||
@ -66,7 +66,7 @@ public final class DescriptorUtils
|
||||
* The numeric USB class.
|
||||
* @return The USB class name.
|
||||
*/
|
||||
public static String getUSBClassName(final int usbClass)
|
||||
public static String getUSBClassName(final byte usbClass)
|
||||
{
|
||||
final String name = CLASS_NAMES.get(usbClass);
|
||||
|
||||
@ -85,9 +85,9 @@ public final class DescriptorUtils
|
||||
* The binary-coded decimal to decode.
|
||||
* @return The decoded binary-coded decimal.
|
||||
*/
|
||||
public static String decodeBCD(final int bcd)
|
||||
public static String decodeBCD(final short bcd)
|
||||
{
|
||||
return String.format("%x.%02x", (bcd & 0xff00) >> 8, bcd & 0xff);
|
||||
return String.format("%x.%02x", (bcd & 0xFF00) >> 8, bcd & 0x00FF);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -169,7 +169,7 @@ public final class DescriptorUtils
|
||||
descriptor.bDescriptorType(),
|
||||
decodeBCD(descriptor.bcdUSB()),
|
||||
descriptor.bDeviceClass() & 0xff,
|
||||
getUSBClassName(descriptor.bDeviceClass() & 0xff),
|
||||
getUSBClassName(descriptor.bDeviceClass()),
|
||||
descriptor.bDeviceSubClass() & 0xff,
|
||||
descriptor.bDeviceProtocol() & 0xff,
|
||||
descriptor.bMaxPacketSize0() & 0xff,
|
||||
@ -246,7 +246,7 @@ public final class DescriptorUtils
|
||||
descriptor.bAlternateSetting() & 0xff,
|
||||
descriptor.bNumEndpoints() & 0xff,
|
||||
descriptor.bInterfaceClass() & 0xff,
|
||||
getUSBClassName(descriptor.bInterfaceClass() & 0xff),
|
||||
getUSBClassName(descriptor.bInterfaceClass()),
|
||||
descriptor.bInterfaceSubClass() & 0xff,
|
||||
descriptor.bInterfaceProtocol() & 0xff,
|
||||
descriptor.iInterface() & 0xff);
|
||||
@ -277,9 +277,9 @@ public final class DescriptorUtils
|
||||
descriptor.bEndpointAddress() & 0xf,
|
||||
((descriptor.bEndpointAddress() & 0x80) == 0) ? ("OUT") : ("IN"),
|
||||
descriptor.bmAttributes() & 0xff,
|
||||
getTransferTypeName(descriptor.bmAttributes() & 0xff),
|
||||
getSynchTypeName(descriptor.bmAttributes() & 0xff),
|
||||
getUsageTypeName(descriptor.bmAttributes() & 0xff),
|
||||
getTransferTypeName(descriptor.bmAttributes()),
|
||||
getSynchTypeName(descriptor.bmAttributes()),
|
||||
getUsageTypeName(descriptor.bmAttributes()),
|
||||
descriptor.wMaxPacketSize() & 0xffff,
|
||||
descriptor.bInterval() & 0xff);
|
||||
}
|
||||
@ -292,7 +292,7 @@ public final class DescriptorUtils
|
||||
* The endpoint attributes value.
|
||||
* @return The transfer type name.
|
||||
*/
|
||||
public static String getTransferTypeName(final int bmAttributes)
|
||||
public static String getTransferTypeName(final byte bmAttributes)
|
||||
{
|
||||
switch (bmAttributes & LibUsb.TRANSFER_TYPE_MASK)
|
||||
{
|
||||
@ -317,7 +317,7 @@ public final class DescriptorUtils
|
||||
* The endpoint attributes value.
|
||||
* @return The synch type name.
|
||||
*/
|
||||
public static String getSynchTypeName(final int bmAttributes)
|
||||
public static String getSynchTypeName(final byte bmAttributes)
|
||||
{
|
||||
switch ((bmAttributes & LibUsb.ISO_SYNC_TYPE_MASK) >> 2)
|
||||
{
|
||||
@ -341,7 +341,7 @@ public final class DescriptorUtils
|
||||
* The endpoint attributes value.
|
||||
* @return The usage type name.
|
||||
*/
|
||||
public static String getUsageTypeName(final int bmAttributes)
|
||||
public static String getUsageTypeName(final byte bmAttributes)
|
||||
{
|
||||
switch ((bmAttributes & LibUsb.ISO_USAGE_TYPE_MASK) >> 4)
|
||||
{
|
||||
|
||||
@ -34,16 +34,16 @@ public class LibUSBDeviceTest
|
||||
private Device device;
|
||||
|
||||
/** The device endpoint to test with. */
|
||||
private int endpoint;
|
||||
private byte endpoint;
|
||||
|
||||
/** The value of the active configuration. */
|
||||
private int configValue;
|
||||
private byte configValue;
|
||||
|
||||
/** The vendor ID of the device we test. */
|
||||
private int vendorId;
|
||||
private short vendorId;
|
||||
|
||||
/** The manufacturer ID of the device we test. */
|
||||
private int productId;
|
||||
private short productId;
|
||||
|
||||
/**
|
||||
* Set up the test.
|
||||
@ -51,19 +51,21 @@ public class LibUSBDeviceTest
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
this.context = new Context();
|
||||
LibUsb.init(this.context);
|
||||
context = new Context();
|
||||
LibUsb.init(context);
|
||||
try
|
||||
{
|
||||
this.device = findTestDevice();
|
||||
if (this.device == null)
|
||||
device = findTestDevice();
|
||||
if (device == null)
|
||||
{
|
||||
throw new IllegalStateException("Need at least one USB device "
|
||||
+
|
||||
"with at least one endpoint to execute this test");
|
||||
}
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
this.device = null;
|
||||
device = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,22 +77,29 @@ public class LibUSBDeviceTest
|
||||
private Device findTestDevice()
|
||||
{
|
||||
DeviceList list = new DeviceList();
|
||||
if (LibUsb.getDeviceList(this.context, list) <= 0) return null;
|
||||
if (LibUsb.getDeviceList(context, list) <= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
try
|
||||
{
|
||||
for (Device device: list)
|
||||
{
|
||||
DeviceDescriptor descriptor = new DeviceDescriptor();
|
||||
if (LibUsb.getDeviceDescriptor(device, descriptor) != 0)
|
||||
{
|
||||
continue;
|
||||
this.vendorId = descriptor.idVendor();
|
||||
this.productId = descriptor.idProduct();
|
||||
}
|
||||
vendorId = descriptor.idVendor();
|
||||
productId = descriptor.idProduct();
|
||||
ConfigDescriptor config = new ConfigDescriptor();
|
||||
if (LibUsb.getActiveConfigDescriptor(device, config) < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
try
|
||||
{
|
||||
this.configValue = config.bConfigurationValue();
|
||||
configValue = config.bConfigurationValue();
|
||||
for (int j = 0; j < config.bNumInterfaces(); j++)
|
||||
{
|
||||
Interface iface = config.iface()[j];
|
||||
@ -100,7 +109,7 @@ public class LibUSBDeviceTest
|
||||
iface.altsetting()[k];
|
||||
if (ifaceDescriptor.bNumEndpoints() > 1)
|
||||
{
|
||||
this.endpoint = ifaceDescriptor.endpoint()[0].
|
||||
endpoint = ifaceDescriptor.endpoint()[0].
|
||||
bEndpointAddress();
|
||||
return LibUsb.refDevice(device);
|
||||
}
|
||||
@ -126,8 +135,14 @@ public class LibUSBDeviceTest
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
if (this.device != null) LibUsb.unrefDevice(this.device);
|
||||
if (this.context != null) LibUsb.exit(this.context);
|
||||
if (device != null)
|
||||
{
|
||||
LibUsb.unrefDevice(device);
|
||||
}
|
||||
if (context != null)
|
||||
{
|
||||
LibUsb.exit(context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,8 +152,8 @@ public class LibUSBDeviceTest
|
||||
public void testGetBusNumber()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
assumeNotNull(this.device);
|
||||
assertTrue(LibUsb.getBusNumber(this.device) >= 0);
|
||||
assumeNotNull(device);
|
||||
assertTrue(LibUsb.getBusNumber(device) >= 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -148,8 +163,8 @@ public class LibUSBDeviceTest
|
||||
public void testGetPortNumber()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
assumeNotNull(this.device);
|
||||
assertTrue(LibUsb.getPortNumber(this.device) >= 0);
|
||||
assumeNotNull(device);
|
||||
assertTrue(LibUsb.getPortNumber(device) >= 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -159,9 +174,9 @@ public class LibUSBDeviceTest
|
||||
public void testGetPortPath()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
assumeNotNull(this.device);
|
||||
assumeNotNull(device);
|
||||
ByteBuffer path = ByteBuffer.allocateDirect(8);
|
||||
int result = LibUsb.getPortPath(this.context, this.device, path);
|
||||
int result = LibUsb.getPortPath(context, device, path);
|
||||
assertTrue(result > 0);
|
||||
assertTrue(result <= path.capacity());
|
||||
}
|
||||
@ -174,9 +189,9 @@ public class LibUSBDeviceTest
|
||||
public void testGetPortPathWithTooSmallBuffer()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
assumeNotNull(this.device);
|
||||
assumeNotNull(device);
|
||||
ByteBuffer path = ByteBuffer.allocateDirect(0);
|
||||
int result = LibUsb.getPortPath(this.context, this.device, path);
|
||||
int result = LibUsb.getPortPath(context, device, path);
|
||||
assertEquals(LibUsb.ERROR_OVERFLOW, result);
|
||||
}
|
||||
|
||||
@ -188,7 +203,7 @@ public class LibUSBDeviceTest
|
||||
public void testGetPortPathWithoutDevice()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getPortPath(this.context, null, ByteBuffer.allocateDirect(8));
|
||||
LibUsb.getPortPath(context, null, ByteBuffer.allocateDirect(8));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -199,7 +214,7 @@ public class LibUSBDeviceTest
|
||||
public void testGetPortPathWithoutBuffer()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getPortPath(this.context, this.device, null);
|
||||
LibUsb.getPortPath(context, device, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -210,9 +225,9 @@ public class LibUSBDeviceTest
|
||||
public void testGetPortPathWithUninitializedContext()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
assumeNotNull(this.device);
|
||||
assumeNotNull(device);
|
||||
final Context context = new Context();
|
||||
LibUsb.getPortPath(context, this.device, ByteBuffer.allocateDirect(16));
|
||||
LibUsb.getPortPath(context, device, ByteBuffer.allocateDirect(16));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -223,7 +238,7 @@ public class LibUSBDeviceTest
|
||||
public void testGetPortPathWithUninitializedDevice()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getPortPath(this.context, new Device(), ByteBuffer.allocateDirect(16));
|
||||
LibUsb.getPortPath(context, new Device(), ByteBuffer.allocateDirect(16));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -233,17 +248,17 @@ public class LibUSBDeviceTest
|
||||
public void testGetParent()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
assumeNotNull(this.device);
|
||||
assumeNotNull(device);
|
||||
DeviceList list = new DeviceList();
|
||||
LibUsb.getDeviceList(this.context, list);
|
||||
LibUsb.getDeviceList(context, list);
|
||||
try
|
||||
{
|
||||
Device parent = LibUsb.getParent(this.device);
|
||||
Device parent = LibUsb.getParent(device);
|
||||
|
||||
// We cannot test anything else here. Parent can be null if our
|
||||
// test device is a root device. We just make sure that it can't
|
||||
// be the device itself.
|
||||
assertNotEquals(parent, this.device);
|
||||
assertNotEquals(parent, device);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -268,8 +283,8 @@ public class LibUSBDeviceTest
|
||||
public void testGetDeviceAddress()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
assumeNotNull(this.device);
|
||||
assertTrue(LibUsb.getDeviceAddress(this.device) >= 0);
|
||||
assumeNotNull(device);
|
||||
assertTrue(LibUsb.getDeviceAddress(device) >= 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -290,9 +305,9 @@ public class LibUSBDeviceTest
|
||||
public void testGetDeviceSpeed()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
assumeNotNull(this.device);
|
||||
int speed = LibUsb.getDeviceSpeed(this.device);
|
||||
assertTrue(speed >= LibUsb.SPEED_UNKNOWN && speed <= LibUsb.SPEED_SUPER);
|
||||
assumeNotNull(device);
|
||||
int speed = LibUsb.getDeviceSpeed(device);
|
||||
assertTrue((speed >= LibUsb.SPEED_UNKNOWN) && (speed <= LibUsb.SPEED_SUPER));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -306,71 +321,71 @@ public class LibUSBDeviceTest
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link LibUsb#getMaxPacketSize(Device, int)} method.
|
||||
* Tests the {@link LibUsb#getMaxPacketSize(Device, byte)} method.
|
||||
*/
|
||||
@Test
|
||||
public void testGetMaxPacketSizeWithInvalidEndpoint()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
assumeNotNull(this.device);
|
||||
assumeNotNull(device);
|
||||
assertEquals(LibUsb.ERROR_NOT_FOUND,
|
||||
LibUsb.getMaxPacketSize(this.device, 0));
|
||||
LibUsb.getMaxPacketSize(device, (byte) 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link LibUsb#getMaxPacketSize(Device, int)} method.
|
||||
* Tests the {@link LibUsb#getMaxPacketSize(Device, byte)} method.
|
||||
*/
|
||||
@Test
|
||||
public void testGetMaxPacketSize()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
assumeNotNull(this.device);
|
||||
assertTrue(LibUsb.getMaxPacketSize(this.device, this.endpoint) > 0);
|
||||
assumeNotNull(device);
|
||||
assertTrue(LibUsb.getMaxPacketSize(device, endpoint) > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link LibUsb#getMaxPacketSize(Device, int)} method without a
|
||||
* Tests the {@link LibUsb#getMaxPacketSize(Device, byte)} method without a
|
||||
* device.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetMaxPacketSizeWithoutDevice()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getMaxPacketSize(null, 0);
|
||||
LibUsb.getMaxPacketSize(null, (byte) 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link LibUsb#getMaxIsoPacketSize(Device, int)} method.
|
||||
* Tests the {@link LibUsb#getMaxIsoPacketSize(Device, byte)} method.
|
||||
*/
|
||||
@Test
|
||||
public void testGetMaxIsoPacketSizeWithInvalidEndpoint()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
assumeNotNull(this.device);
|
||||
assumeNotNull(device);
|
||||
assertEquals(LibUsb.ERROR_NOT_FOUND,
|
||||
LibUsb.getMaxIsoPacketSize(this.device, 0));
|
||||
LibUsb.getMaxIsoPacketSize(device, (byte) 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link LibUsb#getMaxIsoPacketSize(Device, int)} method.
|
||||
* Tests the {@link LibUsb#getMaxIsoPacketSize(Device, byte)} method.
|
||||
*/
|
||||
@Test
|
||||
public void testGetMaxIsoPacketSize()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
assumeNotNull(this.device);
|
||||
assertTrue(LibUsb.getMaxIsoPacketSize(this.device, this.endpoint) > 0);
|
||||
assumeNotNull(device);
|
||||
assertTrue(LibUsb.getMaxIsoPacketSize(device, endpoint) > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link LibUsb#getMaxIsoPacketSize(Device, int)} method without
|
||||
* Tests the {@link LibUsb#getMaxIsoPacketSize(Device, byte)} method without
|
||||
* a device.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetMaxIsoPacketSizeWithoutDevice()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getMaxIsoPacketSize(null, 0);
|
||||
LibUsb.getMaxIsoPacketSize(null, (byte) 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -381,7 +396,7 @@ public class LibUSBDeviceTest
|
||||
public void testRefUnRefDevice()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
assumeNotNull(this.device);
|
||||
assumeNotNull(device);
|
||||
Device device = LibUsb.refDevice(this.device);
|
||||
try
|
||||
{
|
||||
@ -424,10 +439,10 @@ public class LibUSBDeviceTest
|
||||
public void testOpenAndClose()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
assumeNotNull(this.device);
|
||||
assumeNotNull(device);
|
||||
DeviceHandle handle = new DeviceHandle();
|
||||
int result = LibUsb.open(this.device, handle);
|
||||
assertTrue(result == LibUsb.SUCCESS || result == LibUsb.ERROR_ACCESS);
|
||||
int result = LibUsb.open(device, handle);
|
||||
assertTrue((result == LibUsb.SUCCESS) || (result == LibUsb.ERROR_ACCESS));
|
||||
if (result == LibUsb.SUCCESS)
|
||||
{
|
||||
LibUsb.close(handle);
|
||||
@ -464,7 +479,7 @@ public class LibUSBDeviceTest
|
||||
public void testOpenWithoutHandle()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.open(this.device, null);
|
||||
LibUsb.open(device, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -486,9 +501,12 @@ public class LibUSBDeviceTest
|
||||
public void testOpenDeviceWithVidPid()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
DeviceHandle handle = LibUsb.openDeviceWithVidPid(this.context,
|
||||
this.vendorId, this.productId);
|
||||
if (handle != null) LibUsb.close(handle);
|
||||
DeviceHandle handle = LibUsb.openDeviceWithVidPid(context,
|
||||
vendorId, productId);
|
||||
if (handle != null)
|
||||
{
|
||||
LibUsb.close(handle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -570,14 +588,14 @@ public class LibUSBDeviceTest
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link LibUsb#clearHalt(DeviceHandle, int)} method without a
|
||||
* Tests the {@link LibUsb#clearHalt(DeviceHandle, byte)} method without a
|
||||
* handle.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testClearHaltWithoutHandle()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.clearHalt(null, 0);
|
||||
LibUsb.clearHalt(null, (byte) 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -643,7 +661,7 @@ public class LibUSBDeviceTest
|
||||
public void testGetDeviceDescriptorWithoutDescriptor()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getDeviceDescriptor(this.device, null);
|
||||
LibUsb.getDeviceDescriptor(device, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -658,9 +676,9 @@ public class LibUSBDeviceTest
|
||||
public void testGetDeviceDescriptor()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
assumeNotNull(this.device);
|
||||
assumeNotNull(device);
|
||||
DeviceDescriptor desc = new DeviceDescriptor();
|
||||
LibUsb.getDeviceDescriptor(this.device, desc);
|
||||
LibUsb.getDeviceDescriptor(device, desc);
|
||||
desc.bcdDevice();
|
||||
desc.bcdUSB();
|
||||
assertEquals(LibUsb.DT_DEVICE, desc.bDescriptorType());
|
||||
@ -693,7 +711,7 @@ public class LibUSBDeviceTest
|
||||
public void testGetActiveConfigDescriptorWithoutDescriptor()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getActiveConfigDescriptor(this.device, null);
|
||||
LibUsb.getActiveConfigDescriptor(device, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -715,7 +733,9 @@ public class LibUSBDeviceTest
|
||||
assertTrue(desc.wTotalLength() >= desc.bLength());
|
||||
|
||||
for (Interface iface: desc.iface())
|
||||
{
|
||||
validateInterface(iface);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -786,9 +806,9 @@ public class LibUSBDeviceTest
|
||||
public void testGetActiveConfigDescriptor()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
assumeNotNull(this.device);
|
||||
assumeNotNull(device);
|
||||
ConfigDescriptor desc = new ConfigDescriptor();
|
||||
LibUsb.getActiveConfigDescriptor(this.device, desc);
|
||||
LibUsb.getActiveConfigDescriptor(device, desc);
|
||||
try
|
||||
{
|
||||
validateConfigDescriptor(desc);
|
||||
@ -801,39 +821,39 @@ public class LibUSBDeviceTest
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#getConfigDescriptor(Device, int, ConfigDescriptor)} method
|
||||
* {@link LibUsb#getConfigDescriptor(Device, byte, ConfigDescriptor)} method
|
||||
* without a device.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetConfigDescriptorWithoutDevice()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getConfigDescriptor(null, 0, new ConfigDescriptor());
|
||||
LibUsb.getConfigDescriptor(null, (byte) 0, new ConfigDescriptor());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#getConfigDescriptor(Device, int, ConfigDescriptor)} method
|
||||
* {@link LibUsb#getConfigDescriptor(Device, byte, ConfigDescriptor)} method
|
||||
* without a descriptor.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetConfigDescriptorWithoutDescriptor()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getConfigDescriptor(this.device, 0, null);
|
||||
LibUsb.getConfigDescriptor(device, (byte) 0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#getConfigDescriptor(Device, int, ConfigDescriptor)} method.
|
||||
* {@link LibUsb#getConfigDescriptor(Device, byte, ConfigDescriptor)} method.
|
||||
*/
|
||||
@Test
|
||||
public void testGetConfigDescriptor()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
assumeNotNull(this.device);
|
||||
assumeNotNull(device);
|
||||
ConfigDescriptor desc = new ConfigDescriptor();
|
||||
LibUsb.getConfigDescriptor(this.device, 0, desc);
|
||||
LibUsb.getConfigDescriptor(device, (byte) 0, desc);
|
||||
try
|
||||
{
|
||||
validateConfigDescriptor(desc);
|
||||
@ -846,40 +866,40 @@ public class LibUSBDeviceTest
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#getConfigDescriptorByValue(Device, int, ConfigDescriptor)}
|
||||
* {@link LibUsb#getConfigDescriptorByValue(Device, byte, ConfigDescriptor)}
|
||||
* method without a device.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetConfigDescriptorByValueWithoutDevice()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getConfigDescriptorByValue(null, 0, new ConfigDescriptor());
|
||||
LibUsb.getConfigDescriptorByValue(null, (byte) 0, new ConfigDescriptor());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#getConfigDescriptorByValue(Device, int, ConfigDescriptor)}
|
||||
* {@link LibUsb#getConfigDescriptorByValue(Device, byte, ConfigDescriptor)}
|
||||
* method without a descriptor.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetConfigDescriptorByValueWithoutDescriptor()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getConfigDescriptorByValue(this.device, 0, null);
|
||||
LibUsb.getConfigDescriptorByValue(device, (byte) 0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#getConfigDescriptorByValue(Device, int, ConfigDescriptor)}
|
||||
* {@link LibUsb#getConfigDescriptorByValue(Device, byte, ConfigDescriptor)}
|
||||
* method.
|
||||
*/
|
||||
@Test
|
||||
public void testGetConfigDescriptorByValue()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
assumeNotNull(this.device);
|
||||
assumeNotNull(device);
|
||||
ConfigDescriptor desc = new ConfigDescriptor();
|
||||
LibUsb.getConfigDescriptorByValue(this.device, this.configValue, desc);
|
||||
LibUsb.getConfigDescriptorByValue(device, configValue, desc);
|
||||
try
|
||||
{
|
||||
validateConfigDescriptor(desc);
|
||||
@ -913,214 +933,214 @@ public class LibUSBDeviceTest
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#getStringDescriptorAscii(DeviceHandle, int, StringBuffer, int)}
|
||||
* {@link LibUsb#getStringDescriptorAscii(DeviceHandle, byte, StringBuffer)}
|
||||
* method without a handle.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetStringDescriptorAsciiWithoutHandle()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getStringDescriptorAscii(null, 0, new StringBuffer());
|
||||
LibUsb.getStringDescriptorAscii(null, (byte) 0, new StringBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#getStringDescriptorAscii(DeviceHandle, int, StringBuffer, int)}
|
||||
* {@link LibUsb#getStringDescriptorAscii(DeviceHandle, byte, StringBuffer)}
|
||||
* method without a buffer.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetStringDescriptorAsciiWithoutBuffer()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getStringDescriptorAscii(new DeviceHandle(), 0, null);
|
||||
LibUsb.getStringDescriptorAscii(new DeviceHandle(), (byte) 0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#getDescriptor(DeviceHandle, int, int, ByteBuffer)} method
|
||||
* {@link LibUsb#getDescriptor(DeviceHandle, byte, byte, ByteBuffer)} method
|
||||
* without a handle.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetDescriptorWithoutHandle()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getDescriptor(null, 0, 0, ByteBuffer.allocate(18));
|
||||
LibUsb.getDescriptor(null, (byte) 0, (byte) 0, ByteBuffer.allocate(18));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#getDescriptor(DeviceHandle, int, int, ByteBuffer)} method
|
||||
* {@link LibUsb#getDescriptor(DeviceHandle, byte, byte, ByteBuffer)} method
|
||||
* without a buffer.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetDescriptorWithoutBuffer()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getDescriptor(new DeviceHandle(), 0, 0, null);
|
||||
LibUsb.getDescriptor(new DeviceHandle(), (byte) 0, (byte) 0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#getStringDescriptor(DeviceHandle, int, int, ByteBuffer)}
|
||||
* {@link LibUsb#getStringDescriptor(DeviceHandle, byte, short, ByteBuffer)}
|
||||
* method without a handle.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetStringDescriptorWithoutHandle()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getStringDescriptor(null, 0, 0, ByteBuffer.allocate(18));
|
||||
LibUsb.getStringDescriptor(null, (byte) 0, (short) 0, ByteBuffer.allocate(18));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#getStringDescriptor(DeviceHandle, int, int, ByteBuffer)}
|
||||
* {@link LibUsb#getStringDescriptor(DeviceHandle, byte, short, ByteBuffer)}
|
||||
* method without a buffer.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetStringDescriptorWithoutBuffer()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getStringDescriptor(new DeviceHandle(), 0, 0, null);
|
||||
LibUsb.getStringDescriptor(new DeviceHandle(), (byte) 0, (short) 0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#controlTransfer(DeviceHandle, int, int, int, int, ByteBuffer, int)}
|
||||
* {@link LibUsb#controlTransfer(DeviceHandle, byte, byte, short, short, ByteBuffer, long)}
|
||||
* method without a handle.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testControlTransferWithoutHandle()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.controlTransfer(null, 0, 0, 0, 0, ByteBuffer.allocate(0), 0);
|
||||
LibUsb.controlTransfer(null, (byte) 0, (byte) 0, (short) 0, (short) 0, ByteBuffer.allocate(0), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#controlTransfer(DeviceHandle, int, int, int, int, ByteBuffer, int)}
|
||||
* {@link LibUsb#controlTransfer(DeviceHandle, byte, byte, short, short, ByteBuffer, long)}
|
||||
* method without a buffer.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testControlTransferWithoutBuffer()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.controlTransfer(new DeviceHandle(), 0, 0, 0, 0, null, 0);
|
||||
LibUsb.controlTransfer(new DeviceHandle(), (byte) 0, (byte) 0, (short) 0, (short) 0, null, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#controlTransfer(DeviceHandle, int, int, int, int, ByteBuffer, int)}
|
||||
* {@link LibUsb#controlTransfer(DeviceHandle, byte, byte, short, short, ByteBuffer, long)}
|
||||
* method with an indirect buffer.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testControlTransferWithIndirectBuffer()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.controlTransfer(new DeviceHandle(), 0, 0, 0, 0,
|
||||
LibUsb.controlTransfer(new DeviceHandle(), (byte) 0, (byte) 0, (short) 0, (short) 0,
|
||||
ByteBuffer.allocate(0), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#bulkTransfer(DeviceHandle, int, ByteBuffer, IntBuffer, int)}
|
||||
* {@link LibUsb#bulkTransfer(DeviceHandle, byte, ByteBuffer, IntBuffer, long)}
|
||||
* method without a handle.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testBulkTransferWithoutHandle()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.bulkTransfer(null, 0, ByteBuffer.allocate(0),
|
||||
LibUsb.bulkTransfer(null, (byte) 0, ByteBuffer.allocate(0),
|
||||
IntBuffer.allocate(1), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#bulkTransfer(DeviceHandle, int, ByteBuffer, IntBuffer, int)}
|
||||
* {@link LibUsb#bulkTransfer(DeviceHandle, byte, ByteBuffer, IntBuffer, long)}
|
||||
* method without a data buffer.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testBulkTransferWithoutDataBuffer()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.bulkTransfer(new DeviceHandle(), 0, null,
|
||||
LibUsb.bulkTransfer(new DeviceHandle(), (byte) 0, null,
|
||||
IntBuffer.allocate(1), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#bulkTransfer(DeviceHandle, int, ByteBuffer, IntBuffer, int)}
|
||||
* {@link LibUsb#bulkTransfer(DeviceHandle, byte, ByteBuffer, IntBuffer, long)}
|
||||
* method with an indirect data buffer.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testBulkTransferWithIndirectDataBuffer()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.bulkTransfer(new DeviceHandle(), 0, ByteBuffer.allocate(0),
|
||||
LibUsb.bulkTransfer(new DeviceHandle(), (byte) 0, ByteBuffer.allocate(0),
|
||||
IntBuffer.allocate(1), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#bulkTransfer(DeviceHandle, int, ByteBuffer, IntBuffer, int)}
|
||||
* {@link LibUsb#bulkTransfer(DeviceHandle, byte, ByteBuffer, IntBuffer, long)}
|
||||
* method without a transferred buffer.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testBulkTransferWithoutTransferredBuffer()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.bulkTransfer(new DeviceHandle(), 0, ByteBuffer.allocate(0),
|
||||
LibUsb.bulkTransfer(new DeviceHandle(), (byte) 0, ByteBuffer.allocate(0),
|
||||
null, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#interruptTransfer(DeviceHandle, int, ByteBuffer, IntBuffer, int)}
|
||||
* {@link LibUsb#interruptTransfer(DeviceHandle, byte, ByteBuffer, IntBuffer, long)}
|
||||
* method without a handle.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testInterruptTransferWithoutHandle()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.interruptTransfer(null, 0, ByteBuffer.allocate(0),
|
||||
LibUsb.interruptTransfer(null, (byte) 0, ByteBuffer.allocate(0),
|
||||
IntBuffer.allocate(1), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#interruptTransfer(DeviceHandle, int, ByteBuffer, IntBuffer, int)}
|
||||
* {@link LibUsb#interruptTransfer(DeviceHandle, byte, ByteBuffer, IntBuffer, long)}
|
||||
* method without a data buffer.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testInterruptTransferWithoutDataBuffer()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.interruptTransfer(new DeviceHandle(), 0, null,
|
||||
LibUsb.interruptTransfer(new DeviceHandle(), (byte) 0, null,
|
||||
IntBuffer.allocate(1), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#interruptTransfer(DeviceHandle, int, ByteBuffer, IntBuffer, int)}
|
||||
* {@link LibUsb#interruptTransfer(DeviceHandle, byte, ByteBuffer, IntBuffer, long)}
|
||||
* method with an indirect data buffer.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testInterruptTransferWithIndirectDataBuffer()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.interruptTransfer(new DeviceHandle(), 0, ByteBuffer.allocate(0),
|
||||
LibUsb.interruptTransfer(new DeviceHandle(), (byte) 0, ByteBuffer.allocate(0),
|
||||
IntBuffer.allocate(1), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#interruptTransfer(DeviceHandle, int, ByteBuffer, IntBuffer, int)}
|
||||
* {@link LibUsb#interruptTransfer(DeviceHandle, byte, ByteBuffer, IntBuffer, long)}
|
||||
* method without a transferred buffer.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testInterruptTransferWithoutTransferredBuffer()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.interruptTransfer(new DeviceHandle(), 0, ByteBuffer.allocate(0),
|
||||
LibUsb.interruptTransfer(new DeviceHandle(), (byte) 0, ByteBuffer.allocate(0),
|
||||
null, 0);
|
||||
}
|
||||
|
||||
@ -1133,9 +1153,9 @@ public class LibUSBDeviceTest
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
DeviceList list = new DeviceList();
|
||||
assertTrue(LibUsb.getDeviceList(this.context, list) >= 0);
|
||||
assertTrue(LibUsb.getDeviceList(context, list) >= 0);
|
||||
LibUsb.freeDeviceList(list, true);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
LibUsb.freeDeviceList(list, true);
|
||||
@ -1162,7 +1182,7 @@ public class LibUSBDeviceTest
|
||||
{
|
||||
assertTrue(LibUsb.getDeviceList(null, list) >= 0);
|
||||
LibUsb.freeDeviceList(list, true);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
LibUsb.freeDeviceList(list, true);
|
||||
|
||||
@ -16,7 +16,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests the global-scope methods of the {@link LibUsb} class which need a
|
||||
* Tests the global-scope methods of the {@link LibUsb} class which need a
|
||||
* open USB context.
|
||||
*
|
||||
* @author Klaus Reimer (k@ailis.de)
|
||||
@ -32,14 +32,14 @@ public class LibUSBGlobalTest
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
this.context = new Context();
|
||||
context = new Context();
|
||||
try
|
||||
{
|
||||
LibUsb.init(this.context);
|
||||
LibUsb.init(context);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
this.context = null;
|
||||
context = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,7 +49,10 @@ public class LibUSBGlobalTest
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
if (this.context != null) LibUsb.exit(this.context);
|
||||
if (context != null)
|
||||
{
|
||||
LibUsb.exit(context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,11 +62,11 @@ public class LibUSBGlobalTest
|
||||
public void testSetDebug()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.setDebug(this.context, LibUsb.LOG_LEVEL_DEBUG);
|
||||
LibUsb.setDebug(this.context, LibUsb.LOG_LEVEL_INFO);
|
||||
LibUsb.setDebug(this.context, LibUsb.LOG_LEVEL_WARNING);
|
||||
LibUsb.setDebug(this.context, LibUsb.LOG_LEVEL_ERROR);
|
||||
LibUsb.setDebug(this.context, LibUsb.LOG_LEVEL_NONE);
|
||||
LibUsb.setDebug(context, LibUsb.LOG_LEVEL_DEBUG);
|
||||
LibUsb.setDebug(context, LibUsb.LOG_LEVEL_INFO);
|
||||
LibUsb.setDebug(context, LibUsb.LOG_LEVEL_WARNING);
|
||||
LibUsb.setDebug(context, LibUsb.LOG_LEVEL_ERROR);
|
||||
LibUsb.setDebug(context, LibUsb.LOG_LEVEL_NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -74,7 +77,7 @@ public class LibUSBGlobalTest
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
final DeviceList list = new DeviceList();
|
||||
final int result = LibUsb.getDeviceList(this.context, list);
|
||||
final int result = LibUsb.getDeviceList(context, list);
|
||||
assertTrue(
|
||||
"At least one USB device must be present for the simple unit tests",
|
||||
result > 0);
|
||||
@ -98,7 +101,7 @@ public class LibUSBGlobalTest
|
||||
public void testGetDeviceListWithoutList()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getDeviceList(this.context, null);
|
||||
LibUsb.getDeviceList(context, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -109,7 +112,7 @@ public class LibUSBGlobalTest
|
||||
public void testEndianConversion()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
assertEquals(0x1234, LibUsb.le16ToCpu(LibUsb.cpuToLe16(0x1234)));
|
||||
assertEquals(0x1234, LibUsb.le16ToCpu(LibUsb.cpuToLe16((short) 0x1234)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -59,9 +59,9 @@ public class LibUSBTest
|
||||
assertEquals(0x07, LibUsb.REQUEST_SET_DESCRIPTOR);
|
||||
assertEquals(0x08, LibUsb.REQUEST_GET_CONFIGURATION);
|
||||
assertEquals(0x09, LibUsb.REQUEST_SET_CONFIGURATION);
|
||||
assertEquals(0x0a, LibUsb.REQUEST_GET_INTERFACE);
|
||||
assertEquals(0x0b, LibUsb.REQUEST_SET_INTERFACE);
|
||||
assertEquals(0x0c, LibUsb.REQUEST_SYNCH_FRAME);
|
||||
assertEquals(0x0A, LibUsb.REQUEST_GET_INTERFACE);
|
||||
assertEquals(0x0B, LibUsb.REQUEST_SET_INTERFACE);
|
||||
assertEquals(0x0C, LibUsb.REQUEST_SYNCH_FRAME);
|
||||
assertEquals(0x30, LibUsb.REQUEST_SET_SEL);
|
||||
assertEquals(0x31, LibUsb.SET_ISOCH_DELAY);
|
||||
|
||||
@ -108,14 +108,14 @@ public class LibUSBTest
|
||||
assertEquals(8, LibUsb.CLASS_MASS_STORAGE);
|
||||
assertEquals(9, LibUsb.CLASS_HUB);
|
||||
assertEquals(10, LibUsb.CLASS_DATA);
|
||||
assertEquals(0x0b, LibUsb.CLASS_SMART_CARD);
|
||||
assertEquals(0x0d, LibUsb.CLASS_CONTENT_SECURITY);
|
||||
assertEquals(0x0e, LibUsb.CLASS_VIDEO);
|
||||
assertEquals(0x0f, LibUsb.CLASS_PERSONAL_HEALTHCARE);
|
||||
assertEquals(0xdc, LibUsb.CLASS_DIAGNOSTIC_DEVICE);
|
||||
assertEquals(0xe0, LibUsb.CLASS_WIRELESS);
|
||||
assertEquals(0xfe, LibUsb.CLASS_APPLICATION);
|
||||
assertEquals(0xff, LibUsb.CLASS_VENDOR_SPEC);
|
||||
assertEquals(0x0B, LibUsb.CLASS_SMART_CARD);
|
||||
assertEquals(0x0D, LibUsb.CLASS_CONTENT_SECURITY);
|
||||
assertEquals(0x0E, LibUsb.CLASS_VIDEO);
|
||||
assertEquals(0x0F, LibUsb.CLASS_PERSONAL_HEALTHCARE);
|
||||
assertEquals((byte) 0xDC, LibUsb.CLASS_DIAGNOSTIC_DEVICE);
|
||||
assertEquals((byte) 0xE0, LibUsb.CLASS_WIRELESS);
|
||||
assertEquals((byte) 0xFE, LibUsb.CLASS_APPLICATION);
|
||||
assertEquals((byte) 0xFF, LibUsb.CLASS_VENDOR_SPEC);
|
||||
|
||||
// Descriptor types
|
||||
assertEquals(0x01, LibUsb.DT_DEVICE);
|
||||
@ -127,10 +127,10 @@ public class LibUSBTest
|
||||
assertEquals(0x22, LibUsb.DT_REPORT);
|
||||
assertEquals(0x23, LibUsb.DT_PHYSICAL);
|
||||
assertEquals(0x29, LibUsb.DT_HUB);
|
||||
assertEquals(0x2a, LibUsb.DT_SUPERSPEED_HUB);
|
||||
assertEquals(0x2A, LibUsb.DT_SUPERSPEED_HUB);
|
||||
|
||||
// Endpoint direction
|
||||
assertEquals(0x80, LibUsb.ENDPOINT_IN);
|
||||
assertEquals((byte) 0x80, LibUsb.ENDPOINT_IN);
|
||||
assertEquals(0x00, LibUsb.ENDPOINT_OUT);
|
||||
|
||||
// Transfer types
|
||||
@ -346,25 +346,25 @@ public class LibUSBTest
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link LibUsb#getMaxPacketSize(Device, int)} method with
|
||||
* Tests the {@link LibUsb#getMaxPacketSize(Device, byte)} method with
|
||||
* uninitialized device.
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testMaxPacketSizeWithUninitializedDevice()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getMaxPacketSize(new Device(), 0);
|
||||
LibUsb.getMaxPacketSize(new Device(), (byte) 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link LibUsb#getMaxIsoPacketSize(Device, int)} method with
|
||||
* Tests the {@link LibUsb#getMaxIsoPacketSize(Device, byte)} method with
|
||||
* uninitialized device.
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testMaxIsoPacketSizeWithUninitializedDevice()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getMaxIsoPacketSize(new Device(), 0);
|
||||
LibUsb.getMaxIsoPacketSize(new Device(), (byte) 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -478,14 +478,14 @@ public class LibUSBTest
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link LibUsb#clearHalt(DeviceHandle, int)} method with
|
||||
* Tests the {@link LibUsb#clearHalt(DeviceHandle, byte)} method with
|
||||
* uninitialized device handle.
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testClearHaltWithUninitializedHandle()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.clearHalt(new DeviceHandle(), 0);
|
||||
LibUsb.clearHalt(new DeviceHandle(), (byte) 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -545,14 +545,14 @@ public class LibUSBTest
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#getStringDescriptorAscii(DeviceHandle, int, StringBuffer, int)}
|
||||
* {@link LibUsb#getStringDescriptorAscii(DeviceHandle, byte, StringBuffer)}
|
||||
* method with uninitialized device handle.
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testGetStringDescriptorAsciiWithUninitializedHandle()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getStringDescriptorAscii(new DeviceHandle(), 0,
|
||||
LibUsb.getStringDescriptorAscii(new DeviceHandle(), (byte) 0,
|
||||
new StringBuffer());
|
||||
}
|
||||
|
||||
@ -570,26 +570,26 @@ public class LibUSBTest
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#getConfigDescriptor(Device, int, ConfigDescriptor)} method
|
||||
* {@link LibUsb#getConfigDescriptor(Device, byte, ConfigDescriptor)} method
|
||||
* with uninitialized device.
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testGetConfigDescriptorWithUninitializedDevice()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getConfigDescriptor(new Device(), 0, new ConfigDescriptor());
|
||||
LibUsb.getConfigDescriptor(new Device(), (byte) 0, new ConfigDescriptor());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#getConfigDescriptorByValue(Device, int, ConfigDescriptor)}
|
||||
* {@link LibUsb#getConfigDescriptorByValue(Device, byte, ConfigDescriptor)}
|
||||
* method with uninitialized device.
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testGetConfigDescriptorByValueWithUninitializedDevice()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getConfigDescriptorByValue(new Device(), 0,
|
||||
LibUsb.getConfigDescriptorByValue(new Device(), (byte) 0,
|
||||
new ConfigDescriptor());
|
||||
}
|
||||
|
||||
@ -606,66 +606,66 @@ public class LibUSBTest
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#getDescriptor(DeviceHandle, int, int, ByteBuffer)} method
|
||||
* {@link LibUsb#getDescriptor(DeviceHandle, byte, byte, ByteBuffer)} method
|
||||
* with uninitialized device handle.
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testGetDescriptorWithUninitializedHandle()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getDescriptor(new DeviceHandle(), 0, 0,
|
||||
LibUsb.getDescriptor(new DeviceHandle(), (byte) 0, (byte) 0,
|
||||
ByteBuffer.allocateDirect(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#getStringDescriptor(DeviceHandle, int, int, ByteBuffer)}
|
||||
* {@link LibUsb#getStringDescriptor(DeviceHandle, byte, short, ByteBuffer)}
|
||||
* method with uninitialized device handle.
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testGetStringDescriptorWithUninitializedHandle()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.getStringDescriptor(new DeviceHandle(), 0, 0,
|
||||
LibUsb.getStringDescriptor(new DeviceHandle(), (byte) 0, (short) 0,
|
||||
ByteBuffer.allocateDirect(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#controlTransfer(DeviceHandle, int, int, int, int, ByteBuffer, int)}
|
||||
* {@link LibUsb#controlTransfer(DeviceHandle, byte, byte, short, short, ByteBuffer, long)}
|
||||
* method with uninitialized device handle.
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testControlTransferWithUninitializedHandle()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.controlTransfer(new DeviceHandle(), 0, 0, 0, 0,
|
||||
LibUsb.controlTransfer(new DeviceHandle(), (byte) 0, (byte) 0, (short) 0, (short) 0,
|
||||
ByteBuffer.allocateDirect(1), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#bulkTransfer(DeviceHandle, int, ByteBuffer, IntBuffer, int)}
|
||||
* {@link LibUsb#bulkTransfer(DeviceHandle, byte, ByteBuffer, IntBuffer, long)}
|
||||
* method with uninitialized device handle.
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testBulkTransferWithUninitializedHandle()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.bulkTransfer(new DeviceHandle(), 0,
|
||||
LibUsb.bulkTransfer(new DeviceHandle(), (byte) 0,
|
||||
ByteBuffer.allocateDirect(1), IntBuffer.allocate(1), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link LibUsb#interruptTransfer(DeviceHandle, int, ByteBuffer, IntBuffer, int)}
|
||||
* {@link LibUsb#interruptTransfer(DeviceHandle, byte, ByteBuffer, IntBuffer, long)}
|
||||
* method with uninitialized device handle.
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testInterruptTransferWithUninitializedHandle()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
LibUsb.interruptTransfer(new DeviceHandle(), 0,
|
||||
LibUsb.interruptTransfer(new DeviceHandle(), (byte) 0,
|
||||
ByteBuffer.allocateDirect(1), IntBuffer.allocate(1), 0);
|
||||
}
|
||||
|
||||
@ -681,7 +681,7 @@ public class LibUSBTest
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link LibUsb#openDeviceWithVidPid(Context, int, int)} with
|
||||
* Tests {@link LibUsb#openDeviceWithVidPid(Context, short, short)} with
|
||||
* uninitialized USB context.
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@ -689,7 +689,7 @@ public class LibUSBTest
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
final Context context = new Context();
|
||||
LibUsb.openDeviceWithVidPid(context, 0, 0);
|
||||
LibUsb.openDeviceWithVidPid(context, (short) 0, (short) 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -26,12 +26,12 @@ import de.ailis.usb4java.libusb.LibUsb;
|
||||
public class DescriptorUtilsTest
|
||||
{
|
||||
/**
|
||||
* Tests the {@link DescriptorUtils#decodeBCD(int)} method.
|
||||
* Tests the {@link DescriptorUtils#decodeBCD(short)} method.
|
||||
*/
|
||||
@Test
|
||||
public void testDecodeBCD()
|
||||
{
|
||||
assertEquals("10.20", DescriptorUtils.decodeBCD(0x1020));
|
||||
assertEquals("10.20", DescriptorUtils.decodeBCD((short) 0x1020));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -49,52 +49,52 @@ public class DescriptorUtilsTest
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link DescriptorUtils#getSynchTypeName(int)} method.
|
||||
* Tests the {@link DescriptorUtils#getSynchTypeName(byte)} method.
|
||||
*/
|
||||
@Test
|
||||
public void testGetSynchTypeName()
|
||||
{
|
||||
assertEquals("None", DescriptorUtils.getSynchTypeName(0));
|
||||
assertEquals("Asynchronous", DescriptorUtils.getSynchTypeName(4));
|
||||
assertEquals("Adaptive", DescriptorUtils.getSynchTypeName(8));
|
||||
assertEquals("Synchronous", DescriptorUtils.getSynchTypeName(12));
|
||||
assertEquals("None", DescriptorUtils.getSynchTypeName((byte) 0));
|
||||
assertEquals("Asynchronous", DescriptorUtils.getSynchTypeName((byte) 4));
|
||||
assertEquals("Adaptive", DescriptorUtils.getSynchTypeName((byte) 8));
|
||||
assertEquals("Synchronous", DescriptorUtils.getSynchTypeName((byte) 12));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link DescriptorUtils#getUsageTypeName(int)} method.
|
||||
* Tests the {@link DescriptorUtils#getUsageTypeName(byte)} method.
|
||||
*/
|
||||
@Test
|
||||
public void testGetUsageTypeName()
|
||||
{
|
||||
assertEquals("Data", DescriptorUtils.getUsageTypeName(0));
|
||||
assertEquals("Feedback", DescriptorUtils.getUsageTypeName(16));
|
||||
assertEquals("Data", DescriptorUtils.getUsageTypeName((byte) 0));
|
||||
assertEquals("Feedback", DescriptorUtils.getUsageTypeName((byte) 16));
|
||||
assertEquals("Implicit Feedback Data",
|
||||
DescriptorUtils.getUsageTypeName(32));
|
||||
assertEquals("Reserved", DescriptorUtils.getUsageTypeName(48));
|
||||
DescriptorUtils.getUsageTypeName((byte) 32));
|
||||
assertEquals("Reserved", DescriptorUtils.getUsageTypeName((byte) 48));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests the {@link DescriptorUtils#getTransferTypeName(int)} method.
|
||||
* Tests the {@link DescriptorUtils#getTransferTypeName(byte)} method.
|
||||
*/
|
||||
@Test
|
||||
public void testGetTransferTypeName()
|
||||
{
|
||||
assertEquals("Control", DescriptorUtils.getTransferTypeName(0));
|
||||
assertEquals("Isochronous", DescriptorUtils.getTransferTypeName(1));
|
||||
assertEquals("Bulk", DescriptorUtils.getTransferTypeName(2));
|
||||
assertEquals("Interrupt", DescriptorUtils.getTransferTypeName(3));
|
||||
assertEquals("Control", DescriptorUtils.getTransferTypeName((byte) 0));
|
||||
assertEquals("Isochronous", DescriptorUtils.getTransferTypeName((byte) 1));
|
||||
assertEquals("Bulk", DescriptorUtils.getTransferTypeName((byte) 2));
|
||||
assertEquals("Interrupt", DescriptorUtils.getTransferTypeName((byte) 3));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link DescriptorUtils#getUSBClassName(int)} method.
|
||||
* Tests the {@link DescriptorUtils#getUSBClassName(byte)} method.
|
||||
*/
|
||||
@Test
|
||||
public void testGetUSBClassName()
|
||||
{
|
||||
assertEquals("Audio",
|
||||
DescriptorUtils.getUSBClassName(LibUsb.CLASS_AUDIO));
|
||||
assertEquals("Unknown", DescriptorUtils.getUSBClassName(0x1234));
|
||||
assertEquals("Unknown", DescriptorUtils.getUSBClassName((byte) 0xF3));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user