mirror of
https://github.com/kiwix/libkiwix.git
synced 2025-06-26 10:11:30 +00:00
Make the Manager
keep a shared_ptr
instead of a raw Library reference.
We want to be sure that `Library` actually exists when we modify it. While it is not a silver bullet (user can still create a shared_ptr on a raw pointer), making the `Manager` keep `shared_ptr` on the library help us a lot here.
This commit is contained in:
@ -239,7 +239,7 @@ typedef std::vector<std::string> Langs;
|
||||
TEST(LibraryOpdsImportTest, allInOne)
|
||||
{
|
||||
auto lib = kiwix::Library::create();
|
||||
kiwix::Manager manager(lib.get());
|
||||
kiwix::Manager manager(lib);
|
||||
manager.readOpds(sampleOpdsStream, "library-opds-import.unittests.dev");
|
||||
|
||||
EXPECT_EQ(10U, lib->getBookCount(true, true));
|
||||
@ -304,7 +304,7 @@ class LibraryTest : public ::testing::Test {
|
||||
LibraryTest(): lib(kiwix::Library::create()) {}
|
||||
|
||||
void SetUp() override {
|
||||
kiwix::Manager manager(lib.get());
|
||||
kiwix::Manager manager(lib);
|
||||
manager.readOpds(sampleOpdsStream, "foo.urlHost");
|
||||
manager.readXml(sampleLibraryXML, false, "./test/library.xml", true);
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
TEST(ManagerTest, addBookFromPathAndGetIdTest)
|
||||
{
|
||||
auto lib = kiwix::Library::create();
|
||||
kiwix::Manager manager = kiwix::Manager(lib.get());
|
||||
kiwix::Manager manager = kiwix::Manager(lib);
|
||||
|
||||
auto bookId = manager.addBookFromPathAndGetId("./test/example.zim");
|
||||
ASSERT_NE(bookId, "");
|
||||
@ -49,7 +49,7 @@ const char sampleLibraryXML[] = R"(
|
||||
TEST(ManagerTest, readXml)
|
||||
{
|
||||
auto lib = kiwix::Library::create();
|
||||
kiwix::Manager manager = kiwix::Manager(lib.get());
|
||||
kiwix::Manager manager = kiwix::Manager(lib);
|
||||
|
||||
EXPECT_EQ(true, manager.readXml(sampleLibraryXML, true, "/data/lib.xml", true));
|
||||
kiwix::Book book = lib->getBookById("0d0bcd57-d3f6-cb22-44cc-a723ccb4e1b2");
|
||||
@ -71,7 +71,7 @@ TEST(ManagerTest, readXml)
|
||||
TEST(Manager, reload)
|
||||
{
|
||||
auto lib = kiwix::Library::create();
|
||||
kiwix::Manager manager(lib.get());
|
||||
kiwix::Manager manager(lib);
|
||||
|
||||
manager.reload({ "./test/library.xml" });
|
||||
EXPECT_EQ(lib->getBooksIds(), (kiwix::Library::BookIdCollection{
|
||||
|
@ -22,7 +22,7 @@ class NameMapperTest : public ::testing::Test {
|
||||
NameMapperTest(): lib(kiwix::Library::create()) {}
|
||||
protected:
|
||||
void SetUp() override {
|
||||
kiwix::Manager manager(lib.get());
|
||||
kiwix::Manager manager(lib);
|
||||
manager.readXml(libraryXML, false, "./library.xml", true);
|
||||
for ( const std::string& id : lib->getBooksIds() ) {
|
||||
kiwix::Book bookCopy = lib->getBookById(id);
|
||||
|
@ -108,7 +108,7 @@ private: // data
|
||||
|
||||
ZimFileServer::ZimFileServer(int serverPort, Cfg _cfg, std::string libraryFilePath)
|
||||
: library(kiwix::Library::create())
|
||||
, manager(this->library.get())
|
||||
, manager(this->library)
|
||||
, cfg(_cfg)
|
||||
{
|
||||
if ( kiwix::isRelativePath(libraryFilePath) )
|
||||
@ -122,7 +122,7 @@ ZimFileServer::ZimFileServer(int serverPort,
|
||||
const FilePathCollection& zimpaths,
|
||||
std::string indexTemplateString)
|
||||
: library(kiwix::Library::create())
|
||||
, manager(this->library.get())
|
||||
, manager(this->library)
|
||||
, cfg(_cfg)
|
||||
{
|
||||
for ( const auto& zimpath : zimpaths ) {
|
||||
|
Reference in New Issue
Block a user