Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThibault Le Ouay2014-11-11 14:37:31 +0000
committerLars Vogel2014-11-28 12:37:43 +0000
commit1673baf681695bf419f1bd75ea73936b3e8c21ea (patch)
tree37a6250fc2b05b8a87b567aaf16dd50931beaa72
parente9159952c7f1ad32201c60f59407ff1116892e76 (diff)
downloadeclipse.platform.ui-1673baf681695bf419f1bd75ea73936b3e8c21ea.tar.gz
eclipse.platform.ui-1673baf681695bf419f1bd75ea73936b3e8c21ea.tar.xz
eclipse.platform.ui-1673baf681695bf419f1bd75ea73936b3e8c21ea.zip
Bug 443094 - [CSS]Move org.eclipse.e4.ui.tests.css.swt tests to JUnit4
Change-Id: I74acd6cfd929c019279c6f4afb9df9261bf60b7a Signed-off-by: Thibault Le Ouay <thibaultleouay@gmail.com>
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/CSS SWT Test Suite.launch2
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/core/resources/CSSResourcesHelpersTest.java46
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/core/resources/SWTResourceRegistryKeyFactoryTest.java35
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/core/resources/SWTResourcesRegistryTest.java15
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTColorHelperTest.java44
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTFontHelperTest.java28
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTHelperTestCase.java37
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/EclipsePreferencesHelperTest.java33
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/PreferenceOverriddenByCssChangeListenerTest.java30
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/properties/preference/EclipsePreferencesHandlerTest.java46
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/Bug419482Test.java43
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ButtonTest.java89
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ButtonTextTransformTest.java15
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CSSSWTTestCase.java98
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CSSSWTWidgetTest.java50
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CTabFolderTest.java142
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CTabItemTest.java525
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ColorDefinitionTest.java51
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CssSwtTestSuite.java66
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/DescendentTest.java35
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/FontDefinitionTest.java67
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/GradientTest.java124
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/IEclipsePreferencesTest.java16
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/IdClassLabelColorTest.java35
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/InheritTest.java24
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/InnerClassElementTest.java12
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/LabelTest.java72
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/LabelTextTransformTest.java15
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/MarginTest.java60
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ShellActiveTest.java26
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ShellTest.java153
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/TestPropertyHelper.java34
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/TextTextTransformTest.java15
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/TextTransformTest.java22
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ThemeTest.java35
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ThemesExtensionTest.java22
36 files changed, 1193 insertions, 969 deletions
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/CSS SWT Test Suite.launch b/tests/org.eclipse.e4.ui.tests.css.swt/CSS SWT Test Suite.launch
index 75409641a90..a661f27446a 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/CSS SWT Test Suite.launch
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/CSS SWT Test Suite.launch
@@ -25,7 +25,7 @@
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
-<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
+<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.e4.ui.tests.css.swt.CssSwtTestSuite"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.e4.ui.tests.css.swt"/>
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/core/resources/CSSResourcesHelpersTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/core/resources/CSSResourcesHelpersTest.java
index 477f67262cf..ed7f34b90c6 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/core/resources/CSSResourcesHelpersTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/core/resources/CSSResourcesHelpersTest.java
@@ -1,55 +1,59 @@
/*******************************************************************************
- * Copyright (c) 2013 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2013, 2014 IBM Corporation and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.css.core.resources;
-import static org.eclipse.e4.ui.css.core.resources.CSSResourcesHelpers.getCSSValueKey;
import static org.eclipse.e4.ui.css.core.resources.CSSResourcesHelpers.getCSSFontPropertiesKey;
+import static org.eclipse.e4.ui.css.core.resources.CSSResourcesHelpers.getCSSValueKey;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import org.eclipse.e4.ui.css.core.dom.properties.css2.CSS2FontProperties;
import org.eclipse.e4.ui.css.swt.helpers.CSSSWTHelperTestCase;
+import org.junit.Test;
import org.w3c.dom.css.CSSPrimitiveValue;
@SuppressWarnings("restriction")
-public class CSSResourcesHelpersTest extends CSSSWTHelperTestCase {
- public void testGetCSSValueKeyWhenFont() throws Exception {
- CSS2FontProperties fontProperties = fontProperties("Arial", 10, null);
-
+public class CSSResourcesHelpersTest extends CSSSWTHelperTestCase {
+ @Test
+ public void testGetCSSValueKeyWhenFont() {
+ CSS2FontProperties fontProperties = null;
+ fontProperties = fontProperties("Arial", 10, null);
String result = getCSSValueKey(fontProperties);
-
assertNotNull(result);
assertEquals(getCSSFontPropertiesKey(fontProperties), result);
}
-
- public void testGetCSSValueKeyWhenDefinitionAsFontFamily() throws Exception {
- CSS2FontProperties fontProperties = fontProperties(addFontDefinitionMarker("symbolicName"), 10, null);
-
+
+ @Test
+ public void testGetCSSValueKeyWhenDefinitionAsFontFamily() {
+ CSS2FontProperties fontProperties = null;
+ fontProperties = fontProperties(addFontDefinitionMarker("symbolicName"), 10, null);
String result = getCSSValueKey(fontProperties);
-
assertNotNull(result);
assertEquals(getCSSFontPropertiesKey(fontProperties), result);
}
-
- public void testGetCSSValueKeyWhenRgbAsColorValue() throws Exception {
+
+ @Test
+ public void testGetCSSValueKeyWhenRgbAsColorValue() {
CSSPrimitiveValue colorValue = colorValue("rgb(255,0,0)");
-
String result = getCSSValueKey(colorValue);
-
assertNotNull(result);
assertEquals("rgb(255,0,0)", result);
}
-
- public void testGetCSSValueKeyWhenDefinitionAsColorValue() throws Exception {
+
+ @Test
+ public void testGetCSSValueKeyWhenDefinitionAsColorValue() {
CSSPrimitiveValue colorValue = colorValue(addColorDefinitionMarker("symbolicName"));
-
+
String result = getCSSValueKey(colorValue);
-
+
assertNotNull(result);
assertEquals("#symbolicName", result);
}
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/core/resources/SWTResourceRegistryKeyFactoryTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/core/resources/SWTResourceRegistryKeyFactoryTest.java
index 50cdd871efb..3cf4bc540b0 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/core/resources/SWTResourceRegistryKeyFactoryTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/core/resources/SWTResourceRegistryKeyFactoryTest.java
@@ -1,28 +1,35 @@
/*******************************************************************************
- * Copyright (c) 2013 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2013, 2014 IBM Corporation and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.css.core.resources;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
import org.eclipse.e4.ui.css.core.dom.properties.css2.CSS2FontProperties;
import org.eclipse.e4.ui.css.swt.helpers.CSSSWTHelperTestCase;
import org.eclipse.e4.ui.css.swt.resources.ResourceByDefinitionKey;
import org.eclipse.e4.ui.css.swt.resources.SWTResourceRegistryKeyFactory;
import org.eclipse.swt.SWT;
+import org.junit.Test;
import org.w3c.dom.css.CSSPrimitiveValue;
@SuppressWarnings("restriction")
public class SWTResourceRegistryKeyFactoryTest extends CSSSWTHelperTestCase {
private SWTResourceRegistryKeyFactory factory = new SWTResourceRegistryKeyFactory();
- public void testCreateKeyWhenFontProperty() throws Exception {
- CSS2FontProperties fontProperties = fontProperties("Arial", 12,
- SWT.ITALIC);
+ @Test
+ public void testCreateKeyWhenFontProperty() {
+ CSS2FontProperties fontProperties = null;
+ fontProperties = fontProperties("Arial", 12, SWT.ITALIC);
+
Object result = factory.createKey(fontProperties);
@@ -30,7 +37,8 @@ public class SWTResourceRegistryKeyFactoryTest extends CSSSWTHelperTestCase {
assertEquals(CSSResourcesHelpers.getCSSValueKey(fontProperties), result);
}
- public void testCreateKeyWhenColorValue() throws Exception {
+ @Test
+ public void testCreateKeyWhenColorValue() {
CSSPrimitiveValue colorValue = colorValue("red");
Object result = factory.createKey(colorValue);
@@ -39,10 +47,14 @@ public class SWTResourceRegistryKeyFactoryTest extends CSSSWTHelperTestCase {
assertEquals(CSSResourcesHelpers.getCSSValueKey(colorValue), result);
}
- public void testCreateKeyWhenFontByDefinition() throws Exception {
- CSS2FontProperties fontProperties = fontProperties(
- "#font-by-definition", 12,
- SWT.ITALIC);
+ @Test
+ public void testCreateKeyWhenFontByDefinition() {
+ CSS2FontProperties fontProperties = null;
+ try {
+ fontProperties = fontProperties("#font-by-definition", 12, SWT.ITALIC);
+ } catch (Exception e) {
+ fail("FontProperties should not throw exception");
+ }
Object result = factory.createKey(fontProperties);
@@ -50,7 +62,8 @@ public class SWTResourceRegistryKeyFactoryTest extends CSSSWTHelperTestCase {
assertEquals(CSSResourcesHelpers.getCSSValueKey(fontProperties).toString(), result.toString());
}
- public void testCreateKeyWhenColorByDefinition() throws Exception {
+ @Test
+ public void testCreateKeyWhenColorByDefinition() {
CSSPrimitiveValue colorValue = colorValue("#color-by-definition");
Object result = factory.createKey(colorValue);
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/core/resources/SWTResourcesRegistryTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/core/resources/SWTResourcesRegistryTest.java
index 50a9826ec7f..39716571583 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/core/resources/SWTResourcesRegistryTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/core/resources/SWTResourcesRegistryTest.java
@@ -1,14 +1,17 @@
/*******************************************************************************
- * Copyright (c) 2013 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2013, 2014 IBM Corporation and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.css.core.resources;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@@ -18,16 +21,16 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import junit.framework.TestCase;
-
import org.eclipse.e4.ui.css.swt.resources.ResourceByDefinitionKey;
import org.eclipse.e4.ui.css.swt.resources.SWTResourcesRegistry;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Resource;
+import org.junit.Test;
@SuppressWarnings("restriction")
-public class SWTResourcesRegistryTest extends TestCase {
- public void testRemoveResourcesByKeyTypeAndType() throws Exception {
+public class SWTResourcesRegistryTest {
+ @Test
+ public void testRemoveResourcesByKeyTypeAndType() {
//given
final Resource resource1 = mock(Resource.class);
final Resource resource2 = mock(Resource.class);
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTColorHelperTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTColorHelperTest.java
index a65cc86e7f8..09a6c9c0c1f 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTColorHelperTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTColorHelperTest.java
@@ -1,48 +1,67 @@
/*******************************************************************************
- * Copyright (c) 2013 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2013, 2014 IBM Corporation and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.css.swt.helpers;
import static org.eclipse.e4.ui.css.swt.helpers.CSSSWTColorHelper.getSWTColor;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import org.w3c.dom.css.CSSValue;
@SuppressWarnings("restriction")
public class CSSSWTColorHelperTest extends CSSSWTHelperTestCase {
private Display display;
+ private Color result;
+
+ @Before
+ public void setUp() {
- @Override
- protected void setUp() throws Exception {
display = Display.getDefault();
}
- public void testGetSWTColor() throws Exception {
- Color result = getSWTColor(colorValue("red"), display);
+ @After
+ public void tearDown() {
+ if (result != null) {
+ result.dispose();
+ }
+ display.dispose();
+ }
+ @Test
+ public void testGetSWTColor() {
+ result = getSWTColor(colorValue("red"), display);
assertNotNull(result);
assertEquals(255, result.getRed());
assertEquals(0, result.getBlue());
assertEquals(0, result.getGreen());
}
- public void testGetSWTColorWhenNotSupportedColorType() throws Exception {
- Color result = getSWTColor(colorValue("123213", CSSValue.CSS_CUSTOM),
+ @Test
+ public void testGetSWTColorWhenNotSupportedColorType() {
+ result = getSWTColor(colorValue("123213", CSSValue.CSS_CUSTOM),
display);
assertNull(result);
}
- public void testGetSWTColorWhenInvalidColorValue() throws Exception {
- Color result = getSWTColor(colorValue("asdsad12"), display);
+ @Test
+ public void testGetSWTColorWhenInvalidColorValue() {
+ result = getSWTColor(colorValue("asdsad12"), display);
assertNotNull(result);
assertEquals(0, result.getRed());
@@ -50,10 +69,11 @@ public class CSSSWTColorHelperTest extends CSSSWTHelperTestCase {
assertEquals(0, result.getGreen());
}
- public void testGetSWTColorWhenColorFromDefinition() throws Exception {
+ @Test
+ public void testGetSWTColorWhenColorFromDefinition() {
registerColorProviderWith("org.eclipse.jdt.debug.ui.InDeadlockColor", new RGB(0, 255, 0));
- Color result = getSWTColor(
+ result = getSWTColor(
colorValue(addColorDefinitionMarker("org-eclipse-jdt-debug-ui-InDeadlockColor")),
display);
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTFontHelperTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTFontHelperTest.java
index e8287dc6e3f..f563bbb7237 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTFontHelperTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTFontHelperTest.java
@@ -1,22 +1,26 @@
/*******************************************************************************
- * Copyright (c) 2013 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2013, 2014 IBM Corporation and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.css.swt.helpers;
import static org.eclipse.e4.ui.css.swt.helpers.CSSSWTFontHelper.getFontData;
+import static org.junit.Assert.assertEquals;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontData;
+import org.junit.Test;
@SuppressWarnings("restriction")
public class CSSSWTFontHelperTest extends CSSSWTHelperTestCase {
- public void testGetFontData() throws Exception {
+ @Test
+ public void testGetFontData() {
FontData result = getFontData(fontProperties("Times", 11, SWT.NORMAL),
new FontData());
@@ -25,7 +29,8 @@ public class CSSSWTFontHelperTest extends CSSSWTHelperTestCase {
assertEquals(SWT.NORMAL, result.getStyle());
}
- public void testGetFontDataWhenMissingFamilyInCss() throws Exception {
+ @Test
+ public void testGetFontDataWhenMissingFamilyInCss() {
FontData result = getFontData(fontProperties(null, 11, SWT.NORMAL),
new FontData("Courier", 5, SWT.ITALIC));
@@ -34,7 +39,8 @@ public class CSSSWTFontHelperTest extends CSSSWTHelperTestCase {
assertEquals(SWT.NORMAL, result.getStyle());
}
- public void testGetFontDataWhenMissingSizeInCss() throws Exception {
+ @Test
+ public void testGetFontDataWhenMissingSizeInCss() {
FontData result = getFontData(fontProperties("Arial", null, SWT.NORMAL),
new FontData("Courier", 5, SWT.ITALIC));
@@ -43,7 +49,8 @@ public class CSSSWTFontHelperTest extends CSSSWTHelperTestCase {
assertEquals(SWT.NORMAL, result.getStyle());
}
- public void testGetFontDataWhenMissingStyleInCss() throws Exception {
+ @Test
+ public void testGetFontDataWhenMissingStyleInCss() {
FontData result = getFontData(fontProperties("Times", 11, null),
new FontData("Courier", 5, SWT.ITALIC));
@@ -52,7 +59,8 @@ public class CSSSWTFontHelperTest extends CSSSWTHelperTestCase {
assertEquals(SWT.ITALIC, result.getStyle());
}
- public void testGetFontDataWhenFontFamilyFromDefinition() throws Exception {
+ @Test
+ public void testGetFontDataWhenFontFamilyFromDefinition() {
registerFontProviderWith("org.eclipse.jface.bannerfont", "Arial", 15, SWT.ITALIC);
FontData result = getFontData(
@@ -66,7 +74,8 @@ public class CSSSWTFontHelperTest extends CSSSWTHelperTestCase {
assertEquals(SWT.ITALIC, result.getStyle());
}
- public void testGetFontDataWhenFontFamilyAndSizeFromDefinition() throws Exception {
+ @Test
+ public void testGetFontDataWhenFontFamilyAndSizeFromDefinition() {
registerFontProviderWith("org.eclipse.jface.bannerfont", "Arial", 15, SWT.ITALIC);
FontData result = getFontData(
@@ -80,7 +89,8 @@ public class CSSSWTFontHelperTest extends CSSSWTHelperTestCase {
assertEquals(SWT.ITALIC, result.getStyle());
}
- public void testGetFontDataWhenFontFamilySizeAndStyleFromDefinition() throws Exception {
+ @Test
+ public void testGetFontDataWhenFontFamilySizeAndStyleFromDefinition() {
registerFontProviderWith("org.eclipse.jface.bannerfont", "Arial", 15, SWT.ITALIC);
FontData result = getFontData(
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTHelperTestCase.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTHelperTestCase.java
index 50c9dceee21..6470115fff1 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTHelperTestCase.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTHelperTestCase.java
@@ -1,19 +1,20 @@
/*******************************************************************************
- * Copyright (c) 2013 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2013, 2014 IBM Corporation and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.css.swt.helpers;
import static org.eclipse.e4.ui.css.swt.helpers.CSSSWTColorHelper.COLOR_DEFINITION_MARKER;
import static org.eclipse.e4.ui.css.swt.helpers.CSSSWTFontHelper.FONT_DEFINITION_MARKER;
+import static org.junit.Assert.fail;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
-import junit.framework.TestCase;
import org.eclipse.e4.ui.css.core.dom.properties.css2.CSS2FontProperties;
import org.eclipse.e4.ui.css.core.impl.dom.CSSValueImpl;
@@ -26,9 +27,9 @@ import org.w3c.dom.css.CSSPrimitiveValue;
import org.w3c.dom.css.CSSValue;
@SuppressWarnings("restriction")
-public abstract class CSSSWTHelperTestCase extends TestCase {
+public abstract class CSSSWTHelperTestCase {
protected void registerFontProviderWith(String expectedSymbolicName,
- String family, int size, int style) throws Exception {
+ String family, int size, int style) {
IColorAndFontProvider provider = mock(IColorAndFontProvider.class);
doReturn(new FontData[] { new FontData(family, size, style) }).when(
provider).getFont(expectedSymbolicName);
@@ -36,27 +37,33 @@ public abstract class CSSSWTHelperTestCase extends TestCase {
}
protected void registerColorProviderWith(String expectedSymbolicName,
- RGB rgb) throws Exception {
+ RGB rgb) {
IColorAndFontProvider provider = mock(IColorAndFontProvider.class);
doReturn(rgb).when(provider).getColor(expectedSymbolicName);
registerProvider(provider);
+
}
- private void registerProvider(final IColorAndFontProvider provider) throws Exception {
- new CSSActivator() {
- @Override
- public IColorAndFontProvider getColorAndFontProvider() {
- return provider;
- };
- }.start(null);
+ private void registerProvider(final IColorAndFontProvider provider) {
+ try {
+ new CSSActivator() {
+ @Override
+ public IColorAndFontProvider getColorAndFontProvider() {
+ return provider;
+ };
+ }.start(null);
+ } catch (Exception e) {
+ fail();
+ }
+
}
- protected CSS2FontProperties fontProperties(String family) throws Exception {
+ protected CSS2FontProperties fontProperties(String family) {
return fontProperties(family, null, null);
}
protected CSS2FontProperties fontProperties(String family, Object size,
- Object style) throws Exception {
+ Object style) {
CSS2FontProperties result = mock(CSS2FontProperties.class);
doReturn(valueImpl(family)).when(result).getFamily();
if (size != null) {
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/EclipsePreferencesHelperTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/EclipsePreferencesHelperTest.java
index 6dfa746b514..2d8df9e4cfc 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/EclipsePreferencesHelperTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/EclipsePreferencesHelperTest.java
@@ -1,3 +1,14 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2014 IBM Corporation and others. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
+ *******************************************************************************/
+
package org.eclipse.e4.ui.css.swt.helpers;
import static org.eclipse.e4.ui.css.swt.helpers.EclipsePreferencesHelper.PROPS_OVERRIDDEN_BY_CSS_PROP;
@@ -7,19 +18,24 @@ import static org.eclipse.e4.ui.css.swt.helpers.EclipsePreferencesHelper.getOver
import static org.eclipse.e4.ui.css.swt.helpers.EclipsePreferencesHelper.getPreferenceChangeListener;
import static org.eclipse.e4.ui.css.swt.helpers.EclipsePreferencesHelper.removeOverriddenByCssProperty;
import static org.eclipse.e4.ui.css.swt.helpers.EclipsePreferencesHelper.removeOverriddenPropertyNames;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.util.List;
-import junit.framework.TestCase;
-
import org.eclipse.core.internal.preferences.EclipsePreferences;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.junit.Test;
-public class EclipsePreferencesHelperTest extends TestCase {
- public void testAppendOverriddenPropertyName() throws Exception {
+@SuppressWarnings("restriction")
+public class EclipsePreferencesHelperTest {
+ @Test
+ public void testAppendOverriddenPropertyName() {
// given
IEclipsePreferences preferences = spy(new EclipsePreferences());
@@ -43,7 +59,8 @@ public class EclipsePreferencesHelperTest extends TestCase {
getPreferenceChangeListener());
}
- public void testGetOverriddenPropertyNames() throws Exception {
+ @Test
+ public void testGetOverriddenPropertyNames() {
// given
IEclipsePreferences preferences = new EclipsePreferences();
appendOverriddenPropertyName(preferences, "prop1");
@@ -60,7 +77,8 @@ public class EclipsePreferencesHelperTest extends TestCase {
assertTrue(propertyNames.add("prop3"));
}
- public void testRemoveOverriddenPropertyNames() throws Exception {
+ @Test
+ public void testRemoveOverriddenPropertyNames() {
// given
IEclipsePreferences preferences = spy(new EclipsePreferences());
appendOverriddenPropertyName(preferences, "prop1");
@@ -75,7 +93,8 @@ public class EclipsePreferencesHelperTest extends TestCase {
getPreferenceChangeListener());
}
- public void testRemoveOverriddenByCssProperty() throws Exception {
+ @Test
+ public void testRemoveOverriddenByCssProperty() {
// given
IEclipsePreferences preferences = new EclipsePreferences();
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/PreferenceOverriddenByCssChangeListenerTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/PreferenceOverriddenByCssChangeListenerTest.java
index d86129391a9..a9819eaa9fa 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/PreferenceOverriddenByCssChangeListenerTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/PreferenceOverriddenByCssChangeListenerTest.java
@@ -1,3 +1,14 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2014 IBM Corporation and others. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
+ *******************************************************************************/
+
package org.eclipse.e4.ui.css.swt.helpers;
import static org.eclipse.e4.ui.css.swt.helpers.EclipsePreferencesHelper.PROPS_OVERRIDDEN_BY_CSS_PROP;
@@ -6,15 +17,16 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import junit.framework.TestCase;
import org.eclipse.core.internal.preferences.EclipsePreferences;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.e4.ui.css.swt.helpers.EclipsePreferencesHelper.PreferenceOverriddenByCssChangeListener;
+import org.junit.Test;
-public class PreferenceOverriddenByCssChangeListenerTest extends TestCase {
- public void testPreferenceChangeEvent() throws Exception {
+public class PreferenceOverriddenByCssChangeListenerTest {
+ @Test
+ public void testPreferenceChangeEvent() {
// given
IEclipsePreferences preferences = new EclipsePreferences();
preferences.put(PROPS_OVERRIDDEN_BY_CSS_PROP, SEPARATOR + "name"
@@ -33,8 +45,8 @@ public class PreferenceOverriddenByCssChangeListenerTest extends TestCase {
.removeOverriddenByCssProperty(event);
}
- public void testPreferenceChangeEventWhenAddPropertyEvent()
- throws Exception {
+ @Test
+ public void testPreferenceChangeEventWhenAddPropertyEvent() {
// given
IEclipsePreferences preferences = new EclipsePreferences();
preferences.put(PROPS_OVERRIDDEN_BY_CSS_PROP, SEPARATOR + "name"
@@ -53,8 +65,8 @@ public class PreferenceOverriddenByCssChangeListenerTest extends TestCase {
.removeOverriddenByCssProperty(event);
}
- public void testPreferenceChangeEventWhenRemovePropertyEvent()
- throws Exception {
+ @Test
+ public void testPreferenceChangeEventWhenRemovePropertyEvent() {
// given
IEclipsePreferences preferences = new EclipsePreferences();
preferences.put(PROPS_OVERRIDDEN_BY_CSS_PROP, SEPARATOR + "name"
@@ -73,8 +85,8 @@ public class PreferenceOverriddenByCssChangeListenerTest extends TestCase {
.removeOverriddenByCssProperty(event);
}
- public void testPreferenceChangeEventWhenModifyPropertyEventButPropertyIsNotOverriddenByCss()
- throws Exception {
+ @Test
+ public void testPreferenceChangeEventWhenModifyPropertyEventButPropertyIsNotOverriddenByCss() {
// given
IEclipsePreferences preferences = new EclipsePreferences();
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/properties/preference/EclipsePreferencesHandlerTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/properties/preference/EclipsePreferencesHandlerTest.java
index 4f22e8e5f82..5b8d6c2211e 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/properties/preference/EclipsePreferencesHandlerTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/properties/preference/EclipsePreferencesHandlerTest.java
@@ -6,28 +6,36 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.css.swt.properties.preference;
import static org.eclipse.e4.ui.css.swt.helpers.EclipsePreferencesHelper.PROPS_OVERRIDDEN_BY_CSS_PROP;
import static org.eclipse.e4.ui.css.swt.properties.preference.EclipsePreferencesHandler.PREFERENCES_PROP;
+import static org.junit.Assert.assertEquals;
+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.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import junit.framework.TestCase;
import org.eclipse.core.internal.preferences.EclipsePreferences;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.e4.ui.css.core.engine.CSSEngine;
import org.eclipse.e4.ui.css.swt.dom.preference.EclipsePreferencesElement;
+import org.junit.Test;
import org.w3c.dom.css.CSSValue;
import org.w3c.dom.css.CSSValueList;
-public class EclipsePreferencesHandlerTest extends TestCase {
- public void testApplyCSSProperty() throws Exception {
+public class EclipsePreferencesHandlerTest {
+
+ @Test
+ public void testApplyCSSProperty() {
// given
CSSEngine engine = mock(CSSEngine.class);
@@ -42,13 +50,19 @@ public class EclipsePreferencesHandlerTest extends TestCase {
EclipsePreferencesHandlerTestable handler = spy(new EclipsePreferencesHandlerTestable());
// when
- handler.applyCSSProperty(element, PREFERENCES_PROP, value, null, engine);
+ try {
+ handler.applyCSSProperty(element, PREFERENCES_PROP, value, null, engine);
+ } catch (Exception e) {
+ fail("Apply CSSProperty should not throw exception");
+ }
// then
verify(handler, times(1)).overrideProperty(preferences, value);
+ engine.dispose();
}
- public void testApplyCSSPropertyWhenCssValueList() throws Exception {
+ @Test
+ public void testApplyCSSPropertyWhenCssValueList() {
// given
CSSEngine engine = mock(CSSEngine.class);
@@ -69,17 +83,23 @@ public class EclipsePreferencesHandlerTest extends TestCase {
EclipsePreferencesHandlerTestable handler = spy(new EclipsePreferencesHandlerTestable());
// when
- handler.applyCSSProperty(element, PREFERENCES_PROP, listValue, null,
- engine);
+ try {
+ handler.applyCSSProperty(element, PREFERENCES_PROP, listValue, null, engine);
+ } catch (Exception e) {
+ fail("Apply CSSProperty should not throw exception");
+
+ }
// then
verify(handler, times(2)).overrideProperty(
any(IEclipsePreferences.class), any(CSSValue.class));
verify(handler, times(1)).overrideProperty(preferences, values[0]);
verify(handler, times(1)).overrideProperty(preferences, values[1]);
+ engine.dispose();
}
- public void testOverridePropertyWithCSSValue() throws Exception {
+ @Test
+ public void testOverridePropertyWithCSSValue() {
// given
IEclipsePreferences preferences = new EclipsePreferences();
@@ -102,7 +122,8 @@ public class EclipsePreferencesHandlerTest extends TestCase {
"value2");
}
- public void testOverridePropertyWithNameAndValueSplit() throws Exception {
+ @Test
+ public void testOverridePropertyWithNameAndValueSplit() {
// given
IEclipsePreferences preferences = new EclipsePreferences();
@@ -117,8 +138,8 @@ public class EclipsePreferencesHandlerTest extends TestCase {
"name"));
}
- public void testOverridePropertyWithNameAndValueSplitAndNameAlreadyAddedByUser()
- throws Exception {
+ @Test
+ public void testOverridePropertyWithNameAndValueSplitAndNameAlreadyAddedByUser() {
// given
IEclipsePreferences preferences = new EclipsePreferences();
// pref is already set that means that user has overridden it with the
@@ -135,7 +156,8 @@ public class EclipsePreferencesHandlerTest extends TestCase {
assertNull(preferences.get(PROPS_OVERRIDDEN_BY_CSS_PROP, null));
}
- public void testCustomizePreferenceOverriddenByCSS() throws Exception {
+ @Test
+ public void testCustomizePreferenceOverriddenByCSS() {
// given
IEclipsePreferences preferences = new EclipsePreferences();
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/Bug419482Test.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/Bug419482Test.java
index 2eb5d0d02c4..37738760828 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/Bug419482Test.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/Bug419482Test.java
@@ -7,31 +7,33 @@
*
* Contributors:
* Stefan Winkler <stefan@winklerweb.net> - initial contribution
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import static org.junit.Assert.assertEquals;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
+import org.junit.Test;
public class Bug419482Test extends CSSSWTTestCase {
private static final RGB RGB_BLUE = new RGB(0, 0, 255);
private static final RGB RGB_RED = new RGB(255, 0, 0);
- private CSSEngine engine;
private ToolBar toolbar1;
private ToolBar toolbar2;
private ToolBar toolbar3;
- public void testTwoLevelsWildcard() throws Exception {
+ @Test
+ public void testTwoLevelsWildcard() {
String cssString = "Shell > * > * { color: red; } \n"
+ "Label { color: blue; }";
@@ -41,7 +43,8 @@ public class Bug419482Test extends CSSSWTTestCase {
assertEquals(RGB_BLUE, rgb);
}
- public void testOneLevelWildcardOneSpecific() throws Exception {
+ @Test
+ public void testOneLevelWildcardOneSpecific() {
String cssString = "Shell > * > Label { color: red; } \n"
+ "Label { color: blue; }";
@@ -51,7 +54,8 @@ public class Bug419482Test extends CSSSWTTestCase {
assertEquals(RGB_RED, rgb);
}
- public void testDescendentsWildcard() throws Exception {
+ @Test
+ public void testDescendentsWildcard() {
String cssString = "Shell * { color: red; } \n"
+ "Label { color: blue; }";
@@ -61,7 +65,8 @@ public class Bug419482Test extends CSSSWTTestCase {
assertEquals(RGB_BLUE, rgb);
}
- public void testDescendentsSpecific() throws Exception {
+ @Test
+ public void testDescendentsSpecific() {
String cssString = "Shell Label { color: red; } \n"
+ "Label { color: blue; }";
@@ -72,26 +77,9 @@ public class Bug419482Test extends CSSSWTTestCase {
}
- private Label createTestLabel(String styleSheet) {
- Display display = Display.getDefault();
- engine = createEngine(styleSheet, display);
-
- // Create widgets
- Shell shell = new Shell(display, SWT.SHELL_TRIM);
- FillLayout layout = new FillLayout();
- shell.setLayout(layout);
-
- Composite composite = new Composite(shell, SWT.NONE);
- composite.setLayout(new FillLayout());
-
- Label labelToTest = new Label(composite, SWT.NONE);
- labelToTest.setText("Some label text");
- // Apply styles
- engine.applyStyles(labelToTest, true);
- return labelToTest;
- }
+ @Test
public void testOriginalBugReport() {
String css = "Shell, Shell > *, Shell > * > * {\n" +
" background-color: red;\n" +
@@ -100,7 +88,6 @@ public class Bug419482Test extends CSSSWTTestCase {
" background-color: blue;\n" +
"}";
- Display display = Display.getDefault();
engine = createEngine(css, display);
Shell shell = createShellWithToolbars(display);
@@ -113,12 +100,12 @@ public class Bug419482Test extends CSSSWTTestCase {
assertEquals(RGB_BLUE, toolbar3.getBackground().getRGB());
}
+ @Test
public void testOriginalBugReportDifferentOrder() {
String css = "ToolBar {\n" + " background-color: blue;\n" + "}"
+ "Shell, Shell > *, Shell > * > * {\n"
+ " background-color: red;\n" + "}\n";
- Display display = Display.getDefault();
engine = createEngine(css, display);
// Create widgets
@@ -146,5 +133,7 @@ public class Bug419482Test extends CSSSWTTestCase {
toolbar3 = new ToolBar(composite2, SWT.BORDER);
return shell;
+
}
+
}
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ButtonTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ButtonTest.java
index 07382fe03f3..283b193d773 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ButtonTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ButtonTest.java
@@ -1,36 +1,37 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2008, 2014 IBM Corporation and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Remy Chi Jian Suen <remy.suen@gmail.com> - bug 137650
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import static org.junit.Assert.assertEquals;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
+import org.junit.Ignore;
+import org.junit.Test;
public class ButtonTest extends CSSSWTTestCase {
static final RGB RED = new RGB(255, 0, 0);
static final RGB GREEN = new RGB(0, 255, 0);
static final RGB BLUE = new RGB(0, 0, 255);
- CSSEngine engine;
-
+
protected Button createTestButton(String styleSheet) {
- Display display = Display.getDefault();
engine = createEngine(styleSheet, display);
-
+
// Create widgets
Shell shell = new Shell(display, SWT.SHELL_TRIM);
FillLayout layout = new FillLayout();
@@ -48,11 +49,10 @@ public class ButtonTest extends CSSSWTTestCase {
shell.pack();
return buttonToTest;
}
-
+
protected Button createTestArrowButton(String styleSheet) {
- Display display = Display.getDefault();
engine = createEngine(styleSheet, display);
-
+
// Create widgets
Shell shell = new Shell(display, SWT.SHELL_TRIM);
FillLayout layout = new FillLayout();
@@ -69,76 +69,83 @@ public class ButtonTest extends CSSSWTTestCase {
shell.pack();
return buttonToTest;
}
-
- public void testColor() throws Exception {
+
+ @Test
+ public void testColor() {
Button buttonToTest = createTestButton("Button { background-color: #FF0000; color: #0000FF }");
assertEquals(RED, buttonToTest.getBackground().getRGB());
assertEquals(BLUE, buttonToTest.getForeground().getRGB());
}
- public void testFontRegular() throws Exception {
+ @Test
+ public void testFontRegular() {
Button buttonToTest = createTestButton("Button { font: Verdana 16px }");
assertEquals(1, buttonToTest.getFont().getFontData().length);
FontData fontData = buttonToTest.getFont().getFontData()[0];
assertEquals("Verdana", fontData.getName());
assertEquals(16, fontData.getHeight());
- assertEquals(SWT.NORMAL, fontData.getStyle());
+ assertEquals(SWT.NORMAL, fontData.getStyle());
}
- public void testFontBold() throws Exception {
+ @Test
+ public void testFontBold() {
Button buttonToTest = createTestButton("Button { font: Arial 12px; font-weight: bold }");
assertEquals(1, buttonToTest.getFont().getFontData().length);
FontData fontData = buttonToTest.getFont().getFontData()[0];
assertEquals("Arial", fontData.getName());
assertEquals(12, fontData.getHeight());
- assertEquals(SWT.BOLD, fontData.getStyle());
+ assertEquals(SWT.BOLD, fontData.getStyle());
}
- public void testFontItalic() throws Exception {
+ @Test
+ public void testFontItalic() {
Button buttonToTest = createTestButton("Button { font-style: italic }");
assertEquals(1, buttonToTest.getFont().getFontData().length);
FontData fontData = buttonToTest.getFont().getFontData()[0];
- assertEquals(SWT.ITALIC, fontData.getStyle());
+ assertEquals(SWT.ITALIC, fontData.getStyle());
+ }
+
+ @Ignore
+ public void testSelectedPseudo() {
+ Button buttonToTest = createTestButton("Button { color: #FF0000; }\n" + "Button:selected { color: #0000FF; }");
+ assertEquals(RED, buttonToTest.getForeground().getRGB());
+ buttonToTest.setSelection(true);
+ engine.applyStyles(buttonToTest.getShell(), true);
+ assertEquals(BLUE, buttonToTest.getForeground().getRGB());
}
-
-// public void testSelectedPseudo() throws Exception {
-// Button buttonToTest = createTestButton("Button { color: #FF0000; }\n" +
-// "Button:selected { color: #0000FF; }");
-// assertEquals(RED, buttonToTest.getForeground().getRGB());
-// buttonToTest.setSelection(true);
-// engine.applyStyles(buttonToTest.getShell(), true);
-// assertEquals(BLUE, buttonToTest.getForeground().getRGB());
-// }
-
- public void testAlignment() throws Exception {
- Button buttonToTest = createTestButton("Button { alignment: right; }");
+
+ @Test
+ public void testAlignment() {
+ Button buttonToTest = createTestButton("Button { alignment: right; }");
assertEquals(SWT.RIGHT, buttonToTest.getAlignment());
-
+
buttonToTest = createTestButton("Button { alignment: left; }");
assertEquals(SWT.LEFT, buttonToTest.getAlignment());
-
+
buttonToTest = createTestButton("Button { alignment: center; }");
assertEquals(SWT.CENTER, buttonToTest.getAlignment());
}
-
- public void testAlignment2() throws Exception {
+
+ @Test
+ public void testAlignment2() {
Button buttonToTest = createTestButton("Button { alignment: trail; }");
assertEquals(SWT.TRAIL, buttonToTest.getAlignment());
-
+
buttonToTest = createTestButton("Button { alignment: lead; }");
assertEquals(SWT.LEAD, buttonToTest.getAlignment());
}
- public void testArrowAlignment() throws Exception {
- Button buttonToTest = createTestArrowButton("Button { alignment: up; }");
+ @Test
+ public void testArrowAlignment() {
+ Button buttonToTest = createTestArrowButton("Button { alignment: up; }");
assertEquals(SWT.UP, buttonToTest.getAlignment());
-
+
buttonToTest = createTestArrowButton("Button { alignment: down; }");
assertEquals(SWT.DOWN, buttonToTest.getAlignment());
-
+
buttonToTest = createTestArrowButton("Button { alignment: left; }");
assertEquals(SWT.LEFT, buttonToTest.getAlignment());
-
+
buttonToTest = createTestArrowButton("Button { alignment: right; }");
assertEquals(SWT.RIGHT, buttonToTest.getAlignment());
}
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ButtonTextTransformTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ButtonTextTransformTest.java
index e4fb3b51443..7256b508fbe 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ButtonTextTransformTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ButtonTextTransformTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Remy Chi Jian Suen and others.
+ * Copyright (c) 2009, 2014 Remy Chi Jian Suen and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Remy Chi Jian Suen <remy.suen@gmail.com> - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
@@ -14,21 +15,25 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-
+
public class ButtonTextTransformTest extends TextTransformTest {
-
+
+ @Override
protected Control createControl(Composite parent) {
return new Button(parent, SWT.PUSH);
}
-
+
+ @Override
protected String getWidgetName() {
return "Button";
}
+ @Override
protected String getText(Control control) {
return ((Button) control).getText();
}
-
+
+ @Override
protected void setText(Control control, String string) {
((Button) control).setText(string);
}
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CSSSWTTestCase.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CSSSWTTestCase.java
index aeac5023c3b..5bea8ac5f88 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CSSSWTTestCase.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CSSSWTTestCase.java
@@ -1,46 +1,57 @@
/*******************************************************************************
- * Copyright (c) 2008, 2012 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2008, 2014 IBM Corporation and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
+import static org.junit.Assert.fail;
+
import java.io.IOException;
import java.io.StringReader;
-import junit.framework.TestCase;
-
import org.eclipse.e4.ui.css.core.engine.CSSEngine;
import org.eclipse.e4.ui.css.core.engine.CSSErrorHandler;
import org.eclipse.e4.ui.css.swt.engine.CSSSWTEngineImpl;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Widget;
+import org.junit.After;
+import org.junit.Before;
+
+public class CSSSWTTestCase {
+
+ protected Display display;
+ protected CSSEngine engine;
-public class CSSSWTTestCase extends TestCase {
-
public CSSEngine createEngine(String styleSheet, Display display) {
- CSSEngine engine = new CSSSWTEngineImpl(display);
-
+ engine = new CSSSWTEngineImpl(display);
+
engine.setErrorHandler(new CSSErrorHandler() {
+ @Override
public void error(Exception e) {
fail(e.getMessage());
}
});
-
+
try {
engine.parseStyleSheet(new StringReader(styleSheet));
} catch (IOException e) {
fail(e.getMessage());
}
return engine;
-
+
}
-
+
/**
* Parse and apply the style sheet, forgetting previous style sheets applied.
* This is helpful for reusing the same engine but writing independent tests.
@@ -53,36 +64,53 @@ public class CSSSWTTestCase extends TestCase {
//Forget all previous styles
engine.reset();
+ if (styleSheet != null) {
- try {
- engine.parseStyleSheet(new StringReader(styleSheet));
- } catch (IOException e) {
- fail(e.getMessage());
+ try {
+ engine.parseStyleSheet(new StringReader(styleSheet));
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
}
-
+
engine.applyStyles(widget, true, true);
}
-
- /**
- * Asserts that two int arrays are equal in size and contents. If they are not
- * an AssertionFailedError is thrown.
- */
- static public void assertEquals(int[] expected, int[] actual) {
- assertEquals(expected.length, actual.length);
- for (int i = 0; i < actual.length; i++) {
- assertEquals(expected[i], actual[i]);
+
+ @Before
+ public void setUp() {
+ display = Display.getDefault();
+ }
+
+ @After
+ public void tearDown() {
+ display = Display.getDefault();
+ if (!display.isDisposed()) {
+ for (Shell shell : display.getShells()) {
+ shell.dispose();
+ }
+ display.dispose();
}
}
- @Override
- protected void tearDown() throws Exception {
- Display display = Display.getDefault();
- if (!display.isDisposed()) {
- for (Shell shell : display.getShells()) {
- shell.dispose();
- }
- }
- super.tearDown();
- }
+ protected Label createTestLabel(String styleSheet) {
+ engine = createEngine(styleSheet, display);
+
+ // Create widgets
+ Shell shell = new Shell(display, SWT.SHELL_TRIM);
+ FillLayout layout = new FillLayout();
+ shell.setLayout(layout);
+
+ Composite panel = new Composite(shell, SWT.NONE);
+ panel.setLayout(new FillLayout());
+
+ Label labelToTest = new Label(panel, SWT.NONE);
+ labelToTest.setText("Some label text");
+
+ // Apply styles
+ engine.applyStyles(labelToTest, true);
+
+ shell.pack();
+ return labelToTest;
+ }
}
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CSSSWTWidgetTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CSSSWTWidgetTest.java
index c581219f59a..8d407e4b806 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CSSSWTWidgetTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CSSSWTWidgetTest.java
@@ -1,63 +1,49 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 IBM Corporation and others.
+ * Copyright (c) 2009, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import static org.junit.Assert.assertEquals;
+
import org.eclipse.e4.ui.css.swt.dom.WidgetElement;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Widget;
+import org.junit.Ignore;
+import org.junit.Test;
public class CSSSWTWidgetTest extends CSSSWTTestCase {
- CSSEngine engine;
-
- protected Widget createTestLabel(String styleSheet) {
- Display display = Display.getDefault();
- engine = createEngine(styleSheet, display);
-
- // Create widgets
- Shell shell = new Shell(display, SWT.SHELL_TRIM);
- FillLayout layout = new FillLayout();
- shell.setLayout(layout);
- Label labelToTest = new Label(shell, SWT.NONE);
- labelToTest.setText("Some label text");
- // Apply styles
- engine.applyStyles(labelToTest, true);
- return labelToTest;
+ @Ignore
+ @Test
+ public void testEngineKey() {
+ Widget widget = createTestLabel("Label { font: Arial 12px; font-weight: bold }");
+ assertEquals(WidgetElement.getEngine(widget), engine);
}
-
-// public void testEngineKey() throws Exception {
-// Widget widget = createTestLabel("Label { font: Arial 12px; font-weight: bold }");
-// assertEquals(WidgetElement.getEngine(widget), engine);
-// }
- public void testIDKey() throws Exception {
+ @Test
+ public void testIDKey() {
final String id = "some.test.id";
Widget widget = createTestLabel("Label { font: Arial 12px; font-weight: bold }");
WidgetElement.setID(widget, id);
- assertEquals(WidgetElement.getID(widget), id);
+ assertEquals(WidgetElement.getID(widget), id);
}
- public void testCSSClassKey() throws Exception {
+ @Test
+ public void testCSSClassKey() {
final String cssClass = "some.test.cssclassname";
Widget widget = createTestLabel("Label { font: Arial 12px; font-weight: bold }");
WidgetElement.setCSSClass(widget, cssClass);
- assertEquals(WidgetElement.getCSSClass(widget), cssClass);
+ assertEquals(WidgetElement.getCSSClass(widget), cssClass);
}
}
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CTabFolderTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CTabFolderTest.java
index fb098b49c81..357b4c932b0 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CTabFolderTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CTabFolderTest.java
@@ -1,15 +1,18 @@
/*******************************************************************************
- * Copyright (c) 2008, 2012 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2008, 2014 IBM Corporation and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+
import org.eclipse.e4.ui.css.swt.dom.CTabFolderElement;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
@@ -21,6 +24,8 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
+import org.junit.Ignore;
+import org.junit.Test;
public class CTabFolderTest extends CSSSWTTestCase {
@@ -28,10 +33,8 @@ public class CTabFolderTest extends CSSSWTTestCase {
static final RGB GREEN = new RGB(0, 255, 0);
static final RGB BLUE = new RGB(0, 0, 255);
static final RGB WHITE = new RGB(255, 255, 255);
- static public CSSEngine engine;
-
+
protected CTabFolder createTestCTabFolder(String styleSheet) {
- Display display = Display.getDefault();
engine = createEngine(styleSheet, display);
// Create widgets
@@ -44,16 +47,15 @@ public class CTabFolderTest extends CSSSWTTestCase {
CTabFolder folderToTest = new CTabFolder(panel, SWT.NONE);
CTabItem tab1 = new CTabItem(folderToTest, SWT.NONE);
tab1.setText("A TAB ITEM");
-
+
engine.applyStyles(shell, true);
shell.pack();
return folderToTest;
}
-
+
protected ToolBar[] createTestToolBars(String styleSheet) {
- Display display = Display.getDefault();
engine = createEngine(styleSheet, display);
// Create widgets
@@ -81,70 +83,77 @@ public class CTabFolderTest extends CSSSWTTestCase {
engine.applyStyles(shell, true);
return new ToolBar[] {toolbarA, toolbarB, toolbarC};
}
-
+
protected Shell createShell(String styleSheet) {
Display display = Display.getDefault();
engine = createEngine(styleSheet, display);
// Create widgets
Shell shell = new Shell(display, SWT.NONE);
-
+
engine.applyStyles(shell, true);
shell.pack();
return shell;
}
-
- public void testBackgroundColor() throws Exception {
+
+ @Test
+ public void testBackgroundColor() {
CTabFolder folderToTest = createTestCTabFolder("CTabFolder { background-color: #0000FF }");
assertEquals(BLUE, folderToTest.getBackground().getRGB());
}
- public void testTextColor() throws Exception {
+ @Test
+ public void testTextColor() {
CTabFolder folderToTest = createTestCTabFolder("CTabFolder { color: #0000FF }");
assertEquals(BLUE, folderToTest.getForeground().getRGB());
}
//See GradientTest for testing background gradient
- public void testFontRegular() throws Exception {
+ @Test
+ public void testFontRegular() {
CTabFolder folderToTest = createTestCTabFolder("CTabFolder { font: Verdana 16px }");
assertEquals(1, folderToTest.getFont().getFontData().length);
FontData fontData = folderToTest.getFont().getFontData()[0];
assertEquals("Verdana", fontData.getName());
assertEquals(16, fontData.getHeight());
- assertEquals(SWT.NORMAL, fontData.getStyle());
+ assertEquals(SWT.NORMAL, fontData.getStyle());
}
- public void testFontBold() throws Exception {
+ @Test
+ public void testFontBold() {
CTabFolder folderToTest = createTestCTabFolder("CTabFolder { font: Arial 12px; font-weight: bold }");
assertEquals(1, folderToTest.getFont().getFontData().length);
FontData fontData = folderToTest.getFont().getFontData()[0];
assertEquals("Arial", fontData.getName());
assertEquals(12, fontData.getHeight());
- assertEquals(SWT.BOLD, fontData.getStyle());
+ assertEquals(SWT.BOLD, fontData.getStyle());
}
- public void testFontItalic() throws Exception {
+ @Test
+ public void testFontItalic() {
CTabFolder folderToTest = createTestCTabFolder("CTabFolder { font: Arial 12px; font-style: italic }");
assertEquals(1, folderToTest.getFont().getFontData().length);
FontData fontData = folderToTest.getFont().getFontData()[0];
assertEquals("Arial", fontData.getName());
assertEquals(12, fontData.getHeight());
- assertEquals(SWT.ITALIC, fontData.getStyle());
+ assertEquals(SWT.ITALIC, fontData.getStyle());
}
-// public void testBorderVisible() throws Exception {
-// CTabFolder folderToTest = createTestCTabFolder("CTabFolder { border-visible: true}");
-// assertEquals(true, folderToTest.getBorderVisible());
-// assertEquals("true", engine.retrieveCSSProperty(folderToTest, "border-visible", null));
-// folderToTest.getShell().close();
-// folderToTest = createTestCTabFolder("CTabFolder { border-visible: false}");
-// assertEquals(false, folderToTest.getBorderVisible());
-// assertEquals("false", engine.retrieveCSSProperty(folderToTest, "border-visible", null));
-// }
-//
- public void testSimple() throws Exception {
+ @Ignore("this test was commented before bug 443094")
+ @Test
+ public void testBorderVisible() {
+ CTabFolder folderToTest = createTestCTabFolder("CTabFolder { border-visible: true}");
+ assertEquals(true, folderToTest.getBorderVisible());
+ assertEquals("true", engine.retrieveCSSProperty(folderToTest, "border-visible", null));
+ folderToTest.getShell().close();
+ folderToTest = createTestCTabFolder("CTabFolder { border-visible: false}");
+ assertEquals(false, folderToTest.getBorderVisible());
+ assertEquals("false", engine.retrieveCSSProperty(folderToTest, "border-visible", null));
+ }
+ @Test
+ public void testSimple() {
CTabFolder folderToTest = createTestCTabFolder("CTabFolder { simple: true}");
assertEquals(true, folderToTest.getSimple());
assertEquals("true", engine.retrieveCSSProperty(folderToTest, "simple", null));
@@ -153,8 +162,9 @@ public class CTabFolderTest extends CSSSWTTestCase {
assertEquals(false, folderToTest.getSimple());
assertEquals("false", engine.retrieveCSSProperty(folderToTest, "simple", null));
}
-
- public void testMaximizeVisible() throws Exception {
+
+ @Test
+ public void testMaximizeVisible() {
CTabFolder folderToTest = createTestCTabFolder("CTabFolder { maximize-visible: true}");
assertEquals(true, folderToTest.getMaximizeVisible());
assertEquals("true", engine.retrieveCSSProperty(folderToTest, "maximize-visible", null));
@@ -163,8 +173,9 @@ public class CTabFolderTest extends CSSSWTTestCase {
assertEquals(false, folderToTest.getMaximizeVisible());
assertEquals("false", engine.retrieveCSSProperty(folderToTest, "maximize-visible", null));
}
-
- public void testMinimizeVisible() throws Exception {
+
+ @Test
+ public void testMinimizeVisible() {
CTabFolder folderToTest = createTestCTabFolder("CTabFolder { minimize-visible: true}");
assertEquals(true, folderToTest.getMinimizeVisible());
assertEquals("true", engine.retrieveCSSProperty(folderToTest, "minimize-visible", null));
@@ -173,8 +184,9 @@ public class CTabFolderTest extends CSSSWTTestCase {
assertEquals(false, folderToTest.getMinimizeVisible());
assertEquals("false", engine.retrieveCSSProperty(folderToTest, "minimize-visible", null));
}
-
- public void testMRUVisible() throws Exception {
+
+ @Test
+ public void testMRUVisible() {
CTabFolder folderToTest = createTestCTabFolder("CTabFolder { mru-visible: true}");
assertEquals(true, folderToTest.getMRUVisible());
assertEquals("true", engine.retrieveCSSProperty(folderToTest, "mru-visible", null));
@@ -183,8 +195,9 @@ public class CTabFolderTest extends CSSSWTTestCase {
assertEquals("false", engine.retrieveCSSProperty(folderToTest, "mru-visible", null));
assertEquals(false, folderToTest.getMRUVisible());
}
-
- public void testMaximized() throws Exception {
+
+ @Test
+ public void testMaximized() {
CTabFolder folderToTest = createTestCTabFolder("CTabFolder { maximized: true}");
assertEquals(true, folderToTest.getMaximized());
assertEquals("true", engine.retrieveCSSProperty(folderToTest, "maximized", null));
@@ -192,8 +205,9 @@ public class CTabFolderTest extends CSSSWTTestCase {
assertEquals(false, folderToTest.getMaximized());
assertEquals("false", engine.retrieveCSSProperty(folderToTest, "maximized", null));
}
-
- public void testMinimized() throws Exception {
+
+ @Test
+ public void testMinimized() {
CTabFolder folderToTest = createTestCTabFolder("CTabFolder { minimized: true}");
assertEquals(true, folderToTest.getMinimized());
assertEquals("true", engine.retrieveCSSProperty(folderToTest, "minimized", null));
@@ -201,25 +215,27 @@ public class CTabFolderTest extends CSSSWTTestCase {
assertEquals(false, folderToTest.getMinimized());
assertEquals("false", engine.retrieveCSSProperty(folderToTest, "minimized", null));
}
-
- public void testTabHeight() throws Exception {
+
+ @Test
+ public void testTabHeight() {
CTabFolder folderToTest = createTestCTabFolder("CTabFolder { tab-height: 30px }");
assertEquals(30, folderToTest.getTabHeight());
folderToTest = createTestCTabFolder("CTabFolder { tab-height: 40px }");
assertEquals(40, folderToTest.getTabHeight());
-
+
//negative test to ensure we don't try to interpret a list
folderToTest = createTestCTabFolder("CTabFolder { tab-height: 40px 50px }");
assertNotSame(40, folderToTest.getTabHeight());
assertNotSame(50, folderToTest.getTabHeight());
-
+
//negative test for ambiguous unit value
folderToTest = createTestCTabFolder("CTabFolder { tab-height: 40 }");
assertNotSame(40, folderToTest.getTabHeight());
}
- public void testSingle() throws Exception {
+ @Test
+ public void testSingle() {
CTabFolder folderToTest = createTestCTabFolder("CTabFolder { single: true}");
assertEquals(true, folderToTest.getSingle());
assertEquals("true", engine.retrieveCSSProperty(folderToTest, "single", null));
@@ -227,8 +243,9 @@ public class CTabFolderTest extends CSSSWTTestCase {
assertEquals(false, folderToTest.getSingle());
assertEquals("false", engine.retrieveCSSProperty(folderToTest, "single", null));
}
-
- public void testUnselectedCloseVisible() throws Exception {
+
+ @Test
+ public void testUnselectedCloseVisible() {
CTabFolder folderToTest = createTestCTabFolder("CTabFolder { unselected-close-visible: true}");
assertEquals(true, folderToTest.getUnselectedCloseVisible());
assertEquals("true", engine.retrieveCSSProperty(folderToTest, "unselected-close-visible", null));
@@ -236,8 +253,9 @@ public class CTabFolderTest extends CSSSWTTestCase {
assertEquals(false, folderToTest.getUnselectedCloseVisible());
assertEquals("false", engine.retrieveCSSProperty(folderToTest, "unselected-close-visible", null));
}
-
- public void testUnselectedImageVisible() throws Exception {
+
+ @Test
+ public void testUnselectedImageVisible() {
CTabFolder folderToTest = createTestCTabFolder("CTabFolder { unselected-image-visible: true}");
assertEquals(true, folderToTest.getUnselectedImageVisible());
assertEquals("true", engine.retrieveCSSProperty(folderToTest, "unselected-image-visible", null));
@@ -245,7 +263,8 @@ public class CTabFolderTest extends CSSSWTTestCase {
assertEquals(false, folderToTest.getUnselectedImageVisible());
assertEquals("false", engine.retrieveCSSProperty(folderToTest, "unselected-image-visible", null));
}
-
+
+ @Test
public void testRetrievePropertyNull() {
Shell shell = createShell("Shell {color:red}");
assertEquals(null, engine.retrieveCSSProperty(shell, "border-visible", null));
@@ -258,26 +277,27 @@ public class CTabFolderTest extends CSSSWTTestCase {
assertEquals(null, engine.retrieveCSSProperty(shell, "single", null));
assertEquals(null, engine.retrieveCSSProperty(shell, "unselected-close-visible", null));
assertEquals(null, engine.retrieveCSSProperty(shell, "unselected-image-visible", null));
- }
-
- public void testTopRightAsDescendentChild() throws Exception {
+ }
+
+ @Test
+ public void testTopRightAsDescendentChild() {
ToolBar[] toolBars = createTestToolBars(
"CTabFolder.special ToolBar { background: #FF0000}\n" +
- "CTabFolder ToolBar { background: #00FF00}\n" +
- "CTabFolder.extraordinary ToolBar { background: #FFFFFF}\n" +
+ "CTabFolder ToolBar { background: #00FF00}\n" +
+ "CTabFolder.extraordinary ToolBar { background: #FFFFFF}\n" +
"ToolBar { background: #0000FF}");
-
+
ToolBar barA = toolBars[0];
ToolBar barB = toolBars[1];
ToolBar barC = toolBars[2];
-
- CTabFolderElement.setCSSClass(barA.getParent(), "special");
+
+ CTabFolderElement.setCSSClass(barA.getParent(), "special");
engine.applyStyles(barA.getShell(), true);
-
+
assertEquals(RED, barA.getBackground().getRGB());
assertEquals(GREEN, barB.getBackground().getRGB());
assertEquals(BLUE, barC.getBackground().getRGB());
-
+
CTabFolderElement.setCSSClass(barA.getParent(), "extraordinary");
engine.applyStyles(barA.getShell(), true);
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CTabItemTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CTabItemTest.java
index ec9ad22b102..d500a6fe26c 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CTabItemTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CTabItemTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2013 Remy Chi Jian Suen and others.
+ * Copyright (c) 2009, 2014 Remy Chi Jian Suen and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,11 +7,19 @@
*
* Contributors:
* Remy Chi Jian Suen <remy.suen@gmail.com> - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import org.eclipse.e4.ui.css.core.engine.CSSEngine;
import org.eclipse.e4.ui.css.swt.dom.CTabItemElement;
+import org.eclipse.e4.ui.css.swt.dom.WidgetElement;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
@@ -22,17 +30,19 @@ import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
+import org.junit.After;
+import org.junit.Ignore;
+import org.junit.Test;
public class CTabItemTest extends CSSSWTTestCase {
- private CSSEngine engine;
private Shell shell;
@Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() {
if (shell != null) {
shell.dispose();
shell = null;
@@ -43,7 +53,6 @@ public class CTabItemTest extends CSSSWTTestCase {
private void spinEventLoop() {
// Workaround for https://bugs.eclipse.org/418101 and https://bugs.eclipse.org/403234 :
// Add some delay to allow asynchronous events to come in, but don't get trapped in an endless Display#sleep().
- Display display = shell.getDisplay();
for (int i = 0; i < 3; i++) {
while (display.readAndDispatch()) {
;
@@ -73,7 +82,6 @@ public class CTabItemTest extends CSSSWTTestCase {
}
private CTabFolder createTestTabFolder(boolean open) {
- Display display = Display.getDefault();
// Create widgets
shell = new Shell(display, SWT.SHELL_TRIM);
@@ -103,7 +111,8 @@ public class CTabItemTest extends CSSSWTTestCase {
return folder;
}
- public void testFontRegular() throws Exception {
+ @Test
+ public void testFontRegular() {
CTabFolder folder = createTestTabFolder("Button { font-family: Verdana; font-size: 12 }\n"
+ "CTabItem { font-family: Verdana; font-size: 16 }");
spinEventLoop();
@@ -131,7 +140,8 @@ public class CTabItemTest extends CSSSWTTestCase {
}
}
- public void testFontBold() throws Exception {
+ @Test
+ public void testFontBold() {
CTabFolder folder = createTestTabFolder("Button { font-weight: bold }\n"
+ "CTabItem { font-weight: bold }");
spinEventLoop();
@@ -145,7 +155,7 @@ public class CTabItemTest extends CSSSWTTestCase {
// verify retrieval
assertEquals("bold",
engine.retrieveCSSProperty(item,
- "font-weight", null));
+ "font-weight", null));
// make sure child controls are styled
Control button = item.getControl();
@@ -154,7 +164,8 @@ public class CTabItemTest extends CSSSWTTestCase {
}
}
- public void testFontItalic() throws Exception {
+ @Test
+ public void testFontItalic() {
CTabFolder folder = createTestTabFolder("Button { font-weight: bold }\n"
+ "CTabItem { font-style: italic }");
spinEventLoop();
@@ -176,8 +187,7 @@ public class CTabItemTest extends CSSSWTTestCase {
}
}
- private void testSelectedFontBold(CTabFolder folder, int selectionIndex)
- throws Exception {
+ private void testSelectedFontBold(CTabFolder folder, int selectionIndex) {
folder.setSelection(selectionIndex);
spinEventLoop();
@@ -192,7 +202,8 @@ public class CTabItemTest extends CSSSWTTestCase {
}
}
- public void testSelectedFontBold() throws Exception {
+ @Test
+ public void testSelectedFontBold() {
CTabFolder folder = createTestTabFolder("CTabItem:selected { font-weight: bold }");
spinEventLoop();
for (int i = 0; i < folder.getItemCount(); i++) {
@@ -200,7 +211,8 @@ public class CTabItemTest extends CSSSWTTestCase {
}
}
- public void testSelectedFontMerged() throws Exception {
+ @Test
+ public void testSelectedFontMerged() {
CTabFolder folder = createTestTabFolder("CTabItem { font-weight: normal; font-style: italic }\n"
+ "CTabItem:selected { font-weight: bold }");
spinEventLoop();
@@ -215,7 +227,8 @@ public class CTabItemTest extends CSSSWTTestCase {
}
}
- public void testSelectedFontMerged2() throws Exception {
+ @Test
+ public void testSelectedFontMerged2() {
CTabFolder folder = createTestTabFolder("CTabItem { font-style: italic }\n"
+ "CTabItem:selected { font-weight: bold }");
spinEventLoop();
@@ -230,7 +243,8 @@ public class CTabItemTest extends CSSSWTTestCase {
}
}
- public void testSelectedFontMerged3() throws Exception {
+ @Test
+ public void testSelectedFontMerged3() {
CTabFolder folder = createTestTabFolder("CTabItem { font-weight: bold }\n"
+ "CTabItem:selected { font-style: italic; font-weight: normal }");
spinEventLoop();
@@ -245,7 +259,7 @@ public class CTabItemTest extends CSSSWTTestCase {
}
}
- private void testShowClose(boolean showClose) throws Exception {
+ private void testShowClose(boolean showClose) {
CTabFolder folder = createTestTabFolder("CTabItem { show-close: "
+ Boolean.toString(showClose) + " }");
CTabItem[] items = folder.getItems();
@@ -256,15 +270,18 @@ public class CTabItemTest extends CSSSWTTestCase {
}
}
- public void testShowCloseFalse() throws Exception {
+ @Test
+ public void testShowCloseFalse() {
testShowClose(false);
}
- public void testShowCloseTrue() throws Exception {
+ @Test
+ public void testShowCloseTrue() {
testShowClose(true);
}
- public void testShowClose() throws Exception {
+ @Test
+ public void testShowClose() {
CTabFolder folder = createTestTabFolder("CTabItem { show-close: true }");
for (int i = 0; i < folder.getItemCount(); i++) {
assertEquals(true, folder.getItem(i).getShowClose());
@@ -278,7 +295,8 @@ public class CTabItemTest extends CSSSWTTestCase {
}
}
- public void testShowClose2() throws Exception {
+ @Test
+ public void testShowClose2() {
CTabFolder folder = createTestTabFolder();
CTabFolder folder2 = createFolder(folder.getShell());
engine = createEngine("CTabItem { show-close: true }", folder
@@ -321,7 +339,8 @@ public class CTabItemTest extends CSSSWTTestCase {
}
}
- public void testSelectedShowClose() throws Exception {
+ @Test
+ public void testSelectedShowClose() {
CTabFolder folder = createTestTabFolder("CTabItem:selected { show-close: true }");
for (int i = 0; i < folder.getItemCount(); i++) {
testSelectedShowClose(folder, i);
@@ -335,7 +354,8 @@ public class CTabItemTest extends CSSSWTTestCase {
}
}
- public void testSelectedShowClose2() throws Exception {
+ @Test
+ public void testSelectedShowClose2() {
CTabFolder folder = createTestTabFolder("CTabItem { show-close: false }\n"
+ "CTabItem:selected { show-close: true }");
for (int i = 0; i < folder.getItemCount(); i++) {
@@ -343,227 +363,228 @@ public class CTabItemTest extends CSSSWTTestCase {
}
}
-// public void testClassSelectedShowClose() throws Exception {
-// CTabFolder folder = createTestTabFolder();
-// WidgetElement.setCSSClass(folder, "editorStack");
-//
-// CSSEngine engine = createEngine(
-// "CTabFolder.editorStack CTabItem { show-close: true }", folder
-// .getDisplay());
-// engine.applyStyles(folder.getShell(), true);
-//
-// for (int i = 0; i < folder.getItemCount(); i++) {
-// assertTrue(folder.getItem(i).getShowClose());
-// }
-// }
-
-// public void testFontsEditorStackClass() {
-// CTabFolder folder = createTestTabFolder(false);
-// CTabFolder folder2 = createFolder(folder.getShell());
-//
-// WidgetElement.setCSSClass(folder2, "editorStack");
-// engine = createEngine(
-// "CTabItem { font-size: 10 }"
-// + "CTabItem:selected { font-size: 14; font-weight: bold }"
-// + "CTabFolder.editorStack CTabItem { font-size: 11; }"
-// + "CTabFolder.editorStack CTabItem:selected { font-size: 13; font-style: italic }",
-// folder.getDisplay());
-// engine.applyStyles(folder.getShell(), true);
-//
-// folder.getShell().open();
-// folder.setSelection(0);
-//
-// spinEventLoop();
-//
-// assertNotNull(folder.getSelection());
-// assertNull(folder2.getSelection());
-//
-// for (int i = 0; i < folder.getItemCount(); i++) {
-// CTabItem item = folder.getItem(i);
-// FontData data = item.getFont().getFontData()[0];
-//
-// if (item == folder.getSelection()) {
-// assertEquals(14, data.getHeight());
-// assertEquals(SWT.BOLD, data.getStyle());
-// } else {
-// assertEquals(10, data.getHeight());
-// assertEquals(SWT.NORMAL, data.getStyle());
-// }
-// }
-//
-// for (int i = 0; i < folder2.getItemCount(); i++) {
-// CTabItem item = folder2.getItem(i);
-// FontData data = item.getFont().getFontData()[0];
-//
-// assertEquals(11, data.getHeight());
-// assertEquals(SWT.NORMAL, data.getStyle());
-// }
-//
-// folder2.setSelection(0);
-// spinEventLoop();
-//
-// for (int i = 0; i < folder2.getItemCount(); i++) {
-// CTabItem item = folder2.getItem(i);
-// FontData data = item.getFont().getFontData()[0];
-// if (item == folder2.getSelection()) {
-// assertEquals(13, data.getHeight());
-// assertEquals(SWT.ITALIC | SWT.BOLD, data.getStyle());
-// } else {
-// assertEquals(11, data.getHeight());
-// assertEquals(SWT.NORMAL, data.getStyle());
-// }
-// }
-// }
-//
-// public void testFontsEditorStackClass2() {
-// CTabFolder folder = createTestTabFolder(false);
-// CTabFolder folder2 = createFolder(folder.getShell());
-//
-// WidgetElement.setCSSClass(folder2, "editorStack");
-// engine = createEngine(
-// "CTabItem { font-size: 10 }"
-// + "CTabItem:selected { font-size: 14; font-weight: bold }"
-// + "CTabFolder.editorStack CTabItem { font-size: 11; }"
-// + "CTabFolder.editorStack CTabItem:selected { font-size: 13; font-weight: normal; font-style: italic }",
-// folder.getDisplay());
-// engine.applyStyles(folder.getShell(), true);
-//
-// folder.getShell().open();
-// folder.setSelection(0);
-//
-// spinEventLoop();
-//
-// assertNotNull(folder.getSelection());
-// assertNull(folder2.getSelection());
-//
-// for (int i = 0; i < folder.getItemCount(); i++) {
-// CTabItem item = folder.getItem(i);
-// FontData data = item.getFont().getFontData()[0];
-//
-// if (item == folder.getSelection()) {
-// assertEquals(14, data.getHeight());
-// assertEquals(SWT.BOLD, data.getStyle());
-// } else {
-// assertEquals(10, data.getHeight());
-// assertEquals(SWT.NORMAL, data.getStyle());
-// }
-// }
-//
-// for (int i = 0; i < folder2.getItemCount(); i++) {
-// CTabItem item = folder2.getItem(i);
-// FontData data = item.getFont().getFontData()[0];
-//
-// assertEquals(11, data.getHeight());
-// assertEquals(SWT.NORMAL, data.getStyle());
-// }
-//
-// folder2.setSelection(0);
-// spinEventLoop();
-//
-// for (int i = 0; i < folder2.getItemCount(); i++) {
-// CTabItem item = folder2.getItem(i);
-// FontData data = item.getFont().getFontData()[0];
-// if (item == folder2.getSelection()) {
-// assertEquals(13, data.getHeight());
-// assertEquals(SWT.ITALIC, data.getStyle());
-// } else {
-// assertEquals(11, data.getHeight());
-// assertEquals(SWT.NORMAL, data.getStyle());
-// }
-// }
-// }
-//
-// public void testShowCloseEditorStack() {
-// CTabFolder folder = createTestTabFolder(false);
-// CTabFolder folder2 = createFolder(folder.getShell());
-//
-// WidgetElement.setCSSClass(folder2, "editorStack");
-// engine = createEngine("CTabItem { show-close: false }"
-// + "CTabItem:selected { show-close: true }"
-// + "CTabFolder.editorStack CTabItem { show-close: true }",
-// folder.getDisplay());
-// engine.applyStyles(folder.getShell(), true);
-//
-// folder.getShell().open();
-// folder.setSelection(0);
-//
-// spinEventLoop();
-//
-// assertNotNull(folder.getSelection());
-// assertNull(folder2.getSelection());
-//
-// for (int i = 0; i < folder.getItemCount(); i++) {
-// CTabItem item = folder.getItem(i);
-// if (item == folder.getSelection()) {
-// assertTrue(item.getShowClose());
-// } else {
-// assertFalse(item.getShowClose());
-// }
-// }
-//
-// for (int i = 0; i < folder2.getItemCount(); i++) {
-// CTabItem item = folder2.getItem(i);
-// assertTrue(item.getShowClose());
-// }
-//
-// folder2.setSelection(0);
-// spinEventLoop();
-//
-// for (int i = 0; i < folder2.getItemCount(); i++) {
-// CTabItem item = folder2.getItem(i);
-// assertTrue(item.getShowClose());
-// }
-// }
-//
-// public void testShowCloseViewStack() {
-// CTabFolder folder = createTestTabFolder(false);
-// CTabFolder folder2 = createFolder(folder.getShell());
-//
-// WidgetElement.setCSSClass(folder2, "viewStack");
-// engine = createEngine(
-// "CTabItem { show-close: false }"
-// + "CTabItem:selected { show-close: true }"
-// + "CTabFolder.viewStack CTabItem { show-close: false }"
-// + "CTabFolder.viewStack CTabItem.selected { show-close: true }",
-// folder.getDisplay());
-// engine.applyStyles(folder.getShell(), true);
-//
-// folder.getShell().open();
-// folder.setSelection(0);
-//
-// spinEventLoop();
-//
-// assertNotNull(folder.getSelection());
-// assertNull(folder2.getSelection());
-//
-// for (int i = 0; i < folder.getItemCount(); i++) {
-// CTabItem item = folder.getItem(i);
-// if (item == folder.getSelection()) {
-// assertTrue(item.getShowClose());
-// } else {
-// assertFalse(item.getShowClose());
-// }
-// }
-//
-// for (int i = 0; i < folder2.getItemCount(); i++) {
-// CTabItem item = folder2.getItem(i);
-// assertFalse(item.getShowClose());
-// }
-//
-// folder2.setSelection(0);
-// spinEventLoop();
-//
-// for (int i = 0; i < folder2.getItemCount(); i++) {
-// CTabItem item = folder.getItem(i);
-// if (item == folder.getSelection()) {
-// assertTrue(item.getShowClose());
-// } else {
-// assertFalse(item.getShowClose());
-// }
-// }
-// }
-
- public void testBackground() throws Exception {
+ @Ignore("test was commented before bug 443094")
+ @Test
+ public void testClassSelectedShowClose() {
+ CTabFolder folder = createTestTabFolder();
+ WidgetElement.setCSSClass(folder, "editorStack");
+
+ CSSEngine engine = createEngine("CTabFolder.editorStack CTabItem { show-close: true }", folder.getDisplay());
+ engine.applyStyles(folder.getShell(), true);
+
+ for (int i = 0; i < folder.getItemCount(); i++) {
+ assertTrue(folder.getItem(i).getShowClose());
+ }
+ }
+
+ @Ignore("test was commented before bug 443094")
+ @Test
+ public void testFontsEditorStackClass() {
+ CTabFolder folder = createTestTabFolder(false);
+ CTabFolder folder2 = createFolder(folder.getShell());
+
+ WidgetElement.setCSSClass(folder2, "editorStack");
+ engine = createEngine("CTabItem { font-size: 10 }" + "CTabItem:selected { font-size: 14; font-weight: bold }"
+ + "CTabFolder.editorStack CTabItem { font-size: 11; }"
+ + "CTabFolder.editorStack CTabItem:selected { font-size: 13; font-style: italic }", folder.getDisplay());
+ engine.applyStyles(folder.getShell(), true);
+
+ folder.getShell().open();
+ folder.setSelection(0);
+
+ spinEventLoop();
+
+ assertNotNull(folder.getSelection());
+ assertNull(folder2.getSelection());
+
+ for (int i = 0; i < folder.getItemCount(); i++) {
+ CTabItem item = folder.getItem(i);
+ FontData data = item.getFont().getFontData()[0];
+
+ if (item == folder.getSelection()) {
+ assertEquals(14, data.getHeight());
+ assertEquals(SWT.BOLD, data.getStyle());
+ } else {
+ assertEquals(10, data.getHeight());
+ assertEquals(SWT.NORMAL, data.getStyle());
+ }
+ }
+
+ for (int i = 0; i < folder2.getItemCount(); i++) {
+ CTabItem item = folder2.getItem(i);
+ FontData data = item.getFont().getFontData()[0];
+
+ assertEquals(11, data.getHeight());
+ assertEquals(SWT.NORMAL, data.getStyle());
+ }
+
+ folder2.setSelection(0);
+ spinEventLoop();
+
+ for (int i = 0; i < folder2.getItemCount(); i++) {
+ CTabItem item = folder2.getItem(i);
+ FontData data = item.getFont().getFontData()[0];
+ if (item == folder2.getSelection()) {
+ assertEquals(13, data.getHeight());
+ assertEquals(SWT.ITALIC | SWT.BOLD, data.getStyle());
+ } else {
+ assertEquals(11, data.getHeight());
+ assertEquals(SWT.NORMAL, data.getStyle());
+ }
+ }
+ }
+
+ @Ignore("test was commented before bug 443094")
+ @Test
+ public void testFontsEditorStackClass2() {
+ CTabFolder folder = createTestTabFolder(false);
+ CTabFolder folder2 = createFolder(folder.getShell());
+
+ WidgetElement.setCSSClass(folder2, "editorStack");
+ engine = createEngine(
+ "CTabItem { font-size: 10 }"
+ + "CTabItem:selected { font-size: 14; font-weight: bold }"
+ + "CTabFolder.editorStack CTabItem { font-size: 11; }"
+ + "CTabFolder.editorStack CTabItem:selected { font-size: 13; font-weight: normal; font-style: italic }",
+ folder.getDisplay());
+ engine.applyStyles(folder.getShell(), true);
+
+ folder.getShell().open();
+ folder.setSelection(0);
+
+ spinEventLoop();
+
+ assertNotNull(folder.getSelection());
+ assertNull(folder2.getSelection());
+
+ for (int i = 0; i < folder.getItemCount(); i++) {
+ CTabItem item = folder.getItem(i);
+ FontData data = item.getFont().getFontData()[0];
+
+ if (item == folder.getSelection()) {
+ assertEquals(14, data.getHeight());
+ assertEquals(SWT.BOLD, data.getStyle());
+ } else {
+ assertEquals(10, data.getHeight());
+ assertEquals(SWT.NORMAL, data.getStyle());
+ }
+ }
+
+ for (int i = 0; i < folder2.getItemCount(); i++) {
+ CTabItem item = folder2.getItem(i);
+ FontData data = item.getFont().getFontData()[0];
+
+ assertEquals(11, data.getHeight());
+ assertEquals(SWT.NORMAL, data.getStyle());
+ }
+
+ folder2.setSelection(0);
+ spinEventLoop();
+
+ for (int i = 0; i < folder2.getItemCount(); i++) {
+ CTabItem item = folder2.getItem(i);
+ FontData data = item.getFont().getFontData()[0];
+ if (item == folder2.getSelection()) {
+ assertEquals(13, data.getHeight());
+ assertEquals(SWT.ITALIC, data.getStyle());
+ } else {
+ assertEquals(11, data.getHeight());
+ assertEquals(SWT.NORMAL, data.getStyle());
+ }
+ }
+ }
+
+ @Ignore("test was commented before bug 443094")
+ @Test
+ public void testShowCloseEditorStack() {
+ CTabFolder folder = createTestTabFolder(false);
+ CTabFolder folder2 = createFolder(folder.getShell());
+
+ WidgetElement.setCSSClass(folder2, "editorStack");
+ engine = createEngine("CTabItem { show-close: false }" + "CTabItem:selected { show-close: true }"
+ + "CTabFolder.editorStack CTabItem { show-close: true }", folder.getDisplay());
+ engine.applyStyles(folder.getShell(), true);
+
+ folder.getShell().open();
+ folder.setSelection(0);
+
+ spinEventLoop();
+
+ assertNotNull(folder.getSelection());
+ assertNull(folder2.getSelection());
+
+ for (int i = 0; i < folder.getItemCount(); i++) {
+ CTabItem item = folder.getItem(i);
+ if (item == folder.getSelection()) {
+ assertTrue(item.getShowClose());
+ } else {
+ assertFalse(item.getShowClose());
+ }
+ }
+
+ for (int i = 0; i < folder2.getItemCount(); i++) {
+ CTabItem item = folder2.getItem(i);
+ assertTrue(item.getShowClose());
+ }
+
+ folder2.setSelection(0);
+ spinEventLoop();
+
+ for (int i = 0; i < folder2.getItemCount(); i++) {
+ CTabItem item = folder2.getItem(i);
+ assertTrue(item.getShowClose());
+ }
+ }
+
+ @Ignore("test was commented before bug 443094")
+ @Test
+ public void testShowCloseViewStack() {
+ CTabFolder folder = createTestTabFolder(false);
+ CTabFolder folder2 = createFolder(folder.getShell());
+
+ WidgetElement.setCSSClass(folder2, "viewStack");
+ engine = createEngine("CTabItem { show-close: false }" + "CTabItem:selected { show-close: true }"
+ + "CTabFolder.viewStack CTabItem { show-close: false }"
+ + "CTabFolder.viewStack CTabItem.selected { show-close: true }", folder.getDisplay());
+ engine.applyStyles(folder.getShell(), true);
+
+ folder.getShell().open();
+ folder.setSelection(0);
+
+ spinEventLoop();
+
+ assertNotNull(folder.getSelection());
+ assertNull(folder2.getSelection());
+
+ for (int i = 0; i < folder.getItemCount(); i++) {
+ CTabItem item = folder.getItem(i);
+ if (item == folder.getSelection()) {
+ assertTrue(item.getShowClose());
+ } else {
+ assertFalse(item.getShowClose());
+ }
+ }
+
+ for (int i = 0; i < folder2.getItemCount(); i++) {
+ CTabItem item = folder2.getItem(i);
+ assertFalse(item.getShowClose());
+ }
+
+ folder2.setSelection(0);
+ spinEventLoop();
+
+ for (int i = 0; i < folder2.getItemCount(); i++) {
+ CTabItem item = folder.getItem(i);
+ if (item == folder.getSelection()) {
+ assertTrue(item.getShowClose());
+ } else {
+ assertFalse(item.getShowClose());
+ }
+ }
+ }
+
+ @Test
+ public void testBackground() {
CTabFolder folder = createTestTabFolder(
"CTabItem { background-color: #0000ff }", false);
assertEquals(new RGB(0, 0, 255), folder.getBackground().getRGB());
@@ -574,7 +595,8 @@ public class CTabItemTest extends CSSSWTTestCase {
}
}
- public void testBackground2() throws Exception {
+ @Test
+ public void testBackground2() {
CTabFolder folder = createTestTabFolder(false);
Color preStyledSelectionBackground = folder.getSelectionBackground();
@@ -602,7 +624,8 @@ public class CTabItemTest extends CSSSWTTestCase {
.getSelectionBackground().getRGB());
}
- public void testSelectionBackground() throws Exception {
+ @Test
+ public void testSelectionBackground() {
CTabFolder folder = createTestTabFolder(
"CTabItem:selected { background-color: #00ff00 }", false);
assertEquals(new RGB(0, 255, 0), folder.getSelectionBackground()
@@ -614,7 +637,8 @@ public class CTabItemTest extends CSSSWTTestCase {
}
}
- public void testForeground() throws Exception {
+ @Test
+ public void testForeground() {
CTabFolder folder = createTestTabFolder("CTabItem { color: #0000ff }",
false);
assertEquals(new RGB(0, 0, 255), folder.getForeground().getRGB());
@@ -625,7 +649,8 @@ public class CTabItemTest extends CSSSWTTestCase {
}
}
- public void testForeground2() throws Exception {
+ @Test
+ public void testForeground2() {
CTabFolder folder = createTestTabFolder(false);
Color preStyledSelectionForeground = folder.getSelectionForeground();
@@ -654,7 +679,8 @@ public class CTabItemTest extends CSSSWTTestCase {
.getSelectionForeground().getRGB());
}
- public void testSelectionForeground() throws Exception {
+ @Test
+ public void testSelectionForeground() {
CTabFolder folder = createTestTabFolder(
"CTabItem:selected { color: #00ff00 }", false);
assertEquals(new RGB(0, 255, 0), folder.getSelectionForeground()
@@ -666,6 +692,7 @@ public class CTabItemTest extends CSSSWTTestCase {
}
}
+ @Test
public void testParent() {
CTabFolder folder = createTestTabFolder(
"CTabItem:selected { color: #00ff00 }", false);
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ColorDefinitionTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ColorDefinitionTest.java
index 20ce5e7c637..771ffb4af88 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ColorDefinitionTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ColorDefinitionTest.java
@@ -7,9 +7,14 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@@ -18,21 +23,17 @@ import org.eclipse.e4.ui.internal.css.swt.CSSActivator;
import org.eclipse.e4.ui.internal.css.swt.definition.IColorAndFontProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.internal.themes.ColorDefinition;
+import org.junit.Test;
@SuppressWarnings("restriction")
public class ColorDefinitionTest extends CSSSWTTestCase {
- private Display display;
- @Override
- protected void setUp() throws Exception {
- display = Display.getDefault();
- }
- public void testColorDefinition() throws Exception {
+ @Test
+ public void testColorDefinition() {
//given
CSSEngine engine = createEngine("ColorDefinition#ACTIVE_HYPERLINK_COLOR{color: green}", display);
ColorDefinition definition = colorDefinition("ACTIVE_HYPERLINK_COLOR", "name", "categoryId", "description");
@@ -49,10 +50,11 @@ public class ColorDefinitionTest extends CSSSWTTestCase {
assertEquals("categoryId", definition.getCategoryId());
assertTrue(definition.getDescription().startsWith("description"));
assertTrue(definition.isOverridden());
+ engine.dispose();
}
- public void testColorDefinitionWhenNameCategoryIdAndDescriptionOverridden()
- throws Exception {
+ @Test
+ public void testColorDefinitionWhenNameCategoryIdAndDescriptionOverridden() {
// given
CSSEngine engine = createEngine("ColorDefinition#ACTIVE_HYPERLINK_COLOR{color: green;" +
"label:'nameOverridden'; category:'#categoryIdOverridden'; description: 'descriptionOverridden'}", display);
@@ -70,9 +72,11 @@ public class ColorDefinitionTest extends CSSSWTTestCase {
assertEquals("categoryIdOverridden", definition.getCategoryId());
assertTrue(definition.getDescription().startsWith("descriptionOverridden"));
assertTrue(definition.isOverridden());
+ engine.dispose();
}
- public void testColorDefinitionWhenDefinitionStylesheetNotFound() throws Exception{
+ @Test
+ public void testColorDefinitionWhenDefinitionStylesheetNotFound() {
//given
CSSEngine engine = createEngine("ColorDefinition#ACTIVE_HYPERLINK_COLOR{color: green}", display);
ColorDefinition definition = colorDefinition("color definition uniqueId without matching stylesheet",
@@ -87,9 +91,11 @@ public class ColorDefinitionTest extends CSSSWTTestCase {
//then
assertEquals(new RGB(0, 0, 0), definition.getValue());
assertFalse(definition.isOverridden());
+ engine.dispose();
}
- public void testWidgetWithColorDefinitionAsBackgroundColor() throws Exception {
+ @Test
+ public void testWidgetWithColorDefinitionAsBackgroundColor() {
//given
registerColorProviderWith("ACTIVE_HYPERLINK_COLOR", new RGB(255, 0, 0));
@@ -105,6 +111,7 @@ public class ColorDefinitionTest extends CSSSWTTestCase {
//then
assertEquals(new RGB(255, 0, 0), label.getBackground().getRGB());
+ engine.dispose();
shell.dispose();
}
@@ -114,14 +121,18 @@ public class ColorDefinitionTest extends CSSSWTTestCase {
categoryId, true, description, "pluginId");
}
- private void registerColorProviderWith(final String symbolicName, final RGB rgb) throws Exception {
- new CSSActivator() {
- @Override
- public IColorAndFontProvider getColorAndFontProvider() {
- IColorAndFontProvider provider = mock(IColorAndFontProvider.class);
- doReturn(rgb).when(provider).getColor(symbolicName);
- return provider;
- };
- }.start(null);
+ private void registerColorProviderWith(final String symbolicName, final RGB rgb) {
+ try {
+ new CSSActivator() {
+ @Override
+ public IColorAndFontProvider getColorAndFontProvider() {
+ IColorAndFontProvider provider = mock(IColorAndFontProvider.class);
+ doReturn(rgb).when(provider).getColor(symbolicName);
+ return provider;
+ };
+ }.start(null);
+ } catch (Exception e) {
+ fail("Register color provider should not fail");
+ }
}
}
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CssSwtTestSuite.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CssSwtTestSuite.java
index 5c1cbe4ef38..399514fe371 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CssSwtTestSuite.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CssSwtTestSuite.java
@@ -7,12 +7,10 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Stefan Winkler <stefan@winklerweb.net> - Bug 419482
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
import org.eclipse.e4.ui.css.core.resources.CSSResourcesHelpersTest;
import org.eclipse.e4.ui.css.core.resources.SWTResourceRegistryKeyFactoryTest;
import org.eclipse.e4.ui.css.core.resources.SWTResourcesRegistryTest;
@@ -21,55 +19,19 @@ import org.eclipse.e4.ui.css.swt.helpers.CSSSWTFontHelperTest;
import org.eclipse.e4.ui.css.swt.helpers.EclipsePreferencesHelperTest;
import org.eclipse.e4.ui.css.swt.helpers.PreferenceOverriddenByCssChangeListenerTest;
import org.eclipse.e4.ui.css.swt.properties.preference.EclipsePreferencesHandlerTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
-public class CssSwtTestSuite extends TestSuite {
- /**
- * Returns the suite. This is required to use the JUnit Launcher.
- */
- public static final Test suite() {
- return new CssSwtTestSuite();
- }
-
- /**
- * Construct the test suite.
- */
- public CssSwtTestSuite() {
- addTestSuite(CSSSWTFontHelperTest.class);
- addTestSuite(CSSSWTColorHelperTest.class);
- addTestSuite(CSSResourcesHelpersTest.class);
- addTestSuite(SWTResourceRegistryKeyFactoryTest.class);
- addTestSuite(SWTResourcesRegistryTest.class);
- addTestSuite(FontDefinitionTest.class);
- addTestSuite(ColorDefinitionTest.class);
- addTestSuite(ThemesExtensionTest.class);
- addTestSuite(IEclipsePreferencesTest.class);
- addTestSuite(EclipsePreferencesHelperTest.class);
- addTestSuite(CSSSWTWidgetTest.class);
- addTestSuite(LabelTest.class);
- addTestSuite(CTabFolderTest.class);
- addTestSuite(CTabItemTest.class);
- // addTestSuite(ETabFolderTest.class);
- // addTestSuite(ETabItemTest.class);
- addTestSuite(IdClassLabelColorTest.class);
- addTestSuite(ShellTest.class);
- addTestSuite(ButtonTest.class);
- // addTestSuite(ShellActiveTest.class); //TODO see bug #273582
- addTestSuite(GradientTest.class);
- addTestSuite(MarginTest.class);
- addTestSuite(InnerClassElementTest.class);
- addTestSuite(EclipsePreferencesHandlerTest.class);
- addTestSuite(PreferenceOverriddenByCssChangeListenerTest.class);
-
- // text-transform tests
- addTestSuite(ButtonTextTransformTest.class);
- addTestSuite(LabelTextTransformTest.class);
- addTestSuite(TextTextTransformTest.class);
-
- //other
- addTestSuite(DescendentTest.class);
- addTestSuite(InheritTest.class);
+@RunWith(Suite.class)
+@Suite.SuiteClasses({ CSSSWTFontHelperTest.class, CSSSWTColorHelperTest.class, CSSResourcesHelpersTest.class,
+ SWTResourceRegistryKeyFactoryTest.class, SWTResourcesRegistryTest.class, FontDefinitionTest.class,
+ ColorDefinitionTest.class, ThemesExtensionTest.class, IEclipsePreferencesTest.class,
+ EclipsePreferencesHelperTest.class, CSSSWTWidgetTest.class, LabelTest.class, CTabFolderTest.class,
+ CTabItemTest.class, IdClassLabelColorTest.class, ShellTest.class, ButtonTest.class, GradientTest.class,
+ MarginTest.class, InnerClassElementTest.class, EclipsePreferencesHandlerTest.class,
+ PreferenceOverriddenByCssChangeListenerTest.class, ButtonTextTransformTest.class, LabelTextTransformTest.class,
+ TextTextTransformTest.class, DescendentTest.class, ThemeTest.class, Bug419482Test.class, ShellActiveTest.class,
+ InheritTest.class })
+public class CssSwtTestSuite {
- addTestSuite(ThemeTest.class);
- addTestSuite(Bug419482Test.class);
- }
}
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/DescendentTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/DescendentTest.java
index 2fd7a334cad..5835d8528c0 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/DescendentTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/DescendentTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 IBM Corporation and others.
+ * Copyright (c) 2013, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,31 +7,31 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import static org.junit.Assert.assertEquals;
+
import org.eclipse.e4.ui.css.swt.dom.WidgetElement;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
+import org.junit.Test;
public class DescendentTest extends CSSSWTTestCase {
-
+
static final RGB RED = new RGB(255, 0, 0);
static final RGB GREEN = new RGB(0, 255, 0);
static final RGB BLUE = new RGB(0, 0, 255);
static final RGB WHITE = new RGB(255, 255, 255);
static final RGB BLACK = new RGB(0, 0, 0);
- static public CSSEngine engine;
-
+
protected Button[] createTestWidgets(String styleSheet) {
- Display display = Display.getDefault();
engine = createEngine(styleSheet, display);
// Create widgets
@@ -50,29 +50,30 @@ public class DescendentTest extends CSSSWTTestCase {
engine.applyStyles(shell, true);
return new Button[] {buttonA, buttonB, buttonC};
}
-
- public void testDescendentSpecificity() throws Exception {
+
+ @Test
+ public void testDescendentSpecificity() {
Button[] buttons = createTestWidgets(
"Composite.special Button { background: #FF0000}\n" + //specificity a=1 b=0 c=1 = 101
- "Composite Button { background: #00FF00}\n" + //specificity a=0 b=0 c=2 = 002
- "Composite.extraordinary Button { background: #FFFFFF}\n" + //specificity a=0 b=0 c=2 = 002
- "#parent Button { background: #000000}\n" + //specificity a=0 b=0 c=2 = 002
+ "Composite Button { background: #00FF00}\n" + //specificity a=0 b=0 c=2 = 002
+ "Composite.extraordinary Button { background: #FFFFFF}\n" + //specificity a=0 b=0 c=2 = 002
+ "#parent Button { background: #000000}\n" + //specificity a=0 b=0 c=2 = 002
"Button { background: #0000FF}"); //specificity a=0 b=0 c=1 = 001
-
+
Button buttonA = buttons[0];
Button buttonB = buttons[1];
Button buttonC = buttons[2];
-
+
WidgetElement.setCSSClass(buttonA.getParent(), "special");
engine.applyStyles(buttonA.getShell(), true);
-
+
assertEquals(RED, buttonA.getBackground().getRGB());
assertEquals(GREEN, buttonB.getBackground().getRGB());
assertEquals(BLUE, buttonC.getBackground().getRGB());
-
+
WidgetElement.setCSSClass(buttonA.getParent(), "extraordinary");
WidgetElement.setID(buttonB.getParent(), "parent");
-
+
engine.applyStyles(buttonA.getShell(), true);
assertEquals(WHITE, buttonA.getBackground().getRGB());
assertEquals(BLACK, buttonB.getBackground().getRGB());
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/FontDefinitionTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/FontDefinitionTest.java
index 91b8dfc8b37..7540e19c5d5 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/FontDefinitionTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/FontDefinitionTest.java
@@ -7,35 +7,40 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
import org.eclipse.e4.ui.internal.css.swt.CSSActivator;
import org.eclipse.e4.ui.internal.css.swt.definition.IColorAndFontProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.internal.themes.FontDefinition;
+import org.junit.Test;
@SuppressWarnings("restriction")
public class FontDefinitionTest extends CSSSWTTestCase {
- private Display display;
- @Override
- protected void setUp() throws Exception {
- display = Display.getDefault();
- }
- public void testFontDefinition() throws Exception {
+
+ @Test
+ public void testFontDefinition() {
//given
- CSSEngine engine = createEngine("FontDefinition#org-eclipse-jface-bannerfont {font-family: 'Times';font-size: 12;font-style: italic;}", display);
+ engine = createEngine(
+ "FontDefinition#org-eclipse-jface-bannerfont {font-family: 'Times';font-size: 12;font-style: italic;}",
+ display);
FontDefinition definition = fontDefinition("org.eclipse.jface.bannerfont", "name", "categoryId","description");
assertNull(definition.getValue());
@@ -55,11 +60,13 @@ public class FontDefinitionTest extends CSSSWTTestCase {
assertTrue(definition.isOverridden());
}
- public void testFontDefinitionWhenNameCategoryIdAndDescriptionOverridden()
- throws Exception {
+ @Test
+ public void testFontDefinitionWhenNameCategoryIdAndDescriptionOverridden() {
// given
- CSSEngine engine = createEngine("FontDefinition#org-eclipse-jface-bannerfont {font-family: 'Times';font-size: 12;font-style: italic;" +
- " label:'nameOverridden'; category: '#categoryIdOverridden'; description: 'descriptionOverridden'}", display);
+ engine = createEngine(
+ "FontDefinition#org-eclipse-jface-bannerfont {font-family: 'Times';font-size: 12;font-style: italic;"
+ +
+ " label:'nameOverridden'; category: '#categoryIdOverridden'; description: 'descriptionOverridden'}", display);
FontDefinition definition = fontDefinition("org.eclipse.jface.bannerfont", "name", "categoryId", "description");
assertNull(definition.getValue());
@@ -79,9 +86,12 @@ public class FontDefinitionTest extends CSSSWTTestCase {
assertTrue(definition.isOverridden());
}
- public void testFontDefinitionWhenDefinitionStylesheetNotFound() throws Exception{
+ @Test
+ public void testFontDefinitionWhenDefinitionStylesheetNotFound() {
//given
- CSSEngine engine = createEngine("FontDefinition#org-eclipse-jface-bannerfont {font-family: 'Times';font-size: 12;font-style: italic;}", display);
+ engine = createEngine(
+ "FontDefinition#org-eclipse-jface-bannerfont {font-family: 'Times';font-size: 12;font-style: italic;}",
+ display);
FontDefinition definition = fontDefinition("font definition uniqueId without matching stylesheet", "name", "categoryId", "description");
assertNull(definition.getValue());
@@ -95,11 +105,12 @@ public class FontDefinitionTest extends CSSSWTTestCase {
assertFalse(definition.isOverridden());
}
- public void testWidgetWithFontDefinitionAsFontFamily() throws Exception {
+ @Test
+ public void testWidgetWithFontDefinitionAsFontFamily() {
//given
registerFontProviderWith("org.eclipse.jface.bannerfont", new FontData("Times", 12, SWT.ITALIC));
- CSSEngine engine = createEngine("Label {font-family: '#org-eclipse-jface-bannerfont'}", display);
+ engine = createEngine("Label {font-family: '#org-eclipse-jface-bannerfont'}", display);
Shell shell = new Shell(display, SWT.SHELL_TRIM);
Label label = new Label(shell, SWT.NONE);
@@ -128,14 +139,18 @@ public class FontDefinitionTest extends CSSSWTTestCase {
new FontData[] {new FontData("Arial", 10, SWT.NORMAL)});
}
- private void registerFontProviderWith(final String symbolicName, final FontData fontData) throws Exception {
- new CSSActivator() {
- @Override
- public IColorAndFontProvider getColorAndFontProvider() {
- IColorAndFontProvider provider = mock(IColorAndFontProvider.class);
- doReturn(new FontData[] { fontData }).when(provider).getFont(symbolicName);
- return provider;
- };
- }.start(null);
+ private void registerFontProviderWith(final String symbolicName, final FontData fontData) {
+ try {
+ new CSSActivator() {
+ @Override
+ public IColorAndFontProvider getColorAndFontProvider() {
+ IColorAndFontProvider provider = mock(IColorAndFontProvider.class);
+ doReturn(new FontData[] { fontData }).when(provider).getFont(symbolicName);
+ return provider;
+ };
+ }.start(null);
+ } catch (Exception e) {
+ fail("CssActivator start failed");
+ }
}
}
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/GradientTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/GradientTest.java
index 4808ee27c7b..3b822b2ea48 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/GradientTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/GradientTest.java
@@ -1,17 +1,20 @@
/*******************************************************************************
- * Copyright (c) 2009, 2012 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2009, 2014 IBM Corporation and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
import java.lang.reflect.Field;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
@@ -19,8 +22,8 @@ import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
+import org.junit.Test;
/**
* Test gradient capabilities.
@@ -30,15 +33,13 @@ import org.eclipse.swt.widgets.Shell;
*/
public class GradientTest extends CSSSWTTestCase {
-
+
static final RGB RED = new RGB(255, 0, 0);
static final RGB GREEN = new RGB(0, 255, 0);
static final RGB BLUE = new RGB(0, 0, 255);
static final RGB WHITE = new RGB(255, 255, 255);
- static public CSSEngine engine;
-
+
protected CTabFolder createTestCTabFolder(String styleSheet) {
- Display display = Display.getDefault();
engine = createEngine(styleSheet, display);
// Create widgets
@@ -51,116 +52,133 @@ public class GradientTest extends CSSSWTTestCase {
CTabFolder folderToTest = new CTabFolder(panel, SWT.NONE);
CTabItem tab1 = new CTabItem(folderToTest, SWT.NONE);
tab1.setText("A TAB ITEM");
-
+
engine.applyStyles(folderToTest, true);
shell.pack();
return folderToTest;
}
-
- public void testGradients() throws Exception {
+
+ @Test
+ public void testGradients() {
CTabFolder folderToTest = createTestCTabFolder(
"CTabItem:selected { background-color: #FF0000 #0000FF}");
- assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin
+ assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin
assertEquals(BLUE, folderToTest.getSelectionBackground().getRGB()); //gradient end
}
-
- public void testDefaultPercents() throws Exception {
+
+ @Test
+ public void testDefaultPercents() {
CTabFolder folderToTest = createTestCTabFolder(
"CTabItem:selected { background-color: #FF0000 #0000FF}");
- assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin
+ assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin
assertEquals(BLUE, folderToTest.getSelectionBackground().getRGB()); //gradient end
- assertEquals(new int[] {100}, getSelectionGradientPercents(folderToTest)); //default percent
+ assertArrayEquals(new int[] { 100 }, getSelectionGradientPercents(folderToTest)); // default
+ // percent
}
- public void testDefaultManyPercents() throws Exception {
+ @Test
+ public void testDefaultManyPercents() {
CTabFolder folderToTest = createTestCTabFolder(
"CTabItem:selected { background-color: red green blue yellow}");
- assertEquals(new int[] {33, 67, 100}, getSelectionGradientPercents(folderToTest)); //default percent
+ assertArrayEquals(new int[] { 33, 67, 100 }, getSelectionGradientPercents(folderToTest)); // default
+ // percent
}
-
- public void testSpecifiedPercents() throws Exception {
+
+ @Test
+ public void testSpecifiedPercents() {
CTabFolder folderToTest = createTestCTabFolder(
"CTabItem:selected { background-color: #FF0000 #0000FF 53%}");
- assertEquals(new int[] {53}, getSelectionGradientPercents(folderToTest));
+ assertArrayEquals(new int[] { 53 }, getSelectionGradientPercents(folderToTest));
}
- public void testManyColorsAndSpecifiedManyPercents() throws Exception {
+ @Test
+ public void testManyColorsAndSpecifiedManyPercents() {
CTabFolder folderToTest = createTestCTabFolder(
"CTabItem:selected { background-color: #FF0000 #00FF00 #0000FF 22% 44%}");
- assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin
- assertEquals(GREEN, getSelectionBackground(folderToTest, 1).getRGB()); //2nd gradient
+ assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin
+ assertEquals(GREEN, getSelectionBackground(folderToTest, 1).getRGB()); //2nd gradient
assertEquals(BLUE, folderToTest.getSelectionBackground().getRGB()); //gradient end
- assertEquals(new int[] {22, 44}, getSelectionGradientPercents(folderToTest));
+ assertArrayEquals(new int[] { 22, 44 }, getSelectionGradientPercents(folderToTest));
}
- /*
+ /*
* Tests handling when # of percents isn't one less than number of colors
*/
- public void testBadPercents() throws Exception {
+ @Test
+ public void testBadPercents() {
//There should be either zero or three percent declarations, otherwise it acts as default
CTabFolder folderToTest = createTestCTabFolder(
"CTabItem:selected { background-color: red green blue yellow 10%}");
- assertEquals(new int[] {33, 67, 100}, getSelectionGradientPercents(folderToTest)); //default percent
+ assertArrayEquals(new int[] { 33, 67, 100 }, getSelectionGradientPercents(folderToTest)); // default
+ // percent
}
- /*
+ /*
* Test to ensure that one bad apple doesn't spoil it for everyone
* (non-existent color name is ignored)
*/
- public void testBadColors() throws Exception {
+ @Test
+ public void testBadColors() {
CTabFolder folderToTest = createTestCTabFolder(
"CTabItem:selected { background-color: #FF0000 notAColor #0000FF}");
- assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin
+ assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin
assertEquals(BLUE, folderToTest.getSelectionBackground().getRGB()); //gradient end
- assertEquals(new int[] {100}, getSelectionGradientPercents(folderToTest)); //default percent
+ assertArrayEquals(new int[] { 100 }, getSelectionGradientPercents(folderToTest)); // default
+ // percent
}
-
- /*
+
+ /*
* Test to ensure that a percent > 100 triggers default
*/
- public void testAboveRangePercents() throws Exception {
+ @Test
+ public void testAboveRangePercents() {
CTabFolder folderToTest = createTestCTabFolder(
"CTabItem:selected { background-color: #FF0000 #00FF00 #0000FF 20% 110%}");
- assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin
+ assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin
assertEquals(BLUE, folderToTest.getSelectionBackground().getRGB()); //gradient end
- assertEquals(new int[] {50, 100}, getSelectionGradientPercents(folderToTest)); //default percent
+ assertArrayEquals(new int[] { 50, 100 }, getSelectionGradientPercents(folderToTest)); // default
+ // percent
}
- /*
+ /*
* Test to ensure that a percent < 0 triggers default
*/
- public void testBelowRangePercents() throws Exception {
+ @Test
+ public void testBelowRangePercents() {
CTabFolder folderToTest = createTestCTabFolder(
"CTabItem:selected { background-color: #FF0000 #00FF00 #0000FF -20% 50%}");
- assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin
+ assertEquals(RED, getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin
assertEquals(BLUE, folderToTest.getSelectionBackground().getRGB()); //gradient end
- assertEquals(new int[] {50, 100}, getSelectionGradientPercents(folderToTest)); //default percent
+ assertArrayEquals(new int[] { 50, 100 }, getSelectionGradientPercents(folderToTest)); // default
+ // percent
}
-
- /*
+
+ /*
* Test to ensure we properly parse something like:
* background-color: gradient,
- * rgb(140,140,140),
- * rgb(48,48,48),
- * 100%;
+ * rgb(140,140,140),
+ * rgb(48,48,48),
+ * 100%;
*/
- public void testAltSyntax() throws Exception {
+ @Test
+ public void testAltSyntax() {
CTabFolder folderToTest = createTestCTabFolder(
"CTabItem:selected { background-color: gradient, rgb(140,140,140), rgb(48,48,48), 100%;");
- assertEquals(new RGB(140,140,140), getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin
+ assertEquals(new RGB(140,140,140), getSelectionBackgroundBegin(folderToTest).getRGB()); //gradient begin
assertEquals(new RGB(48,48,48), folderToTest.getSelectionBackground().getRGB()); //gradient end
- assertEquals(new int[] {100}, getSelectionGradientPercents(folderToTest)); //default percent
+ assertArrayEquals(new int[] { 100 }, getSelectionGradientPercents(folderToTest)); // default
+ // percent
}
-
-
+
+
//CTabFolder doesn't provide getter for these so we need to dig via reflection
-
+
Color getSelectionBackgroundBegin(CTabFolder folder) {
return getSelectionBackground(folder, 0);
}
-
+
Color getSelectionBackground(CTabFolder folder, int i) {
try {
Field field = folder.getClass().getDeclaredField("selectionGradientColors");
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/IEclipsePreferencesTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/IEclipsePreferencesTest.java
index a0f5473a161..48d3fa79f0a 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/IEclipsePreferencesTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/IEclipsePreferencesTest.java
@@ -7,27 +7,25 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
+import static org.junit.Assert.assertEquals;
+
import org.eclipse.core.internal.preferences.EclipsePreferences;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.swt.widgets.Display;
+import org.junit.Test;
public class IEclipsePreferencesTest extends CSSSWTTestCase {
- private Display display;
- @Override
- protected void setUp() throws Exception {
- display = Display.getDefault();
- }
- public void testIEclipsePreferences() throws Exception {
+ @Test
+ public void testIEclipsePreferences() {
// given
IEclipsePreferences preferences = new EclipsePreferences(null, "org.eclipse.jdt.ui") {};
- CSSEngine engine = createEngine(
+ engine = createEngine(
"IEclipsePreferences#org-eclipse-jdt-ui{preferences:"
+ "'semanticHighlighting.abstractClass.color=128,255,0',"
+ "'java_bracket=0,255,255',"
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/IdClassLabelColorTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/IdClassLabelColorTest.java
index 28564caf08f..6d96f04acf4 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/IdClassLabelColorTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/IdClassLabelColorTest.java
@@ -1,23 +1,25 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2008, 2014 IBM Corporation and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import static org.junit.Assert.assertEquals;
+
import org.eclipse.e4.ui.css.swt.dom.WidgetElement;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
+import org.junit.Test;
/*
* Tests the CSS class and Id rules
@@ -28,13 +30,13 @@ public class IdClassLabelColorTest extends CSSSWTTestCase {
static final RGB RED = new RGB(255, 0, 0);
static final RGB GREEN = new RGB(0, 255, 0);
static final RGB BLUE = new RGB(0, 0, 255);
-
+
static final String CSS_CLASS_NAME = "makeItGreenClass";
static final String CSS_ID = "makeItBlueID";
-
+
+ @Override
protected Label createTestLabel(String styleSheet) {
- Display display = Display.getDefault();
- CSSEngine engine = createEngine(styleSheet, display);
+ engine = createEngine(styleSheet, display);
// Create widgets
Shell shell = new Shell(display, SWT.SHELL_TRIM);
@@ -48,22 +50,24 @@ public class IdClassLabelColorTest extends CSSSWTTestCase {
labelToTest.setText("Some label text");
WidgetElement.setCSSClass(labelToTest, CSS_CLASS_NAME);
WidgetElement.setID(labelToTest, CSS_ID);
-
+
// Apply styles
engine.applyStyles(shell, true);
shell.pack();
return labelToTest;
}
-
+
//For completeness, test that the html type rule works
- public void testWidgetClass() throws Exception {
+ @Test
+ public void testWidgetClass() {
Label label = createTestLabel("Label { background-color: #FF0000 }");
assertEquals(RED, label.getBackground().getRGB());
}
-
+
//Test the CSS class rule
- public void testCssClass() throws Exception {
+ @Test
+ public void testCssClass() {
Label labelToTest = createTestLabel("." + CSS_CLASS_NAME + " { background-color: #00FF00 }");
//Ensure the widget actually thinks it has this CSS class
@@ -73,9 +77,10 @@ public class IdClassLabelColorTest extends CSSSWTTestCase {
}
//Test the id rule
- public void testWidgetId() throws Exception {
+ @Test
+ public void testWidgetId() {
Label labelToTest = createTestLabel("#" + CSS_ID + " { background-color: #0000FF }");
-
+
//Ensure the widget actually thinks it has this ID
assertEquals(WidgetElement.getID(labelToTest), CSS_ID);
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/InheritTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/InheritTest.java
index 14e1d0d5a7d..0ef0ddb5eee 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/InheritTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/InheritTest.java
@@ -6,39 +6,44 @@
*
* Contributors:
* Stefan Winkler - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import static org.junit.Assert.assertEquals;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
public class InheritTest extends CSSSWTTestCase {
- private CSSEngine engine;
- private Display display;
+
private Color redColor;
static final RGB GREEN = new RGB(0, 255, 0);
static final RGB BLUE = new RGB(0, 0, 255);
static final RGB RED = new RGB(255, 0, 0);
+ @Before
@Override
- protected void setUp() throws Exception {
+ public void setUp() {
super.setUp();
- display = Display.getDefault();
+
redColor = new Color(display, RED);
}
+ @After
@Override
- protected void tearDown() throws Exception {
+ public void tearDown() {
redColor.dispose();
super.tearDown();
}
@@ -48,7 +53,8 @@ public class InheritTest extends CSSSWTTestCase {
* to widgets matching more specific rules with specify no explicit
* backgound-color.
*/
- public void testBackgroundNoInherit() throws Exception {
+ @Test
+ public void testBackgroundNoInherit() {
Label labelToTest = createTestLabel(
"Label { background-color: #00FF00; }\n"
+ "Composite Label { color: #0000FF; }", true);
@@ -62,6 +68,7 @@ public class InheritTest extends CSSSWTTestCase {
* 'background-color: inherit;' Instead, the background-color is set to the
* background-color of the parent widget.
*/
+ @Test
public void testBackgroundInherit() throws Exception {
Label labelToTest = createTestLabel(
"Label { background-color: #00FF00; }\n"
@@ -78,6 +85,7 @@ public class InheritTest extends CSSSWTTestCase {
* 'background-color: inherit;' Instead, the background-color is set to the
* background-color of the parent widget.
*/
+ @Test
public void testBackgroundInheritsAlsoExplicitlySetColors()
throws Exception {
Label labelToTest = createTestLabel(
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/InnerClassElementTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/InnerClassElementTest.java
index 96c60632a29..40cf76e6445 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/InnerClassElementTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/InnerClassElementTest.java
@@ -6,21 +6,22 @@
*
* Contributors:
* Stefan Winkler <stefan@winklerweb.net> - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import static org.junit.Assert.assertEquals;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
+import org.junit.Test;
public class InnerClassElementTest extends CSSSWTTestCase {
- CSSEngine engine;
// create an inner class to address via CSS
class CustomComposite extends Composite {
@@ -29,8 +30,8 @@ public class InnerClassElementTest extends CSSSWTTestCase {
}
}
+ @Override
protected Label createTestLabel(String styleSheet) {
- Display display = Display.getDefault();
engine = createEngine(styleSheet, display);
// Create widgets
@@ -50,7 +51,8 @@ public class InnerClassElementTest extends CSSSWTTestCase {
return labelToTest;
}
- public void testInnerClassElement() throws Exception {
+ @Test
+ public void testInnerClassElement() {
Label label = createTestLabel("InnerClassElementTest-CustomComposite Label { color: #00ffa0; }");
assertEquals(0x00, label.getForeground().getRed());
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/LabelTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/LabelTest.java
index 16b3ccf02a2..1112b77ba50 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/LabelTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/LabelTest.java
@@ -1,103 +1,83 @@
/*******************************************************************************
- * Copyright (c) 2009 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2009, 2014 IBM Corporation and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Remy Chi Jian Suen <remy.suen@gmail.com> - bug 137650
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import static org.junit.Assert.assertEquals;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
+import org.junit.Test;
public class LabelTest extends CSSSWTTestCase {
static final RGB RED = new RGB(255, 0, 0);
static final RGB GREEN = new RGB(0, 255, 0);
static final RGB BLUE = new RGB(0, 0, 255);
-
- CSSEngine engine;
-
- protected Label createTestLabel(String styleSheet) {
- Display display = Display.getDefault();
- engine = createEngine(styleSheet, display);
-
- // Create widgets
- Shell shell = new Shell(display, SWT.SHELL_TRIM);
- FillLayout layout = new FillLayout();
- shell.setLayout(layout);
-
- Composite panel = new Composite(shell, SWT.NONE);
- panel.setLayout(new FillLayout());
-
- Label labelToTest = new Label(panel, SWT.NONE);
- labelToTest.setText("Some label text");
- // Apply styles
- engine.applyStyles(labelToTest, true);
-
- shell.pack();
- return labelToTest;
- }
-
-
- public void testColor() throws Exception {
+ @Test
+ public void testColor() {
Label labelToTest = createTestLabel("Label { background-color: #FF0000; color: #0000FF }");
assertEquals(RED, labelToTest.getBackground().getRGB());
assertEquals(BLUE, labelToTest.getForeground().getRGB());
}
- public void testFontRegular() throws Exception {
+ @Test
+ public void testFontRegular() {
Label labelToTest = createTestLabel("Label { font: Verdana 16px }");
assertEquals(1, labelToTest.getFont().getFontData().length);
FontData fontData = labelToTest.getFont().getFontData()[0];
assertEquals("Verdana", fontData.getName());
assertEquals(16, fontData.getHeight());
- assertEquals(SWT.NORMAL, fontData.getStyle());
+ assertEquals(SWT.NORMAL, fontData.getStyle());
}
- public void testFontBold() throws Exception {
+ @Test
+ public void testFontBold() {
Label labelToTest = createTestLabel("Label { font: Arial 12px; font-weight: bold }");
assertEquals(1, labelToTest.getFont().getFontData().length);
FontData fontData = labelToTest.getFont().getFontData()[0];
assertEquals("Arial", fontData.getName());
assertEquals(12, fontData.getHeight());
- assertEquals(SWT.BOLD, fontData.getStyle());
+ assertEquals(SWT.BOLD, fontData.getStyle());
}
- public void testFontItalic() throws Exception {
+ @Test
+ public void testFontItalic() {
Label labelToTest = createTestLabel("Label { font-style: italic }");
assertEquals(1, labelToTest.getFont().getFontData().length);
FontData fontData = labelToTest.getFont().getFontData()[0];
- assertEquals(SWT.ITALIC, fontData.getStyle());
+ assertEquals(SWT.ITALIC, fontData.getStyle());
}
-
- public void testAlignment() throws Exception {
+
+ @Test
+ public void testAlignment() {
Label labelToTest = createTestLabel("Label { alignment: right }");
assertEquals(SWT.RIGHT, labelToTest.getAlignment());
-
+
labelToTest = createTestLabel("Label { alignment: center; }");
assertEquals(SWT.CENTER, labelToTest.getAlignment());
labelToTest = createTestLabel("Label { alignment: left; }");
assertEquals(SWT.LEFT, labelToTest.getAlignment());
-
+
}
-
- public void testAlignment2() throws Exception {
+
+ @Test
+ public void testAlignment2() {
Label labelToTest = createTestLabel("Label { alignment: trail }");
assertEquals(SWT.TRAIL, labelToTest.getAlignment());
-
+
labelToTest = createTestLabel("Label { alignment: lead; }");
assertEquals(SWT.LEAD, labelToTest.getAlignment());
}
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/LabelTextTransformTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/LabelTextTransformTest.java
index fe34c603b6d..c20eec3034e 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/LabelTextTransformTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/LabelTextTransformTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Remy Chi Jian Suen and others.
+ * Copyright (c) 2009, 2014 Remy Chi Jian Suen and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Remy Chi Jian Suen <remy.suen@gmail.com> - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
@@ -14,21 +15,25 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
-
+
public class LabelTextTransformTest extends TextTransformTest {
-
+
+ @Override
protected Control createControl(Composite parent) {
return new Label(parent, SWT.LEAD);
}
-
+
+ @Override
protected String getWidgetName() {
return "Label";
}
+ @Override
protected String getText(Control control) {
return ((Label) control).getText();
}
-
+
+ @Override
protected void setText(Control control, String string) {
((Label) control).setText(string);
}
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/MarginTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/MarginTest.java
index 9d6d6469e31..572b7d24a5f 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/MarginTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/MarginTest.java
@@ -1,15 +1,18 @@
/*******************************************************************************
- * Copyright (c) 2009 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2009, 2014 IBM Corporation and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+
import org.eclipse.e4.ui.css.swt.CSSSWTConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.RGB;
@@ -17,28 +20,26 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
+import org.junit.Test;
public class MarginTest extends CSSSWTTestCase {
private static final RGB RED = new RGB(255, 0, 0);
- CSSEngine engine;
-
+
private final static int TOP = 0;
private final static int RIGHT = 1;
private final static int BOTTOM = 2;
private final static int LEFT = 3;
-
+
protected Control createTestControl(String styleSheet) {
- Display display = Display.getDefault();
engine = createEngine(styleSheet, display);
-
+
// Create widgets
Shell shell = new Shell(display, SWT.SHELL_TRIM);
Composite panel = new Composite(shell, SWT.NONE);
panel.setData(CSSSWTConstants.MARGIN_WRAPPER_KEY, true);
-
+
//Must be grid, see CSSPropertyMarginSWTHandler
GridLayout layout = new GridLayout();
layout.marginTop = 0;
@@ -57,9 +58,8 @@ public class MarginTest extends CSSSWTTestCase {
}
protected Control createBadControlNoLayout(String styleSheet) {
- Display display = Display.getDefault();
engine = createEngine(styleSheet, display);
-
+
Shell shell = new Shell(display, SWT.SHELL_TRIM);
Composite panel = new Composite(shell, SWT.NONE);
panel.setData(CSSSWTConstants.MARGIN_WRAPPER_KEY);
@@ -72,9 +72,8 @@ public class MarginTest extends CSSSWTTestCase {
}
protected Control createBadControlNoComposite(String styleSheet) {
- Display display = Display.getDefault();
engine = createEngine(styleSheet, display);
-
+
Shell shell = new Shell(display, SWT.SHELL_TRIM);
//No composite
Button buttonToTest = new Button(shell, SWT.CHECK);
@@ -83,9 +82,8 @@ public class MarginTest extends CSSSWTTestCase {
return buttonToTest;
}
-
+
protected Control createBadControlNoKey(String styleSheet) {
- Display display = Display.getDefault();
engine = createEngine(styleSheet, display);
// Create widgets
@@ -110,6 +108,7 @@ public class MarginTest extends CSSSWTTestCase {
return buttonToTest;
}
+ @Test
public void testTopMargin() {
Control control = createTestControl("Button { margin-top: 10}");
assertEquals(10, getMargin(control, TOP));
@@ -118,6 +117,7 @@ public class MarginTest extends CSSSWTTestCase {
assertEquals(0, getMargin(control, LEFT));
}
+ @Test
public void testRightMargin() {
Control control = createTestControl("Button { margin-right: 20}");
assertEquals(0, getMargin(control, TOP));
@@ -126,6 +126,7 @@ public class MarginTest extends CSSSWTTestCase {
assertEquals(0, getMargin(control, LEFT));
}
+ @Test
public void testBottomMargin() {
Control control = createTestControl("Button { margin-bottom: 30}");
assertEquals(0, getMargin(control, TOP));
@@ -134,6 +135,7 @@ public class MarginTest extends CSSSWTTestCase {
assertEquals(0, getMargin(control, LEFT));
}
+ @Test
public void testLeftMargin() {
Control control = createTestControl("Button { margin-left: 40}");
assertEquals(0, getMargin(control, TOP));
@@ -142,6 +144,7 @@ public class MarginTest extends CSSSWTTestCase {
assertEquals(40, getMargin(control, LEFT));
}
+ @Test
public void testMargin1Value() {
Control control = createTestControl("Button { margin: 15}");
assertEquals(15, getMargin(control, TOP));
@@ -149,7 +152,8 @@ public class MarginTest extends CSSSWTTestCase {
assertEquals(15, getMargin(control, BOTTOM));
assertEquals(15, getMargin(control, LEFT));
}
-
+
+ @Test
public void testMargin2Values() {
Control control = createTestControl("Button { margin: 10 15}");
assertEquals(10, getMargin(control, TOP));
@@ -158,6 +162,7 @@ public class MarginTest extends CSSSWTTestCase {
assertEquals(15, getMargin(control, LEFT));
}
+ @Test
public void testMargin4Values() {
Control control = createTestControl("Button { margin: 10 15 20 40}");
assertEquals(10, getMargin(control, TOP));
@@ -165,10 +170,11 @@ public class MarginTest extends CSSSWTTestCase {
assertEquals(20, getMargin(control, BOTTOM));
assertEquals(40, getMargin(control, LEFT));
}
-
+
/*
* Test handling if there is no layout on the control so can't set margins
- */
+ */
+ @Test
public void testMarginNoLayout() {
//shouldn't blow up, nothing should happen
Control control = createBadControlNoLayout("Button { margin: 10 15 20 40; background-color: #FF0000 }");
@@ -178,7 +184,8 @@ public class MarginTest extends CSSSWTTestCase {
/*
* Test handling if there is no composite on the control so can't set margins
- */
+ */
+ @Test
public void testMarginNoComposite() {
//shouldn't blow up, nothing should happen
Control control = createBadControlNoComposite("Button { margin: 10 15 20 40; background-color: #FF0000 }");
@@ -188,7 +195,8 @@ public class MarginTest extends CSSSWTTestCase {
/*
* Test handling if there is no key to tell us we can manipulate the composite's layout
- */
+ */
+ @Test
public void testMarginNoKey() {
//shouldn't blow up, nothing should happen
Control control = createBadControlNoKey("Button { margin: 10 15 20 40; background-color: #FF0000 }");
@@ -196,8 +204,8 @@ public class MarginTest extends CSSSWTTestCase {
assertEquals(RED, control.getBackground().getRGB());
assertNotSame(10, getMargin(control, TOP));
}
-
-
+
+
private int getMargin(Control control, int side) {
//Note: relies on implementation details of how we achieve margins on the widgets
//See CSSPropertyMarginSWTHandler
@@ -206,11 +214,11 @@ public class MarginTest extends CSSSWTTestCase {
case TOP:
return layout.marginTop;
case RIGHT:
- return layout.marginRight;
+ return layout.marginRight;
case BOTTOM:
- return layout.marginBottom;
+ return layout.marginBottom;
case LEFT:
- return layout.marginLeft;
+ return layout.marginLeft;
}
return -1;
}
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ShellActiveTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ShellActiveTest.java
index a95ddf10510..b96aa93dfbf 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ShellActiveTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ShellActiveTest.java
@@ -1,42 +1,46 @@
/*******************************************************************************
- * Copyright (c) 2009 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2009, 2014 IBM Corporation and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import static org.junit.Assert.assertEquals;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
+import org.junit.Ignore;
+import org.junit.Test;
+@Ignore("see bug #273582")
public class ShellActiveTest extends CSSSWTTestCase {
-
+
static final RGB RED = new RGB(255, 0, 0);
static final RGB BLUE = new RGB(0, 0, 255);
-
+
protected Shell createShell(String styleSheet) {
- Display display = Display.getDefault();
- CSSEngine engine = createEngine(styleSheet, display);
+ createEngine(styleSheet, display);
// Create widgets
Shell shell = new Shell(display, SWT.NONE);
-
+
engine.applyStyles(shell, true);
shell.pack();
shell.open();
return shell;
}
-
+
+ @Test
public void testShellActive() throws Exception {
Shell shell = createShell("Shell:active {background-color: #FF0000;}\n" +
- "Shell {background-color: #0000FF;}");
+ "Shell {background-color: #0000FF;}");
assertEquals(RED, shell.getBackground().getRGB());
Shell newShell = createShell("Shell { background-color: #0000FF; }");
assertEquals(BLUE, shell.getBackground().getRGB());
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ShellTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ShellTest.java
index 40e9da182fb..151a8affe31 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ShellTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ShellTest.java
@@ -1,36 +1,38 @@
/*******************************************************************************
- * Copyright (c) 2008, 2012 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2008, 2014 IBM Corporation and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+
import java.util.HashSet;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
import org.eclipse.e4.ui.css.swt.dom.WidgetElement;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
+import org.junit.Test;
public class ShellTest extends CSSSWTTestCase {
static final RGB RED = new RGB(255, 0, 0);
static final RGB GREEN = new RGB(0, 255, 0);
static final RGB BLUE = new RGB(0, 0, 255);
-
+
protected Shell createTestShell(String styleSheet) {
- Display display = Display.getDefault();
- CSSEngine engine = createEngine(styleSheet, display);
-
+ engine = createEngine(styleSheet, display);
+
// Create widgets
Shell shell = new Shell(display, SWT.SHELL_TRIM);
FillLayout layout = new FillLayout();
@@ -45,90 +47,94 @@ public class ShellTest extends CSSSWTTestCase {
shell.pack();
return shell;
}
-
-
- public void testColor() throws Exception {
+
+
+ @Test
+ public void testColor() {
Shell shellToTest = createTestShell("Shell { background-color: #FF0000; color: #0000FF }");
assertEquals(RED, shellToTest.getBackground().getRGB());
assertEquals(BLUE, shellToTest.getForeground().getRGB());
}
- public void testFontRegular() throws Exception {
+ @Test
+ public void testFontRegular() {
Shell shellToTest = createTestShell("Shell { font: Verdana 16px }");
assertEquals(1, shellToTest.getFont().getFontData().length);
FontData fontData = shellToTest.getFont().getFontData()[0];
assertEquals("Verdana", fontData.getName());
assertEquals(16, fontData.getHeight());
- assertEquals(SWT.NORMAL, fontData.getStyle());
+ assertEquals(SWT.NORMAL, fontData.getStyle());
}
- public void testFontBold() throws Exception {
+ @Test
+ public void testFontBold() {
Shell shellToTest = createTestShell("Shell { font: Arial 12px; font-weight: bold }");
assertEquals(1, shellToTest.getFont().getFontData().length);
FontData fontData = shellToTest.getFont().getFontData()[0];
assertEquals("Arial", fontData.getName());
assertEquals(12, fontData.getHeight());
- assertEquals(SWT.BOLD, fontData.getStyle());
+ assertEquals(SWT.BOLD, fontData.getStyle());
}
- public void testFontItalic() throws Exception {
+ @Test
+ public void testFontItalic() {
Shell shellToTest = createTestShell("Shell { font-style: italic }");
assertEquals(1, shellToTest.getFont().getFontData().length);
FontData fontData = shellToTest.getFont().getFontData()[0];
- assertEquals(SWT.ITALIC, fontData.getStyle());
+ assertEquals(SWT.ITALIC, fontData.getStyle());
+ }
+
+ // bug 375069: ensure children aren't caught up in parent
+ @Test
+ public void test375069ChildShellDifferentiation() {
+ engine = createEngine("Shell.parent { font-style: italic; }", display);
+
+ Shell parent = new Shell(display, SWT.NONE);
+ WidgetElement.setCSSClass(parent, "parent");
+ Shell child = new Shell(parent, SWT.NONE);
+ WidgetElement.setCSSClass(child, "child");
+ parent.open();
+ child.open();
+ engine.applyStyles(parent, true);
+ engine.applyStyles(child, true);
+
+
+ assertEquals(1, parent.getFont().getFontData().length);
+ FontData fontData = parent.getFont().getFontData()[0];
+ assertEquals(SWT.ITALIC, fontData.getStyle());
+
+ assertEquals(1, child.getFont().getFontData().length);
+ fontData = child.getFont().getFontData()[0];
+ assertNotSame(SWT.ITALIC, fontData.getStyle());
}
- // bug 375069: ensure children aren't caught up in parent
- public void test375069ChildShellDifferentiation() throws Exception {
- Display display = Display.getDefault();
- CSSEngine engine = createEngine("Shell.parent { font-style: italic; }", display);
-
- Shell parent = new Shell(display, SWT.NONE);
- WidgetElement.setCSSClass(parent, "parent");
- Shell child = new Shell(parent, SWT.NONE);
- WidgetElement.setCSSClass(child, "child");
- parent.open();
- child.open();
- engine.applyStyles(parent, true);
- engine.applyStyles(child, true);
-
-
- assertEquals(1, parent.getFont().getFontData().length);
- FontData fontData = parent.getFont().getFontData()[0];
- assertEquals(SWT.ITALIC, fontData.getStyle());
-
- assertEquals(1, child.getFont().getFontData().length);
- fontData = child.getFont().getFontData()[0];
- assertNotSame(SWT.ITALIC, fontData.getStyle());
- }
-
- // bug 375069: ensure children shells are still captured by Shell
- public void test375069AllShell() throws Exception {
- Display display = Display.getDefault();
- CSSEngine engine = createEngine("Shell { font-style: italic; }", display);
-
- Shell parent = new Shell(display, SWT.NONE);
- WidgetElement.setCSSClass(parent, "parent");
- Shell child = new Shell(parent, SWT.NONE);
+ // bug 375069: ensure children shells are still captured by Shell
+ @Test
+ public void test375069AllShell() {
+ engine = createEngine("Shell { font-style: italic; }", display);
+
+ Shell parent = new Shell(display, SWT.NONE);
+ WidgetElement.setCSSClass(parent, "parent");
+ Shell child = new Shell(parent, SWT.NONE);
WidgetElement.setCSSClass(child, "child");
- parent.open();
- child.open();
- engine.applyStyles(parent, true);
- engine.applyStyles(child, true);
+ parent.open();
+ child.open();
+ engine.applyStyles(parent, true);
+ engine.applyStyles(child, true);
- assertEquals(1, parent.getFont().getFontData().length);
- FontData fontData = parent.getFont().getFontData()[0];
- assertEquals(SWT.ITALIC, fontData.getStyle());
+ assertEquals(1, parent.getFont().getFontData().length);
+ FontData fontData = parent.getFont().getFontData()[0];
+ assertEquals(SWT.ITALIC, fontData.getStyle());
- assertEquals(1, child.getFont().getFontData().length);
- fontData = child.getFont().getFontData()[0];
- assertEquals(SWT.ITALIC, fontData.getStyle());
- }
+ assertEquals(1, child.getFont().getFontData().length);
+ fontData = child.getFont().getFontData()[0];
+ assertEquals(SWT.ITALIC, fontData.getStyle());
+ }
// bug 375069: ensure children shells are still captured by Shell
- public void testShellParentage() throws Exception {
- Display display = Display.getDefault();
- CSSEngine engine = createEngine(
+ @Test
+ public void testShellParentage() {
+ engine = createEngine(
"Shell[parentage='parent'] { font-style: italic; }", display);
Shell parent = new Shell(display, SWT.NONE);
@@ -149,9 +155,9 @@ public class ShellTest extends CSSSWTTestCase {
assertEquals(SWT.ITALIC, fontData.getStyle());
}
- public void testShellUnparentedPseudoelement() throws Exception {
- Display display = Display.getDefault();
- CSSEngine engine = createEngine(
+ @Test
+ public void testShellUnparentedPseudoelement() {
+ engine = createEngine(
"Shell:swt-unparented { font-style: italic; }", display);
Shell parent = new Shell(display, SWT.NONE);
@@ -172,9 +178,9 @@ public class ShellTest extends CSSSWTTestCase {
assertNotSame(SWT.ITALIC, fontData.getStyle());
}
- public void testShellParentedPseudoelement() throws Exception {
- Display display = Display.getDefault();
- CSSEngine engine = createEngine(
+ @Test
+ public void testShellParentedPseudoelement() {
+ engine = createEngine(
"Shell:swt-parented { font-style: italic; }", display);
Shell parent = new Shell(display, SWT.NONE);
@@ -195,9 +201,9 @@ public class ShellTest extends CSSSWTTestCase {
assertEquals(SWT.ITALIC, fontData.getStyle());
}
- public void testSwtDataClassAttribute() throws Exception {
- Display display = Display.getDefault();
- CSSEngine engine = createEngine(
+ @Test
+ public void testSwtDataClassAttribute() {
+ engine = createEngine(
"Shell[swt-data-class ~= 'java.util.HashSet'] { font-style: italic; }",
display);
@@ -211,7 +217,8 @@ public class ShellTest extends CSSSWTTestCase {
assertEquals(SWT.ITALIC, fontData.getStyle());
}
- public void testBackgroundMode() throws Exception {
+ @Test
+ public void testBackgroundMode() {
Shell shellToTest = createTestShell("Shell { swt-background-mode: force; }");
assertEquals(SWT.INHERIT_FORCE, shellToTest.getBackgroundMode());
}
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/TestPropertyHelper.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/TestPropertyHelper.java
index fbc79cd7a9b..5116789dcfd 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/TestPropertyHelper.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/TestPropertyHelper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 IBM Corporation and others.
+ * Copyright (c) 2013, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,14 +7,17 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
-import org.eclipse.e4.ui.css.swt.helpers.PropertyHelper;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
-import junit.framework.TestCase;
+import org.eclipse.e4.ui.css.swt.helpers.PropertyHelper;
+import org.junit.Test;
-public class TestPropertyHelper extends TestCase {
+public class TestPropertyHelper {
public static class Base {
private String a = "A";
public String getA() {
@@ -23,40 +26,41 @@ public class TestPropertyHelper extends TestCase {
public void setA(String a) {
this.a = a;
}
-
+
public String getC() {
return "C";
}
-
+
public boolean isD() {
return true;
}
}
-
+
public static class Impl extends Base {
private String b = "B";
private Base nested = new Base();
{
nested.a = "Nested";
}
-
+
public String getB() {
return b;
}
-
+
public void setB(String b) {
this.b = b;
}
-
+
public Base getNested() {
return nested;
}
-
+
public void setNested(Base nested) {
this.nested = nested;
}
}
-
+
+ @Test
public void testReadWriteProperty() {
Impl bean = new Impl();
try {
@@ -67,7 +71,8 @@ public class TestPropertyHelper extends TestCase {
fail();
}
}
-
+
+ @Test
public void testReadOnlyProperty() {
Impl bean = new Impl();
try {
@@ -78,7 +83,8 @@ public class TestPropertyHelper extends TestCase {
fail();
}
}
-
+
+ @Test
public void testNestedProperty() {
Impl bean = new Impl();
try {
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/TextTextTransformTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/TextTextTransformTest.java
index 1b1a26cdd14..19b1fda867e 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/TextTextTransformTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/TextTextTransformTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Remy Chi Jian Suen and others.
+ * Copyright (c) 2009, 2014 Remy Chi Jian Suen and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Remy Chi Jian Suen <remy.suen@gmail.com> - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
@@ -14,21 +15,25 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;
-
+
public class TextTextTransformTest extends TextTransformTest {
-
+
+ @Override
protected Control createControl(Composite parent) {
return new Text(parent, SWT.SINGLE);
}
-
+
+ @Override
protected String getWidgetName() {
return "Text";
}
+ @Override
protected String getText(Control control) {
return ((Text) control).getText();
}
-
+
+ @Override
protected void setText(Control control, String string) {
((Text) control).setText(string);
}
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/TextTransformTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/TextTransformTest.java
index 889cef70de1..5205b103685 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/TextTransformTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/TextTransformTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Remy Chi Jian Suen and others.
+ * Copyright (c) 2009, 2014 Remy Chi Jian Suen and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,16 +7,18 @@
*
* Contributors:
* Remy Chi Jian Suen <remy.suen@gmail.com> - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import static org.junit.Assert.assertEquals;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
+import org.junit.Test;
/**
* Tests the <code>text-transform</code> property.
@@ -35,12 +37,11 @@ import org.eclipse.swt.widgets.Shell;
*/
public abstract class TextTransformTest extends CSSSWTTestCase {
- private CSSEngine engine;
/**
* Retrieves the name of the widget that is being tested, must not be
* <code>null</code>.
- *
+ *
* @return the name of the widget for identification by the style sheet
*/
protected abstract String getWidgetName();
@@ -49,7 +50,7 @@ public abstract class TextTransformTest extends CSSSWTTestCase {
* Creates and returns the control that will be tested for verifying that
* the <code>text-transform</code> property works, must not be
* <code>null</code>.
- *
+ *
* @param parent
* the parent composite to house the control
* @return the created control, must not be <code>null</code>
@@ -58,7 +59,7 @@ public abstract class TextTransformTest extends CSSSWTTestCase {
/**
* Retrieves the text set to the specified control.
- *
+ *
* @param control
* the control to retrieve text from
* @return the text that's set on the underlying control
@@ -67,7 +68,7 @@ public abstract class TextTransformTest extends CSSSWTTestCase {
/**
* Sets the specified string to the control.
- *
+ *
* @param control
* the control to set the string to
* @param string
@@ -76,7 +77,6 @@ public abstract class TextTransformTest extends CSSSWTTestCase {
protected abstract void setText(Control control, String string);
private Control createTestControl(String styleSheet) {
- Display display = Display.getDefault();
engine = createEngine(styleSheet, display);
// Create widgets
@@ -97,6 +97,7 @@ public abstract class TextTransformTest extends CSSSWTTestCase {
/**
* Tests the <code>capitalize</code> attribute value.
*/
+ @Test
public void testTextTransformCapitalize() {
Control controlToTest = createTestControl(getWidgetName()
+ " { text-transform: capitalize; }");
@@ -106,6 +107,7 @@ public abstract class TextTransformTest extends CSSSWTTestCase {
/**
* Tests the <code>uppercase</code> attribute value.
*/
+ @Test
public void testTextTransformUpperCase() {
Control controlToTest = createTestControl(getWidgetName()
+ " { text-transform: uppercase; }");
@@ -115,9 +117,11 @@ public abstract class TextTransformTest extends CSSSWTTestCase {
/**
* Tests the <code>lowercase</code> attribute value.
*/
+ @Test
public void testTextTransformLowerCase() {
Control controlToTest = createTestControl(getWidgetName()
+ " { text-transform: lowercase; }");
assertEquals("some label text", getText(controlToTest));
}
+
}
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ThemeTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ThemeTest.java
index ee0db5030d7..8af91f38475 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ThemeTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ThemeTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 IBM Corporation and others.
+ * Copyright (c) 2013, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,9 +7,14 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import java.util.Dictionary;
import java.util.Hashtable;
@@ -18,6 +23,9 @@ import org.eclipse.e4.ui.css.swt.theme.ITheme;
import org.eclipse.e4.ui.css.swt.theme.IThemeEngine;
import org.eclipse.e4.ui.css.swt.theme.IThemeManager;
import org.eclipse.swt.widgets.Display;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
@@ -32,42 +40,45 @@ public class ThemeTest extends CSSSWTTestCase {
private ServiceRegistration<EventHandler> themeListenerRegistration;
private ServiceReference<IThemeManager> themeManagerReference;
- @Override
- public void setUp() throws Exception {
+ @Before
+ public void setUp() {
Bundle b = FrameworkUtil.getBundle(this.getClass());
assertNotNull("Not running in an OSGi environment", b);
context = b.getBundleContext();
assertNotNull("Not running in an OSGi environment", b);
themeManagerReference = context
.getServiceReference(IThemeManager.class);
- super.setUp();
}
@Override
- public void tearDown() throws Exception {
+ @After
+ public void tearDown() {
themeListenerRegistration.unregister();
super.tearDown();
}
- public void testThemeChangeNotification() throws Exception {
+ @Test
+ public void testThemeChangeNotification() {
// we don't call createEngine() as ThemeEngine creates its own engine
+
final Display display = Display.getDefault();
final IThemeEngine themer = getThemeEngine(display);
-
+
final boolean success[] = new boolean[] { false };
Dictionary<String, String> properties = new Hashtable<String, String>();
properties.put(EventConstants.EVENT_TOPIC,
IThemeEngine.Events.THEME_CHANGED);
themeListenerRegistration = context.registerService(EventHandler.class, new EventHandler() {
+ @Override
public void handleEvent(Event event) {
ITheme theme = (ITheme)event.getProperty(IThemeEngine.Events.THEME);
success[0] = IThemeEngine.Events.THEME_CHANGED.equals(event.getTopic())
- && theme != null
- && theme.getId().equals("test")
- && event.getProperty(IThemeEngine.Events.DEVICE) == display
- && event.getProperty(IThemeEngine.Events.THEME_ENGINE) == themer
- && event.getProperty(IThemeEngine.Events.RESTORE) == Boolean.TRUE;
+ && theme != null
+ && theme.getId().equals("test")
+ && event.getProperty(IThemeEngine.Events.DEVICE) == display
+ && event.getProperty(IThemeEngine.Events.THEME_ENGINE) == themer
+ && event.getProperty(IThemeEngine.Events.RESTORE) == Boolean.TRUE;
}}, properties);
assertFalse(success[0]);
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ThemesExtensionTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ThemesExtensionTest.java
index 0dd9a58184a..a8ef45e0a69 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ThemesExtensionTest.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ThemesExtensionTest.java
@@ -7,27 +7,29 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Thibault Le Ouay <thibaultleouay@gmail.com> - Bug 443094
*******************************************************************************/
package org.eclipse.e4.ui.tests.css.swt;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.swt.widgets.Display;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import org.eclipse.ui.internal.themes.ColorDefinition;
import org.eclipse.ui.internal.themes.FontDefinition;
import org.eclipse.ui.internal.themes.ThemesExtension;
+import org.junit.Test;
@SuppressWarnings("restriction")
public class ThemesExtensionTest extends CSSSWTTestCase {
- private Display display;
-
- @Override
- protected void setUp() throws Exception {
- display = Display.getDefault();
- }
- public void testThemesExtension() throws Exception {
+ @Test
+ public void testThemesExtension() {
//given
- CSSEngine engine = createEngine("ThemesExtension {font-definition: '#org-eclipse-ui-workbench-FONT_DEF_1'," +
+ engine = createEngine(
+ "ThemesExtension {font-definition: '#org-eclipse-ui-workbench-FONT_DEF_1',"
+ +
"'#org-eclipse-ui-workbench-FONT_DEF_2'; color-definition: '#org-eclipse-ui-workbench-COLOR_DEF_1';}", display);
ThemesExtension themesExtention = new ThemesExtension();

Back to the top