From f4f7ee4c4a6e1217e003b66b90b6ef00d9a16c2b Mon Sep 17 00:00:00 2001 From: schlaepfer Date: Thu, 16 Nov 2006 07:12:49 +0000 Subject: [PATCH] - 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 --- java/test/ch/ntb/usb/DeviceTest.java | 26 +++++++++++++++++++++++--- java/testdevice.properties | 9 +++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 java/testdevice.properties diff --git a/java/test/ch/ntb/usb/DeviceTest.java b/java/test/ch/ntb/usb/DeviceTest.java index 663fb65..6afca45 100644 --- a/java/test/ch/ntb/usb/DeviceTest.java +++ b/java/test/ch/ntb/usb/DeviceTest.java @@ -1,6 +1,11 @@ package ch.ntb.usb; import static org.junit.Assert.fail; + +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.Properties; + import junit.framework.Assert; import org.junit.AfterClass; @@ -11,6 +16,10 @@ import ch.ntb.usb.AbstractDeviceInfo.WriteMode; public class DeviceTest { + private static final String testdevicePropertiesFile = "testdevice.properties"; + + private static final String deviceInfoKey = "testdeviceInfo"; + private static AbstractDeviceInfo devinfo; private static byte[] testData; @@ -21,8 +30,19 @@ public class DeviceTest { @BeforeClass public static void setUp() throws Exception { - // select the device - devinfo = new AT90USB1287(); + // load the device info class with the key + // 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(); // setup test data testData = new byte[devinfo.getMaxDataSize()]; @@ -169,7 +189,7 @@ public class DeviceTest { @AfterClass public static void tearDown() throws Exception { - if (dev.isOpen()) { + if (dev != null && dev.isOpen()) { dev.close(); } } diff --git a/java/testdevice.properties b/java/testdevice.properties new file mode 100644 index 0000000..55b86fe --- /dev/null +++ b/java/testdevice.properties @@ -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