mirror of
https://github.com/kiwix/java-libkiwix.git
synced 2025-09-09 23:30:34 -04:00
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.
This commit is contained in:
parent
07defa8356
commit
d4f2f82e98
@ -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'
|
||||
]
|
||||
}
|
||||
|
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.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(); }
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user