VirtualBox

source: kBuild/vendor/grep/2.12/gnulib-tests/test-wcwidth.c@ 3627

Last change on this file since 3627 was 2595, checked in by bird, 13 years ago

gnu grep version 2.12 (grep-2.12.tar.xz, md5sum=8d2f0346d08b13c18afb81f0e8aa1e2f)

  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1/* Test of wcwidth() function.
2 Copyright (C) 2007-2012 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"
24SIGNATURE_CHECK (wcwidth, int, (wchar_t));
25
26#include <locale.h>
27#include <string.h>
28
29#include "localcharset.h"
30#include "macros.h"
31
32int
33main ()
34{
35 wchar_t wc;
36
37 /* Test width of ASCII characters. */
38 for (wc = 0x20; wc < 0x7F; wc++)
39 ASSERT (wcwidth (wc) == 1);
40
41 /* Switch to an UTF-8 locale. */
42 if (setlocale (LC_ALL, "fr_FR.UTF-8") != NULL
43 /* Check whether it's really an UTF-8 locale.
44 On OpenBSD 4.0, the setlocale call succeeds only for the LC_CTYPE
45 category and therefore returns "C/fr_FR.UTF-8/C/C/C/C", but the
46 LC_CTYPE category is effectively set to an ASCII LC_CTYPE category;
47 in particular, locale_charset() returns "ASCII". */
48 && strcmp (locale_charset (), "UTF-8") == 0)
49 {
50 /* Test width of ASCII characters. */
51 for (wc = 0x20; wc < 0x7F; wc++)
52 ASSERT (wcwidth (wc) == 1);
53
54 /* Test width of some non-spacing characters. */
55 ASSERT (wcwidth (0x0301) == 0);
56 ASSERT (wcwidth (0x05B0) == 0);
57
58 /* Test width of some format control characters. */
59 ASSERT (wcwidth (0x200E) <= 0);
60 ASSERT (wcwidth (0x2060) <= 0);
61#if 0 /* wchar_t may be only 16 bits. */
62 ASSERT (wcwidth (0xE0001) <= 0);
63 ASSERT (wcwidth (0xE0044) <= 0);
64#endif
65
66 /* Test width of some zero width characters. */
67 ASSERT (wcwidth (0x200B) == 0);
68 ASSERT (wcwidth (0xFEFF) <= 0);
69
70 /* Test width of some CJK characters. */
71 ASSERT (wcwidth (0x3000) == 2);
72 ASSERT (wcwidth (0xB250) == 2);
73 ASSERT (wcwidth (0xFF1A) == 2);
74#if 0 /* wchar_t may be only 16 bits. */
75 ASSERT (wcwidth (0x20369) == 2);
76 ASSERT (wcwidth (0x2F876) == 2);
77#endif
78 }
79
80 return 0;
81}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette