Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRalf Sternberg2011-02-05 20:38:32 +0000
committerRalf Sternberg2011-02-05 20:38:32 +0000
commit9afbd3e2cc712814727166523e3dc059de646af0 (patch)
tree21c5da4cd59d11c68043c97145f01d6e27b5e25c /tests
parent5d437fb7b59839029029da0e27baad5aa4da4df3 (diff)
downloadorg.eclipse.rap-9afbd3e2cc712814727166523e3dc059de646af0.tar.gz
org.eclipse.rap-9afbd3e2cc712814727166523e3dc059de646af0.tar.xz
org.eclipse.rap-9afbd3e2cc712814727166523e3dc059de646af0.zip
Speed up theming tests for default theme
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.rap.rwt.themes.test/src/org/eclipse/rap/rwt/themes/test/ThemeTestCase.java13
-rw-r--r--tests/org.eclipse.rap.rwt.themes.test/src/org/eclipse/rap/rwt/themes/test/ThemesTestUtil.java54
-rw-r--r--tests/org.eclipse.rap.rwt.themes.test/src/org/eclipse/rap/rwt/themes/test/rwtdefault/DefaultTheme_Test.java43
3 files changed, 40 insertions, 70 deletions
diff --git a/tests/org.eclipse.rap.rwt.themes.test/src/org/eclipse/rap/rwt/themes/test/ThemeTestCase.java b/tests/org.eclipse.rap.rwt.themes.test/src/org/eclipse/rap/rwt/themes/test/ThemeTestCase.java
index 0e556926ab..d5084eac45 100644
--- a/tests/org.eclipse.rap.rwt.themes.test/src/org/eclipse/rap/rwt/themes/test/ThemeTestCase.java
+++ b/tests/org.eclipse.rap.rwt.themes.test/src/org/eclipse/rap/rwt/themes/test/ThemeTestCase.java
@@ -18,6 +18,7 @@ import org.eclipse.rwt.internal.theme.css.StyleSheet;
import org.w3c.css.sac.Selector;
import org.w3c.css.sac.SelectorList;
+
public abstract class ThemeTestCase extends TestCase {
protected void setUp() {
@@ -60,11 +61,13 @@ public abstract class ThemeTestCase extends TestCase {
QxType actual = ThemeUtil.getCssValue( selector.getElementName(),
property,
config );
- String message = "Css test failed for "
- + createSelectorString( selector )
- + ", property "
- + property;
- assertEquals( message, expected, actual );
+ if( !actual.equals( expected ) ) {
+ String message = "Css test failed for "
+ + createSelectorString( selector )
+ + ", property "
+ + property;
+ assertEquals( message, expected, actual );
+ }
}
}
diff --git a/tests/org.eclipse.rap.rwt.themes.test/src/org/eclipse/rap/rwt/themes/test/ThemesTestUtil.java b/tests/org.eclipse.rap.rwt.themes.test/src/org/eclipse/rap/rwt/themes/test/ThemesTestUtil.java
index fd1ea937d7..bc49122455 100644
--- a/tests/org.eclipse.rap.rwt.themes.test/src/org/eclipse/rap/rwt/themes/test/ThemesTestUtil.java
+++ b/tests/org.eclipse.rap.rwt.themes.test/src/org/eclipse/rap/rwt/themes/test/ThemesTestUtil.java
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*******************************************************************************
* Copyright (c) 2010 EclipseSource 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
@@ -6,11 +6,12 @@
*
* Contributors:
* EclipseSource - initial API and implementation
-*******************************************************************************/
+*******************************************************************************/
package org.eclipse.rap.rwt.themes.test;
import java.io.IOException;
import java.io.InputStream;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
@@ -26,15 +27,14 @@ import org.eclipse.rwt.internal.theme.css.StyleSheet;
public class ThemesTestUtil {
public static final String CLASSIC_PATH = "theme/classic.css";
-
+
public static final String BUSINESS_PATH = "theme/business/business.css";
public static final String FANCY_PATH = "theme/fancy/fancy.css";
-
+
public static final String DEFAULT_PREFIX = "org/eclipse/swt/internal/";
- static final ResourceLoader RESOURCE_LOADER
- = createResourceLoader( ThemesTestUtil.class );
+ static final ResourceLoader RESOURCE_LOADER = getDefaultResourceLoader();
private static final String BUNDLE_ID = "org.eclipse.rap.rwt.themes.test";
@@ -55,18 +55,18 @@ public class ThemesTestUtil {
}
}
- private static String getBundlePath( final URLClassLoader classLoader,
- final String bundleId )
+ private static String getBundlePath( final URLClassLoader classLoader,
+ final String bundleId )
{
URL[] urls = classLoader.getURLs();
String path = null;
for( int i = 0; i < urls.length && path == null; i++ ) {
- String tempPath = urls[ i ].getPath();
+ String tempPath = urls[ i ].getPath();
if( tempPath.indexOf( bundleId ) != -1
- && tempPath.indexOf( BUNDLE_ID ) == -1 )
+ && tempPath.indexOf( BUNDLE_ID ) == -1 )
{
int indexOfBin = tempPath.indexOf( "bin" );
- if( indexOfBin != -1 ) {
+ if( indexOfBin != -1 ) {
String protocol = urls[ i ].getProtocol();
path = protocol + ":" + tempPath.substring( 0, indexOfBin );
}
@@ -88,12 +88,12 @@ public class ThemesTestUtil {
method.invoke( classLoader, url );
} catch( final Throwable e ) {
e.printStackTrace();
- }
+ }
}
}
- public static void createAndActivateTheme( final String path,
- final String themeId )
+ public static void createAndActivateTheme( final String path,
+ final String themeId )
{
StyleSheet styleSheet;
try {
@@ -106,19 +106,19 @@ public class ThemesTestUtil {
ThemeManager themeManager = ThemeManager.getInstance();
themeManager.registerTheme( theme );
themeManager.initialize();
- ThemeUtil.setCurrentThemeId( themeId );
+ ThemeUtil.setCurrentThemeId( themeId );
}
-
- public static ResourceLoader createResourceLoader( final Class clazz ) {
- final ClassLoader classLoader = clazz.getClassLoader();
- ResourceLoader resLoader = new ResourceLoader() {
- public InputStream getResourceAsStream( final String resourceName )
- throws IOException
- {
- return classLoader.getResourceAsStream( resourceName );
- }
- };
- return resLoader;
+
+ private static ResourceLoader getDefaultResourceLoader() {
+ ResourceLoader result;
+ try {
+ String name = "STANDARD_RESOURCE_LOADER";
+ Field field = ThemeManager.class.getDeclaredField( name );
+ field.setAccessible( true );
+ result = ( ResourceLoader )field.get( null );
+ } catch( Exception e ) {
+ throw new RuntimeException( "Failed to obtain default resource loader" );
+ }
+ return result;
}
-
}
diff --git a/tests/org.eclipse.rap.rwt.themes.test/src/org/eclipse/rap/rwt/themes/test/rwtdefault/DefaultTheme_Test.java b/tests/org.eclipse.rap.rwt.themes.test/src/org/eclipse/rap/rwt/themes/test/rwtdefault/DefaultTheme_Test.java
index 433dceda43..3d11d38ab3 100644
--- a/tests/org.eclipse.rap.rwt.themes.test/src/org/eclipse/rap/rwt/themes/test/rwtdefault/DefaultTheme_Test.java
+++ b/tests/org.eclipse.rap.rwt.themes.test/src/org/eclipse/rap/rwt/themes/test/rwtdefault/DefaultTheme_Test.java
@@ -10,77 +10,44 @@
package org.eclipse.rap.rwt.themes.test.rwtdefault;
import java.io.IOException;
-import java.util.Random;
import org.eclipse.rap.rwt.themes.test.ThemeTestCase;
-import org.eclipse.rap.rwt.themes.test.ThemesTestUtil;
+import org.eclipse.rwt.internal.theme.ThemeManager;
+import org.eclipse.rwt.internal.theme.ThemeUtil;
public class DefaultTheme_Test extends ThemeTestCase {
public void testDefaultTheme() throws IOException {
- createFakeTheme( "widgets/buttonkit/Button.default.css" );
+ ThemeManager.resetInstance();
+ ThemeManager.getInstance().initialize();
+ ThemeUtil.setCurrentThemeId( ThemeManager.DEFAULT_THEME_ID );
processCssTestFile( getClass(), "Button.test.css" );
- createFakeTheme( "widgets/shellkit/Shell.default.css" );
processCssTestFile( getClass(), "Shell.test.css" );
- createFakeTheme( "widgets/toolbarkit/ToolBar.default.css" );
processCssTestFile( getClass(), "Toolbar.test.css" );
- createFakeTheme( "widgets/treekit/Tree.default.css" );
processCssTestFile( getClass(), "Tree.test.css" );
- createFakeTheme( "widgets/tablekit/Table.default.css" );
processCssTestFile( getClass(), "Table.test.css" );
- createFakeTheme( "widgets/listkit/List.default.css" );
processCssTestFile( getClass(), "List.test.css" );
- createFakeTheme( "widgets/linkkit/Link.default.css" );
processCssTestFile( getClass(), "Link.test.css" );
- createFakeTheme( "widgets/menukit/Menu.default.css" );
processCssTestFile( getClass(), "Menu.test.css" );
- createFakeTheme( "custom/clabelkit/CLabel.default.css" );
processCssTestFile( getClass(), "CLabel.test.css" );
- createFakeTheme( "widgets/labelkit/Label.default.css" );
processCssTestFile( getClass(), "Label.test.css" );
- createFakeTheme( "widgets/expandbarkit/ExpandBar.default.css" );
processCssTestFile( getClass(), "ExpandBar.test.css" );
- createFakeTheme( "widgets/combokit/Combo.default.css" );
processCssTestFile( getClass(), "Combo.test.css" );
- createFakeTheme( "custom/ccombokit/CCombo.default.css" );
processCssTestFile( getClass(), "CCombo.test.css" );
- createFakeTheme( "widgets/spinnerkit/Spinner.default.css" );
processCssTestFile( getClass(), "Spinner.test.css" );
- createFakeTheme( "widgets/datetimekit/DateTime.default.css" );
processCssTestFile( getClass(), "DateTime.test.css" );
- createFakeTheme( "widgets/textkit/Text.default.css" );
processCssTestFile( getClass(), "Text.test.css" );
- createFakeTheme( "widgets/groupkit/Group.default.css" );
processCssTestFile( getClass(), "Group.test.css" );
- createFakeTheme( "widgets/progressbarkit/ProgressBar.default.css" );
processCssTestFile( getClass(), "ProgressBar.test.css" );
- createFakeTheme( "widgets/compositekit/Composite.default.css" );
processCssTestFile( getClass(), "Composite.test.css" );
- createFakeTheme( "widgets/sliderkit/Slider.default.css" );
processCssTestFile( getClass(), "Slider.test.css" );
- createFakeTheme( "widgets/scrollbarkit/ScrollBar.default.css" );
processCssTestFile( getClass(), "ScrollBar.test.css" );
- createFakeTheme( "widgets/widgetkit/Widget.default.css" );
processCssTestFile( getClass(), "Widget.test.css" );
- createFakeTheme( "widgets/tabfolderkit/TabFolder.default.css" );
processCssTestFile( getClass(), "TabFolder.test.css" );
- createFakeTheme( "custom/ctabfolderkit/CTabFolder.default.css" );
processCssTestFile( getClass(), "CTabFolder.test.css" );
- createFakeTheme( "widgets/scalekit/Scale.default.css" );
processCssTestFile( getClass(), "Scale.test.css" );
- createFakeTheme( "widgets/sashkit/Sash.default.css" );
processCssTestFile( getClass(), "Sash.test.css" );
- createFakeTheme( "widgets/tooltipkit/ToolTip.default.css" );
processCssTestFile( getClass(), "ToolTip.test.css" );
}
-
-
- private void createFakeTheme( final String filePath ) {
- String prefix = ThemesTestUtil.DEFAULT_PREFIX;
- Random random = new Random();
- ThemesTestUtil.createAndActivateTheme( prefix + filePath,
- "test." + random.nextInt() + ".id");
- }
-
}

Back to the top