| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/format_macros.h" | |
| 6 #include "base/string_util.h" | |
| 7 #include "base/stringprintf.h" | |
| 8 #include "base/utf_string_conversions.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 #include "webkit/tools/test_shell/mock_spellcheck.h" | |
| 11 | |
| 12 class MockSpellCheckTest : public testing::Test { | |
| 13 public: | |
| 14 MockSpellCheckTest() { | |
| 15 } | |
| 16 | |
| 17 virtual ~MockSpellCheckTest() { | |
| 18 } | |
| 19 }; | |
| 20 | |
| 21 TEST_F(MockSpellCheckTest, SpellCheckStrings) { | |
| 22 // Test cases. | |
| 23 // Even though the following test cases are copied from our unit test, | |
| 24 // SpellCheckTest.SpellCheckStrings_EN_US, we omit some test cases which | |
| 25 // needs to handle non-ASCII characters correctly since our MockSpellCheck | |
| 26 // class cannot handle non-ASCII characters. (It just ignores non-ASCII | |
| 27 // characters.) | |
| 28 static const struct { | |
| 29 const wchar_t* input; | |
| 30 bool expected_result; | |
| 31 int misspelling_start; | |
| 32 int misspelling_length; | |
| 33 } kTestCases[] = { | |
| 34 {L"", true, 0, 0}, | |
| 35 {L" ", true, 0, 0}, | |
| 36 {L"\xA0", true, 0, 0}, | |
| 37 {L"\x3000", true, 0, 0}, | |
| 38 | |
| 39 {L"hello", true, 0, 0}, | |
| 40 {L"\x4F60\x597D", true, 0, 0}, | |
| 41 {L"\xC548\xB155\xD558\xC138\xC694", true, 0, 0}, | |
| 42 {L"\x3053\x3093\x306B\x3061\x306F", true, 0, 0}, | |
| 43 {L"\x0930\x093E\x091C\x0927\x093E\x0928", true, 0, 0}, | |
| 44 {L"\xFF28\xFF45\xFF4C\xFF4C\xFF4F", true, 0, 0}, | |
| 45 {L"\x03B3\x03B5\x03B9\x03AC" L" " L"\x03C3\x03BF\x03C5", true, 0, 0}, | |
| 46 {L"\x0437\x0434\x0440\x0430\x0432\x0441" | |
| 47 L"\x0442\x0432\x0443\x0439\x0442\x0435", true, 0, 0}, | |
| 48 | |
| 49 {L" " L"hello", true, 0, 0}, | |
| 50 {L"hello" L" ", true, 0, 0}, | |
| 51 {L"hello" L" " L"hello", true, 0, 0}, | |
| 52 {L"hello:hello", true, 0, 0}, | |
| 53 | |
| 54 {L"ifmmp", false, 0, 5}, | |
| 55 {L"_ifmmp_", false, 1, 5}, | |
| 56 | |
| 57 {L" " L"ifmmp", false, 1, 5}, | |
| 58 {L"ifmmp" L" ", false, 0, 5}, | |
| 59 {L"ifmmp" L" " L"ifmmp", false, 0, 5}, | |
| 60 | |
| 61 {L"qwertyuiopasd", false, 0, 13}, | |
| 62 {L"qwertyuiopasdf", false, 0, 14}, | |
| 63 }; | |
| 64 | |
| 65 MockSpellCheck spellchecker; | |
| 66 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | |
| 67 SCOPED_TRACE(base::StringPrintf("kTestCases[%" PRIuS "]", i)); | |
| 68 | |
| 69 std::wstring input(kTestCases[i].input); | |
| 70 int misspelling_start; | |
| 71 int misspelling_length; | |
| 72 bool result = spellchecker.SpellCheckWord(WideToUTF16(input), | |
| 73 &misspelling_start, | |
| 74 &misspelling_length); | |
| 75 | |
| 76 EXPECT_EQ(kTestCases[i].expected_result, result); | |
| 77 EXPECT_EQ(kTestCases[i].misspelling_start, misspelling_start); | |
| 78 EXPECT_EQ(kTestCases[i].misspelling_length, misspelling_length); | |
| 79 } | |
| 80 } | |
| OLD | NEW |