X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=test%2Ftest_iconv.c;h=76d3965afd2aeec02d14a2fc28111392e749368e;hp=27596b207c41f6841b51cb14f21c4ea31abfc2c2;hb=6ee0d7c0404834a0a59547c3bd7e2686f838ce37;hpb=fd0e844569539b1c365114ff1b82209832f14bf7 diff --git a/test/test_iconv.c b/test/test_iconv.c index 27596b2..76d3965 100644 --- a/test/test_iconv.c +++ b/test/test_iconv.c @@ -156,16 +156,6 @@ static int tst_convert(yaz_iconv_t cd, const char *buf, const char *cmpbuf) return tst_convert_x(cd, buf, cmpbuf, 0); } -/* some test strings in ISO-8859-1 format */ -static const char *iso_8859_1_a[] = { - "ax" , - "\xd8", - "eneb\346r", - "\xe5" "\xd8", - "\xe5" "\xd8" "b", - "\xe5" "\xe5", - 0 }; - static void tst_marc8_to_ucs4b(void) { yaz_iconv_t cd = yaz_iconv_open("UCS4", "MARC8"); @@ -288,6 +278,15 @@ static void tst_ucs4b_to_utf8(void) static void dconvert(int mandatory, const char *tmpcode) { + /* some test strings in ISO-8859-1 format */ + static const char *iso_8859_1_a[] = { + "ax" , + "\xd8", + "eneb\346r", + "\xe5" "\xd8", + "\xe5" "\xd8" "b", + "\xe5" "\xe5", + 0 }; int i; int ret; yaz_iconv_t cd; @@ -682,9 +681,9 @@ static void tst_utf8_codes(void) YAZ_CHECK(utf8_check(100000000)); } -static void tst_danmarc_to_latin1(void) +static void tst_danmarc_to_utf8(void) { - yaz_iconv_t cd = yaz_iconv_open("iso-8859-1", "danmarc"); + yaz_iconv_t cd = yaz_iconv_open("utf-8", "danmarc"); YAZ_CHECK(cd); if (!cd) @@ -694,14 +693,49 @@ static void tst_danmarc_to_latin1(void) 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_CHECK(tst_convert(cd, "@*", "*")); + YAZ_CHECK(tst_convert(cd, "@@", "@")); + YAZ_CHECK(tst_convert(cd, "@\xa4", "\xC2\xA4")); + YAZ_CHECK(tst_convert(cd, "\xa4", "\xC2\xA4")); + YAZ_CHECK(tst_convert(cd, "@\xe5", "\xEA\x9C\xB3")); + YAZ_CHECK(tst_convert(cd, "@\xc5.", "\xEA\x9C\xB2" ".")); + + YAZ_CHECK(tst_convert(cd, "@a733", "\xEA\x9C\xB3")); + YAZ_CHECK(tst_convert(cd, "@a732.", "\xEA\x9C\xB2" ".")); + + YAZ_CHECK(tst_convert(cd, "a@03BBb", "a\xce\xbb" "b")); /* lambda */ yaz_iconv_close(cd); } +static void tst_utf8_to_danmarc(void) +{ + yaz_iconv_t cd = yaz_iconv_open("danmarc", "utf-8"); + + 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, "*", "@*")); + YAZ_CHECK(tst_convert(cd, "@", "@@")); + YAZ_CHECK(tst_convert(cd, "\xC2\xA4", "\xa4")); + + YAZ_CHECK(tst_convert(cd, "a\xc3\xa5" "b", "a\xe5" "b")); /* aring */ + YAZ_CHECK(tst_convert(cd, "a\xce\xbb" "b", "a@03BBb")); /* lambda */ + + YAZ_CHECK(tst_convert(cd, "\xEA\x9C\xB2" ".", "@\xc5.")); + YAZ_CHECK(tst_convert(cd, "\xEA\x9C\xB3", "@\xe5")); + + yaz_iconv_close(cd); +} + + int main (int argc, char **argv) { @@ -722,7 +756,8 @@ int main (int argc, char **argv) tst_utf8_to_marc8("marc8lossy"); tst_utf8_to_marc8("marc8lossless"); - tst_danmarc_to_latin1(); + tst_danmarc_to_utf8(); + tst_utf8_to_danmarc(); tst_latin1_to_marc8();