Defined log level bits app2 and app3
[yaz-moved-to-github.git] / util / tsticonv.c
1 /*
2  * Copyright (c) 2002-2003, Index Data
3  * See the file LICENSE for details.
4  *
5  * $Id: tsticonv.c,v 1.2 2003-05-06 10:07:33 adam Exp $
6  */
7
8 #if HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11
12 #include <errno.h>
13 #include <string.h>
14 #include <ctype.h>
15
16 #include <yaz/yaz-util.h>
17
18 /* some test strings in ISO-8859-1 format */
19 const char *buf[] = {
20         "ax" ,
21         "\330",
22         "eneb\346r",
23         0 };
24
25 static dconvert(int mandatory, const char *tmpcode)
26 {
27     int i;
28     yaz_iconv_t cd;
29     for (i = 0; buf[i]; i++)
30     {
31         int j;
32         size_t r;
33         char *inbuf = (char*) buf[i];
34         size_t inbytesleft = strlen(inbuf);
35         char outbuf0[24];
36         char outbuf1[10];
37         char *outbuf = outbuf0;
38         size_t outbytesleft = sizeof(outbuf0);
39
40         cd = yaz_iconv_open(tmpcode, "ISO-8859-1");
41         if (!cd)
42         {
43             if (!mandatory)
44                 return;
45             printf ("tsticonv 1\n");
46             exit(1);
47         }
48         r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
49         if (r == (size_t)(-1))
50         {
51             int e = yaz_iconv_error(cd);
52
53             printf ("tsticonv 2 e=%d\n", e);
54             exit(2);
55         }
56         yaz_iconv_close(cd);
57         
58         cd = yaz_iconv_open("ISO-8859-1", tmpcode);
59         if (!cd)
60         {
61             if (!mandatory)
62                 return;
63             printf ("tsticonv 3\n");
64             exit(3);
65         }
66         inbuf = outbuf0;
67         inbytesleft = sizeof(outbuf0) - outbytesleft;
68
69         outbuf = outbuf1;
70         outbytesleft = sizeof(outbuf1);
71         r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
72         if (r == (size_t)(-1)) {
73             int e = yaz_iconv_error(cd);
74
75             printf ("tsticonv 4 e=%d\n", e);
76             exit(4);
77         }
78         if (strlen(buf[i]) == (sizeof(outbuf1) - outbytesleft) &&
79             memcmp(outbuf1, buf[i], strlen(buf[i])))
80         {
81             printf ("tsticonv 5\n");
82             exit(5);
83         }
84         yaz_iconv_close(cd);
85     }
86 }
87         
88 int main (int argc, char **argv)
89 {
90     dconvert(1, "UTF-8");
91     dconvert(1, "ISO-8859-1");
92     dconvert(1, "UCS4");
93     dconvert(0, "CP865");
94     exit (0);
95 }