Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Byko-Ianko <v.bykoianko@corp.mail.ru>2016-11-15 10:12:32 +0300
committerVladimir Byko-Ianko <v.bykoianko@corp.mail.ru>2016-11-16 14:20:39 +0300
commit649d4f4bedaf509549084860514824909df3c66d (patch)
tree716fef126f19e1a68b9f188d7ac55fa1f541b397 /generator
parente995ce1d3992931a73bf2093e06d2ce4a35cd1b1 (diff)
Fixing restrictions_collector_test and moving osm ids to feature ids generation to generator_tests_support.
Diffstat (limited to 'generator')
-rw-r--r--generator/generator_tests/restriction_collector_test.cpp76
-rw-r--r--generator/generator_tests/restriction_test.cpp37
-rw-r--r--generator/generator_tests_support/generator_tests_support.pro2
-rw-r--r--generator/generator_tests_support/restrcion_support.cpp36
-rw-r--r--generator/generator_tests_support/restrcion_support.hpp16
-rw-r--r--generator/restriction_collector.hpp6
-rw-r--r--generator/restriction_generator.hpp13
7 files changed, 89 insertions, 97 deletions
diff --git a/generator/generator_tests/restriction_collector_test.cpp b/generator/generator_tests/restriction_collector_test.cpp
index 838a9a65e1..852f7193b6 100644
--- a/generator/generator_tests/restriction_collector_test.cpp
+++ b/generator/generator_tests/restriction_collector_test.cpp
@@ -1,5 +1,7 @@
#include "testing/testing.hpp"
+#include "generator/generator_tests_support/restrcion_support.hpp"
+
#include "generator/osm_id.hpp"
#include "generator/restriction_collector.hpp"
@@ -18,6 +20,7 @@
#include "std/utility.hpp"
#include "std/vector.hpp"
+using namespace generator;
using namespace platform;
using namespace platform::tests_support;
@@ -27,13 +30,13 @@ string const kRestrictionTestDir = "test-restrictions";
UNIT_TEST(RestrictionTest_ValidCase)
{
- RestrictionCollector restrictionCollector("" /* restrictionPath */, "" /* featureIdToOsmIdsPath */);
+ RestrictionCollector restrictionCollector("" /* restrictionPath */, "" /* osmIdsToFeatureIdsPath */);
// Adding feature ids.
- restrictionCollector.AddFeatureId(30 /* featureId */, {3} /* osmIds */);
- restrictionCollector.AddFeatureId(10 /* featureId */, {1} /* osmIds */);
- restrictionCollector.AddFeatureId(50 /* featureId */, {5} /* osmIds */);
- restrictionCollector.AddFeatureId(70 /* featureId */, {7} /* osmIds */);
- restrictionCollector.AddFeatureId(20 /* featureId */, {2} /* osmIds */);
+ restrictionCollector.AddFeatureId(30 /* featureId */, 3 /* osmId */);
+ restrictionCollector.AddFeatureId(10 /* featureId */, 1 /* osmId */);
+ restrictionCollector.AddFeatureId(50 /* featureId */, 5 /* osmId */);
+ restrictionCollector.AddFeatureId(70 /* featureId */, 7 /* osmId */);
+ restrictionCollector.AddFeatureId(20 /* featureId */, 2 /* osmId */);
// Adding restrictions.
TEST(restrictionCollector.AddRestriction(Restriction::Type::No, {1, 2} /* osmIds */), ());
@@ -52,9 +55,9 @@ UNIT_TEST(RestrictionTest_ValidCase)
UNIT_TEST(RestrictionTest_InvalidCase)
{
- RestrictionCollector restrictionCollector("" /* restrictionPath */, "" /* featureIdToOsmIdsPath */);
- restrictionCollector.AddFeatureId(0 /* featureId */, {0} /* osmIds */);
- restrictionCollector.AddFeatureId(20 /* featureId */, {2} /* osmIds */);
+ RestrictionCollector restrictionCollector("" /* restrictionPath */, "" /* osmIdsToFeatureIdsPath */);
+ restrictionCollector.AddFeatureId(0 /* featureId */, 0 /* osmId */);
+ restrictionCollector.AddFeatureId(20 /* featureId */, 2 /* osmId */);
TEST(!restrictionCollector.AddRestriction(Restriction::Type::No, {0, 1} /* osmIds */), ());
@@ -75,7 +78,7 @@ UNIT_TEST(RestrictionTest_ParseRestrictions)
ScopedDir const scopedDir(kRestrictionTestDir);
ScopedFile const scopedFile(kRestrictionPath, kRestrictionContent);
- RestrictionCollector restrictionCollector("" /* restrictionPath */, "" /* featureIdToOsmIdsPath */);
+ RestrictionCollector restrictionCollector("" /* restrictionPath */, "" /* osmIdsToFeatureIdsPath */);
Platform const & platform = Platform();
@@ -85,35 +88,6 @@ UNIT_TEST(RestrictionTest_ParseRestrictions)
TEST(!restrictionCollector.HasRestrictions(), ());
}
-UNIT_TEST(RestrictionTest_ParseFeatureId2OsmIdsMapping)
-{
- string const kFeatureIdToOsmIdsName = "feature_id_to_osm_ids.csv";
- string const kFeatureIdToOsmIdsPath =
- my::JoinFoldersToPath(kRestrictionTestDir, kFeatureIdToOsmIdsName);
- string const kFeatureIdToOsmIdsContent = R"(1, 10,
- 2, 20
- 779703, 5423239545,
- 3, 30)";
-
- ScopedDir const scopedDir(kRestrictionTestDir);
- ScopedFile const scopedFile(kFeatureIdToOsmIdsPath, kFeatureIdToOsmIdsContent);
-
- RestrictionCollector restrictionCollector("" /* restrictionPath */, "" /* featureIdToOsmIdsPath */);
-
- Platform const & platform = Platform();
- restrictionCollector.ParseOsmIdToFeatureIdMapping(
- my::JoinFoldersToPath(platform.WritableDir(), kFeatureIdToOsmIdsPath));
-
- vector<pair<uint64_t, uint32_t>> const expectedOsmIds2FeatureId = {
- {10, 1}, {20, 2}, {30, 3}, {5423239545, 779703}};
- vector<pair<uint64_t, uint32_t>> osmIds2FeatureId(
- restrictionCollector.m_osmIdToFeatureId.cbegin(),
- restrictionCollector.m_osmIdToFeatureId.cend());
- sort(osmIds2FeatureId.begin(), osmIds2FeatureId.end(),
- my::LessBy(&pair<uint64_t, uint32_t>::first));
- TEST_EQUAL(osmIds2FeatureId, expectedOsmIds2FeatureId, ());
-}
-
UNIT_TEST(RestrictionTest_RestrictionCollectorWholeClassTest)
{
string const kRestrictionName = "restrictions_in_osm_ids.csv";
@@ -122,22 +96,24 @@ UNIT_TEST(RestrictionTest_RestrictionCollectorWholeClassTest)
Only, 10, 20,
Only, 30, 40,)";
- string const kFeatureIdToOsmIdsName = "feature_id_to_osm_ids.csv";
- string const kFeatureIdToOsmIdsPath =
- my::JoinFoldersToPath(kRestrictionTestDir, kFeatureIdToOsmIdsName);
- string const kFeatureIdToOsmIdsContent = R"(1, 10,
- 2, 20,
- 3, 30,
- 4, 40)";
+ string const kOsmIdsToFeatureIdsName = "osm_ids_to_feature_ids" OSM2FEATURE_FILE_EXTENSION;
+ string const osmIdsToFeatureIdsPath =
+ my::JoinFoldersToPath(kRestrictionTestDir, kOsmIdsToFeatureIdsName);
+ string const kOsmIdsToFeatureIdsContent = R"(10, 1,
+ 20, 2,
+ 30, 3,
+ 40, 4)";
+ Platform const & platform = Platform();
+ string const osmIdsToFeatureIdsFullPath = my::JoinFoldersToPath(platform.WritableDir(),
+ osmIdsToFeatureIdsPath);
+ GenerateOsmIdsToFeatureIdsMapping(kOsmIdsToFeatureIdsContent, osmIdsToFeatureIdsFullPath);
ScopedDir scopedDir(kRestrictionTestDir);
ScopedFile restrictionScopedFile(kRestrictionPath, kRestrictionContent);
- ScopedFile mappingScopedFile(kFeatureIdToOsmIdsPath, kFeatureIdToOsmIdsContent);
+ ScopedFile mappingScopedFile(osmIdsToFeatureIdsPath);
- Platform const & platform = Platform();
RestrictionCollector restrictionCollector(
- my::JoinFoldersToPath(platform.WritableDir(), kRestrictionPath),
- my::JoinFoldersToPath(platform.WritableDir(), kFeatureIdToOsmIdsPath));
+ my::JoinFoldersToPath(platform.WritableDir(), kRestrictionPath), osmIdsToFeatureIdsFullPath);
TEST(restrictionCollector.IsValid(), ());
RestrictionVec const & restrictions = restrictionCollector.GetRestrictions();
diff --git a/generator/generator_tests/restriction_test.cpp b/generator/generator_tests/restriction_test.cpp
index e16bbe1172..efd6e5ff96 100644
--- a/generator/generator_tests/restriction_test.cpp
+++ b/generator/generator_tests/restriction_test.cpp
@@ -1,9 +1,9 @@
#include "testing/testing.hpp"
+#include "generator/generator_tests_support/restrcion_support.hpp"
#include "generator/generator_tests_support/test_feature.hpp"
#include "generator/generator_tests_support/test_mwm_builder.hpp"
-#include "generator/gen_mwm_info.hpp"
#include "generator/restriction_collector.hpp"
#include "generator/restriction_generator.hpp"
@@ -13,7 +13,6 @@
#include "indexer/mwm_set.hpp"
#include "coding/file_name_utils.hpp"
-#include "coding/file_writer.hpp"
#include "platform/platform_tests_support/scoped_dir.hpp"
#include "platform/platform_tests_support/scoped_file.hpp"
@@ -23,9 +22,7 @@
#include "base/logging.hpp"
#include "base/scope_guard.hpp"
-#include "base/string_utils.hpp"
-#include "std/utility.hpp"
#include "std/string.hpp"
using namespace feature;
@@ -48,40 +45,10 @@ void BuildEmptyMwm(LocalCountryFile & country)
generator::tests_support::TestMwmBuilder builder(country, feature::DataHeader::country);
}
-/// \brief Generates a binary file with by a string with mapping from osm ids to feature ids.
-/// \param mappingContent a string with lines with mapping from osm id to feature id (one to one).
-/// For example
-/// 10, 1,
-/// 20, 2
-/// 30, 3,
-/// 40, 4
-/// \parma outputFilePath full path to an output file where the mapping is saved.
-void GenerateOsmIdsToFeatureIdsMapping(string const & mappingContent, string const & outputFilePath)
-{
- strings::SimpleTokenizer lineIter(mappingContent, "\n\r" /* string delimiter */);
-
- gen::Accumulator<pair<uint64_t, uint32_t>> osmIdsToFeatureIds;
- for (; lineIter; ++lineIter)
- {
- strings::SimpleTokenizer idIter(*lineIter, ", \t" /* id delimiter */);
- uint64_t osmId = 0;
- TEST(strings::to_uint64(*idIter, osmId), ("Cannot covert to uint64_t:", *idIter));
- TEST(idIter, ("Wrong feature ids to osm ids mapping."));
- ++idIter;
-
- uint32_t featureId = 0;
- TEST(strings::to_uint(*idIter, featureId), ("Cannot covert to uint:", *idIter));
- osmIdsToFeatureIds.Add(make_pair(osmId, featureId));
- }
-
- FileWriter osm2ftWriter(outputFilePath);
- osmIdsToFeatureIds.Flush(osm2ftWriter);
-}
-
/// \brief Generates a restriction section, adds it to an empty mwm,
/// loads the restriction section and test loaded restrictions.
/// \param restrictionContent comma separated text with restrictions in osm id terms.
-/// \param mappingContent comma separated text with with mapping from osm ids to feature ids.
+/// \param mappingContent comma separated text with mapping from osm ids to feature ids.
void TestRestrictionBuilding(string const & restrictionContent, string const & mappingContent)
{
Platform & platform = GetPlatform();
diff --git a/generator/generator_tests_support/generator_tests_support.pro b/generator/generator_tests_support/generator_tests_support.pro
index 380dc89064..af3ff085e2 100644
--- a/generator/generator_tests_support/generator_tests_support.pro
+++ b/generator/generator_tests_support/generator_tests_support.pro
@@ -7,9 +7,11 @@ ROOT_DIR = ../..
include($$ROOT_DIR/common.pri)
SOURCES += \
+ restrcion_support.cpp \
test_feature.cpp \
test_mwm_builder.cpp \
HEADERS += \
+ restrcion_support.hpp \
test_feature.hpp \
test_mwm_builder.hpp \
diff --git a/generator/generator_tests_support/restrcion_support.cpp b/generator/generator_tests_support/restrcion_support.cpp
new file mode 100644
index 0000000000..678cc37fd4
--- /dev/null
+++ b/generator/generator_tests_support/restrcion_support.cpp
@@ -0,0 +1,36 @@
+#include "generator/generator_tests_support/restrcion_support.hpp"
+
+#include "testing/testing.hpp"
+
+#include "generator/gen_mwm_info.hpp"
+
+#include "coding/file_writer.hpp"
+
+#include "base/string_utils.hpp"
+
+#include "std/utility.hpp"
+
+namespace generator
+{
+void GenerateOsmIdsToFeatureIdsMapping(string const & mappingContent, string const & outputFilePath)
+{
+ strings::SimpleTokenizer lineIter(mappingContent, "\n\r" /* string delimiter */);
+
+ gen::Accumulator<pair<uint64_t, uint32_t>> osmIdsToFeatureIds;
+ for (; lineIter; ++lineIter)
+ {
+ strings::SimpleTokenizer idIter(*lineIter, ", \t" /* id delimiter */);
+ uint64_t osmId = 0;
+ TEST(strings::to_uint64(*idIter, osmId), ("Cannot covert to uint64_t:", *idIter));
+ TEST(idIter, ("Wrong feature ids to osm ids mapping."));
+ ++idIter;
+
+ uint32_t featureId = 0;
+ TEST(strings::to_uint(*idIter, featureId), ("Cannot covert to uint:", *idIter));
+ osmIdsToFeatureIds.Add(make_pair(osmId, featureId));
+ }
+
+ FileWriter osm2ftWriter(outputFilePath);
+ osmIdsToFeatureIds.Flush(osm2ftWriter);
+}
+} // namespace generator
diff --git a/generator/generator_tests_support/restrcion_support.hpp b/generator/generator_tests_support/restrcion_support.hpp
new file mode 100644
index 0000000000..2268158c5a
--- /dev/null
+++ b/generator/generator_tests_support/restrcion_support.hpp
@@ -0,0 +1,16 @@
+#pragma once
+
+#include "std/string.hpp"
+
+namespace generator
+{
+/// \brief Generates a binary file with by a string with mapping from osm ids to feature ids.
+/// \param mappingContent a string with lines with mapping from osm id to feature id (one to one).
+/// For example
+/// 10, 1,
+/// 20, 2
+/// 30, 3,
+/// 40, 4
+/// \parma outputFilePath full path to an output file where the mapping is saved.
+void GenerateOsmIdsToFeatureIdsMapping(string const & mappingContent, string const & outputFilePath);
+} // namespace generator
diff --git a/generator/restriction_collector.hpp b/generator/restriction_collector.hpp
index 155e84973c..432acdc159 100644
--- a/generator/restriction_collector.hpp
+++ b/generator/restriction_collector.hpp
@@ -17,8 +17,8 @@ class RestrictionCollector
{
public:
/// \param restrictionPath full path to file with road restrictions in osm id terms.
- /// \param featureIdToOsmIdsPath full path to file with mapping from feature id to osm id.
- RestrictionCollector(string const & restrictionPath, string const & featureIdToOsmIdsPath);
+ /// \param osmIdsToFeatureIdsPath full path to file with mapping from osm ids to feature ids.
+ RestrictionCollector(string const & restrictionPath, string const & osmIdsToFeatureIdsPath);
bool HasRestrictions() const { return !m_restrictions.empty(); }
@@ -53,7 +53,7 @@ private:
/// Only, 335049632, 49356687,
/// No, 157616940, 157616940,
/// No, 157616940, 157617107,
- /// \param featureIdToOsmIdsPath path to the text file.
+ /// \param path path to the text file with restrictions.
bool ParseRestrictions(string const & path);
/// \brief Adds feature id and corresponding |osmId| to |m_osmIdToFeatureId|.
diff --git a/generator/restriction_generator.hpp b/generator/restriction_generator.hpp
index 17636f6fc8..d960f8149c 100644
--- a/generator/restriction_generator.hpp
+++ b/generator/restriction_generator.hpp
@@ -12,14 +12,9 @@ namespace routing
/// For example:
/// Only, 335049632, 49356687,
/// No, 157616940, 157616940,
-/// \param featureIdToOsmIdsPath comma separated (csv like) file with mapping from feature id to osm
-/// ids
-/// in following format:
-/// <feature id>, <osm id 1 corresponding feature id>, <osm id 2 corresponding feature id>, and so
-/// on
-/// For example:
-/// 137999, 5170186,
-/// 138000, 5170209,
+/// \param osmIdsToFeatureIdsPath a binary file with mapping form osm ids to feature ids.
+/// One osm id is mapped to one feature is. The file should be saved with the help of
+/// OsmID2FeatureID class or using a similar way.
bool BuildRoadRestrictions(string const & mwmPath, string const & restrictionPath,
- string const & featureIdToOsmIdsPath);
+ string const & osmIdsToFeatureIdsPath);
} // namespace routing