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

Side by Side Diff: app/l10n_util_unittest.cc

Issue 5742006: wstrings: make l10n_util::TruncateString use string16 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years 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 | « app/l10n_util.cc ('k') | chrome/browser/extensions/extension_menu_manager.cc » ('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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 s = l10n_util::GetStringF(IDS_PLACEHOLDERS, L"chrome", L"10"); 55 s = l10n_util::GetStringF(IDS_PLACEHOLDERS, L"chrome", L"10");
56 EXPECT_EQ(std::wstring(L"Hello, chrome. Your number is 10."), s); 56 EXPECT_EQ(std::wstring(L"Hello, chrome. Your number is 10."), s);
57 57
58 s = l10n_util::GetStringF(IDS_PLACEHOLDERS_2, 20); 58 s = l10n_util::GetStringF(IDS_PLACEHOLDERS_2, 20);
59 EXPECT_EQ(std::wstring(L"You owe me $20."), s); 59 EXPECT_EQ(std::wstring(L"You owe me $20."), s);
60 } 60 }
61 #endif // defined(OS_WIN) 61 #endif // defined(OS_WIN)
62 62
63 TEST_F(L10nUtilTest, TruncateString) { 63 TEST_F(L10nUtilTest, TruncateString) {
64 std::wstring string(L"foooooey bxxxar baz"); 64 string16 string = ASCIIToUTF16("foooooey bxxxar baz");
65 65
66 // Make sure it doesn't modify the string if length > string length. 66 // Make sure it doesn't modify the string if length > string length.
67 EXPECT_EQ(string, l10n_util::TruncateString(string, 100)); 67 EXPECT_EQ(string, l10n_util::TruncateString(string, 100));
68 68
69 // Test no characters. 69 // Test no characters.
70 EXPECT_EQ(L"", l10n_util::TruncateString(string, 0)); 70 EXPECT_EQ(L"", UTF16ToWide(l10n_util::TruncateString(string, 0)));
71 71
72 // Test 1 character. 72 // Test 1 character.
73 EXPECT_EQ(L"\x2026", l10n_util::TruncateString(string, 1)); 73 EXPECT_EQ(L"\x2026", UTF16ToWide(l10n_util::TruncateString(string, 1)));
74 74
75 // Test adds ... at right spot when there is enough room to break at a 75 // Test adds ... at right spot when there is enough room to break at a
76 // word boundary. 76 // word boundary.
77 EXPECT_EQ(L"foooooey\x2026", l10n_util::TruncateString(string, 14)); 77 EXPECT_EQ(L"foooooey\x2026",
78 UTF16ToWide(l10n_util::TruncateString(string, 14)));
78 79
79 // Test adds ... at right spot when there is not enough space in first word. 80 // Test adds ... at right spot when there is not enough space in first word.
80 EXPECT_EQ(L"f\x2026", l10n_util::TruncateString(string, 2)); 81 EXPECT_EQ(L"f\x2026", UTF16ToWide(l10n_util::TruncateString(string, 2)));
81 82
82 // Test adds ... at right spot when there is not enough room to break at a 83 // Test adds ... at right spot when there is not enough room to break at a
83 // word boundary. 84 // word boundary.
84 EXPECT_EQ(L"foooooey\x2026", l10n_util::TruncateString(string, 11)); 85 EXPECT_EQ(L"foooooey\x2026",
86 UTF16ToWide(l10n_util::TruncateString(string, 11)));
85 87
86 // Test completely truncates string if break is on initial whitespace. 88 // Test completely truncates string if break is on initial whitespace.
87 EXPECT_EQ(L"\x2026", l10n_util::TruncateString(L" ", 2)); 89 EXPECT_EQ(L"\x2026",
90 UTF16ToWide(l10n_util::TruncateString(ASCIIToUTF16(" "), 2)));
88 } 91 }
89 92
90 void SetICUDefaultLocale(const std::string& locale_string) { 93 void SetICUDefaultLocale(const std::string& locale_string) {
91 icu::Locale locale(locale_string.c_str()); 94 icu::Locale locale(locale_string.c_str());
92 UErrorCode error_code = U_ZERO_ERROR; 95 UErrorCode error_code = U_ZERO_ERROR;
93 icu::Locale::setDefault(locale, error_code); 96 icu::Locale::setDefault(locale, error_code);
94 EXPECT_TRUE(U_SUCCESS(error_code)); 97 EXPECT_TRUE(U_SUCCESS(error_code));
95 } 98 }
96 99
97 #if !defined(OS_MACOSX) 100 #if !defined(OS_MACOSX)
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 318
316 result = l10n_util::GetDisplayNameForLocale("zh-TW", "en", false); 319 result = l10n_util::GetDisplayNameForLocale("zh-TW", "en", false);
317 EXPECT_EQ(result, ASCIIToUTF16("Chinese (Traditional Han)")); 320 EXPECT_EQ(result, ASCIIToUTF16("Chinese (Traditional Han)"));
318 321
319 result = l10n_util::GetDisplayNameForLocale("pt-BR", "en", false); 322 result = l10n_util::GetDisplayNameForLocale("pt-BR", "en", false);
320 EXPECT_EQ(result, ASCIIToUTF16("Portuguese (Brazil)")); 323 EXPECT_EQ(result, ASCIIToUTF16("Portuguese (Brazil)"));
321 324
322 result = l10n_util::GetDisplayNameForLocale("es-419", "en", false); 325 result = l10n_util::GetDisplayNameForLocale("es-419", "en", false);
323 EXPECT_EQ(result, ASCIIToUTF16("Spanish (Latin America and the Caribbean)")); 326 EXPECT_EQ(result, ASCIIToUTF16("Spanish (Latin America and the Caribbean)"));
324 } 327 }
OLDNEW
« no previous file with comments | « app/l10n_util.cc ('k') | chrome/browser/extensions/extension_menu_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698