diff --git a/lib/src/test/org/kiwix/test/libkiwix/TestBook.java b/lib/src/test/org/kiwix/test/libkiwix/TestBook.java index 7d15d9a..da019c4 100644 --- a/lib/src/test/org/kiwix/test/libkiwix/TestBook.java +++ b/lib/src/test/org/kiwix/test/libkiwix/TestBook.java @@ -2,7 +2,7 @@ package org.kiwix.test.libkiwix; import org.kiwix.libkiwix.Book; -import org.kiwix.libkiwix.Illustration; +import org.kiwix.test.libkiwix.TestIllustration; import org.kiwix.test.libzim.TestArchive; public class TestBook @@ -35,6 +35,6 @@ public class TestBook public long getMediaCount() { return inner.getMediaCount(); } public long getSize() { return inner.getSize(); } - public Illustration[] getIllustrations() { return inner.getIllustrations(); } - public Illustration getIllustration(int size) { return inner.getIllustration(size); } + public TestIllustration[] getIllustrations() { return Stream.of(inner.getIllustrations()).map(i -> new TestIllustration(i)).toArray(TestIllustration[]::new); } + public TestIllustration getIllustration(int size) { return new TestIllustration(inner.getIllustration(size)); } } diff --git a/lib/src/test/org/kiwix/test/libkiwix/TestIllustration.java b/lib/src/test/org/kiwix/test/libkiwix/TestIllustration.java new file mode 100644 index 0000000..7461f5e --- /dev/null +++ b/lib/src/test/org/kiwix/test/libkiwix/TestIllustration.java @@ -0,0 +1,15 @@ + +package org.kiwix.test.libkiwix; + +import org.kiwix.libkiwix.Illustration; + +public class TestIllustration +{ + private Illustration inner; + + public int width() { return inner.width(); } + public int height() { return inner.height(); } + public String mimeType() { return inner.mimeType(); } + public String url() { return inner.url(); } + public byte[] getData() { return inner.getData(); } +} diff --git a/lib/src/test/test.java b/lib/src/test/test.java index ba419b0..ca17482 100644 --- a/lib/src/test/test.java +++ b/lib/src/test/test.java @@ -303,7 +303,7 @@ private void testLibrary(TestLibrary lib) TestBook book = lib.getBookById(bookIds[0]); assertEquals(book.getTitle(), "Test ZIM file"); assertEquals(book.getTags(), "_category:Category;_ftindex:yes;_ftindex:yes;_pictures:yes;_videos:yes;_details:yes"); - assertEquals(book.getIllustration(48).width(), 48); + assertEquals(book.getUrl(), "http://localhost/small.zim"); assertEquals(book.getDescription(), "Description"); assertEquals(book.getCreator(), "Creator"); @@ -328,7 +328,15 @@ public void testLibrarySimple() throws IOException { testLibrary(lib); String[] bookIds = lib.getBooksIds(); TestBook book = lib.getBookById(bookIds[0]); - assertEquals(book.getIllustration(48).url(), ""); + + TestIllustration illustration = book.getIllustration(48); + assertEquals(illustration.width(), 48); + assertEquals(illustration.height(), 48); + assertEquals(illustration.mimeType(), "image/png"); + assertEquals(illustration.url(), ""); + byte[] faviconData = getFileContent("small_zimfile_data/favicon.png"); + assertTrue(Arrays.equals(faviconData, illustration.getData())); + assertEquals(book.getPath(), new File("small.zim").getAbsolutePath()); assertEquals(book.getHumanReadableIdFromPath(), "small"); assertTrue(book.isPathValid()); @@ -351,7 +359,15 @@ public void testLibraryXml() throws IOException { testLibrary(lib); String[] bookIds = lib.getBooksIds(); TestBook book = lib.getBookById(bookIds[0]); - assertEquals(book.getIllustration(48).url(), ""); + + Illustration illustration = book.getIllustration(48); + assertEquals(illustration.width(), 48); + assertEquals(illustration.height(), 48); + assertEquals(illustration.mimeType(), "image/png"); + assertEquals(illustration.url(), ""); + byte[] faviconData = getFileContent("small_zimfile_data/favicon.png"); + assertTrue(Arrays.equals(faviconData, illustration.getData())); + assertEquals(book.getPath(), new File("small.zim").getAbsolutePath()); assertEquals(book.getHumanReadableIdFromPath(), "small"); assertTrue(book.isPathValid()); @@ -370,7 +386,15 @@ public void testLibraryXmlContent() throws IOException { testLibrary(lib); String[] bookIds = lib.getBooksIds(); TestBook book = lib.getBookById(bookIds[0]); - assertEquals(book.getIllustration(48).url(), ""); + + Illustration illustration = book.getIllustration(48); + assertEquals(illustration.width(), 48); + assertEquals(illustration.height(), 48); + assertEquals(illustration.mimeType(), "image/png"); + assertEquals(illustration.url(), ""); + byte[] faviconData = getFileContent("small_zimfile_data/favicon.png"); + assertTrue(Arrays.equals(faviconData, illustration.getData())); + assertEquals(book.getPath(), new File("small.zim").getAbsolutePath()); assertEquals(book.getHumanReadableIdFromPath(), "small"); assertTrue(book.isPathValid()); @@ -389,7 +413,15 @@ public void testLibraryOPDS() throws IOException { testLibrary(lib); String[] bookIds = lib.getBooksIds(); TestBook book = lib.getBookById(bookIds[0]); - assertEquals(book.getIllustration(48).url(), "http://localhost/meta?name=favicon&content=small"); + + Illustration illustration = book.getIllustration(48); + assertEquals(illustration.width(), 48); + assertEquals(illustration.height(), 48); + assertEquals(illustration.mimeType(), "image/png"); + assertEquals(illustration.url(), "http://localhost/meta?name=favicon&content=small"); + // This will try to downoald to the data, but we have no local server. So return null. + assertEquals(illustration.getData(), null); + assertEquals(book.getPath(), ""); assertEquals(book.getHumanReadableIdFromPath(), ""); assertFalse(book.isPathValid());