2 * Copyright (c) 2012 Michihiro NAKAJIMA
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 __FBSDID("$FreeBSD$");
32 struct archive_entry *ae;
35 if (!assert((m = archive_match_new()) != NULL))
37 if (!assert((ae = archive_entry_new()) != NULL)) {
38 archive_match_free(m);
42 assertEqualIntA(m, 0, archive_match_include_uid(m, 1000));
43 assertEqualIntA(m, 0, archive_match_include_uid(m, 1002));
45 archive_entry_set_uid(ae, 0);
46 failure("uid 0 should be excluded");
47 assertEqualInt(1, archive_match_owner_excluded(m, ae));
48 assertEqualInt(1, archive_match_excluded(m, ae));
49 archive_entry_set_uid(ae, 1000);
50 failure("uid 1000 should not be excluded");
51 assertEqualInt(0, archive_match_owner_excluded(m, ae));
52 assertEqualInt(0, archive_match_excluded(m, ae));
53 archive_entry_set_uid(ae, 1001);
54 failure("uid 1001 should be excluded");
55 assertEqualInt(1, archive_match_owner_excluded(m, ae));
56 assertEqualInt(1, archive_match_excluded(m, ae));
57 archive_entry_set_uid(ae, 1002);
58 failure("uid 1002 should not be excluded");
59 assertEqualInt(0, archive_match_owner_excluded(m, ae));
60 assertEqualInt(0, archive_match_excluded(m, ae));
61 archive_entry_set_uid(ae, 1003);
62 failure("uid 1003 should be excluded");
63 assertEqualInt(1, archive_match_owner_excluded(m, ae));
64 assertEqualInt(1, archive_match_excluded(m, ae));
67 archive_entry_free(ae);
68 archive_match_free(m);
74 struct archive_entry *ae;
77 if (!assert((m = archive_match_new()) != NULL))
79 if (!assert((ae = archive_entry_new()) != NULL)) {
80 archive_match_free(m);
84 assertEqualIntA(m, 0, archive_match_include_gid(m, 1000));
85 assertEqualIntA(m, 0, archive_match_include_gid(m, 1002));
87 archive_entry_set_gid(ae, 0);
88 failure("uid 0 should be excluded");
89 assertEqualInt(1, archive_match_owner_excluded(m, ae));
90 assertEqualInt(1, archive_match_excluded(m, ae));
91 archive_entry_set_gid(ae, 1000);
92 failure("uid 1000 should not be excluded");
93 assertEqualInt(0, archive_match_owner_excluded(m, ae));
94 assertEqualInt(0, archive_match_excluded(m, ae));
95 archive_entry_set_gid(ae, 1001);
96 failure("uid 1001 should be excluded");
97 assertEqualInt(1, archive_match_owner_excluded(m, ae));
98 assertEqualInt(1, archive_match_excluded(m, ae));
99 archive_entry_set_gid(ae, 1002);
100 failure("uid 1002 should not be excluded");
101 assertEqualInt(0, archive_match_owner_excluded(m, ae));
102 assertEqualInt(0, archive_match_excluded(m, ae));
103 archive_entry_set_gid(ae, 1003);
104 failure("uid 1003 should be excluded");
105 assertEqualInt(1, archive_match_owner_excluded(m, ae));
106 assertEqualInt(1, archive_match_excluded(m, ae));
109 archive_entry_free(ae);
110 archive_match_free(m);
116 struct archive_entry *ae;
119 if (!assert((m = archive_match_new()) != NULL))
121 if (!assert((ae = archive_entry_new()) != NULL)) {
122 archive_match_free(m);
126 assertEqualIntA(m, 0, archive_match_include_uname(m, "foo"));
127 assertEqualIntA(m, 0, archive_match_include_uname(m, "bar"));
129 archive_entry_copy_uname(ae, "unknown");
130 failure("User 'unknown' should be excluded");
131 assertEqualInt(1, archive_match_owner_excluded(m, ae));
132 assertEqualInt(1, archive_match_excluded(m, ae));
133 archive_entry_copy_uname(ae, "foo");
134 failure("User 'foo' should not be excluded");
135 assertEqualInt(0, archive_match_owner_excluded(m, ae));
136 assertEqualInt(0, archive_match_excluded(m, ae));
137 archive_entry_copy_uname(ae, "foo1");
138 failure("User 'foo1' should be excluded");
139 assertEqualInt(1, archive_match_owner_excluded(m, ae));
140 assertEqualInt(1, archive_match_excluded(m, ae));
141 archive_entry_copy_uname(ae, "bar");
142 failure("User 'bar' should not be excluded");
143 assertEqualInt(0, archive_match_owner_excluded(m, ae));
144 assertEqualInt(0, archive_match_excluded(m, ae));
145 archive_entry_copy_uname(ae, "bar1");
146 failure("User 'bar1' should be excluded");
147 assertEqualInt(1, archive_match_owner_excluded(m, ae));
148 assertEqualInt(1, archive_match_excluded(m, ae));
151 archive_entry_free(ae);
152 archive_match_free(m);
158 struct archive_entry *ae;
161 if (!assert((m = archive_match_new()) != NULL))
163 if (!assert((ae = archive_entry_new()) != NULL)) {
164 archive_match_free(m);
168 assertEqualIntA(m, 0, archive_match_include_uname_w(m, L"foo"));
169 assertEqualIntA(m, 0, archive_match_include_uname_w(m, L"bar"));
171 archive_entry_copy_uname_w(ae, L"unknown");
172 failure("User 'unknown' should be excluded");
173 assertEqualInt(1, archive_match_owner_excluded(m, ae));
174 assertEqualInt(1, archive_match_excluded(m, ae));
175 archive_entry_copy_uname_w(ae, L"foo");
176 failure("User 'foo' should not be excluded");
177 assertEqualInt(0, archive_match_owner_excluded(m, ae));
178 assertEqualInt(0, archive_match_excluded(m, ae));
179 archive_entry_copy_uname_w(ae, L"foo1");
180 failure("User 'foo1' should be excluded");
181 assertEqualInt(1, archive_match_owner_excluded(m, ae));
182 assertEqualInt(1, archive_match_excluded(m, ae));
183 archive_entry_copy_uname_w(ae, L"bar");
184 failure("User 'bar' should not be excluded");
185 assertEqualInt(0, archive_match_owner_excluded(m, ae));
186 assertEqualInt(0, archive_match_excluded(m, ae));
187 archive_entry_copy_uname_w(ae, L"bar1");
188 failure("User 'bar1' should be excluded");
189 assertEqualInt(1, archive_match_owner_excluded(m, ae));
190 assertEqualInt(1, archive_match_excluded(m, ae));
193 archive_entry_free(ae);
194 archive_match_free(m);
200 struct archive_entry *ae;
203 if (!assert((m = archive_match_new()) != NULL))
205 if (!assert((ae = archive_entry_new()) != NULL)) {
206 archive_match_free(m);
210 assertEqualIntA(m, 0, archive_match_include_gname(m, "foo"));
211 assertEqualIntA(m, 0, archive_match_include_gname(m, "bar"));
213 archive_entry_copy_gname(ae, "unknown");
214 failure("Group 'unknown' should be excluded");
215 assertEqualInt(1, archive_match_owner_excluded(m, ae));
216 assertEqualInt(1, archive_match_excluded(m, ae));
217 archive_entry_copy_gname(ae, "foo");
218 failure("Group 'foo' should not be excluded");
219 assertEqualInt(0, archive_match_owner_excluded(m, ae));
220 assertEqualInt(0, archive_match_excluded(m, ae));
221 archive_entry_copy_gname(ae, "foo1");
222 failure("Group 'foo1' should be excluded");
223 assertEqualInt(1, archive_match_owner_excluded(m, ae));
224 assertEqualInt(1, archive_match_excluded(m, ae));
225 archive_entry_copy_gname(ae, "bar");
226 failure("Group 'bar' should not be excluded");
227 assertEqualInt(0, archive_match_owner_excluded(m, ae));
228 assertEqualInt(0, archive_match_excluded(m, ae));
229 archive_entry_copy_gname(ae, "bar1");
230 failure("Group 'bar1' should be excluded");
231 assertEqualInt(1, archive_match_owner_excluded(m, ae));
232 assertEqualInt(1, archive_match_excluded(m, ae));
235 archive_entry_free(ae);
236 archive_match_free(m);
242 struct archive_entry *ae;
245 if (!assert((m = archive_match_new()) != NULL))
247 if (!assert((ae = archive_entry_new()) != NULL)) {
248 archive_match_free(m);
252 assertEqualIntA(m, 0, archive_match_include_gname_w(m, L"foo"));
253 assertEqualIntA(m, 0, archive_match_include_gname_w(m, L"bar"));
255 archive_entry_copy_gname_w(ae, L"unknown");
256 failure("Group 'unknown' should be excluded");
257 assertEqualInt(1, archive_match_owner_excluded(m, ae));
258 assertEqualInt(1, archive_match_excluded(m, ae));
259 archive_entry_copy_gname_w(ae, L"foo");
260 failure("Group 'foo' should not be excluded");
261 assertEqualInt(0, archive_match_owner_excluded(m, ae));
262 assertEqualInt(0, archive_match_excluded(m, ae));
263 archive_entry_copy_gname_w(ae, L"foo1");
264 failure("Group 'foo1' should be excluded");
265 assertEqualInt(1, archive_match_owner_excluded(m, ae));
266 assertEqualInt(1, archive_match_excluded(m, ae));
267 archive_entry_copy_gname_w(ae, L"bar");
268 failure("Group 'bar' should not be excluded");
269 assertEqualInt(0, archive_match_owner_excluded(m, ae));
270 assertEqualInt(0, archive_match_excluded(m, ae));
271 archive_entry_copy_gname_w(ae, L"bar1");
272 failure("Group 'bar1' should be excluded");
273 assertEqualInt(1, archive_match_owner_excluded(m, ae));
274 assertEqualInt(1, archive_match_excluded(m, ae));
277 archive_entry_free(ae);
278 archive_match_free(m);
281 DEFINE_TEST(test_archive_match_owner)