| 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "chrome/common/chrome_paths.h" | 11 #include "chrome/common/chrome_paths.h" |
| 12 #include "chrome/common/l10n_util.h" | 12 #include "chrome/common/l10n_util.h" |
| 13 #include "chrome/common/stl_util-inl.h" |
| 13 #if !defined(OS_MACOSX) | 14 #if !defined(OS_MACOSX) |
| 14 #include "chrome/test/data/resource.h" | 15 #include "chrome/test/data/resource.h" |
| 15 #endif | 16 #endif |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "testing/platform_test.h" | 18 #include "testing/platform_test.h" |
| 18 #include "unicode/locid.h" | 19 #include "unicode/locid.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 class L10nUtilTest: public PlatformTest { | 23 class StringWrapper { |
| 24 public: |
| 25 explicit StringWrapper(const std::wstring& string) : string_(string) {} |
| 26 const std::wstring& string() const { return string_; } |
| 27 |
| 28 private: |
| 29 std::wstring string_; |
| 30 |
| 31 DISALLOW_COPY_AND_ASSIGN(StringWrapper); |
| 32 }; |
| 33 |
| 34 } // namespace |
| 35 |
| 36 class L10nUtilTest : public PlatformTest { |
| 23 }; | 37 }; |
| 24 | 38 |
| 25 #if defined(OS_WIN) | 39 #if defined(OS_WIN) |
| 26 TEST_F(L10nUtilTest, GetString) { | 40 TEST_F(L10nUtilTest, GetString) { |
| 27 std::wstring s = l10n_util::GetString(IDS_SIMPLE); | 41 std::wstring s = l10n_util::GetString(IDS_SIMPLE); |
| 28 EXPECT_EQ(std::wstring(L"Hello World!"), s); | 42 EXPECT_EQ(std::wstring(L"Hello World!"), s); |
| 29 | 43 |
| 30 s = l10n_util::GetStringF(IDS_PLACEHOLDERS, L"chrome", L"10"); | 44 s = l10n_util::GetStringF(IDS_PLACEHOLDERS, L"chrome", L"10"); |
| 31 EXPECT_EQ(std::wstring(L"Hello, chrome. Your number is 10."), s); | 45 EXPECT_EQ(std::wstring(L"Hello, chrome. Your number is 10."), s); |
| 32 | 46 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 SetICUDefaultLocale(L"he"); | 167 SetICUDefaultLocale(L"he"); |
| 154 EXPECT_EQ(L"en-US", l10n_util::GetApplicationLocale(L"en")); | 168 EXPECT_EQ(L"en-US", l10n_util::GetApplicationLocale(L"en")); |
| 155 | 169 |
| 156 // Clean up. | 170 // Clean up. |
| 157 PathService::Override(chrome::DIR_LOCALES, orig_locale_dir); | 171 PathService::Override(chrome::DIR_LOCALES, orig_locale_dir); |
| 158 file_util::Delete(new_locale_dir, true); | 172 file_util::Delete(new_locale_dir, true); |
| 159 UErrorCode error_code = U_ZERO_ERROR; | 173 UErrorCode error_code = U_ZERO_ERROR; |
| 160 Locale::setDefault(locale, error_code); | 174 Locale::setDefault(locale, error_code); |
| 161 } | 175 } |
| 162 | 176 |
| 177 TEST_F(L10nUtilTest, SortStringsUsingFunction) { |
| 178 std::vector<StringWrapper*> strings; |
| 179 strings.push_back(new StringWrapper(L"C")); |
| 180 strings.push_back(new StringWrapper(L"d")); |
| 181 strings.push_back(new StringWrapper(L"b")); |
| 182 strings.push_back(new StringWrapper(L"a")); |
| 183 l10n_util::SortStringsUsingMethod(L"en-US", &strings, &StringWrapper::string); |
| 184 ASSERT_TRUE(L"a" == strings[0]->string()); |
| 185 ASSERT_TRUE(L"b" == strings[1]->string()); |
| 186 ASSERT_TRUE(L"C" == strings[2]->string()); |
| 187 ASSERT_TRUE(L"d" == strings[3]->string()); |
| 188 STLDeleteElements(&strings); |
| 189 } |
| 190 |
| 163 TEST_F(L10nUtilTest, GetFirstStrongCharacterDirection) { | 191 TEST_F(L10nUtilTest, GetFirstStrongCharacterDirection) { |
| 164 // Test pure LTR string. | 192 // Test pure LTR string. |
| 165 std::wstring string(L"foo bar"); | 193 std::wstring string(L"foo bar"); |
| 166 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, | 194 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, |
| 167 l10n_util::GetFirstStrongCharacterDirection(string)); | 195 l10n_util::GetFirstStrongCharacterDirection(string)); |
| 168 | 196 |
| 169 // Test bidi string in which the first character with strong directionality | 197 // Test bidi string in which the first character with strong directionality |
| 170 // is a character with type L. | 198 // is a character with type L. |
| 171 string.assign(L"foo \x05d0 bar"); | 199 string.assign(L"foo \x05d0 bar"); |
| 172 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, | 200 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 } | 355 } |
| 328 }; | 356 }; |
| 329 for (unsigned int i = 0; i < arraysize(test_data); ++i) { | 357 for (unsigned int i = 0; i < arraysize(test_data); ++i) { |
| 330 string16 localized_file_path_string; | 358 string16 localized_file_path_string; |
| 331 FilePath path = FilePath::FromWStringHack(test_data[i].path); | 359 FilePath path = FilePath::FromWStringHack(test_data[i].path); |
| 332 l10n_util::WrapPathWithLTRFormatting(path, &localized_file_path_string); | 360 l10n_util::WrapPathWithLTRFormatting(path, &localized_file_path_string); |
| 333 std::wstring wrapped_path = UTF16ToWide(localized_file_path_string); | 361 std::wstring wrapped_path = UTF16ToWide(localized_file_path_string); |
| 334 EXPECT_EQ(wrapped_path, test_data[i].wrapped_path); | 362 EXPECT_EQ(wrapped_path, test_data[i].wrapped_path); |
| 335 } | 363 } |
| 336 } | 364 } |
| 337 } | |
| 338 | |
| OLD | NEW |