mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Unit tests and bug fixes for removable drive finders.
This commit is contained in:
@@ -10,8 +10,9 @@ class LinuxRemovableDriveFinder extends UnixRemovableDriveFinder {
|
||||
@Override
|
||||
protected String parseMountPoint(String line) {
|
||||
// The format is "/dev/foo on /bar/baz type bam (opt1,opt2)"
|
||||
line = line.replaceFirst("^/dev/[^ ]+ on ", "");
|
||||
return line.replaceFirst(" type [^ ]+ \\([^)]+\\)$", "");
|
||||
String pattern = "^/dev/[^ ]+ on (.*) type [^ ]+ \\([^)]+\\)$";
|
||||
String path = line.replaceFirst(pattern, "$1");
|
||||
return path.equals(line) ? null : path;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,8 +10,9 @@ class MacRemovableDriveFinder extends UnixRemovableDriveFinder {
|
||||
@Override
|
||||
protected String parseMountPoint(String line) {
|
||||
// The format is "/dev/foo on /bar/baz (opt1, opt2)"
|
||||
line = line.replaceFirst("^/dev/[^ ]+ on ", "");
|
||||
return line.replaceFirst(" \\([^)]+\\)$", "");
|
||||
String pattern = "^/dev/[^ ]+ on (.*) \\([^)]+\\)$";
|
||||
String path = line.replaceFirst(pattern, "$1");
|
||||
return path.equals(line) ? null : path;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
<test name='net.sf.briar.i18n.FontManagerTest'/>
|
||||
<test name='net.sf.briar.i18n.I18nTest'/>
|
||||
<test name='net.sf.briar.invitation.InvitationWorkerTest'/>
|
||||
<test name='net.sf.briar.plugins.file.LinuxRemovableDriveFinderTest'/>
|
||||
<test name='net.sf.briar.plugins.file.MacRemovableDriveFinderTest'/>
|
||||
<test name='net.sf.briar.plugins.file.RemovableDrivePluginTest'/>
|
||||
<test name='net.sf.briar.protocol.AckReaderTest'/>
|
||||
<test name='net.sf.briar.protocol.BatchReaderTest'/>
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package net.sf.briar.plugins.file;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class LinuxRemovableDriveFinderTest extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testParseMountPoint() {
|
||||
LinuxRemovableDriveFinder f = new LinuxRemovableDriveFinder();
|
||||
String line = "/dev/sda3 on / type ext3"
|
||||
+ " (rw,errors=remount-ro,commit=0)";
|
||||
assertEquals("/", f.parseMountPoint(line));
|
||||
line = "gvfs-fuse-daemon on /home/alice/.gvfs"
|
||||
+ " type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=alice)";
|
||||
assertEquals(null, f.parseMountPoint(line)); // Can't be parsed
|
||||
line = "fusectl on /sys/fs/fuse/connections type fusectl (rw)";
|
||||
assertEquals(null, f.parseMountPoint(line)); // Can't be parsed
|
||||
line = "/dev/sdd1 on /media/HAZ SPACE(!) type vfat"
|
||||
+ " (rw,nosuid,nodev,uhelper=udisks,uid=1000,gid=1000,"
|
||||
+ "shortname=mixed,dmask=0077,utf8=1,showexec,flush)";
|
||||
assertEquals("/media/HAZ SPACE(!)", f.parseMountPoint(line));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package net.sf.briar.plugins.file;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class MacRemovableDriveFinderTest extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testParseMountPoint() {
|
||||
MacRemovableDriveFinder f = new MacRemovableDriveFinder();
|
||||
String line = "/dev/disk0s3 on / (local, journaled)";
|
||||
assertEquals("/", f.parseMountPoint(line));
|
||||
line = "devfs on /dev (local)";
|
||||
assertEquals(null, f.parseMountPoint(line)); // Can't be parsed
|
||||
line = "<volfs> on /.vol";
|
||||
assertEquals(null, f.parseMountPoint(line)); // Can't be parsed
|
||||
line = "automount -nsl [117] on /Network (automounted)";
|
||||
assertEquals(null, f.parseMountPoint(line)); // Can't be parsed
|
||||
line = "/dev/disk1s1 on /Volumes/HAZ SPACE(!) (local, nodev, nosuid)";
|
||||
assertEquals("/Volumes/HAZ SPACE(!)", f.parseMountPoint(line));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user