Add more unit tests for GetDeviceList

This commit is contained in:
Klaus Reimer 2018-10-09 00:14:26 +02:00
parent b24618df0f
commit b762fb3f01
1 changed files with 51 additions and 0 deletions

View File

@ -308,6 +308,47 @@ public class LibUsbTest
LibUsb.setOption(context, 0);
}
/**
* Tests {@link LibUsb#getDeviceList(Context, DeviceList)} method.
*/
@Test
public void testGetDeviceList()
{
assumeUsbTestsEnabled();
final Context context = new Context();
final DeviceList deviceList = new DeviceList();
LibUsb.init(context);
try
{
assertTrue(LibUsb.getDeviceList(context, deviceList) >= 0);
LibUsb.freeDeviceList(deviceList, true);
}
finally
{
LibUsb.exit(context);
}
}
/**
* Tests {@link LibUsb#getDeviceList(Context, DeviceList)} method with the default context.
*/
@Test
public void testGetDeviceListFromDefaultContext()
{
assumeUsbTestsEnabled();
final DeviceList deviceList = new DeviceList();
LibUsb.init(null);
try
{
assertTrue(LibUsb.getDeviceList(null, deviceList) >= 0);
LibUsb.freeDeviceList(deviceList, true);
}
finally
{
LibUsb.exit(null);
}
}
/**
* Tests {@link LibUsb#getDeviceList(Context, DeviceList)} method with uninitialized USB context.
*/
@ -319,6 +360,16 @@ public class LibUsbTest
LibUsb.getDeviceList(context, new DeviceList());
}
/**
* Tests {@link LibUsb#getDeviceList(Context, DeviceList)} method with uninitialized default USB context.
*/
@Test(expected = IllegalStateException.class)
public void testGetDeviceListWithUninitializedDefaultContext()
{
assumeUsbTestsEnabled();
LibUsb.getDeviceList(null, new DeviceList());
}
/**
* Tests {@link LibUsb#freeDeviceList(DeviceList, boolean)} method with
* uninitialized list.