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
156 str_init_strings (NULL);
157
158 vfs_init ();
159 vfs_init_localfs ();
160 vfs_setup_work_dir ();
161
162 #ifdef HAVE_CHARSET
163 mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
164 load_codepages_list ();
165 #endif
166
167 mc_global.main_config = mc_config_init ("edit_complete_word_cmd.ini", FALSE);
168 mc_config_set_bool (mc_global.main_config, CONFIG_APP_SECTION,
169 "editor_wordcompletion_collect_all_files", TRUE);
170
171 edit_options.filesize_threshold = (char *) "64M";
172
173 rect_init (&r, 0, 0, 24, 80);
174 test_edit = edit_init (NULL, &r, vfs_path_from_str ("test-data.txt"), 1);
175 memset (&owner, 0, sizeof (owner));
176 group_add_widget (&owner, WIDGET (test_edit));
177 edit_completion_dialog_show__init ();
178 }
179
180
181
182
183 static void
184 my_teardown (void)
185 {
186 edit_completion_dialog_show__deinit ();
187 edit_clean (test_edit);
188 group_remove_widget (test_edit);
189 g_free (test_edit);
190
191 mc_config_deinit (mc_global.main_config);
192
193 #ifdef HAVE_CHARSET
194 free_codepages_list ();
195 #endif
196
197 vfs_shut ();
198
199 str_uninit_strings ();
200 }
201
202
203
204 #ifdef HAVE_CHARSET
205
206
207 static const struct test_autocomplete_ds
208 {
209 off_t input_position;
210 const char *input_system_code_page;
211 int input_source_codepage_id;
212 const char *input_editor_code_page;
213 int input_display_codepage_id;
214 const char *input_completed_word;
215
216 int expected_max_width;
217 int expected_compl_word_count;
218 int input_completed_word_start_pos;
219 const char *expected_completed_word;
220 } test_autocomplete_ds[] =
221 {
222 {
223 102,
224 "KOI8-R",
225 0,
226 "UTF-8",
227 1,
228 "эъйцукен",
229
230 16,
231 2,
232 98,
233 "эъйцукен"
234 },
235 {
236 138,
237 "UTF-8",
238 1,
239 "KOI8-R",
240 0,
241 "",
242
243 8,
244 2,
245 136,
246 ""
247 },
248 };
249
250
251
252
253 START_PARAMETRIZED_TEST (test_autocomplete, test_autocomplete_ds)
254
255 {
256
257 edit_completion_dialog_show__return_value = g_strdup (data->input_completed_word);
258
259
260 mc_global.source_codepage = data->input_source_codepage_id;
261 mc_global.display_codepage = data->input_display_codepage_id;
262 cp_source = data->input_editor_code_page;
263 cp_display = data->input_system_code_page;
264
265 do_set_codepage (0);
266 edit_set_codeset (test_edit);
267
268
269 edit_cursor_move (test_edit, data->input_position);
270 edit_complete_word_cmd (test_edit);
271
272
273 mctest_assert_ptr_eq (edit_completion_dialog_show__edit, test_edit);
274 ck_assert_int_eq (g_queue_get_length (edit_completion_dialog_show__compl),
275 data->expected_compl_word_count);
276 ck_assert_int_eq (edit_completion_dialog_show__max_width, data->expected_max_width);
277
278 {
279 off_t i = 0;
280 GString *actual_completed_str;
281
282 actual_completed_str = g_string_new ("");
283
284 while (TRUE)
285 {
286 int chr;
287
288 chr =
289 edit_buffer_get_byte (&test_edit->buffer,
290 data->input_completed_word_start_pos + i++);
291 if (isspace (chr))
292 break;
293 g_string_append_c (actual_completed_str, chr);
294 }
295 mctest_assert_str_eq (actual_completed_str->str, data->expected_completed_word);
296 g_string_free (actual_completed_str, TRUE);
297 }
298 }
299
300 END_PARAMETRIZED_TEST
301
302
303
304
305
306
307 static const struct test_autocomplete_single_ds
308 {
309 off_t input_position;
310 const char *input_system_code_page;
311 int input_source_codepage_id;
312 const char *input_editor_code_page;
313 int input_display_codepage_id;
314
315 int input_completed_word_start_pos;
316
317 const char *expected_completed_word;
318 } test_autocomplete_single_ds[] =
319 {
320 {
321 146,
322 "UTF-8",
323 1,
324 "KOI8-R",
325 0,
326
327 145,
328 ""
329 },
330 };
331
332
333
334
335 START_PARAMETRIZED_TEST (test_autocomplete_single, test_autocomplete_single_ds)
336
337 {
338
339 mc_global.source_codepage = data->input_source_codepage_id;
340 mc_global.display_codepage = data->input_display_codepage_id;
341 cp_source = data->input_editor_code_page;
342 cp_display = data->input_system_code_page;
343
344 do_set_codepage (0);
345 edit_set_codeset (test_edit);
346
347
348 edit_cursor_move (test_edit, data->input_position);
349 edit_complete_word_cmd (test_edit);
350
351
352 {
353 off_t i = 0;
354 GString *actual_completed_str;
355
356 actual_completed_str = g_string_new ("");
357
358 while (TRUE)
359 {
360 int chr;
361
362 chr =
363 edit_buffer_get_byte (&test_edit->buffer,
364 data->input_completed_word_start_pos + i++);
365 if (isspace (chr))
366 break;
367 g_string_append_c (actual_completed_str, chr);
368 }
369 mctest_assert_str_eq (actual_completed_str->str, data->expected_completed_word);
370 g_string_free (actual_completed_str, TRUE);
371 }
372 }
373
374 END_PARAMETRIZED_TEST
375
376
377
378 #endif
379
380
381
382 int
383 main (void)
384 {
385 TCase *tc_core;
386
387 tc_core = tcase_create ("Core");
388
389 tcase_add_checked_fixture (tc_core, my_setup, my_teardown);
390
391
392 #ifdef HAVE_CHARSET
393 mctest_add_parameterized_test (tc_core, test_autocomplete, test_autocomplete_ds);
394 mctest_add_parameterized_test (tc_core, test_autocomplete_single, test_autocomplete_single_ds);
395 #endif
396
397
398 return mctest_run_all (tc_core);
399 }
400
401