diff options
-rw-r--r-- | AUTHORS | 2 | ||||
-rw-r--r-- | base/BUILD.gn | 2 | ||||
-rw-r--r-- | base/base.gyp | 2 | ||||
-rw-r--r-- | base/i18n/case_conversion_unittest.cc | 7 | ||||
-rw-r--r-- | base/i18n/number_formatting_unittest.cc | 5 | ||||
-rw-r--r-- | base/i18n/rtl_unittest.cc | 4 | ||||
-rw-r--r-- | base/i18n/time_formatting_unittest.cc | 6 | ||||
-rw-r--r-- | base/test/icu_test_util.cc | 21 | ||||
-rw-r--r-- | base/test/icu_test_util.h | 29 |
9 files changed, 73 insertions, 5 deletions
@@ -622,7 +622,7 @@ Raghu Ram Nagaraj <r.nagaraj@samsung.com> Chanho Park <parkch98@gmail.com> Payal Pandey <payal.pandey@samsung.com> Kenneth Strickland <ken.strickland@gmail.com> -Olli Syrjälä <olli.syrjala@intel.com> +Olli Raula (Old name Olli Syrjälä) <olli.raula@intel.com> Vishal Bhatnagar <vishal.b@samsung.com> Yunsik Jang <yunsik.jang@lge.com> Siddharth Bagai <b.siddharth@samsung.com> diff --git a/base/BUILD.gn b/base/BUILD.gn index 7b7cdb9..51510ad 100644 --- a/base/BUILD.gn +++ b/base/BUILD.gn @@ -1383,6 +1383,8 @@ test("base_unittests") { "task_runner_util_unittest.cc", "template_util_unittest.cc", "test/histogram_tester_unittest.cc", + "test/icu_test_util.cc", + "test/icu_test_util.h", "test/test_pending_task_unittest.cc", "test/test_reg_util_win_unittest.cc", "test/trace_event_analyzer_unittest.cc", diff --git a/base/base.gyp b/base/base.gyp index 4a558d8..f2c1fc6 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -900,6 +900,8 @@ 'test/gtest_xml_util.h', 'test/histogram_tester.cc', 'test/histogram_tester.h', + 'test/icu_test_util.cc', + 'test/icu_test_util.h', 'test/ios/wait_util.h', 'test/ios/wait_util.mm', 'test/launcher/test_launcher.cc', diff --git a/base/i18n/case_conversion_unittest.cc b/base/i18n/case_conversion_unittest.cc index dc5bc1f..ee795bc 100644 --- a/base/i18n/case_conversion_unittest.cc +++ b/base/i18n/case_conversion_unittest.cc @@ -5,6 +5,7 @@ #include "base/i18n/case_conversion.h" #include "base/i18n/rtl.h" #include "base/strings/utf_string_conversions.h" +#include "base/test/icu_test_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/icu/source/i18n/unicode/usearch.h" @@ -58,7 +59,7 @@ TEST(CaseConversionTest, TurkishLocaleConversion) { const string16 expected_lower(WideToUTF16(L"\x69\x131")); const string16 expected_upper(WideToUTF16(L"\x49\x49")); - std::string default_locale(uloc_getDefault()); + test::ScopedRestoreICUDefaultLocale restore_locale; i18n::SetICUDefaultLocale("en_US"); string16 result = ToLower(mixed); @@ -77,8 +78,6 @@ TEST(CaseConversionTest, TurkishLocaleConversion) { result = ToUpper(mixed); EXPECT_EQ(expected_upper_turkish, result); - - SetICUDefaultLocale(default_locale.data()); } TEST(CaseConversionTest, FoldCase) { @@ -97,7 +96,7 @@ TEST(CaseConversionTest, FoldCase) { const string16 turkish(WideToUTF16(L"\x49\x131")); const string16 turkish_expected(WideToUTF16(L"\x69\x131")); - std::string default_locale(uloc_getDefault()); + test::ScopedRestoreICUDefaultLocale restore_locale; i18n::SetICUDefaultLocale("en_US"); EXPECT_EQ(turkish_expected, FoldCase(turkish)); diff --git a/base/i18n/number_formatting_unittest.cc b/base/i18n/number_formatting_unittest.cc index 3b0718d..dc6de2b 100644 --- a/base/i18n/number_formatting_unittest.cc +++ b/base/i18n/number_formatting_unittest.cc @@ -7,7 +7,9 @@ #include "base/i18n/number_formatting.h" #include "base/i18n/rtl.h" #include "base/strings/utf_string_conversions.h" +#include "base/test/icu_test_util.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/icu/source/i18n/unicode/usearch.h" namespace base { namespace { @@ -27,6 +29,8 @@ TEST(NumberFormattingTest, FormatNumber) { {-42, "-42", "-42"}, }; + test::ScopedRestoreICUDefaultLocale restore_locale; + for (size_t i = 0; i < arraysize(cases); ++i) { i18n::SetICUDefaultLocale("en"); testing::ResetFormatters(); @@ -72,6 +76,7 @@ TEST(NumberFormattingTest, FormatDouble) { {-42.7, 3, "-42.700", "-42,700"}, }; + test::ScopedRestoreICUDefaultLocale restore_locale; for (size_t i = 0; i < arraysize(cases); ++i) { i18n::SetICUDefaultLocale("en"); testing::ResetFormatters(); diff --git a/base/i18n/rtl_unittest.cc b/base/i18n/rtl_unittest.cc index ddaff1e..6deaf34 100644 --- a/base/i18n/rtl_unittest.cc +++ b/base/i18n/rtl_unittest.cc @@ -10,6 +10,7 @@ #include "base/strings/string_util.h" #include "base/strings/sys_string_conversions.h" #include "base/strings/utf_string_conversions.h" +#include "base/test/icu_test_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" #include "third_party/icu/source/i18n/unicode/usearch.h" @@ -305,6 +306,7 @@ TEST_F(RTLTest, WrapString) { const bool was_rtl = IsRTL(); + test::ScopedRestoreICUDefaultLocale restore_locale; for (size_t i = 0; i < 2; ++i) { // Toggle the application default text direction (to try each direction). SetRTL(!IsRTL()); @@ -352,6 +354,7 @@ TEST_F(RTLTest, GetDisplayStringInLTRDirectionality) { const bool was_rtl = IsRTL(); + test::ScopedRestoreICUDefaultLocale restore_locale; for (size_t i = 0; i < 2; ++i) { // Toggle the application default text direction (to try each direction). SetRTL(!IsRTL()); @@ -438,6 +441,7 @@ TEST_F(RTLTest, UnadjustStringForLocaleDirection) { const bool was_rtl = IsRTL(); + test::ScopedRestoreICUDefaultLocale restore_locale; for (size_t i = 0; i < 2; ++i) { // Toggle the application default text direction (to try each direction). SetRTL(!IsRTL()); diff --git a/base/i18n/time_formatting_unittest.cc b/base/i18n/time_formatting_unittest.cc index 9f152c0..e64acf1 100644 --- a/base/i18n/time_formatting_unittest.cc +++ b/base/i18n/time_formatting_unittest.cc @@ -7,6 +7,7 @@ #include "base/i18n/rtl.h" #include "base/memory/scoped_ptr.h" #include "base/strings/utf_string_conversions.h" +#include "base/test/icu_test_util.h" #include "base/time/time.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/icu/source/common/unicode/uversion.h" @@ -41,6 +42,7 @@ base::string16 GetShortTimeZone(const Time& time) { TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault12h) { // Test for a locale defaulted to 12h clock. // As an instance, we use third_party/icu/source/data/locales/en.txt. + test::ScopedRestoreICUDefaultLocale restore_locale; i18n::SetICUDefaultLocale("en_US"); Time time(Time::FromLocalExploded(kTestDateTimeExploded)); @@ -76,6 +78,7 @@ TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault12h) { TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault24h) { // Test for a locale defaulted to 24h clock. // As an instance, we use third_party/icu/source/data/locales/en_GB.txt. + test::ScopedRestoreICUDefaultLocale restore_locale; i18n::SetICUDefaultLocale("en_GB"); Time time(Time::FromLocalExploded(kTestDateTimeExploded)); @@ -111,6 +114,7 @@ TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault24h) { TEST(TimeFormattingTest, TimeFormatTimeOfDayJP) { // Test for a locale that uses different mark than "AM" and "PM". // As an instance, we use third_party/icu/source/data/locales/ja.txt. + test::ScopedRestoreICUDefaultLocale restore_locale; i18n::SetICUDefaultLocale("ja_JP"); Time time(Time::FromLocalExploded(kTestDateTimeExploded)); @@ -144,6 +148,7 @@ TEST(TimeFormattingTest, TimeFormatTimeOfDayJP) { TEST(TimeFormattingTest, TimeFormatDateUS) { // See third_party/icu/source/data/locales/en.txt. // The date patterns are "EEEE, MMMM d, y", "MMM d, y", and "M/d/yy". + test::ScopedRestoreICUDefaultLocale restore_locale; i18n::SetICUDefaultLocale("en_US"); Time time(Time::FromLocalExploded(kTestDateTimeExploded)); @@ -166,6 +171,7 @@ TEST(TimeFormattingTest, TimeFormatDateUS) { TEST(TimeFormattingTest, TimeFormatDateGB) { // See third_party/icu/source/data/locales/en_GB.txt. // The date patterns are "EEEE, d MMMM y", "d MMM y", and "dd/MM/yyyy". + test::ScopedRestoreICUDefaultLocale restore_locale; i18n::SetICUDefaultLocale("en_GB"); Time time(Time::FromLocalExploded(kTestDateTimeExploded)); diff --git a/base/test/icu_test_util.cc b/base/test/icu_test_util.cc new file mode 100644 index 0000000..a1a8029 --- /dev/null +++ b/base/test/icu_test_util.cc @@ -0,0 +1,21 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/test/icu_test_util.h" + +#include "base/i18n/rtl.h" +#include "third_party/icu/source/common/unicode/uloc.h" + +namespace base { +namespace test { + +ScopedRestoreICUDefaultLocale::ScopedRestoreICUDefaultLocale() + : default_locale_(uloc_getDefault()) {} + +ScopedRestoreICUDefaultLocale::~ScopedRestoreICUDefaultLocale() { + i18n::SetICUDefaultLocale(default_locale_.data()); +} + +} // namespace test +} // namespace base diff --git a/base/test/icu_test_util.h b/base/test/icu_test_util.h new file mode 100644 index 0000000..6a75eed --- /dev/null +++ b/base/test/icu_test_util.h @@ -0,0 +1,29 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BASE_ICU_TEST_UTIL_H_ +#define BASE_ICU_TEST_UTIL_H_ + +#include <string> + +#include "base/macros.h" + +namespace base { +namespace test { + +class ScopedRestoreICUDefaultLocale { + public: + ScopedRestoreICUDefaultLocale(); + ~ScopedRestoreICUDefaultLocale(); + + private: + std::string default_locale_; + + DISALLOW_COPY_AND_ASSIGN(ScopedRestoreICUDefaultLocale); +}; + +} // namespace test +} // namespace base + +#endif // BASE_ICU_TEST_UTIL_H_ |