From 83a6429565b9afb1111be752c959926c9f3ef189 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 14 Jun 2023 14:49:10 +0200 Subject: [PATCH] Introduce TestBook, TestLibrary, TestManager and TestServer. --- .../org/kiwix/test/libkiwix/TestBook.java | 40 ++++++++++++ .../org/kiwix/test/libkiwix/TestLibrary.java | 62 +++++++++++++++++++ .../org/kiwix/test/libkiwix/TestManager.java | 43 +++++++++++++ .../org/kiwix/test/libkiwix/TestServer.java | 41 ++++++++++++ .../org/kiwix/test/libzim/TestArchive.java | 2 + lib/src/test/test.java | 21 ++++--- 6 files changed, 199 insertions(+), 10 deletions(-) create mode 100644 lib/src/test/org/kiwix/test/libkiwix/TestBook.java create mode 100644 lib/src/test/org/kiwix/test/libkiwix/TestLibrary.java create mode 100644 lib/src/test/org/kiwix/test/libkiwix/TestManager.java create mode 100644 lib/src/test/org/kiwix/test/libkiwix/TestServer.java diff --git a/lib/src/test/org/kiwix/test/libkiwix/TestBook.java b/lib/src/test/org/kiwix/test/libkiwix/TestBook.java new file mode 100644 index 0000000..7d15d9a --- /dev/null +++ b/lib/src/test/org/kiwix/test/libkiwix/TestBook.java @@ -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); } +} diff --git a/lib/src/test/org/kiwix/test/libkiwix/TestLibrary.java b/lib/src/test/org/kiwix/test/libkiwix/TestLibrary.java new file mode 100644 index 0000000..163b9d3 --- /dev/null +++ b/lib/src/test/org/kiwix/test/libkiwix/TestLibrary.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2019-2020 Matthieu Gautier + * + * 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.libzim.Searcher; +import org.kiwix.libkiwix.Filter; +import org.kiwix.libkiwix.Book; +import org.kiwix.libkiwix.JNIKiwixException; +import org.kiwix.libkiwix.Bookmark; + +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(Bookmark bookmark) { inner.addBookmark(bookmark); } + public boolean removeBookmark(String zimId, String url) { return inner.removeBookmark(zimId, url); } + public Bookmark[] getBookmarks(boolean onlyValidBookmarks) { return inner.getBookmarks(onlyValidBookmarks); } +} diff --git a/lib/src/test/org/kiwix/test/libkiwix/TestManager.java b/lib/src/test/org/kiwix/test/libkiwix/TestManager.java new file mode 100644 index 0000000..bfd1729 --- /dev/null +++ b/lib/src/test/org/kiwix/test/libkiwix/TestManager.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2020 Matthieu Gautier + * + * 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()); + } +} diff --git a/lib/src/test/org/kiwix/test/libkiwix/TestServer.java b/lib/src/test/org/kiwix/test/libkiwix/TestServer.java new file mode 100644 index 0000000..e4cb19d --- /dev/null +++ b/lib/src/test/org/kiwix/test/libkiwix/TestServer.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2019 Matthieu Gautier + * + * 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()); + } +} diff --git a/lib/src/test/org/kiwix/test/libzim/TestArchive.java b/lib/src/test/org/kiwix/test/libzim/TestArchive.java index 25b7d3b..1b12839 100644 --- a/lib/src/test/org/kiwix/test/libzim/TestArchive.java +++ b/lib/src/test/org/kiwix/test/libzim/TestArchive.java @@ -28,7 +28,9 @@ 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); diff --git a/lib/src/test/test.java b/lib/src/test/test.java index 22d6325..afc85ce 100644 --- a/lib/src/test/test.java +++ b/lib/src/test/test.java @@ -8,6 +8,7 @@ import static org.junit.Assert.*; import org.kiwix.libkiwix.*; import org.kiwix.libzim.*; import org.kiwix.test.libzim.*; +import org.kiwix.test.libkiwix.*; public class test { static { @@ -111,8 +112,8 @@ public class test { @Test public void testLibrary() throws IOException { - Library lib = new Library(); - Manager manager = new Manager(lib); + TestLibrary lib = new TestLibrary(); + TestManager manager = new TestManager(lib); String content = getTextFileContent("catalog.xml"); manager.readOpds(content, "http://localhost"); assertEquals(lib.getBookCount(true, true), 1); @@ -120,7 +121,7 @@ public class test { assertEquals(bookIds.length, 1); 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.getTags(), "unit;test"); assertEquals(book.getIllustration(48).width(), 48); @@ -135,22 +136,22 @@ public class test { @Test public void testServer() throws ZimFileFormatException, JNIKiwixException { - Archive archive = new Archive("small.zim"); - Library lib = new Library(); - Book book = new Book(); + TestArchive archive = new TestArchive("small.zim"); + TestLibrary lib = new TestLibrary(); + TestBook book = new TestBook(); book.update(archive); lib.addBook(book); assertEquals(1, lib.getBookCount(true, true)); - Server server = new Server(lib); + TestServer server = new TestServer(lib); server.setPort(8080); assertEquals(true, server.start()); } @Test public void testBookMark() throws ZimFileFormatException, JNIKiwixException { - Archive archive = new Archive("small.zim"); - Library lib = new Library(); - Book book = new Book(); + TestArchive archive = new TestArchive("small.zim"); + TestLibrary lib = new TestLibrary(); + TestBook book = new TestBook(); book.update(archive); lib.addBook(book); Bookmark bookmark = new Bookmark();