summaryrefslogtreecommitdiffstats
path: root/base/i18n
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-07 20:16:31 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-07 20:16:31 +0000
commit3c8fe063fdf240454fe45b011f3e44054936da8f (patch)
tree58d6e3b01dac32d0919574adde45319a1e45aa6e /base/i18n
parentc08504dd3f26f10c73ddd86e764a003fa879cd6d (diff)
downloadchromium_src-3c8fe063fdf240454fe45b011f3e44054936da8f.zip
chromium_src-3c8fe063fdf240454fe45b011f3e44054936da8f.tar.gz
chromium_src-3c8fe063fdf240454fe45b011f3e44054936da8f.tar.bz2
Reuse base::i18n::SetICUDefaultLocale from rtl.h in some unittests.
This removes duplicated versions of SetICUDefaultLocale() defined in unittests. TEST=base_unittests,ui_unittests R=phajdan.jr@chromium.org Review URL: http://codereview.chromium.org/8139034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104550 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/i18n')
-rw-r--r--base/i18n/number_formatting_unittest.cc45
-rw-r--r--base/i18n/time_formatting_unittest.cc149
2 files changed, 87 insertions, 107 deletions
diff --git a/base/i18n/number_formatting_unittest.cc b/base/i18n/number_formatting_unittest.cc
index c7485d1..c40ab34 100644
--- a/base/i18n/number_formatting_unittest.cc
+++ b/base/i18n/number_formatting_unittest.cc
@@ -5,21 +5,13 @@
#include <limits>
#include "base/i18n/number_formatting.h"
+#include "base/i18n/rtl.h"
#include "base/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "unicode/locid.h"
+namespace base {
namespace {
-void SetICUDefaultLocale(const std::string& locale_string) {
- icu::Locale locale(locale_string.c_str());
- UErrorCode error_code = U_ZERO_ERROR;
- icu::Locale::setDefault(locale, error_code);
- EXPECT_TRUE(U_SUCCESS(error_code));
-}
-
-} // namespace
-
TEST(NumberFormattingTest, FormatNumber) {
static const struct {
int64 number;
@@ -36,14 +28,14 @@ TEST(NumberFormattingTest, FormatNumber) {
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
- SetICUDefaultLocale("en");
- base::testing::ResetFormatters();
+ i18n::SetICUDefaultLocale("en");
+ testing::ResetFormatters();
EXPECT_EQ(cases[i].expected_english,
- UTF16ToUTF8(base::FormatNumber(cases[i].number)));
- SetICUDefaultLocale("de");
- base::testing::ResetFormatters();
+ UTF16ToUTF8(FormatNumber(cases[i].number)));
+ i18n::SetICUDefaultLocale("de");
+ testing::ResetFormatters();
EXPECT_EQ(cases[i].expected_german,
- UTF16ToUTF8(base::FormatNumber(cases[i].number)));
+ UTF16ToUTF8(FormatNumber(cases[i].number)));
}
}
@@ -81,15 +73,16 @@ TEST(NumberFormattingTest, FormatDouble) {
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
- SetICUDefaultLocale("en");
- base::testing::ResetFormatters();
- EXPECT_EQ(cases[i].expected_english,
- UTF16ToUTF8(base::FormatDouble(cases[i].number,
- cases[i].frac_digits)));
- SetICUDefaultLocale("de");
- base::testing::ResetFormatters();
- EXPECT_EQ(cases[i].expected_german,
- UTF16ToUTF8(base::FormatDouble(cases[i].number,
- cases[i].frac_digits)));
+ i18n::SetICUDefaultLocale("en");
+ testing::ResetFormatters();
+ EXPECT_EQ(cases[i].expected_english,
+ UTF16ToUTF8(FormatDouble(cases[i].number, cases[i].frac_digits)));
+ i18n::SetICUDefaultLocale("de");
+ testing::ResetFormatters();
+ EXPECT_EQ(cases[i].expected_german,
+ UTF16ToUTF8(FormatDouble(cases[i].number, cases[i].frac_digits)));
}
}
+
+} // namespace
+} // namespace base
diff --git a/base/i18n/time_formatting_unittest.cc b/base/i18n/time_formatting_unittest.cc
index eab12d9..76ffa5d 100644
--- a/base/i18n/time_formatting_unittest.cc
+++ b/base/i18n/time_formatting_unittest.cc
@@ -4,164 +4,151 @@
#include "base/i18n/time_formatting.h"
+#include "base/i18n/rtl.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "unicode/locid.h"
+namespace base {
namespace {
-void SetICUDefaultLocale(const std::string& locale_string) {
- icu::Locale locale(locale_string.c_str());
- UErrorCode error_code = U_ZERO_ERROR;
- icu::Locale::setDefault(locale, error_code);
- EXPECT_TRUE(U_SUCCESS(error_code));
-}
-
-const base::Time::Exploded kTestDateTimeExploded = {
+const Time::Exploded kTestDateTimeExploded = {
2011, 4, 6, 30, // Sat, Apr 30, 2011
15, 42, 7, 0 // 15:42:07.000
};
-} // namespace
-
TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault12h) {
// Test for a locale defaulted to 12h clock.
// As an instance, we use third_party/icu/source/data/locales/en.txt.
- SetICUDefaultLocale("en_US");
+ i18n::SetICUDefaultLocale("en_US");
- base::Time time(base::Time::FromLocalExploded(kTestDateTimeExploded));
+ Time time(Time::FromLocalExploded(kTestDateTimeExploded));
string16 clock24h(ASCIIToUTF16("15:42"));
string16 clock12h_pm(ASCIIToUTF16("3:42 PM"));
string16 clock12h(ASCIIToUTF16("3:42"));
// The default is 12h clock.
- EXPECT_EQ(clock12h_pm,
- base::TimeFormatTimeOfDay(time));
- EXPECT_EQ(base::k12HourClock, base::GetHourClockType());
+ EXPECT_EQ(clock12h_pm, TimeFormatTimeOfDay(time));
+ EXPECT_EQ(k12HourClock, GetHourClockType());
// k{Keep,Drop}AmPm should not affect for 24h clock.
EXPECT_EQ(clock24h,
- base::TimeFormatTimeOfDayWithHourClockType(time,
- base::k24HourClock,
- base::kKeepAmPm));
+ TimeFormatTimeOfDayWithHourClockType(time,
+ k24HourClock,
+ kKeepAmPm));
EXPECT_EQ(clock24h,
- base::TimeFormatTimeOfDayWithHourClockType(time,
- base::k24HourClock,
- base::kDropAmPm));
+ TimeFormatTimeOfDayWithHourClockType(time,
+ k24HourClock,
+ kDropAmPm));
// k{Keep,Drop}AmPm affects for 12h clock.
EXPECT_EQ(clock12h_pm,
- base::TimeFormatTimeOfDayWithHourClockType(time,
- base::k12HourClock,
- base::kKeepAmPm));
+ TimeFormatTimeOfDayWithHourClockType(time,
+ k12HourClock,
+ kKeepAmPm));
EXPECT_EQ(clock12h,
- base::TimeFormatTimeOfDayWithHourClockType(time,
- base::k12HourClock,
- base::kDropAmPm));
+ TimeFormatTimeOfDayWithHourClockType(time,
+ k12HourClock,
+ kDropAmPm));
}
-
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.
- SetICUDefaultLocale("en_GB");
+ i18n::SetICUDefaultLocale("en_GB");
- base::Time time(base::Time::FromLocalExploded(kTestDateTimeExploded));
+ Time time(Time::FromLocalExploded(kTestDateTimeExploded));
string16 clock24h(ASCIIToUTF16("15:42"));
string16 clock12h_pm(ASCIIToUTF16("3:42 PM"));
string16 clock12h(ASCIIToUTF16("3:42"));
// The default is 24h clock.
- EXPECT_EQ(clock24h,
- base::TimeFormatTimeOfDay(time));
- EXPECT_EQ(base::k24HourClock, base::GetHourClockType());
+ EXPECT_EQ(clock24h, TimeFormatTimeOfDay(time));
+ EXPECT_EQ(k24HourClock, GetHourClockType());
// k{Keep,Drop}AmPm should not affect for 24h clock.
EXPECT_EQ(clock24h,
- base::TimeFormatTimeOfDayWithHourClockType(time,
- base::k24HourClock,
- base::kKeepAmPm));
+ TimeFormatTimeOfDayWithHourClockType(time,
+ k24HourClock,
+ kKeepAmPm));
EXPECT_EQ(clock24h,
- base::TimeFormatTimeOfDayWithHourClockType(time,
- base::k24HourClock,
- base::kDropAmPm));
+ TimeFormatTimeOfDayWithHourClockType(time,
+ k24HourClock,
+ kDropAmPm));
// k{Keep,Drop}AmPm affects for 12h clock.
EXPECT_EQ(clock12h_pm,
- base::TimeFormatTimeOfDayWithHourClockType(time,
- base::k12HourClock,
- base::kKeepAmPm));
+ TimeFormatTimeOfDayWithHourClockType(time,
+ k12HourClock,
+ kKeepAmPm));
EXPECT_EQ(clock12h,
- base::TimeFormatTimeOfDayWithHourClockType(time,
- base::k12HourClock,
- base::kDropAmPm));
+ TimeFormatTimeOfDayWithHourClockType(time,
+ k12HourClock,
+ kDropAmPm));
}
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.
- SetICUDefaultLocale("ja_JP");
+ i18n::SetICUDefaultLocale("ja_JP");
- base::Time time(base::Time::FromLocalExploded(kTestDateTimeExploded));
+ Time time(Time::FromLocalExploded(kTestDateTimeExploded));
string16 clock24h(ASCIIToUTF16("15:42"));
string16 clock12h_pm(WideToUTF16(L"\x5348\x5f8c"L"3:42"));
string16 clock12h(ASCIIToUTF16("3:42"));
// The default is 24h clock.
- EXPECT_EQ(clock24h,
- base::TimeFormatTimeOfDay(time));
- EXPECT_EQ(base::k24HourClock, base::GetHourClockType());
+ EXPECT_EQ(clock24h, TimeFormatTimeOfDay(time));
+ EXPECT_EQ(k24HourClock, GetHourClockType());
// k{Keep,Drop}AmPm should not affect for 24h clock.
EXPECT_EQ(clock24h,
- base::TimeFormatTimeOfDayWithHourClockType(time,
- base::k24HourClock,
- base::kKeepAmPm));
+ TimeFormatTimeOfDayWithHourClockType(time,
+ k24HourClock,
+ kKeepAmPm));
EXPECT_EQ(clock24h,
- base::TimeFormatTimeOfDayWithHourClockType(time,
- base::k24HourClock,
- base::kDropAmPm));
+ TimeFormatTimeOfDayWithHourClockType(time,
+ k24HourClock,
+ kDropAmPm));
// k{Keep,Drop}AmPm affects for 12h clock.
EXPECT_EQ(clock12h_pm,
- base::TimeFormatTimeOfDayWithHourClockType(time,
- base::k12HourClock,
- base::kKeepAmPm));
+ TimeFormatTimeOfDayWithHourClockType(time,
+ k12HourClock,
+ kKeepAmPm));
EXPECT_EQ(clock12h,
- base::TimeFormatTimeOfDayWithHourClockType(time,
- base::k12HourClock,
- base::kDropAmPm));
+ TimeFormatTimeOfDayWithHourClockType(time,
+ k12HourClock,
+ kDropAmPm));
}
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".
- SetICUDefaultLocale("en_US");
+ i18n::SetICUDefaultLocale("en_US");
- base::Time time(base::Time::FromLocalExploded(kTestDateTimeExploded));
+ Time time(Time::FromLocalExploded(kTestDateTimeExploded));
- EXPECT_EQ(ASCIIToUTF16("Apr 30, 2011"),
- base::TimeFormatShortDate(time));
- EXPECT_EQ(ASCIIToUTF16("4/30/11"),
- base::TimeFormatShortDateNumeric(time));
+ EXPECT_EQ(ASCIIToUTF16("Apr 30, 2011"), TimeFormatShortDate(time));
+ EXPECT_EQ(ASCIIToUTF16("4/30/11"), TimeFormatShortDateNumeric(time));
EXPECT_EQ(ASCIIToUTF16("4/30/11 3:42:07 PM"),
- base::TimeFormatShortDateAndTime(time));
+ TimeFormatShortDateAndTime(time));
EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011 3:42:07 PM"),
- base::TimeFormatFriendlyDateAndTime(time));
+ TimeFormatFriendlyDateAndTime(time));
EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011"),
- base::TimeFormatFriendlyDate(time));
+ TimeFormatFriendlyDate(time));
}
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".
- SetICUDefaultLocale("en_GB");
+ i18n::SetICUDefaultLocale("en_GB");
- base::Time time(base::Time::FromLocalExploded(kTestDateTimeExploded));
+ Time time(Time::FromLocalExploded(kTestDateTimeExploded));
- EXPECT_EQ(ASCIIToUTF16("30 Apr 2011"),
- base::TimeFormatShortDate(time));
- EXPECT_EQ(ASCIIToUTF16("30/04/2011"),
- base::TimeFormatShortDateNumeric(time));
+ EXPECT_EQ(ASCIIToUTF16("30 Apr 2011"), TimeFormatShortDate(time));
+ EXPECT_EQ(ASCIIToUTF16("30/04/2011"), TimeFormatShortDateNumeric(time));
EXPECT_EQ(ASCIIToUTF16("30/04/2011 15:42:07"),
- base::TimeFormatShortDateAndTime(time));
+ TimeFormatShortDateAndTime(time));
EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011 15:42:07"),
- base::TimeFormatFriendlyDateAndTime(time));
+ TimeFormatFriendlyDateAndTime(time));
EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011"),
- base::TimeFormatFriendlyDate(time));
+ TimeFormatFriendlyDate(time));
}
+
+} // namespace
+} // namespace base