From 827ab31c38d8ec5b51a3863b60672ae84190937b Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Fri, 30 Jun 2023 10:37:37 +0200 Subject: [PATCH] Better testing of errors. --- lib/src/test/test.java | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/src/test/test.java b/lib/src/test/test.java index c177824..bfffb25 100644 --- a/lib/src/test/test.java +++ b/lib/src/test/test.java @@ -116,6 +116,7 @@ public class test { assertFalse(archive.getRandomEntry().getTitle().isEmpty()); + // Test different iterators { TestEntryIterator iter = archive.iterByPath(); assertTrue(iter.hasNext()); @@ -153,7 +154,20 @@ public class test { assertEquals("main.html", iter.next().getPath()); 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 public void testArchiveDirect() @@ -163,9 +177,12 @@ public class test { assertTrue(archive.check()); assertEquals("small.zim", archive.getFilename()); archive.dispose(); + } - // test reader with invalid zim file - String zimFile = "test.zim"; + @Test + public void testNonExistant() { + // test reader with non existant zim file + String zimFile = "non_existant.zim"; try { TestArchive archive1 = new TestArchive(zimFile); 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 public void testArchiveByFd() throws JNIKiwixException, IOException, ZimFileFormatException {