diff options
author | Yuri Gorshenin <y@maps.me> | 2016-08-22 13:47:56 +0300 |
---|---|---|
committer | Yuri Gorshenin <y@maps.me> | 2016-08-26 16:21:13 +0300 |
commit | afc3d20264e8fcd99dc3cd465ce1770d0b3246d0 (patch) | |
tree | 67d2bcd855340555d742181e467cc987bd70a332 /indexer | |
parent | 336c137d59c12d0de9fd292bcf3db9b453670567 (diff) |
[search] Added matching of edited features by type.
Diffstat (limited to 'indexer')
-rw-r--r-- | indexer/indexer_tests/indexer_tests.pro | 8 | ||||
-rw-r--r-- | indexer/indexer_tests/osm_editor_test.cpp | 22 | ||||
-rw-r--r-- | indexer/indexer_tests_support/helpers.cpp | 19 | ||||
-rw-r--r-- | indexer/indexer_tests_support/helpers.hpp | 30 | ||||
-rw-r--r-- | indexer/indexer_tests_support/indexer_tests_support.pro | 13 | ||||
-rw-r--r-- | indexer/osm_editor.cpp | 1 | ||||
-rw-r--r-- | indexer/osm_editor.hpp | 12 |
7 files changed, 78 insertions, 27 deletions
diff --git a/indexer/indexer_tests/indexer_tests.pro b/indexer/indexer_tests/indexer_tests.pro index 43abbd013a..81b1b08b1b 100644 --- a/indexer/indexer_tests/indexer_tests.pro +++ b/indexer/indexer_tests/indexer_tests.pro @@ -4,10 +4,10 @@ CONFIG -= app_bundle TEMPLATE = app ROOT_DIR = ../.. -DEPENDENCIES = search_tests_support generator_tests_support platform_tests_support \ - generator search routing indexer storage editor platform coding geometry \ - base stats_client jansson tess2 protobuf tomcrypt succinct opening_hours \ - pugixml +DEPENDENCIES = generator_tests_support search_tests_support indexer_tests_support \ + platform_tests_support generator search routing indexer storage editor \ + platform coding geometry base stats_client jansson tess2 protobuf tomcrypt \ + succinct opening_hours pugixml include($$ROOT_DIR/common.pri) diff --git a/indexer/indexer_tests/osm_editor_test.cpp b/indexer/indexer_tests/osm_editor_test.cpp index c19032ccb2..21bc744d23 100644 --- a/indexer/indexer_tests/osm_editor_test.cpp +++ b/indexer/indexer_tests/osm_editor_test.cpp @@ -4,11 +4,12 @@ #include "search/reverse_geocoder.hpp" -#include "indexer/classificator_loader.hpp" #include "indexer/classificator.hpp" +#include "indexer/classificator_loader.hpp" #include "indexer/ftypes_matcher.hpp" -#include "indexer/osm_editor.hpp" #include "indexer/index_helpers.hpp" +#include "indexer/indexer_tests_support/helpers.hpp" +#include "indexer/osm_editor.hpp" #include "editor/editor_storage.hpp" @@ -17,6 +18,7 @@ #include "coding/file_name_utils.hpp" using namespace generator::tests_support; +using namespace indexer::tests_support; namespace { @@ -70,17 +72,6 @@ void FillEditableMapObject(osm::Editor const & editor, FeatureType const & ft, o emo.SetEditableProperties(editor.GetEditableProperties(ft)); } -template <typename TFn> -void EditFeature(FeatureType const & ft, TFn && fn) -{ - auto & editor = osm::Editor::Instance(); - - osm::EditableMapObject emo; - FillEditableMapObject(editor, ft, emo); - fn(emo); - TEST_EQUAL(editor.SaveEditedFeature(emo), osm::Editor::SaveResult::SavedSuccessfully, ()); -} - void SetBuildingLevelsToOne(FeatureType const & ft) { EditFeature(ft, [](osm::EditableMapObject & emo) @@ -153,10 +144,7 @@ EditorTest::EditorTest() LOG(LERROR, ("Classificator read error: ", e.what())); } - auto & editor = osm::Editor::Instance(); - editor.SetIndex(m_index); - editor.m_storage = make_unique<editor::InMemoryStorage>(); - editor.ClearAllLocalEdits(); + indexer::tests_support::SetUpEditorForTesting(m_index); } EditorTest::~EditorTest() diff --git a/indexer/indexer_tests_support/helpers.cpp b/indexer/indexer_tests_support/helpers.cpp new file mode 100644 index 0000000000..05392903de --- /dev/null +++ b/indexer/indexer_tests_support/helpers.cpp @@ -0,0 +1,19 @@ +#include "indexer/indexer_tests_support/helpers.hpp" + +#include "editor/editor_storage.hpp" + +#include "std/unique_ptr.hpp" + +namespace indexer +{ +namespace tests_support +{ +void SetUpEditorForTesting(Index & index) +{ + auto & editor = osm::Editor::Instance(); + editor.SetIndex(index); + editor.SetStorageForTesting(make_unique<editor::InMemoryStorage>()); + editor.ClearAllLocalEdits(); +} +} // namespace tests_support +} // namespace indexer diff --git a/indexer/indexer_tests_support/helpers.hpp b/indexer/indexer_tests_support/helpers.hpp new file mode 100644 index 0000000000..fd3018ffcf --- /dev/null +++ b/indexer/indexer_tests_support/helpers.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include "indexer/editable_map_object.hpp" +#include "indexer/osm_editor.hpp" + +#include "base/assert.hpp" + +class Index; + +namespace indexer +{ +namespace tests_support +{ +void SetUpEditorForTesting(Index & index); + +template <typename TFn> +void EditFeature(FeatureType const & ft, TFn && fn) +{ + auto & editor = osm::Editor::Instance(); + + osm::EditableMapObject emo; + emo.SetFromFeatureType(ft); + emo.SetEditableProperties(editor.GetEditableProperties(ft)); + + fn(emo); + + CHECK_EQUAL(editor.SaveEditedFeature(emo), osm::Editor::SaveResult::SavedSuccessfully, ()); +} +} // namespace tests_support +} // namespace indexer diff --git a/indexer/indexer_tests_support/indexer_tests_support.pro b/indexer/indexer_tests_support/indexer_tests_support.pro new file mode 100644 index 0000000000..9f7d6ee79e --- /dev/null +++ b/indexer/indexer_tests_support/indexer_tests_support.pro @@ -0,0 +1,13 @@ +TARGET = indexer_tests_support +TEMPLATE = lib +CONFIG += staticlib warn_on + +ROOT_DIR = ../.. + +include($$ROOT_DIR/common.pri) + +SOURCES += \ + helpers.cpp \ + +HEADERS += \ + helpers.hpp \ diff --git a/indexer/osm_editor.cpp b/indexer/osm_editor.cpp index 30a324770a..808da533e9 100644 --- a/indexer/osm_editor.cpp +++ b/indexer/osm_editor.cpp @@ -17,7 +17,6 @@ #include "platform/preferred_languages.hpp" #include "editor/changeset_wrapper.hpp" -#include "editor/editor_storage.hpp" #include "editor/osm_auth.hpp" #include "editor/server_api.hpp" #include "editor/xml_feature.hpp" diff --git a/indexer/osm_editor.hpp b/indexer/osm_editor.hpp index 282f9b98ef..dcdf39255a 100644 --- a/indexer/osm_editor.hpp +++ b/indexer/osm_editor.hpp @@ -10,6 +10,7 @@ #include "editor/editor_config.hpp" #include "editor/editor_notes.hpp" +#include "editor/editor_storage.hpp" #include "editor/xml_feature.hpp" #include "base/timer.hpp" @@ -23,11 +24,6 @@ namespace editor { -class StorageBase; -} // namespace editor - -namespace editor -{ namespace testing { class EditorTest; @@ -74,9 +70,15 @@ public: }; static Editor & Instance(); + // Reference to the index will be used in editor functors, it should not be temporary object. void SetIndex(Index const & index); + inline void SetStorageForTesting(unique_ptr<editor::StorageBase> storage) + { + m_storage = move(storage); + } + void SetInvalidateFn(TInvalidateFn const & fn) { m_invalidateFn = fn; } void LoadMapEdits(); |