s3/lib/ctdbd_conn: assert hdr following read/recv
[Samba.git] / lib / util / tests / test_ms_fnmatch.c
blobd11c7bed4becf8a9fb5e0b0a1922f1a988b30332
1 /*
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/>.
20 #include <stdarg.h>
21 #include <stddef.h>
22 #include <stdint.h>
23 #include <setjmp.h>
24 #include <cmocka.h>
26 #include <errno.h>
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)
34 int cmp;
36 /* no wildcards in pattern, a simple strcasecmp_m */
37 cmp = ms_fnmatch_protocol("pattern", "string", PROTOCOL_COREPLUS,
38 true); /* case sensitive */
39 assert_int_equal(cmp, -3);
42 static void test_ms_fn_match_protocol_pattern_upgraded(void **state)
44 int cmp;
46 /* protocol < PROTOCOL_NT1 pattern is "upgraded" */
47 cmp = ms_fnmatch_protocol("??????", "string", PROTOCOL_COREPLUS,
48 false);
49 assert_int_equal(cmp, 0);
52 static void test_ms_fn_match_protocol_match_zero_or_more(void **state)
54 int cmp;
56 /* '*' matches zero or more characters. handled via recursive calls */
57 cmp = ms_fnmatch_protocol("********", "string", PROTOCOL_COREPLUS,
58 true);
59 assert_int_equal(cmp, 0);
62 static void test_ms_fn_match_protocol_mapped_char(void **state)
64 int cmp;
66 /* '?' is mapped to '>', which matches any char or a '\0' */
67 cmp = ms_fnmatch_protocol("???????", "string", PROTOCOL_COREPLUS,
68 false);
69 assert_int_equal(cmp, 0);
72 static void test_ms_fn_match_protocol_nt1_any_char(void **state)
74 int cmp;
76 /* PROTOCOL_NT1 '?' matches any char, '\0' is not included */
77 cmp = ms_fnmatch_protocol("???????", "string", PROTOCOL_NT1,
78 false);
79 assert_int_equal(cmp, -1);
82 static void test_ms_fn_match_protocol_nt1_case_sensitive(void **state)
84 int cmp;
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,
95 false);
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);
102 int main(void) {
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);