/* check paragraph count and boundaries */
if (paraCount != (count = bidi.countParagraphs())) {
errln("1st Bidi.countParagraphs returned " + count + ", should be " +
paraCount);
}
BidiRun run;
for (i = 0; i < paraCount; i++) {
run = bidi.getParagraphByIndex(i);
paraStart = run.getStart();
paraLimit = run.getLimit();
if ((paraStart != paraBounds[i]) ||
(paraLimit != paraBounds[i + 1])) {
errln("Found boundaries of paragraph " + i + ": " +
paraStart + "-" + paraLimit + "; expected: " +
paraBounds[i] + "-" + paraBounds[i + 1]);
}
}
/* check with last paragraph not terminated by B */
char[] chars = text.toCharArray();
chars[chars.length - 1] = 'L';
src = new String(chars);
try {
bidi.setPara(src, Bidi.LTR, null);
} catch (IllegalArgumentException e) {
errln("2nd Bidi.setPara failed, paraLevel = " + Bidi.LTR);
}
if (paraCount != (count = bidi.countParagraphs())) {
errln("2nd Bidi.countParagraphs returned " + count +
", should be " + paraCount);
}
i = paraCount - 1;
run = bidi.getParagraphByIndex(i);
paraStart = run.getStart();
paraLimit = run.getLimit();
if ((paraStart != paraBounds[i]) ||
(paraLimit != paraBounds[i + 1])) {
errln("2nd Found boundaries of paragraph " + i + ": " +
paraStart + "-" + paraLimit + "; expected: " +
paraBounds[i] + "-" + paraBounds[i + 1]);
}
/* check paraLevel for all paragraphs under various paraLevel specs */
for (k = 0; k < 6; k++) {
try {
bidi.setPara(src, paraLevels[k], null);
} catch (IllegalArgumentException e) {
errln("3nd Bidi.setPara failed, paraLevel = " + paraLevels[k]);
}
for (i = 0; i < paraCount; i++) {
paraIndex = bidi.getParagraphIndex(paraBounds[i]);
run = bidi.getParagraph(paraBounds[i]);
if (paraIndex != i) {
errln("#1 For paraLevel = " + paraLevels[k] +
" paragraph = " + i + ", found paragraph" +
" index = " + paraIndex + " expected = " + i);
}
gotLevel = run.getEmbeddingLevel();
if (gotLevel != multiLevels[k][i]) {
errln("#2 For paraLevel = " + paraLevels[k] +
" paragraph = " + i + ", found level = " + gotLevel +
", expected = " + multiLevels[k][i]);
}
}
gotLevel = bidi.getParaLevel();
if (gotLevel != multiLevels[k][0]) {
errln("#3 For paraLevel = " + paraLevels[k] +
" getParaLevel = " + gotLevel + ", expected " +
multiLevels[k][0]);
}
}
/* check that the result of Bidi.getParaLevel changes if the first
* paragraph has a different level
*/
chars[0] = '\u05d2'; /* Hebrew letter Gimel */
src = new String(chars);
try {
bidi.setPara(src, Bidi.LEVEL_DEFAULT_LTR, null);
} catch (IllegalArgumentException e) {
errln("Bidi.setPara failed, paraLevel = " + Bidi.LEVEL_DEFAULT_LTR);
}
gotLevel = bidi.getParaLevel();
if (gotLevel != Bidi.RTL) {
errln("#4 For paraLevel = Bidi.LEVEL_DEFAULT_LTR getParaLevel = " +
gotLevel + ", expected = " + Bidi.RTL);
}
/* check that line cannot overlap paragraph boundaries */
bidiLine = new Bidi();
i = paraBounds[1];
k = paraBounds[2] + 1;
try {
bidiLine = bidi.setLine(i, k);
errln("For line limits " + i + "-" + k
+ " got success, while expected failure");
} catch (Exception e) {}
i = paraBounds[1];
k = paraBounds[2];
try {
bidiLine = bidi.setLine(i, k);
} catch (Exception e) {
errln("For line limits " + i + "-" + k + " got failure");
}
/* check level of block separator at end of paragraph when orderParagraphsLTR==FALSE */
try {
bidi.setPara(src, Bidi.RTL, null);
} catch (IllegalArgumentException e) {
errln("Bidi.setPara failed, paraLevel = " + Bidi.RTL);
}
/* get levels through para Bidi block */
try {
gotLevels = bidi.getLevels();
} catch (Exception e) {
errln("Error on Bidi.getLevels");
gotLevels = new byte[bidi.getLength()];
Arrays.fill(gotLevels, (byte)-1);
}
for (i = 26; i < 32; i++) {
if (gotLevels[i] != Bidi.RTL) {
errln("For char " + i + "(0x" + Utility.hex(chars[i]) +
"), level = " + gotLevels[i] + ", expected = " + Bidi.RTL);
}
}
/* get levels through para Line block */
i = paraBounds[1];
k = paraBounds[2];
try {
bidiLine = bidi.setLine(i, k);
} catch (Exception e) {
errln("For line limits " + i + "-" + k + " got failure");
return;
}
paraIndex = bidiLine.getParagraphIndex(i);
run = bidiLine.getParagraph(i);
try {
gotLevels = bidiLine.getLevels();
} catch (Exception e) {
errln("Error on bidiLine.getLevels");
gotLevels = new byte[bidiLine.getLength()];
Arrays.fill(gotLevels, (byte)-1);
}
length = bidiLine.getLength();
gotLevel = run.getEmbeddingLevel();
if ((gotLevel != Bidi.RTL) || (gotLevels[length - 1] != Bidi.RTL)) {
errln("For paragraph " + paraIndex + " with limits " +
run.getStart() + "-" + run.getLimit() +
", paraLevel = " + gotLevel +
"expected = " + Bidi.RTL +
", level of separator = " + gotLevels[length - 1] +
" expected = " + Bidi.RTL);
}
orderParagraphsLTR = bidi.isOrderParagraphsLTR();
assertFalse("orderParagraphsLTR is true", orderParagraphsLTR);
bidi.orderParagraphsLTR(true);
orderParagraphsLTR = bidi.isOrderParagraphsLTR();
assertTrue("orderParagraphsLTR is false", orderParagraphsLTR);
/* check level of block separator at end of paragraph when orderParagraphsLTR==TRUE */
try {
bidi.setPara(src, Bidi.RTL, null);
} catch (IllegalArgumentException e) {
errln("Bidi.setPara failed, paraLevel = " + Bidi.RTL);
}
/* get levels through para Bidi block */
try {
gotLevels = bidi.getLevels();
} catch (Exception e) {
errln("Error on Bidi.getLevels");
gotLevels = new byte[bidi.getLength()];
Arrays.fill(gotLevels, (byte)-1);
}
for (i = 26; i < 32; i++) {
if (gotLevels[i] != 0) {
errln("For char " + i + "(0x" + Utility.hex(chars[i]) +
"), level = "+ gotLevels[i] + ", expected = 0");
}
}
/* get levels through para Line block */
i = paraBounds[1];
k = paraBounds[2];
paraStart = run.getStart();
paraLimit = run.getLimit();
try {
bidiLine = bidi.setLine(paraStart, paraLimit);
} catch (Exception e) {
errln("For line limits " + paraStart + "-" + paraLimit +
" got failure");
}
paraIndex = bidiLine.getParagraphIndex(i);
run = bidiLine.getParagraph(i);
try {
gotLevels = bidiLine.getLevels();
} catch (Exception e) {
errln("Error on bidiLine.getLevels");
gotLevels = new byte[bidiLine.getLength()];
Arrays.fill(gotLevels, (byte)-1);
}
length = bidiLine.getLength();
gotLevel = run.getEmbeddingLevel();
if ((gotLevel != Bidi.RTL) || (gotLevels[length - 1] != 0)) {
err("\nFor paragraph " + paraIndex + " with limits " +
run.getStart() + "-" + run.getLimit() +
", paraLevel = " + gotLevel + "expected = " + Bidi.RTL +
", level of separator = " + gotLevels[length - 1] +
" expected = 0\nlevels = ");
for (count = 0; count < length; count++) {
errcont(gotLevels[count] + " ");