2 * Copyright (c) 2002-2003, Index Data
3 * See the file LICENSE for details.
5 * $Id: tsticonv.c,v 1.5 2003-06-22 11:48:33 adam Exp $
16 #include <yaz/yaz-util.h>
18 /* some test strings in ISO-8859-1 format */
28 /* some test strings in MARC-8 format */
29 const char *marc8_strings[] = {
31 "\xa2", /* latin capital letter o with stroke */
32 "eneb\xb5r", /* latin small letter ae */
33 "\xe8\x75", /* latin small letter u with umlaut */
34 "\xe3\x75", /* latin small letter u with circumflex */
35 "\xe3\x75r", /* latin small letter u with circumflex */
39 static void marc8_tst()
44 cd = yaz_iconv_open("ISO-8859-1", "MARC8");
45 for (i = 0; buf[i]; i++)
48 char *inbuf= (char*) marc8_strings[i];
49 size_t inbytesleft = strlen(inbuf);
51 char *outbuf = outbuf0;
52 size_t outbytesleft = sizeof(outbuf0);
54 r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
55 if (r == (size_t) (-1))
57 int e = yaz_iconv_error(cd);
59 printf ("tsticonv 6 i=%d e=%d\n", i, e);
62 if ((outbuf - outbuf0) != strlen(buf[i])
63 || memcmp(outbuf0, buf[i], strlen(buf[i])))
65 printf ("tsticonv 7 i=%d\n", i);
66 printf ("buf=%s out=%s\n", buf[i], outbuf0);
73 static void dconvert(int mandatory, const char *tmpcode)
77 for (i = 0; buf[i]; i++)
80 char *inbuf = (char*) buf[i];
81 size_t inbytesleft = strlen(inbuf);
84 char *outbuf = outbuf0;
85 size_t outbytesleft = sizeof(outbuf0);
87 cd = yaz_iconv_open(tmpcode, "ISO-8859-1");
92 printf ("tsticonv 1\n");
95 r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
96 if (r == (size_t)(-1))
98 int e = yaz_iconv_error(cd);
100 printf ("tsticonv 2 e=%d\n", e);
105 cd = yaz_iconv_open("ISO-8859-1", tmpcode);
110 printf ("tsticonv 3\n");
114 inbytesleft = sizeof(outbuf0) - outbytesleft;
117 outbytesleft = sizeof(outbuf1);
118 r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
119 if (r == (size_t)(-1)) {
120 int e = yaz_iconv_error(cd);
122 printf ("tsticonv 4 e=%d\n", e);
125 if (strlen(buf[i]) == (sizeof(outbuf1) - outbytesleft) &&
126 memcmp(outbuf1, buf[i], strlen(buf[i])))
128 printf ("tsticonv 5\n");
135 int main (int argc, char **argv)
137 dconvert(1, "UTF-8");
138 dconvert(1, "ISO-8859-1");
140 dconvert(0, "CP865");