tools/llvm: Do not build with symbols
[minix3.git] / tests / lib / libc / gen / t_fnmatch.c
blobf90d8cfdd0d1665266cacc9854da95f7c4cd91f7
1 /* $NetBSD: t_fnmatch.c,v 1.3 2012/04/08 09:58:59 jruoho Exp $ */
3 /*-
4 * Copyright (c) 2012 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jukka Ruohonen.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __RCSID("$NetBSD: t_fnmatch.c,v 1.3 2012/04/08 09:58:59 jruoho Exp $");
34 #include <atf-c.h>
35 #include <fnmatch.h>
36 #include <stdio.h>
38 ATF_TC(fnmatch_backslashes);
39 ATF_TC_HEAD(fnmatch_backslashes, tc)
41 atf_tc_set_md_var(tc, "descr",
42 "Test translation of '\\' with fnmatch(3) (PR lib/41558)");
45 ATF_TC_BODY(fnmatch_backslashes, tc)
47 const int rv = fnmatch(/* pattern */ "\\", "\\", 0);
49 if (rv != FNM_NOMATCH)
50 atf_tc_fail("fnmatch(3) did not translate '\\'");
53 ATF_TC(fnmatch_casefold);
54 ATF_TC_HEAD(fnmatch_casefold, tc)
56 atf_tc_set_md_var(tc, "descr", "Test FNM_CASEFOLD");
59 ATF_TC_BODY(fnmatch_casefold, tc)
61 ATF_CHECK(fnmatch("xxx", "XXX", 0) != 0);
62 ATF_CHECK(fnmatch("XXX", "xxx", 0) != 0);
63 ATF_CHECK(fnmatch("xxx", "XxX", 0) != 0);
64 ATF_CHECK(fnmatch("XxX", "xxx", 0) != 0);
65 ATF_CHECK(fnmatch("x*x", "XXX", 0) != 0);
66 ATF_CHECK(fnmatch("**x", "XXX", 0) != 0);
67 ATF_CHECK(fnmatch("*?x", "XXX", 0) != 0);
69 ATF_CHECK(fnmatch("xxx", "XXX", FNM_CASEFOLD) == 0);
70 ATF_CHECK(fnmatch("XXX", "xxx", FNM_CASEFOLD) == 0);
71 ATF_CHECK(fnmatch("xxx", "XxX", FNM_CASEFOLD) == 0);
72 ATF_CHECK(fnmatch("XxX", "xxx", FNM_CASEFOLD) == 0);
73 ATF_CHECK(fnmatch("x*x", "XXX", FNM_CASEFOLD) == 0);
74 ATF_CHECK(fnmatch("**x", "XXX", FNM_CASEFOLD) == 0);
75 ATF_CHECK(fnmatch("*?x", "XXX", FNM_CASEFOLD) == 0);
78 ATF_TC(fnmatch_leadingdir);
79 ATF_TC_HEAD(fnmatch_leadingdir, tc)
81 atf_tc_set_md_var(tc, "descr", "Test FNM_LEADING_DIR");
84 ATF_TC_BODY(fnmatch_leadingdir, tc)
86 ATF_CHECK(fnmatch("", "/*", 0) != 0);
87 ATF_CHECK(fnmatch(" ", " /*", 0) != 0);
88 ATF_CHECK(fnmatch("x", "x/*", 0) != 0);
89 ATF_CHECK(fnmatch("///", "////*", 0) != 0);
91 ATF_CHECK(fnmatch("", "/*", FNM_LEADING_DIR) == 0);
92 ATF_CHECK(fnmatch(" ", " /*", FNM_LEADING_DIR) == 0);
93 ATF_CHECK(fnmatch("x", "x/*", FNM_LEADING_DIR) == 0);
94 ATF_CHECK(fnmatch("///", "////*", FNM_LEADING_DIR) == 0);
97 ATF_TC(fnmatch_noescape);
98 ATF_TC_HEAD(fnmatch_noescape, tc)
100 atf_tc_set_md_var(tc, "descr", "Test FNM_NOESCAPE");
103 ATF_TC_BODY(fnmatch_noescape, tc)
105 ATF_CHECK(fnmatch(" \\x", " \\x", 0) != 0);
106 ATF_CHECK(fnmatch("xx\\x", "xx\\x", 0) != 0);
107 ATF_CHECK(fnmatch("\\xxx", "\\xxx", 0) != 0);
109 ATF_CHECK(fnmatch(" \\x", " \\x", FNM_NOESCAPE) == 0);
110 ATF_CHECK(fnmatch("xx\\x", "xx\\x", FNM_NOESCAPE) == 0);
111 ATF_CHECK(fnmatch("\\xxx", "\\xxx", FNM_NOESCAPE) == 0);
114 ATF_TC(fnmatch_pathname);
115 ATF_TC_HEAD(fnmatch_pathname, tc)
117 atf_tc_set_md_var(tc, "descr", "Test FNM_PATHNAME");
120 ATF_TC_BODY(fnmatch_pathname, tc)
122 ATF_CHECK(fnmatch("???x", "xxx/x", FNM_PATHNAME) != 0);
123 ATF_CHECK(fnmatch("***x", "xxx/x", FNM_PATHNAME) != 0);
125 ATF_CHECK(fnmatch("???x", "xxxx", FNM_PATHNAME) == 0);
126 ATF_CHECK(fnmatch("*/xxx", "/xxx", FNM_PATHNAME) == 0);
127 ATF_CHECK(fnmatch("x/*.y", "x/z.y", FNM_PATHNAME) == 0);
130 ATF_TC(fnmatch_period);
131 ATF_TC_HEAD(fnmatch_period, tc)
133 atf_tc_set_md_var(tc, "descr", "Test FNM_PERIOD");
136 ATF_TC_BODY(fnmatch_period, tc)
138 ATF_CHECK(fnmatch("*x*", "X", FNM_PERIOD) != 0);
139 ATF_CHECK(fnmatch("*x*", "X", FNM_PERIOD | FNM_CASEFOLD) == 0);
141 ATF_CHECK(fnmatch("x?y", "x.y", FNM_PATHNAME | FNM_PERIOD) == 0);
142 ATF_CHECK(fnmatch("x*y", "x.y", FNM_PATHNAME | FNM_PERIOD) == 0);
143 ATF_CHECK(fnmatch("*.c", "x.c", FNM_PATHNAME | FNM_PERIOD) == 0);
144 ATF_CHECK(fnmatch("*/?", "x/y", FNM_PATHNAME | FNM_PERIOD) == 0);
145 ATF_CHECK(fnmatch("*/*", "x/y", FNM_PATHNAME | FNM_PERIOD) == 0);
146 ATF_CHECK(fnmatch(".*/?", ".x/y", FNM_PATHNAME | FNM_PERIOD) == 0);
147 ATF_CHECK(fnmatch("*/.?", "x/.y", FNM_PATHNAME | FNM_PERIOD) == 0);
148 ATF_CHECK(fnmatch("x[.]y", "x.y", FNM_PATHNAME | FNM_PERIOD) == 0);
150 ATF_CHECK(fnmatch("?x/y", ".x/y", FNM_PATHNAME | FNM_PERIOD) != 0);
151 ATF_CHECK(fnmatch("*x/y", ".x/y", FNM_PATHNAME | FNM_PERIOD) != 0);
152 ATF_CHECK(fnmatch("x/?y", "x/.y", FNM_PATHNAME | FNM_PERIOD) != 0);
153 ATF_CHECK(fnmatch("x/*y", "x/.y", FNM_PATHNAME | FNM_PERIOD) != 0);
156 ATF_TP_ADD_TCS(tp)
159 ATF_TP_ADD_TC(tp, fnmatch_backslashes);
160 ATF_TP_ADD_TC(tp, fnmatch_casefold);
161 ATF_TP_ADD_TC(tp, fnmatch_leadingdir);
162 ATF_TP_ADD_TC(tp, fnmatch_noescape);
163 ATF_TP_ADD_TC(tp, fnmatch_pathname);
164 ATF_TP_ADD_TC(tp, fnmatch_period);
166 return atf_no_error();