Skip to content

Commit 08d59c4

Browse files
authored
Merge pull request #33 from kiwix/better_testing
Better testing (coverage)
2 parents 8cc3627 + 52cc2e4 commit 08d59c4

13 files changed

Lines changed: 497 additions & 33 deletions

File tree

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
jobs:
1313
publish:
1414

15-
runs-on: ubuntu-18.04
15+
runs-on: ubuntu-20.04
1616

1717
steps:
1818
- uses: actions/checkout@v2

lib/build.gradle

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ task downloadLibzimSoAndHeaderFiles(type: Download) {
8686
libzim_base_url + '/libzim_android-arm64.tar.gz',
8787
libzim_base_url + '/libzim_android-x86.tar.gz',
8888
libzim_base_url + '/libzim_android-x86_64.tar.gz',
89-
libzim_base_url + '/libzim_linux-x86_64.tar.gz'
89+
libzim_base_url + '/libzim_linux-x86_64-bionic.tar.gz'
9090
])
9191
dest buildDir
9292
overwrite true
@@ -106,12 +106,12 @@ task unzipLibzim(type: Copy) {
106106
from tarTree(buildDir.path + "/libzim_android-x86_64.tar.gz")
107107
into buildDir
108108
// unzip linux x86_64
109-
from tarTree(buildDir.path + "/libzim_linux-x86_64.tar.gz")
109+
from tarTree(buildDir.path + "/libzim_linux-x86_64-bionic.tar.gz")
110110
into buildDir
111111
}
112112

113113
task renameLibzimFolders() {
114-
renameFolders(buildDir.path,"libzim_")
114+
removeDateFromFolderName(buildDir.path,"libzim_")
115115
}
116116

117117
task copyLibzimHeaderAndSoFiles(type: Copy) {
@@ -147,8 +147,8 @@ task copyLibzimHeaderAndSoFiles(type: Copy) {
147147

148148
copy {
149149
// copying linux_x86_64 so file
150-
project.ext.set("libzim_version", getFileFromFolder(buildDir.path + "/libzim_linux-x86_64/lib/x86_64-linux-gnu/"))
151-
from buildDir.path + "/libzim_linux-x86_64/lib/x86_64-linux-gnu/" + libzim_version
150+
project.ext.set("libzim_version", getFileFromFolder(buildDir.path + "/libzim_linux-x86_64-bionic/lib/x86_64-linux-gnu/"))
151+
from buildDir.path + "/libzim_linux-x86_64-bionic/lib/x86_64-linux-gnu/" + libzim_version
152152
into buildDir.path
153153
}
154154
}
@@ -175,10 +175,10 @@ task downloadLibkiwixSoAndHeaderFiles(type: Download) {
175175
}
176176

177177
task renameLibkiwixFolders() {
178-
renameFolders(buildDir.path,"libkiwix_")
178+
removeDateFromFolderName(buildDir.path,"libkiwix_")
179179
}
180180

181-
static void renameFolders(String path, String startWith) {
181+
static void removeDateFromFolderName(String path, String startWith) {
182182
File directory = new File(path)
183183
if (directory.exists() && directory.isDirectory()) {
184184
Arrays.stream(directory.listFiles())
@@ -274,20 +274,20 @@ task testSourceJar(type: Jar) {
274274

275275
task compileTestFile(type: JavaCompile) {
276276
dependsOn testSourceJar
277-
source = file('src/test/test.java')
278-
destinationDirectory = file('src/test/')
277+
source = file('src/test')
278+
destinationDirectory = file("$buildDir")
279279
classpath = files("src/test/junit-4.13.jar" , "src/test/hamcrest-core-1.4.jar", "build/libs/test-sources.jar")
280280
}
281281

282282
task runTests(type: JavaExec) {
283283
workingDir("$projectDir/src/test/")
284284
dependsOn compileTestFile
285-
classpath = files('src/test/', 'src/test/java/', 'src/test/junit-4.13.jar', 'src/test/hamcrest-core-1.3.jar')
285+
classpath = files("$buildDir", 'src/test/java/', 'src/test/junit-4.13.jar', 'src/test/hamcrest-core-1.3.jar')
286286
main = 'org.junit.runner.JUnitCore'
287287
args = ['test']
288288
jvmArgs = [
289289
'-Djava.library.path=' + buildDir.path,
290-
'-javaagent:jacoco-0.8.7/lib/jacocoagent.jar'
290+
'-javaagent:jacoco-0.8.7/lib/jacocoagent.jar=destfile=../../build/jacoco/jacoco.exec'
291291
]
292292
}
293293

@@ -297,9 +297,9 @@ task createCodeCoverageReport(type: JavaExec) {
297297
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/*')
298298
main = 'org.jacoco.cli.internal.Main'
299299
args = [
300-
'report', 'jacoco.exec',
301-
'--classfiles', 'java/org/kiwix/libkiwix/', '--classfiles', 'java/org/kiwix/libzim/',
302-
'--html', '../../build/coverage-report', '--xml', 'coverage.xml'
300+
'report', '../../build/jacoco/jacoco.exec',
301+
'--classfiles', 'java/org/kiwix', '--classfiles', '../../build/org/kiwix',
302+
'--html', '../../build/coverage-report', '--xml', '../../build/coverage.xml'
303303
]
304304
}
305305

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
package org.kiwix.test.libkiwix;
3+
4+
import org.kiwix.libkiwix.Book;
5+
import org.kiwix.libkiwix.Illustration;
6+
import org.kiwix.test.libzim.TestArchive;
7+
8+
public class TestBook
9+
{
10+
private Book inner;
11+
public TestBook() { inner = new Book(); }
12+
public TestBook(Book _inner) { inner = _inner; }
13+
public Book inner() { return inner; }
14+
15+
public void update(TestBook book) { inner.update(book.inner()); }
16+
public void update(TestArchive archive) { inner.update(archive.inner()); }
17+
18+
public String getId() { return inner.getId(); }
19+
public String getPath() { return inner.getPath(); }
20+
public String getHumanReadableIdFromPath() { return inner.getHumanReadableIdFromPath(); }
21+
public boolean isPathValid() { return inner.isPathValid(); }
22+
public String getTitle() { return inner.getTitle(); }
23+
public String getDescription() { return inner.getDescription(); }
24+
public String getLanguage() { return inner.getLanguage(); }
25+
public String getCreator() { return inner.getCreator(); }
26+
public String getPublisher() { return inner.getPublisher(); }
27+
public String getDate() { return inner.getDate(); }
28+
public String getUrl() { return inner.getUrl(); }
29+
public String getName() { return inner.getName(); }
30+
public String getFlavour() { return inner.getFlavour(); }
31+
public String getCategory() { return inner.getCategory(); }
32+
public String getTags() { return inner.getTags(); }
33+
public String getTagStr(String tagName) { return inner.getTagStr(tagName); }
34+
public long getArticleCount() { return inner.getArticleCount(); }
35+
public long getMediaCount() { return inner.getMediaCount(); }
36+
public long getSize() { return inner.getSize(); }
37+
38+
public Illustration[] getIllustrations() { return inner.getIllustrations(); }
39+
public Illustration getIllustration(int size) { return inner.getIllustration(size); }
40+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (C) 2022 Matthieu Gautier <mgautier@kymeria.fr>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3 of the License, or
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301, USA.
18+
*/
19+
20+
package org.kiwix.test.libkiwix;
21+
22+
import org.kiwix.libkiwix.Bookmark;
23+
24+
public class TestBookmark
25+
{
26+
private Bookmark inner;
27+
public Bookmark inner() { return inner; }
28+
public TestBookmark() { inner = new Bookmark(); }
29+
public TestBookmark(Bookmark _inner) { inner = _inner; }
30+
31+
public void setBookId(String bookId) { inner.setBookId(bookId); }
32+
public void setBookTitle(String bookTitle) { inner.setBookTitle(bookTitle); }
33+
public void setUrl(String url) { inner.setUrl(url); }
34+
public void setTitle(String title) { inner.setTitle(title); }
35+
public void setLanguage(String language) { inner.setLanguage(language); }
36+
public void setDate(String date) { inner.setDate(date); }
37+
38+
public String getBookId() { return inner.getBookId(); }
39+
public String getBookTitle() { return inner.getBookTitle(); }
40+
public String getUrl() { return inner.getUrl(); }
41+
public String getTitle() { return inner.getTitle(); }
42+
public String getLanguage() { return inner.getLanguage(); }
43+
public String getDate() { return inner.getDate(); }
44+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (C) 2019-2020 Matthieu Gautier <mgautier@kymeria.fr>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3 of the License, or
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301, USA.
18+
*/
19+
20+
package org.kiwix.test.libkiwix;
21+
22+
import org.kiwix.libkiwix.Library;
23+
import org.kiwix.test.libzim.TestArchive;
24+
import org.kiwix.test.libkiwix.TestBookmark;
25+
import org.kiwix.libzim.Searcher;
26+
import org.kiwix.libkiwix.Filter;
27+
import org.kiwix.libkiwix.JNIKiwixException;
28+
import java.util.stream.Stream;
29+
30+
public class TestLibrary
31+
{
32+
private Library inner;
33+
public Library inner() { return inner; }
34+
public TestLibrary() { inner = new Library(); }
35+
public TestLibrary(Library _inner) { inner = _inner; }
36+
public boolean addBook(TestBook book) throws JNIKiwixException { return inner.addBook(book.inner()); }
37+
38+
public TestBook getBookById(String id) { return new TestBook(inner.getBookById(id)); }
39+
40+
public TestArchive getArchiveById(String id) { return new TestArchive(inner.getArchiveById(id)); }
41+
//public native Searcher getSearcherById(String id);
42+
//public native Searcher getSearcherByIds(String ids[]);
43+
44+
public boolean removeBookById(String id) { return inner.removeBookById(id); }
45+
46+
public boolean writeToFile(String path) { return inner.writeToFile(path); }
47+
public boolean writeBookmarksToFile(String path) { return inner.writeBookmarksToFile(path); }
48+
49+
public int getBookCount(boolean localBooks, boolean remoteBooks) { return inner.getBookCount(localBooks, remoteBooks); }
50+
51+
public String[] getBooksIds() { return inner.getBooksIds(); }
52+
public String[] filter(Filter filter) { return inner.filter(filter); }
53+
54+
public String[] getBooksLanguages() { return inner.getBooksLanguages(); }
55+
public String[] getBooksCategories() { return inner.getBooksCategories(); }
56+
public String[] getBooksCreators() { return inner.getBooksCreators(); }
57+
public String[] getBooksPublishers() { return inner.getBooksPublishers(); }
58+
59+
public void addBookmark(TestBookmark bookmark) { inner.addBookmark(bookmark.inner()); }
60+
public boolean removeBookmark(String zimId, String url) { return inner.removeBookmark(zimId, url); }
61+
public TestBookmark[] getBookmarks(boolean onlyValidBookmarks) { return Stream.of(inner.getBookmarks(onlyValidBookmarks)).map(b -> new TestBookmark(b)).toArray(TestBookmark[]::new); }
62+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (C) 2020 Matthieu Gautier <mgautier@kymeria.fr>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3 of the License, or
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301, USA.
18+
*/
19+
20+
package org.kiwix.test.libkiwix;
21+
22+
import org.kiwix.libkiwix.Manager;
23+
24+
public class TestManager
25+
{
26+
private Manager inner;
27+
28+
public TestManager(Manager _inner) { inner = _inner; }
29+
30+
public boolean readFile(String path) { return inner.readFile(path); }
31+
public boolean readXml(String content, String libraryPath) { return inner.readXml(content, libraryPath); }
32+
public boolean readOpds(String content, String urlHost) { return inner.readOpds(content, urlHost); }
33+
public boolean readBookmarkFile(String path) { return inner.readBookmarkFile(path); }
34+
public String addBookFromPath(String pathToOpen,
35+
String pathToSave,
36+
String url,
37+
boolean checkMetaData)
38+
{ return inner.addBookFromPath(pathToOpen, pathToSave, url, checkMetaData); }
39+
40+
public TestManager(TestLibrary library) {
41+
inner = new Manager(library.inner());
42+
}
43+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (C) 2019 Matthieu Gautier <mgautier@kymeria.fr>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3 of the License, or
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301, USA.
18+
*/
19+
20+
package org.kiwix.test.libkiwix;
21+
22+
import org.kiwix.libkiwix.Library;
23+
import org.kiwix.libkiwix.Server;
24+
25+
public class TestServer
26+
{
27+
private Server inner;
28+
29+
public void setRoot(String root) { inner.setRoot(root); }
30+
public void setAddress(String address) { inner.setAddress(address); }
31+
public void setPort(int port) { inner.setPort(port); }
32+
public void setNbThreads(int nbTreads) { inner.setNbThreads(nbTreads); }
33+
public void setTaskbar(boolean withTaskBar, boolean witLibraryButton) { inner.setTaskbar(withTaskBar, witLibraryButton); }
34+
public void setBlockExternalLinks(boolean blockExternalLinks) { inner.setBlockExternalLinks(blockExternalLinks); }
35+
public boolean start() { return inner.start(); }
36+
public void stop() { inner.stop(); }
37+
public TestServer(TestLibrary library)
38+
{
39+
inner = new Server(library.inner());
40+
}
41+
}

0 commit comments

Comments
 (0)