]> git.ipfire.org Git - thirdparty/glibc.git/blame - string/tst-strxfrm2.c
misc/test-errno-linux: Handle EINVAL from quotactl
[thirdparty/glibc.git] / string / tst-strxfrm2.c
CommitLineData
2f334ad5
UD
1#include <locale.h>
2#include <stdio.h>
3#include <string.h>
4
fb82116f 5int
2f334ad5
UD
6do_test (void)
7{
60cf80f0
MS
8 static const char test_locale[] = "de_DE.UTF-8";
9
2f334ad5
UD
10 int res = 0;
11
52a33795 12 char buf[20];
2f334ad5
UD
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));
52a33795
UD
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 }
2f334ad5 36
52a33795 37 if (l1 != l2 || l1 != l3 || l1 != l4 || l1 != l5)
2f334ad5 38 {
52a33795 39 puts ("C locale retval test failed");
2f334ad5
UD
40 res = 1;
41 }
42
60cf80f0 43 if (setlocale (LC_ALL, test_locale) == NULL)
2f334ad5 44 {
60cf80f0 45 printf ("cannot set locale \"%s\"\n", test_locale);
2f334ad5
UD
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));
52a33795
UD
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 }
2f334ad5 73
52a33795 74 if (l1 != l2 || l1 != l3 || l1 != l4 || l1 != l5)
2f334ad5 75 {
52a33795 76 puts ("UTF-8 locale retval test failed");
2f334ad5
UD
77 res = 1;
78 }
79 }
80
81 return res;
82}
83
fb82116f 84#include <support/test-driver.c>