• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <string.h>
2 #include <errno.h>
3 #include <iconv.h>
4 #include "test.h"
5 
main(void)6 int main(void)
7 {
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";
16 
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));
22 
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));
27 
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));
35 
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));
43 
44 	r = iconv_close(cd);
45 	if (r == -1)
46 		t_error("iconv_close failed: %s\n", strerror(errno));
47 
48 	return t_status;
49 }
50