diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_GC.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_GC.java index 1bcb0c9ada2..9e8ca8c3b91 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_GC.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_GC.java @@ -30,6 +30,7 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.lang.ref.WeakReference; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import org.eclipse.swt.SWT; @@ -249,7 +250,7 @@ public void test_dispose() { @Test -public void test_drawImage_nonAutoScalableGC_bug_2504() { +public void test_drawImage_nonAutoScalableGC_bug_2504() throws InterruptedException { Shell shell = new Shell(display); float targetScale = 2f; int srcSize = 50; @@ -273,15 +274,18 @@ public boolean isAutoScalable() { int canvasWidth = Math.round(bounds.width * targetScale); int canvasHeight = Math.round(bounds.height * targetScale); canvas.setSize(canvasWidth, canvasHeight); + AtomicBoolean paintListenerCalled = new AtomicBoolean(); canvas.addPaintListener(e -> { e.gc.drawImage(image, 0, 0, bounds.width, bounds.height, 0, 0, canvasWidth, canvasHeight); + paintListenerCalled.set(true); }); shell.open(); - while (display.readAndDispatch()) { - } - Image target = new Image(display, canvasWidth, canvasHeight); + int timeoutMillis = 2000; + SwtTestUtil.processEvents(timeoutMillis, () -> paintListenerCalled.get()); + assertTrue(paintListenerCalled.get(), "paint listener was never called"); + Image target = new Image(display, canvasWidth, canvasHeight); GC gcCopy = new GC(canvas); gcCopy.copyArea(target, 0, 0); gcCopy.dispose();