Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Williams2017-07-31 19:07:43 +0000
committerEric Williams2017-08-08 14:58:07 +0000
commitb69831d4025b9c00cf4f5f43b3a78aafa674e76d (patch)
tree7df28c28149589138a71269c260fc41079ba9266
parent273ade8c541f21b3434b810031a943cba2fe72f9 (diff)
downloadeclipse.platform.swt-b69831d4025b9c00cf4f5f43b3a78aafa674e76d.tar.gz
eclipse.platform.swt-b69831d4025b9c00cf4f5f43b3a78aafa674e76d.tar.xz
eclipse.platform.swt-b69831d4025b9c00cf4f5f43b3a78aafa674e76d.zip
Bug 519576: [GTK3] Use GTK CSS for background/foreground colors on
GTK3.14 and below Test cases to prevent issues with background/foreground colors for SWT.CHECK and SWT.RADIO Buttons. Change-Id: I270b060639c80d0c2c9c22602ec04ce79ad4a4f4 Signed-off-by: Eric Williams <ericwill@redhat.com>
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Button.java166
1 files changed, 166 insertions, 0 deletions
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Button.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Button.java
index 10bf66d982..03f823737c 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Button.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Button.java
@@ -15,10 +15,12 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Event;
@@ -171,6 +173,96 @@ public void test_setAlignmentI() {
assertTrue(alignment != button.getAlignment());
}
+@Test
+public void test_setBackgroundCheckButton() {
+ Button checkButton = new Button(shell, SWT.CHECK);
+ Color color = new Color(checkButton.getDisplay(), 255, 0, 0);
+ checkButton.setBackground(color);
+ assertEquals("getBackground not equal after setBackground for SWT.CHECK Button",
+ color, checkButton.getBackground());
+ checkButton.setBackground(null);
+ assertTrue("getBackground unchanged after setBackground(null) for SWT.CHECK Button",
+ !checkButton.getBackground().equals(color));
+ color.dispose();
+ color = new Color(checkButton.getDisplay(), 255, 0, 0, 0);
+ checkButton.setBackground(color);
+ assertEquals("getBackground not equal after setBackground with 0 alpha for SWT.CHECK Button",
+ color, checkButton.getBackground());
+ checkButton.setBackground(null);
+ assertTrue("getBackground unchanged after setBackground(null) with 0 alpha for SWT.CHECK Button",
+ !checkButton.getBackground().equals(color));
+ if ("gtk".equals(SWT.getPlatform ())) {
+ Color fg = new Color(checkButton.getDisplay(), 0, 255, 0);
+ checkButton.setBackground(color);
+ checkButton.setForeground(fg);
+ assertEquals("Setting a foreground disrupted the background color for SWT.CHECK Button",
+ color, checkButton.getBackground());
+ assertEquals("Setting a foreground onto an SWT.CHECK Button with a background failed",
+ fg, checkButton.getForeground());
+ }
+ color.dispose();
+ checkButton.dispose();
+}
+
+@Test
+public void test_setBackgroundAlphaCheckButton() {
+ Button checkButton = new Button(shell, SWT.CHECK);
+ Color color = new Color (checkButton.getDisplay(), 255, 0, 0, 0);
+ checkButton.setBackground(color);
+ assertEquals(color, checkButton.getBackground());
+ Color fg = new Color(checkButton.getDisplay(), 0, 255, 0, 0);
+ checkButton.setForeground(fg);
+ assertEquals(color, checkButton.getBackground());
+ color.dispose();
+ fg.dispose();
+ checkButton.dispose();
+}
+
+@Test
+public void test_setBackgroundRadioButton() {
+ Button radioButton = new Button(shell, SWT.RADIO);
+ Color color = new Color(radioButton.getDisplay(), 255, 0, 0);
+ radioButton.setBackground(color);
+ assertEquals("getBackground not equal after setBackground for SWT.RADIO Button",
+ color, radioButton.getBackground());
+ radioButton.setBackground(null);
+ assertTrue("getBackground unchanged after setBackground(null) for SWT.RADIO Button",
+ !radioButton.getBackground().equals(color));
+ color.dispose();
+ color = new Color(radioButton.getDisplay(), 255, 0, 0, 0);
+ radioButton.setBackground(color);
+ assertEquals("getBackground not equal after setBackground with 0 alpha for SWT.RADIO Button",
+ color, radioButton.getBackground());
+ radioButton.setBackground(null);
+ assertTrue("getBackground unchanged after setBackground(null) with 0 alpha for SWT.RADIO Button",
+ !radioButton.getBackground().equals(color));
+ if ("gtk".equals(SWT.getPlatform ())) {
+ Color fg = new Color(radioButton.getDisplay(), 0, 255, 0);
+ radioButton.setBackground(color);
+ radioButton.setForeground(fg);
+ assertEquals("Setting a foreground disrupted the background color for SWT.RADIO Button",
+ color, radioButton.getBackground());
+ assertEquals("Setting a foreground onto an SWT.RADIO Button with a background failed",
+ fg, radioButton.getForeground());
+ }
+ color.dispose();
+ radioButton.dispose();
+}
+
+@Test
+public void test_setBackgroundAlphaRadioButton() {
+ Button radioButton = new Button(shell, SWT.RADIO);
+ Color color = new Color (radioButton.getDisplay(), 255, 0, 0, 0);
+ radioButton.setBackground(color);
+ assertEquals(color, radioButton.getBackground());
+ Color fg = new Color(radioButton.getDisplay(), 0, 255, 0, 0);
+ radioButton.setForeground(fg);
+ assertEquals(color, radioButton.getBackground());
+ color.dispose();
+ fg.dispose();
+ radioButton.dispose();
+}
+
@Override
@Test
public void test_setFocus() {
@@ -179,6 +271,80 @@ public void test_setFocus() {
}
@Test
+public void test_setForegroundCheckButton() {
+ Button checkButton = new Button(shell, SWT.CHECK);
+ Color color = new Color(checkButton.getDisplay(), 255, 0, 0);
+ checkButton.setForeground(color);
+ assertEquals(color, checkButton.getForeground());
+ checkButton.setForeground(null);
+ assertFalse(checkButton.getForeground().equals(color));
+ if ("gtk".equals(SWT.getPlatform ())) {
+ Color bg = new Color(checkButton.getDisplay(), 0, 255, 0);
+ checkButton.setForeground(color);
+ checkButton.setBackground(bg);
+ assertEquals("Setting a background disrupted the foreground color for SWT.CHECK Button",
+ color, checkButton.getForeground());
+ assertEquals("Setting a background onto an SWT.CHECK Button with a foreground failed",
+ bg, checkButton.getBackground());
+ }
+ color.dispose();
+ checkButton.dispose();
+}
+
+@Test
+public void test_setForegroundAlphaCheckButton() {
+ Button checkButton = new Button(shell, SWT.CHECK);
+ assumeTrue("Alpha support for foreground colors does not exist on GTK2 or Win32",
+ SwtTestUtil.isCocoa || SwtTestUtil.isGTK3());
+ Color color = new Color (checkButton.getDisplay(), 255, 0, 0, 0);
+ checkButton.setForeground(color);
+ assertEquals(color, checkButton.getForeground());
+ Color bg = new Color(checkButton.getDisplay(), 0, 255, 0, 0);
+ checkButton.setBackground(bg);
+ assertEquals(color, checkButton.getForeground());
+ color.dispose();
+ bg.dispose();
+ checkButton.dispose();
+}
+
+@Test
+public void test_setForegroundRadioButton() {
+ Button radioButton = new Button(shell, SWT.RADIO);
+ Color color = new Color(radioButton.getDisplay(), 255, 0, 0);
+ radioButton.setForeground(color);
+ assertEquals(color, radioButton.getForeground());
+ radioButton.setForeground(null);
+ assertFalse(radioButton.getForeground().equals(color));
+ if ("gtk".equals(SWT.getPlatform ())) {
+ Color bg = new Color(radioButton.getDisplay(), 0, 255, 0);
+ radioButton.setForeground(color);
+ radioButton.setBackground(bg);
+ assertEquals("Setting a background disrupted the foreground color for SWT.RADIO Button",
+ color, radioButton.getForeground());
+ assertEquals("Setting a background onto an SWT.RADIO Button with a foreground failed",
+ bg, radioButton.getBackground());
+ }
+ color.dispose();
+ radioButton.dispose();
+}
+
+@Test
+public void test_setForegroundAlphaRadiokButton() {
+ Button radioButton = new Button(shell, SWT.RADIO);
+ assumeTrue("Alpha support for foreground colors does not exist on GTK2 or Win32",
+ SwtTestUtil.isCocoa || SwtTestUtil.isGTK3());
+ Color color = new Color (radioButton.getDisplay(), 255, 0, 0, 0);
+ radioButton.setForeground(color);
+ assertEquals(color, radioButton.getForeground());
+ Color bg = new Color(radioButton.getDisplay(), 0, 255, 0, 0);
+ radioButton.setBackground(bg);
+ assertEquals(color, radioButton.getForeground());
+ color.dispose();
+ bg.dispose();
+ radioButton.dispose();
+}
+
+@Test
public void test_setImageLorg_eclipse_swt_graphics_Image() {
Image image = button.getImage();
button.setImage(image);

Back to the top