mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-25 23:33:53 +00:00
@@ -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<OSMTag> 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<OSMTag> 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<OSMTag> 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<OSMTag> 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<OSMTag> resultVector = GetOSMTranslator().OsmTagsFromType(type);
|
||||
uint32_t restaurantType = classif().GetTypeByReadableObjectName("amenity-restaurant");
|
||||
std::vector<OSMTag> 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<OSMTag> 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)
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -22,6 +22,8 @@ public:
|
||||
void LoadFromStream(std::istream & s);
|
||||
std::vector<OSMTag> OsmTagsFromType(uint32_t type) const;
|
||||
|
||||
std::map<uint32_t, std::vector<OSMTag>> const & GetStorage() const { return m_storage; }
|
||||
|
||||
private:
|
||||
std::map<uint32_t, std::vector<OSMTag>> m_storage;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user