Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a32742b4cdbbbe158f1680c7d3f8632aabcc1b5f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*******************************************************************************
 * Copyright (c) 2013 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
 *******************************************************************************/
package org.eclipse.e4.ui.css.swt.helpers;

import static org.eclipse.e4.ui.css.swt.helpers.CSSSWTColorHelper.getSWTColor;

import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
import org.w3c.dom.css.CSSValue;

@SuppressWarnings("restriction")
public class CSSSWTColorHelperTest extends CSSSWTHelperTestCase {
	private Display display;
	
	@Override
	protected void setUp() throws Exception {
		display = Display.getDefault();
	}
	
	public void testGetSWTColor() throws Exception {
		Color result = getSWTColor(colorProperties("red"), display);
		
		assertNotNull(result);
		assertEquals(255, result.getRed());
		assertEquals(0, result.getBlue());
		assertEquals(0, result.getGreen());
	}
	
	public void testGetSWTColorWhenNotSupportedColorType() throws Exception {
		Color result = getSWTColor(colorProperties("123213", CSSValue.CSS_CUSTOM), display);
		
		assertNull(result);
	}
	
	public void testGetSWTColorWhenInvalidColorValue() throws Exception {
		Color result = getSWTColor(colorProperties("asdsad12"), display);
		
		assertNotNull(result);
		assertEquals(0, result.getRed());
		assertEquals(0, result.getBlue());
		assertEquals(0, result.getGreen());
	}
	
	public void testGetSWTColorWhenColorFromDefinition() throws Exception {
		registerColorProviderWith("org.eclipse.jdt.debug.ui.InDeadlockColor", new RGB(0, 255, 0));
		
		Color result = getSWTColor(colorProperties(colorDefinition("org-eclipse-jdt-debug-ui-InDeadlockColor")), display);
		
		assertNotNull(result);
		assertEquals(0, result.getRed());
		assertEquals(0, result.getBlue());
		assertEquals(255, result.getGreen());
	}	
}

Back to the top