Better testing of errors.

This commit is contained in:
Matthieu Gautier 2023-06-30 10:37:37 +02:00
parent 40dd4ea853
commit 827ab31c38

View File

@ -116,6 +116,7 @@ public class test {
assertFalse(archive.getRandomEntry().getTitle().isEmpty()); assertFalse(archive.getRandomEntry().getTitle().isEmpty());
// Test different iterators
{ {
TestEntryIterator iter = archive.iterByPath(); TestEntryIterator iter = archive.iterByPath();
assertTrue(iter.hasNext()); assertTrue(iter.hasNext());
@ -153,7 +154,20 @@ public class test {
assertEquals("main.html", iter.next().getPath()); assertEquals("main.html", iter.next().getPath());
assertFalse(iter.hasNext()); assertFalse(iter.hasNext());
} }
}
// Test invalid path
try {
archive.getEntryByTitle("Wrong title");
} catch(Exception e) {
assertEquals("Cannot find entry", e.getMessage());
}
try {
archive.getEntryByPath("wrong_path.html");
} catch(Exception e) {
assertEquals("Cannot find entry", e.getMessage());
}
}
@Test @Test
public void testArchiveDirect() public void testArchiveDirect()
@ -163,9 +177,12 @@ public class test {
assertTrue(archive.check()); assertTrue(archive.check());
assertEquals("small.zim", archive.getFilename()); assertEquals("small.zim", archive.getFilename());
archive.dispose(); archive.dispose();
}
// test reader with invalid zim file @Test
String zimFile = "test.zim"; public void testNonExistant() {
// test reader with non existant zim file
String zimFile = "non_existant.zim";
try { try {
TestArchive archive1 = new TestArchive(zimFile); TestArchive archive1 = new TestArchive(zimFile);
fail("ERROR: Archive created with invalid Zim file!"); fail("ERROR: Archive created with invalid Zim file!");
@ -174,6 +191,18 @@ public class test {
} }
} }
@Test
public void testNotValid() {
// test reader with non existant zim file
String zimFile = "test.java";
try {
TestArchive archive1 = new TestArchive(zimFile);
fail("ERROR: Archive created with invalid Zim file!");
} catch (ZimFileFormatException e) {
assertEquals("Invalid magic number", e.getMessage());
}
}
@Test @Test
public void testArchiveByFd() public void testArchiveByFd()
throws JNIKiwixException, IOException, ZimFileFormatException { throws JNIKiwixException, IOException, ZimFileFormatException {