OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 19 matching lines...) Expand all Loading... |
30 #endif | 30 #endif |
31 | 31 |
32 #if !defined(OS_MACOSX) | 32 #if !defined(OS_MACOSX) |
33 #include "ui/base/test/data/resource.h" | 33 #include "ui/base/test/data/resource.h" |
34 #endif | 34 #endif |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 class StringWrapper { | 38 class StringWrapper { |
39 public: | 39 public: |
40 explicit StringWrapper(const string16& string) : string_(string) {} | 40 explicit StringWrapper(const base::string16& string) : string_(string) {} |
41 const string16& string() const { return string_; } | 41 const base::string16& string() const { return string_; } |
42 | 42 |
43 private: | 43 private: |
44 string16 string_; | 44 base::string16 string_; |
45 | 45 |
46 DISALLOW_COPY_AND_ASSIGN(StringWrapper); | 46 DISALLOW_COPY_AND_ASSIGN(StringWrapper); |
47 }; | 47 }; |
48 | 48 |
49 } // namespace | 49 } // namespace |
50 | 50 |
51 class L10nUtilTest : public PlatformTest { | 51 class L10nUtilTest : public PlatformTest { |
52 }; | 52 }; |
53 | 53 |
54 #if defined(OS_WIN) | 54 #if defined(OS_WIN) |
55 // TODO(beng): disabled until app strings move to app. | 55 // TODO(beng): disabled until app strings move to app. |
56 TEST_F(L10nUtilTest, DISABLED_GetString) { | 56 TEST_F(L10nUtilTest, DISABLED_GetString) { |
57 std::string s = l10n_util::GetStringUTF8(IDS_SIMPLE); | 57 std::string s = l10n_util::GetStringUTF8(IDS_SIMPLE); |
58 EXPECT_EQ(std::string("Hello World!"), s); | 58 EXPECT_EQ(std::string("Hello World!"), s); |
59 | 59 |
60 s = l10n_util::GetStringFUTF8(IDS_PLACEHOLDERS, | 60 s = l10n_util::GetStringFUTF8(IDS_PLACEHOLDERS, |
61 UTF8ToUTF16("chrome"), | 61 UTF8ToUTF16("chrome"), |
62 UTF8ToUTF16("10")); | 62 UTF8ToUTF16("10")); |
63 EXPECT_EQ(std::string("Hello, chrome. Your number is 10."), s); | 63 EXPECT_EQ(std::string("Hello, chrome. Your number is 10."), s); |
64 | 64 |
65 string16 s16 = l10n_util::GetStringFUTF16Int(IDS_PLACEHOLDERS_2, 20); | 65 base::string16 s16 = l10n_util::GetStringFUTF16Int(IDS_PLACEHOLDERS_2, 20); |
66 EXPECT_EQ(UTF8ToUTF16("You owe me $20."), s16); | 66 EXPECT_EQ(UTF8ToUTF16("You owe me $20."), s16); |
67 } | 67 } |
68 #endif // defined(OS_WIN) | 68 #endif // defined(OS_WIN) |
69 | 69 |
70 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 70 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
71 // On Mac, we are disabling this test because GetApplicationLocale() as an | 71 // On Mac, we are disabling this test because GetApplicationLocale() as an |
72 // API isn't something that we'll easily be able to unit test in this manner. | 72 // API isn't something that we'll easily be able to unit test in this manner. |
73 // The meaning of that API, on the Mac, is "the locale used by Cocoa's main | 73 // The meaning of that API, on the Mac, is "the locale used by Cocoa's main |
74 // nib file", which clearly can't be stubbed by a test app that doesn't use | 74 // nib file", which clearly can't be stubbed by a test app that doesn't use |
75 // Cocoa. | 75 // Cocoa. |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 } | 319 } |
320 | 320 |
321 /** | 321 /** |
322 * Helper method for validating strings that require direcitonal markup. | 322 * Helper method for validating strings that require direcitonal markup. |
323 * Checks that parentheses are enclosed in appropriate direcitonal markers. | 323 * Checks that parentheses are enclosed in appropriate direcitonal markers. |
324 */ | 324 */ |
325 void CheckUiDisplayNameForLocale(const std::string& locale, | 325 void CheckUiDisplayNameForLocale(const std::string& locale, |
326 const std::string& display_locale, | 326 const std::string& display_locale, |
327 bool is_rtl) { | 327 bool is_rtl) { |
328 EXPECT_EQ(true, base::i18n::IsRTL()); | 328 EXPECT_EQ(true, base::i18n::IsRTL()); |
329 string16 result = l10n_util::GetDisplayNameForLocale(locale, | 329 base::string16 result = l10n_util::GetDisplayNameForLocale(locale, |
330 display_locale, | 330 display_locale, |
331 /* is_for_ui */ true); | 331 /* is_for_ui */ true); |
332 | 332 |
333 bool rtl_direction = true; | 333 bool rtl_direction = true; |
334 for (size_t i = 0; i < result.length() - 1; i++) { | 334 for (size_t i = 0; i < result.length() - 1; i++) { |
335 char16 ch = result.at(i); | 335 char16 ch = result.at(i); |
336 switch (ch) { | 336 switch (ch) { |
337 case base::i18n::kLeftToRightMark: | 337 case base::i18n::kLeftToRightMark: |
338 case base::i18n::kLeftToRightEmbeddingMark: | 338 case base::i18n::kLeftToRightEmbeddingMark: |
339 rtl_direction = false; | 339 rtl_direction = false; |
340 break; | 340 break; |
341 case base::i18n::kRightToLeftMark: | 341 case base::i18n::kRightToLeftMark: |
342 case base::i18n::kRightToLeftEmbeddingMark: | 342 case base::i18n::kRightToLeftEmbeddingMark: |
343 rtl_direction = true; | 343 rtl_direction = true; |
344 break; | 344 break; |
345 case '(': | 345 case '(': |
346 case ')': | 346 case ')': |
347 EXPECT_EQ(is_rtl, rtl_direction); | 347 EXPECT_EQ(is_rtl, rtl_direction); |
348 } | 348 } |
349 } | 349 } |
350 } | 350 } |
351 | 351 |
352 TEST_F(L10nUtilTest, GetDisplayNameForLocale) { | 352 TEST_F(L10nUtilTest, GetDisplayNameForLocale) { |
353 // TODO(jungshik): Make this test more extensive. | 353 // TODO(jungshik): Make this test more extensive. |
354 // Test zh-CN and zh-TW are treated as zh-Hans and zh-Hant. | 354 // Test zh-CN and zh-TW are treated as zh-Hans and zh-Hant. |
355 string16 result = l10n_util::GetDisplayNameForLocale("zh-CN", "en", false); | 355 base::string16 result = |
| 356 l10n_util::GetDisplayNameForLocale("zh-CN", "en", false); |
356 EXPECT_EQ(ASCIIToUTF16("Chinese (Simplified Han)"), result); | 357 EXPECT_EQ(ASCIIToUTF16("Chinese (Simplified Han)"), result); |
357 | 358 |
358 result = l10n_util::GetDisplayNameForLocale("zh-TW", "en", false); | 359 result = l10n_util::GetDisplayNameForLocale("zh-TW", "en", false); |
359 EXPECT_EQ(ASCIIToUTF16("Chinese (Traditional Han)"), result); | 360 EXPECT_EQ(ASCIIToUTF16("Chinese (Traditional Han)"), result); |
360 | 361 |
361 result = l10n_util::GetDisplayNameForLocale("pt-BR", "en", false); | 362 result = l10n_util::GetDisplayNameForLocale("pt-BR", "en", false); |
362 EXPECT_EQ(ASCIIToUTF16("Portuguese (Brazil)"), result); | 363 EXPECT_EQ(ASCIIToUTF16("Portuguese (Brazil)"), result); |
363 | 364 |
364 result = l10n_util::GetDisplayNameForLocale("es-419", "en", false); | 365 result = l10n_util::GetDisplayNameForLocale("es-419", "en", false); |
365 EXPECT_EQ(ASCIIToUTF16("Spanish (Latin America)"), result); | 366 EXPECT_EQ(ASCIIToUTF16("Spanish (Latin America)"), result); |
(...skipping 15 matching lines...) Expand all Loading... |
381 CheckUiDisplayNameForLocale("en-US", "en", false); | 382 CheckUiDisplayNameForLocale("en-US", "en", false); |
382 CheckUiDisplayNameForLocale("en-US", "he", true); | 383 CheckUiDisplayNameForLocale("en-US", "he", true); |
383 | 384 |
384 // Clean up. | 385 // Clean up. |
385 base::i18n::SetICUDefaultLocale(original_locale); | 386 base::i18n::SetICUDefaultLocale(original_locale); |
386 #endif | 387 #endif |
387 | 388 |
388 // ToUpper and ToLower should work with embedded NULLs. | 389 // ToUpper and ToLower should work with embedded NULLs. |
389 const size_t length_with_null = 4; | 390 const size_t length_with_null = 4; |
390 char16 buf_with_null[length_with_null] = { 0, 'a', 0, 'b' }; | 391 char16 buf_with_null[length_with_null] = { 0, 'a', 0, 'b' }; |
391 string16 string16_with_null(buf_with_null, length_with_null); | 392 base::string16 string16_with_null(buf_with_null, length_with_null); |
392 | 393 |
393 string16 upper_with_null = base::i18n::ToUpper(string16_with_null); | 394 base::string16 upper_with_null = base::i18n::ToUpper(string16_with_null); |
394 ASSERT_EQ(length_with_null, upper_with_null.size()); | 395 ASSERT_EQ(length_with_null, upper_with_null.size()); |
395 EXPECT_TRUE(upper_with_null[0] == 0 && upper_with_null[1] == 'A' && | 396 EXPECT_TRUE(upper_with_null[0] == 0 && upper_with_null[1] == 'A' && |
396 upper_with_null[2] == 0 && upper_with_null[3] == 'B'); | 397 upper_with_null[2] == 0 && upper_with_null[3] == 'B'); |
397 | 398 |
398 string16 lower_with_null = base::i18n::ToLower(upper_with_null); | 399 base::string16 lower_with_null = base::i18n::ToLower(upper_with_null); |
399 ASSERT_EQ(length_with_null, upper_with_null.size()); | 400 ASSERT_EQ(length_with_null, upper_with_null.size()); |
400 EXPECT_TRUE(lower_with_null[0] == 0 && lower_with_null[1] == 'a' && | 401 EXPECT_TRUE(lower_with_null[0] == 0 && lower_with_null[1] == 'a' && |
401 lower_with_null[2] == 0 && lower_with_null[3] == 'b'); | 402 lower_with_null[2] == 0 && lower_with_null[3] == 'b'); |
402 } | 403 } |
403 | 404 |
404 TEST_F(L10nUtilTest, GetDisplayNameForCountry) { | 405 TEST_F(L10nUtilTest, GetDisplayNameForCountry) { |
405 string16 result = l10n_util::GetDisplayNameForCountry("BR", "en"); | 406 base::string16 result = l10n_util::GetDisplayNameForCountry("BR", "en"); |
406 EXPECT_EQ(ASCIIToUTF16("Brazil"), result); | 407 EXPECT_EQ(ASCIIToUTF16("Brazil"), result); |
407 | 408 |
408 result = l10n_util::GetDisplayNameForCountry("419", "en"); | 409 result = l10n_util::GetDisplayNameForCountry("419", "en"); |
409 EXPECT_EQ(ASCIIToUTF16("Latin America"), result); | 410 EXPECT_EQ(ASCIIToUTF16("Latin America"), result); |
410 | 411 |
411 result = l10n_util::GetDisplayNameForCountry("xyz", "en"); | 412 result = l10n_util::GetDisplayNameForCountry("xyz", "en"); |
412 EXPECT_EQ(ASCIIToUTF16("XYZ"), result); | 413 EXPECT_EQ(ASCIIToUTF16("XYZ"), result); |
413 } | 414 } |
414 | 415 |
415 TEST_F(L10nUtilTest, GetParentLocales) { | 416 TEST_F(L10nUtilTest, GetParentLocales) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("Latin")); | 471 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("Latin")); |
471 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("German")); | 472 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("German")); |
472 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("pt--BR")); | 473 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("pt--BR")); |
473 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("sl-macedonia")); | 474 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("sl-macedonia")); |
474 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("@")); | 475 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("@")); |
475 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@")); | 476 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@")); |
476 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x")); | 477 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x")); |
477 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x=")); | 478 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x=")); |
478 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@=y")); | 479 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@=y")); |
479 } | 480 } |
OLD | NEW |