diff --git a/search/search_integration_tests/retrieval_test.cpp b/search/search_integration_tests/retrieval_test.cpp index a302779dbe..917578d830 100644 --- a/search/search_integration_tests/retrieval_test.cpp +++ b/search/search_integration_tests/retrieval_test.cpp @@ -34,6 +34,8 @@ using namespace search::tests_support; +using TRules = vector>; + namespace { void InitParams(string const & query, search::SearchQueryParams & params) @@ -142,9 +144,9 @@ UNIT_TEST(Retrieval_Smoke) platform::LocalCountryFile file(platform.WritableDir(), platform::CountryFile("WhiskeyTown"), 0); Cleanup(file); MY_SCOPE_GUARD(deleteFile, [&]() - { - Cleanup(file); - }); + { + Cleanup(file); + }); // Create a test mwm with 100 whiskey bars. { @@ -228,9 +230,9 @@ UNIT_TEST(Retrieval_3Mwms) platform::LocalCountryFile zrh(platform.WritableDir(), platform::CountryFile("zrh"), 0); Cleanup({msk, mtv, zrh}); MY_SCOPE_GUARD(cleanup, [&]() - { - Cleanup({msk, mtv, zrh}); - }); + { + Cleanup({msk, mtv, zrh}); + }); { TestMwmBuilder builder(msk, feature::DataHeader::country); @@ -339,7 +341,7 @@ UNIT_TEST(Retrieval_CafeMTV) 0); Cleanup({msk, mtv, testWorld}); MY_SCOPE_GUARD(cleanup, [&]() - { + { Cleanup({msk, mtv, testWorld}); }); @@ -387,10 +389,8 @@ UNIT_TEST(Retrieval_CafeMTV) TestSearchRequest request(engine, "Moscow ", "en", search::Mode::Everywhere, mskViewport); request.Wait(); - initializer_list> mskCityAlts = { - make_shared(testWorldId, mskCity), make_shared(mskId, mskCity)}; - vector> rules = {make_shared(mskCityAlts), - make_shared(mtvId, mskCafe)}; + auto mskCityAlts = {ExactMatch(testWorldId, mskCity), ExactMatch(mskId, mskCity)}; + TRules rules = {AlternativesMatch(mskCityAlts), ExactMatch(mtvId, mskCafe)}; TEST(MatchResults(engine, rules, request.Results()), ()); } @@ -398,10 +398,8 @@ UNIT_TEST(Retrieval_CafeMTV) TestSearchRequest request(engine, "MTV ", "en", search::Mode::Everywhere, mtvViewport); request.Wait(); - initializer_list> mtvCityAlts = { - make_shared(testWorldId, mtvCity), make_shared(mtvId, mtvCity)}; - vector> rules = {make_shared(mtvCityAlts), - make_shared(mskId, mtvCafe)}; + auto mtvCityAlts = {ExactMatch(testWorldId, mtvCity), ExactMatch(mtvId, mtvCity)}; + TRules rules = {AlternativesMatch(mtvCityAlts), ExactMatch(mskId, mtvCafe)}; TEST(MatchResults(engine, rules, request.Results()), ()); } @@ -409,9 +407,8 @@ UNIT_TEST(Retrieval_CafeMTV) TestSearchRequest request(engine, "Moscow MTV ", "en", search::Mode::Everywhere, mtvViewport); request.Wait(); - initializer_list> alternatives = { - make_shared(mskId, mtvCafe), make_shared(mtvId, mskCafe)}; - vector> rules = {make_shared(alternatives)}; + auto alternatives = {ExactMatch(mskId, mtvCafe), ExactMatch(mtvId, mskCafe)}; + TRules rules = {AlternativesMatch(alternatives)}; // TODO (@gorshenin): current search algorithm can't retrieve both // Cafe Moscow @ MTV and Cafe MTV @ Moscow, it'll just return one diff --git a/search/search_integration_tests/search_query_v2_test.cpp b/search/search_integration_tests/search_query_v2_test.cpp index 0cc1492344..7a62272db5 100644 --- a/search/search_integration_tests/search_query_v2_test.cpp +++ b/search/search_integration_tests/search_query_v2_test.cpp @@ -70,7 +70,7 @@ public: void RegisterCountry(string const & name, m2::RectD const & rect) { auto & infoGetter = - static_cast(m_engine.GetCountryInfoGetter()); + static_cast(m_engine.GetCountryInfoGetter()); infoGetter.AddCountry(storage::CountryDef(name, rect)); } @@ -99,7 +99,8 @@ public: return MatchResults(m_engine, rules, request.Results()); } - bool ResultsMatch(string const & query, search::Mode mode, vector> const & rules) + bool ResultsMatch(string const & query, search::Mode mode, + vector> const & rules) { TestSearchRequest request(m_engine, query, "en", mode, m_viewport); request.Wait(); @@ -204,69 +205,65 @@ UNIT_CLASS_TEST(SearchQueryV2Test, Smoke) SetViewport(m2::RectD(m2::PointD(-1.0, -1.0), m2::PointD(1.0, 1.0))); { - TRules rules = {make_shared(wonderlandId, busStop)}; + TRules rules = {ExactMatch(wonderlandId, busStop)}; TEST(ResultsMatch("Bus stop", rules), ()); } { - TRules rules = {make_shared(wonderlandId, quantumCafe), - make_shared(wonderlandId, quantumTeleport1), - make_shared(wonderlandId, quantumTeleport2)}; + TRules rules = {ExactMatch(wonderlandId, quantumCafe), + ExactMatch(wonderlandId, quantumTeleport1), + ExactMatch(wonderlandId, quantumTeleport2)}; TEST(ResultsMatch("quantum", rules), ()); } { - TRules rules = {make_shared(wonderlandId, quantumCafe), - make_shared(wonderlandId, quantumTeleport1)}; + TRules rules = {ExactMatch(wonderlandId, quantumCafe), + ExactMatch(wonderlandId, quantumTeleport1)}; TEST(ResultsMatch("quantum Moscow ", rules), ()); } { TEST(ResultsMatch(" ", TRules()), ()); } { - TRules rules = {make_shared(wonderlandId, quantumTeleport2)}; + TRules rules = {ExactMatch(wonderlandId, quantumTeleport2)}; TEST(ResultsMatch("teleport feynman street", rules), ()); } { - TRules rules = {make_shared(wonderlandId, quantumTeleport2)}; + TRules rules = {ExactMatch(wonderlandId, quantumTeleport2)}; TEST(ResultsMatch("feynman street 3", rules), ()); } { - TRules rules = {make_shared(wonderlandId, feynmanHouse), - make_shared(wonderlandId, lantern1)}; + TRules rules = {ExactMatch(wonderlandId, feynmanHouse), ExactMatch(wonderlandId, lantern1)}; TEST(ResultsMatch("feynman street 1", rules), ()); } { - TRules rules = {make_shared(wonderlandId, bohrHouse), - make_shared(wonderlandId, hilbertHouse), - make_shared(wonderlandId, lantern1)}; + TRules rules = {ExactMatch(wonderlandId, bohrHouse), ExactMatch(wonderlandId, hilbertHouse), + ExactMatch(wonderlandId, lantern1)}; TEST(ResultsMatch("bohr street 1", rules), ()); } { TEST(ResultsMatch("bohr street 1 unit 3", TRules()), ()); } { - TRules rules = {make_shared(wonderlandId, lantern1), - make_shared(wonderlandId, lantern2)}; + TRules rules = {ExactMatch(wonderlandId, lantern1), ExactMatch(wonderlandId, lantern2)}; TEST(ResultsMatch("bohr street 1 lantern ", rules), ()); } { - TRules rules = {make_shared(wonderlandId, feynmanHouse)}; + TRules rules = {ExactMatch(wonderlandId, feynmanHouse)}; TEST(ResultsMatch("wonderland los alamos feynman 1 unit 1 ", rules), ()); } { // It's possible to find Descartes house by name. - TRules rules = {make_shared(wonderlandId, descartesHouse)}; + TRules rules = {ExactMatch(wonderlandId, descartesHouse)}; TEST(ResultsMatch("Los Alamos Descartes", rules), ()); } { // It's not possible to find Descartes house by house number, // because it doesn't belong to Los Alamos streets. But it still // exists. - TRules rules = {make_shared(wonderlandId, lantern2), - make_shared(wonderlandId, quantumTeleport2)}; + TRules rules = {ExactMatch(wonderlandId, lantern2), ExactMatch(wonderlandId, quantumTeleport2)}; TEST(ResultsMatch("Los Alamos 2", rules), ()); } { - TRules rules = {make_shared(wonderlandId, bornHouse)}; + TRules rules = {ExactMatch(wonderlandId, bornHouse)}; TEST(ResultsMatch("long pond 1st april street 8", rules), ()); } } @@ -276,8 +273,7 @@ UNIT_CLASS_TEST(SearchQueryV2Test, SearchInWorld) TestCountry wonderland(m2::PointD(0, 0), "Wonderland", "en"); TestCity losAlamos(m2::PointD(0, 0), "Los Alamos", "en", 100 /* rank */); - auto testWorldId = BuildMwm("testWorld", feature::DataHeader::world, - [&](TestMwmBuilder & builder) + auto testWorldId = BuildMwm("testWorld", feature::DataHeader::world, [&](TestMwmBuilder & builder) { builder.Add(wonderland); builder.Add(losAlamos); @@ -287,15 +283,15 @@ UNIT_CLASS_TEST(SearchQueryV2Test, SearchInWorld) SetViewport(m2::RectD(m2::PointD(-1.0, -1.0), m2::PointD(-0.5, -0.5))); { - TRules rules = {make_shared(testWorldId, losAlamos)}; + TRules rules = {ExactMatch(testWorldId, losAlamos)}; TEST(ResultsMatch("Los Alamos", rules), ()); } { - TRules rules = {make_shared(testWorldId, wonderland)}; + TRules rules = {ExactMatch(testWorldId, wonderland)}; TEST(ResultsMatch("Wonderland", rules), ()); } { - TRules rules = {make_shared(testWorldId, losAlamos)}; + TRules rules = {ExactMatch(testWorldId, losAlamos)}; TEST(ResultsMatch("Wonderland Los Alamos", rules), ()); } } @@ -312,18 +308,18 @@ UNIT_CLASS_TEST(SearchQueryV2Test, SearchByName) { builder.Add(london); }); - auto wonderlandId = BuildMwm("wonderland", feature::DataHeader::country, - [&](TestMwmBuilder & builder) - { - builder.Add(hydePark); - builder.Add(cafe); - }); + auto wonderlandId = + BuildMwm("wonderland", feature::DataHeader::country, [&](TestMwmBuilder & builder) + { + builder.Add(hydePark); + builder.Add(cafe); + }); RegisterCountry("Wonderland", m2::RectD(m2::PointD(0, 0), m2::PointD(2, 2))); SetViewport(m2::RectD(m2::PointD(-1.0, -1.0), m2::PointD(-0.9, -0.9))); { - TRules rules = {make_shared(wonderlandId, hydePark)}; + TRules rules = {ExactMatch(wonderlandId, hydePark)}; TEST(ResultsMatch("hyde park", rules), ()); TEST(ResultsMatch("london hyde park", rules), ()); TEST(ResultsMatch("hyde london park", TRules()), ()); @@ -331,12 +327,11 @@ UNIT_CLASS_TEST(SearchQueryV2Test, SearchByName) SetViewport(m2::RectD(m2::PointD(0.5, 0.5), m2::PointD(1.5, 1.5))); { - TRules rules = {make_shared(worldId, london)}; + TRules rules = {ExactMatch(worldId, london)}; TEST(ResultsMatch("london", search::Mode::World, rules), ()); } { - TRules rules = {make_shared(worldId, london), - make_shared(wonderlandId, cafe)}; + TRules rules = {ExactMatch(worldId, london), ExactMatch(wonderlandId, cafe)}; TEST(ResultsMatch("london", search::Mode::Everywhere, rules), ()); } } diff --git a/search/search_tests_support/test_results_matching.cpp b/search/search_tests_support/test_results_matching.cpp index 30bb69bc88..dde87f4674 100644 --- a/search/search_tests_support/test_results_matching.cpp +++ b/search/search_tests_support/test_results_matching.cpp @@ -11,31 +11,31 @@ namespace search { namespace tests_support { -ExactMatch::ExactMatch(MwmSet::MwmId const & mwmId, TestFeature & feature) +ExactMatchingRule::ExactMatchingRule(MwmSet::MwmId const & mwmId, TestFeature & feature) : m_mwmId(mwmId), m_feature(feature) { } -bool ExactMatch::Matches(FeatureType const & feature) const +bool ExactMatchingRule::Matches(FeatureType const & feature) const { if (m_mwmId != feature.GetID().m_mwmId) return false; return m_feature.Matches(feature); } -string ExactMatch::ToString() const +string ExactMatchingRule::ToString() const { ostringstream os; - os << "ExactMatch [ " << DebugPrint(m_mwmId) << ", " << DebugPrint(m_feature) << " ]"; + os << "ExactMatchingRule [ " << DebugPrint(m_mwmId) << ", " << DebugPrint(m_feature) << " ]"; return os.str(); } -AlternativesMatch::AlternativesMatch(initializer_list> rules) +AlternativesMatchingRule::AlternativesMatchingRule(initializer_list> rules) : m_rules(move(rules)) { } -bool AlternativesMatch::Matches(FeatureType const & feature) const +bool AlternativesMatchingRule::Matches(FeatureType const & feature) const { for (auto const & rule : m_rules) { @@ -45,7 +45,7 @@ bool AlternativesMatch::Matches(FeatureType const & feature) const return false; } -string AlternativesMatch::ToString() const +string AlternativesMatchingRule::ToString() const { ostringstream os; os << "OrRule [ "; diff --git a/search/search_tests_support/test_results_matching.hpp b/search/search_tests_support/test_results_matching.hpp index 06edc26c03..5ddb1be1bd 100644 --- a/search/search_tests_support/test_results_matching.hpp +++ b/search/search_tests_support/test_results_matching.hpp @@ -26,10 +26,10 @@ public: virtual string ToString() const = 0; }; -class ExactMatch : public MatchingRule +class ExactMatchingRule : public MatchingRule { public: - ExactMatch(MwmSet::MwmId const & mwmId, TestFeature & feature); + ExactMatchingRule(MwmSet::MwmId const & mwmId, TestFeature & feature); // MatchingRule overrides: bool Matches(FeatureType const & feature) const override; @@ -40,10 +40,10 @@ private: TestFeature & m_feature; }; -class AlternativesMatch : public MatchingRule +class AlternativesMatchingRule : public MatchingRule { public: - AlternativesMatch(initializer_list> rules); + AlternativesMatchingRule(initializer_list> rules); // MatchingRule overrides: bool Matches(FeatureType const & feature) const override; @@ -53,6 +53,18 @@ private: vector> m_rules; }; +template +shared_ptr ExactMatch(TArgs &&... args) +{ + return make_shared(forward(args)...); +} + +template +shared_ptr AlternativesMatch(TArgs &&... args) +{ + return make_shared(forward(args)...); +} + bool MatchResults(Index const & index, vector> rules, vector const & actual);