summaryrefslogtreecommitdiff
path: root/tests/unigbrk/test-ulc-grapheme-breaks.c
diff options
context:
space:
mode:
authorManuel A. Fernandez Montecelo <manuel.montezelo@gmail.com>2016-05-26 16:48:39 +0100
committerManuel A. Fernandez Montecelo <manuel.montezelo@gmail.com>2016-05-26 16:48:39 +0100
commit8dfc46115527afe3706e9e4225e9ad019c97d695 (patch)
tree372d5192b218455834781a0037c57e919a06b488 /tests/unigbrk/test-ulc-grapheme-breaks.c
parent2291cf138eb72ad38d8c59b8b6f762875c8c4ff2 (diff)
parent5f2b09982312c98863eb9a8dfe2c608b81f58259 (diff)
Merge tag 'upstream/0.9.6'
Upstream version 0.9.6
Diffstat (limited to 'tests/unigbrk/test-ulc-grapheme-breaks.c')
-rw-r--r--tests/unigbrk/test-ulc-grapheme-breaks.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/unigbrk/test-ulc-grapheme-breaks.c b/tests/unigbrk/test-ulc-grapheme-breaks.c
new file mode 100644
index 0000000..29b8a26
--- /dev/null
+++ b/tests/unigbrk/test-ulc-grapheme-breaks.c
@@ -0,0 +1,86 @@
+/* Grapheme cluster breaks test.
+ Copyright (C) 2009-2015 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 3 of the License, 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, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Ben Pfaff <blp@cs.stanford.edu>, 2010,
+ based on code by Bruno Haible <bruno@clisp.org>, 2009. */
+
+#include <config.h>
+
+#include "unigbrk.h"
+
+#include <locale.h>
+#include <stdlib.h>
+
+#include "macros.h"
+
+static bool
+is_8859_6_break (unsigned char c)
+{
+ /* ISO-8859-6 has combining characters in positions 0xeb through 0xf2. */
+ return !(c >= 0xeb && c <= 0xf2);
+}
+
+int
+main ()
+{
+ /* configure should already have checked that the locale is supported. */
+ if (setlocale (LC_ALL, "") == NULL)
+ return 1;
+
+ /* Test case n = 0. */
+ ulc_grapheme_breaks (NULL, 0, NULL);
+
+#if HAVE_ICONV
+ {
+ /* This is just a random collection of bytes from ISO-8859-6.
+
+ (We use ISO-8859-6 because it is one of very few non-UTF-8 locale
+ encodings supported by glibc that have combining characters.) */
+ static const char s[] = "ZYX\352\353W\360\361V\362";
+ enum { LENGTH = sizeof s - 1 };
+ char p[LENGTH];
+ size_t i;
+
+ ulc_grapheme_breaks (s, LENGTH, p);
+ for (i = 0; i < LENGTH; i++)
+ if (p[i] != is_8859_6_break (s[i]))
+ {
+ size_t j;
+
+ fprintf (stderr, "wrong grapheme breaks:\n");
+
+ fprintf (stderr, " input:");
+ for (j = 0; j < LENGTH; j++)
+ fprintf (stderr, " %02x", (unsigned char) s[j]);
+ putc ('\n', stderr);
+
+ fprintf (stderr, "expected:");
+ for (j = 0; j < LENGTH; j++)
+ fprintf (stderr, " %d", is_8859_6_break (s[j]));
+ putc ('\n', stderr);
+
+ fprintf (stderr, " actual:");
+ for (j = 0; j < LENGTH; j++)
+ fprintf (stderr, " %d", p[j]);
+ putc ('\n', stderr);
+
+ abort ();
+ }
+ }
+#endif
+
+ return 0;
+}