1 // Copyright 2010-2018, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 #include "config/character_form_manager.h"
31
32 #include <string>
33
34 #include "base/system_util.h"
35 #include "config/config_handler.h"
36 #include "protocol/config.pb.h"
37 #include "testing/base/public/googletest.h"
38 #include "testing/base/public/gunit.h"
39
40 DECLARE_string(test_tmpdir);
41
42 namespace mozc {
43 namespace config {
44
45 class CharacterFormManagerTest : public ::testing::Test {
46 public:
SetUp()47 void SetUp() override {
48 // set default user profile directory
49 SystemUtil::SetUserProfileDirectory(FLAGS_test_tmpdir);
50 CharacterFormManager *manager =
51 CharacterFormManager::GetCharacterFormManager();
52 manager->SetDefaultRule();
53 }
54
TearDown()55 void TearDown() override {
56 CharacterFormManager *manager =
57 CharacterFormManager::GetCharacterFormManager();
58 manager->SetDefaultRule();
59 }
60 };
61
TEST_F(CharacterFormManagerTest,DefaultTest)62 TEST_F(CharacterFormManagerTest, DefaultTest) {
63 CharacterFormManager *manager =
64 CharacterFormManager::GetCharacterFormManager();
65
66 manager->ClearHistory();
67
68 EXPECT_EQ(
69 config::Config::FULL_WIDTH,
70 manager->GetPreeditCharacterForm("カタカナ"));
71
72 EXPECT_EQ(
73 config::Config::FULL_WIDTH,
74 manager->GetPreeditCharacterForm("012"));
75
76 EXPECT_EQ(
77 config::Config::FULL_WIDTH,
78 manager->GetPreeditCharacterForm("["));
79
80 EXPECT_EQ(
81 config::Config::FULL_WIDTH,
82 manager->GetPreeditCharacterForm("/"));
83
84 EXPECT_EQ(
85 config::Config::FULL_WIDTH,
86 manager->GetPreeditCharacterForm("・"));
87
88 EXPECT_EQ(
89 config::Config::FULL_WIDTH,
90 manager->GetPreeditCharacterForm("。"));
91
92 EXPECT_EQ(
93 config::Config::FULL_WIDTH,
94 manager->GetPreeditCharacterForm("、"));
95
96 EXPECT_EQ(
97 config::Config::FULL_WIDTH,
98 manager->GetPreeditCharacterForm("\\"));
99
100 EXPECT_EQ(
101 config::Config::NO_CONVERSION,
102 manager->GetConversionCharacterForm("ABC012ほげ"));
103
104 EXPECT_EQ(
105 config::Config::FULL_WIDTH,
106 manager->GetConversionCharacterForm("カタカナ"));
107
108 EXPECT_EQ(
109 config::Config::FULL_WIDTH,
110 manager->GetConversionCharacterForm("012"));
111
112 EXPECT_EQ(
113 config::Config::FULL_WIDTH,
114 manager->GetConversionCharacterForm("["));
115
116 EXPECT_EQ(
117 config::Config::FULL_WIDTH,
118 manager->GetConversionCharacterForm("/"));
119
120 EXPECT_EQ(
121 config::Config::FULL_WIDTH,
122 manager->GetConversionCharacterForm("・"));
123
124 EXPECT_EQ(
125 config::Config::FULL_WIDTH,
126 manager->GetConversionCharacterForm("。"));
127
128 EXPECT_EQ(
129 config::Config::FULL_WIDTH,
130 manager->GetConversionCharacterForm("、"));
131
132 EXPECT_EQ(
133 config::Config::FULL_WIDTH,
134 manager->GetConversionCharacterForm("\\"));
135
136 EXPECT_EQ(
137 config::Config::NO_CONVERSION,
138 manager->GetConversionCharacterForm("ABC012ほげ"));
139
140 string output;
141 manager->ConvertPreeditString("京都東京ABCインターネット", &output);
142 EXPECT_EQ("京都東京ABCインターネット", output);
143
144 manager->ConvertPreeditString("インターネット", &output);
145 EXPECT_EQ("インターネット", output);
146
147 manager->ConvertPreeditString("[]・。、", &output);
148 EXPECT_EQ("[]・。、", output);
149
150 manager->ConvertPreeditString(".!@#$%^&", &output);
151 EXPECT_EQ(".!@#$%^&", output);
152
153 manager->ConvertPreeditString("京都東京ABCインターネット012", &output);
154 EXPECT_EQ("京都東京ABCインターネット012", output);
155
156 manager->ConvertPreeditString("グーグルABCインターネット012あいう", &output);
157 EXPECT_EQ("グーグルABCインターネット012あいう", output);
158
159 manager->ConvertPreeditString("京都東京ABCインターネット", &output);
160 EXPECT_EQ("京都東京ABCインターネット", output);
161
162 manager->ConvertPreeditString("[京都]{東京}ABC!インターネット", &output);
163 EXPECT_EQ("[京都]{東京}ABC!インターネット", output);
164
165 manager->ConvertConversionString("インターネット", &output);
166 EXPECT_EQ("インターネット", output);
167
168 manager->ConvertConversionString("[]・。、", &output);
169 EXPECT_EQ("[]・。、", output);
170
171 manager->ConvertConversionString(".!@#$%^&", &output);
172 EXPECT_EQ(".!@#$%^&", output);
173
174 manager->ConvertConversionString("京都東京ABCインターネット012", &output);
175 EXPECT_EQ("京都東京ABCインターネット012", output);
176
177 manager->ConvertConversionString("グーグルABCインターネット012あいう", &output);
178 EXPECT_EQ("グーグルABCインターネット012あいう", output);
179
180 manager->ConvertConversionString("[京都]{東京}ABC!インターネット", &output);
181 EXPECT_EQ("[京都]{東京}ABC!インターネット", output);
182
183 // Set
184 manager->SetCharacterForm("カタカナ", config::Config::HALF_WIDTH);
185 manager->SetCharacterForm("012", config::Config::HALF_WIDTH);
186 manager->SetCharacterForm("[", config::Config::HALF_WIDTH);
187 manager->SetCharacterForm("/", config::Config::HALF_WIDTH);
188 manager->SetCharacterForm("・", config::Config::HALF_WIDTH);
189 manager->SetCharacterForm("。", config::Config::HALF_WIDTH);
190 manager->SetCharacterForm("、", config::Config::HALF_WIDTH);
191 manager->SetCharacterForm("\\", config::Config::HALF_WIDTH);
192
193 // retry
194 EXPECT_EQ(
195 config::Config::FULL_WIDTH,
196 manager->GetPreeditCharacterForm("カタカナ"));
197
198 EXPECT_EQ(
199 config::Config::FULL_WIDTH,
200 manager->GetPreeditCharacterForm("012"));
201
202 EXPECT_EQ(
203 config::Config::FULL_WIDTH,
204 manager->GetPreeditCharacterForm("["));
205
206 EXPECT_EQ(
207 config::Config::FULL_WIDTH,
208 manager->GetPreeditCharacterForm("/"));
209
210 EXPECT_EQ(
211 config::Config::FULL_WIDTH,
212 manager->GetPreeditCharacterForm("・"));
213
214 EXPECT_EQ(
215 config::Config::FULL_WIDTH,
216 manager->GetPreeditCharacterForm("。"));
217
218 EXPECT_EQ(
219 config::Config::FULL_WIDTH,
220 manager->GetPreeditCharacterForm("、"));
221
222 EXPECT_EQ(
223 config::Config::FULL_WIDTH,
224 manager->GetPreeditCharacterForm("\\"));
225
226 EXPECT_EQ(
227 config::Config::NO_CONVERSION,
228 manager->GetConversionCharacterForm("ABC012ほげ"));
229
230 EXPECT_EQ(
231 config::Config::FULL_WIDTH,
232 manager->GetConversionCharacterForm("カタカナ"));
233
234 EXPECT_EQ(
235 config::Config::HALF_WIDTH,
236 manager->GetConversionCharacterForm("012"));
237
238 EXPECT_EQ(
239 config::Config::HALF_WIDTH,
240 manager->GetConversionCharacterForm("["));
241
242 EXPECT_EQ(
243 config::Config::HALF_WIDTH,
244 manager->GetConversionCharacterForm("/"));
245
246 EXPECT_EQ(
247 config::Config::FULL_WIDTH,
248 manager->GetConversionCharacterForm("・"));
249
250 EXPECT_EQ(
251 config::Config::FULL_WIDTH,
252 manager->GetConversionCharacterForm("。"));
253
254 EXPECT_EQ(
255 config::Config::FULL_WIDTH,
256 manager->GetConversionCharacterForm("、"));
257
258 EXPECT_EQ(
259 config::Config::HALF_WIDTH,
260 manager->GetConversionCharacterForm("\\"));
261
262 manager->ConvertPreeditString("京都東京ABCインターネット", &output);
263 EXPECT_EQ("京都東京ABCインターネット", output);
264
265 manager->ConvertPreeditString("インターネット", &output);
266 EXPECT_EQ("インターネット", output);
267
268 manager->ConvertPreeditString("[]・。、", &output);
269 EXPECT_EQ("[]・。、", output);
270
271 manager->ConvertPreeditString(".!@#$%^&", &output);
272 EXPECT_EQ(".!@#$%^&", output);
273
274 manager->ConvertPreeditString("京都東京ABCインターネット", &output);
275 EXPECT_EQ("京都東京ABCインターネット", output);
276
277 manager->ConvertPreeditString("グーグルABCインターネットあいう", &output);
278 EXPECT_EQ("グーグルABCインターネットあいう", output);
279
280 manager->ConvertPreeditString("京都東京ABCインターネット", &output);
281 EXPECT_EQ("京都東京ABCインターネット", output);
282
283 manager->ConvertPreeditString("[京都]{東京}ABC!インターネット", &output);
284 EXPECT_EQ("[京都]{東京}ABC!インターネット", output);
285
286 manager->ConvertConversionString("インターネット", &output);
287 EXPECT_EQ("インターネット", output);
288
289 manager->ConvertConversionString("[]・。、", &output);
290 EXPECT_EQ("[]・。、", output);
291
292 manager->ConvertConversionString(".!@#$%^&", &output);
293 // ".!@#$%^&" will be ".!@#$%^&" by preference, but this is not
294 // consistent form. so we do not convert this.
295 EXPECT_EQ(".!@#$%^&", output);
296
297 // However we can convert separately.
298 manager->ConvertConversionString(".!", &output);
299 // ".!"
300 EXPECT_EQ(".!", output);
301 manager->ConvertConversionString("@#$%^&", &output);
302 EXPECT_EQ("@#$%^&", output);
303
304 manager->ConvertConversionString("京都東京ABCインターネット", &output);
305 EXPECT_EQ("京都東京ABCインターネット", output);
306
307 manager->ConvertConversionString("グーグルABCインターネットあいう", &output);
308 EXPECT_EQ("グーグルABCインターネットあいう", output);
309
310 manager->ConvertConversionString("[京都]{東京}ABC!インターネット", &output);
311 // "[京都]{東京}ABC!インターネット" will be
312 // "[京都]{東京}ABC!インターネット" by preference and this is
313 // not consistent
314 EXPECT_EQ("[京都]{東京}ABC!インターネット", output);
315
316 // we can convert separately
317 // "[京都]{東京}ABC!インターネット"
318 manager->ConvertConversionString("[京都]{東京}", &output);
319 EXPECT_EQ("[京都]{東京}", output);
320
321 manager->ConvertConversionString("ABC!インターネット", &output);
322 EXPECT_EQ("ABC!インターネット", output);
323
324 // reset
325 manager->SetCharacterForm("カタカナ", config::Config::FULL_WIDTH);
326 manager->SetCharacterForm("012", config::Config::FULL_WIDTH);
327 manager->SetCharacterForm("[", config::Config::FULL_WIDTH);
328 manager->SetCharacterForm("/", config::Config::FULL_WIDTH);
329 manager->SetCharacterForm("・", config::Config::FULL_WIDTH);
330 manager->SetCharacterForm("。", config::Config::FULL_WIDTH);
331 manager->SetCharacterForm("、", config::Config::FULL_WIDTH);
332 manager->SetCharacterForm("\\", config::Config::FULL_WIDTH);
333
334 EXPECT_EQ(
335 config::Config::FULL_WIDTH,
336 manager->GetPreeditCharacterForm("カタカナ"));
337
338 EXPECT_EQ(
339 config::Config::FULL_WIDTH,
340 manager->GetPreeditCharacterForm("012"));
341
342 EXPECT_EQ(
343 config::Config::FULL_WIDTH,
344 manager->GetPreeditCharacterForm("["));
345
346 EXPECT_EQ(
347 config::Config::FULL_WIDTH,
348 manager->GetPreeditCharacterForm("/"));
349
350 EXPECT_EQ(
351 config::Config::FULL_WIDTH,
352 manager->GetPreeditCharacterForm("・"));
353
354 EXPECT_EQ(
355 config::Config::FULL_WIDTH,
356 manager->GetPreeditCharacterForm("。"));
357
358 EXPECT_EQ(
359 config::Config::FULL_WIDTH,
360 manager->GetPreeditCharacterForm("、"));
361
362 EXPECT_EQ(
363 config::Config::FULL_WIDTH,
364 manager->GetPreeditCharacterForm("\\"));
365
366 EXPECT_EQ(
367 config::Config::NO_CONVERSION,
368 manager->GetConversionCharacterForm("ABC012ほげ"));
369
370 EXPECT_EQ(
371 config::Config::FULL_WIDTH,
372 manager->GetConversionCharacterForm("カタカナ"));
373
374 EXPECT_EQ(
375 config::Config::FULL_WIDTH,
376 manager->GetConversionCharacterForm("012"));
377
378 EXPECT_EQ(
379 config::Config::FULL_WIDTH,
380 manager->GetConversionCharacterForm("["));
381
382 EXPECT_EQ(
383 config::Config::FULL_WIDTH,
384 manager->GetConversionCharacterForm("/"));
385
386 EXPECT_EQ(
387 config::Config::FULL_WIDTH,
388 manager->GetConversionCharacterForm("・"));
389
390 EXPECT_EQ(
391 config::Config::FULL_WIDTH,
392 manager->GetConversionCharacterForm("。"));
393
394 EXPECT_EQ(
395 config::Config::FULL_WIDTH,
396 manager->GetConversionCharacterForm("、"));
397
398 EXPECT_EQ(
399 config::Config::NO_CONVERSION,
400 manager->GetConversionCharacterForm("ABC012ほげ"));
401
402 manager->ConvertPreeditString("京都東京ABCインターネット", &output);
403 EXPECT_EQ("京都東京ABCインターネット", output);
404
405 manager->ConvertPreeditString("インターネット", &output);
406 EXPECT_EQ("インターネット", output);
407
408 manager->ConvertPreeditString("[]・。、", &output);
409 EXPECT_EQ("[]・。、", output);
410
411 manager->ConvertPreeditString(".!@#$%^&", &output);
412 EXPECT_EQ(".!@#$%^&", output);
413
414 manager->ConvertPreeditString("京都東京ABCインターネット012", &output);
415 EXPECT_EQ("京都東京ABCインターネット012", output);
416
417 manager->ConvertPreeditString("グーグルABCインターネット012あいう", &output);
418 EXPECT_EQ("グーグルABCインターネット012あいう", output);
419
420 manager->ConvertPreeditString("京都東京ABCインターネット", &output);
421 EXPECT_EQ("京都東京ABCインターネット", output);
422
423 manager->ConvertPreeditString("[京都]{東京}ABC!インターネット", &output);
424 EXPECT_EQ("[京都]{東京}ABC!インターネット", output);
425
426 manager->ConvertConversionString("インターネット", &output);
427 EXPECT_EQ("インターネット", output);
428
429 manager->ConvertConversionString("[]・。、", &output);
430 EXPECT_EQ("[]・。、", output);
431
432 manager->ConvertConversionString(".!@#$%^&", &output);
433 EXPECT_EQ(".!@#$%^&", output);
434
435 manager->ConvertConversionString("京都東京ABCインターネット012", &output);
436 EXPECT_EQ("京都東京ABCインターネット012", output);
437
438 manager->ConvertConversionString("グーグルABCインターネット012あいう", &output);
439 EXPECT_EQ("グーグルABCインターネット012あいう", output);
440
441 manager->ConvertConversionString("[京都]{東京}ABC!インターネット", &output);
442 EXPECT_EQ("[京都]{東京}ABC!インターネット", output);
443 }
444
TEST_F(CharacterFormManagerTest,MixedFormTest)445 TEST_F(CharacterFormManagerTest, MixedFormTest) {
446 CharacterFormManager *manager =
447 CharacterFormManager::GetCharacterFormManager();
448
449 manager->AddConversionRule("0", config::Config::FULL_WIDTH);
450 manager->AddConversionRule(".,", config::Config::HALF_WIDTH);
451 manager->AddPreeditRule("0", config::Config::FULL_WIDTH);
452 manager->AddPreeditRule(".,", config::Config::HALF_WIDTH);
453
454 string output;
455 manager->ConvertConversionString("1.23", &output);
456 EXPECT_EQ("1.23", output);
457
458 manager->ConvertPreeditString("1.23", &output);
459 // The period is half width here
460 // because require_consistent_conversion_ is false.
461 EXPECT_EQ("1.23", output);
462 }
463
TEST_F(CharacterFormManagerTest,GroupTest)464 TEST_F(CharacterFormManagerTest, GroupTest) {
465 CharacterFormManager *manager =
466 CharacterFormManager::GetCharacterFormManager();
467
468 {
469 manager->ClearHistory();
470 manager->Clear();
471 manager->AddConversionRule("ア", config::Config::FULL_WIDTH);
472 manager->AddPreeditRule("ア", config::Config::HALF_WIDTH);
473 manager->AddConversionRule("[]", config::Config::HALF_WIDTH);
474 manager->AddPreeditRule("[]", config::Config::FULL_WIDTH);
475 manager->AddConversionRule("!@#$%^&*()-=",
476 config::Config::FULL_WIDTH);
477 manager->AddConversionRule("!@#$%^&*()-=",
478 config::Config::HALF_WIDTH);
479
480 EXPECT_EQ(
481 config::Config::HALF_WIDTH,
482 manager->GetConversionCharacterForm("["));
483
484 EXPECT_EQ(
485 config::Config::FULL_WIDTH,
486 manager->GetPreeditCharacterForm("["));
487
488 EXPECT_EQ(
489 config::Config::HALF_WIDTH,
490 manager->GetPreeditCharacterForm("ア"));
491
492
493 manager->SetCharacterForm("[",
494 config::Config::FULL_WIDTH);
495 manager->SetCharacterForm("ア",
496 config::Config::FULL_WIDTH);
497 manager->SetCharacterForm("@",
498 config::Config::FULL_WIDTH);
499
500 EXPECT_EQ(
501 config::Config::HALF_WIDTH,
502 manager->GetConversionCharacterForm("["));
503
504 EXPECT_EQ(
505 config::Config::FULL_WIDTH,
506 manager->GetPreeditCharacterForm("["));
507
508 EXPECT_EQ(
509 config::Config::HALF_WIDTH,
510 manager->GetPreeditCharacterForm("ア"));
511 }
512
513 {
514 manager->ClearHistory();
515 manager->Clear();
516 manager->AddConversionRule("ア", config::Config::FULL_WIDTH);
517 manager->AddConversionRule("[]", config::Config::LAST_FORM);
518 manager->AddConversionRule("!@#$%^&*()-=",
519 config::Config::FULL_WIDTH);
520
521 EXPECT_EQ(
522 config::Config::FULL_WIDTH, // default
523 manager->GetConversionCharacterForm("["));
524
525 // same group
526 manager->SetCharacterForm("]",
527 config::Config::HALF_WIDTH);
528
529 EXPECT_EQ(
530 config::Config::HALF_WIDTH,
531 manager->GetConversionCharacterForm("["));
532 }
533
534 {
535 manager->ClearHistory();
536 manager->Clear();
537 manager->AddConversionRule("ア", config::Config::FULL_WIDTH);
538 manager->AddConversionRule("[](){}", config::Config::LAST_FORM);
539 manager->AddConversionRule("!@#$%^&*-=",
540 config::Config::FULL_WIDTH);
541
542 EXPECT_EQ(
543 config::Config::FULL_WIDTH,
544 manager->GetConversionCharacterForm("{"));
545 EXPECT_EQ(
546 config::Config::FULL_WIDTH,
547 manager->GetConversionCharacterForm("}"));
548 EXPECT_EQ(
549 config::Config::FULL_WIDTH,
550 manager->GetConversionCharacterForm("("));
551 EXPECT_EQ(
552 config::Config::FULL_WIDTH,
553 manager->GetConversionCharacterForm(")"));
554
555 // same group
556 manager->SetCharacterForm(")",
557 config::Config::HALF_WIDTH);
558
559 EXPECT_EQ(
560 config::Config::HALF_WIDTH,
561 manager->GetConversionCharacterForm("{"));
562 EXPECT_EQ(
563 config::Config::HALF_WIDTH,
564 manager->GetConversionCharacterForm("}"));
565 EXPECT_EQ(
566 config::Config::HALF_WIDTH,
567 manager->GetConversionCharacterForm("("));
568 EXPECT_EQ(
569 config::Config::HALF_WIDTH,
570 manager->GetConversionCharacterForm(")"));
571 }
572
573 {
574 manager->ClearHistory();
575 manager->Clear();
576 manager->AddConversionRule("ア", config::Config::FULL_WIDTH);
577 manager->AddConversionRule("[](){}", config::Config::LAST_FORM);
578 manager->AddPreeditRule("[](){}", config::Config::FULL_WIDTH);
579 manager->AddConversionRule("!@#$%^&*-=",
580 config::Config::FULL_WIDTH);
581
582 EXPECT_EQ(
583 config::Config::FULL_WIDTH,
584 manager->GetConversionCharacterForm("{"));
585 EXPECT_EQ(
586 config::Config::FULL_WIDTH,
587 manager->GetConversionCharacterForm("}"));
588 EXPECT_EQ(
589 config::Config::FULL_WIDTH,
590 manager->GetConversionCharacterForm("("));
591 EXPECT_EQ(
592 config::Config::FULL_WIDTH,
593 manager->GetConversionCharacterForm(")"));
594
595 EXPECT_EQ(
596 config::Config::FULL_WIDTH,
597 manager->GetPreeditCharacterForm("{"));
598 EXPECT_EQ(
599 config::Config::FULL_WIDTH,
600 manager->GetPreeditCharacterForm("}"));
601 EXPECT_EQ(
602 config::Config::FULL_WIDTH,
603 manager->GetPreeditCharacterForm("("));
604 EXPECT_EQ(
605 config::Config::FULL_WIDTH,
606 manager->GetPreeditCharacterForm(")"));
607
608 // same group
609 manager->SetCharacterForm(")",
610 config::Config::HALF_WIDTH);
611
612 EXPECT_EQ(
613 config::Config::HALF_WIDTH,
614 manager->GetConversionCharacterForm("{"));
615 EXPECT_EQ(
616 config::Config::HALF_WIDTH,
617 manager->GetConversionCharacterForm("}"));
618 EXPECT_EQ(
619 config::Config::HALF_WIDTH,
620 manager->GetConversionCharacterForm("("));
621 EXPECT_EQ(
622 config::Config::HALF_WIDTH,
623 manager->GetConversionCharacterForm(")"));
624
625 EXPECT_EQ(
626 config::Config::FULL_WIDTH,
627 manager->GetPreeditCharacterForm("{"));
628 EXPECT_EQ(
629 config::Config::FULL_WIDTH,
630 manager->GetPreeditCharacterForm("}"));
631 EXPECT_EQ(
632 config::Config::FULL_WIDTH,
633 manager->GetPreeditCharacterForm("("));
634 EXPECT_EQ(
635 config::Config::FULL_WIDTH,
636 manager->GetPreeditCharacterForm(")"));
637 }
638 }
639
TEST_F(CharacterFormManagerTest,GetFormTypesFromStringPair)640 TEST_F(CharacterFormManagerTest, GetFormTypesFromStringPair) {
641 CharacterFormManager::FormType f1, f2;
642
643 EXPECT_FALSE(CharacterFormManager::GetFormTypesFromStringPair(
644 "", &f1,
645 "", &f2));
646
647 EXPECT_FALSE(CharacterFormManager::GetFormTypesFromStringPair(
648 "abc", &f1,
649 "ab", &f2));
650
651 EXPECT_FALSE(CharacterFormManager::GetFormTypesFromStringPair(
652 "abc", &f1,
653 "abc", &f2));
654
655 EXPECT_FALSE(CharacterFormManager::GetFormTypesFromStringPair(
656 "12", &f1,
657 "12", &f2));
658
659 EXPECT_FALSE(CharacterFormManager::GetFormTypesFromStringPair(
660 "あいう", &f1,
661 "あいう", &f2));
662
663 EXPECT_FALSE(CharacterFormManager::GetFormTypesFromStringPair(
664 "アイウ", &f1,
665 "アイウ", &f2));
666
667 EXPECT_FALSE(CharacterFormManager::GetFormTypesFromStringPair(
668 "愛", &f1,
669 "恋", &f2));
670
671 EXPECT_TRUE(CharacterFormManager::GetFormTypesFromStringPair(
672 "ABC", &f1,
673 "ABC", &f2));
674 EXPECT_EQ(f1, CharacterFormManager::HALF_WIDTH);
675 EXPECT_EQ(f2, CharacterFormManager::FULL_WIDTH);
676
677 EXPECT_TRUE(CharacterFormManager::GetFormTypesFromStringPair(
678 "abc", &f1,
679 "abc", &f2));
680 EXPECT_EQ(f1, CharacterFormManager::FULL_WIDTH);
681 EXPECT_EQ(f2, CharacterFormManager::HALF_WIDTH);
682
683 EXPECT_TRUE(CharacterFormManager::GetFormTypesFromStringPair(
684 "おばQ", &f1,
685 "おばQ", &f2));
686 EXPECT_EQ(f1, CharacterFormManager::HALF_WIDTH);
687 EXPECT_EQ(f2, CharacterFormManager::FULL_WIDTH);
688
689 EXPECT_TRUE(CharacterFormManager::GetFormTypesFromStringPair(
690 "よろしくヨロシク", &f1,
691 "よろしくヨロシク", &f2));
692 EXPECT_EQ(f1, CharacterFormManager::FULL_WIDTH);
693 EXPECT_EQ(f2, CharacterFormManager::HALF_WIDTH);
694
695 EXPECT_TRUE(CharacterFormManager::GetFormTypesFromStringPair(
696 "よろしくグーグル", &f1,
697 "よろしくグーグル", &f2));
698 EXPECT_EQ(f1, CharacterFormManager::FULL_WIDTH);
699 EXPECT_EQ(f2, CharacterFormManager::HALF_WIDTH);
700
701 // semi voice sound mark
702 EXPECT_TRUE(CharacterFormManager::GetFormTypesFromStringPair(
703 "カッパよろしくグーグル", &f1,
704 "カッパよろしくグーグル", &f2));
705 EXPECT_EQ(f1, CharacterFormManager::FULL_WIDTH);
706 EXPECT_EQ(f2, CharacterFormManager::HALF_WIDTH);
707
708 EXPECT_TRUE(CharacterFormManager::GetFormTypesFromStringPair(
709 "ヨロシクQ", &f1,
710 "ヨロシクQ", &f2));
711 EXPECT_EQ(f1, CharacterFormManager::FULL_WIDTH);
712 EXPECT_EQ(f2, CharacterFormManager::HALF_WIDTH);
713
714 // mixed
715 EXPECT_FALSE(CharacterFormManager::GetFormTypesFromStringPair(
716 "ヨロシクQ", &f1,
717 "ヨロシクQ", &f2));
718
719 EXPECT_TRUE(CharacterFormManager::GetFormTypesFromStringPair(
720 "京都Qぐーぐる", &f1,
721 "京都Qぐーぐる", &f2));
722 EXPECT_EQ(f1, CharacterFormManager::HALF_WIDTH);
723 EXPECT_EQ(f2, CharacterFormManager::FULL_WIDTH);
724 }
725
726 } // namespace config
727 } // namespace mozc
728