OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "app/app_paths.h" | 7 #include "app/app_paths.h" |
8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
9 #if !defined(OS_MACOSX) | 9 #if !defined(OS_MACOSX) |
10 #include "app/test/data/resource.h" | 10 #include "app/test/data/resource.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
79 // Test adds ... at right spot when there is not enough room to break at a | 79 // Test adds ... at right spot when there is not enough room to break at a |
80 // word boundary. | 80 // word boundary. |
81 EXPECT_EQ(L"foooooey\x2026", l10n_util::TruncateString(string, 11)); | 81 EXPECT_EQ(L"foooooey\x2026", l10n_util::TruncateString(string, 11)); |
82 | 82 |
83 // Test completely truncates string if break is on initial whitespace. | 83 // Test completely truncates string if break is on initial whitespace. |
84 EXPECT_EQ(L"\x2026", l10n_util::TruncateString(L" ", 2)); | 84 EXPECT_EQ(L"\x2026", l10n_util::TruncateString(L" ", 2)); |
85 } | 85 } |
86 | 86 |
87 void SetICUDefaultLocale(const std::string& locale_string) { | 87 void SetICUDefaultLocale(const std::string& locale_string) { |
88 Locale locale(locale_string.c_str()); | 88 icu::Locale locale(locale_string.c_str()); |
89 UErrorCode error_code = U_ZERO_ERROR; | 89 UErrorCode error_code = U_ZERO_ERROR; |
90 Locale::setDefault(locale, error_code); | 90 icu::Locale::setDefault(locale, error_code); |
91 EXPECT_TRUE(U_SUCCESS(error_code)); | 91 EXPECT_TRUE(U_SUCCESS(error_code)); |
92 } | 92 } |
93 | 93 |
94 #if defined(OS_WIN) || defined(OS_LINUX) | 94 #if defined(OS_WIN) || defined(OS_LINUX) |
95 // We are disabling this test on MacOS because GetApplicationLocale() as an | 95 // We are disabling this test on MacOS because GetApplicationLocale() as an |
96 // API isn't something that we'll easily be able to unit test in this manner. | 96 // API isn't something that we'll easily be able to unit test in this manner. |
97 // The meaning of that API, on the Mac, is "the locale used by Cocoa's main | 97 // The meaning of that API, on the Mac, is "the locale used by Cocoa's main |
98 // nib file", which clearly can't be stubbed by a test app that doesn't use | 98 // nib file", which clearly can't be stubbed by a test app that doesn't use |
99 // Cocoa. | 99 // Cocoa. |
100 TEST_F(L10nUtilTest, GetAppLocale) { | 100 TEST_F(L10nUtilTest, GetAppLocale) { |
(...skipping 26 matching lines...) Expand all Loading... |
127 #elif defined(OS_POSIX) | 127 #elif defined(OS_POSIX) |
128 static const char kLocaleFileExtension[] = ".pak"; | 128 static const char kLocaleFileExtension[] = ".pak"; |
129 #endif | 129 #endif |
130 for (size_t i = 0; i < arraysize(filenames); ++i) { | 130 for (size_t i = 0; i < arraysize(filenames); ++i) { |
131 FilePath filename = new_locale_dir.AppendASCII( | 131 FilePath filename = new_locale_dir.AppendASCII( |
132 filenames[i] + kLocaleFileExtension); | 132 filenames[i] + kLocaleFileExtension); |
133 file_util::WriteFile(filename, "", 0); | 133 file_util::WriteFile(filename, "", 0); |
134 } | 134 } |
135 | 135 |
136 // Keep a copy of ICU's default locale before we overwrite it. | 136 // Keep a copy of ICU's default locale before we overwrite it. |
137 Locale locale = Locale::getDefault(); | 137 icu::Locale locale = icu::Locale::getDefault(); |
138 | 138 |
139 SetICUDefaultLocale("en-US"); | 139 SetICUDefaultLocale("en-US"); |
140 EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(L"")); | 140 EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(L"")); |
141 | 141 |
142 SetICUDefaultLocale("en-GB"); | 142 SetICUDefaultLocale("en-GB"); |
143 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale(L"")); | 143 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale(L"")); |
144 | 144 |
145 SetICUDefaultLocale("fr-CA"); | 145 SetICUDefaultLocale("fr-CA"); |
146 EXPECT_EQ("fr", l10n_util::GetApplicationLocale(L"")); | 146 EXPECT_EQ("fr", l10n_util::GetApplicationLocale(L"")); |
147 | 147 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 EXPECT_EQ("or", l10n_util::GetApplicationLocale(L"")); | 206 EXPECT_EQ("or", l10n_util::GetApplicationLocale(L"")); |
207 SetICUDefaultLocale("en-GB"); | 207 SetICUDefaultLocale("en-GB"); |
208 EXPECT_EQ("or", l10n_util::GetApplicationLocale(L"or")); | 208 EXPECT_EQ("or", l10n_util::GetApplicationLocale(L"or")); |
209 } | 209 } |
210 #endif // defined(OS_WIN) | 210 #endif // defined(OS_WIN) |
211 | 211 |
212 // Clean up. | 212 // Clean up. |
213 PathService::Override(app::DIR_LOCALES, orig_locale_dir.ToWStringHack()); | 213 PathService::Override(app::DIR_LOCALES, orig_locale_dir.ToWStringHack()); |
214 file_util::Delete(new_locale_dir, true); | 214 file_util::Delete(new_locale_dir, true); |
215 UErrorCode error_code = U_ZERO_ERROR; | 215 UErrorCode error_code = U_ZERO_ERROR; |
216 Locale::setDefault(locale, error_code); | 216 icu::Locale::setDefault(locale, error_code); |
217 } | 217 } |
218 #endif // defined(OS_WIN) || defined(OS_LINUX) | 218 #endif // defined(OS_WIN) || defined(OS_LINUX) |
219 | 219 |
220 TEST_F(L10nUtilTest, SortStringsUsingFunction) { | 220 TEST_F(L10nUtilTest, SortStringsUsingFunction) { |
221 std::vector<StringWrapper*> strings; | 221 std::vector<StringWrapper*> strings; |
222 strings.push_back(new StringWrapper(L"C")); | 222 strings.push_back(new StringWrapper(L"C")); |
223 strings.push_back(new StringWrapper(L"d")); | 223 strings.push_back(new StringWrapper(L"d")); |
224 strings.push_back(new StringWrapper(L"b")); | 224 strings.push_back(new StringWrapper(L"b")); |
225 strings.push_back(new StringWrapper(L"a")); | 225 strings.push_back(new StringWrapper(L"a")); |
226 l10n_util::SortStringsUsingMethod(L"en-US", &strings, &StringWrapper::string); | 226 l10n_util::SortStringsUsingMethod(L"en-US", &strings, &StringWrapper::string); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("en")); | 432 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("en")); |
433 // Chinese in China with '-'. | 433 // Chinese in China with '-'. |
434 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("zh-CN")); | 434 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("zh-CN")); |
435 // Filipino : 3-letter code | 435 // Filipino : 3-letter code |
436 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("fil")); | 436 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("fil")); |
437 // Russian | 437 // Russian |
438 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("ru")); | 438 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("ru")); |
439 // Japanese that uses multiple scripts | 439 // Japanese that uses multiple scripts |
440 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("ja")); | 440 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("ja")); |
441 } | 441 } |
OLD | NEW |