1 /* Test of character set conversion with error handling.
2 Copyright (C) 2007-2009 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
21 #include "striconveh.h"
32 #define SIZEOF(array) (sizeof (array) / sizeof (array[0]))
33 #define ASSERT(expr) \
38 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
45 /* Magic number for detecting bounds violations. */
46 #define MAGIC 0x1983EFF1
49 new_offsets (size_t n)
51 size_t *offsets = (size_t *) malloc ((n + 1) * sizeof (size_t));
59 static enum iconv_ilseq_handler handlers[] =
60 { iconveh_error, iconveh_question_mark, iconveh_escape_sequence };
66 /* Assume that iconv() supports at least the encodings ASCII, ISO-8859-1,
67 ISO-8859-2, and UTF-8. */
68 iconv_t cd_88591_to_88592 = iconv_open ("ISO-8859-2", "ISO-8859-1");
69 iconv_t cd_88592_to_88591 = iconv_open ("ISO-8859-1", "ISO-8859-2");
70 iconv_t cd_88591_to_utf8 = iconv_open ("UTF-8", "ISO-8859-1");
71 iconv_t cd_utf8_to_88591 = iconv_open ("ISO-8859-1", "UTF-8");
72 iconv_t cd_88592_to_utf8 = iconv_open ("UTF-8", "ISO-8859-2");
73 iconv_t cd_utf8_to_88592 = iconv_open ("ISO-8859-2", "UTF-8");
74 iconv_t cd_utf7_to_utf8 = iconv_open ("UTF-8", "UTF-7");
76 ASSERT (cd_88591_to_utf8 != (iconv_t)(-1));
77 ASSERT (cd_utf8_to_88591 != (iconv_t)(-1));
78 ASSERT (cd_88592_to_utf8 != (iconv_t)(-1));
79 ASSERT (cd_utf8_to_88592 != (iconv_t)(-1));
81 /* ------------------------ Test mem_cd_iconveh() ------------------------ */
83 /* Test conversion from ISO-8859-2 to ISO-8859-1 with no errors. */
84 for (h = 0; h < SIZEOF (handlers); h++)
86 enum iconv_ilseq_handler handler = handlers[h];
87 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
88 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
89 for (o = 0; o < 2; o++)
91 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
94 int retval = mem_cd_iconveh (input, strlen (input),
96 cd_88592_to_utf8, cd_utf8_to_88591,
100 ASSERT (retval == 0);
101 ASSERT (length == strlen (expected));
102 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
105 for (i = 0; i < 37; i++)
106 ASSERT (offsets[i] == i);
107 ASSERT (offsets[37] == MAGIC);
114 /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */
115 for (h = 0; h < SIZEOF (handlers); h++)
117 enum iconv_ilseq_handler handler = handlers[h];
118 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */
119 for (o = 0; o < 2; o++)
121 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
124 int retval = mem_cd_iconveh (input, strlen (input),
126 cd_88592_to_utf8, cd_utf8_to_88591,
133 ASSERT (retval == -1 && errno == EILSEQ);
134 ASSERT (result == NULL);
138 case iconveh_question_mark:
140 static const char expected[] = "Rafa? Maszkowski";
141 ASSERT (retval == 0);
142 ASSERT (length == strlen (expected));
143 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
146 for (i = 0; i < 16; i++)
147 ASSERT (offsets[i] == i);
148 ASSERT (offsets[16] == MAGIC);
154 case iconveh_escape_sequence:
156 static const char expected[] = "Rafa\\u0142 Maszkowski";
157 ASSERT (retval == 0);
158 ASSERT (length == strlen (expected));
159 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
162 for (i = 0; i < 16; i++)
163 ASSERT (offsets[i] == (i < 5 ? i :
165 ASSERT (offsets[16] == MAGIC);
175 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */
176 for (h = 0; h < SIZEOF (handlers); h++)
178 enum iconv_ilseq_handler handler = handlers[h];
179 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
180 static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
181 for (o = 0; o < 2; o++)
183 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
186 int retval = mem_cd_iconveh (input, strlen (input),
188 cd_88591_to_utf8, (iconv_t)(-1),
192 ASSERT (retval == 0);
193 ASSERT (length == strlen (expected));
194 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
197 for (i = 0; i < 37; i++)
198 ASSERT (offsets[i] == (i < 1 ? i :
202 ASSERT (offsets[37] == MAGIC);
209 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */
210 for (h = 0; h < SIZEOF (handlers); h++)
212 enum iconv_ilseq_handler handler = handlers[h];
213 static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
214 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
215 for (o = 0; o < 2; o++)
217 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
220 int retval = mem_cd_iconveh (input, strlen (input),
222 (iconv_t)(-1), cd_utf8_to_88591,
226 ASSERT (retval == 0);
227 ASSERT (length == strlen (expected));
228 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
231 for (i = 0; i < 41; i++)
232 ASSERT (offsets[i] == (i < 1 ? i :
233 i == 1 ? (size_t)(-1) :
235 i == 13 ? (size_t)(-1) :
237 i == 20 ? (size_t)(-1) :
240 ASSERT (offsets[41] == MAGIC);
247 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
248 for (h = 0; h < SIZEOF (handlers); h++)
250 enum iconv_ilseq_handler handler = handlers[h];
251 static const char input[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */
252 for (o = 0; o < 2; o++)
254 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
257 int retval = mem_cd_iconveh (input, strlen (input),
259 (iconv_t)(-1), cd_utf8_to_88591,
266 ASSERT (retval == -1 && errno == EILSEQ);
267 ASSERT (result == NULL);
271 case iconveh_question_mark:
273 static const char expected[] = "Rafa? Maszkowski";
274 ASSERT (retval == 0);
275 ASSERT (length == strlen (expected));
276 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
279 for (i = 0; i < 17; i++)
280 ASSERT (offsets[i] == (i < 5 ? i :
281 i == 5 ? (size_t)(-1) :
283 ASSERT (offsets[17] == MAGIC);
289 case iconveh_escape_sequence:
291 static const char expected[] = "Rafa\\u0142 Maszkowski";
292 ASSERT (retval == 0);
293 ASSERT (length == strlen (expected));
294 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
297 for (i = 0; i < 17; i++)
298 ASSERT (offsets[i] == (i < 5 ? i :
299 i == 5 ? (size_t)(-1) :
301 ASSERT (offsets[17] == MAGIC);
311 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
312 for (h = 0; h < SIZEOF (handlers); h++)
314 enum iconv_ilseq_handler handler = handlers[h];
315 static const char input[] = "\342";
316 for (o = 0; o < 2; o++)
318 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
321 int retval = mem_cd_iconveh (input, strlen (input),
323 (iconv_t)(-1), cd_utf8_to_88591,
327 ASSERT (retval == 0);
328 ASSERT (length == 0);
331 ASSERT (offsets[0] == 0);
332 ASSERT (offsets[1] == MAGIC);
339 if (cd_utf7_to_utf8 != (iconv_t)(-1))
341 /* Disabled on Solaris, because Solaris 9 iconv() is buggy: it returns
342 -1 / EILSEQ when converting the 7th byte of the input "+VDLYP9hA". */
343 # if !(defined __sun && !defined _LIBICONV_VERSION)
344 /* Test conversion from UTF-7 to UTF-8 with EINVAL. */
345 for (h = 0; h < SIZEOF (handlers); h++)
347 enum iconv_ilseq_handler handler = handlers[h];
348 /* This is base64 encoded 0x54 0x32 0xD8 0x3F 0xD8 0x40. It would
349 convert to U+5432 U+D83F U+D840 but these are Unicode surrogates. */
350 static const char input[] = "+VDLYP9hA";
351 static const char expected1[] = "\345\220\262"; /* 吲 glibc */
352 static const char expected2[] = ""; /* libiconv */
355 int retval = mem_cd_iconveh (input, 7,
357 cd_utf7_to_utf8, (iconv_t)(-1),
361 ASSERT (retval == 0);
362 ASSERT (length == strlen (expected1) || length == strlen (expected2));
363 ASSERT (result != NULL);
364 if (length == strlen (expected1))
365 ASSERT (memcmp (result, expected1, strlen (expected1)) == 0);
367 ASSERT (memcmp (result, expected2, strlen (expected2)) == 0);
371 /* Test conversion from UTF-7 to UTF-8 with EILSEQ. */
372 for (h = 0; h < SIZEOF (handlers); h++)
374 enum iconv_ilseq_handler handler = handlers[h];
375 /* This is base64 encoded 0xD8 0x3F 0xD8 0x40 0xD8 0x41. It would
376 convert to U+D83F U+D840 U+D841 but these are Unicode surrogates. */
377 static const char input[] = "+2D/YQNhB";
380 int retval = mem_cd_iconveh (input, strlen (input),
382 cd_utf7_to_utf8, (iconv_t)(-1),
389 ASSERT (retval == -1 && errno == EILSEQ);
390 ASSERT (result == NULL);
392 case iconveh_question_mark:
393 case iconveh_escape_sequence:
396 static const char expected1[] = "?????";
397 /* libiconv <= 1.12 result */
398 static const char expected2[] = "?2D/YQNhB";
399 /* libiconv behaviour changed in version 1.13: the result is
400 '?' U+0FF6 U+1036; this is U+D83F U+D840 U+D841 shifted left
402 static const char expected3[] = "?\340\277\266\341\200\266";
403 ASSERT (retval == 0);
404 ASSERT (length == strlen (expected1)
405 || length == strlen (expected2)
406 || length == strlen (expected3));
407 ASSERT (result != NULL);
408 if (length == strlen (expected1))
409 ASSERT (memcmp (result, expected1, strlen (expected1)) == 0);
410 else if (length == strlen (expected2))
411 ASSERT (memcmp (result, expected2, strlen (expected2)) == 0);
413 ASSERT (memcmp (result, expected3, strlen (expected3)) == 0);
422 /* ------------------------ Test str_cd_iconveh() ------------------------ */
424 /* Test conversion from ISO-8859-2 to ISO-8859-1 with no errors. */
425 for (h = 0; h < SIZEOF (handlers); h++)
427 enum iconv_ilseq_handler handler = handlers[h];
428 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
429 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
430 char *result = str_cd_iconveh (input,
432 cd_88592_to_utf8, cd_utf8_to_88591,
434 ASSERT (result != NULL);
435 ASSERT (strcmp (result, expected) == 0);
439 /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */
440 for (h = 0; h < SIZEOF (handlers); h++)
442 enum iconv_ilseq_handler handler = handlers[h];
443 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */
444 char *result = str_cd_iconveh (input,
446 cd_88592_to_utf8, cd_utf8_to_88591,
451 ASSERT (result == NULL && errno == EILSEQ);
453 case iconveh_question_mark:
455 static const char expected[] = "Rafa? Maszkowski";
456 ASSERT (result != NULL);
457 ASSERT (strcmp (result, expected) == 0);
461 case iconveh_escape_sequence:
463 static const char expected[] = "Rafa\\u0142 Maszkowski";
464 ASSERT (result != NULL);
465 ASSERT (strcmp (result, expected) == 0);
472 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */
473 for (h = 0; h < SIZEOF (handlers); h++)
475 enum iconv_ilseq_handler handler = handlers[h];
476 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
477 static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
478 char *result = str_cd_iconveh (input,
480 cd_88591_to_utf8, (iconv_t)(-1),
482 ASSERT (result != NULL);
483 ASSERT (strcmp (result, expected) == 0);
487 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */
488 for (h = 0; h < SIZEOF (handlers); h++)
490 enum iconv_ilseq_handler handler = handlers[h];
491 static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
492 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
493 char *result = str_cd_iconveh (input,
495 (iconv_t)(-1), cd_utf8_to_88591,
497 ASSERT (result != NULL);
498 ASSERT (strcmp (result, expected) == 0);
502 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
503 for (h = 0; h < SIZEOF (handlers); h++)
505 enum iconv_ilseq_handler handler = handlers[h];
506 static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */
507 char *result = str_cd_iconveh (input,
509 (iconv_t)(-1), cd_utf8_to_88591,
514 ASSERT (result == NULL && errno == EILSEQ);
516 case iconveh_question_mark:
518 static const char expected[] = "Costs: 27 ?";
519 ASSERT (result != NULL);
520 ASSERT (strcmp (result, expected) == 0);
524 case iconveh_escape_sequence:
526 static const char expected[] = "Costs: 27 \\u20AC";
527 ASSERT (result != NULL);
528 ASSERT (strcmp (result, expected) == 0);
535 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
536 for (h = 0; h < SIZEOF (handlers); h++)
538 enum iconv_ilseq_handler handler = handlers[h];
539 static const char input[] = "\342";
540 char *result = str_cd_iconveh (input,
542 (iconv_t)(-1), cd_utf8_to_88591,
544 ASSERT (result != NULL);
545 ASSERT (strcmp (result, "") == 0);
549 if (cd_88591_to_88592 != (iconv_t)(-1))
550 iconv_close (cd_88591_to_88592);
551 if (cd_88592_to_88591 != (iconv_t)(-1))
552 iconv_close (cd_88592_to_88591);
553 iconv_close (cd_88591_to_utf8);
554 iconv_close (cd_utf8_to_88591);
555 iconv_close (cd_88592_to_utf8);
556 iconv_close (cd_utf8_to_88592);
558 /* ------------------------- Test mem_iconveh() ------------------------- */
560 /* Test conversion from ISO-8859-2 to ISO-8859-1 with no errors. */
561 for (h = 0; h < SIZEOF (handlers); h++)
563 enum iconv_ilseq_handler handler = handlers[h];
564 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
565 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
566 for (o = 0; o < 2; o++)
568 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
571 int retval = mem_iconveh (input, strlen (input),
572 "ISO-8859-2", "ISO-8859-1",
576 ASSERT (retval == 0);
577 ASSERT (length == strlen (expected));
578 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
581 for (i = 0; i < 37; i++)
582 ASSERT (offsets[i] == i);
583 ASSERT (offsets[37] == MAGIC);
590 /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */
591 for (h = 0; h < SIZEOF (handlers); h++)
593 enum iconv_ilseq_handler handler = handlers[h];
594 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */
595 for (o = 0; o < 2; o++)
597 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
600 int retval = mem_iconveh (input, strlen (input),
601 "ISO-8859-2", "ISO-8859-1",
608 ASSERT (retval == -1 && errno == EILSEQ);
609 ASSERT (result == NULL);
613 case iconveh_question_mark:
615 static const char expected[] = "Rafa? Maszkowski";
616 ASSERT (retval == 0);
617 ASSERT (length == strlen (expected));
618 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
621 for (i = 0; i < 16; i++)
622 ASSERT (offsets[i] == i);
623 ASSERT (offsets[16] == MAGIC);
629 case iconveh_escape_sequence:
631 static const char expected[] = "Rafa\\u0142 Maszkowski";
632 ASSERT (retval == 0);
633 ASSERT (length == strlen (expected));
634 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
637 for (i = 0; i < 16; i++)
638 ASSERT (offsets[i] == (i < 5 ? i :
640 ASSERT (offsets[16] == MAGIC);
650 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */
651 for (h = 0; h < SIZEOF (handlers); h++)
653 enum iconv_ilseq_handler handler = handlers[h];
654 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
655 static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
656 for (o = 0; o < 2; o++)
658 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
661 int retval = mem_iconveh (input, strlen (input),
662 "ISO-8859-1", "UTF-8",
666 ASSERT (retval == 0);
667 ASSERT (length == strlen (expected));
668 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
671 for (i = 0; i < 37; i++)
672 ASSERT (offsets[i] == (i < 1 ? i :
676 ASSERT (offsets[37] == MAGIC);
683 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */
684 for (h = 0; h < SIZEOF (handlers); h++)
686 enum iconv_ilseq_handler handler = handlers[h];
687 static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
688 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
689 for (o = 0; o < 2; o++)
691 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
694 int retval = mem_iconveh (input, strlen (input),
695 "UTF-8", "ISO-8859-1",
699 ASSERT (retval == 0);
700 ASSERT (length == strlen (expected));
701 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
704 for (i = 0; i < 41; i++)
705 ASSERT (offsets[i] == (i < 1 ? i :
706 i == 1 ? (size_t)(-1) :
708 i == 13 ? (size_t)(-1) :
710 i == 20 ? (size_t)(-1) :
713 ASSERT (offsets[41] == MAGIC);
720 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
721 for (h = 0; h < SIZEOF (handlers); h++)
723 enum iconv_ilseq_handler handler = handlers[h];
724 static const char input[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */
725 for (o = 0; o < 2; o++)
727 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
730 int retval = mem_iconveh (input, strlen (input),
731 "UTF-8", "ISO-8859-1",
738 ASSERT (retval == -1 && errno == EILSEQ);
739 ASSERT (result == NULL);
743 case iconveh_question_mark:
745 static const char expected[] = "Rafa? Maszkowski";
746 ASSERT (retval == 0);
747 ASSERT (length == strlen (expected));
748 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
751 for (i = 0; i < 17; i++)
752 ASSERT (offsets[i] == (i < 5 ? i :
753 i == 5 ? (size_t)(-1) :
755 ASSERT (offsets[17] == MAGIC);
761 case iconveh_escape_sequence:
763 static const char expected[] = "Rafa\\u0142 Maszkowski";
764 ASSERT (retval == 0);
765 ASSERT (length == strlen (expected));
766 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
769 for (i = 0; i < 17; i++)
770 ASSERT (offsets[i] == (i < 5 ? i :
771 i == 5 ? (size_t)(-1) :
773 ASSERT (offsets[17] == MAGIC);
783 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
784 for (h = 0; h < SIZEOF (handlers); h++)
786 enum iconv_ilseq_handler handler = handlers[h];
787 static const char input[] = "\342";
788 for (o = 0; o < 2; o++)
790 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
793 int retval = mem_iconveh (input, strlen (input),
794 "UTF-8", "ISO-8859-1",
798 ASSERT (retval == 0);
799 ASSERT (length == 0);
802 ASSERT (offsets[0] == 0);
803 ASSERT (offsets[1] == MAGIC);
810 /* ------------------------- Test str_iconveh() ------------------------- */
812 /* Test conversion from ISO-8859-2 to ISO-8859-1 with no errors. */
813 for (h = 0; h < SIZEOF (handlers); h++)
815 enum iconv_ilseq_handler handler = handlers[h];
816 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
817 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
818 char *result = str_iconveh (input, "ISO-8859-2", "ISO-8859-1", handler);
819 ASSERT (result != NULL);
820 ASSERT (strcmp (result, expected) == 0);
824 /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */
825 for (h = 0; h < SIZEOF (handlers); h++)
827 enum iconv_ilseq_handler handler = handlers[h];
828 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */
829 char *result = str_iconveh (input, "ISO-8859-2", "ISO-8859-1", handler);
833 ASSERT (result == NULL && errno == EILSEQ);
835 case iconveh_question_mark:
837 static const char expected[] = "Rafa? Maszkowski";
838 ASSERT (result != NULL);
839 ASSERT (strcmp (result, expected) == 0);
843 case iconveh_escape_sequence:
845 static const char expected[] = "Rafa\\u0142 Maszkowski";
846 ASSERT (result != NULL);
847 ASSERT (strcmp (result, expected) == 0);
854 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */
855 for (h = 0; h < SIZEOF (handlers); h++)
857 enum iconv_ilseq_handler handler = handlers[h];
858 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
859 static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
860 char *result = str_iconveh (input, "ISO-8859-1", "UTF-8", handler);
861 ASSERT (result != NULL);
862 ASSERT (strcmp (result, expected) == 0);
866 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */
867 for (h = 0; h < SIZEOF (handlers); h++)
869 enum iconv_ilseq_handler handler = handlers[h];
870 static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
871 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
872 char *result = str_iconveh (input, "UTF-8", "ISO-8859-1", handler);
873 ASSERT (result != NULL);
874 ASSERT (strcmp (result, expected) == 0);
878 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
879 for (h = 0; h < SIZEOF (handlers); h++)
881 enum iconv_ilseq_handler handler = handlers[h];
882 static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */
883 char *result = str_iconveh (input, "UTF-8", "ISO-8859-1", handler);
887 ASSERT (result == NULL && errno == EILSEQ);
889 case iconveh_question_mark:
891 static const char expected[] = "Costs: 27 ?";
892 ASSERT (result != NULL);
893 ASSERT (strcmp (result, expected) == 0);
897 case iconveh_escape_sequence:
899 static const char expected[] = "Costs: 27 \\u20AC";
900 ASSERT (result != NULL);
901 ASSERT (strcmp (result, expected) == 0);
908 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
909 for (h = 0; h < SIZEOF (handlers); h++)
911 enum iconv_ilseq_handler handler = handlers[h];
912 static const char input[] = "\342";
913 char *result = str_iconveh (input, "UTF-8", "ISO-8859-1", handler);
914 ASSERT (result != NULL);
915 ASSERT (strcmp (result, "") == 0);