Testing of JNIKiwixReader.getDirectAccessInformation()

This commit is contained in:
Veloman Yunkan 2020-12-07 23:11:19 +04:00 committed by Emmanuel Engelhart
parent 7a465e66d7
commit 5a8b825c70
2 changed files with 29 additions and 1 deletions

View File

@ -111,7 +111,7 @@ class Entry
* The offset is the offset to read in the file. * The offset is the offset to read in the file.
* Return <"",0> if is not possible to read directly. * Return <"",0> if is not possible to read directly.
*/ */
std::pair<std::string, offset_type> getDirectAccessInfo() const { return entry.getItem().getDirectAccessInformation(); } zim::Item::DirectAccessInfo getDirectAccessInfo() const { return entry.getItem().getDirectAccessInformation(); }
/** /**
* Get the size of the entry. * Get the size of the entry.

View File

@ -22,6 +22,19 @@ throws IOException
return data; return data;
} }
private static byte[] getFileContentPartial(String path, int offset, int size)
throws IOException
{
File file = new File(path);
DataInputStream in = new DataInputStream(
new BufferedInputStream(
new FileInputStream(file)));
byte[] data = new byte[size];
in.skipBytes(offset);
in.read(data, 0, size);
return data;
}
private static String getTextFileContent(String path) private static String getTextFileContent(String path)
throws IOException throws IOException
{ {
@ -50,6 +63,11 @@ throws JNIKiwixException, IOException
new JNIKiwixString(), new JNIKiwixString(),
new JNIKiwixInt()); new JNIKiwixInt());
assertTrue(Arrays.equals(faviconData, c)); assertTrue(Arrays.equals(faviconData, c));
DirectAccessInfo dai = reader.getDirectAccessInformation("I/favicon.png");
assertNotEquals("", dai.filename);
c = getFileContentPartial(dai.filename, (int)dai.offset, faviconData.length);
assertTrue(Arrays.equals(faviconData, c));
} }
@Test @Test
@ -75,6 +93,11 @@ throws JNIKiwixException, IOException
new JNIKiwixString(), new JNIKiwixString(),
new JNIKiwixInt()); new JNIKiwixInt());
assertTrue(Arrays.equals(faviconData, c)); assertTrue(Arrays.equals(faviconData, c));
DirectAccessInfo dai = reader.getDirectAccessInformation("I/favicon.png");
assertNotEquals("", dai.filename);
c = getFileContentPartial(dai.filename, (int)dai.offset, faviconData.length);
assertTrue(Arrays.equals(faviconData, c));
} }
@Test @Test
@ -101,6 +124,11 @@ throws JNIKiwixException, IOException
new JNIKiwixString(), new JNIKiwixString(),
new JNIKiwixInt()); new JNIKiwixInt());
assertTrue(Arrays.equals(faviconData, c)); assertTrue(Arrays.equals(faviconData, c));
DirectAccessInfo dai = reader.getDirectAccessInformation("I/favicon.png");
assertNotEquals("", dai.filename);
c = getFileContentPartial(dai.filename, (int)dai.offset, faviconData.length);
assertTrue(Arrays.equals(faviconData, c));
} }
@Test @Test