Skip to content

Commit 0c0c064

Browse files
committed
Make GC copyArea tests compatible with HiDPI monitors
The copyArea() tests for GC are currently disabled on non-100% monitors. In particular on MacOS, 200% monitors are quite common, such that those tests are not executed. This change adapts the tests to fit to non-100% monitors.
1 parent a9526c3 commit 0c0c064

1 file changed

Lines changed: 22 additions & 31 deletions

File tree

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

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import static org.junit.jupiter.api.Assertions.assertThrows;
2727
import static org.junit.jupiter.api.Assertions.assertTrue;
2828
import static org.junit.jupiter.api.Assumptions.assumeFalse;
29-
import static org.junit.jupiter.api.Assumptions.assumeTrue;
3029

3130
import java.io.IOException;
3231
import java.io.InputStream;
@@ -149,10 +148,6 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DrawableI() {
149148

150149
@Test
151150
public void test_copyAreaIIIIII() {
152-
// This test verifies pixel-level color values after a copyArea() operation.
153-
// Such pixel-accurate checks are only reliable at 100% zoom due to fractional scaling.
154-
assumeTrue(DPIUtil.getDeviceZoom() == 100, "Skipping test due to non-100% zoom");
155-
156151
Color white = display.getSystemColor(SWT.COLOR_WHITE);
157152
Color blue = display.getSystemColor(SWT.COLOR_BLUE);
158153
RGB whiteRGB = getRealRGB(white);
@@ -168,25 +163,21 @@ public void test_copyAreaIIIIII() {
168163
gc.fillRectangle(5, 0, 6, 1);
169164
gc.copyArea(0, 0, width, height, destX, destY);
170165

171-
ImageData imageData = image.getImageData();
166+
ImageData imageData = image.getImageData(DPIUtil.getDeviceZoom());
172167
PaletteData palette = imageData.palette;
173168

174-
int pixel = imageData.getPixel(destX + 4, destY);
169+
int pixel = imageData.getPixel(scaleWithDeviceZoom(destX + 4), scaleWithDeviceZoom(destY));
175170
assertEquals(whiteRGB, palette.getRGB(pixel));
176-
pixel = imageData.getPixel(destX + 6 , destY);
171+
pixel = imageData.getPixel(scaleWithDeviceZoom(destX + 6), scaleWithDeviceZoom(destY));
177172
assertEquals(blueRGB, palette.getRGB(pixel));
178-
pixel = imageData.getPixel(destX + 10, destY);
173+
pixel = imageData.getPixel(scaleWithDeviceZoom(destX + 10), scaleWithDeviceZoom(destY));
179174
assertEquals(blueRGB, palette.getRGB(pixel));
180-
pixel = imageData.getPixel(destX + 12, destY);
175+
pixel = imageData.getPixel(scaleWithDeviceZoom(destX + 12), scaleWithDeviceZoom(destY));
181176
assertEquals(whiteRGB, palette.getRGB(pixel));
182177
}
183178

184179
@Test
185180
public void test_copyAreaIIIIII_overlapingSourceTarget() {
186-
// This test verifies pixel-level color values after a copyArea() operation.
187-
// Such pixel-accurate checks are only reliable at 100% zoom due to fractional scaling.
188-
assumeTrue(DPIUtil.getDeviceZoom() == 100, "Skipping test due to non-100% zoom");
189-
190181
Color red= display.getSystemColor(SWT.COLOR_RED);
191182
Color blue = display.getSystemColor(SWT.COLOR_BLUE);
192183
RGB redRGB = getRealRGB(red);
@@ -197,38 +188,34 @@ public void test_copyAreaIIIIII_overlapingSourceTarget() {
197188
gc.setBackground(blue);
198189
gc.fillRectangle(0, 100, 200, 100);
199190

200-
ImageData imageData = image.getImageData();
191+
ImageData imageData = image.getImageData(DPIUtil.getDeviceZoom());
201192
PaletteData palette = imageData.palette;
202193

203194
int pixel = imageData.getPixel(0, 0);
204195
assertEquals(redRGB, palette.getRGB(pixel));
205-
pixel = imageData.getPixel(0, 105);
196+
pixel = imageData.getPixel(0, scaleWithDeviceZoom(105));
206197
assertEquals(blueRGB, palette.getRGB(pixel));
207-
pixel = imageData.getPixel(0, 155);
198+
pixel = imageData.getPixel(0, scaleWithDeviceZoom(155));
208199
assertEquals(blueRGB, palette.getRGB(pixel));
209200

210201
gc.copyArea(0, 50, 200, 100, 0, 100);
211202

212-
imageData = image.getImageData();
203+
imageData = image.getImageData(DPIUtil.getDeviceZoom());
213204
palette = imageData.palette;
214205

215-
pixel = imageData.getPixel(0, 105);
206+
pixel = imageData.getPixel(0, scaleWithDeviceZoom(105));
216207
assertEquals(redRGB, palette.getRGB(pixel));
217-
pixel = imageData.getPixel(0, 145);
208+
pixel = imageData.getPixel(0, scaleWithDeviceZoom(145));
218209
assertEquals(redRGB, palette.getRGB(pixel));
219-
pixel = imageData.getPixel(0, 155);
210+
pixel = imageData.getPixel(0, scaleWithDeviceZoom(155));
220211
assertEquals(blueRGB, palette.getRGB(pixel));
221-
pixel = imageData.getPixel(0, 195);
212+
pixel = imageData.getPixel(0, scaleWithDeviceZoom(195));
222213
assertEquals(blueRGB, palette.getRGB(pixel));
223214
}
224215

225216

226217
@Test
227218
public void test_copyAreaLorg_eclipse_swt_graphics_ImageII() {
228-
// This test verifies pixel-level color values after a copyArea() operation.
229-
// Such pixel-accurate checks are only reliable at 100% zoom due to fractional scaling.
230-
assumeTrue(DPIUtil.getDeviceZoom() == 100, "Skipping test due to non-100% zoom");
231-
232219
Color white = display.getSystemColor(SWT.COLOR_WHITE);
233220
Color blue = display.getSystemColor(SWT.COLOR_BLUE);
234221
RGB whiteRGB = getRealRGB(white);
@@ -240,20 +227,24 @@ public void test_copyAreaLorg_eclipse_swt_graphics_ImageII() {
240227
gc.fillRectangle(5, 0, 6, 1);
241228
Image image = new Image(display, 12, 12);
242229
gc.copyArea(image, 0, 0);
243-
ImageData imageData = image.getImageData();
230+
ImageData imageData = image.getImageData(DPIUtil.getDeviceZoom());
244231
PaletteData palette = imageData.palette;
245232

246-
int pixel = imageData.getPixel(4, 0);
233+
int pixel = imageData.getPixel(scaleWithDeviceZoom(4), 0);
247234
assertEquals(whiteRGB, palette.getRGB(pixel));
248-
pixel = imageData.getPixel(5, 0);
235+
pixel = imageData.getPixel(scaleWithDeviceZoom(5), 0);
249236
assertEquals(blueRGB, palette.getRGB(pixel));
250-
pixel = imageData.getPixel(10, 0);
237+
pixel = imageData.getPixel(scaleWithDeviceZoom(10), 0);
251238
assertEquals(blueRGB, palette.getRGB(pixel));
252-
pixel = imageData.getPixel(11, 0);
239+
pixel = imageData.getPixel(scaleWithDeviceZoom(11), 0);
253240
assertEquals(whiteRGB, palette.getRGB(pixel));
254241
image.dispose();
255242
}
256243

244+
private int scaleWithDeviceZoom(int value) {
245+
return value * DPIUtil.getDeviceZoom() / 100;
246+
}
247+
257248
@Test
258249
public void test_dispose() {
259250
gc.dispose();

0 commit comments

Comments
 (0)