mirror of
https://github.com/kiwix/java-libkiwix.git
synced 2025-09-12 00:27:46 -04:00
Add a test on Illustration data coming from book.
This commit is contained in:
parent
1cbbd4eaa5
commit
ed6a302d1c
@ -2,8 +2,9 @@
|
|||||||
package org.kiwix.test.libkiwix;
|
package org.kiwix.test.libkiwix;
|
||||||
|
|
||||||
import org.kiwix.libkiwix.Book;
|
import org.kiwix.libkiwix.Book;
|
||||||
import org.kiwix.libkiwix.Illustration;
|
import org.kiwix.test.libkiwix.TestIllustration;
|
||||||
import org.kiwix.test.libzim.TestArchive;
|
import org.kiwix.test.libzim.TestArchive;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class TestBook
|
public class TestBook
|
||||||
{
|
{
|
||||||
@ -35,6 +36,6 @@ public class TestBook
|
|||||||
public long getMediaCount() { return inner.getMediaCount(); }
|
public long getMediaCount() { return inner.getMediaCount(); }
|
||||||
public long getSize() { return inner.getSize(); }
|
public long getSize() { return inner.getSize(); }
|
||||||
|
|
||||||
public Illustration[] getIllustrations() { return inner.getIllustrations(); }
|
public TestIllustration[] getIllustrations() { return Stream.of(inner.getIllustrations()).map(i -> new TestIllustration(i)).toArray(TestIllustration[]::new); }
|
||||||
public Illustration getIllustration(int size) { return inner.getIllustration(size); }
|
public TestIllustration getIllustration(int size) { return new TestIllustration(inner.getIllustration(size)); }
|
||||||
}
|
}
|
||||||
|
16
lib/src/test/org/kiwix/test/libkiwix/TestIllustration.java
Normal file
16
lib/src/test/org/kiwix/test/libkiwix/TestIllustration.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
package org.kiwix.test.libkiwix;
|
||||||
|
|
||||||
|
import org.kiwix.libkiwix.Illustration;
|
||||||
|
|
||||||
|
public class TestIllustration
|
||||||
|
{
|
||||||
|
private Illustration inner;
|
||||||
|
public TestIllustration(Illustration _inner) { inner = _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(); }
|
||||||
|
}
|
@ -303,7 +303,7 @@ public class test {
|
|||||||
TestBook book = lib.getBookById(bookIds[0]);
|
TestBook book = lib.getBookById(bookIds[0]);
|
||||||
assertEquals(book.getTitle(), "Test ZIM file");
|
assertEquals(book.getTitle(), "Test ZIM file");
|
||||||
assertEquals(book.getTags(), "_category:Category;_ftindex:yes;_ftindex:yes;_pictures:yes;_videos:yes;_details:yes");
|
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.getUrl(), "http://localhost/small.zim");
|
||||||
assertEquals(book.getDescription(), "Description");
|
assertEquals(book.getDescription(), "Description");
|
||||||
assertEquals(book.getCreator(), "Creator");
|
assertEquals(book.getCreator(), "Creator");
|
||||||
@ -313,7 +313,7 @@ public class test {
|
|||||||
assertEquals(book.getArticleCount(), 1);
|
assertEquals(book.getArticleCount(), 1);
|
||||||
assertEquals(book.getMediaCount(), 1);
|
assertEquals(book.getMediaCount(), 1);
|
||||||
assertEquals(book.getSize(), 66560);
|
assertEquals(book.getSize(), 66560);
|
||||||
Illustration[] illustrations = book.getIllustrations();
|
TestIllustration[] illustrations = book.getIllustrations();
|
||||||
assertEquals(1, illustrations.length);
|
assertEquals(1, illustrations.length);
|
||||||
|
|
||||||
assertEquals(book.getTagStr("video"), "");
|
assertEquals(book.getTagStr("video"), "");
|
||||||
@ -328,7 +328,15 @@ public class test {
|
|||||||
testLibrary(lib);
|
testLibrary(lib);
|
||||||
String[] bookIds = lib.getBooksIds();
|
String[] bookIds = lib.getBooksIds();
|
||||||
TestBook book = lib.getBookById(bookIds[0]);
|
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.getPath(), new File("small.zim").getAbsolutePath());
|
||||||
assertEquals(book.getHumanReadableIdFromPath(), "small");
|
assertEquals(book.getHumanReadableIdFromPath(), "small");
|
||||||
assertTrue(book.isPathValid());
|
assertTrue(book.isPathValid());
|
||||||
@ -351,7 +359,15 @@ public class test {
|
|||||||
testLibrary(lib);
|
testLibrary(lib);
|
||||||
String[] bookIds = lib.getBooksIds();
|
String[] bookIds = lib.getBooksIds();
|
||||||
TestBook book = lib.getBookById(bookIds[0]);
|
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.getPath(), new File("small.zim").getAbsolutePath());
|
||||||
assertEquals(book.getHumanReadableIdFromPath(), "small");
|
assertEquals(book.getHumanReadableIdFromPath(), "small");
|
||||||
assertTrue(book.isPathValid());
|
assertTrue(book.isPathValid());
|
||||||
@ -370,7 +386,15 @@ public class test {
|
|||||||
testLibrary(lib);
|
testLibrary(lib);
|
||||||
String[] bookIds = lib.getBooksIds();
|
String[] bookIds = lib.getBooksIds();
|
||||||
TestBook book = lib.getBookById(bookIds[0]);
|
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.getPath(), new File("small.zim").getAbsolutePath());
|
||||||
assertEquals(book.getHumanReadableIdFromPath(), "small");
|
assertEquals(book.getHumanReadableIdFromPath(), "small");
|
||||||
assertTrue(book.isPathValid());
|
assertTrue(book.isPathValid());
|
||||||
@ -389,7 +413,15 @@ public class test {
|
|||||||
testLibrary(lib);
|
testLibrary(lib);
|
||||||
String[] bookIds = lib.getBooksIds();
|
String[] bookIds = lib.getBooksIds();
|
||||||
TestBook book = lib.getBookById(bookIds[0]);
|
TestBook book = lib.getBookById(bookIds[0]);
|
||||||
assertEquals(book.getIllustration(48).url(), "http://localhost/meta?name=favicon&content=small");
|
|
||||||
|
TestIllustration 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 empty array.
|
||||||
|
assertTrue(Arrays.equals(illustration.getData(), new byte[0]));
|
||||||
|
|
||||||
assertEquals(book.getPath(), "");
|
assertEquals(book.getPath(), "");
|
||||||
assertEquals(book.getHumanReadableIdFromPath(), "");
|
assertEquals(book.getHumanReadableIdFromPath(), "");
|
||||||
assertFalse(book.isPathValid());
|
assertFalse(book.isPathValid());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user