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

Side by Side Diff: chrome/common/l10n_util_unittest.cc

Issue 18863: Review request: fix issue 6099 -- bad display of multi-line English message in pop ups (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/common/l10n_util.cc ('k') | chrome/views/label.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 SetICUDefaultLocale(L"he"); 153 SetICUDefaultLocale(L"he");
154 EXPECT_EQ(L"en-US", l10n_util::GetApplicationLocale(L"en")); 154 EXPECT_EQ(L"en-US", l10n_util::GetApplicationLocale(L"en"));
155 155
156 // Clean up. 156 // Clean up.
157 PathService::Override(chrome::DIR_LOCALES, orig_locale_dir); 157 PathService::Override(chrome::DIR_LOCALES, orig_locale_dir);
158 file_util::Delete(new_locale_dir, true); 158 file_util::Delete(new_locale_dir, true);
159 UErrorCode error_code = U_ZERO_ERROR; 159 UErrorCode error_code = U_ZERO_ERROR;
160 Locale::setDefault(locale, error_code); 160 Locale::setDefault(locale, error_code);
161 } 161 }
162 162
163 TEST_F(L10nUtilTest, GetFirstStrongCharacterDirection) {
164 // Test pure LTR string.
165 std::wstring string(L"foo bar");
166 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT,
167 l10n_util::GetFirstStrongCharacterDirection(string));
168
169 // Test bidi string in which the first character with strong directionality
170 // is a character with type L.
171 string.assign(L"foo \x05d0 bar");
172 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT,
173 l10n_util::GetFirstStrongCharacterDirection(string));
174
175 // Test bidi string in which the first character with strong directionality
176 // is a character with type R.
177 string.assign(L"\x05d0 foo bar");
178 EXPECT_EQ(l10n_util::RIGHT_TO_LEFT,
179 l10n_util::GetFirstStrongCharacterDirection(string));
180
181 // Test bidi string which starts with a character with weak directionality
182 // and in which the first character with strong directionality is a character
183 // with type L.
184 string.assign(L"!foo \x05d0 bar");
185 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT,
186 l10n_util::GetFirstStrongCharacterDirection(string));
187
188 // Test bidi string which starts with a character with weak directionality
189 // and in which the first character with strong directionality is a character
190 // with type R.
191 string.assign(L",\x05d0 foo bar");
192 EXPECT_EQ(l10n_util::RIGHT_TO_LEFT,
193 l10n_util::GetFirstStrongCharacterDirection(string));
194
195 // Test bidi string in which the first character with strong directionality
196 // is a character with type LRE.
197 string.assign(L"\x202a \x05d0 foo bar");
198 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT,
199 l10n_util::GetFirstStrongCharacterDirection(string));
200
201 // Test bidi string in which the first character with strong directionality
202 // is a character with type LRO.
203 string.assign(L"\x202d \x05d0 foo bar");
204 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT,
205 l10n_util::GetFirstStrongCharacterDirection(string));
206
207 // Test bidi string in which the first character with strong directionality
208 // is a character with type RLE.
209 string.assign(L"\x202b foo \x05d0 bar");
210 EXPECT_EQ(l10n_util::RIGHT_TO_LEFT,
211 l10n_util::GetFirstStrongCharacterDirection(string));
212
213 // Test bidi string in which the first character with strong directionality
214 // is a character with type RLO.
215 string.assign(L"\x202e foo \x05d0 bar");
216 EXPECT_EQ(l10n_util::RIGHT_TO_LEFT,
217 l10n_util::GetFirstStrongCharacterDirection(string));
218
219 // Test bidi string in which the first character with strong directionality
220 // is a character with type AL.
221 string.assign(L"\x0622 foo \x05d0 bar");
222 EXPECT_EQ(l10n_util::RIGHT_TO_LEFT,
223 l10n_util::GetFirstStrongCharacterDirection(string));
224
225 // Test a string without strong directionality characters.
226 string.assign(L",!.{}");
227 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT,
228 l10n_util::GetFirstStrongCharacterDirection(string));
229
230 // Test empty string.
231 string.assign(L"");
232 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT,
233 l10n_util::GetFirstStrongCharacterDirection(string));
234
235 // Test characters in non-BMP (e.g. Phoenician letters. Please refer to
236 // http://demo.icu-project.org/icu-bin/ubrowse?scr=151&b=10910 for more
237 // information).
238 #if defined(WCHAR_T_IS_UTF32)
239 string.assign(L" ! \x10910" L"abc 123");
240 #elif defined(WCHAR_T_IS_UTF16)
241 string.assign(L" ! \xd802\xdd10" L"abc 123");
242 #else
243 #error wchar_t should be either UTF-16 or UTF-32
244 #endif
245 EXPECT_EQ(l10n_util::RIGHT_TO_LEFT,
246 l10n_util::GetFirstStrongCharacterDirection(string));
247
248 #if defined(WCHAR_T_IS_UTF32)
249 string.assign(L" ! \x10401" L"abc 123");
250 #elif defined(WCHAR_T_IS_UTF16)
251 string.assign(L" ! \xd801\xdc01" L"abc 123");
252 #else
253 #error wchar_t should be either UTF-16 or UTF-32
254 #endif
255 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT,
256 l10n_util::GetFirstStrongCharacterDirection(string));
257 }
258
163 typedef struct { 259 typedef struct {
164 std::wstring path; 260 std::wstring path;
165 std::wstring wrapped_path; 261 std::wstring wrapped_path;
166 } PathAndWrappedPath; 262 } PathAndWrappedPath;
167 263
168 TEST_F(L10nUtilTest, WrapPathWithLTRFormatting) { 264 TEST_F(L10nUtilTest, WrapPathWithLTRFormatting) {
169 std::wstring kSeparator; 265 std::wstring kSeparator;
170 kSeparator.push_back(static_cast<wchar_t>(FilePath::kSeparators[0])); 266 kSeparator.push_back(static_cast<wchar_t>(FilePath::kSeparators[0]));
171 const PathAndWrappedPath test_data[] = { 267 const PathAndWrappedPath test_data[] = {
172 // Test common path, such as "c:\foo\bar". 268 // Test common path, such as "c:\foo\bar".
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 for (unsigned int i = 0; i < arraysize(test_data); ++i) { 329 for (unsigned int i = 0; i < arraysize(test_data); ++i) {
234 string16 localized_file_path_string; 330 string16 localized_file_path_string;
235 FilePath path = FilePath::FromWStringHack(test_data[i].path); 331 FilePath path = FilePath::FromWStringHack(test_data[i].path);
236 l10n_util::WrapPathWithLTRFormatting(path, &localized_file_path_string); 332 l10n_util::WrapPathWithLTRFormatting(path, &localized_file_path_string);
237 std::wstring wrapped_path = UTF16ToWide(localized_file_path_string); 333 std::wstring wrapped_path = UTF16ToWide(localized_file_path_string);
238 EXPECT_EQ(wrapped_path, test_data[i].wrapped_path); 334 EXPECT_EQ(wrapped_path, test_data[i].wrapped_path);
239 } 335 }
240 } 336 }
241 } 337 }
242 338
OLDNEW
« no previous file with comments | « chrome/common/l10n_util.cc ('k') | chrome/views/label.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698