mirror of
https://github.com/kiwix/java-libkiwix.git
synced 2025-09-13 09:07:48 -04:00
Merge pull request #33 from kiwix/better_testing
Better testing (coverage)
This commit is contained in:
commit
08d59c4221
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -12,7 +12,7 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
publish:
|
publish:
|
||||||
|
|
||||||
runs-on: ubuntu-18.04
|
runs-on: ubuntu-20.04
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
@ -86,7 +86,7 @@ task downloadLibzimSoAndHeaderFiles(type: Download) {
|
|||||||
libzim_base_url + '/libzim_android-arm64.tar.gz',
|
libzim_base_url + '/libzim_android-arm64.tar.gz',
|
||||||
libzim_base_url + '/libzim_android-x86.tar.gz',
|
libzim_base_url + '/libzim_android-x86.tar.gz',
|
||||||
libzim_base_url + '/libzim_android-x86_64.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
|
dest buildDir
|
||||||
overwrite true
|
overwrite true
|
||||||
@ -106,12 +106,12 @@ task unzipLibzim(type: Copy) {
|
|||||||
from tarTree(buildDir.path + "/libzim_android-x86_64.tar.gz")
|
from tarTree(buildDir.path + "/libzim_android-x86_64.tar.gz")
|
||||||
into buildDir
|
into buildDir
|
||||||
// unzip linux x86_64
|
// 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
|
into buildDir
|
||||||
}
|
}
|
||||||
|
|
||||||
task renameLibzimFolders() {
|
task renameLibzimFolders() {
|
||||||
renameFolders(buildDir.path,"libzim_")
|
removeDateFromFolderName(buildDir.path,"libzim_")
|
||||||
}
|
}
|
||||||
|
|
||||||
task copyLibzimHeaderAndSoFiles(type: Copy) {
|
task copyLibzimHeaderAndSoFiles(type: Copy) {
|
||||||
@ -147,8 +147,8 @@ task copyLibzimHeaderAndSoFiles(type: Copy) {
|
|||||||
|
|
||||||
copy {
|
copy {
|
||||||
// copying linux_x86_64 so file
|
// copying linux_x86_64 so file
|
||||||
project.ext.set("libzim_version", getFileFromFolder(buildDir.path + "/libzim_linux-x86_64/lib/x86_64-linux-gnu/"))
|
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/lib/x86_64-linux-gnu/" + libzim_version
|
from buildDir.path + "/libzim_linux-x86_64-bionic/lib/x86_64-linux-gnu/" + libzim_version
|
||||||
into buildDir.path
|
into buildDir.path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -175,10 +175,10 @@ task downloadLibkiwixSoAndHeaderFiles(type: Download) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
task renameLibkiwixFolders() {
|
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)
|
File directory = new File(path)
|
||||||
if (directory.exists() && directory.isDirectory()) {
|
if (directory.exists() && directory.isDirectory()) {
|
||||||
Arrays.stream(directory.listFiles())
|
Arrays.stream(directory.listFiles())
|
||||||
@ -274,20 +274,20 @@ task testSourceJar(type: Jar) {
|
|||||||
|
|
||||||
task compileTestFile(type: JavaCompile) {
|
task compileTestFile(type: JavaCompile) {
|
||||||
dependsOn testSourceJar
|
dependsOn testSourceJar
|
||||||
source = file('src/test/test.java')
|
source = file('src/test')
|
||||||
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")
|
classpath = files("src/test/junit-4.13.jar" , "src/test/hamcrest-core-1.4.jar", "build/libs/test-sources.jar")
|
||||||
}
|
}
|
||||||
|
|
||||||
task runTests(type: JavaExec) {
|
task runTests(type: JavaExec) {
|
||||||
workingDir("$projectDir/src/test/")
|
workingDir("$projectDir/src/test/")
|
||||||
dependsOn compileTestFile
|
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'
|
main = 'org.junit.runner.JUnitCore'
|
||||||
args = ['test']
|
args = ['test']
|
||||||
jvmArgs = [
|
jvmArgs = [
|
||||||
'-Djava.library.path=' + buildDir.path,
|
'-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/*')
|
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'
|
main = 'org.jacoco.cli.internal.Main'
|
||||||
args = [
|
args = [
|
||||||
'report', 'jacoco.exec',
|
'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', 'coverage.xml'
|
'--html', '../../build/coverage-report', '--xml', '../../build/coverage.xml'
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
40
lib/src/test/org/kiwix/test/libkiwix/TestBook.java
Normal file
40
lib/src/test/org/kiwix/test/libkiwix/TestBook.java
Normal file
@ -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); }
|
||||||
|
}
|
44
lib/src/test/org/kiwix/test/libkiwix/TestBookmark.java
Normal file
44
lib/src/test/org/kiwix/test/libkiwix/TestBookmark.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 Matthieu Gautier <mgautier@kymeria.fr>
|
||||||
|
*
|
||||||
|
* 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(); }
|
||||||
|
}
|
62
lib/src/test/org/kiwix/test/libkiwix/TestLibrary.java
Normal file
62
lib/src/test/org/kiwix/test/libkiwix/TestLibrary.java
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019-2020 Matthieu Gautier <mgautier@kymeria.fr>
|
||||||
|
*
|
||||||
|
* 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.test.libkiwix.TestBookmark;
|
||||||
|
import org.kiwix.libzim.Searcher;
|
||||||
|
import org.kiwix.libkiwix.Filter;
|
||||||
|
import org.kiwix.libkiwix.JNIKiwixException;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
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(TestBookmark bookmark) { inner.addBookmark(bookmark.inner()); }
|
||||||
|
public boolean removeBookmark(String zimId, String url) { return inner.removeBookmark(zimId, url); }
|
||||||
|
public TestBookmark[] getBookmarks(boolean onlyValidBookmarks) { return Stream.of(inner.getBookmarks(onlyValidBookmarks)).map(b -> new TestBookmark(b)).toArray(TestBookmark[]::new); }
|
||||||
|
}
|
43
lib/src/test/org/kiwix/test/libkiwix/TestManager.java
Normal file
43
lib/src/test/org/kiwix/test/libkiwix/TestManager.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Matthieu Gautier <mgautier@kymeria.fr>
|
||||||
|
*
|
||||||
|
* 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());
|
||||||
|
}
|
||||||
|
}
|
41
lib/src/test/org/kiwix/test/libkiwix/TestServer.java
Normal file
41
lib/src/test/org/kiwix/test/libkiwix/TestServer.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 Matthieu Gautier <mgautier@kymeria.fr>
|
||||||
|
*
|
||||||
|
* 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());
|
||||||
|
}
|
||||||
|
}
|
97
lib/src/test/org/kiwix/test/libzim/TestArchive.java
Normal file
97
lib/src/test/org/kiwix/test/libzim/TestArchive.java
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 Matthieu Gautier <mgautier@kymeria.fr>
|
||||||
|
*
|
||||||
|
* 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.EntryIterator;
|
||||||
|
import org.kiwix.libzim.Archive;
|
||||||
|
import java.io.FileDescriptor;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 TestItem getMetadataItem(String name) { return new TestItem(inner.getMetadataItem(name)); }
|
||||||
|
public String[] getMetadataKeys() { return inner.getMetadataKeys(); }
|
||||||
|
|
||||||
|
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(); }
|
||||||
|
|
||||||
|
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 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 TestEntry getEntryByClusterOrder(int index) { return new TestEntry(inner.getEntryByClusterOrder(index)); }
|
||||||
|
|
||||||
|
public TestEntry getMainEntry() { return new TestEntry(inner.getMainEntry()); }
|
||||||
|
public boolean hasMainEntry() { return inner.hasMainEntry(); }
|
||||||
|
|
||||||
|
public TestEntry getRandomEntry() { return new TestEntry(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 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(); }
|
||||||
|
}
|
30
lib/src/test/org/kiwix/test/libzim/TestBlob.java
Normal file
30
lib/src/test/org/kiwix/test/libzim/TestBlob.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 Matthieu Gautier <mgautier@kymeria.fr>
|
||||||
|
*
|
||||||
|
* 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(); }
|
||||||
|
}
|
35
lib/src/test/org/kiwix/test/libzim/TestEntry.java
Normal file
35
lib/src/test/org/kiwix/test/libzim/TestEntry.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 Matthieu Gautier <mgautier@kymeria.fr>
|
||||||
|
*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
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 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()); }
|
||||||
|
}
|
33
lib/src/test/org/kiwix/test/libzim/TestEntryIterator.java
Normal file
33
lib/src/test/org/kiwix/test/libzim/TestEntryIterator.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 Matthieu Gautier <mgautier@kymeria.fr>
|
||||||
|
*
|
||||||
|
* 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<TestEntry>
|
||||||
|
{
|
||||||
|
private EntryIterator inner;
|
||||||
|
|
||||||
|
public TestEntryIterator(EntryIterator _inner) { inner = _inner; }
|
||||||
|
|
||||||
|
public boolean hasNext() { return inner.hasNext(); }
|
||||||
|
public TestEntry next() { return new TestEntry(inner.next()); }
|
||||||
|
}
|
37
lib/src/test/org/kiwix/test/libzim/TestItem.java
Normal file
37
lib/src/test/org/kiwix/test/libzim/TestItem.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 Matthieu Gautier <mgautier@kymeria.fr>
|
||||||
|
*
|
||||||
|
* 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.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 TestBlob getData() { return new TestBlob(inner.getData()); }
|
||||||
|
public long getSize() { return inner.getSize(); }
|
||||||
|
|
||||||
|
public DirectAccessInfo getDirectAccessInformation() { return inner.getDirectAccessInformation(); }
|
||||||
|
}
|
@ -7,6 +7,8 @@ import static org.junit.Assert.*;
|
|||||||
|
|
||||||
import org.kiwix.libkiwix.*;
|
import org.kiwix.libkiwix.*;
|
||||||
import org.kiwix.libzim.*;
|
import org.kiwix.libzim.*;
|
||||||
|
import org.kiwix.test.libzim.*;
|
||||||
|
import org.kiwix.test.libkiwix.*;
|
||||||
|
|
||||||
public class test {
|
public class test {
|
||||||
static {
|
static {
|
||||||
@ -44,7 +46,7 @@ public class test {
|
|||||||
return new String(getFileContent(path));
|
return new String(getFileContent(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testArchive(Archive archive)
|
private void testArchive(TestArchive archive)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
// test the zim file main page title
|
// test the zim file main page title
|
||||||
assertEquals("Test ZIM file", archive.getMainEntry().getTitle());
|
assertEquals("Test ZIM file", archive.getMainEntry().getTitle());
|
||||||
@ -60,7 +62,7 @@ public class test {
|
|||||||
// test zim file icon
|
// test zim file icon
|
||||||
assertEquals(true, archive.hasIllustration(48));
|
assertEquals(true, archive.hasIllustration(48));
|
||||||
byte[] faviconData = getFileContent("small_zimfile_data/favicon.png");
|
byte[] faviconData = getFileContent("small_zimfile_data/favicon.png");
|
||||||
Item item = archive.getIllustrationItem(48);
|
TestItem item = archive.getIllustrationItem(48);
|
||||||
assertEquals(faviconData.length, item.getSize());
|
assertEquals(faviconData.length, item.getSize());
|
||||||
assert(Arrays.equals(faviconData, item.getData().getData()));
|
assert(Arrays.equals(faviconData, item.getData().getData()));
|
||||||
|
|
||||||
@ -74,14 +76,14 @@ public class test {
|
|||||||
@Test
|
@Test
|
||||||
public void testArchiveDirect()
|
public void testArchiveDirect()
|
||||||
throws JNIKiwixException, IOException, ZimFileFormatException {
|
throws JNIKiwixException, IOException, ZimFileFormatException {
|
||||||
Archive archive = new Archive("small.zim");
|
TestArchive archive = new TestArchive("small.zim");
|
||||||
testArchive(archive);
|
testArchive(archive);
|
||||||
archive.dispose();
|
archive.dispose();
|
||||||
|
|
||||||
// test reader with invalid zim file
|
// test reader with invalid zim file
|
||||||
String zimFile = "test.zim";
|
String zimFile = "test.zim";
|
||||||
try {
|
try {
|
||||||
Archive archive1 = new Archive(zimFile);
|
TestArchive archive1 = new TestArchive(zimFile);
|
||||||
fail("ERROR: Archive created with invalid Zim file!");
|
fail("ERROR: Archive created with invalid Zim file!");
|
||||||
} catch (ZimFileFormatException zimFileFormatException) {
|
} catch (ZimFileFormatException zimFileFormatException) {
|
||||||
assertEquals("Cannot open zimfile " + zimFile, zimFileFormatException.getMessage());
|
assertEquals("Cannot open zimfile " + zimFile, zimFileFormatException.getMessage());
|
||||||
@ -92,7 +94,7 @@ public class test {
|
|||||||
public void testArchiveByFd()
|
public void testArchiveByFd()
|
||||||
throws JNIKiwixException, IOException, ZimFileFormatException {
|
throws JNIKiwixException, IOException, ZimFileFormatException {
|
||||||
FileInputStream fis = new FileInputStream("small.zim");
|
FileInputStream fis = new FileInputStream("small.zim");
|
||||||
Archive archive = new Archive(fis.getFD());
|
TestArchive archive = new TestArchive(fis.getFD());
|
||||||
testArchive(archive);
|
testArchive(archive);
|
||||||
archive.dispose();
|
archive.dispose();
|
||||||
}
|
}
|
||||||
@ -102,7 +104,7 @@ public class test {
|
|||||||
throws JNIKiwixException, IOException, ZimFileFormatException {
|
throws JNIKiwixException, IOException, ZimFileFormatException {
|
||||||
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");
|
||||||
Archive archive = new Archive(fis.getFD(), 8, plainArchive.length());
|
TestArchive archive = new TestArchive(fis.getFD(), 8, plainArchive.length());
|
||||||
testArchive(archive);
|
testArchive(archive);
|
||||||
archive.dispose();
|
archive.dispose();
|
||||||
}
|
}
|
||||||
@ -110,8 +112,8 @@ public class test {
|
|||||||
@Test
|
@Test
|
||||||
public void testLibrary()
|
public void testLibrary()
|
||||||
throws IOException {
|
throws IOException {
|
||||||
Library lib = new Library();
|
TestLibrary lib = new TestLibrary();
|
||||||
Manager manager = new Manager(lib);
|
TestManager manager = new TestManager(lib);
|
||||||
String content = getTextFileContent("catalog.xml");
|
String content = getTextFileContent("catalog.xml");
|
||||||
manager.readOpds(content, "http://localhost");
|
manager.readOpds(content, "http://localhost");
|
||||||
assertEquals(lib.getBookCount(true, true), 1);
|
assertEquals(lib.getBookCount(true, true), 1);
|
||||||
@ -119,7 +121,7 @@ public class test {
|
|||||||
assertEquals(bookIds.length, 1);
|
assertEquals(bookIds.length, 1);
|
||||||
lib.filter(new Filter().local(true));
|
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.getTitle(), "Test ZIM file");
|
||||||
assertEquals(book.getTags(), "unit;test");
|
assertEquals(book.getTags(), "unit;test");
|
||||||
assertEquals(book.getIllustration(48).width(), 48);
|
assertEquals(book.getIllustration(48).width(), 48);
|
||||||
@ -134,25 +136,25 @@ public class test {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testServer() throws ZimFileFormatException, JNIKiwixException {
|
public void testServer() throws ZimFileFormatException, JNIKiwixException {
|
||||||
Archive archive = new Archive("small.zim");
|
TestArchive archive = new TestArchive("small.zim");
|
||||||
Library lib = new Library();
|
TestLibrary lib = new TestLibrary();
|
||||||
Book book = new Book();
|
TestBook book = new TestBook();
|
||||||
book.update(archive);
|
book.update(archive);
|
||||||
lib.addBook(book);
|
lib.addBook(book);
|
||||||
assertEquals(1, lib.getBookCount(true, true));
|
assertEquals(1, lib.getBookCount(true, true));
|
||||||
Server server = new Server(lib);
|
TestServer server = new TestServer(lib);
|
||||||
server.setPort(8080);
|
server.setPort(8080);
|
||||||
assertEquals(true, server.start());
|
assertEquals(true, server.start());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBookMark() throws ZimFileFormatException, JNIKiwixException {
|
public void testBookMark() throws ZimFileFormatException, JNIKiwixException {
|
||||||
Archive archive = new Archive("small.zim");
|
TestArchive archive = new TestArchive("small.zim");
|
||||||
Library lib = new Library();
|
TestLibrary lib = new TestLibrary();
|
||||||
Book book = new Book();
|
TestBook book = new TestBook();
|
||||||
book.update(archive);
|
book.update(archive);
|
||||||
lib.addBook(book);
|
lib.addBook(book);
|
||||||
Bookmark bookmark = new Bookmark();
|
TestBookmark bookmark = new TestBookmark();
|
||||||
bookmark.setBookId(book.getId());
|
bookmark.setBookId(book.getId());
|
||||||
bookmark.setTitle(book.getTitle());
|
bookmark.setTitle(book.getTitle());
|
||||||
bookmark.setUrl(book.getUrl());
|
bookmark.setUrl(book.getUrl());
|
||||||
@ -161,7 +163,7 @@ public class test {
|
|||||||
bookmark.setBookTitle(book.getName());
|
bookmark.setBookTitle(book.getName());
|
||||||
// add bookmark to library
|
// add bookmark to library
|
||||||
lib.addBookmark(bookmark);
|
lib.addBookmark(bookmark);
|
||||||
Bookmark[] bookmarkArray = lib.getBookmarks(true);
|
TestBookmark[] bookmarkArray = lib.getBookmarks(true);
|
||||||
assertEquals(1, bookmarkArray.length);
|
assertEquals(1, bookmarkArray.length);
|
||||||
bookmark = bookmarkArray[0];
|
bookmark = bookmarkArray[0];
|
||||||
// test saved bookmark
|
// test saved bookmark
|
||||||
|
Loading…
x
Reference in New Issue
Block a user