Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: chrome/tools/convert_dict/convert_dict_unittest.cc

Issue 6312154: Remove wstring from RVH's run Javascript command.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 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"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
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<std::wstring, bool>& word_list) { 65 const std::map<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(StringPrintf("SET %s\n", codepage)); 67 std::string aff_data(StringPrintf("SET %s\n", codepage));
68 68
69 std::string dic_data(StringPrintf("%" PRIuS "\n", word_list.size())); 69 std::string dic_data(StringPrintf("%" PRIuS "\n", word_list.size()));
70 for (std::map<std::wstring, bool>::const_iterator it = word_list.begin(); 70 for (std::map<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(WideToCodepage(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
81 // Create a temporary affix file and a dictionary file from the test data. 81 // Create a temporary affix file and a dictionary file from the test data.
82 FilePath aff_file; 82 FilePath aff_file;
83 file_util::CreateTemporaryFile(&aff_file); 83 file_util::CreateTemporaryFile(&aff_file);
84 file_util::WriteFile(aff_file, aff_data.c_str(), aff_data.length()); 84 file_util::WriteFile(aff_file, aff_data.c_str(), aff_data.length());
85 85
86 FilePath dic_file; 86 FilePath dic_file;
87 file_util::CreateTemporaryFile(&dic_file); 87 file_util::CreateTemporaryFile(&dic_file);
88 file_util::WriteFile(dic_file, dic_data.c_str(), dic_data.length()); 88 file_util::WriteFile(dic_file, dic_data.c_str(), dic_data.length());
89 89
90 { 90 {
91 // Read the above affix file with AffReader and read the dictionary file 91 // Read the above affix file with AffReader and read the dictionary file
92 // with DicReader, respectively. 92 // with DicReader, respectively.
93 convert_dict::AffReader aff_reader(aff_file); 93 convert_dict::AffReader aff_reader(aff_file);
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(StringPrintf("dic_reader.words()[%" PRIuS "]: %s", 102 SCOPED_TRACE(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 std::wstring word(UTF8ToWide(dic_reader.words()[i].first)); 104 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
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<std::wstring, bool> word_list; 152 std::map<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<std::wstring, bool>(kWords[i], true)); 154 word_list.insert(std::make_pair<string16, bool>(WideToUTF16(kWords[i]),
155 true));
155 156
156 RunDictionaryTest(kCodepage, word_list); 157 RunDictionaryTest(kCodepage, word_list);
157 } 158 }
158 159
159 // 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.
160 TEST(ConvertDictTest, Russian) { 161 TEST(ConvertDictTest, Russian) {
161 const char kCodepage[] = "KOI8-R"; 162 const char kCodepage[] = "KOI8-R";
162 const wchar_t* kWords[] = { 163 const wchar_t* kWords[] = {
163 L"\x044f", 164 L"\x044f",
164 L"\x0442\x044b", 165 L"\x0442\x044b",
165 L"\x043e\x043d", 166 L"\x043e\x043d",
166 L"\x043e\x043d\x0430", 167 L"\x043e\x043d\x0430",
167 L"\x043e\x043d\x043e", 168 L"\x043e\x043d\x043e",
168 L"\x043c\x044b", 169 L"\x043c\x044b",
169 L"\x0432\x044b", 170 L"\x0432\x044b",
170 L"\x043e\x043d\x0438", 171 L"\x043e\x043d\x0438",
171 }; 172 };
172 173
173 std::map<std::wstring, bool> word_list; 174 std::map<string16, bool> word_list;
174 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kWords); ++i) 175 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kWords); ++i)
175 word_list.insert(std::make_pair<std::wstring, bool>(kWords[i], true)); 176 word_list.insert(std::make_pair<string16, bool>(WideToUTF16(kWords[i]),
177 true));
176 178
177 RunDictionaryTest(kCodepage, word_list); 179 RunDictionaryTest(kCodepage, word_list);
178 } 180 }
179 181
180 // 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.
181 TEST(ConvertDictTest, Hungarian) { 183 TEST(ConvertDictTest, Hungarian) {
182 const char kCodepage[] = "ISO8859-2"; 184 const char kCodepage[] = "ISO8859-2";
183 const wchar_t* kWords[] = { 185 const wchar_t* kWords[] = {
184 L"\x00e9\x006e", 186 L"\x00e9\x006e",
185 L"\x0074\x0065", 187 L"\x0074\x0065",
186 L"\x0151", 188 L"\x0151",
187 L"\x00f6\x006e", 189 L"\x00f6\x006e",
188 L"\x006d\x0061\x0067\x0061", 190 L"\x006d\x0061\x0067\x0061",
189 L"\x006d\x0069", 191 L"\x006d\x0069",
190 L"\x0074\x0069", 192 L"\x0074\x0069",
191 L"\x0151\x006b", 193 L"\x0151\x006b",
192 L"\x00f6\x006e\x00f6\x006b", 194 L"\x00f6\x006e\x00f6\x006b",
193 L"\x006d\x0061\x0067\x0075\x006b", 195 L"\x006d\x0061\x0067\x0075\x006b",
194 }; 196 };
195 197
196 std::map<std::wstring, bool> word_list; 198 std::map<string16, bool> word_list;
197 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kWords); ++i) 199 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kWords); ++i)
198 word_list.insert(std::make_pair<std::wstring, bool>(kWords[i], true)); 200 word_list.insert(std::make_pair<string16, bool>(WideToUTF16(kWords[i]),
201 true));
199 202
200 RunDictionaryTest(kCodepage, word_list); 203 RunDictionaryTest(kCodepage, word_list);
201 } 204 }
OLDNEW
« chrome/test/webdriver/automation.cc ('K') | « chrome/test/webdriver/automation.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698