Test files for libxml2 output
[yaz-moved-to-github.git] / test / tsticonv.c
index 200c5b9..352033a 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2008 Index Data
+ * Copyright (C) 1995-2010 Index Data
  * See the file LICENSE for details.
  */
 
@@ -96,7 +96,7 @@ static int tst_convert_x(yaz_iconv_t cd, const char *buf, const char *cmpbuf,
     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;
@@ -600,6 +600,7 @@ static void tst_utf8_to_marc8(const char *marc8_type)
 #endif
         YAZ_CHECK(strcmp("\033p0\x1bs", outbuf0) == 0);
     }
+    yaz_iconv(cd, 0, 0, 0, 0);
     yaz_iconv_close(cd);
 }
 
@@ -680,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);
@@ -699,6 +721,8 @@ int main (int argc, char **argv)
     tst_utf8_to_marc8("marc8lossy");
     tst_utf8_to_marc8("marc8lossless");
 
+    tst_danmarc_to_latin1();
+
     tst_latin1_to_marc8();
 
     tst_marc8_to_ucs4b();
@@ -715,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
  */
+