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, locale: "de_DE.UTF-8"); |
11 | |
12 | iconv_t cd = iconv_open (tocode: "ISO-2022-JP//TRANSLIT", fromcode: ""); |
13 | if (cd == (iconv_t) -1) |
14 | { |
15 | puts (s: "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: cd, inbuf: &inptr, inbytesleft: &inlen, outbuf: &outptr, outbytesleft: &outlen); |
27 | if (r != 1 |
28 | || inlen != 0 |
29 | || outlen != sizeof (outstr) - sizeof (expstr1) |
30 | || memcmp (s1: outstr, s2: expstr1, n: sizeof (expstr1)) != 0) |
31 | { |
32 | puts (s: "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: cd, inbuf: &inptr, inbytesleft: &inlen, outbuf: &outptr, outbytesleft: &outlen); |
43 | if (r != 1 |
44 | || inlen != 0 |
45 | || outlen != sizeof (outstr) - sizeof (expstr2) |
46 | || memcmp (s1: outstr, s2: expstr2, n: sizeof (expstr2)) != 0) |
47 | { |
48 | puts (s: "wrong second conversion"); |
49 | return 1; |
50 | } |
51 | |
52 | if (iconv_close (cd: cd) != 0) |
53 | { |
54 | puts (s: "iconv_close failed"); |
55 | return 1; |
56 | } |
57 | return 0; |
58 | } |
59 | |
60 | #define TEST_FUNCTION do_test () |
61 | #include "../test-skeleton.c" |
62 |