2 * Unix SMB/CIFS implementation.
4 * Copyright (C) 2018 David Disseldorp <ddiss@samba.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include "lib/replace/replace.h"
29 #include "lib/util/samba_util.h"
30 #include "libcli/smb/smb_constants.h"
32 static void test_ms_fn_match_protocol_no_wildcard(void **state
)
36 /* no wildcards in pattern, a simple strcasecmp_m */
37 cmp
= ms_fnmatch_protocol("pattern", "string", PROTOCOL_COREPLUS
,
38 true); /* case sensitive */
42 static void test_ms_fn_match_protocol_pattern_upgraded(void **state
)
46 /* protocol < PROTOCOL_NT1 pattern is "upgraded" */
47 cmp
= ms_fnmatch_protocol("??????", "string", PROTOCOL_COREPLUS
,
49 assert_int_equal(cmp
, 0);
52 static void test_ms_fn_match_protocol_match_zero_or_more(void **state
)
56 /* '*' matches zero or more characters. handled via recursive calls */
57 cmp
= ms_fnmatch_protocol("********", "string", PROTOCOL_COREPLUS
,
59 assert_int_equal(cmp
, 0);
62 static void test_ms_fn_match_protocol_mapped_char(void **state
)
66 /* '?' is mapped to '>', which matches any char or a '\0' */
67 cmp
= ms_fnmatch_protocol("???????", "string", PROTOCOL_COREPLUS
,
69 assert_int_equal(cmp
, 0);
72 static void test_ms_fn_match_protocol_nt1_any_char(void **state
)
76 /* PROTOCOL_NT1 '?' matches any char, '\0' is not included */
77 cmp
= ms_fnmatch_protocol("???????", "string", PROTOCOL_NT1
,
79 assert_int_equal(cmp
, -1);
82 static void test_ms_fn_match_protocol_nt1_case_sensitive(void **state
)
86 cmp
= ms_fnmatch_protocol("StRinG", "string", PROTOCOL_NT1
,
87 true); /* case sensitive */
88 assert_int_equal(cmp
, 0);
90 cmp
= ms_fnmatch_protocol("StRin?", "string", PROTOCOL_NT1
,
91 true); /* case sensitive */
92 assert_int_equal(cmp
, -1);
94 cmp
= ms_fnmatch_protocol("StRin?", "string", PROTOCOL_NT1
,
96 assert_int_equal(cmp
, 0);
97 cmp
= ms_fnmatch_protocol("strin?", "string", PROTOCOL_NT1
,
98 true); /* case sensitive */
99 assert_int_equal(cmp
, 0);
103 const struct CMUnitTest tests
[] = {
104 cmocka_unit_test(test_ms_fn_match_protocol_no_wildcard
),
105 cmocka_unit_test(test_ms_fn_match_protocol_pattern_upgraded
),
106 cmocka_unit_test(test_ms_fn_match_protocol_match_zero_or_more
),
107 cmocka_unit_test(test_ms_fn_match_protocol_mapped_char
),
108 cmocka_unit_test(test_ms_fn_match_protocol_nt1_any_char
),
109 cmocka_unit_test(test_ms_fn_match_protocol_nt1_case_sensitive
),
112 cmocka_set_message_output(CM_OUTPUT_SUBUNIT
);
113 return cmocka_run_group_tests(tests
, NULL
, NULL
);