From 07defa835612d8926a6786d4fa7477365b33e95a Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Thu, 6 Apr 2023 18:59:06 +0530 Subject: [PATCH 01/11] Generating test binding and jacoco reports in build directory --- lib/build.gradle | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index 9c49ee1..7a051d5 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -275,19 +275,19 @@ task testSourceJar(type: Jar) { task compileTestFile(type: JavaCompile) { dependsOn testSourceJar source = file('src/test/test.java') - destinationDirectory = file('src/test/') + destinationDirectory = file("$buildDir") classpath = files("src/test/junit-4.13.jar" , "src/test/hamcrest-core-1.4.jar", "build/libs/test-sources.jar") } task runTests(type: JavaExec) { workingDir("$projectDir/src/test/") dependsOn compileTestFile - classpath = files('src/test/', 'src/test/java/', 'src/test/junit-4.13.jar', 'src/test/hamcrest-core-1.3.jar') + classpath = files("$buildDir", 'src/test/java/', 'src/test/junit-4.13.jar', 'src/test/hamcrest-core-1.3.jar') main = 'org.junit.runner.JUnitCore' args = ['test'] jvmArgs = [ '-Djava.library.path=' + buildDir.path, - '-javaagent:jacoco-0.8.7/lib/jacocoagent.jar' + '-javaagent:jacoco-0.8.7/lib/jacocoagent.jar=destfile=../../build/jacoco/jacoco.exec' ] } @@ -297,9 +297,9 @@ task createCodeCoverageReport(type: JavaExec) { classpath = files('src/test/', 'src/test/java/', 'src/test/junit-4.13.jar', 'src/test/hamcrest-core-1.3.jar', 'src/test/jacoco-0.8.7/lib/*') main = 'org.jacoco.cli.internal.Main' args = [ - 'report', 'jacoco.exec', + 'report', '../../build/jacoco/jacoco.exec', '--classfiles', 'java/org/kiwix/libkiwix/', '--classfiles', 'java/org/kiwix/libzim/', - '--html', '../../build/coverage-report', '--xml', 'coverage.xml' + '--html', '../../build/coverage-report', '--xml', '../../build/coverage.xml' ] } From d4f2f82e982391c2024a092484f62b78da6b7732 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 13 Jun 2023 17:19:40 +0200 Subject: [PATCH 02/11] Introduce test package. Jacoco don't track native methods, so our code coverage don't include all the native methods, and it is exactly want we want to check. By introducing a test package wrapping all native methods with a small java function, we have the coverage of the wrapping methods. --- lib/build.gradle | 4 +- .../org/kiwix/test/libzim/TestArchive.java | 97 +++++++++++++++++++ lib/src/test/test.java | 11 ++- 3 files changed, 105 insertions(+), 7 deletions(-) create mode 100644 lib/src/test/org/kiwix/test/libzim/TestArchive.java diff --git a/lib/build.gradle b/lib/build.gradle index 7a051d5..a58f976 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -274,7 +274,7 @@ task testSourceJar(type: Jar) { task compileTestFile(type: JavaCompile) { dependsOn testSourceJar - source = file('src/test/test.java') + source = file('src/test') destinationDirectory = file("$buildDir") classpath = files("src/test/junit-4.13.jar" , "src/test/hamcrest-core-1.4.jar", "build/libs/test-sources.jar") } @@ -298,7 +298,7 @@ task createCodeCoverageReport(type: JavaExec) { main = 'org.jacoco.cli.internal.Main' args = [ 'report', '../../build/jacoco/jacoco.exec', - '--classfiles', 'java/org/kiwix/libkiwix/', '--classfiles', 'java/org/kiwix/libzim/', + '--classfiles', 'java/org/kiwix', '--classfiles', '../../build/org/kiwix', '--html', '../../build/coverage-report', '--xml', '../../build/coverage.xml' ] } diff --git a/lib/src/test/org/kiwix/test/libzim/TestArchive.java b/lib/src/test/org/kiwix/test/libzim/TestArchive.java new file mode 100644 index 0000000..5546075 --- /dev/null +++ b/lib/src/test/org/kiwix/test/libzim/TestArchive.java @@ -0,0 +1,97 @@ +/* + * 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.ZimFileFormatException; +import org.kiwix.libzim.Entry; +import org.kiwix.libzim.Item; +import org.kiwix.libzim.EntryIterator; +import org.kiwix.libzim.Archive; +import java.io.FileDescriptor; +import org.kiwix.libzim.*; + +public class TestArchive +{ + private Archive inner; + + public TestArchive(String filename) throws ZimFileFormatException + { + inner = new Archive(filename); + } + + public TestArchive(FileDescriptor fd) throws ZimFileFormatException + { + inner = new Archive(fd); + } + + public TestArchive(FileDescriptor fd, long offset, long size) + throws ZimFileFormatException + { + inner = new Archive(fd, offset, size); + } + + public String getFilename() { return inner.getFilename(); } + public long getFilesize() { return inner.getFilesize(); } + public int getAllEntryCount() { return inner.getAllEntryCount(); } + public int getEntryCount() { return inner.getEntryCount(); } + public int getArticleCount() { return inner.getArticleCount(); } + public int getMediaCount() { return inner.getMediaCount(); } + public String getUuid() { return inner.getUuid(); } + public String getMetadata(String name) { return inner.getMetadata(name); } + public Item getMetadataItem(String name) { return inner.getMetadataItem(name); } + public String[] getMetadataKeys() { return inner.getMetadataKeys(); } + + public Item getIllustrationItem(int size) { return inner.getIllustrationItem(size); } + public boolean hasIllustration(int size) { return inner.hasIllustration(size); } + public long[] getIllustrationSizes() { return inner.getIllustrationSizes(); } + + public Entry getEntryByPath(String path) { return inner.getEntryByPath(path); } + public Entry getEntryByPath(int index) { return inner.getEntryByPath(index); } + public boolean hasEntryByPath(String path) { return inner.hasEntryByPath(path); } + + public Entry getEntryByTitle(String title) { return inner.getEntryByTitle(title); } + public Entry getEntryByTitle(int index) { return inner.getEntryByTitle(index); } + public boolean hasEntryByTitle(String title) { return inner.hasEntryByTitle(title); } + + public Entry getEntryByClusterOrder(int index) { return inner.getEntryByClusterOrder(index); } + + public Entry getMainEntry() { return inner.getMainEntry(); } + public boolean hasMainEntry() { return inner.hasMainEntry(); } + + public Entry getRandomEntry() { return inner.getRandomEntry(); } + + public boolean hasFulltextIndex() { return inner.hasFulltextIndex(); } + public boolean hasTitleIndex() { return inner.hasTitleIndex(); } + + public boolean hasChecksum() { return inner.hasChecksum(); } + public String getChecksum() { return inner.getChecksum(); } + public boolean check() { return inner.check(); } + + public boolean isMultiPart() { return inner.isMultiPart(); } + public boolean hasNewNamespaceScheme() { return inner.hasNewNamespaceScheme(); } + + public EntryIterator iterByPath() { return inner.iterByPath(); } + public EntryIterator iterByTitle() { return inner.iterByTitle(); } + public EntryIterator iterEfficient() { return inner.iterEfficient(); } + public EntryIterator findByPath(String path) { return inner.findByPath(path); } + public EntryIterator findByTitle(String path) { return inner.findByTitle(path); } + + public void dispose() { inner.dispose(); } +} diff --git a/lib/src/test/test.java b/lib/src/test/test.java index a95a1e2..8602aa2 100644 --- a/lib/src/test/test.java +++ b/lib/src/test/test.java @@ -7,6 +7,7 @@ import static org.junit.Assert.*; import org.kiwix.libkiwix.*; import org.kiwix.libzim.*; +import org.kiwix.test.libzim.*; public class test { static { @@ -44,7 +45,7 @@ public class test { return new String(getFileContent(path)); } - private void testArchive(Archive archive) + private void testArchive(TestArchive archive) throws IOException { // test the zim file main page title assertEquals("Test ZIM file", archive.getMainEntry().getTitle()); @@ -74,14 +75,14 @@ public class test { @Test public void testArchiveDirect() throws JNIKiwixException, IOException, ZimFileFormatException { - Archive archive = new Archive("small.zim"); + TestArchive archive = new TestArchive("small.zim"); testArchive(archive); archive.dispose(); // test reader with invalid zim file String zimFile = "test.zim"; try { - Archive archive1 = new Archive(zimFile); + TestArchive archive1 = new TestArchive(zimFile); fail("ERROR: Archive created with invalid Zim file!"); } catch (ZimFileFormatException zimFileFormatException) { assertEquals("Cannot open zimfile " + zimFile, zimFileFormatException.getMessage()); @@ -92,7 +93,7 @@ public class test { public void testArchiveByFd() throws JNIKiwixException, IOException, ZimFileFormatException { FileInputStream fis = new FileInputStream("small.zim"); - Archive archive = new Archive(fis.getFD()); + TestArchive archive = new TestArchive(fis.getFD()); testArchive(archive); archive.dispose(); } @@ -102,7 +103,7 @@ public class test { throws JNIKiwixException, IOException, ZimFileFormatException { File plainArchive = new File("small.zim"); FileInputStream fis = new FileInputStream("small.zim.embedded"); - Archive archive = new Archive(fis.getFD(), 8, plainArchive.length()); + TestArchive archive = new TestArchive(fis.getFD(), 8, plainArchive.length()); testArchive(archive); archive.dispose(); } From ff6469a34f0c21d18b6f001f5ff3e049ba9aa4b2 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 13 Jun 2023 17:38:18 +0200 Subject: [PATCH 03/11] Introduce TestEntry.java --- .../org/kiwix/test/libzim/TestArchive.java | 15 ++++---- .../test/org/kiwix/test/libzim/TestEntry.java | 36 +++++++++++++++++++ 2 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 lib/src/test/org/kiwix/test/libzim/TestEntry.java diff --git a/lib/src/test/org/kiwix/test/libzim/TestArchive.java b/lib/src/test/org/kiwix/test/libzim/TestArchive.java index 5546075..3bd447f 100644 --- a/lib/src/test/org/kiwix/test/libzim/TestArchive.java +++ b/lib/src/test/org/kiwix/test/libzim/TestArchive.java @@ -20,7 +20,6 @@ package org.kiwix.test.libzim; import org.kiwix.libzim.ZimFileFormatException; -import org.kiwix.libzim.Entry; import org.kiwix.libzim.Item; import org.kiwix.libzim.EntryIterator; import org.kiwix.libzim.Archive; @@ -62,20 +61,20 @@ public class TestArchive public boolean hasIllustration(int size) { return inner.hasIllustration(size); } public long[] getIllustrationSizes() { return inner.getIllustrationSizes(); } - public Entry getEntryByPath(String path) { return inner.getEntryByPath(path); } - public Entry getEntryByPath(int index) { return inner.getEntryByPath(index); } + public TestEntry getEntryByPath(String path) { return new TestEntry(inner.getEntryByPath(path)); } + public TestEntry getEntryByPath(int index) { return new TestEntry(inner.getEntryByPath(index)); } public boolean hasEntryByPath(String path) { return inner.hasEntryByPath(path); } - public Entry getEntryByTitle(String title) { return inner.getEntryByTitle(title); } - public Entry getEntryByTitle(int index) { return inner.getEntryByTitle(index); } + public TestEntry getEntryByTitle(String title) { return new TestEntry(inner.getEntryByTitle(title)); } + public TestEntry getEntryByTitle(int index) { return new TestEntry(inner.getEntryByTitle(index)); } public boolean hasEntryByTitle(String title) { return inner.hasEntryByTitle(title); } - public Entry getEntryByClusterOrder(int index) { return inner.getEntryByClusterOrder(index); } + public TestEntry getEntryByClusterOrder(int index) { return new TestEntry(inner.getEntryByClusterOrder(index)); } - public Entry getMainEntry() { return inner.getMainEntry(); } + public TestEntry getMainEntry() { return new TestEntry(inner.getMainEntry()); } public boolean hasMainEntry() { return inner.hasMainEntry(); } - public Entry getRandomEntry() { return inner.getRandomEntry(); } + public TestEntry getRandomEntry() { return new TestEntry(inner.getRandomEntry()); } public boolean hasFulltextIndex() { return inner.hasFulltextIndex(); } public boolean hasTitleIndex() { return inner.hasTitleIndex(); } diff --git a/lib/src/test/org/kiwix/test/libzim/TestEntry.java b/lib/src/test/org/kiwix/test/libzim/TestEntry.java new file mode 100644 index 0000000..188f92d --- /dev/null +++ b/lib/src/test/org/kiwix/test/libzim/TestEntry.java @@ -0,0 +1,36 @@ +/* + * 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.Entry; +import org.kiwix.libzim.Item; + +public class TestEntry +{ + private Entry inner; + public TestEntry(Entry _inner) { inner = _inner; } + public boolean isRedirect() { return inner.isRedirect(); } + public String getTitle() { return inner.getTitle(); } + public String getPath() { return inner.getPath(); } + + public Item getItem(boolean follow) { return inner.getItem(follow); } + public Item getRedirect() { return inner.getRedirect(); } + public TestEntry getRedirectEntry() { return new TestEntry(inner.getRedirectEntry()); } +} From 80f692020112ee1a601bb2f238700ff0f12825f9 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 13 Jun 2023 17:46:21 +0200 Subject: [PATCH 04/11] Introduce TestItem.java --- .../org/kiwix/test/libzim/TestArchive.java | 5 +-- .../test/org/kiwix/test/libzim/TestEntry.java | 5 +-- .../test/org/kiwix/test/libzim/TestItem.java | 38 +++++++++++++++++++ lib/src/test/test.java | 2 +- 4 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 lib/src/test/org/kiwix/test/libzim/TestItem.java diff --git a/lib/src/test/org/kiwix/test/libzim/TestArchive.java b/lib/src/test/org/kiwix/test/libzim/TestArchive.java index 3bd447f..9f3006f 100644 --- a/lib/src/test/org/kiwix/test/libzim/TestArchive.java +++ b/lib/src/test/org/kiwix/test/libzim/TestArchive.java @@ -20,7 +20,6 @@ package org.kiwix.test.libzim; import org.kiwix.libzim.ZimFileFormatException; -import org.kiwix.libzim.Item; import org.kiwix.libzim.EntryIterator; import org.kiwix.libzim.Archive; import java.io.FileDescriptor; @@ -54,10 +53,10 @@ public class TestArchive public int getMediaCount() { return inner.getMediaCount(); } public String getUuid() { return inner.getUuid(); } public String getMetadata(String name) { return inner.getMetadata(name); } - public Item getMetadataItem(String name) { return inner.getMetadataItem(name); } + public TestItem getMetadataItem(String name) { return new TestItem(inner.getMetadataItem(name)); } public String[] getMetadataKeys() { return inner.getMetadataKeys(); } - public Item getIllustrationItem(int size) { return inner.getIllustrationItem(size); } + public TestItem getIllustrationItem(int size) { return new TestItem(inner.getIllustrationItem(size)); } public boolean hasIllustration(int size) { return inner.hasIllustration(size); } public long[] getIllustrationSizes() { return inner.getIllustrationSizes(); } diff --git a/lib/src/test/org/kiwix/test/libzim/TestEntry.java b/lib/src/test/org/kiwix/test/libzim/TestEntry.java index 188f92d..559f8c4 100644 --- a/lib/src/test/org/kiwix/test/libzim/TestEntry.java +++ b/lib/src/test/org/kiwix/test/libzim/TestEntry.java @@ -20,7 +20,6 @@ package org.kiwix.test.libzim; import org.kiwix.libzim.Entry; -import org.kiwix.libzim.Item; public class TestEntry { @@ -30,7 +29,7 @@ public class TestEntry public String getTitle() { return inner.getTitle(); } public String getPath() { return inner.getPath(); } - public Item getItem(boolean follow) { return inner.getItem(follow); } - public Item getRedirect() { return inner.getRedirect(); } + public TestItem getItem(boolean follow) { return new TestItem(inner.getItem(follow)); } + public TestItem getRedirect() { return new TestItem(inner.getRedirect()); } public TestEntry getRedirectEntry() { return new TestEntry(inner.getRedirectEntry()); } } diff --git a/lib/src/test/org/kiwix/test/libzim/TestItem.java b/lib/src/test/org/kiwix/test/libzim/TestItem.java new file mode 100644 index 0000000..6928651 --- /dev/null +++ b/lib/src/test/org/kiwix/test/libzim/TestItem.java @@ -0,0 +1,38 @@ +/* + * 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.Item; +import org.kiwix.libzim.Blob; +import org.kiwix.libzim.DirectAccessInfo; + +public class TestItem +{ + private Item inner; + public TestItem(Item _inner) { inner = _inner; } + public String getTitle() { return inner.getTitle(); } + public String getPath() { return inner.getPath(); } + public String getMimetype() { return inner.getMimetype(); } + + public Blob getData() { return inner.getData(); } + public long getSize() { return inner.getSize(); } + + public DirectAccessInfo getDirectAccessInformation() { return inner.getDirectAccessInformation(); } +} diff --git a/lib/src/test/test.java b/lib/src/test/test.java index 8602aa2..22d6325 100644 --- a/lib/src/test/test.java +++ b/lib/src/test/test.java @@ -61,7 +61,7 @@ public class test { // test zim file icon assertEquals(true, archive.hasIllustration(48)); byte[] faviconData = getFileContent("small_zimfile_data/favicon.png"); - Item item = archive.getIllustrationItem(48); + TestItem item = archive.getIllustrationItem(48); assertEquals(faviconData.length, item.getSize()); assert(Arrays.equals(faviconData, item.getData().getData())); From ce1f216108b37e7245e4a2eb1a8f985a1c342a39 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 13 Jun 2023 17:49:02 +0200 Subject: [PATCH 05/11] Introduce TestBlob.java --- .../test/org/kiwix/test/libzim/TestBlob.java | 30 +++++++++++++++++++ .../test/org/kiwix/test/libzim/TestItem.java | 3 +- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 lib/src/test/org/kiwix/test/libzim/TestBlob.java diff --git a/lib/src/test/org/kiwix/test/libzim/TestBlob.java b/lib/src/test/org/kiwix/test/libzim/TestBlob.java new file mode 100644 index 0000000..afbe604 --- /dev/null +++ b/lib/src/test/org/kiwix/test/libzim/TestBlob.java @@ -0,0 +1,30 @@ +/* + * 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.Blob; + +public class TestBlob +{ + private Blob inner; + TestBlob(Blob _inner) { inner = _inner; } + public byte[] getData() { return inner.getData(); } + public long size() { return inner.size(); } +} diff --git a/lib/src/test/org/kiwix/test/libzim/TestItem.java b/lib/src/test/org/kiwix/test/libzim/TestItem.java index 6928651..790e457 100644 --- a/lib/src/test/org/kiwix/test/libzim/TestItem.java +++ b/lib/src/test/org/kiwix/test/libzim/TestItem.java @@ -20,7 +20,6 @@ package org.kiwix.test.libzim; import org.kiwix.libzim.Item; -import org.kiwix.libzim.Blob; import org.kiwix.libzim.DirectAccessInfo; public class TestItem @@ -31,7 +30,7 @@ public class TestItem public String getPath() { return inner.getPath(); } public String getMimetype() { return inner.getMimetype(); } - public Blob getData() { return inner.getData(); } + public TestBlob getData() { return new TestBlob(inner.getData()); } public long getSize() { return inner.getSize(); } public DirectAccessInfo getDirectAccessInformation() { return inner.getDirectAccessInformation(); } From 57fb755a0262b770f65eec363487103774e9d22f Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 14 Jun 2023 10:11:49 +0200 Subject: [PATCH 06/11] Latest libzim nigthly is build on bionic. --- lib/build.gradle | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index a58f976..901541b 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -86,7 +86,7 @@ task downloadLibzimSoAndHeaderFiles(type: Download) { libzim_base_url + '/libzim_android-arm64.tar.gz', libzim_base_url + '/libzim_android-x86.tar.gz', libzim_base_url + '/libzim_android-x86_64.tar.gz', - libzim_base_url + '/libzim_linux-x86_64.tar.gz' + libzim_base_url + '/libzim_linux-x86_64-bionic.tar.gz' ]) dest buildDir overwrite true @@ -106,7 +106,7 @@ task unzipLibzim(type: Copy) { from tarTree(buildDir.path + "/libzim_android-x86_64.tar.gz") into buildDir // unzip linux x86_64 - from tarTree(buildDir.path + "/libzim_linux-x86_64.tar.gz") + from tarTree(buildDir.path + "/libzim_linux-x86_64-bionic.tar.gz") into buildDir } @@ -147,8 +147,8 @@ task copyLibzimHeaderAndSoFiles(type: Copy) { copy { // copying linux_x86_64 so file - project.ext.set("libzim_version", getFileFromFolder(buildDir.path + "/libzim_linux-x86_64/lib/x86_64-linux-gnu/")) - from buildDir.path + "/libzim_linux-x86_64/lib/x86_64-linux-gnu/" + libzim_version + project.ext.set("libzim_version", getFileFromFolder(buildDir.path + "/libzim_linux-x86_64-bionic/lib/x86_64-linux-gnu/")) + from buildDir.path + "/libzim_linux-x86_64-bionic/lib/x86_64-linux-gnu/" + libzim_version into buildDir.path } } From 88441468c35ce286704dfdf9e2fff30c3643febb Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 14 Jun 2023 10:12:11 +0200 Subject: [PATCH 07/11] [CI] Move release workflow to ubuntu 20.04 --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8118c2c..8c91aa1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,7 +12,7 @@ on: jobs: publish: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 From 7c7f56d0de389a7c2aa8ec8d3590d406b860ef0a Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 14 Jun 2023 10:12:42 +0200 Subject: [PATCH 08/11] Rename `renameFolders` to `removeDateFromFolderName` --- lib/build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index 901541b..0c5dc79 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -111,7 +111,7 @@ task unzipLibzim(type: Copy) { } task renameLibzimFolders() { - renameFolders(buildDir.path,"libzim_") + removeDateFromFolderName(buildDir.path,"libzim_") } task copyLibzimHeaderAndSoFiles(type: Copy) { @@ -175,10 +175,10 @@ task downloadLibkiwixSoAndHeaderFiles(type: Download) { } task renameLibkiwixFolders() { - renameFolders(buildDir.path,"libkiwix_") + removeDateFromFolderName(buildDir.path,"libkiwix_") } -static void renameFolders(String path, String startWith) { +static void removeDateFromFolderName(String path, String startWith) { File directory = new File(path) if (directory.exists() && directory.isDirectory()) { Arrays.stream(directory.listFiles()) From f84d951e971cfd779e83c768461e729743d020b2 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 14 Jun 2023 14:15:46 +0200 Subject: [PATCH 09/11] Introduce TestEntryIterator.java --- .../org/kiwix/test/libzim/TestArchive.java | 10 +++--- .../kiwix/test/libzim/TestEntryIterator.java | 33 +++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 lib/src/test/org/kiwix/test/libzim/TestEntryIterator.java diff --git a/lib/src/test/org/kiwix/test/libzim/TestArchive.java b/lib/src/test/org/kiwix/test/libzim/TestArchive.java index 9f3006f..25b7d3b 100644 --- a/lib/src/test/org/kiwix/test/libzim/TestArchive.java +++ b/lib/src/test/org/kiwix/test/libzim/TestArchive.java @@ -85,11 +85,11 @@ public class TestArchive public boolean isMultiPart() { return inner.isMultiPart(); } public boolean hasNewNamespaceScheme() { return inner.hasNewNamespaceScheme(); } - public EntryIterator iterByPath() { return inner.iterByPath(); } - public EntryIterator iterByTitle() { return inner.iterByTitle(); } - public EntryIterator iterEfficient() { return inner.iterEfficient(); } - public EntryIterator findByPath(String path) { return inner.findByPath(path); } - public EntryIterator findByTitle(String path) { return inner.findByTitle(path); } + public TestEntryIterator iterByPath() { return new TestEntryIterator(inner.iterByPath()); } + public TestEntryIterator iterByTitle() { return new TestEntryIterator(inner.iterByTitle()); } + public TestEntryIterator iterEfficient() { return new TestEntryIterator(inner.iterEfficient()); } + public TestEntryIterator findByPath(String path) { return new TestEntryIterator(inner.findByPath(path)); } + public TestEntryIterator findByTitle(String path) { return new TestEntryIterator(inner.findByTitle(path)); } public void dispose() { inner.dispose(); } } diff --git a/lib/src/test/org/kiwix/test/libzim/TestEntryIterator.java b/lib/src/test/org/kiwix/test/libzim/TestEntryIterator.java new file mode 100644 index 0000000..2634cd4 --- /dev/null +++ b/lib/src/test/org/kiwix/test/libzim/TestEntryIterator.java @@ -0,0 +1,33 @@ +/* + * 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 java.util.Iterator; +import org.kiwix.libzim.EntryIterator; + +public class TestEntryIterator implements Iterator +{ + private EntryIterator inner; + + public TestEntryIterator(EntryIterator _inner) { inner = _inner; } + + public boolean hasNext() { return inner.hasNext(); } + public TestEntry next() { return new TestEntry(inner.next()); } +} From 83a6429565b9afb1111be752c959926c9f3ef189 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 14 Jun 2023 14:49:10 +0200 Subject: [PATCH 10/11] Introduce TestBook, TestLibrary, TestManager and TestServer. --- .../org/kiwix/test/libkiwix/TestBook.java | 40 ++++++++++++ .../org/kiwix/test/libkiwix/TestLibrary.java | 62 +++++++++++++++++++ .../org/kiwix/test/libkiwix/TestManager.java | 43 +++++++++++++ .../org/kiwix/test/libkiwix/TestServer.java | 41 ++++++++++++ .../org/kiwix/test/libzim/TestArchive.java | 2 + lib/src/test/test.java | 21 ++++--- 6 files changed, 199 insertions(+), 10 deletions(-) create mode 100644 lib/src/test/org/kiwix/test/libkiwix/TestBook.java create mode 100644 lib/src/test/org/kiwix/test/libkiwix/TestLibrary.java create mode 100644 lib/src/test/org/kiwix/test/libkiwix/TestManager.java create mode 100644 lib/src/test/org/kiwix/test/libkiwix/TestServer.java diff --git a/lib/src/test/org/kiwix/test/libkiwix/TestBook.java b/lib/src/test/org/kiwix/test/libkiwix/TestBook.java new file mode 100644 index 0000000..7d15d9a --- /dev/null +++ b/lib/src/test/org/kiwix/test/libkiwix/TestBook.java @@ -0,0 +1,40 @@ + +package org.kiwix.test.libkiwix; + +import org.kiwix.libkiwix.Book; +import org.kiwix.libkiwix.Illustration; +import org.kiwix.test.libzim.TestArchive; + +public class TestBook +{ + private Book inner; + public TestBook() { inner = new Book(); } + public TestBook(Book _inner) { inner = _inner; } + public Book inner() { return inner; } + + public void update(TestBook book) { inner.update(book.inner()); } + public void update(TestArchive archive) { inner.update(archive.inner()); } + + public String getId() { return inner.getId(); } + public String getPath() { return inner.getPath(); } + public String getHumanReadableIdFromPath() { return inner.getHumanReadableIdFromPath(); } + public boolean isPathValid() { return inner.isPathValid(); } + public String getTitle() { return inner.getTitle(); } + public String getDescription() { return inner.getDescription(); } + public String getLanguage() { return inner.getLanguage(); } + public String getCreator() { return inner.getCreator(); } + public String getPublisher() { return inner.getPublisher(); } + public String getDate() { return inner.getDate(); } + public String getUrl() { return inner.getUrl(); } + public String getName() { return inner.getName(); } + public String getFlavour() { return inner.getFlavour(); } + public String getCategory() { return inner.getCategory(); } + public String getTags() { return inner.getTags(); } + public String getTagStr(String tagName) { return inner.getTagStr(tagName); } + public long getArticleCount() { return inner.getArticleCount(); } + public long getMediaCount() { return inner.getMediaCount(); } + public long getSize() { return inner.getSize(); } + + public Illustration[] getIllustrations() { return inner.getIllustrations(); } + public Illustration getIllustration(int size) { return inner.getIllustration(size); } +} diff --git a/lib/src/test/org/kiwix/test/libkiwix/TestLibrary.java b/lib/src/test/org/kiwix/test/libkiwix/TestLibrary.java new file mode 100644 index 0000000..163b9d3 --- /dev/null +++ b/lib/src/test/org/kiwix/test/libkiwix/TestLibrary.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2019-2020 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.libkiwix; + +import org.kiwix.libkiwix.Library; +import org.kiwix.test.libzim.TestArchive; +import org.kiwix.libzim.Searcher; +import org.kiwix.libkiwix.Filter; +import org.kiwix.libkiwix.Book; +import org.kiwix.libkiwix.JNIKiwixException; +import org.kiwix.libkiwix.Bookmark; + +public class TestLibrary +{ + private Library inner; + public Library inner() { return inner; } + public TestLibrary() { inner = new Library(); } + public TestLibrary(Library _inner) { inner = _inner; } + public boolean addBook(TestBook book) throws JNIKiwixException { return inner.addBook(book.inner()); } + + public TestBook getBookById(String id) { return new TestBook(inner.getBookById(id)); } + + public TestArchive getArchiveById(String id) { return new TestArchive(inner.getArchiveById(id)); } + //public native Searcher getSearcherById(String id); + //public native Searcher getSearcherByIds(String ids[]); + + public boolean removeBookById(String id) { return inner.removeBookById(id); } + + public boolean writeToFile(String path) { return inner.writeToFile(path); } + public boolean writeBookmarksToFile(String path) { return inner.writeBookmarksToFile(path); } + + public int getBookCount(boolean localBooks, boolean remoteBooks) { return inner.getBookCount(localBooks, remoteBooks); } + + public String[] getBooksIds() { return inner.getBooksIds(); } + public String[] filter(Filter filter) { return inner.filter(filter); } + + public String[] getBooksLanguages() { return inner.getBooksLanguages(); } + public String[] getBooksCategories() { return inner.getBooksCategories(); } + public String[] getBooksCreators() { return inner.getBooksCreators(); } + public String[] getBooksPublishers() { return inner.getBooksPublishers(); } + + public void addBookmark(Bookmark bookmark) { inner.addBookmark(bookmark); } + public boolean removeBookmark(String zimId, String url) { return inner.removeBookmark(zimId, url); } + public Bookmark[] getBookmarks(boolean onlyValidBookmarks) { return inner.getBookmarks(onlyValidBookmarks); } +} diff --git a/lib/src/test/org/kiwix/test/libkiwix/TestManager.java b/lib/src/test/org/kiwix/test/libkiwix/TestManager.java new file mode 100644 index 0000000..bfd1729 --- /dev/null +++ b/lib/src/test/org/kiwix/test/libkiwix/TestManager.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2020 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.libkiwix; + +import org.kiwix.libkiwix.Manager; + +public class TestManager +{ + private Manager inner; + + public TestManager(Manager _inner) { inner = _inner; } + + public boolean readFile(String path) { return inner.readFile(path); } + public boolean readXml(String content, String libraryPath) { return inner.readXml(content, libraryPath); } + public boolean readOpds(String content, String urlHost) { return inner.readOpds(content, urlHost); } + public boolean readBookmarkFile(String path) { return inner.readBookmarkFile(path); } + public String addBookFromPath(String pathToOpen, + String pathToSave, + String url, + boolean checkMetaData) + { return inner.addBookFromPath(pathToOpen, pathToSave, url, checkMetaData); } + + public TestManager(TestLibrary library) { + inner = new Manager(library.inner()); + } +} diff --git a/lib/src/test/org/kiwix/test/libkiwix/TestServer.java b/lib/src/test/org/kiwix/test/libkiwix/TestServer.java new file mode 100644 index 0000000..e4cb19d --- /dev/null +++ b/lib/src/test/org/kiwix/test/libkiwix/TestServer.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2019 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.libkiwix; + +import org.kiwix.libkiwix.Library; +import org.kiwix.libkiwix.Server; + +public class TestServer +{ + private Server inner; + + public void setRoot(String root) { inner.setRoot(root); } + public void setAddress(String address) { inner.setAddress(address); } + public void setPort(int port) { inner.setPort(port); } + public void setNbThreads(int nbTreads) { inner.setNbThreads(nbTreads); } + public void setTaskbar(boolean withTaskBar, boolean witLibraryButton) { inner.setTaskbar(withTaskBar, witLibraryButton); } + public void setBlockExternalLinks(boolean blockExternalLinks) { inner.setBlockExternalLinks(blockExternalLinks); } + public boolean start() { return inner.start(); } + public void stop() { inner.stop(); } + public TestServer(TestLibrary library) + { + inner = new Server(library.inner()); + } +} diff --git a/lib/src/test/org/kiwix/test/libzim/TestArchive.java b/lib/src/test/org/kiwix/test/libzim/TestArchive.java index 25b7d3b..1b12839 100644 --- a/lib/src/test/org/kiwix/test/libzim/TestArchive.java +++ b/lib/src/test/org/kiwix/test/libzim/TestArchive.java @@ -28,7 +28,9 @@ import org.kiwix.libzim.*; public class TestArchive { private Archive inner; + public Archive inner() { return inner; } + public TestArchive(Archive _inner) { inner = _inner; } public TestArchive(String filename) throws ZimFileFormatException { inner = new Archive(filename); diff --git a/lib/src/test/test.java b/lib/src/test/test.java index 22d6325..afc85ce 100644 --- a/lib/src/test/test.java +++ b/lib/src/test/test.java @@ -8,6 +8,7 @@ import static org.junit.Assert.*; import org.kiwix.libkiwix.*; import org.kiwix.libzim.*; import org.kiwix.test.libzim.*; +import org.kiwix.test.libkiwix.*; public class test { static { @@ -111,8 +112,8 @@ public class test { @Test public void testLibrary() throws IOException { - Library lib = new Library(); - Manager manager = new Manager(lib); + TestLibrary lib = new TestLibrary(); + TestManager manager = new TestManager(lib); String content = getTextFileContent("catalog.xml"); manager.readOpds(content, "http://localhost"); assertEquals(lib.getBookCount(true, true), 1); @@ -120,7 +121,7 @@ public class test { assertEquals(bookIds.length, 1); lib.filter(new Filter().local(true)); - Book book = lib.getBookById(bookIds[0]); + TestBook book = lib.getBookById(bookIds[0]); assertEquals(book.getTitle(), "Test ZIM file"); assertEquals(book.getTags(), "unit;test"); assertEquals(book.getIllustration(48).width(), 48); @@ -135,22 +136,22 @@ public class test { @Test public void testServer() throws ZimFileFormatException, JNIKiwixException { - Archive archive = new Archive("small.zim"); - Library lib = new Library(); - Book book = new Book(); + TestArchive archive = new TestArchive("small.zim"); + TestLibrary lib = new TestLibrary(); + TestBook book = new TestBook(); book.update(archive); lib.addBook(book); assertEquals(1, lib.getBookCount(true, true)); - Server server = new Server(lib); + TestServer server = new TestServer(lib); server.setPort(8080); assertEquals(true, server.start()); } @Test public void testBookMark() throws ZimFileFormatException, JNIKiwixException { - Archive archive = new Archive("small.zim"); - Library lib = new Library(); - Book book = new Book(); + TestArchive archive = new TestArchive("small.zim"); + TestLibrary lib = new TestLibrary(); + TestBook book = new TestBook(); book.update(archive); lib.addBook(book); Bookmark bookmark = new Bookmark(); From 52cc2e48a87aa219f4f77041d4a53ec644fa8f43 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 14 Jun 2023 15:07:38 +0200 Subject: [PATCH 11/11] Introduce TestBookmark. --- .../org/kiwix/test/libkiwix/TestBookmark.java | 44 +++++++++++++++++++ .../org/kiwix/test/libkiwix/TestLibrary.java | 8 ++-- lib/src/test/test.java | 4 +- 3 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 lib/src/test/org/kiwix/test/libkiwix/TestBookmark.java diff --git a/lib/src/test/org/kiwix/test/libkiwix/TestBookmark.java b/lib/src/test/org/kiwix/test/libkiwix/TestBookmark.java new file mode 100644 index 0000000..ed71704 --- /dev/null +++ b/lib/src/test/org/kiwix/test/libkiwix/TestBookmark.java @@ -0,0 +1,44 @@ +/* + * 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.libkiwix; + +import org.kiwix.libkiwix.Bookmark; + +public class TestBookmark +{ + private Bookmark inner; + public Bookmark inner() { return inner; } + public TestBookmark() { inner = new Bookmark(); } + public TestBookmark(Bookmark _inner) { inner = _inner; } + + public void setBookId(String bookId) { inner.setBookId(bookId); } + public void setBookTitle(String bookTitle) { inner.setBookTitle(bookTitle); } + public void setUrl(String url) { inner.setUrl(url); } + public void setTitle(String title) { inner.setTitle(title); } + public void setLanguage(String language) { inner.setLanguage(language); } + public void setDate(String date) { inner.setDate(date); } + + public String getBookId() { return inner.getBookId(); } + public String getBookTitle() { return inner.getBookTitle(); } + public String getUrl() { return inner.getUrl(); } + public String getTitle() { return inner.getTitle(); } + public String getLanguage() { return inner.getLanguage(); } + public String getDate() { return inner.getDate(); } +} diff --git a/lib/src/test/org/kiwix/test/libkiwix/TestLibrary.java b/lib/src/test/org/kiwix/test/libkiwix/TestLibrary.java index 163b9d3..3402354 100644 --- a/lib/src/test/org/kiwix/test/libkiwix/TestLibrary.java +++ b/lib/src/test/org/kiwix/test/libkiwix/TestLibrary.java @@ -21,11 +21,11 @@ package org.kiwix.test.libkiwix; import org.kiwix.libkiwix.Library; import org.kiwix.test.libzim.TestArchive; +import org.kiwix.test.libkiwix.TestBookmark; import org.kiwix.libzim.Searcher; import org.kiwix.libkiwix.Filter; -import org.kiwix.libkiwix.Book; import org.kiwix.libkiwix.JNIKiwixException; -import org.kiwix.libkiwix.Bookmark; +import java.util.stream.Stream; public class TestLibrary { @@ -56,7 +56,7 @@ public class TestLibrary public String[] getBooksCreators() { return inner.getBooksCreators(); } public String[] getBooksPublishers() { return inner.getBooksPublishers(); } - public void addBookmark(Bookmark bookmark) { inner.addBookmark(bookmark); } + public void addBookmark(TestBookmark bookmark) { inner.addBookmark(bookmark.inner()); } public boolean removeBookmark(String zimId, String url) { return inner.removeBookmark(zimId, url); } - public Bookmark[] getBookmarks(boolean onlyValidBookmarks) { return inner.getBookmarks(onlyValidBookmarks); } + public TestBookmark[] getBookmarks(boolean onlyValidBookmarks) { return Stream.of(inner.getBookmarks(onlyValidBookmarks)).map(b -> new TestBookmark(b)).toArray(TestBookmark[]::new); } } diff --git a/lib/src/test/test.java b/lib/src/test/test.java index afc85ce..6528de2 100644 --- a/lib/src/test/test.java +++ b/lib/src/test/test.java @@ -154,7 +154,7 @@ public class test { TestBook book = new TestBook(); book.update(archive); lib.addBook(book); - Bookmark bookmark = new Bookmark(); + TestBookmark bookmark = new TestBookmark(); bookmark.setBookId(book.getId()); bookmark.setTitle(book.getTitle()); bookmark.setUrl(book.getUrl()); @@ -163,7 +163,7 @@ public class test { bookmark.setBookTitle(book.getName()); // add bookmark to library lib.addBookmark(bookmark); - Bookmark[] bookmarkArray = lib.getBookmarks(true); + TestBookmark[] bookmarkArray = lib.getBookmarks(true); assertEquals(1, bookmarkArray.length); bookmark = bookmarkArray[0]; // test saved bookmark