xref: /freebsd/contrib/sendmail/libsm/t-match.c (revision 193d9e768ba63fcfb187cfd17f461f7d41345048)
1 /*
2  * Copyright (c) 2000 Proofpoint, Inc. and its suppliers.
3  *	All rights reserved.
4  *
5  * By using this file, you agree to the terms and conditions set
6  * forth in the LICENSE file which can be found at the top level of
7  * the sendmail distribution.
8  */
9 
10 #include <sm/gen.h>
11 SM_IDSTR(id, "@(#)$Id: t-match.c,v 1.10 2013-11-22 20:51:43 ca Exp $")
12 
13 #include <sm/string.h>
14 #include <sm/io.h>
15 #include <sm/test.h>
16 
17 #define try(str, pat, want) \
18 	got = sm_match(str, pat); \
19 	if (!SM_TEST(got == want)) \
20 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, \
21 			"sm_match(\"%s\", \"%s\") returns %s\n", \
22 			str, pat, got ? "true" : "false");
23 
24 int
25 main(argc, argv)
26 	int argc;
27 	char **argv;
28 {
29 	bool got;
30 
31 	sm_test_begin(argc, argv, "test sm_match");
32 
33 	try("foo", "foo", true);
34 	try("foo", "bar", false);
35 	try("foo[bar", "foo[bar", true);
36 	try("foo[bar]", "foo[bar]", false);
37 	try("foob", "foo[bar]", true);
38 	try("a-b", "a[]-]b", true);
39 	try("abcde", "a*e", true);
40 	try("[", "[[]", true);
41 	try("c", "[a-z]", true);
42 	try("C", "[a-z]", false);
43 	try("F:sm.heap", "[!F]*", false);
44 	try("E:sm.err", "[!F]*", true);
45 
46 	return sm_test_end();
47 }
48