ready for tagging
[util-vserver.git] / lib_internal / testsuite / matchlist.c
1 // $Id$    --*- c -*--
2
3 // Copyright (C) 2007 Daniel Hokka Zakrisson
4 //  
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
8 //  
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 //  
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 #ifdef HAVE_CONFIG_H
19 #  include <config.h>
20 #endif
21
22 #include <stdio.h>
23 #include <unistd.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <lib_internal/util.h>
27 #include <lib_internal/matchlist.h>
28
29 int wrapper_exit_code = 255;
30
31 int main(int argc, char *argv[])
32 {
33         struct MatchList list;
34         static const char *files[] = {
35                 "/bin",
36                 "+/bin/a",
37         };
38         int test = 0;
39         uint32_t result = 0;
40
41         MatchList_init(&list, "/", sizeof(files) / sizeof(*files));
42         MatchList_appendFiles(&list, 0, files, sizeof(files) / sizeof(*files), true);
43
44 #define DO_TEST(x)      switch (MatchList_compare(&list, x)) { \
45                         case stINCLUDE: result |= 1 << test; break; \
46                         case stEXCLUDE: result |= 2 << test; break; \
47                         case stSKIP:    result |= 4 << test; break; \
48                         } \
49                         test += 3;
50         DO_TEST("/bin");
51         list.skip_depth++;
52         DO_TEST("/bin/a");
53         DO_TEST("/bin/b");
54         list.skip_depth--;
55         DO_TEST("/sbin");
56         DO_TEST("/usr/lib/a");
57
58         MatchList_destroy(&list);
59
60         if (result == 011212)
61                 return 0;
62         else {
63                 char buf[(sizeof(result) * 8) / 3 + 2], *ptr;
64                 ssize_t i;
65                 WRITE_MSG(1, "result = ");
66                 buf[sizeof(buf) - 1] = '\0';
67                 for (i = 0, ptr = buf + sizeof(buf) - 2; i < (sizeof(result) * 8); i += 3, ptr--)
68                         *ptr = '0' + ((result & (7 << i)) >> i);
69                 WRITE_STR(1, buf);
70                 WRITE_MSG(1, "\n");
71                 return 1;
72         }
73 }