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 13:51:24 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 02:58:49 +0300
commitc9ea450ec5fd459b4062dcb15a603f64f7ead06b (patch)
tree6a1df5edfbd90351785554e942c8847a20f38814 /platform
parent4d1f0e8ef4cb0a2f2cfb4ee289938b28ee0745e4 (diff)
Correction after colleagues comments. Adding unit tests. Some other changes.
Diffstat (limited to 'platform')
-rw-r--r--platform/get_text_by_id.cpp23
-rw-r--r--platform/get_text_by_id.hpp6
-rw-r--r--platform/platform_tests/get_text_by_id_tests.cpp80
3 files changed, 62 insertions, 47 deletions
diff --git a/platform/get_text_by_id.cpp b/platform/get_text_by_id.cpp
index d382787890..d2c8f028a2 100644
--- a/platform/get_text_by_id.cpp
+++ b/platform/get_text_by_id.cpp
@@ -9,6 +9,7 @@
#include "std/target_os.hpp"
+
namespace
{
string GetTextSourceString(platform::TextSource textSouce)
@@ -38,19 +39,29 @@ GetTextById::GetTextById(TextSource textSouce, string const & localeName)
{GetTextSourceString(textSouce), localeName + ".json"}, "localize.json");
// @TODO(vbykoianko) Add assert if locale path pathToJson is not valid.
+ LOG(LDEBUG, ("Trying to open json file at path", pathToJson));
string jsonBuffer;
ReaderPtr<Reader>(GetPlatform().GetReader(pathToJson)).ReadAsString(jsonBuffer);
+ InitFromJson(jsonBuffer);
+}
+
+GetTextById::GetTextById(string const & jsonBuffer)
+{
+ InitFromJson(jsonBuffer);
+}
+void GetTextById::InitFromJson(string const & jsonBuffer)
+{
if (jsonBuffer.empty())
{
- ASSERT(false, ("No json files found at the path", pathToJson));
+ ASSERT(false, ("No json files found."));
return;
}
my::Json root(jsonBuffer.c_str());
if (root.get() == nullptr)
{
- ASSERT(false, ("Cannot parse the json file found at the path", pathToJson));
+ ASSERT(false, ("Cannot parse the json file."));
return;
}
@@ -67,14 +78,14 @@ GetTextById::GetTextById(TextSource textSouce, string const & localeName)
ASSERT_EQUAL(m_localeTexts.size(), json_object_size(root.get()), ());
}
-pair<string, bool> GetTextById::operator()(string const & textId) const
+string GetTextById::operator()(string const & textId) const
{
if (!IsValid())
- return make_pair(textId, false);
+ return "";
auto const textIt = m_localeTexts.find(textId);
if (textIt == m_localeTexts.end())
- return make_pair(textId, false);
- return make_pair(textIt->second, true);
+ return "";
+ return textIt->second;
}
} // namespace platform
diff --git a/platform/get_text_by_id.hpp b/platform/get_text_by_id.hpp
index b70bac0cec..45c8fdb5e5 100644
--- a/platform/get_text_by_id.hpp
+++ b/platform/get_text_by_id.hpp
@@ -19,14 +19,18 @@ class GetTextById
{
public:
GetTextById(TextSource textSouce, string const & localeName);
+ /// The constructor is used for writing unit tests only.
+ GetTextById(string const & jsonBuffer);
bool IsValid() const { return !m_localeTexts.empty(); }
/// @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;
+ string operator()(string const & textId) const;
private:
+ void InitFromJson(string const & jsonBuffer);
+
unordered_map<string, string> m_localeTexts;
};
} // namespace platform
diff --git a/platform/platform_tests/get_text_by_id_tests.cpp b/platform/platform_tests/get_text_by_id_tests.cpp
index e9a7df4bf9..b5228e3138 100644
--- a/platform/platform_tests/get_text_by_id_tests.cpp
+++ b/platform/platform_tests/get_text_by_id_tests.cpp
@@ -7,69 +7,69 @@ using namespace platform;
UNIT_TEST(GetTextByIdEnglishTest)
{
platform::GetTextById getEnglish(TextSource::TtsSound, "en");
- 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("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").first, "some_nonexistent_key", ());
- TEST(!getEnglish("some_nonexistent_key").second, ());
- TEST(!getEnglish("").second, ());
- TEST(!getEnglish(" ").second, ());
+ TEST_EQUAL(getEnglish("some_nonexistent_key"), "", ());
+ TEST_EQUAL(getEnglish("some_nonexistent_key"), "", ());
+ TEST_EQUAL(getEnglish(""), "", ());
+ TEST_EQUAL(getEnglish(" "), "", ());
}
UNIT_TEST(GetTextByIdRussianTest)
{
platform::GetTextById getRussian(TextSource::TtsSound, "ru");
- 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("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").first, "some_nonexistent_key", ());
- TEST(!getRussian("some_nonexistent_key").second, ());
- TEST(!getRussian("").second, ());
- TEST(!getRussian(" ").second, ());
+ TEST_EQUAL(getRussian("some_nonexistent_key"), "", ());
+ TEST_EQUAL(getRussian("some_nonexistent_key"), "", ());
+ TEST_EQUAL(getRussian(""), "", ());
+ TEST_EQUAL(getRussian(" "), "", ());
}
UNIT_TEST(GetTextByIdKoreanTest)
{
platform::GetTextById getKorean(TextSource::TtsSound, "ko");
- 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("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").first, "some_nonexistent_key", ());
- TEST(!getKorean("some_nonexistent_key").second, ());
- TEST(!getKorean("").second, ());
- TEST(!getKorean(" ").second, ());
+ TEST_EQUAL(getKorean("some_nonexistent_key"), "", ());
+ TEST_EQUAL(getKorean("some_nonexistent_key"), "", ());
+ TEST_EQUAL(getKorean(""), "", ());
+ TEST_EQUAL(getKorean(" "), "", ());
}
UNIT_TEST(GetTextByIdArabicTest)
{
platform::GetTextById getArabic(TextSource::TtsSound, "ar");
- 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("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").first, "some_nonexistent_key", ());
- TEST(!getArabic("some_nonexistent_key").second, ());
- TEST(!getArabic("").second, ());
- TEST(!getArabic(" ").second, ());
+ TEST_EQUAL(getArabic("some_nonexistent_key"), "", ());
+ TEST_EQUAL(getArabic("some_nonexistent_key"), "", ());
+ TEST_EQUAL(getArabic(""), "", ());
+ TEST_EQUAL(getArabic(" "), "", ());
}
UNIT_TEST(GetTextByIdFrenchTest)
{
platform::GetTextById getFrench(TextSource::TtsSound, "fr");
- 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("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").first, "some_nonexistent_key", ());
- TEST(!getFrench("some_nonexistent_key").second, ());
- TEST(!getFrench("").second, ());
- TEST(!getFrench(" ").second, ());
+ TEST_EQUAL(getFrench("some_nonexistent_key"), "", ());
+ TEST_EQUAL(getFrench("some_nonexistent_key"), "", ());
+ TEST_EQUAL(getFrench(""), "", ());
+ TEST_EQUAL(getFrench(" "), "", ());
}