diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java index a126b6735b6..c5d5e345c8b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java @@ -4937,7 +4937,6 @@ public static void error (int code, Throwable throwable, String detail) { case ERROR_CANNOT_SET_TEXT: case ERROR_ITEM_NOT_ADDED: case ERROR_ITEM_NOT_REMOVED: - case ERROR_NO_HANDLES: //FALL THROUGH /* SWT Errors (fatal, may occur only on some platforms) */ @@ -4949,6 +4948,10 @@ public static void error (int code, Throwable throwable, String detail) { error.throwable = throwable; throw error; } + case ERROR_NO_HANDLES: + SWTError error = new SWTError (code, message); + error.throwable = throwable; + throw error; } /* Unknown/Undefined Error */ diff --git a/tests/org.eclipse.swt.tests.win32/JUnit Tests/org/eclipse/swt/tests/win32/KeyboardLayoutTest.java b/tests/org.eclipse.swt.tests.win32/JUnit Tests/org/eclipse/swt/tests/win32/KeyboardLayoutTest.java index 6674e27bf3b..0c7f78d3b1f 100644 --- a/tests/org.eclipse.swt.tests.win32/JUnit Tests/org/eclipse/swt/tests/win32/KeyboardLayoutTest.java +++ b/tests/org.eclipse.swt.tests.win32/JUnit Tests/org/eclipse/swt/tests/win32/KeyboardLayoutTest.java @@ -255,8 +255,12 @@ public void setUp() { @After public void tearDown() { - shell.dispose(); - display.dispose(); + if (shell != null) { + shell.dispose(); + } + if (display != null) { + display.dispose(); + } } protected static void failOnApiError(String name) { diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java index e604ad0696b..e460ab4a619 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java @@ -76,12 +76,9 @@ import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.ScrollBar; import org.eclipse.swt.widgets.Widget; -import org.eclipse.test.Screenshots; import org.junit.Assume; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.TestWatcher; /** * Automated Test Suite for class org.eclipse.swt.custom.StyledText @@ -103,9 +100,6 @@ public class Test_org_eclipse_swt_custom_StyledText extends Test_org_eclipse_swt private boolean listenerCalled; private boolean listener2Called; -@Rule -public TestWatcher screenshotRule = Screenshots.onFailure(); - @Override @Before public void setUp() { diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText_multiCaretsSelections.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText_multiCaretsSelections.java index b04c25230ec..71580ee9244 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText_multiCaretsSelections.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText_multiCaretsSelections.java @@ -39,9 +39,6 @@ */ public class Test_org_eclipse_swt_custom_StyledText_multiCaretsSelections { - @Rule - public TestWatcher screenshotRule = Screenshots.onFailure(); - Shell shell; StyledText text; GC gc; @@ -53,10 +50,12 @@ public void setUp() { gc = new GC(text); } + @Rule + public TestWatcher screenshotRule = Screenshots.onFailure(() -> this.shell); + @After public void tearDown() { gc.dispose(); - shell.dispose(); } @Test public void test_MultiSelectionEdit() { diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Tree.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Tree.java index e0b7732dc6a..cefb3846c7c 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Tree.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Tree.java @@ -33,12 +33,8 @@ import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeColumn; import org.eclipse.swt.widgets.TreeItem; -import org.eclipse.test.Screenshots; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.TestName; -import org.junit.rules.TestWatcher; /** * Automated Test Suite for class org.eclipse.swt.widgets.Tree @@ -47,8 +43,7 @@ */ public class Test_org_eclipse_swt_widgets_Tree extends Test_org_eclipse_swt_widgets_Composite { -@Rule -public TestName testName = new TestName(); +private Tree tree; @Override @Before @@ -750,9 +745,6 @@ public void test_showSelection() { tree.showSelection(); } -/* custom */ -public Tree tree; - /** * Clean up the environment for a new test. * @@ -916,9 +908,6 @@ public void test_disposeItemNotTriggerSelection() { assertFalse(selectionCalled[0]); } -@Rule -public TestWatcher screenshotRule = Screenshots.onFailure(); - @Test public void test_Virtual() { tree.dispose(); diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Widget.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Widget.java index e119f1fd008..b57995ebdcf 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Widget.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Widget.java @@ -31,6 +31,7 @@ import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Widget; +import org.eclipse.test.Screenshots.ScreenshotOnFailure; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -42,7 +43,10 @@ * * @see org.eclipse.swt.widgets.Widget */ -public class Test_org_eclipse_swt_widgets_Widget{ +abstract class Test_org_eclipse_swt_widgets_Widget{ + protected Shell shell; + private Widget widget; + // Use this variable to help validate callbacks boolean listenerCalled; /** @@ -56,36 +60,39 @@ public void setUp() { shell = new Shell(); } +@Rule +public ScreenshotOnFailure screenshotRule = new ScreenshotOnFailure(()-> this.shell) { + @Override + public void dispose() { + Display display = null; + if (!disposedIntentionally) { + assertFalse(shell.isDisposed()); + display = shell.getDisplay(); + } + super.dispose(); + if (widget != null) { + assertTrue(widget.isDisposed()); + if(SwtTestUtil.isLinux && display != null) { + assertNotExists(getWidgetTable(display), widget); + } + } + assertTrue(shell.isDisposed()); + if(SwtTestUtil.isCocoa || SwtTestUtil.isGTK) { + // process pending events to properly close the shell + while (display != null && !display.isDisposed() && display.readAndDispatch()) { + } + } + if(SwtTestUtil.isLinux && display != null) { + assertNotExists(getWidgetTable(display), shell); + } + } +}; + @After public void tearDown() { if (widget != null) { assertEquals(disposedIntentionally, widget.isDisposed()); } - Display display = null; - if (!disposedIntentionally) { - assertFalse(shell.isDisposed()); - display = shell.getDisplay(); - } - shell.dispose(); - if (widget != null) { - assertTrue(widget.isDisposed()); - if(SwtTestUtil.isLinux && display != null) { - assertNotExists(getWidgetTable(display), widget); - } - } - assertTrue(shell.isDisposed()); - if(SwtTestUtil.isCocoa || SwtTestUtil.isGTK) { - // process pending events to properly close the shell - while (display != null && !display.isDisposed() && display.readAndDispatch()) { - } - } - if(SwtTestUtil.isLinux && display != null) { - assertNotExists(getWidgetTable(display), shell); - } -} -@Test -public void test_ConstructorLorg_eclipse_swt_widgets_WidgetI() { - // abstract class } @Test public void test_addDisposeListenerLorg_eclipse_swt_events_DisposeListener() { @@ -174,10 +181,6 @@ public void test_toString() { assertTrue(widget.toString().length() > 0); } -/* custom */ -public Shell shell; -private Widget widget; - protected void setWidget(Widget w) { widget = w; }