- Removed library's JNI test
- Introduced code to explicitly unref devices - Corrected code formatting git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@309 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
@@ -299,7 +299,7 @@ public class LibusbJava {
|
|||||||
handle = LibusbJava1.libusb_open(dev);
|
handle = LibusbJava1.libusb_open(dev);
|
||||||
}
|
}
|
||||||
catch (LibusbError e) {
|
catch (LibusbError e) {
|
||||||
System.err.println("LibusbJava-1.0 init failed with errorcode: "
|
System.err.println("LibusbJava-1.0 failed with errorcode: "
|
||||||
+ e.getMessage());
|
+ e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
handle = 0;
|
handle = 0;
|
||||||
@@ -581,6 +581,7 @@ public class LibusbJava {
|
|||||||
try {
|
try {
|
||||||
result = LibusbJava1.libusb_get_descriptor(dev_handle, type, index, size);
|
result = LibusbJava1.libusb_get_descriptor(dev_handle, type, index, size);
|
||||||
} catch (LibusbError e) {
|
} catch (LibusbError e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -107,6 +107,36 @@ public class Usb_Device {
|
|||||||
next = dev;
|
next = dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void freeDeviceList(Usb_Device device)
|
||||||
|
{
|
||||||
|
Usb_Device curr = device.getPrev();
|
||||||
|
|
||||||
|
/* Detach the left part of the list */
|
||||||
|
device.setPrev(null);
|
||||||
|
|
||||||
|
/* First walk to the left of the list and free all
|
||||||
|
devices on our way */
|
||||||
|
while (curr != null)
|
||||||
|
{
|
||||||
|
freeDevice(curr);
|
||||||
|
curr = curr.getPrev();
|
||||||
|
}
|
||||||
|
|
||||||
|
curr = device;
|
||||||
|
/* Then walk to the right of the list and free all */
|
||||||
|
while (curr != null)
|
||||||
|
{
|
||||||
|
freeDevice(curr);
|
||||||
|
curr = curr.getNext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void freeDevice(Usb_Device device)
|
||||||
|
{
|
||||||
|
freeDeviceList(device.getChildren());
|
||||||
|
LibusbJava1.libusb_unref_device(device);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of children of this device.<br>
|
* Returns the number of children of this device.<br>
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ package ch.ntb.inf.libusbJava;
|
|||||||
* endpoints into a functional group performing a single feature of the device.<br>
|
* endpoints into a functional group performing a single feature of the device.<br>
|
||||||
* <br>
|
* <br>
|
||||||
* The length of the interface descriptor is
|
* The length of the interface descriptor is
|
||||||
* {@link ch.ntb.inf.libusbJava.Usb_Descriptor#USB_DT_INTERFACE_SIZE} and the type is
|
* {@link ch.ntb.inf.libusbJava.Usb_Descriptor#USB_DT_INTERFACE_SIZE} and the
|
||||||
* {@link ch.ntb.inf.libusbJava.Usb_Descriptor#USB_DT_INTERFACE}.
|
* type is {@link ch.ntb.inf.libusbJava.Usb_Descriptor#USB_DT_INTERFACE}.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Usb_Interface_Descriptor extends Usb_Descriptor {
|
public class Usb_Interface_Descriptor extends Usb_Descriptor {
|
||||||
@@ -51,7 +51,8 @@ public class Usb_Interface_Descriptor extends Usb_Descriptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value used to select the alternate setting ({@link LibusbJava#usb_set_altinterface(long, int)}).<br>
|
* Returns the value used to select the alternate setting (
|
||||||
|
* {@link LibusbJava#usb_set_altinterface(long, int)}).<br>
|
||||||
*
|
*
|
||||||
* @return the alternate setting
|
* @return the alternate setting
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -15,12 +15,14 @@ import ch.ntb.inf.libusbJava.Utils;
|
|||||||
* Initalises Libusb and prints the bus(ses) with attached devices to the
|
* Initalises Libusb and prints the bus(ses) with attached devices to the
|
||||||
* standard out.<br>
|
* standard out.<br>
|
||||||
*
|
*
|
||||||
*
|
* @deprecated This class will be removed with the legacy {@link LibusbJava}
|
||||||
|
* class
|
||||||
*/
|
*/
|
||||||
public class LogBus {
|
public class LogBus {
|
||||||
|
|
||||||
private static void logBus() {
|
private static void logBus() {
|
||||||
// if you don't use the ch.ntb.inf.libusbJava.Device class you must initialise
|
// if you don't use the ch.ntb.inf.libusbJava.Device class you must
|
||||||
|
// initialise
|
||||||
// Libusb before use
|
// Libusb before use
|
||||||
LibusbJava.usb_init();
|
LibusbJava.usb_init();
|
||||||
LibusbJava.usb_find_busses();
|
LibusbJava.usb_find_busses();
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package ch.ntb.inf.libusbJava.test;
|
package ch.ntb.inf.libusbJava.test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -21,68 +19,6 @@ public class LibusbJava1Test {
|
|||||||
public void testLibusb_set_debug() {
|
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.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Test
|
|
||||||
public void testLibusb_exception() {
|
|
||||||
/*
|
|
||||||
* 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests a helper function in the DLL that creates a byte array object from
|
|
||||||
* a piece of memory given.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Test
|
|
||||||
public void testLibusb_to_byteArrayWithContent() {
|
|
||||||
final String str = "SimpleTest";
|
|
||||||
final int testLen = 5;
|
|
||||||
final byte[] reference = str.substring(0, testLen).getBytes();
|
|
||||||
|
|
||||||
byte[] result = LibusbJava1.to_byteArrayTest(str, testLen);
|
|
||||||
|
|
||||||
assertNotNull("Got a byte array", result);
|
|
||||||
assertEquals("Byte array has correct length", testLen, result.length);
|
|
||||||
|
|
||||||
for (int i = 0;i < result.length;i++)
|
|
||||||
{
|
|
||||||
assertEquals("Array content is correct", reference[i], result[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests a helper function in the DLL that creates a byte array object from
|
|
||||||
* a piece of memory given.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Test
|
|
||||||
public void testLibusb_to_byteArrayLength0() {
|
|
||||||
final String str = "SimpleTest";
|
|
||||||
|
|
||||||
byte[] result = LibusbJava1.to_byteArrayTest(str, 0);
|
|
||||||
|
|
||||||
assertNotNull("Got a byte array", result);
|
|
||||||
assertEquals("Byte array has correct length", 0, result.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLibusb_init() {
|
public void testLibusb_init() {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user