/*Test suite start*/ @Test public void test_getLevel() { TextLayout layout = new TextLayout(display); String text = "abc55\u05e9\u05e066"; layout.setText(text); assertEquals(0, layout.getLevel(0)); assertEquals(0, layout.getLevel(2)); // assertEquals(0, layout.getLevel(4)); //bug in windows (uniscribe) assertEquals(1, layout.getLevel(5)); assertEquals(1, layout.getLevel(6)); assertEquals(2, layout.getLevel(7)); assertEquals(0, layout.getLevel(9)); try { layout.getLevel(-1); fail("invalid range expection expected"); } catch (Exception e) { } try { layout.getLevel(text.length() + 1); fail("invalid range expection expected"); } catch (Exception e) { } layout.dispose(); }
@Test public void test_getSegmentsChars() { if (SwtTestUtil.isCocoa) { // TODO Fix Cocoa failure. if (SwtTestUtil.verbose) { System.out.println( "Excluded test_getSegmentsChars(org.eclipse.swt.tests.junit.Test_org_eclipse_swt_graphics_TextLayout)."); } return; } TextLayout layout = new TextLayout(display); String text = "ab\u05d0\u05d1.\u05d2cd"; int textLength = text.length(); layout.setText(text); String[] messages = { "no segments", "Embedding RTL dir test", "Embedding LTR dir test", "LRO test", "RLO test", "Traditional segments", "Traditional segments invalid" }; int[][] segments = { null, {0, 0, 4, 4, 5, 5, 8, 8}, {0, 0, 4, 4, 5, 5, 8, 8}, {0, textLength}, {0, textLength}, {0, 4, 8}, {1} }; char[][] chars = { null, {'\u202a', '\u202b', '\u202c', '\u200e', '\u200e', '\u202b', '\u202c', '\u202c'}, {'\u202b', '\u202a', '\u202c', '\u200f', '\u200f', '\u202a', '\u202c', '\u202c'}, {0x202d, 0x202c}, {0x202e, 0x202c}, null, null }; int[][] levels = { {0, 0, 1, 1, 1, 1, 0, 0}, {4, 4, 3, 3, 2, 3, 4, 4}, {2, 2, 3, 3, 1, 3, 2, 2}, {2, 2, 2, 2, 2, 2, 2, 2}, // Fails on cocoa, where it returns {0, 0, 0, 0, 0, 0, 0, 0} {1, 1, 1, 1, 1, 1, 1, 1}, {0, 0, 1, 1, 0, 1, 0, 0}, {0, 0, 1, 1, 1, 1, 0, 0} }; int[] offsets = {0, textLength}; for (int i = 0; i < segments.length; i++) { layout.setSegments(segments[i]); layout.setSegmentsChars(chars[i]); assertArrayEquals("Test line offsets" + ": group: " + i, offsets, layout.getLineOffsets()); for (int j = 0; j < textLength; j++) { assertEquals( messages[i] + ": group: " + i + ", index: " + j, levels[i][j], layout.getLevel(j)); } } layout.dispose(); }