mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Non-JUnit tests for detecting when the other end hangs up.
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,5 +44,4 @@ public class ModemClientTest extends DuplexClientTest {
|
||||
executor.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user