private void _testReordering(Bidi bidi, int testNumber) { int[] logicalMap1; int[] logicalMap2; int[] logicalMap3; int[] visualMap1; int[] visualMap2; int[] visualMap3; int[] visualMap4 = new int[MAXLEN]; sbyte[] levels; int i, length = bidi.GetLength(), destLength = bidi.GetResultLength(); int runCount, visualIndex, logicalIndex = -1, logicalStart, runLength; bool odd; if (length <= 0) { return; } /* get the logical and visual maps from the object */ logicalMap1 = bidi.GetLogicalMap(); if (logicalMap1 == null) { Errln("getLogicalMap in test " + testNumber + " is null"); logicalMap1 = new int[0]; } visualMap1 = bidi.GetVisualMap(); if (visualMap1 == null) { Errln("getVisualMap() in test " + testNumber + " is null"); visualMap1 = new int[0]; } /* invert them both */ visualMap2 = IBM.ICU.Text.Bidi.InvertMap(logicalMap1); logicalMap2 = IBM.ICU.Text.Bidi.InvertMap(visualMap1); /* get them from the levels array, too */ levels = bidi.GetLevels(); if (levels == null || levels.Length != length) { Errln("getLevels() in test " + testNumber + " failed"); } logicalMap3 = IBM.ICU.Text.Bidi.ReorderLogical(levels); visualMap3 = IBM.ICU.Text.Bidi.ReorderVisual(levels); /* get the visual map from the runs, too */ try { runCount = bidi.CountRuns(); } catch (InvalidOperationException e) { Errln("countRuns() in test " + testNumber + " failed"); runCount = 0; } Logln("\n---- " + runCount + " runs"); visualIndex = 0; BidiRun run; for (i = 0; i < runCount; ++i) { run = bidi.GetVisualRun(i); if (run == null) { Errln("null visual run encountered at index " + i + ", in test " + testNumber); continue; } odd = run.IsOddRun(); logicalStart = run.GetStart(); runLength = run.GetLength(); Log("(" + ((run.IsOddRun()) ? "R" : "L")); Log(" @" + run.GetStart() + '[' + run.GetLength() + "])\n"); if (!odd) { do /* LTR */ { visualMap4[visualIndex++] = logicalStart++; } while (--runLength > 0); } else { logicalStart += runLength; /* logicalLimit */ do /* RTL */ { visualMap4[visualIndex++] = --logicalStart; } while (--runLength > 0); } } Log("\n"); /* print all the maps */ Logln("logical maps:"); for (i = 0; i < length; ++i) { Log(logicalMap1[i] + " "); } Log("\n"); for (i = 0; i < length; ++i) { Log(logicalMap2[i] + " "); } Log("\n"); for (i = 0; i < length; ++i) { Log(logicalMap3[i] + " "); } Log("\nvisual maps:\n"); for (i = 0; i < destLength; ++i) { Log(visualMap1[i] + " "); } Log("\n"); for (i = 0; i < destLength; ++i) { Log(visualMap2[i] + " "); } Log("\n"); for (i = 0; i < length; ++i) { Log(visualMap3[i] + " "); } Log("\n"); for (i = 0; i < length; ++i) { Log(visualMap4[i] + " "); } Log("\n"); /* * check that the indexes are the same between these and * Bidi.getLogical/VisualIndex() */ for (i = 0; i < length; ++i) { if (logicalMap1[i] != logicalMap2[i]) { Errln("Error in tests[" + testNumber + "]: (logicalMap1[" + i + "] == " + logicalMap1[i] + ") != (logicalMap2[" + i + "] == " + logicalMap2[i] + ")"); } if (logicalMap1[i] != logicalMap3[i]) { Errln("Error in tests[" + testNumber + "]: (logicalMap1[" + i + "] == " + logicalMap1[i] + ") != (logicalMap3[" + i + "] == " + logicalMap3[i] + ")"); } if (visualMap1[i] != visualMap2[i]) { Errln("Error in tests[" + testNumber + "]: (visualMap1[" + i + "] == " + visualMap1[i] + ") != (visualMap2[" + i + "] == " + visualMap2[i] + ")"); } if (visualMap1[i] != visualMap3[i]) { Errln("Error in tests[" + testNumber + "]: (visualMap1[" + i + "] == " + visualMap1[i] + ") != (visualMap3[" + i + "] == " + visualMap3[i] + ")"); } if (visualMap1[i] != visualMap4[i]) { Errln("Error in tests[" + testNumber + "]: (visualMap1[" + i + "] == " + visualMap1[i] + ") != (visualMap4[" + i + "] == " + visualMap4[i] + ")"); } try { visualIndex = bidi.GetVisualIndex(i); } catch (Exception e_0) { Errln("Bidi.getVisualIndex(" + i + ") failed in tests[" + testNumber + "]"); } if (logicalMap1[i] != visualIndex) { Errln("Error in tests[" + testNumber + "]: (logicalMap1[" + i + "] == " + logicalMap1[i] + ") != (Bidi.getVisualIndex(" + i + ") == " + visualIndex + ")"); } try { logicalIndex = bidi.GetLogicalIndex(i); } catch (Exception e_1) { Errln("Bidi.getLogicalIndex(" + i + ") failed in tests[" + testNumber + "]"); } if (visualMap1[i] != logicalIndex) { Errln("Error in tests[" + testNumber + "]: (visualMap1[" + i + "] == " + visualMap1[i] + ") != (Bidi.getLogicalIndex(" + i + ") == " + logicalIndex + ")"); } } }
private bool CheckMaps(Bidi bidi, int stringIndex, String src, String dest, String mode, String option, sbyte level, bool forward) { int[] actualLogicalMap; int[] actualVisualMap; int[] getIndexMap; int i, srcLen, resLen, index; int[] expectedLogicalMap, expectedVisualMap; bool testOK = true; if (forward) { expectedLogicalMap = forwardMap[stringIndex]; expectedVisualMap = inverseMap[stringIndex]; } else { expectedLogicalMap = inverseMap[stringIndex]; expectedVisualMap = forwardMap[stringIndex]; } actualLogicalMap = bidi.GetLogicalMap(); srcLen = bidi.GetProcessedLength(); if (!ILOG.J2CsMapping.Collections.Arrays.Equals(expectedLogicalMap, actualLogicalMap)) { Err("Bidi.getLogicalMap returned unexpected map for output " + "string index " + stringIndex + "\n" + "source: " + src + "\n" + "dest : " + dest + "\n" + "Scale : " + IBM.ICU.Charset.BidiTest.columnString + "\n" + "ExpMap: " + FormatMap(expectedLogicalMap) + "\n" + "Actual: " + FormatMap(actualLogicalMap) + "\n" + "Paragraph level : " + level + " == " + bidi.GetParaLevel() + "\n" + "Reordering mode : " + mode + " == " + bidi.GetReorderingMode() + "\n" + "Reordering option: " + option + " == " + bidi.GetReorderingOptions() + "\n" + "Forward flag : " + forward + "\n"); testOK = false; } resLen = bidi.GetResultLength(); actualVisualMap = bidi.GetVisualMap(); if (!ILOG.J2CsMapping.Collections.Arrays.Equals(expectedVisualMap, actualVisualMap)) { Err("Bidi.getVisualMap returned unexpected map for output " + "string index " + stringIndex + "\n" + "source: " + src + "\n" + "dest : " + dest + "\n" + "Scale : " + IBM.ICU.Charset.BidiTest.columnString + "\n" + "ExpMap: " + FormatMap(expectedVisualMap) + "\n" + "Actual: " + FormatMap(actualVisualMap) + "\n" + "Paragraph level : " + level + " == " + bidi.GetParaLevel() + "\n" + "Reordering mode : " + mode + " == " + bidi.GetReorderingMode() + "\n" + "Reordering option: " + option + " == " + bidi.GetReorderingOptions() + "\n" + "Forward flag : " + forward + "\n"); testOK = false; } getIndexMap = new int[srcLen]; for (i = 0; i < srcLen; i++) { index = bidi.GetVisualIndex(i); getIndexMap[i] = index; } if (!ILOG.J2CsMapping.Collections.Arrays.Equals(actualLogicalMap, getIndexMap)) { Err("Mismatch between getLogicalMap and getVisualIndex for output " + "string index " + stringIndex + "\n" + "source: " + src + "\n" + "dest : " + dest + "\n" + "Scale : " + IBM.ICU.Charset.BidiTest.columnString + "\n" + "ActMap: " + FormatMap(actualLogicalMap) + "\n" + "IdxMap: " + FormatMap(getIndexMap) + "\n" + "Paragraph level : " + level + " == " + bidi.GetParaLevel() + "\n" + "Reordering mode : " + mode + " == " + bidi.GetReorderingMode() + "\n" + "Reordering option: " + option + " == " + bidi.GetReorderingOptions() + "\n" + "Forward flag : " + forward + "\n"); testOK = false; } getIndexMap = new int[resLen]; for (i = 0; i < resLen; i++) { index = bidi.GetLogicalIndex(i); getIndexMap[i] = index; } if (!ILOG.J2CsMapping.Collections.Arrays.Equals(actualVisualMap, getIndexMap)) { Err("Mismatch between getVisualMap and getLogicalIndex for output " + "string index " + stringIndex + "\n" + "source: " + src + "\n" + "dest : " + dest + "\n" + "Scale : " + IBM.ICU.Charset.BidiTest.columnString + "\n" + "ActMap: " + FormatMap(actualVisualMap) + "\n" + "IdxMap: " + FormatMap(getIndexMap) + "\n" + "Paragraph level : " + level + " == " + bidi.GetParaLevel() + "\n" + "Reordering mode : " + mode + " == " + bidi.GetReorderingMode() + "\n" + "Reordering option: " + option + " == " + bidi.GetReorderingOptions() + "\n" + "Forward flag : " + forward + "\n"); testOK = false; } return(testOK); }
internal bool CheckWhatYouCan(Bidi bidi, String src, String dst) { int i, idx, logLimit, visLimit; bool testOK, errMap, errDst; char[] srcChars = src.ToCharArray(); char[] dstChars = dst.ToCharArray(); int[] visMap = bidi.GetVisualMap(); int[] logMap = bidi.GetLogicalMap(); testOK = true; errMap = errDst = false; logLimit = bidi.GetProcessedLength(); visLimit = bidi.GetResultLength(); if (visLimit > dstChars.Length) { visLimit = dstChars.Length; } char[] accumSrc = new char[logLimit]; char[] accumDst = new char[visLimit]; ILOG.J2CsMapping.Collections.Arrays.Fill(accumSrc, '?'); ILOG.J2CsMapping.Collections.Arrays.Fill(accumDst, '?'); if (logMap.Length != logLimit) { errMap = true; } for (i = 0; i < logLimit; i++) { idx = bidi.GetVisualIndex(i); if (idx != logMap[i]) { errMap = true; } if (idx == IBM.ICU.Text.Bidi.MAP_NOWHERE) { continue; } if (idx >= visLimit) { continue; } accumDst[idx] = srcChars[i]; if (!MatchingPair(bidi, i, srcChars[i], dstChars[idx])) { errDst = true; } } if (errMap) { if (testOK) { PrintCaseInfo(bidi, src, dst); testOK = false; } Errln("Mismatch between getLogicalMap() and getVisualIndex()"); Errcont("Map :" + ValueOf(logMap)); Errcont("\n"); Errcont("Indexes:"); for (i = 0; i < logLimit; i++) { Errcont(" " + bidi.GetVisualIndex(i)); } Errcont("\n"); } if (errDst) { if (testOK) { PrintCaseInfo(bidi, src, dst); testOK = false; } Errln("Source does not map to Result"); Errcontln("We got: " + ILOG.J2CsMapping.Util.StringUtil.NewString(accumDst)); } errMap = errDst = false; if (visMap.Length != visLimit) { errMap = true; } for (i = 0; i < visLimit; i++) { idx = bidi.GetLogicalIndex(i); if (idx != visMap[i]) { errMap = true; } if (idx == IBM.ICU.Text.Bidi.MAP_NOWHERE) { continue; } if (idx >= logLimit) { continue; } accumSrc[idx] = dstChars[i]; if (!MatchingPair(bidi, idx, srcChars[idx], dstChars[i])) { errDst = true; } } if (errMap) { if (testOK) { PrintCaseInfo(bidi, src, dst); testOK = false; } Errln("Mismatch between getVisualMap() and getLogicalIndex()"); Errcont("Map :" + ValueOf(visMap)); Errcont("\n"); Errcont("Indexes:"); for (i = 0; i < visLimit; i++) { Errcont(" " + bidi.GetLogicalIndex(i)); } Errcont("\n"); } if (errDst) { if (testOK) { PrintCaseInfo(bidi, src, dst); testOK = false; } Errln("Result does not map to Source"); Errcontln("We got: " + ILOG.J2CsMapping.Util.StringUtil.NewString(accumSrc)); } return(testOK); }