-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1539 from TranceLove/bugfix/issue1522
Remove limit of MainActivityHelper.isNewDirectoryRecursive(file) on mkdir()
- Loading branch information
1 parent
9fc9a80
commit 6488833
Showing
2 changed files
with
235 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
234 changes: 234 additions & 0 deletions
234
app/src/test/java/com/amaze/filemanager/filesystem/OperationsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,234 @@ | ||
package com.amaze.filemanager.filesystem; | ||
|
||
import android.os.Environment; | ||
|
||
import com.amaze.filemanager.BuildConfig; | ||
import com.amaze.filemanager.utils.OpenMode; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.RuntimeEnvironment; | ||
import org.robolectric.annotation.Config; | ||
import org.robolectric.shadows.multidex.ShadowMultiDex; | ||
|
||
import java.io.File; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
@RunWith(RobolectricTestRunner.class) | ||
@Config(maxSdk = 27, constants = BuildConfig.class, shadows = {ShadowMultiDex.class}) | ||
public class OperationsTest { | ||
|
||
private File storageRoot = Environment.getExternalStorageDirectory(); | ||
|
||
@Test | ||
public void testMkdir() throws InterruptedException | ||
{ | ||
File newFolder = new File(storageRoot, "test"); | ||
HybridFile newFolderHF = new HybridFile(OpenMode.FILE, newFolder.getAbsolutePath()); | ||
|
||
CountDownLatch waiter = new CountDownLatch(1); | ||
Operations.mkdir(newFolderHF, RuntimeEnvironment.application, false, new AbstractErrorCallback() { | ||
@Override | ||
public void done(HybridFile hFile, boolean b) { | ||
waiter.countDown(); | ||
} | ||
}); | ||
waiter.await(); | ||
assertTrue(newFolder.exists()); | ||
} | ||
|
||
@Test | ||
public void testMkdirDuplicate() throws InterruptedException | ||
{ | ||
File newFolder = new File(storageRoot, "test"); | ||
HybridFile newFolderHF = new HybridFile(OpenMode.FILE, newFolder.getAbsolutePath()); | ||
|
||
CountDownLatch waiter1 = new CountDownLatch(1); | ||
Operations.mkdir(newFolderHF, RuntimeEnvironment.application, false, new AbstractErrorCallback() { | ||
@Override | ||
public void done(HybridFile hFile, boolean b) { | ||
waiter1.countDown(); | ||
} | ||
}); | ||
waiter1.await(); | ||
assertTrue(newFolder.exists()); | ||
|
||
CountDownLatch waiter2 = new CountDownLatch(1); | ||
AtomicBoolean assertFlag = new AtomicBoolean(false); | ||
Operations.mkdir(newFolderHF, RuntimeEnvironment.application, false, new AbstractErrorCallback() { | ||
@Override | ||
public void exists(HybridFile file) { | ||
assertFlag.set(true); | ||
waiter2.countDown(); | ||
} | ||
}); | ||
waiter2.await(); | ||
assertTrue(assertFlag.get()); | ||
} | ||
|
||
@Test | ||
public void testMkdirNewFolderSameNameAsCurrentFolder() throws InterruptedException | ||
{ | ||
File newFolder = new File(storageRoot, "test"); | ||
HybridFile newFolderHF = new HybridFile(OpenMode.FILE, newFolder.getAbsolutePath()); | ||
|
||
CountDownLatch waiter1 = new CountDownLatch(1); | ||
Operations.mkdir(newFolderHF, RuntimeEnvironment.application, false, new AbstractErrorCallback() { | ||
@Override | ||
public void done(HybridFile hFile, boolean b) { | ||
waiter1.countDown(); | ||
} | ||
}); | ||
waiter1.await(); | ||
assertTrue(newFolder.exists()); | ||
|
||
File newFolder2 = new File(newFolder, "test"); | ||
HybridFile newFolder2HF = new HybridFile(OpenMode.FILE, newFolder2.getAbsolutePath()); | ||
CountDownLatch waiter2 = new CountDownLatch(1); | ||
Operations.mkdir(newFolder2HF, RuntimeEnvironment.application, false, new AbstractErrorCallback() { | ||
@Override | ||
public void done(HybridFile hFile, boolean b) { | ||
waiter2.countDown(); | ||
} | ||
}); | ||
waiter2.await(); | ||
assertTrue(newFolder2.exists()); | ||
|
||
CountDownLatch waiter3 = new CountDownLatch(1); | ||
AtomicBoolean assertFlag = new AtomicBoolean(false); | ||
Operations.mkdir(newFolder2HF, RuntimeEnvironment.application, false, new AbstractErrorCallback() { | ||
@Override | ||
public void exists(HybridFile file) { | ||
assertFlag.set(true); | ||
waiter3.countDown(); | ||
} | ||
}); | ||
waiter3.await(); | ||
assertTrue(assertFlag.get()); | ||
} | ||
|
||
@Test | ||
public void testRename() throws InterruptedException | ||
{ | ||
File oldFolder = new File(storageRoot, "test1"); | ||
HybridFile oldFolderHF = new HybridFile(OpenMode.FILE, oldFolder.getAbsolutePath()); | ||
File newFolder = new File(storageRoot, "test2"); | ||
HybridFile newFolderHF = new HybridFile(OpenMode.FILE, newFolder.getAbsolutePath()); | ||
|
||
CountDownLatch waiter1 = new CountDownLatch(1); | ||
Operations.mkdir(oldFolderHF, RuntimeEnvironment.application, false, new AbstractErrorCallback() { | ||
@Override | ||
public void done(HybridFile hFile, boolean b) { | ||
waiter1.countDown(); | ||
} | ||
}); | ||
waiter1.await(); | ||
assertTrue(oldFolder.exists()); | ||
|
||
CountDownLatch waiter2 = new CountDownLatch(1); | ||
Operations.rename(oldFolderHF, newFolderHF, false, RuntimeEnvironment.application, new AbstractErrorCallback() { | ||
@Override | ||
public void done(HybridFile hFile, boolean b) { | ||
waiter2.countDown(); | ||
} | ||
}); | ||
waiter2.await(); | ||
assertFalse(oldFolder.exists()); | ||
assertTrue(newFolder.exists()); | ||
} | ||
|
||
@Test | ||
public void testRenameSameName() throws InterruptedException | ||
{ | ||
File folder = new File(storageRoot, "test"); | ||
HybridFile folderHF = new HybridFile(OpenMode.FILE, folder.getAbsolutePath()); | ||
|
||
CountDownLatch waiter1 = new CountDownLatch(1); | ||
Operations.mkdir(folderHF, RuntimeEnvironment.application, false, new AbstractErrorCallback() { | ||
@Override | ||
public void done(HybridFile hFile, boolean b) { | ||
waiter1.countDown(); | ||
} | ||
}); | ||
waiter1.await(); | ||
assertTrue(folder.exists()); | ||
|
||
CountDownLatch waiter2 = new CountDownLatch(1); | ||
AtomicBoolean assertFlag = new AtomicBoolean(false); | ||
Operations.rename(folderHF, folderHF, false, RuntimeEnvironment.application, new AbstractErrorCallback() { | ||
@Override | ||
public void exists(HybridFile file){ | ||
assertFlag.set(true); | ||
waiter2.countDown(); | ||
} | ||
}); | ||
waiter2.await(); | ||
assertTrue(folder.exists()); | ||
assertTrue(assertFlag.get()); | ||
} | ||
|
||
@Test | ||
public void testRenameSameName2() throws InterruptedException | ||
{ | ||
File folder = new File(storageRoot, "test"); | ||
HybridFile folderHF = new HybridFile(OpenMode.FILE, folder.getAbsolutePath()); | ||
|
||
CountDownLatch waiter1 = new CountDownLatch(1); | ||
Operations.mkdir(folderHF, RuntimeEnvironment.application, false, new AbstractErrorCallback() { | ||
@Override | ||
public void done(HybridFile hFile, boolean b) { | ||
waiter1.countDown(); | ||
} | ||
}); | ||
waiter1.await(); | ||
assertTrue(folder.exists()); | ||
|
||
File folder2 = new File(storageRoot, "test2"); | ||
HybridFile folder2HF = new HybridFile(OpenMode.FILE, folder2.getAbsolutePath()); | ||
|
||
CountDownLatch waiter2 = new CountDownLatch(1); | ||
Operations.mkdir(folder2HF, RuntimeEnvironment.application, false, new AbstractErrorCallback() { | ||
@Override | ||
public void done(HybridFile hFile, boolean b) { | ||
waiter2.countDown(); | ||
} | ||
}); | ||
waiter2.await(); | ||
assertTrue(folder2.exists()); | ||
|
||
CountDownLatch waiter3 = new CountDownLatch(1); | ||
AtomicBoolean assertFlag = new AtomicBoolean(false); | ||
Operations.rename(folderHF, folder2HF, false, RuntimeEnvironment.application, new AbstractErrorCallback() { | ||
@Override | ||
public void exists(HybridFile file){ | ||
assertFlag.set(true); | ||
waiter3.countDown(); | ||
} | ||
}); | ||
waiter3.await(); | ||
assertTrue(folder.exists()); | ||
assertTrue(assertFlag.get()); | ||
} | ||
|
||
private abstract class AbstractErrorCallback implements Operations.ErrorCallBack | ||
{ | ||
@Override | ||
public void exists(HybridFile file) {} | ||
|
||
@Override | ||
public void launchSAF(HybridFile file) {} | ||
|
||
@Override | ||
public void launchSAF(HybridFile file, HybridFile file1) {} | ||
|
||
@Override | ||
public void done(HybridFile hFile, boolean b) {} | ||
|
||
@Override | ||
public void invalidName(HybridFile file) {} | ||
} | ||
} |