mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 13:19:52 +01:00
Merge branch 'refs/heads/master' of ssh://akwizgran@briar.git.sourceforge.net/gitroot/briar/prototype
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
<test name='net.sf.briar.i18n.I18nTest'/>
|
||||
<test name='net.sf.briar.invitation.InvitationWorkerTest'/>
|
||||
<test name='net.sf.briar.lifecycle.ShutdownManagerImplTest'/>
|
||||
<test name='net.sf.briar.lifecycle.WindowsShutdownManagerImplTest'/>
|
||||
<test name='net.sf.briar.plugins.PluginManagerImplTest'/>
|
||||
<test name='net.sf.briar.plugins.file.LinuxRemovableDriveFinderTest'/>
|
||||
<test name='net.sf.briar.plugins.file.MacRemovableDriveFinderTest'/>
|
||||
|
||||
@@ -12,7 +12,7 @@ public class ShutdownManagerImplTest extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testAddAndRemove() {
|
||||
ShutdownManager s = new ShutdownManagerImpl();
|
||||
ShutdownManager s = createShutdownManager();
|
||||
Set<Integer> handles = new HashSet<Integer>();
|
||||
for(int i = 0; i < 100; i++) {
|
||||
int handle = s.addShutdownHook(new Runnable() {
|
||||
@@ -26,4 +26,8 @@ public class ShutdownManagerImplTest extends TestCase {
|
||||
// The hooks should no longer be removable
|
||||
for(int handle : handles) assertFalse(s.removeShutdownHook(handle));
|
||||
}
|
||||
|
||||
protected ShutdownManager createShutdownManager() {
|
||||
return new ShutdownManagerImpl();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package net.sf.briar.lifecycle;
|
||||
|
||||
import net.sf.briar.api.lifecycle.ShutdownManager;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class WindowsShutdownManagerImplTest extends ShutdownManagerImplTest {
|
||||
|
||||
@Override
|
||||
protected ShutdownManager createShutdownManager() {
|
||||
return new WindowsShutdownManagerImpl();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManagerWaitsForHooksToRun() {
|
||||
WindowsShutdownManagerImpl s = new WindowsShutdownManagerImpl();
|
||||
SlowHook[] hooks = new SlowHook[10];
|
||||
for(int i = 0; i < hooks.length; i++) {
|
||||
hooks[i] = new SlowHook();
|
||||
s.addShutdownHook(hooks[i]);
|
||||
}
|
||||
s.runShutdownHooks();
|
||||
for(int i = 0; i < hooks.length; i++) assertTrue(hooks[i].finished);
|
||||
}
|
||||
|
||||
private static class SlowHook implements Runnable {
|
||||
|
||||
private volatile boolean finished = false;
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
finished = true;
|
||||
} catch(InterruptedException e) {
|
||||
// Don't finish
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,9 +41,12 @@ public class PluginManagerImplTest extends TestCase {
|
||||
Poller poller = new PollerImpl();
|
||||
PluginManagerImpl p = new PluginManagerImpl(db, executor, poller,
|
||||
dispatcher, uiCallback);
|
||||
// The Bluetooth plugin will not start without a Bluetooth device, so
|
||||
// we expect two plugins to be started
|
||||
assertEquals(2, p.startPlugins());
|
||||
assertEquals(2, p.stopPlugins());
|
||||
// We expect either 2 or 3 plugins to be started, depending on whether
|
||||
// the test machine has a Bluetooth device
|
||||
int started = p.startPlugins();
|
||||
int stopped = p.stopPlugins();
|
||||
assertEquals(started, stopped);
|
||||
assertTrue(started >= 2);
|
||||
assertTrue(started <= 3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.plugins.file.RemovableDriveMonitor.Callback;
|
||||
import net.sf.briar.util.OsUtils;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -25,6 +26,10 @@ public class UnixRemovableDriveMonitorTest extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testNonexistentDir() throws Exception {
|
||||
if(!OsUtils.isLinux() || OsUtils.isMacLeopardOrNewer()) {
|
||||
System.err.println("Warning: Skipping test");
|
||||
return;
|
||||
}
|
||||
File doesNotExist = new File(testDir, "doesNotExist");
|
||||
RemovableDriveMonitor monitor = createMonitor(doesNotExist);
|
||||
monitor.start(null);
|
||||
@@ -33,6 +38,10 @@ public class UnixRemovableDriveMonitorTest extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testOneCallbackPerFile() throws Exception {
|
||||
if(!OsUtils.isLinux() || OsUtils.isMacLeopardOrNewer()) {
|
||||
System.err.println("Warning: Skipping test");
|
||||
return;
|
||||
}
|
||||
// Create a callback that will wait for two files before stopping
|
||||
final List<File> detected = new ArrayList<File>();
|
||||
final CountDownLatch latch = new CountDownLatch(2);
|
||||
|
||||
Reference in New Issue
Block a user