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