From 0b1740e6c5814c9fd6e54d87e8c4b458b24f49a6 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Fri, 5 Mar 2021 00:10:44 +0400 Subject: [PATCH] LibraryServerTest.catalog_search_by_tag --- test/server.cpp | 71 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 5 deletions(-) diff --git a/test/server.cpp b/test/server.cpp index 9c4d73075..28fffc72d 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -587,11 +587,33 @@ protected: } }; -std::string maskVariableOPDSFeedData(const std::string& s) +// Returns a copy of 'text' with every line that fully matches 'pattern' +// replaced with the fixed string 'replacement' +std::string replaceLines(const std::string& text, + const std::string& pattern, + const std::string& replacement) { - const auto p = s.find(""); - const std::string u("YYYY-MM-DDThh:mm:ssZ"); - return s.substr(0, p) + u + s.substr(p + u.size()); + std::regex regex("^" + pattern + "$"); + std::ostringstream oss; + std::istringstream iss(text); + std::string line; + while ( std::getline(iss, line) ) { + if ( std::regex_match(line, regex) ) { + oss << replacement << "\n"; + } else { + oss << line << "\n"; + } + } + return oss.str(); +} + +std::string maskVariableOPDSFeedData(std::string s) +{ + s = replaceLines(s, " .+", + " YYYY-MM-DDThh:mm:ssZ"); + s = replaceLines(s, " .+", + " 12345678-90ab-cdef-1234-567890abcdef"); + return s; } TEST_F(LibraryServerTest, catalog_root_xml) @@ -600,7 +622,7 @@ TEST_F(LibraryServerTest, catalog_root_xml) EXPECT_EQ(r->status, 200); EXPECT_EQ(maskVariableOPDSFeedData(r->body), "\n" - " 5e2e6fa3-14d5-f2c2-6c16-8ceaedd82237\n" + " 12345678-90ab-cdef-1234-567890abcdef\n" " All zims\n" " YYYY-MM-DDThh:mm:ssZ\n" " \n" @@ -668,3 +690,42 @@ TEST_F(LibraryServerTest, catalog_searchdescription_xml) "\n" ); } + +TEST_F(LibraryServerTest, catalog_search_by_tag) +{ + const auto r = zfs1_->GET("/catalog/search?tag=_category:jazz"); + EXPECT_EQ(r->status, 200); + EXPECT_EQ(maskVariableOPDSFeedData(r->body), + "\n" + " 12345678-90ab-cdef-1234-567890abcdef\n" + " Search result for <Empty query>\n" + " YYYY-MM-DDThh:mm:ssZ\n" + " 1\n" + " 0\n" + " 1\n" + " \n" + " \n" + " \n" + " urn:uuid:charlesray\n" + " Charles, Ray\n" + " Wikipedia articles about Charles, Ray\n" + " eng\n" + " 2020-03-31T00:00::00Z\n" + " wikipedia_en_ray_charles\n" + " \n" + " unittest;wikipedia;_category:jazz;_pictures:no;_videos:no;_details:no;_ftindex:yes\n" + " 284\n" + " 2\n" + " /meta?name=favicon&content=zimfile\n" + " \n" + " \n" + " Wikipedia\n" + " \n" + " \n" + " Kiwix\n" + " \n" + " \n" + " \n" + "\n" + ); +}