Set correct key and config for testing.
With the previous implementation, preedit text was transliterated to
get the query for prediction (half width ascii to full width) and this
was not the expected behavior.
By this change, we will be able to test the suggestion result of ascii
preedit text.
TODO(toshiyuki):
- Use new method(Composer::SetPreeditTextForTestOnly) for other test modules
or
- Modify the implementation of InsertCharacterPreedit() and remove
SetPreeditTextForTestOnly() if we can confirm that that will not cause
any problems.
REF_BUG=67485370
REF_CL=173622500
REF_TIME=2017-10-27T11:01:19+09:00
REF_TIME_RAW=1509069679 +0900
Toshiyuki Hanaoka
6 years ago
437 | 437 | begin += mblen; |
438 | 438 | } |
439 | 439 | DCHECK_EQ(begin, end); |
440 | } | |
441 | ||
442 | // Note: This method is only for test. | |
443 | void Composer::SetPreeditTextForTestOnly(const string &input) { | |
444 | SetTemporaryInputMode(transliteration::HALF_ASCII); | |
445 | InsertCharacterPreedit(input); | |
440 | 446 | } |
441 | 447 | |
442 | 448 | void Composer::InsertCharacterPreeditForProbableKeyEvents( |
139 | 139 | void DeleteRange(size_t pos, size_t length); |
140 | 140 | |
141 | 141 | void InsertCharacter(const string &input); |
142 | ||
143 | // Set preedit text to composer. | |
144 | // | |
145 | // If you want to set preedit text for testing | |
146 | // (to convert from HIRAGANA string rather than key input), | |
147 | // you should use SetPreeditTextForTestOnly(). | |
148 | // With the current implementation, prediction queries can be transliterated | |
149 | // and you will not be able to get right candidates. | |
142 | 150 | void InsertCharacterPreedit(const string &input); |
151 | ||
152 | // TEST ONLY: Set preedit text to composer. | |
153 | // | |
154 | // The |input| will be used in as-is form for conversion/suggestion query | |
155 | // and will not be transliterated. | |
156 | // For example, when the |input| will be set as "mo", suggestion will be | |
157 | // triggered by "mo", rather than "も", or "mo", etc. | |
158 | void SetPreeditTextForTestOnly(const string &input); | |
159 | ||
143 | 160 | bool InsertCharacterKeyAndPreedit(const string &key, const string &preedit); |
144 | 161 | void InsertCharacterForProbableKeyEvents( |
145 | 162 | const string &input, |
54 | 54 | #include "protocol/commands.pb.h" |
55 | 55 | #include "protocol/config.pb.h" |
56 | 56 | #include "request/conversion_request.h" |
57 | #include "session/request_test_util.h" | |
57 | 58 | |
58 | 59 | DEFINE_int32(max_conversion_candidates_size, 200, "maximum candidates size"); |
59 | 60 | DEFINE_string(user_profile_dir, "", "path to user profile directory"); |
270 | 271 | CHECK_FIELDS_LENGTH(2); |
271 | 272 | Table table; |
272 | 273 | Composer composer(&table, &request, &config); |
273 | composer.InsertCharacterPreedit(fields[1]); | |
274 | composer.SetPreeditTextForTestOnly(fields[1]); | |
274 | 275 | ConversionRequest conversion_request(&composer, &request, &config); |
275 | 276 | return converter.StartConversionForRequest(conversion_request, segments); |
276 | 277 | } else if (func == "convertwithnodeinfo" || func == "cn") { |
289 | 290 | Table table; |
290 | 291 | Composer composer(&table, &request, &config); |
291 | 292 | if (fields.size() >= 2) { |
292 | composer.InsertCharacterPreedit(fields[1]); | |
293 | composer.SetPreeditTextForTestOnly(fields[1]); | |
293 | 294 | ConversionRequest conversion_request(&composer, &request, &config); |
294 | 295 | return converter.StartPredictionForRequest(conversion_request, segments); |
295 | 296 | } else { |
300 | 301 | Table table; |
301 | 302 | Composer composer(&table, &request, &config); |
302 | 303 | if (fields.size() >= 2) { |
303 | composer.InsertCharacterPreedit(fields[1]); | |
304 | composer.SetPreeditTextForTestOnly(fields[1]); | |
304 | 305 | ConversionRequest conversion_request(&composer, &request, &config); |
305 | 306 | return converter.StartSuggestionForRequest(conversion_request, segments); |
306 | 307 | } else { |
453 | 454 | FLAGS_magic); |
454 | 455 | CHECK_EQ(status, mozc::DataManager::Status::OK); |
455 | 456 | |
457 | mozc::commands::Request request; | |
456 | 458 | std::unique_ptr<mozc::EngineInterface> engine; |
457 | 459 | if (FLAGS_engine_type == "desktop") { |
458 | 460 | engine = mozc::Engine::CreateDesktopEngine(std::move(data_manager)); |
459 | 461 | } else if (FLAGS_engine_type == "mobile") { |
460 | 462 | engine = mozc::Engine::CreateMobileEngine(std::move(data_manager)); |
463 | mozc::commands::RequestForUnitTest::FillMobileRequest(&request); | |
461 | 464 | } else { |
462 | 465 | LOG(FATAL) << "Invalid type: --engine_type=" << FLAGS_engine_type; |
463 | 466 | return 0; |
466 | 469 | mozc::ConverterInterface *converter = engine->GetConverter(); |
467 | 470 | CHECK(converter); |
468 | 471 | |
469 | const mozc::commands::Request request; | |
470 | 472 | mozc::Segments segments; |
471 | 473 | string line; |
472 | 474 |
202 | 202 | if (command == kConversionExpect || |
203 | 203 | command == kConversionNotExpect) { |
204 | 204 | composer::Composer composer(&table, request_.get(), config_.get()); |
205 | composer.InsertCharacterPreedit(key); | |
205 | composer.SetPreeditTextForTestOnly(key); | |
206 | 206 | ConversionRequest request(&composer, request_.get(), config_.get()); |
207 | 207 | converter_->StartConversionForRequest(request, segments_.get()); |
208 | 208 | } else if (command == kReverseConversionExpect || |
211 | 211 | } else if (command == kPredictionExpect || |
212 | 212 | command == kPredictionNotExpect) { |
213 | 213 | composer::Composer composer(&table, request_.get(), config_.get()); |
214 | composer.InsertCharacterPreedit(key); | |
214 | composer.SetPreeditTextForTestOnly(key); | |
215 | 215 | ConversionRequest request(&composer, request_.get(), config_.get()); |
216 | 216 | converter_->StartPredictionForRequest(request, segments_.get()); |
217 | 217 | } else if (command == kSuggestionExpect || |
218 | 218 | command == kSuggestionNotExpect) { |
219 | 219 | composer::Composer composer(&table, request_.get(), config_.get()); |
220 | composer.InsertCharacterPreedit(key); | |
220 | composer.SetPreeditTextForTestOnly(key); | |
221 | 221 | ConversionRequest request(&composer, request_.get(), config_.get()); |
222 | 222 | converter_->StartSuggestionForRequest(request, segments_.get()); |
223 | 223 | } else { |