X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=test%2Ftsticonv.c;h=a011c372f21cb2247110fe62fbd9f04e6e7b3487;hb=785a4eb49c2023ac55d8eac471cefcddf6d19e80;hp=6410e5734f1313fd115ea6ee5843ffcf53e0b27a;hpb=c6e47cbbff56f39f6d81b079ebaeac41d793d4d9;p=yaz-moved-to-github.git diff --git a/test/tsticonv.c b/test/tsticonv.c index 6410e57..a011c37 100644 --- a/test/tsticonv.c +++ b/test/tsticonv.c @@ -1,53 +1,86 @@ /* - * Copyright (c) 2002-2003, Index Data + * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * $Id: tsticonv.c,v 1.1 2003-10-27 12:21:38 adam Exp $ + * $Id: tsticonv.c,v 1.8 2005-02-02 23:27:05 adam Exp $ */ #if HAVE_CONFIG_H #include #endif +#include #include #include #include #include +static int compare_buffers(char *msg, int no, + int expect_len, const unsigned char *expect_buf, + int got_len, const unsigned char *got_buf) +{ + int i; + if (expect_len == got_len + && !memcmp(expect_buf, got_buf, expect_len)) + return 1; + printf("tsticonv test=%s i=%d failed\n", msg, no); + printf("off got exp\n"); + for (i = 0; i 12) + outbytesleft = 12; + r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); + if (r == (size_t) (-1)) + { + int e = yaz_iconv_error(cd); + if (e != YAZ_ICONV_E2BIG) + { + printf ("tsticonv 21 i=%d e=%d\n", i, e); + exit(21); + } + } + else + break; + } + compare_buffers("tsticonv 22", i, + expect_len, ar[i].ucs4_b, + outbuf - outbuf0, outbuf0); + } + yaz_iconv_close(cd); +} + +static void tst_ucs4b_to_utf8() +{ + static const char *ucs4_c[] = { + "\x00\x00\xFF\x1F\x00\x00\x00o", + "\x00\x00\xAE\x0E\x00\x00\xC0\xF4", + 0 + }; + static const char *utf8_c[] = { + "\xEF\xBC\x9F\x6F", + "\xEA\xB8\x8E\xEC\x83\xB4", + 0 + }; + + int i; + yaz_iconv_t cd; + + cd = yaz_iconv_open("UTF8", "UCS4"); + if (!cd) + { + printf ("tsticonv 30 yaz_iconv_open failed\n"); + exit(30); + } + for (i = 0; ucs4_c[i]; i++) + { + size_t r; + char *inbuf= (char*) ucs4_c[i]; + size_t inbytesleft = 8; + char outbuf0[24]; + char *outbuf = outbuf0; + size_t outbytesleft = sizeof(outbuf0); + + r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); + if (r == (size_t) (-1)) { - printf ("tsticonv 7 i=%d\n", i); - printf ("buf=%s out=%s\n", buf[i], outbuf0); - exit(7); + int e = yaz_iconv_error(cd); + + printf ("tsticonv 31 i=%d e=%d\n", i, e); + exit(31); } + compare_buffers("tsticonv 32", i, + strlen(utf8_c[i]), utf8_c[i], + outbuf - outbuf0, outbuf0); } yaz_iconv_close(cd); } @@ -74,10 +250,10 @@ static void dconvert(int mandatory, const char *tmpcode) { int i; yaz_iconv_t cd; - for (i = 0; buf[i]; i++) + for (i = 0; iso_8859_1_a[i]; i++) { size_t r; - char *inbuf = (char*) buf[i]; + char *inbuf = (char*) iso_8859_1_a[i]; size_t inbytesleft = strlen(inbuf); char outbuf0[24]; char outbuf1[10]; @@ -89,7 +265,7 @@ static void dconvert(int mandatory, const char *tmpcode) { if (!mandatory) return; - printf ("tsticonv 1\n"); + printf ("tsticonv code=%s 1\n", tmpcode); exit(1); } r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); @@ -97,7 +273,7 @@ static void dconvert(int mandatory, const char *tmpcode) { int e = yaz_iconv_error(cd); - printf ("tsticonv 2 e=%d\n", e); + printf ("tsticonv code=%s 2 e=%d\n", tmpcode, e); exit(2); } yaz_iconv_close(cd); @@ -107,7 +283,7 @@ static void dconvert(int mandatory, const char *tmpcode) { if (!mandatory) return; - printf ("tsticonv 3\n"); + printf ("tsticonv code=%s 3\n", tmpcode); exit(3); } inbuf = outbuf0; @@ -119,15 +295,12 @@ static void dconvert(int mandatory, const char *tmpcode) if (r == (size_t)(-1)) { int e = yaz_iconv_error(cd); - printf ("tsticonv 4 e=%d\n", e); + printf ("tsticonv code=%s 4 e=%d\n", tmpcode, e); exit(4); } - if (strlen(buf[i]) == (sizeof(outbuf1) - outbytesleft) && - memcmp(outbuf1, buf[i], strlen(buf[i]))) - { - printf ("tsticonv 5\n"); - exit(5); - } + compare_buffers("dconvert", i, + strlen(iso_8859_1_a[i]), iso_8859_1_a[i], + sizeof(outbuf1) - outbytesleft, outbuf1); yaz_iconv_close(cd); } } @@ -137,7 +310,10 @@ int main (int argc, char **argv) dconvert(1, "UTF-8"); dconvert(1, "ISO-8859-1"); dconvert(1, "UCS4"); + dconvert(1, "UCS4LE"); dconvert(0, "CP865"); - marc8_tst(); + tst_marc8_to_iso_8859_1(); + tst_marc8_to_ucs4b(); + tst_ucs4b_to_utf8(); exit (0); }