OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 16 matching lines...) Expand all Loading... |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "platform/text/LocaleWin.h" | 31 #include "platform/text/LocaleWin.h" |
32 | 32 |
33 #include "platform/DateComponents.h" | 33 #include "platform/DateComponents.h" |
34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
35 #include "wtf/DateMath.h" | 35 #include "wtf/DateMath.h" |
36 #include "wtf/MathExtras.h" | 36 #include "wtf/MathExtras.h" |
37 #include "wtf/PassOwnPtr.h" | |
38 #include "wtf/text/CString.h" | 37 #include "wtf/text/CString.h" |
| 38 #include <memory> |
39 | 39 |
40 namespace blink { | 40 namespace blink { |
41 | 41 |
42 class LocaleWinTest : public ::testing::Test { | 42 class LocaleWinTest : public ::testing::Test { |
43 protected: | 43 protected: |
44 enum { | 44 enum { |
45 January = 0, February, March, | 45 January = 0, February, March, |
46 April, May, June, | 46 April, May, June, |
47 July, August, September, | 47 July, August, September, |
48 October, November, December, | 48 October, November, December, |
(...skipping 28 matching lines...) Expand all Loading... |
77 return date; | 77 return date; |
78 } | 78 } |
79 | 79 |
80 double msForDate(int year, int month, int day) | 80 double msForDate(int year, int month, int day) |
81 { | 81 { |
82 return dateToDaysFrom1970(year, month, day) * msPerDay; | 82 return dateToDaysFrom1970(year, month, day) * msPerDay; |
83 } | 83 } |
84 | 84 |
85 String formatDate(LCID lcid, int year, int month, int day) | 85 String formatDate(LCID lcid, int year, int month, int day) |
86 { | 86 { |
87 OwnPtr<LocaleWin> locale = LocaleWin::create(lcid, true /* defaultsForLo
cale */); | 87 std::unique_ptr<LocaleWin> locale = LocaleWin::create(lcid, true /* defa
ultsForLocale */); |
88 return locale->formatDateTime(getDateComponents(year, month, day)); | 88 return locale->formatDateTime(getDateComponents(year, month, day)); |
89 } | 89 } |
90 | 90 |
91 unsigned firstDayOfWeek(LCID lcid) | 91 unsigned firstDayOfWeek(LCID lcid) |
92 { | 92 { |
93 OwnPtr<LocaleWin> locale = LocaleWin::create(lcid, true /* defaultsForLo
cale */); | 93 std::unique_ptr<LocaleWin> locale = LocaleWin::create(lcid, true /* defa
ultsForLocale */); |
94 return locale->firstDayOfWeek(); | 94 return locale->firstDayOfWeek(); |
95 } | 95 } |
96 | 96 |
97 String monthLabel(LCID lcid, unsigned index) | 97 String monthLabel(LCID lcid, unsigned index) |
98 { | 98 { |
99 OwnPtr<LocaleWin> locale = LocaleWin::create(lcid, true /* defaultsForLo
cale */); | 99 std::unique_ptr<LocaleWin> locale = LocaleWin::create(lcid, true /* defa
ultsForLocale */); |
100 return locale->monthLabels()[index]; | 100 return locale->monthLabels()[index]; |
101 } | 101 } |
102 | 102 |
103 String weekDayShortLabel(LCID lcid, unsigned index) | 103 String weekDayShortLabel(LCID lcid, unsigned index) |
104 { | 104 { |
105 OwnPtr<LocaleWin> locale = LocaleWin::create(lcid, true /* defaultsForLo
cale */); | 105 std::unique_ptr<LocaleWin> locale = LocaleWin::create(lcid, true /* defa
ultsForLocale */); |
106 return locale->weekDayShortLabels()[index]; | 106 return locale->weekDayShortLabels()[index]; |
107 } | 107 } |
108 | 108 |
109 bool isRTL(LCID lcid) | 109 bool isRTL(LCID lcid) |
110 { | 110 { |
111 OwnPtr<LocaleWin> locale = LocaleWin::create(lcid, true /* defaultsForLo
cale */); | 111 std::unique_ptr<LocaleWin> locale = LocaleWin::create(lcid, true /* defa
ultsForLocale */); |
112 return locale->isRTL(); | 112 return locale->isRTL(); |
113 } | 113 } |
114 | 114 |
115 String monthFormat(LCID lcid) | 115 String monthFormat(LCID lcid) |
116 { | 116 { |
117 OwnPtr<LocaleWin> locale = LocaleWin::create(lcid, true /* defaultsForLo
cale */); | 117 std::unique_ptr<LocaleWin> locale = LocaleWin::create(lcid, true /* defa
ultsForLocale */); |
118 return locale->monthFormat(); | 118 return locale->monthFormat(); |
119 } | 119 } |
120 | 120 |
121 String timeFormat(LCID lcid) | 121 String timeFormat(LCID lcid) |
122 { | 122 { |
123 OwnPtr<LocaleWin> locale = LocaleWin::create(lcid, true /* defaultsForLo
cale */); | 123 std::unique_ptr<LocaleWin> locale = LocaleWin::create(lcid, true /* defa
ultsForLocale */); |
124 return locale->timeFormat(); | 124 return locale->timeFormat(); |
125 } | 125 } |
126 | 126 |
127 String shortTimeFormat(LCID lcid) | 127 String shortTimeFormat(LCID lcid) |
128 { | 128 { |
129 OwnPtr<LocaleWin> locale = LocaleWin::create(lcid, true /* defaultsForLo
cale */); | 129 std::unique_ptr<LocaleWin> locale = LocaleWin::create(lcid, true /* defa
ultsForLocale */); |
130 return locale->shortTimeFormat(); | 130 return locale->shortTimeFormat(); |
131 } | 131 } |
132 | 132 |
133 String shortMonthLabel(LCID lcid, unsigned index) | 133 String shortMonthLabel(LCID lcid, unsigned index) |
134 { | 134 { |
135 OwnPtr<LocaleWin> locale = LocaleWin::create(lcid, true /* defaultsForLo
cale */); | 135 std::unique_ptr<LocaleWin> locale = LocaleWin::create(lcid, true /* defa
ultsForLocale */); |
136 return locale->shortMonthLabels()[index]; | 136 return locale->shortMonthLabels()[index]; |
137 } | 137 } |
138 | 138 |
139 String timeAMPMLabel(LCID lcid, unsigned index) | 139 String timeAMPMLabel(LCID lcid, unsigned index) |
140 { | 140 { |
141 OwnPtr<LocaleWin> locale = LocaleWin::create(lcid, true /* defaultsForLo
cale */); | 141 std::unique_ptr<LocaleWin> locale = LocaleWin::create(lcid, true /* defa
ultsForLocale */); |
142 return locale->timeAMPMLabels()[index]; | 142 return locale->timeAMPMLabels()[index]; |
143 } | 143 } |
144 | 144 |
145 String decimalSeparator(LCID lcid) | 145 String decimalSeparator(LCID lcid) |
146 { | 146 { |
147 OwnPtr<LocaleWin> locale = LocaleWin::create(lcid, true /* defaultsForLo
cale */); | 147 std::unique_ptr<LocaleWin> locale = LocaleWin::create(lcid, true /* defa
ultsForLocale */); |
148 return locale->localizedDecimalSeparator(); | 148 return locale->localizedDecimalSeparator(); |
149 } | 149 } |
150 }; | 150 }; |
151 | 151 |
152 TEST_F(LocaleWinTest, formatDate) | 152 TEST_F(LocaleWinTest, formatDate) |
153 { | 153 { |
154 EXPECT_STREQ("04/27/2005", formatDate(EnglishUS, 2005, April, 27).utf8().dat
a()); | 154 EXPECT_STREQ("04/27/2005", formatDate(EnglishUS, 2005, April, 27).utf8().dat
a()); |
155 EXPECT_STREQ("27/04/2005", formatDate(FrenchFR, 2005, April, 27).utf8().data
()); | 155 EXPECT_STREQ("27/04/2005", formatDate(FrenchFR, 2005, April, 27).utf8().data
()); |
156 EXPECT_STREQ("2005/04/27", formatDate(JapaneseJP, 2005, April, 27).utf8().da
ta()); | 156 EXPECT_STREQ("2005/04/27", formatDate(JapaneseJP, 2005, April, 27).utf8().da
ta()); |
157 } | 157 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 } | 254 } |
255 | 255 |
256 TEST_F(LocaleWinTest, decimalSeparator) | 256 TEST_F(LocaleWinTest, decimalSeparator) |
257 { | 257 { |
258 EXPECT_STREQ(".", decimalSeparator(EnglishUS).utf8().data()); | 258 EXPECT_STREQ(".", decimalSeparator(EnglishUS).utf8().data()); |
259 EXPECT_STREQ(",", decimalSeparator(FrenchFR).utf8().data()); | 259 EXPECT_STREQ(",", decimalSeparator(FrenchFR).utf8().data()); |
260 } | 260 } |
261 | 261 |
262 static void testNumberIsReversible(LCID lcid, const char* original, const char*
shouldHave = 0) | 262 static void testNumberIsReversible(LCID lcid, const char* original, const char*
shouldHave = 0) |
263 { | 263 { |
264 OwnPtr<LocaleWin> locale = LocaleWin::create(lcid, true /* defaultsForLocale
*/); | 264 std::unique_ptr<LocaleWin> locale = LocaleWin::create(lcid, true /* defaults
ForLocale */); |
265 String localized = locale->convertToLocalizedNumber(original); | 265 String localized = locale->convertToLocalizedNumber(original); |
266 if (shouldHave) | 266 if (shouldHave) |
267 EXPECT_TRUE(localized.contains(shouldHave)); | 267 EXPECT_TRUE(localized.contains(shouldHave)); |
268 String converted = locale->convertFromLocalizedNumber(localized); | 268 String converted = locale->convertFromLocalizedNumber(localized); |
269 EXPECT_STREQ(original, converted.utf8().data()); | 269 EXPECT_STREQ(original, converted.utf8().data()); |
270 } | 270 } |
271 | 271 |
272 void testNumbers(LCID lcid) | 272 void testNumbers(LCID lcid) |
273 { | 273 { |
274 testNumberIsReversible(lcid, "123456789012345678901234567890"); | 274 testNumberIsReversible(lcid, "123456789012345678901234567890"); |
(...skipping 20 matching lines...) Expand all Loading... |
295 testNumbers(Spanish); | 295 testNumbers(Spanish); |
296 testNumbers(Persian); | 296 testNumbers(Persian); |
297 testNumbers(JapaneseJP); | 297 testNumbers(JapaneseJP); |
298 testNumbers(KoreanKR); | 298 testNumbers(KoreanKR); |
299 testNumbers(ChineseCN); | 299 testNumbers(ChineseCN); |
300 testNumbers(ChineseHK); | 300 testNumbers(ChineseHK); |
301 testNumbers(ChineseTW); | 301 testNumbers(ChineseTW); |
302 } | 302 } |
303 | 303 |
304 } // namespace blink | 304 } // namespace blink |
OLD | NEW |