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