1 /* Test program for character classes and mappings.
2    Copyright (C) 1999-2022 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4 
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9 
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14 
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <https://www.gnu.org/licenses/>.  */
18 
19 #include <ctype.h>
20 #include <locale.h>
21 #include <wchar.h>
22 
23 
24 int
main(void)25 main (void)
26 {
27   const char lower[] = "abcdefghijklmnopqrstuvwxyz";
28   const char upper[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
29 #define LEN (sizeof (upper) - 1)
30   const wchar_t wlower[] = L"abcdefghijklmnopqrstuvwxyz";
31   const wchar_t wupper[] = L"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
32   int i;
33   int result = 0;
34 
35   setlocale (LC_ALL, "test6");
36 
37   for (i = 0; i < LEN; ++i)
38     {
39       /* Test basic table handling (basic == not more than 256 characters).
40 	 The charmaps swaps the normal lower-upper case meaning of the
41 	 ASCII characters used in the source code while the Unicode mapping
42 	 in the repertoire map has the normal correspondents.  This test
43 	 shows the independence of the tables for `char' and `wchar_t'
44 	 characters.  */
45 
46       if (islower (lower[i]))
47 	{
48 	  printf ("islower ('%c') false\n", lower[i]);
49 	  result = 1;
50 	}
51       if (! isupper (lower[i]))
52 	{
53 	  printf ("isupper ('%c') false\n", lower[i]);
54 	  result = 1;
55 	}
56 
57       if (! islower (upper[i]))
58 	{
59 	  printf ("islower ('%c') false\n", upper[i]);
60 	  result = 1;
61 	}
62       if (isupper (upper[i]))
63 	{
64 	  printf ("isupper ('%c') false\n", upper[i]);
65 	  result = 1;
66 	}
67 
68       if (toupper (lower[i]) != lower[i])
69 	{
70 	  printf ("toupper ('%c') false\n", lower[i]);
71 	  result = 1;
72 	}
73       if (tolower (lower[i]) != upper[i])
74 	{
75 	  printf ("tolower ('%c') false\n", lower[i]);
76 	  result = 1;
77 	}
78 
79       if (tolower (upper[i]) != upper[i])
80 	{
81 	  printf ("tolower ('%c') false\n", upper[i]);
82 	  result = 1;
83 	}
84       if (toupper (upper[i]) != lower[i])
85 	{
86 	  printf ("toupper ('%c') false\n", upper[i]);
87 	  result = 1;
88 	}
89 
90       if (iswlower (wupper[i]))
91 	{
92 	  printf ("iswlower (L'%c') false\n", upper[i]);
93 	  result = 1;
94 	}
95       if (! iswupper (wupper[i]))
96 	{
97 	  printf ("iswupper (L'%c') false\n", upper[i]);
98 	  result = 1;
99 	}
100 
101       if (iswupper (wlower[i]))
102 	{
103 	  printf ("iswupper (L'%c') false\n", lower[i]);
104 	  result = 1;
105 	}
106       if (! iswlower (wlower[i]))
107 	{
108 	  printf ("iswlower (L'%c') false\n", lower[i]);
109 	  result = 1;
110 	}
111 
112       if (towupper (wlower[i]) != wupper[i])
113 	{
114 	  printf ("towupper ('%c') false\n", lower[i]);
115 	  result = 1;
116 	}
117       if (towlower (wlower[i]) != wlower[i])
118 	{
119 	  printf ("towlower ('%c') false\n", lower[i]);
120 	  result = 1;
121 	}
122 
123       if (towlower (wupper[i]) != wlower[i])
124 	{
125 	  printf ("towlower ('%c') false\n", upper[i]);
126 	  result = 1;
127 	}
128       if (towupper (wupper[i]) != wupper[i])
129 	{
130 	  printf ("towupper ('%c') false\n", upper[i]);
131 	  result = 1;
132 	}
133     }
134 
135   return result;
136 }
137