source: branches/libc-0.6/src/libctests/glibc/posix/runptests.c

Last change on this file was 2135, checked in by bird, 20 years ago

libc adjustments / config.

  • Property cvs2svn:cvs-rev set to 1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
Line 
1/* POSIX regex testsuite from IEEE 2003.2.
2 Copyright (C) 1998, 2003 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
20
21#include <sys/types.h>
22#include <regex.h>
23#include <stdio.h>
24#include <string.h>
25
26/* Data structure to describe the tests. */
27struct test
28{
29 int start;
30 int end;
31 const char *reg;
32 const char *str;
33 int options;
34} tests[] =
35{
36#include "ptestcases.h"
37};
38
39
40int
41main (int argc, char *argv[])
42{
43 size_t cnt;
44 int errors = 0;
45 int errors_expected = argc > 1 ? atoi(argv[argc - 1]) : 0;
46
47 for (cnt = 0; cnt < sizeof (tests) / sizeof (tests[0]); ++cnt)
48 if (tests[cnt].str == NULL)
49 {
50 printf ("\n%s\n%.*s\n", tests[cnt].reg,
51 (int) strlen (tests[cnt].reg),
52 "-----------------------------------------------------");
53 }
54 else if (tests[cnt].reg == NULL)
55 printf ("!!! %s\n", tests[cnt].str);
56 else
57 {
58 regex_t re;
59 regmatch_t match[20];
60 int err;
61
62 printf ("regexp: \"%s\", string: \"%s\" -> ", tests[cnt].reg,
63 tests[cnt].str);
64
65 /* Compile the expression. */
66 err = regcomp (&re, tests[cnt].reg, tests[cnt].options);
67 if (err != 0)
68 {
69 if (tests[cnt].start == -2)
70 puts ("compiling failed, OK");
71 else
72 {
73 char buf[100];
74 regerror (err, &re, buf, sizeof (buf));
75 printf ("FAIL: %s\n", buf);
76 ++errors;
77 }
78
79 continue;
80 }
81 else if (tests[cnt].start == -2)
82 {
83 puts ("compiling suceeds, FAIL");
84 errors++;
85 continue;
86 }
87
88 /* Run the actual test. */
89 err = regexec (&re, tests[cnt].str, 20, match, 0);
90
91 if (err != 0)
92 {
93 if (tests[cnt].start == -1)
94 puts ("no match, OK");
95 else
96 {
97 puts ("no match, FAIL");
98 ++errors;
99 }
100 }
101 else
102 {
103 if (match[0].rm_so == 0 && tests[cnt].start == 0
104 && match[0].rm_eo == 0 && tests[cnt].end == 0)
105 puts ("match, OK");
106 else if (match[0].rm_so + 1 == tests[cnt].start
107 && match[0].rm_eo == tests[cnt].end)
108 puts ("match, OK");
109 else
110 {
111 printf ("wrong match (%d to %d): FAIL\n",
112 match[0].rm_so, match[0].rm_eo);
113 ++errors;
114 }
115 }
116
117 /* Free all resources. */
118 regfree (&re);
119 }
120
121 printf ("\n%Zu tests, %d errors, expected %d\n", cnt, errors, errors_expected);
122
123 return errors != errors_expected;
124}
Note: See TracBrowser for help on using the repository browser.