< prev index next >

jdk/test/java/text/Bidi/BidiConformance.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 21,31 **** * questions. */ /* * @test ! * @bug 6850113 * @summary confirm the behavior of new Bidi implementation. (Backward compatibility) */ import java.awt.font.NumericShaper; import java.awt.font.TextAttribute; --- 21,31 ---- * questions. */ /* * @test ! * @bug 6850113 8032446 * @summary confirm the behavior of new Bidi implementation. (Backward compatibility) */ import java.awt.font.NumericShaper; import java.awt.font.TextAttribute;
*** 38,47 **** --- 38,49 ---- /* internal flags */ private static boolean error = false; private static boolean verbose = false; private static boolean abort = false; + private static final byte MAX_EXPLICIT_LEVEL = 125; + public static void main(String[] args) { for (int i = 0; i < args.length; i++) { String arg = args[i]; if (arg.equals("-verbose")) { verbose = true;
*** 366,458 **** int start = paragraph.indexOf('<')+1; int limit = paragraph.indexOf('>'); AttributedString astr = new AttributedString(paragraph); astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL); ! astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-61), start, limit); try { bidi = new Bidi(astr.getIterator()); for (int i = start; i < limit; i++) { ! if (bidi.getLevelAt(i) != 61) { errorHandling("Bidi(AttributedCharacterIterator).getLevelAt(" + i + ") should not be " + bidi.getLevelAt(i) + ! " but 60 when BIDI_EMBEDDING is -61."); } } } catch (Exception e) { errorHandling(" Unexpected exception: " + e); } astr = new AttributedString(paragraph); astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL); ! astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-62), start, limit); try { bidi = new Bidi(astr.getIterator()); for (int i = start; i < limit; i++) { if (bidi.getLevelAt(i) != 1) { errorHandling("Bidi(AttributedCharacterIterator).getLevelAt() " + ! "should be 1 when BIDI_EMBEDDING is -62."); } } } catch (Exception e) { errorHandling(" Unexpected exception: " + e); } astr = new AttributedString(paragraph); astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL); ! astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(60), start, limit); try { bidi = new Bidi(astr.getIterator()); for (int i = start; i < limit; i++) { ! if (bidi.getLevelAt(i) != 61) { errorHandling("Bidi(AttributedCharacterIterator).getLevelAt() " + ! "should be 61 when BIDI_EMBEDDING is 60."); } } } catch (Exception e) { errorHandling(" Unexpected exception: " + e); } astr = new AttributedString(paragraph); astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL); ! astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(61), start, limit); try { bidi = new Bidi(astr.getIterator()); for (int i = start; i < limit; i++) { ! if (bidi.getLevelAt(i) != 61) { errorHandling("Bidi(AttributedCharacterIterator).getLevelAt(" + i + ") should not be " + bidi.getLevelAt(i) + ! " but 61 when BIDI_EMBEDDING is 61."); } } } catch (Exception e) { errorHandling(" Unexpected exception: " + e); } astr = new AttributedString(paragraph); astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL); ! astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(62), start, limit); try { bidi = new Bidi(astr.getIterator()); for (int i = start; i < limit; i++) { if (bidi.getLevelAt(i) != 1) { ! errorHandling("Bidi(AttributedCharacterIterator).getLevelAt()" + ! " should not be " + bidi.getLevelAt(i) + ! " but 1 when BIDI_EMBEDDING is 62."); } } } catch (Exception e) { errorHandling(" Unexpected exception: " + e); --- 368,460 ---- int start = paragraph.indexOf('<')+1; int limit = paragraph.indexOf('>'); AttributedString astr = new AttributedString(paragraph); astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL); ! astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-MAX_EXPLICIT_LEVEL), start, limit); try { bidi = new Bidi(astr.getIterator()); for (int i = start; i < limit; i++) { ! if (bidi.getLevelAt(i) != MAX_EXPLICIT_LEVEL) { errorHandling("Bidi(AttributedCharacterIterator).getLevelAt(" + i + ") should not be " + bidi.getLevelAt(i) + ! " but MAX_EXPLICIT_LEVEL-1 when BIDI_EMBEDDING is -MAX_EXPLICIT_LEVEL."); } } } catch (Exception e) { errorHandling(" Unexpected exception: " + e); } astr = new AttributedString(paragraph); astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL); ! astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-(MAX_EXPLICIT_LEVEL+1)), start, limit); try { bidi = new Bidi(astr.getIterator()); for (int i = start; i < limit; i++) { if (bidi.getLevelAt(i) != 1) { errorHandling("Bidi(AttributedCharacterIterator).getLevelAt() " + ! "should be 1 when BIDI_EMBEDDING is -(MAX_EXPLICIT_LEVEL+1)."); } } } catch (Exception e) { errorHandling(" Unexpected exception: " + e); } astr = new AttributedString(paragraph); astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL); ! astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(MAX_EXPLICIT_LEVEL-1), start, limit); try { bidi = new Bidi(astr.getIterator()); for (int i = start; i < limit; i++) { ! if (bidi.getLevelAt(i) != MAX_EXPLICIT_LEVEL) { errorHandling("Bidi(AttributedCharacterIterator).getLevelAt() " + ! "should be MAX_EXPLICIT_LEVEL when BIDI_EMBEDDING is MAX_EXPLICIT_LEVEL-1."); } } } catch (Exception e) { errorHandling(" Unexpected exception: " + e); } astr = new AttributedString(paragraph); astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL); ! astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(MAX_EXPLICIT_LEVEL), start, limit); try { bidi = new Bidi(astr.getIterator()); for (int i = start; i < limit; i++) { ! if (bidi.getLevelAt(i) != MAX_EXPLICIT_LEVEL) { errorHandling("Bidi(AttributedCharacterIterator).getLevelAt(" + i + ") should not be " + bidi.getLevelAt(i) + ! " but MAX_EXPLICIT_LEVEL when BIDI_EMBEDDING is MAX_EXPLICIT_LEVEL."); } } } catch (Exception e) { errorHandling(" Unexpected exception: " + e); } astr = new AttributedString(paragraph); astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL); ! astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(MAX_EXPLICIT_LEVEL+1), start, limit); try { bidi = new Bidi(astr.getIterator()); for (int i = start; i < limit; i++) { if (bidi.getLevelAt(i) != 1) { ! errorHandling("Bidi(AttributedCharacterIterator).getLevelAt(" + ! i + ") should not be " + bidi.getLevelAt(i) + ! " but 1 when BIDI_EMBEDDING is MAX_EXPLICIT_LEVEL+1."); } } } catch (Exception e) { errorHandling(" Unexpected exception: " + e);
*** 534,545 **** 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); --- 536,547 ---- 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, -MAX_EXPLICIT_LEVEL, -(MAX_EXPLICIT_LEVEL-1), -2, -1}; ! byte[] expectedLevels1 = {0, MAX_EXPLICIT_LEVEL, MAX_EXPLICIT_LEVEL-1, 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);
*** 551,565 **** 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); --- 553,567 ---- toString(expectedLevels1) + "}."); } } catch (Exception e) { errorHandling("Bidi(char[], ...) should not throw an exception " + ! "when embeddings is valid(-MAX_EXPLICIT_LEVEL)."); } ! byte[] validEmbeddings2 = {0, MAX_EXPLICIT_LEVEL, MAX_EXPLICIT_LEVEL-1, 2, 1}; ! byte[] expectedLevels2 = {0, MAX_EXPLICIT_LEVEL+1, MAX_EXPLICIT_LEVEL-1, 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);
*** 571,609 **** 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); --- 573,611 ---- toString(expectedLevels2) + "}."); } } catch (Exception e) { errorHandling("Bidi(char[], ...) should not throw an exception " + ! "when embeddings is valid(MAX_EXPLICIT_LEVEL)."); } ! byte[] invalidEmbeddings1 = {0, -(MAX_EXPLICIT_LEVEL+1), 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 -(MAX_EXPLICIT_LEVEL+1)."); } } catch (Exception e) { errorHandling("Bidi(char[], ...) should not throw an exception " + ! "even when embeddings includes -(MAX_EXPLICIT_LEVEL+1)."); } ! byte[] invalidEmbeddings2 = {0, MAX_EXPLICIT_LEVEL+1, 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 MAX_EXPLICIT_LEVEL+1."); } } catch (Exception e) { errorHandling("Bidi(char[], ...) should not throw an exception " + ! "even when embeddings includes MAX_EXPLICIT_LEVEL+1."); } try { bidi = new Bidi(text, 0, embeddings, 0, -1, Bidi.DIRECTION_LEFT_TO_RIGHT);
*** 1593,1602 **** --- 1595,1608 ---- private static final char LRE = '\u202A'; private static final char RLE = '\u202B'; private static final char PDF = '\u202C'; private static final char LRO = '\u202D'; private static final char RLO = '\u202E'; + private static final char LRI = '\u2066'; + private static final char RLI = '\u2067'; + private static final char FSI = '\u2068'; + private static final char PDI = '\u2069'; /* * 0x05D0-0x05EA: [R] Hewbrew letters (Strong) * 0x0627-0x063A: [AL] Arabic letters (Strong) * 0x0660-0x0669: [AN] Arabic-Indic digits (Weak)
*** 2000,2011 **** "11111111111111222222222244443333333322111", "33333333333333444444444466665555555544333"}, /* For Text #18 */ {" ABC (" + ArabicABC + " " + Arabic123 + ") 123.", ! "0000001111222112220", "0000001111222112220", ! "0000001111222112220", "1222111111222112221"}, /* For Text #19 */ {" " + HebrewABC + " (ABC 123) " + NKo123 + ".", "1111112222222111111", "1111112222222111111", "0111000000000001110", "1111112222222111111"}, --- 2006,2017 ---- "11111111111111222222222244443333333322111", "33333333333333444444444466665555555544333"}, /* For Text #18 */ {" ABC (" + ArabicABC + " " + Arabic123 + ") 123.", ! "0000001111222002220", "0000001111222002220", ! "0000001111222002220", "1222111111222112221"}, /* For Text #19 */ {" " + HebrewABC + " (ABC 123) " + NKo123 + ".", "1111112222222111111", "1111112222222111111", "0111000000000001110", "1111112222222111111"},
*** 2026,2035 **** --- 2032,2125 ---- /* For Text #22 */ {RLE + OsmanyaABC + " " + KharoshthiABC + " " + Kharoshthi123 + "." + PDF, "22222221111111111111110", "22222221111111111111110", "22222221111111111111110", "44444443333333333333331"}, + + /* For Text #23 */ + {" ABC (" + Arabic123 + " " + ArabicABC + ") 123.", + "0000002221111002220", "0000002221111002220", + "0000002221111002220", "1222112221111112221"}, + + /* For Text #24 */ + {" 123 (" + ArabicABC + " " + Arabic123 + ") ABC.", + "1222111111222112221", "1222111111222112221", + "0000001111222000000", "1222111111222112221"}, + + /* For Text #25 */ + {" 123 (" + Arabic123 + " " + ArabicABC + ") ABC.", + "1222112221111112221", "1222112221111112221", + "0000002221111000000", "1222112221111112221"}, + + /* For Text #26 */ + {" " + ArabicABC + " (ABC 123) " + Arabic123 + ".", + "1111112222222112221", "1111112222222112221", + "0111000000000002220", "1111112222222112221"}, + + /* For Text #27 */ + {" " + ArabicABC + " (123 ABC) " + Arabic123 + ".", + "1111112221222112221", "1111112221222112221", + "0111002220000002220", "1111112221222112221"}, + + /* For Text #28 */ + {" " + Arabic123 + " (ABC 123) " + ArabicABC + ".", + "0222000000000001110", "0222000000000001110", + "0222000000000001110", "1222112222222111111"}, + + /* For Text #29 */ + {" " + Arabic123 + " (123 ABC) " + ArabicABC + ".", + "0222000000000001110", "0222000000000001110", + "0222000000000001110", "1222112221222111111"}, + + /* For Text #30 */ + {RLI + "ABC " + ArabicABC + " " + ArabicABC + "." + PDI, + "02221111111110", "14443333333331", + "02221111111110", "14443333333331"}, + + /* For Text #31 */ + {"ABC abc \"" + RLI + "IJK " + ArabicABC + " " + ArabicABC + PDI + + ".\" \"" + RLI + ArabicABC + " " + ArabicABC + PDI + ",\" xyz XYZ.", + "0000000000222111111110000001111111000000000000", + "0000000000222111111110000001111111000000000000", + "0000000000222111111110000001111111000000000000", + "2222222222444333333332222223333333222222222221"}, + + /* For Text #32 */ + {ArabicABC + " " + ArabicABC + " '" + LRI + "abc def \"" + RLI + + "xyz " + ArabicABC + " " + ArabicABC + PDI + "\"" + PDI + "'?", + "111111111122222222224443333333322111", + "111111111122222222224443333333322111", + "111111100022222222224443333333322000", + "111111111122222222224443333333322111"}, + + /* For Text #33 */ + {FSI + Arabic123 + " ABC " + ArabicABC + " " + ArabicABC + "." + PDI, + "044422222333333320", "144422222333333321", + "044422222333333320", "144422222333333321"}, + + /* For Text #34 */ + {FSI + "123 ABC " + ArabicABC + " " + ArabicABC + "." + PDI, + "022222222333333320", "122222222333333321", + "022222222333333320", "122222222333333321"}, + + /* For Text #35 */ + {FSI + "123 " + ArabicABC + " ABC " + ArabicABC + "." + PDI, + "022211111222111110", "144433333444333331", + "022211111222111110", "144433333444333331"}, + + /* For Text #36 */ + {FSI + Arabic123 + " " + ArabicABC + " ABC " + ArabicABC + "." + PDI, + "022211111222111110", "144433333444333331", + "022211111222111110", "144433333444333331"}, + + /* For Text #37 */ + {FSI + Arabic123 + " 123." + PDI, + "0444222220", "1444222221", "0444222220", "1444222221"}, + + /* For Text #38 */ + {FSI + "123 " + Arabic123 + "." + PDI, + "0222244420", "1222244421", "0222244420", "1222244421"}, }; /* Golden data for baseIsLeftToRight() results */ private static boolean[][] baseIsLTR4Constructor2 = { /* For Text #0 - $4 */
*** 2058,2071 **** {true, true, true, false}, {true, true, true, false}, {true, true, true, false}, {false, false, true, false}, ! /* For Text #20 - $22 */ {true, true, true, false}, {true, true, true, false}, {true, true, true, false}, }; /* Golden data for isLeftToRight() & isRightToLeft() results */ private static boolean[][][] isLTR_isRTL4Constructor2 = { /* isLeftToRight() results & isRightToLeft() results */ --- 2148,2183 ---- {true, true, true, false}, {true, true, true, false}, {true, true, true, false}, {false, false, true, false}, ! /* For Text #20 - $24 */ ! {true, true, true, false}, ! {true, true, true, false}, ! {true, true, true, false}, ! {true, true, true, false}, ! {false, false, true, false}, ! ! /* For Text #25 - $29 */ ! {false, false, true, false}, ! {false, false, true, false}, ! {false, false, true, false}, {true, true, true, false}, {true, true, true, false}, + + /* For Text #30 - $34 */ + {true, false, true, false}, {true, true, true, false}, + {false, false, true, false}, + {true, false, true, false}, + {true , false, true, false}, + + /* For Text #35 - $38 */ + {true, false, true, false}, + {true, false, true, false}, + {true, false, true, false}, + {true, false, true, false}, }; /* Golden data for isLeftToRight() & isRightToLeft() results */ private static boolean[][][] isLTR_isRTL4Constructor2 = { /* isLeftToRight() results & isRightToLeft() results */
*** 2095,2105 **** {{false, false, false, false}, {false, false, false, false}}, {{false, false, false, false}, {false, false, false, false}}, {{false, false, false, false}, {false, false, false, false}}, {{false, false, false, false}, {false, false, false, false}}, ! /* For Text #20 - $22 */ {{false, false, false, false}, {false, false, false, false}}, {{false, false, false, false}, {false, false, false, false}}, {{false, false, false, false}, {false, false, false, false}}, }; --- 2207,2239 ---- {{false, false, false, false}, {false, false, false, false}}, {{false, false, false, false}, {false, false, false, false}}, {{false, false, false, false}, {false, false, false, false}}, {{false, false, false, false}, {false, false, false, false}}, ! /* For Text #20 - $24 */ ! {{false, false, false, false}, {false, false, false, false}}, ! {{false, false, false, false}, {false, false, false, false}}, ! {{false, false, false, false}, {false, false, false, false}}, ! {{false, false, false, false}, {false, false, false, false}}, ! {{false, false, false, false}, {false, false, false, false}}, ! ! /* For Text #25 - $29 */ ! {{false, false, false, false}, {false, false, false, false}}, ! {{false, false, false, false}, {false, false, false, false}}, ! {{false, false, false, false}, {false, false, false, false}}, ! {{false, false, false, false}, {false, false, false, false}}, ! {{false, false, false, false}, {false, false, false, false}}, ! ! /* For Text #30 - $34 */ ! {{false, false, false, false}, {false, false, false, false}}, ! {{false, false, false, false}, {false, false, false, false}}, ! {{false, false, false, false}, {false, false, false, false}}, ! {{false, false, false, false}, {false, false, false, false}}, ! {{false, false, false, false}, {false, false, false, false}}, ! ! /* For Text #35 - $37 */ ! {{false, false, false, false}, {false, false, false, false}}, {{false, false, false, false}, {false, false, false, false}}, {{false, false, false, false}, {false, false, false, false}}, {{false, false, false, false}, {false, false, false, false}}, };
*** 2111,2122 **** /* For Text #10 - $19 */ true, true, true, true, true, true, true, true, true, true, ! /* For Text #20 - $22 */ ! true, true, true, }; /* --------------------------------------------------------------------- */ /* --- 2245,2261 ---- /* For Text #10 - $19 */ true, true, true, true, true, true, true, true, true, true, ! /* For Text #20 - $29 */ ! true, true, true, true, true, ! true, true, true, true, true, ! ! /* For Text #30 - $37 */ ! true, true, true, true, true, ! true, true, true, true, }; /* --------------------------------------------------------------------- */ /*
< prev index next >