diff --git a/java/.classpath b/java/.classpath index 91624f7..70b82ed 100644 --- a/java/.classpath +++ b/java/.classpath @@ -1,7 +1,15 @@ - - + + + + + + + + + + diff --git a/java/src/ch/ntb/inf/libusbJava/LibusbJava.java b/java/src/ch/ntb/inf/libusbJava/LibusbJava.java index e86cfcd..ea8ed17 100644 --- a/java/src/ch/ntb/inf/libusbJava/LibusbJava.java +++ b/java/src/ch/ntb/inf/libusbJava/LibusbJava.java @@ -15,11 +15,12 @@ package ch.ntb.inf.libusbJava; import ch.ntb.inf.libusbJava.exceptions.LibusbError; /** - * This class is used as compatibility layer for libusb 0.1 projects. For new - * projects use {@link LibusbJava1} + * This class is used as compatibility layer for libusb 0.1 projects. * + * @deprecated This class will not be subject to test anymore. Be aware that possible + * modifications could always break the functionality. For new + * projects only use {@link LibusbJava1}. */ -@Deprecated public class LibusbJava { private static Usb_Bus busses = null; diff --git a/java/src/ch/ntb/inf/libusbJava/LibusbJava1.java b/java/src/ch/ntb/inf/libusbJava/LibusbJava1.java index d4e9de3..1346d05 100644 --- a/java/src/ch/ntb/inf/libusbJava/LibusbJava1.java +++ b/java/src/ch/ntb/inf/libusbJava/LibusbJava1.java @@ -73,8 +73,8 @@ public class LibusbJava1 { * This function must be called before calling any other libusb function.
*
* - * @return a context to operate on
- * or a LIBUSB_ERROR code on failure + * @return a context to operate on + * @throws LibusbError if an error occured */ public static native long libusb_init() throws LibusbError; @@ -86,7 +86,8 @@ public class LibusbJava1 { *
* * @param ctx - * the context to deinitialize, or NULL for the default context + * the context to deinitialize, or 0 if the default context has + * been used. */ public static native void libusb_exit(long ctx); @@ -102,7 +103,7 @@ public class LibusbJava1 { * @return Usb_Devices currently attached to the system
* if no device is attached the devnum of the returned device is set * to -1
- * or NULL if a failure occurs + * or NULL if an error occurs */ public static native Usb_Device libusb_get_device_list(long ctx); @@ -355,12 +356,14 @@ public class LibusbJava1 { * a device handle * @param interface_number * the bInterfaceNumber of the interface you wish to claim - * @throws LibusbError in case of an error
- * Possible causes for errors are:
- * - ERROR_NOT_FOUND if the interface was not claimed
- * - ERROR_NO_DEVICE if the device has been disconnected
- * - ERROR_BUSY if another program or driver has claimed the interface
- * - another LIBUSB_ERROR code on other failure
+ * @throws LibusbError + * in case of an error
+ * Possible causes for errors are:
+ * - ERROR_NOT_FOUND if the interface was not claimed
+ * - ERROR_NO_DEVICE if the device has been disconnected
+ * - ERROR_BUSY if another program or driver has claimed the + * interface
+ * - another LIBUSB_ERROR code on other failure
*/ public static native void libusb_claim_interface(long dev_handle, int interface_number) throws LibusbError; @@ -379,11 +382,12 @@ public class LibusbJava1 { * a device handle * @param interface_number * the bInterfaceNumber of the previously-claimed interface - * @throws LibusbError in case of an error
- * Possible causes for errors are:
- * - ERROR_NOT_FOUND if the interface was not claimed
- * - ERROR_NO_DEVICE if the device has been disconnected
- * - another ERROR code on other failure
+ * @throws LibusbError + * in case of an error
+ * Possible causes for errors are:
+ * - ERROR_NOT_FOUND if the interface was not claimed
+ * - ERROR_NO_DEVICE if the device has been disconnected
+ * - another ERROR code on other failure
*/ public static native void libusb_release_interface(long dev_handle, int interface_number) throws LibusbError; @@ -407,11 +411,13 @@ public class LibusbJava1 { * the bInterfaceNumber of the previously-claimed interface * @param alternate_setting * the bAlternateSetting of the alternate setting to activate - * @throws LibusbError in case of an error
- * Possible causes for errors are:
- * - ERROR_NOT_FOUND if the interface was not claimed, or the requested alternate setting does not exist
- * - ERROR_NO_DEVICE if the device has been disconnected
- * - another LIBUSB_ERROR code on other failure
+ * @throws LibusbError + * in case of an error
+ * Possible causes for errors are:
+ * - ERROR_NOT_FOUND if the interface was not claimed, or the + * requested alternate setting does not exist
+ * - ERROR_NO_DEVICE if the device has been disconnected
+ * - another LIBUSB_ERROR code on other failure
*/ public static native void libusb_set_interface_alt_setting(long dev_handle, int interface_number, int alternate_setting) throws LibusbError; @@ -432,13 +438,15 @@ public class LibusbJava1 { * a device handle * @param endpoint * the endpoint to clear halt status - * @throws LibusbError in case of an error
- * Possible causes for errors are:
- * - ERROR_NOT_FOUND if the endpoint does not exist
- * - ERROR_NO_DEVICE if the device has been disconnected
- * - another LIBUSB_ERROR code on other failure
+ * @throws LibusbError + * in case of an error
+ * Possible causes for errors are:
+ * - ERROR_NOT_FOUND if the endpoint does not exist
+ * - ERROR_NO_DEVICE if the device has been disconnected
+ * - another LIBUSB_ERROR code on other failure
*/ - public static native void libusb_clear_halt(long dev_handle, short endpoint) throws LibusbError; + public static native void libusb_clear_halt(long dev_handle, short endpoint) + throws LibusbError; /** * Perform a USB port reset to reinitialize a device.
@@ -457,12 +465,15 @@ public class LibusbJava1 { * * @param dev_handle * a handle of the device to reset - * @throws LibusbError in case of an error
- * Possible causes for errors are:
- * - ERROR_NOT_FOUND if re-enumeration is required, or if the device has been disconnected
- * - another LIBUSB_ERROR code on other failure
+ * @throws LibusbError + * in case of an error
+ * Possible causes for errors are:
+ * - ERROR_NOT_FOUND if re-enumeration is required, or if the + * device has been disconnected
+ * - another LIBUSB_ERROR code on other failure
*/ - public static native void libusb_reset_device(long dev_handle) throws LibusbError; + public static native void libusb_reset_device(long dev_handle) + throws LibusbError; /** * Determine if a kernel driver is active on an interface.
@@ -477,14 +488,15 @@ public class LibusbJava1 { * the interface to check * @return 0 if no kernel driver is active
* 1 if a kernel driver is active
- * @throws LibusbError in case of an error
- * Possible causes for errors are:
- * - ERROR_NO_DEVICE if the device has been disconnected
- * - another LIBUSB_ERROR code on other failure
+ * @throws LibusbError + * in case of an error
+ * Possible causes for errors are:
+ * - ERROR_NO_DEVICE if the device has been disconnected
+ * - another LIBUSB_ERROR code on other failure
* @see #libusb_detach_kernel_driver(long, int) */ public static native int libusb_kernel_driver_active(long dev_handle, - int interface_number)throws LibusbError; + int interface_number) throws LibusbError; /** * Detach a kernel driver from an interface.
@@ -497,12 +509,13 @@ public class LibusbJava1 { * a device handle * @param interface_number * the interface to detach the driver from - * @throws LibusbError in case of an error
- * Possible causes for errors are:
- * - ERROR_NOT_FOUND if no kernel driver was active
- * - ERROR_INVALID_PARAM if the interface does not exist
- * - ERROR_NO_DEVICE if the device has been disconnected
- * - another ERROR code on other failure
+ * @throws LibusbError + * in case of an error
+ * Possible causes for errors are:
+ * - ERROR_NOT_FOUND if no kernel driver was active
+ * - ERROR_INVALID_PARAM if the interface does not exist
+ * - ERROR_NO_DEVICE if the device has been disconnected
+ * - another ERROR code on other failure
* @see #libusb_kernel_driver_active(long, int) */ public static native void libusb_detach_kernel_driver(long dev_handle, @@ -516,13 +529,15 @@ public class LibusbJava1 { * a device handle * @param interface_number * the interface to attach the driver from - * @throws LibusbError in case of an error
- * Possible causes for errors are:
- * - ERROR_NOT_FOUND if no kernel driver was active
- * - ERROR_INVALID_PARAM if the interface does not exist
- * - ERROR_NO_DEVICE if the device has been disconnected
- * - ERROR_BUSY if the driver cannot be attached because the interface is claimed by a program or driver
- * - another ERROR code on other failure
+ * @throws LibusbError + * in case of an error
+ * Possible causes for errors are:
+ * - ERROR_NOT_FOUND if no kernel driver was active
+ * - ERROR_INVALID_PARAM if the interface does not exist
+ * - ERROR_NO_DEVICE if the device has been disconnected
+ * - ERROR_BUSY if the driver cannot be attached because the + * interface is claimed by a program or driver
+ * - another ERROR code on other failure
* @see #libusb_kernel_driver_active(long, int) */ public static native void libusb_attach_kernel_driver(long dev_handle, @@ -558,7 +573,8 @@ public class LibusbJava1 { * number of charactes which will be retrieved (the length of the * resulting String) * @return a string which contains the string descriptor - * @throws LibusbError in case of an error
+ * @throws LibusbError + * in case of an error
*/ public static native String libusb_get_string_descriptor_ascii( long dev_handle, short desc_index, int size) throws LibusbError; @@ -579,7 +595,8 @@ public class LibusbJava1 { * number of bytes which will be retrieved (the length of the * resulting byte[]) * @return a byte[] which contains the descriptor or null on failure - * @throws LibusbError in case of an error
+ * @throws LibusbError + * in case of an error
* */ public static native byte[] libusb_get_descriptor(long dev_handle, @@ -602,7 +619,8 @@ public class LibusbJava1 { * number of charactes which will be retrieved (the length of the * resulting String) * @return a string which contains the string descriptor - * @throws LibusbError in case of an error
+ * @throws LibusbError + * in case of an error
* @see #libusb_get_string_descriptor_ascii(long, short, int) */ public static native String libusb_get_string_descriptor(long dev_handle, @@ -661,13 +679,15 @@ public class LibusbJava1 { * * @param transfernumber * the transfer to submit - * @throws LibusbError in case of an error
- * Possible causes for errors are:
- * - ERROR_NO_DEVICE if the device has been disconnected
- * - ERROR_BUSY if the transfer has already been submitted.
- * - another LIBUSB_ERROR code on other failure
+ * @throws LibusbError + * in case of an error
+ * Possible causes for errors are:
+ * - ERROR_NO_DEVICE if the device has been disconnected
+ * - ERROR_BUSY if the transfer has already been submitted.
+ * - another LIBUSB_ERROR code on other failure
*/ - public static native void libusb_submit_transfer(long transfernumber) throws LibusbError; + public static native void libusb_submit_transfer(long transfernumber) + throws LibusbError; /** * Asynchronously cancel a previously submitted transfer.
@@ -678,12 +698,15 @@ public class LibusbJava1 { * * @param transfernumber * a transfer - * @throws LibusbError in case of an error
- * Possible causes for errors are:
- * - ERROR_NOT_FOUND if the transfer is already complete or cancelled.
- * - a LIBUSB_ERROR code on failure
+ * @throws LibusbError + * in case of an error
+ * Possible causes for errors are:
+ * - ERROR_NOT_FOUND if the transfer is already complete or + * cancelled.
+ * - a LIBUSB_ERROR code on failure
*/ - public static native void libusb_cancel_transfer(long transfernumber) throws LibusbError; + public static native void libusb_cancel_transfer(long transfernumber) + throws LibusbError; /** * Get the data section of a control transfer.
@@ -697,7 +720,8 @@ public class LibusbJava1 { * * @param transfernumber * a transfer - * @return the data section from the transfer, null if the transfer number was invalid. + * @return the data section from the transfer, null if the transfer number + * was invalid. */ public static native byte[] libusb_control_transfer_get_data( long transfernumber); @@ -714,7 +738,8 @@ public class LibusbJava1 { * * @param transfernumber * a transfer - * @return the setup packet from the transfer, null if the transfer number was invalid. + * @return the setup packet from the transfer, null if the transfer number + * was invalid. */ public static native byte[] libusb_control_transfer_get_setup( long transfernumber); @@ -1066,9 +1091,11 @@ public class LibusbJava1 { * @param timeval * the maximum time to block waiting for events, or zero for * non-blocking mode - * @throws LibusbError in case of an error
+ * @throws LibusbError + * in case of an error
*/ - public static native void libusb_handle_events_timeout(long ctx, long timeval) throws LibusbError; + public static native void libusb_handle_events_timeout(long ctx, + long timeval) throws LibusbError; /** * Handle any pending events in blocking mode with a sensible timeout.
@@ -1080,7 +1107,8 @@ public class LibusbJava1 { * * @param ctx * the context to operate on, or NULL for the default context - * @throws LibusbError in case of an error
+ * @throws LibusbError + * in case of an error
*/ public static native void libusb_handle_events(long ctx) throws LibusbError; @@ -1103,9 +1131,11 @@ public class LibusbJava1 { * @param timeval * the maximum time in seconds to block waiting for events, or * zero for non-blocking mode - * @throws LibusbError in case of an error
+ * @throws LibusbError + * in case of an error
*/ - public static native void libusb_handle_events_locked(long ctx, long timeval) throws LibusbError; + public static native void libusb_handle_events_locked(long ctx, long timeval) + throws LibusbError; /** * Determines whether your application must apply special timing diff --git a/java/test/ch/ntb/inf/libusbJava/test/LibusbJava1Test.java b/java/test/ch/ntb/inf/libusbJava/test/LibusbJava1Test.java new file mode 100644 index 0000000..9934b47 --- /dev/null +++ b/java/test/ch/ntb/inf/libusbJava/test/LibusbJava1Test.java @@ -0,0 +1,354 @@ +package ch.ntb.inf.libusbJava.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.Test; + +import ch.ntb.inf.libusbJava.LibusbJava1; +import ch.ntb.inf.libusbJava.Usb_Device; +import ch.ntb.inf.libusbJava.exceptions.LibusbError; + +public class LibusbJava1Test { + /** + * This method does not need to be tested. This test only exists to document + * the fact that this function has not been forgotten. + */ + @Test + public void testLibusb_set_debug() { + } + + /** + * This test is used to check if the library constructs and throws the + * correct exceptions if requested to do so. + */ + @Test + public void testLibusb_exceptionTest() { + /* + * We go through every currently possible error just to check a several + * different error codes. + */ + for (int i = -1; i > LibusbError.ERROR_OTHER; i--) { + boolean exception_occured = false; + + try { + LibusbJava1.libusb_exceptionTest(i); + } catch (LibusbError e) { + assertEquals("Exception code correct", e.getErrorCode(), i); + exception_occured = true; + } + + assertTrue("Exception occured", exception_occured); + } + } + + @Test + public void testLibusb_init() { + try { + long handle = LibusbJava1.libusb_init(); + LibusbJava1.libusb_exit(handle); + } catch (LibusbError e) { + fail("Initialization failed, Code: " + e.getErrorString()); + } + } + + /** + * This method can not be tested (yet). This test only exists to document + * the fact that this function has not been forgotten. + */ + @Test + public void testLibusb_exit() { + } + + @Test + public void testLibusb_get_device_list() throws LibusbError { + long handle = LibusbJava1.libusb_init(); + Usb_Device devices = LibusbJava1.libusb_get_device_list(handle); + assertNotNull("Got devices", devices); + System.out.println(devices.toString()); + LibusbJava1.libusb_exit(handle); + } + + @Test + public void testLibusb_get_bus_number() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_get_max_iso_packet_size() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_ref_device() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_unref_device() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_open() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_open_device_with_vid_pid() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_close() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_get_device() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_get_configuration() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_set_configuration() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_claim_interface() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_release_interface() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_set_interface_alt_setting() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_clear_halt() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_reset_device() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_kernel_driver_active() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_detach_kernel_driver() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_attach_kernel_driver() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_get_active_config_descriptor() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_get_string_descriptor_ascii() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_get_descriptor() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_get_string_descriptor() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_alloc_transfer() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_free_transfer() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_submit_transfer() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_cancel_transfer() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_control_transfer_get_data() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_control_transfer_get_setup() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_fill_control_setup() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_fill_control_transfer() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_fill_bulk_transfer() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_fill_interrupt_transfer() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_fill_iso_transfer() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_set_iso_packet_lengths() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_get_iso_packet_buffer() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_get_iso_packet_buffer_simple() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_try_lock_events() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_lock_events() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_unlock_events() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_event_handling_ok() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_event_handler_active() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_lock_event_waiters() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_unlock_event_waiters() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_wait_for_event() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_handle_events_timeout() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_handle_events() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_handle_events_locked() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_pollfds_handle_timeouts() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_get_next_timeout() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_set_pollfd_notifiers() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_get_pollfds() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_control_transfer() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_bulk_transfer() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_interrupt_transfer() { + fail("Not yet implemented"); + } + + @Test + public void testLibusb_strerror() { + fail("Not yet implemented"); + } + + @Test + public void testIsHandleValid() { + fail("Not yet implemented"); + } + +}