OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 }, | 112 }, |
113 }; | 113 }; |
114 | 114 |
115 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | 115 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
116 SCOPED_TRACE(base::StringPrintf("kTestCases[%" PRIuS "]: language=%s", i, | 116 SCOPED_TRACE(base::StringPrintf("kTestCases[%" PRIuS "]: language=%s", i, |
117 kTestCases[i].language)); | 117 kTestCases[i].language)); |
118 | 118 |
119 SpellcheckCharAttribute attributes; | 119 SpellcheckCharAttribute attributes; |
120 attributes.SetDefaultLanguage(kTestCases[i].language); | 120 attributes.SetDefaultLanguage(kTestCases[i].language); |
121 | 121 |
122 string16 input(WideToUTF16(kTestText)); | 122 string16 input(base::WideToUTF16(kTestText)); |
123 SpellcheckWordIterator iterator; | 123 SpellcheckWordIterator iterator; |
124 EXPECT_TRUE(iterator.Initialize(&attributes, | 124 EXPECT_TRUE(iterator.Initialize(&attributes, |
125 kTestCases[i].allow_contraction)); | 125 kTestCases[i].allow_contraction)); |
126 EXPECT_TRUE(iterator.SetText(input.c_str(), input.length())); | 126 EXPECT_TRUE(iterator.SetText(input.c_str(), input.length())); |
127 | 127 |
128 std::vector<string16> expected_words; | 128 std::vector<string16> expected_words; |
129 base::SplitString( | 129 base::SplitString( |
130 WideToUTF16(kTestCases[i].expected_words), ' ', &expected_words); | 130 base::WideToUTF16(kTestCases[i].expected_words), ' ', &expected_words); |
131 | 131 |
132 string16 actual_word; | 132 string16 actual_word; |
133 int actual_start, actual_end; | 133 int actual_start, actual_end; |
134 size_t index = 0; | 134 size_t index = 0; |
135 while (iterator.GetNextWord(&actual_word, &actual_start, &actual_end)) { | 135 while (iterator.GetNextWord(&actual_word, &actual_start, &actual_end)) { |
136 EXPECT_TRUE(index < expected_words.size()); | 136 EXPECT_TRUE(index < expected_words.size()); |
137 if (index < expected_words.size()) | 137 if (index < expected_words.size()) |
138 EXPECT_EQ(expected_words[index], actual_word); | 138 EXPECT_EQ(expected_words[index], actual_word); |
139 ++index; | 139 ++index; |
140 } | 140 } |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 // Tests whether our SpellcheckWordIterator extracts an empty word without | 144 // Tests whether our SpellcheckWordIterator extracts an empty word without |
145 // getting stuck in an infinite loop when inputting a Khmer text. (This is a | 145 // getting stuck in an infinite loop when inputting a Khmer text. (This is a |
146 // regression test for Issue 46278.) | 146 // regression test for Issue 46278.) |
147 TEST(SpellcheckWordIteratorTest, RuleSetConsistency) { | 147 TEST(SpellcheckWordIteratorTest, RuleSetConsistency) { |
148 SpellcheckCharAttribute attributes; | 148 SpellcheckCharAttribute attributes; |
149 attributes.SetDefaultLanguage("en-US"); | 149 attributes.SetDefaultLanguage("en-US"); |
150 | 150 |
151 const wchar_t kTestText[] = L"\x1791\x17c1\x002e"; | 151 const wchar_t kTestText[] = L"\x1791\x17c1\x002e"; |
152 string16 input(WideToUTF16(kTestText)); | 152 string16 input(base::WideToUTF16(kTestText)); |
153 | 153 |
154 SpellcheckWordIterator iterator; | 154 SpellcheckWordIterator iterator; |
155 EXPECT_TRUE(iterator.Initialize(&attributes, true)); | 155 EXPECT_TRUE(iterator.Initialize(&attributes, true)); |
156 EXPECT_TRUE(iterator.SetText(input.c_str(), input.length())); | 156 EXPECT_TRUE(iterator.SetText(input.c_str(), input.length())); |
157 | 157 |
158 // When SpellcheckWordIterator uses an inconsistent ICU ruleset, the following | 158 // When SpellcheckWordIterator uses an inconsistent ICU ruleset, the following |
159 // iterator.GetNextWord() call gets stuck in an infinite loop. Therefore, this | 159 // iterator.GetNextWord() call gets stuck in an infinite loop. Therefore, this |
160 // test succeeds if this call returns without timeouts. | 160 // test succeeds if this call returns without timeouts. |
161 string16 actual_word; | 161 string16 actual_word; |
162 int actual_start, actual_end; | 162 int actual_start, actual_end; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 }, | 207 }, |
208 }; | 208 }; |
209 | 209 |
210 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 210 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
211 SCOPED_TRACE(base::StringPrintf("kTestCases[%" PRIuS "]: language=%s", i, | 211 SCOPED_TRACE(base::StringPrintf("kTestCases[%" PRIuS "]: language=%s", i, |
212 kTestCases[i].language)); | 212 kTestCases[i].language)); |
213 | 213 |
214 SpellcheckCharAttribute attributes; | 214 SpellcheckCharAttribute attributes; |
215 attributes.SetDefaultLanguage(kTestCases[i].language); | 215 attributes.SetDefaultLanguage(kTestCases[i].language); |
216 | 216 |
217 string16 input_word(WideToUTF16(kTestCases[i].text)); | 217 string16 input_word(base::WideToUTF16(kTestCases[i].text)); |
218 SpellcheckWordIterator iterator; | 218 SpellcheckWordIterator iterator; |
219 EXPECT_TRUE(iterator.Initialize(&attributes, true)); | 219 EXPECT_TRUE(iterator.Initialize(&attributes, true)); |
220 EXPECT_TRUE(iterator.SetText(input_word.c_str(), input_word.length())); | 220 EXPECT_TRUE(iterator.SetText(input_word.c_str(), input_word.length())); |
221 | 221 |
222 string16 actual_word; | 222 string16 actual_word; |
223 int actual_start, actual_end; | 223 int actual_start, actual_end; |
224 EXPECT_TRUE(iterator.GetNextWord(&actual_word, &actual_start, &actual_end)); | 224 EXPECT_TRUE(iterator.GetNextWord(&actual_word, &actual_start, &actual_end)); |
225 if (kTestCases[i].left_to_right) | 225 if (kTestCases[i].left_to_right) |
226 EXPECT_EQ(input_word, actual_word); | 226 EXPECT_EQ(input_word, actual_word); |
227 else | 227 else |
(...skipping 12 matching lines...) Expand all Loading... |
240 } | 240 } |
241 | 241 |
242 // Test initialization fails when no default language is set. | 242 // Test initialization fails when no default language is set. |
243 { | 243 { |
244 SpellcheckCharAttribute attributes; | 244 SpellcheckCharAttribute attributes; |
245 | 245 |
246 SpellcheckWordIterator iterator; | 246 SpellcheckWordIterator iterator; |
247 EXPECT_FALSE(iterator.Initialize(&attributes, true)); | 247 EXPECT_FALSE(iterator.Initialize(&attributes, true)); |
248 } | 248 } |
249 } | 249 } |
OLD | NEW |