]> git.ipfire.org Git - thirdparty/glibc.git/blob - posix/runtests.c
Update.
[thirdparty/glibc.git] / posix / runtests.c
1 /***********************************************************
2
3 Copyright 1995 by Tom Lord
4
5 All Rights Reserved
6
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the name of the copyright holder not be
12 used in advertising or publicity pertaining to distribution of the
13 software without specific, written prior permission.
14
15 Tom Lord DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17 EVENT SHALL TOM LORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
19 USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21 PERFORMANCE OF THIS SOFTWARE.
22
23 ******************************************************************/
24
25
26 \f
27 #include <sys/types.h>
28 #include <regex.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 \f
34
35 struct a_test
36 {
37 int expected;
38 const char * pattern;
39 const unsigned char * data;
40 };
41
42 static const struct a_test the_tests[] =
43 {
44 #include "testcases.h"
45 {-1, 0, 0}
46 };
47
48
49 \f
50
51 int
52 run_a_test (int id, const struct a_test * t)
53 {
54 static const char * last_pattern = 0;
55 static regex_t r;
56 int err;
57 char errmsg[100];
58 int x;
59 regmatch_t regs[10];
60
61 if (!last_pattern || strcmp (last_pattern, t->pattern))
62 {
63 if (last_pattern)
64 regfree (&r);
65 last_pattern = t->pattern;
66 err = regcomp (&r, t->pattern, REG_EXTENDED);
67 if (err)
68 {
69 if (t->expected == 2)
70 {
71 puts (" OK.");
72 return 0;
73 }
74 regerror (err, &r, errmsg, 100);
75 printf ("test %d\n", id);
76 puts (errmsg);
77 return 1;
78 }
79 else if (t->expected == 2)
80 {
81 printf ("test %d\n", id);
82 printf ("pattern \"%s\" successfull compilation not expected\n",
83 t->pattern);
84 return 1;
85 }
86 }
87
88 err = regexec (&r, t->data, 10, regs, 0);
89
90 if (err != t->expected)
91 {
92 printf ("test %d\n", id);
93 printf ("pattern \"%s\" data \"%s\" wanted %d got %d\n",
94 t->pattern, t->data, t->expected, err);
95 for (x = 0; x < 10; ++x)
96 printf ("reg %d == (%d, %d) %.*s\n",
97 x,
98 regs[x].rm_so,
99 regs[x].rm_eo,
100 regs[x].rm_eo - regs[x].rm_so,
101 t->data + regs[x].rm_so);
102 return 1;
103 }
104 puts (" OK.");
105 return 0;
106 }
107
108 \f
109
110 int
111 main (int argc, char * argv[])
112 {
113 int x;
114 int lo;
115 int hi;
116 int res = 0;
117
118 lo = 0;
119 hi = (sizeof (the_tests) / sizeof (the_tests[0])) - 1;
120
121 if (argc > 1)
122 {
123 lo = atoi (argv[1]);
124 hi = lo + 1;
125
126 if (argc > 2)
127 hi = atoi (argv[2]);
128 }
129
130 for (x = lo; x < hi; ++x)
131 {
132 printf ("#%d:", x);
133 res |= run_a_test (x, &the_tests[x]);
134 }
135 return res != 0;
136 }