mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-20 10:23:30 -04:00
make code more uniform
insert the path of the temporary directory inside the base path itself instead of adding it every time a new file has to be created
This commit is contained in:
parent
e3e901671f
commit
c97420cd04
@ -32,7 +32,7 @@ public class FileUtilsInstrumentationTest {
|
||||
// Filename ends with .zimXX and the files up till "FileName.zimer" exist
|
||||
// i.e. 26 * 4 + 18 = 122 files exist
|
||||
String testId = "2rs5475f-51h7-vbz6-331b-7rr25r58251s";
|
||||
String fileName = "/" + testId + "testfile.zim";
|
||||
String fileName = testDir.getPath() + "/" + testId + "testfile.zim";
|
||||
String fileNameWithExtension;
|
||||
Random r = new Random();
|
||||
boolean bool[] = new boolean[122];
|
||||
@ -45,7 +45,7 @@ public class FileUtilsInstrumentationTest {
|
||||
fileNameWithExtension = fileName + char1 + char2;
|
||||
fileNameWithExtension =
|
||||
bool[index] ? fileNameWithExtension : fileNameWithExtension + ".part";
|
||||
File file = new File(testDir.getPath() + fileNameWithExtension);
|
||||
File file = new File(fileNameWithExtension);
|
||||
file.createNewFile();
|
||||
if (char1 == 'e' && char2 == 'r') {
|
||||
break;
|
||||
@ -58,7 +58,7 @@ public class FileUtilsInstrumentationTest {
|
||||
}
|
||||
|
||||
Book book = new Book();
|
||||
book.file = new File(testDir.getPath() + fileName + "bg");
|
||||
book.file = new File(fileName + "bg");
|
||||
|
||||
List<File> files = FileUtils.getAllZimParts(book);
|
||||
|
||||
@ -79,35 +79,35 @@ public class FileUtilsInstrumentationTest {
|
||||
@Test
|
||||
public void testHasPart() throws IOException {
|
||||
String testId = "3yd5474g-55d1-aqw0-108z-1xp69x25260d";
|
||||
String baseName = "/" + testId + "testFile";
|
||||
String baseName = testDir.getPath() + "/" + testId + "testFile";
|
||||
|
||||
// FileName ends with .zim
|
||||
File file1 = new File(testDir + baseName + "1" + ".zim");
|
||||
File file1 = new File(baseName + "1" + ".zim");
|
||||
file1.createNewFile();
|
||||
assertEquals("if the fileName ends with .zim and exists in memory, return false",
|
||||
false, FileUtils.hasPart(file1));
|
||||
|
||||
// FileName ends with .part
|
||||
File file2 = new File(testDir + baseName + "2" + ".zim");
|
||||
File file2 = new File(baseName + "2" + ".zim");
|
||||
file2.createNewFile();
|
||||
assertEquals("if the fileName ends with .part and exists in memory, return true",
|
||||
false, FileUtils.hasPart(file2));
|
||||
|
||||
// FileName ends with .zim, however, only the FileName.zim.part file exists in memory
|
||||
File file3 = new File(testDir + baseName + "3" + ".zim" + ".part");
|
||||
File file3 = new File(baseName + "3" + ".zim" + ".part");
|
||||
file3.createNewFile();
|
||||
File file4 = new File(testDir + baseName + "3" + ".zim");
|
||||
File file4 = new File(baseName + "3" + ".zim");
|
||||
assertEquals("if the fileName ends with .zim, but instead the .zim.part file exists in memory",
|
||||
true, FileUtils.hasPart(file4));
|
||||
|
||||
// FileName ends with .zimXX
|
||||
File testCall = new File(testDir + baseName + ".zimcj");
|
||||
File testCall = new File(baseName + ".zimcj");
|
||||
testCall.createNewFile();
|
||||
|
||||
// Case : FileName.zimXX.part does not exist for any value of "XX" from "aa" till "bl", but FileName.zimXX exists for all "XX" from "aa', till "bk", then it does not exist
|
||||
for (char char1 = 'a'; char1 <= 'z'; char1++) {
|
||||
for (char char2 = 'a'; char2 <= 'z'; char2++) {
|
||||
File file = new File(testDir.getPath() + baseName + ".zim" + char1 + char2);
|
||||
File file = new File(baseName + ".zim" + char1 + char2);
|
||||
file.createNewFile();
|
||||
if (char1 == 'b' && char2 == 'k') {
|
||||
break;
|
||||
@ -122,12 +122,12 @@ public class FileUtilsInstrumentationTest {
|
||||
|
||||
// Case : FileName.zim is the calling file, but neither FileName.zim, nor FileName.zim.part exist
|
||||
// In this case the answer will be the same as that in the previous (FileName.zimXX) case
|
||||
File testCall2 = new File(testDir.getPath() + baseName + ".zim");
|
||||
File testCall2 = new File(baseName + ".zim");
|
||||
assertEquals(false, FileUtils.hasPart(testCall2));
|
||||
|
||||
// Case : FileName.zimXX.part exists for some "XX" between "aa" till "bl"
|
||||
// And FileName.zimXX exists for all "XX" from "aa', till "bk", and then it does not exist
|
||||
File t = new File(testDir + baseName + ".zimaj.part");
|
||||
File t = new File(baseName + ".zimaj.part");
|
||||
t.createNewFile();
|
||||
assertEquals(true, FileUtils.hasPart(testCall));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user