1 /**
2 * test-keyboardless.c
3 *
4 * Copyright (c) 2013
5 * libchewing Core Team. See ChangeLog for details.
6 *
7 * See the file "COPYING" for information on usage and redistribution
8 * of this file.
9 */
10 #include <assert.h>
11 #include <stdlib.h>
12
13 #include "testhelper.h"
14 #include "chewing.h"
15
16 FILE *fd;
17
test_cand_open_word()18 void test_cand_open_word()
19 {
20 ChewingContext *ctx;
21 int ret;
22
23 ctx = chewing_new();
24 start_testcase(ctx, fd);
25
26 type_keystroke_by_string(ctx, "hk4" /* ㄘㄜˋ */ );
27
28 ret = chewing_cand_open(ctx);
29 ok(ret == 0, "chewing_cand_open() returns `%d' shall be `%d'", ret, 0);
30
31 ret = chewing_cand_TotalChoice(ctx);
32 ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall be greater than `%d'", ret, 0);
33
34 chewing_delete(ctx);
35 }
36
test_cand_open_symbol()37 void test_cand_open_symbol()
38 {
39 ChewingContext *ctx;
40 int ret;
41
42 ctx = chewing_new();
43 start_testcase(ctx, fd);
44
45 type_keystroke_by_string(ctx, "`31" /* , */ );
46
47 ret = chewing_cand_open(ctx);
48 ok(ret == 0, "chewing_cand_open() returns `%d' shall be `%d'", ret, 0);
49
50 ret = chewing_cand_TotalChoice(ctx);
51 ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall be greater than `%d'", ret, 0);
52
53 chewing_delete(ctx);
54 }
55
test_cand_open_already_opened()56 void test_cand_open_already_opened()
57 {
58 ChewingContext *ctx;
59 int ret;
60
61 ctx = chewing_new();
62 start_testcase(ctx, fd);
63
64 type_keystroke_by_string(ctx, "hk4" /* ㄘㄜˋ */ );
65
66 ret = chewing_cand_open(ctx);
67 ok(ret == 0, "chewing_cand_open() returns `%d' shall be `%d'", ret, 0);
68
69 ret = chewing_cand_TotalChoice(ctx);
70 ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall be greater than `%d'", ret, 0);
71
72 /* FIXME: Need to ensure the candidate windows does not change */
73 ret = chewing_cand_open(ctx);
74 ok(ret == 0, "chewing_cand_open() returns `%d' shall be `%d'", ret, 0);
75
76 ret = chewing_cand_TotalChoice(ctx);
77 ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall be greater than `%d'", ret, 0);
78
79 chewing_delete(ctx);
80 }
81
test_cand_open_nothing_in_preedit()82 void test_cand_open_nothing_in_preedit()
83 {
84 ChewingContext *ctx;
85 int ret;
86
87 ctx = chewing_new();
88 start_testcase(ctx, fd);
89
90 ret = chewing_cand_open(ctx);
91 ok(ret == -1, "chewing_cand_open() returns `%d' shall be `%d'", ret, -1);
92
93 ret = chewing_cand_TotalChoice(ctx);
94 ok(ret == 0, "chewing_cand_TotalChoice() returns `%d' shall be `%d'", ret, 0);
95
96 chewing_delete(ctx);
97 }
98
test_cand_open_during_bopomofo()99 void test_cand_open_during_bopomofo()
100 {
101 ChewingContext *ctx;
102 int ret;
103
104 /* FIXME: shall we clean bopomofo when chewing_cand_open is called? */
105
106 ctx = chewing_new();
107 start_testcase(ctx, fd);
108
109 type_keystroke_by_string(ctx, "hk" /* ㄘㄜ */ );
110
111 ret = chewing_cand_open(ctx);
112 ok(ret == -1, "chewing_cand_open() returns `%d' shall be `%d'", ret, -1);
113
114 ret = chewing_cand_TotalChoice(ctx);
115 ok(ret == 0, "chewing_cand_TotalChoice() returns `%d' shall be `%d'", ret, 0);
116
117 chewing_Reset(ctx);
118
119 type_keystroke_by_string(ctx, "hk4g" /* ㄘㄜˋ ㄕ */ );
120 ret = chewing_cand_open(ctx);
121 ok(ret == 0, "chewing_cand_open() returns `%d' shall be `%d'", ret, 0);
122
123 ret = chewing_cand_TotalChoice(ctx);
124 ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall be greater than `%d'", ret, 0);
125
126 chewing_delete(ctx);
127 }
128
test_cand_open()129 void test_cand_open()
130 {
131 test_cand_open_word();
132 test_cand_open_symbol();
133 test_cand_open_already_opened();
134 test_cand_open_nothing_in_preedit();
135 test_cand_open_during_bopomofo();
136 }
137
test_cand_close_word()138 void test_cand_close_word()
139 {
140 ChewingContext *ctx;
141 int ret;
142
143 ctx = chewing_new();
144 start_testcase(ctx, fd);
145
146 type_keystroke_by_string(ctx, "hk4" /* ㄘㄜˋ */ );
147
148 ret = chewing_cand_open(ctx);
149 ok(ret == 0, "chewing_cand_open() returns `%d' shall be `%d'", ret, 0);
150
151 ret = chewing_cand_TotalChoice(ctx);
152 ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall be greater than `%d'", ret, 0);
153
154 ret = chewing_cand_close(ctx);
155 ok(ret == 0, "chewing_cand_close() returns `%d' shall be `%d'", ret, 0);
156
157 ret = chewing_cand_TotalChoice(ctx);
158 ok(ret == 0, "chewing_cand_TotalChoice() returns `%d' shall be 0 than `%d'", ret, 0);
159
160 ok_commit_buffer(ctx, "");
161
162 chewing_delete(ctx);
163 }
164
165
test_cand_close_symbol()166 void test_cand_close_symbol()
167 {
168 ChewingContext *ctx;
169 int ret;
170
171 ctx = chewing_new();
172 start_testcase(ctx, fd);
173
174 type_keystroke_by_string(ctx, "`31" /* , */ );
175
176 ret = chewing_cand_open(ctx);
177 ok(ret == 0, "chewing_cand_open() returns `%d' shall be `%d'", ret, 0);
178
179 ret = chewing_cand_TotalChoice(ctx);
180 ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall be greater than `%d'", ret, 0);
181
182 ret = chewing_cand_close(ctx);
183 ok(ret == 0, "chewing_cand_close() returns `%d' shall be `%d'", ret, 0);
184
185 ret = chewing_cand_TotalChoice(ctx);
186 ok(ret == 0, "chewing_cand_TotalChoice() returns `%d' shall be 0 than `%d'", ret, 0);
187
188 ok_commit_buffer(ctx, "");
189
190 chewing_delete(ctx);
191 }
192
test_cand_close_already_closed()193 void test_cand_close_already_closed()
194 {
195 ChewingContext *ctx;
196 int ret;
197
198 ctx = chewing_new();
199 start_testcase(ctx, fd);
200
201 type_keystroke_by_string(ctx, "hk4" /* ㄘㄜˋ */ );
202
203 ret = chewing_cand_close(ctx);
204 ok(ret == 0, "chewing_cand_close() returns `%d' shall be `%d'", ret, 0);
205
206 ret = chewing_cand_TotalChoice(ctx);
207 ok(ret == 0, "chewing_cand_TotalChoice() returns `%d' shall be 0 than `%d'", ret, 0);
208
209 chewing_delete(ctx);
210 }
211
test_cand_close_nothing_in_preedit()212 void test_cand_close_nothing_in_preedit()
213 {
214 ChewingContext *ctx;
215 int ret;
216
217 ctx = chewing_new();
218 start_testcase(ctx, fd);
219
220 ret = chewing_cand_close(ctx);
221 ok(ret == 0, "chewing_cand_close() returns `%d' shall be `%d'", ret, 0);
222
223 ret = chewing_cand_TotalChoice(ctx);
224 ok(ret == 0, "chewing_cand_TotalChoice() returns `%d' shall be 0 than `%d'", ret, 0);
225
226 chewing_delete(ctx);
227 }
228
test_cand_close()229 void test_cand_close()
230 {
231 test_cand_close_word();
232 test_cand_close_symbol();
233 test_cand_close_already_closed();
234 test_cand_close_nothing_in_preedit();
235 }
236
test_cand_choose_word()237 void test_cand_choose_word()
238 {
239 ChewingContext *ctx;
240 int ret;
241
242 clean_userphrase();
243
244 ctx = chewing_new();
245 start_testcase(ctx, fd);
246
247 type_keystroke_by_string(ctx, "hk4" /* ㄘㄜˋ */ );
248
249 ret = chewing_cand_open(ctx);
250 ok(ret == 0, "chewing_cand_open() returns `%d' shall be `%d'", ret, 0);
251
252 ret = chewing_cand_TotalChoice(ctx);
253 ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall be greater than `%d'", ret, 0);
254
255 ret = chewing_cand_choose_by_index(ctx, 2);
256 ok(ret == 0, "chewing_cand_choose_by_index() returns `%d' shall be `%d'", ret, 0);
257
258 ok_preedit_buffer(ctx, "\xE6\xB8\xAC" /* 測 */ );
259
260 chewing_delete(ctx);
261 }
262
test_cand_choose_symbol()263 void test_cand_choose_symbol()
264 {
265 ChewingContext *ctx;
266 int ret;
267
268 ctx = chewing_new();
269 start_testcase(ctx, fd);
270
271 type_keystroke_by_string(ctx, "`" /* , */ );
272
273 ret = chewing_cand_choose_by_index(ctx, 2);
274 ok(ret == 0, "chewing_cand_choose_by_index() returns `%d' shall be `%d'", ret, 0);
275
276 ret = chewing_cand_choose_by_index(ctx, 0);
277 ok(ret == 0, "chewing_cand_choose_by_index() returns `%d' shall be `%d'", ret, 0);
278
279 ok_preedit_buffer(ctx, "\xEF\xBC\x8C" /* , */ );
280
281 chewing_delete(ctx);
282 }
283
test_cand_choose_out_of_range()284 void test_cand_choose_out_of_range()
285 {
286 ChewingContext *ctx;
287 int ret;
288 int total_choice;
289
290 clean_userphrase();
291
292 ctx = chewing_new();
293 start_testcase(ctx, fd);
294
295 type_keystroke_by_string(ctx, "hk4" /* ㄘㄜˋ */ );
296
297 ret = chewing_cand_open(ctx);
298 ok(ret == 0, "chewing_cand_open() returns `%d' shall be `%d'", ret, 0);
299
300 total_choice = chewing_cand_TotalChoice(ctx);
301 ok(total_choice > 0, "chewing_cand_TotalChoice() returns `%d' shall be greater than `%d'", total_choice, 0);
302
303 ret = chewing_cand_choose_by_index(ctx, total_choice);
304 ok(ret == -1, "chewing_cand_choose_by_index() returns `%d' shall be `%d'", ret, -1);
305
306 ret = chewing_cand_choose_by_index(ctx, -1);
307 ok(ret == -1, "chewing_cand_choose_by_index() returns `%d' shall be `%d'", ret, -1);
308
309 ok_preedit_buffer(ctx, "\xE5\x86\x8A" /* 冊 */ );
310
311 chewing_delete(ctx);
312 }
313
test_cand_choose_second_layer()314 void test_cand_choose_second_layer()
315 {
316 ChewingContext *ctx;
317 int ret;
318
319 ctx = chewing_new();
320 start_testcase(ctx, fd);
321
322 type_keystroke_by_string(ctx, "`");
323 ret = chewing_cand_TotalChoice(ctx);
324 ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall be greater than `%d'", ret, 0);
325 ret = chewing_cand_choose_by_index(ctx, 2);
326 ok(ret == 0, "chewing_cand_choose_by_index() returns `%d' shall be `%d'", ret, 0);
327 ret = chewing_cand_TotalChoice(ctx);
328 ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall be greater than `%d'", ret, 0);
329 ret = chewing_cand_choose_by_index(ctx, 0);
330 ok(ret == 0, "chewing_cand_choose_by_index() returns `%d' shall be `%d'", ret, 0);
331 ok_preedit_buffer(ctx, "\xEF\xBC\x8C" /* , */ );
332
333 chewing_delete(ctx);
334 }
335
test_cand_choose_not_in_select()336 void test_cand_choose_not_in_select()
337 {
338 ChewingContext *ctx;
339 int ret;
340
341 clean_userphrase();
342
343 ctx = chewing_new();
344 start_testcase(ctx, fd);
345
346 type_keystroke_by_string(ctx, "hk4" /* ㄘㄜˋ */ );
347
348 ret = chewing_cand_TotalChoice(ctx);
349 ok(ret == 0, "chewing_cand_TotalChoice() returns `%d' shall be `%d'", ret, 0);
350
351 ret = chewing_cand_choose_by_index(ctx, 2);
352 ok(ret == -1, "chewing_cand_choose_by_index() returns `%d' shall be `%d'", ret, -1);
353
354 ok_preedit_buffer(ctx, "\xE5\x86\x8A" /* 冊 */ );
355
356 chewing_delete(ctx);
357 }
358
test_cand_choose()359 void test_cand_choose()
360 {
361 test_cand_choose_word();
362 test_cand_choose_symbol();
363 test_cand_choose_second_layer();
364 test_cand_choose_out_of_range();
365 test_cand_choose_not_in_select();
366 }
367
test_cand_list_word_no_rearward()368 void test_cand_list_word_no_rearward()
369 {
370 ChewingContext *ctx;
371 int ret;
372
373 ctx = chewing_new();
374 start_testcase(ctx, fd);
375 chewing_set_phraseChoiceRearward(ctx, 0);
376
377 type_keystroke_by_string(ctx, "hk4g4<H>" /* 測試 */ );
378
379 ret = chewing_cand_open(ctx);
380 ok(ret == 0, "chewing_cand_open() returns `%d' shall be `%d'", ret, 0);
381 ok_candidate_len(ctx, 2);
382
383 ret = chewing_cand_list_has_next(ctx);
384 ok(ret == 1, "chewing_cand_list_has_next() returns `%d' shall be `%d'", ret, 1);
385 ret = chewing_cand_list_next(ctx);
386 ok(ret == 0, "chewing_cand_list_next() returns `%d' shall be `%d'", ret, 0);
387 ok_candidate_len(ctx, 1);
388
389 ret = chewing_cand_list_has_next(ctx);
390 ok(ret == 0, "chewing_cand_list_has_next() returns `%d' shall be `%d'", ret, 0);
391 ret = chewing_cand_list_next(ctx);
392 ok(ret == -1, "chewing_cand_list_next() returns `%d' shall be `%d'", ret, -1);
393 ok_candidate_len(ctx, 1);
394
395 ret = chewing_cand_list_has_prev(ctx);
396 ok(ret == 1, "chewing_cand_list_has_prev() returns `%d' shall be `%d'", ret, 1);
397 ret = chewing_cand_list_prev(ctx);
398 ok(ret == 0, "chewing_cand_list_prev() returns `%d' shall be `%d'", ret, 0);
399 ok_candidate_len(ctx, 2);
400
401 ret = chewing_cand_list_has_prev(ctx);
402 ok(ret == 0, "chewing_cand_list_has_prev() returns `%d' shall be `%d'", ret, 0);
403 ret = chewing_cand_list_prev(ctx);
404 ok(ret == -1, "chewing_cand_list_prev() returns `%d' shall be `%d'", ret, -1);
405 ok_candidate_len(ctx, 2);
406
407 ret = chewing_cand_list_last(ctx);
408 ok(ret == 0, "chewing_cand_list_last() returns `%d' shall be `%d'", ret, 0);
409 ok_candidate_len(ctx, 1);
410
411 ret = chewing_cand_list_first(ctx);
412 ok(ret == 0, "chewing_cand_list_first() returns `%d' shall be `%d'", ret, 0);
413 ok_candidate_len(ctx, 2);
414
415 chewing_delete(ctx);
416 }
417
test_cand_list_word_rearward()418 void test_cand_list_word_rearward()
419 {
420 ChewingContext *ctx;
421 int ret;
422
423 ctx = chewing_new();
424 start_testcase(ctx, fd);
425 chewing_set_phraseChoiceRearward(ctx, 1);
426
427 type_keystroke_by_string(ctx, "hk4g4" /* 測試 */ );
428
429 ret = chewing_cand_open(ctx);
430 ok(ret == 0, "chewing_cand_open() returns `%d' shall be `%d'", ret, 0);
431 ok_candidate_len(ctx, 2);
432
433 ret = chewing_cand_list_has_next(ctx);
434 ok(ret == 1, "chewing_cand_list_has_next() returns `%d' shall be `%d'", ret, 1);
435 ret = chewing_cand_list_next(ctx);
436 ok(ret == 0, "chewing_cand_list_next() returns `%d' shall be `%d'", ret, 0);
437 ok_candidate_len(ctx, 1);
438
439 ret = chewing_cand_list_has_next(ctx);
440 ok(ret == 0, "chewing_cand_list_has_next() returns `%d' shall be `%d'", ret, 0);
441 ret = chewing_cand_list_next(ctx);
442 ok(ret == -1, "chewing_cand_list_next() returns `%d' shall be `%d'", ret, -1);
443 ok_candidate_len(ctx, 1);
444
445 ret = chewing_cand_list_has_prev(ctx);
446 ok(ret == 1, "chewing_cand_list_has_prev() returns `%d' shall be `%d'", ret, 1);
447 ret = chewing_cand_list_prev(ctx);
448 ok(ret == 0, "chewing_cand_list_prev() returns `%d' shall be `%d'", ret, 0);
449 ok_candidate_len(ctx, 2);
450
451 ret = chewing_cand_list_has_prev(ctx);
452 ok(ret == 0, "chewing_cand_list_has_prev() returns `%d' shall be `%d'", ret, 0);
453 ret = chewing_cand_list_prev(ctx);
454 ok(ret == -1, "chewing_cand_list_prev() returns `%d' shall be `%d'", ret, -1);
455 ok_candidate_len(ctx, 2);
456
457 ret = chewing_cand_list_last(ctx);
458 ok(ret == 0, "chewing_cand_list_last() returns `%d' shall be `%d'", ret, 0);
459 ok_candidate_len(ctx, 1);
460
461 ret = chewing_cand_list_first(ctx);
462 ok(ret == 0, "chewing_cand_list_first() returns `%d' shall be `%d'", ret, 0);
463 ok_candidate_len(ctx, 2);
464
465 chewing_delete(ctx);
466 }
467
468
test_cand_list_word_selection_next_no_rearward()469 void test_cand_list_word_selection_next_no_rearward()
470 {
471 ChewingContext *ctx;
472 int ret;
473
474 clean_userphrase();
475
476 ctx = chewing_new();
477 start_testcase(ctx, fd);
478
479 type_keystroke_by_string(ctx, "u61o4y7<H>" /* ㄧˊ ㄅㄟˋ ㄗ˙ */ );
480
481 ret = chewing_cand_open(ctx);
482 ok(ret == 0, "chewing_cand_open() returns `%d' shall be `%d'", ret, 0);
483
484 ret = chewing_cand_TotalChoice(ctx);
485 ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall be greater than `%d'", ret, 0);
486 ok_candidate_len(ctx, 3);
487
488 ret = chewing_cand_list_has_next(ctx);
489 ok(ret == 1, "chewing_cand_list_has_next() returns `%d' shall be `%d'", ret, 1);
490 ret = chewing_cand_list_next(ctx);
491 ok(ret == 0, "chewing_cand_list_next() returns `%d' shall be `%d'", ret, 0);
492
493 ret = chewing_cand_TotalChoice(ctx);
494 ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall be greater than `%d'", ret, 0);
495 ok_candidate_len(ctx, 2);
496
497 ret = chewing_cand_choose_by_index(ctx, 1);
498 ok(ret == 0, "chewing_cand_choose_by_index() returns `%d' shall be `%d'", ret, 0);
499
500 ok_preedit_buffer(ctx, "\xE4\xB8\x80\xE8\xBC\xA9\xE5\xAD\x90" /* 一輩子 */ );
501
502 chewing_delete(ctx);
503 }
504
test_cand_list_word_selection_next_rearward()505 void test_cand_list_word_selection_next_rearward()
506 {
507 ChewingContext *ctx;
508 int ret;
509
510 clean_userphrase();
511
512 ctx = chewing_new();
513 start_testcase(ctx, fd);
514
515 chewing_set_phraseChoiceRearward(ctx, 1);
516
517 type_keystroke_by_string(ctx, "u61o4y7" /* ㄧˊ ㄅㄟˋ ㄗ˙ */ );
518
519 ret = chewing_cand_open(ctx);
520 ok(ret == 0, "chewing_cand_open() returns `%d' shall be `%d'", ret, 0);
521
522 ret = chewing_cand_TotalChoice(ctx);
523 ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall be greater than `%d'", ret, 0);
524 ok_candidate_len(ctx, 3);
525
526 ret = chewing_cand_list_has_next(ctx);
527 ok(ret == 1, "chewing_cand_list_has_next() returns `%d' shall be `%d'", ret, 1);
528 ret = chewing_cand_list_next(ctx);
529 ok(ret == 0, "chewing_cand_list_next() returns `%d' shall be `%d'", ret, 0);
530
531 ret = chewing_cand_TotalChoice(ctx);
532 ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall be greater than `%d'", ret, 0);
533 ok_candidate_len(ctx, 2);
534
535 ret = chewing_cand_choose_by_index(ctx, 0);
536 ok(ret == 0, "chewing_cand_choose_by_index() returns `%d' shall be `%d'", ret, 0);
537
538 ok_preedit_buffer(ctx, "\xE4\xB8\x80\xE8\xBC\xA9\xE5\xAD\x90" /* 一輩子 */ );
539
540 chewing_delete(ctx);
541 }
542
test_cand_list_word_selection_prev_no_rearward()543 void test_cand_list_word_selection_prev_no_rearward()
544 {
545 ChewingContext *ctx;
546 int ret;
547
548 clean_userphrase();
549
550 ctx = chewing_new();
551 start_testcase(ctx, fd);
552
553 type_keystroke_by_string(ctx, "u61o4y7<H>" /* ㄧˊ ㄅㄟˋ ㄗ˙ */ );
554
555 ret = chewing_cand_open(ctx);
556 ok(ret == 0, "chewing_cand_open() returns `%d' shall be `%d'", ret, 0);
557
558 ret = chewing_cand_TotalChoice(ctx);
559 ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall be greater than `%d'", ret, 0);
560 ok_candidate_len(ctx, 3);
561
562 ret = chewing_cand_list_last(ctx);
563 ok(ret == 0, "chewing_cand_list_last() returns `%d' shall be `%d'", ret, 1);
564 ok_candidate_len(ctx, 1);
565
566 ret = chewing_cand_list_has_prev(ctx);
567 ok(ret == 1, "chewing_cand_list_has_prev() returns `%d' shall be `%d'", ret, 1);
568 ret = chewing_cand_list_prev(ctx);
569 ok(ret == 0, "chewing_cand_list_prev() returns `%d' shall be `%d'", ret, 0);
570
571 ret = chewing_cand_TotalChoice(ctx);
572 ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall be greater than `%d'", ret, 0);
573 ok_candidate_len(ctx, 2);
574
575 ret = chewing_cand_choose_by_index(ctx, 1);
576 ok(ret == 0, "chewing_cand_choose_by_index() returns `%d' shall be `%d'", ret, 0);
577
578 ok_preedit_buffer(ctx, "\xE4\xB8\x80\xE8\xBC\xA9\xE5\xAD\x90" /* 一輩子 */ );
579
580 chewing_delete(ctx);
581 }
582
test_cand_list_word_selection_prev_rearward()583 void test_cand_list_word_selection_prev_rearward()
584 {
585 ChewingContext *ctx;
586 int ret;
587
588 clean_userphrase();
589
590 ctx = chewing_new();
591 start_testcase(ctx, fd);
592
593 chewing_set_phraseChoiceRearward(ctx, 1);
594
595 type_keystroke_by_string(ctx, "u61o4y7" /* ㄧˊ ㄅㄟˋ ㄗ˙ */ );
596
597 ret = chewing_cand_open(ctx);
598 ok(ret == 0, "chewing_cand_open() returns `%d' shall be `%d'", ret, 0);
599
600 ret = chewing_cand_TotalChoice(ctx);
601 ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall be greater than `%d'", ret, 0);
602 ok_candidate_len(ctx, 3);
603
604 ret = chewing_cand_list_last(ctx);
605 ok(ret == 0, "chewing_cand_list_last() returns `%d' shall be `%d'", ret, 1);
606 ok_candidate_len(ctx, 1);
607
608 ret = chewing_cand_list_has_prev(ctx);
609 ok(ret == 1, "chewing_cand_list_has_prev() returns `%d' shall be `%d'", ret, 1);
610 ret = chewing_cand_list_prev(ctx);
611 ok(ret == 0, "chewing_cand_list_prev() returns `%d' shall be `%d'", ret, 0);
612
613 ret = chewing_cand_TotalChoice(ctx);
614 ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall be greater than `%d'", ret, 0);
615 ok_candidate_len(ctx, 2);
616
617 ret = chewing_cand_choose_by_index(ctx, 0);
618 ok(ret == 0, "chewing_cand_choose_by_index() returns `%d' shall be `%d'", ret, 0);
619
620 ok_preedit_buffer(ctx, "\xE4\xB8\x80\xE8\xBC\xA9\xE5\xAD\x90" /* 一輩子 */ );
621
622 chewing_delete(ctx);
623 }
624
test_cand_list_word()625 void test_cand_list_word()
626 {
627 test_cand_list_word_no_rearward();
628 test_cand_list_word_rearward();
629 test_cand_list_word_selection_next_no_rearward();
630 test_cand_list_word_selection_next_rearward();
631 test_cand_list_word_selection_prev_no_rearward();
632 test_cand_list_word_selection_prev_rearward();
633 }
634
test_cand_list_symbol()635 void test_cand_list_symbol()
636 {
637 ChewingContext *ctx;
638 int ret;
639
640 ctx = chewing_new();
641 start_testcase(ctx, fd);
642 type_keystroke_by_string(ctx, "`31" /* , */ );
643
644 ret = chewing_cand_open(ctx);
645 ok(ret == 0, "chewing_cand_open() returns `%d' shall be `%d'", ret, 0);
646 ok_candidate_len(ctx, 1);
647
648 ret = chewing_cand_list_has_next(ctx);
649 ok(ret == 0, "chewing_cand_list_has_next() returns `%d' shall be `%d'", ret, 0);
650 ret = chewing_cand_list_next(ctx);
651 ok(ret == -1, "chewing_cand_list_has_next() returns `%d' shall be `%d'", ret, -1);
652 ok_candidate_len(ctx, 1);
653
654 ret = chewing_cand_list_has_prev(ctx);
655 ok(ret == 0, "chewing_cand_list_has_prev() returns `%d' shall be `%d'", ret, 0);
656 ret = chewing_cand_list_prev(ctx);
657 ok(ret == -1, "chewing_cand_list_prev() returns `%d' shall be `%d'", ret, -1);
658 ok_candidate_len(ctx, 1);
659
660 ret = chewing_cand_list_first(ctx);
661 ok(ret == 0, "chewing_cand_list_first() returns `%d' shall be `%d'", ret, 0);
662 ok_candidate_len(ctx, 1);
663
664 ret = chewing_cand_list_last(ctx);
665 ok(ret == 0, "chewing_cand_list_last() returns `%d' shall be `%d'", ret, 0);
666 ok_candidate_len(ctx, 1);
667
668 chewing_delete(ctx);
669 }
670
test_cand_list_no_cand_windows()671 void test_cand_list_no_cand_windows()
672 {
673 ChewingContext *ctx;
674 int ret;
675
676 ctx = chewing_new();
677 start_testcase(ctx, fd);
678
679 type_keystroke_by_string(ctx, "hk4g4" /* 測試 */ );
680
681 ret = chewing_cand_list_has_next(ctx);
682 ok(ret == 0, "chewing_cand_list_has_next() returns `%d' shall be `%d'", ret, 0);
683 ret = chewing_cand_list_next(ctx);
684 ok(ret == -1, "chewing_cand_list_next() returns `%d' shall be `%d'", ret, -1);
685
686 ret = chewing_cand_list_has_prev(ctx);
687 ok(ret == 0, "chewing_cand_list_has_prev() returns `%d' shall be `%d'", ret, 0);
688 ret = chewing_cand_list_prev(ctx);
689 ok(ret == -1, "chewing_cand_list_prev() returns `%d' shall be `%d'", ret, -1);
690
691 ret = chewing_cand_list_first(ctx);
692 ok(ret == -1, "chewing_cand_list_first() returns `%d' shall be `%d'", ret, 0);
693
694 ret = chewing_cand_list_last(ctx);
695 ok(ret == -1, "chewing_cand_list_last() returns `%d' shall be `%d'", ret, 0);
696
697 chewing_delete(ctx);
698 }
699
test_cand_list()700 void test_cand_list()
701 {
702 test_cand_list_word();
703 test_cand_list_symbol();
704 test_cand_list_no_cand_windows();
705 }
706
test_commit_preedit_normal()707 void test_commit_preedit_normal()
708 {
709 static const char phrase[] = "\xE6\xB8\xAC\xE8\xA9\xA6" /* 測試 */ ;
710 ChewingContext *ctx;
711 int ret;
712
713 ctx = chewing_new();
714 start_testcase(ctx, fd);
715
716 type_keystroke_by_string(ctx, "hk4g4" /* 測試 */ );
717 ret = chewing_commit_preedit_buf(ctx);
718 ok(ret == 0, "chewing_commit_preedit_buf() returns `%d' shall be `%d'", ret, 0);
719
720 ok_preedit_buffer(ctx, "");
721 ok_commit_buffer(ctx, phrase);
722
723 chewing_delete(ctx);
724 }
725
test_commit_preedit_empty()726 void test_commit_preedit_empty()
727 {
728 ChewingContext *ctx;
729 int ret;
730
731 ctx = chewing_new();
732 start_testcase(ctx, fd);
733
734 ret = chewing_commit_preedit_buf(ctx);
735 ok(ret == -1, "chewing_commit_preedit_buf() returns `%d' shall be `%d'", ret, -1);
736
737 ok_preedit_buffer(ctx, "");
738 ok_commit_buffer(ctx, "");
739
740 chewing_delete(ctx);
741 }
742
test_commit_preedit_during_cand_selecting()743 void test_commit_preedit_during_cand_selecting()
744 {
745 static const char phrase[] = "\xE6\xB8\xAC\xE8\xA9\xA6" /* 測試 */ ;
746 ChewingContext *ctx;
747 int ret;
748
749 ctx = chewing_new();
750 start_testcase(ctx, fd);
751
752 type_keystroke_by_string(ctx, "hk4g4" /* 測試 */ );
753
754 ret = chewing_cand_open(ctx);
755 ok(ret == 0, "chewing_cand_open() returns `%d' shall be `%d'", ret, 0);
756
757 ret = chewing_commit_preedit_buf(ctx);
758 ok(ret == -1, "chewing_commit_preedit_buf() returns `%d' shall be `%d'", ret, -1);
759
760 ok_preedit_buffer(ctx, phrase);
761 ok_commit_buffer(ctx, "");
762
763 chewing_delete(ctx);
764 }
765
test_commit_preedit()766 void test_commit_preedit()
767 {
768 test_commit_preedit_normal();
769 test_commit_preedit_empty();
770 test_commit_preedit_during_cand_selecting();
771 }
772
test_clean_preedit_normal()773 void test_clean_preedit_normal()
774 {
775 ChewingContext *ctx;
776 int ret;
777
778 ctx = chewing_new();
779 start_testcase(ctx, fd);
780
781 type_keystroke_by_string(ctx, "hk4g4" /* 測試 */ );
782 ret = chewing_clean_preedit_buf(ctx);
783 ok(ret == 0, "chewing_clean_preedit_buf() returns `%d' shall be `%d'", ret, 0);
784
785 ok_preedit_buffer(ctx, "");
786 ok_commit_buffer(ctx, "");
787
788 chewing_delete(ctx);
789 }
790
test_clean_preedit_empty()791 void test_clean_preedit_empty()
792 {
793 ChewingContext *ctx;
794 int ret;
795
796 ctx = chewing_new();
797 start_testcase(ctx, fd);
798
799 ret = chewing_clean_preedit_buf(ctx);
800 ok(ret == 0, "chewing_clean_preedit_buf() returns `%d' shall be `%d'", ret, 0);
801
802 ok_preedit_buffer(ctx, "");
803 ok_commit_buffer(ctx, "");
804
805 chewing_delete(ctx);
806 }
807
test_clean_preedit_during_cand_selecting()808 void test_clean_preedit_during_cand_selecting()
809 {
810 static const char phrase[] = "\xE6\xB8\xAC\xE8\xA9\xA6" /* 測試 */ ;
811 ChewingContext *ctx;
812 int ret;
813
814 ctx = chewing_new();
815 start_testcase(ctx, fd);
816
817 type_keystroke_by_string(ctx, "hk4g4" /* 測試 */ );
818
819 ret = chewing_cand_open(ctx);
820 ok(ret == 0, "chewing_cand_open() returns `%d' shall be `%d'", ret, 0);
821
822 ret = chewing_clean_preedit_buf(ctx);
823 ok(ret == -1, "chewing_commit_preedit_buf() returns `%d' shall be `%d'", ret, -1);
824
825 ok_preedit_buffer(ctx, phrase);
826 ok_commit_buffer(ctx, "");
827
828 chewing_delete(ctx);
829 }
830
test_clean_preedit()831 void test_clean_preedit()
832 {
833 test_clean_preedit_normal();
834 test_clean_preedit_empty();
835 test_clean_preedit_during_cand_selecting();
836 }
837
test_clean_bopomofo_normal()838 void test_clean_bopomofo_normal()
839 {
840 ChewingContext *ctx;
841 int ret;
842
843 ctx = chewing_new();
844 start_testcase(ctx, fd);
845
846 type_keystroke_by_string(ctx, "hk" /* ㄘㄜ */ );
847 ret = chewing_clean_bopomofo_buf(ctx);
848 ok(ret == 0, "chewing_clean_bopomofo_buf() returns `%d' shall be `%d'", ret, 0);
849
850 ok_bopomofo_buffer(ctx, "");
851
852 chewing_delete(ctx);
853 }
854
test_clean_bopomofo_empty()855 void test_clean_bopomofo_empty()
856 {
857 ChewingContext *ctx;
858 int ret;
859
860 ctx = chewing_new();
861 start_testcase(ctx, fd);
862
863 ret = chewing_clean_bopomofo_buf(ctx);
864 ok(ret == 0, "chewing_clean_bopomofo_buf() returns `%d' shall be `%d'", ret, 0);
865
866 ok_bopomofo_buffer(ctx, "");
867
868 chewing_delete(ctx);
869 }
870
test_clean_bopomofo_after_complete()871 void test_clean_bopomofo_after_complete()
872 {
873 ChewingContext *ctx;
874 int ret;
875
876 ctx = chewing_new();
877 start_testcase(ctx, fd);
878
879 type_keystroke_by_string(ctx, "hk4" /* ㄘㄜˋ */ );
880 ret = chewing_clean_bopomofo_buf(ctx);
881 ok(ret == 0, "chewing_clean_bopomofo_buf() returns `%d' shall be `%d'", ret, 0);
882
883 ok_preedit_buffer(ctx, "\xE5\x86\x8A" /* 冊 */ );
884 ok_bopomofo_buffer(ctx, "");
885
886 chewing_delete(ctx);
887 }
888
test_clean_bopomofo_during_cand_selecting()889 void test_clean_bopomofo_during_cand_selecting()
890 {
891 ChewingContext *ctx;
892 int ret;
893
894 ctx = chewing_new();
895 start_testcase(ctx, fd);
896
897 type_keystroke_by_string(ctx, "hk4g4" /* 測試 */ );
898
899 ret = chewing_cand_open(ctx);
900 ok(ret == 0, "chewing_cand_open() returns `%d' shall be `%d'", ret, 0);
901
902 /* XXX: Shall return 0 in select mode? */
903 ret = chewing_clean_bopomofo_buf(ctx);
904 ok(ret == 0, "chewing_clean_bopomofo_buf() returns `%d' shall be `%d'", ret, 0);
905
906 ok_bopomofo_buffer(ctx, "");
907
908 chewing_delete(ctx);
909 }
910
test_clean_bopomofo()911 void test_clean_bopomofo()
912 {
913 test_clean_bopomofo_normal();
914 test_clean_bopomofo_empty();
915 test_clean_bopomofo_after_complete();
916 test_clean_bopomofo_during_cand_selecting();
917 }
918
main(int argc,char * argv[])919 int main(int argc, char *argv[])
920 {
921 char *logname;
922 int ret;
923
924 putenv("CHEWING_PATH=" CHEWING_DATA_PREFIX);
925 putenv("CHEWING_USER_PATH=" TEST_HASH_DIR);
926
927 ret = asprintf(&logname, "%s.log", argv[0]);
928 if (ret == -1)
929 return -1;
930 fd = fopen(logname, "w");
931 assert(fd);
932 free(logname);
933
934
935 test_cand_open();
936 test_cand_close();
937 test_cand_choose();
938 test_cand_list();
939
940 test_commit_preedit();
941 test_clean_preedit();
942
943 test_clean_bopomofo();
944
945 fclose(fd);
946
947 return exit_status();
948 }
949