From: Bruno Haible Date: Sat, 7 Jul 2007 21:39:09 +0000 (+0000) Subject: Tests for module 'wcwidth'. X-Git-Tag: cvs-readonly~142 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=7d084f9eeb5b975b556170a7c7da8db9ecc9282c;p=gnulib.git Tests for module 'wcwidth'. --- diff --git a/ChangeLog b/ChangeLog index 03b4ecf07..dbce8d210 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2007-07-07 Bruno Haible + * modules/wcwidth-tests: New file. + * tests/test-wcwidth.c: New file. + Work around MacOS X wcwidth() bug. * m4/wcwidth.m4 (gl_FUNC_WCWIDTH): Test against MacOS X 10.3 bug. * lib/wcwidth.c: Include localcharset.h, streq.h, uniwidth.h. diff --git a/modules/wcwidth-tests b/modules/wcwidth-tests new file mode 100644 index 000000000..91ae1b5e3 --- /dev/null +++ b/modules/wcwidth-tests @@ -0,0 +1,11 @@ +Files: +tests/test-wcwidth.c + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-wcwidth +check_PROGRAMS += test-wcwidth + diff --git a/tests/test-wcwidth.c b/tests/test-wcwidth.c new file mode 100644 index 000000000..4412ecc2d --- /dev/null +++ b/tests/test-wcwidth.c @@ -0,0 +1,82 @@ +/* Test of wcwidth() function. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include + +#include +#include +#include + +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +int +main () +{ + wchar_t wc; + + /* Test width of ASCII characters. */ + for (wc = 0x20; wc < 0x7F; wc++) + ASSERT (wcwidth (wc) == 1); + + /* Switch to an UTF-8 locale. */ + if (setlocale (LC_ALL, "fr_FR.UTF-8") != NULL) + { + /* Test width of ASCII characters. */ + for (wc = 0x20; wc < 0x7F; wc++) + ASSERT (wcwidth (wc) == 1); + + /* Test width of some non-spacing characters. */ + ASSERT (wcwidth (0x0301) == 0); + ASSERT (wcwidth (0x05B0) == 0); + + /* Test width of some format control characters. */ + ASSERT (wcwidth (0x200E) == 0); + ASSERT (wcwidth (0x2060) == 0); +#if 0 /* wchar_t may be only 16 bits. */ + ASSERT (wcwidth (0xE0001) == 0); + ASSERT (wcwidth (0xE0044) == 0); +#endif + + /* Test width of some zero width characters. */ + ASSERT (wcwidth (0x200B) == 0); + ASSERT (wcwidth (0xFEFF) == 0); + + /* Test width of some CJK characters. */ + ASSERT (wcwidth (0x3000) == 2); + ASSERT (wcwidth (0xB250) == 2); + ASSERT (wcwidth (0xFF1A) == 2); +#if 0 /* wchar_t may be only 16 bits. */ + ASSERT (wcwidth (0x20369) == 2); + ASSERT (wcwidth (0x2F876) == 2); +#endif + } + + return 0; +}