VirtualBox

source: kBuild/vendor/sed/4.1.5/testsuite/runtests.c@ 599

Last change on this file since 599 was 599, checked in by bird, 18 years ago

GNU sed 4.1.5.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette