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

Side by Side Diff: third_party/WebKit/Source/platform/text/LocaleICUTest.cpp

Issue 2050123002: Remove OwnPtr from Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: First attempt to land. Created 4 years, 6 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
OLDNEW
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 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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/LocaleICU.h" 31 #include "platform/text/LocaleICU.h"
32 32
33 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
34 #include "wtf/PassOwnPtr.h"
35 #include "wtf/text/StringBuilder.h" 34 #include "wtf/text/StringBuilder.h"
35 #include <memory>
36 #include <unicode/uvernum.h> 36 #include <unicode/uvernum.h>
37 37
38 namespace blink { 38 namespace blink {
39 39
40 class LocaleICUTest : public ::testing::Test { 40 class LocaleICUTest : public ::testing::Test {
41 public: 41 public:
42 // Labels class is used for printing results in EXPECT_EQ macro. 42 // Labels class is used for printing results in EXPECT_EQ macro.
43 class Labels { 43 class Labels {
44 public: 44 public:
45 Labels(const Vector<String> labels) 45 Labels(const Vector<String> labels)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 Labels labelsFromTwoElements(const String& element1, const String& element2) 82 Labels labelsFromTwoElements(const String& element1, const String& element2)
83 { 83 {
84 Vector<String> labels = Vector<String>(); 84 Vector<String> labels = Vector<String>();
85 labels.append(element1); 85 labels.append(element1);
86 labels.append(element2); 86 labels.append(element2);
87 return Labels(labels); 87 return Labels(labels);
88 } 88 }
89 89
90 String monthFormat(const char* localeString) 90 String monthFormat(const char* localeString)
91 { 91 {
92 OwnPtr<LocaleICU> locale = LocaleICU::create(localeString); 92 std::unique_ptr<LocaleICU> locale = LocaleICU::create(localeString);
93 return locale->monthFormat(); 93 return locale->monthFormat();
94 } 94 }
95 95
96 String localizedDateFormatText(const char* localeString) 96 String localizedDateFormatText(const char* localeString)
97 { 97 {
98 OwnPtr<LocaleICU> locale = LocaleICU::create(localeString); 98 std::unique_ptr<LocaleICU> locale = LocaleICU::create(localeString);
99 return locale->timeFormat(); 99 return locale->timeFormat();
100 } 100 }
101 101
102 String localizedShortDateFormatText(const char* localeString) 102 String localizedShortDateFormatText(const char* localeString)
103 { 103 {
104 OwnPtr<LocaleICU> locale = LocaleICU::create(localeString); 104 std::unique_ptr<LocaleICU> locale = LocaleICU::create(localeString);
105 return locale->shortTimeFormat(); 105 return locale->shortTimeFormat();
106 } 106 }
107 107
108 String shortMonthLabel(const char* localeString, unsigned index) 108 String shortMonthLabel(const char* localeString, unsigned index)
109 { 109 {
110 OwnPtr<LocaleICU> locale = LocaleICU::create(localeString); 110 std::unique_ptr<LocaleICU> locale = LocaleICU::create(localeString);
111 return locale->shortMonthLabels()[index]; 111 return locale->shortMonthLabels()[index];
112 } 112 }
113 113
114 String shortStandAloneMonthLabel(const char* localeString, unsigned index) 114 String shortStandAloneMonthLabel(const char* localeString, unsigned index)
115 { 115 {
116 OwnPtr<LocaleICU> locale = LocaleICU::create(localeString); 116 std::unique_ptr<LocaleICU> locale = LocaleICU::create(localeString);
117 return locale->shortStandAloneMonthLabels()[index]; 117 return locale->shortStandAloneMonthLabels()[index];
118 } 118 }
119 119
120 String standAloneMonthLabel(const char* localeString, unsigned index) 120 String standAloneMonthLabel(const char* localeString, unsigned index)
121 { 121 {
122 OwnPtr<LocaleICU> locale = LocaleICU::create(localeString); 122 std::unique_ptr<LocaleICU> locale = LocaleICU::create(localeString);
123 return locale->standAloneMonthLabels()[index]; 123 return locale->standAloneMonthLabels()[index];
124 } 124 }
125 125
126 Labels timeAMPMLabels(const char* localeString) 126 Labels timeAMPMLabels(const char* localeString)
127 { 127 {
128 OwnPtr<LocaleICU> locale = LocaleICU::create(localeString); 128 std::unique_ptr<LocaleICU> locale = LocaleICU::create(localeString);
129 return Labels(locale->timeAMPMLabels()); 129 return Labels(locale->timeAMPMLabels());
130 } 130 }
131 131
132 bool isRTL(const char* localeString) 132 bool isRTL(const char* localeString)
133 { 133 {
134 OwnPtr<LocaleICU> locale = LocaleICU::create(localeString); 134 std::unique_ptr<LocaleICU> locale = LocaleICU::create(localeString);
135 return locale->isRTL(); 135 return locale->isRTL();
136 } 136 }
137 }; 137 };
138 138
139 std::ostream& operator<<(std::ostream& os, const LocaleICUTest::Labels& labels) 139 std::ostream& operator<<(std::ostream& os, const LocaleICUTest::Labels& labels)
140 { 140 {
141 return os << labels.toString().utf8().data(); 141 return os << labels.toString().utf8().data();
142 } 142 }
143 143
144 TEST_F(LocaleICUTest, isRTL) 144 TEST_F(LocaleICUTest, isRTL)
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 EXPECT_EQ(labelsFromTwoElements("AM", "PM"), timeAMPMLabels("en_US")); 230 EXPECT_EQ(labelsFromTwoElements("AM", "PM"), timeAMPMLabels("en_US"));
231 EXPECT_EQ(labelsFromTwoElements("AM", "PM"), timeAMPMLabels("fr")); 231 EXPECT_EQ(labelsFromTwoElements("AM", "PM"), timeAMPMLabels("fr"));
232 232
233 UChar jaAM[3] = { 0x5348, 0x524d, 0 }; 233 UChar jaAM[3] = { 0x5348, 0x524d, 0 };
234 UChar jaPM[3] = { 0x5348, 0x5F8C, 0 }; 234 UChar jaPM[3] = { 0x5348, 0x5F8C, 0 };
235 EXPECT_EQ(labelsFromTwoElements(String(jaAM), String(jaPM)), timeAMPMLabels( "ja")); 235 EXPECT_EQ(labelsFromTwoElements(String(jaAM), String(jaPM)), timeAMPMLabels( "ja"));
236 } 236 }
237 237
238 static String testDecimalSeparator(const AtomicString& localeIdentifier) 238 static String testDecimalSeparator(const AtomicString& localeIdentifier)
239 { 239 {
240 OwnPtr<Locale> locale = Locale::create(localeIdentifier); 240 std::unique_ptr<Locale> locale = Locale::create(localeIdentifier);
241 return locale->localizedDecimalSeparator(); 241 return locale->localizedDecimalSeparator();
242 } 242 }
243 243
244 TEST_F(LocaleICUTest, localizedDecimalSeparator) 244 TEST_F(LocaleICUTest, localizedDecimalSeparator)
245 { 245 {
246 EXPECT_EQ(String("."), testDecimalSeparator("en_US")); 246 EXPECT_EQ(String("."), testDecimalSeparator("en_US"));
247 EXPECT_EQ(String(","), testDecimalSeparator("fr")); 247 EXPECT_EQ(String(","), testDecimalSeparator("fr"));
248 } 248 }
249 249
250 void testNumberIsReversible(const AtomicString& localeIdentifier, const char* or iginal, const char* shouldHave = 0) 250 void testNumberIsReversible(const AtomicString& localeIdentifier, const char* or iginal, const char* shouldHave = 0)
251 { 251 {
252 OwnPtr<Locale> locale = Locale::create(localeIdentifier); 252 std::unique_ptr<Locale> locale = Locale::create(localeIdentifier);
253 String localized = locale->convertToLocalizedNumber(original); 253 String localized = locale->convertToLocalizedNumber(original);
254 if (shouldHave) 254 if (shouldHave)
255 EXPECT_TRUE(localized.contains(shouldHave)); 255 EXPECT_TRUE(localized.contains(shouldHave));
256 String converted = locale->convertFromLocalizedNumber(localized); 256 String converted = locale->convertFromLocalizedNumber(localized);
257 EXPECT_EQ(original, converted); 257 EXPECT_EQ(original, converted);
258 } 258 }
259 259
260 void testNumbers(const char* localeString) 260 void testNumbers(const char* localeString)
261 { 261 {
262 testNumberIsReversible(localeString, "123456789012345678901234567890"); 262 testNumberIsReversible(localeString, "123456789012345678901234567890");
(...skipping 22 matching lines...) Expand all
285 testNumbers("de_DE"); 285 testNumbers("de_DE");
286 testNumbers("es_ES"); 286 testNumbers("es_ES");
287 testNumbers("ja_JP"); 287 testNumbers("ja_JP");
288 testNumbers("ko_KR"); 288 testNumbers("ko_KR");
289 testNumbers("zh_CN"); 289 testNumbers("zh_CN");
290 testNumbers("zh_HK"); 290 testNumbers("zh_HK");
291 testNumbers("zh_TW"); 291 testNumbers("zh_TW");
292 } 292 }
293 293
294 } // namespace blink 294 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/text/LocaleICU.cpp ('k') | third_party/WebKit/Source/platform/text/LocaleMac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698