2 * test_allow - Test program for the IUCV Terminal Applications
4 * Test program to check common functions that use the regex api
6 * Copyright IBM Corp. 2008, 2009
7 * Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
13 #include "iucvterm/config.h"
14 #include "iucvterm/functions.h"
17 static int test_userid_cpy(char padded
[9])
23 memcpy(uid
, padded
, 8);
24 userid_cpy(id_str
, uid
);
27 assert(0 == memcmp(padded
, id_str
, len
));
29 if (strchr(id_str
, ' ') != NULL
)
37 char re_ok
[] = "^T63[[:digit:]]{1,5}$";
38 char re_wrong
[] = "^t63[[:alpha:]+$";
39 char re_short
[] = "^lnx[[:digit:]]{3}$";
43 /* redirect stderr to /dev/null to avoid regex error output */
44 freopen("/dev/null", "w", stderr
);
46 assert(-1 == is_regex_valid(re_wrong
));
47 assert(-1 == is_regex_valid(NULL
));
48 assert(0 == is_regex_valid(re_ok
));
49 assert(0 == is_regex_valid(re_short
));
52 assert(0 == strmatch("T6345050", "T6345050"));
54 assert(0 == strmatch("T6345050", re_ok
));
55 assert(0 == strmatch("t6345050", re_ok
)); /* icase */
56 assert(-1 == strmatch("T6345050", NULL
));
57 assert(-1 == strmatch("T6345050", re_wrong
));
58 assert(1 == strmatch("T634505A", re_ok
));
60 /* test userid_cpy() function */
61 snprintf(id_short
, 9, "%-8s", "");
62 assert(0 == test_userid_cpy(id_short
));
63 snprintf(id_short
, 9, "1");
64 assert(1 == test_userid_cpy(id_short
));
65 snprintf(id_short
, 9, "12345678");
66 assert(8 == test_userid_cpy(id_short
));
67 snprintf(id_short
, 9, "ABCD");
68 assert(4 == test_userid_cpy(id_short
));
70 /* check for user IDs < 8 characters */
71 snprintf(id_short
, 9, "%-8s", "LNX001");
72 memcpy(user_id
, id_short
, 8);
73 userid_cpy(id_short
, user_id
);
74 assert(0 == strmatch(id_short
, re_short
));