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