1 // 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html#License 3 /* 4 ******************************************************************************* 5 * Copyright (C) 2001-2013, International Business Machines 6 * Corporation and others. All Rights Reserved. 7 ******************************************************************************* 8 */ 9 10 package com.ibm.icu.dev.test.bidi; 11 12 import com.ibm.icu.lang.UCharacterDirection; 13 import com.ibm.icu.text.Bidi; 14 15 16 /** 17 * Data and helper methods for Bidi regression tests 18 * 19 * Ported from C by Lina Kemmel, Matitiahu Allouche 20 * 21 */ 22 public class TestData { 23 protected static final int L = UCharacterDirection.LEFT_TO_RIGHT; 24 protected static final int R = UCharacterDirection.RIGHT_TO_LEFT; 25 protected static final int EN = UCharacterDirection.EUROPEAN_NUMBER; 26 protected static final int ES = UCharacterDirection.EUROPEAN_NUMBER_SEPARATOR; 27 protected static final int ET = UCharacterDirection.EUROPEAN_NUMBER_TERMINATOR; 28 protected static final int AN = UCharacterDirection.ARABIC_NUMBER; 29 protected static final int CS = UCharacterDirection.COMMON_NUMBER_SEPARATOR; 30 protected static final int B = UCharacterDirection.BLOCK_SEPARATOR; 31 protected static final int S = UCharacterDirection.SEGMENT_SEPARATOR; 32 protected static final int WS = UCharacterDirection.WHITE_SPACE_NEUTRAL; 33 protected static final int ON = UCharacterDirection.OTHER_NEUTRAL; 34 protected static final int LRE = UCharacterDirection.LEFT_TO_RIGHT_EMBEDDING; 35 protected static final int LRO = UCharacterDirection.LEFT_TO_RIGHT_OVERRIDE; 36 protected static final int AL = UCharacterDirection.RIGHT_TO_LEFT_ARABIC; 37 protected static final int RLE = UCharacterDirection.RIGHT_TO_LEFT_EMBEDDING; 38 protected static final int RLO = UCharacterDirection.RIGHT_TO_LEFT_OVERRIDE; 39 protected static final int PDF = UCharacterDirection.POP_DIRECTIONAL_FORMAT; 40 protected static final int NSM = UCharacterDirection.DIR_NON_SPACING_MARK; 41 protected static final int BN = UCharacterDirection.BOUNDARY_NEUTRAL; 42 protected static final int FSI = UCharacterDirection.FIRST_STRONG_ISOLATE; 43 protected static final int LRI = UCharacterDirection.LEFT_TO_RIGHT_ISOLATE; 44 protected static final int RLI = UCharacterDirection.RIGHT_TO_LEFT_ISOLATE; 45 protected static final int PDI = UCharacterDirection.POP_DIRECTIONAL_ISOLATE; 46 protected static final int DEF = Bidi.CLASS_DEFAULT; 47 48 protected static final String[] dirPropNames = { 49 "L", "R", "EN", "ES", "ET", "AN", "CS", "B", "S", "WS", "ON", 50 "LRE", "LRO", "AL", "RLE", "RLO", "PDF", "NSM", "BN", 51 "FSI", "LRI", "RLI", "PDI" /* new in Unicode 6.3/ICU 52 */ 52 }; 53 protected static final short[][] testDirProps = { 54 { L, L, WS, L, WS, EN, L, B }, // 0 55 { R, AL, WS, R, AL, WS, R }, // 1 56 { L, L, WS, EN, CS, WS, EN, CS, EN, WS, L, L }, // 2 57 { L, AL, AL, AL, L, AL, AL, L, WS, EN, CS, WS, EN, CS, EN, WS, L, L }, // 3 58 { AL, R, AL, WS, EN, CS, WS, EN, CS, EN, WS, R, R, WS, L, L }, // 4 59 { R, EN, NSM, ET }, // 5 60 { RLE, WS, R, R, R, WS, PDF, WS, B }, // 6 61 { 62 LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, /* 15 entries */ 63 LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, /* 15 entries */ 64 AN, RLO, NSM, LRE, PDF, RLE, ES, EN, ON /* 9 entries */ 65 }, //7 66 { 67 LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, /* 15 entries */ 68 LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, LRE, /* 15 entries */ 69 LRE, BN, CS, RLO, S, PDF, EN, LRO, AN, ES /* 10 entries */ 70 }, // 8 71 { S, WS, NSM, RLE, WS, L, L, L, WS, LRO, WS, R, R, R, WS, RLO, WS, L, L, 72 L, WS, LRE, WS, R, R, R, WS, PDF, WS, L, L, L, WS, PDF, WS, AL, AL, 73 AL, WS, PDF, WS, L, L, L, WS, PDF, WS, L, L, L, WS, PDF, ON, PDF, 74 BN, BN, ON, PDF }, // 9 75 { NSM, WS, L, L, L, L, L, L, L, WS, L, L, L, L, WS, R, R, R, R, R, WS, 76 L, L, L, L, L, L, L, WS, WS, AL, AL, AL, AL, WS, EN, EN, ES, EN, 77 EN, CS, S, EN, EN, CS, WS, EN, EN, WS, AL, AL, AL, AL, AL, B, L, L, 78 L, L, L, L, L, L, WS, AN, AN, CS, AN, AN, WS }, // 10 79 { NSM, WS, L, L, L, L, L, L, L, WS, L, L, L, L, WS, R, R, R, R, R, WS, 80 L, L, L, L, L, L, L, WS, WS, AL, AL, AL, AL, WS, EN, EN, ES, EN, 81 EN, CS, S, EN, EN, CS, WS, EN, EN, WS, AL, AL, AL, AL, AL, B, L, L, 82 L, L, L, L, L, L, WS, AN, AN, CS, AN, AN, WS }, // 11 83 { NSM, WS, L, L, L, L, L, L, L, WS, L, L, L, L, WS, R, R, R, R, R, WS, 84 L, L, L, L, L, L, L, WS, WS, AL, AL, AL, AL, WS, EN, EN, ES, EN, 85 EN, CS, S, EN, EN, CS, WS, EN, EN, WS, AL, AL, AL, AL, AL, B, L, L, 86 L, L, L, L, L, L, WS, AN, AN, CS, AN, AN, WS }, // 12 87 { NSM, WS, L, L, L, L, L, L, L, WS, L, L, L, L, WS, R, R, R, R, R, WS, 88 L, L, L, L, L, L, L, WS, WS, AL, AL, AL, AL, WS, EN, EN, ES, EN, 89 EN, CS, S, EN, EN, CS, WS, EN, EN, WS, AL, AL, AL, AL, AL, B, L, L, 90 L, L, L, L, L, L, WS, AN, AN, CS, AN, AN, WS }, // 13 91 { NSM, WS, L, L, L, L, L, L, L, WS, L, L, L, L, WS, R, R, R, R, R, WS, 92 L, L, L, L, L, L, L, WS, WS, AL, AL, AL, AL, WS, EN, EN, ES, EN, 93 EN, CS, S, EN, EN, CS, WS, EN, EN, WS, AL, AL, AL, AL, AL, B, L, L, 94 L, L, L, L, L, L, WS, AN, AN, CS, AN, AN, WS }, // 14 95 { ON, L, RLO, CS, R, WS, AN, AN, PDF, LRE, R, L, LRO, WS, BN, ON, S, 96 LRE, LRO, B }, // 15 97 { ON, L, RLO, CS, R, WS, AN, AN, PDF, LRE, R, L, LRO, WS, BN, ON, S, 98 LRE, LRO, B }, // 16 99 { RLO, RLO, AL, AL, WS, EN, ES, ON, WS, S, S, PDF, LRO, WS, AL, ET, RLE, 100 ON, EN, B }, // 17 101 { R, L, CS, L }, // 18 102 { L, L, L, WS, L, L, L, WS, L, L, L }, // 19 103 { R, R, R, WS, R, R, R, WS, R, R, R }, // 20 104 { L }, // 21 105 null // 22 106 }; 107 108 protected static final byte[][] testLevels = { 109 { 0, 0, 0, 0, 0, 0, 0, 0 }, // 0 110 { 1, 1, 1, 1, 1, 1, 1 }, // 1 111 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 2 112 { 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 3 113 { 1, 1, 1, 1, 2, 1, 1, 2, 2, 2, 1, 1, 1, 1, 2, 2 }, // 4 114 { 1, 2, 2, 2 }, // 5 115 { 1, 1, 1, 1, 1, 1, 1, 1, 1 }, // 6 116 { 117 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, /* 15 entries */ 118 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, /* 15 entries */ 119 126, 125, 125, 125, 125, 125, 125, 125, 125 /* 9 entries */ 120 }, // 7 121 { 122 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, /* 15 entries */ 123 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, /* 15 entries */ 124 124, 124, 124, 64, 64, 124, 124, 126, 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, 5, 143 6, 6, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 5, 6, 6, 6, 6, 6, 144 5 }, // 13 145 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 146 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 1, 2, 2, 1, 0, 2, 2, 1, 1, 147 2, 2, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 148 0 }, // 14 149 { 0, 0, 1, 1, 1, 1, 1, 1, 3, 3, 3, 2, 4, 4, 4, 4, 0, 0, 0, 0 }, // 15 150 { 0, 0, 1, 1, 1, 0 }, // 16 151 { 1 }, // 17 152 { 2 }, // 18 153 { 2, 2, 2, 2, 2, 2, 2, 1 }, // 19 154 { 1, 1, 1, 1, 1, 1, 1, 0 }, // 20 155 { 2 }, // 21 156 null // 22 157 }; 158 159 protected static final int[][] testVisualMaps = { 160 { 0, 1, 2, 3, 4, 5, 6, 7 }, // 0 161 { 6, 5, 4, 3, 2, 1, 0 }, // 1 162 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }, // 2 163 { 0, 3, 2, 1, 4, 6, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }, // 3 164 { 15, 14, 13, 12, 11, 10, 9, 6, 7, 8, 5, 4, 3, 2, 0, 1 }, // 4 165 { 3, 0, 1, 2 }, // 5 166 { 8, 7, 6, 5, 4, 3, 2, 1, 0 }, // 6 167 { 168 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, /* 15 entries */ 169 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, /* 15 entries */ 170 38, 7, 6, 5, 4, 3, 2, 1, 0 /* 9 entries */ 171 }, // 7 172 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 173 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 174 37, 38, 39 }, // 8 175 { 0, 1, 2, 44, 43, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 31, 30, 29, 28, 27, 176 26, 20, 21, 24, 23, 22, 25, 19, 18, 17, 16, 15, 14, 32, 33, 34, 35, 177 36, 37, 38, 39, 40, 41, 42, 3, 45, 46, 47, 48, 49, 50, 51, 52, 53, 178 54, 55, 56, 57 }, // 9 179 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 19, 18, 17, 16, 15, 180 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 40, 39, 38, 37, 36, 34, 35, 181 33, 31, 32, 30, 41, 52, 53, 51, 50, 48, 49, 47, 46, 45, 44, 43, 42, 182 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69 }, // 10 183 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 19, 18, 17, 16, 15, 184 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 40, 39, 38, 37, 36, 34, 35, 185 33, 31, 32, 30, 41, 52, 53, 51, 50, 48, 49, 47, 46, 45, 44, 43, 42, 186 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69 }, // 11 187 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 19, 18, 17, 16, 15, 188 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 40, 39, 38, 37, 36, 34, 35, 189 33, 31, 32, 30, 41, 52, 53, 51, 50, 48, 49, 47, 46, 45, 44, 43, 42, 190 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69 }, // 12 191 { 69, 68, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 55, 54, 53, 192 52, 51, 50, 49, 42, 43, 44, 45, 46, 47, 48, 41, 40, 39, 38, 37, 36, 193 35, 33, 34, 32, 30, 31, 29, 28, 26, 27, 25, 24, 22, 23, 21, 20, 19, 194 18, 17, 16, 15, 7, 8, 9, 10, 11, 12, 13, 14, 6, 1, 2, 3, 4, 5, 0 }, // 13 195 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 19, 18, 17, 16, 15, 196 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 40, 39, 38, 37, 36, 34, 35, 197 33, 31, 32, 30, 41, 52, 53, 51, 50, 48, 49, 47, 46, 45, 44, 43, 42, 198 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69 }, // 14 199 { 0, 1, 15, 14, 13, 12, 11, 10, 4, 3, 2, 5, 6, 7, 8, 9, 16, 17, 18, 19 }, // 15 200 { 0, 1, 4, 3, 2, 5 }, // 16 201 { 0 }, // 17 202 { 0 }, // 18 203 { 1, 2, 3, 4, 5, 6, 7, 0 }, // 19 204 { 6, 5, 4, 3, 2, 1, 0, 7 }, // 20 205 { 0 }, // 21 206 null // 22 207 }; 208 209 protected static final byte[] testParaLevels = { 210 Bidi.LEVEL_DEFAULT_LTR, Bidi.LEVEL_DEFAULT_LTR, Bidi.LEVEL_DEFAULT_LTR, 211 Bidi.LEVEL_DEFAULT_LTR, Bidi.LEVEL_DEFAULT_LTR, Bidi.LEVEL_DEFAULT_LTR, 212 Bidi.LEVEL_DEFAULT_LTR, 64, 64, 213 Bidi.LEVEL_DEFAULT_LTR, Bidi.LEVEL_DEFAULT_LTR, Bidi.LEVEL_DEFAULT_RTL, 214 2, 5, Bidi.LEVEL_DEFAULT_LTR, Bidi.LEVEL_DEFAULT_LTR, Bidi.LEVEL_DEFAULT_LTR, 215 Bidi.LEVEL_DEFAULT_LTR, Bidi.LEVEL_DEFAULT_LTR, Bidi.RTL, Bidi.LTR, Bidi.RTL, 216 Bidi.LEVEL_DEFAULT_LTR 217 }; 218 219 protected static final byte[] testDirections = { 220 Bidi.LTR, Bidi.RTL, Bidi.LTR, Bidi.MIXED, Bidi.MIXED, Bidi.MIXED, 221 Bidi.RTL, Bidi.MIXED, Bidi.MIXED, Bidi.MIXED, Bidi.MIXED, Bidi.MIXED, 222 Bidi.MIXED, Bidi.MIXED, Bidi.MIXED, Bidi.MIXED, Bidi.MIXED, Bidi.RTL, 223 Bidi.LTR, Bidi.MIXED, Bidi.MIXED, Bidi.MIXED, Bidi.LTR 224 }; 225 226 protected static final byte[] testResultLevels = new byte[] { 227 Bidi.LTR, Bidi.RTL, Bidi.LTR, Bidi.LTR, Bidi.RTL, Bidi.RTL, Bidi.RTL, 228 64, 64 , Bidi.LTR, Bidi.LTR, Bidi.LTR, 2, 5, Bidi.LTR, 229 Bidi.LTR, Bidi.LTR, Bidi.RTL, 2, Bidi.RTL, Bidi.LTR, Bidi.RTL, Bidi.LTR 230 }; 231 232 protected static final byte[] testLineStarts = { 233 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 13, 234 2, 0, 0, -1, -1 235 }; 236 237 protected static final byte[] testLineLimits = { 238 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 6, 14, 239 3, 8, 8, -1, -1 240 }; 241 242 protected short[] dirProps; 243 protected int lineStart; 244 protected int lineLimit; 245 protected byte direction; 246 protected byte paraLevel; 247 protected byte resultLevel; 248 protected byte[] levels; 249 protected int[] visualMap; 250 251 private TestData(short[] dirProps, int lineStart, int lineLimit, 252 byte direction, byte paraLevel, byte resultLevel, byte[] levels, 253 int[] visualMap) { 254 this.dirProps = dirProps; 255 this.lineStart = lineStart; 256 this.lineLimit = lineLimit; 257 this.direction = direction; 258 this.paraLevel = paraLevel; 259 this.resultLevel = resultLevel; 260 this.levels = levels; 261 this.visualMap = visualMap; 262 } 263 264 protected static TestData getTestData(int testNumber) { 265 return new TestData(testDirProps[testNumber], 266 testLineStarts[testNumber], testLineLimits[testNumber], 267 testDirections[testNumber], testParaLevels[testNumber], 268 testResultLevels[testNumber], testLevels[testNumber], 269 testVisualMaps[testNumber]); 270 } 271 272 protected static int testCount() { 273 return testDirProps.length; 274 } 275 } 276