Added testReader unit-test for the java wrapper

This commit is contained in:
Veloman Yunkan 2020-11-29 21:27:22 +04:00 committed by Emmanuel Engelhart
parent e40827fbac
commit 98d69ef59b
1 changed files with 21 additions and 4 deletions

View File

@ -10,10 +10,10 @@ static {
System.loadLibrary("kiwix"); System.loadLibrary("kiwix");
} }
private static String getCatalogContent() private static String getFileContent(String path)
throws IOException throws IOException
{ {
BufferedReader reader = new BufferedReader(new FileReader("catalog.xml")); BufferedReader reader = new BufferedReader(new FileReader(path));
String line; String line;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null) while ((line = reader.readLine()) != null)
@ -25,12 +25,29 @@ throws IOException
} }
@Test @Test
public void testSome() public void testReader()
throws JNIKiwixException, IOException
{
JNIKiwixReader reader = new JNIKiwixReader("small.zim");
assertEquals("Test ZIM file", reader.getTitle());
assertEquals(45, reader.getFileSize()); // The file size is in KiB
assertEquals("A/main.html", reader.getMainPage());
String s = getFileContent("small_zimfile_data/main.html");
byte[] c = reader.getContent(new JNIKiwixString("A/main.html"),
new JNIKiwixString(),
new JNIKiwixString(),
new JNIKiwixInt());
assertEquals(s, new String(c));
}
@Test
public void testLibrary()
throws IOException throws IOException
{ {
Library lib = new Library(); Library lib = new Library();
Manager manager = new Manager(lib); Manager manager = new Manager(lib);
String content = getCatalogContent(); String content = getFileContent("catalog.xml");
manager.readOpds(content, "http://localhost"); manager.readOpds(content, "http://localhost");
assertEquals(lib.getBookCount(true, true), 1); assertEquals(lib.getBookCount(true, true), 1);
String[] bookIds = lib.getBooksIds(); String[] bookIds = lib.getBooksIds();