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/>.
27 #include "lib/replace/replace.h"
28 #include "lib/util/samba_util.h"
29 #include "libcli/smb/smb_constants.h"
31 static void test_ms_fn_match_protocol_no_wildcard(void **state)
35 /* no wildcards in pattern, a simple strcasecmp_m */
36 cmp = ms_fnmatch_protocol("pattern", "string", PROTOCOL_COREPLUS,
37 true); /* case sensitive */
38 assert_int_equal(cmp, -3);
41 static void test_ms_fn_match_protocol_pattern_upgraded(void **state)
45 /* protocol < PROTOCOL_NT1 pattern is "upgraded" */
46 cmp = ms_fnmatch_protocol("??????", "string", PROTOCOL_COREPLUS,
48 assert_int_equal(cmp, 0);
51 static void test_ms_fn_match_protocol_match_zero_or_more(void **state)
55 /* '*' matches zero or more characters. handled via recursive calls */
56 cmp = ms_fnmatch_protocol("********", "string", PROTOCOL_COREPLUS,
58 assert_int_equal(cmp, 0);
61 static void test_ms_fn_match_protocol_mapped_char(void **state)
65 /* '?' is mapped to '>', which matches any char or a '\0' */
66 cmp = ms_fnmatch_protocol("???????", "string", PROTOCOL_COREPLUS,
68 assert_int_equal(cmp, 0);
71 static void test_ms_fn_match_protocol_nt1_any_char(void **state)
75 /* PROTOCOL_NT1 '?' matches any char, '\0' is not included */
76 cmp = ms_fnmatch_protocol("???????", "string", PROTOCOL_NT1,
78 assert_int_equal(cmp, -1);
81 static void test_ms_fn_match_protocol_nt1_case_sensitive(void **state)
85 cmp = ms_fnmatch_protocol("StRinG", "string", PROTOCOL_NT1,
86 true); /* case sensitive */
87 assert_int_equal(cmp, 0);
89 cmp = ms_fnmatch_protocol("StRin?", "string", PROTOCOL_NT1,
90 true); /* case sensitive */
91 assert_int_equal(cmp, -1);
93 cmp = ms_fnmatch_protocol("StRin?", "string", PROTOCOL_NT1,
95 assert_int_equal(cmp, 0);
96 cmp = ms_fnmatch_protocol("strin?", "string", PROTOCOL_NT1,
97 true); /* case sensitive */
98 assert_int_equal(cmp, 0);
102 const struct CMUnitTest tests[] = {
103 cmocka_unit_test(test_ms_fn_match_protocol_no_wildcard),
104 cmocka_unit_test(test_ms_fn_match_protocol_pattern_upgraded),
105 cmocka_unit_test(test_ms_fn_match_protocol_match_zero_or_more),
106 cmocka_unit_test(test_ms_fn_match_protocol_mapped_char),
107 cmocka_unit_test(test_ms_fn_match_protocol_nt1_any_char),
108 cmocka_unit_test(test_ms_fn_match_protocol_nt1_case_sensitive),
111 cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
112 return cmocka_run_group_tests(tests, NULL, NULL);