|
20 | 20 | import static org.junit.Assert.assertFalse;
|
21 | 21 | import static org.junit.Assert.assertNotNull;
|
22 | 22 | import static org.junit.Assert.assertNull;
|
23 |
| -import static org.junit.Assert.assertSame; |
24 | 23 | import static org.junit.Assert.assertThrows;
|
25 | 24 | import static org.junit.Assert.assertTrue;
|
26 | 25 | import static org.junit.Assume.assumeFalse;
|
|
33 | 32 | import java.nio.file.Files;
|
34 | 33 | import java.nio.file.Path;
|
35 | 34 | import java.util.Comparator;
|
| 35 | +import java.util.List; |
| 36 | +import java.util.concurrent.atomic.AtomicInteger; |
36 | 37 | import java.util.function.Consumer;
|
37 | 38 |
|
38 | 39 | import org.eclipse.swt.SWT;
|
@@ -683,6 +684,25 @@ public void test_getImageData() {
|
683 | 684 | getImageData2(32, new PaletteData(0xff0000, 0xff00, 0xff));
|
684 | 685 | }
|
685 | 686 |
|
| 687 | +@Test |
| 688 | +public void test_getImageData_changingImageDataDoesNotAffectImage() { |
| 689 | + List<Image> images = List.of( // |
| 690 | + new Image(display, imageFileNameProvider), // |
| 691 | + new Image(display, imageDataProvider), // |
| 692 | + new Image(display, new ImageData(10, 10, 32, new PaletteData(0xff0000, 0xff00, 0xff))) // |
| 693 | + ); |
| 694 | + |
| 695 | + try { |
| 696 | + for (Image image : images) { |
| 697 | + ImageData originalImageData = image.getImageData(); |
| 698 | + originalImageData.setPixel(0, 0, originalImageData.getPixel(0, 0) + 1); |
| 699 | + assertNotEquals(image.getImageData().getPixel(0, 0), originalImageData.getPixel(0, 0)); |
| 700 | + } |
| 701 | + } finally { |
| 702 | + images.forEach(Image::dispose); |
| 703 | + } |
| 704 | +} |
| 705 | + |
686 | 706 | @Test
|
687 | 707 | public void test_getImageData_100() {
|
688 | 708 | getImageData_int(100);
|
@@ -1032,11 +1052,17 @@ public void test_updateWidthHeightAfterDPIChange() {
|
1032 | 1052 | public void test_imageDataIsCached() {
|
1033 | 1053 | assumeTrue("On-demand image creation only implemented for Windows", SwtTestUtil.isWindows);
|
1034 | 1054 | String imagePath = getPath("collapseall.png");
|
| 1055 | + AtomicInteger callCount = new AtomicInteger(); |
1035 | 1056 | ImageFileNameProvider imageFileNameProvider = __ -> {
|
| 1057 | + callCount.incrementAndGet(); |
1036 | 1058 | return imagePath;
|
1037 | 1059 | };
|
1038 | 1060 | Image fileNameProviderImage = new Image(display, imageFileNameProvider);
|
1039 |
| - assertSame(fileNameProviderImage.getImageData(100), fileNameProviderImage.getImageData(100)); |
| 1061 | + callCount.set(0); |
| 1062 | + fileNameProviderImage.getImageData(100); |
| 1063 | + fileNameProviderImage.getImageData(100); |
| 1064 | + fileNameProviderImage.getImageData(100); |
| 1065 | + assertEquals(0, callCount.get()); |
1040 | 1066 | }
|
1041 | 1067 |
|
1042 | 1068 | @Test
|
|
0 commit comments