From 5a8b825c7032dabcd0aef040fdf0e106ad9b4a82 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Mon, 7 Dec 2020 23:11:19 +0400 Subject: [PATCH] Testing of JNIKiwixReader.getDirectAccessInformation() --- include/entry.h | 2 +- src/wrapper/java/org/kiwix/testing/test.java | 28 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/entry.h b/include/entry.h index e2edf0a9a..c3a01521c 100644 --- a/include/entry.h +++ b/include/entry.h @@ -111,7 +111,7 @@ class Entry * The offset is the offset to read in the file. * Return <"",0> if is not possible to read directly. */ - std::pair getDirectAccessInfo() const { return entry.getItem().getDirectAccessInformation(); } + zim::Item::DirectAccessInfo getDirectAccessInfo() const { return entry.getItem().getDirectAccessInformation(); } /** * Get the size of the entry. diff --git a/src/wrapper/java/org/kiwix/testing/test.java b/src/wrapper/java/org/kiwix/testing/test.java index 0ab2d3959..788729d12 100644 --- a/src/wrapper/java/org/kiwix/testing/test.java +++ b/src/wrapper/java/org/kiwix/testing/test.java @@ -22,6 +22,19 @@ throws IOException 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) throws IOException { @@ -50,6 +63,11 @@ throws JNIKiwixException, IOException new JNIKiwixString(), new JNIKiwixInt()); 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 @@ -75,6 +93,11 @@ throws JNIKiwixException, IOException new JNIKiwixString(), new JNIKiwixInt()); 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 @@ -101,6 +124,11 @@ throws JNIKiwixException, IOException new JNIKiwixString(), new JNIKiwixInt()); 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