Search in sources :

Example 1 with Bidi

use of java.text.Bidi in project robovm by robovm.

the class OldBidiTest method testToString.

public void testToString() {
    try {
        bd = new Bidi("bidi", 173);
        assertNotNull("Bidi representation is null", bd.toString());
    } catch (Exception e) {
        fail("Unexpected exception " + e.toString());
    }
}
Also used : Bidi(java.text.Bidi)

Example 2 with Bidi

use of java.text.Bidi in project robovm by robovm.

the class OldBidiTest method testGetRunStart.

public void testGetRunStart() {
    bd = new Bidi(new char[] { 's', 's', 's' }, 0, new byte[] { (byte) -7, (byte) -2, (byte) 3 }, 0, 3, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
    assertEquals(0, bd.getRunStart(0));
    assertEquals(1, bd.getRunStart(1));
    assertEquals(2, bd.getRunStart(2));
    String LTR = "ab";
    String RTL = "לם";
    String newLine = "\n";
    String defText = LTR + newLine + RTL + LTR + RTL;
    int[][] expectedRuns = { { 0, 3 }, { 3, 5 }, { 5, 7 }, { 7, 9 } };
    Bidi bi = new Bidi(defText, 0);
    final int count = bi.getRunCount();
    for (int i = 0; i < count; i++) {
        assertEquals(expectedRuns[i][0], bi.getRunStart(i));
    }
}
Also used : Bidi(java.text.Bidi)

Example 3 with Bidi

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).");
    }
}
Also used : Bidi(java.text.Bidi) AttributedString(java.text.AttributedString)

Example 4 with Bidi

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).");
    }
}
Also used : Bidi(java.text.Bidi)

Example 5 with Bidi

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);
                }
            }
        }
    }
}
Also used : Bidi(java.text.Bidi) AttributedString(java.text.AttributedString)

Aggregations

Bidi (java.text.Bidi)30 AttributedString (java.text.AttributedString)11 TextLineComponent (sun.font.TextLineComponent)3 TextLabelFactory (sun.font.TextLabelFactory)2 Font (java.awt.Font)1 NumericShaper (java.awt.font.NumericShaper)1 Hashtable (java.util.Hashtable)1 AttributeValues (sun.font.AttributeValues)1 Decoration (sun.font.Decoration)1