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

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

Issue 878143002: Clean up time_formatting_unittest.cc now that chromium icu has been updated (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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 | « no previous file | no next file » | 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/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/icu/source/common/unicode/uversion.h" 11 #include "third_party/icu/source/common/unicode/uversion.h"
jungshik at Google 2015/02/03 21:49:09 Sorry that I forgot to point this out. You don't n
12 12
13 namespace base { 13 namespace base {
14 namespace { 14 namespace {
15 15
16 const Time::Exploded kTestDateTimeExploded = { 16 const Time::Exploded kTestDateTimeExploded = {
17 2011, 4, 6, 30, // Sat, Apr 30, 2011 17 2011, 4, 6, 30, // Sat, Apr 30, 2011
18 15, 42, 7, 0 // 15:42:07.000 18 15, 42, 7, 0 // 15:42:07.000
19 }; 19 };
20 20
21 TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault12h) { 21 TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault12h) {
(...skipping 29 matching lines...) Expand all
51 kDropAmPm)); 51 kDropAmPm));
52 } 52 }
53 53
54 TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault24h) { 54 TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault24h) {
55 // Test for a locale defaulted to 24h clock. 55 // Test for a locale defaulted to 24h clock.
56 // As an instance, we use third_party/icu/source/data/locales/en_GB.txt. 56 // As an instance, we use third_party/icu/source/data/locales/en_GB.txt.
57 i18n::SetICUDefaultLocale("en_GB"); 57 i18n::SetICUDefaultLocale("en_GB");
58 58
59 Time time(Time::FromLocalExploded(kTestDateTimeExploded)); 59 Time time(Time::FromLocalExploded(kTestDateTimeExploded));
60 string16 clock24h(ASCIIToUTF16("15:42")); 60 string16 clock24h(ASCIIToUTF16("15:42"));
61 #if U_ICU_VERSION_MAJOR_NUM >= 50
62 string16 clock12h_pm(ASCIIToUTF16("3:42 pm")); 61 string16 clock12h_pm(ASCIIToUTF16("3:42 pm"));
63 #else
64 // TODO(phajdan.jr): Clean up after bundled ICU gets updated to 50.
65 string16 clock12h_pm(ASCIIToUTF16("3:42 PM"));
66 #endif
67 string16 clock12h(ASCIIToUTF16("3:42")); 62 string16 clock12h(ASCIIToUTF16("3:42"));
68 63
69 // The default is 24h clock. 64 // The default is 24h clock.
70 EXPECT_EQ(clock24h, TimeFormatTimeOfDay(time)); 65 EXPECT_EQ(clock24h, TimeFormatTimeOfDay(time));
71 EXPECT_EQ(k24HourClock, GetHourClockType()); 66 EXPECT_EQ(k24HourClock, GetHourClockType());
72 // k{Keep,Drop}AmPm should not affect for 24h clock. 67 // k{Keep,Drop}AmPm should not affect for 24h clock.
73 EXPECT_EQ(clock24h, 68 EXPECT_EQ(clock24h,
74 TimeFormatTimeOfDayWithHourClockType(time, 69 TimeFormatTimeOfDayWithHourClockType(time,
75 k24HourClock, 70 k24HourClock,
76 kKeepAmPm)); 71 kKeepAmPm));
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 TEST(TimeFormattingTest, TimeFormatDateUS) { 120 TEST(TimeFormattingTest, TimeFormatDateUS) {
126 // See third_party/icu/source/data/locales/en.txt. 121 // See third_party/icu/source/data/locales/en.txt.
127 // The date patterns are "EEEE, MMMM d, y", "MMM d, y", and "M/d/yy". 122 // The date patterns are "EEEE, MMMM d, y", "MMM d, y", and "M/d/yy".
128 i18n::SetICUDefaultLocale("en_US"); 123 i18n::SetICUDefaultLocale("en_US");
129 124
130 Time time(Time::FromLocalExploded(kTestDateTimeExploded)); 125 Time time(Time::FromLocalExploded(kTestDateTimeExploded));
131 126
132 EXPECT_EQ(ASCIIToUTF16("Apr 30, 2011"), TimeFormatShortDate(time)); 127 EXPECT_EQ(ASCIIToUTF16("Apr 30, 2011"), TimeFormatShortDate(time));
133 EXPECT_EQ(ASCIIToUTF16("4/30/11"), TimeFormatShortDateNumeric(time)); 128 EXPECT_EQ(ASCIIToUTF16("4/30/11"), TimeFormatShortDateNumeric(time));
134 129
135 #if U_ICU_VERSION_MAJOR_NUM >= 50
136 EXPECT_EQ(ASCIIToUTF16("4/30/11, 3:42:07 PM"), 130 EXPECT_EQ(ASCIIToUTF16("4/30/11, 3:42:07 PM"),
137 TimeFormatShortDateAndTime(time)); 131 TimeFormatShortDateAndTime(time));
138 #else
139 // TODO(phajdan.jr): Clean up after bundled ICU gets updated to 50.
140 EXPECT_EQ(ASCIIToUTF16("4/30/11 3:42:07 PM"),
141 TimeFormatShortDateAndTime(time));
142 #endif
143 132
144 #if U_ICU_VERSION_MAJOR_NUM >= 50
145 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011 at 3:42:07 PM"), 133 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011 at 3:42:07 PM"),
146 TimeFormatFriendlyDateAndTime(time)); 134 TimeFormatFriendlyDateAndTime(time));
147 #else
148 // TODO(phajdan.jr): Clean up after bundled ICU gets updated to 50.
149 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011 3:42:07 PM"),
150 TimeFormatFriendlyDateAndTime(time));
151 #endif
152 135
153 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011"), 136 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011"),
154 TimeFormatFriendlyDate(time)); 137 TimeFormatFriendlyDate(time));
155 } 138 }
156 139
157 TEST(TimeFormattingTest, TimeFormatDateGB) { 140 TEST(TimeFormattingTest, TimeFormatDateGB) {
158 // See third_party/icu/source/data/locales/en_GB.txt. 141 // See third_party/icu/source/data/locales/en_GB.txt.
159 // The date patterns are "EEEE, d MMMM y", "d MMM y", and "dd/MM/yyyy". 142 // The date patterns are "EEEE, d MMMM y", "d MMM y", and "dd/MM/yyyy".
160 i18n::SetICUDefaultLocale("en_GB"); 143 i18n::SetICUDefaultLocale("en_GB");
161 144
162 Time time(Time::FromLocalExploded(kTestDateTimeExploded)); 145 Time time(Time::FromLocalExploded(kTestDateTimeExploded));
163 146
164 EXPECT_EQ(ASCIIToUTF16("30 Apr 2011"), TimeFormatShortDate(time)); 147 EXPECT_EQ(ASCIIToUTF16("30 Apr 2011"), TimeFormatShortDate(time));
165 EXPECT_EQ(ASCIIToUTF16("30/04/2011"), TimeFormatShortDateNumeric(time)); 148 EXPECT_EQ(ASCIIToUTF16("30/04/2011"), TimeFormatShortDateNumeric(time));
166 EXPECT_EQ(ASCIIToUTF16("30/04/2011 15:42:07"), 149 EXPECT_EQ(ASCIIToUTF16("30/04/2011 15:42:07"),
167 TimeFormatShortDateAndTime(time)); 150 TimeFormatShortDateAndTime(time));
168 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011 15:42:07"), 151 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011 15:42:07"),
169 TimeFormatFriendlyDateAndTime(time)); 152 TimeFormatFriendlyDateAndTime(time));
170 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011"), 153 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011"),
171 TimeFormatFriendlyDate(time)); 154 TimeFormatFriendlyDate(time));
172 } 155 }
173 156
174 } // namespace 157 } // namespace
175 } // namespace base 158 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698