X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib_internal%2Ftestsuite%2Fmatchlist.c;fp=lib_internal%2Ftestsuite%2Fmatchlist.c;h=d4693451cfcf4d9d43d267403e70c0f2ed6c5bc8;hb=a741f6faf2baae1e823d334012f6a09e6a1bda51;hp=0000000000000000000000000000000000000000;hpb=426a0d3a38995dc25a839aaa56d8642e6bdcbba5;p=util-vserver.git diff --git a/lib_internal/testsuite/matchlist.c b/lib_internal/testsuite/matchlist.c new file mode 100644 index 0000000..d469345 --- /dev/null +++ b/lib_internal/testsuite/matchlist.c @@ -0,0 +1,73 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2007 Daniel Hokka Zakrisson +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include +#include +#include + +int wrapper_exit_code = 255; + +int main(int argc, char *argv[]) +{ + struct MatchList list; + static const char *files[] = { + "/bin", + "+/bin/a", + }; + int test = 0; + uint32_t result = 0; + + MatchList_init(&list, "/", sizeof(files) / sizeof(*files)); + MatchList_appendFiles(&list, 0, files, sizeof(files) / sizeof(*files), true); + +#define DO_TEST(x) switch (MatchList_compare(&list, x)) { \ + case stINCLUDE: result |= 1 << test; break; \ + case stEXCLUDE: result |= 2 << test; break; \ + case stSKIP: result |= 4 << test; break; \ + } \ + test += 3; + DO_TEST("/bin"); + list.skip_depth++; + DO_TEST("/bin/a"); + DO_TEST("/bin/b"); + list.skip_depth--; + DO_TEST("/sbin"); + DO_TEST("/usr/lib/a"); + + MatchList_destroy(&list); + + if (result == 011212) + return 0; + else { + char buf[(sizeof(result) * 8) / 3 + 2], *ptr; + ssize_t i; + WRITE_MSG(1, "result = "); + buf[sizeof(buf) - 1] = '\0'; + for (i = 0, ptr = buf + sizeof(buf) - 2; i < (sizeof(result) * 8); i += 3, ptr--) + *ptr = '0' + ((result & (7 << i)) >> i); + WRITE_STR(1, buf); + WRITE_MSG(1, "\n"); + return 1; + } +}