add test for strftime
[libc-test.git] / src / functional / iconv_open.c
blob8f6b28561ccb25b73dbbb0fe679112d745dc877f
1 #include <string.h>
2 #include <errno.h>
3 #include <iconv.h>
4 #include "test.h"
6 int main(void)
8 iconv_t cd;
9 char buf[100];
10 char *inbuf = "test";
11 char *outbuf = buf;
12 size_t inlen = strlen(inbuf);
13 size_t outlen;
14 size_t r;
15 char *bad = "bad-codeset";
17 cd = iconv_open(bad, bad);
18 if (cd != (iconv_t)-1)
19 t_error("iconv_open(\"%s\",\"%s\") didn't fail\n", bad, bad);
20 if (errno != EINVAL)
21 t_error("iconv_open(\"%s\",\"%s\") did not fail with EINVAL, got %s\n", bad, bad, strerror(errno));
23 errno = 0;
24 cd = iconv_open("UTF-8", "UTF-8");
25 if (cd == (iconv_t)-1)
26 t_error("iconv_open(\"\",\"\") failed: %s\n", strerror(errno));
28 errno = 0;
29 outlen = 0;
30 r = iconv(cd, &inbuf, &inlen, &outbuf, &outlen);
31 if (r != -1)
32 t_error("iconv() did not fail with 0 output length\n");
33 if (errno != E2BIG)
34 t_error("iconv() did not fail with E2BIG, got %s\n", strerror(errno));
36 errno = 0;
37 outlen = sizeof buf;
38 r = iconv(cd, &inbuf, &inlen, &outbuf, &outlen);
39 if (r)
40 t_error("iconv() did not return 0 when converting utf8 to utf8, got %d\n", r);
41 if (errno)
42 t_error("iconv() failed: %s\n", strerror(errno));
44 r = iconv_close(cd);
45 if (r == -1)
46 t_error("iconv_close failed: %s\n", strerror(errno));
48 return t_status;