Skip to content

Commit a726779

Browse files
committed
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%.
1 parent aa1dbb8 commit a726779

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,20 +807,31 @@ public void test_setSizeLorg_eclipse_swt_graphics_Point() {
807807
Point newSize = new Point(112, 27);
808808
for (int i = 0; i < 10; i++) {
809809
testShell.setSize(newSize);
810-
assertEquals(newSize, testShell.getSize());
810+
assertShellProperlySized(testShell, newSize);
811811
newSize.x += 100;
812812
newSize.y += 100;
813813
}
814814
newSize = new Point(1292, 1036);
815815
for (int i = 0; i < 10; i++) {
816816
testShell.setSize(newSize);
817-
assertEquals(newSize, testShell.getSize());
817+
assertShellProperlySized(testShell, newSize);
818818
newSize.x -= 100;
819819
newSize.y -= 100;
820820
}
821821
}
822822
}
823823

824+
private void assertShellProperlySized(Shell shell, Point expectedSize) {
825+
int tolerance = shell.getZoom() != 100 ? 1 : 0;
826+
Point actualSize = shell.getSize();
827+
assertTrue(
828+
Math.abs(expectedSize.x - actualSize.x) <= tolerance
829+
&& Math.abs(expectedSize.y - actualSize.y) <= tolerance,
830+
"Shell is not sized correctly" //
831+
+ " (expected size: " + expectedSize + " ± " + tolerance //
832+
+ ", actual size: " + actualSize + ")");
833+
}
834+
824835
Shell testShell;
825836

826837
private void createShell() {

0 commit comments

Comments
 (0)