Skip to content
Snippets Groups Projects
Commit 7aa836c6 authored by akwizgran's avatar akwizgran
Browse files

Skip tests that can't be run on the present machine.

parent a2f5f68f
No related branches found
No related tags found
No related merge requests found
package org.briarproject.plugins.file; package org.briarproject.plugins.file;
import static java.util.concurrent.TimeUnit.SECONDS; import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.Assume.assumeTrue;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
...@@ -23,12 +22,15 @@ public class UnixRemovableDriveMonitorTest extends BriarTestCase { ...@@ -23,12 +22,15 @@ public class UnixRemovableDriveMonitorTest extends BriarTestCase {
@Before @Before
public void setUp() { public void setUp() {
assumeTrue(OsUtils.isLinux() || OsUtils.isMacLeopardOrNewer());
testDir.mkdirs(); testDir.mkdirs();
} }
@Test @Test
public void testNonexistentDir() throws Exception { public void testNonexistentDir() throws Exception {
if(!(OsUtils.isLinux() || OsUtils.isMacLeopardOrNewer())) {
System.err.println("WARNING: Skipping test, can't run on this OS");
return;
}
File doesNotExist = new File(testDir, "doesNotExist"); File doesNotExist = new File(testDir, "doesNotExist");
RemovableDriveMonitor monitor = createMonitor(doesNotExist); RemovableDriveMonitor monitor = createMonitor(doesNotExist);
monitor.start(new Callback() { monitor.start(new Callback() {
...@@ -46,6 +48,10 @@ public class UnixRemovableDriveMonitorTest extends BriarTestCase { ...@@ -46,6 +48,10 @@ public class UnixRemovableDriveMonitorTest extends BriarTestCase {
@Test @Test
public void testOneCallbackPerFile() throws Exception { public void testOneCallbackPerFile() throws Exception {
if(!(OsUtils.isLinux() || OsUtils.isMacLeopardOrNewer())) {
System.err.println("WARNING: Skipping test, can't run on this OS");
return;
}
// Create a callback that will wait for two files before stopping // Create a callback that will wait for two files before stopping
final List<File> detected = new ArrayList<File>(); final List<File> detected = new ArrayList<File>();
final CountDownLatch latch = new CountDownLatch(2); final CountDownLatch latch = new CountDownLatch(2);
......
...@@ -6,8 +6,10 @@ import java.io.IOException; ...@@ -6,8 +6,10 @@ import java.io.IOException;
import java.net.Inet4Address; import java.net.Inet4Address;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.NetworkInterface;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.util.Collections;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
...@@ -73,6 +75,10 @@ public class LanTcpPluginTest extends BriarTestCase { ...@@ -73,6 +75,10 @@ public class LanTcpPluginTest extends BriarTestCase {
@Test @Test
public void testIncomingConnection() throws Exception { public void testIncomingConnection() throws Exception {
if(!systemHasLocalIpv4Address()) {
System.err.println("WARNING: Skipping test, no local IPv4 address");
return;
}
Callback callback = new Callback(); Callback callback = new Callback();
Executor executor = Executors.newCachedThreadPool(); Executor executor = Executors.newCachedThreadPool();
DuplexPlugin plugin = new LanTcpPlugin(executor, callback, 0, 0, 0); DuplexPlugin plugin = new LanTcpPlugin(executor, callback, 0, 0, 0);
...@@ -101,6 +107,10 @@ public class LanTcpPluginTest extends BriarTestCase { ...@@ -101,6 +107,10 @@ public class LanTcpPluginTest extends BriarTestCase {
@Test @Test
public void testOutgoingConnection() throws Exception { public void testOutgoingConnection() throws Exception {
if(!systemHasLocalIpv4Address()) {
System.err.println("WARNING: Skipping test, no local IPv4 address");
return;
}
Callback callback = new Callback(); Callback callback = new Callback();
Executor executor = Executors.newCachedThreadPool(); Executor executor = Executors.newCachedThreadPool();
DuplexPlugin plugin = new LanTcpPlugin(executor, callback, 0, 0, 0); DuplexPlugin plugin = new LanTcpPlugin(executor, callback, 0, 0, 0);
...@@ -143,6 +153,17 @@ public class LanTcpPluginTest extends BriarTestCase { ...@@ -143,6 +153,17 @@ public class LanTcpPluginTest extends BriarTestCase {
plugin.stop(); plugin.stop();
} }
private boolean systemHasLocalIpv4Address() throws Exception {
for(NetworkInterface i : Collections.list(
NetworkInterface.getNetworkInterfaces())) {
for(InetAddress a : Collections.list(i.getInetAddresses())) {
if(a instanceof Inet4Address)
return a.isLinkLocalAddress() || a.isSiteLocalAddress();
}
}
return false;
}
private static class Callback implements DuplexPluginCallback { private static class Callback implements DuplexPluginCallback {
private final Map<ContactId, TransportProperties> remote = private final Map<ContactId, TransportProperties> remote =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment