diff --git a/.gitignore b/.gitignore index f4a4218ae..2d491d0fc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea/ *.swp subprojects/googletest-release* +*.class diff --git a/src/wrapper/java/meson.build b/src/wrapper/java/meson.build index 3f9e2d56b..034173045 100644 --- a/src/wrapper/java/meson.build +++ b/src/wrapper/java/meson.build @@ -44,8 +44,12 @@ kiwix_sources += jni_sources + [kiwix_jni] if 'java' in wrapper kiwix_jar = jar('kiwixlib', java_sources) + #junit_jar = files('org/kiwix/testing/junit-4.13.jar') + #test_jar = jar('testing', 'org/kiwix/testing/test.java', + # link_with: [kiwix_jar, junit_jar]) + #test('javatest', test_jar) endif -install_subdir('org', install_dir: 'kiwix-lib/java') +install_subdir('org', install_dir: 'kiwix-lib/java', exclude_directories: ['kiwix/testing']) install_subdir('res', install_dir: 'kiwix-lib') install_data('AndroidManifest.xml', install_dir: 'kiwix-lib') diff --git a/src/wrapper/java/org/kiwix/testing/compile_test.sh b/src/wrapper/java/org/kiwix/testing/compile_test.sh new file mode 100755 index 000000000..a98569935 --- /dev/null +++ b/src/wrapper/java/org/kiwix/testing/compile_test.sh @@ -0,0 +1,26 @@ +#!/usr/bin/bash + +# This script compile the unit test to test the java wrapper. +# This is not integrated in meson because ... this is not so easy. + + +KIWIX_LIB_JAR=$1 +if [ -z $KIWIX_LIB_JAR ] +then + echo "You must give the path to the kiwixlib.jar as first argument" + exit 1 +fi + +KIWIX_LIB_DIR=$2 +if [ -z $KIWIX_LIB_DIR ] +then + echo "You must give the path to directory containing libkiwix.so as second argument" + exit 1 +fi +TEST_SOURCE_DIR=$(dirname $(readlink -f $0)) + + +javac -g -d . -s . -cp $TEST_SOURCE_DIR/junit-4.13.jar:$KIWIX_LIB_JAR $TEST_SOURCE_DIR/test.java + +java -Djava.library.path=$KIWIX_LIB_DIR -cp $TEST_SOURCE_DIR/junit-4.13.jar:$TEST_SOURCE_DIR/hamcrest-core-1.3.jar:$KIWIX_LIB_JAR:. org.junit.runner.JUnitCore test + diff --git a/src/wrapper/java/org/kiwix/testing/hamcrest-core-1.3.jar b/src/wrapper/java/org/kiwix/testing/hamcrest-core-1.3.jar new file mode 100644 index 000000000..9d5fe16e3 Binary files /dev/null and b/src/wrapper/java/org/kiwix/testing/hamcrest-core-1.3.jar differ diff --git a/src/wrapper/java/org/kiwix/testing/junit-4.13.jar b/src/wrapper/java/org/kiwix/testing/junit-4.13.jar new file mode 100644 index 000000000..acc3c4320 Binary files /dev/null and b/src/wrapper/java/org/kiwix/testing/junit-4.13.jar differ diff --git a/src/wrapper/java/org/kiwix/testing/test.java b/src/wrapper/java/org/kiwix/testing/test.java new file mode 100644 index 000000000..671b0b46e --- /dev/null +++ b/src/wrapper/java/org/kiwix/testing/test.java @@ -0,0 +1,53 @@ + +import java.io.*; +import java.util.*; +import org.junit.Test; +import static org.junit.Assert.*; +import org.kiwix.kiwixlib.*; + +public class test { +static { + System.loadLibrary("kiwix"); +} + +private static String getCatalogContent() +throws IOException +{ + BufferedReader reader = new BufferedReader(new FileReader("catalog.xml")); + String line; + StringBuilder sb = new StringBuilder(); + while ((line = reader.readLine()) != null) + { + sb.append(line + "\n"); + } + reader.close(); + return sb.toString(); +} + +@Test +public void testSome() +throws IOException +{ + Library lib = new Library(); + Manager manager = new Manager(lib); + String content = getCatalogContent(); + manager.readOpds(content, "https://library.kiwix.org"); + assertEquals(lib.getBookCount(true, true), 10); + String[] bookIds = lib.getBooksIds(); + assertEquals(bookIds.length, 10); + Book book = lib.getBookById(bookIds[0]); + assertEquals(book.getTitle(), "Wikisource"); + assertEquals(book.getTags(), "wikisource;_category:wikisource;_pictures:no;_videos:no;_details:yes;_ftindex:yes"); + assertEquals(book.getFaviconUrl(), "https://library.kiwix.org/meta?name=favicon&content=wikisource_fr_all_nopic_2020-01"); + assertEquals(book.getUrl(), "http://download.kiwix.org/zim/wikisource/wikisource_fr_all_nopic_2020-01.zim.meta4"); +} + +static +public void main(String[] args) { + Library lib = new Library(); + lib.getBookCount(true, true); +} + + + +}