• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
4  * COPYRIGHT:
5  * Copyright (c) 1997-2016, International Business Machines Corporation and
6  * others. All Rights Reserved.
7  ********************************************************************/
8 /*   file name:  cbididat.c
9 *   encoding:   UTF-8
10 *   tab size:   8 (not used)
11 *   indentation:4
12 *
13 *   created on: 1999sep22
14 *   created by: Markus W. Scherer
15 */
16 
17 #include "unicode/utypes.h"
18 #include "unicode/uchar.h"
19 #include "unicode/ubidi.h"
20 #include "cbiditst.h"
21 #include "cmemory.h"
22 
23 const char * const
24 dirPropNames[U_CHAR_DIRECTION_COUNT]={
25     "L", "R", "EN", "ES", "ET", "AN", "CS", "B", "S", "WS", "ON",
26     "LRE", "LRO", "AL", "RLE", "RLO", "PDF", "NSM", "BN",
27     "FSI", "LRI", "RLI", "PDI"  /* new in Unicode 6.3/ICU 52 */
28 };
29 
30 UChar
31 charFromDirProp[U_CHAR_DIRECTION_COUNT]={
32  /* L     R      EN    ES    ET    AN     CS    B    S    WS    ON */
33     0x61, 0x5d0, 0x30, 0x2f, 0x25, 0x660, 0x2c, 0xa, 0x9, 0x20, 0x26,
34  /* LRE     LRO     AL     RLE     RLO     PDF     NSM    BN */
35     0x202a, 0x202d, 0x627, 0x202b, 0x202e, 0x202c, 0x308, 0x200c,
36  /* FSI     LRI     RLI     PDI */
37     0x2068, 0x2066, 0x2067, 0x2069  /* new in Unicode 6.3/ICU 52 */
38 };
39 
40 static const uint8_t
41 testText1[]={
42     L, L, WS, L, WS, EN, L, B
43 };
44 
45 static const UBiDiLevel
46 testLevels1[]={
47     0, 0, 0, 0, 0, 0, 0, 0
48 };
49 
50 static const uint8_t
51 testVisualMap1[]={
52     0, 1, 2, 3, 4, 5, 6, 7
53 };
54 
55 static const uint8_t
56 testText2[]={
57     R, AL, WS, R, AL, WS, R
58 };
59 
60 static const UBiDiLevel
61 testLevels2[]={
62     1, 1, 1, 1, 1, 1, 1
63 };
64 
65 static const uint8_t
66 testVisualMap2[]={
67     6, 5, 4, 3, 2, 1, 0
68 };
69 
70 static const uint8_t
71 testText3[]={
72     L, L, WS, EN, CS, WS, EN, CS, EN, WS, L, L
73 };
74 
75 static const UBiDiLevel
76 testLevels3[]={
77     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
78 };
79 
80 static const uint8_t
81 testVisualMap3[]={
82     0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
83 };
84 
85 static const uint8_t
86 testText4[]={
87     L, AL, AL, AL, L, AL, AL, L, WS, EN, CS, WS, EN, CS, EN, WS, L, L
88 };
89 
90 static const UBiDiLevel
91 testLevels4[]={
92     0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
93 };
94 
95 static const uint8_t
96 testVisualMap4[]={
97     0, 3, 2, 1, 4, 6, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17
98 };
99 
100 static const uint8_t
101 testText5[]={
102     AL, R, AL, WS, EN, CS, WS, EN, CS, EN, WS, R, R, WS, L, L
103 };
104 
105 static const UBiDiLevel
106 testLevels5[]={
107     1, 1, 1, 1, 2, 1, 1, 2, 2, 2, 1, 1, 1, 1, 2, 2
108 };
109 
110 static const uint8_t
111 testVisualMap5[]={
112     15, 14, 13, 12, 11, 10, 9, 6, 7, 8, 5, 4, 3, 2, 0, 1
113 };
114 
115 static const uint8_t
116 testText6[]={
117     R, EN, NSM, ET
118 };
119 
120 static const UBiDiLevel
121 testLevels6[]={
122     1, 2, 2, 2
123 };
124 
125 static const uint8_t
126 testVisualMap6[]={
127     3, 0, 1, 2
128 };
129 
130 #if 0
131 static const uint8_t
132 testText7[]={
133     /* empty */
134 };
135 
136 static const UBiDiLevel
137 testLevels7[]={
138 };
139 
140 static const uint8_t
141 testVisualMap7[]={
142 };
143 
144 #endif
145 
146 static const uint8_t
147 testText8[]={
148     RLE, WS, R, R, R, WS, PDF, WS, B
149 };
150 
151 static const UBiDiLevel
152 testLevels8[]={
153     1, 1, 1, 1, 1, 1, 1, 1, 1
154 };
155 
156 static const uint8_t
157 testVisualMap8[]={
158     8, 7, 6, 5, 4, 3, 2, 1, 0
159 };
160 
161 static const uint8_t
162 testText9[]={
163     LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE,      /* 15 entries */
164     LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE,      /* 15 entries */
165     AN, RLO, NSM, LRE, PDF, RLE, ES, EN, ON                                         /*  9 entries */
166 };
167 
168 static const UBiDiLevel
169 testLevels9[]={
170     126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126,      /* 15 entries */
171     126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126,      /* 15 entries */
172     126, 125, 125, 125, 125, 125, 125, 125, 125                                     /*  9 entries */
173 };
174 
175 static const uint8_t
176 testVisualMap9[]={
177     8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,                       /* 15 entries */
178     23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,                     /* 15 entries */
179     38, 7, 6, 5, 4, 3, 2, 1, 0                                                      /*  9 entries */
180 };
181 
182 static const uint8_t
183 testText10[]={
184     LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE,      /* 15 entries */
185     LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE,      /* 15 entries */
186     LRE, BN, CS, RLO, S, PDF, EN, LRO, AN, ES                                       /* 10 entries */
187 };
188 
189 static const UBiDiLevel
190 testLevels10[]={
191     124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,      /* 15 entries */
192     124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,      /* 15 entries */
193     124, 124, 124, 64, 64, 124, 124, 126, 126, 124                                  /* 10 entries */
194 };
195 
196 static const uint8_t
197 testVisualMap10[]={
198     0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,                               /* 15 entries */
199     15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,                     /* 15 entries */
200     30, 31, 32, 33, 34, 35, 36, 37, 38, 39                                          /* 10 entries */
201 };
202 
203 static const uint8_t
204 testText11[]={
205     S, WS, NSM, RLE, WS, L, L, L, WS, LRO, WS, R, R, R, WS, RLO, WS, L, L, L,       /* 20 entries */
206     WS, LRE, WS, R, R, R, WS, PDF, WS, L, L, L, WS, PDF, WS, AL, AL, AL, WS, PDF,   /* 20 entries */
207     WS, L, L, L, WS, PDF, WS, L, L, L, WS, PDF, ON, PDF, BN, BN, ON, PDF            /* 18 entries */
208 };
209 
210 static const UBiDiLevel
211 testLevels11[]={
212     0, 0, 0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3,                     /* 20 entries */
213     3, 4, 4, 5, 5, 5, 4, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2,                     /* 20 entries */
214     2, 2, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0                            /* 18 entries */
215 };
216 
217 static const uint8_t
218 testVisualMap11[]={
219     0, 1, 2, 44, 43, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 31, 30, 29, 28, 27,          /* 20 entries */
220     26, 20, 21, 24, 23, 22, 25, 19, 18, 17, 16, 15, 14, 32, 33, 34, 35, 36, 37, 38, /* 20 entries */
221     39, 40, 41, 42, 3, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57           /* 18 entries */
222 };
223 
224 static const uint8_t
225 testText12[]={
226     NSM, WS, L, L, L, L, L, L, L, WS, L, L, L, L, WS,
227     R, R, R, R, R, WS, L, L, L, L, L, L, L, WS, WS, AL,
228     AL, AL, AL, WS, EN, EN, ES, EN, EN, CS, S, EN, EN, CS, WS,
229     EN, EN, WS, AL, AL, AL, AL, AL, B, L, L, L, L, L, L,
230     L, L, WS, AN, AN, CS, AN, AN, WS
231 };
232 
233 static const UBiDiLevel
234 testLevels12[]={
235     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 1, 2, 2, 1, 0, 2, 2, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 0
236 };
237 
238 static const uint8_t
239 testVisualMap12[]={
240     0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 19, 18, 17, 16, 15, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 40, 39, 38, 37, 36, 34, 35, 33, 31, 32, 30, 41, 52, 53, 51, 50, 48, 49, 47, 46, 45, 44, 43, 42, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69
241 };
242 
243 static const UBiDiLevel
244 testLevels13[]={
245     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 1, 2, 2, 1, 0, 2, 2, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 0
246 };
247 
248 static const uint8_t
249 testVisualMap13[]={
250     0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 19, 18, 17, 16, 15, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 40, 39, 38, 37, 36, 34, 35, 33, 31, 32, 30, 41, 52, 53, 51, 50, 48, 49, 47, 46, 45, 44, 43, 42, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69
251 };
252 
253 static const UBiDiLevel
254 testLevels14[]={
255     2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 3, 4, 4, 3, 2, 4, 4, 3, 3, 4, 4, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 2
256 };
257 
258 static const uint8_t
259 testVisualMap14[]={
260     0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 19, 18, 17, 16, 15, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 40, 39, 38, 37, 36, 34, 35, 33, 31, 32, 30, 41, 52, 53, 51, 50, 48, 49, 47, 46, 45, 44, 43, 42, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69
261 };
262 
263 static const UBiDiLevel
264 testLevels15[]={
265     5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 6, 6, 5, 6, 6, 5, 5, 6, 6, 5, 5, 6, 6, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 5, 6, 6, 6, 6, 6, 5
266 };
267 
268 static const uint8_t
269 testVisualMap15[]={
270     69, 68, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 55, 54, 53, 52, 51, 50, 49, 42, 43, 44, 45, 46, 47, 48, 41, 40, 39, 38, 37, 36, 35, 33, 34, 32, 30, 31, 29, 28, 26, 27, 25, 24, 22, 23, 21, 20, 19, 18, 17, 16, 15, 7, 8, 9, 10, 11, 12, 13, 14, 6, 1, 2, 3, 4, 5, 0
271 };
272 
273 static const UBiDiLevel
274 testLevels16[]={
275     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 1, 2, 2, 1, 0, 2, 2, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 0
276 };
277 
278 static const uint8_t
279 testVisualMap16[]={
280     0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 19, 18, 17, 16, 15, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 40, 39, 38, 37, 36, 34, 35, 33, 31, 32, 30, 41, 52, 53, 51, 50, 48, 49, 47, 46, 45, 44, 43, 42, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69
281 };
282 
283 static const uint8_t
284 testText13[]={
285     ON, L, RLO, CS, R, WS, AN, AN, PDF, LRE, R, L, LRO, WS, BN, ON, S, LRE, LRO, B
286 };
287 
288 static const UBiDiLevel
289 testLevels17[]={
290     0, 0, 1, 1, 1, 1, 1, 1, 3, 3, 3, 2, 4, 4, 4, 4, 0, 0, 0, 0
291 };
292 
293 static const uint8_t
294 testVisualMap17[]={
295     0, 1, 15, 14, 13, 12, 11, 10, 4, 3, 2, 5, 6, 7, 8, 9, 16, 17, 18, 19
296 };
297 
298 static const UBiDiLevel
299 testLevels18[]={
300     0, 0, 1, 1, 1, 0
301 };
302 
303 static const uint8_t
304 testVisualMap18[]={
305     0, 1, 4, 3, 2, 5
306 };
307 
308 static const uint8_t
309 testText14[]={
310     RLO, RLO, AL, AL, WS, EN, ES, ON, WS, S, S, PDF, LRO, WS, AL, ET, RLE, ON, EN, B
311 };
312 
313 static const UBiDiLevel
314 testLevels19[]={
315     1
316 };
317 
318 static const uint8_t
319 testVisualMap19[]={
320     0
321 };
322 
323 static const uint8_t
324 testText15[]={
325     R, L, CS, L
326 };
327 
328 static const UBiDiLevel
329 testLevels20[]={
330     2
331 };
332 
333 static const uint8_t
334 testText16[]={
335     L, L, L, WS, L, L, L, WS, L, L, L
336 };
337 
338 static const UBiDiLevel
339 testLevels21[]={
340     2, 2, 2, 2, 2, 2, 2, 1
341 };
342 
343 static const uint8_t
344 testVisualMap20[]={
345     1, 2, 3, 4, 5, 6, 7, 0
346 };
347 
348 static const uint8_t
349 testText17[]={
350     R, R, R, WS, R, R, R, WS, R, R, R
351 };
352 
353 static const UBiDiLevel
354 testLevels22[]={
355     1, 1, 1, 1, 1, 1, 1, 0
356 };
357 
358 static const uint8_t
359 testVisualMap21[]={
360     6, 5, 4, 3, 2, 1, 0, 7
361 };
362 
363 static const uint8_t
364 testTextXX[]={
365     L
366 };
367 
368 static const UBiDiLevel
369 testLevelsXX[]={
370     2
371 };
372 
373 static const uint8_t
374 testVisualMapXX[]={
375     0
376 };
377 
378 const BiDiTestData
379 tests[]={
380     {testText1,  UPRV_LENGTHOF(testText1),  UBIDI_DEFAULT_LTR, -1, -1,
381         UBIDI_LTR, 0,
382         testLevels1, testVisualMap1},
383     {testText2,  UPRV_LENGTHOF(testText2),  UBIDI_DEFAULT_LTR, -1, -1,
384         UBIDI_RTL, 1,
385         testLevels2, testVisualMap2},
386     {testText3,  UPRV_LENGTHOF(testText3),  UBIDI_DEFAULT_LTR, -1, -1,
387         UBIDI_LTR, 0,
388         testLevels3, testVisualMap3},
389     {testText4,  UPRV_LENGTHOF(testText4),  UBIDI_DEFAULT_LTR, -1, -1,
390         UBIDI_MIXED, 0,
391         testLevels4, testVisualMap4},
392     {testText5,  UPRV_LENGTHOF(testText5),  UBIDI_DEFAULT_LTR, -1, -1,
393         UBIDI_MIXED, 1,
394         testLevels5, testVisualMap5},
395     {testText6,  UPRV_LENGTHOF(testText6),  UBIDI_DEFAULT_LTR, -1, -1,
396         UBIDI_MIXED, 1,
397         testLevels6, testVisualMap6},
398     {NULL,       0,                        UBIDI_DEFAULT_LTR, -1, -1,
399         UBIDI_LTR, 0,
400         NULL, NULL},
401     {testText8,  UPRV_LENGTHOF(testText8),  UBIDI_DEFAULT_LTR, -1, -1,
402         UBIDI_RTL, 1,
403         testLevels8, testVisualMap8},
404     {testText9,  UPRV_LENGTHOF(testText9),  64, -1, -1,
405         UBIDI_MIXED, 64,
406         testLevels9, testVisualMap9},
407     {testText10, UPRV_LENGTHOF(testText10), 64, -1, -1,
408         UBIDI_MIXED, 64,
409         testLevels10, testVisualMap10},
410     {testText11, UPRV_LENGTHOF(testText11), UBIDI_DEFAULT_LTR, -1, -1,
411         UBIDI_MIXED, 0,
412         testLevels11, testVisualMap11},
413     {testText12, UPRV_LENGTHOF(testText12), UBIDI_DEFAULT_LTR, -1, -1,
414         UBIDI_MIXED, 0,
415         testLevels12, testVisualMap12},
416     {testText12, UPRV_LENGTHOF(testText12), UBIDI_DEFAULT_RTL, -1, -1,
417         UBIDI_MIXED, 0,
418         testLevels13, testVisualMap13},
419     {testText12, UPRV_LENGTHOF(testText12), 2, -1, -1,
420         UBIDI_MIXED, 2,
421         testLevels14, testVisualMap14},
422     {testText12, UPRV_LENGTHOF(testText12), 5, -1, -1,
423         UBIDI_MIXED, 5,
424         testLevels15, testVisualMap15},
425     {testText12, UPRV_LENGTHOF(testText12), UBIDI_DEFAULT_LTR, -1, -1,
426         UBIDI_MIXED, 0,
427         testLevels16, testVisualMap16},
428     {testText13, UPRV_LENGTHOF(testText13), UBIDI_DEFAULT_LTR, -1, -1,
429         UBIDI_MIXED, 0,
430         testLevels17, testVisualMap17},
431     {testText13, UPRV_LENGTHOF(testText13), UBIDI_DEFAULT_LTR, 0, 6,
432         UBIDI_MIXED, 0,
433         testLevels18, testVisualMap18},
434     {testText14, UPRV_LENGTHOF(testText14), UBIDI_DEFAULT_LTR, 13, 14,
435         UBIDI_RTL, 1,
436         testLevels19, testVisualMap19},
437     {testText15, UPRV_LENGTHOF(testText15), UBIDI_DEFAULT_LTR, 2, 3,
438         UBIDI_LTR, 2,
439         testLevels20, testVisualMap19},
440     {testText16, UPRV_LENGTHOF(testText16), UBIDI_RTL, 0, 8,
441         UBIDI_MIXED, 1,
442         testLevels21, testVisualMap20},
443     {testText17, UPRV_LENGTHOF(testText17), UBIDI_LTR, 0, 8,
444         UBIDI_MIXED, 0,
445         testLevels22, testVisualMap21},
446     {testTextXX, UPRV_LENGTHOF(testTextXX), UBIDI_RTL, -1, -1,
447         UBIDI_MIXED, 1, testLevelsXX, testVisualMapXX}
448 };
449 
450 const int
451 bidiTestCount=UPRV_LENGTHOF(tests);
452