summaryrefslogtreecommitdiff
path: root/tests/unigbrk/test-ulc-grapheme-breaks.c
blob: dae68758e9777fa2dfb2e45b7207dcb12936c940 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* Grapheme cluster breaks test.
   Copyright (C) 2009-2022 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 <https://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;
}