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 "base/i18n/case_conversion.h" | 5 #include "base/i18n/case_conversion.h" |
6 #include "base/i18n/rtl.h" | 6 #include "base/i18n/rtl.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "base/test/icu_test_util.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "third_party/icu/source/i18n/unicode/usearch.h" | 10 #include "third_party/icu/source/i18n/unicode/usearch.h" |
10 | 11 |
11 namespace base { | 12 namespace base { |
12 namespace i18n { | 13 namespace i18n { |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 const wchar_t kNonASCIIMixed[] = | 17 const wchar_t kNonASCIIMixed[] = |
17 L"\xC4\xD6\xE4\xF6\x20\xCF\xEF\x20\xF7\x25" | 18 L"\xC4\xD6\xE4\xF6\x20\xCF\xEF\x20\xF7\x25" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 52 |
52 result = ToUpper(mixed); | 53 result = ToUpper(mixed); |
53 EXPECT_EQ(expected_upper, result); | 54 EXPECT_EQ(expected_upper, result); |
54 } | 55 } |
55 | 56 |
56 TEST(CaseConversionTest, TurkishLocaleConversion) { | 57 TEST(CaseConversionTest, TurkishLocaleConversion) { |
57 const string16 mixed(WideToUTF16(L"\x49\x131")); | 58 const string16 mixed(WideToUTF16(L"\x49\x131")); |
58 const string16 expected_lower(WideToUTF16(L"\x69\x131")); | 59 const string16 expected_lower(WideToUTF16(L"\x69\x131")); |
59 const string16 expected_upper(WideToUTF16(L"\x49\x49")); | 60 const string16 expected_upper(WideToUTF16(L"\x49\x49")); |
60 | 61 |
61 std::string default_locale(uloc_getDefault()); | 62 test::ScopedRestoreICUDefaultLocale restore_locale; |
62 i18n::SetICUDefaultLocale("en_US"); | 63 i18n::SetICUDefaultLocale("en_US"); |
63 | 64 |
64 string16 result = ToLower(mixed); | 65 string16 result = ToLower(mixed); |
65 EXPECT_EQ(expected_lower, result); | 66 EXPECT_EQ(expected_lower, result); |
66 | 67 |
67 result = ToUpper(mixed); | 68 result = ToUpper(mixed); |
68 EXPECT_EQ(expected_upper, result); | 69 EXPECT_EQ(expected_upper, result); |
69 | 70 |
70 i18n::SetICUDefaultLocale("tr"); | 71 i18n::SetICUDefaultLocale("tr"); |
71 | 72 |
72 const string16 expected_lower_turkish(WideToUTF16(L"\x131\x131")); | 73 const string16 expected_lower_turkish(WideToUTF16(L"\x131\x131")); |
73 const string16 expected_upper_turkish(WideToUTF16(L"\x49\x49")); | 74 const string16 expected_upper_turkish(WideToUTF16(L"\x49\x49")); |
74 | 75 |
75 result = ToLower(mixed); | 76 result = ToLower(mixed); |
76 EXPECT_EQ(expected_lower_turkish, result); | 77 EXPECT_EQ(expected_lower_turkish, result); |
77 | 78 |
78 result = ToUpper(mixed); | 79 result = ToUpper(mixed); |
79 EXPECT_EQ(expected_upper_turkish, result); | 80 EXPECT_EQ(expected_upper_turkish, result); |
80 | |
81 SetICUDefaultLocale(default_locale.data()); | |
82 } | 81 } |
83 | 82 |
84 TEST(CaseConversionTest, FoldCase) { | 83 TEST(CaseConversionTest, FoldCase) { |
85 // Simple ASCII, should lower-case. | 84 // Simple ASCII, should lower-case. |
86 EXPECT_EQ(ASCIIToUTF16("hello, world"), | 85 EXPECT_EQ(ASCIIToUTF16("hello, world"), |
87 FoldCase(ASCIIToUTF16("Hello, World"))); | 86 FoldCase(ASCIIToUTF16("Hello, World"))); |
88 | 87 |
89 // Non-ASCII cases from above. They should all fold to the same result. | 88 // Non-ASCII cases from above. They should all fold to the same result. |
90 EXPECT_EQ(FoldCase(WideToUTF16(kNonASCIIMixed)), | 89 EXPECT_EQ(FoldCase(WideToUTF16(kNonASCIIMixed)), |
91 FoldCase(WideToUTF16(kNonASCIILower))); | 90 FoldCase(WideToUTF16(kNonASCIILower))); |
92 EXPECT_EQ(FoldCase(WideToUTF16(kNonASCIIMixed)), | 91 EXPECT_EQ(FoldCase(WideToUTF16(kNonASCIIMixed)), |
93 FoldCase(WideToUTF16(kNonASCIIUpper))); | 92 FoldCase(WideToUTF16(kNonASCIIUpper))); |
94 | 93 |
95 // Turkish cases from above. This is the lower-case expected result from the | 94 // Turkish cases from above. This is the lower-case expected result from the |
96 // US locale. It should be the same even when the current locale is Turkish. | 95 // US locale. It should be the same even when the current locale is Turkish. |
97 const string16 turkish(WideToUTF16(L"\x49\x131")); | 96 const string16 turkish(WideToUTF16(L"\x49\x131")); |
98 const string16 turkish_expected(WideToUTF16(L"\x69\x131")); | 97 const string16 turkish_expected(WideToUTF16(L"\x69\x131")); |
99 | 98 |
100 std::string default_locale(uloc_getDefault()); | 99 test::ScopedRestoreICUDefaultLocale restore_locale; |
101 i18n::SetICUDefaultLocale("en_US"); | 100 i18n::SetICUDefaultLocale("en_US"); |
102 EXPECT_EQ(turkish_expected, FoldCase(turkish)); | 101 EXPECT_EQ(turkish_expected, FoldCase(turkish)); |
103 | 102 |
104 i18n::SetICUDefaultLocale("tr"); | 103 i18n::SetICUDefaultLocale("tr"); |
105 EXPECT_EQ(turkish_expected, FoldCase(turkish)); | 104 EXPECT_EQ(turkish_expected, FoldCase(turkish)); |
106 | 105 |
107 // Test a case that gets bigger when processed. | 106 // Test a case that gets bigger when processed. |
108 // U+130 = LATIN CAPITAL LETTER I WITH DOT ABOVE gets folded to a lower case | 107 // U+130 = LATIN CAPITAL LETTER I WITH DOT ABOVE gets folded to a lower case |
109 // "i" followed by U+307 COMBINING DOT ABOVE. | 108 // "i" followed by U+307 COMBINING DOT ABOVE. |
110 EXPECT_EQ(WideToUTF16(L"i\u0307j"), FoldCase(WideToUTF16(L"\u0130j"))); | 109 EXPECT_EQ(WideToUTF16(L"i\u0307j"), FoldCase(WideToUTF16(L"\u0130j"))); |
111 | 110 |
112 // U+00DF (SHARP S) and U+1E9E (CAPIRAL SHARP S) are both folded to "ss". | 111 // U+00DF (SHARP S) and U+1E9E (CAPIRAL SHARP S) are both folded to "ss". |
113 EXPECT_EQ(ASCIIToUTF16("ssss"), FoldCase(WideToUTF16(L"\u00DF\u1E9E"))); | 112 EXPECT_EQ(ASCIIToUTF16("ssss"), FoldCase(WideToUTF16(L"\u00DF\u1E9E"))); |
114 } | 113 } |
115 | 114 |
116 } // namespace i18n | 115 } // namespace i18n |
117 } // namespace base | 116 } // namespace base |
118 | 117 |
119 | 118 |
120 | 119 |
OLD | NEW |