1 /* Test of character set conversion with error handling.
2 Copyright (C) 2007-2008 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:
395 static const char expected1[] = "?????"; /* glibc */
396 static const char expected2[] = "?2D/YQNhB"; /* libiconv */
397 ASSERT (retval == 0);
398 ASSERT (length == strlen (expected1) || length == strlen (expected2));
399 ASSERT (result != NULL);
400 if (length == strlen (expected1))
401 ASSERT (memcmp (result, expected1, strlen (expected1)) == 0);
403 ASSERT (memcmp (result, expected2, strlen (expected2)) == 0);
412 /* ------------------------ Test str_cd_iconveh() ------------------------ */
414 /* Test conversion from ISO-8859-2 to ISO-8859-1 with no errors. */
415 for (h = 0; h < SIZEOF (handlers); h++)
417 enum iconv_ilseq_handler handler = handlers[h];
418 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
419 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
420 char *result = str_cd_iconveh (input,
422 cd_88592_to_utf8, cd_utf8_to_88591,
424 ASSERT (result != NULL);
425 ASSERT (strcmp (result, expected) == 0);
429 /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */
430 for (h = 0; h < SIZEOF (handlers); h++)
432 enum iconv_ilseq_handler handler = handlers[h];
433 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */
434 char *result = str_cd_iconveh (input,
436 cd_88592_to_utf8, cd_utf8_to_88591,
441 ASSERT (result == NULL && errno == EILSEQ);
443 case iconveh_question_mark:
445 static const char expected[] = "Rafa? Maszkowski";
446 ASSERT (result != NULL);
447 ASSERT (strcmp (result, expected) == 0);
451 case iconveh_escape_sequence:
453 static const char expected[] = "Rafa\\u0142 Maszkowski";
454 ASSERT (result != NULL);
455 ASSERT (strcmp (result, expected) == 0);
462 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */
463 for (h = 0; h < SIZEOF (handlers); h++)
465 enum iconv_ilseq_handler handler = handlers[h];
466 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
467 static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
468 char *result = str_cd_iconveh (input,
470 cd_88591_to_utf8, (iconv_t)(-1),
472 ASSERT (result != NULL);
473 ASSERT (strcmp (result, expected) == 0);
477 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */
478 for (h = 0; h < SIZEOF (handlers); h++)
480 enum iconv_ilseq_handler handler = handlers[h];
481 static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
482 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
483 char *result = str_cd_iconveh (input,
485 (iconv_t)(-1), cd_utf8_to_88591,
487 ASSERT (result != NULL);
488 ASSERT (strcmp (result, expected) == 0);
492 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
493 for (h = 0; h < SIZEOF (handlers); h++)
495 enum iconv_ilseq_handler handler = handlers[h];
496 static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */
497 char *result = str_cd_iconveh (input,
499 (iconv_t)(-1), cd_utf8_to_88591,
504 ASSERT (result == NULL && errno == EILSEQ);
506 case iconveh_question_mark:
508 static const char expected[] = "Costs: 27 ?";
509 ASSERT (result != NULL);
510 ASSERT (strcmp (result, expected) == 0);
514 case iconveh_escape_sequence:
516 static const char expected[] = "Costs: 27 \\u20AC";
517 ASSERT (result != NULL);
518 ASSERT (strcmp (result, expected) == 0);
525 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
526 for (h = 0; h < SIZEOF (handlers); h++)
528 enum iconv_ilseq_handler handler = handlers[h];
529 static const char input[] = "\342";
530 char *result = str_cd_iconveh (input,
532 (iconv_t)(-1), cd_utf8_to_88591,
534 ASSERT (result != NULL);
535 ASSERT (strcmp (result, "") == 0);
539 if (cd_88591_to_88592 != (iconv_t)(-1))
540 iconv_close (cd_88591_to_88592);
541 if (cd_88592_to_88591 != (iconv_t)(-1))
542 iconv_close (cd_88592_to_88591);
543 iconv_close (cd_88591_to_utf8);
544 iconv_close (cd_utf8_to_88591);
545 iconv_close (cd_88592_to_utf8);
546 iconv_close (cd_utf8_to_88592);
548 /* ------------------------- Test mem_iconveh() ------------------------- */
550 /* Test conversion from ISO-8859-2 to ISO-8859-1 with no errors. */
551 for (h = 0; h < SIZEOF (handlers); h++)
553 enum iconv_ilseq_handler handler = handlers[h];
554 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
555 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
556 for (o = 0; o < 2; o++)
558 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
561 int retval = mem_iconveh (input, strlen (input),
562 "ISO-8859-2", "ISO-8859-1",
566 ASSERT (retval == 0);
567 ASSERT (length == strlen (expected));
568 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
571 for (i = 0; i < 37; i++)
572 ASSERT (offsets[i] == i);
573 ASSERT (offsets[37] == MAGIC);
580 /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */
581 for (h = 0; h < SIZEOF (handlers); h++)
583 enum iconv_ilseq_handler handler = handlers[h];
584 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */
585 for (o = 0; o < 2; o++)
587 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
590 int retval = mem_iconveh (input, strlen (input),
591 "ISO-8859-2", "ISO-8859-1",
598 ASSERT (retval == -1 && errno == EILSEQ);
599 ASSERT (result == NULL);
603 case iconveh_question_mark:
605 static const char expected[] = "Rafa? Maszkowski";
606 ASSERT (retval == 0);
607 ASSERT (length == strlen (expected));
608 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
611 for (i = 0; i < 16; i++)
612 ASSERT (offsets[i] == i);
613 ASSERT (offsets[16] == MAGIC);
619 case iconveh_escape_sequence:
621 static const char expected[] = "Rafa\\u0142 Maszkowski";
622 ASSERT (retval == 0);
623 ASSERT (length == strlen (expected));
624 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
627 for (i = 0; i < 16; i++)
628 ASSERT (offsets[i] == (i < 5 ? i :
630 ASSERT (offsets[16] == MAGIC);
640 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */
641 for (h = 0; h < SIZEOF (handlers); h++)
643 enum iconv_ilseq_handler handler = handlers[h];
644 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
645 static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
646 for (o = 0; o < 2; o++)
648 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
651 int retval = mem_iconveh (input, strlen (input),
652 "ISO-8859-1", "UTF-8",
656 ASSERT (retval == 0);
657 ASSERT (length == strlen (expected));
658 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
661 for (i = 0; i < 37; i++)
662 ASSERT (offsets[i] == (i < 1 ? i :
666 ASSERT (offsets[37] == MAGIC);
673 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */
674 for (h = 0; h < SIZEOF (handlers); h++)
676 enum iconv_ilseq_handler handler = handlers[h];
677 static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
678 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
679 for (o = 0; o < 2; o++)
681 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
684 int retval = mem_iconveh (input, strlen (input),
685 "UTF-8", "ISO-8859-1",
689 ASSERT (retval == 0);
690 ASSERT (length == strlen (expected));
691 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
694 for (i = 0; i < 41; i++)
695 ASSERT (offsets[i] == (i < 1 ? i :
696 i == 1 ? (size_t)(-1) :
698 i == 13 ? (size_t)(-1) :
700 i == 20 ? (size_t)(-1) :
703 ASSERT (offsets[41] == MAGIC);
710 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
711 for (h = 0; h < SIZEOF (handlers); h++)
713 enum iconv_ilseq_handler handler = handlers[h];
714 static const char input[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */
715 for (o = 0; o < 2; o++)
717 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
720 int retval = mem_iconveh (input, strlen (input),
721 "UTF-8", "ISO-8859-1",
728 ASSERT (retval == -1 && errno == EILSEQ);
729 ASSERT (result == NULL);
733 case iconveh_question_mark:
735 static const char expected[] = "Rafa? Maszkowski";
736 ASSERT (retval == 0);
737 ASSERT (length == strlen (expected));
738 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
741 for (i = 0; i < 17; i++)
742 ASSERT (offsets[i] == (i < 5 ? i :
743 i == 5 ? (size_t)(-1) :
745 ASSERT (offsets[17] == MAGIC);
751 case iconveh_escape_sequence:
753 static const char expected[] = "Rafa\\u0142 Maszkowski";
754 ASSERT (retval == 0);
755 ASSERT (length == strlen (expected));
756 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
759 for (i = 0; i < 17; i++)
760 ASSERT (offsets[i] == (i < 5 ? i :
761 i == 5 ? (size_t)(-1) :
763 ASSERT (offsets[17] == MAGIC);
773 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
774 for (h = 0; h < SIZEOF (handlers); h++)
776 enum iconv_ilseq_handler handler = handlers[h];
777 static const char input[] = "\342";
778 for (o = 0; o < 2; o++)
780 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
783 int retval = mem_iconveh (input, strlen (input),
784 "UTF-8", "ISO-8859-1",
788 ASSERT (retval == 0);
789 ASSERT (length == 0);
792 ASSERT (offsets[0] == 0);
793 ASSERT (offsets[1] == MAGIC);
800 /* ------------------------- Test str_iconveh() ------------------------- */
802 /* Test conversion from ISO-8859-2 to ISO-8859-1 with no errors. */
803 for (h = 0; h < SIZEOF (handlers); h++)
805 enum iconv_ilseq_handler handler = handlers[h];
806 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
807 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
808 char *result = str_iconveh (input, "ISO-8859-2", "ISO-8859-1", handler);
809 ASSERT (result != NULL);
810 ASSERT (strcmp (result, expected) == 0);
814 /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */
815 for (h = 0; h < SIZEOF (handlers); h++)
817 enum iconv_ilseq_handler handler = handlers[h];
818 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */
819 char *result = str_iconveh (input, "ISO-8859-2", "ISO-8859-1", handler);
823 ASSERT (result == NULL && errno == EILSEQ);
825 case iconveh_question_mark:
827 static const char expected[] = "Rafa? Maszkowski";
828 ASSERT (result != NULL);
829 ASSERT (strcmp (result, expected) == 0);
833 case iconveh_escape_sequence:
835 static const char expected[] = "Rafa\\u0142 Maszkowski";
836 ASSERT (result != NULL);
837 ASSERT (strcmp (result, expected) == 0);
844 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */
845 for (h = 0; h < SIZEOF (handlers); h++)
847 enum iconv_ilseq_handler handler = handlers[h];
848 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
849 static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
850 char *result = str_iconveh (input, "ISO-8859-1", "UTF-8", handler);
851 ASSERT (result != NULL);
852 ASSERT (strcmp (result, expected) == 0);
856 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */
857 for (h = 0; h < SIZEOF (handlers); h++)
859 enum iconv_ilseq_handler handler = handlers[h];
860 static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
861 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
862 char *result = str_iconveh (input, "UTF-8", "ISO-8859-1", handler);
863 ASSERT (result != NULL);
864 ASSERT (strcmp (result, expected) == 0);
868 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
869 for (h = 0; h < SIZEOF (handlers); h++)
871 enum iconv_ilseq_handler handler = handlers[h];
872 static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */
873 char *result = str_iconveh (input, "UTF-8", "ISO-8859-1", handler);
877 ASSERT (result == NULL && errno == EILSEQ);
879 case iconveh_question_mark:
881 static const char expected[] = "Costs: 27 ?";
882 ASSERT (result != NULL);
883 ASSERT (strcmp (result, expected) == 0);
887 case iconveh_escape_sequence:
889 static const char expected[] = "Costs: 27 \\u20AC";
890 ASSERT (result != NULL);
891 ASSERT (strcmp (result, expected) == 0);
898 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
899 for (h = 0; h < SIZEOF (handlers); h++)
901 enum iconv_ilseq_handler handler = handlers[h];
902 static const char input[] = "\342";
903 char *result = str_iconveh (input, "UTF-8", "ISO-8859-1", handler);
904 ASSERT (result != NULL);
905 ASSERT (strcmp (result, "") == 0);