1 /* $Id: tstcodec.c,v 1.6 2005-01-15 19:38:35 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
23 #include "../../index/index.h"
27 int tst_encode(int num)
31 void *codec_handle =iscz1_start();
32 char *dst_buf = malloc(200 + num * 10);
36 printf ("%s: out of memory (num=%d)\n", prog, num);
40 for (i = 0; i<num; i++)
42 const char *src = (const char *) &key;
47 iscz1_encode (codec_handle, &dst, &src);
48 if (dst > dst_buf + num*10)
50 printf ("%s: i=%d size overflow\n", prog, i);
54 iscz1_stop(codec_handle);
56 codec_handle =iscz1_start();
60 const char *src = dst_buf;
61 for (i = 0; i<num; i++)
63 char *dst = (char *) &key;
64 const char *src0 = src;
65 iscz1_decode(codec_handle, &dst, &src);
69 printf ("%s: i=%d key.len=%d expected 2\n", prog,
73 printf (" %02X (%d decimal)", *src0, *src0);
79 if (key.mem[0] != (i<<8))
81 printf ("%s: i=%d mem[0]=" ZINT_FORMAT " expected "
82 "%d\n", prog, i, key.mem[0], i>>8);
85 printf (" %02X (%d decimal)", *src0, *src0);
91 if (key.mem[1] != (i&255))
93 printf ("%s: i=%d mem[0]=" ZINT_FORMAT " expected %d\n",
94 prog, i, key.mem[1], i&255);
97 printf (" %02X (%d decimal)", *src0, *src0);
106 iscz1_stop(codec_handle);
118 void *codec_handle =iscz1_start();
120 memset(&key1, 0, sizeof(key1));
121 memset(&key2, 0, sizeof(key2));
124 key1.mem[0] = 4*65536+1016;
126 key1.mem[2] = 125060;
131 iscz1_encode(codec_handle, &dst, &src);
133 iscz1_stop(codec_handle);
135 codec_handle =iscz1_start();
140 iscz1_decode(codec_handle, &dst, &src);
142 iscz1_stop(codec_handle);
144 if (memcmp(&key1, &key2, sizeof(key1)))
146 const char *cp1 = (char*) &key1;
147 const char *cp2 = (char*) &key2;
149 for (i = 0; i<sizeof(key1); i++)
150 printf ("offset=%d char1=%d char2=%d\n", i, cp1[i], cp2[i]);
155 int main(int argc, char **argv)
161 if (num < 1 || num > 100000000)
164 exit(tst_encode(num));