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 "chrome/browser/spellchecker.h" | 10 #include "chrome/browser/spellchecker.h" |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 {L"ifmmp:ifmmp", false, 0, 11}, | 249 {L"ifmmp:ifmmp", false, 0, 11}, |
250 }; | 250 }; |
251 | 251 |
252 std::wstring hunspell_directory; | 252 std::wstring hunspell_directory; |
253 ASSERT_TRUE(PathService::Get(chrome::DIR_APP_DICTIONARIES, | 253 ASSERT_TRUE(PathService::Get(chrome::DIR_APP_DICTIONARIES, |
254 &hunspell_directory)); | 254 &hunspell_directory)); |
255 | 255 |
256 scoped_refptr<SpellChecker> spell_checker(new SpellChecker( | 256 scoped_refptr<SpellChecker> spell_checker(new SpellChecker( |
257 hunspell_directory, L"en-US", NULL, std::wstring())); | 257 hunspell_directory, L"en-US", NULL, std::wstring())); |
258 | 258 |
259 for (int i = 0; i < arraysize(kTestCases); i++) { | 259 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
260 size_t input_length = 0; | 260 size_t input_length = 0; |
261 if (kTestCases[i].input != NULL) { | 261 if (kTestCases[i].input != NULL) { |
262 input_length = wcslen(kTestCases[i].input); | 262 input_length = wcslen(kTestCases[i].input); |
263 } | 263 } |
264 int misspelling_start; | 264 int misspelling_start; |
265 int misspelling_length; | 265 int misspelling_length; |
266 bool result = spell_checker->SpellCheckWord(kTestCases[i].input, | 266 bool result = spell_checker->SpellCheckWord(kTestCases[i].input, |
267 static_cast<int>(input_length), | 267 static_cast<int>(input_length), |
268 &misspelling_start, | 268 &misspelling_start, |
269 &misspelling_length, NULL); | 269 &misspelling_length, NULL); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 // TODO (Sidchat): add many more examples. | 303 // TODO (Sidchat): add many more examples. |
304 }; | 304 }; |
305 | 305 |
306 std::wstring hunspell_directory; | 306 std::wstring hunspell_directory; |
307 ASSERT_TRUE(PathService::Get(chrome::DIR_APP_DICTIONARIES, | 307 ASSERT_TRUE(PathService::Get(chrome::DIR_APP_DICTIONARIES, |
308 &hunspell_directory)); | 308 &hunspell_directory)); |
309 | 309 |
310 scoped_refptr<SpellChecker> spell_checker(new SpellChecker( | 310 scoped_refptr<SpellChecker> spell_checker(new SpellChecker( |
311 hunspell_directory, L"en-US", NULL, std::wstring())); | 311 hunspell_directory, L"en-US", NULL, std::wstring())); |
312 | 312 |
313 for (int i = 0; i < arraysize(kTestCases); i++) { | 313 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
314 std::vector<std::wstring> suggestions; | 314 std::vector<std::wstring> suggestions; |
315 size_t input_length = 0; | 315 size_t input_length = 0; |
316 if (kTestCases[i].input != NULL) { | 316 if (kTestCases[i].input != NULL) { |
317 input_length = wcslen(kTestCases[i].input); | 317 input_length = wcslen(kTestCases[i].input); |
318 } | 318 } |
319 int misspelling_start; | 319 int misspelling_start; |
320 int misspelling_length; | 320 int misspelling_length; |
321 bool result = spell_checker->SpellCheckWord(kTestCases[i].input, | 321 bool result = spell_checker->SpellCheckWord(kTestCases[i].input, |
322 static_cast<int>(input_length), | 322 static_cast<int>(input_length), |
323 &misspelling_start, | 323 &misspelling_start, |
(...skipping 27 matching lines...) Expand all Loading... |
351 {L"Googler"}, | 351 {L"Googler"}, |
352 }; | 352 }; |
353 | 353 |
354 std::wstring hunspell_directory; | 354 std::wstring hunspell_directory; |
355 ASSERT_TRUE(PathService::Get(chrome::DIR_APP_DICTIONARIES, | 355 ASSERT_TRUE(PathService::Get(chrome::DIR_APP_DICTIONARIES, |
356 &hunspell_directory)); | 356 &hunspell_directory)); |
357 | 357 |
358 scoped_refptr<SpellChecker> spell_checker(new SpellChecker( | 358 scoped_refptr<SpellChecker> spell_checker(new SpellChecker( |
359 hunspell_directory, L"en-US", NULL, kTempCustomDictionaryFile)); | 359 hunspell_directory, L"en-US", NULL, kTempCustomDictionaryFile)); |
360 | 360 |
361 for (int i = 0; i < arraysize(kTestCases); i++) { | 361 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
362 // Add the word to spellchecker. | 362 // Add the word to spellchecker. |
363 spell_checker->AddWord(std::wstring(kTestCases[i].word_to_add)); | 363 spell_checker->AddWord(std::wstring(kTestCases[i].word_to_add)); |
364 | 364 |
365 // Now check whether it is added to Spellchecker. | 365 // Now check whether it is added to Spellchecker. |
366 std::vector<std::wstring> suggestions; | 366 std::vector<std::wstring> suggestions; |
367 size_t input_length = 0; | 367 size_t input_length = 0; |
368 if (kTestCases[i].word_to_add != NULL) { | 368 if (kTestCases[i].word_to_add != NULL) { |
369 input_length = wcslen(kTestCases[i].word_to_add); | 369 input_length = wcslen(kTestCases[i].word_to_add); |
370 } | 370 } |
371 int misspelling_start; | 371 int misspelling_start; |
372 int misspelling_length; | 372 int misspelling_length; |
373 bool result = spell_checker->SpellCheckWord(kTestCases[i].word_to_add, | 373 bool result = spell_checker->SpellCheckWord(kTestCases[i].word_to_add, |
374 static_cast<int>(input_length), | 374 static_cast<int>(input_length), |
375 &misspelling_start, | 375 &misspelling_start, |
376 &misspelling_length, | 376 &misspelling_length, |
377 &suggestions); | 377 &suggestions); |
378 | 378 |
379 // Check for spelling. | 379 // Check for spelling. |
380 EXPECT_TRUE(result); | 380 EXPECT_TRUE(result); |
381 } | 381 } |
382 | 382 |
383 // Now initialize another spellchecker to see that AddToWord is permanent. | 383 // Now initialize another spellchecker to see that AddToWord is permanent. |
384 scoped_refptr<SpellChecker> spell_checker_new(new SpellChecker( | 384 scoped_refptr<SpellChecker> spell_checker_new(new SpellChecker( |
385 hunspell_directory, L"en-US", NULL, kTempCustomDictionaryFile)); | 385 hunspell_directory, L"en-US", NULL, kTempCustomDictionaryFile)); |
386 | 386 |
387 for (int i = 0; i < arraysize(kTestCases); i++) { | 387 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
388 // Now check whether it is added to Spellchecker. | 388 // Now check whether it is added to Spellchecker. |
389 std::vector<std::wstring> suggestions; | 389 std::vector<std::wstring> suggestions; |
390 size_t input_length = 0; | 390 size_t input_length = 0; |
391 if (kTestCases[i].word_to_add != NULL) { | 391 if (kTestCases[i].word_to_add != NULL) { |
392 input_length = wcslen(kTestCases[i].word_to_add); | 392 input_length = wcslen(kTestCases[i].word_to_add); |
393 } | 393 } |
394 int misspelling_start; | 394 int misspelling_start; |
395 int misspelling_length; | 395 int misspelling_length; |
396 bool result = spell_checker_new->SpellCheckWord( | 396 bool result = spell_checker_new->SpellCheckWord( |
397 kTestCases[i].word_to_add, | 397 kTestCases[i].word_to_add, |
(...skipping 21 matching lines...) Expand all Loading... |
419 {L"Googler"}, | 419 {L"Googler"}, |
420 }; | 420 }; |
421 | 421 |
422 std::wstring hunspell_directory; | 422 std::wstring hunspell_directory; |
423 ASSERT_TRUE(PathService::Get(chrome::DIR_APP_DICTIONARIES, | 423 ASSERT_TRUE(PathService::Get(chrome::DIR_APP_DICTIONARIES, |
424 &hunspell_directory)); | 424 &hunspell_directory)); |
425 | 425 |
426 scoped_refptr<SpellChecker> spell_checker(new SpellChecker( | 426 scoped_refptr<SpellChecker> spell_checker(new SpellChecker( |
427 hunspell_directory, L"en-US", NULL, kTempCustomDictionaryFile)); | 427 hunspell_directory, L"en-US", NULL, kTempCustomDictionaryFile)); |
428 | 428 |
429 for (int i = 0; i < arraysize(kTestCases); i++) { | 429 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
430 // Add the word to spellchecker. | 430 // Add the word to spellchecker. |
431 spell_checker->AddWord(std::wstring(kTestCases[i].word_to_add)); | 431 spell_checker->AddWord(std::wstring(kTestCases[i].word_to_add)); |
432 } | 432 } |
433 | 433 |
434 // Now check to see whether the custom words are suggested for | 434 // Now check to see whether the custom words are suggested for |
435 // misspelled but similar words. | 435 // misspelled but similar words. |
436 static const struct { | 436 static const struct { |
437 // A string to be tested. | 437 // A string to be tested. |
438 const wchar_t* input; | 438 const wchar_t* input; |
439 // An expected result for this test case. | 439 // An expected result for this test case. |
440 // * true: the input string does not have any invalid words. | 440 // * true: the input string does not have any invalid words. |
441 // * false: the input string has one or more invalid words. | 441 // * false: the input string has one or more invalid words. |
442 bool expected_result; | 442 bool expected_result; |
443 // The position and the length of the first invalid word. | 443 // The position and the length of the first invalid word. |
444 int misspelling_start; | 444 int misspelling_start; |
445 int misspelling_length; | 445 int misspelling_length; |
446 | 446 |
447 // A suggested word that should occur. | 447 // A suggested word that should occur. |
448 const wchar_t* suggested_word; | 448 const wchar_t* suggested_word; |
449 } kTestCasesToBeTested[] = { | 449 } kTestCasesToBeTested[] = { |
450 {L"oogley", false, 0, 0, L"Googley"}, | 450 {L"oogley", false, 0, 0, L"Googley"}, |
451 {L"oogler", false, 0, 0, L"Googler"}, | 451 {L"oogler", false, 0, 0, L"Googler"}, |
452 {L"oogleplex", false, 0, 0, L"Googleplex"}, | 452 {L"oogleplex", false, 0, 0, L"Googleplex"}, |
453 }; | 453 }; |
454 | 454 |
455 for (int i = 0; i < arraysize(kTestCasesToBeTested); i++) { | 455 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCasesToBeTested); ++i) { |
456 std::vector<std::wstring> suggestions; | 456 std::vector<std::wstring> suggestions; |
457 size_t input_length = 0; | 457 size_t input_length = 0; |
458 if (kTestCasesToBeTested[i].input != NULL) { | 458 if (kTestCasesToBeTested[i].input != NULL) { |
459 input_length = wcslen(kTestCasesToBeTested[i].input); | 459 input_length = wcslen(kTestCasesToBeTested[i].input); |
460 } | 460 } |
461 int misspelling_start; | 461 int misspelling_start; |
462 int misspelling_length; | 462 int misspelling_length; |
463 bool result = spell_checker->SpellCheckWord(kTestCasesToBeTested[i].input, | 463 bool result = spell_checker->SpellCheckWord(kTestCasesToBeTested[i].input, |
464 static_cast<int>(input_length), | 464 static_cast<int>(input_length), |
465 &misspelling_start, | 465 &misspelling_start, |
(...skipping 12 matching lines...) Expand all Loading... |
478 break; | 478 break; |
479 } | 479 } |
480 } | 480 } |
481 | 481 |
482 EXPECT_TRUE(suggested_word_is_present); | 482 EXPECT_TRUE(suggested_word_is_present); |
483 } | 483 } |
484 | 484 |
485 // Remove the temp custom dictionary file. | 485 // Remove the temp custom dictionary file. |
486 file_util::Delete(kTempCustomDictionaryFile, false); | 486 file_util::Delete(kTempCustomDictionaryFile, false); |
487 } | 487 } |
OLD | NEW |