diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 653568d..885bddf 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -2,8 +2,9 @@ name: Pull requests on: pull_request: + push: branches: - - '**' + - main jobs: diff --git a/lib/src/main/cpp/libzim/search.cpp b/lib/src/main/cpp/libzim/search.cpp index 763bb2c..5e26433 100644 --- a/lib/src/main/cpp/libzim/search.cpp +++ b/lib/src/main/cpp/libzim/search.cpp @@ -37,7 +37,7 @@ DISPOSE METHOD(jobject, getResults, jint start, jint maxResults) { auto results = THIS->getResults(TO_C(start), TO_C(maxResults)); - auto obj = NEW_OBJECT("ork/kiwix/libzim/SearchIterator"); + auto obj = NEW_OBJECT("org/kiwix/libzim/SearchIterator"); SET_HANDLE(zim::SearchIterator, obj, results.begin()); // We have to set the nativeHandleEnd but no macro ease our work here. diff --git a/lib/src/main/cpp/libzim/search_iterator.cpp b/lib/src/main/cpp/libzim/search_iterator.cpp index 6c04c7d..65e1342 100644 --- a/lib/src/main/cpp/libzim/search_iterator.cpp +++ b/lib/src/main/cpp/libzim/search_iterator.cpp @@ -64,8 +64,8 @@ METHOD0(jboolean, hasNext) { } METHOD0(jobject, next) { - (*THIS)++; zim::Entry entry = **THIS; + (*THIS)++; return BUILD_WRAPPER("org/kiwix/libzim/Entry", entry); } diff --git a/lib/src/main/cpp/libzim/suggestion_iterator.cpp b/lib/src/main/cpp/libzim/suggestion_iterator.cpp index 5181ae1..2d2c410 100644 --- a/lib/src/main/cpp/libzim/suggestion_iterator.cpp +++ b/lib/src/main/cpp/libzim/suggestion_iterator.cpp @@ -49,8 +49,8 @@ METHOD0(jboolean, hasNext) { } METHOD0(jobject, next) { - (*THIS)++; zim::SuggestionItem item = **THIS; + (*THIS)++; return BUILD_WRAPPER("org/kiwix/libzim/SuggestionItem", item); } diff --git a/lib/src/main/cpp/libzim/suggestion_search.cpp b/lib/src/main/cpp/libzim/suggestion_search.cpp index 26fa783..27507d8 100644 --- a/lib/src/main/cpp/libzim/suggestion_search.cpp +++ b/lib/src/main/cpp/libzim/suggestion_search.cpp @@ -37,7 +37,7 @@ DISPOSE METHOD(jobject, getResults, jint start, jint maxResults) { auto results = THIS->getResults(TO_C(start), TO_C(maxResults)); - auto obj = NEW_OBJECT("ork/kiwix/libzim/SuggestionIterator"); + auto obj = NEW_OBJECT("org/kiwix/libzim/SuggestionIterator"); SET_HANDLE(zim::SuggestionIterator, obj, results.begin()); // We have to set the nativeHandleEnd but no macro ease our work here. diff --git a/lib/src/test/create_test_zimfiles b/lib/src/test/create_test_zimfiles index 4610b7d..ac60bcd 100755 --- a/lib/src/test/create_test_zimfiles +++ b/lib/src/test/create_test_zimfiles @@ -8,12 +8,13 @@ die() cd "$(dirname "$0")" rm -f small.zim -zimwriterfs --withoutFTIndex \ - -w main.html \ - -f favicon.png \ - -l en \ +zimwriterfs -w main.html \ + -n "Test" \ + -I favicon.png \ + -l eng \ -t "Test ZIM file" \ -d "N/A" \ + -L "Test File" \ -c "N/A" \ -p "N/A" \ small_zimfile_data \ diff --git a/lib/src/test/org/kiwix/test/libzim/TestQuery.java b/lib/src/test/org/kiwix/test/libzim/TestQuery.java new file mode 100644 index 0000000..5a45f96 --- /dev/null +++ b/lib/src/test/org/kiwix/test/libzim/TestQuery.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2022 Matthieu Gautier + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +package org.kiwix.test.libzim; + +import org.kiwix.libzim.Query; + +public class TestQuery +{ + private Query inner; + public Query inner() { return inner; } + public TestQuery(String query) { + inner = new Query(query); + } + + public TestQuery setQuery(String query) { + inner.setQuery(query); + return this; + } + + public TestQuery setGeorange(float latitude, float longitute, float distance) { + inner.setGeorange(latitude, latitude, distance); + return this; + } + +} diff --git a/lib/src/test/org/kiwix/test/libzim/TestSearch.java b/lib/src/test/org/kiwix/test/libzim/TestSearch.java new file mode 100644 index 0000000..d7c2ca1 --- /dev/null +++ b/lib/src/test/org/kiwix/test/libzim/TestSearch.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2022 Matthieu Gautier + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +package org.kiwix.test.libzim; + +import org.kiwix.libzim.Search; +import org.kiwix.libzim.SearchIterator; + +public class TestSearch +{ + private Search inner; + public TestSearch(Search _inner) { inner = _inner; } + public TestSearchIterator getResults(int start, int maxResults) { return new TestSearchIterator(inner.getResults(start, maxResults)); } + public long getEstimatedMatches() { return inner.getEstimatedMatches(); } +} diff --git a/lib/src/test/org/kiwix/test/libzim/TestSearchIterator.java b/lib/src/test/org/kiwix/test/libzim/TestSearchIterator.java new file mode 100644 index 0000000..f942c28 --- /dev/null +++ b/lib/src/test/org/kiwix/test/libzim/TestSearchIterator.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2022 Matthieu Gautier + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +package org.kiwix.test.libzim; + +import org.kiwix.libzim.SearchIterator; +import java.util.Iterator; + +public class TestSearchIterator implements Iterator +{ + private SearchIterator inner; + public TestSearchIterator(SearchIterator _inner) { inner = _inner; } + public String getPath() { return inner.getPath(); } + public String getTitle() { return inner.getTitle(); } + public int getScore() { return inner.getScore(); } + public String getSnippet() { return inner.getSnippet(); } + public int getWordCount() { return inner.getWordCount(); } + public int getFileIndex() { return inner.getFileIndex(); } + public int getSize() { return inner.getSize(); } + public String getZimId() { return inner.getZimId(); } + + public boolean hasNext() { return inner.hasNext(); } + public TestEntry next() { return new TestEntry(inner.next()); } +} diff --git a/lib/src/test/org/kiwix/test/libzim/TestSearcher.java b/lib/src/test/org/kiwix/test/libzim/TestSearcher.java new file mode 100644 index 0000000..2259f0d --- /dev/null +++ b/lib/src/test/org/kiwix/test/libzim/TestSearcher.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2022 Matthieu Gautier + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +package org.kiwix.test.libzim; + +import org.kiwix.libzim.Archive; +import org.kiwix.libzim.Searcher; +import org.kiwix.libzim.Search; +import java.util.stream.Stream; + +public class TestSearcher +{ + private Searcher inner; + public TestSearcher(TestArchive archive) throws Exception + { + inner = new Searcher(archive.inner()); + } + + public TestSearcher(TestArchive[] archives) throws Exception + { + inner = new Searcher( + Stream.of(archives).map(a -> a.inner()).toArray(Archive[]::new) + ); + } + + public TestSearcher addArchive(TestArchive archive) { + inner.addArchive(archive.inner()); + return this; + } + public TestSearch search(TestQuery query) { return new TestSearch(inner.search(query.inner())); } + public void setVerbose(boolean verbose) { inner.setVerbose(verbose); } + + public void dispose() { inner.dispose(); } +} diff --git a/lib/src/test/org/kiwix/test/libzim/TestSuggestionItem.java b/lib/src/test/org/kiwix/test/libzim/TestSuggestionItem.java new file mode 100644 index 0000000..b3f9ab3 --- /dev/null +++ b/lib/src/test/org/kiwix/test/libzim/TestSuggestionItem.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2022 Matthieu Gautier + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +package org.kiwix.test.libzim; + +import org.kiwix.libzim.SuggestionItem; + +public class TestSuggestionItem +{ + private SuggestionItem inner; + public TestSuggestionItem(SuggestionItem _inner) { inner = _inner; } + public String getTitle() { return inner.getTitle(); } + public String getPath() { return inner.getPath(); } + public String getSnippet() { return inner.getSnippet(); } + public boolean hasSnippet() { return inner.hasSnippet(); } +} diff --git a/lib/src/test/org/kiwix/test/libzim/TestSuggestionIterator.java b/lib/src/test/org/kiwix/test/libzim/TestSuggestionIterator.java new file mode 100644 index 0000000..89133fe --- /dev/null +++ b/lib/src/test/org/kiwix/test/libzim/TestSuggestionIterator.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2022 Matthieu Gautier + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +package org.kiwix.test.libzim; + +import org.kiwix.libzim.SuggestionIterator; +import java.util.Iterator; + +public class TestSuggestionIterator implements Iterator +{ + private SuggestionIterator inner; + public TestSuggestionIterator(SuggestionIterator _inner) { inner = _inner; } + public boolean hasNext() { return inner.hasNext(); } + public TestSuggestionItem next() { return new TestSuggestionItem(inner.next()); } +} diff --git a/lib/src/test/org/kiwix/test/libzim/TestSuggestionSearch.java b/lib/src/test/org/kiwix/test/libzim/TestSuggestionSearch.java new file mode 100644 index 0000000..093bff7 --- /dev/null +++ b/lib/src/test/org/kiwix/test/libzim/TestSuggestionSearch.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2022 Matthieu Gautier + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +package org.kiwix.test.libzim; + +import org.kiwix.libzim.SuggestionSearch; + +public class TestSuggestionSearch +{ + private SuggestionSearch inner; + public TestSuggestionSearch(SuggestionSearch _inner) { inner = _inner; } + + public TestSuggestionIterator getResults(int start, int maxResults) { return new TestSuggestionIterator(inner.getResults(start, maxResults)); } + public long getEstimatedMatches() { return inner.getEstimatedMatches(); } +} diff --git a/lib/src/test/org/kiwix/test/libzim/TestSuggestionSearcher.java b/lib/src/test/org/kiwix/test/libzim/TestSuggestionSearcher.java new file mode 100644 index 0000000..e91eba5 --- /dev/null +++ b/lib/src/test/org/kiwix/test/libzim/TestSuggestionSearcher.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2022 Matthieu Gautier + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +package org.kiwix.test.libzim; + +import org.kiwix.libzim.SuggestionSearcher; + +import java.io.FileDescriptor; + +public class TestSuggestionSearcher +{ + private SuggestionSearcher inner; + public TestSuggestionSearcher(TestArchive archive) throws Exception + { + inner = new SuggestionSearcher(archive.inner()); + } + + public TestSuggestionSearch suggest(String query) { return new TestSuggestionSearch(inner.suggest(query)); } + public void setVerbose(boolean verbose) { inner.setVerbose(verbose); } + public void dispose() { inner.dispose(); } +} diff --git a/lib/src/test/small.zim b/lib/src/test/small.zim index cb7072d..eb9674b 100644 Binary files a/lib/src/test/small.zim and b/lib/src/test/small.zim differ diff --git a/lib/src/test/small.zim.embedded b/lib/src/test/small.zim.embedded index a96f0bb..95c84b0 100644 Binary files a/lib/src/test/small.zim.embedded and b/lib/src/test/small.zim.embedded differ diff --git a/lib/src/test/test.java b/lib/src/test/test.java index 6528de2..7d4b25e 100644 --- a/lib/src/test/test.java +++ b/lib/src/test/test.java @@ -49,14 +49,18 @@ public class test { private void testArchive(TestArchive archive) throws IOException { // test the zim file main page title - assertEquals("Test ZIM file", archive.getMainEntry().getTitle()); - // test zim file size - assertEquals(4070, archive.getFilesize()); // The file size is in KiB + TestEntry mainPage = archive.getMainEntry(); + assertEquals("mainPage", mainPage.getTitle()); + assertEquals("Test ZIM file", mainPage.getItem(true).getTitle()); // test zim file main url - assertEquals("A/main.html", archive.getMainEntry().getPath()); + assertEquals("mainPage", mainPage.getPath()); + assertEquals("main.html", mainPage.getItem(true).getPath()); + + // test zim file size + assertEquals(66910, archive.getFilesize()); // The file size is in KiB // test zim file content byte[] mainData = getFileContent("small_zimfile_data/main.html"); - byte[] inZimMainData = archive.getEntryByPath("A/main.html").getItem(true).getData().getData(); + byte[] inZimMainData = archive.getEntryByPath("main.html").getItem(true).getData().getData(); assert(Arrays.equals(mainData, inZimMainData)); // test zim file icon @@ -177,30 +181,30 @@ public class test { bookmarkArray = lib.getBookmarks(true); assertEquals(0, bookmarkArray.length); } -/* + @Test public void testSearcher() throws Exception, ZimFileFormatException, JNIKiwixException { - Archive archive = new Archive("small.zim"); + TestArchive archive = new TestArchive("small.zim"); - Searcher searcher = new Searcher(archive); - Query query = new Query("test"); - Search search = searcher.search(query); + TestSearcher searcher = new TestSearcher(archive); + TestQuery query = new TestQuery("test"); + TestSearch search = searcher.search(query); int estimatedMatches = (int) search.getEstimatedMatches(); assertEquals(1, estimatedMatches); - SearchIterator iterator = search.getResults(0, estimatedMatches); + TestSearchIterator iterator = search.getResults(0, estimatedMatches); assertEquals("Test ZIM file", iterator.getTitle()); searcher.dispose(); - SuggestionSearcher suggestionSearcher = new SuggestionSearcher(archive); - SuggestionSearch suggestionSearch = suggestionSearcher.suggest("test"); + TestSuggestionSearcher suggestionSearcher = new TestSuggestionSearcher(archive); + TestSuggestionSearch suggestionSearch = suggestionSearcher.suggest("test"); int matches = (int) suggestionSearch.getEstimatedMatches(); assertEquals(1, matches); - SuggestionIterator results = suggestionSearch.getResults(1, matches); - SuggestionItem suggestionItem = results.next(); + TestSuggestionIterator results = suggestionSearch.getResults(0, matches); + TestSuggestionItem suggestionItem = results.next(); assertEquals("Test ZIM file", suggestionItem.getTitle()); suggestionSearcher.dispose(); } -*/ + static public void main(String[] args) { Library lib = new Library();