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 ("edit_complete_word_cmd_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 static const struct test_autocomplete_ds
210 {
211 off_t input_position;
212 const char *input_system_code_page;
213 int input_source_codepage_id;
214 const char *input_editor_code_page;
215 int input_display_codepage_id;
216 const char *input_completed_word;
217
218 int expected_max_width;
219 int expected_compl_word_count;
220 int input_completed_word_start_pos;
221 const char *expected_completed_word;
222 } test_autocomplete_ds[] = {
223 {
224
225 102,
226 "KOI8-R",
227 0,
228 "UTF-8",
229 1,
230 "эъйцукен",
231
232 16,
233 2,
234 98,
235 "эъйцукен",
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 START_PARAMETRIZED_TEST (test_autocomplete, test_autocomplete_ds)
255 {
256
257 edit_completion_dialog_show__return_value = g_strdup (data->input_completed_word);
258
259 mc_global.source_codepage = data->input_source_codepage_id;
260 mc_global.display_codepage = data->input_display_codepage_id;
261 cp_source = data->input_editor_code_page;
262 cp_display = data->input_system_code_page;
263
264 do_set_codepage (0);
265 edit_set_codeset (test_edit);
266
267
268 edit_cursor_move (test_edit, data->input_position);
269 edit_complete_word_cmd (test_edit);
270
271
272 mctest_assert_ptr_eq (edit_completion_dialog_show__edit, test_edit);
273 ck_assert_int_eq (g_queue_get_length (edit_completion_dialog_show__compl),
274 data->expected_compl_word_count);
275 ck_assert_int_eq (edit_completion_dialog_show__max_width, data->expected_max_width);
276
277 {
278 off_t i = 0;
279 GString *actual_completed_str;
280
281 actual_completed_str = g_string_new ("");
282
283 while (TRUE)
284 {
285 int chr;
286
287 chr = edit_buffer_get_byte (&test_edit->buffer,
288 data->input_completed_word_start_pos + i++);
289 if (isspace (chr))
290 break;
291 g_string_append_c (actual_completed_str, chr);
292 }
293 mctest_assert_str_eq (actual_completed_str->str, data->expected_completed_word);
294 g_string_free (actual_completed_str, TRUE);
295 }
296 }
297 END_PARAMETRIZED_TEST
298
299
300
301
302 static const struct test_autocomplete_single_ds
303 {
304 off_t input_position;
305 const char *input_system_code_page;
306 int input_source_codepage_id;
307 const char *input_editor_code_page;
308 int input_display_codepage_id;
309
310 int input_completed_word_start_pos;
311
312 const char *expected_completed_word;
313 } test_autocomplete_single_ds[] = {
314 {
315
316 146,
317 "UTF-8",
318 1,
319 "KOI8-R",
320 0,
321
322 145,
323 "\xC6\xD9\xD7\xC1",
324 },
325 };
326
327
328 START_PARAMETRIZED_TEST (test_autocomplete_single, test_autocomplete_single_ds)
329 {
330
331 mc_global.source_codepage = data->input_source_codepage_id;
332 mc_global.display_codepage = data->input_display_codepage_id;
333 cp_source = data->input_editor_code_page;
334 cp_display = data->input_system_code_page;
335
336 do_set_codepage (0);
337 edit_set_codeset (test_edit);
338
339
340 edit_cursor_move (test_edit, data->input_position);
341 edit_complete_word_cmd (test_edit);
342
343
344 {
345 off_t i = 0;
346 GString *actual_completed_str;
347
348 actual_completed_str = g_string_new ("");
349
350 while (TRUE)
351 {
352 int chr;
353
354 chr = edit_buffer_get_byte (&test_edit->buffer,
355 data->input_completed_word_start_pos + i++);
356 if (isspace (chr))
357 break;
358 g_string_append_c (actual_completed_str, chr);
359 }
360 mctest_assert_str_eq (actual_completed_str->str, data->expected_completed_word);
361 g_string_free (actual_completed_str, TRUE);
362 }
363 }
364 END_PARAMETRIZED_TEST
365
366 #endif
367
368
369
370 int
371 main (void)
372 {
373 TCase *tc_core;
374
375 tc_core = tcase_create ("Core");
376
377 tcase_add_checked_fixture (tc_core, my_setup, my_teardown);
378
379
380 #ifdef HAVE_CHARSET
381 mctest_add_parameterized_test (tc_core, test_autocomplete, test_autocomplete_ds);
382 mctest_add_parameterized_test (tc_core, test_autocomplete_single, test_autocomplete_single_ds);
383 #endif
384
385
386 return mctest_run_all (tc_core);
387 }
388
389