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:
authorVladimir Byko-Ianko <v.bykoianko@corp.mail.ru>2015-07-30 10:36:12 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 02:58:47 +0300
commit14c8bd3b20a9b99fa11ec9ffa61d045e50c3748e (patch)
treec98c209769814ffe1950489e64441910e0581a4f /platform
parent2ecb8efa5c2938435d2bff520d69b7dc9724eccc (diff)
GetTextById::operator() returns flag if textId is found in a specified locale.
Diffstat (limited to 'platform')
-rw-r--r--platform/get_text_by_id.cpp9
-rw-r--r--platform/get_text_by_id.hpp10
-rw-r--r--platform/platform_tests/get_text_by_id_tests.cpp70
3 files changed, 57 insertions, 32 deletions
diff --git a/platform/get_text_by_id.cpp b/platform/get_text_by_id.cpp
index f2e48e8e49..d382787890 100644
--- a/platform/get_text_by_id.cpp
+++ b/platform/get_text_by_id.cpp
@@ -37,6 +37,7 @@ GetTextById::GetTextById(TextSource textSouce, string const & localeName)
string const pathToJson = my::JoinFoldersToPath(
{GetTextSourceString(textSouce), localeName + ".json"}, "localize.json");
+ // @TODO(vbykoianko) Add assert if locale path pathToJson is not valid.
string jsonBuffer;
ReaderPtr<Reader>(GetPlatform().GetReader(pathToJson)).ReadAsString(jsonBuffer);
@@ -66,14 +67,14 @@ GetTextById::GetTextById(TextSource textSouce, string const & localeName)
ASSERT_EQUAL(m_localeTexts.size(), json_object_size(root.get()), ());
}
-string GetTextById::operator()(string const & textId) const
+pair<string, bool> GetTextById::operator()(string const & textId) const
{
if (!IsValid())
- return textId;
+ return make_pair(textId, false);
auto const textIt = m_localeTexts.find(textId);
if (textIt == m_localeTexts.end())
- return textId;
- return textIt->second;
+ return make_pair(textId, false);
+ return make_pair(textIt->second, true);
}
} // namespace platform
diff --git a/platform/get_text_by_id.hpp b/platform/get_text_by_id.hpp
index c018e7ec84..b70bac0cec 100644
--- a/platform/get_text_by_id.hpp
+++ b/platform/get_text_by_id.hpp
@@ -1,7 +1,8 @@
#pragma once
-#include <std/string.hpp>
-#include <std/unordered_map.hpp>
+#include "std/string.hpp"
+#include "std/unordered_map.hpp"
+#include "std/utility.hpp"
namespace platform
{
@@ -20,7 +21,10 @@ public:
GetTextById(TextSource textSouce, string const & localeName);
bool IsValid() const { return !m_localeTexts.empty(); }
- string operator()(string const & textId) const;
+ /// @return a pair of a text string in a specified locale for textId and a boolean flag.
+ /// If textId is found in m_localeTexts then the boolean flag is set to true.
+ /// The boolean flag is set to false otherwise.
+ pair<string, bool> operator()(string const & textId) const;
private:
unordered_map<string, string> m_localeTexts;
diff --git a/platform/platform_tests/get_text_by_id_tests.cpp b/platform/platform_tests/get_text_by_id_tests.cpp
index 657669a11d..e9a7df4bf9 100644
--- a/platform/platform_tests/get_text_by_id_tests.cpp
+++ b/platform/platform_tests/get_text_by_id_tests.cpp
@@ -7,49 +7,69 @@ using namespace platform;
UNIT_TEST(GetTextByIdEnglishTest)
{
platform::GetTextById getEnglish(TextSource::TtsSound, "en");
- TEST_EQUAL(getEnglish("make_a_slight_right_turn"), "Make a slight right turn.", ());
- TEST_EQUAL(getEnglish("in_900_meters"), "In 900 meters.", ());
- TEST_EQUAL(getEnglish("then"), "Then.", ());
- TEST_EQUAL(getEnglish("in_1_mile"), "In one mile.", ());
- TEST_EQUAL(getEnglish("some_nonexistent_key"), "some_nonexistent_key", ());
+ TEST_EQUAL(getEnglish("make_a_slight_right_turn").first, "Make a slight right turn.", ());
+ TEST_EQUAL(getEnglish("in_900_meters").first, "In 900 meters.", ());
+ TEST_EQUAL(getEnglish("then").first, "Then.", ());
+ TEST_EQUAL(getEnglish("in_1_mile").first, "In one mile.", ());
+
+ TEST_EQUAL(getEnglish("some_nonexistent_key").first, "some_nonexistent_key", ());
+ TEST(!getEnglish("some_nonexistent_key").second, ());
+ TEST(!getEnglish("").second, ());
+ TEST(!getEnglish(" ").second, ());
}
UNIT_TEST(GetTextByIdRussianTest)
{
platform::GetTextById getRussian(TextSource::TtsSound, "ru");
- TEST_EQUAL(getRussian("in_800_meters"), "Через 800 метров.", ());
- TEST_EQUAL(getRussian("make_a_slight_right_turn"), "Плавный поворот направо.", ());
- TEST_EQUAL(getRussian("take_the_6th_exit"), "6-й поворот с кольца.", ());
- TEST_EQUAL(getRussian("in_1_mile"), "Через одну милю.", ());
- TEST_EQUAL(getRussian("some_nonexistent_key"), "some_nonexistent_key", ());
+ TEST_EQUAL(getRussian("in_800_meters").first, "Через 800 метров.", ());
+ TEST_EQUAL(getRussian("make_a_slight_right_turn").first, "Плавный поворот направо.", ());
+ TEST_EQUAL(getRussian("take_the_6th_exit").first, "6-й поворот с кольца.", ());
+ TEST_EQUAL(getRussian("in_1_mile").first, "Через одну милю.", ());
+
+ TEST_EQUAL(getRussian("some_nonexistent_key").first, "some_nonexistent_key", ());
+ TEST(!getRussian("some_nonexistent_key").second, ());
+ TEST(!getRussian("").second, ());
+ TEST(!getRussian(" ").second, ());
}
UNIT_TEST(GetTextByIdKoreanTest)
{
platform::GetTextById getKorean(TextSource::TtsSound, "ko");
- TEST_EQUAL(getKorean("in_700_meters"), "700 미터 앞", ());
- TEST_EQUAL(getKorean("make_a_right_turn"), "우회전입니다.", ());
- TEST_EQUAL(getKorean("take_the_5th_exit"), "다섯 번째 출구입니다.", ());
- TEST_EQUAL(getKorean("in_5000_feet"), "5000피트 앞", ());
- TEST_EQUAL(getKorean("some_nonexistent_key"), "some_nonexistent_key", ());
+ TEST_EQUAL(getKorean("in_700_meters").first, "700 미터 앞", ());
+ TEST_EQUAL(getKorean("make_a_right_turn").first, "우회전입니다.", ());
+ TEST_EQUAL(getKorean("take_the_5th_exit").first, "다섯 번째 출구입니다.", ());
+ TEST_EQUAL(getKorean("in_5000_feet").first, "5000피트 앞", ());
+
+ TEST_EQUAL(getKorean("some_nonexistent_key").first, "some_nonexistent_key", ());
+ TEST(!getKorean("some_nonexistent_key").second, ());
+ TEST(!getKorean("").second, ());
+ TEST(!getKorean(" ").second, ());
}
UNIT_TEST(GetTextByIdArabicTest)
{
platform::GetTextById getArabic(TextSource::TtsSound, "ar");
- TEST_EQUAL(getArabic("in_1_kilometer"), "بعد كيلو متر واحدٍ", ());
- TEST_EQUAL(getArabic("leave_the_roundabout"), "اخرج من الطريق الدوار", ());
- TEST_EQUAL(getArabic("take_the_3rd_exit"), "اسلك المخرج الثالث", ());
- TEST_EQUAL(getArabic("in_4000_feet"), "بعد 4000 قدم", ());
- TEST_EQUAL(getArabic("some_nonexistent_key"), "some_nonexistent_key", ());
+ TEST_EQUAL(getArabic("in_1_kilometer").first, "بعد كيلو متر واحدٍ", ());
+ TEST_EQUAL(getArabic("leave_the_roundabout").first, "اخرج من الطريق الدوار", ());
+ TEST_EQUAL(getArabic("take_the_3rd_exit").first, "اسلك المخرج الثالث", ());
+ TEST_EQUAL(getArabic("in_4000_feet").first, "بعد 4000 قدم", ());
+
+ TEST_EQUAL(getArabic("some_nonexistent_key").first, "some_nonexistent_key", ());
+ TEST(!getArabic("some_nonexistent_key").second, ());
+ TEST(!getArabic("").second, ());
+ TEST(!getArabic(" ").second, ());
}
UNIT_TEST(GetTextByIdFrenchTest)
{
platform::GetTextById getFrench(TextSource::TtsSound, "fr");
- TEST_EQUAL(getFrench("in_1_5_kilometers"), "Dans un virgule cinq kilomètre.", ());
- TEST_EQUAL(getFrench("enter_the_roundabout"), "Prenez le rond-point.", ());
- TEST_EQUAL(getFrench("take_the_2nd_exit"), "Prenez la deuxième sortie.", ());
- TEST_EQUAL(getFrench("in_3500_feet"), "Dans 3500 feet.", ());
- TEST_EQUAL(getFrench("some_nonexistent_key"), "some_nonexistent_key", ());
+ TEST_EQUAL(getFrench("in_1_5_kilometers").first, "Dans un virgule cinq kilomètre.", ());
+ TEST_EQUAL(getFrench("enter_the_roundabout").first, "Prenez le rond-point.", ());
+ TEST_EQUAL(getFrench("take_the_2nd_exit").first, "Prenez la deuxième sortie.", ());
+ TEST_EQUAL(getFrench("in_3500_feet").first, "Dans 3500 feet.", ());
+
+ TEST_EQUAL(getFrench("some_nonexistent_key").first, "some_nonexistent_key", ());
+ TEST(!getFrench("some_nonexistent_key").second, ());
+ TEST(!getFrench("").second, ());
+ TEST(!getFrench(" ").second, ());
}