From eeafca574165bdb51789540dacda87d98d77f23a Mon Sep 17 00:00:00 2001 From: Viktor Govako Date: Thu, 20 Jan 2022 10:06:50 +0300 Subject: [PATCH] [tests] Prettify OsmType_XXX tests. Signed-off-by: Viktor Govako --- generator/generator_tests/osm_type_test.cpp | 103 ++++++++------------ 1 file changed, 43 insertions(+), 60 deletions(-) diff --git a/generator/generator_tests/osm_type_test.cpp b/generator/generator_tests/osm_type_test.cpp index 7154c210fd..8c6ef2121a 100644 --- a/generator/generator_tests/osm_type_test.cpp +++ b/generator/generator_tests/osm_type_test.cpp @@ -26,24 +26,6 @@ using namespace tests; using Tags = std::vector; -void DumpTypes(std::vector const & v) -{ - Classificator const & c = classif(); - for (size_t i = 0; i < v.size(); ++i) - std::cout << c.GetFullObjectName(v[i]) << std::endl; -} - -void DumpParsedTypes(Tags const & tags) -{ - OsmElement e; - FillXmlElement(tags, &e); - - FeatureBuilderParams params; - ftype::GetNameAndType(&e, params); - - DumpTypes(params.m_types); -} - void TestSurfaceTypes(std::string const & surface, std::string const & smoothness, std::string const & grade, char const * value) { @@ -76,6 +58,9 @@ FeatureBuilderParams GetFeatureBuilderParams(Tags const & tags) FillXmlElement(tags, &e); FeatureBuilderParams params; + static TagReplacer tagReplacer(GetPlatform().ResourcesDir() + REPLACED_TAGS_FILE); + tagReplacer.Process(e); + ftype::GetNameAndType(&e, params); return params; } @@ -98,36 +83,48 @@ UNIT_CLASS_TEST(TestWithClassificator, OsmType_SkipDummy) UNIT_CLASS_TEST(TestWithClassificator, OsmType_Check) { - Tags const tags1 = { - { "highway", "primary" }, - { "motorroad", "yes" }, - { "name", "Каширское шоссе" }, - { "oneway", "yes" } - }; + { + Tags const tags = { + { "highway", "primary" }, + { "motorroad", "yes" }, + { "name", "Каширское шоссе" }, + { "oneway", "yes" } + }; - Tags const tags2 = { - { "highway", "primary" }, - { "name", "Каширское шоссе" }, - { "oneway", "-1" }, - { "motorroad", "yes" } - }; + auto const params = GetFeatureBuilderParams(tags); - Tags const tags3 = { - { "admin_level", "4" }, - { "border_type", "state" }, - { "boundary", "administrative" } - }; + TEST_EQUAL(params.m_types.size(), 2, (params)); + TEST(params.IsTypeExist(GetType({"highway", "primary"})), ()); + TEST(params.IsTypeExist(GetType({"hwtag", "oneway"})), ()); + } - Tags const tags4 = { - { "border_type", "state" }, - { "admin_level", "4" }, - { "boundary", "administrative" } - }; + { + Tags const tags = { + { "highway", "primary" }, + { "name", "Каширское шоссе" }, + { "oneway", "-1" }, + { "motorroad", "yes" } + }; - DumpParsedTypes(tags1); - DumpParsedTypes(tags2); - DumpParsedTypes(tags3); - DumpParsedTypes(tags4); + auto const params = GetFeatureBuilderParams(tags); + + TEST_EQUAL(params.m_types.size(), 2, (params)); + TEST(params.IsTypeExist(GetType({"highway", "primary"})), ()); + TEST(params.IsTypeExist(GetType({"hwtag", "oneway"})), ()); + } + + { + Tags const tags = { + { "admin_level", "4" }, + { "border_type", "state" }, + { "boundary", "administrative" } + }; + + auto const params = GetFeatureBuilderParams(tags); + + TEST_EQUAL(params.m_types.size(), 1, (params)); + TEST(params.IsTypeExist(GetType({"boundary", "administrative", "4"})), ()); + } } UNIT_CLASS_TEST(TestWithClassificator, OsmType_Combined) @@ -281,14 +278,7 @@ UNIT_CLASS_TEST(TestWithClassificator, OsmType_Synonyms) { "drinkable", "yes"}, }; - OsmElement e; - FillXmlElement(tags, &e); - - TagReplacer tagReplacer(GetPlatform().ResourcesDir() + REPLACED_TAGS_FILE); - tagReplacer.Process(e); - - FeatureBuilderParams params; - ftype::GetNameAndType(&e, params); + auto const params = GetFeatureBuilderParams(tags); TEST_EQUAL(params.m_types.size(), 7, (params)); @@ -859,14 +849,7 @@ UNIT_CLASS_TEST(TestWithClassificator, OsmType_Entrance) { "barrier", "entrance" }, }; - OsmElement e; - FillXmlElement(tags, &e); - - TagReplacer tagReplacer(GetPlatform().ResourcesDir() + REPLACED_TAGS_FILE); - tagReplacer.Process(e); - - FeatureBuilderParams params; - ftype::GetNameAndType(&e, params); + auto const params = GetFeatureBuilderParams(tags); TEST_EQUAL(params.m_types.size(), 2, (params)); TEST(params.IsTypeExist(GetType({"entrance"})), (params));