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