root/maint/gnulib/tests/unigbrk/test-ulc-grapheme-breaks.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. is_8859_6_break
  2. main

   1 /* Grapheme cluster breaks test.
   2    Copyright (C) 2009-2021 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 <https://www.gnu.org/licenses/>.  */
  16 
  17 /* Written by Ben Pfaff <blp@cs.stanford.edu>, 2010,
  18    based on code by Bruno Haible <bruno@clisp.org>, 2009.  */
  19 
  20 #include <config.h>
  21 
  22 #include "unigbrk.h"
  23 
  24 #include <locale.h>
  25 #include <stdlib.h>
  26 
  27 #include "macros.h"
  28 
  29 static bool
  30 is_8859_6_break (unsigned char c)
     /* [previous][next][first][last][top][bottom][index][help] */
  31 {
  32   /* ISO-8859-6 has combining characters in positions 0xeb through 0xf2. */
  33   return !(c >= 0xeb && c <= 0xf2);
  34 }
  35 
  36 int
  37 main ()
     /* [previous][next][first][last][top][bottom][index][help] */
  38 {
  39   /* configure should already have checked that the locale is supported.  */
  40   if (setlocale (LC_ALL, "") == NULL)
  41     return 1;
  42 
  43   /* Test case n = 0.  */
  44   ulc_grapheme_breaks (NULL, 0, NULL);
  45 
  46 #if HAVE_ICONV
  47   {
  48     /* This is just a random collection of bytes from ISO-8859-6.
  49 
  50        (We use ISO-8859-6 because it is one of very few non-UTF-8 locale
  51        encodings supported by glibc that have combining characters.) */
  52     static const char s[] = "ZYX\352\353W\360\361V\362";
  53     enum { LENGTH = sizeof s - 1 };
  54     char p[LENGTH];
  55     size_t i;
  56 
  57     ulc_grapheme_breaks (s, LENGTH, p);
  58     for (i = 0; i < LENGTH; i++)
  59       if (p[i] != is_8859_6_break (s[i]))
  60         {
  61           size_t j;
  62 
  63           fprintf (stderr, "wrong grapheme breaks:\n");
  64 
  65           fprintf (stderr, "   input:");
  66           for (j = 0; j < LENGTH; j++)
  67             fprintf (stderr, " %02x", (unsigned char) s[j]);
  68           putc ('\n', stderr);
  69 
  70           fprintf (stderr, "expected:");
  71           for (j = 0; j < LENGTH; j++)
  72             fprintf (stderr, "  %d", is_8859_6_break (s[j]));
  73           putc ('\n', stderr);
  74 
  75           fprintf (stderr, "  actual:");
  76           for (j = 0; j < LENGTH; j++)
  77             fprintf (stderr, "  %d", p[j]);
  78           putc ('\n', stderr);
  79 
  80           abort ();
  81         }
  82   }
  83 #endif
  84 
  85   return 0;
  86 }

/* [previous][next][first][last][top][bottom][index][help] */