OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <map> | 5 #include <map> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/i18n/icu_string_conversions.h" | 10 #include "base/i18n/icu_string_conversions.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 55 |
56 // Implements the test process used by ConvertDictTest. | 56 // Implements the test process used by ConvertDictTest. |
57 // This function encapsulates all complicated operations used by | 57 // This function encapsulates all complicated operations used by |
58 // ConvertDictTest so we can conceal them from the tests themselves. | 58 // ConvertDictTest so we can conceal them from the tests themselves. |
59 // This function consists of the following parts: | 59 // This function consists of the following parts: |
60 // * Creates a dummy affix file and a dictionary file. | 60 // * Creates a dummy affix file and a dictionary file. |
61 // * Reads the dummy files. | 61 // * Reads the dummy files. |
62 // * Creates bdict data. | 62 // * Creates bdict data. |
63 // * Verify the bdict data. | 63 // * Verify the bdict data. |
64 void RunDictionaryTest(const char* codepage, | 64 void RunDictionaryTest(const char* codepage, |
65 const std::map<string16, bool>& word_list) { | 65 const std::map<base::string16, bool>& word_list) { |
66 // Create an affix data and a dictionary data. | 66 // Create an affix data and a dictionary data. |
67 std::string aff_data(base::StringPrintf("SET %s\n", codepage)); | 67 std::string aff_data(base::StringPrintf("SET %s\n", codepage)); |
68 | 68 |
69 std::string dic_data(base::StringPrintf("%" PRIuS "\n", word_list.size())); | 69 std::string dic_data(base::StringPrintf("%" PRIuS "\n", word_list.size())); |
70 for (std::map<string16, bool>::const_iterator it = word_list.begin(); | 70 for (std::map<base::string16, bool>::const_iterator it = word_list.begin(); |
71 it != word_list.end(); ++it) { | 71 it != word_list.end(); ++it) { |
72 std::string encoded_word; | 72 std::string encoded_word; |
73 EXPECT_TRUE(UTF16ToCodepage(it->first, | 73 EXPECT_TRUE(UTF16ToCodepage(it->first, |
74 codepage, | 74 codepage, |
75 base::OnStringConversionError::FAIL, | 75 base::OnStringConversionError::FAIL, |
76 &encoded_word)); | 76 &encoded_word)); |
77 dic_data += encoded_word; | 77 dic_data += encoded_word; |
78 dic_data += "\n"; | 78 dic_data += "\n"; |
79 } | 79 } |
80 | 80 |
(...skipping 13 matching lines...) Expand all Loading... |
94 EXPECT_TRUE(aff_reader.Read()); | 94 EXPECT_TRUE(aff_reader.Read()); |
95 | 95 |
96 convert_dict::DicReader dic_reader(dic_file); | 96 convert_dict::DicReader dic_reader(dic_file); |
97 EXPECT_TRUE(dic_reader.Read(&aff_reader)); | 97 EXPECT_TRUE(dic_reader.Read(&aff_reader)); |
98 | 98 |
99 // Verify this DicReader includes all the input words. | 99 // Verify this DicReader includes all the input words. |
100 EXPECT_EQ(word_list.size(), dic_reader.words().size()); | 100 EXPECT_EQ(word_list.size(), dic_reader.words().size()); |
101 for (size_t i = 0; i < dic_reader.words().size(); ++i) { | 101 for (size_t i = 0; i < dic_reader.words().size(); ++i) { |
102 SCOPED_TRACE(base::StringPrintf("dic_reader.words()[%" PRIuS "]: %s", | 102 SCOPED_TRACE(base::StringPrintf("dic_reader.words()[%" PRIuS "]: %s", |
103 i, dic_reader.words()[i].first.c_str())); | 103 i, dic_reader.words()[i].first.c_str())); |
104 string16 word(UTF8ToUTF16(dic_reader.words()[i].first)); | 104 base::string16 word(UTF8ToUTF16(dic_reader.words()[i].first)); |
105 EXPECT_TRUE(word_list.find(word) != word_list.end()); | 105 EXPECT_TRUE(word_list.find(word) != word_list.end()); |
106 } | 106 } |
107 | 107 |
108 // Create BDICT data and verify it. | 108 // Create BDICT data and verify it. |
109 hunspell::BDictWriter writer; | 109 hunspell::BDictWriter writer; |
110 writer.SetComment(aff_reader.comments()); | 110 writer.SetComment(aff_reader.comments()); |
111 writer.SetAffixRules(aff_reader.affix_rules()); | 111 writer.SetAffixRules(aff_reader.affix_rules()); |
112 writer.SetAffixGroups(aff_reader.GetAffixGroups()); | 112 writer.SetAffixGroups(aff_reader.GetAffixGroups()); |
113 writer.SetReplacements(aff_reader.replacements()); | 113 writer.SetReplacements(aff_reader.replacements()); |
114 writer.SetOtherCommands(aff_reader.other_commands()); | 114 writer.SetOtherCommands(aff_reader.other_commands()); |
(...skipping 27 matching lines...) Expand all Loading... |
142 const wchar_t* kWords[] = { | 142 const wchar_t* kWords[] = { |
143 L"I", | 143 L"I", |
144 L"he", | 144 L"he", |
145 L"she", | 145 L"she", |
146 L"it", | 146 L"it", |
147 L"we", | 147 L"we", |
148 L"you", | 148 L"you", |
149 L"they", | 149 L"they", |
150 }; | 150 }; |
151 | 151 |
152 std::map<string16, bool> word_list; | 152 std::map<base::string16, bool> word_list; |
153 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kWords); ++i) | 153 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kWords); ++i) |
154 word_list.insert(std::make_pair<string16, bool>(WideToUTF16(kWords[i]), | 154 word_list.insert( |
155 true)); | 155 std::make_pair<base::string16, bool>(WideToUTF16(kWords[i]), true)); |
156 | 156 |
157 RunDictionaryTest(kCodepage, word_list); | 157 RunDictionaryTest(kCodepage, word_list); |
158 } | 158 } |
159 | 159 |
160 // Tests whether or not our DicReader can read all the input Russian words. | 160 // Tests whether or not our DicReader can read all the input Russian words. |
161 TEST(ConvertDictTest, Russian) { | 161 TEST(ConvertDictTest, Russian) { |
162 const char kCodepage[] = "KOI8-R"; | 162 const char kCodepage[] = "KOI8-R"; |
163 const wchar_t* kWords[] = { | 163 const wchar_t* kWords[] = { |
164 L"\x044f", | 164 L"\x044f", |
165 L"\x0442\x044b", | 165 L"\x0442\x044b", |
166 L"\x043e\x043d", | 166 L"\x043e\x043d", |
167 L"\x043e\x043d\x0430", | 167 L"\x043e\x043d\x0430", |
168 L"\x043e\x043d\x043e", | 168 L"\x043e\x043d\x043e", |
169 L"\x043c\x044b", | 169 L"\x043c\x044b", |
170 L"\x0432\x044b", | 170 L"\x0432\x044b", |
171 L"\x043e\x043d\x0438", | 171 L"\x043e\x043d\x0438", |
172 }; | 172 }; |
173 | 173 |
174 std::map<string16, bool> word_list; | 174 std::map<base::string16, bool> word_list; |
175 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kWords); ++i) | 175 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kWords); ++i) |
176 word_list.insert(std::make_pair<string16, bool>(WideToUTF16(kWords[i]), | 176 word_list.insert( |
177 true)); | 177 std::make_pair<base::string16, bool>(WideToUTF16(kWords[i]), true)); |
178 | 178 |
179 RunDictionaryTest(kCodepage, word_list); | 179 RunDictionaryTest(kCodepage, word_list); |
180 } | 180 } |
181 | 181 |
182 // Tests whether or not our DicReader can read all the input Hungarian words. | 182 // Tests whether or not our DicReader can read all the input Hungarian words. |
183 TEST(ConvertDictTest, Hungarian) { | 183 TEST(ConvertDictTest, Hungarian) { |
184 const char kCodepage[] = "ISO8859-2"; | 184 const char kCodepage[] = "ISO8859-2"; |
185 const wchar_t* kWords[] = { | 185 const wchar_t* kWords[] = { |
186 L"\x00e9\x006e", | 186 L"\x00e9\x006e", |
187 L"\x0074\x0065", | 187 L"\x0074\x0065", |
188 L"\x0151", | 188 L"\x0151", |
189 L"\x00f6\x006e", | 189 L"\x00f6\x006e", |
190 L"\x006d\x0061\x0067\x0061", | 190 L"\x006d\x0061\x0067\x0061", |
191 L"\x006d\x0069", | 191 L"\x006d\x0069", |
192 L"\x0074\x0069", | 192 L"\x0074\x0069", |
193 L"\x0151\x006b", | 193 L"\x0151\x006b", |
194 L"\x00f6\x006e\x00f6\x006b", | 194 L"\x00f6\x006e\x00f6\x006b", |
195 L"\x006d\x0061\x0067\x0075\x006b", | 195 L"\x006d\x0061\x0067\x0075\x006b", |
196 }; | 196 }; |
197 | 197 |
198 std::map<string16, bool> word_list; | 198 std::map<base::string16, bool> word_list; |
199 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kWords); ++i) | 199 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kWords); ++i) |
200 word_list.insert(std::make_pair<string16, bool>(WideToUTF16(kWords[i]), | 200 word_list.insert( |
201 true)); | 201 std::make_pair<base::string16, bool>(WideToUTF16(kWords[i]), true)); |
202 | 202 |
203 RunDictionaryTest(kCodepage, word_list); | 203 RunDictionaryTest(kCodepage, word_list); |
204 } | 204 } |
OLD | NEW |