| 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 "webkit/glue/webkit_glue.h" | 5 #include "webkit/glue/webkit_glue.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/sys_string_conversions.h" |
| 10 #include "chrome/browser/spellchecker.h" | 11 #include "chrome/browser/spellchecker.h" |
| 12 #include "chrome/browser/spellchecker_platform_engine.h" |
| 11 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 15 |
| 14 namespace { | 16 namespace { |
| 15 const FilePath::CharType kTempCustomDictionaryFile[] = | 17 const FilePath::CharType kTempCustomDictionaryFile[] = |
| 16 FILE_PATH_LITERAL("temp_custom_dictionary.txt"); | 18 FILE_PATH_LITERAL("temp_custom_dictionary.txt"); |
| 17 } // namespace | 19 } // namespace |
| 18 | 20 |
| 19 class SpellCheckTest : public testing::Test { | 21 class SpellCheckTest : public testing::Test { |
| 20 private: | 22 private: |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 275 |
| 274 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 276 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
| 275 size_t input_length = 0; | 277 size_t input_length = 0; |
| 276 if (kTestCases[i].input != NULL) { | 278 if (kTestCases[i].input != NULL) { |
| 277 input_length = wcslen(kTestCases[i].input); | 279 input_length = wcslen(kTestCases[i].input); |
| 278 } | 280 } |
| 279 int misspelling_start; | 281 int misspelling_start; |
| 280 int misspelling_length; | 282 int misspelling_length; |
| 281 bool result = spell_checker->SpellCheckWord(kTestCases[i].input, | 283 bool result = spell_checker->SpellCheckWord(kTestCases[i].input, |
| 282 static_cast<int>(input_length), | 284 static_cast<int>(input_length), |
| 285 0, |
| 283 &misspelling_start, | 286 &misspelling_start, |
| 284 &misspelling_length, NULL); | 287 &misspelling_length, NULL); |
| 285 | 288 |
| 286 EXPECT_EQ(kTestCases[i].expected_result, result); | 289 EXPECT_EQ(kTestCases[i].expected_result, result); |
| 287 EXPECT_EQ(kTestCases[i].misspelling_start, misspelling_start); | 290 EXPECT_EQ(kTestCases[i].misspelling_start, misspelling_start); |
| 288 EXPECT_EQ(kTestCases[i].misspelling_length, misspelling_length); | 291 EXPECT_EQ(kTestCases[i].misspelling_length, misspelling_length); |
| 289 } | 292 } |
| 290 } | 293 } |
| 291 | 294 |
| 292 | 295 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 {L"changable", false, 0,0,L"changeable"}, | 373 {L"changable", false, 0,0,L"changeable"}, |
| 371 {L"cheif", false, 0,0,L"chief"}, | 374 {L"cheif", false, 0,0,L"chief"}, |
| 372 {L"citezen", false, 0,0,L"citizen"}, | 375 {L"citezen", false, 0,0,L"citizen"}, |
| 373 {L"collaegue", false, 0,0,L"colleague"}, | 376 {L"collaegue", false, 0,0,L"colleague"}, |
| 374 {L"colum", false, 0,0,L"column"}, | 377 {L"colum", false, 0,0,L"column"}, |
| 375 {L"comming", false, 0,0,L"coming"}, | 378 {L"comming", false, 0,0,L"coming"}, |
| 376 {L"commited", false, 0,0,L"committed"}, | 379 {L"commited", false, 0,0,L"committed"}, |
| 377 {L"compitition", false, 0,0,L"competition"}, | 380 {L"compitition", false, 0,0,L"competition"}, |
| 378 {L"conceed", false, 0,0,L"concede"}, | 381 {L"conceed", false, 0,0,L"concede"}, |
| 379 {L"congradulate", false, 0,0,L"congratulate"}, | 382 {L"congradulate", false, 0,0,L"congratulate"}, |
| 380 // TODO(pwicks): This fails as a result of 13432. | 383 {L"consciencious", false, 0, 0, L"conscientious"}, |
| 381 // Once that is fixed, uncomment this. | |
| 382 // {L"consciencious", false, 0,0,L"conscientious"}, | |
| 383 {L"concious", false, 0,0,L"conscious"}, | 384 {L"concious", false, 0,0,L"conscious"}, |
| 384 {L"concensus", false, 0,0,L"consensus"}, | 385 {L"concensus", false, 0,0,L"consensus"}, |
| 385 {L"contraversy", false, 0,0,L"controversy"}, | 386 {L"contraversy", false, 0,0,L"controversy"}, |
| 386 {L"conveniance", false, 0,0,L"convenience"}, | 387 {L"conveniance", false, 0,0,L"convenience"}, |
| 387 {L"critecize", false, 0,0,L"criticize"}, | 388 {L"critecize", false, 0,0,L"criticize"}, |
| 388 {L"dacquiri", false, 0,0,L"daiquiri"}, | 389 {L"dacquiri", false, 0,0,L"daiquiri"}, |
| 389 {L"decieve", false, 0,0,L"deceive"}, | 390 {L"decieve", false, 0,0,L"deceive"}, |
| 390 {L"dicide", false, 0,0,L"decide"}, | 391 {L"dicide", false, 0,0,L"decide"}, |
| 391 {L"definate", false, 0,0,L"definite"}, | 392 {L"definate", false, 0,0,L"definite"}, |
| 392 {L"definitly", false, 0,0,L"definitely"}, | 393 {L"definitly", false, 0,0,L"definitely"}, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 {L"hygene", false, 0,0,L"hygiene"}, | 446 {L"hygene", false, 0,0,L"hygiene"}, |
| 446 {L"hipocrit", false, 0,0,L"hypocrite"}, | 447 {L"hipocrit", false, 0,0,L"hypocrite"}, |
| 447 {L"idenity", false, 0,0,L"identity"}, | 448 {L"idenity", false, 0,0,L"identity"}, |
| 448 {L"ignorence", false, 0,0,L"ignorance"}, | 449 {L"ignorence", false, 0,0,L"ignorance"}, |
| 449 {L"imaginery", false, 0,0,L"imaginary"}, | 450 {L"imaginery", false, 0,0,L"imaginary"}, |
| 450 {L"immitate", false, 0,0,L"imitate"}, | 451 {L"immitate", false, 0,0,L"imitate"}, |
| 451 {L"immitation", false, 0,0,L"imitation"}, | 452 {L"immitation", false, 0,0,L"imitation"}, |
| 452 {L"imediately", false, 0,0,L"immediately"}, | 453 {L"imediately", false, 0,0,L"immediately"}, |
| 453 {L"incidently", false, 0,0,L"incidentally"}, | 454 {L"incidently", false, 0,0,L"incidentally"}, |
| 454 {L"independant", false, 0,0,L"independent"}, | 455 {L"independant", false, 0,0,L"independent"}, |
| 455 // TODO(pwicks): This fails as a result of 13432. | 456 {L"indispensible", false, 0, 0, L"indispensable"}, |
| 456 // Once that is fixed, uncomment this. | |
| 457 // {L"indispensible", false, 0,0,L"indispensable"}, | |
| 458 {L"innoculate", false, 0,0,L"inoculate"}, | 457 {L"innoculate", false, 0,0,L"inoculate"}, |
| 459 {L"inteligence", false, 0,0,L"intelligence"}, | 458 {L"inteligence", false, 0,0,L"intelligence"}, |
| 460 {L"intresting", false, 0,0,L"interesting"}, | 459 {L"intresting", false, 0,0,L"interesting"}, |
| 461 {L"interuption", false, 0,0,L"interruption"}, | 460 {L"interuption", false, 0,0,L"interruption"}, |
| 462 {L"irrelevent", false, 0,0,L"irrelevant"}, | 461 {L"irrelevent", false, 0,0,L"irrelevant"}, |
| 463 {L"irritible", false, 0,0,L"irritable"}, | 462 {L"irritible", false, 0,0,L"irritable"}, |
| 464 {L"iland", false, 0,0,L"island"}, | 463 {L"iland", false, 0,0,L"island"}, |
| 465 {L"jellous", false, 0,0,L"jealous"}, | 464 {L"jellous", false, 0,0,L"jealous"}, |
| 466 {L"knowlege", false, 0,0,L"knowledge"}, | 465 {L"knowlege", false, 0,0,L"knowledge"}, |
| 467 {L"labratory", false, 0,0,L"laboratory"}, | 466 {L"labratory", false, 0,0,L"laboratory"}, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 {L"practicle", false, 0,0,L"practical"}, | 525 {L"practicle", false, 0,0,L"practical"}, |
| 527 {L"preceed", false, 0,0,L"precede"}, | 526 {L"preceed", false, 0,0,L"precede"}, |
| 528 {L"predjudice", false, 0,0,L"prejudice"}, | 527 {L"predjudice", false, 0,0,L"prejudice"}, |
| 529 {L"presance", false, 0,0,L"presence"}, | 528 {L"presance", false, 0,0,L"presence"}, |
| 530 {L"privelege", false, 0,0,L"privilege"}, | 529 {L"privelege", false, 0,0,L"privilege"}, |
| 531 // This one should probably work. It does in FF and Hunspell. | 530 // This one should probably work. It does in FF and Hunspell. |
| 532 // {L"probly", false, 0,0,L"probably"}, | 531 // {L"probly", false, 0,0,L"probably"}, |
| 533 {L"proffesional", false, 0,0,L"professional"}, | 532 {L"proffesional", false, 0,0,L"professional"}, |
| 534 {L"professer", false, 0,0,L"professor"}, | 533 {L"professer", false, 0,0,L"professor"}, |
| 535 {L"promiss", false, 0,0,L"promise"}, | 534 {L"promiss", false, 0,0,L"promise"}, |
| 536 // TODO(pwicks): This fails as a result of 13432. | 535 {L"pronounciation", false, 0, 0, L"pronunciation"}, |
| 537 // Once that is fixed, uncomment this. | |
| 538 // {L"pronounciation", false, 0,0,L"pronunciation"}, | |
| 539 {L"prufe", false, 0,0,L"proof"}, | 536 {L"prufe", false, 0,0,L"proof"}, |
| 540 {L"psycology", false, 0,0,L"psychology"}, | 537 {L"psycology", false, 0,0,L"psychology"}, |
| 541 {L"publically", false, 0,0,L"publicly"}, | 538 {L"publically", false, 0,0,L"publicly"}, |
| 542 {L"quanity", false, 0,0,L"quantity"}, | 539 {L"quanity", false, 0,0,L"quantity"}, |
| 543 {L"quarentine", false, 0,0,L"quarantine"}, | 540 {L"quarentine", false, 0,0,L"quarantine"}, |
| 544 {L"questionaire", false, 0,0,L"questionnaire"}, | 541 {L"questionaire", false, 0,0,L"questionnaire"}, |
| 545 {L"readible", false, 0,0,L"readable"}, | 542 {L"readible", false, 0,0,L"readable"}, |
| 546 {L"realy", false, 0,0,L"really"}, | 543 {L"realy", false, 0,0,L"really"}, |
| 547 {L"recieve", false, 0,0,L"receive"}, | 544 {L"recieve", false, 0,0,L"receive"}, |
| 548 {L"reciept", false, 0,0,L"receipt"}, | 545 {L"reciept", false, 0,0,L"receipt"}, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 621 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
| 625 std::vector<std::wstring> suggestions; | 622 std::vector<std::wstring> suggestions; |
| 626 size_t input_length = 0; | 623 size_t input_length = 0; |
| 627 if (kTestCases[i].input != NULL) { | 624 if (kTestCases[i].input != NULL) { |
| 628 input_length = wcslen(kTestCases[i].input); | 625 input_length = wcslen(kTestCases[i].input); |
| 629 } | 626 } |
| 630 int misspelling_start; | 627 int misspelling_start; |
| 631 int misspelling_length; | 628 int misspelling_length; |
| 632 bool result = spell_checker->SpellCheckWord(kTestCases[i].input, | 629 bool result = spell_checker->SpellCheckWord(kTestCases[i].input, |
| 633 static_cast<int>(input_length), | 630 static_cast<int>(input_length), |
| 631 0, |
| 634 &misspelling_start, | 632 &misspelling_start, |
| 635 &misspelling_length, | 633 &misspelling_length, |
| 636 &suggestions); | 634 &suggestions); |
| 637 | 635 |
| 638 // Check for spelling. | 636 // Check for spelling. |
| 639 EXPECT_EQ(kTestCases[i].expected_result, result); | 637 EXPECT_EQ(kTestCases[i].expected_result, result); |
| 640 | 638 |
| 641 // Check if the suggested words occur. | 639 // Check if the suggested words occur. |
| 642 bool suggested_word_is_present = false; | 640 bool suggested_word_is_present = false; |
| 643 for (int j=0; j < static_cast<int>(suggestions.size()); j++) { | 641 for (int j=0; j < static_cast<int>(suggestions.size()); j++) { |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 hunspell_directory, kTestCases[i].language, NULL, FilePath())); | 890 hunspell_directory, kTestCases[i].language, NULL, FilePath())); |
| 893 | 891 |
| 894 size_t input_length = 0; | 892 size_t input_length = 0; |
| 895 if (kTestCases[i].input != NULL) | 893 if (kTestCases[i].input != NULL) |
| 896 input_length = wcslen(kTestCases[i].input); | 894 input_length = wcslen(kTestCases[i].input); |
| 897 | 895 |
| 898 int misspelling_start = 0; | 896 int misspelling_start = 0; |
| 899 int misspelling_length = 0; | 897 int misspelling_length = 0; |
| 900 bool result = spell_checker->SpellCheckWord(kTestCases[i].input, | 898 bool result = spell_checker->SpellCheckWord(kTestCases[i].input, |
| 901 static_cast<int>(input_length), | 899 static_cast<int>(input_length), |
| 900 0, |
| 902 &misspelling_start, | 901 &misspelling_start, |
| 903 &misspelling_length, NULL); | 902 &misspelling_length, NULL); |
| 904 | 903 |
| 905 EXPECT_EQ(true, result) << kTestCases[i].language; | 904 EXPECT_EQ(true, result) << kTestCases[i].language; |
| 906 EXPECT_EQ(0, misspelling_start); | 905 EXPECT_EQ(0, misspelling_start); |
| 907 EXPECT_EQ(0, misspelling_length); | 906 EXPECT_EQ(0, misspelling_length); |
| 908 } | 907 } |
| 909 } | 908 } |
| 910 | 909 |
| 911 // This test Adds words to the SpellChecker and veifies that it remembers them. | 910 // This test Adds words to the SpellChecker and veifies that it remembers them. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 933 // Now check whether it is added to Spellchecker. | 932 // Now check whether it is added to Spellchecker. |
| 934 std::vector<std::wstring> suggestions; | 933 std::vector<std::wstring> suggestions; |
| 935 size_t input_length = 0; | 934 size_t input_length = 0; |
| 936 if (kTestCases[i].word_to_add != NULL) { | 935 if (kTestCases[i].word_to_add != NULL) { |
| 937 input_length = wcslen(kTestCases[i].word_to_add); | 936 input_length = wcslen(kTestCases[i].word_to_add); |
| 938 } | 937 } |
| 939 int misspelling_start; | 938 int misspelling_start; |
| 940 int misspelling_length; | 939 int misspelling_length; |
| 941 bool result = spell_checker->SpellCheckWord(kTestCases[i].word_to_add, | 940 bool result = spell_checker->SpellCheckWord(kTestCases[i].word_to_add, |
| 942 static_cast<int>(input_length), | 941 static_cast<int>(input_length), |
| 942 0, |
| 943 &misspelling_start, | 943 &misspelling_start, |
| 944 &misspelling_length, | 944 &misspelling_length, |
| 945 &suggestions); | 945 &suggestions); |
| 946 | 946 |
| 947 // Check for spelling. | 947 // Check for spelling. |
| 948 EXPECT_TRUE(result); | 948 EXPECT_TRUE(result); |
| 949 } | 949 } |
| 950 | 950 |
| 951 // Now initialize another spellchecker to see that AddToWord is permanent. | 951 // Now initialize another spellchecker to see that AddToWord is permanent. |
| 952 scoped_refptr<SpellChecker> spell_checker_new(new SpellChecker( | 952 scoped_refptr<SpellChecker> spell_checker_new(new SpellChecker( |
| 953 hunspell_directory, "en-US", NULL, custom_dictionary_file)); | 953 hunspell_directory, "en-US", NULL, custom_dictionary_file)); |
| 954 | 954 |
| 955 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 955 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
| 956 // Now check whether it is added to Spellchecker. | 956 // Now check whether it is added to Spellchecker. |
| 957 std::vector<std::wstring> suggestions; | 957 std::vector<std::wstring> suggestions; |
| 958 size_t input_length = 0; | 958 size_t input_length = 0; |
| 959 if (kTestCases[i].word_to_add != NULL) { | 959 if (kTestCases[i].word_to_add != NULL) { |
| 960 input_length = wcslen(kTestCases[i].word_to_add); | 960 input_length = wcslen(kTestCases[i].word_to_add); |
| 961 } | 961 } |
| 962 int misspelling_start; | 962 int misspelling_start; |
| 963 int misspelling_length; | 963 int misspelling_length; |
| 964 bool result = spell_checker_new->SpellCheckWord( | 964 bool result = spell_checker_new->SpellCheckWord( |
| 965 kTestCases[i].word_to_add, | 965 kTestCases[i].word_to_add, |
| 966 static_cast<int>(input_length), | 966 static_cast<int>(input_length), |
| 967 0, |
| 967 &misspelling_start, | 968 &misspelling_start, |
| 968 &misspelling_length, | 969 &misspelling_length, |
| 969 &suggestions); | 970 &suggestions); |
| 970 | 971 |
| 971 // Check for spelling. | 972 // Check for spelling. |
| 972 EXPECT_TRUE(result); | 973 EXPECT_TRUE(result); |
| 973 } | 974 } |
| 974 | 975 |
| 975 // Remove the temp custom dictionary file. | 976 // Remove the temp custom dictionary file. |
| 976 file_util::Delete(custom_dictionary_file, false); | 977 file_util::Delete(custom_dictionary_file, false); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1023 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCasesToBeTested); ++i) { | 1024 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCasesToBeTested); ++i) { |
| 1024 std::vector<std::wstring> suggestions; | 1025 std::vector<std::wstring> suggestions; |
| 1025 size_t input_length = 0; | 1026 size_t input_length = 0; |
| 1026 if (kTestCasesToBeTested[i].input != NULL) { | 1027 if (kTestCasesToBeTested[i].input != NULL) { |
| 1027 input_length = wcslen(kTestCasesToBeTested[i].input); | 1028 input_length = wcslen(kTestCasesToBeTested[i].input); |
| 1028 } | 1029 } |
| 1029 int misspelling_start; | 1030 int misspelling_start; |
| 1030 int misspelling_length; | 1031 int misspelling_length; |
| 1031 bool result = spell_checker->SpellCheckWord(kTestCasesToBeTested[i].input, | 1032 bool result = spell_checker->SpellCheckWord(kTestCasesToBeTested[i].input, |
| 1032 static_cast<int>(input_length), | 1033 static_cast<int>(input_length), |
| 1034 0, |
| 1033 &misspelling_start, | 1035 &misspelling_start, |
| 1034 &misspelling_length, | 1036 &misspelling_length, |
| 1035 &suggestions); | 1037 &suggestions); |
| 1036 | 1038 |
| 1037 // Check for spelling. | 1039 // Check for spelling. |
| 1038 EXPECT_EQ(result, kTestCasesToBeTested[i].expected_result); | 1040 EXPECT_EQ(result, kTestCasesToBeTested[i].expected_result); |
| 1039 | 1041 |
| 1040 // Check if the suggested words occur. | 1042 // Check if the suggested words occur. |
| 1041 bool suggested_word_is_present = false; | 1043 bool suggested_word_is_present = false; |
| 1042 for (int j=0; j < static_cast<int>(suggestions.size()); j++) { | 1044 for (int j=0; j < static_cast<int>(suggestions.size()); j++) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1074 ASSERT_FALSE(hunspell_directory.empty()); | 1076 ASSERT_FALSE(hunspell_directory.empty()); |
| 1075 | 1077 |
| 1076 scoped_refptr<SpellChecker> spell_checker(new SpellChecker( | 1078 scoped_refptr<SpellChecker> spell_checker(new SpellChecker( |
| 1077 hunspell_directory, "en-US", NULL, FilePath())); | 1079 hunspell_directory, "en-US", NULL, FilePath())); |
| 1078 spell_checker->EnableAutoSpellCorrect(true); | 1080 spell_checker->EnableAutoSpellCorrect(true); |
| 1079 | 1081 |
| 1080 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 1082 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
| 1081 std::wstring misspelled_word(kTestCases[i].input); | 1083 std::wstring misspelled_word(kTestCases[i].input); |
| 1082 std::wstring expected_autocorrect_word(kTestCases[i].expected_result); | 1084 std::wstring expected_autocorrect_word(kTestCases[i].expected_result); |
| 1083 std::wstring autocorrect_word; | 1085 std::wstring autocorrect_word; |
| 1084 spell_checker->GetAutoCorrectionWord(misspelled_word, &autocorrect_word); | 1086 spell_checker->GetAutoCorrectionWord(misspelled_word, 0, &autocorrect_word); |
| 1085 | 1087 |
| 1086 // Check for spelling. | 1088 // Check for spelling. |
| 1087 EXPECT_EQ(expected_autocorrect_word, autocorrect_word); | 1089 EXPECT_EQ(expected_autocorrect_word, autocorrect_word); |
| 1088 } | 1090 } |
| 1089 } | 1091 } |
| 1092 |
| 1093 #if defined(OS_MACOSX) |
| 1094 // Tests that words are properly ignored. Currently only enabled on OS X as it |
| 1095 // is the only platform to support ignoring words. Note that in this test, we |
| 1096 // supply a non-zero doc_tag, in order to test that ignored words are matched to |
| 1097 // the correct document. |
| 1098 TEST_F(SpellCheckTest, IgnoreWords_EN_US) { |
| 1099 static const struct { |
| 1100 // A misspelled word. |
| 1101 const wchar_t* input; |
| 1102 bool input_result; |
| 1103 } kTestCases[] = { |
| 1104 {L"teh",false}, |
| 1105 {L"moer", false}, |
| 1106 {L"watre",false}, |
| 1107 {L"noen", false}, |
| 1108 }; |
| 1109 |
| 1110 FilePath hunspell_directory = GetHunspellDirectory(); |
| 1111 ASSERT_FALSE(hunspell_directory.empty()); |
| 1112 |
| 1113 scoped_refptr<SpellChecker> spell_checker(new SpellChecker( |
| 1114 hunspell_directory, "en-US", NULL, FilePath())); |
| 1115 |
| 1116 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
| 1117 std::wstring word(kTestCases[i].input); |
| 1118 std::string misspelled_word = base::SysWideToUTF8(word); |
| 1119 std::vector<std::wstring> suggestions; |
| 1120 size_t input_length = 0; |
| 1121 if (kTestCases[i].input != NULL) { |
| 1122 input_length = wcslen(kTestCases[i].input); |
| 1123 } |
| 1124 int misspelling_start; |
| 1125 int misspelling_length; |
| 1126 |
| 1127 int doc_tag = SpellCheckerPlatform::GetDocumentTag(); |
| 1128 bool result = spell_checker->SpellCheckWord(kTestCases[i].input, |
| 1129 static_cast<int>(input_length), |
| 1130 doc_tag, |
| 1131 &misspelling_start, |
| 1132 &misspelling_length, |
| 1133 &suggestions); |
| 1134 |
| 1135 // The word should show up as misspelled. |
| 1136 EXPECT_EQ(kTestCases[i].input_result, result); |
| 1137 |
| 1138 // Ignore the word. |
| 1139 SpellCheckerPlatform::IgnoreWord(misspelled_word); |
| 1140 |
| 1141 // Spellcheck again. |
| 1142 result = spell_checker->SpellCheckWord(kTestCases[i].input, |
| 1143 static_cast<int>(input_length), |
| 1144 doc_tag, |
| 1145 &misspelling_start, |
| 1146 &misspelling_length, |
| 1147 &suggestions); |
| 1148 |
| 1149 // The word should now show up as correctly spelled. |
| 1150 EXPECT_EQ(!(kTestCases[i].input_result), result); |
| 1151 |
| 1152 // Close the docuemnt. Any words that we had previously ignored should no |
| 1153 // longer be ignored and thus should show up as misspelled. |
| 1154 SpellCheckerPlatform::CloseDocumentWithTag(doc_tag); |
| 1155 |
| 1156 // Spellcheck one more time. |
| 1157 result = spell_checker->SpellCheckWord(kTestCases[i].input, |
| 1158 static_cast<int>(input_length), |
| 1159 doc_tag, |
| 1160 &misspelling_start, |
| 1161 &misspelling_length, |
| 1162 &suggestions); |
| 1163 |
| 1164 // The word should now show be spelled wrong again |
| 1165 EXPECT_EQ(kTestCases[i].input_result, result); |
| 1166 } |
| 1167 } // Test IgnoreWords_EN_US |
| 1168 #endif // OS_MACOSX |
| OLD | NEW |