diff --git a/libs/editor/editor_tests/feature_type_to_osm_test.cpp b/libs/editor/editor_tests/feature_type_to_osm_test.cpp index bbc39ef20..af05b9ce4 100644 --- a/libs/editor/editor_tests/feature_type_to_osm_test.cpp +++ b/libs/editor/editor_tests/feature_type_to_osm_test.cpp @@ -7,12 +7,13 @@ using namespace editor; -UNIT_TEST(loadFromStream) +UNIT_TEST(loadFromStream_simpleType) { std::string data = "building;[building];;addr:housenumber;name;1;\n" - "amenity|restaurant;61;\n" - "tourism|information|office;[tourism=information][information=office];;name;int_name;313;\n"; + " # comment that should be ignored\n" + "\n" + "amenity|restaurant;61;\n"; classificator::Load(); @@ -25,25 +26,86 @@ UNIT_TEST(loadFromStream) TEST_EQUAL(result.size(), 1, ()); TEST_EQUAL(result[0].key, "amenity", ()); TEST_EQUAL(result[0].value, "restaurant", ()); + + uint32_t type2 = classif().GetTypeByReadableObjectName("building"); + std::vector result2 = translator.OsmTagsFromType(type2); + TEST_EQUAL(result2.size(), 1, ()); + TEST_EQUAL(result2[0].key, "building", ()); + TEST_EQUAL(result2[0].value, "yes", ()); +} + +UNIT_TEST(loadFromStream_complexType) +{ + std::string data = + "building;[building];;addr:housenumber;name;1;\n" + " # comment that should be ignored\n" + "\n" + "amenity|restaurant;61;\n" + "tourism|information|office;[tourism=information][information=office];;name;int_name;313;\n" + "historic|castle|fortress;[historic=castle][castle_type=fortress],[historic=fortress];;name;int_name;1144;\n" + "#comment\n" + "amenity|place_of_worship|christian|mormon;[amenity=place_of_worship][religion=christian][denomination=mormon];;name;int_name;1572;\n"; + + classificator::Load(); + + TypeToOSMTranslator translator(false); + std::stringstream s(data); + translator.LoadFromStream(s); + + uint32_t officeType = classif().GetTypeByReadableObjectName("tourism-information-office"); + std::vector officeResult = translator.OsmTagsFromType(officeType); + TEST_EQUAL(officeResult.size(), 2, ()); + TEST_EQUAL(officeResult[0].key, "tourism", ()); + TEST_EQUAL(officeResult[0].value, "information", ()); + TEST_EQUAL(officeResult[1].key, "information", ()); + TEST_EQUAL(officeResult[1].value, "office", ()); + + uint32_t fortressType = classif().GetTypeByReadableObjectName("historic-castle-fortress"); + std::vector fortressResult = translator.OsmTagsFromType(fortressType); + TEST_EQUAL(fortressResult.size(), 2, ()); + TEST_EQUAL(fortressResult[0].key, "historic", ()); + TEST_EQUAL(fortressResult[0].value, "castle", ()); + TEST_EQUAL(fortressResult[1].key, "castle_type", ()); + TEST_EQUAL(fortressResult[1].value, "fortress", ()); + + uint32_t mormonType = classif().GetTypeByReadableObjectName("amenity-place_of_worship-christian-mormon"); + std::vector mormonResult = translator.OsmTagsFromType(mormonType); + TEST_EQUAL(mormonResult.size(), 3, ()); + TEST_EQUAL(mormonResult[0].key, "amenity", ()); + TEST_EQUAL(mormonResult[0].value, "place_of_worship", ()); + TEST_EQUAL(mormonResult[1].key, "religion", ()); + TEST_EQUAL(mormonResult[1].value, "christian", ()); + TEST_EQUAL(mormonResult[2].key, "denomination", ()); + TEST_EQUAL(mormonResult[2].value, "mormon", ()); } UNIT_TEST(loadConfigFile) { TypeToOSMTranslator translator(false); translator.LoadConfigFile(); + + size_t size = translator.GetStorage().size(); + LOG(LINFO, ("Size of feature type storage:", size)); + ASSERT(size > 1000, ()); } UNIT_TEST(OsmTagsFromType) { classificator::Load(); - uint32_t type = classif().GetTypeByReadableObjectName("amenity-restaurant"); - std::vector resultVector = GetOSMTranslator().OsmTagsFromType(type); + uint32_t restaurantType = classif().GetTypeByReadableObjectName("amenity-restaurant"); + std::vector restaurantResult = GetOSMTranslator().OsmTagsFromType(restaurantType); + TEST_EQUAL(restaurantResult.size(), 1, ()); + TEST_EQUAL(restaurantResult[0].key, "amenity", ()); + TEST_EQUAL(restaurantResult[0].value, "restaurant", ()); - TEST_EQUAL(resultVector.size(), 1, ()); - OSMTag const & result = resultVector.front(); - TEST_EQUAL(result.key, "amenity", ()); - TEST_EQUAL(result.value, "restaurant", ()); + uint32_t officeType = classif().GetTypeByReadableObjectName("tourism-information-office"); + std::vector officeResult = GetOSMTranslator().OsmTagsFromType(officeType); + TEST_EQUAL(officeResult.size(), 2, ()); + TEST_EQUAL(officeResult[0].key, "tourism", ()); + TEST_EQUAL(officeResult[0].value, "information", ()); + TEST_EQUAL(officeResult[1].key, "information", ()); + TEST_EQUAL(officeResult[1].value, "office", ()); } UNIT_TEST(testToFail) diff --git a/libs/editor/feature_type_to_osm.cpp b/libs/editor/feature_type_to_osm.cpp index 0fed3f174..94526ee35 100644 --- a/libs/editor/feature_type_to_osm.cpp +++ b/libs/editor/feature_type_to_osm.cpp @@ -41,8 +41,8 @@ void TypeToOSMTranslator::LoadFromStream(std::istream & s) getline(s, line); strings::Trim(line); - // skip empty lines and comments - if (line.empty() || line[0] == '#') + // skip empty lines, comments and deprecated types + if (line.empty() || line[0] == '#' || line.starts_with("deprecated")) continue; //LOG(LINFO, ("Reading line: ", line)); diff --git a/libs/editor/feature_type_to_osm.hpp b/libs/editor/feature_type_to_osm.hpp index 275a37463..f8a31ba2f 100644 --- a/libs/editor/feature_type_to_osm.hpp +++ b/libs/editor/feature_type_to_osm.hpp @@ -22,6 +22,8 @@ public: void LoadFromStream(std::istream & s); std::vector OsmTagsFromType(uint32_t type) const; + std::map> const & GetStorage() const { return m_storage; } + private: std::map> m_storage; };