use of org.eclipse.swt.SWTException in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_browser_Browser method test_LocationListener_evaluateInCallback.
/**
* This test replicates what happens internally
* if you click on a link in a javadoc popup hoverbox.
* I.e, in a location listener, evaluation() is performed.
*
* The goal of this test is to ensure there are no 'Freezes'/deadlocks if
* javascript evaluation is invoked inside an SWT listener.
*
* At time of writing, it also highlights that evaluation inside SWT listeners
* is not consistent across browsers.
*/
@Test
public void test_LocationListener_evaluateInCallback() {
assumeTrue(isWebkit2 || SwtTestUtil.isCocoa || SwtTestUtil.isWindows);
// On Webki1 this test works, but is prone to crashes. See Bug 509411
AtomicBoolean changingFinished = new AtomicBoolean(false);
AtomicBoolean changedFinished = new AtomicBoolean(false);
browser.addLocationListener(new LocationListener() {
@Override
public void changing(LocationEvent event) {
// Broken on Webkit1. I.e evaluate() in a 'changing()' signal doesn't do anything.
browser.evaluate("SWTchanging = true");
changingFinished.set(true);
}
@Override
public void changed(LocationEvent event) {
browser.evaluate("SWTchanged = true");
changedFinished.set(true);
}
});
browser.setText("<body>Hello <b>World</b></body>");
// Wait till both listeners were fired.
if (SwtTestUtil.isWindows) {
// Windows doesn't reach changedFinished.get();
waitForPassCondition(changingFinished::get);
} else
waitForPassCondition(() -> (changingFinished.get() && changedFinished.get()));
// Inspect if evaluate() was executed correctly.
Boolean changed = false;
try {
changed = (Boolean) browser.evaluate("return SWTchanged");
} catch (SWTException e) {
}
Boolean changing = false;
try {
changing = (Boolean) browser.evaluate("return SWTchanging");
} catch (SWTException e) {
}
String errMsg = "\n changing: fired:" + changingFinished.get() + " evaluated:" + changing + "\n changed: fired:" + changedFinished.get() + " evaluated:" + changed;
boolean passed = false;
if (isWebkit2) {
// Evaluation works in all cases.
passed = changingFinished.get() && changedFinished.get() && changed && changing;
} else if (isWebkit1) {
// On Webkit1, evaluation in 'changing' fails.
// && changing (broken)
passed = changingFinished.get() && changedFinished.get() && changed;
} else if (SwtTestUtil.isCocoa) {
// On Cocoa, evaluation in 'changing' fails.
// && changing (broken)
passed = changingFinished.get() && changedFinished.get() && changed;
} else if (SwtTestUtil.isWindows) {
// On Windows, evaluation inside SWT listeners fails altogether.
// Further, only 'changing' is fired if evaluation is invoked inside listeners.
passed = changingFinished.get();
}
assertTrue(errMsg, passed);
}
use of org.eclipse.swt.SWTException in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_graphics_Image method test_ConstructorLorg_eclipse_swt_graphics_DeviceLjava_lang_String.
@Test
public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLjava_lang_String() {
String fileName = null;
try {
Image image = new Image(display, fileName);
image.dispose();
fail("No exception thrown for file name == null");
} catch (IllegalArgumentException e) {
assertSWTProblem("Incorrect exception thrown for file name == null", SWT.ERROR_NULL_ARGUMENT, e);
}
try {
String pathName = "nonexistent.txt";
Image image = new Image(display, pathName);
image.dispose();
fail("No exception thrown for non-existent file name");
} catch (SWTException e) {
assertSWTProblem("Incorrect exception thrown for non-existent file name", SWT.ERROR_IO, e);
}
try {
String pathName = getPath("empty.txt");
Image image = new Image(display, pathName);
image.dispose();
fail("No exception thrown for invalid file name");
} catch (SWTException e) {
assertSWTProblem("Incorrect exception thrown for invalid file name", SWT.ERROR_UNSUPPORTED_FORMAT, e);
}
int numFormats = SwtTestUtil.imageFormats.length;
fileName = SwtTestUtil.invalidImageFilenames[0];
Display[] displays = { display, null };
for (int j = 0; j < displays.length; j++) {
// Display tempDisplay = displays[j];
for (int i = 0; i < numFormats; i++) {
String format = SwtTestUtil.imageFormats[i];
try {
String pathName = getPath(fileName + "." + format);
Image image = new Image(display, pathName);
image.dispose();
fail("No exception thrown for invalid file name");
} catch (SWTException e) {
// Bug 70167 - Image(Device, InputStream) throws incorrect exception for bad PNG
// remove comment when bug is fixed.
// assertEquals("Incorrect exception thrown for invalid image file name", SWT.ERROR_INVALID_IMAGE, e);
}
}
}
try {
String pathName = getPath(SwtTestUtil.invalidImageFilenames[1]);
Image image = new Image(display, pathName);
image.dispose();
fail("No exception thrown for invalid file name");
} catch (SWTException e) {
assertSWTProblem("Incorrect exception thrown for invalid image file name", SWT.ERROR_INVALID_IMAGE, e);
}
// create valid images
for (int j = 0; j < displays.length; j++) {
// Display tempDisplay = displays[j];
int numFileNames = SwtTestUtil.imageFilenames.length;
for (int k = 0; k < numFileNames; k++) {
fileName = SwtTestUtil.imageFilenames[k];
for (int i = 0; i < numFormats; i++) {
String format = SwtTestUtil.imageFormats[i];
String pathName = getPath(fileName + "." + format);
Image image = new Image(display, pathName);
image.dispose();
}
}
}
}
use of org.eclipse.swt.SWTException in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_graphics_Image method test_getImageDataCurrentZoom.
@SuppressWarnings("deprecation")
@Test
public void test_getImageDataCurrentZoom() {
Rectangle bounds = new Rectangle(0, 0, 10, 20);
Image image = new Image(display, bounds.width, bounds.height);
image.dispose();
try {
image.getImageDataAtCurrentZoom();
fail("No exception thrown for disposed image");
} catch (SWTException e) {
assertSWTProblem("Incorrect exception thrown for disposed image", SWT.ERROR_GRAPHIC_DISPOSED, e);
}
// creates bitmap image and compare size of imageData
image = new Image(display, bounds.width, bounds.height);
ImageData imageDataAtCurrentZoom = image.getImageDataAtCurrentZoom();
image.dispose();
Rectangle boundsAtCurrentZoom = new Rectangle(0, 0, imageDataAtCurrentZoom.width, imageDataAtCurrentZoom.height);
assertEquals(":a: Size of ImageData returned from Image.getImageDataAtCurrentZoom method doesn't return matches with bounds in Pixel values.", boundsAtCurrentZoom, DPIUtil.autoScaleUp(bounds));
// create icon image and compare size of imageData
ImageData imageData = new ImageData(bounds.width, bounds.height, 1, new PaletteData(new RGB[] { new RGB(0, 0, 0) }));
image = new Image(display, imageData);
imageDataAtCurrentZoom = image.getImageDataAtCurrentZoom();
image.dispose();
boundsAtCurrentZoom = new Rectangle(0, 0, imageDataAtCurrentZoom.width, imageDataAtCurrentZoom.height);
assertEquals(":b: Size of ImageData returned from Image.getImageDataAtCurrentZoom method doesn't return matches with bounds in Pixel values.", boundsAtCurrentZoom, DPIUtil.autoScaleUp(bounds));
// create image with FileNameProvider
image = new Image(display, imageFileNameProvider);
imageDataAtCurrentZoom = image.getImageDataAtCurrentZoom();
boundsAtCurrentZoom = new Rectangle(0, 0, imageDataAtCurrentZoom.width, imageDataAtCurrentZoom.height);
bounds = image.getBounds();
image.dispose();
assertEquals(":c: Size of ImageData returned from Image.getImageDataAtCurrentZoom method doesn't return matches with bounds in Pixel values.", boundsAtCurrentZoom, DPIUtil.autoScaleUp(bounds));
// create image with ImageDataProvider
image = new Image(display, imageDataProvider);
imageDataAtCurrentZoom = image.getImageDataAtCurrentZoom();
boundsAtCurrentZoom = new Rectangle(0, 0, imageDataAtCurrentZoom.width, imageDataAtCurrentZoom.height);
bounds = image.getBounds();
image.dispose();
assertEquals(":d: Size of ImageData returned from Image.getImageDataAtCurrentZoom method doesn't return matches with bounds in Pixel values.", boundsAtCurrentZoom, DPIUtil.autoScaleUp(bounds));
}
use of org.eclipse.swt.SWTException in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_graphics_Image method getImageData_int.
void getImageData_int(int zoom) {
Rectangle bounds = new Rectangle(0, 0, 10, 20);
Image image = new Image(display, bounds.width, bounds.height);
image.dispose();
try {
image.getImageData(zoom);
fail("No exception thrown for disposed image");
} catch (SWTException e) {
assertSWTProblem("Incorrect exception thrown for disposed image", SWT.ERROR_GRAPHIC_DISPOSED, e);
}
// creates bitmap image and compare size of imageData
image = new Image(display, bounds.width, bounds.height);
ImageData imageDataAtZoom = image.getImageData(zoom);
image.dispose();
Rectangle boundsAtZoom = new Rectangle(0, 0, imageDataAtZoom.width, imageDataAtZoom.height);
assertEquals(":a: Size of ImageData returned from Image.getImageData(int) method doesn't return matches with bounds in Pixel values.", scaleBounds(bounds, zoom, 100), boundsAtZoom);
// create icon image and compare size of imageData
ImageData imageData = new ImageData(bounds.width, bounds.height, 1, new PaletteData(new RGB[] { new RGB(0, 0, 0) }));
image = new Image(display, imageData);
imageDataAtZoom = image.getImageData(zoom);
image.dispose();
boundsAtZoom = new Rectangle(0, 0, imageDataAtZoom.width, imageDataAtZoom.height);
assertEquals(":b: Size of ImageData returned from Image.getImageData(int) method doesn't return matches with bounds in Pixel values.", scaleBounds(bounds, zoom, 100), boundsAtZoom);
// create image with FileNameProvider
image = new Image(display, imageFileNameProvider);
imageDataAtZoom = image.getImageData(zoom);
boundsAtZoom = new Rectangle(0, 0, imageDataAtZoom.width, imageDataAtZoom.height);
bounds = image.getBounds();
image.dispose();
assertEquals(":c: Size of ImageData returned from Image.getImageData(int) method doesn't return matches with bounds in Pixel values.", scaleBounds(bounds, zoom, 100), boundsAtZoom);
// create image with ImageDataProvider
image = new Image(display, imageDataProvider);
imageDataAtZoom = image.getImageData(zoom);
boundsAtZoom = new Rectangle(0, 0, imageDataAtZoom.width, imageDataAtZoom.height);
bounds = image.getBounds();
image.dispose();
assertEquals(":d: Size of ImageData returned from Image.getImageData(int) method doesn't return matches with bounds in Pixel values.", scaleBounds(bounds, zoom, 100), boundsAtZoom);
}
use of org.eclipse.swt.SWTException in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_graphics_Image method test_getBoundsInPixels.
@SuppressWarnings("deprecation")
@Test
public void test_getBoundsInPixels() {
Rectangle bounds = new Rectangle(0, 0, 10, 20);
Image image = new Image(display, bounds.width, bounds.height);
image.dispose();
try {
image.getBoundsInPixels();
fail("No exception thrown for disposed image");
} catch (SWTException e) {
assertSWTProblem("Incorrect exception thrown for disposed image", SWT.ERROR_GRAPHIC_DISPOSED, e);
}
// creates bitmap image
image = new Image(display, bounds.width, bounds.height);
Rectangle boundsInPixels = image.getBoundsInPixels();
image.dispose();
assertEquals(":a: Image.getBoundsInPixels method doesn't return bounds in Pixel values.", boundsInPixels, DPIUtil.autoScaleUp(bounds));
// create icon image
ImageData imageData = new ImageData(bounds.width, bounds.height, 1, new PaletteData(new RGB[] { new RGB(0, 0, 0) }));
image = new Image(display, imageData);
boundsInPixels = image.getBoundsInPixels();
image.dispose();
assertEquals(":b: Image.getBoundsInPixels method doesn't return bounds in Pixel values.", boundsInPixels, DPIUtil.autoScaleUp(bounds));
// create image with FileNameProvider
image = new Image(display, imageFileNameProvider);
boundsInPixels = image.getBoundsInPixels();
bounds = image.getBounds();
image.dispose();
assertEquals(":c: Image.getBoundsInPixels method doesn't return bounds in Pixel values.", boundsInPixels, DPIUtil.autoScaleUp(bounds));
// create image with ImageDataProvider
image = new Image(display, imageDataProvider);
boundsInPixels = image.getBoundsInPixels();
bounds = image.getBounds();
image.dispose();
assertEquals(":d: Image.getBoundsInPixels method doesn't return bounds in Pixel values.", boundsInPixels, DPIUtil.autoScaleUp(bounds));
}
Aggregations