This source file includes following definitions.
- mc_refresh
- edit_load_syntax
- edit_get_syntax_color
- edit_load_macro_cmd
- edit_completion_dialog_show
- edit_completion_dialog_show__init
- edit_completion_dialog_show__string_free
- edit_completion_dialog_show__deinit
- my_setup
- my_teardown
- START_PARAMETRIZED_TEST
- START_PARAMETRIZED_TEST
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 #define TEST_SUITE_NAME "/src/editor"
28
29 #include "tests/mctest.h"
30
31 #include <ctype.h>
32
33 #ifdef HAVE_CHARSET
34 #include "lib/charsets.h"
35 #endif
36 #include "lib/strutil.h"
37
38 #include "src/vfs/local/local.c"
39 #ifdef HAVE_CHARSET
40 #include "src/selcodepage.h"
41 #endif
42 #include "src/editor/editwidget.h"
43 #include "src/editor/editmacros.h"
44 #include "src/editor/editcomplete.h"
45
46 static WGroup owner;
47 static WEdit *test_edit;
48
49
50
51 void
52 mc_refresh (void)
53 {
54 }
55
56
57
58 void
59 edit_load_syntax (WEdit *_edit, GPtrArray *_pnames, const char *_type)
60 {
61 (void) _edit;
62 (void) _pnames;
63 (void) _type;
64 }
65
66
67
68
69 int
70 edit_get_syntax_color (WEdit *_edit, off_t _byte_index)
71 {
72 (void) _edit;
73 (void) _byte_index;
74
75 return 0;
76 }
77
78
79
80
81 gboolean
82 edit_load_macro_cmd (WEdit *_edit)
83 {
84 (void) _edit;
85
86 return FALSE;
87 }
88
89
90
91
92 static const WEdit *edit_completion_dialog_show__edit;
93
94 static int edit_completion_dialog_show__max_width;
95
96 static GQueue *edit_completion_dialog_show__compl;
97
98
99 static char *edit_completion_dialog_show__return_value;
100
101
102 char *
103 edit_completion_dialog_show (const WEdit *edit, GQueue *compl, int max_width)
104 {
105
106 edit_completion_dialog_show__edit = edit;
107 edit_completion_dialog_show__max_width = max_width;
108
109 {
110 GList *i;
111
112 edit_completion_dialog_show__compl = g_queue_new ();
113
114 for (i = g_queue_peek_tail_link (compl); i != NULL; i = g_list_previous (i))
115 {
116 GString *s = (GString *) i->data;
117
118 g_queue_push_tail (edit_completion_dialog_show__compl, mc_g_string_dup (s));
119 }
120 }
121
122 return edit_completion_dialog_show__return_value;
123 }
124
125 static void
126 edit_completion_dialog_show__init (void)
127 {
128 edit_completion_dialog_show__edit = NULL;
129 edit_completion_dialog_show__max_width = 0;
130 edit_completion_dialog_show__compl = NULL;
131 edit_completion_dialog_show__return_value = NULL;
132 }
133
134 static void
135 edit_completion_dialog_show__string_free (gpointer data)
136 {
137 g_string_free ((GString *) data, TRUE);
138 }
139
140 static void
141 edit_completion_dialog_show__deinit (void)
142 {
143 if (edit_completion_dialog_show__compl != NULL)
144 g_queue_free_full (edit_completion_dialog_show__compl,
145 edit_completion_dialog_show__string_free);
146 }
147
148
149
150
151 static void
152 my_setup (void)
153 {
154 WRect r;
155 edit_arg_t arg;
156
157 str_init_strings (NULL);
158
159 vfs_init ();
160 vfs_init_localfs ();
161 vfs_setup_work_dir ();
162
163 #ifdef HAVE_CHARSET
164 mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
165 load_codepages_list ();
166 #endif
167
168 mc_global.main_config = mc_config_init ("edit_complete_word_cmd.ini", FALSE);
169 mc_config_set_bool (mc_global.main_config, CONFIG_APP_SECTION,
170 "editor_wordcompletion_collect_all_files", TRUE);
171
172 edit_options.filesize_threshold = (char *) "64M";
173
174 rect_init (&r, 0, 0, 24, 80);
175 arg.file_vpath = vfs_path_from_str ("test-data.txt");
176 arg.line_number = 1;
177 test_edit = edit_init (NULL, &r, &arg);
178 memset (&owner, 0, sizeof (owner));
179 group_add_widget (&owner, WIDGET (test_edit));
180 edit_completion_dialog_show__init ();
181 }
182
183
184
185
186 static void
187 my_teardown (void)
188 {
189 edit_completion_dialog_show__deinit ();
190 edit_clean (test_edit);
191 group_remove_widget (test_edit);
192 g_free (test_edit);
193
194 mc_config_deinit (mc_global.main_config);
195
196 #ifdef HAVE_CHARSET
197 free_codepages_list ();
198 #endif
199
200 vfs_shut ();
201
202 str_uninit_strings ();
203 }
204
205
206
207 #ifdef HAVE_CHARSET
208
209
210 static const struct test_autocomplete_ds
211 {
212 off_t input_position;
213 const char *input_system_code_page;
214 int input_source_codepage_id;
215 const char *input_editor_code_page;
216 int input_display_codepage_id;
217 const char *input_completed_word;
218
219 int expected_max_width;
220 int expected_compl_word_count;
221 int input_completed_word_start_pos;
222 const char *expected_completed_word;
223 } test_autocomplete_ds[] =
224 {
225 {
226 102,
227 "KOI8-R",
228 0,
229 "UTF-8",
230 1,
231 "эъйцукен",
232
233 16,
234 2,
235 98,
236 "эъйцукен"
237 },
238 {
239 138,
240 "UTF-8",
241 1,
242 "KOI8-R",
243 0,
244 "\xDC\xDF\xCA\xC3\xD5\xCB\xC5\xCE",
245
246 8,
247 2,
248 136,
249 "\xDC\xDF\xCA\xC3\xD5\xCB\xC5\xCE"
250 },
251 };
252
253
254
255
256 START_PARAMETRIZED_TEST (test_autocomplete, test_autocomplete_ds)
257
258 {
259
260 edit_completion_dialog_show__return_value = g_strdup (data->input_completed_word);
261
262
263 mc_global.source_codepage = data->input_source_codepage_id;
264 mc_global.display_codepage = data->input_display_codepage_id;
265 cp_source = data->input_editor_code_page;
266 cp_display = data->input_system_code_page;
267
268 do_set_codepage (0);
269 edit_set_codeset (test_edit);
270
271
272 edit_cursor_move (test_edit, data->input_position);
273 edit_complete_word_cmd (test_edit);
274
275
276 mctest_assert_ptr_eq (edit_completion_dialog_show__edit, test_edit);
277 ck_assert_int_eq (g_queue_get_length (edit_completion_dialog_show__compl),
278 data->expected_compl_word_count);
279 ck_assert_int_eq (edit_completion_dialog_show__max_width, data->expected_max_width);
280
281 {
282 off_t i = 0;
283 GString *actual_completed_str;
284
285 actual_completed_str = g_string_new ("");
286
287 while (TRUE)
288 {
289 int chr;
290
291 chr =
292 edit_buffer_get_byte (&test_edit->buffer,
293 data->input_completed_word_start_pos + i++);
294 if (isspace (chr))
295 break;
296 g_string_append_c (actual_completed_str, chr);
297 }
298 mctest_assert_str_eq (actual_completed_str->str, data->expected_completed_word);
299 g_string_free (actual_completed_str, TRUE);
300 }
301 }
302
303 END_PARAMETRIZED_TEST
304
305
306
307
308
309
310 static const struct test_autocomplete_single_ds
311 {
312 off_t input_position;
313 const char *input_system_code_page;
314 int input_source_codepage_id;
315 const char *input_editor_code_page;
316 int input_display_codepage_id;
317
318 int input_completed_word_start_pos;
319
320 const char *expected_completed_word;
321 } test_autocomplete_single_ds[] =
322 {
323 {
324 146,
325 "UTF-8",
326 1,
327 "KOI8-R",
328 0,
329
330 145,
331 "\xC6\xD9\xD7\xC1"
332 },
333 };
334
335
336
337
338 START_PARAMETRIZED_TEST (test_autocomplete_single, test_autocomplete_single_ds)
339
340 {
341
342 mc_global.source_codepage = data->input_source_codepage_id;
343 mc_global.display_codepage = data->input_display_codepage_id;
344 cp_source = data->input_editor_code_page;
345 cp_display = data->input_system_code_page;
346
347 do_set_codepage (0);
348 edit_set_codeset (test_edit);
349
350
351 edit_cursor_move (test_edit, data->input_position);
352 edit_complete_word_cmd (test_edit);
353
354
355 {
356 off_t i = 0;
357 GString *actual_completed_str;
358
359 actual_completed_str = g_string_new ("");
360
361 while (TRUE)
362 {
363 int chr;
364
365 chr =
366 edit_buffer_get_byte (&test_edit->buffer,
367 data->input_completed_word_start_pos + i++);
368 if (isspace (chr))
369 break;
370 g_string_append_c (actual_completed_str, chr);
371 }
372 mctest_assert_str_eq (actual_completed_str->str, data->expected_completed_word);
373 g_string_free (actual_completed_str, TRUE);
374 }
375 }
376
377 END_PARAMETRIZED_TEST
378
379
380
381 #endif
382
383
384
385 int
386 main (void)
387 {
388 TCase *tc_core;
389
390 tc_core = tcase_create ("Core");
391
392 tcase_add_checked_fixture (tc_core, my_setup, my_teardown);
393
394
395 #ifdef HAVE_CHARSET
396 mctest_add_parameterized_test (tc_core, test_autocomplete, test_autocomplete_ds);
397 mctest_add_parameterized_test (tc_core, test_autocomplete_single, test_autocomplete_single_ds);
398 #endif
399
400
401 return mctest_run_all (tc_core);
402 }
403
404