From 4eaebe2ea8c551e824dcc06715c6fbbf2eff4da8 Mon Sep 17 00:00:00 2001 From: Tushar Maheshwari Date: Sat, 17 Aug 2024 02:17:00 +0530 Subject: [PATCH] chore: Update test files and dependencies --- test/counterParsing.cpp | 2 +- test/defaultIndexdata.cpp | 4 +- test/error_in_creator.cpp | 77 ++++++++++++--------------------------- test/parseLongPath.cpp | 64 +++++++------------------------- 4 files changed, 40 insertions(+), 107 deletions(-) diff --git a/test/counterParsing.cpp b/test/counterParsing.cpp index bc9cc9394..b99110812 100644 --- a/test/counterParsing.cpp +++ b/test/counterParsing.cpp @@ -25,7 +25,7 @@ #include "../src/tools.h" using namespace zim; -#define parse parseMimetypeCounter +const auto parse = parseMimetypeCounter; namespace { diff --git a/test/defaultIndexdata.cpp b/test/defaultIndexdata.cpp index 9956a6b07..29a1e7ec0 100644 --- a/test/defaultIndexdata.cpp +++ b/test/defaultIndexdata.cpp @@ -96,7 +96,7 @@ namespace { ASSERT_EQ(indexData->getWordCount(), 3U); auto geoPos = indexData->getGeoPosition(); ASSERT_TRUE(std::get<0>(geoPos)); - ASSERT_TRUE(std::abs(std::get<1>(geoPos)-45.005) < 0.00001); - ASSERT_TRUE(std::abs(std::get<2>(geoPos)-10.1) < 0.00001); + ASSERT_NEAR(std::get<1>(geoPos), 45.005, 0.00001); + ASSERT_NEAR(std::get<2>(geoPos), 10.1, 0.00001); } } diff --git a/test/error_in_creator.cpp b/test/error_in_creator.cpp index 2dc2cbf7b..5d2ef2cfe 100644 --- a/test/error_in_creator.cpp +++ b/test/error_in_creator.cpp @@ -182,36 +182,21 @@ TEST_P(FaultyItemErrorTest, faultyItem) EXPECT_NO_THROW(creator.finishZimCreation()); } -// It would be more natural to put the `#if defined` only around the -// discarded values, but when crosscompiling on Windows, compiler fail to -// understand ``#if defined` when used inside the `INSTANTIATE_TEST_SUITE_P` -// macro. I suspect some macro definition conflicts. +const auto errorKinds = { + ERRORKIND::PATH, + ERRORKIND::TITLE, + ERRORKIND::MIMETYPE, + ERRORKIND::HINTS, + ERRORKIND::GET_CONTENTPROVIDER, + ERRORKIND::EXCEPTION_CONTENTPROVIDER_SIZE, #if defined(ENABLE_XAPIAN) + ERRORKIND::GET_INDEXDATA, +#endif //ENABLE_XAPIAN +}; INSTANTIATE_TEST_SUITE_P( CreatorError, FaultyItemErrorTest, -::testing::Values( - ERRORKIND::PATH, - ERRORKIND::TITLE, - ERRORKIND::MIMETYPE, - ERRORKIND::HINTS, - ERRORKIND::GET_CONTENTPROVIDER, - ERRORKIND::EXCEPTION_CONTENTPROVIDER_SIZE, - ERRORKIND::GET_INDEXDATA -)); -#else -INSTANTIATE_TEST_SUITE_P( -CreatorError, -FaultyItemErrorTest, -::testing::Values( - ERRORKIND::PATH, - ERRORKIND::TITLE, - ERRORKIND::MIMETYPE, - ERRORKIND::HINTS, - ERRORKIND::GET_CONTENTPROVIDER, - ERRORKIND::EXCEPTION_CONTENTPROVIDER_SIZE -)); -#endif //ENABLE_XAPIAN +::testing::ValuesIn(errorKinds)); double getWaitTimeFactor() { char* str_time_factor = std::getenv("WAIT_TIME_FACTOR_TEST"); @@ -352,35 +337,21 @@ TEST_P(FaultyDelayedItemErrorTest, faultyUnfinishedCreator) zim::ZimFileFormatError ); } -// It would be more natural to put the `#if defined` only around the -// discarded values, but when crosscompiling on Windows, compiler fail to -// understand ``#if defined` when used inside the `INSTANTIATE_TEST_SUITE_P` -// macro. I suspect some macro definition conflicts. +const auto delayedErrorKinds = { + ERRORKIND::EXCEPTION_CONTENTPROVIDER_FEED, + ERRORKIND::WRONG_OVER_SIZE_CONTENTPROVIDER, + ERRORKIND::WRONG_UNDER_SIZE_CONTENTPROVIDER, #if defined(ENABLE_XAPIAN) + ERRORKIND::HAS_INDEXDATA, + ERRORKIND::GET_INDEXDATA_TITLE, + ERRORKIND::GET_INDEXDATA_CONTENT, + ERRORKIND::GET_INDEXDATA_KEYWORD, + ERRORKIND::GET_INDEXDATA_WORDCOUNT, + ERRORKIND::GET_INDEXDATA_POSITION, +#endif // ENABLE_XAPIAN +}; INSTANTIATE_TEST_SUITE_P( CreatorError, FaultyDelayedItemErrorTest, -::testing::Values( - ERRORKIND::EXCEPTION_CONTENTPROVIDER_FEED, - ERRORKIND::WRONG_OVER_SIZE_CONTENTPROVIDER, - ERRORKIND::WRONG_UNDER_SIZE_CONTENTPROVIDER , - ERRORKIND::HAS_INDEXDATA, - ERRORKIND::GET_INDEXDATA_TITLE, - ERRORKIND::GET_INDEXDATA_CONTENT, - ERRORKIND::GET_INDEXDATA_KEYWORD, - ERRORKIND::GET_INDEXDATA_WORDCOUNT, - ERRORKIND::GET_INDEXDATA_POSITION -)); -#else -INSTANTIATE_TEST_SUITE_P( -CreatorError, -FaultyDelayedItemErrorTest, -::testing::Values( - ERRORKIND::EXCEPTION_CONTENTPROVIDER_FEED, - ERRORKIND::WRONG_OVER_SIZE_CONTENTPROVIDER, - ERRORKIND::WRONG_UNDER_SIZE_CONTENTPROVIDER -)); -#endif // ENABLE_XAPIAN +::testing::ValuesIn(delayedErrorKinds)); } // unnamed namespace - - diff --git a/test/parseLongPath.cpp b/test/parseLongPath.cpp index 2ee7c031f..ffdbf67b7 100644 --- a/test/parseLongPath.cpp +++ b/test/parseLongPath.cpp @@ -25,7 +25,7 @@ namespace zim { std::tuple parseLongPath(const std::string& longPath); }; -using namespace zim; +using zim::parseLongPath; namespace { @@ -44,55 +44,17 @@ TEST(ParseLongPathTest, invalid) TEST(ParseLongPathTest, valid) { - char ns; - std::string path; - - std::tie(ns, path) = parseLongPath("A/path"); - ASSERT_EQ(ns, 'A'); - ASSERT_EQ(path, "path"); - - std::tie(ns, path) = parseLongPath("A/p"); - ASSERT_EQ(ns, 'A'); - ASSERT_EQ(path, "p"); - - std::tie(ns, path) = parseLongPath("/B/path"); - ASSERT_EQ(ns, 'B'); - ASSERT_EQ(path, "path"); - - std::tie(ns, path) = parseLongPath("/B/p"); - ASSERT_EQ(ns, 'B'); - ASSERT_EQ(path, "p"); - - std::tie(ns, path) = parseLongPath("C//path"); - ASSERT_EQ(ns, 'C'); - ASSERT_EQ(path, "/path"); - - std::tie(ns, path) = parseLongPath("/C//path"); - ASSERT_EQ(ns, 'C'); - ASSERT_EQ(path, "/path"); - - std::tie(ns, path) = parseLongPath("L/path/with/separator"); - ASSERT_EQ(ns, 'L'); - ASSERT_EQ(path, "path/with/separator"); - - std::tie(ns, path) = parseLongPath("L//path/with/separator"); - ASSERT_EQ(ns, 'L'); - ASSERT_EQ(path, "/path/with/separator"); - - std::tie(ns, path) = parseLongPath("A"); - ASSERT_EQ(ns, 'A'); - ASSERT_EQ(path, ""); - - std::tie(ns, path) = parseLongPath("/A"); - ASSERT_EQ(ns, 'A'); - ASSERT_EQ(path, ""); - - std::tie(ns, path) = parseLongPath("A/"); - ASSERT_EQ(ns, 'A'); - ASSERT_EQ(path, ""); - - std::tie(ns, path) = parseLongPath("/A/"); - ASSERT_EQ(ns, 'A'); - ASSERT_EQ(path, ""); + ASSERT_EQ(parseLongPath("A/path"), std::make_tuple('A', "path")); + ASSERT_EQ(parseLongPath("A/p"), std::make_tuple('A', "p")); + ASSERT_EQ(parseLongPath("/B/path"), std::make_tuple('B', "path")); + ASSERT_EQ(parseLongPath("/B/p"), std::make_tuple('B', "p")); + ASSERT_EQ(parseLongPath("C//path"), std::make_tuple('C', "/path")); + ASSERT_EQ(parseLongPath("/C//path"), std::make_tuple('C', "/path")); + ASSERT_EQ(parseLongPath("L/path/with/separator"), std::make_tuple('L', "path/with/separator")); + ASSERT_EQ(parseLongPath("L//path/with/separator"), std::make_tuple('L', "/path/with/separator")); + ASSERT_EQ(parseLongPath("A"), std::make_tuple('A', "")); + ASSERT_EQ(parseLongPath("/A"), std::make_tuple('A', "")); + ASSERT_EQ(parseLongPath("A/"), std::make_tuple('A', "")); + ASSERT_EQ(parseLongPath("/A/"), std::make_tuple('A', "")); } };