OLD | NEW |
1 // Copyright (c) 2012 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 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
(...skipping 284 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, GetDisplayNameForLocale) { | 306 TEST_F(L10nUtilTest, LocaleDisplayName) { |
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 | |
327 // ToUpper and ToLower should work with embedded NULLs. | 321 // ToUpper and ToLower should work with embedded NULLs. |
328 const size_t length_with_null = 4; | 322 const size_t length_with_null = 4; |
329 char16 buf_with_null[length_with_null] = { 0, 'a', 0, 'b' }; | 323 char16 buf_with_null[length_with_null] = { 0, 'a', 0, 'b' }; |
330 string16 string16_with_null(buf_with_null, length_with_null); | 324 string16 string16_with_null(buf_with_null, length_with_null); |
331 | 325 |
332 string16 upper_with_null = base::i18n::ToUpper(string16_with_null); | 326 string16 upper_with_null = base::i18n::ToUpper(string16_with_null); |
333 ASSERT_EQ(length_with_null, upper_with_null.size()); | 327 ASSERT_EQ(length_with_null, upper_with_null.size()); |
334 EXPECT_TRUE(upper_with_null[0] == 0 && upper_with_null[1] == 'A' && | 328 EXPECT_TRUE(upper_with_null[0] == 0 && upper_with_null[1] == 'A' && |
335 upper_with_null[2] == 0 && upper_with_null[3] == 'B'); | 329 upper_with_null[2] == 0 && upper_with_null[3] == 'B'); |
336 | 330 |
337 string16 lower_with_null = base::i18n::ToLower(upper_with_null); | 331 string16 lower_with_null = base::i18n::ToLower(upper_with_null); |
338 ASSERT_EQ(length_with_null, upper_with_null.size()); | 332 ASSERT_EQ(length_with_null, upper_with_null.size()); |
339 EXPECT_TRUE(lower_with_null[0] == 0 && lower_with_null[1] == 'a' && | 333 EXPECT_TRUE(lower_with_null[0] == 0 && lower_with_null[1] == 'a' && |
340 lower_with_null[2] == 0 && lower_with_null[3] == 'b'); | 334 lower_with_null[2] == 0 && lower_with_null[3] == 'b'); |
341 } | 335 } |
342 | 336 |
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 | |
354 TEST_F(L10nUtilTest, GetParentLocales) { | 337 TEST_F(L10nUtilTest, GetParentLocales) { |
355 std::vector<std::string> locales; | 338 std::vector<std::string> locales; |
356 const std::string top_locale("sr_Cyrl_RS"); | 339 const std::string top_locale("sr_Cyrl_RS"); |
357 l10n_util::GetParentLocales(top_locale, &locales); | 340 l10n_util::GetParentLocales(top_locale, &locales); |
358 | 341 |
359 ASSERT_EQ(3U, locales.size()); | 342 ASSERT_EQ(3U, locales.size()); |
360 EXPECT_EQ("sr_Cyrl_RS", locales[0]); | 343 EXPECT_EQ("sr_Cyrl_RS", locales[0]); |
361 EXPECT_EQ("sr_Cyrl", locales[1]); | 344 EXPECT_EQ("sr_Cyrl", locales[1]); |
362 EXPECT_EQ("sr", locales[2]); | 345 EXPECT_EQ("sr", locales[2]); |
363 } | 346 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("Latin")); | 392 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("Latin")); |
410 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("German")); | 393 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("German")); |
411 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("pt--BR")); | 394 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("pt--BR")); |
412 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("sl-macedonia")); | 395 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("sl-macedonia")); |
413 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("@")); | 396 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("@")); |
414 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@")); | 397 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@")); |
415 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x")); | 398 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x")); |
416 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x=")); | 399 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x=")); |
417 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@=y")); | 400 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@=y")); |
418 } | 401 } |
OLD | NEW |