Use libm_alias_float for sparc.
[glibc.git] / wcsmbs / tst-c16c32-1.c
blob3b1c1d674cac0790963c13f57a1f0371504d752e
1 #include <inttypes.h>
2 #include <locale.h>
3 #include <stdio.h>
4 #include <uchar.h>
5 #include <stdint.h>
7 static int
8 do_test (void)
10 if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL)
12 puts ("cannot set locale");
13 return 1;
16 int result = 0;
18 char32_t c32 = 48;
21 if (c32 >= 0xd800 && c32 <= 0xe000)
22 continue;
24 char buf[20];
25 size_t n1 = c32rtomb (buf, c32, NULL);
26 if (n1 <= 0)
28 printf ("c32rtomb for U'\\x%" PRIx32 "' failed\n", (uint32_t) c32);
29 result = 1;
30 continue;
33 char32_t c32out;
34 size_t n2 = mbrtoc32 (&c32out, buf, n1, NULL);
35 if ((ssize_t) n2 < 0)
37 printf ("mbrtoc32 for U'\\x%" PRIx32 "' failed\n", (uint32_t) c32);
38 result = 1;
39 continue;
41 if (n2 != n1)
43 printf ("mbrtoc32 for U'\\x%" PRIx32 "' consumed %zu bytes, not %zu\n",
44 (uint32_t) c32, n2, n1);
45 result = 1;
47 else if (c32out != c32)
49 printf ("mbrtoc32 for U'\\x%" PRIx32 "' produced U'\\x%" PRIx32 "\n",
50 (uint32_t) c32, (uint32_t) c32out);
51 result = 1;
54 char16_t c16;
55 size_t n3 = mbrtoc16 (&c16, buf, n1, NULL);
56 if (n3 != n1)
58 printf ("mbrtoc16 for U'\\x%" PRIx32 "' did not consume all bytes\n",
59 (uint32_t) c32);
60 result = 1;
61 continue;
63 if (c32 < 0x10000)
65 if (c16 != c32)
67 printf ("mbrtoc16 for U'\\x%" PRIx32 "' produce u'\\x%" PRIx16 "'\n",
68 (uint32_t) c32, (uint16_t) c16);
69 result = 1;
70 continue;
73 else
75 buf[0] = '1';
76 char16_t c16_2;
77 size_t n4 = mbrtoc16 (&c16_2, buf, 1, NULL);
78 if (n4 != (size_t) -3)
80 printf ("second mbrtoc16 for U'\\x%" PRIx32 "' did not return -3\n",
81 (uint32_t) c32);
82 result = 1;
83 continue;
86 if (c32 != (((uint32_t) (c16 - 0xd7c0)) << 10) + (c16_2 - 0xdc00))
88 printf ("mbrtoc16 for U'\\x%" PRIx32 "' returns U'\\x%" PRIx32 "\n",
89 (uint32_t) c32,
90 (((uint32_t) (c16 - 0xd7c0)) << 10) + (c16_2 - 0xdc00));
91 result = 1;
92 continue;
96 buf[0] = '\0';
97 char16_t c16_nul;
98 n3 = mbrtoc16 (&c16_nul, buf, n1, NULL);
99 if (n3 != 0)
101 printf ("mbrtoc16 for '\\0' returns %zd\n", n3);
102 result = 1;
103 continue;
106 if (c32 < 0x10000)
108 size_t n5 = c16rtomb (buf, c16, NULL);
109 if ((ssize_t) n5 < 0)
111 printf ("c16rtomb for U'\\x%" PRIx32 "' failed with %zd\n",
112 (uint32_t) c32, n5);
113 result = 1;
114 continue;
116 if (n5 != n1)
118 printf ("c16rtomb for U'\\x%" PRIx32 "' produced %zu bytes instead of %zu bytes\n",
119 (uint32_t) c32, n5, n1);
120 result = 1;
121 continue;
125 while ((c32 += 0x1111) <= U'\x12000');
127 return result;
130 #define TEST_FUNCTION do_test ()
131 #include "../test-skeleton.c"