diff --git a/test/data/library.xml b/test/data/library.xml
new file mode 100644
index 00000000..e8fd2e34
--- /dev/null
+++ b/test/data/library.xml
@@ -0,0 +1,34 @@
+
+
+
+
diff --git a/test/meson.build b/test/meson.build
index 2cd9055e..15d878e5 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -25,7 +25,8 @@ if gtest_dep.found() and not meson.is_cross_build()
data_files = [
'example.zim',
'zimfile.zim',
- 'corner_cases.zim'
+ 'corner_cases.zim',
+ 'library.xml'
]
foreach file : data_files
# configure_file(input : 'data/' + file,
diff --git a/test/server.cpp b/test/server.cpp
index 2e18657c..bb963b7b 100644
--- a/test/server.cpp
+++ b/test/server.cpp
@@ -53,6 +53,7 @@ public: // types
typedef std::vector FilePathCollection;
public: // functions
+ ZimFileServer(int serverPort, std::string libraryFilePath);
ZimFileServer(int serverPort, const FilePathCollection& zimpaths);
~ZimFileServer();
@@ -66,6 +67,9 @@ public: // functions
return client->Head(path, headers);
}
+private:
+ void run(int serverPort);
+
private: // data
kiwix::Library library;
kiwix::Manager manager;
@@ -74,6 +78,16 @@ private: // data
std::unique_ptr client;
};
+ZimFileServer::ZimFileServer(int serverPort, std::string libraryFilePath)
+: manager(&this->library)
+{
+ if ( isRelativePath(libraryFilePath) )
+ libraryFilePath = computeAbsolutePath(getCurrentDirectory(), libraryFilePath);
+ manager.readFile(libraryFilePath, true, true);
+
+ run(serverPort);
+}
+
ZimFileServer::ZimFileServer(int serverPort, const FilePathCollection& zimpaths)
: manager(&this->library)
{
@@ -82,6 +96,11 @@ ZimFileServer::ZimFileServer(int serverPort, const FilePathCollection& zimpaths)
throw std::runtime_error("Unable to add the ZIM file '" + zimpath + "'");
}
+ run(serverPort);
+}
+
+void ZimFileServer::run(int serverPort)
+{
const std::string address = "127.0.0.1";
nameMapper.reset(new kiwix::HumanReadableNameMapper(library, false));
server.reset(new kiwix::Server(&library, nameMapper.get()));
@@ -546,3 +565,88 @@ TEST_F(ServerTest, RangeHeaderIsCaseInsensitive)
EXPECT_EQ(r0->body, r->body);
}
}
+
+////////////////////////////////////////////////////////////////////////////////
+// Testing of the library-related functionality of the server
+////////////////////////////////////////////////////////////////////////////////
+
+class LibraryServerTest : public ::testing::Test
+{
+protected:
+ std::unique_ptr zfs1_;
+
+ const int PORT = 8002;
+
+protected:
+ void SetUp() override {
+ zfs1_.reset(new ZimFileServer(PORT, "./test/library.xml"));
+ }
+
+ void TearDown() override {
+ zfs1_.reset();
+ }
+};
+
+std::string maskVariableOPDSFeedData(const std::string& s)
+{
+ const auto p = s.find("");
+ const std::string u("YYYY-MM-DDThh:mm:ssZ");
+ return s.substr(0, p) + u + s.substr(p + u.size());
+}
+
+TEST_F(LibraryServerTest, catalog_root_xml)
+{
+ const auto r = zfs1_->GET("/catalog/root.xml");
+ EXPECT_EQ(r->status, 200);
+ EXPECT_EQ(maskVariableOPDSFeedData(r->body),
+ "\n"
+ " 5e2e6fa3-14d5-f2c2-6c16-8ceaedd82237\n"
+ " All zims\n"
+ " YYYY-MM-DDThh:mm:ssZ\n"
+ " \n"
+ " \n"
+ " \n"
+ " urn:uuid:charlesray\n"
+ " Charles, Ray\n"
+ " Wikipedia articles about Charles, Ray\n"
+ " eng\n"
+ " 2020-03-31T00:00::00Z\n"
+ " wikipedia_en_ray_charles\n"
+ " \n"
+ " unittest;wikipedia;_category:jazz;_pictures:no;_videos:no;_details:no;_ftindex:yes\n"
+ " 284\n"
+ " 2\n"
+ " /meta?name=favicon&content=zimfile\n"
+ " \n"
+ " \n"
+ " Wikipedia\n"
+ " \n"
+ " \n"
+ " Kiwix\n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " urn:uuid:raycharles\n"
+ " Ray Charles\n"
+ " Wikipedia articles about Ray Charles\n"
+ " eng\n"
+ " 2020-03-31T00:00::00Z\n"
+ " wikipedia_en_ray_charles\n"
+ " \n"
+ " unittest;wikipedia;_category:wikipedia;_pictures:no;_videos:no;_details:no;_ftindex:yes\n"
+ " 284\n"
+ " 2\n"
+ " /meta?name=favicon&content=zimfile\n"
+ " \n"
+ " \n"
+ " Wikipedia\n"
+ " \n"
+ " \n"
+ " Kiwix\n"
+ " \n"
+ " \n"
+ " \n"
+ "\n"
+ );
+}