diff options
author | Arsentiy Milchakov <a.milchakov@corp.mail.ru> | 2016-09-08 15:49:19 +0300 |
---|---|---|
committer | Arsentiy Milchakov <a.milchakov@corp.mail.ru> | 2016-09-08 15:49:19 +0300 |
commit | ce77f75d4db3fe9d6c7325db997cd4d5111af54d (patch) | |
tree | 187c37dcdd67a6c7d434c040a4e4dea0421f0d43 /indexer | |
parent | 3320c9eddabd67330b6d132ba71cfc822f23fa95 (diff) |
review fixes
Diffstat (limited to 'indexer')
-rw-r--r-- | indexer/editable_map_object.cpp | 14 | ||||
-rw-r--r-- | indexer/editable_map_object.hpp | 16 | ||||
-rw-r--r-- | indexer/indexer_tests/editable_map_object_test.cpp | 102 |
3 files changed, 72 insertions, 60 deletions
diff --git a/indexer/editable_map_object.cpp b/indexer/editable_map_object.cpp index c7121920a9..f11296d0be 100644 --- a/indexer/editable_map_object.cpp +++ b/indexer/editable_map_object.cpp @@ -96,10 +96,10 @@ osm::FakeNames MakeFakeSource(StringUtf8Multilang const & source, fakeSource.AddString(code, defaultName); } - fakeNames.names.push_back({code, tempName}); + fakeNames.m_names.emplace_back(code, tempName); } - fakeNames.defaultName = defaultName; + fakeNames.m_defaultName = defaultName; return fakeNames; } @@ -141,14 +141,14 @@ void RemoveFakesFromName(osm::FakeNames const & fakeNames, StringUtf8Multilang & string defaultName; name.GetString(StringUtf8Multilang::kDefaultCode, defaultName); - for (auto const & item : fakeNames.names) + for (auto const & item : fakeNames.m_names) { string tempName; if (!name.GetString(item.m_code, tempName)) continue; // No need to save in case when name is empty, duplicate of default name or was not changed. if (tempName.empty() || tempName == defaultName || - (tempName == item.m_filledName && tempName == fakeNames.defaultName)) + (tempName == item.m_filledName && tempName == fakeNames.m_defaultName)) { codesToExclude.push_back(item.m_code); } @@ -334,7 +334,7 @@ bool EditableMapObject::CanUseAsDefaultName(int8_t const lang, vector<int8_t> co // static void EditableMapObject::RemoveFakeNames(FakeNames const & fakeNames, StringUtf8Multilang & name) { - if (fakeNames.names.empty()) + if (fakeNames.m_names.empty()) return; int8_t newDefaultNameCode = StringUtf8Multilang::kUnsupportedLanguageCode; @@ -343,7 +343,7 @@ void EditableMapObject::RemoveFakeNames(FakeNames const & fakeNames, StringUtf8M name.GetString(StringUtf8Multilang::kDefaultCode, defaultName); // New default name calculation priority: 1. name on mwm language, 2. english name. - for (auto it = fakeNames.names.rbegin(); it != fakeNames.names.rend(); ++it) + for (auto it = fakeNames.m_names.rbegin(); it != fakeNames.m_names.rend(); ++it) { string tempName; if (!name.GetString(it->m_code, tempName)) @@ -359,7 +359,7 @@ void EditableMapObject::RemoveFakeNames(FakeNames const & fakeNames, StringUtf8M } // If all previously filled fake names were changed - try to change the default name. - if (changedCount == fakeNames.names.size()) + if (changedCount == fakeNames.m_names.size()) { if (!TryToFillDefaultNameFromCode(newDefaultNameCode, name)) TryToFillDefaultNameFromAnyLanguage(name); diff --git a/indexer/editable_map_object.hpp b/indexer/editable_map_object.hpp index c4c16509d1..09dcaffdb9 100644 --- a/indexer/editable_map_object.hpp +++ b/indexer/editable_map_object.hpp @@ -59,7 +59,13 @@ struct NamesDataSource struct FakeName { - int8_t m_code; + FakeName(int8_t code, string filledName) + : m_code(code) + , m_filledName(filledName) + { + } + + int8_t m_code = StringUtf8Multilang::kUnsupportedLanguageCode; string m_filledName; }; /// Contains information about fake names which were added for user convenience. @@ -67,12 +73,12 @@ struct FakeNames { void Clear() { - names.clear(); - defaultName.clear(); + m_names.clear(); + m_defaultName.clear(); } - vector<FakeName> names; - string defaultName; + vector<FakeName> m_names; + string m_defaultName; }; struct LocalizedStreet diff --git a/indexer/indexer_tests/editable_map_object_test.cpp b/indexer/indexer_tests/editable_map_object_test.cpp index f9bdab1f00..044cc8d6ab 100644 --- a/indexer/indexer_tests/editable_map_object_test.cpp +++ b/indexer/indexer_tests/editable_map_object_test.cpp @@ -19,7 +19,12 @@ struct ExpectedName string m_value; }; -void CheckExpectations(StringUtf8Multilang const s, vector<ExpectedName> const expectations) +string DebugPrint(ExpectedName const & expectedName) +{ + return expectedName.m_lang + ", " + expectedName.m_value; +} + +void CheckExpectations(StringUtf8Multilang const & s, vector<ExpectedName> const & expectations) { size_t counter = 0; s.ForEach([&expectations, &counter](int8_t const code, string const & name) { @@ -29,14 +34,15 @@ void CheckExpectations(StringUtf8Multilang const s, vector<ExpectedName> const e }); if (it == expectations.end()) - TEST(false, ("Unexpected language code:", code)); + TEST(false, ("Unexpected language code: ", code, ". Expectations: ", expectations)); TEST_EQUAL(name, it->m_value, ()); ++counter; return true; }); - TEST_EQUAL(counter, expectations.size(), ()); + TEST_EQUAL(counter, expectations.size(), ("Unexpected count of names, expected ", expectations.size(), + ", but turned out ", counter, ". Expectations: ", expectations)); } UNIT_TEST(EditableMapObject_SetWebsite) @@ -325,9 +331,9 @@ UNIT_TEST(EditableMapObject_RemoveFakeNames) name.AddString(GetLangCode("default"), "Default name"); name.AddString(GetLangCode("ru"), "Default name"); name.AddString(GetLangCode("en"), "Default name"); - fakeNames.names.push_back({GetLangCode("ru"), "Default name"}); - fakeNames.names.push_back({GetLangCode("en"), "Default name"}); - fakeNames.defaultName = "Default name"; + fakeNames.m_names.push_back({GetLangCode("ru"), "Default name"}); + fakeNames.m_names.push_back({GetLangCode("en"), "Default name"}); + fakeNames.m_defaultName = "Default name"; EditableMapObject::RemoveFakeNames(fakeNames, name); @@ -339,9 +345,9 @@ UNIT_TEST(EditableMapObject_RemoveFakeNames) name.AddString(GetLangCode("default"), "Default name"); name.AddString(GetLangCode("ru"), "Changed name"); name.AddString(GetLangCode("en"), "Default name"); - fakeNames.names.push_back({GetLangCode("ru"), "Default name"}); - fakeNames.names.push_back({GetLangCode("en"), "Default name"}); - fakeNames.defaultName = "Default name"; + fakeNames.m_names.push_back({GetLangCode("ru"), "Default name"}); + fakeNames.m_names.push_back({GetLangCode("en"), "Default name"}); + fakeNames.m_defaultName = "Default name"; EditableMapObject::RemoveFakeNames(fakeNames, name); @@ -353,9 +359,9 @@ UNIT_TEST(EditableMapObject_RemoveFakeNames) name.AddString(GetLangCode("default"), "Default name"); name.AddString(GetLangCode("ru"), "Default name"); name.AddString(GetLangCode("en"), "Changed name"); - fakeNames.names.push_back({GetLangCode("ru"), "Default name"}); - fakeNames.names.push_back({GetLangCode("en"), "Default name"}); - fakeNames.defaultName = "Default name"; + fakeNames.m_names.push_back({GetLangCode("ru"), "Default name"}); + fakeNames.m_names.push_back({GetLangCode("en"), "Default name"}); + fakeNames.m_defaultName = "Default name"; EditableMapObject::RemoveFakeNames(fakeNames, name); @@ -367,9 +373,9 @@ UNIT_TEST(EditableMapObject_RemoveFakeNames) name.AddString(GetLangCode("default"), "Default name"); name.AddString(GetLangCode("ru"), "Changed name"); name.AddString(GetLangCode("en"), "Changed name"); - fakeNames.names.push_back({GetLangCode("ru"), "Default name"}); - fakeNames.names.push_back({GetLangCode("en"), "Default name"}); - fakeNames.defaultName = "Default name"; + fakeNames.m_names.push_back({GetLangCode("ru"), "Default name"}); + fakeNames.m_names.push_back({GetLangCode("en"), "Default name"}); + fakeNames.m_defaultName = "Default name"; EditableMapObject::RemoveFakeNames(fakeNames, name); @@ -381,9 +387,9 @@ UNIT_TEST(EditableMapObject_RemoveFakeNames) name.AddString(GetLangCode("default"), "Default name"); name.AddString(GetLangCode("ru"), "Changed name ru"); name.AddString(GetLangCode("en"), "Changed name en"); - fakeNames.names.push_back({GetLangCode("ru"), "Default name"}); - fakeNames.names.push_back({GetLangCode("en"), "Default name"}); - fakeNames.defaultName = "Default name"; + fakeNames.m_names.push_back({GetLangCode("ru"), "Default name"}); + fakeNames.m_names.push_back({GetLangCode("en"), "Default name"}); + fakeNames.m_defaultName = "Default name"; EditableMapObject::RemoveFakeNames(fakeNames, name); @@ -395,9 +401,9 @@ UNIT_TEST(EditableMapObject_RemoveFakeNames) name.AddString(GetLangCode("default"), "Changed by other logic"); name.AddString(GetLangCode("ru"), "Default name"); name.AddString(GetLangCode("en"), "Changed name en"); - fakeNames.names.push_back({GetLangCode("ru"), "Default name"}); - fakeNames.names.push_back({GetLangCode("en"), "Default name"}); - fakeNames.defaultName = "Default name"; + fakeNames.m_names.push_back({GetLangCode("ru"), "Default name"}); + fakeNames.m_names.push_back({GetLangCode("en"), "Default name"}); + fakeNames.m_defaultName = "Default name"; EditableMapObject::RemoveFakeNames(fakeNames, name); @@ -409,9 +415,9 @@ UNIT_TEST(EditableMapObject_RemoveFakeNames) name.AddString(GetLangCode("default"), "Changed by other logic"); name.AddString(GetLangCode("ru"), "Changed name ru"); name.AddString(GetLangCode("en"), "Changed name en"); - fakeNames.names.push_back({GetLangCode("ru"), "Default name"}); - fakeNames.names.push_back({GetLangCode("en"), "Default name"}); - fakeNames.defaultName = "Default name"; + fakeNames.m_names.push_back({GetLangCode("ru"), "Default name"}); + fakeNames.m_names.push_back({GetLangCode("en"), "Default name"}); + fakeNames.m_defaultName = "Default name"; EditableMapObject::RemoveFakeNames(fakeNames, name); @@ -423,9 +429,9 @@ UNIT_TEST(EditableMapObject_RemoveFakeNames) name.AddString(GetLangCode("default"), "Changed by other logic"); name.AddString(GetLangCode("ru"), "Default name"); name.AddString(GetLangCode("en"), "Default name"); - fakeNames.names.push_back({GetLangCode("ru"), "Default name"}); - fakeNames.names.push_back({GetLangCode("en"), "Default name"}); - fakeNames.defaultName = "Default name"; + fakeNames.m_names.push_back({GetLangCode("ru"), "Default name"}); + fakeNames.m_names.push_back({GetLangCode("en"), "Default name"}); + fakeNames.m_defaultName = "Default name"; EditableMapObject::RemoveFakeNames(fakeNames, name); @@ -437,9 +443,9 @@ UNIT_TEST(EditableMapObject_RemoveFakeNames) name.AddString(GetLangCode("default"), "Default name"); name.AddString(GetLangCode("ru"), ""); name.AddString(GetLangCode("en"), "Changed name en"); - fakeNames.names.push_back({GetLangCode("ru"), "Default name"}); - fakeNames.names.push_back({GetLangCode("en"), "Default name"}); - fakeNames.defaultName = "Default name"; + fakeNames.m_names.push_back({GetLangCode("ru"), "Default name"}); + fakeNames.m_names.push_back({GetLangCode("en"), "Default name"}); + fakeNames.m_defaultName = "Default name"; EditableMapObject::RemoveFakeNames(fakeNames, name); @@ -451,9 +457,9 @@ UNIT_TEST(EditableMapObject_RemoveFakeNames) name.AddString(GetLangCode("default"), "Default name"); name.AddString(GetLangCode("ru"), ""); name.AddString(GetLangCode("en"), ""); - fakeNames.names.push_back({GetLangCode("ru"), "Default name"}); - fakeNames.names.push_back({GetLangCode("en"), "Default name"}); - fakeNames.defaultName = "Default name"; + fakeNames.m_names.push_back({GetLangCode("ru"), "Default name"}); + fakeNames.m_names.push_back({GetLangCode("en"), "Default name"}); + fakeNames.m_defaultName = "Default name"; EditableMapObject::RemoveFakeNames(fakeNames, name); @@ -466,9 +472,9 @@ UNIT_TEST(EditableMapObject_RemoveFakeNames) name.AddString(GetLangCode("ru"), ""); name.AddString(GetLangCode("en"), ""); name.AddString(GetLangCode("de"), "Deutch name"); - fakeNames.names.push_back({GetLangCode("ru"), "Default name"}); - fakeNames.names.push_back({GetLangCode("en"), "Default name"}); - fakeNames.defaultName = "Default name"; + fakeNames.m_names.push_back({GetLangCode("ru"), "Default name"}); + fakeNames.m_names.push_back({GetLangCode("en"), "Default name"}); + fakeNames.m_defaultName = "Default name"; EditableMapObject::RemoveFakeNames(fakeNames, name); @@ -480,9 +486,9 @@ UNIT_TEST(EditableMapObject_RemoveFakeNames) name.AddString(GetLangCode("default"), "Default name"); name.AddString(GetLangCode("ru"), "Test name"); name.AddString(GetLangCode("en"), "Default name"); - fakeNames.names.push_back({GetLangCode("ru"), "Test name"}); - fakeNames.names.push_back({GetLangCode("en"), "Default name"}); - fakeNames.defaultName = "Default name"; + fakeNames.m_names.push_back({GetLangCode("ru"), "Test name"}); + fakeNames.m_names.push_back({GetLangCode("en"), "Default name"}); + fakeNames.m_defaultName = "Default name"; EditableMapObject::RemoveFakeNames(fakeNames, name); @@ -494,9 +500,9 @@ UNIT_TEST(EditableMapObject_RemoveFakeNames) name.AddString(GetLangCode("default"), "Default name"); name.AddString(GetLangCode("ru"), "Test name changed"); name.AddString(GetLangCode("en"), "Default name changed"); - fakeNames.names.push_back({GetLangCode("ru"), "Test name"}); - fakeNames.names.push_back({GetLangCode("en"), "Default name"}); - fakeNames.defaultName = "Default name"; + fakeNames.m_names.push_back({GetLangCode("ru"), "Test name"}); + fakeNames.m_names.push_back({GetLangCode("en"), "Default name"}); + fakeNames.m_defaultName = "Default name"; EditableMapObject::RemoveFakeNames(fakeNames, name); @@ -508,9 +514,9 @@ UNIT_TEST(EditableMapObject_RemoveFakeNames) name.AddString(GetLangCode("default"), "Default name"); name.AddString(GetLangCode("ru"), "Test name"); name.AddString(GetLangCode("en"), "Second test name changed"); - fakeNames.names.push_back({GetLangCode("ru"), "Test name"}); - fakeNames.names.push_back({GetLangCode("en"), "Second test name"}); - fakeNames.defaultName = "Default name"; + fakeNames.m_names.push_back({GetLangCode("ru"), "Test name"}); + fakeNames.m_names.push_back({GetLangCode("en"), "Second test name"}); + fakeNames.m_defaultName = "Default name"; EditableMapObject::RemoveFakeNames(fakeNames, name); @@ -522,9 +528,9 @@ UNIT_TEST(EditableMapObject_RemoveFakeNames) name.AddString(GetLangCode("default"), "Default name"); name.AddString(GetLangCode("ru"), ""); name.AddString(GetLangCode("en"), "Second test name changed"); - fakeNames.names.push_back({GetLangCode("ru"), "Test name"}); - fakeNames.names.push_back({GetLangCode("en"), "Second test name"}); - fakeNames.defaultName = "Default name"; + fakeNames.m_names.push_back({GetLangCode("ru"), "Test name"}); + fakeNames.m_names.push_back({GetLangCode("en"), "Second test name"}); + fakeNames.m_defaultName = "Default name"; EditableMapObject::RemoveFakeNames(fakeNames, name); |