Skip to content

Commit 37f6ed2

Browse files
committed
Move imageDataComparator from to test util class
A result of #2664
1 parent 0cbf8f2 commit 37f6ed2

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/graphics/ImageDataTestHelper.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.lang.reflect.InvocationTargetException;
2020
import java.lang.reflect.Method;
21+
import java.util.Comparator;
2122
import java.util.Random;
2223

2324
import org.eclipse.swt.graphics.Image;
@@ -212,6 +213,28 @@ public static BlitTestInfo blit(BlitTestInfo srcInfo, int dstInfo_depth, int dst
212213
return new BlitTestInfo(dstInfo_depth, dstInfo_scale, dstInfo_byteOrder, dstInfo_isDirect, dst);
213214
}
214215

216+
/**
217+
* Compares ImageData, allows for change in things like bit depth by comparing pixel values rather
218+
* that the raw data like {@link #assertImageDataEqual(ImageData, ImageData, ImageData)}
219+
*/
220+
public static Comparator<ImageData> imageDataComparator() {
221+
return Comparator.<ImageData>comparingInt(d -> d.width) //
222+
.thenComparing(d -> d.height) //
223+
.thenComparing((ImageData firstData, ImageData secondData) -> {
224+
for (int x = 0; x < firstData.width; x++) {
225+
for (int y = 0; y < firstData.height; y++) {
226+
if (firstData.getPixel(x, y) != secondData.getPixel(x, y)) {
227+
return -1;
228+
}
229+
if (firstData.getAlpha(x, y) != secondData.getAlpha(x, y)) {
230+
return -1;
231+
}
232+
}
233+
}
234+
return 0;
235+
});
236+
}
237+
215238
public static void assertImageDataEqual(ImageData source, ImageData actual, ImageData expected) {
216239
if (TEST_BLIT_SHOW_IMAGES) {
217240
Image[] images = new Image[3];

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package org.eclipse.swt.tests.junit;
1616

1717

18+
import static org.eclipse.swt.tests.graphics.ImageDataTestHelper.imageDataComparator;
1819
import static org.eclipse.swt.tests.junit.SwtTestUtil.assertSWTProblem;
1920
import static org.junit.jupiter.api.Assertions.assertEquals;
2021
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -31,7 +32,6 @@
3132
import java.io.InputStream;
3233
import java.nio.file.Files;
3334
import java.nio.file.Path;
34-
import java.util.Comparator;
3535
import java.util.List;
3636
import java.util.concurrent.atomic.AtomicInteger;
3737
import java.util.function.Consumer;
@@ -1158,23 +1158,5 @@ public void test_gcOnImageGcDrawer_imageDataAtNonDeviceZoom() {
11581158
}
11591159
}
11601160

1161-
private Comparator<ImageData> imageDataComparator() {
1162-
return Comparator.<ImageData>comparingInt(d -> d.width) //
1163-
.thenComparing(d -> d.height) //
1164-
.thenComparing((ImageData firstData, ImageData secondData) -> {
1165-
for (int x = 0; x < firstData.width; x++) {
1166-
for (int y = 0; y < firstData.height; y++) {
1167-
if (firstData.getPixel(x, y) != secondData.getPixel(x, y)) {
1168-
return -1;
1169-
}
1170-
if (firstData.getAlpha(x, y) != secondData.getAlpha(x, y)) {
1171-
return -1;
1172-
}
1173-
}
1174-
}
1175-
return 0;
1176-
});
1177-
}
1178-
11791161
}
11801162

0 commit comments

Comments
 (0)