Non-JUnit tests for detecting when the other end hangs up.

This commit is contained in:
akwizgran
2012-12-07 16:10:58 +00:00
parent a6777f1fe1
commit ef8841e712
4 changed files with 86 additions and 1 deletions

View File

@@ -13,5 +13,6 @@
<classpathentry kind="lib" path="/briar-core/libs/commons-io-2.0.1.jar"/>
<classpathentry kind="lib" path="/briar-core/libs/jnotify-0.93.jar"/>
<classpathentry kind="lib" path="/briar-core/libs/scprov-jdk15on-1.47.0.3-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="/briar-core/libs/jssc-0.9-briar.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -0,0 +1,42 @@
package net.sf.briar.plugins.modem;
import static java.util.logging.Level.INFO;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Logger;
public class HangupClientTest {
public static void main(String[] args) throws Exception {
if(args.length != 2) {
System.err.println("Please specify the server's phone number "
+ " and the serial port");
System.exit(1);
}
String number = args[0];
String portName = args[1];
Logger.getLogger("net.sf.briar").setLevel(INFO);
ExecutorService executor = Executors.newCachedThreadPool();
Modem.Callback callback = new Modem.Callback() {
public void incomingCallConnected() {
System.err.println("Unexpected incoming call");
System.exit(1);
}
};
try {
Modem modem = new ModemImpl(executor, callback, portName);
modem.start();
System.out.println("Dialling");
if(modem.dial(number)) {
System.out.println("Connected");
Thread.sleep(10 * 1000);
} else {
System.out.println("Did not connect");
}
modem.stop();
} finally {
executor.shutdown();
}
}
}

View File

@@ -0,0 +1,43 @@
package net.sf.briar.plugins.modem;
import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.logging.Level.INFO;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Logger;
public class HangupServerTest {
public static void main(String[] args) throws Exception {
if(args.length != 1) {
System.err.println("Please specify the serial port");
System.exit(1);
}
String portName = args[0];
Logger.getLogger("net.sf.briar").setLevel(INFO);
ExecutorService executor = Executors.newCachedThreadPool();
final CountDownLatch latch = new CountDownLatch(1);
Modem.Callback callback = new Modem.Callback() {
public void incomingCallConnected() {
System.out.println("Connected");
latch.countDown();
}
};
try {
final Modem modem = new ModemImpl(executor, callback, portName);
modem.start();
System.out.println("Waiting for incoming call");
if(latch.await(60, SECONDS)) {
System.out.println("Hanging up");
modem.hangUp();
} else {
System.out.println("Did not connect");
}
modem.stop();
} finally {
executor.shutdown();
}
}
}

View File

@@ -44,5 +44,4 @@ public class ModemClientTest extends DuplexClientTest {
executor.shutdown();
}
}
}