3030import static org .junit .jupiter .api .Assumptions .assumeTrue ;
3131
3232import java .lang .ref .WeakReference ;
33+ import java .util .concurrent .atomic .AtomicBoolean ;
3334import java .util .concurrent .atomic .AtomicReference ;
3435
3536import org .eclipse .swt .SWT ;
@@ -249,7 +250,7 @@ public void test_dispose() {
249250
250251
251252@ Test
252- public void test_drawImage_nonAutoScalableGC_bug_2504 () {
253+ public void test_drawImage_nonAutoScalableGC_bug_2504 () throws InterruptedException {
253254 Shell shell = new Shell (display );
254255 float targetScale = 2f ;
255256 int srcSize = 50 ;
@@ -273,15 +274,18 @@ public boolean isAutoScalable() {
273274 int canvasWidth = Math .round (bounds .width * targetScale );
274275 int canvasHeight = Math .round (bounds .height * targetScale );
275276 canvas .setSize (canvasWidth , canvasHeight );
277+ AtomicBoolean paintListenerCalled = new AtomicBoolean ();
276278 canvas .addPaintListener (e -> {
277279 e .gc .drawImage (image , 0 , 0 , bounds .width , bounds .height ,
278280 0 , 0 , canvasWidth , canvasHeight );
281+ paintListenerCalled .set (true );
279282 });
280283
281284 shell .open ();
282- while (display .readAndDispatch ()) {
283- }
284- Image target = new Image (display , canvasWidth , canvasHeight );
285+ int timeoutMillis = 2000 ;
286+ SwtTestUtil .processEvents (timeoutMillis , () -> paintListenerCalled .get ());
287+ assertTrue (paintListenerCalled .get (), "paint listener was never called" );
288+ Image target = new Image (display , canvasWidth , canvasHeight );
285289 GC gcCopy = new GC (canvas );
286290 gcCopy .copyArea (target , 0 , 0 );
287291 gcCopy .dispose ();
0 commit comments