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 "base/files/file_util.h" | 5 #include "base/files/file_util.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/common/chrome_paths.h" | 10 #include "chrome/common/chrome_paths.h" |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 {L"10th", true}, | 371 {L"10th", true}, |
372 {L"100th", true}, | 372 {L"100th", true}, |
373 {L"1000th", true}, | 373 {L"1000th", true}, |
374 {L"25", true}, | 374 {L"25", true}, |
375 {L"2012", true}, | 375 {L"2012", true}, |
376 {L"100,000,000", true}, | 376 {L"100,000,000", true}, |
377 {L"3.141592653", true}, | 377 {L"3.141592653", true}, |
378 | 378 |
379 }; | 379 }; |
380 | 380 |
381 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 381 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
382 size_t input_length = 0; | 382 size_t input_length = 0; |
383 if (kTestCases[i].input != NULL) { | 383 if (kTestCases[i].input != NULL) { |
384 input_length = wcslen(kTestCases[i].input); | 384 input_length = wcslen(kTestCases[i].input); |
385 } | 385 } |
386 int misspelling_start; | 386 int misspelling_start; |
387 int misspelling_length; | 387 int misspelling_length; |
388 bool result = spell_check()->SpellCheckWord( | 388 bool result = spell_check()->SpellCheckWord( |
389 base::WideToUTF16(kTestCases[i].input).c_str(), | 389 base::WideToUTF16(kTestCases[i].input).c_str(), |
390 static_cast<int>(input_length), | 390 static_cast<int>(input_length), |
391 0, | 391 0, |
(...skipping 29 matching lines...) Expand all Loading... |
421 {L"wate", false, 0, 0, L"ate"}, | 421 {L"wate", false, 0, 0, L"ate"}, |
422 {L"jum", false, 0, 0, L"jump"}, | 422 {L"jum", false, 0, 0, L"jump"}, |
423 {L"jum", false, 0, 0, L"hum"}, | 423 {L"jum", false, 0, 0, L"hum"}, |
424 {L"jum", false, 0, 0, L"sum"}, | 424 {L"jum", false, 0, 0, L"sum"}, |
425 {L"jum", false, 0, 0, L"um"}, | 425 {L"jum", false, 0, 0, L"um"}, |
426 // A regression test for Issue 36523. | 426 // A regression test for Issue 36523. |
427 {L"privliged", false, 0, 0, L"privileged"}, | 427 {L"privliged", false, 0, 0, L"privileged"}, |
428 // TODO (Sidchat): add many more examples. | 428 // TODO (Sidchat): add many more examples. |
429 }; | 429 }; |
430 | 430 |
431 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 431 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
432 std::vector<base::string16> suggestions; | 432 std::vector<base::string16> suggestions; |
433 size_t input_length = 0; | 433 size_t input_length = 0; |
434 if (kTestCases[i].input != NULL) { | 434 if (kTestCases[i].input != NULL) { |
435 input_length = wcslen(kTestCases[i].input); | 435 input_length = wcslen(kTestCases[i].input); |
436 } | 436 } |
437 int misspelling_start; | 437 int misspelling_start; |
438 int misspelling_length; | 438 int misspelling_length; |
439 bool result = spell_check()->SpellCheckWord( | 439 bool result = spell_check()->SpellCheckWord( |
440 base::WideToUTF16(kTestCases[i].input).c_str(), | 440 base::WideToUTF16(kTestCases[i].input).c_str(), |
441 static_cast<int>(input_length), | 441 static_cast<int>(input_length), |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 L"\x043c\x0430\x0432\x04b7\x0443\x0434\x0430, \x043e\x0441\x043e\x043d " | 800 L"\x043c\x0430\x0432\x04b7\x0443\x0434\x0430, \x043e\x0441\x043e\x043d " |
801 L"\x043d\x0430\x043c\x0443\x0434\x0430\x043d\x0438 " | 801 L"\x043d\x0430\x043c\x0443\x0434\x0430\x043d\x0438 " |
802 L"\x0438\x0441\x0442\x0438\x0444\x043e\x0434\x0430\x0431\x0430\x0440" | 802 L"\x0438\x0441\x0442\x0438\x0444\x043e\x0434\x0430\x0431\x0430\x0440" |
803 L"\x04e3 \x0432\x0430 \x0434\x0430\x0441\x0442\x0440\x0430\x0441\x0438 " | 803 L"\x04e3 \x0432\x0430 \x0434\x0430\x0441\x0442\x0440\x0430\x0441\x0438 " |
804 L"\x0443\x043c\x0443\x043c " | 804 L"\x0443\x043c\x0443\x043c " |
805 L"\x0433\x0430\x0440\x0434\x043e\x043d\x0438\x0434\x0430\x043d\x0438 " | 805 L"\x0433\x0430\x0440\x0434\x043e\x043d\x0438\x0434\x0430\x043d\x0438 " |
806 L"\x043e\x043d\x04b3\x043e \x0430\x0441\x0442." | 806 L"\x043e\x043d\x04b3\x043e \x0430\x0441\x0442." |
807 }, | 807 }, |
808 }; | 808 }; |
809 | 809 |
810 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 810 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
811 ReinitializeSpellCheck(kTestCases[i].language); | 811 ReinitializeSpellCheck(kTestCases[i].language); |
812 size_t input_length = 0; | 812 size_t input_length = 0; |
813 if (kTestCases[i].input != NULL) | 813 if (kTestCases[i].input != NULL) |
814 input_length = wcslen(kTestCases[i].input); | 814 input_length = wcslen(kTestCases[i].input); |
815 | 815 |
816 int misspelling_start = 0; | 816 int misspelling_start = 0; |
817 int misspelling_length = 0; | 817 int misspelling_length = 0; |
818 bool result = spell_check()->SpellCheckWord( | 818 bool result = spell_check()->SpellCheckWord( |
819 base::WideToUTF16(kTestCases[i].input).c_str(), | 819 base::WideToUTF16(kTestCases[i].input).c_str(), |
820 static_cast<int>(input_length), | 820 static_cast<int>(input_length), |
(...skipping 24 matching lines...) Expand all Loading... |
845 } kTestCases[] = { | 845 } kTestCases[] = { |
846 {"teh", "the"}, | 846 {"teh", "the"}, |
847 {"moer", "more"}, | 847 {"moer", "more"}, |
848 {"watre", "water"}, | 848 {"watre", "water"}, |
849 {"noen", ""}, | 849 {"noen", ""}, |
850 {"what", ""}, | 850 {"what", ""}, |
851 }; | 851 }; |
852 | 852 |
853 EnableAutoCorrect(true); | 853 EnableAutoCorrect(true); |
854 | 854 |
855 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 855 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
856 base::string16 misspelled_word(base::UTF8ToUTF16(kTestCases[i].input)); | 856 base::string16 misspelled_word(base::UTF8ToUTF16(kTestCases[i].input)); |
857 base::string16 expected_autocorrect_word( | 857 base::string16 expected_autocorrect_word( |
858 base::UTF8ToUTF16(kTestCases[i].expected_result)); | 858 base::UTF8ToUTF16(kTestCases[i].expected_result)); |
859 base::string16 autocorrect_word = spell_check()->GetAutoCorrectionWord( | 859 base::string16 autocorrect_word = spell_check()->GetAutoCorrectionWord( |
860 misspelled_word, 0); | 860 misspelled_word, 0); |
861 | 861 |
862 // Check for spelling. | 862 // Check for spelling. |
863 EXPECT_EQ(expected_autocorrect_word, autocorrect_word); | 863 EXPECT_EQ(expected_autocorrect_word, autocorrect_word); |
864 } | 864 } |
865 } | 865 } |
(...skipping 21 matching lines...) Expand all Loading... |
887 // Hindi | 887 // Hindi |
888 "hi-IN", | 888 "hi-IN", |
889 L"\x0905\x0905\x0905\x0905\x0905\x0905\x0905\x0905\x0905\x0905", | 889 L"\x0905\x0905\x0905\x0905\x0905\x0905\x0905\x0905\x0905\x0905", |
890 }, { | 890 }, { |
891 // A misspelled word for Russian | 891 // A misspelled word for Russian |
892 "ru-RU", | 892 "ru-RU", |
893 L"\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430", | 893 L"\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430", |
894 }, | 894 }, |
895 }; | 895 }; |
896 | 896 |
897 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 897 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
898 ReinitializeSpellCheck(kTestCases[i].language); | 898 ReinitializeSpellCheck(kTestCases[i].language); |
899 | 899 |
900 base::string16 word(base::WideToUTF16(kTestCases[i].input)); | 900 base::string16 word(base::WideToUTF16(kTestCases[i].input)); |
901 int word_length = static_cast<int>(word.length()); | 901 int word_length = static_cast<int>(word.length()); |
902 int misspelling_start = 0; | 902 int misspelling_start = 0; |
903 int misspelling_length = 0; | 903 int misspelling_length = 0; |
904 bool result = spell_check()->SpellCheckWord(word.c_str(), | 904 bool result = spell_check()->SpellCheckWord(word.c_str(), |
905 word_length, | 905 word_length, |
906 0, | 906 0, |
907 &misspelling_start, | 907 &misspelling_start, |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1194 {"recencies", false}, | 1194 {"recencies", false}, |
1195 // Issue 140486 | 1195 // Issue 140486 |
1196 {"movie", true}, | 1196 {"movie", true}, |
1197 {"movies", true}, | 1197 {"movies", true}, |
1198 }; | 1198 }; |
1199 | 1199 |
1200 static const char* kLocales[] = { "en-GB", "en-US", "en-CA", "en-AU" }; | 1200 static const char* kLocales[] = { "en-GB", "en-US", "en-CA", "en-AU" }; |
1201 | 1201 |
1202 for (size_t j = 0; j < arraysize(kLocales); ++j) { | 1202 for (size_t j = 0; j < arraysize(kLocales); ++j) { |
1203 ReinitializeSpellCheck(kLocales[j]); | 1203 ReinitializeSpellCheck(kLocales[j]); |
1204 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 1204 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
1205 size_t input_length = 0; | 1205 size_t input_length = 0; |
1206 if (kTestCases[i].input != NULL) | 1206 if (kTestCases[i].input != NULL) |
1207 input_length = strlen(kTestCases[i].input); | 1207 input_length = strlen(kTestCases[i].input); |
1208 | 1208 |
1209 int misspelling_start = 0; | 1209 int misspelling_start = 0; |
1210 int misspelling_length = 0; | 1210 int misspelling_length = 0; |
1211 bool result = spell_check()->SpellCheckWord( | 1211 bool result = spell_check()->SpellCheckWord( |
1212 base::ASCIIToUTF16(kTestCases[i].input).c_str(), | 1212 base::ASCIIToUTF16(kTestCases[i].input).c_str(), |
1213 static_cast<int>(input_length), | 1213 static_cast<int>(input_length), |
1214 0, | 1214 0, |
(...skipping 22 matching lines...) Expand all Loading... |
1237 {"suckerbert", "cocksuckers", "en-US", true}, | 1237 {"suckerbert", "cocksuckers", "en-US", true}, |
1238 {"suckerbert", "cocksuckers", "en-CA", true}, | 1238 {"suckerbert", "cocksuckers", "en-CA", true}, |
1239 {"suckerbert", "cocksuckers", "en-AU", true}, | 1239 {"suckerbert", "cocksuckers", "en-AU", true}, |
1240 {"Batasunaa", "Batasuna", "ca-ES", true}, | 1240 {"Batasunaa", "Batasuna", "ca-ES", true}, |
1241 {"pornoo", "porno", "it-IT", true}, | 1241 {"pornoo", "porno", "it-IT", true}, |
1242 {"catass", "catas", "lt-LT", true}, | 1242 {"catass", "catas", "lt-LT", true}, |
1243 {"kuracc", "kurac", "sl-SI", true}, | 1243 {"kuracc", "kurac", "sl-SI", true}, |
1244 {"pittt", "pitt", "sv-SE", true}, | 1244 {"pittt", "pitt", "sv-SE", true}, |
1245 }; | 1245 }; |
1246 | 1246 |
1247 size_t test_cases_size = ARRAYSIZE_UNSAFE(kTestCases); | 1247 size_t test_cases_size = arraysize(kTestCases); |
1248 for (size_t i = 0; i < test_cases_size; ++i) { | 1248 for (size_t i = 0; i < test_cases_size; ++i) { |
1249 ReinitializeSpellCheck(kTestCases[i].locale); | 1249 ReinitializeSpellCheck(kTestCases[i].locale); |
1250 size_t suggestion_length = 0; | 1250 size_t suggestion_length = 0; |
1251 if (kTestCases[i].suggestion != NULL) | 1251 if (kTestCases[i].suggestion != NULL) |
1252 suggestion_length = strlen(kTestCases[i].suggestion); | 1252 suggestion_length = strlen(kTestCases[i].suggestion); |
1253 | 1253 |
1254 // First check that the NOSUGGEST flag didn't mark this word as not being in | 1254 // First check that the NOSUGGEST flag didn't mark this word as not being in |
1255 // the dictionary. | 1255 // the dictionary. |
1256 int misspelling_start = 0; | 1256 int misspelling_start = 0; |
1257 int misspelling_length = 0; | 1257 int misspelling_length = 0; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1331 // Initialization magic - call InitializeIfNeeded twice. The first one simply | 1331 // Initialization magic - call InitializeIfNeeded twice. The first one simply |
1332 // flags internal state that a dictionary was requested. The second one will | 1332 // flags internal state that a dictionary was requested. The second one will |
1333 // take the passed-in file and initialize hunspell with it. (The file was | 1333 // take the passed-in file and initialize hunspell with it. (The file was |
1334 // passed to hunspell in the ctor for the test fixture). | 1334 // passed to hunspell in the ctor for the test fixture). |
1335 // This needs to be done since we need to ensure the SpellingEngine object | 1335 // This needs to be done since we need to ensure the SpellingEngine object |
1336 // contained in |spellcheck_| from the test fixture does get initialized. | 1336 // contained in |spellcheck_| from the test fixture does get initialized. |
1337 // TODO(groby): Clean up this mess. | 1337 // TODO(groby): Clean up this mess. |
1338 InitializeIfNeeded(); | 1338 InitializeIfNeeded(); |
1339 ASSERT_FALSE(InitializeIfNeeded()); | 1339 ASSERT_FALSE(InitializeIfNeeded()); |
1340 | 1340 |
1341 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 1341 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
1342 bool result = CheckSpelling(kTestCases[i].word, 0); | 1342 bool result = CheckSpelling(kTestCases[i].word, 0); |
1343 EXPECT_EQ(kTestCases[i].expected_result, result) << | 1343 EXPECT_EQ(kTestCases[i].expected_result, result) << |
1344 "Failed test for " << kTestCases[i].word; | 1344 "Failed test for " << kTestCases[i].word; |
1345 } | 1345 } |
1346 } | 1346 } |
1347 | 1347 |
1348 // Chrome should not suggest "Othello" for "hellllo" or "identically" for | 1348 // Chrome should not suggest "Othello" for "hellllo" or "identically" for |
1349 // "accidently". | 1349 // "accidently". |
1350 TEST_F(SpellCheckTest, LogicalSuggestions) { | 1350 TEST_F(SpellCheckTest, LogicalSuggestions) { |
1351 static const struct { | 1351 static const struct { |
1352 const char* misspelled; | 1352 const char* misspelled; |
1353 const char* suggestion; | 1353 const char* suggestion; |
1354 } kTestCases[] = { | 1354 } kTestCases[] = { |
1355 { "hellllo", "hello" }, | 1355 { "hellllo", "hello" }, |
1356 { "accidently", "accidentally" } | 1356 { "accidently", "accidentally" } |
1357 }; | 1357 }; |
1358 | 1358 |
1359 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 1359 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
1360 int misspelling_start = 0; | 1360 int misspelling_start = 0; |
1361 int misspelling_length = 0; | 1361 int misspelling_length = 0; |
1362 std::vector<base::string16> suggestions; | 1362 std::vector<base::string16> suggestions; |
1363 EXPECT_FALSE(spell_check()->SpellCheckWord( | 1363 EXPECT_FALSE(spell_check()->SpellCheckWord( |
1364 base::ASCIIToUTF16(kTestCases[i].misspelled).c_str(), | 1364 base::ASCIIToUTF16(kTestCases[i].misspelled).c_str(), |
1365 strlen(kTestCases[i].misspelled), | 1365 strlen(kTestCases[i].misspelled), |
1366 0, | 1366 0, |
1367 &misspelling_start, | 1367 &misspelling_start, |
1368 &misspelling_length, | 1368 &misspelling_length, |
1369 &suggestions)); | 1369 &suggestions)); |
1370 EXPECT_GE(suggestions.size(), static_cast<size_t>(1)); | 1370 EXPECT_GE(suggestions.size(), static_cast<size_t>(1)); |
1371 if (suggestions.size() > 0) | 1371 if (suggestions.size() > 0) |
1372 EXPECT_EQ(suggestions[0], base::ASCIIToUTF16(kTestCases[i].suggestion)); | 1372 EXPECT_EQ(suggestions[0], base::ASCIIToUTF16(kTestCases[i].suggestion)); |
1373 } | 1373 } |
1374 } | 1374 } |
OLD | NEW |