From ff21a095cba35b16d89472ecd50cd804251f89a6 Mon Sep 17 00:00:00 2001 From: luddens Date: Tue, 7 Jan 2020 14:54:49 +0100 Subject: [PATCH] update book even if the members aren't empty remove the conditions to always update the book --- src/book.cpp | 28 +++++++--------------------- test/book.cpp | 33 +++++++++++++++++++++++++++++++++ test/meson.build | 3 ++- 3 files changed, 42 insertions(+), 22 deletions(-) create mode 100644 test/book.cpp diff --git a/src/book.cpp b/src/book.cpp index 55f1505a0..3e530510a 100644 --- a/src/book.cpp +++ b/src/book.cpp @@ -45,28 +45,14 @@ bool Book::update(const kiwix::Book& other) return false; m_readOnly = other.m_readOnly; + m_path = other.m_path; + m_pathValid = other.m_pathValid; + m_url = other.m_url; + m_tags = other.m_tags; + m_name = other.m_name; + m_favicon = other.m_favicon; + m_faviconMimeType = other.m_faviconMimeType; - if (m_path.empty()) { - m_path = other.m_path; - m_pathValid = other.m_pathValid; - } - - if (m_url.empty()) { - m_url = other.m_url; - } - - if (m_tags.empty()) { - m_tags = other.m_tags; - } - - if (m_name.empty()) { - m_name = other.m_name; - } - - if (m_faviconMimeType.empty()) { - m_favicon = other.m_favicon; - m_faviconMimeType = other.m_faviconMimeType; - } return true; } diff --git a/test/book.cpp b/test/book.cpp new file mode 100644 index 000000000..3298ee953 --- /dev/null +++ b/test/book.cpp @@ -0,0 +1,33 @@ +#include "gtest/gtest.h" +#include "../include/book.h" + +TEST(BookTest, updateTest) +{ + kiwix::Book book; + + book.setReadOnly(false); + book.setPath("/home/user/Downloads/skin-of-color-society_en_all_2019-11.zim"); + book.setPathValid(true); + book.setUrl("book-url"); + book.setTags("youtube;_videos:yes;_ftindex:yes;_ftindex:yes;_pictures:yes;_details:yes"); + book.setName("skin-of-color-society_en_all"); + book.setFavicon("book-favicon"); + book.setFaviconMimeType("book-favicon-mimetype"); + + kiwix::Book newBook; + + newBook.setReadOnly(true); + EXPECT_FALSE(newBook.update(book)); + + newBook.setReadOnly(false); + EXPECT_TRUE(newBook.update(book)); + + EXPECT_EQ(newBook.readOnly(), book.readOnly()); + EXPECT_EQ(newBook.getPath(), book.getPath()); + EXPECT_EQ(newBook.isPathValid(), book.isPathValid()); + EXPECT_EQ(newBook.getUrl(), book.getUrl()); + EXPECT_EQ(newBook.getTags(), book.getTags()); + EXPECT_EQ(newBook.getName(), book.getName()); + EXPECT_EQ(newBook.getFavicon(), book.getFavicon()); + EXPECT_EQ(newBook.getFaviconMimeType(), book.getFaviconMimeType()); +} diff --git a/test/meson.build b/test/meson.build index c4690e1fb..dec41fbd0 100644 --- a/test/meson.build +++ b/test/meson.build @@ -7,7 +7,8 @@ tests = [ 'tagParsing', 'stringTools', 'pathTools', - 'kiwixserve' + 'kiwixserve', + 'book' ]