test_dr.h 8.93 KB
Newer Older
1 2 3
/*****************************************************************************
 * test_dr.h
 * (c)2001-2002 VideoLAN
4
 * $Id: test_dr.h,v 1.3 2002/05/09 20:39:02 bozo Exp $
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 *****************************************************************************/
23 24 25 26 27
#ifdef WIN32
# define PRI64d "I64u"
#else
# define PRI64d "llu"
#endif
28

29 30
#include "test_dr_cmp.h"

31 32
#define BOZO_VARS(sname)                                                \
  int i_err = 0;                                                        \
33
  long long unsigned int i_loop_count;                                  \
34 35 36 37 38 39 40 41
  dvbpsi_##sname##_dr_t s_decoded, *p_new_decoded;                      \
  dvbpsi_descriptor_t * p_descriptor;

#define BOZO_CLEAN()                                                    \
  dvbpsi_DeleteDescriptors(p_descriptor);

#define BOZO_DOJOB(fname)                                               \
  if(!(i_loop_count & 0xffff))                                          \
42
    fprintf(stdout, "\r  iteration count: %22"PRI64d, i_loop_count);       \
43 44 45 46 47 48 49 50 51
  i_loop_count++;                                                       \
  p_descriptor = dvbpsi_Gen##fname##Dr(&s_decoded, 0);                  \
  p_new_decoded = dvbpsi_Decode##fname##Dr(p_descriptor);

#define BOZO_START(name)                                                \
  fprintf(stdout, "\"%s\" descriptor check:\n", #name);

#define BOZO_END(name)                                                  \
  if(i_err)                                                             \
52
    fprintf(stderr, "\"%s\" descriptor check FAILED !!!\n\n", #name);   \
53 54 55 56 57
  else                                                                  \
    fprintf(stdout, "\"%s\" descriptor check succeeded\n\n", #name);


/* integer */
58 59 60
#define BOZO_init_integer(name, default)                                \
  s_decoded.name = default;

61
#define BOZO_begin_integer(name, bitcount)                              \
62 63
  if(!i_err)                                                            \
  {                                                                     \
64
    unsigned int i = 0;                                                 \
65 66 67
    fprintf(stdout, "  \"%s\" %u bit(s) integer check\n",               \
            #name, bitcount);                                           \
    i_loop_count = 0;                                                   \
68
    s_decoded.name = 1;                                                 \
69 70 71
    do                                                                  \
    {

72 73
#define BOZO_end_integer(name, bitcount)                                \
      s_decoded.name <<= 1;                                             \
74
    } while(!i_err                                                      \
75
         && (++i < bitcount));                                          \
76
    fprintf(stdout, "\r  iteration count: %22"PRI64d, i_loop_count);       \
77 78 79 80 81
    if(i_err)                                                           \
      fprintf(stdout, "    FAILED !!!\n");                              \
    else                                                                \
      fprintf(stdout, "    Ok.\n");                                     \
  }
82 83 84 85

#define BOZO_check_integer(name, bitcount)                              \
  if(!i_err && (s_decoded.name != p_new_decoded->name))                 \
  {                                                                     \
86
    fprintf(stderr, "\nError: integer %s %"PRI64d" -> %"PRI64d"\n", #name,        \
87 88
            (long long unsigned int)s_decoded.name,                     \
            (long long unsigned int)p_new_decoded->name);               \
89 90 91 92 93
    i_err = 1;                                                          \
  }


/* boolean */
94 95 96
#define BOZO_init_boolean(name, default)                                \
  s_decoded.name = default;

97
#define BOZO_begin_boolean(name)                                        \
98 99 100 101
  if(!i_err)                                                            \
  {                                                                     \
    fprintf(stdout, "  \"%s\" boolean check\n", #name);                 \
    i_loop_count = 0;                                                   \
102
    s_decoded.name = false;                                             \
103 104
    do                                                                  \
    {
105 106

#define BOZO_end_boolean(name)                                          \
107 108
      s_decoded.name ^= true;                                           \
    } while(!i_err && s_decoded.name);                                  \
109
    fprintf(stdout, "\r  iteration count: %22"PRI64d, i_loop_count);       \
110 111 112 113 114
    if(i_err)                                                           \
      fprintf(stdout, "    FAILED !!!\n");                              \
    else                                                                \
      fprintf(stdout, "    Ok.\n");                                     \
  }
115 116 117 118 119 120 121 122 123 124

#define BOZO_check_boolean(name)                                        \
  if(    !i_err                                                         \
      && (    (s_decoded.name && !p_new_decoded->name)                  \
           || (!s_decoded.name && p_new_decoded->name)))                \
  {                                                                     \
    fprintf(stderr, "\nError: boolean %s %d -> %d\n", #name,            \
            s_decoded.name, p_new_decoded->name);                       \
    i_err = 1;                                                          \
  }
125

126 127
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))

128
/* array */
129
#define BOZO_begin_array(name, len_name, min_size)                      \
130 131 132
  if(!i_err)                                                            \
  {                                                                     \
    fprintf(stdout, "  \"%s\" array check\n", #name);                   \
133
    i_loop_count = min_size;                                            \
134 135
    do                                                                  \
    {                                                                   \
136 137
      for(size_t i = 0 ; i < sizeof(s_decoded.name) ; ++i)              \
        ((uint8_t*)s_decoded.name)[i] = rand();                         \
138 139
      s_decoded.len_name = i_loop_count;

140 141
#define BOZO_end_array(name, max_len)                                   \
    } while(!i_err && i_loop_count < max_len);                          \
142 143 144 145 146 147 148
    fprintf(stdout, "\r  iteration count: %22"PRI64d, i_loop_count);       \
    if(i_err)                                                           \
      fprintf(stdout, "    FAILED !!!\n");                              \
    else                                                                \
      fprintf(stdout, "    Ok.\n");                                     \
  }

149 150 151 152 153 154 155 156 157 158
#define BOZO_check_array_begin(name, len_name)                          \
  if(!i_err && s_decoded.len_name != p_new_decoded->len_name)           \
  {                                                                     \
    fprintf(stderr, "\nError : array %s sizes not equal : %d -> %d\n",  \
      #name, s_decoded.len_name, p_new_decoded->len_name);              \
    i_err = 1;                                                          \
  }

#define BOZO_check_array_gen(name, len_name)                            \
  else if(    !i_err                                                    \
159 160
      && (memcmp(s_decoded.name, p_new_decoded->name,                   \
        s_decoded.len_name * sizeof(s_decoded.name[0])) != 0))          \
161 162 163
  {                                                                     \
    fprintf(stderr, "\nError: array %s not equal\n", #name);            \
    i_err = 1;                                                          \
164 165 166 167
  }

#define BOZO_check_array_cmp(name, len_name, type)                      \
  else if(    !i_err                                                    \
168 169
      && (my_memcmp(s_decoded.name, p_new_decoded->name,                \
        s_decoded.len_name, compare_##type) != 0))                      \
170
  {                                                                     \
171
    fprintf(stderr, "\nError: array %s not equal\n", #name);            \
172 173
    i_err = 1;                                                          \
  }