torture_bnf.c 2.63 KB
Newer Older
Pekka Pessi's avatar
Pekka Pessi committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
/*
 * This file is part of the Sofia-SIP package
 *
 * Copyright (C) 2005 Nokia Corporation.
 *
 * Contact: Pekka Pessi <pekka.pessi@nokia.com>
 *
 * * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

/**@CFILE torture_bnf.c
 *
 * Torture tests for BNF functions.
 *
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
 *
 * @date Created: Tue Aug 21 15:18:26 2001 ppessi
 * $Date: 2005/07/20 20:34:54 $
 */

#include "config.h"

const char torture_bnf_c_id[] =
"$Id: torture_bnf.c,v 1.1.1.1 2005/07/20 20:34:54 kaiv Exp $";

#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <stdio.h>
#include <assert.h>

#include "bnf.h"

static int test_flags = 0;
#define TSTFLAGS test_flags

#include <tstdef.h>

char const name[] = "torture_bnf";

void usage(void)
{
  fprintf(stderr, "usage: %s [-v]\n", name);
}

static int bnf_test(void);

int main(int argc, char *argv[])
{
  int retval = 0;
  int i;

  for (i = 1; argv[i]; i++) {
    if (strcmp(argv[i], "-v") == 0)
      test_flags |= tst_verbatim;
    else
      usage();
  }

  retval |= bnf_test(); fflush(stdout);

  return retval;
}

int count_bnf(int bnf_flags)
{
  int i, n;

  for (i = 0, n = 0; i < 128; i++)
    if (_bnf_table[i] & bnf_flags)
      n++;

  return n;
}

int bnf_test(void)
{
  BEGIN();
  TEST_1(IS_TOKEN('a'));
  TEST_1(IS_TOKEN('b'));
  TEST(span_lws("  \r\n \r\nLoppuu"), 7);
  TEST(span_lws("  \r\r\nLoppuu"), 5);
  TEST(span_lws("  \n\r\nLoppuu"), 5);
  TEST(span_token(SIP_TOKEN), strlen(SIP_TOKEN));
  TEST(count_bnf(bnf_token), strlen(SIP_TOKEN "$"));
  #define SIP_PARAM SIP_TOKEN "[:]/"
  TEST(span_param(SIP_PARAM), strlen(SIP_PARAM));
  TEST(count_bnf(bnf_param), strlen(SIP_PARAM "$"));

  TEST(span_unreserved(URL_UNRESERVED URL_ESCAPED), 
       strlen(URL_UNRESERVED URL_ESCAPED));

  TEST(count_bnf(bnf_unreserved),
       strlen(URL_UNRESERVED URL_ESCAPED));

  {
    char word[] = ALPHA DIGIT "-.!%*_+`'~()<>:\\\"/[]?{}";
    TEST(span_word(word), strlen(word));
  }

  END();
}