From dd7d0828fc769b5be404e7042445e8a2b22ace9d Mon Sep 17 00:00:00 2001 From: vng Date: Fri, 29 Apr 2016 18:33:28 +0300 Subject: [PATCH] Added test for unique category names checking. --- indexer/indexer_tests/categories_test.cpp | 43 +++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/indexer/indexer_tests/categories_test.cpp b/indexer/indexer_tests/categories_test.cpp index 74a81c400a..3ea51ad2d5 100644 --- a/indexer/indexer_tests/categories_test.cpp +++ b/indexer/indexer_tests/categories_test.cpp @@ -4,13 +4,18 @@ #include "indexer/categories_index.hpp" #include "indexer/classificator.hpp" #include "indexer/classificator_loader.hpp" +#include "indexer/new_feature_categories.hpp" + +#include "editor/editor_config.hpp" #include "coding/multilang_utf8_string.hpp" #include "coding/reader.hpp" #include "std/algorithm.hpp" +#include "std/bind.hpp" #include "std/sstream.hpp" #include "std/vector.hpp" +#include "std/transform_iterator.hpp" #include "base/stl_helpers.hpp" @@ -254,3 +259,41 @@ UNIT_TEST(CategoriesIndex_AllCategoriesEnglishName) TEST_LESS(index.GetNumTrieNodes(), 6000, ()); } #endif + +UNIT_TEST(CategoriesIndex_UniqueNames) +{ + classificator::Load(); + auto const & cl = classif(); + + editor::EditorConfig config; + osm::NewFeatureCategories categories(config); + + for (auto const & lang : {"en", "ru", "de", "cs", "da", "es", "fi", "fr", "hu", + "id", "it", "ja", "co", "nl", "nb", "pl", "pt", "ro", + "sk", "sv", "th", "tr", "uk", "vi", "zh-Hant" "ar"}) + { + categories.AddLanguage(lang); + auto const & names = categories.GetAllCategoryNames(lang); + + auto firstFn = bind(&pair::first, _1); + set uniqueNames(make_transform_iterator(names.begin(), firstFn), + make_transform_iterator(names.end(), firstFn)); + + if (uniqueNames.size() != names.size()) + { + LOG(LWARNING, ("Invalid category translations", lang)); + + for (size_t i = 1; i < names.size(); ++i) + { + if (names[i-1].first == names[i].first) + { + LOG(LWARNING, (names[i].first, + cl.GetReadableObjectName(names[i].second), + cl.GetReadableObjectName(names[i-1].second))); + } + } + + LOG(LWARNING, ("+++++++++++++++++++++++++++++++++++++")); + } + } +}