diff options
Diffstat (limited to 'tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java')
-rw-r--r-- | tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java | 117 |
1 files changed, 105 insertions, 12 deletions
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java index ebc6f7ca72..4572ae2181 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -23,9 +23,11 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.IOException; import java.util.concurrent.atomic.AtomicBoolean; import org.eclipse.swt.SWT; +import org.eclipse.swt.SWTException; import org.eclipse.swt.graphics.DeviceData; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; @@ -40,6 +42,7 @@ import org.eclipse.swt.widgets.Monitor; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Synchronizer; import org.eclipse.test.Screenshots; +import org.junit.Assume; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; @@ -217,12 +220,13 @@ public void test_findDisplayLjava_lang_Thread() { @Test public void test_getActiveShell() { + Assume.assumeFalse("Test fails on Mac: Bug 536564", SwtTestUtil.isCocoa); Display display = new Display(); try { Shell shell = new Shell(display); shell.setText("test_getActiveShell"); shell.open(); - drainEventQueue(display, 5000); // workaround for https://bugs.eclipse.org/506680 + drainEventQueue(display, 150); // workaround for https://bugs.eclipse.org/506680 assertSame(shell, display.getActiveShell()); shell.dispose(); } finally { @@ -274,7 +278,7 @@ public void test_getClientArea() { public void test_getCurrent() { Display display = new Display(); try { - assertTrue(display.getThread() == Thread.currentThread()); + assertSame(display.getThread(), Thread.currentThread()); } finally { display.dispose(); } @@ -395,7 +399,7 @@ public void test_getShells() { try { Shell shell1 = new Shell(display); Shell shell2 = new Shell(display); - assertTrue(display.getShells().length == 2); + assertEquals(2, display.getShells().length); shell1.dispose(); shell2.dispose(); } finally { @@ -456,8 +460,8 @@ public void test_getSystemColorI() { SWT.COLOR_LIST_BACKGROUND, SWT.COLOR_LIST_SELECTION, SWT.COLOR_LIST_SELECTION_TEXT, }; - for (int i=0; i < colorIds.length; i++) { - assertNotNull(display.getSystemColor(colorIds[i])); + for (int colorId : colorIds) { + assertNotNull(display.getSystemColor(colorId)); } } finally { display.dispose(); @@ -479,7 +483,7 @@ public void test_getSystemFont() { public void test_getThread() { Display display = new Display(); try { - assertTrue(display.getThread() == Thread.currentThread()); + assertSame(display.getThread(), Thread.currentThread()); } finally { display.dispose(); } @@ -1020,8 +1024,8 @@ public void test_mapLorg_eclipse_swt_widgets_ControlLorg_eclipse_swt_widgets_Con @Test public void test_postLorg_eclipse_swt_widgets_Event() { - if (SwtTestUtil.isGTK || SwtTestUtil.isCocoa) { - //TODO Fix GTK and Cocoa failure. + if (SwtTestUtil.isGTK || SwtTestUtil.isCocoa || SwtTestUtil.isWindows ) { + //TODO Fix/revisit GTK, Cocoa and Win10 failure test-case via bug 553754 if (SwtTestUtil.verbose) { System.out.println("Excluded test_postLorg_eclipse_swt_widgets_Event(org.eclipse.swt.tests.junit.Test_org_eclipse_swt_widgets_Display)"); } @@ -1246,7 +1250,7 @@ public void test_setDataLjava_lang_Object() { display.setData(Integer.valueOf(10)); Integer i = (Integer)display.getData(); assertNotNull(i); - assertTrue(i.equals(Integer.valueOf(10))); + assertEquals(Integer.valueOf(10), i); } finally { display.dispose(); } @@ -1260,10 +1264,10 @@ public void test_setDataLjava_lang_StringLjava_lang_Object() { display.setData("String", "xyz"); Integer i = (Integer)display.getData("Integer"); assertNotNull(i); - assertTrue(i.equals(Integer.valueOf(10))); + assertEquals(Integer.valueOf(10), i); String s = (String)display.getData("String"); assertNotNull(s); - assertTrue(s.equals("xyz")); + assertEquals("xyz", s); } finally { display.dispose(); } @@ -1383,6 +1387,89 @@ public void test_syncExecLjava_lang_Runnable_dispose() { } @Test +public void test_syncCall() { + final Display display = new Display(); + try { + int depth=display.syncCall(() -> display.getDepth()); + assertEquals(display.getDepth(), depth); + } finally { + display.dispose(); + } +} + +@Test +public void test_syncCall_dispose() { + final Display display = new Display(); + try { + int magic=display.syncCall(() -> {display.dispose(); return 42;}); + assertEquals(42, magic); + } finally { + assertTrue(display.isDisposed()); + } +} +@Test +public void test_syncCall_RuntimeException() { + final Display display = new Display(); + try { + int depth=display.syncCall(() -> {throw new IllegalArgumentException("42");}); + assertFalse("should not be reached "+depth, true); + } catch (RuntimeException e) { + assertEquals("42", e.getMessage()); + } finally { + display.dispose(); + } +} +@Test +public void test_syncCall_Exception() { + final Display display = new Display(); + try { + int depth=display.syncCall(() -> {throw new IOException("42");}); + assertFalse("should not be reached "+depth, true); + } catch (IOException e) { + assertEquals("42", e.getMessage()); + } finally { + display.dispose(); + } +} +@Test +public void test_syncCall_SWTException() { + final Display display = new Display(); + display.dispose(); + try { + int magic=display.syncCall(() -> {display.dispose(); return 42;}); + assertFalse("should not be reached "+magic, true); + } catch (SWTException e) { + assertEquals("Device is disposed", e.getMessage()); + } +} +@Test +public void test_syncCall_concurrentCallable() { + final Display display = new Display(); + try { + java.util.concurrent.Callable<Integer> c=() -> {return 42;}; + int magic=display.syncCall(c::call); + assertEquals(42, magic); + } catch (Exception e) { + assertFalse("should not be reached ", true); + } finally { + display.dispose(); + } +} +@Test +public void test_syncCall_concurrentCallable_Exception() { + final Display display = new Display(); + try { + java.util.concurrent.Callable<Integer> c=() -> {throw new IOException("42");}; + int depth=display.syncCall(c::call); + assertFalse("should not be reached "+depth, true); + } catch (Exception e) { + assertEquals("42", e.getMessage()); + } finally { + display.dispose(); + } +} + +@Test public void test_timerExecILjava_lang_Runnable() { final Display display = new Display(); try { @@ -1507,4 +1594,10 @@ public void test_setWarningsZ() { display.dispose(); } } + +@Test +public void test_isSystemDarkTheme() { + System.out.println("org.eclipse.swt.widgets.Display.isSystemDarkTheme(): " + Display.isSystemDarkTheme()); +} + } |