X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=test%2Ftsticonv.c;h=352033a9e95651fe7c7f77fee1a712d613b879f2;hb=055f23ee3692349a03f681ef1a0d5fd70c0cc770;hp=f31b6d659b8f99e55cea9785a7c0d318c77c2e3d;hpb=af3fd923edc18c8ba6a0b629632e4a11ea30e8eb;p=yaz-moved-to-github.git diff --git a/test/tsticonv.c b/test/tsticonv.c index f31b6d6..352033a 100644 --- a/test/tsticonv.c +++ b/test/tsticonv.c @@ -1,8 +1,6 @@ -/* - * Copyright (C) 1995-2007, Index Data ApS +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2010 Index Data * See the file LICENSE for details. - * - * $Id: tsticonv.c,v 1.35 2008-03-12 08:53:28 adam Exp $ */ #if HAVE_CONFIG_H @@ -94,11 +92,11 @@ static int tst_convert_x(yaz_iconv_t cd, const char *buf, const char *cmpbuf, { int ret = 1; WRBUF b = wrbuf_alloc(); - char outbuf[12]; + char outbuf[16]; size_t inbytesleft = strlen(buf); const char *inp = buf; int rounds = 0; - for (rounds = 0; inbytesleft && rounds < sizeof(outbuf); rounds++) + for (rounds = 0; inbytesleft && rounds < (int) sizeof(outbuf); rounds++) { size_t outbytesleft = sizeof(outbuf); char *outp = outbuf; @@ -423,6 +421,9 @@ static void tst_marc8_to_utf8(void) YAZ_CHECK(tst_convert_x(cd, ESC "(", "", YAZ_ICONV_EINVAL)); YAZ_CHECK(tst_convert_x(cd, ESC "(B", "", 0)); + YAZ_CHECK(tst_convert(cd, ESC "(B" "\x31", "1")); /* ASCII in G0 */ + YAZ_CHECK(tst_convert(cd, ESC ")B" "\xB1", "1")); /* ASCII in G1 */ + yaz_iconv_close(cd); } @@ -486,9 +487,9 @@ static void tst_marc8_to_latin1(void) yaz_iconv_close(cd); } -static void tst_utf8_to_marc8(void) +static void tst_utf8_to_marc8(const char *marc8_type) { - yaz_iconv_t cd = yaz_iconv_open("MARC8", "UTF-8"); + yaz_iconv_t cd = yaz_iconv_open(marc8_type, "UTF-8"); YAZ_CHECK(cd); if (!cd) @@ -599,6 +600,7 @@ static void tst_utf8_to_marc8(void) #endif YAZ_CHECK(strcmp("\033p0\x1bs", outbuf0) == 0); } + yaz_iconv(cd, 0, 0, 0, 0); yaz_iconv_close(cd); } @@ -679,6 +681,27 @@ static void tst_utf8_codes(void) YAZ_CHECK(utf8_check(100000000)); } +static void tst_danmarc_to_latin1(void) +{ + yaz_iconv_t cd = yaz_iconv_open("iso-8859-1", "danmarc"); + + YAZ_CHECK(cd); + if (!cd) + return; + + YAZ_CHECK(tst_convert(cd, "ax", "ax")); + + YAZ_CHECK(tst_convert(cd, "a@@b", "a@b")); + YAZ_CHECK(tst_convert(cd, "a@@@@b", "a@@b")); + YAZ_CHECK(tst_convert(cd, "@000ab", "\nb")); + + YAZ_CHECK(tst_convert(cd, "@\xe5", "aa")); + YAZ_CHECK(tst_convert(cd, "@\xc5.", "Aa.")); + + yaz_iconv_close(cd); +} + + int main (int argc, char **argv) { YAZ_CHECK_INIT(argc, argv); @@ -694,7 +717,11 @@ int main (int argc, char **argv) tst_advance_to_utf8(); tst_utf8_to_advance(); - tst_utf8_to_marc8(); + tst_utf8_to_marc8("marc8"); + tst_utf8_to_marc8("marc8lossy"); + tst_utf8_to_marc8("marc8lossless"); + + tst_danmarc_to_latin1(); tst_latin1_to_marc8(); @@ -712,7 +739,9 @@ int main (int argc, char **argv) /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab */ +