1 /* Test program for iswctype() function in ja_JP locale.
2    Copyright (C) 2000-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 <error.h>
20 #include <locale.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <wchar.h>
24 #include <wctype.h>
25 
26 static int
do_test(void)27 do_test (void)
28 {
29   wctype_t wct;
30   wchar_t buf[1000];
31   int result = 1;
32 
33   setlocale (LC_ALL, "");
34   wprintf (L"locale = %s\n", setlocale (LC_CTYPE, NULL));
35 
36   wct = wctype ("jhira");
37   if (wct == 0)
38     error (EXIT_FAILURE, 0, "jhira: no such character class");
39 
40   if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
41     {
42       int n;
43 
44       wprintf (L"buf[] = \"%ls\"\n", buf);
45 
46       result = 0;
47 
48       for (n = 0; buf[n] != L'\0'; ++n)
49 	{
50 	  wprintf (L"jhira(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
51 		   iswctype (buf[n], wct));
52 	  result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
53 		     || (buf[n] > 0xff && !iswctype (buf[n], wct)));
54 	}
55     }
56 
57   wct = wctype ("jkata");
58   if (wct == 0)
59     error (EXIT_FAILURE, 0, "jkata: no such character class");
60 
61   if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
62     {
63       int n;
64 
65       wprintf (L"buf[] = \"%ls\"\n", buf);
66 
67       result = 0;
68 
69       for (n = 0; buf[n] != L'\0'; ++n)
70 	{
71 	  wprintf (L"jkata(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
72 		   iswctype (buf[n], wct));
73 	  result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
74 		     || (buf[n] > 0xff && !iswctype (buf[n], wct)));
75 	}
76     }
77 
78   wct = wctype ("jdigit");
79   if (wct == 0)
80     error (EXIT_FAILURE, 0, "jdigit: no such character class");
81 
82   if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
83     {
84       int n;
85 
86       wprintf (L"buf[] = \"%ls\"\n", buf);
87 
88       result = 0;
89 
90       for (n = 0; buf[n] != L'\0'; ++n)
91 	{
92 	  wprintf (L"jdigit(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
93 		   iswctype (buf[n], wct));
94 	  result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
95 		     || (buf[n] > 0xff && !iswctype (buf[n], wct)));
96 	}
97     }
98 
99   wct = wctype ("jspace");
100   if (wct == 0)
101     error (EXIT_FAILURE, 0, "jspace: no such character class");
102 
103   if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
104     {
105       int n;
106 
107       wprintf (L"buf[] = \"%ls\"\n", buf);
108 
109       result = 0;
110 
111       for (n = 0; buf[n] != L'\0'; ++n)
112 	{
113 	  wprintf (L"jspace(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
114 		   iswctype (buf[n], wct));
115 	  result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
116 		     || (buf[n] > 0xff && !iswctype (buf[n], wct)));
117 	}
118     }
119 
120   wct = wctype ("jkanji");
121   if (wct == 0)
122     error (EXIT_FAILURE, 0, "jkanji: no such character class");
123 
124   if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
125     {
126       int n;
127 
128       wprintf (L"buf[] = \"%ls\"\n", buf);
129 
130       result = 0;
131 
132       for (n = 0; buf[n] != L'\0'; ++n)
133 	{
134 	  wprintf (L"jkanji(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
135 		   iswctype (buf[n], wct));
136 	  result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
137 		     || (buf[n] > 0xff && !iswctype (buf[n], wct)));
138 	}
139     }
140 
141   return result;
142 }
143 
144 #define TEST_FUNCTION do_test ()
145 #include "../test-skeleton.c"
146