1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2010 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "../../index/index.h"
25 int tst_encode(int num)
29 void *codec_handle =iscz1_start();
30 char *dst_buf = malloc(200 + num * 10);
34 printf ("%s: out of memory (num=%d)\n", prog, num);
38 for (i = 0; i<num; i++)
40 const char *src = (const char *) &key;
45 iscz1_encode (codec_handle, &dst, &src);
46 if (dst > dst_buf + num*10)
48 printf ("%s: i=%d size overflow\n", prog, i);
52 iscz1_stop(codec_handle);
54 codec_handle =iscz1_start();
58 const char *src = dst_buf;
59 for (i = 0; i<num; i++)
61 char *dst = (char *) &key;
62 const char *src0 = src;
63 iscz1_decode(codec_handle, &dst, &src);
67 printf ("%s: i=%d key.len=%d expected 2\n", prog,
71 printf (" %02X (%d decimal)", *src0, *src0);
77 if (key.mem[0] != (i<<8))
79 printf ("%s: i=%d mem[0]=" ZINT_FORMAT " expected "
80 "%d\n", prog, i, key.mem[0], i>>8);
83 printf (" %02X (%d decimal)", *src0, *src0);
89 if (key.mem[1] != (i&255))
91 printf ("%s: i=%d mem[0]=" ZINT_FORMAT " expected %d\n",
92 prog, i, key.mem[1], i&255);
95 printf (" %02X (%d decimal)", *src0, *src0);
104 iscz1_stop(codec_handle);
116 void *codec_handle =iscz1_start();
118 memset(&key1, 0, sizeof(key1));
119 memset(&key2, 0, sizeof(key2));
122 key1.mem[0] = 4*65536+1016;
124 key1.mem[2] = 125060;
129 iscz1_encode(codec_handle, &dst, &src);
131 iscz1_stop(codec_handle);
133 codec_handle =iscz1_start();
138 iscz1_decode(codec_handle, &dst, &src);
140 iscz1_stop(codec_handle);
142 if (memcmp(&key1, &key2, sizeof(key1)))
144 const char *cp1 = (char*) &key1;
145 const char *cp2 = (char*) &key2;
147 for (i = 0; i<sizeof(key1); i++)
148 printf ("offset=%d char1=%d char2=%d\n", i, cp1[i], cp2[i]);
152 int tstcodec2(int num)
157 int neg = 0; /* iscz1_{en,de}code does not handle negative numbers */
158 void *encode_handle =iscz1_start();
159 void *decode_handle =iscz1_start();
162 for (i = 0; i<num; i++)
164 struct it_key ar1, ar2;
168 for (j = 0; j<ar1.len; j++)
170 int r = (rand() % max) - neg;
176 const char *src = (const char *) &ar1;
178 iscz1_encode(encode_handle, &dst, &src);
182 iscz1_decode(decode_handle, &dst, &src);
185 if (ar1.len != ar2.len)
187 printf("tstcodec2: length does not match\n");
190 for (j = 0; j<ar1.len; j++)
192 if (ar1.mem[j] != ar2.mem[j])
195 for (j = 0; j<ar1.len; j++)
196 printf(" %d " ZINT_FORMAT " " ZINT_FORMAT "\n",
197 j, ar1.mem[j], ar2.mem[j]);
203 iscz1_stop(encode_handle);
204 iscz1_stop(decode_handle);
209 int main(int argc, char **argv)
216 if (num < 1 || num > 100000000)
219 ret = tstcodec2(500);
220 ret = tst_encode(num);
227 * c-file-style: "Stroustrup"
228 * indent-tabs-mode: nil
230 * vim: shiftwidth=4 tabstop=8 expandtab