Copy test from branch Issue#19

zim files has been changed but I don't know why.
Change came from commits 3cd8ed98 and 8bff08ca but it is not explain
what are the changes. @MohitMaliFtechiz ?
This commit is contained in:
Matthieu Gautier 2022-12-20 11:53:08 +01:00
parent a0d95cb9c6
commit 3e02f1733f
7 changed files with 189 additions and 140 deletions

View File

@ -0,0 +1,39 @@
cmake_minimum_required (VERSION 3.16)
project (buildkiwix)
add_library(buildkiwix
SHARED
${CMAKE_SOURCE_DIR}/../../../../../main/cpp/base64.cpp
${CMAKE_SOURCE_DIR}/../../../../../main/cpp/book.cpp
${CMAKE_SOURCE_DIR}/../../../../../main/cpp/filter.cpp
${CMAKE_SOURCE_DIR}/../../../../../main/cpp/kiwixicu.cpp
${CMAKE_SOURCE_DIR}/../../../../../main/cpp/kiwixreader.cpp
${CMAKE_SOURCE_DIR}/../../../../../main/cpp/kiwixsearcher.cpp
${CMAKE_SOURCE_DIR}/../../../../../main/cpp/kiwixserver.cpp
${CMAKE_SOURCE_DIR}/../../../../../main/cpp/library.cpp
${CMAKE_SOURCE_DIR}/../../../../../main/cpp/manager.cpp
${CMAKE_SOURCE_DIR}/../../../../../main/cpp/utils.h
)
find_package(JNI)
if (JNI_FOUND)
message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
message (STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}")
endif()
include_directories(
/opt/hostedtoolcache/jdk/11.0.17/x64/include
/opt/hostedtoolcache/jdk/11.0.17/x64/include/linux
${CMAKE_SOURCE_DIR}/../../../../../main/cpp
${CMAKE_SOURCE_DIR}/../../../../../main/cpp/include/libkiwix
${CMAKE_SOURCE_DIR}/../../../../../main/cpp/include/libzim
${CMAKE_SOURCE_DIR}/../../../../../main/cpp/include/javah_generated
${CMAKE_SOURCE_DIR}/../../../../../main/cpp/include/utils
)
target_link_libraries(buildkiwix
LINK_PUBLIC
${CMAKE_SOURCE_DIR}/../../../../../../build/libkiwix.so
${CMAKE_SOURCE_DIR}/../../../../../../build/libzim.so
)

View File

@ -9,6 +9,14 @@ die()
exit 1 exit 1
} }
# This is for building wrapper so file
cmake .
make
# Copy generated .so file to build directory to run test cases
cd ../../../../../../../
./gradlew copyBuildKiwixSoFile
cd app/src/androidTests/java/org/kiwix/kiwixlib/
KIWIX_LIB_JAR=$1 KIWIX_LIB_JAR=$1
if [ -z $KIWIX_LIB_JAR ] if [ -z $KIWIX_LIB_JAR ]
@ -32,6 +40,10 @@ javac -g -d . -s . -cp "junit-4.13.jar:$KIWIX_LIB_JAR" test.java \
|| die "Compilation failed" || die "Compilation failed"
java -Djava.library.path="$KIWIX_LIB_DIR" \ java -Djava.library.path="$KIWIX_LIB_DIR" \
-cp "junit-4.13.jar:hamcrest-core-1.3.jar:$KIWIX_LIB_JAR:." \ -javaagent:jacoco-0.8.7/lib/jacocoagent.jar -cp "junit-4.13.jar:hamcrest-core-1.3.jar:$KIWIX_LIB_JAR:." \
org.junit.runner.JUnitCore test \ org.junit.runner.JUnitCore test \
|| die "Unit test failed" || die "Unit test failed"
java -jar jacoco-0.8.7/lib/jacococli.jar report jacoco.exec \
--classfiles org/kiwix/kiwixlib/ \
--html ../../../../../../../build/coverage-report --xml coverage.xml

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,3 @@
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
import org.junit.Test; import org.junit.Test;
@ -6,13 +5,15 @@ import static org.junit.Assert.*;
import org.kiwix.kiwixlib.*; import org.kiwix.kiwixlib.*;
public class test { public class test {
static { static {
System.loadLibrary("kiwix"); System.loadLibrary("kiwix");
} System.loadLibrary("zim");
System.loadLibrary("buildkiwix");
}
private static byte[] getFileContent(String path) private static byte[] getFileContent(String path)
throws IOException throws IOException
{ {
File file = new File(path); File file = new File(path);
DataInputStream in = new DataInputStream( DataInputStream in = new DataInputStream(
new BufferedInputStream( new BufferedInputStream(
@ -20,11 +21,11 @@ throws IOException
byte[] data = new byte[(int)file.length()]; byte[] data = new byte[(int)file.length()];
in.read(data); in.read(data);
return data; return data;
} }
private static byte[] getFileContentPartial(String path, int offset, int size) private static byte[] getFileContentPartial(String path, int offset, int size)
throws IOException throws IOException
{ {
File file = new File(path); File file = new File(path);
DataInputStream in = new DataInputStream( DataInputStream in = new DataInputStream(
new BufferedInputStream( new BufferedInputStream(
@ -33,21 +34,21 @@ throws IOException
in.skipBytes(offset); in.skipBytes(offset);
in.read(data, 0, size); in.read(data, 0, size);
return data; return data;
} }
private static String getTextFileContent(String path) private static String getTextFileContent(String path)
throws IOException throws IOException
{ {
return new String(getFileContent(path)); return new String(getFileContent(path));
} }
@Test @Test
public void testReader() public void testReader()
throws JNIKiwixException, IOException throws JNIKiwixException, IOException
{ {
JNIKiwixReader reader = new JNIKiwixReader("small.zim"); JNIKiwixReader reader = new JNIKiwixReader("small.zim");
assertEquals("Test ZIM file", reader.getTitle()); assertEquals("Test ZIM file", reader.getTitle());
assertEquals(45, reader.getFileSize()); // The file size is in KiB assertEquals(3, reader.getFileSize()); // The file size is in KiB
assertEquals("A/main.html", reader.getMainPage()); assertEquals("A/main.html", reader.getMainPage());
String s = getTextFileContent("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"),
@ -68,16 +69,16 @@ throws JNIKiwixException, IOException
assertNotEquals("", dai.filename); assertNotEquals("", dai.filename);
c = getFileContentPartial(dai.filename, (int)dai.offset, faviconData.length); c = getFileContentPartial(dai.filename, (int)dai.offset, faviconData.length);
assertTrue(Arrays.equals(faviconData, c)); assertTrue(Arrays.equals(faviconData, c));
} }
@Test @Test
public void testReaderByFd() public void testReaderByFd()
throws JNIKiwixException, IOException throws JNIKiwixException, IOException
{ {
FileInputStream fis = new FileInputStream("small.zim"); FileInputStream fis = new FileInputStream("small.zim");
JNIKiwixReader reader = new JNIKiwixReader(fis.getFD()); JNIKiwixReader reader = new JNIKiwixReader(fis.getFD());
assertEquals("Test ZIM file", reader.getTitle()); assertEquals("Test ZIM file", reader.getTitle());
assertEquals(45, reader.getFileSize()); // The file size is in KiB assertEquals(3, reader.getFileSize()); // The file size is in KiB
assertEquals("A/main.html", reader.getMainPage()); assertEquals("A/main.html", reader.getMainPage());
String s = getTextFileContent("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"),
@ -98,17 +99,17 @@ throws JNIKiwixException, IOException
assertNotEquals("", dai.filename); assertNotEquals("", dai.filename);
c = getFileContentPartial(dai.filename, (int)dai.offset, faviconData.length); c = getFileContentPartial(dai.filename, (int)dai.offset, faviconData.length);
assertTrue(Arrays.equals(faviconData, c)); assertTrue(Arrays.equals(faviconData, c));
} }
@Test @Test
public void testReaderWithAnEmbeddedArchive() public void testReaderWithAnEmbeddedArchive()
throws JNIKiwixException, IOException throws JNIKiwixException, IOException
{ {
File plainArchive = new File("small.zim"); File plainArchive = new File("small.zim");
FileInputStream fis = new FileInputStream("small.zim.embedded"); FileInputStream fis = new FileInputStream("small.zim.embedded");
JNIKiwixReader reader = new JNIKiwixReader(fis.getFD(), 8, plainArchive.length()); JNIKiwixReader reader = new JNIKiwixReader(fis.getFD(), 8, plainArchive.length());
assertEquals("Test ZIM file", reader.getTitle()); assertEquals("Test ZIM file", reader.getTitle());
assertEquals(45, reader.getFileSize()); // The file size is in KiB assertEquals(3, reader.getFileSize()); // The file size is in KiB
assertEquals("A/main.html", reader.getMainPage()); assertEquals("A/main.html", reader.getMainPage());
String s = getTextFileContent("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"),
@ -129,12 +130,12 @@ throws JNIKiwixException, IOException
assertNotEquals("", dai.filename); assertNotEquals("", dai.filename);
c = getFileContentPartial(dai.filename, (int)dai.offset, faviconData.length); c = getFileContentPartial(dai.filename, (int)dai.offset, faviconData.length);
assertTrue(Arrays.equals(faviconData, c)); assertTrue(Arrays.equals(faviconData, c));
} }
@Test @Test
public void testLibrary() 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 = getTextFileContent("catalog.xml"); String content = getTextFileContent("catalog.xml");
@ -147,14 +148,11 @@ throws IOException
assertEquals(book.getTags(), "unit;test"); assertEquals(book.getTags(), "unit;test");
assertEquals(book.getFaviconUrl(), "http://localhost/meta?name=favicon&content=small"); assertEquals(book.getFaviconUrl(), "http://localhost/meta?name=favicon&content=small");
assertEquals(book.getUrl(), "http://localhost/small.zim"); assertEquals(book.getUrl(), "http://localhost/small.zim");
} }
static static
public void main(String[] args) { public void main(String[] args) {
Library lib = new Library(); Library lib = new Library();
lib.getBookCount(true, true); lib.getBookCount(true, true);
} }
} }