public class IHandleHashtableTest {
// private JavaFish jf = JavaFishSingleton.getInstance();
private IHandleHashtable iht;
private List<Integer> serials = Arrays.asList(
0x1, 0x3, 0x5, 0x7, 0x9, 0x11, 0x13, 0x15, 0x17, 0x19, 0x21, 0x23, 0x25, 0x27
);
@Before
public void before() {
for(int i = 0; i < 8; i++) {
System.out.println("closing interface " + i
+ " Status: " + Integer.toHexString(new JavaFish().jrCloseInterface(i))); //not risking that a JavaFish instance expires
}
iht = new IHandleHashtable();
}
//Please keep this test, as it shows an important Problem of JavaFish
// @Test
// public void jfTest() { //test if JavaFish is working correctly
// JavaFish jf = new JavaFish();
// int iHandle = JavaFish.jrError;
// iHandle = jf.jrOpenInterfaceUSB(60, 0x1);
// assertTrue(iHandle != JavaFish.jrError);
// jf.jrCloseInterface(iHandle);
//
// jf = new JavaFish();
// iHandle = jf.jrOpenInterfaceUSB(60, 0x1);
// assertTrue(iHandle != JavaFish.jrError);
// assertTrue(jf.jrOpenInterfaceUSB(60, 0x1) == JavaFish.jrError); //you can't open two interfaces for one serial
// assertTrue(jf.jrCloseInterface(iHandle) == JavaFish.jrError); //IMPORTANT: If you try to open a already open interface, you can't ever open that interface again
// }
@Test
public void multipleEqualRequestTest() throws InvalidIHandleException{
for(int i = 0; i < 10; i++) {
iht.get(0x1);
}
}
@Test
public void manyRequestTest() throws InvalidIHandleException {
for(int i : serials) {
iht.get(i);
}
}
@Test
public synchronized void timeoutTest() throws InvalidIHandleException, InterruptedException {
List<Integer> ihandles = new ArrayList<Integer>();
for(int i : serials) {
ihandles.add(iht.get(i));
}
wait(1000);
for(int i : serials) {
ihandles.add(iht.get(i));
}
}
@Test (expected=InvalidIHandleException.class)
public void invalidRequestTest() throws InvalidIHandleException {
iht.get(0x35);
}
}