use of java.text.Bidi in project jdk8u_jdk by JetBrains.
the class BidiConformance method testMethod_getRunStart.
private void testMethod_getRunStart() {
System.out.println("*** Test getRunStart()");
String str = "ABC 123";
int length = str.length();
Bidi bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);
try {
if (// runCount - 2
bidi.getRunStart(-1) != 0 || // runCount - 1
bidi.getRunStart(0) != 0 || // runCount
bidi.getRunStart(1) != 0 || bidi.getRunStart(2) != 0) {
// runCount + 1
errorHandling("getRunStart() should return 0" + " when getRunCount() is 1.");
}
} catch (Exception e) {
errorHandling("getRunLimit() should not throw an exception" + " when getRunCount() is 1.");
}
str = "ABC " + NKoABC + " 123";
length = str.length();
bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);
try {
bidi.getRunStart(-1);
errorHandling("getRunStart() should throw an AIOoBE" + " when run is -1(too small).");
} catch (ArrayIndexOutOfBoundsException e) {
} catch (IllegalArgumentException e) {
errorHandling("getRunStart() should not throw an IAE " + "but an AIOoBE when run is -1(too small).");
}
try {
bidi.getRunStart(0);
bidi.getRunStart(1);
bidi.getRunStart(2);
} catch (ArrayIndexOutOfBoundsException e) {
errorHandling("getRunStart() should not throw an AIOOBE " + "when run is from 0 to 2(runCount-1).");
}
try {
if (bidi.getRunStart(3) != length) {
errorHandling("getRunStart() should return " + length + " when run is 3(same as runCount).");
}
} catch (Exception e) {
errorHandling("getRunStart() should not throw an exception " + "when run is 3(same as runCount).");
}
try {
bidi.getRunStart(4);
errorHandling("getRunStart() should throw an AIOoBE " + "when run is runCount+1(too large).");
} catch (ArrayIndexOutOfBoundsException e) {
} catch (IllegalArgumentException e) {
errorHandling("getRunStart() should not throw an IAE " + "but an AIOoBE when run is runCount+1(too large).");
}
}
use of java.text.Bidi in project jdk8u_jdk by JetBrains.
the class BidiConformance method testConstructor3.
private void testConstructor3() {
char[] text = { 'a', 'b', 'c', 'd', 'e' };
byte[] embeddings = { 0, 0, 0, 0, 0 };
Bidi bidi;
try {
bidi = new Bidi(null, 0, embeddings, 0, 5, Bidi.DIRECTION_LEFT_TO_RIGHT);
errorHandling("Bidi(char[], ...) should throw an IAE " + "when text=null.");
} catch (IllegalArgumentException e) {
} catch (NullPointerException e) {
errorHandling("Bidi(char[], ...) should not throw an NPE " + "but an IAE when text=null.");
}
try {
bidi = new Bidi(text, -1, embeddings, 0, 5, Bidi.DIRECTION_LEFT_TO_RIGHT);
errorHandling("Bidi(char[], ...) should throw an IAE " + "when textStart is incorrect(-1: too small).");
} catch (IllegalArgumentException e) {
} catch (ArrayIndexOutOfBoundsException e) {
errorHandling("Bidi(char[], ...) should not throw an NPE " + "but an IAE when textStart is incorrect(-1: too small).");
}
try {
bidi = new Bidi(text, 4, embeddings, 0, 2, Bidi.DIRECTION_LEFT_TO_RIGHT);
errorHandling("Bidi(char[], ...) should throw an IAE " + "when textStart is incorrect(4: too large).");
} catch (IllegalArgumentException e) {
} catch (ArrayIndexOutOfBoundsException e) {
errorHandling("Bidi(char[], ...) should not throw an NPE " + "but an IAE when textStart is incorrect(4: too large).");
}
byte[] actualLevels = new byte[text.length];
byte[] validEmbeddings1 = { 0, -61, -60, -2, -1 };
byte[] expectedLevels1 = { 0, 61, 60, 2, 1 };
try {
bidi = new Bidi(text, 0, validEmbeddings1, 0, 5, Bidi.DIRECTION_LEFT_TO_RIGHT);
for (int i = 0; i < text.length; i++) {
actualLevels[i] = (byte) bidi.getLevelAt(i);
}
if (!Arrays.equals(expectedLevels1, actualLevels)) {
errorHandling("Bidi(char[], ...).getLevelAt()" + " should be {" + toString(actualLevels) + "} when embeddings are {" + toString(expectedLevels1) + "}.");
}
} catch (Exception e) {
errorHandling("Bidi(char[], ...) should not throw an exception " + "when embeddings is valid(-61).");
}
byte[] validEmbeddings2 = { 0, 61, 60, 2, 1 };
byte[] expectedLevels2 = { 0, 62, 60, 2, 2 };
try {
bidi = new Bidi(text, 0, validEmbeddings2, 0, 5, Bidi.DIRECTION_LEFT_TO_RIGHT);
for (int i = 0; i < text.length; i++) {
actualLevels[i] = (byte) bidi.getLevelAt(i);
}
if (!Arrays.equals(expectedLevels2, actualLevels)) {
errorHandling("Bidi(char[], ...).getLevelAt()" + " should be {" + toString(actualLevels) + "} when embeddings are {" + toString(expectedLevels2) + "}.");
}
} catch (Exception e) {
errorHandling("Bidi(char[], ...) should not throw an exception " + "when embeddings is valid(61).");
}
byte[] invalidEmbeddings1 = { 0, -62, 0, 0, 0 };
try {
bidi = new Bidi(text, 0, invalidEmbeddings1, 0, 5, Bidi.DIRECTION_LEFT_TO_RIGHT);
if (bidi.getLevelAt(1) != 0) {
errorHandling("Bidi(char[], ...).getLevelAt(1) should be 0 " + "when embeddings[1] is -62.");
}
} catch (Exception e) {
errorHandling("Bidi(char[], ...) should not throw an exception " + "even when embeddings includes -62.");
}
byte[] invalidEmbeddings2 = { 0, 62, 0, 0, 0 };
try {
bidi = new Bidi(text, 0, invalidEmbeddings2, 0, 5, Bidi.DIRECTION_LEFT_TO_RIGHT);
if (bidi.getLevelAt(1) != 0) {
errorHandling("Bidi(char[], ...).getLevelAt(1) should be 0 " + "when embeddings[1] is 62.");
}
} catch (Exception e) {
errorHandling("Bidi(char[], ...) should not throw an exception " + "even when embeddings includes 62.");
}
try {
bidi = new Bidi(text, 0, embeddings, 0, -1, Bidi.DIRECTION_LEFT_TO_RIGHT);
errorHandling("Bidi(char[], ...) should throw an IAE " + "when paragraphLength=-1(too small).");
} catch (IllegalArgumentException e) {
} catch (NegativeArraySizeException e) {
errorHandling("Bidi(char[], ...) should not throw an NASE " + "but an IAE when paragraphLength=-1(too small).");
}
try {
bidi = new Bidi(text, 0, embeddings, 0, 6, Bidi.DIRECTION_LEFT_TO_RIGHT);
errorHandling("Bidi(char[], ...) should throw an IAE " + "when paragraphLength=6(too large).");
} catch (IllegalArgumentException e) {
} catch (ArrayIndexOutOfBoundsException e) {
errorHandling("Bidi(char[], ...) should not throw an AIOoBE " + "but an IAE when paragraphLength=6(too large).");
}
try {
bidi = new Bidi(text, 0, embeddings, 0, 4, -3);
} catch (Exception e) {
errorHandling("Bidi(char[], ...) should not throw an exception " + "even when flag=-3(too small).");
}
try {
bidi = new Bidi(text, 0, embeddings, 0, 5, 2);
} catch (Exception e) {
errorHandling("Bidi(char[], ...) should not throw an exception " + "even when flag=2(too large).");
}
}
use of java.text.Bidi in project jdk8u_jdk by JetBrains.
the class BidiConformance method testMethods4Constructor3.
private void testMethods4Constructor3() {
System.out.println("*** Test methods for constructor 3");
String paragraph;
Bidi bidi;
for (int textNo = 0; textNo < data4Constructor3.length; textNo++) {
paragraph = data4Constructor3[textNo][0];
char[] c = paragraph.toCharArray();
int start = paragraph.indexOf('<') + 1;
byte[][] embeddings = (c.length < emb4Constructor3[1][0].length) ? emb4Constructor3[0] : emb4Constructor3[1];
for (int flagNo = 0; flagNo < FLAGS.length; flagNo++) {
int flag = FLAGS[flagNo];
for (int embNo = 0; embNo < embeddings.length; embNo++) {
int dataNo = flagNo * FLAGS.length + embNo;
System.out.println("*** Test textNo=" + textNo + ": Bidi(char[]\"" + toReadableString(paragraph) + "\", 0, embeddings={" + toString(embeddings[embNo]) + "}, " + c.length + ", " + getFlagName(flag) + ")" + " dataNo=" + dataNo);
try {
bidi = new Bidi(c, 0, embeddings[embNo], 0, c.length, flag);
callTestEachMethod4Constructor3(textNo, dataNo, bidi);
} catch (Exception e) {
errorHandling(" Unexpected exception: " + e);
}
}
}
}
}
use of java.text.Bidi in project jdk8u_jdk by JetBrains.
the class BidiConformance method testMethod_getRunLimit.
private void testMethod_getRunLimit() {
System.out.println("*** Test getRunLimit()");
String str = "ABC 123";
int length = str.length();
Bidi bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);
try {
if (// runCount - 2
bidi.getRunLimit(-1) != length || // runCount - 1
bidi.getRunLimit(0) != length || // runCount
bidi.getRunLimit(1) != length || bidi.getRunLimit(2) != length) {
// runCount + 1
errorHandling("getRunLimit() should return " + length + " when getRunCount() is 1.");
}
} catch (Exception e) {
errorHandling("getRunLimit() should not throw an exception " + "when getRunCount() is 1.");
}
str = "ABC " + ArabicABC + " 123";
length = str.length();
bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);
try {
bidi.getRunLimit(-1);
errorHandling("getRunLimit() should throw an AIOoBE " + "when run is -1(too small).");
} catch (ArrayIndexOutOfBoundsException e) {
} catch (IllegalArgumentException e) {
errorHandling("getRunLimit() should not throw an IAE " + "but an AIOoBE when run is -1(too small).");
}
try {
bidi.getRunLimit(0);
bidi.getRunLimit(1);
bidi.getRunLimit(2);
} catch (ArrayIndexOutOfBoundsException e) {
errorHandling("getRunLimit() should not throw an AIOOBE " + "when run is from 0 to 2(runCount-1).");
}
try {
bidi.getRunLimit(3);
errorHandling("getRunLimit() should throw an AIOoBE " + "when run is 3(same as runCount).");
} catch (ArrayIndexOutOfBoundsException e) {
} catch (IllegalArgumentException e) {
errorHandling("getRunLimit() should not throw an IAE " + "but an AIOoBE when run is 3(same as runCount).");
}
}
use of java.text.Bidi in project jdk8u_jdk by JetBrains.
the class BidiEmbeddingTest method test1.
static void test1() {
String target = "BACK WARDS";
String str = "If this text is >" + target + "< the test passed.";
int start = str.indexOf(target);
int limit = start + target.length();
System.out.println("start: " + start + " limit: " + limit);
AttributedString astr = new AttributedString(str);
astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-1), start, limit);
Bidi bidi = new Bidi(astr.getIterator());
for (int i = 0; i < bidi.getRunCount(); ++i) {
System.out.println("run " + i + " from " + bidi.getRunStart(i) + " to " + bidi.getRunLimit(i) + " at level " + bidi.getRunLevel(i));
}
System.out.println(bidi);
byte[] embs = new byte[str.length() + 3];
for (int i = start + 1; i < limit + 1; ++i) {
embs[i] = -1;
}
Bidi bidi2 = new Bidi(str.toCharArray(), 0, embs, 1, str.length(), Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
for (int i = 0; i < bidi2.getRunCount(); ++i) {
System.out.println("run " + i + " from " + bidi2.getRunStart(i) + " to " + bidi2.getRunLimit(i) + " at level " + bidi2.getRunLevel(i));
}
System.out.println(bidi2 + "\n");
if (bidi.getRunCount() != 3 || bidi2.getRunCount() != 3) {
throw new Error("Bidi run count incorrect");
} else {
System.out.println("test1() passed.\n");
}
}
Aggregations