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");
75 iconveh_t cdeh_88592_to_88591;
76 iconveh_t cdeh_88591_to_utf8;
77 iconveh_t cdeh_utf8_to_88591;
78 iconveh_t cdeh_utf7_to_utf8;
80 ASSERT (cd_88591_to_utf8 != (iconv_t)(-1));
81 ASSERT (cd_utf8_to_88591 != (iconv_t)(-1));
82 ASSERT (cd_88592_to_utf8 != (iconv_t)(-1));
83 ASSERT (cd_utf8_to_88592 != (iconv_t)(-1));
85 cdeh_88592_to_88591.cd = cd_88592_to_88591;
86 cdeh_88592_to_88591.cd1 = cd_88592_to_utf8;
87 cdeh_88592_to_88591.cd2 = cd_utf8_to_88591;
89 cdeh_88591_to_utf8.cd = cd_88591_to_utf8;
90 cdeh_88591_to_utf8.cd1 = cd_88591_to_utf8;
91 cdeh_88591_to_utf8.cd2 = (iconv_t)(-1);
93 cdeh_utf8_to_88591.cd = cd_utf8_to_88591;
94 cdeh_utf8_to_88591.cd1 = (iconv_t)(-1);
95 cdeh_utf8_to_88591.cd2 = cd_utf8_to_88591;
97 cdeh_utf7_to_utf8.cd = cd_utf7_to_utf8;
98 cdeh_utf7_to_utf8.cd1 = cd_utf7_to_utf8;
99 cdeh_utf7_to_utf8.cd2 = (iconv_t)(-1);
101 /* ------------------------ Test mem_cd_iconveh() ------------------------ */
103 /* Test conversion from ISO-8859-2 to ISO-8859-1 with no errors. */
104 for (h = 0; h < SIZEOF (handlers); h++)
106 enum iconv_ilseq_handler handler = handlers[h];
107 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
108 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
109 for (o = 0; o < 2; o++)
111 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
114 int retval = mem_cd_iconveh (input, strlen (input),
115 &cdeh_88592_to_88591,
119 ASSERT (retval == 0);
120 ASSERT (length == strlen (expected));
121 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
124 for (i = 0; i < 37; i++)
125 ASSERT (offsets[i] == i);
126 ASSERT (offsets[37] == MAGIC);
133 /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */
134 for (h = 0; h < SIZEOF (handlers); h++)
136 enum iconv_ilseq_handler handler = handlers[h];
137 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */
138 for (o = 0; o < 2; o++)
140 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
143 int retval = mem_cd_iconveh (input, strlen (input),
144 &cdeh_88592_to_88591,
151 ASSERT (retval == -1 && errno == EILSEQ);
152 ASSERT (result == NULL);
156 case iconveh_question_mark:
158 static const char expected[] = "Rafa? Maszkowski";
159 ASSERT (retval == 0);
160 ASSERT (length == strlen (expected));
161 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
164 for (i = 0; i < 16; i++)
165 ASSERT (offsets[i] == i);
166 ASSERT (offsets[16] == MAGIC);
172 case iconveh_escape_sequence:
174 static const char expected[] = "Rafa\\u0142 Maszkowski";
175 ASSERT (retval == 0);
176 ASSERT (length == strlen (expected));
177 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
180 for (i = 0; i < 16; i++)
181 ASSERT (offsets[i] == (i < 5 ? i :
183 ASSERT (offsets[16] == MAGIC);
193 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */
194 for (h = 0; h < SIZEOF (handlers); h++)
196 enum iconv_ilseq_handler handler = handlers[h];
197 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
198 static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
199 for (o = 0; o < 2; o++)
201 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
204 int retval = mem_cd_iconveh (input, strlen (input),
209 ASSERT (retval == 0);
210 ASSERT (length == strlen (expected));
211 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
214 for (i = 0; i < 37; i++)
215 ASSERT (offsets[i] == (i < 1 ? i :
219 ASSERT (offsets[37] == MAGIC);
226 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */
227 for (h = 0; h < SIZEOF (handlers); h++)
229 enum iconv_ilseq_handler handler = handlers[h];
230 static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
231 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
232 for (o = 0; o < 2; o++)
234 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
237 int retval = mem_cd_iconveh (input, strlen (input),
242 ASSERT (retval == 0);
243 ASSERT (length == strlen (expected));
244 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
247 for (i = 0; i < 41; i++)
248 ASSERT (offsets[i] == (i < 1 ? i :
249 i == 1 ? (size_t)(-1) :
251 i == 13 ? (size_t)(-1) :
253 i == 20 ? (size_t)(-1) :
256 ASSERT (offsets[41] == MAGIC);
263 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
264 for (h = 0; h < SIZEOF (handlers); h++)
266 enum iconv_ilseq_handler handler = handlers[h];
267 static const char input[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */
268 for (o = 0; o < 2; o++)
270 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
273 int retval = mem_cd_iconveh (input, strlen (input),
281 ASSERT (retval == -1 && errno == EILSEQ);
282 ASSERT (result == NULL);
286 case iconveh_question_mark:
288 static const char expected[] = "Rafa? Maszkowski";
289 ASSERT (retval == 0);
290 ASSERT (length == strlen (expected));
291 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
294 for (i = 0; i < 17; i++)
295 ASSERT (offsets[i] == (i < 5 ? i :
296 i == 5 ? (size_t)(-1) :
298 ASSERT (offsets[17] == MAGIC);
304 case iconveh_escape_sequence:
306 static const char expected[] = "Rafa\\u0142 Maszkowski";
307 ASSERT (retval == 0);
308 ASSERT (length == strlen (expected));
309 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
312 for (i = 0; i < 17; i++)
313 ASSERT (offsets[i] == (i < 5 ? i :
314 i == 5 ? (size_t)(-1) :
316 ASSERT (offsets[17] == MAGIC);
326 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
327 for (h = 0; h < SIZEOF (handlers); h++)
329 enum iconv_ilseq_handler handler = handlers[h];
330 static const char input[] = "\342";
331 for (o = 0; o < 2; o++)
333 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
336 int retval = mem_cd_iconveh (input, strlen (input),
341 ASSERT (retval == 0);
342 ASSERT (length == 0);
345 ASSERT (offsets[0] == 0);
346 ASSERT (offsets[1] == MAGIC);
353 if (cd_utf7_to_utf8 != (iconv_t)(-1))
355 /* Disabled on Solaris, because Solaris 9 iconv() is buggy: it returns
356 -1 / EILSEQ when converting the 7th byte of the input "+VDLYP9hA". */
357 # if !(defined __sun && !defined _LIBICONV_VERSION)
358 /* Test conversion from UTF-7 to UTF-8 with EINVAL. */
359 for (h = 0; h < SIZEOF (handlers); h++)
361 enum iconv_ilseq_handler handler = handlers[h];
362 /* This is base64 encoded 0x54 0x32 0xD8 0x3F 0xD8 0x40. It would
363 convert to U+5432 U+D83F U+D840 but these are Unicode surrogates. */
364 static const char input[] = "+VDLYP9hA";
365 static const char expected1[] = "\345\220\262"; /* 吲 glibc */
366 static const char expected2[] = ""; /* libiconv */
369 int retval = mem_cd_iconveh (input, 7,
374 ASSERT (retval == 0);
375 ASSERT (length == strlen (expected1) || length == strlen (expected2));
376 ASSERT (result != NULL);
377 if (length == strlen (expected1))
378 ASSERT (memcmp (result, expected1, strlen (expected1)) == 0);
380 ASSERT (memcmp (result, expected2, strlen (expected2)) == 0);
384 /* Test conversion from UTF-7 to UTF-8 with EILSEQ. */
385 for (h = 0; h < SIZEOF (handlers); h++)
387 enum iconv_ilseq_handler handler = handlers[h];
388 /* This is base64 encoded 0xD8 0x3F 0xD8 0x40 0xD8 0x41. It would
389 convert to U+D83F U+D840 U+D841 but these are Unicode surrogates. */
390 static const char input[] = "+2D/YQNhB";
393 int retval = mem_cd_iconveh (input, strlen (input),
401 ASSERT (retval == -1 && errno == EILSEQ);
402 ASSERT (result == NULL);
404 case iconveh_question_mark:
405 case iconveh_escape_sequence:
408 static const char expected1[] = "?????";
409 /* libiconv <= 1.12 result */
410 static const char expected2[] = "?2D/YQNhB";
411 /* libiconv behaviour changed in version 1.13: the result is
412 '?' U+0FF6 U+1036; this is U+D83F U+D840 U+D841 shifted left
414 static const char expected3[] = "?\340\277\266\341\200\266";
415 ASSERT (retval == 0);
416 ASSERT (length == strlen (expected1)
417 || length == strlen (expected2)
418 || length == strlen (expected3));
419 ASSERT (result != NULL);
420 if (length == strlen (expected1))
421 ASSERT (memcmp (result, expected1, strlen (expected1)) == 0);
422 else if (length == strlen (expected2))
423 ASSERT (memcmp (result, expected2, strlen (expected2)) == 0);
425 ASSERT (memcmp (result, expected3, strlen (expected3)) == 0);
434 /* ------------------------ Test str_cd_iconveh() ------------------------ */
436 /* Test conversion from ISO-8859-2 to ISO-8859-1 with no errors. */
437 for (h = 0; h < SIZEOF (handlers); h++)
439 enum iconv_ilseq_handler handler = handlers[h];
440 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
441 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
442 char *result = str_cd_iconveh (input,
443 &cdeh_88592_to_88591,
445 ASSERT (result != NULL);
446 ASSERT (strcmp (result, expected) == 0);
450 /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */
451 for (h = 0; h < SIZEOF (handlers); h++)
453 enum iconv_ilseq_handler handler = handlers[h];
454 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */
455 char *result = str_cd_iconveh (input,
456 &cdeh_88592_to_88591,
461 ASSERT (result == NULL && errno == EILSEQ);
463 case iconveh_question_mark:
465 static const char expected[] = "Rafa? Maszkowski";
466 ASSERT (result != NULL);
467 ASSERT (strcmp (result, expected) == 0);
471 case iconveh_escape_sequence:
473 static const char expected[] = "Rafa\\u0142 Maszkowski";
474 ASSERT (result != NULL);
475 ASSERT (strcmp (result, expected) == 0);
482 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */
483 for (h = 0; h < SIZEOF (handlers); h++)
485 enum iconv_ilseq_handler handler = handlers[h];
486 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
487 static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
488 char *result = str_cd_iconveh (input,
491 ASSERT (result != NULL);
492 ASSERT (strcmp (result, expected) == 0);
496 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */
497 for (h = 0; h < SIZEOF (handlers); h++)
499 enum iconv_ilseq_handler handler = handlers[h];
500 static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
501 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
502 char *result = str_cd_iconveh (input,
505 ASSERT (result != NULL);
506 ASSERT (strcmp (result, expected) == 0);
510 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
511 for (h = 0; h < SIZEOF (handlers); h++)
513 enum iconv_ilseq_handler handler = handlers[h];
514 static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */
515 char *result = str_cd_iconveh (input,
521 ASSERT (result == NULL && errno == EILSEQ);
523 case iconveh_question_mark:
525 static const char expected[] = "Costs: 27 ?";
526 ASSERT (result != NULL);
527 ASSERT (strcmp (result, expected) == 0);
531 case iconveh_escape_sequence:
533 static const char expected[] = "Costs: 27 \\u20AC";
534 ASSERT (result != NULL);
535 ASSERT (strcmp (result, expected) == 0);
542 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
543 for (h = 0; h < SIZEOF (handlers); h++)
545 enum iconv_ilseq_handler handler = handlers[h];
546 static const char input[] = "\342";
547 char *result = str_cd_iconveh (input,
550 ASSERT (result != NULL);
551 ASSERT (strcmp (result, "") == 0);
555 if (cd_88591_to_88592 != (iconv_t)(-1))
556 iconv_close (cd_88591_to_88592);
557 if (cd_88592_to_88591 != (iconv_t)(-1))
558 iconv_close (cd_88592_to_88591);
559 iconv_close (cd_88591_to_utf8);
560 iconv_close (cd_utf8_to_88591);
561 iconv_close (cd_88592_to_utf8);
562 iconv_close (cd_utf8_to_88592);
564 /* ------------------------- Test mem_iconveh() ------------------------- */
566 /* Test conversion from ISO-8859-2 to ISO-8859-1 with no errors. */
567 for (h = 0; h < SIZEOF (handlers); h++)
569 enum iconv_ilseq_handler handler = handlers[h];
570 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
571 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
572 for (o = 0; o < 2; o++)
574 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
577 int retval = mem_iconveh (input, strlen (input),
578 "ISO-8859-2", "ISO-8859-1",
582 ASSERT (retval == 0);
583 ASSERT (length == strlen (expected));
584 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
587 for (i = 0; i < 37; i++)
588 ASSERT (offsets[i] == i);
589 ASSERT (offsets[37] == MAGIC);
596 /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */
597 for (h = 0; h < SIZEOF (handlers); h++)
599 enum iconv_ilseq_handler handler = handlers[h];
600 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */
601 for (o = 0; o < 2; o++)
603 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
606 int retval = mem_iconveh (input, strlen (input),
607 "ISO-8859-2", "ISO-8859-1",
614 ASSERT (retval == -1 && errno == EILSEQ);
615 ASSERT (result == NULL);
619 case iconveh_question_mark:
621 static const char expected[] = "Rafa? 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);
629 ASSERT (offsets[16] == MAGIC);
635 case iconveh_escape_sequence:
637 static const char expected[] = "Rafa\\u0142 Maszkowski";
638 ASSERT (retval == 0);
639 ASSERT (length == strlen (expected));
640 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
643 for (i = 0; i < 16; i++)
644 ASSERT (offsets[i] == (i < 5 ? i :
646 ASSERT (offsets[16] == MAGIC);
656 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */
657 for (h = 0; h < SIZEOF (handlers); h++)
659 enum iconv_ilseq_handler handler = handlers[h];
660 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
661 static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
662 for (o = 0; o < 2; o++)
664 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
667 int retval = mem_iconveh (input, strlen (input),
668 "ISO-8859-1", "UTF-8",
672 ASSERT (retval == 0);
673 ASSERT (length == strlen (expected));
674 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
677 for (i = 0; i < 37; i++)
678 ASSERT (offsets[i] == (i < 1 ? i :
682 ASSERT (offsets[37] == MAGIC);
689 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */
690 for (h = 0; h < SIZEOF (handlers); h++)
692 enum iconv_ilseq_handler handler = handlers[h];
693 static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
694 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
695 for (o = 0; o < 2; o++)
697 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
700 int retval = mem_iconveh (input, strlen (input),
701 "UTF-8", "ISO-8859-1",
705 ASSERT (retval == 0);
706 ASSERT (length == strlen (expected));
707 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
710 for (i = 0; i < 41; i++)
711 ASSERT (offsets[i] == (i < 1 ? i :
712 i == 1 ? (size_t)(-1) :
714 i == 13 ? (size_t)(-1) :
716 i == 20 ? (size_t)(-1) :
719 ASSERT (offsets[41] == MAGIC);
726 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
727 for (h = 0; h < SIZEOF (handlers); h++)
729 enum iconv_ilseq_handler handler = handlers[h];
730 static const char input[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */
731 for (o = 0; o < 2; o++)
733 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
736 int retval = mem_iconveh (input, strlen (input),
737 "UTF-8", "ISO-8859-1",
744 ASSERT (retval == -1 && errno == EILSEQ);
745 ASSERT (result == NULL);
749 case iconveh_question_mark:
751 static const char expected[] = "Rafa? Maszkowski";
752 ASSERT (retval == 0);
753 ASSERT (length == strlen (expected));
754 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
757 for (i = 0; i < 17; i++)
758 ASSERT (offsets[i] == (i < 5 ? i :
759 i == 5 ? (size_t)(-1) :
761 ASSERT (offsets[17] == MAGIC);
767 case iconveh_escape_sequence:
769 static const char expected[] = "Rafa\\u0142 Maszkowski";
770 ASSERT (retval == 0);
771 ASSERT (length == strlen (expected));
772 ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0);
775 for (i = 0; i < 17; i++)
776 ASSERT (offsets[i] == (i < 5 ? i :
777 i == 5 ? (size_t)(-1) :
779 ASSERT (offsets[17] == MAGIC);
789 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
790 for (h = 0; h < SIZEOF (handlers); h++)
792 enum iconv_ilseq_handler handler = handlers[h];
793 static const char input[] = "\342";
794 for (o = 0; o < 2; o++)
796 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
799 int retval = mem_iconveh (input, strlen (input),
800 "UTF-8", "ISO-8859-1",
804 ASSERT (retval == 0);
805 ASSERT (length == 0);
808 ASSERT (offsets[0] == 0);
809 ASSERT (offsets[1] == MAGIC);
816 /* ------------------------- Test str_iconveh() ------------------------- */
818 /* Test conversion from ISO-8859-2 to ISO-8859-1 with no errors. */
819 for (h = 0; h < SIZEOF (handlers); h++)
821 enum iconv_ilseq_handler handler = handlers[h];
822 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
823 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
824 char *result = str_iconveh (input, "ISO-8859-2", "ISO-8859-1", handler);
825 ASSERT (result != NULL);
826 ASSERT (strcmp (result, expected) == 0);
830 /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */
831 for (h = 0; h < SIZEOF (handlers); h++)
833 enum iconv_ilseq_handler handler = handlers[h];
834 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */
835 char *result = str_iconveh (input, "ISO-8859-2", "ISO-8859-1", handler);
839 ASSERT (result == NULL && errno == EILSEQ);
841 case iconveh_question_mark:
843 static const char expected[] = "Rafa? Maszkowski";
844 ASSERT (result != NULL);
845 ASSERT (strcmp (result, expected) == 0);
849 case iconveh_escape_sequence:
851 static const char expected[] = "Rafa\\u0142 Maszkowski";
852 ASSERT (result != NULL);
853 ASSERT (strcmp (result, expected) == 0);
860 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */
861 for (h = 0; h < SIZEOF (handlers); h++)
863 enum iconv_ilseq_handler handler = handlers[h];
864 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
865 static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
866 char *result = str_iconveh (input, "ISO-8859-1", "UTF-8", handler);
867 ASSERT (result != NULL);
868 ASSERT (strcmp (result, expected) == 0);
872 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */
873 for (h = 0; h < SIZEOF (handlers); h++)
875 enum iconv_ilseq_handler handler = handlers[h];
876 static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
877 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
878 char *result = str_iconveh (input, "UTF-8", "ISO-8859-1", handler);
879 ASSERT (result != NULL);
880 ASSERT (strcmp (result, expected) == 0);
884 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
885 for (h = 0; h < SIZEOF (handlers); h++)
887 enum iconv_ilseq_handler handler = handlers[h];
888 static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */
889 char *result = str_iconveh (input, "UTF-8", "ISO-8859-1", handler);
893 ASSERT (result == NULL && errno == EILSEQ);
895 case iconveh_question_mark:
897 static const char expected[] = "Costs: 27 ?";
898 ASSERT (result != NULL);
899 ASSERT (strcmp (result, expected) == 0);
903 case iconveh_escape_sequence:
905 static const char expected[] = "Costs: 27 \\u20AC";
906 ASSERT (result != NULL);
907 ASSERT (strcmp (result, expected) == 0);
914 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
915 for (h = 0; h < SIZEOF (handlers); h++)
917 enum iconv_ilseq_handler handler = handlers[h];
918 static const char input[] = "\342";
919 char *result = str_iconveh (input, "UTF-8", "ISO-8859-1", handler);
920 ASSERT (result != NULL);
921 ASSERT (strcmp (result, "") == 0);