Skip to content

Commit 99aff36

Browse files
tobias-melchermickaelistria
authored andcommitted
add test verticalIndent_resetsCacheForAllLinesAssumingLowestLineHeight
1 parent cc5eb77 commit 99aff36

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4691,6 +4691,48 @@ public void test_verticalIndent_changeRelativeBounds() {
46914691
assertEquals(0, text.getTopPixel());
46924692
}
46934693

4694+
/**
4695+
* test fix for eclipse-platform/eclipse.platform.swt#2512
4696+
*/
4697+
@Test
4698+
public void test_verticalIndent_resetsCacheForAllLinesAssumingLowestLineHeight() throws Exception {
4699+
text.dispose();
4700+
text = new StyledText(shell, SWT.V_SCROLL);
4701+
setWidget(text);
4702+
shell.setVisible(true);
4703+
var str = new StringBuilder();
4704+
for (int i = 0; i < 200; i++) {
4705+
str.append("line ").append(i).append("\n");
4706+
}
4707+
text.setText(str.toString());
4708+
text.setSize(500, 200);
4709+
4710+
var m = StyledText.class.getDeclaredMethod("getPartialBottomIndex");
4711+
m.setAccessible(true);
4712+
int bottomIndex = (int) m.invoke(text);
4713+
4714+
text.setLineVerticalIndent(1, 5 * text.getLineHeight());
4715+
while (Display.getDefault().readAndDispatch()) {
4716+
}
4717+
for (int i = 1; i >= 0; i--) {
4718+
int lineNr = bottomIndex - i;
4719+
text.setLineVerticalIndent(lineNr, 2 * text.getLineHeight());
4720+
}
4721+
for (int i = 1; i >= 0; i--) {
4722+
int lineNr = bottomIndex - i;
4723+
var field = StyledText.class.getDeclaredField("renderer");
4724+
field.setAccessible(true);
4725+
Object renderer = field.get(text);
4726+
m = renderer.getClass().getDeclaredMethod("getLineSize", int.class);
4727+
m.setAccessible(true);
4728+
Object lineSize = m.invoke(renderer, lineNr);
4729+
field = lineSize.getClass().getDeclaredField("height");
4730+
field.setAccessible(true);
4731+
int height = (int) field.get(lineSize);
4732+
assertEquals("resetCache is not called for line "+lineNr+" after setLineVerticalIndent",-1, height);
4733+
}
4734+
}
4735+
46944736
@Test
46954737
public void test_verticalIndent_keepsCurrentCaretAndLinePosition() {
46964738
text.dispose();

0 commit comments

Comments
 (0)