<string.h>: Make strchrnul, strcasestr, memmem available by default
[platform/upstream/glibc.git] / string / tst-strxfrm2.c
1 #include <locale.h>
2 #include <stdio.h>
3 #include <string.h>
4
5 int
6 do_test (void)
7 {
8   static const char test_locale[] = "de_DE.UTF-8";
9
10   int res = 0;
11
12   char buf[20];
13   size_t l1 = strxfrm (NULL, "ab", 0);
14   size_t l2 = strxfrm (buf, "ab", 1);
15   size_t l3 = strxfrm (buf, "ab", sizeof (buf));
16   if (l3 < sizeof (buf) && strlen (buf) != l3)
17     {
18       puts ("C locale l3 test failed");
19       res = 1;
20     }
21
22   size_t l4 = strxfrm (buf, "ab", l1 + 1);
23   if (l4 < l1 + 1 && strlen (buf) != l4)
24     {
25       puts ("C locale l4 test failed");
26       res = 1;
27     }
28
29   buf[l1] = 'Z';
30   size_t l5 = strxfrm (buf, "ab", l1);
31   if (buf[l1] != 'Z')
32     {
33       puts ("C locale l5 test failed");
34       res = 1;
35     }
36
37   if (l1 != l2 || l1 != l3 || l1 != l4 || l1 != l5)
38     {
39       puts ("C locale retval test failed");
40       res = 1;
41     }
42
43   if (setlocale (LC_ALL, test_locale) == NULL)
44     {
45       printf ("cannot set locale \"%s\"\n", test_locale);
46       res = 1;
47     }
48   else
49     {
50       l1 = strxfrm (NULL, "ab", 0);
51       l2 = strxfrm (buf, "ab", 1);
52       l3 = strxfrm (buf, "ab", sizeof (buf));
53       if (l3 < sizeof (buf) && strlen (buf) != l3)
54         {
55           puts ("UTF-8 locale l3 test failed");
56           res = 1;
57         }
58
59       l4 = strxfrm (buf, "ab", l1 + 1);
60       if (l4 < l1 + 1 && strlen (buf) != l4)
61         {
62           puts ("UTF-8 locale l4 test failed");
63           res = 1;
64         }
65
66       buf[l1] = 'Z';
67       l5 = strxfrm (buf, "ab", l1);
68       if (buf[l1] != 'Z')
69         {
70           puts ("UTF-8 locale l5 test failed");
71           res = 1;
72         }
73
74       if (l1 != l2 || l1 != l3 || l1 != l4 || l1 != l5)
75         {
76           puts ("UTF-8 locale retval test failed");
77           res = 1;
78         }
79     }
80
81   return res;
82 }
83
84 #include <support/test-driver.c>