diff --git a/lib/src/test/catalog.xml b/lib/src/test/catalog.xml
index d312c87..e0724b5 100644
--- a/lib/src/test/catalog.xml
+++ b/lib/src/test/catalog.xml
@@ -2,21 +2,24 @@
00000000-0000-0000-0000-000000000000
Test ZIM file
- urn:uuid:86c91e51-55bf-8882-464e-072aca37a3e8
+ urn:uuid:e34f5109-ed0d-b93e-943d-06f7717c7340
/meta?name=favicon&content=small
2020-11-27:00::00:Z
- en
- This is a ZIM file used in libzim unit-tests
- unit;test
+ small.zim
+ eng
+ Description
+ _category:Category;_ftindex:yes;_ftindex:yes;_pictures:yes;_videos:yes;_details:yes
- Kiwix
+ Creator
Publisher
- Super category
-
+ Category
+ 1
+ 1
+
diff --git a/lib/src/test/create_test_zimfiles b/lib/src/test/create_test_zimfiles
index ac60bcd..43bbf66 100755
--- a/lib/src/test/create_test_zimfiles
+++ b/lib/src/test/create_test_zimfiles
@@ -13,10 +13,11 @@ zimwriterfs -w main.html \
-I favicon.png \
-l eng \
-t "Test ZIM file" \
- -d "N/A" \
- -L "Test File" \
- -c "N/A" \
- -p "N/A" \
+ -d "Description" \
+ -L "Long Description" \
+ -c "Creator" \
+ -p "Publisher" \
+ --tags "_category:Category" \
small_zimfile_data \
small.zim \
&& echo 'small.zim was successfully created' \
diff --git a/lib/src/test/library.xml b/lib/src/test/library.xml
new file mode 100644
index 0000000..f0fc637
--- /dev/null
+++ b/lib/src/test/library.xml
@@ -0,0 +1,3 @@
+
+
+
diff --git a/lib/src/test/small.zim b/lib/src/test/small.zim
index eb9674b..efcf89c 100644
Binary files a/lib/src/test/small.zim and b/lib/src/test/small.zim differ
diff --git a/lib/src/test/small.zim.embedded b/lib/src/test/small.zim.embedded
index 95c84b0..fe7248b 100644
Binary files a/lib/src/test/small.zim.embedded and b/lib/src/test/small.zim.embedded differ
diff --git a/lib/src/test/test.java b/lib/src/test/test.java
index 3f8c582..db50102 100644
--- a/lib/src/test/test.java
+++ b/lib/src/test/test.java
@@ -60,7 +60,7 @@ public class test {
assertEquals("main.html", mainPage.getItem(true).getPath());
// test zim file size
- assertEquals(66910, archive.getFilesize()); // The file size is in KiB
+ assertEquals(66937, archive.getFilesize()); // The file size is in KiB
// test zim file content
byte[] mainData = getFileContent("small_zimfile_data/main.html");
byte[] inZimMainData = archive.getEntryByPath("main.html").getItem(true).getData().getData();
@@ -86,7 +86,7 @@ public class test {
assertFalse(archive.isMultiPart());
assertTrue(archive.hasNewNamespaceScheme());
assertTrue(archive.hasChecksum());
- assertEquals("f4373bda1fdce141ba8e5c80baaf905d", archive.getChecksum());
+ assertEquals("4a2709fddbee8c27db708c20b4952a06", archive.getChecksum());
assertTrue(archive.hasTitleIndex());
assertTrue(archive.hasFulltextIndex());
assertTrue(archive.hasMainEntry());
@@ -97,7 +97,7 @@ public class test {
metaKeys,
archive.getMetadataKeys()
));
- assertEquals("c23a31c1-c357-9e82-3b43-f87aaf706d04", archive.getUuid());
+ assertEquals("e34f5109-ed0d-b93e-943d-06f7717c7340", archive.getUuid());
assertEquals(1, archive.getMediaCount());
assertEquals(1, archive.getArticleCount());
assertEquals(2, archive.getEntryCount());
@@ -205,9 +205,10 @@ public class test {
assertEquals(bookIds.length, 1);
lib.filter(new Filter().local(true));
assertTrue(Arrays.equals(lib.getBooksPublishers(), new String[]{"Publisher"}));
- assertTrue(Arrays.equals(lib.getBooksCreators(), new String[]{"Kiwix"}));
- assertTrue(Arrays.equals(lib.getBooksCategories(), new String[]{"Super category"}));
- assertTrue(Arrays.equals(lib.getBooksLanguages(), new String[]{"en"}));
+ assertTrue(Arrays.equals(lib.getBooksCreators(), new String[]{"Creator"}));
+ System.out.println(Arrays.toString(lib.getBooksCategories()));
+ assertTrue(Arrays.equals(lib.getBooksCategories(), new String[]{"Category"}));
+ assertTrue(Arrays.equals(lib.getBooksLanguages(), new String[]{"eng"}));
// getArchiveById needs books with valid path. Which is not possible by definition if library is initialized by opds stream.
@@ -215,25 +216,35 @@ public class test {
TestBook book = lib.getBookById(bookIds[0]);
assertEquals(book.getTitle(), "Test ZIM file");
- assertEquals(book.getTags(), "unit;test");
+ assertEquals(book.getTags(), "_category:Category;_ftindex:yes;_ftindex:yes;_pictures:yes;_videos:yes;_details:yes");
assertEquals(book.getIllustration(48).width(), 48);
- assertEquals(book.getIllustration(48).url(), "http://localhost/meta?name=favicon&content=small");
assertEquals(book.getUrl(), "http://localhost/small.zim");
- assertEquals(book.getPath(), "");
- assertEquals(book.getHumanReadableIdFromPath(), "");
- assertFalse(book.isPathValid());
- assertEquals(book.getDescription(), "This is a ZIM file used in libzim unit-tests");
- assertEquals(book.getCreator(), "Kiwix");
+ assertEquals(book.getDescription(), "Description");
+ assertEquals(book.getCreator(), "Creator");
assertEquals(book.getPublisher(), "Publisher");
assertEquals(book.getFlavour(), "");
- assertEquals(book.getCategory(), "Super category");
- assertEquals(book.getArticleCount(), 0);
- assertEquals(book.getMediaCount(), 0);
- assertEquals(book.getSize(), 78982);
+ assertEquals(book.getCategory(), "Category");
+ assertEquals(book.getArticleCount(), 1);
+ assertEquals(book.getMediaCount(), 1);
+ assertEquals(book.getSize(), 66560);
Illustration[] illustrations = book.getIllustrations();
assertEquals(1, illustrations.length);
assertEquals(book.getTagStr("video"), "");
+ }
+
+ @Test
+ public void testLibrarySimple() throws IOException {
+ TestLibrary lib = new TestLibrary();
+ TestManager manager = new TestManager(lib);
+ manager.addBookFromPath("small.zim", "small.zim", "http://localhost/small.zim", true);
+ testLibrary(lib);
+ String[] bookIds = lib.getBooksIds();
+ TestBook book = lib.getBookById(bookIds[0]);
+ assertEquals(book.getIllustration(48).url(), "");
+ assertEquals(book.getPath(), new File("small.zim").getAbsolutePath());
+ assertEquals(book.getHumanReadableIdFromPath(), "small");
+ assertTrue(book.isPathValid());
// remove book from library by id
lib.removeBookById(bookIds[0]);
@@ -241,6 +252,35 @@ public class test {
assertEquals(bookIds.length, 0);
}
+ @Test
+ public void testLibraryXml() throws IOException {
+ TestLibrary lib = new TestLibrary();
+ TestManager manager = new TestManager(lib);
+ manager.readFile("library.xml");
+ testLibrary(lib);
+ String[] bookIds = lib.getBooksIds();
+ TestBook book = lib.getBookById(bookIds[0]);
+ assertEquals(book.getIllustration(48).url(), "");
+ assertEquals(book.getPath(), new File("small.zim").getAbsolutePath());
+ assertEquals(book.getHumanReadableIdFromPath(), "small");
+ assertTrue(book.isPathValid());
+ }
+
+ @Test
+ public void testLibraryXmlContent() throws IOException {
+ TestLibrary lib = new TestLibrary();
+ TestManager manager = new TestManager(lib);
+ String content = getTextFileContent("library.xml");
+ manager.readXml(content, "library.xml");
+ testLibrary(lib);
+ String[] bookIds = lib.getBooksIds();
+ TestBook book = lib.getBookById(bookIds[0]);
+ assertEquals(book.getIllustration(48).url(), "");
+ assertEquals(book.getPath(), new File("small.zim").getAbsolutePath());
+ assertEquals(book.getHumanReadableIdFromPath(), "small");
+ assertTrue(book.isPathValid());
+ }
+
@Test
public void testLibraryOPDS() throws IOException {
TestLibrary lib = new TestLibrary();
@@ -248,6 +288,12 @@ public class test {
String content = getTextFileContent("catalog.xml");
manager.readOpds(content, "http://localhost");
testLibrary(lib);
+ String[] bookIds = lib.getBooksIds();
+ TestBook book = lib.getBookById(bookIds[0]);
+ assertEquals(book.getIllustration(48).url(), "http://localhost/meta?name=favicon&content=small");
+ assertEquals(book.getPath(), "");
+ assertEquals(book.getHumanReadableIdFromPath(), "");
+ assertFalse(book.isPathValid());
}
@Test
@@ -322,7 +368,7 @@ public class test {
assertEquals(3, iterator.getWordCount());
assertEquals(0, iterator.getFileIndex());
assertEquals(-1, iterator.getSize());
- assertEquals("c23a31c1-c357-9e82-3b43-f87aaf706d04", iterator.getZimId());
+ assertEquals("e34f5109-ed0d-b93e-943d-06f7717c7340", iterator.getZimId());
TestEntry entry = iterator.next();
assertEquals("main.html", entry.getPath());