Remove isamd. It's not been in use for a long time and isamb is better
[idzebra-moved-to-github.git] / test / codec / tstcodec.c
1 /* $Id: tstcodec.c,v 1.2 2004-08-04 08:35:26 adam Exp $
2    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
3    Index Data Aps
4
5 This file is part of the Zebra server.
6
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
10 version.
11
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
15 for more details.
16
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
20 02111-1307, USA.
21 */
22
23 #include "../../index/index.h"
24
25 char *prog = "";
26
27 int tst_encode(int num)
28 {
29     struct it_key key;
30     int i;
31     void *codec_handle =iscz1_start();
32     char *dst_buf = malloc(200 + num * 10);
33     char *dst = dst_buf;
34     if (!dst_buf)
35     {
36         printf ("%s: out of memory (num=%d)\n", prog, num);
37         return 10;
38     }
39
40     for (i = 0; i<num; i++)
41     {
42         const char *src = (const char *) &key;
43
44 #if IT_KEY_NEW
45         key.len = 2;
46         key.mem[0] = i >> 8;
47         key.mem[1] = i & 255;
48 #else
49         key.sysno = num;
50         key.seqno = 1;  
51 #endif
52         iscz1_encode (codec_handle, &dst, &src);
53         if (dst > dst_buf + num*10)
54         {
55             printf ("%s: i=%d size overflow\n", prog, i);
56             return 1;
57         }
58     }
59     iscz1_stop(codec_handle);
60
61     codec_handle =iscz1_start();
62
63     if (1)
64     {
65         const char *src = dst_buf;
66         for (i = 0; i<num; i++)
67         {
68             char *dst = (char *) &key;
69             const char *src0 = src;
70             iscz1_decode(codec_handle, &dst, &src);
71             
72 #if IT_KEY_NEW
73             if (key.len != 2)
74             {
75                 printf ("%s: i=%d key.len=%d expected 2\n", prog,
76                         i, key.len);
77                 while (src0 != src)
78                 {
79                     printf (" %02X (%d decimal)", *src0, *src0);
80                     src0++;
81                 }
82                 printf ("\n");
83                 return 2;
84             }
85             if (key.mem[0] != (i>>8))
86             {
87                 printf ("%s: i=%d mem[0]=" ZINT_FORMAT " expected "
88                         "%d\n", prog, i, key.mem[0], i>>8);
89                 while (src0 != src)
90                 {
91                     printf (" %02X (%d decimal)", *src0, *src0);
92                     src0++;
93                 }
94                 printf ("\n");
95                 return 3;
96             }
97             if (key.mem[1] != (i&255))
98             {
99                 printf ("%s: i=%d mem[0]=" ZINT_FORMAT " expected %d\n",
100                         prog, i, key.mem[1], i&255);
101                 while (src0 != src)
102                 {
103                     printf (" %02X (%d decimal)", *src0, *src0);
104                     src0++;
105                 }
106                 printf ("\n");
107                 return 4;
108             }
109 #else
110
111 #endif
112         }
113     }
114
115     iscz1_stop(codec_handle);
116     free(dst_buf);
117     return 0;
118 }
119
120 int main(int argc, char **argv)
121 {
122     int num = 0;
123     prog = *argv;
124     if (argc > 1)
125         num = atoi(argv[1]);
126     if (num < 1 || num > 100000000)
127         num = 10000;
128     exit(tst_encode(num));
129 }
130