| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 s = l10n_util::GetStringFUTF8(IDS_PLACEHOLDERS, | 58 s = l10n_util::GetStringFUTF8(IDS_PLACEHOLDERS, |
| 59 UTF8ToUTF16("chrome"), | 59 UTF8ToUTF16("chrome"), |
| 60 UTF8ToUTF16("10")); | 60 UTF8ToUTF16("10")); |
| 61 EXPECT_EQ(std::string("Hello, chrome. Your number is 10."), s); | 61 EXPECT_EQ(std::string("Hello, chrome. Your number is 10."), s); |
| 62 | 62 |
| 63 string16 s16 = l10n_util::GetStringFUTF16Int(IDS_PLACEHOLDERS_2, 20); | 63 string16 s16 = l10n_util::GetStringFUTF16Int(IDS_PLACEHOLDERS_2, 20); |
| 64 EXPECT_EQ(UTF8ToUTF16("You owe me $20."), s16); | 64 EXPECT_EQ(UTF8ToUTF16("You owe me $20."), s16); |
| 65 } | 65 } |
| 66 #endif // defined(OS_WIN) | 66 #endif // defined(OS_WIN) |
| 67 | 67 |
| 68 TEST_F(L10nUtilTest, TruncateString) { | |
| 69 string16 string = ASCIIToUTF16("foooooey bxxxar baz"); | |
| 70 | |
| 71 // Make sure it doesn't modify the string if length > string length. | |
| 72 EXPECT_EQ(string, l10n_util::TruncateString(string, 100)); | |
| 73 | |
| 74 // Test no characters. | |
| 75 EXPECT_EQ(L"", UTF16ToWide(l10n_util::TruncateString(string, 0))); | |
| 76 | |
| 77 // Test 1 character. | |
| 78 EXPECT_EQ(L"\x2026", UTF16ToWide(l10n_util::TruncateString(string, 1))); | |
| 79 | |
| 80 // Test adds ... at right spot when there is enough room to break at a | |
| 81 // word boundary. | |
| 82 EXPECT_EQ(L"foooooey\x2026", | |
| 83 UTF16ToWide(l10n_util::TruncateString(string, 14))); | |
| 84 | |
| 85 // Test adds ... at right spot when there is not enough space in first word. | |
| 86 EXPECT_EQ(L"f\x2026", UTF16ToWide(l10n_util::TruncateString(string, 2))); | |
| 87 | |
| 88 // Test adds ... at right spot when there is not enough room to break at a | |
| 89 // word boundary. | |
| 90 EXPECT_EQ(L"foooooey\x2026", | |
| 91 UTF16ToWide(l10n_util::TruncateString(string, 11))); | |
| 92 | |
| 93 // Test completely truncates string if break is on initial whitespace. | |
| 94 EXPECT_EQ(L"\x2026", | |
| 95 UTF16ToWide(l10n_util::TruncateString(ASCIIToUTF16(" "), 2))); | |
| 96 } | |
| 97 | |
| 98 void SetICUDefaultLocale(const std::string& locale_string) { | 68 void SetICUDefaultLocale(const std::string& locale_string) { |
| 99 icu::Locale locale(locale_string.c_str()); | 69 icu::Locale locale(locale_string.c_str()); |
| 100 UErrorCode error_code = U_ZERO_ERROR; | 70 UErrorCode error_code = U_ZERO_ERROR; |
| 101 icu::Locale::setDefault(locale, error_code); | 71 icu::Locale::setDefault(locale, error_code); |
| 102 EXPECT_TRUE(U_SUCCESS(error_code)); | 72 EXPECT_TRUE(U_SUCCESS(error_code)); |
| 103 } | 73 } |
| 104 | 74 |
| 105 #if !defined(OS_MACOSX) | 75 #if !defined(OS_MACOSX) |
| 106 // We are disabling this test on MacOS because GetApplicationLocale() as an | 76 // We are disabling this test on MacOS because GetApplicationLocale() as an |
| 107 // API isn't something that we'll easily be able to unit test in this manner. | 77 // API isn't something that we'll easily be able to unit test in this manner. |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("Latin")); | 380 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("Latin")); |
| 411 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("German")); | 381 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("German")); |
| 412 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("pt--BR")); | 382 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("pt--BR")); |
| 413 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("sl-macedonia")); | 383 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("sl-macedonia")); |
| 414 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("@")); | 384 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("@")); |
| 415 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@")); | 385 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@")); |
| 416 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x")); | 386 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x")); |
| 417 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x=")); | 387 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x=")); |
| 418 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@=y")); | 388 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@=y")); |
| 419 } | 389 } |
| OLD | NEW |