mirror of https://github.com/kiwix/libkiwix.git
Java wrapper test checks favicon.png too
This commit is contained in:
parent
e028bcbb04
commit
5a99634dfd
|
@ -10,18 +10,22 @@ static {
|
||||||
System.loadLibrary("kiwix");
|
System.loadLibrary("kiwix");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getFileContent(String path)
|
private static byte[] getFileContent(String path)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(path));
|
File file = new File(path);
|
||||||
String line;
|
DataInputStream in = new DataInputStream(
|
||||||
StringBuilder sb = new StringBuilder();
|
new BufferedInputStream(
|
||||||
while ((line = reader.readLine()) != null)
|
new FileInputStream(file)));
|
||||||
{
|
byte[] data = new byte[(int)file.length()];
|
||||||
sb.append(line + "\n");
|
in.read(data);
|
||||||
}
|
return data;
|
||||||
reader.close();
|
}
|
||||||
return sb.toString();
|
|
||||||
|
private static String getTextFileContent(String path)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
return new String(getFileContent(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -32,13 +36,20 @@ throws JNIKiwixException, IOException
|
||||||
assertEquals("Test ZIM file", reader.getTitle());
|
assertEquals("Test ZIM file", reader.getTitle());
|
||||||
assertEquals(45, reader.getFileSize()); // The file size is in KiB
|
assertEquals(45, reader.getFileSize()); // The file size is in KiB
|
||||||
assertEquals("A/main.html", reader.getMainPage());
|
assertEquals("A/main.html", reader.getMainPage());
|
||||||
String s = getFileContent("small_zimfile_data/main.html");
|
String s = getTextFileContent("small_zimfile_data/main.html");
|
||||||
byte[] c = reader.getContent(new JNIKiwixString("A/main.html"),
|
byte[] c = reader.getContent(new JNIKiwixString("A/main.html"),
|
||||||
new JNIKiwixString(),
|
new JNIKiwixString(),
|
||||||
new JNIKiwixString(),
|
new JNIKiwixString(),
|
||||||
new JNIKiwixInt());
|
new JNIKiwixInt());
|
||||||
assertEquals(s, new String(c));
|
assertEquals(s, new String(c));
|
||||||
|
|
||||||
|
byte[] faviconData = getFileContent("small_zimfile_data/favicon.png");
|
||||||
|
assertEquals(faviconData.length, reader.getArticleSize("I/favicon.png"));
|
||||||
|
c = reader.getContent(new JNIKiwixString("I/favicon.png"),
|
||||||
|
new JNIKiwixString(),
|
||||||
|
new JNIKiwixString(),
|
||||||
|
new JNIKiwixInt());
|
||||||
|
assertTrue(Arrays.equals(faviconData, c));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -50,13 +61,20 @@ throws JNIKiwixException, IOException
|
||||||
assertEquals("Test ZIM file", reader.getTitle());
|
assertEquals("Test ZIM file", reader.getTitle());
|
||||||
assertEquals(45, reader.getFileSize()); // The file size is in KiB
|
assertEquals(45, reader.getFileSize()); // The file size is in KiB
|
||||||
assertEquals("A/main.html", reader.getMainPage());
|
assertEquals("A/main.html", reader.getMainPage());
|
||||||
String s = getFileContent("small_zimfile_data/main.html");
|
String s = getTextFileContent("small_zimfile_data/main.html");
|
||||||
byte[] c = reader.getContent(new JNIKiwixString("A/main.html"),
|
byte[] c = reader.getContent(new JNIKiwixString("A/main.html"),
|
||||||
new JNIKiwixString(),
|
new JNIKiwixString(),
|
||||||
new JNIKiwixString(),
|
new JNIKiwixString(),
|
||||||
new JNIKiwixInt());
|
new JNIKiwixInt());
|
||||||
assertEquals(s, new String(c));
|
assertEquals(s, new String(c));
|
||||||
|
|
||||||
|
byte[] faviconData = getFileContent("small_zimfile_data/favicon.png");
|
||||||
|
assertEquals(faviconData.length, reader.getArticleSize("I/favicon.png"));
|
||||||
|
c = reader.getContent(new JNIKiwixString("I/favicon.png"),
|
||||||
|
new JNIKiwixString(),
|
||||||
|
new JNIKiwixString(),
|
||||||
|
new JNIKiwixInt());
|
||||||
|
assertTrue(Arrays.equals(faviconData, c));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -69,13 +87,20 @@ throws JNIKiwixException, IOException
|
||||||
assertEquals("Test ZIM file", reader.getTitle());
|
assertEquals("Test ZIM file", reader.getTitle());
|
||||||
assertEquals(45, reader.getFileSize()); // The file size is in KiB
|
assertEquals(45, reader.getFileSize()); // The file size is in KiB
|
||||||
assertEquals("A/main.html", reader.getMainPage());
|
assertEquals("A/main.html", reader.getMainPage());
|
||||||
String s = getFileContent("small_zimfile_data/main.html");
|
String s = getTextFileContent("small_zimfile_data/main.html");
|
||||||
byte[] c = reader.getContent(new JNIKiwixString("A/main.html"),
|
byte[] c = reader.getContent(new JNIKiwixString("A/main.html"),
|
||||||
new JNIKiwixString(),
|
new JNIKiwixString(),
|
||||||
new JNIKiwixString(),
|
new JNIKiwixString(),
|
||||||
new JNIKiwixInt());
|
new JNIKiwixInt());
|
||||||
assertEquals(s, new String(c));
|
assertEquals(s, new String(c));
|
||||||
|
|
||||||
|
byte[] faviconData = getFileContent("small_zimfile_data/favicon.png");
|
||||||
|
assertEquals(faviconData.length, reader.getArticleSize("I/favicon.png"));
|
||||||
|
c = reader.getContent(new JNIKiwixString("I/favicon.png"),
|
||||||
|
new JNIKiwixString(),
|
||||||
|
new JNIKiwixString(),
|
||||||
|
new JNIKiwixInt());
|
||||||
|
assertTrue(Arrays.equals(faviconData, c));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -84,7 +109,7 @@ throws IOException
|
||||||
{
|
{
|
||||||
Library lib = new Library();
|
Library lib = new Library();
|
||||||
Manager manager = new Manager(lib);
|
Manager manager = new Manager(lib);
|
||||||
String content = getFileContent("catalog.xml");
|
String content = getTextFileContent("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();
|
||||||
|
|
Loading…
Reference in New Issue