Skip to content

Commit d1d296f

Browse files
committed
Removing getDeviceZoom from tests
1 parent 4df99ba commit d1d296f

File tree

11 files changed

+58
-117
lines changed

11 files changed

+58
-117
lines changed

bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/graphics/GCWin32Tests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private void checkGcZoomLevelOnCanvas(int expectedZoom) {
5555
public void drawnElementsShouldScaleUpToTheRightZoomLevel() {
5656
Shell shell = new Shell(Display.getDefault());
5757

58-
int zoom = DPIUtil.getDeviceZoom();
58+
int zoom = DPIUtil.getZoomForAutoscaleProperty(Device.getDevice().getDeviceZoom());
5959
int scalingFactor = 2;
6060
GC gc = GC.win32_new(shell, new GCData());
6161
gc.getGCData().nativeZoom = zoom * scalingFactor;

bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/graphics/RegionWin32Tests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class RegionWin32Tests {
3131
public void testRegionMustBeScaledOnHandleOfScaledZoomLevel() {
3232
Display display = Display.getDefault();
3333

34-
int zoom = DPIUtil.getDeviceZoom();
34+
int zoom = 100;
3535
int scalingFactor = 2;
3636

3737
Region region = new Region(display);

bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/graphics/TransformWin32Tests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class TransformWin32Tests {
2929
@Test
3030
public void testShouldHaveDifferentHandlesAtDifferentZoomLevels() {
3131
Display display = Display.getDefault();
32-
int zoom = DPIUtil.getDeviceZoom();
32+
int zoom = 100;
3333
Transform transform = new Transform(display);
3434
long scaledHandle = transform.getHandle(zoom * 2);
3535
assertNotEquals("There should be different handles for different zoom levels", scaledHandle, transform.getHandle(zoom));

bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/ControlWin32Tests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ record FontComparison(int originalFontHeight, int currentFontHeight) {
8080
private FontComparison updateFont(int scalingFactor) {
8181
Shell shell = new Shell(Display.getDefault());
8282
Control control = new Composite(shell, SWT.NONE);
83-
int zoom = DPIUtil.getDeviceZoom();
83+
int zoom = shell.getNativeZoom();
8484
int newZoom = zoom * scalingFactor;
8585

8686
Font oldFont = control.getFont();

bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/WidgetWin32Tests.java

+23-18
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class WidgetWin32Tests {
3232
public void testWidgetZoomShouldChangeOnZoomLevelChange() {
3333
Display display = Display.getDefault();
3434
Shell shell = new Shell(display);
35-
int zoom = DPIUtil.getDeviceZoom();
35+
int zoom = shell.getNativeZoom();
3636
int scaledZoom = zoom * 2;
3737

3838
Button button = new Button(shell, SWT.PUSH);
@@ -49,10 +49,11 @@ public void testWidgetZoomShouldChangeOnZoomLevelChange() {
4949
@Test
5050
public void testButtonPointsAfterZooming() throws NoSuchMethodException, IllegalAccessException {
5151
Display display = Display.getDefault();
52-
int zoom = DPIUtil.getDeviceZoom();
52+
Shell shell = new Shell(display);
53+
int zoom = shell.getNativeZoom();
54+
5355
int scaledZoom = zoom * 2;
5456

55-
Shell shell = new Shell(display);
5657
shell.setBounds(0, 0, 100, 160);
5758
shell.setLayout(new FillLayout());
5859
shell.pack();
@@ -73,7 +74,8 @@ public void testButtonPointsAfterZooming() throws NoSuchMethodException, Illegal
7374
@Test
7475
public void testImagePixelsWithDoubleZoomLevel() {
7576
Display display = Display.getDefault();
76-
int zoom = DPIUtil.getDeviceZoom();
77+
Shell shell = new Shell(display);
78+
int zoom = shell.getNativeZoom();
7779
int scaledZoom = zoom * 2;
7880

7981
InputStream inputStream = WidgetWin32Tests.class.getResourceAsStream("folder.png");
@@ -99,10 +101,12 @@ private Point getImageDimension(Image image, Integer zoomLevel) {
99101
@Test
100102
public void testButtonFontAfterZooming() {
101103
Display display = Display.getDefault();
102-
int zoom = DPIUtil.getDeviceZoom();
104+
Shell shell = new Shell(display);
105+
int zoom = shell.getNativeZoom();
106+
103107
int scaledZoom = zoom * 2;
104108

105-
Shell shell = new Shell(display);
109+
106110
shell.setBounds(0, 0, 100, 160);
107111
shell.setLayout(new FillLayout());
108112
shell.pack();
@@ -124,10 +128,11 @@ public void testButtonFontAfterZooming() {
124128
@Test
125129
public void testCoolItemAfterZooming() {
126130
Display display = Display.getDefault();
127-
int zoom = DPIUtil.getDeviceZoom();
131+
Shell shell = new Shell(display);
132+
int zoom = shell.getNativeZoom();
128133
int scaledZoom = zoom * 2;
129134

130-
Shell shell = new Shell(display);
135+
131136
shell.setBounds(0, 0, 100, 160);
132137
shell.setLayout(new FillLayout());
133138
shell.pack();
@@ -163,10 +168,10 @@ public void testCoolItemAfterZooming() {
163168
@Test
164169
public void testExpandItemAfterZooming() {
165170
Display display = Display.getDefault();
166-
int zoom = DPIUtil.getDeviceZoom();
171+
Shell shell = new Shell(display);
172+
int zoom = shell.getNativeZoom();
167173
int scaledZoom = zoom * 2;
168174

169-
Shell shell = new Shell(display);
170175
shell.setBounds(0, 0, 100, 160);
171176
shell.setLayout(new FillLayout());
172177
shell.pack();
@@ -190,10 +195,10 @@ public void testExpandItemAfterZooming() {
190195
@Test
191196
public void testTabFolderSizeAfterZooming() {
192197
Display display = Display.getDefault();
193-
int zoom = DPIUtil.getDeviceZoom();
198+
Shell shell = new Shell(display);
199+
int zoom = shell.getNativeZoom();
194200
int scaledZoom = zoom * 2;
195201

196-
Shell shell = new Shell(display);
197202
shell.setBounds(0, 0, 100, 160);
198203
shell.setLayout(new FillLayout());
199204
shell.pack();
@@ -220,10 +225,10 @@ public void testTabFolderSizeAfterZooming() {
220225
@Test
221226
public void testTableAfterZooming() {
222227
Display display = Display.getDefault();
223-
int zoom = DPIUtil.getDeviceZoom();
224-
int scaledZoom = zoom * 2;
225228

226229
Shell shell = new Shell(display);
230+
int zoom = shell.getNativeZoom();
231+
int scaledZoom = zoom * 2;
227232
shell.setBounds(0, 0, 100, 160);
228233
shell.setLayout(new FillLayout());
229234
shell.pack();
@@ -258,10 +263,10 @@ public void testTableAfterZooming() {
258263
@Test
259264
public void testTreeAfterZooming() {
260265
Display display = Display.getDefault();
261-
int zoom = DPIUtil.getDeviceZoom();
266+
Shell shell = new Shell(display);
267+
int zoom = shell.getNativeZoom();
262268
int scaledZoom = zoom * 2;
263269

264-
Shell shell = new Shell(display);
265270
shell.setBounds(0, 0, 100, 160);
266271
shell.setLayout(new FillLayout());
267272
shell.pack();
@@ -294,10 +299,10 @@ public void testTreeAfterZooming() {
294299
@Test
295300
public void testCaretInStyledTextAfterZooming() {
296301
Display display = Display.getDefault();
297-
int zoom = DPIUtil.getDeviceZoom();
302+
Shell shell = new Shell(display);
303+
int zoom = shell.getNativeZoom();
298304
int scaledZoom = zoom * 2;
299305

300-
Shell shell = new Shell(display);
301306
shell.setBounds(0, 0, 100, 160);
302307
shell.setLayout(new FillLayout());
303308
shell.pack();

tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/widgets/PatternWin32ManualTest.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import org.eclipse.swt.graphics.Color;
1717
import org.eclipse.swt.graphics.Pattern;
18-
import org.eclipse.swt.internal.DPIUtil;
1918

2019
/*
2120
* This Snippet tests a pattern at multiple zoom levels.
@@ -33,8 +32,8 @@ public class PatternWin32ManualTest {
3332
private static Display display = Display.getDefault();
3433

3534
public static void main (String [] args) {
36-
@SuppressWarnings("restriction")
37-
int zoom = DPIUtil.getDeviceZoom();
35+
Shell shell = new Shell(display);
36+
int zoom = shell.getNativeZoom();
3837
int scalingFactor = 3;
3938
int scaledZoom = zoom * scalingFactor;
4039
int width = 400;

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

+22-21
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@
3737
public class DPIUtilTests {
3838

3939
private int deviceZoom;
40+
private static final int ZOOM_200 = 200;
4041

4142
@BeforeEach
4243
public void setup() {
4344
deviceZoom = DPIUtil.getDeviceZoom();
44-
DPIUtil.setDeviceZoom(200);
45+
DPIUtil.setDeviceZoom(ZOOM_200);
4546
}
4647

4748
@AfterEach
@@ -57,10 +58,10 @@ public void scaleDownFloatArray() {
5758

5859
float[] scaledValue = DPIUtil.autoScaleDown(valueAt200);
5960
assertArrayEquals(valueAt100, scaledValue, .001f, String.format("Scaling down float array from device zoom (%d) to 100 failed",
60-
DPIUtil.getDeviceZoom()));
61+
ZOOM_200));
6162
scaledValue = DPIUtil.autoScaleDown((Device) null, valueAt200);
6263
assertArrayEquals(valueAt100, scaledValue, .001f, String.format("Scaling down float array from device zoom (%d) to 100 with device failed",
63-
DPIUtil.getDeviceZoom()));
64+
ZOOM_200));
6465

6566
scaledValue = DPIUtil.scaleDown(valueAt200, 200);
6667
assertArrayEquals(valueAt100, scaledValue, .001f, "Scaling down float array from 200 failed");
@@ -84,10 +85,10 @@ public void scaleDownInteger() {
8485

8586
int scaledValue = DPIUtil.autoScaleDown(valueAt200);
8687
assertEquals(
87-
valueAt100, scaledValue, String.format("Scaling down integer from device zoom (%d) to 100 failed", DPIUtil.getDeviceZoom()));
88+
valueAt100, scaledValue, String.format("Scaling down integer from device zoom (%d) to 100 failed", ZOOM_200));
8889
scaledValue = DPIUtil.autoScaleDown((Device) null, valueAt200);
8990
assertEquals(
90-
valueAt100, scaledValue, String.format("Scaling down integer from device zoom (%d) to 100 with device failed", DPIUtil.getDeviceZoom()));
91+
valueAt100, scaledValue, String.format("Scaling down integer from device zoom (%d) to 100 with device failed", ZOOM_200));
9192

9293
scaledValue = DPIUtil.scaleDown(valueAt200, 200);
9394
assertEquals(valueAt100, scaledValue, "Scaling down integer from 200 failed");
@@ -111,10 +112,10 @@ public void scaleDownFloat() {
111112

112113
float scaledValue = DPIUtil.autoScaleDown(valueAt200);
113114
assertEquals(valueAt100, scaledValue, .001f,
114-
String.format("Scaling down float from device zoom (%d) to 100 failed", DPIUtil.getDeviceZoom()));
115+
String.format("Scaling down float from device zoom (%d) to 100 failed", ZOOM_200));
115116
scaledValue = DPIUtil.autoScaleDown((Device) null, valueAt200);
116117
assertEquals(valueAt100, scaledValue, .001f, String
117-
.format("Scaling down float from device zoom (%d) to 100 with device failed", DPIUtil.getDeviceZoom()));
118+
.format("Scaling down float from device zoom (%d) to 100 with device failed", ZOOM_200));
118119

119120
scaledValue = DPIUtil.scaleDown(valueAt200, 200);
120121
assertEquals(valueAt100, scaledValue, .001f, "Scaling down float from 200 failed");
@@ -138,10 +139,10 @@ public void scaleDownPoint() {
138139

139140
Point scaledValue = DPIUtil.autoScaleDown(valueAt200);
140141
assertEquals(valueAt100, scaledValue,
141-
String.format("Scaling down Point from device zoom (%d) to 100 failed", DPIUtil.getDeviceZoom()));
142+
String.format("Scaling down Point from device zoom (%d) to 100 failed", ZOOM_200));
142143
scaledValue = DPIUtil.autoScaleDown((Device) null, valueAt200);
143144
assertEquals(valueAt100, scaledValue, String
144-
.format("Scaling down Point from device zoom (%d) to 100 with device failed", DPIUtil.getDeviceZoom()));
145+
.format("Scaling down Point from device zoom (%d) to 100 with device failed", ZOOM_200));
145146

146147
scaledValue = DPIUtil.scaleDown(valueAt200, 200);
147148
assertEquals(valueAt100, scaledValue, "Scaling down Point from 200 failed");
@@ -165,10 +166,10 @@ public void scaleDownRectangle() {
165166

166167
Rectangle scaledValue = DPIUtil.autoScaleDown(valueAt200);
167168
assertEquals(valueAt100, scaledValue,
168-
String.format("Scaling down Rectangle from device zoom (%d) to 100 failed", DPIUtil.getDeviceZoom()));
169+
String.format("Scaling down Rectangle from device zoom (%d) to 100 failed", ZOOM_200));
169170
scaledValue = DPIUtil.autoScaleDown((Device) null, valueAt200);
170171
assertEquals(valueAt100, scaledValue, String.format(
171-
"Scaling down Rectangle from device zoom (%d) to 100 with device failed", DPIUtil.getDeviceZoom()));
172+
"Scaling down Rectangle from device zoom (%d) to 100 with device failed", ZOOM_200));
172173

173174
scaledValue = DPIUtil.scaleDown(valueAt200, 200);
174175
assertEquals(valueAt100, scaledValue, "Scaling down Rectangle from 200 failed");
@@ -192,10 +193,10 @@ public void scaleUpIntArray() {
192193

193194
int[] scaledValue = DPIUtil.autoScaleUp(valueAt100);
194195
assertArrayEquals(valueAt200, scaledValue,
195-
String.format("Scaling up int array to device zoom (%d) to 100 failed", DPIUtil.getDeviceZoom()));
196+
String.format("Scaling up int array to device zoom (%d) to 100 failed", ZOOM_200));
196197
scaledValue = DPIUtil.autoScaleUp((Device) null, valueAt100);
197198
assertArrayEquals(valueAt200, scaledValue, String
198-
.format("Scaling up int array to device zoom (%d) to 100 with device failed", DPIUtil.getDeviceZoom()));
199+
.format("Scaling up int array to device zoom (%d) to 100 with device failed", ZOOM_200));
199200

200201
scaledValue = DPIUtil.scaleUp(valueAt100, 200);
201202
assertArrayEquals(valueAt200, scaledValue, "Scaling up int array to 200 failed");
@@ -219,10 +220,10 @@ public void scaleUpInteger() {
219220

220221
int scaledValue = DPIUtil.autoScaleUp(valueAt100);
221222
assertEquals(valueAt200, scaledValue,
222-
String.format("Scaling up integer to device zoom (%d) to 100 failed", DPIUtil.getDeviceZoom()));
223+
String.format("Scaling up integer to device zoom (%d) to 100 failed", ZOOM_200));
223224
scaledValue = DPIUtil.autoScaleUp((Device) null, valueAt100);
224225
assertEquals(valueAt200, scaledValue, String
225-
.format("Scaling up integer to device zoom (%d) to 100 with device failed", DPIUtil.getDeviceZoom()));
226+
.format("Scaling up integer to device zoom (%d) to 100 with device failed", ZOOM_200));
226227

227228
scaledValue = DPIUtil.scaleUp(valueAt100, 200);
228229
assertEquals(valueAt200, scaledValue, "Scaling up integer to 200 failed");
@@ -246,10 +247,10 @@ public void scaleUpFloat() {
246247

247248
float scaledValue = DPIUtil.autoScaleUp(valueAt100);
248249
assertEquals(valueAt200, scaledValue, 0.001f,
249-
String.format("Scaling up integer to device zoom (%d) to 100 failed", DPIUtil.getDeviceZoom()));
250+
String.format("Scaling up integer to device zoom (%d) to 100 failed", ZOOM_200));
250251
scaledValue = DPIUtil.autoScaleUp((Device) null, valueAt100);
251252
assertEquals(valueAt200, scaledValue, 0.001f, String
252-
.format("Scaling up integer to device zoom (%d) to 100 with device failed", DPIUtil.getDeviceZoom()));
253+
.format("Scaling up integer to device zoom (%d) to 100 with device failed", ZOOM_200));
253254

254255
scaledValue = DPIUtil.scaleUp(valueAt100, 200);
255256
assertEquals(valueAt200, scaledValue, 0.001f, "Scaling up integer to 200 failed");
@@ -273,10 +274,10 @@ public void scaleUpPoint() {
273274

274275
Point scaledValue = DPIUtil.autoScaleUp(valueAt100);
275276
assertEquals(valueAt200, scaledValue,
276-
String.format("Scaling up Point to device zoom (%d) to 100 failed", DPIUtil.getDeviceZoom()));
277+
String.format("Scaling up Point to device zoom (%d) to 100 failed", ZOOM_200));
277278
scaledValue = DPIUtil.autoScaleUp((Device) null, valueAt100);
278279
assertEquals(valueAt200, scaledValue, String
279-
.format("Scaling up Point to device zoom (%d) to 100 with device failed", DPIUtil.getDeviceZoom()));
280+
.format("Scaling up Point to device zoom (%d) to 100 with device failed", ZOOM_200));
280281

281282
scaledValue = DPIUtil.scaleUp(valueAt100, 200);
282283
assertEquals(valueAt200, scaledValue, "Scaling up Point to 200 failed");
@@ -300,10 +301,10 @@ public void scaleUpRectangle() {
300301

301302
Rectangle scaledValue = DPIUtil.autoScaleUp(valueAt100);
302303
assertEquals(valueAt200, scaledValue,
303-
String.format("Scaling up Rectangle to device zoom (%d) to 100 failed", DPIUtil.getDeviceZoom()));
304+
String.format("Scaling up Rectangle to device zoom (%d) to 100 failed", ZOOM_200));
304305
scaledValue = DPIUtil.autoScaleUp((Device) null, valueAt100);
305306
assertEquals(valueAt200, scaledValue, String
306-
.format("Scaling up Rectangle to device zoom (%d) to 100 with device failed", DPIUtil.getDeviceZoom()));
307+
.format("Scaling up Rectangle to device zoom (%d) to 100 with device failed", ZOOM_200));
307308

308309
scaledValue = DPIUtil.scaleUp(valueAt100, 200);
309310
assertEquals(valueAt200, scaledValue, "Scaling up Rectangle to 200 failed");

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

-24
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,6 @@ public void test_copyAreaIIIIII() {
154154
ImageData imageData = image.getImageData();
155155
PaletteData palette = imageData.palette;
156156

157-
if (DPIUtil.getDeviceZoom() != 100) {
158-
//TODO Fix non integer scaling factors.
159-
if (SwtTestUtil.verbose) {
160-
System.out.println("Excluded test_copyAreaIIIIII(org.eclipse.swt.tests.junit.Test_org_eclipse_swt_graphics_GC)");
161-
}
162-
return;
163-
}
164-
165157
int pixel = imageData.getPixel(destX + 4, destY);
166158
assertEquals(":a:", whiteRGB, palette.getRGB(pixel));
167159
pixel = imageData.getPixel(destX + 6 , destY);
@@ -199,13 +191,6 @@ public void test_copyAreaIIIIII_overlapingSourceTarget() {
199191
imageData = image.getImageData();
200192
palette = imageData.palette;
201193

202-
if (DPIUtil.getDeviceZoom() != 100) {
203-
//TODO Fix non integer scaling factors.
204-
if (SwtTestUtil.verbose) {
205-
System.out.println("Excluded test_copyAreaIIIIII(org.eclipse.swt.tests.junit.Test_org_eclipse_swt_graphics_GC)");
206-
}
207-
return;
208-
}
209194

210195
pixel = imageData.getPixel(0, 105);
211196
assertEquals(redRGB, palette.getRGB(pixel));
@@ -234,15 +219,6 @@ public void test_copyAreaLorg_eclipse_swt_graphics_ImageII() {
234219
ImageData imageData = image.getImageData();
235220
PaletteData palette = imageData.palette;
236221

237-
if (DPIUtil.getDeviceZoom() != 100) {
238-
//TODO Fix non integer scaling factors.
239-
if (SwtTestUtil.verbose) {
240-
System.out.println("Excluded test_copyAreaLorg_eclipse_swt_graphics_ImageII(org.eclipse.swt.tests.junit.Test_org_eclipse_swt_graphics_GC)");
241-
}
242-
image.dispose();
243-
return;
244-
}
245-
246222
int pixel = imageData.getPixel(4, 0);
247223
assertEquals(":a:", whiteRGB, palette.getRGB(pixel));
248224
pixel = imageData.getPixel(5, 0);

0 commit comments

Comments
 (0)