From a7267793dc7ace9ace75304fe3c099b108988f8e Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Fri, 24 Apr 2026 16:45:06 +0200 Subject: [PATCH] Make Shell.setSize() test compatible with fractional scaling The test case test_setSizeLorg_eclipse_swt_graphics_Point in Test_org_eclipse_swt_widgets_Shell sporadically fails in I-Builds and constantly fails when executed locally on a non-100% monitor. Due to rounding of the point-based size when converting to pixels upon setting the shell size, the value yielded by getSize() used for result validation is not necessarily equal. This change adapts the test case to apply an according tolerance value whenever the shell zoom is not 100%. --- .../junit/Test_org_eclipse_swt_widgets_Shell.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Shell.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Shell.java index 8a3c83b1a1f..d16f1e47ae1 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Shell.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Shell.java @@ -807,20 +807,31 @@ public void test_setSizeLorg_eclipse_swt_graphics_Point() { Point newSize = new Point(112, 27); for (int i = 0; i < 10; i++) { testShell.setSize(newSize); - assertEquals(newSize, testShell.getSize()); + assertShellProperlySized(testShell, newSize); newSize.x += 100; newSize.y += 100; } newSize = new Point(1292, 1036); for (int i = 0; i < 10; i++) { testShell.setSize(newSize); - assertEquals(newSize, testShell.getSize()); + assertShellProperlySized(testShell, newSize); newSize.x -= 100; newSize.y -= 100; } } } +private void assertShellProperlySized(Shell shell, Point expectedSize) { + int tolerance = shell.getZoom() != 100 ? 1 : 0; + Point actualSize = shell.getSize(); + assertTrue( + Math.abs(expectedSize.x - actualSize.x) <= tolerance + && Math.abs(expectedSize.y - actualSize.y) <= tolerance, + "Shell is not sized correctly" // + + " (expected size: " + expectedSize + " ± " + tolerance // + + ", actual size: " + actualSize + ")"); +} + Shell testShell; private void createShell() {