Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortherearesomewhocallmetim <dtv@mapswithme.com>2016-06-28 16:53:06 +0300
committerGitHub <noreply@github.com>2016-06-28 16:53:06 +0300
commitcd6395349a25803dfbee006001eea5939ec15ec9 (patch)
tree6934486a15998f972d4e836ec037630651b40867 /indexer
parentf6b968aa0ab9ae9dad82e95f48849bf64737bf28 (diff)
parent89053af365d4beee928dd96b5cf142b6f20bea64 (diff)
Merge pull request #3173 from mpimenov/fix-tests
[indexer] Fix tests for unique new feature category names.
Diffstat (limited to 'indexer')
-rw-r--r--indexer/categories_holder.cpp67
-rw-r--r--indexer/categories_holder.hpp16
-rw-r--r--indexer/categories_index.cpp8
-rw-r--r--indexer/indexer_tests/categories_test.cpp45
-rw-r--r--indexer/new_feature_categories.hpp6
5 files changed, 93 insertions, 49 deletions
diff --git a/indexer/categories_holder.cpp b/indexer/categories_holder.cpp
index 4cb7c0ab2c..c723cbee17 100644
--- a/indexer/categories_holder.cpp
+++ b/indexer/categories_holder.cpp
@@ -20,8 +20,41 @@ enum State
} // unnamed namespace
// static
-size_t const CategoriesHolder::kNumLanguages = 30;
-size_t const CategoriesHolder::kEnglishCode = 1;
+int8_t const CategoriesHolder::kEnglishCode = 1;
+int8_t const CategoriesHolder::kUnsupportedLocaleCode = -1;
+// *NOTE* These constants should be updated when
+// adding new translation to categories.txt.
+vector<CategoriesHolder::Mapping> const CategoriesHolder::kLocaleMapping = {{"en", 1},
+ {"ru", 2},
+ {"uk", 3},
+ {"de", 4},
+ {"fr", 5},
+ {"it", 6},
+ {"es", 7},
+ {"ko", 8},
+ {"ja", 9},
+ {"cs", 10},
+ {"nl", 11},
+ {"zh-Hant", 12},
+ {"pl", 13},
+ {"pt", 14},
+ {"hu", 15},
+ {"th", 16},
+ {"zh-Hans", 17},
+ {"ar", 18},
+ {"da", 19},
+ {"tr", 20},
+ {"sk", 21},
+ {"sv", 22},
+ {"vi", 23},
+ {"id", 24},
+ {"ro", 25},
+ {"nb", 26},
+ {"fi", 27},
+ {"el", 28},
+ {"he", 29},
+ {"sw", 30}};
+vector<string> CategoriesHolder::kDisabledLanguages = {"el", "he", "sw"};
CategoriesHolder::CategoriesHolder(unique_ptr<Reader> && reader)
{
@@ -277,27 +310,17 @@ bool CategoriesHolder::IsTypeExist(uint32_t type) const
int8_t CategoriesHolder::MapLocaleToInteger(string const & locale)
{
- struct Mapping
+ ASSERT(!kLocaleMapping.empty(), ());
+ ASSERT_EQUAL(string(kLocaleMapping[0].m_name), "en", ());
+ ASSERT_EQUAL(kLocaleMapping[0].m_code, kEnglishCode, ());
+ ASSERT(
+ find(kDisabledLanguages.begin(), kDisabledLanguages.end(), "en") == kDisabledLanguages.end(),
+ ());
+
+ for (auto const & entry : kLocaleMapping)
{
- char const * m_name;
- int8_t m_code;
- };
- // TODO(AlexZ): These constants should be updated when adding new
- // translation into categories.txt
- static const Mapping mapping[] = {
- {"en", 1}, {"ru", 2}, {"uk", 3}, {"de", 4}, {"fr", 5}, {"it", 6},
- {"es", 7}, {"ko", 8}, {"ja", 9}, {"cs", 10}, {"nl", 11}, {"zh-Hant", 12},
- {"pl", 13}, {"pt", 14}, {"hu", 15}, {"th", 16}, {"zh-Hans", 17}, {"ar", 18},
- {"da", 19}, {"tr", 20}, {"sk", 21}, {"sv", 22}, {"vi", 23}, {"id", 24},
- {"ro", 25}, {"nb", 26}, {"fi", 27}, {"el", 28}, {"he", 29}, {"sw", 30}};
- static_assert(ARRAY_SIZE(mapping) == kNumLanguages, "");
- static_assert(CategoriesHolder::kEnglishCode == 1, "");
- ASSERT_EQUAL(string(mapping[0].m_name), "en", ());
- ASSERT_EQUAL(mapping[0].m_code, CategoriesHolder::kEnglishCode, ());
- for (size_t i = 0; i < kNumLanguages; ++i)
- {
- if (locale.find(mapping[i].m_name) == 0)
- return mapping[i].m_code;
+ if (locale.find(entry.m_name) == 0)
+ return entry.m_code;
}
// Special cases for different Chinese variations
diff --git a/indexer/categories_holder.hpp b/indexer/categories_holder.hpp
index 2677a7e718..b488e4ab5d 100644
--- a/indexer/categories_holder.hpp
+++ b/indexer/categories_holder.hpp
@@ -35,6 +35,12 @@ public:
}
};
+ struct Mapping
+ {
+ char const * m_name;
+ int8_t m_code;
+ };
+
private:
typedef strings::UniString StringT;
typedef multimap<uint32_t, shared_ptr<Category> > Type2CategoryContT;
@@ -45,8 +51,13 @@ private:
Name2CatContT m_name2type;
public:
- static size_t const kNumLanguages;
- static size_t const kEnglishCode;
+ static int8_t const kEnglishCode;
+ static int8_t const kUnsupportedLocaleCode;
+ static vector<Mapping> const kLocaleMapping;
+
+ // List of languages that are currently disabled in the application
+ // because their translations are not yet complete.
+ static vector<string> kDisabledLanguages;
explicit CategoriesHolder(unique_ptr<Reader> && reader);
void LoadFromStream(istream & s);
@@ -114,7 +125,6 @@ public:
/// Converts any language locale from UI to internal integer code
static int8_t MapLocaleToInteger(string const & locale);
- static constexpr int8_t kUnsupportedLocaleCode = -1;
private:
void AddCategory(Category & cat, vector<uint32_t> & types);
diff --git a/indexer/categories_index.cpp b/indexer/categories_index.cpp
index 3582e6e074..b57559a723 100644
--- a/indexer/categories_index.cpp
+++ b/indexer/categories_index.cpp
@@ -52,7 +52,8 @@ namespace indexer
{
void CategoriesIndex::AddCategoryByTypeAndLang(uint32_t type, int8_t lang)
{
- ASSERT(lang >= 1 && lang <= CategoriesHolder::kNumLanguages, ("Invalid lang code:", lang));
+ ASSERT(lang >= 1 && lang <= CategoriesHolder::kLocaleMapping.size(),
+ ("Invalid lang code:", lang));
m_catHolder->ForEachNameByType(type, [&](TCategory::Name const & name)
{
if (name.m_locale == lang)
@@ -62,13 +63,14 @@ void CategoriesIndex::AddCategoryByTypeAndLang(uint32_t type, int8_t lang)
void CategoriesIndex::AddCategoryByTypeAllLangs(uint32_t type)
{
- for (size_t i = 1; i <= CategoriesHolder::kNumLanguages; ++i)
+ for (size_t i = 1; i <= CategoriesHolder::kLocaleMapping.size(); ++i)
AddCategoryByTypeAndLang(type, i);
}
void CategoriesIndex::AddAllCategoriesInLang(int8_t lang)
{
- ASSERT(lang >= 1 && lang <= CategoriesHolder::kNumLanguages, ("Invalid lang code:", lang));
+ ASSERT(lang >= 1 && lang <= CategoriesHolder::kLocaleMapping.size(),
+ ("Invalid lang code:", lang));
m_catHolder->ForEachTypeAndCategory([&](uint32_t type, TCategory const & cat)
{
for (auto const & name : cat.m_synonyms)
diff --git a/indexer/indexer_tests/categories_test.cpp b/indexer/indexer_tests/categories_test.cpp
index 2efd94b1b8..141a05a152 100644
--- a/indexer/indexer_tests/categories_test.cpp
+++ b/indexer/indexer_tests/categories_test.cpp
@@ -13,6 +13,7 @@
#include "std/algorithm.hpp"
#include "std/bind.hpp"
+#include "std/map.hpp"
#include "std/sstream.hpp"
#include "std/vector.hpp"
#include "std/transform_iterator.hpp"
@@ -269,30 +270,44 @@ UNIT_TEST(CategoriesIndex_UniqueNames)
editor::EditorConfig config;
osm::NewFeatureCategories categories(config);
- categories.ForEachLanguage([&](string const & lang)
+ auto const & disabled = CategoriesHolder::kDisabledLanguages;
+
+ bool noDuplicates = true;
+ for (auto const & locale : CategoriesHolder::kLocaleMapping)
{
+ string const lang(locale.m_name);
+ if (find(disabled.begin(), disabled.end(), lang) != disabled.end())
+ continue;
categories.AddLanguage(lang);
auto const & names = categories.GetAllCategoryNames(lang);
auto firstFn = bind(&pair<string, uint32_t>::first, _1);
set<string> uniqueNames(make_transform_iterator(names.begin(), firstFn),
make_transform_iterator(names.end(), firstFn));
+ if (uniqueNames.size() == names.size())
+ continue;
- if (uniqueNames.size() != names.size())
- {
- LOG(LWARNING, ("Invalid category translations", lang));
+ 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)));
- }
- }
+ map<string, vector<uint32_t>> typesByName;
+ for (auto const & entry : names)
+ typesByName[entry.first].push_back(entry.second);
- LOG(LWARNING, ("+++++++++++++++++++++++++++++++++++++"));
+ for (auto const & entry : typesByName)
+ {
+ if (entry.second.size() <= 1)
+ continue;
+ noDuplicates = false;
+ ostringstream str;
+ str << entry.first << ":";
+ for (auto const & type : entry.second)
+ str << " " << cl.GetReadableObjectName(type);
+ LOG(LWARNING, (str.str()));
}
- });
+
+ LOG(LWARNING,
+ ("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"));
+ };
+
+ TEST(noDuplicates, ());
}
diff --git a/indexer/new_feature_categories.hpp b/indexer/new_feature_categories.hpp
index 4148b87854..f236e0802f 100644
--- a/indexer/new_feature_categories.hpp
+++ b/indexer/new_feature_categories.hpp
@@ -48,12 +48,6 @@ public:
// The returned list is sorted.
TNames const & GetAllCategoryNames(string const & lang) const;
- template <class TFn> void ForEachLanguage(TFn && fn) const
- {
- for (auto const & e : m_categoriesByLang)
- fn(e.first);
- }
-
private:
indexer::CategoriesIndex m_index;
vector<uint32_t> m_types;