Skip to content

Commit 83a6429

Browse files
committed
Introduce TestBook, TestLibrary, TestManager and TestServer.
1 parent f84d951 commit 83a6429

6 files changed

Lines changed: 199 additions & 10 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
package org.kiwix.test.libkiwix;
3+
4+
import org.kiwix.libkiwix.Book;
5+
import org.kiwix.libkiwix.Illustration;
6+
import org.kiwix.test.libzim.TestArchive;
7+
8+
public class TestBook
9+
{
10+
private Book inner;
11+
public TestBook() { inner = new Book(); }
12+
public TestBook(Book _inner) { inner = _inner; }
13+
public Book inner() { return inner; }
14+
15+
public void update(TestBook book) { inner.update(book.inner()); }
16+
public void update(TestArchive archive) { inner.update(archive.inner()); }
17+
18+
public String getId() { return inner.getId(); }
19+
public String getPath() { return inner.getPath(); }
20+
public String getHumanReadableIdFromPath() { return inner.getHumanReadableIdFromPath(); }
21+
public boolean isPathValid() { return inner.isPathValid(); }
22+
public String getTitle() { return inner.getTitle(); }
23+
public String getDescription() { return inner.getDescription(); }
24+
public String getLanguage() { return inner.getLanguage(); }
25+
public String getCreator() { return inner.getCreator(); }
26+
public String getPublisher() { return inner.getPublisher(); }
27+
public String getDate() { return inner.getDate(); }
28+
public String getUrl() { return inner.getUrl(); }
29+
public String getName() { return inner.getName(); }
30+
public String getFlavour() { return inner.getFlavour(); }
31+
public String getCategory() { return inner.getCategory(); }
32+
public String getTags() { return inner.getTags(); }
33+
public String getTagStr(String tagName) { return inner.getTagStr(tagName); }
34+
public long getArticleCount() { return inner.getArticleCount(); }
35+
public long getMediaCount() { return inner.getMediaCount(); }
36+
public long getSize() { return inner.getSize(); }
37+
38+
public Illustration[] getIllustrations() { return inner.getIllustrations(); }
39+
public Illustration getIllustration(int size) { return inner.getIllustration(size); }
40+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (C) 2019-2020 Matthieu Gautier <mgautier@kymeria.fr>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3 of the License, or
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301, USA.
18+
*/
19+
20+
package org.kiwix.test.libkiwix;
21+
22+
import org.kiwix.libkiwix.Library;
23+
import org.kiwix.test.libzim.TestArchive;
24+
import org.kiwix.libzim.Searcher;
25+
import org.kiwix.libkiwix.Filter;
26+
import org.kiwix.libkiwix.Book;
27+
import org.kiwix.libkiwix.JNIKiwixException;
28+
import org.kiwix.libkiwix.Bookmark;
29+
30+
public class TestLibrary
31+
{
32+
private Library inner;
33+
public Library inner() { return inner; }
34+
public TestLibrary() { inner = new Library(); }
35+
public TestLibrary(Library _inner) { inner = _inner; }
36+
public boolean addBook(TestBook book) throws JNIKiwixException { return inner.addBook(book.inner()); }
37+
38+
public TestBook getBookById(String id) { return new TestBook(inner.getBookById(id)); }
39+
40+
public TestArchive getArchiveById(String id) { return new TestArchive(inner.getArchiveById(id)); }
41+
//public native Searcher getSearcherById(String id);
42+
//public native Searcher getSearcherByIds(String ids[]);
43+
44+
public boolean removeBookById(String id) { return inner.removeBookById(id); }
45+
46+
public boolean writeToFile(String path) { return inner.writeToFile(path); }
47+
public boolean writeBookmarksToFile(String path) { return inner.writeBookmarksToFile(path); }
48+
49+
public int getBookCount(boolean localBooks, boolean remoteBooks) { return inner.getBookCount(localBooks, remoteBooks); }
50+
51+
public String[] getBooksIds() { return inner.getBooksIds(); }
52+
public String[] filter(Filter filter) { return inner.filter(filter); }
53+
54+
public String[] getBooksLanguages() { return inner.getBooksLanguages(); }
55+
public String[] getBooksCategories() { return inner.getBooksCategories(); }
56+
public String[] getBooksCreators() { return inner.getBooksCreators(); }
57+
public String[] getBooksPublishers() { return inner.getBooksPublishers(); }
58+
59+
public void addBookmark(Bookmark bookmark) { inner.addBookmark(bookmark); }
60+
public boolean removeBookmark(String zimId, String url) { return inner.removeBookmark(zimId, url); }
61+
public Bookmark[] getBookmarks(boolean onlyValidBookmarks) { return inner.getBookmarks(onlyValidBookmarks); }
62+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (C) 2020 Matthieu Gautier <mgautier@kymeria.fr>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3 of the License, or
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301, USA.
18+
*/
19+
20+
package org.kiwix.test.libkiwix;
21+
22+
import org.kiwix.libkiwix.Manager;
23+
24+
public class TestManager
25+
{
26+
private Manager inner;
27+
28+
public TestManager(Manager _inner) { inner = _inner; }
29+
30+
public boolean readFile(String path) { return inner.readFile(path); }
31+
public boolean readXml(String content, String libraryPath) { return inner.readXml(content, libraryPath); }
32+
public boolean readOpds(String content, String urlHost) { return inner.readOpds(content, urlHost); }
33+
public boolean readBookmarkFile(String path) { return inner.readBookmarkFile(path); }
34+
public String addBookFromPath(String pathToOpen,
35+
String pathToSave,
36+
String url,
37+
boolean checkMetaData)
38+
{ return inner.addBookFromPath(pathToOpen, pathToSave, url, checkMetaData); }
39+
40+
public TestManager(TestLibrary library) {
41+
inner = new Manager(library.inner());
42+
}
43+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (C) 2019 Matthieu Gautier <mgautier@kymeria.fr>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3 of the License, or
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301, USA.
18+
*/
19+
20+
package org.kiwix.test.libkiwix;
21+
22+
import org.kiwix.libkiwix.Library;
23+
import org.kiwix.libkiwix.Server;
24+
25+
public class TestServer
26+
{
27+
private Server inner;
28+
29+
public void setRoot(String root) { inner.setRoot(root); }
30+
public void setAddress(String address) { inner.setAddress(address); }
31+
public void setPort(int port) { inner.setPort(port); }
32+
public void setNbThreads(int nbTreads) { inner.setNbThreads(nbTreads); }
33+
public void setTaskbar(boolean withTaskBar, boolean witLibraryButton) { inner.setTaskbar(withTaskBar, witLibraryButton); }
34+
public void setBlockExternalLinks(boolean blockExternalLinks) { inner.setBlockExternalLinks(blockExternalLinks); }
35+
public boolean start() { return inner.start(); }
36+
public void stop() { inner.stop(); }
37+
public TestServer(TestLibrary library)
38+
{
39+
inner = new Server(library.inner());
40+
}
41+
}

lib/src/test/org/kiwix/test/libzim/TestArchive.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
public class TestArchive
2929
{
3030
private Archive inner;
31+
public Archive inner() { return inner; }
3132

33+
public TestArchive(Archive _inner) { inner = _inner; }
3234
public TestArchive(String filename) throws ZimFileFormatException
3335
{
3436
inner = new Archive(filename);

lib/src/test/test.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.kiwix.libkiwix.*;
99
import org.kiwix.libzim.*;
1010
import org.kiwix.test.libzim.*;
11+
import org.kiwix.test.libkiwix.*;
1112

1213
public class test {
1314
static {
@@ -111,16 +112,16 @@ public void testArchiveWithAnEmbeddedArchive()
111112
@Test
112113
public void testLibrary()
113114
throws IOException {
114-
Library lib = new Library();
115-
Manager manager = new Manager(lib);
115+
TestLibrary lib = new TestLibrary();
116+
TestManager manager = new TestManager(lib);
116117
String content = getTextFileContent("catalog.xml");
117118
manager.readOpds(content, "http://localhost");
118119
assertEquals(lib.getBookCount(true, true), 1);
119120
String[] bookIds = lib.getBooksIds();
120121
assertEquals(bookIds.length, 1);
121122
lib.filter(new Filter().local(true));
122123

123-
Book book = lib.getBookById(bookIds[0]);
124+
TestBook book = lib.getBookById(bookIds[0]);
124125
assertEquals(book.getTitle(), "Test ZIM file");
125126
assertEquals(book.getTags(), "unit;test");
126127
assertEquals(book.getIllustration(48).width(), 48);
@@ -135,22 +136,22 @@ public void testLibrary()
135136

136137
@Test
137138
public void testServer() throws ZimFileFormatException, JNIKiwixException {
138-
Archive archive = new Archive("small.zim");
139-
Library lib = new Library();
140-
Book book = new Book();
139+
TestArchive archive = new TestArchive("small.zim");
140+
TestLibrary lib = new TestLibrary();
141+
TestBook book = new TestBook();
141142
book.update(archive);
142143
lib.addBook(book);
143144
assertEquals(1, lib.getBookCount(true, true));
144-
Server server = new Server(lib);
145+
TestServer server = new TestServer(lib);
145146
server.setPort(8080);
146147
assertEquals(true, server.start());
147148
}
148149

149150
@Test
150151
public void testBookMark() throws ZimFileFormatException, JNIKiwixException {
151-
Archive archive = new Archive("small.zim");
152-
Library lib = new Library();
153-
Book book = new Book();
152+
TestArchive archive = new TestArchive("small.zim");
153+
TestLibrary lib = new TestLibrary();
154+
TestBook book = new TestBook();
154155
book.update(archive);
155156
lib.addBook(book);
156157
Bookmark bookmark = new Bookmark();

0 commit comments

Comments
 (0)