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