Skip to content

Commit

Permalink
abstract Widget tests: take screenshot before dispose
Browse files Browse the repository at this point in the history
  • Loading branch information
EcljpseB0T committed Oct 11, 2024
1 parent 552167f commit 35f6c19
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand All @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -750,9 +745,6 @@ public void test_showSelection() {
tree.showSelection();
}

/* custom */
public Tree tree;

/**
* Clean up the environment for a new test.
*
Expand Down Expand Up @@ -916,9 +908,6 @@ public void test_disposeItemNotTriggerSelection() {
assertFalse(selectionCalled[0]);
}

@Rule
public TestWatcher screenshotRule = Screenshots.onFailure();

@Test
public void test_Virtual() {
tree.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
/**
Expand All @@ -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() {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 35f6c19

Please sign in to comment.