Skip to content

Commit

Permalink
Update tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgautierfr committed Apr 22, 2024
1 parent 1d49be8 commit d2ace70
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib/src/test/org/kiwix/test/libzim/TestArchive.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ public TestArchive(FileDescriptor fd, long offset, long size)
inner = new Archive(fd, offset, size);
}

public TestArchive(FdInput fd)
throws ZimFileFormatException
{
inner = new Archive(fd);
}

public TestArchive(FdInput[] fds)
throws ZimFileFormatException
{
inner = new Archive(fds);
}

public String getFilename() { return inner.getFilename(); }
public long getFilesize() { return inner.getFilesize(); }
public int getAllEntryCount() { return inner.getAllEntryCount(); }
Expand Down
74 changes: 72 additions & 2 deletions lib/src/test/test.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@ private void testArchive(TestArchive archive)
assertTrue(Arrays.equals(faviconData, readData));

// Checking all metadata
assertFalse(archive.isMultiPart());
assertTrue(archive.hasNewNamespaceScheme());
assertTrue(archive.hasChecksum());
assertEquals("4a2709fddbee8c27db708c20b4952a06", archive.getChecksum());
assertTrue(archive.hasTitleIndex());
assertTrue(archive.hasFulltextIndex());
assertTrue(archive.hasMainEntry());
long[] illuSizes = {48};
Expand Down Expand Up @@ -221,6 +219,8 @@ public void testArchiveDirect()
{
TestArchive archive = new TestArchive("small.zim");
testArchive(archive);
assertFalse(archive.isMultiPart());
assertTrue(archive.hasTitleIndex());
assertTrue(archive.check());
assertEquals("small.zim", archive.getFilename());
}
Expand Down Expand Up @@ -261,6 +261,26 @@ public void testArchiveByFd()
FileInputStream fis = new FileInputStream("small.zim");
TestArchive archive = new TestArchive(fis.getFD());
testArchive(archive);
assertFalse(archive.isMultiPart());
assertTrue(archive.hasTitleIndex());
assertTrue(archive.check());
assertEquals("", archive.getFilename());
}
System.gc();
System.runFinalization();
}

@Test
public void testArchiveByFdInput()
throws JNIKiwixException, IOException, ZimFileFormatException, EntryNotFoundException {
{
File plainArchive = new File("small.zim");
FileInputStream fis = new FileInputStream("small.zim");
FdInput fd = new FdInput(fis.getFD(), 0, plainArchive.length());
TestArchive archive = new TestArchive(fd);
testArchive(archive);
assertFalse(archive.isMultiPart());
assertTrue(archive.hasTitleIndex());
assertTrue(archive.check());
assertEquals("", archive.getFilename());
}
Expand All @@ -278,6 +298,56 @@ public void testArchiveWithAnEmbeddedArchive()
// This fails. See https://github.com/openzim/libzim/issues/812
//assertTrue(archive.check());
testArchive(archive);
assertFalse(archive.isMultiPart());
assertTrue(archive.hasTitleIndex());
assertEquals("", archive.getFilename());
}
System.gc();
System.runFinalization();
}

@Test
public void testArchiveWithAnEmbeddedArchiveFdInputNaive()
throws JNIKiwixException, IOException, ZimFileFormatException, EntryNotFoundException {
{
File plainArchive = new File("small.zim");
FileInputStream fis = new FileInputStream("small.zim.embedded");
FdInput fd1 = new FdInput(fis.getFD(), 8, plainArchive.length() / 2);
FdInput fd2 = new FdInput(fis.getFD(), fd1.offset + fd1.size, plainArchive.length() - fd1.size);

FdInput fds[] = {fd1, fd2};

TestArchive archive = new TestArchive(fds);
// This fails. See https://github.com/openzim/libzim/issues/812
//assertTrue(archive.check());
testArchive(archive);
assertTrue(archive.isMultiPart());
//Naive split cut the title index in the middle. libzim cannot read it.
assertFalse(archive.hasTitleIndex());
assertEquals("", archive.getFilename());
}
System.gc();
System.runFinalization();
}

@Test
public void testArchiveWithAnEmbeddedArchiveFdInput()
throws JNIKiwixException, IOException, ZimFileFormatException, EntryNotFoundException {
{
File plainArchive = new File("small.zim");
FileInputStream fis = new FileInputStream("small.zim.embedded");
FdInput fd1 = new FdInput(fis.getFD(), 8, plainArchive.length() / 10);
FdInput fd2 = new FdInput(fis.getFD(), fd1.offset + fd1.size, plainArchive.length() - fd1.size);

FdInput fds[] = {fd1, fd2};

TestArchive archive = new TestArchive(fds);
// This fails. See https://github.com/openzim/libzim/issues/812
//assertTrue(archive.check());
testArchive(archive);
assertTrue(archive.isMultiPart());
//If we don't cut in the middle of xapian db, we can read it.
assertTrue(archive.hasTitleIndex());
assertEquals("", archive.getFilename());
}
System.gc();
Expand Down

0 comments on commit d2ace70

Please sign in to comment.