diff --git a/test/data/example.zim b/test/data/example.zim new file mode 100644 index 000000000..eebf33dc7 Binary files /dev/null and b/test/data/example.zim differ diff --git a/test/manager.cpp b/test/manager.cpp new file mode 100644 index 000000000..6a2bbe8bd --- /dev/null +++ b/test/manager.cpp @@ -0,0 +1,25 @@ +#include "gtest/gtest.h" +#include "../include/manager.h" +#include "../include/library.h" +#include "../include/book.h" +#include +#include + +TEST(ManagerTest, addBookFromPathAndGetIdTest) +{ + kiwix::Library lib; + kiwix::Manager manager = kiwix::Manager(&lib); + + auto bookId = manager.addBookFromPathAndGetId("./test/example.zim"); + EXPECT_NE(bookId, ""); + kiwix::Book book = lib.getBookById(bookId); + EXPECT_EQ(book.getPath(), computeAbsolutePath("", "./test/example.zim")); + + const std::string pathToSave = "./pathToSave"; + const std::string url = "url"; + bookId = manager.addBookFromPathAndGetId("./test/example.zim", pathToSave, url, true); + book = lib.getBookById(bookId); + auto savedPath = computeAbsolutePath(removeLastPathElement(manager.writableLibraryPath), pathToSave); + EXPECT_EQ(book.getPath(), savedPath); + EXPECT_EQ(book.getUrl(), url); +} \ No newline at end of file diff --git a/test/meson.build b/test/meson.build index dec41fbd0..e52187688 100644 --- a/test/meson.build +++ b/test/meson.build @@ -1,4 +1,6 @@ - +configure_file(input : 'data/example.zim', + output : 'example.zim', + copy: true ) tests = [ 'parseUrl', @@ -8,7 +10,8 @@ tests = [ 'stringTools', 'pathTools', 'kiwixserve', - 'book' + 'book', + 'manager' ]