- int ret = 0;
- WRBUF b = wrbuf_alloc();
- char outbuf[12];
- size_t inbytesleft = strlen(buf);
- const char *inp = buf;
- while (inbytesleft)
- {
- size_t outbytesleft = sizeof(outbuf);
- char *outp = outbuf;
- size_t r = yaz_iconv(cd, (char**) &inp, &inbytesleft,
- &outp, &outbytesleft);
- if (r == (size_t) (-1))
- {
- int e = yaz_iconv_error(cd);
- if (e != YAZ_ICONV_E2BIG)
- break;
- }
- wrbuf_write(b, outbuf, outp - outbuf);
- }
- if (wrbuf_len(b) == strlen(cmpbuf)
- && !memcmp(cmpbuf, wrbuf_buf(b), wrbuf_len(b)))
- ret = 1;
- else
- yaz_log(YLOG_LOG, "GOT (%.*s)", wrbuf_len(b), wrbuf_buf(b));
- wrbuf_free(b, 1);
- return ret;
+ yaz_iconv_t cd = yaz_iconv_open("UTF-8", "MARC8");
+
+ YAZ_CHECK(cd);
+ if (!cd)
+ return;
+
+ YAZ_CHECK(tst_convert(cd, "Cours de math",
+ "Cours de math"));
+ /* COMBINING ACUTE ACCENT */
+ YAZ_CHECK(tst_convert(cd, "Cours de mathâe",
+ "Cours de mathe\xcc\x81"));
+
+ YAZ_CHECK(tst_convert(cd, "\xea" "a", "a\xcc\x8a"));
+ YAZ_CHECK(tst_convert(cd, "a" "\xea" "\x1e", "a" "\x1e\xcc\x8a"));
+ YAZ_CHECK(tst_convert(cd, "a" "\xea" "p", "a" "p\xcc\x8a"));
+
+ YAZ_CHECK(tst_convert_x(cd, "a\xea", "a", YAZ_ICONV_EINVAL));
+ YAZ_CHECK(tst_convert(cd, "p", "\xcc\x8a")); /* note: missing p */
+ yaz_iconv(cd, 0, 0, 0, 0); /* incomplete. so we have to reset */
+
+ /* bug #2115 */
+ YAZ_CHECK(tst_convert(cd, ESC "(N" ESC ")Qp" ESC "(B", "\xd0\x9f"));
+
+ YAZ_CHECK(tst_convert_x(cd, ESC , "", YAZ_ICONV_EINVAL));
+ 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);
+}
+
+static void tst_marc8s_to_utf8(void)
+{
+ yaz_iconv_t cd = yaz_iconv_open("UTF-8", "MARC8s");
+
+ YAZ_CHECK(cd);
+ if (!cd)
+ return;
+
+ YAZ_CHECK(tst_convert(cd, "Cours de math",
+ "Cours de math"));
+ /* E9: LATIN SMALL LETTER E WITH ACUTE */
+ YAZ_CHECK(tst_convert(cd, "Cours de mathâe",
+ "Cours de math\xc3\xa9"));
+
+ yaz_iconv_close(cd);