mirror of https://github.com/kiwix/libkiwix.git
Dropped Library::getBookBy*() non-const functions
This commit is contained in:
parent
298247ca9b
commit
b712c732f2
|
@ -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<Reader> getReaderById(const std::string& id);
|
||||
std::shared_ptr<zim::Archive> getArchiveById(const std::string& id);
|
||||
|
||||
|
|
|
@ -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<Book&>(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<Book&>(const_self.getBookByPath(path));
|
||||
}
|
||||
|
||||
std::shared_ptr<Reader> Library::getReaderById(const std::string& id)
|
||||
{
|
||||
try {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue