From f3be6799ba37fa766dfdd5ec263603ba3cd45006 Mon Sep 17 00:00:00 2001 From: Maxim Pimenov Date: Tue, 20 Sep 2016 20:24:53 +0300 Subject: [PATCH] Added a test. --- .../generator_tests_support/test_feature.cpp | 23 ++++++++ .../generator_tests_support/test_feature.hpp | 11 ++++ indexer/editable_map_object.cpp | 17 +++++- indexer/editable_map_object.hpp | 3 + indexer/osm_editor.cpp | 2 + search/processor.cpp | 3 +- .../search_edited_features_test.cpp | 59 +++++++++++++++++++ 7 files changed, 116 insertions(+), 2 deletions(-) diff --git a/generator/generator_tests_support/test_feature.cpp b/generator/generator_tests_support/test_feature.cpp index ea8f24329f..eaaebc0d46 100644 --- a/generator/generator_tests_support/test_feature.cpp +++ b/generator/generator_tests_support/test_feature.cpp @@ -3,10 +3,14 @@ #include "generator/feature_builder.hpp" #include "indexer/classificator.hpp" +#include "indexer/editable_map_object.hpp" #include "indexer/feature.hpp" #include "indexer/feature_algo.hpp" +#include "indexer/feature_decl.hpp" #include "indexer/feature_meta.hpp" #include "indexer/ftypes_matcher.hpp" +#include "indexer/mwm_set.hpp" +#include "indexer/osm_editor.hpp" #include "coding/multilang_utf8_string.hpp" @@ -162,6 +166,25 @@ TestPOI::TestPOI(m2::PointD const & center, string const & name, string const & m_types = {{"railway", "station"}}; } +// static +TestPOI TestPOI::AddWithEditor(osm::Editor & editor, MwmSet::MwmId const & mwmId, + string const & name, m2::PointD const & pt, FeatureID & tmp) +{ + TestPOI poi(pt, name, "en"); + + osm::EditableMapObject emo; + editor.CreatePoint(classif().GetTypeByPath({"shop", "bakery"}), pt, mwmId, emo); + + StringUtf8Multilang names; + names.AddString(StringUtf8Multilang::GetLangIndex("en"), name); + emo.SetName(names); + emo.SetTestId(poi.GetId()); + + editor.SaveEditedFeature(emo); + tmp = emo.GetID(); + return poi; +} + void TestPOI::Serialize(FeatureBuilder1 & fb) const { TestFeature::Serialize(fb); diff --git a/generator/generator_tests_support/test_feature.hpp b/generator/generator_tests_support/test_feature.hpp index fb345505ed..b617c2e796 100644 --- a/generator/generator_tests_support/test_feature.hpp +++ b/generator/generator_tests_support/test_feature.hpp @@ -1,5 +1,8 @@ #pragma once +#include "indexer/feature_decl.hpp" +#include "indexer/mwm_set.hpp" + #include "geometry/point2d.hpp" #include "std/string.hpp" @@ -8,6 +11,11 @@ class FeatureBuilder1; class FeatureType; +namespace osm +{ +class Editor; +} // namespace osm + namespace generator { namespace tests_support @@ -91,6 +99,9 @@ class TestPOI : public TestFeature public: TestPOI(m2::PointD const & center, string const & name, string const & lang); + static TestPOI AddWithEditor(osm::Editor & editor, MwmSet::MwmId const & mwmId, + string const & name, m2::PointD const & pt, FeatureID & tmp); + // TestFeature overrides: void Serialize(FeatureBuilder1 & fb) const override; string ToString() const override; diff --git a/indexer/editable_map_object.cpp b/indexer/editable_map_object.cpp index 85be3f9419..0af0c72c95 100644 --- a/indexer/editable_map_object.cpp +++ b/indexer/editable_map_object.cpp @@ -9,7 +9,7 @@ #include "std/cctype.hpp" #include "std/cmath.hpp" - +#include "std/sstream.hpp" namespace { @@ -285,6 +285,14 @@ string EditableMapObject::GetWikipedia() const return m_metadata.Get(feature::Metadata::FMD_WIKIPEDIA); } +uint64_t EditableMapObject::GetTestId() const +{ + istringstream iss(m_metadata.Get(feature::Metadata::FMD_TEST_ID)); + uint64_t id; + iss >> id; + return id; +} + void EditableMapObject::SetEditableProperties(osm::EditableProperties const & props) { m_editableProperties = props; @@ -498,6 +506,13 @@ void EditableMapObject::SetOpeningHours(string const & openingHours) m_metadata.Set(feature::Metadata::FMD_OPEN_HOURS, openingHours); } +void EditableMapObject::SetTestId(uint64_t const & id) +{ + ostringstream oss; + oss << id; + m_metadata.Set(feature::Metadata::FMD_TEST_ID, oss.str()); +} + void EditableMapObject::SetPointType() { m_geomType = feature::EGeomType::GEOM_POINT; } diff --git a/indexer/editable_map_object.hpp b/indexer/editable_map_object.hpp index 0ae8e39714..d003fa8894 100644 --- a/indexer/editable_map_object.hpp +++ b/indexer/editable_map_object.hpp @@ -109,6 +109,7 @@ public: string const & GetHouseNumber() const; string GetPostcode() const; string GetWikipedia() const; + uint64_t GetTestId() const; void SetEditableProperties(osm::EditableProperties const & props); // void SetFeatureID(FeatureID const & fid); @@ -142,6 +143,8 @@ public: void SetCuisines(vector const & cuisine); void SetOpeningHours(string const & openingHours); + void SetTestId(uint64_t const & id); + /// Special mark that it's a point feature, not area or line. void SetPointType(); /// Enables advanced mode with direct access to default name and disables any recalculations. diff --git a/indexer/osm_editor.cpp b/indexer/osm_editor.cpp index e804dee125..e4ffc6169a 100644 --- a/indexer/osm_editor.cpp +++ b/indexer/osm_editor.cpp @@ -1054,6 +1054,8 @@ FeatureID Editor::GenerateNewFeatureId(MwmSet::MwmId const & id) bool Editor::CreatePoint(uint32_t type, m2::PointD const & mercator, MwmSet::MwmId const & id, EditableMapObject & outFeature) { ASSERT(id.IsAlive(), ("Please check that feature is created in valid MWM file before calling this method.")); + ASSERT(id.GetInfo()->m_limitRect.IsPointInside(mercator), + ("Attempt to create a feature outside of the MWM's bounding box.")); outFeature.SetMercator(mercator); outFeature.SetID(GenerateNewFeatureId(id)); outFeature.SetType(type); diff --git a/search/processor.cpp b/search/processor.cpp index a2851c4987..cbd950309f 100644 --- a/search/processor.cpp +++ b/search/processor.cpp @@ -376,6 +376,7 @@ void Processor::ForEachCategoryType(StringSliceBase const & slice, ToDo && todo) void Processor::Search(SearchParams const & params, m2::RectD const & viewport) { + SetMode(params.GetMode()); bool const viewportSearch = m_mode == Mode::Viewport; bool rankPivotIsSet = false; @@ -398,8 +399,8 @@ void Processor::Search(SearchParams const & params, m2::RectD const & viewport) SetMinDistanceOnMapBetweenResults(params.m_minDistanceOnMapBetweenResults); - SetMode(params.m_mode); SetSuggestsEnabled(params.m_suggestsEnabled); + SetInputLocale(params.m_inputLocale); ASSERT(!params.m_query.empty(), ()); diff --git a/search/search_integration_tests/search_edited_features_test.cpp b/search/search_integration_tests/search_edited_features_test.cpp index bd3ed5c7f0..a4f4014fa1 100644 --- a/search/search_integration_tests/search_edited_features_test.cpp +++ b/search/search_integration_tests/search_edited_features_test.cpp @@ -59,4 +59,63 @@ UNIT_CLASS_TEST(SearchEditedFeaturesTest, Smoke) TEST(ResultsMatch("wifi bar quahog", rules), ()); } } + +UNIT_CLASS_TEST(SearchEditedFeaturesTest, SearchInViewport) +{ + TestCity city(m2::PointD(0, 0), "Canterlot", "default", 100 /* rank */); + TestPOI bakery0(m2::PointD(0, 0), "Bakery 0", "default"); + TestPOI cornerPost(m2::PointD(100, 100), "Corner Post", "default"); + auto & editor = osm::Editor::Instance(); + + BuildWorld([&](TestMwmBuilder & builder) { builder.Add(city); }); + + auto const countryId = BuildCountry("Equestria", [&](TestMwmBuilder & builder) { + builder.Add(bakery0); + builder.Add(cornerPost); + }); + + FeatureID id1, id2, id3; + auto bakery1 = TestPOI::AddWithEditor(editor, countryId, "bakery1", {1.0, 1.0}, id1); + auto bakery2 = TestPOI::AddWithEditor(editor, countryId, "bakery2", {2.0, 2.0}, id2); + auto bakery3 = TestPOI::AddWithEditor(editor, countryId, "bakery3", {3.0, 3.0}, id3); + + SetViewport(m2::RectD(-1.0, -1.0, 4.0, 4.0)); + { + TRules const rules = {ExactMatch(countryId, bakery0), ExactMatch(countryId, bakery1), + ExactMatch(countryId, bakery2), ExactMatch(countryId, bakery3)}; + + TEST(ResultsMatch("bakery", Mode::Viewport, rules), ()); + } + + SetViewport(m2::RectD(-2.0, -2.0, -1.0, -1.0)); + { + TRules const rules = {}; + + TEST(ResultsMatch("bakery", Mode::Viewport, rules), ()); + } + + SetViewport(m2::RectD(-1.0, -1.0, 1.5, 1.5)); + { + TRules const rules = {ExactMatch(countryId, bakery0), ExactMatch(countryId, bakery1)}; + + TEST(ResultsMatch("bakery", Mode::Viewport, rules), ()); + } + + SetViewport(m2::RectD(1.5, 1.5, 4.0, 4.0)); + { + TRules const rules = {ExactMatch(countryId, bakery2), ExactMatch(countryId, bakery3)}; + + TEST(ResultsMatch("bakery", Mode::Viewport, rules), ()); + } + + editor.DeleteFeature(id1); + editor.DeleteFeature(id3); + + SetViewport(m2::RectD(-1.0, -1.0, 4.0, 4.0)); + { + TRules const rules = {ExactMatch(countryId, bakery0), ExactMatch(countryId, bakery2)}; + + TEST(ResultsMatch("bakery", Mode::Viewport, rules), ()); + } +} } // namespace