Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(558)

Side by Side Diff: base/i18n/time_formatting_unittest.cc

Issue 1162603004: Restore locales after tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added spaces Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/i18n/rtl_unittest.cc ('k') | base/test/icu_test_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/i18n/time_formatting.h" 5 #include "base/i18n/time_formatting.h"
6 6
7 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/test/icu_test_util.h"
10 #include "base/time/time.h" 11 #include "base/time/time.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/icu/source/common/unicode/uversion.h" 13 #include "third_party/icu/source/common/unicode/uversion.h"
13 #include "third_party/icu/source/i18n/unicode/calendar.h" 14 #include "third_party/icu/source/i18n/unicode/calendar.h"
14 #include "third_party/icu/source/i18n/unicode/timezone.h" 15 #include "third_party/icu/source/i18n/unicode/timezone.h"
15 #include "third_party/icu/source/i18n/unicode/tzfmt.h" 16 #include "third_party/icu/source/i18n/unicode/tzfmt.h"
16 17
17 namespace base { 18 namespace base {
18 namespace { 19 namespace {
19 20
(...skipping 14 matching lines...) Expand all
34 icu::UnicodeString name; 35 icu::UnicodeString name;
35 zone_formatter->format(UTZFMT_STYLE_SPECIFIC_SHORT, *zone, 36 zone_formatter->format(UTZFMT_STYLE_SPECIFIC_SHORT, *zone,
36 static_cast<UDate>(time.ToDoubleT() * 1000), 37 static_cast<UDate>(time.ToDoubleT() * 1000),
37 name, nullptr); 38 name, nullptr);
38 return base::string16(name.getBuffer(), name.length()); 39 return base::string16(name.getBuffer(), name.length());
39 } 40 }
40 41
41 TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault12h) { 42 TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault12h) {
42 // Test for a locale defaulted to 12h clock. 43 // Test for a locale defaulted to 12h clock.
43 // As an instance, we use third_party/icu/source/data/locales/en.txt. 44 // As an instance, we use third_party/icu/source/data/locales/en.txt.
45 test::ScopedRestoreICUDefaultLocale restore_locale;
44 i18n::SetICUDefaultLocale("en_US"); 46 i18n::SetICUDefaultLocale("en_US");
45 47
46 Time time(Time::FromLocalExploded(kTestDateTimeExploded)); 48 Time time(Time::FromLocalExploded(kTestDateTimeExploded));
47 string16 clock24h(ASCIIToUTF16("15:42")); 49 string16 clock24h(ASCIIToUTF16("15:42"));
48 string16 clock12h_pm(ASCIIToUTF16("3:42 PM")); 50 string16 clock12h_pm(ASCIIToUTF16("3:42 PM"));
49 string16 clock12h(ASCIIToUTF16("3:42")); 51 string16 clock12h(ASCIIToUTF16("3:42"));
50 string16 clock24h_millis(ASCIIToUTF16("15:42:07.000")); 52 string16 clock24h_millis(ASCIIToUTF16("15:42:07.000"));
51 53
52 // The default is 12h clock. 54 // The default is 12h clock.
53 EXPECT_EQ(clock12h_pm, TimeFormatTimeOfDay(time)); 55 EXPECT_EQ(clock12h_pm, TimeFormatTimeOfDay(time));
(...skipping 15 matching lines...) Expand all
69 kKeepAmPm)); 71 kKeepAmPm));
70 EXPECT_EQ(clock12h, 72 EXPECT_EQ(clock12h,
71 TimeFormatTimeOfDayWithHourClockType(time, 73 TimeFormatTimeOfDayWithHourClockType(time,
72 k12HourClock, 74 k12HourClock,
73 kDropAmPm)); 75 kDropAmPm));
74 } 76 }
75 77
76 TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault24h) { 78 TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault24h) {
77 // Test for a locale defaulted to 24h clock. 79 // Test for a locale defaulted to 24h clock.
78 // As an instance, we use third_party/icu/source/data/locales/en_GB.txt. 80 // As an instance, we use third_party/icu/source/data/locales/en_GB.txt.
81 test::ScopedRestoreICUDefaultLocale restore_locale;
79 i18n::SetICUDefaultLocale("en_GB"); 82 i18n::SetICUDefaultLocale("en_GB");
80 83
81 Time time(Time::FromLocalExploded(kTestDateTimeExploded)); 84 Time time(Time::FromLocalExploded(kTestDateTimeExploded));
82 string16 clock24h(ASCIIToUTF16("15:42")); 85 string16 clock24h(ASCIIToUTF16("15:42"));
83 string16 clock12h_pm(ASCIIToUTF16("3:42 pm")); 86 string16 clock12h_pm(ASCIIToUTF16("3:42 pm"));
84 string16 clock12h(ASCIIToUTF16("3:42")); 87 string16 clock12h(ASCIIToUTF16("3:42"));
85 string16 clock24h_millis(ASCIIToUTF16("15:42:07.000")); 88 string16 clock24h_millis(ASCIIToUTF16("15:42:07.000"));
86 89
87 // The default is 24h clock. 90 // The default is 24h clock.
88 EXPECT_EQ(clock24h, TimeFormatTimeOfDay(time)); 91 EXPECT_EQ(clock24h, TimeFormatTimeOfDay(time));
(...skipping 15 matching lines...) Expand all
104 kKeepAmPm)); 107 kKeepAmPm));
105 EXPECT_EQ(clock12h, 108 EXPECT_EQ(clock12h,
106 TimeFormatTimeOfDayWithHourClockType(time, 109 TimeFormatTimeOfDayWithHourClockType(time,
107 k12HourClock, 110 k12HourClock,
108 kDropAmPm)); 111 kDropAmPm));
109 } 112 }
110 113
111 TEST(TimeFormattingTest, TimeFormatTimeOfDayJP) { 114 TEST(TimeFormattingTest, TimeFormatTimeOfDayJP) {
112 // Test for a locale that uses different mark than "AM" and "PM". 115 // Test for a locale that uses different mark than "AM" and "PM".
113 // As an instance, we use third_party/icu/source/data/locales/ja.txt. 116 // As an instance, we use third_party/icu/source/data/locales/ja.txt.
117 test::ScopedRestoreICUDefaultLocale restore_locale;
114 i18n::SetICUDefaultLocale("ja_JP"); 118 i18n::SetICUDefaultLocale("ja_JP");
115 119
116 Time time(Time::FromLocalExploded(kTestDateTimeExploded)); 120 Time time(Time::FromLocalExploded(kTestDateTimeExploded));
117 string16 clock24h(ASCIIToUTF16("15:42")); 121 string16 clock24h(ASCIIToUTF16("15:42"));
118 string16 clock12h_pm(WideToUTF16(L"\x5348\x5f8c" L"3:42")); 122 string16 clock12h_pm(WideToUTF16(L"\x5348\x5f8c" L"3:42"));
119 string16 clock12h(ASCIIToUTF16("3:42")); 123 string16 clock12h(ASCIIToUTF16("3:42"));
120 124
121 // The default is 24h clock. 125 // The default is 24h clock.
122 EXPECT_EQ(clock24h, TimeFormatTimeOfDay(time)); 126 EXPECT_EQ(clock24h, TimeFormatTimeOfDay(time));
123 EXPECT_EQ(k24HourClock, GetHourClockType()); 127 EXPECT_EQ(k24HourClock, GetHourClockType());
(...skipping 13 matching lines...) Expand all
137 kKeepAmPm)); 141 kKeepAmPm));
138 EXPECT_EQ(clock12h, 142 EXPECT_EQ(clock12h,
139 TimeFormatTimeOfDayWithHourClockType(time, 143 TimeFormatTimeOfDayWithHourClockType(time,
140 k12HourClock, 144 k12HourClock,
141 kDropAmPm)); 145 kDropAmPm));
142 } 146 }
143 147
144 TEST(TimeFormattingTest, TimeFormatDateUS) { 148 TEST(TimeFormattingTest, TimeFormatDateUS) {
145 // See third_party/icu/source/data/locales/en.txt. 149 // See third_party/icu/source/data/locales/en.txt.
146 // The date patterns are "EEEE, MMMM d, y", "MMM d, y", and "M/d/yy". 150 // The date patterns are "EEEE, MMMM d, y", "MMM d, y", and "M/d/yy".
151 test::ScopedRestoreICUDefaultLocale restore_locale;
147 i18n::SetICUDefaultLocale("en_US"); 152 i18n::SetICUDefaultLocale("en_US");
148 153
149 Time time(Time::FromLocalExploded(kTestDateTimeExploded)); 154 Time time(Time::FromLocalExploded(kTestDateTimeExploded));
150 155
151 EXPECT_EQ(ASCIIToUTF16("Apr 30, 2011"), TimeFormatShortDate(time)); 156 EXPECT_EQ(ASCIIToUTF16("Apr 30, 2011"), TimeFormatShortDate(time));
152 EXPECT_EQ(ASCIIToUTF16("4/30/11"), TimeFormatShortDateNumeric(time)); 157 EXPECT_EQ(ASCIIToUTF16("4/30/11"), TimeFormatShortDateNumeric(time));
153 158
154 EXPECT_EQ(ASCIIToUTF16("4/30/11, 3:42:07 PM"), 159 EXPECT_EQ(ASCIIToUTF16("4/30/11, 3:42:07 PM"),
155 TimeFormatShortDateAndTime(time)); 160 TimeFormatShortDateAndTime(time));
156 EXPECT_EQ(ASCIIToUTF16("4/30/11, 3:42:07 PM ") + GetShortTimeZone(time), 161 EXPECT_EQ(ASCIIToUTF16("4/30/11, 3:42:07 PM ") + GetShortTimeZone(time),
157 TimeFormatShortDateAndTimeWithTimeZone(time)); 162 TimeFormatShortDateAndTimeWithTimeZone(time));
158 163
159 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011 at 3:42:07 PM"), 164 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011 at 3:42:07 PM"),
160 TimeFormatFriendlyDateAndTime(time)); 165 TimeFormatFriendlyDateAndTime(time));
161 166
162 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011"), 167 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011"),
163 TimeFormatFriendlyDate(time)); 168 TimeFormatFriendlyDate(time));
164 } 169 }
165 170
166 TEST(TimeFormattingTest, TimeFormatDateGB) { 171 TEST(TimeFormattingTest, TimeFormatDateGB) {
167 // See third_party/icu/source/data/locales/en_GB.txt. 172 // See third_party/icu/source/data/locales/en_GB.txt.
168 // The date patterns are "EEEE, d MMMM y", "d MMM y", and "dd/MM/yyyy". 173 // The date patterns are "EEEE, d MMMM y", "d MMM y", and "dd/MM/yyyy".
174 test::ScopedRestoreICUDefaultLocale restore_locale;
169 i18n::SetICUDefaultLocale("en_GB"); 175 i18n::SetICUDefaultLocale("en_GB");
170 176
171 Time time(Time::FromLocalExploded(kTestDateTimeExploded)); 177 Time time(Time::FromLocalExploded(kTestDateTimeExploded));
172 178
173 EXPECT_EQ(ASCIIToUTF16("30 Apr 2011"), TimeFormatShortDate(time)); 179 EXPECT_EQ(ASCIIToUTF16("30 Apr 2011"), TimeFormatShortDate(time));
174 EXPECT_EQ(ASCIIToUTF16("30/04/2011"), TimeFormatShortDateNumeric(time)); 180 EXPECT_EQ(ASCIIToUTF16("30/04/2011"), TimeFormatShortDateNumeric(time));
175 EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07"), 181 EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07"),
176 TimeFormatShortDateAndTime(time)); 182 TimeFormatShortDateAndTime(time));
177 EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07 ") + GetShortTimeZone(time), 183 EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07 ") + GetShortTimeZone(time),
178 TimeFormatShortDateAndTimeWithTimeZone(time)); 184 TimeFormatShortDateAndTimeWithTimeZone(time));
179 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011 at 15:42:07"), 185 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011 at 15:42:07"),
180 TimeFormatFriendlyDateAndTime(time)); 186 TimeFormatFriendlyDateAndTime(time));
181 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011"), 187 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011"),
182 TimeFormatFriendlyDate(time)); 188 TimeFormatFriendlyDate(time));
183 } 189 }
184 190
185 } // namespace 191 } // namespace
186 } // namespace base 192 } // namespace base
OLDNEW
« no previous file with comments | « base/i18n/rtl_unittest.cc ('k') | base/test/icu_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698