- 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:
@@ -8,5 +8,4 @@
|
||||
</listAttribute>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="ch.ntb.inf.libusbJava.usbView.UsbView"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="ch.ntb.inf.libusbJava"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Djava.library.path="D:\inf-ma\libusbjava\libusbjava\LibusbJava\out;${env_var:PATH}""/>
|
||||
</launchConfiguration>
|
||||
|
||||
@@ -1387,13 +1387,29 @@ public class LibusbJava1 {
|
||||
|
||||
/**
|
||||
* This method is only used for testing the DLL-code that throws exceptions
|
||||
* in the java environment.
|
||||
* in the java environment.
|
||||
*
|
||||
* @param code
|
||||
* Code of the error to be simulated and hence the code of the
|
||||
* exception that shall be thrown.
|
||||
*
|
||||
* @throws LibusbError
|
||||
* @deprecated This function is only for testing purpose and should not be
|
||||
* called in production code
|
||||
*/
|
||||
@Deprecated
|
||||
public static native void libusb_exceptionTest(int code) throws LibusbError;
|
||||
|
||||
/**
|
||||
* This method is only used for testing the DLL helpercode. It creates a
|
||||
* byte Array of the given size from the given string.
|
||||
*
|
||||
* @param str String to be copied into the array
|
||||
* @param size Size of the array to be created
|
||||
*
|
||||
* @deprecated This function is only for testing purpose and should not be
|
||||
* called in production code
|
||||
*/
|
||||
@Deprecated
|
||||
public static native byte[] to_byteArrayTest(String str, int size);
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user