This source file includes following definitions.
- setup
- teardown
- test_load_text
- test_get_block
- test_insert_column_check
- 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 #define TEST_SUITE_NAME "/src/editor"
27
28 #include "tests/mctest.h"
29
30 #include "lib/charsets.h"
31 #include "src/selcodepage.h"
32
33 #include "src/editor/editwidget.h"
34
35 static WGroup owner;
36 static WEdit *test_edit;
37
38
39 static const char test_text_in[] = "11111\n"
40 "22\n"
41 "aa\n"
42 "bb\n";
43
44
45 static const char test_insert_column_out1[] = "11111\n"
46 "22\n"
47 "a111a\n"
48 "b2 b\n";
49
50
51 static const char test_insert_column_out2[] = "11111\n"
52 "22\n"
53 "aa111\n"
54 "bb2\n";
55
56
57
58
59 void edit_insert_column_of_text (WEdit *edit, GString *data, long width, off_t *start_pos,
60 off_t *end_pos, long *col1, long *col2);
61
62
63
64
65 static void
66 setup (void)
67 {
68 WRect r;
69
70 str_init_strings (NULL);
71
72 mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
73 load_codepages_list ();
74
75 edit_options.filesize_threshold = (char *) "64M";
76
77 rect_init (&r, 0, 0, 24, 80);
78 test_edit = edit_init (NULL, &r, NULL);
79 memset (&owner, 0, sizeof (owner));
80 group_add_widget (&owner, WIDGET (test_edit));
81
82 mc_global.source_codepage = 0;
83 mc_global.display_codepage = 0;
84 cp_source = "ASCII";
85 cp_display = "ASCII";
86
87 do_set_codepage (0);
88 edit_set_codeset (test_edit);
89 }
90
91
92
93
94 static void
95 teardown (void)
96 {
97 edit_clean (test_edit);
98 group_remove_widget (test_edit);
99 g_free (test_edit);
100
101 free_codepages_list ();
102 str_uninit_strings ();
103 }
104
105
106
107 static void
108 test_load_text (void)
109 {
110 for (const char *ti = test_text_in; *ti != '\0'; ti++)
111 edit_buffer_insert (&test_edit->buffer, *ti);
112 }
113
114
115
116 static GString *
117 test_get_block (const off_t start, const off_t finish)
118 {
119 GString *r;
120
121 r = g_string_sized_new (finish - start);
122
123
124 for (off_t i = start; i < finish; i++)
125 {
126 off_t x;
127
128 x = edit_buffer_get_bol (&test_edit->buffer, i);
129 x = edit_move_forward3 (test_edit, x, 0, i);
130
131 const int c = edit_buffer_get_byte (&test_edit->buffer, i);
132
133 if ((x >= test_edit->column1 && x < test_edit->column2)
134 || (x >= test_edit->column2 && x < test_edit->column1) || c == '\n')
135 g_string_append_c (r, (gchar) c);
136 }
137
138 return r;
139 }
140
141
142
143 static void
144 test_insert_column_check (const char *test_out)
145 {
146 GString *actual_text;
147
148 actual_text = g_string_new ("");
149
150 for (off_t i = 0; i < test_edit->buffer.size; i++)
151 {
152 const int chr = edit_buffer_get_byte (&test_edit->buffer, i);
153
154 g_string_append_c (actual_text, chr);
155 }
156
157 mctest_assert_str_eq (actual_text->str, test_out);
158 g_string_free (actual_text, TRUE);
159 }
160
161
162
163 static const struct test_insert_column_ds
164 {
165 off_t offset;
166 const char *expected_text;
167 } test_insert_column_ds[] = {
168 {
169
170 10,
171 test_insert_column_out1,
172 },
173 {
174
175 11,
176 test_insert_column_out2,
177 },
178 };
179
180
181 START_PARAMETRIZED_TEST (test_insert_column, test_insert_column_ds)
182 {
183 off_t start_mark, end_mark;
184 GString *copy_buf;
185 off_t start_pos, end_pos;
186 long col1, col2;
187
188
189 test_load_text ();
190
191 test_edit->column_highlight = 1;
192 test_edit->mark1 = 1;
193 test_edit->mark2 = 8;
194 test_edit->column1 = 1;
195 test_edit->column2 = 4;
196
197
198 edit_cursor_move (test_edit, -test_edit->buffer.curs1 + data->offset);
199
200 const gboolean eval_marks_result = eval_marks (test_edit, &start_mark, &end_mark);
201
202 mctest_assert_true (eval_marks_result);
203
204 copy_buf = test_get_block (start_mark, end_mark);
205 edit_push_markers (test_edit);
206
207 const long col_delta = labs (test_edit->column2 - test_edit->column1);
208
209 edit_insert_column_of_text (test_edit, copy_buf, col_delta, &start_pos, &end_pos, &col1, &col2);
210
211 g_string_free (copy_buf, TRUE);
212
213
214 test_insert_column_check (data->expected_text);
215 }
216 END_PARAMETRIZED_TEST
217
218
219
220 int
221 main (void)
222 {
223 TCase *tc_core;
224
225 tc_core = tcase_create ("Core");
226
227 tcase_add_checked_fixture (tc_core, setup, teardown);
228
229
230 mctest_add_parameterized_test (tc_core, test_insert_column, test_insert_column_ds);
231
232
233 return mctest_run_all (tc_core);
234 }
235
236