From: Adam Dickmeiss Date: Tue, 1 Feb 2005 21:07:19 +0000 (+0000) Subject: Better diagnostics for iconv test. Added case for bug #258 X-Git-Tag: YAZ.2.0.34~23 X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=commitdiff_plain;h=273ad9b2ed17eaf4daa43e321ad4b96be2b92518 Better diagnostics for iconv test. Added case for bug #258 --- diff --git a/test/tsticonv.c b/test/tsticonv.c index 7a27f10..a3fbda1 100644 --- a/test/tsticonv.c +++ b/test/tsticonv.c @@ -2,19 +2,53 @@ * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * $Id: tsticonv.c,v 1.5 2005-01-15 19:47:15 adam Exp $ + * $Id: tsticonv.c,v 1.6 2005-02-01 21:07:19 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 marc8_tst_c() +static void tst_ucs4b_to_utf8() { static const char *ucs4_c[] = { "\x00\x00\xFF\x1F\x00\x00\x00o", @@ -171,7 +219,6 @@ static void marc8_tst_c() for (i = 0; ucs4_c[i]; i++) { size_t r; - size_t len; char *inbuf= (char*) ucs4_c[i]; size_t inbytesleft = 8; char outbuf0[24]; @@ -186,13 +233,9 @@ static void marc8_tst_c() printf ("tsticonv 31 i=%d e=%d\n", i, e); exit(31); } - len = outbuf - outbuf0; - if (len != strlen(utf8_c[i]) || memcmp(outbuf0, utf8_c[i], len)) - { - printf ("tsticonv 32 len=%d gotlen=%d i=%d\n", - strlen(utf8_c[i]), len, i); - exit(32); - } + compare_buffers("tsticonv 32", i, + strlen(utf8_c[i]), utf8_c[i], + outbuf - outbuf0, outbuf0); } yaz_iconv_close(cd); } @@ -249,14 +292,9 @@ static void dconvert(int mandatory, const char *tmpcode) printf ("tsticonv code=%s 4 e=%d\n", tmpcode, e); exit(4); } - if (strlen(iso_8859_1_a[i]) == - (sizeof(outbuf1) - outbytesleft) && - memcmp(outbuf1, iso_8859_1_a[i], - strlen(iso_8859_1_a[i]))) - { - printf ("tsticonv code=%s 5\n", tmpcode); - 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); } } @@ -268,8 +306,8 @@ int main (int argc, char **argv) dconvert(1, "UCS4"); dconvert(1, "UCS4LE"); dconvert(0, "CP865"); - marc8_tst_a(); - marc8_tst_b(); - marc8_tst_c(); + tst_marc8_to_iso_8859_1(); + tst_marc8_to_ucs4b(); + tst_ucs4b_to_utf8(); exit (0); }