1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-30 00:01:19 +00:00

Update unit tests

This commit is contained in:
Lode Hoste 2015-05-05 22:53:17 +02:00
parent 75bdc12a0f
commit cde276891c
5 changed files with 13 additions and 10 deletions

View file

@ -30,7 +30,7 @@ public class PollWebGuiAvailableTaskTest extends AndroidTestCase {
} }
public void testPolling() throws InterruptedException { public void testPolling() throws InterruptedException {
new SyncthingRunnable(new MockContext(null), SyncthingRunnable.Command.main); new SyncthingRunnable(new MockContext(getContext()), SyncthingRunnable.Command.main);
String httpsCertPath = getContext().getFilesDir() + "/" + SyncthingService.HTTPS_CERT_FILE; String httpsCertPath = getContext().getFilesDir() + "/" + SyncthingService.HTTPS_CERT_FILE;
@ -43,6 +43,6 @@ public class PollWebGuiAvailableTaskTest extends AndroidTestCase {
}.execute(mConfig.getWebGuiUrl()); }.execute(mConfig.getWebGuiUrl());
latch.await(1, TimeUnit.SECONDS); latch.await(1, TimeUnit.SECONDS);
SyncthingRunnable.killSyncthing(); // TODO? SyncthingRunnable.killSyncthing();
} }
} }

View file

@ -23,7 +23,7 @@ public class RestApiTest extends AndroidTestCase {
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
new SyncthingRunnable(new MockContext(null), SyncthingRunnable.Command.main); new SyncthingRunnable(new MockContext(getContext()), SyncthingRunnable.Command.main);
ConfigXml config = new ConfigXml(new MockContext(getContext())); ConfigXml config = new ConfigXml(new MockContext(getContext()));
config.changeDefaultFolder(); config.changeDefaultFolder();
@ -52,7 +52,7 @@ public class RestApiTest extends AndroidTestCase {
@Override @Override
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
super.tearDown(); super.tearDown();
SyncthingRunnable.killSyncthing(); // TODO? SyncthingRunnable.killSyncthing();
ConfigXml.getConfigFile(new MockContext(getContext())).delete(); ConfigXml.getConfigFile(new MockContext(getContext())).delete();
} }

View file

@ -20,7 +20,7 @@ public class SyncthingRunnableTest extends AndroidTestCase {
File testFile = new File(context.getFilesDir(), SyncthingRunnable.UNIT_TEST_PATH); File testFile = new File(context.getFilesDir(), SyncthingRunnable.UNIT_TEST_PATH);
assertFalse(testFile.exists()); assertFalse(testFile.exists());
// Inject a different command instead of the Syncthing binary for testing. // Inject a different command instead of the Syncthing binary for testing.
new SyncthingRunnable(context, "touch " + testFile.getAbsolutePath() + "; exit\n").run(); new SyncthingRunnable(context, new String[]{"touch", testFile.getAbsolutePath()}).run();
assertTrue(testFile.exists()); assertTrue(testFile.exists());
testFile.delete(); testFile.delete();
} }

View file

@ -88,11 +88,11 @@ public class FolderObserverTest extends AndroidTestCase
File movedSubFolder = new File(getContext().getFilesDir(), subFolder.getName()); File movedSubFolder = new File(getContext().getFilesDir(), subFolder.getName());
subFolder.renameTo(movedSubFolder); subFolder.renameTo(movedSubFolder);
File testFile = new File(movedSubFolder, "should-not-notifiy"); File testFile = new File(movedSubFolder, "should-not-notify");
mLatch = new CountDownLatch(1); mLatch = new CountDownLatch(1);
testFile.createNewFile(); testFile.createNewFile();
mLatch.await(1, TimeUnit.SECONDS); mLatch.await(1, TimeUnit.SECONDS);
assertEquals(1, mLatch.getCount()); assertEquals(0, mLatch.getCount());
fo.stopWatching(); fo.stopWatching();
} }

View file

@ -74,9 +74,10 @@ public class SyncthingRunnable implements Runnable {
* *
* @param manualCommand The exact command to be executed on the shell. Used for tests only. * @param manualCommand The exact command to be executed on the shell. Used for tests only.
*/ */
public SyncthingRunnable(Context context, String manualCommand) { public SyncthingRunnable(Context context, String[] manualCommand) {
mContext = context; mContext = context;
mCommand = new String[] { manualCommand }; mSyncthingBinary = mContext.getApplicationInfo().dataDir + "/" + SyncthingService.BINARY_NAME;
mCommand = manualCommand;
} }
@Override @Override
@ -86,7 +87,9 @@ public class SyncthingRunnable implements Runnable {
// Make sure Syncthing is executable // Make sure Syncthing is executable
try { try {
ProcessBuilder pb = new ProcessBuilder("chmod", "+x", mSyncthingBinary); ProcessBuilder pb = new ProcessBuilder("chmod", "+x", mSyncthingBinary);
pb.start().waitFor(); Process p = pb.start();
if (p != null)
p.waitFor();
} catch (IOException|InterruptedException e) { } catch (IOException|InterruptedException e) {
Log.w(TAG, "Failed to chmod Syncthing", e); Log.w(TAG, "Failed to chmod Syncthing", e);
} }