- use a properties file to select the test device
git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@194 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
@@ -1,6 +1,11 @@
|
|||||||
package ch.ntb.usb;
|
package ch.ntb.usb;
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
@@ -11,6 +16,10 @@ import ch.ntb.usb.AbstractDeviceInfo.WriteMode;
|
|||||||
|
|
||||||
public class DeviceTest {
|
public class DeviceTest {
|
||||||
|
|
||||||
|
private static final String testdevicePropertiesFile = "testdevice.properties";
|
||||||
|
|
||||||
|
private static final String deviceInfoKey = "testdeviceInfo";
|
||||||
|
|
||||||
private static AbstractDeviceInfo devinfo;
|
private static AbstractDeviceInfo devinfo;
|
||||||
|
|
||||||
private static byte[] testData;
|
private static byte[] testData;
|
||||||
@@ -21,8 +30,19 @@ public class DeviceTest {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
// select the device
|
// load the device info class with the key
|
||||||
devinfo = new AT90USB1287();
|
// from 'testdevice.properties'
|
||||||
|
InputStream propInputStream = new FileInputStream(
|
||||||
|
testdevicePropertiesFile);
|
||||||
|
Properties devInfoProp = new Properties();
|
||||||
|
devInfoProp.load(propInputStream);
|
||||||
|
String devInfoClazzName = devInfoProp.getProperty(deviceInfoKey);
|
||||||
|
if (devInfoClazzName == null) {
|
||||||
|
throw new IllegalArgumentException("property " + deviceInfoKey
|
||||||
|
+ "not found in file " + testdevicePropertiesFile);
|
||||||
|
}
|
||||||
|
Class devInfoClazz = Class.forName(devInfoClazzName);
|
||||||
|
devinfo = (AbstractDeviceInfo) devInfoClazz.newInstance();
|
||||||
// devinfo = new CY7C68013A();
|
// devinfo = new CY7C68013A();
|
||||||
// setup test data
|
// setup test data
|
||||||
testData = new byte[devinfo.getMaxDataSize()];
|
testData = new byte[devinfo.getMaxDataSize()];
|
||||||
@@ -169,7 +189,7 @@ public class DeviceTest {
|
|||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void tearDown() throws Exception {
|
public static void tearDown() throws Exception {
|
||||||
if (dev.isOpen()) {
|
if (dev != null && dev.isOpen()) {
|
||||||
dev.close();
|
dev.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
9
java/testdevice.properties
Normal file
9
java/testdevice.properties
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
################################################################
|
||||||
|
# define the usb test class for test/ch.ntb.usb.DeviceTest here
|
||||||
|
# it must implement ch.ntb.usb.AbstractDeviceInfo
|
||||||
|
################################################################
|
||||||
|
|
||||||
|
# Atmel AVR AT90USB1287
|
||||||
|
testdeviceInfo=ch.ntb.usb.AT90USB1287
|
||||||
|
# Cypress FX2 CY7C68013A
|
||||||
|
# testdeviceInfo=ch.ntb.usb.CY7C68013A
|
||||||
Reference in New Issue
Block a user