Tests for module 'uninorm/canonical-decomposition'.
[gnulib.git] / tests / uninorm / test-canonical-decomposition.c
1 /* Test of canonical decomposition of Unicode characters.
2    Copyright (C) 2009 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 <http://www.gnu.org/licenses/>.  */
16
17 /* Written by Bruno Haible <bruno@clisp.org>, 2009.  */
18
19 #include <config.h>
20
21 #include "uninorm.h"
22
23 #include <stdio.h>
24 #include <stdlib.h>
25
26 #define ASSERT(expr) \
27   do                                                                         \
28     {                                                                        \
29       if (!(expr))                                                           \
30         {                                                                    \
31           fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
32           fflush (stderr);                                                   \
33           abort ();                                                          \
34         }                                                                    \
35     }                                                                        \
36   while (0)
37
38 int
39 main ()
40 {
41   ucs4_t decomposed[UC_DECOMPOSITION_MAX_LENGTH];
42   int ret;
43
44   /* SPACE */
45   ret = uc_canonical_decomposition (0x0020, decomposed);
46   ASSERT (ret == -1);
47
48   /* LATIN CAPITAL LETTER A WITH DIAERESIS */
49   ret = uc_canonical_decomposition (0x00C4, decomposed);
50   ASSERT (ret == 2);
51   ASSERT (decomposed[0] == 0x0041);
52   ASSERT (decomposed[1] == 0x0308);
53
54   /* LATIN CAPITAL LETTER A WITH DIAERESIS AND MACRON */
55   ret = uc_canonical_decomposition (0x01DE, decomposed);
56   ASSERT (ret == 2);
57   ASSERT (decomposed[0] == 0x00C4);
58   ASSERT (decomposed[1] == 0x0304);
59
60   /* GREEK DIALYTIKA AND PERISPOMENI */
61   ret = uc_canonical_decomposition (0x1FC1, decomposed);
62   ASSERT (ret == 2);
63   ASSERT (decomposed[0] == 0x00A8);
64   ASSERT (decomposed[1] == 0x0342);
65
66   /* SCRIPT SMALL L */
67   ret = uc_canonical_decomposition (0x2113, decomposed);
68   ASSERT (ret == -1);
69
70   /* NO-BREAK SPACE */
71   ret = uc_canonical_decomposition (0x00A0, decomposed);
72   ASSERT (ret == -1);
73
74   /* ARABIC LETTER VEH INITIAL FORM */
75   ret = uc_canonical_decomposition (0xFB6C, decomposed);
76   ASSERT (ret == -1);
77
78   /* ARABIC LETTER VEH MEDIAL FORM */
79   ret = uc_canonical_decomposition (0xFB6D, decomposed);
80   ASSERT (ret == -1);
81
82   /* ARABIC LETTER VEH FINAL FORM */
83   ret = uc_canonical_decomposition (0xFB6B, decomposed);
84   ASSERT (ret == -1);
85
86   /* ARABIC LETTER VEH ISOLATED FORM */
87   ret = uc_canonical_decomposition (0xFB6A, decomposed);
88   ASSERT (ret == -1);
89
90   /* CIRCLED NUMBER FIFTEEN */
91   ret = uc_canonical_decomposition (0x246E, decomposed);
92   ASSERT (ret == -1);
93
94   /* TRADE MARK SIGN */
95   ret = uc_canonical_decomposition (0x2122, decomposed);
96   ASSERT (ret == -1);
97
98   /* LATIN SUBSCRIPT SMALL LETTER I */
99   ret = uc_canonical_decomposition (0x1D62, decomposed);
100   ASSERT (ret == -1);
101
102   /* PRESENTATION FORM FOR VERTICAL LEFT PARENTHESIS */
103   ret = uc_canonical_decomposition (0xFE35, decomposed);
104   ASSERT (ret == -1);
105
106   /* FULLWIDTH LATIN CAPITAL LETTER A */
107   ret = uc_canonical_decomposition (0xFF21, decomposed);
108   ASSERT (ret == -1);
109
110   /* HALFWIDTH IDEOGRAPHIC COMMA */
111   ret = uc_canonical_decomposition (0xFF64, decomposed);
112   ASSERT (ret == -1);
113
114   /* SMALL IDEOGRAPHIC COMMA */
115   ret = uc_canonical_decomposition (0xFE51, decomposed);
116   ASSERT (ret == -1);
117
118   /* SQUARE MHZ */
119   ret = uc_canonical_decomposition (0x3392, decomposed);
120   ASSERT (ret == -1);
121
122   /* VULGAR FRACTION THREE EIGHTHS */
123   ret = uc_canonical_decomposition (0x215C, decomposed);
124   ASSERT (ret == -1);
125
126   /* MICRO SIGN */
127   ret = uc_canonical_decomposition (0x00B5, decomposed);
128   ASSERT (ret == -1);
129
130   /* ARABIC LIGATURE SALLALLAHOU ALAYHE WASALLAM */
131   ret = uc_canonical_decomposition (0xFDFA, decomposed);
132   ASSERT (ret == -1);
133
134   /* HANGUL SYLLABLE GEUL */
135   ret = uc_canonical_decomposition (0xAE00, decomposed);
136   ASSERT (ret == 3);
137   ASSERT (decomposed[0] == 0x1100);
138   ASSERT (decomposed[1] == 0x1173);
139   ASSERT (decomposed[2] == 0x11AF);
140
141   /* HANGUL SYLLABLE GEU */
142   ret = uc_canonical_decomposition (0xADF8, decomposed);
143   ASSERT (ret == 2);
144   ASSERT (decomposed[0] == 0x1100);
145   ASSERT (decomposed[1] == 0x1173);
146
147   return 0;
148 }