added 'fmt'
[util-vserver.git] / util-vserver / lib / testsuite / flags.c
1 // $Id$    --*- c -*--
2
3 // Copyright (C) 2004 Enrico Scholz <ensc@delenn.intern.sigma-chemnitz.de>
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
19 #ifdef HAVE_CONFIG_H
20 #  include <config.h>
21 #endif
22
23 #include "vserver.h"
24 #include <assert.h>
25 #include <string.h>
26
27 #define TEST_T2F(X,Y,Z) assert(vc_text2flag(X,Y)==Z)
28 #define TEST_F2T(Y,X) {                         \
29     char const *x=vc_hiflag2text(X);            \
30     assert((x==0 && Y==0) || (x!=0 && Y!=0));   \
31     if (x!=0) assert(strcmp(x, Y)==0);          \
32   }
33
34 #define TEST_LIST(STR,LEN,EXP,ERR_POS,ERR_LEN) {                \
35     char const  *err_ptr;                                       \
36     size_t      err_len;                                        \
37     char        buf[] = STR;                                    \
38     uint32_t    res;                                            \
39     res = vc_textlist2flag(buf, LEN, &err_ptr, &err_len);       \
40     assert(res==(EXP));                                         \
41     assert(err_len==ERR_LEN);                                   \
42     if (ERR_POS==-1) assert(err_ptr==0);                        \
43     else             assert(err_ptr==buf+(ERR_POS));            \
44   }
45
46
47 int main()
48 {
49   TEST_T2F("lock",     0, S_CTX_INFO_LOCK);
50   TEST_T2F("lockXXXX", 4, S_CTX_INFO_LOCK);
51   TEST_T2F("locXXXXX", 3, 0);
52   TEST_T2F("sched",    0, S_CTX_INFO_SCHED);
53   TEST_T2F("nproc",    0, S_CTX_INFO_NPROC);
54   TEST_T2F("private",  0, S_CTX_INFO_PRIVATE);
55   TEST_T2F("fakeinit", 0, S_CTX_INFO_INIT);
56   TEST_T2F("hideinfo", 0, S_CTX_INFO_HIDEINFO);
57   TEST_T2F("ulimit",   0, S_CTX_INFO_ULIMIT);
58   TEST_T2F("XXX",      0, 0);
59   TEST_T2F("",         0, 0);
60
61   TEST_F2T("lock",     S_CTX_INFO_LOCK);
62   TEST_F2T("sched",    S_CTX_INFO_SCHED);
63   TEST_F2T("nproc",    S_CTX_INFO_NPROC);
64   TEST_F2T("private",  S_CTX_INFO_PRIVATE);
65   TEST_F2T("fakeinit", S_CTX_INFO_INIT);
66   TEST_F2T("hideinfo", S_CTX_INFO_HIDEINFO);
67   TEST_F2T("ulimit",   S_CTX_INFO_ULIMIT);
68   TEST_F2T(0,          0);
69   TEST_F2T("ulimit",   64 | 128 | 23 );
70   TEST_F2T("fakeinit", 23);
71
72   TEST_LIST("lock",         0, S_CTX_INFO_LOCK,                  -1,0);
73   TEST_LIST("lock,sched,",  0, S_CTX_INFO_LOCK|S_CTX_INFO_SCHED, -1,0);
74   TEST_LIST("lock,XXX",     0, S_CTX_INFO_LOCK,                   5,3);
75   TEST_LIST("",             0, 0,                                -1,0);
76   TEST_LIST("X",            0, 0,                                 0,1);
77   TEST_LIST("lock,sched,", 10, S_CTX_INFO_LOCK|S_CTX_INFO_SCHED, -1,0);
78
79   return 0;
80 }
81