use of org.eclipse.swt.SWTException in project eclipse.platform.swt by eclipse.
the class ImageAnalyzer method showErrorDialog.
/*
* Open an error dialog displaying the specified information.
*/
void showErrorDialog(String operation, String filename, Throwable e) {
MessageBox box = new MessageBox(shell, SWT.ICON_ERROR);
String message = createMsg(bundle.getString("Error"), new String[] { operation, filename });
String errorMessage = "";
if (e != null) {
if (e instanceof SWTException) {
SWTException swte = (SWTException) e;
errorMessage = swte.getMessage();
if (swte.throwable != null) {
errorMessage += ":\n" + swte.throwable.toString();
}
} else if (e instanceof SWTError) {
SWTError swte = (SWTError) e;
errorMessage = swte.getMessage();
if (swte.throwable != null) {
errorMessage += ":\n" + swte.throwable.toString();
}
} else {
errorMessage = e.toString();
}
}
box.setMessage(message + errorMessage);
box.open();
}
use of org.eclipse.swt.SWTException in project eclipse.platform.swt by eclipse.
the class SwtTestUtil method assertSWTProblem.
public static void assertSWTProblem(String message, int expectedCode, Throwable actualThrowable) {
if (actualThrowable instanceof SWTError) {
SWTError error = (SWTError) actualThrowable;
assertEquals(message, expectedCode, error.code);
} else if (actualThrowable instanceof SWTException) {
SWTException exception = (SWTException) actualThrowable;
assertEquals(message, expectedCode, exception.code);
} else {
try {
SWT.error(expectedCode);
} catch (Throwable expectedThrowable) {
if (actualThrowable.getMessage().length() > expectedThrowable.getMessage().length()) {
assertTrue(message, actualThrowable.getMessage().startsWith(expectedThrowable.getMessage()));
} else {
assertEquals(message, expectedThrowable.getMessage(), actualThrowable.getMessage());
}
}
}
}
use of org.eclipse.swt.SWTException in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_SWTException method test_printStackTrace.
@Test
public void test_printStackTrace() {
try {
Class.forName("java.io.PrintStream");
} catch (ClassNotFoundException e) {
// ignore test if running on CLDC
return;
}
// test default SWTException
ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setErr(new PrintStream(out));
SWTException error = new SWTException();
error.printStackTrace();
assertTrue(out.size() > 0);
assertTrue(new String(out.toByteArray()).indexOf("test_printStackTrace") != -1);
// test SWTException with code
out = new ByteArrayOutputStream();
System.setErr(new PrintStream(out));
error = new SWTException(SWT.ERROR_INVALID_ARGUMENT);
error.printStackTrace();
assertTrue(out.size() > 0);
assertTrue(new String(out.toByteArray()).indexOf("test_printStackTrace") != -1);
}
use of org.eclipse.swt.SWTException in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_browser_Browser method test_OpenWindowListener_evaluateInCallback.
/**
* Verify that evaluation works inside an OpenWindowListener
*/
@Test
public void test_OpenWindowListener_evaluateInCallback() {
// This works on Webkit1, but can sporadically fail, see Bug 509411
assumeTrue(!isWebkit1);
AtomicBoolean eventFired = new AtomicBoolean(false);
browser.addOpenWindowListener(event -> {
browser.evaluate("SWTopenListener = true");
eventFired.set(true);
event.required = true;
});
shell.open();
browser.evaluate("window.open()");
boolean fired = waitForPassCondition(() -> eventFired.get());
boolean evaluated = false;
try {
evaluated = (Boolean) browser.evaluate("return SWTopenListener");
} catch (SWTException e) {
}
boolean passed = fired && evaluated;
String errMsg = "Event fired:" + fired + " evaluated:" + evaluated;
assertTrue(errMsg, passed);
}
use of org.eclipse.swt.SWTException in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_browser_Browser method test_evaluate_invalid_return_value.
/**
* Test the evaluate() api that throws the invalid return value exception. Functionality based on Snippet308.
* Only wait till success. Otherwise timeout after 3 seconds.
*/
@Test
public void test_evaluate_invalid_return_value() {
// Bug 509411
assumeFalse(webkit1SkipMsg(), isWebkit1);
if (SwtTestUtil.isWindows) {
/* Bug 508210 . Inconsistent beahiour on windows at the moment.
* Fixing requires deeper investigation. Disabling newly added test for now.
*/
return;
}
final AtomicInteger exception = new AtomicInteger(-1);
browser.addProgressListener(completedAdapter(event -> {
try {
// Date is not supoprted as return value.
browser.evaluate("return new Date()");
} catch (SWTException e) {
exception.set(e.code);
}
}));
browser.setText("<html><body>HelloWorld</body></html>");
shell.open();
AtomicBoolean wrongExceptionCode = new AtomicBoolean(false);
boolean passed = waitForPassCondition(() -> {
if (exception.get() != -1) {
if (exception.get() == SWT.ERROR_INVALID_RETURN_VALUE) {
return true;
} else if (exception.get() == SWT.ERROR_FAILED_EVALUATE) {
wrongExceptionCode.set(true);
return true;
}
}
return false;
});
if (wrongExceptionCode.get()) {
System.err.println("SWT Warning: test_evaluate_invalid_return_value threw wrong exception code." + " Expected ERROR_INVALID_RETURN_VALUE but got ERROR_FAILED_EVALUATE");
}
String message = exception.get() == -1 ? "Exception was not thrown. Test timed out" : "Exception thrown, but wrong code: " + exception.get();
assertTrue(message, passed);
}
Aggregations