Back to index

glibc  2.9
Classes | Functions | Variables
runtests.c File Reference
#include <sys/types.h>
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "testcases.h"

Go to the source code of this file.

Classes

struct  a_test

Functions

static int run_a_test (int id, const struct a_test *t)
int main (int argc, char *argv[])

Variables

static struct a_test []

Class Documentation

struct a_test

Definition at line 35 of file runtests.c.

Class Members
const char * data
int expected
const char * pattern

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 113 of file runtests.c.

{
  int x;
  int lo;
  int hi;
  int res = 0;

  lo = 0;
  hi = (sizeof (the_tests) / sizeof (the_tests[0])) - 1;

  if (argc > 1)
    {
      lo = atoi (argv[1]);
      hi = lo + 1;

      if (argc > 2)
       hi = atoi (argv[2]);
    }

  for (x = lo; x < hi; ++x)
    {
      printf ("#%d:", x);
      res |= run_a_test (x, &the_tests[x]);
    }
  return res != 0;
}

Here is the call graph for this function:

static int run_a_test ( int  id,
const struct a_test t 
) [static]

Definition at line 52 of file runtests.c.

{
  static const char * last_pattern = 0;
  static regex_t r;
  int err;
  char errmsg[100];
  int x;
  regmatch_t regs[10];

  if (!last_pattern || strcmp (last_pattern, t->pattern))
    {
      if (last_pattern)
       regfree (&r);
      last_pattern = t->pattern;
      err = regcomp (&r, t->pattern, REG_EXTENDED);
      if (err)
       {
         if (t->expected == 2)
           {
             puts (" OK.");
             return 0;
           }
         if (last_pattern)
           regfree (&r);
         last_pattern = NULL;
         regerror (err, &r, errmsg, 100);
         printf (" FAIL: %s.\n", errmsg);
         return 1;
       }
      else if (t->expected == 2)
       {
         printf ("test %d\n", id);
         printf ("pattern \"%s\" successfull compilation not expected\n",
                t->pattern);
         return 1;
       }
    }

  err = regexec (&r, t->data, 10, regs, 0);

  if (err != t->expected)
    {
      printf ("test %d\n", id);
      printf ("pattern \"%s\" data \"%s\" wanted %d got %d\n",
             t->pattern, t->data, t->expected, err);
      for (x = 0; x < 10; ++x)
       printf ("reg %d == (%d, %d) %.*s\n",
              x,
              regs[x].rm_so,
              regs[x].rm_eo,
              regs[x].rm_eo - regs[x].rm_so,
              t->data + regs[x].rm_so);
      return 1;
    }
  puts (" OK.");
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

struct a_test[] [static]

Definition at line 42 of file runtests.c.