1 /* $Id: tstcodec.c,v 1.8 2006-02-20 18:33:09 adam Exp $
2 Copyright (C) 1995-2005
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "../../index/index.h"
28 int tst_encode(int num)
32 void *codec_handle =iscz1_start();
33 char *dst_buf = malloc(200 + num * 10);
37 printf ("%s: out of memory (num=%d)\n", prog, num);
41 for (i = 0; i<num; i++)
43 const char *src = (const char *) &key;
48 iscz1_encode (codec_handle, &dst, &src);
49 if (dst > dst_buf + num*10)
51 printf ("%s: i=%d size overflow\n", prog, i);
55 iscz1_stop(codec_handle);
57 codec_handle =iscz1_start();
61 const char *src = dst_buf;
62 for (i = 0; i<num; i++)
64 char *dst = (char *) &key;
65 const char *src0 = src;
66 iscz1_decode(codec_handle, &dst, &src);
70 printf ("%s: i=%d key.len=%d expected 2\n", prog,
74 printf (" %02X (%d decimal)", *src0, *src0);
80 if (key.mem[0] != (i<<8))
82 printf ("%s: i=%d mem[0]=" ZINT_FORMAT " expected "
83 "%d\n", prog, i, key.mem[0], i>>8);
86 printf (" %02X (%d decimal)", *src0, *src0);
92 if (key.mem[1] != (i&255))
94 printf ("%s: i=%d mem[0]=" ZINT_FORMAT " expected %d\n",
95 prog, i, key.mem[1], i&255);
98 printf (" %02X (%d decimal)", *src0, *src0);
107 iscz1_stop(codec_handle);
119 void *codec_handle =iscz1_start();
121 memset(&key1, 0, sizeof(key1));
122 memset(&key2, 0, sizeof(key2));
125 key1.mem[0] = 4*65536+1016;
127 key1.mem[2] = 125060;
132 iscz1_encode(codec_handle, &dst, &src);
134 iscz1_stop(codec_handle);
136 codec_handle =iscz1_start();
141 iscz1_decode(codec_handle, &dst, &src);
143 iscz1_stop(codec_handle);
145 if (memcmp(&key1, &key2, sizeof(key1)))
147 const char *cp1 = (char*) &key1;
148 const char *cp2 = (char*) &key2;
150 for (i = 0; i<sizeof(key1); i++)
151 printf ("offset=%d char1=%d char2=%d\n", i, cp1[i], cp2[i]);
155 int tstcodec2(int num)
160 int neg = 0; /* iscz1_{en,de}code does not handle negative numbers */
161 void *encode_handle =iscz1_start();
162 void *decode_handle =iscz1_start();
165 for (i = 0; i<num; i++)
167 struct it_key ar1, ar2;
171 for (j = 0; j<ar1.len; j++)
173 int r = (rand() % max) - neg;
179 const char *src = (const char *) &ar1;
181 iscz1_encode(encode_handle, &dst, &src);
185 iscz1_decode(decode_handle, &dst, &src);
188 if (ar1.len != ar2.len)
190 printf("tstcodec2: length does not match\n");
193 for (j = 0; j<ar1.len; j++)
195 if (ar1.mem[j] != ar2.mem[j])
198 for (j = 0; j<ar1.len; j++)
199 printf(" %d " ZINT_FORMAT " " ZINT_FORMAT "\n",
200 j, ar1.mem[j], ar2.mem[j]);
206 iscz1_stop(encode_handle);
207 iscz1_stop(decode_handle);
212 int main(int argc, char **argv)
219 if (num < 1 || num > 100000000)
222 ret = tstcodec2(500);
223 ret = tst_encode(num);