- Added unit-test functions to the DLL interface

- Marked the unit-test functions as deprecated to prevent developers from using them in productive code
- Added unit-tests for helper functions in the DLL
- Setup the classes using "LibusbJava" so they don't warn of using a deprecated class

git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@296 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
uniederer
2012-04-19 15:43:09 +00:00
parent da72b7b39b
commit 4b7e567c32
7 changed files with 67 additions and 7 deletions

View File

@@ -37,6 +37,7 @@ import ch.ntb.inf.libusbJava.Utils;
import ch.ntb.inf.libusbJava.testApp.AbstractDeviceInfo;
import ch.ntb.inf.libusbJava.testApp.AbstractDeviceInfo.TransferMode;
@SuppressWarnings("deprecation")
public class DeviceTest {
private static final String testdevicePropertiesFile = "testdevice.properties";

View File

@@ -2,6 +2,7 @@ package ch.ntb.inf.libusbJava.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -24,8 +25,9 @@ public class LibusbJava1Test {
* 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_exceptionTest() {
public void testLibusb_exception() {
/*
* We go through every currently possible error just to check a several
* different error codes.
@@ -43,6 +45,43 @@ public class LibusbJava1Test {
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
public void testLibusb_init() {
@@ -68,12 +107,17 @@ public class LibusbJava1Test {
Usb_Device devices = LibusbJava1.libusb_get_device_list(handle);
assertNotNull("Got devices", devices);
System.out.println(devices.toString());
assertNull("Bus is null", devices.getBus());
LibusbJava1.libusb_exit(handle);
}
@Test
public void testLibusb_get_bus_number() {
fail("Not yet implemented");
public void testLibusb_get_bus_number() throws LibusbError {
long handle = LibusbJava1.libusb_init();
Usb_Device devices = LibusbJava1.libusb_get_device_list(handle);
assertNotNull("Got devices", devices);
System.out.println(devices.getBus());
LibusbJava1.libusb_exit(handle);
}
@Test

View File

@@ -30,6 +30,7 @@ import ch.ntb.inf.libusbJava.Utils;
import ch.ntb.inf.libusbJava.testApp.AbstractDeviceInfo;
import ch.ntb.inf.libusbJava.testApp.AbstractDeviceInfo.TransferMode;
@SuppressWarnings("deprecation")
public class MemoryLeakTest {
private static final String testdevicePropertiesFile = "testdevice.properties";

View File

@@ -19,6 +19,7 @@ import ch.ntb.inf.libusbJava.Usb_Interface_Descriptor;
* This class replicates the code from testlibusb.c supplied in the
* libusb-0.1.12 release.
*/
@SuppressWarnings("deprecation")
public class TestLibUsbJava {
static boolean verbose;

View File

@@ -1,8 +1,6 @@
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;