1 /*
2 src/filemanager - tests for is_wildcarded() function
3
4 Copyright (C) 2011-2025
5 Free Software Foundation, Inc.
6
7 Written by:
8 Slava Zanko <slavazanko@gmail.com>, 2015
9
10 This file is part of the Midnight Commander.
11
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.
16
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.
21
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
26 #define TEST_SUITE_NAME "/src/filemanager"
27
28 #include "tests/mctest.h"
29
30 #include "src/vfs/local/local.c"
31
32 #include "src/filemanager/filegui.c"
33
34 /* --------------------------------------------------------------------------------------------- */
35
36 /* @Before */
37 static void
38 setup (void)
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
39 {
40 str_init_strings (NULL);
41
42 vfs_init ();
43 vfs_init_localfs ();
44 vfs_setup_work_dir ();
45 }
46
47 /* --------------------------------------------------------------------------------------------- */
48
49 /* @After */
50 static void
51 teardown (void)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
52 {
53 vfs_shut ();
54 str_uninit_strings ();
55 }
56
57 /* --------------------------------------------------------------------------------------------- */
58
59 /* @DataSource("test_is_wildcarded_ds") */
60 static const struct test_is_wildcarded_ds
61 {
62 const char *input_value;
63 gboolean expected_result;
64 } test_is_wildcarded_ds[] = {
65 { "blabla", FALSE }, // 0
66 { "bla?bla", TRUE }, // 1
67 { "bla*bla", TRUE }, // 2
68 { "bla\\*bla", FALSE }, // 3
69 { "bla\\\\*bla", TRUE }, // 4
70 { "bla\\1bla", TRUE }, // 5
71 { "bla\\\\1bla", FALSE }, // 6
72 { "bla\\\t\\\\1bla", FALSE }, // 7
73 { "bla\\\t\\\\\\1bla", TRUE }, // 8
74 { "bla\\9bla", TRUE }, // 9
75 { "blabla\\", FALSE }, // 10
76 { "blab\\?la", FALSE }, // 11
77 { "blab\\\\?la", TRUE }, // 12
78 };
79
80 /* @Test(dataSource = "test_is_wildcarded_ds") */
81 START_PARAMETRIZED_TEST (test_is_wildcarded, test_is_wildcarded_ds)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
82 {
83 // given
84 gboolean actual_result;
85
86 // when
87 actual_result = is_wildcarded (data->input_value);
88 // then
89 ck_assert_int_eq (actual_result, data->expected_result);
90 }
91 END_PARAMETRIZED_TEST
92
93 /* --------------------------------------------------------------------------------------------- */
94
95 int
96 main (void)
/* ![[previous]](../icons/left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
97 {
98 TCase *tc_core;
99
100 tc_core = tcase_create ("Core");
101
102 tcase_add_checked_fixture (tc_core, setup, teardown);
103
104 // Add new tests here: ***************
105 mctest_add_parameterized_test (tc_core, test_is_wildcarded, test_is_wildcarded_ds);
106 // ***********************************
107
108 return mctest_run_all (tc_core);
109 }
110
111 /* --------------------------------------------------------------------------------------------- */