diff options
| author | Niraj Modi | 2015-03-31 08:43:51 +0000 |
|---|---|---|
| committer | Niraj Modi | 2015-03-31 11:26:17 +0000 |
| commit | 72e691af6bca78442e18184dc1453e5eecb6f768 (patch) | |
| tree | d7c6a2bdf2b7caa87f60bf69b381215ceac58eba | |
| parent | ef9b2ace84f9bf3603ba33e4a4c8fc9ae7227032 (diff) | |
| download | eclipse.platform.swt-72e691af6bca78442e18184dc1453e5eecb6f768.tar.gz eclipse.platform.swt-72e691af6bca78442e18184dc1453e5eecb6f768.tar.xz eclipse.platform.swt-72e691af6bca78442e18184dc1453e5eecb6f768.zip | |
Bug 462569 - [api]
ImageFileNameProvider/ImageDataProvider#getImageData(int) can't
determine size of image
Change-Id: I9360d86276e6a9c10499e86fad09bdfa926529d7
Signed-off-by: Niraj Modi <niraj.modi@in.ibm.com>
7 files changed, 272 insertions, 71 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java index 8b938afbcd..81d66e6feb 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java @@ -563,7 +563,7 @@ public Image(Device device, String filename) { * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> * <li>ERROR_NULL_ARGUMENT - if the ImageFileNameProvider is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the fileName provided by ImageFileNameProvider is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the fileName provided by ImageFileNameProvider is null at 100% zoom</li> * </ul> * @exception SWTException <ul> * <li>ERROR_IO - if an IO error occurs while reading from the file</li> @@ -580,18 +580,19 @@ public Image(Device device, ImageFileNameProvider imageFileNameProvider) { super(device); if (imageFileNameProvider == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); String filename = imageFileNameProvider.getImagePath(100); + if (filename == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT); NSAutoreleasePool pool = null; if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); try { - if (filename == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT); initNative(filename); if (this.handle == null) init(new ImageData(filename)); init(); String filename2x = imageFileNameProvider.getImagePath(200); - if (filename2x == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - id id = NSImageRep.imageRepWithContentsOfFile(NSString.stringWith(filename2x)); - NSImageRep rep = new NSImageRep(id); - handle.addRepresentation(rep); + if (filename2x != null) { + id id = NSImageRep.imageRepWithContentsOfFile(NSString.stringWith(filename2x)); + NSImageRep rep = new NSImageRep(id); + handle.addRepresentation(rep); + } } finally { if (pool != null) pool.release(); } @@ -613,7 +614,7 @@ public Image(Device device, ImageFileNameProvider imageFileNameProvider) { * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> * <li>ERROR_NULL_ARGUMENT - if the ImageDataProvider is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the ImageData provided by ImageDataProvider is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the ImageData provided by ImageDataProvider is null at 100% zoom</li> * </ul> * @exception SWTException <ul> * <li>ERROR_IO - if an IO error occurs while reading from the file</li> @@ -637,10 +638,11 @@ public Image(Device device, ImageDataProvider imageDataProvider) { init (data); init (); ImageData data2x = imageDataProvider.getImageData (200); - if (data2x == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - NSBitmapImageRep rep = createRepresentaion (data2x); - handle.addRepresentation(rep); - rep.release(); + if (data2x != null) { + NSBitmapImageRep rep = createRepresentaion (data2x); + handle.addRepresentation(rep); + rep.release(); + } } finally { if (pool != null) pool.release(); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/DPIUtil.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/DPIUtil.java index e3d4fbb123..6b16051329 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/DPIUtil.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/DPIUtil.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.swt.graphics; +import java.util.*; + /** * This class hold common constants and utility functions w.r.t. to SWT high DPI * functionality. @@ -38,4 +40,30 @@ class DPIUtil { } return zoom; } + + /** + * Gets Map of image file path at specified zoom level and boolean flag + * as TRUE if expected image at zoom was found. + */ + @SuppressWarnings("unchecked") + static Map<String, Boolean> getImagePathAtZoom (ImageFileNameProvider provider, int zoom) { + if (provider == null) return Collections.EMPTY_MAP; + String filename = provider.getImagePath (zoom); + /* If image is null when (zoom != 100%), fall-back to image at 100% zoom */ + if (zoom != 100 && filename == null) return Collections.singletonMap (provider.getImagePath (100), Boolean.FALSE); + return Collections.singletonMap (filename, Boolean.TRUE); + } + + /** + * Gets Map of Image data at specified zoom level and boolean flag + * as TRUE if expected image at zoom was found. + */ + @SuppressWarnings("unchecked") + static Map<ImageData, Boolean> getImageDataAtZoom (ImageDataProvider provider, int zoom) { + if (provider == null) return Collections.EMPTY_MAP; + ImageData data = provider.getImageData (zoom); + /* If image is null when (zoom != 100%), fall-back to image at 100% zoom */ + if (zoom != 100 && data == null) return Collections.singletonMap (provider.getImageData (100), Boolean.FALSE); + return Collections.singletonMap (data, Boolean.TRUE); + } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageDataProvider.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageDataProvider.java index a2e52f13c6..4817aa077d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageDataProvider.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageDataProvider.java @@ -22,19 +22,20 @@ package org.eclipse.swt.graphics; */ public interface ImageDataProvider { + /** - * Retrieves the image data for a particular zoom level. This method needs - * to be implemented on the client side. + * Returns the image data for the given zoom level. * <p> - * If the image is not available for a particular zoom level, please - * fall back to image of 100% level and return its image data. - * - * Note: SWT will throw an exception if this method returns null. - * - * @param zoom Currently accepted values (sent by SWT) are 100, 150, and 200 - * corresponding to 16x16, 24x24 and 32x32 images respectively. + * If no image is available for a particular zoom level, this method should + * return <code>null</code>. For <code>zoom == 100</code>, returning + * <code>null</code> in not allowed, and SWT will throw an exception. * - * @return an object of ImageData + * @param zoom + * The zoom level in % of the standard resolution (which is 1 + * physical monitor pixel == 1 SWT logical pixel). Typically 100, + * 150, or 200. + * @return the image data, or <code>null</code> if <code>zoom != 100</code> + * and no image is available for the given zoom level. * @since 3.104 */ public ImageData getImageData (int zoom); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageFileNameProvider.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageFileNameProvider.java index a3959ddd9d..9822838355 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageFileNameProvider.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageFileNameProvider.java @@ -23,21 +23,21 @@ package org.eclipse.swt.graphics; public interface ImageFileNameProvider { /** - * Retrieves the filename for a particular zoom level. This method needs - * to be implemented on the client side. + * Returns the image filePath for the given zoom level. * <p> - * If the image is not available for a particular zoom level, please - * fall back to image of 100% level and return its file name. - * - * Note: SWT will throw an exception if this method returns null. - * - * @param zoom Currently accepted values (sent by SWT) are 100, 150, and 200 - * corresponding to 16x16, 24x24 and 32x32 images respectively. + * If no image is available for a particular zoom level, this method should + * return <code>null</code>. For <code>zoom == 100</code>, returning + * <code>null</code> in not allowed, and SWT will throw an exception. * - * @return an object of String + * @param zoom + * The zoom level in % of the standard resolution (which is 1 + * physical monitor pixel == 1 SWT logical pixel). Typically 100, + * 150, or 200. + * @return the image filePath, or <code>null</code> if + * <code>zoom != 100</code> and no image is available for the given + * zoom level. * @since 3.104 */ - public String getImagePath (int zoom); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java index 968f2d5f9f..fb75c223a2 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java @@ -16,6 +16,7 @@ import org.eclipse.swt.internal.cairo.*; import org.eclipse.swt.internal.gtk.*; import org.eclipse.swt.*; import java.io.*; +import java.util.*; /** * Instances of this class are graphics which have been prepared @@ -171,9 +172,9 @@ public final class Image extends Resource implements Drawable { ImageDataProvider imageDataProvider; /** - * Attribute to cache image zoom level + * Attribute to cache current device zoom level */ - int imageZoomLevel = 100; + int currentDeviceZoom = 100; Image(Device device) { super(device); @@ -699,7 +700,7 @@ public Image(Device device, String filename) { * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> * <li>ERROR_NULL_ARGUMENT - if the ImageFileNameProvider is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the fileName provided by ImageFileNameProvider is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the fileName provided by ImageFileNameProvider is null at 100% zoom</li> * </ul> * @exception SWTException <ul> * <li>ERROR_IO - if an IO error occurs while reading from the file</li> @@ -716,8 +717,15 @@ public Image(Device device, ImageFileNameProvider imageFileNameProvider) { super(device); if (imageFileNameProvider == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); this.imageFileNameProvider = imageFileNameProvider; - imageZoomLevel = getDeviceZoom (); - String filename = imageFileNameProvider.getImagePath(imageZoomLevel); + currentDeviceZoom = getDeviceZoom (); + String filename = null; + Map <String, Boolean> result = DPIUtil.getImagePathAtZoom (imageFileNameProvider, currentDeviceZoom); + if (result != null && !result.isEmpty ()) { + for (String str : result.keySet()) { + filename = str; + break; + } + } if (filename == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT); initNative (filename); if (this.pixmap == 0 && this.surface == 0) init(new ImageData(filename)); @@ -740,7 +748,7 @@ public Image(Device device, ImageFileNameProvider imageFileNameProvider) { * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> * <li>ERROR_NULL_ARGUMENT - if the ImageDataProvider is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the ImageData provided by ImageDataProvider is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the ImageData provided by ImageDataProvider is null at 100% zoom</li> * </ul> * @exception SWTException <ul> * <li>ERROR_IO - if an IO error occurs while reading from the file</li> @@ -757,8 +765,15 @@ public Image(Device device, ImageDataProvider imageDataProvider) { super(device); if (imageDataProvider == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); this.imageDataProvider = imageDataProvider; - imageZoomLevel = getDeviceZoom (); - ImageData data = imageDataProvider.getImageData (imageZoomLevel); + currentDeviceZoom = getDeviceZoom (); + ImageData data = null; + Map <ImageData, Boolean> result = DPIUtil.getImageDataAtZoom (imageDataProvider, currentDeviceZoom); + if (result != null && !result.isEmpty ()) { + for (ImageData imageData : result.keySet()) { + data = imageData; + break; + } + } if (data == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT); init (data); init (); @@ -775,20 +790,47 @@ int getDeviceZoom () { */ boolean refreshImageForZoom () { int deviceZoomLevel = getDeviceZoom(); - if (deviceZoomLevel != imageZoomLevel) { + boolean refreshed = false; + if (deviceZoomLevel != currentDeviceZoom) { if (imageFileNameProvider != null) { - String filename = imageFileNameProvider.getImagePath(deviceZoomLevel); - initNative(filename); + String filename = null; + Map <String, Boolean> result = DPIUtil.getImagePathAtZoom (imageFileNameProvider, deviceZoomLevel); + if (result != null && !result.isEmpty ()) { + for (String str : result.keySet()) { + filename = str; + break; + } + } + if (filename == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + if (result.get (filename) || currentDeviceZoom != 100) { + /* Release current native resources */ + destroy (); + initNative(filename); + if (this.pixmap == 0 && this.surface == 0) init(new ImageData(filename)); + init (); + refreshed = true; + } } else if (imageDataProvider != null) { - ImageData data = imageDataProvider.getImageData(deviceZoomLevel); - init(data); - } else { - return false; + ImageData data = null; + Map <ImageData, Boolean> result = DPIUtil.getImageDataAtZoom (imageDataProvider, deviceZoomLevel); + if (result != null && !result.isEmpty ()) { + for (ImageData imageData : result.keySet()) { + data = imageData; + break; + } + } + if (data == null) SWT.error(SWT.ERROR_INVALID_IMAGE); + if (result.get (data) || currentDeviceZoom != 100) { + /* Release current native resources */ + destroy (); + init(data); + init(); + refreshed = true; + } } - imageZoomLevel = deviceZoomLevel; - return true; + currentDeviceZoom = deviceZoomLevel; } - return false; + return refreshed; } void initNative(String filename) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java index 9d0eb9f9ac..7db0ec874a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java @@ -12,6 +12,7 @@ package org.eclipse.swt.graphics; import java.io.*; +import java.util.*; import org.eclipse.swt.*; import org.eclipse.swt.internal.gdip.*; @@ -134,9 +135,9 @@ public final class Image extends Resource implements Drawable { ImageDataProvider imageDataProvider; /** - * Attribute to cache image zoom level + * Attribute to cache current device zoom level */ - int imageZoomLevel = 100; + int currentDeviceZoom = 100; /** * width of the image @@ -646,7 +647,7 @@ public Image (Device device, String filename) { * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> * <li>ERROR_NULL_ARGUMENT - if the ImageFileNameProvider is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the fileName provided by ImageFileNameProvider is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the fileName provided by ImageFileNameProvider is null at 100% zoom</li> * </ul> * @exception SWTException <ul> * <li>ERROR_IO - if an IO error occurs while reading from the file</li> @@ -663,8 +664,15 @@ public Image(Device device, ImageFileNameProvider imageFileNameProvider) { super(device); if (imageFileNameProvider == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); this.imageFileNameProvider = imageFileNameProvider; - imageZoomLevel = getDeviceZoom (); - String fileName = imageFileNameProvider.getImagePath (imageZoomLevel); + currentDeviceZoom = getDeviceZoom (); + String fileName = null; + Map <String, Boolean> result = DPIUtil.getImagePathAtZoom (imageFileNameProvider, currentDeviceZoom); + if (result != null && !result.isEmpty ()) { + for (String str : result.keySet()) { + fileName = str; + break; + } + } if (fileName == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT); initNative (fileName); if (this.handle == 0) init(new ImageData (fileName)); @@ -687,7 +695,7 @@ public Image(Device device, ImageFileNameProvider imageFileNameProvider) { * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> * <li>ERROR_NULL_ARGUMENT - if the ImageDataProvider is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the ImageData provided by ImageDataProvider is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the ImageData provided by ImageDataProvider is null at 100% zoom</li> * </ul> * @exception SWTException <ul> * <li>ERROR_IO - if an IO error occurs while reading from the file</li> @@ -704,8 +712,15 @@ public Image(Device device, ImageDataProvider imageDataProvider) { super(device); if (imageDataProvider == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); this.imageDataProvider = imageDataProvider; - imageZoomLevel = getDeviceZoom (); - ImageData data = imageDataProvider.getImageData(imageZoomLevel); + currentDeviceZoom = getDeviceZoom (); + ImageData data = null; + Map <ImageData, Boolean> result = DPIUtil.getImageDataAtZoom (imageDataProvider, currentDeviceZoom); + if (result != null && !result.isEmpty ()) { + for (ImageData imageData : result.keySet()) { + data = imageData; + break; + } + } if (data == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT); init(data); init(); @@ -722,23 +737,47 @@ int getDeviceZoom () { */ boolean refreshImageForZoom () { int deviceZoomLevel = getDeviceZoom(); - if (deviceZoomLevel != imageZoomLevel) { + boolean refreshed = false; + if (deviceZoomLevel != currentDeviceZoom) { if (imageFileNameProvider != null) { - String filename = imageFileNameProvider.getImagePath(deviceZoomLevel); - initNative(filename); - init(new ImageData (filename)); - init(); + String filename = null; + Map <String, Boolean> result = DPIUtil.getImagePathAtZoom (imageFileNameProvider, deviceZoomLevel); + if (result != null && !result.isEmpty ()) { + for (String str : result.keySet()) { + filename = str; + break; + } + } + if (filename == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + if (result.get (filename) || currentDeviceZoom != 100) { + /* Release current native resources */ + destroy (); + initNative(filename); + if (this.handle == 0) init(new ImageData (filename)); + init(); + refreshed = true; + } } else if (imageDataProvider != null) { - ImageData data = imageDataProvider.getImageData(deviceZoomLevel); - init(data); - init(); - } else { - return false; + ImageData data = null; + Map <ImageData, Boolean> result = DPIUtil.getImageDataAtZoom (imageDataProvider, deviceZoomLevel); + if (result != null && !result.isEmpty ()) { + for (ImageData imageData : result.keySet()) { + data = imageData; + break; + } + } + if (data == null) SWT.error(SWT.ERROR_INVALID_IMAGE); + if (result.get (data) || currentDeviceZoom != 100) { + /* Release current native resources */ + destroy (); + init(data); + init(); + refreshed = true; + } } - imageZoomLevel = deviceZoomLevel; - return true; + currentDeviceZoom = deviceZoomLevel; } - return false; + return refreshed; } void initNative(String filename) { @@ -1199,6 +1238,7 @@ long /*int*/ [] createGdipImage() { return null; } +@Override void destroy () { if (memGC != null) memGC.dispose(); if (type == SWT.ICON) { @@ -1221,6 +1261,7 @@ void destroy () { * * @see #hashCode */ +@Override public boolean equals (Object object) { if (object == this) return true; if (!(object instanceof Image)) return false; @@ -1709,6 +1750,7 @@ public ImageData getImageData() { * * @see #equals */ +@Override public int hashCode () { return (int)/*64*/handle; } @@ -2180,6 +2222,7 @@ public void internal_dispose_GC (long /*int*/ hDC, GCData data) { * * @return <code>true</code> when the image is disposed and <code>false</code> otherwise */ +@Override public boolean isDisposed() { return handle == 0; } @@ -2259,6 +2302,7 @@ public void setBackground(Color color) { * * @return a string representation of the receiver */ +@Override public String toString () { if (isDisposed()) return "Image {*DISPOSED*}"; return "Image {" + handle + "}"; diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Image.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Image.java index 47a0cf41e9..94856571a9 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Image.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Image.java @@ -469,6 +469,48 @@ public void test_ConstructorLorg_eclipse_swt_graphics_Device_ImageFileNameProvid }; Image image = new Image(display, provider); image.dispose(); + // Corrupt Image provider + provider = new ImageFileNameProvider() { + public String getImagePath(int zoom) { + String fileName; + switch (zoom) { + case 100: + fileName = "corrupt.png"; break; + case 150: + fileName = "corrupt.png"; break; + case 200: + fileName = "corrupt.png"; break; + default: + return null; + } + return getPath(fileName); + } + }; + try { + image = new Image(display, provider); + image.dispose(); + fail("No exception thrown for corrupt image file."); + } catch (SWTException e) { + assertSWTProblem("Incorrect exception thrown for provider with corrupt images", SWT.ERROR_INVALID_IMAGE, e); + } + // Valid provider only 100% zoom + provider = new ImageFileNameProvider() { + public String getImagePath(int zoom) { + String fileName; + switch (zoom) { + case 100: + fileName = "collapseall.png"; + break; + case 150: + case 200: + default: + return null; + } + return getPath(fileName); + } + }; + image = new Image(display, provider); + image.dispose(); } public void test_ConstructorLorg_eclipse_swt_graphics_Device_ImageDataProvider() { @@ -516,6 +558,48 @@ public void test_ConstructorLorg_eclipse_swt_graphics_Device_ImageDataProvider() }; Image image = new Image(display, provider); image.dispose(); + // Corrupt Image provider + provider = new ImageDataProvider() { + public ImageData getImageData(int zoom) { + String fileName; + switch (zoom) { + case 100: + fileName = "corrupt.png"; break; + case 150: + fileName = "corrupt.png"; break; + case 200: + fileName = "corrupt.png"; break; + default: + return null; + } + return new ImageData(getPath(fileName)); + } + }; + try { + image = new Image(display, provider); + image.dispose(); + fail("No exception thrown for corrupt image file."); + } catch (SWTException e) { + assertSWTProblem("Incorrect exception thrown for provider with corrupt images", SWT.ERROR_INVALID_IMAGE, e); + } + // Valid provider only 100% zoom + provider = new ImageDataProvider() { + public ImageData getImageData(int zoom) { + String fileName; + switch (zoom) { + case 100: + fileName = "collapseall.png"; + break; + case 150: + case 200: + default: + return null; + } + return new ImageData(getPath(fileName)); + } + }; + image = new Image(display, provider); + image.dispose(); } public void test_equalsLjava_lang_Object() { |
