- Bugfix: LibusbJava.cpp, Ln 1288 removed the manipulation of the return value

- Bugfix: Guaranteeing '\0'-Termination of the retrieved C-Strings for all libusb_get_string_descriptor* calls
- Change: The whole interface makes now use of exceptions to pass errors into the java environment instead encoding them into return values.
- Change: Allowing Descriptor strings to have a length of 0

git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@292 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
uniederer
2012-04-12 14:40:09 +00:00
parent 0aae67e050
commit 667906d5d4
9 changed files with 826 additions and 303 deletions

View File

@@ -120,7 +120,7 @@ public class TestLibUsbJava {
udev = LibusbJava.usb_open(dev);
if (udev <= 0) {
if (udev != 0) {
if (dev.getDescriptor().getIManufacturer() != 0) {
mfr = LibusbJava.usb_get_string_simple(udev, dev
.getDescriptor().getIManufacturer());

View File

@@ -0,0 +1,75 @@
package ch.ntb.inf.libusbJava.test.exceptions;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import ch.ntb.inf.libusbJava.exceptions.LibusbError;
@RunWith(Parameterized.class)
public class LibusbErrorTest {
@Parameters
public static Collection<Object[]> codesToTest() {
return Arrays.asList(new Object[][] { {"ERROR_UNKNWON (0)", 0 },
{"ERROR_IO", -1 },
{"ERROR_INVALID_PARAM", -2},
{"ERROR_ACCESS", -3},
{"ERROR_NO_DEVICE", -4},
{"ERROR_NOT_FOUND", -5},
{"ERROR_BUSY", -6},
{"ERROR_TIMEOUT", -7},
{"ERROR_OVERFLOW", -8},
{"ERROR_PIPE", -9},
{"ERROR_INTERRUPTED", -10},
{"ERROR_NO_MEM", -11},
{"ERROR_NOT_SUPPORTED", -12},
{"ERROR_UNKNWON (-13)", -13},
{"ERROR_UNKNWON (-98)", -98},
{"ERROR_UNKNWON (-100)", -100},
{"ERROR_OTHER", -99} });
}
private String exp_desc;
private int code;
private LibusbError e;
public LibusbErrorTest(String exp_desc, int code) {
this.exp_desc = exp_desc;
this.code = code;
try {
throw new LibusbError(code);
} catch (LibusbError e) {
this.e = e;
}
}
@Test
public void testGetErrorCode() {
assertEquals("Error code is correct", e.getErrorCode(), code);
}
@Test
public void testGetStringFromCode() {
String gen_desc = LibusbError.getStringFromCode(code);
assertEquals("Correct error description for " + code, exp_desc, gen_desc);
}
@Test
public void testGetErrorString() {
assertEquals("Correct error string for " + code, e.getErrorString(), exp_desc);
}
@Test
public void testGetMessage() {
assertEquals("Correct error string for " + code, e.getMessage(), "libusb result: " + exp_desc);
}
}