1 /**
2 * test-regression.c
3 *
4 * Copyright (c) 2012
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
11 #ifdef HAVE_CONFIG_H
12 # include <config.h>
13 #endif
14
15 #include <assert.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18
19 #include "chewing.h"
20 #include "plat_types.h"
21 #include "testhelper.h"
22
23 FILE *fd;
24
test_libchewing_googlecode_issue_472()25 void test_libchewing_googlecode_issue_472()
26 {
27 static const char *const INPUT[] = {
28 "<T>|&Wt<H>mrJY)G<C2>OqJ<H><H>Yl<R>p0<EE>QE[^<C1>k",
29 "+F<C9>hQ$UIICMr!X8/9<C3>(N<T>yU2!-LUI<D>`CS<D>jShm9SF}<EN>[`QYu<C8>k",
30 "hk4`2<D>jk",
31 "hk4`j 0",
32 "hk4<C0>j 0",
33 };
34 size_t i;
35 ChewingContext *ctx;
36
37 ctx = chewing_new();
38 start_testcase(ctx, fd);
39 chewing_set_maxChiSymbolLen(ctx, 16);
40 chewing_set_autoShiftCur(ctx, 1);
41
42 for (i = 0; i < ARRAY_SIZE(INPUT); ++i) {
43 chewing_Reset(ctx);
44 type_keystroke_by_string(ctx, INPUT[i]);
45 }
46
47 chewing_delete(ctx);
48 }
49
test_libchewing_googlecode_issue_473()50 void test_libchewing_googlecode_issue_473()
51 {
52 static const char *const INPUT[] = {
53 "t<N->_ M1<N+>H[Ls3<L><N1>PL+Z]4<C1>&(^H*H<TT>Sc<N->P]!|<CB>-<C6>S<H><N1><C0>U<B>d}P!f<EN><N.><C7>V!U!w|4-=S<C1>b<N2>Q",
54 "wv<C0><C5><N9>$FIF<D><N4>B *<C2>E4*<C2>q)Kf)<SS><TT>4=<N5>%<R>mN4<EN>H<N9><N.>8s{XTD<N6>jZV(y3G`9<C6>JTy<B>J<C1>SNc<E>hC<SL><N/><R><C6>@an<C3><N7>wzF<C3>P*<N*><B>l<C3><N6>W<N*> $<SR><N.><N1><E><E><N0><N6>Y",
55 };
56 size_t i;
57 ChewingContext *ctx;
58
59 ctx = chewing_new();
60 start_testcase(ctx, fd);
61 chewing_set_maxChiSymbolLen(ctx, 16);
62 chewing_set_autoShiftCur(ctx, 1);
63 chewing_set_candPerPage(ctx, 9);
64 chewing_set_addPhraseDirection(ctx, 1);
65 chewing_set_spaceAsSelection(ctx, 1);
66
67 for (i = 0; i < ARRAY_SIZE(INPUT); ++i) {
68 chewing_Reset(ctx);
69 type_keystroke_by_string(ctx, INPUT[i]);
70 }
71
72 chewing_delete(ctx);
73 }
74
test_libchewing_issue_30()75 void test_libchewing_issue_30()
76 {
77 ChewingContext *ctx;
78 int cursor;
79
80 clean_userphrase();
81
82 ctx = chewing_new();
83 start_testcase(ctx, fd);
84 chewing_set_maxChiSymbolLen(ctx, 16);
85 chewing_set_autoShiftCur(ctx, 1);
86 chewing_set_spaceAsSelection(ctx, 1);
87 chewing_set_phraseChoiceRearward(ctx, 1);
88
89 type_keystroke_by_string(ctx, "hk4g4<H> 3 1");
90 cursor = chewing_cursor_Current(ctx);
91 ok(cursor == 2, "cursor position `%d' shall be `2'", cursor);
92
93 chewing_delete(ctx);
94 }
95
test_libchewing_issue_108()96 void test_libchewing_issue_108()
97 {
98 ChewingContext *ctx;
99
100 clean_userphrase();
101
102 ctx = chewing_new();
103 start_testcase(ctx, fd);
104
105 type_keystroke_by_string(ctx, "yjo4cl3183<E>");
106
107 chewing_delete(ctx);
108 }
109
test_libchewing_data_issue_1()110 void test_libchewing_data_issue_1()
111 {
112 const TestData DATA = { "e03y.3", "\xE8\xB6\x95\xE8\xB5\xB0" /* 趕走 */ };
113 ChewingContext *ctx;
114
115 clean_userphrase();
116
117 ctx = chewing_new();
118 start_testcase(ctx, fd);
119 chewing_set_maxChiSymbolLen(ctx, 16);
120 type_keystroke_by_string(ctx, DATA.token);
121 ok_preedit_buffer(ctx, DATA.expected);
122
123 chewing_delete(ctx);
124 }
125
main(int argc,char * argv[])126 int main(int argc, char *argv[])
127 {
128 char *logname;
129 int ret;
130
131 putenv("CHEWING_PATH=" CHEWING_DATA_PREFIX);
132 putenv("CHEWING_USER_PATH=" TEST_HASH_DIR);
133
134 ret = asprintf(&logname, "%s.log", argv[0]);
135 if (ret == -1)
136 return -1;
137 fd = fopen(logname, "w");
138 assert(fd);
139 free(logname);
140
141
142 test_libchewing_data_issue_1();
143 test_libchewing_issue_30();
144 test_libchewing_issue_108();
145 test_libchewing_googlecode_issue_472();
146 test_libchewing_googlecode_issue_473();
147
148 fclose(fd);
149
150 return exit_status();
151 }
152