summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2007-07-07 21:39:09 +0000
committerBruno Haible <bruno@clisp.org>2007-07-07 21:39:09 +0000
commit7d084f9eeb5b975b556170a7c7da8db9ecc9282c (patch)
treee52cd14251327a298c1596dcea73e552b1fe75c9 /tests
parent7599e817ca9e12244449ca2fad855b96f6c8b817 (diff)
downloadgnulib-7d084f9eeb5b975b556170a7c7da8db9ecc9282c.tar.gz
Tests for module 'wcwidth'.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-wcwidth.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/test-wcwidth.c b/tests/test-wcwidth.c
new file mode 100644
index 0000000000..4412ecc2d8
--- /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 <bruno@clisp.org>, 2007. */
+
+#include <config.h>
+
+#include <wchar.h>
+
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#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;
+}