2 lib/widget - tests for autocomplete feature
5 The Free Software Foundation, Inc.
8 Slava Zanko <slavazanko@gmail.com>, 2013
10 This file is part of the Midnight Commander.
12 The Midnight Commander is free software: you can redistribute it
13 and/or modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation, either version 3 of the License,
15 or (at your option) any later version.
17 The Midnight Commander is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #define TEST_SUITE_NAME "/lib/widget"
32 #include "lib/global.h"
33 #include "lib/strutil.h"
34 #include "lib/widget.h"
36 /* --------------------------------------------------------------------------------------------- */
38 void complete_engine_fill_completions (WInput
* in
);
39 char **try_complete (char *text
, int *lc_start
, int *lc_end
, input_complete_t flags
);
41 /* --------------------------------------------------------------------------------------------- */
44 static char *try_complete__text__captured
;
46 static int try_complete__lc_start__captured
;
48 static int try_complete__lc_end__captured
;
50 static input_complete_t try_complete__flags__captured
;
52 /* @ThenReturnValue */
53 static char **try_complete__return_value
;
57 try_complete (char *text
, int *lc_start
, int *lc_end
, input_complete_t flags
)
59 try_complete__text__captured
= g_strdup (text
);
60 try_complete__lc_start__captured
= *lc_start
;
61 try_complete__lc_end__captured
= *lc_end
;
62 try_complete__flags__captured
= flags
;
64 return try_complete__return_value
;
68 try_complete__init (void)
70 try_complete__text__captured
= NULL
;
71 try_complete__lc_start__captured
= 0;
72 try_complete__lc_end__captured
= 0;
73 try_complete__flags__captured
= 0;
77 try_complete__deinit (void)
79 g_free (try_complete__text__captured
);
82 /* --------------------------------------------------------------------------------------------- */
88 str_init_strings (NULL
);
89 try_complete__init ();
92 /* --------------------------------------------------------------------------------------------- */
98 try_complete__deinit ();
99 str_uninit_strings ();
102 /* --------------------------------------------------------------------------------------------- */
104 /* @DataSource("test_complete_engine_fill_completions_ds") */
106 static const struct test_complete_engine_fill_completions_ds
108 const char *input_buffer
;
109 const int input_point
;
110 const input_complete_t input_completion_flags
;
113 } test_complete_engine_fill_completions_ds
[] =
118 INPUT_COMPLETE_DEFAULT
,
125 INPUT_COMPLETE_DEFAULT
,
132 INPUT_COMPLETE_DEFAULT
,
139 INPUT_COMPLETE_DEFAULT
,
146 INPUT_COMPLETE_DEFAULT
,
153 INPUT_COMPLETE_DEFAULT
,
160 INPUT_COMPLETE_DEFAULT
,
165 "some!@#$%^&*()_\\+~`\"',./?:string",
167 INPUT_COMPLETE_DEFAULT
,
175 /* @Test(dataSource = "test_complete_engine_fill_completions_ds") */
177 START_TEST (test_complete_engine_fill_completions
)
183 const struct test_complete_engine_fill_completions_ds
*data
=
184 &test_complete_engine_fill_completions_ds
[_i
];
186 w_input
= g_new (WInput
, 1);
187 w_input
->buffer
= g_strdup (data
->input_buffer
);
188 w_input
->point
= data
->input_point
;
189 w_input
->completion_flags
= data
->input_completion_flags
;
192 complete_engine_fill_completions (w_input
);
195 g_assert_cmpstr (try_complete__text__captured
, ==, data
->input_buffer
);
196 ck_assert_int_eq (try_complete__lc_start__captured
, data
->expected_start
);
197 ck_assert_int_eq (try_complete__lc_end__captured
, data
->expected_end
);
198 ck_assert_int_eq (try_complete__flags__captured
, data
->input_completion_flags
);
205 /* --------------------------------------------------------------------------------------------- */
212 Suite
*s
= suite_create (TEST_SUITE_NAME
);
213 TCase
*tc_core
= tcase_create ("Core");
216 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
218 /* Add new tests here: *************** */
219 tcase_add_loop_test (tc_core
, test_complete_engine_fill_completions
, 0,
220 sizeof (test_complete_engine_fill_completions_ds
) /
221 sizeof (test_complete_engine_fill_completions_ds
[0]));
222 /* *********************************** */
224 suite_add_tcase (s
, tc_core
);
225 sr
= srunner_create (s
);
226 srunner_set_log (sr
, "complete_engine.log");
227 srunner_run_all (sr
, CK_NORMAL
);
228 number_failed
= srunner_ntests_failed (sr
);
230 return (number_failed
== 0) ? 0 : 1;
233 /* --------------------------------------------------------------------------------------------- */