Bump to 1.14.1
[platform/upstream/augeas.git] / tests / test-wcwidth.c
1 /* Test of wcwidth() function.
2    Copyright (C) 2007-2016 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
16
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
18
19 #include <config.h>
20
21 #include <wchar.h>
22
23 #include "signature.h"
24 SIGNATURE_CHECK (wcwidth, int, (wchar_t));
25
26 #include <locale.h>
27 #include <string.h>
28
29 #include "c-ctype.h"
30 #include "localcharset.h"
31 #include "macros.h"
32
33 int
34 main ()
35 {
36   wchar_t wc;
37
38 #ifdef C_CTYPE_ASCII
39   /* Test width of ASCII characters.  */
40   for (wc = 0x20; wc < 0x7F; wc++)
41     ASSERT (wcwidth (wc) == 1);
42 #endif
43
44   /* Switch to an UTF-8 locale.  */
45   if (setlocale (LC_ALL, "fr_FR.UTF-8") != NULL
46       /* Check whether it's really an UTF-8 locale.
47          On OpenBSD 4.0, the setlocale call succeeds only for the LC_CTYPE
48          category and therefore returns "C/fr_FR.UTF-8/C/C/C/C", but the
49          LC_CTYPE category is effectively set to an ASCII LC_CTYPE category;
50          in particular, locale_charset() returns "ASCII".  */
51       && strcmp (locale_charset (), "UTF-8") == 0)
52     {
53       /* Test width of ASCII characters.  */
54       for (wc = 0x20; wc < 0x7F; wc++)
55         ASSERT (wcwidth (wc) == 1);
56
57       /* Test width of some non-spacing characters.  */
58       ASSERT (wcwidth (0x0301) == 0);
59       ASSERT (wcwidth (0x05B0) == 0);
60
61       /* Test width of some format control characters.  */
62       ASSERT (wcwidth (0x200E) <= 0);
63       ASSERT (wcwidth (0x2060) <= 0);
64 #if 0  /* wchar_t may be only 16 bits.  */
65       ASSERT (wcwidth (0xE0001) <= 0);
66       ASSERT (wcwidth (0xE0044) <= 0);
67 #endif
68
69       /* Test width of some zero width characters.  */
70       ASSERT (wcwidth (0x200B) == 0);
71       ASSERT (wcwidth (0xFEFF) <= 0);
72
73       /* Test width of some CJK characters.  */
74       ASSERT (wcwidth (0x3000) == 2);
75       ASSERT (wcwidth (0xB250) == 2);
76       ASSERT (wcwidth (0xFF1A) == 2);
77 #if 0  /* wchar_t may be only 16 bits.  */
78       ASSERT (wcwidth (0x20369) == 2);
79       ASSERT (wcwidth (0x2F876) == 2);
80 #endif
81     }
82
83   return 0;
84 }