lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | #include <iconv.h> |
| 2 | #include <locale.h> |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | #include <string.h> |
| 6 | |
| 7 | static int |
| 8 | do_test (void) |
| 9 | { |
| 10 | setlocale (LC_ALL, "de_DE.UTF-8"); |
| 11 | |
| 12 | iconv_t cd = iconv_open ("ISO-2022-JP//TRANSLIT", ""); |
| 13 | if (cd == (iconv_t) -1) |
| 14 | { |
| 15 | puts ("iconv_open failed"); |
| 16 | return 1; |
| 17 | } |
| 18 | |
| 19 | char instr1[] = "\xc2\xa3\xe2\x82\xac\n"; |
| 20 | const char expstr1[] = "\033$B!r\033(BEUR\n"; |
| 21 | char outstr[32]; |
| 22 | size_t inlen = sizeof (instr1); |
| 23 | size_t outlen = sizeof (outstr); |
| 24 | char *inptr = instr1; |
| 25 | char *outptr = outstr; |
| 26 | size_t r = iconv (cd, &inptr, &inlen, &outptr, &outlen); |
| 27 | if (r != 1 |
| 28 | || inlen != 0 |
| 29 | || outlen != sizeof (outstr) - sizeof (expstr1) |
| 30 | || memcmp (outstr, expstr1, sizeof (expstr1)) != 0) |
| 31 | { |
| 32 | puts ("wrong first conversion"); |
| 33 | return 1; |
| 34 | } |
| 35 | |
| 36 | char instr2[] = "\xe3\x88\xb1\n"; |
| 37 | const char expstr2[] = "(\033$B3t\033(B)\n"; |
| 38 | inlen = sizeof (instr2); |
| 39 | outlen = sizeof (outstr); |
| 40 | inptr = instr2; |
| 41 | outptr = outstr; |
| 42 | r = iconv (cd, &inptr, &inlen, &outptr, &outlen); |
| 43 | if (r != 1 |
| 44 | || inlen != 0 |
| 45 | || outlen != sizeof (outstr) - sizeof (expstr2) |
| 46 | || memcmp (outstr, expstr2, sizeof (expstr2)) != 0) |
| 47 | { |
| 48 | puts ("wrong second conversion"); |
| 49 | return 1; |
| 50 | } |
| 51 | |
| 52 | if (iconv_close (cd) != 0) |
| 53 | { |
| 54 | puts ("iconv_close failed"); |
| 55 | return 1; |
| 56 | } |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | #define TEST_FUNCTION do_test () |
| 61 | #include "../test-skeleton.c" |