diff options
author | Arsentiy Milchakov <milcars@mapswithme.com> | 2017-11-09 17:49:24 +0300 |
---|---|---|
committer | Yuri Gorshenin <mipt.vi002@gmail.com> | 2017-11-16 15:58:07 +0300 |
commit | 18728c8d11cb99fe2875936a7157d5b9a8c49b15 (patch) | |
tree | 742456fda94f4b0e1c512b3e8fa2ef7511ef2542 /indexer/indexer_tests_support | |
parent | 962e27b2857e544ebed4adf9a39e72634fbc2d47 (diff) |
[booking] availability filter tests
Diffstat (limited to 'indexer/indexer_tests_support')
-rw-r--r-- | indexer/indexer_tests_support/helpers.hpp | 2 | ||||
-rw-r--r-- | indexer/indexer_tests_support/test_mwm_environment.cpp | 36 | ||||
-rw-r--r-- | indexer/indexer_tests_support/test_mwm_environment.hpp | 83 |
3 files changed, 119 insertions, 2 deletions
diff --git a/indexer/indexer_tests_support/helpers.hpp b/indexer/indexer_tests_support/helpers.hpp index 6232ad7184..5adfbb0768 100644 --- a/indexer/indexer_tests_support/helpers.hpp +++ b/indexer/indexer_tests_support/helpers.hpp @@ -7,8 +7,6 @@ #include "std/unique_ptr.hpp" -class Index; - namespace indexer { namespace tests_support diff --git a/indexer/indexer_tests_support/test_mwm_environment.cpp b/indexer/indexer_tests_support/test_mwm_environment.cpp new file mode 100644 index 0000000000..ca686ef114 --- /dev/null +++ b/indexer/indexer_tests_support/test_mwm_environment.cpp @@ -0,0 +1,36 @@ +#include "indexer/indexer_tests_support/test_mwm_environment.hpp" + +#include <indexer/classificator_loader.hpp> + +namespace indexer +{ +namespace tests_support +{ +TestMwmEnvironment::TestMwmEnvironment() { classificator::Load(); } + +TestMwmEnvironment::~TestMwmEnvironment() +{ + for (auto const & file : m_mwmFiles) + Cleanup(file); +} + +void TestMwmEnvironment::Cleanup(platform::LocalCountryFile const & map) +{ + platform::CountryIndexes::DeleteFromDisk(map); + map.DeleteFromDisk(MapOptions::Map); +} + +bool TestMwmEnvironment::RemoveMwm(MwmSet::MwmId const & mwmId) +{ + auto const & file = mwmId.GetInfo()->GetLocalFile(); + auto const it = find(m_mwmFiles.begin(), m_mwmFiles.end(), file); + + if (it == m_mwmFiles.end()) + return false; + + Cleanup(*it); + m_mwmFiles.erase(it); + return true; +} +} // namespace tests_support +} // namespace indexer diff --git a/indexer/indexer_tests_support/test_mwm_environment.hpp b/indexer/indexer_tests_support/test_mwm_environment.hpp new file mode 100644 index 0000000000..9d0e439f53 --- /dev/null +++ b/indexer/indexer_tests_support/test_mwm_environment.hpp @@ -0,0 +1,83 @@ +#pragma once + +#include "generator/generator_tests_support/test_feature.hpp" +#include "generator/generator_tests_support/test_mwm_builder.hpp" + +#include "platform/local_country_file_utils.hpp" + +#include "storage/country_info_getter.hpp" + +#include <indexer/index.hpp> + +#include <vector> + +namespace indexer +{ +namespace tests_support +{ +class TestMwmEnvironment +{ +public: + using MwmList = std::vector<platform::LocalCountryFile>; + + TestMwmEnvironment(); + ~TestMwmEnvironment(); + + template <typename TBuildFn> + MwmSet::MwmId BuildMwm(string const & name, TBuildFn && fn, int64_t version = 0) + { + m_mwmFiles.emplace_back(GetPlatform().WritableDir(), platform::CountryFile(name), version); + auto & file = m_mwmFiles.back(); + Cleanup(file); + + { + generator::tests_support::TestMwmBuilder builder(file, feature::DataHeader::country); + fn(builder); + } + + auto result = m_index.RegisterMap(file); + CHECK_EQUAL(result.second, MwmSet::RegResult::Success, ()); + + auto const & id = result.first; + + auto const & info = id.GetInfo(); + if (info) + m_infoGetter.AddCountry(storage::CountryDef(name, info->m_limitRect)); + + CHECK(id.IsAlive(), ()); + + return id; + } + + template <typename Checker> + FeatureID FeatureIdForPoint(m2::PointD const & mercator, Checker const & checker) + { + m2::RectD const rect = + MercatorBounds::RectByCenterXYAndSizeInMeters(mercator, 0.2 /* rect width */); + FeatureID id; + auto const fn = [&id, &checker](FeatureType const & featureType) + { + if (checker(featureType)) + id = featureType.GetID(); + }; + m_index.ForEachInRect(fn, rect, scales::GetUpperScale()); + CHECK(id.IsValid(), ()); + return id; + } + + void Cleanup(platform::LocalCountryFile const & map); + bool RemoveMwm(MwmSet::MwmId const & mwmId); + + Index & GetIndex() { return m_index; } + Index const & GetIndex() const { return m_index; } + + MwmList & GetMwms() { return m_mwmFiles; } + MwmList const & GetMwms() const { return m_mwmFiles; } + +private: + Index m_index; + storage::CountryInfoGetterForTesting m_infoGetter; + MwmList m_mwmFiles; +}; +} // namespace tests_support +} // namespace indexer
\ No newline at end of file |