summaryrefslogtreecommitdiffstats
path: root/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_PaletteData.java
blob: 35c6dc3fb72168938fc848b579017cdac8088d0b (plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*******************************************************************************
 * Copyright (c) 2000, 2003 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.tests.junit;


import org.eclipse.swt.graphics.*;

import junit.framework.*;
import junit.textui.*;

/**
 * Automated Test Suite for class org.eclipse.swt.graphics.PaletteData
 *
 * @see org.eclipse.swt.graphics.PaletteData
 */
public class Test_org_eclipse_swt_graphics_PaletteData extends SwtTestCase {

public Test_org_eclipse_swt_graphics_PaletteData(String name) {
	super(name);
}

public static void main(String[] args) {
	TestRunner.run(suite());
}

protected void setUp() {
}

protected void tearDown() {
}

public void test_Constructor$Lorg_eclipse_swt_graphics_RGB() {
	try {
		new PaletteData(null);
		fail("No exception thrown for rgb == null");
	}
	catch (IllegalArgumentException e) {
	}

	PaletteData data = new PaletteData(new RGB[] {});
	assertFalse(":a:", data.isDirect);

	new PaletteData(new RGB[] {null, null});
	assertFalse(":b:", data.isDirect);

	new PaletteData(new RGB[] {new RGB(0, 0, 0), new RGB(255, 255, 255)});
	assertFalse(":c:", data.isDirect);
}

public void test_ConstructorIII() {
	PaletteData data = new PaletteData(0, 0, 0);
	assertTrue(":a:", data.isDirect);

	data = new PaletteData(-1, -1, -1);
	assertTrue(":b:", data.isDirect);

	data = new PaletteData(0xff0000, 0x00ff00, 0x0000ff);
	assertTrue(":c:", data.isDirect);
}

public void test_getPixelLorg_eclipse_swt_graphics_RGB() {
	// indexed palette tests	
	RGB[] rgbs = {new RGB(0, 0, 0), new RGB(255, 255, 255), new RGB(50, 100, 150)};
	PaletteData data = new PaletteData(rgbs);
	
	try {
		data.getPixel(null);
		fail("No exception thrown for indexed palette with rgb == null");
	}
	catch (IllegalArgumentException e) {
	}
	
	try {
		data.getPixel(new RGB(0, 0, 1));
		fail("No exception thrown for rgb not found");
	}
	catch (IllegalArgumentException e) {
	}

	assertEquals(":a:", rgbs.length-1, data.getPixel(rgbs[rgbs.length-1]));
	
	// direct palette tests	
	RGB rgb =new RGB(0x32, 0x64, 0x96);
	data = new PaletteData(0xff0000, 0x00ff00, 0x0000ff);
	
	try {
		data.getPixel(null);
		fail("No exception thrown for direct palette with rgb == null");
	}
	catch (IllegalArgumentException e) {
	}

	assertEquals(":b:", 0x326496, data.getPixel(rgb));
}

public void test_getRGBI() {
	// indexed palette tests	
	RGB[] rgbs = {new RGB(0, 0, 0), new RGB(255, 255, 255), new RGB(50, 100, 150)};
	PaletteData data = new PaletteData(rgbs);

	try {
		data.getRGB(rgbs.length);
		fail("No exception thrown for nonexistent pixel");
	}
	catch (IllegalArgumentException e) {
	}

	assertEquals(":a:", rgbs[rgbs.length-1], data.getRGB(rgbs.length-1));

	// direct palette tests	
	RGB rgb =new RGB(0x32, 0x64, 0x96);
	data = new PaletteData(0xff0000, 0x00ff00, 0x0000ff);
	
	assertEquals(":b:", rgb, data.getRGB(0x326496));
}

public void test_getRGBs() {
	// indexed palette tests	
	RGB[] rgbs = {new RGB(0, 0, 0), new RGB(255, 255, 255)};
	PaletteData data = new PaletteData(rgbs);
	
	assertEquals(":a:", rgbs, data.getRGBs());
	
	// direct palette tests	
	data = new PaletteData(0xff0000, 0x00ff00, 0x0000ff);
	
	assertNull(":b:", data.getRGBs());
}

public static Test suite() {
	TestSuite suite = new TestSuite();
	java.util.Vector methodNames = methodNames();
	java.util.Enumeration e = methodNames.elements();
	while (e.hasMoreElements()) {
		suite.addTest(new Test_org_eclipse_swt_graphics_PaletteData((String)e.nextElement()));
	}
	return suite;
}
public static java.util.Vector methodNames() {
	java.util.Vector methodNames = new java.util.Vector();
	methodNames.addElement("test_Constructor$Lorg_eclipse_swt_graphics_RGB");
	methodNames.addElement("test_ConstructorIII");
	methodNames.addElement("test_getPixelLorg_eclipse_swt_graphics_RGB");
	methodNames.addElement("test_getRGBI");
	methodNames.addElement("test_getRGBs");
	return methodNames;
}
protected void runTest() throws Throwable {
	if (getName().equals("test_Constructor$Lorg_eclipse_swt_graphics_RGB")) test_Constructor$Lorg_eclipse_swt_graphics_RGB();
	else if (getName().equals("test_ConstructorIII")) test_ConstructorIII();
	else if (getName().equals("test_getPixelLorg_eclipse_swt_graphics_RGB")) test_getPixelLorg_eclipse_swt_graphics_RGB();
	else if (getName().equals("test_getRGBI")) test_getRGBI();
	else if (getName().equals("test_getRGBs")) test_getRGBs();
}
}