Skip to content

[GTK3] Test Tree crash in SetData event #1611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.swt.tests.junit;

import static java.lang.System.currentTimeMillis;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand All @@ -27,6 +28,7 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.TreeListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
Expand Down Expand Up @@ -967,6 +969,58 @@ public void test_Virtual() {
dataCounter[0] > visibleCount / 2 && dataCounter[0] <= visibleCount * 3);
}

/** Ensure setText() and setImage() can be set from SetData handler.
@see https://github.com/eclipse-platform/eclipse.platform.swt/issues/678
**/
@Test
public void test_setData() {
tree.dispose();
disposedIntentionally = true;
Image image = new Image(Display.getCurrent(), 20, 20);
try {
shell.setSize(200, 200);
shell.setLayout(new FillLayout());
shell.open();
waitUntilIdle();
for (int i = 0; i < 200; i++) {
Tree tree = new Tree(shell, SWT.VIRTUAL);
tree.addListener(SWT.SetData, e -> {
TreeItem item = (TreeItem) e.item;
item.setText(0, "A");
item.setImage(image); // <-- this is the critical line!
});
waitUntilIdle(); // slightly increase crash probability by preventing unrelated background processing on the next line
tree.setItemCount(1);

waitUntilIdle(); // may crash while processing asynchronous events

assertEquals("A", tree.getItem(0).getText(0));
assertEquals(image, tree.getItem(0).getImage());
tree.dispose();
}
} finally {
image.dispose();
}
}

private void waitUntilIdle() {
long lastActive = currentTimeMillis();
while (true) {
if (Thread.interrupted()) {
throw new AssertionError();
}
if (Display.getCurrent().readAndDispatch()) {
lastActive = currentTimeMillis();
} else {
if (lastActive + 10 < currentTimeMillis()) {
return;
}
Thread.yield();
}
}
}


@Test
public void test_emptinessChanged() {
int NOT_EMPTY = 0;
Expand Down
Loading