From b712c732f26e4c598650836dd9691c2885cd93c4 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sun, 28 Nov 2021 13:48:04 +0400 Subject: [PATCH] Dropped Library::getBookBy*() non-const functions --- include/library.h | 2 -- src/library.cpp | 12 ------------ test/library.cpp | 5 +++-- test/name_mapper.cpp | 6 ++++-- 4 files changed, 7 insertions(+), 18 deletions(-) diff --git a/include/library.h b/include/library.h index 9191b47d2..7211a843f 100644 --- a/include/library.h +++ b/include/library.h @@ -197,9 +197,7 @@ class Library bool removeBookmark(const std::string& zimId, const std::string& url); const Book& getBookById(const std::string& id) const; - Book& getBookById(const std::string& id); const Book& getBookByPath(const std::string& path) const; - Book& getBookByPath(const std::string& path); std::shared_ptr getReaderById(const std::string& id); std::shared_ptr getArchiveById(const std::string& id); diff --git a/src/library.cpp b/src/library.cpp index 5caacc64c..e7afad696 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -132,12 +132,6 @@ const Book& Library::getBookById(const std::string& id) const return m_books.at(id); } -Book& Library::getBookById(const std::string& id) -{ - const Library& const_self = *this; - return const_cast(const_self.getBookById(id)); -} - const Book& Library::getBookByPath(const std::string& path) const { for(auto& it: m_books) { @@ -150,12 +144,6 @@ const Book& Library::getBookByPath(const std::string& path) const throw std::out_of_range(ss.str()); } -Book& Library::getBookByPath(const std::string& path) -{ - const Library& const_self = *this; - return const_cast(const_self.getBookByPath(path)); -} - std::shared_ptr Library::getReaderById(const std::string& id) { try { diff --git a/test/library.cpp b/test/library.cpp index 77780ba7b..e06026318 100644 --- a/test/library.cpp +++ b/test/library.cpp @@ -232,7 +232,7 @@ class LibraryTest : public ::testing::Test { void SetUp() override { kiwix::Manager manager(&lib); manager.readOpds(sampleOpdsStream, "foo.urlHost"); - manager.readXml(sampleLibraryXML, true, "./test/library.xml", true); + manager.readXml(sampleLibraryXML, false, "./test/library.xml", true); } kiwix::Bookmark createBookmark(const std::string &id) { @@ -660,13 +660,14 @@ TEST_F(LibraryTest, filterByMultipleCriteria) TEST_F(LibraryTest, getBookByPath) { - auto& book = lib.getBookById(lib.getBooksIds()[0]); + kiwix::Book book = lib.getBookById(lib.getBooksIds()[0]); #ifdef _WIN32 auto path = "C:\\some\\abs\\path.zim"; #else auto path = "/some/abs/path.zim"; #endif book.setPath(path); + lib.addBook(book); EXPECT_EQ(lib.getBookByPath(path).getId(), book.getId()); EXPECT_THROW(lib.getBookByPath("non/existant/path.zim"), std::out_of_range); } diff --git a/test/name_mapper.cpp b/test/name_mapper.cpp index 2a24f329b..0bc60254a 100644 --- a/test/name_mapper.cpp +++ b/test/name_mapper.cpp @@ -21,9 +21,11 @@ class NameMapperTest : public ::testing::Test { protected: void SetUp() override { kiwix::Manager manager(&lib); - manager.readXml(libraryXML, true, "./library.xml", true); + manager.readXml(libraryXML, false, "./library.xml", true); for ( const std::string& id : lib.getBooksIds() ) { - lib.getBookById(id).setPathValid(true); + kiwix::Book bookCopy = lib.getBookById(id); + bookCopy.setPathValid(true); + lib.addBook(bookCopy); } }