1 /********************************************************************
2 * © 2016 and later: Unicode, Inc. and others.
3 * License & terms of use: http://www.unicode.org/copyright.html
4 ********************************************************************/
5 /* file name: cbiditransformtst.c
7 * tab size: 8 (not used)
10 * created on: 2016aug21
11 * created by: Lina Kemmel
15 #include "unicode/ubidi.h"
16 #include "unicode/ubiditransform.h"
17 #include "unicode/ushape.h"
18 #include "unicode/ustring.h"
24 #define LATN_ZERO 0x0030
25 #define ARAB_ZERO 0x0660
26 #define MIN_HEB_LETTER 0x05D0
27 #define MIN_ARAB_LETTER 0x0630 /* relevant to this test only */
28 #define MIN_SHAPED_LETTER 0xFEAB /* relevant to this test only */
30 #define STR_CAPACITY 100
32 #define NUM_LETTERS 5 /* Used for arrays hereafter */
33 static const UChar unshapedLetters
[NUM_LETTERS
+ 1] = {0x0630, 0, 0x0631, 0, 0x0632, 2};
34 static const UChar shapedLetters
[NUM_LETTERS
+ 1] = {0xfeab, 0, 0xfead, 0, 0xfeaf, 1};
41 const char *pReorderNoMirror
;
42 const char *pReorderAndMirror
;
43 const char *pContextShapes
;
47 UChar src
[STR_CAPACITY
] = { 0 };
48 UChar dest
[STR_CAPACITY
] = { 0 };
49 UChar expected
[STR_CAPACITY
] = { 0 };
50 UChar temp
[STR_CAPACITY
* 2] = { 0 };
51 char pseudo
[STR_CAPACITY
] = { 0 };
53 void addBidiTransformTest(TestNode
** root
);
55 static void testAutoDirection(void);
57 static void testAllTransformOptions(void);
59 static char* pseudoScript(const UChar
*str
);
61 static void shapeDigits(UChar
*str
, UChar srcZero
, UChar destZero
);
63 static void shapeLetters(UChar
*str
, const UChar
*from
, const UChar
*to
);
65 static void logResultsForDir(const UChar
*srcText
, const UChar
*destTxt
,
66 const UChar
*expectedTxt
, UBiDiLevel inLevel
, UBiDiLevel outLevel
);
68 static void verifyResultsForAllOpt(const UBidiTestCases
*pTest
, const UChar
*srcTxt
,
69 const UChar
*destTxt
, const char *expectedChars
, uint32_t digits
,
73 static void substituteByPseudoChar(const UChar
*src
, char *dest
,
74 const UChar baseReal
, const char basePseudo
, const char max
);
77 /* TODO: This code assumes the codepage is ASCII based. */
80 * Using the following conventions:
88 substituteByPseudoChar(const UChar
*src
, char *dest
, const UChar baseReal
,
89 const char basePseudo
, const char max
) {
90 *dest
= basePseudo
+ (*src
- baseReal
); /* (range math won't work on EBCDIC) */
97 pseudoScript(const UChar
*str
) {
100 for (; *str
; str
++, p
++) {
101 switch (u_charDirection(*str
)) {
102 case U_RIGHT_TO_LEFT
:
103 substituteByPseudoChar(str
, p
, MIN_HEB_LETTER
, 'K', 'Z');
105 case U_RIGHT_TO_LEFT_ARABIC
:
107 substituteByPseudoChar(str
, p
, MIN_SHAPED_LETTER
, 'F', 'J');
109 substituteByPseudoChar(str
, p
, MIN_ARAB_LETTER
, 'A', 'E');
112 case U_ARABIC_NUMBER
:
113 substituteByPseudoChar(str
, p
, ARAB_ZERO
, '5', '9');
126 pseudoScript(const UChar
*str
) {
127 return aescstrdup(str
, -1);
132 logResultsForDir(const UChar
*srcTxt
, const UChar
*destTxt
, const UChar
*expectedTxt
,
133 UBiDiLevel inLevel
, UBiDiLevel outLevel
)
135 if (u_strcmp(expectedTxt
, destTxt
)) {
136 log_err("Unexpected transform Dest: inLevel: 0x%02x; outLevel: 0x%02x;\ninText: %s; outText: %s; expected: %s\n",
137 inLevel
, outLevel
, pseudoScript(srcTxt
), pseudoScript(destTxt
), pseudoScript(expectedTxt
));
142 * Tests various combinations of base directions, with the input either
143 * <code>UBIDI_DEFAULT_LTR</code> or <code>UBIDI_DEFAULT_RTL</code>, and the
144 * output either <code>UBIDI_LTR</code> or <code>UBIDI_RTL</code>. Order is
145 * always <code>UBIDI_LOGICAL</code> for the input and <code>UBIDI_VISUAL</code>
149 testAutoDirection(void)
151 static const UBiDiLevel inLevels
[] = {
152 UBIDI_DEFAULT_LTR
, UBIDI_DEFAULT_RTL
154 static const UBiDiLevel outLevels
[] = {
157 static const char *srcTexts
[] = {
158 "abc \\u05d0\\u05d1",
159 "... abc \\u05d0\\u05d1",
160 "\\u05d0\\u05d1 abc",
161 "... \\u05d0\\u05d1 abc",
164 uint32_t nTexts
= sizeof(srcTexts
) / sizeof(srcTexts
[0]);
165 uint32_t i
, nInLevels
= sizeof(inLevels
) / sizeof(inLevels
[0]);
166 uint32_t j
, nOutLevels
= sizeof(outLevels
) / sizeof(outLevels
[0]);
168 UBiDi
*pBidi
= ubidi_open();
170 UErrorCode errorCode
= U_ZERO_ERROR
;
171 UBiDiTransform
*pTransform
= ubiditransform_open(&errorCode
);
173 while (nTexts
-- > 0) {
175 u_unescape(srcTexts
[nTexts
], src
, STR_CAPACITY
);
176 srcLen
= u_strlen(src
);
177 for (i
= 0; i
< nInLevels
; i
++) {
178 for (j
= 0; j
< nOutLevels
; j
++) {
179 ubiditransform_transform(pTransform
, src
, -1, dest
, STR_CAPACITY
- 1,
180 inLevels
[i
], UBIDI_LOGICAL
, outLevels
[j
], UBIDI_VISUAL
,
181 UBIDI_MIRRORING_OFF
, 0, &errorCode
);
182 /* Use UBiDi as a model we compare to */
183 ubidi_setPara(pBidi
, src
, srcLen
, inLevels
[i
], NULL
, &errorCode
);
184 ubidi_writeReordered(pBidi
, expected
, STR_CAPACITY
, UBIDI_REORDER_DEFAULT
, &errorCode
);
185 if (outLevels
[j
] == UBIDI_RTL
) {
186 ubidi_writeReverse(expected
, u_strlen(expected
), temp
, STR_CAPACITY
,
187 UBIDI_OUTPUT_REVERSE
, &errorCode
);
188 logResultsForDir(src
, dest
, temp
, inLevels
[i
], outLevels
[j
]);
190 logResultsForDir(src
, dest
, expected
, inLevels
[i
], outLevels
[j
]);
196 ubiditransform_close(pTransform
);
200 shapeDigits(UChar
*str
, UChar srcZero
, UChar destZero
)
203 uint32_t i
= 0, j
, length
= u_strlen(str
);
206 U16_NEXT(str
, i
, length
, c
);
207 if (c
>= srcZero
&& c
<= srcZero
+ 9) {
208 /* length of c here is always a single UChar16 */
209 str
[j
] = c
+ (destZero
- srcZero
);
215 shapeLetters(UChar
*str
, const UChar
*from
, const UChar
*to
)
217 uint32_t i
= 0, j
, length
= u_strlen(expected
), index
;
221 U16_NEXT(str
, i
, length
, c
);
223 if (index
< NUM_LETTERS
&& from
[index
* from
[NUM_LETTERS
]] != 0) {
224 /* The length of old and new values is always a single UChar16,
225 so can just assign a new value to str[j] */
226 str
[j
] = to
[index
* from
[NUM_LETTERS
]];
232 verifyResultsForAllOpt(const UBidiTestCases
*pTest
, const UChar
*srcTxt
,
233 const UChar
*destTxt
, const char *expectedChars
, uint32_t digits
, uint32_t letters
)
235 u_unescape(expectedChars
, expected
, STR_CAPACITY
);
238 case U_SHAPE_DIGITS_EN2AN
:
239 shapeDigits(expected
, LATN_ZERO
, ARAB_ZERO
);
241 case U_SHAPE_DIGITS_AN2EN
:
242 shapeDigits(expected
, ARAB_ZERO
, LATN_ZERO
);
248 case U_SHAPE_LETTERS_SHAPE
:
249 shapeLetters(expected
, unshapedLetters
, shapedLetters
);
251 case U_SHAPE_LETTERS_UNSHAPE
:
252 shapeLetters(expected
, shapedLetters
, unshapedLetters
);
255 if (u_strcmp(expected
, dest
)) {
256 log_err("Unexpected transform Dest: Test: %s; Digits: 0x%08x; Letters: 0x%08x\ninText: %s; outText: %s; expected: %s\n",
257 pTest
->pMessage
, digits
, letters
, pseudoScript(srcTxt
), pseudoScript(destTxt
), pseudoScript(expected
));
262 * This function covers:
264 * <li>all possible combinations of ordering schemes and <strong>explicit</strong>
265 * base directions, applied to both input and output,</li>
266 * <li>selected tests for auto direction (systematically, auto direction is
267 * covered in a dedicated test) applied on both input and output,</li>
268 * <li>all possible combinations of mirroring, digits and letters applied
269 * to output only.</li>
273 testAllTransformOptions(void)
275 static const char *inText
=
276 "a[b]c \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 1 d \\u0630 23\\u0660 e\\u06314 f \\ufeaf \\u0661\\u0662";
278 static const UBidiTestCases testCases
[] = {
279 { UBIDI_LTR
, UBIDI_LOGICAL
, UBIDI_LTR
, UBIDI_LOGICAL
,
280 "a[b]c \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 1 d \\u0630 23\\u0660 e\\u06314 f \\ufeaf \\u0661\\u0662", // reordering no mirroring
281 "a[b]c \\u05d0)\\u05d1\\u05d2 \\u05d3(\\u05d4 1 d \\u0630 23\\u0660 e\\u06314 f \\ufeaf \\u0661\\u0662", // mirroring
282 "a[b]c \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 1 d \\u0630 \\u0662\\u0663\\u0660 e\\u0631\\u0664 f \\ufeaf \\u0661\\u0662", // context numeric shaping
283 "1: Logical LTR ==> Logical LTR" },
284 { UBIDI_LTR
, UBIDI_LOGICAL
, UBIDI_LTR
, UBIDI_VISUAL
,
285 "a[b]c 1 \\u05d4)\\u05d3 \\u05d2\\u05d1(\\u05d0 d 23\\u0660 \\u0630 e4\\u0631 f \\u0661\\u0662 \\ufeaf",
286 "a[b]c 1 \\u05d4(\\u05d3 \\u05d2\\u05d1)\\u05d0 d 23\\u0660 \\u0630 e4\\u0631 f \\u0661\\u0662 \\ufeaf",
287 "a[b]c 1 \\u05d4)\\u05d3 \\u05d2\\u05d1(\\u05d0 d \\u0662\\u0663\\u0660 \\u0630 e\\u0664\\u0631 f \\u0661\\u0662 \\ufeaf",
288 "2: Logical LTR ==> Visual LTR" },
289 { UBIDI_LTR
, UBIDI_LOGICAL
, UBIDI_RTL
, UBIDI_LOGICAL
,
290 "\\ufeaf \\u0661\\u0662 f \\u0631e4 \\u0630 23\\u0660 d \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 1 a[b]c",
291 "\\ufeaf \\u0661\\u0662 f \\u0631e4 \\u0630 23\\u0660 d \\u05d0)\\u05d1\\u05d2 \\u05d3(\\u05d4 1 a[b]c",
292 "\\ufeaf \\u0661\\u0662 f \\u0631e\\u0664 \\u0630 \\u0662\\u0663\\u0660 d \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 1 a[b]c",
293 "3: Logical LTR ==> Logical RTL" },
294 { UBIDI_LTR
, UBIDI_LOGICAL
, UBIDI_RTL
, UBIDI_VISUAL
,
295 "\\ufeaf \\u0662\\u0661 f \\u06314e \\u0630 \\u066032 d \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 1 c]b[a",
296 "\\ufeaf \\u0662\\u0661 f \\u06314e \\u0630 \\u066032 d \\u05d0)\\u05d1\\u05d2 \\u05d3(\\u05d4 1 c]b[a",
297 "\\ufeaf \\u0662\\u0661 f \\u0631\\u0664e \\u0630 \\u0660\\u0663\\u0662 d \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 1 c]b[a",
298 "4: Logical LTR ==> Visual RTL" },
299 { UBIDI_RTL
, UBIDI_LOGICAL
, UBIDI_RTL
, UBIDI_LOGICAL
,
300 "a[b]c \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 1 d \\u0630 23\\u0660 e\\u06314 f \\ufeaf \\u0661\\u0662",
301 "a[b]c \\u05d0)\\u05d1\\u05d2 \\u05d3(\\u05d4 1 d \\u0630 23\\u0660 e\\u06314 f \\ufeaf \\u0661\\u0662", // mirroring
302 "a[b]c \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 1 d \\u0630 23\\u0660 e\\u06314 f \\ufeaf \\u0661\\u0662",
303 "5: Logical RTL ==> Logical RTL" },
304 { UBIDI_RTL
, UBIDI_LOGICAL
, UBIDI_RTL
, UBIDI_VISUAL
,
305 "c]b[a \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 1 d \\u0630 \\u066032 e\\u06314 f \\ufeaf \\u0662\\u0661",
306 "c]b[a \\u05d0)\\u05d1\\u05d2 \\u05d3(\\u05d4 1 d \\u0630 \\u066032 e\\u06314 f \\ufeaf \\u0662\\u0661",
307 "c]b[a \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 1 d \\u0630 \\u066032 e\\u06314 f \\ufeaf \\u0662\\u0661",
308 "6: Logical RTL ==> Visual RTL" },
309 { UBIDI_RTL
, UBIDI_LOGICAL
, UBIDI_LTR
, UBIDI_LOGICAL
,
310 "\\ufeaf \\u0661\\u0662 f 4\\u0631e 23\\u0630 \\u0660 d 1 \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 a[b]c",
311 "\\ufeaf \\u0661\\u0662 f 4\\u0631e 23\\u0630 \\u0660 d 1 \\u05d0)\\u05d1\\u05d2 \\u05d3(\\u05d4 a[b]c",
312 "\\ufeaf \\u0661\\u0662 f 4\\u0631e 23\\u0630 \\u0660 d 1 \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 a[b]c",
313 "7: Logical RTL ==> Logical LTR" },
314 { UBIDI_RTL
, UBIDI_LOGICAL
, UBIDI_LTR
, UBIDI_VISUAL
,
315 "\\u0661\\u0662 \\ufeaf f 4\\u0631e 23\\u0660 \\u0630 d 1 \\u05d4)\\u05d3 \\u05d2\\u05d1(\\u05d0 a[b]c",
316 "\\u0661\\u0662 \\ufeaf f 4\\u0631e 23\\u0660 \\u0630 d 1 \\u05d4(\\u05d3 \\u05d2\\u05d1)\\u05d0 a[b]c",
317 "\\u0661\\u0662 \\ufeaf f 4\\u0631e 23\\u0660 \\u0630 d 1 \\u05d4)\\u05d3 \\u05d2\\u05d1(\\u05d0 a[b]c",
318 "8: Logical RTL ==> Visual LTR" },
319 { UBIDI_LTR
, UBIDI_VISUAL
, UBIDI_LTR
, UBIDI_VISUAL
,
320 "a[b]c \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 1 d \\u0630 23\\u0660 e\\u06314 f \\ufeaf \\u0661\\u0662",
321 "a[b]c \\u05d0)\\u05d1\\u05d2 \\u05d3(\\u05d4 1 d \\u0630 23\\u0660 e\\u06314 f \\ufeaf \\u0661\\u0662", // mirroring
322 "a[b]c \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 1 d \\u0630 \\u0662\\u0663\\u0660 e\\u0631\\u0664 f \\ufeaf \\u0661\\u0662",
323 "9: Visual LTR ==> Visual LTR" },
324 { UBIDI_LTR
, UBIDI_VISUAL
, UBIDI_LTR
, UBIDI_LOGICAL
,
325 "a[b]c 1 \\u05d4)\\u05d3 \\u05d2\\u05d1(\\u05d0 d 23\\u0660 \\u0630 e4\\u0631 f \\u0661\\u0662 \\ufeaf",
326 "a[b]c 1 \\u05d4(\\u05d3 \\u05d2\\u05d1)\\u05d0 d 23\\u0660 \\u0630 e4\\u0631 f \\u0661\\u0662 \\ufeaf",
327 "a[b]c 1 \\u05d4)\\u05d3 \\u05d2\\u05d1(\\u05d0 d 23\\u0660 \\u0630 e4\\u0631 f \\u0661\\u0662 \\ufeaf",
328 "10: Visual LTR ==> Logical LTR" },
329 { UBIDI_LTR
, UBIDI_VISUAL
, UBIDI_RTL
, UBIDI_VISUAL
,
330 "\\u0662\\u0661 \\ufeaf f 4\\u0631e \\u066032 \\u0630 d 1 \\u05d4)\\u05d3 \\u05d2\\u05d1(\\u05d0 c]b[a",
331 "\\u0662\\u0661 \\ufeaf f 4\\u0631e \\u066032 \\u0630 d 1 \\u05d4(\\u05d3 \\u05d2\\u05d1)\\u05d0 c]b[a",
332 "\\u0662\\u0661 \\ufeaf f \\u0664\\u0631e \\u0660\\u0663\\u0662 \\u0630 d 1 \\u05d4)\\u05d3 \\u05d2\\u05d1(\\u05d0 c]b[a",
333 "11: Visual LTR ==> Visual RTL" },
334 { UBIDI_LTR
, UBIDI_VISUAL
, UBIDI_RTL
, UBIDI_LOGICAL
,
335 "\\u0661\\u0662 \\ufeaf f 4\\u0631e 23\\u0660 \\u0630 d 1 \\u05d4)\\u05d3 \\u05d2\\u05d1(\\u05d0 a[b]c",
336 "\\u0661\\u0662 \\ufeaf f 4\\u0631e 23\\u0660 \\u0630 d 1 \\u05d4(\\u05d3 \\u05d2\\u05d1)\\u05d0 a[b]c",
337 "\\u0661\\u0662 \\ufeaf f \\u0664\\u0631e \\u0662\\u0663\\u0660 \\u0630 d 1 \\u05d4)\\u05d3 \\u05d2\\u05d1(\\u05d0 a[b]c",
338 "12: Visual LTR ==> Logical RTL" },
339 { UBIDI_RTL
, UBIDI_VISUAL
, UBIDI_RTL
, UBIDI_VISUAL
,
340 "a[b]c \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 1 d \\u0630 23\\u0660 e\\u06314 f \\ufeaf \\u0661\\u0662",
341 "a[b]c \\u05d0)\\u05d1\\u05d2 \\u05d3(\\u05d4 1 d \\u0630 23\\u0660 e\\u06314 f \\ufeaf \\u0661\\u0662",
342 "a[b]c \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 1 d \\u0630 23\\u0660 e\\u06314 f \\ufeaf \\u0661\\u0662",
343 "13: Visual RTL ==> Visual RTL" },
344 { UBIDI_RTL
, UBIDI_VISUAL
, UBIDI_RTL
, UBIDI_LOGICAL
,
345 "c]b[a \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 1 d \\u0630 \\u066032 e\\u06314 f \\ufeaf \\u0662\\u0661",
346 "c]b[a \\u05d0)\\u05d1\\u05d2 \\u05d3(\\u05d4 1 d \\u0630 \\u066032 e\\u06314 f \\ufeaf \\u0662\\u0661",
347 "c]b[a \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 1 d \\u0630 \\u066032 e\\u06314 f \\ufeaf \\u0662\\u0661",
348 "14: Visual RTL ==> Logical RTL" },
349 { UBIDI_RTL
, UBIDI_VISUAL
, UBIDI_LTR
, UBIDI_VISUAL
,
350 "\\u0662\\u0661 \\ufeaf f 4\\u0631e \\u066032 \\u0630 d 1 \\u05d4)\\u05d3 \\u05d2\\u05d1(\\u05d0 c]b[a",
351 "\\u0662\\u0661 \\ufeaf f 4\\u0631e \\u066032 \\u0630 d 1 \\u05d4(\\u05d3 \\u05d2\\u05d1)\\u05d0 c]b[a",
352 "\\u0662\\u0661 \\ufeaf f 4\\u0631e \\u066032 \\u0630 d 1 \\u05d4)\\u05d3 \\u05d2\\u05d1(\\u05d0 c]b[a",
353 "15: Visual RTL ==> Visual LTR" },
354 { UBIDI_RTL
, UBIDI_VISUAL
, UBIDI_LTR
, UBIDI_LOGICAL
,
355 "\\ufeaf \\u0662\\u0661 f 4\\u0631e \\u066032 \\u0630 d 1 \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 c]b[a",
356 "\\ufeaf \\u0662\\u0661 f 4\\u0631e \\u066032 \\u0630 d 1 \\u05d0)\\u05d1\\u05d2 \\u05d3(\\u05d4 c]b[a",
357 "\\ufeaf \\u0662\\u0661 f 4\\u0631e \\u066032 \\u0630 d 1 \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 c]b[a",
358 "16: Visual RTL ==> Logical LTR" },
359 { UBIDI_DEFAULT_RTL
, UBIDI_LOGICAL
, UBIDI_LTR
, UBIDI_VISUAL
,
360 "a[b]c 1 \\u05d4)\\u05d3 \\u05d2\\u05d1(\\u05d0 d 23\\u0660 \\u0630 e4\\u0631 f \\u0661\\u0662 \\ufeaf",
361 "a[b]c 1 \\u05d4(\\u05d3 \\u05d2\\u05d1)\\u05d0 d 23\\u0660 \\u0630 e4\\u0631 f \\u0661\\u0662 \\ufeaf",
362 "a[b]c 1 \\u05d4)\\u05d3 \\u05d2\\u05d1(\\u05d0 d \\u0662\\u0663\\u0660 \\u0630 e\\u0664\\u0631 f \\u0661\\u0662 \\ufeaf",
363 "17: Logical DEFAULT_RTL ==> Visual LTR" },
364 { UBIDI_RTL
, UBIDI_LOGICAL
, UBIDI_DEFAULT_LTR
, UBIDI_VISUAL
,
365 "c]b[a \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 1 d \\u0630 \\u066032 e\\u06314 f \\ufeaf \\u0662\\u0661",
366 "c]b[a \\u05d0)\\u05d1\\u05d2 \\u05d3(\\u05d4 1 d \\u0630 \\u066032 e\\u06314 f \\ufeaf \\u0662\\u0661",
367 "c]b[a \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 1 d \\u0630 \\u066032 e\\u06314 f \\ufeaf \\u0662\\u0661",
368 "18: Logical RTL ==> Visual DEFAULT_LTR" },
369 { UBIDI_DEFAULT_LTR
, UBIDI_LOGICAL
, UBIDI_LTR
, UBIDI_VISUAL
,
370 "a[b]c 1 \\u05d4)\\u05d3 \\u05d2\\u05d1(\\u05d0 d 23\\u0660 \\u0630 e4\\u0631 f \\u0661\\u0662 \\ufeaf",
371 "a[b]c 1 \\u05d4(\\u05d3 \\u05d2\\u05d1)\\u05d0 d 23\\u0660 \\u0630 e4\\u0631 f \\u0661\\u0662 \\ufeaf",
372 "a[b]c 1 \\u05d4)\\u05d3 \\u05d2\\u05d1(\\u05d0 d \\u0662\\u0663\\u0660 \\u0630 e\\u0664\\u0631 f \\u0661\\u0662 \\ufeaf",
373 "19: Logical DEFAULT_LTR ==> Visual LTR" },
374 { UBIDI_RTL
, UBIDI_LOGICAL
, UBIDI_DEFAULT_RTL
, UBIDI_VISUAL
,
375 "c]b[a \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 1 d \\u0630 \\u066032 e\\u06314 f \\ufeaf \\u0662\\u0661",
376 "c]b[a \\u05d0)\\u05d1\\u05d2 \\u05d3(\\u05d4 1 d \\u0630 \\u066032 e\\u06314 f \\ufeaf \\u0662\\u0661",
377 "c]b[a \\u05d0(\\u05d1\\u05d2 \\u05d3)\\u05d4 1 d \\u0630 \\u066032 e\\u06314 f \\ufeaf \\u0662\\u0661",
378 "20: Logical RTL ==> Visual DEFAULT_RTL" }
380 static const uint32_t digits
[] = {
382 U_SHAPE_DIGITS_AN2EN
,
383 U_SHAPE_DIGITS_EN2AN
,
384 U_SHAPE_DIGITS_ALEN2AN_INIT_LR
386 static const uint32_t letters
[] = {
387 U_SHAPE_LETTERS_UNSHAPE
,
388 U_SHAPE_LETTERS_SHAPE
390 const char *expectedStr
;
391 uint32_t i
, nTestCases
= sizeof(testCases
) / sizeof(testCases
[0]);
392 uint32_t j
, nDigits
= sizeof(digits
) / sizeof(digits
[0]);
393 uint32_t k
, nLetters
= sizeof(letters
) / sizeof(letters
[0]);
395 UErrorCode errorCode
= U_ZERO_ERROR
;
396 UBiDiTransform
*pTransform
= ubiditransform_open(&errorCode
);
398 u_unescape(inText
, src
, STR_CAPACITY
);
400 // Test various combinations of base levels, orders, mirroring, digits and letters
401 for (i
= 0; i
< nTestCases
; i
++) {
402 expectedStr
= testCases
[i
].pReorderAndMirror
;
403 ubiditransform_transform(pTransform
, src
, -1, dest
, STR_CAPACITY
,
404 testCases
[i
].inLevel
, testCases
[i
].inOr
,
405 testCases
[i
].outLevel
, testCases
[i
].outOr
,
406 UBIDI_MIRRORING_ON
, 0, &errorCode
);
407 verifyResultsForAllOpt(&testCases
[i
], src
, dest
, expectedStr
, U_SHAPE_DIGITS_NOOP
,
408 U_SHAPE_LETTERS_NOOP
);
410 for (j
= 0; j
< nDigits
; j
++) {
411 expectedStr
= digits
[j
] == U_SHAPE_DIGITS_ALEN2AN_INIT_LR
? testCases
[i
].pContextShapes
412 : testCases
[i
].pReorderNoMirror
;
413 for (k
= 0; k
< nLetters
; k
++) {
414 /* Use here NULL for pTransform */
415 ubiditransform_transform(NULL
, src
, -1, dest
, STR_CAPACITY
,
416 testCases
[i
].inLevel
, testCases
[i
].inOr
,
417 testCases
[i
].outLevel
, testCases
[i
].outOr
,
418 UBIDI_MIRRORING_OFF
, digits
[j
] | letters
[k
],
420 verifyResultsForAllOpt(&testCases
[i
], src
, dest
, expectedStr
, digits
[j
],
425 ubiditransform_close(pTransform
);
429 addBidiTransformTest(TestNode
** root
)
431 addTest(root
, testAutoDirection
, "complex/bidi-transform/TestAutoDirection");
432 addTest(root
, testAllTransformOptions
, "complex/bidi-transform/TestAllTransformOptions");