Skip to content

Commit f811bf7

Browse files
committed
[GTK3] Test Tree crash in SetData event
The failure only happens in Ubuntu 24 (GTK 3.24.41)
1 parent e6588c2 commit f811bf7

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*******************************************************************************/
1414
package org.eclipse.swt.tests.junit;
1515

16+
import static java.lang.System.currentTimeMillis;
1617
import static org.junit.Assert.assertArrayEquals;
1718
import static org.junit.Assert.assertEquals;
1819
import static org.junit.Assert.assertFalse;
@@ -27,6 +28,7 @@
2728
import org.eclipse.swt.SWT;
2829
import org.eclipse.swt.events.TreeListener;
2930
import org.eclipse.swt.graphics.Color;
31+
import org.eclipse.swt.graphics.Image;
3032
import org.eclipse.swt.layout.FillLayout;
3133
import org.eclipse.swt.widgets.Display;
3234
import org.eclipse.swt.widgets.Event;
@@ -967,6 +969,58 @@ public void test_Virtual() {
967969
dataCounter[0] > visibleCount / 2 && dataCounter[0] <= visibleCount * 3);
968970
}
969971

972+
/** Ensure setText() and setImage() can be set from SetData handler.
973+
@see https://github.com/eclipse-platform/eclipse.platform.swt/issues/678
974+
**/
975+
@Test
976+
public void test_setData() {
977+
tree.dispose();
978+
disposedIntentionally = true;
979+
Image image = new Image(Display.getCurrent(), 20, 20);
980+
try {
981+
shell.setSize(200, 200);
982+
shell.setLayout(new FillLayout());
983+
shell.open();
984+
waitUntilIdle();
985+
for (int i = 0; i < 200; i++) {
986+
Tree tree = new Tree(shell, SWT.VIRTUAL);
987+
tree.addListener(SWT.SetData, e -> {
988+
TreeItem item = (TreeItem) e.item;
989+
item.setText(0, "A");
990+
item.setImage(image); // <-- this is the critical line!
991+
});
992+
waitUntilIdle(); // slightly increase crash probability by preventing unrelated background processing on the next line
993+
tree.setItemCount(1);
994+
995+
waitUntilIdle(); // may crash while processing asynchronous events
996+
997+
assertEquals("A", tree.getItem(0).getText(0));
998+
assertEquals(image, tree.getItem(0).getImage());
999+
tree.dispose();
1000+
}
1001+
} finally {
1002+
image.dispose();
1003+
}
1004+
}
1005+
1006+
private void waitUntilIdle() {
1007+
long lastActive = currentTimeMillis();
1008+
while (true) {
1009+
if (Thread.interrupted()) {
1010+
throw new AssertionError();
1011+
}
1012+
if (Display.getCurrent().readAndDispatch()) {
1013+
lastActive = currentTimeMillis();
1014+
} else {
1015+
if (lastActive + 10 < currentTimeMillis()) {
1016+
return;
1017+
}
1018+
Thread.yield();
1019+
}
1020+
}
1021+
}
1022+
1023+
9701024
@Test
9711025
public void test_emptinessChanged() {
9721026
int NOT_EMPTY = 0;

0 commit comments

Comments
 (0)