Import version 1.8.3
[s390-tools.git] / iucvterm / test / test_allow.c
blob259e576796f2c366090b12457c20f80a0b32dc88
1 /*
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>
8 */
9 #include <stdio.h>
10 #include <unistd.h>
11 #include "test.h"
13 #include "iucvterm/config.h"
14 #include "iucvterm/functions.h"
17 static int test_userid_cpy(char padded[9])
19 char uid[8];
20 char id_str[9];
21 size_t len;
23 memcpy(uid, padded, 8);
24 userid_cpy(id_str, uid);
26 len = strlen(id_str);
27 assert(0 == memcmp(padded, id_str, len));
29 if (strchr(id_str, ' ') != NULL)
30 __fail();
32 return len;
35 int main(void)
37 char re_ok[] = "^T63[[:digit:]]{1,5}$";
38 char re_wrong[] = "^t63[[:alpha:]+$";
39 char re_short[] = "^lnx[[:digit:]]{3}$";
40 char id_short[9];
41 char user_id[8];
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));
51 /* simple */
52 assert(0 == strmatch("T6345050", "T6345050"));
53 /* using re */
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));
76 return 0;