08394edd028afeb28a6def6b7c532049049e8b92
[yaz-moved-to-github.git] / test / tsticonv.c
1 /*
2  * Copyright (C) 1995-2007, Index Data ApS
3  * See the file LICENSE for details.
4  *
5  * $Id: tsticonv.c,v 1.35 2008-03-12 08:53:28 adam Exp $
6  */
7
8 #if HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11
12 #include <stdlib.h>
13 #include <errno.h>
14 #include <string.h>
15 #include <ctype.h>
16
17 #include <yaz/yaz-util.h>
18 #include <yaz/test.h>
19
20 #define ESC "\x1b"
21
22 static int compare_buffers(char *msg, int no,
23                            int expect_len, const char *expect_buf,
24                            int got_len, const char *got_buf)
25 {
26     if (expect_len == got_len
27         && !memcmp(expect_buf, got_buf, expect_len))
28         return 1;
29     
30     if (0) /* use 1 see how the buffers differ (for debug purposes) */
31     {
32         int i;
33         printf("tsticonv test=%s i=%d failed\n", msg, no);
34         printf("off got exp\n");
35         for (i = 0; i<got_len || i<expect_len; i++)
36         {
37             char got_char[10];
38             char expect_char[10];
39             
40             if (i < got_len)
41                 sprintf(got_char, "%02X", got_buf[i]);
42             else
43                 sprintf(got_char, "?  ");
44             
45             if (i < expect_len)
46                 sprintf(expect_char, "%02X", expect_buf[i]);
47             else
48                 sprintf(expect_char, "?  ");
49             
50             printf("%02d  %s  %s %c\n",
51                    i, got_char, expect_char, got_buf[i] == expect_buf[i] ?
52                    ' ' : '*');
53             
54         }
55     }
56     return 0;
57 }
58
59 static int tst_convert_l(yaz_iconv_t cd, size_t in_len, const char *in_buf,
60                          size_t expect_len, const char *expect_buf)
61 {
62     size_t r;
63     char *inbuf= (char*) in_buf;
64     size_t inbytesleft = in_len > 0 ? in_len : strlen(in_buf);
65     char outbuf0[64];
66     char *outbuf = outbuf0;
67
68     while (inbytesleft)
69     {
70         size_t outbytesleft = outbuf0 + sizeof(outbuf0) - outbuf;
71         if (outbytesleft > 12)
72             outbytesleft = 12;
73         r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
74         if (r == (size_t) (-1))
75         {
76             int e = yaz_iconv_error(cd);
77             if (e != YAZ_ICONV_E2BIG)
78                 return 0;
79         }
80         else
81         {
82             yaz_iconv(cd, 0, 0, &outbuf, &outbytesleft);
83             break;
84         }
85     }
86
87     return compare_buffers("tsticonv 22", 0,
88                            expect_len, expect_buf,
89                            outbuf - outbuf0, outbuf0);
90 }
91
92 static int tst_convert_x(yaz_iconv_t cd, const char *buf, const char *cmpbuf,
93                          int expect_error)
94 {
95     int ret = 1;
96     WRBUF b = wrbuf_alloc();
97     char outbuf[12];
98     size_t inbytesleft = strlen(buf);
99     const char *inp = buf;
100     int rounds = 0;
101     for (rounds = 0; inbytesleft && rounds < sizeof(outbuf); rounds++)
102     {
103         size_t outbytesleft = sizeof(outbuf);
104         char *outp = outbuf;
105         size_t r = yaz_iconv(cd, (char**) &inp,  &inbytesleft,
106                              &outp, &outbytesleft);
107         wrbuf_write(b, outbuf, outp - outbuf);
108         if (r == (size_t) (-1))
109         {
110             int e = yaz_iconv_error(cd);
111             if (e != YAZ_ICONV_E2BIG)
112             {
113                 if (expect_error != -1)
114                     if (e != expect_error)
115                         ret = 0;
116                 break;
117             }
118         }
119         else
120         {
121             size_t outbytesleft = sizeof(outbuf);
122             char *outp = outbuf;
123             r = yaz_iconv(cd, 0, 0, &outp, &outbytesleft);
124             wrbuf_write(b, outbuf, outp - outbuf);
125             if (expect_error != -1)
126                 if (expect_error)
127                     ret = 0;
128             break;
129         }
130     }
131     if (wrbuf_len(b) == strlen(cmpbuf) 
132         && !memcmp(cmpbuf, wrbuf_buf(b), wrbuf_len(b)))
133         ;
134     else
135     {
136         WRBUF w = wrbuf_alloc();
137
138         ret = 0;
139         wrbuf_rewind(w);
140         wrbuf_puts_escaped(w, buf);
141         yaz_log(YLOG_LOG, "input %s", wrbuf_cstr(w));
142
143         wrbuf_rewind(w);
144         wrbuf_write_escaped(w, wrbuf_buf(b), wrbuf_len(b));
145         yaz_log(YLOG_LOG, "got %s", wrbuf_cstr(w));
146         
147         wrbuf_rewind(w);
148         wrbuf_puts_escaped(w, cmpbuf);
149         yaz_log(YLOG_LOG, "exp %s", wrbuf_cstr(w));
150
151         wrbuf_destroy(w);
152     }
153
154     wrbuf_destroy(b);
155     return ret;
156 }
157
158 static int tst_convert(yaz_iconv_t cd, const char *buf, const char *cmpbuf)
159 {
160     return tst_convert_x(cd, buf, cmpbuf, 0);
161 }
162
163 /* some test strings in ISO-8859-1 format */
164 static const char *iso_8859_1_a[] = {
165     "ax" ,
166     "\xd8",
167     "eneb\346r",
168     "\xe5" "\xd8",
169     "\xe5" "\xd8" "b",
170     "\xe5" "\xe5",
171     0 };
172
173 static void tst_marc8_to_ucs4b(void)
174 {
175     yaz_iconv_t cd = yaz_iconv_open("UCS4", "MARC8");
176     YAZ_CHECK(cd);
177     if (!cd)
178         return;
179     
180     YAZ_CHECK(tst_convert_l(
181                   cd,
182                   0,
183                   "\033$1" "\x21\x2B\x3B" /* FF1F */ "\033(B" "o",
184                   8, 
185                   "\x00\x00\xFF\x1F" "\x00\x00\x00o"));
186     YAZ_CHECK(tst_convert_l(
187                   cd,
188                   0,
189                   "\033$1" "\x6F\x77\x29" /* AE0E */
190                   "\x6F\x52\x7C" /* c0F4 */ "\033(B",
191                   8,
192                   "\x00\x00\xAE\x0E" "\x00\x00\xC0\xF4"));
193     YAZ_CHECK(tst_convert_l(
194                   cd,
195                   0,
196                   "\033$1"
197                   "\x21\x50\x6E"  /* UCS 7CFB */
198                   "\x21\x51\x31"  /* UCS 7D71 */
199                   "\x21\x3A\x67"  /* UCS 5B89 */
200                   "\x21\x33\x22"  /* UCS 5168 */
201                   "\x21\x33\x53"  /* UCS 5206 */
202                   "\x21\x44\x2B"  /* UCS 6790 */
203                   "\033(B",
204                   24, 
205                   "\x00\x00\x7C\xFB"
206                   "\x00\x00\x7D\x71"
207                   "\x00\x00\x5B\x89"
208                   "\x00\x00\x51\x68"
209                   "\x00\x00\x52\x06"
210                   "\x00\x00\x67\x90"));
211
212     YAZ_CHECK(tst_convert_l(
213                   cd,
214                   0,
215                   "\xB0\xB2",     /* AYN and oSLASH */
216                   8, 
217                   "\x00\x00\x02\xBB"  "\x00\x00\x00\xF8"));
218     YAZ_CHECK(tst_convert_l(
219                   cd,
220                   0,
221                   "\xF6\x61",     /* a underscore */
222                   8, 
223                   "\x00\x00\x00\x61"  "\x00\x00\x03\x32"));
224
225     YAZ_CHECK(tst_convert_l(
226                   cd,
227                   0,
228                   "\x61\xC2",     /* a, phonorecord mark */
229                   8,
230                   "\x00\x00\x00\x61"  "\x00\x00\x21\x17"));
231
232     /* bug #258 */
233     YAZ_CHECK(tst_convert_l(
234                   cd,
235                   0,
236                   "el" "\xe8" "am\xe8" "an", /* elaman where a is a" */
237                   32,
238                   "\x00\x00\x00" "e"
239                   "\x00\x00\x00" "l"
240                   "\x00\x00\x00" "a"
241                   "\x00\x00\x03\x08"
242                   "\x00\x00\x00" "m"
243                   "\x00\x00\x00" "a"
244                   "\x00\x00\x03\x08"
245                   "\x00\x00\x00" "n"));
246     /* bug #260 */
247     YAZ_CHECK(tst_convert_l(
248                   cd,
249                   0,
250                   "\xe5\xe8\x41",
251                   12, 
252                   "\x00\x00\x00\x41" "\x00\x00\x03\x04" "\x00\x00\x03\x08"));
253     /* bug #416 */
254     YAZ_CHECK(tst_convert_l(
255                   cd,
256                   0,
257                   "\xEB\x74\xEC\x73",
258                   12,
259                   "\x00\x00\x00\x74" "\x00\x00\x03\x61" "\x00\x00\x00\x73"));
260     /* bug #416 */
261     YAZ_CHECK(tst_convert_l(
262                   cd,
263                   0,
264                   "\xFA\x74\xFB\x73",
265                   12, 
266                   "\x00\x00\x00\x74" "\x00\x00\x03\x60" "\x00\x00\x00\x73"));
267
268     yaz_iconv_close(cd);
269 }
270
271 static void tst_ucs4b_to_utf8(void)
272 {
273     yaz_iconv_t cd = yaz_iconv_open("UTF8", "UCS4");
274     YAZ_CHECK(cd);
275     if (!cd)
276         return;
277     YAZ_CHECK(tst_convert_l(
278                   cd,
279                   8,
280                   "\x00\x00\xFF\x1F\x00\x00\x00o",
281                   4,
282                   "\xEF\xBC\x9F\x6F"));
283
284     YAZ_CHECK(tst_convert_l(
285                   cd,
286                   8, 
287                   "\x00\x00\xAE\x0E\x00\x00\xC0\xF4",
288                   6,
289                   "\xEA\xB8\x8E\xEC\x83\xB4"));
290     yaz_iconv_close(cd);
291 }
292
293 static void dconvert(int mandatory, const char *tmpcode)
294 {
295     int i;
296     int ret;
297     yaz_iconv_t cd;
298     for (i = 0; iso_8859_1_a[i]; i++)
299     {
300         size_t r;
301         char *inbuf = (char*) iso_8859_1_a[i];
302         size_t inbytesleft = strlen(inbuf);
303         char outbuf0[24];
304         char outbuf1[10];
305         char *outbuf = outbuf0;
306         size_t outbytesleft = sizeof(outbuf0);
307
308         cd = yaz_iconv_open(tmpcode, "ISO-8859-1");
309         YAZ_CHECK(cd || !mandatory);
310         if (!cd)
311             return;
312         r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
313         YAZ_CHECK(r != (size_t) (-1));
314
315         r = yaz_iconv(cd, 0, 0, &outbuf, &outbytesleft);
316         YAZ_CHECK(r != (size_t) (-1));
317         yaz_iconv_close(cd);
318         if (r == (size_t) (-1))
319             return;
320         
321         cd = yaz_iconv_open("ISO-8859-1", tmpcode);
322         YAZ_CHECK(cd || !mandatory);
323         if (!cd)
324             return;
325         inbuf = outbuf0;
326         inbytesleft = sizeof(outbuf0) - outbytesleft;
327
328         outbuf = outbuf1;
329         outbytesleft = sizeof(outbuf1);
330         r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
331         YAZ_CHECK(r != (size_t) (-1));
332
333         r = yaz_iconv(cd, 0, 0, &outbuf, &outbytesleft);
334         if (r == (size_t)(-1))
335         {
336             fprintf(stderr, "failed\n");
337         }
338         YAZ_CHECK(r != (size_t) (-1));
339
340         if (r != (size_t)(-1)) 
341         {
342             ret = compare_buffers("dconvert", i,
343                                   strlen(iso_8859_1_a[i]), iso_8859_1_a[i],
344                                   sizeof(outbuf1) - outbytesleft, outbuf1);
345             YAZ_CHECK(ret);
346         }
347         yaz_iconv_close(cd);
348     }
349 }
350
351 int utf8_check(unsigned c)
352 {
353     if (sizeof(c) >= 4)
354     {
355         size_t r;
356         char src[4];
357         char dst[4];
358         char utf8buf[6];
359         char *inbuf = src;
360         size_t inbytesleft = 4;
361         char *outbuf = utf8buf;
362         size_t outbytesleft = sizeof(utf8buf);
363         int i;
364         yaz_iconv_t cd = yaz_iconv_open("UTF-8", "UCS4LE");
365         if (!cd)
366             return 0;
367         for (i = 0; i<4; i++)
368             src[i] = c >> (i*8);
369         
370         r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
371         yaz_iconv_close(cd);
372
373         if (r == (size_t)(-1))
374             return 0;
375
376         cd = yaz_iconv_open("UCS4LE", "UTF-8");
377         if (!cd)
378             return 0;
379         inbytesleft = sizeof(utf8buf) - outbytesleft;
380         inbuf = utf8buf;
381
382         outbuf = dst;
383         outbytesleft = 4;
384
385         r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
386         if (r == (size_t)(-1))
387             return 0;
388
389         yaz_iconv_close(cd);
390
391         if (memcmp(src, dst, 4))
392             return 0;
393     }
394     return 1;
395 }
396         
397 static void tst_marc8_to_utf8(void)
398 {
399     yaz_iconv_t cd = yaz_iconv_open("UTF-8", "MARC8");
400
401     YAZ_CHECK(cd);
402     if (!cd)
403         return;
404
405     YAZ_CHECK(tst_convert(cd, "Cours de math", 
406                           "Cours de math"));
407     /* COMBINING ACUTE ACCENT */
408     YAZ_CHECK(tst_convert(cd, "Cours de mathâe", 
409                           "Cours de mathe\xcc\x81"));
410
411     YAZ_CHECK(tst_convert(cd, "\xea" "a", "a\xcc\x8a"));
412     YAZ_CHECK(tst_convert(cd, "a" "\xea" "\x1e", "a" "\x1e\xcc\x8a"));
413     YAZ_CHECK(tst_convert(cd, "a" "\xea" "p", "a" "p\xcc\x8a"));
414
415     YAZ_CHECK(tst_convert_x(cd, "a\xea", "a", YAZ_ICONV_EINVAL));
416     YAZ_CHECK(tst_convert(cd, "p", "\xcc\x8a")); /* note: missing p */
417     yaz_iconv(cd, 0, 0, 0, 0);     /* incomplete. so we have to reset */
418
419     /* bug #2115 */
420     YAZ_CHECK(tst_convert(cd, ESC "(N" ESC ")Qp" ESC "(B", "\xd0\x9f"));
421
422     YAZ_CHECK(tst_convert_x(cd, ESC , "", YAZ_ICONV_EINVAL));
423     YAZ_CHECK(tst_convert_x(cd, ESC "(", "", YAZ_ICONV_EINVAL));
424     YAZ_CHECK(tst_convert_x(cd, ESC "(B", "", 0));
425
426     YAZ_CHECK(tst_convert(cd, ESC "(B" "\x31", "1"));  /* ASCII in G0 */
427     YAZ_CHECK(tst_convert(cd, ESC ")B" "\xB1", "1"));  /* ASCII in G1 */
428
429     yaz_iconv_close(cd);
430 }
431
432 static void tst_marc8s_to_utf8(void)
433 {
434     yaz_iconv_t cd = yaz_iconv_open("UTF-8", "MARC8s");
435
436     YAZ_CHECK(cd);
437     if (!cd)
438         return;
439
440     YAZ_CHECK(tst_convert(cd, "Cours de math", 
441                           "Cours de math"));
442     /* E9: LATIN SMALL LETTER E WITH ACUTE */
443     YAZ_CHECK(tst_convert(cd, "Cours de mathâe", 
444                           "Cours de math\xc3\xa9"));
445
446     yaz_iconv_close(cd);
447 }
448
449
450 static void tst_marc8_to_latin1(void)
451 {
452     yaz_iconv_t cd = yaz_iconv_open("ISO-8859-1", "MARC8");
453
454     YAZ_CHECK(cd);
455     if (!cd)
456         return;
457
458     YAZ_CHECK(tst_convert(cd, "ax", "ax"));
459
460     /* latin capital letter o with stroke */
461     YAZ_CHECK(tst_convert(cd, "\xa2", "\xd8"));
462
463     /* with latin small letter ae */
464     YAZ_CHECK(tst_convert(cd, "eneb\xb5r", "eneb\346r"));
465
466     YAZ_CHECK(tst_convert(cd, "\xea" "a\xa2", "\xe5" "\xd8"));
467
468     YAZ_CHECK(tst_convert(cd, "\xea" "a\xa2" "b", "\xe5" "\xd8" "b"));
469
470     YAZ_CHECK(tst_convert(cd, "\xea" "a"  "\xea" "a", "\xe5" "\xe5"));
471
472     YAZ_CHECK(tst_convert(cd, "Cours de math", 
473                           "Cours de math"));
474     YAZ_CHECK(tst_convert(cd, "Cours de mathâe", 
475                           "Cours de mathé"));
476     YAZ_CHECK(tst_convert(cd, "12345678âe", 
477                           "12345678é"));
478     YAZ_CHECK(tst_convert(cd, "123456789âe", 
479                           "123456789é"));
480     YAZ_CHECK(tst_convert(cd, "1234567890âe", 
481                           "1234567890é"));
482     YAZ_CHECK(tst_convert(cd, "12345678901âe", 
483                           "12345678901é"));
484     YAZ_CHECK(tst_convert(cd, "Cours de mathâem", 
485                           "Cours de mathém"));
486     YAZ_CHECK(tst_convert(cd, "Cours de mathâematiques", 
487                           "Cours de mathématiques"));
488
489     yaz_iconv_close(cd);
490 }
491
492 static void tst_utf8_to_marc8(void)
493 {
494     yaz_iconv_t cd = yaz_iconv_open("MARC8", "UTF-8");
495
496     YAZ_CHECK(cd);
497     if (!cd)
498         return;
499
500     YAZ_CHECK(tst_convert(cd, "Cours ", "Cours "));
501
502     /** Pure ASCII. 11 characters (sizeof(outbuf)-1) */
503     YAZ_CHECK(tst_convert(cd, "Cours de mat", "Cours de mat"));
504
505     /** Pure ASCII. 12 characters (sizeof(outbuf)) */
506     YAZ_CHECK(tst_convert(cd, "Cours de math", "Cours de math"));
507
508     /** Pure ASCII. 13 characters (sizeof(outbuf)+1) */
509     YAZ_CHECK(tst_convert(cd, "Cours de math.", "Cours de math."));
510
511     /** UPPERCASE SCANDINAVIAN O */
512     YAZ_CHECK(tst_convert(cd, "S\xc3\x98", "S\xa2"));
513
514     /** ARING */
515     YAZ_CHECK(tst_convert(cd, "A" "\xCC\x8A", "\xEA" "A"));
516
517     /** A MACRON + UMLAUT, DIAERESIS */
518     YAZ_CHECK(tst_convert(cd, "A" "\xCC\x84" "\xCC\x88",
519                           "\xE5\xE8\x41"));
520     
521     /* Ligature spanning two characters */
522     YAZ_CHECK(tst_convert(cd,
523                           "\x74" "\xCD\xA1" "\x73",  /* UTF-8 */
524                           "\xEB\x74\xEC\x73"));      /* MARC-8 */
525
526     /* Double title spanning two characters */
527     YAZ_CHECK(tst_convert(cd,
528                           "\x74" "\xCD\xA0" "\x73",  /* UTF-8 */
529                           "\xFA\x74\xFB\x73"));      /* MARC-8 */
530
531     /** Ideographic question mark (Unicode FF1F) */
532     YAZ_CHECK(tst_convert(cd,
533                           "\xEF\xBC\x9F" "o",        /* UTF-8 */
534                           "\033$1" "\x21\x2B\x3B" "\033(B" "o" ));
535
536
537     /** Ideographic space per ANSI Z39.64 */
538     YAZ_CHECK(tst_convert(cd,
539                           "\xe3\x80\x80" "o",        /* UTF-8 */
540                           "\033$1" "\x21\x23\x21" "\033(B" "o" ));
541
542     /** Superscript 0 . bug #642 */
543     YAZ_CHECK(tst_convert(cd,
544                           "(\xe2\x81\xb0)",        /* UTF-8 */
545                           "(\033p0\x1bs)"));
546     
547     
548     /** bug #1778 */
549     YAZ_CHECK(tst_convert(cd,
550                           /* offset 0x530 in UTF-8 rec marccol4.u8.marc */
551                           "\xE3\x83\xB3" "\xE3\x82\xBF" 
552                           "\xCC\x84" "\xCC\x84" "\xE3\x83\xBC" /* UTF-8 */,
553                           "\x1B\x24\x31" "\x69\x25\x73"
554                           "\x1B\x28\x42" "\xE5\xE5" "\x1B\x24\x31" 
555                           "\x69\x25\x3F"
556                           "\x69\x21\x3C" "\x1B\x28\x42"));
557
558     
559     /** bug #2120 */
560     YAZ_CHECK(tst_convert(cd, 
561                           "\xCE\x94\xCE\xB5\xCF\x84"
562                           "\xCE\xBF\xCF\x81\xCE\xB1"
563                           "\xCE\xBA\xCE\xB7\xCF\x82\x2C",
564
565                           "\x1B\x28\x53\x45\x66\x78\x72\x75"
566                           "\x61\x6D\x6A\x77"
567                           "\x1B\x28\x42\x2C"
568                   ));
569  
570     {
571         char *inbuf0 = "\xe2\x81\xb0";
572         char *inbuf = inbuf0;
573         size_t inbytesleft = strlen(inbuf);
574         char outbuf0[64];
575         char *outbuf = outbuf0;
576         size_t outbytesleft = sizeof(outbuf0)-1;
577         size_t r;
578 #if 0
579         int i;
580 #endif
581         r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
582         YAZ_CHECK(r != (size_t) (-1));
583
584 #if 0
585         *outbuf = '\0';  /* so we know when to stop printing */
586         for (i = 0; outbuf0[i]; i++)
587         {
588             int ch = outbuf0[i] & 0xff;
589             yaz_log(YLOG_LOG, "ch%d %02X %c", i, ch, ch >= ' ' ? ch : '?');
590         }
591 #endif
592
593         r = yaz_iconv(cd, 0, 0, &outbuf, &outbytesleft);
594         YAZ_CHECK(r != (size_t) (-1));
595         *outbuf = '\0';  /* for strcmp test below and printing */
596 #if 0
597         for (i = 0; outbuf0[i]; i++)
598         {
599             int ch = outbuf0[i] & 0xff;
600             yaz_log(YLOG_LOG, "ch%d %02X %c", i, ch, ch >= ' ' ? ch : '?');
601         }
602 #endif
603         YAZ_CHECK(strcmp("\033p0\x1bs", outbuf0) == 0);
604     }
605     yaz_iconv_close(cd);
606 }
607
608 static void tst_advance_to_utf8(void)
609 {
610     yaz_iconv_t cd = yaz_iconv_open("utf-8", "advancegreek");
611
612     YAZ_CHECK(cd);
613     if (!cd)
614         return;
615
616     YAZ_CHECK(tst_convert(cd, "Cours ", "Cours "));
617     yaz_iconv_close(cd);
618 }
619
620 static void tst_utf8_to_advance(void)
621 {
622     yaz_iconv_t cd = yaz_iconv_open("advancegreek", "utf-8");
623
624     YAZ_CHECK(cd);
625     if (!cd)
626         return;
627
628     YAZ_CHECK(tst_convert(cd, "Cours ", "Cours "));
629     yaz_iconv_close(cd);
630 }
631
632 static void tst_latin1_to_marc8(void)
633 {
634     yaz_iconv_t cd = yaz_iconv_open("MARC8", "ISO-8859-1");
635
636     YAZ_CHECK(cd);
637     if (!cd)
638         return;
639
640     YAZ_CHECK(tst_convert(cd, "Cours ", "Cours "));
641
642     /** Pure ASCII. 11 characters (sizeof(outbuf)-1) */
643     YAZ_CHECK(tst_convert(cd, "Cours de mat", "Cours de mat"));
644
645     /** Pure ASCII. 12 characters (sizeof(outbuf)) */
646     YAZ_CHECK(tst_convert(cd, "Cours de math", "Cours de math"));
647
648     /** Pure ASCII. 13 characters (sizeof(outbuf)) */
649     YAZ_CHECK(tst_convert(cd, "Cours de math.", "Cours de math."));
650
651     /** D8: UPPERCASE SCANDINAVIAN O */
652     YAZ_CHECK(tst_convert(cd, "S\xd8", "S\xa2"));
653
654     /** E9: LATIN SMALL LETTER E WITH ACUTE */
655     YAZ_CHECK(tst_convert(cd, "Cours de math\xe9", "Cours de mathâe"));
656     YAZ_CHECK(tst_convert(cd, "Cours de math", "Cours de math"
657                   ));
658     YAZ_CHECK(tst_convert(cd, "Cours de mathé", "Cours de mathâe" ));
659     YAZ_CHECK(tst_convert(cd, "12345678é","12345678âe"));
660     YAZ_CHECK(tst_convert(cd, "123456789é", "123456789âe"));
661     YAZ_CHECK(tst_convert(cd, "1234567890é","1234567890âe"));
662     YAZ_CHECK(tst_convert(cd, "12345678901é", "12345678901âe"));
663     YAZ_CHECK(tst_convert(cd, "Cours de mathém", "Cours de mathâem"));
664     YAZ_CHECK(tst_convert(cd, "Cours de mathématiques",
665                           "Cours de mathâematiques"));
666     yaz_iconv_close(cd);
667 }
668
669 static void tst_utf8_codes(void)
670 {
671     YAZ_CHECK(utf8_check(3));
672     YAZ_CHECK(utf8_check(127));
673     YAZ_CHECK(utf8_check(128));
674     YAZ_CHECK(utf8_check(255));
675     YAZ_CHECK(utf8_check(256));
676     YAZ_CHECK(utf8_check(900));
677     YAZ_CHECK(utf8_check(1000));
678     YAZ_CHECK(utf8_check(10000));
679     YAZ_CHECK(utf8_check(100000));
680     YAZ_CHECK(utf8_check(1000000));
681     YAZ_CHECK(utf8_check(10000000));
682     YAZ_CHECK(utf8_check(100000000));
683 }
684
685 int main (int argc, char **argv)
686 {
687     YAZ_CHECK_INIT(argc, argv);
688
689     tst_utf8_codes();
690
691     tst_marc8_to_utf8();
692
693     tst_marc8s_to_utf8();
694
695     tst_marc8_to_latin1();
696
697     tst_advance_to_utf8();
698     tst_utf8_to_advance();
699
700     tst_utf8_to_marc8();
701
702     tst_latin1_to_marc8();
703
704     tst_marc8_to_ucs4b();
705     tst_ucs4b_to_utf8();
706
707     dconvert(1, "UTF-8");
708     dconvert(1, "ISO-8859-1");
709     dconvert(1, "UCS4");
710     dconvert(1, "UCS4LE");
711     dconvert(0, "CP865");
712
713     YAZ_CHECK_TERM;
714 }
715 /*
716  * Local variables:
717  * c-basic-offset: 4
718  * indent-tabs-mode: nil
719  * End:
720  * vim: shiftwidth=4 tabstop=8 expandtab
721  */