Two unit-tests for Library::removeBookById

The `XmlLibraryTest.removeBookByIdDropsTheReader` unit-test fails,
demonstrating a bug in `kiwix::Library::removeBookById()`.
This commit is contained in:
Veloman Yunkan 2021-04-09 15:34:38 +04:00
parent ba44033273
commit ccdc316217
1 changed files with 27 additions and 0 deletions

View File

@ -283,4 +283,31 @@ TEST_F(LibraryTest, getBookByPath)
EXPECT_EQ(lib.getBookByPath(path).getId(), book.getId());
EXPECT_THROW(lib.getBookByPath("non/existant/path.zim"), std::out_of_range);
}
class XmlLibraryTest : public ::testing::Test {
protected:
void SetUp() override {
kiwix::Manager manager(&lib);
manager.readFile( "./test/library.xml", true, true);
}
kiwix::Library lib;
};
TEST_F(XmlLibraryTest, removeBookByIdRemovesTheBook)
{
EXPECT_EQ(3U, lib.getBookCount(true, true));
EXPECT_NO_THROW(lib.getBookById("raycharles"));
lib.removeBookById("raycharles");
EXPECT_EQ(2U, lib.getBookCount(true, true));
EXPECT_THROW(lib.getBookById("raycharles"), std::out_of_range);
};
TEST_F(XmlLibraryTest, removeBookByIdDropsTheReader)
{
EXPECT_NE(nullptr, lib.getReaderById("raycharles"));
lib.removeBookById("raycharles");
EXPECT_THROW(lib.getReaderById("raycharles"), std::out_of_range);
};
};