add an sscanf regression test
[libc-test] / src / regression / iconv-roundtrips.c
1 // commit: b7bfb5c3a8330002250f304cb5deb522fa054eae
2 // fix iconv conversions for iso88592-iso885916
3 #include <iconv.h>
4 #include <string.h>
5 #include "test.h"
6
7 int main(void)
8 {
9         static char *test_charsets[] = {
10                 "iso-8859-1",
11                 "iso-8859-2",
12                 "iso-8859-4",
13                 "iso-8859-5",
14                 "iso-8859-9",
15                 "iso-8859-10",
16                 "iso-8859-13",
17                 "iso-8859-14",
18                 "iso-8859-15",
19                 "iso-8859-16",
20                 0
21         };
22         char all_codepoints[256];
23         int i;
24
25         for (i=0; i<256; i++)
26                 all_codepoints[i] = 255-i;
27
28         for (i=0; test_charsets[i]; i++) {
29                 iconv_t there = iconv_open("UTF-8", test_charsets[i]);
30                 if (there == (iconv_t)-1) continue;
31                 iconv_t andback = iconv_open(test_charsets[i], "UTF-8");
32                 if (andback == (iconv_t)-1) {
33                         iconv_close(there);
34                         continue;
35                 }
36                 char u8buf[1024];
37                 char buf[256];
38                 size_t u8rem = sizeof u8buf;
39                 int r1 = iconv(there,
40                         &(char *){all_codepoints}, &(size_t){sizeof all_codepoints},
41                         &(char *){u8buf}, &u8rem);
42                 size_t u8len = sizeof u8buf - u8rem;
43                 int r2 = iconv(andback,
44                         &(char *){u8buf}, &(size_t){u8len},
45                         &(char *){buf}, &(size_t){sizeof buf});
46
47                 if (r1) t_error("got %d converting from %s\n", r1, test_charsets[i]);
48                 if (r2) t_error("got %d converting back to %s\n", r2, test_charsets[i]);
49
50                 if (memcmp(all_codepoints, buf, sizeof buf)) {
51                         t_error("round trip corrupted %s characters\n", test_charsets[i]);
52                 }
53
54                 iconv_close(there);
55                 iconv_close(andback);
56         }
57
58         return t_status;
59 }