OLD | NEW |
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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 7 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
8 #include <cstdlib> | 8 #include <cstdlib> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 l10n_util::SortStringsUsingMethod("en-US", | 296 l10n_util::SortStringsUsingMethod("en-US", |
297 &strings, | 297 &strings, |
298 &StringWrapper::string); | 298 &StringWrapper::string); |
299 ASSERT_TRUE(UTF8ToUTF16("a") == strings[0]->string()); | 299 ASSERT_TRUE(UTF8ToUTF16("a") == strings[0]->string()); |
300 ASSERT_TRUE(UTF8ToUTF16("b") == strings[1]->string()); | 300 ASSERT_TRUE(UTF8ToUTF16("b") == strings[1]->string()); |
301 ASSERT_TRUE(UTF8ToUTF16("C") == strings[2]->string()); | 301 ASSERT_TRUE(UTF8ToUTF16("C") == strings[2]->string()); |
302 ASSERT_TRUE(UTF8ToUTF16("d") == strings[3]->string()); | 302 ASSERT_TRUE(UTF8ToUTF16("d") == strings[3]->string()); |
303 STLDeleteElements(&strings); | 303 STLDeleteElements(&strings); |
304 } | 304 } |
305 | 305 |
306 TEST_F(L10nUtilTest, LocaleDisplayName) { | 306 TEST_F(L10nUtilTest, GetDisplayNameForLocale) { |
307 // TODO(jungshik): Make this test more extensive. | 307 // TODO(jungshik): Make this test more extensive. |
308 // Test zh-CN and zh-TW are treated as zh-Hans and zh-Hant. | 308 // Test zh-CN and zh-TW are treated as zh-Hans and zh-Hant. |
309 string16 result = l10n_util::GetDisplayNameForLocale("zh-CN", "en", false); | 309 string16 result = l10n_util::GetDisplayNameForLocale("zh-CN", "en", false); |
310 EXPECT_EQ(ASCIIToUTF16("Chinese (Simplified Han)"), result); | 310 EXPECT_EQ(ASCIIToUTF16("Chinese (Simplified Han)"), result); |
311 | 311 |
312 result = l10n_util::GetDisplayNameForLocale("zh-TW", "en", false); | 312 result = l10n_util::GetDisplayNameForLocale("zh-TW", "en", false); |
313 EXPECT_EQ(ASCIIToUTF16("Chinese (Traditional Han)"), result); | 313 EXPECT_EQ(ASCIIToUTF16("Chinese (Traditional Han)"), result); |
314 | 314 |
315 result = l10n_util::GetDisplayNameForLocale("pt-BR", "en", false); | 315 result = l10n_util::GetDisplayNameForLocale("pt-BR", "en", false); |
316 EXPECT_EQ(ASCIIToUTF16("Portuguese (Brazil)"), result); | 316 EXPECT_EQ(ASCIIToUTF16("Portuguese (Brazil)"), result); |
317 | 317 |
318 result = l10n_util::GetDisplayNameForLocale("es-419", "en", false); | 318 result = l10n_util::GetDisplayNameForLocale("es-419", "en", false); |
319 EXPECT_EQ(ASCIIToUTF16("Spanish (Latin America)"), result); | 319 EXPECT_EQ(ASCIIToUTF16("Spanish (Latin America)"), result); |
320 | 320 |
| 321 result = l10n_util::GetDisplayNameForLocale("-BR", "en", false); |
| 322 EXPECT_EQ(ASCIIToUTF16("Brazil"), result); |
| 323 |
| 324 result = l10n_util::GetDisplayNameForLocale("xyz-xyz", "en", false); |
| 325 EXPECT_EQ(ASCIIToUTF16("xyz (XYZ)"), result); |
| 326 |
321 // ToUpper and ToLower should work with embedded NULLs. | 327 // ToUpper and ToLower should work with embedded NULLs. |
322 const size_t length_with_null = 4; | 328 const size_t length_with_null = 4; |
323 char16 buf_with_null[length_with_null] = { 0, 'a', 0, 'b' }; | 329 char16 buf_with_null[length_with_null] = { 0, 'a', 0, 'b' }; |
324 string16 string16_with_null(buf_with_null, length_with_null); | 330 string16 string16_with_null(buf_with_null, length_with_null); |
325 | 331 |
326 string16 upper_with_null = base::i18n::ToUpper(string16_with_null); | 332 string16 upper_with_null = base::i18n::ToUpper(string16_with_null); |
327 ASSERT_EQ(length_with_null, upper_with_null.size()); | 333 ASSERT_EQ(length_with_null, upper_with_null.size()); |
328 EXPECT_TRUE(upper_with_null[0] == 0 && upper_with_null[1] == 'A' && | 334 EXPECT_TRUE(upper_with_null[0] == 0 && upper_with_null[1] == 'A' && |
329 upper_with_null[2] == 0 && upper_with_null[3] == 'B'); | 335 upper_with_null[2] == 0 && upper_with_null[3] == 'B'); |
330 | 336 |
331 string16 lower_with_null = base::i18n::ToLower(upper_with_null); | 337 string16 lower_with_null = base::i18n::ToLower(upper_with_null); |
332 ASSERT_EQ(length_with_null, upper_with_null.size()); | 338 ASSERT_EQ(length_with_null, upper_with_null.size()); |
333 EXPECT_TRUE(lower_with_null[0] == 0 && lower_with_null[1] == 'a' && | 339 EXPECT_TRUE(lower_with_null[0] == 0 && lower_with_null[1] == 'a' && |
334 lower_with_null[2] == 0 && lower_with_null[3] == 'b'); | 340 lower_with_null[2] == 0 && lower_with_null[3] == 'b'); |
335 } | 341 } |
336 | 342 |
| 343 TEST_F(L10nUtilTest, GetDisplayNameForCountry) { |
| 344 string16 result = l10n_util::GetDisplayNameForCountry("BR", "en"); |
| 345 EXPECT_EQ(ASCIIToUTF16("Brazil"), result); |
| 346 |
| 347 result = l10n_util::GetDisplayNameForCountry("419", "en"); |
| 348 EXPECT_EQ(ASCIIToUTF16("Latin America"), result); |
| 349 |
| 350 result = l10n_util::GetDisplayNameForCountry("xyz", "en"); |
| 351 EXPECT_EQ(ASCIIToUTF16("XYZ"), result); |
| 352 } |
| 353 |
337 TEST_F(L10nUtilTest, GetParentLocales) { | 354 TEST_F(L10nUtilTest, GetParentLocales) { |
338 std::vector<std::string> locales; | 355 std::vector<std::string> locales; |
339 const std::string top_locale("sr_Cyrl_RS"); | 356 const std::string top_locale("sr_Cyrl_RS"); |
340 l10n_util::GetParentLocales(top_locale, &locales); | 357 l10n_util::GetParentLocales(top_locale, &locales); |
341 | 358 |
342 ASSERT_EQ(3U, locales.size()); | 359 ASSERT_EQ(3U, locales.size()); |
343 EXPECT_EQ("sr_Cyrl_RS", locales[0]); | 360 EXPECT_EQ("sr_Cyrl_RS", locales[0]); |
344 EXPECT_EQ("sr_Cyrl", locales[1]); | 361 EXPECT_EQ("sr_Cyrl", locales[1]); |
345 EXPECT_EQ("sr", locales[2]); | 362 EXPECT_EQ("sr", locales[2]); |
346 } | 363 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("Latin")); | 409 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("Latin")); |
393 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("German")); | 410 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("German")); |
394 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("pt--BR")); | 411 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("pt--BR")); |
395 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("sl-macedonia")); | 412 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("sl-macedonia")); |
396 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("@")); | 413 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("@")); |
397 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@")); | 414 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@")); |
398 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x")); | 415 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x")); |
399 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x=")); | 416 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x=")); |
400 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@=y")); | 417 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@=y")); |
401 } | 418 } |
OLD | NEW |